WIP: A simple cli for daily tangled use cases and AI integration. This is for my personal use right now, but happy if others get mileage from it! :)

Update TODO and README

markbennett.ca bf2d82ca 3c43bd03

verified
+74 -57
+41 -37
README.md
··· 35 35 36 36 ## 4. Tech Stack (TypeScript) 37 37 38 - | Component | Library | Purpose | 39 - | :---------------- | :-------------------- | :----------------------------------------------------------- | 40 - | **Framework** | **commander** | Routing (tangled repo create). | 41 - | **API Client** | **@atproto/api** | Official XRPC client & session management. | 42 - | **Git Context** | **git-url-parse** | **New:** Parses remote URLs to extract the Tangled DID/NSID. | 43 - | **Git Ops** | **simple-git** | Wraps local git operations safely. | 44 - | **Validation** | **zod** | Validates inputs & generates schemas for LLMs. | 45 - | **Interactivity** | **@inquirer/prompts** | Modern prompts for humans. | 46 - | **Formatting** | **cli-table3** | **New:** For gh-style pretty tables in Human Mode. | 38 + | Component | Library | Purpose | 39 + | :---------------- | :-------------------- | :------------------------------------------------------------ | 40 + | **Framework** | **commander** | Routing (tangled repo create). | 41 + | **API Client** | **@atproto/api** | Official XRPC client & session management. | 42 + | **Git Context** | **git-url-parse** | **New:** Parses remote URLs to extract the Tangled DID/NSID. | 43 + | **Git Ops** | **simple-git** | Wraps local git operations safely. | 44 + | **Validation** | **zod** | Validates inputs & generates schemas for LLMs. | 45 + | **Interactivity** | **@inquirer/prompts** | Modern prompts for humans. | 46 + | **Formatting** | **cli-table3** | **New:** For gh-style pretty tables in Human Mode. | 47 47 | **OS Keychain** | **keytar** | **New:** To securely store session tokens in the OS keychain. | 48 48 49 49 ## 5. Agent Integration (The "LLM Friendly" Layer) ··· 71 71 ### Rule 4: Flexible Input for Issue Bodies 72 72 73 73 Following `gh`'s pattern, `tangled issue create` will support various ways to provide the issue body, making it LLM-friendly and flexible for scripting. It will accept: 74 - - `--body "Text"` or `-b "Text"` for a direct string. 75 - - `--body-file ./file.md` or `-F ./file.md` to read from a file. 76 - - `--body-file -` or `-F -` to read from standard input (stdin). 74 + 75 + - `--body "Text"` or `-b "Text"` for a direct string. 76 + - `--body-file ./file.md` or `-F ./file.md` to read from a file. 77 + - `--body-file -` or `-F -` to read from standard input (stdin). 77 78 78 79 ### Summary of Improvements 79 80 ··· 132 133 133 134 ### 1. (Resolved) SSH Key Management (`gh` Compatibility) 134 135 135 - * **Original Question:** How does `gh` manage SSH keys, and can we follow that pattern? 136 - * **Resolution:** Analysis shows that `gh` does *not* manage private keys. It facilitates uploading the user's *public* key to their GitHub account. The local SSH agent handles the private key. 137 - * **Our Approach:** The `tangled ssh-key add` command follows this exact pattern. It provides a user-friendly way to upload a public key to `tangled.org`. This resolves the core of this issue, as it is compatible with external key managers like 1Password's SSH agent. 136 + - **Original Question:** How does `gh` manage SSH keys, and can we follow that pattern? 137 + - **Resolution:** Analysis shows that `gh` does _not_ manage private keys. It facilitates uploading the user's _public_ key to their GitHub account. The local SSH agent handles the private key. 138 + - **Our Approach:** The `tangled ssh-key add` command follows this exact pattern. It provides a user-friendly way to upload a public key to `tangled.org`. This resolves the core of this issue, as it is compatible with external key managers like 1Password's SSH agent. 138 139 139 140 ### 2. (Decided) Secure Session Storage 140 141 141 - * **Original Question:** How should we securely store the AT Proto session token? 142 - * **Resolution:** Storing sensitive tokens in plaintext files is not secure. 143 - * **Our Approach:** The CLI will use the operating system's native keychain for secure storage (e.g., macOS Keychain, Windows Credential Manager, or Secret Service on Linux). A library like `keytar` will be used to abstract the platform differences. 142 + - **Original Question:** How should we securely store the AT Proto session token? 143 + - **Resolution:** Storing sensitive tokens in plaintext files is not secure. 144 + - **Our Approach:** The CLI will use the operating system's native keychain for secure storage (e.g., macOS Keychain, Windows Credential Manager, or Secret Service on Linux). A library like `keytar` will be used to abstract the platform differences. 144 145 145 146 ### 3. (Decided) Configuration Resolution Order 146 147 147 - * **Original Question:** How should settings be resolved from different sources? 148 - * **Resolution:** A clear precedence order is necessary. 149 - * **Our Approach:** The CLI will resolve settings in the following order of precedence (highest first): 150 - 1. Command-line flags (e.g., `--repo-did ...`) 151 - 2. Environment variables (e.g., `TANGLED_REPO_DID=...`) 152 - 3. Project-specific config file (e.g., `.tangled/config.yml` in the current directory) 153 - 4. Global user config file (e.g., `~/.config/tangled/config.yml`) 148 + - **Original Question:** How should settings be resolved from different sources? 149 + - **Resolution:** A clear precedence order is necessary. 150 + - **Our Approach:** The CLI will resolve settings in the following order of precedence (highest first): 151 + 1. Command-line flags (e.g., `--repo-did ...`) 152 + 2. Environment variables (e.g., `TANGLED_REPO_DID=...`) 153 + 3. Project-specific config file (e.g., `.tangled/config.yml` in the current directory) 154 + 4. Global user config file (e.g., `~/.config/tangled/config.yml`) 154 155 155 - ### 4. (Outstanding) Web-based Authentication Flow 156 + ### 4. (Decided for V1) Authentication Flow: App Passwords (PDS) 156 157 157 - * **Original Question:** Can we allow auth through a web browser? 158 - * **Status:** This remains an outstanding issue. The standard AT Protocol authentication flow is based on user handles and app passwords, not a third-party OAuth2 flow like GitHub CLI uses. 159 - * **Path Forward:** Implementing a web-based auth flow would require custom development on the `tangled.org` service itself to securely generate and transmit a session token back to the CLI. This is out of scope for the initial version of the CLI. 158 + - **Original Question:** Can we allow auth through a web browser? 159 + - **Resolution:** For the initial version, the CLI will use **App Passwords** for authentication. This is the standard and simplest method for third-party AT Protocol clients and aligns with existing practices. 160 + - **`tangled auth login` Flow:** When running `tangled auth login`, the CLI will prompt the user for their **PDS handle** (e.g., `@mark.bsky.social`) and an **App Password**. 161 + - **Generating an App Password:** Users typically generate App Passwords from their PDS's settings (e.g., in the official Bluesky app under "Settings -> App Passwords", or on their self-hosted PDS web interface). The CLI **does not** generate app passwords. 162 + - **Session Management:** The session established is with the user's PDS, and this authenticated session is then used to interact with `tangled.org`'s App View/Service. 163 + - **OAuth Support:** Implementing a web-based OAuth flow (similar to `gh`'s approach) is more complex and not a standard part of the AT Protocol client authentication flow. This approach is deferred for future consideration. 160 164 161 165 ## 9. Future Expansion Opportunities 162 166 163 167 The analysis of the `tangled.org` API revealed a rich set of features that are not yet part of the initial CLI plan but represent significant opportunities for future expansion. These include: 164 168 165 - * **CI/CD Pipelines:** Commands to view pipeline status and manage CI/CD jobs. 166 - * **Repository Secrets:** A dedicated command set for managing CI/CD secrets within a repository (`tangled repo secret ...`). 167 - * **Advanced Git Operations:** Commands to interact with the commit log, diffs, branches, and tags directly via the API, augmenting local `git` commands. 168 - * **Social & Feed Interactions:** Commands for starring repositories, reacting to feed items, and managing the user's social graph (following/unfollowing). 169 - * **Label Management:** Commands to create, apply, and remove labels from issues and pull requests. 170 - * **Collaboration:** Commands to manage repository collaborators. 171 - * **Fork Management:** Commands for forking repositories and managing the sync status of forks. 169 + - **CI/CD Pipelines:** Commands to view pipeline status and manage CI/CD jobs. 170 + - **Repository Secrets:** A dedicated command set for managing CI/CD secrets within a repository (`tangled repo secret ...`). 171 + - **Advanced Git Operations:** Commands to interact with the commit log, diffs, branches, and tags directly via the API, augmenting local `git` commands. 172 + - **Social & Feed Interactions:** Commands for starring repositories, reacting to feed items, and managing the user's social graph (following/unfollowing). 173 + - **Label Management:** Commands to create, apply, and remove labels from issues and pull requests. 174 + - **Collaboration:** Commands to manage repository collaborators. 175 + - **Fork Management:** Commands for forking repositories and managing the sync status of forks. 172 176 173 177 ## 10. Task Management 174 178 175 - We're bootstrapping task tracking with TODO.md, but will migrate all tasks into Tangled issues and dog food the product as soon as we have basic issue creation and listing working. 179 + We're bootstrapping task tracking with TODO.md, but will migrate all tasks into Tangled issues and dog food the product as soon as we have basic issue creation and listing working.
+33 -20
TODO.md
··· 3 3 This document outlines the development tasks for the Tangled CLI, based on the `README.md` and project goals. 4 4 5 5 ## 1. Project Setup & Core Structure (Commander.js) 6 + 6 7 - [ ] Initialize Node.js project. 7 8 - [ ] Install `commander` for CLI routing. 8 9 - [ ] Implement basic CLI command structure (e.g., `tangled --version`, `tangled --help`). ··· 10 11 - [ ] Configure linting and formatting (ESLint, Prettier). 11 12 12 13 ## 2. Authentication (Auth) 14 + 13 15 - [ ] Implement `tangled auth login` command. 14 - - [ ] Implement session storage using an OS keychain library (e.g., `keytar`) for secure, cross-platform token management. 15 - - [ ] Integrate `@atproto/api` for XRPC client and session management. 16 - - [ ] Investigate web browser authentication flow. 16 + - [ ] Collect user's PDS handle and app password. 17 + - [ ] Implement session storage using an OS keychain library (e.g., `keytar`) for secure, cross-platform token management. 18 + - [ ] Integrate `@atproto/api` for XRPC client and session management. 17 19 - [ ] Implement `tangled auth logout` command. 18 20 19 21 ## 3. Git SSH Key Management 22 + 20 23 - [ ] Implement `tangled ssh-key add <public-key-path>` command. 21 - - [ ] This command should upload the provided public SSH key to the user's tangled.org account via the API, similar to how `gh ssh-key add` works. 22 - - [ ] The CLI is not responsible for generating SSH keys or managing the local ssh-agent; users are expected to handle these steps externally. 24 + - [ ] This command should upload the provided public SSH key to the user's tangled.org account via the API, similar to how `gh ssh-key add` works. 25 + - [ ] The CLI is not responsible for generating SSH keys or managing the local ssh-agent; users are expected to handle these steps externally. 23 26 - [ ] Implement `tangled ssh-key verify` command. 24 - - [ ] This command should execute `ssh -T git@tangled.org`, parse the DID from its output, and then resolve that DID to a Bluesky handle, displaying the result to the user. 27 + - [ ] This command should execute `ssh -T git@tangled.org`, parse the DID from its output, and then resolve that DID to a Bluesky handle, displaying the result to the user. 25 28 - [ ] Ensure all Git operations leverage SSH keys for authentication, as `tangled.org` exclusively supports SSH for Git. 26 29 27 30 ## 4. Context Engine (Git Integration) 31 + 28 32 - [ ] Integrate `git-url-parse` to resolve Tangled DID/NSID from `.git/config` remote URLs. 29 33 - [ ] Develop a "Context Resolver" module to infer repository context (DID) from the current working directory. 30 34 - [ ] Implement fallback mechanisms if no git remote is found or DID cannot be resolved (error handling). ··· 33 37 - [ ] Implement functionality to resolve a DID (e.g., `did:plc:b2mcbcamkwyznc5fkplwlxbf`) into a human-readable Bluesky handle (will be reused by `tangled ssh-key verify`). 34 38 35 39 ## 5. Repository Management 40 + 36 41 - [ ] Implement `tangled repo create <repo-name>` command. 37 42 - [ ] Implement `tangled repo view` command (display repo details). 38 - - [ ] Support `--json` output with field filtering (e.g., `--json name,cloneUrl,description`) using `lodash/pick`). 43 + - [ ] Support `--json` output with field filtering (e.g., `--json name,cloneUrl,description`) using `lodash/pick`). 39 44 40 45 ## 6. Issue Management 46 + 41 47 - [ ] Implement `tangled issue create "<title>" [--body "<body>" | --body-file <file> | -F -]` command. 42 48 - [ ] Implement `tangled issue list [--json "id,title"]` command. 43 - - [ ] Support `--json` output with field filtering. 49 + - [ ] Support `--json` output with field filtering. 44 50 45 51 ## 7. Pull Request Management 46 52 47 53 This section outlines the phased implementation for Pull Request (PR) support, following `gh` CLI patterns. 48 54 49 55 ### Phase 1: Creating a Pull Request from a Branch (Author Workflow) 56 + 50 57 - [ ] Implement `tangled pr create --base <base-branch> --head <head-branch> --title <title> [--body <body> | --body-file <file> | -F -]` command. 51 - - [ ] Generate the `git diff` patch between the `--head` and `--base` branches. 52 - - [ ] Upload the generated patch as a blob using `com.atproto.repo.uploadBlob` (or equivalent). 53 - - [ ] Create a `sh.tangled.repo.pull` record using `com.atproto.repo.createRecord`, including `target` (repo and base branch), `source` (head branch and SHA), `title`, `body`, and the `patchBlob` reference. 58 + - [ ] Generate the `git diff` patch between the `--head` and `--base` branches. 59 + - [ ] Upload the generated patch as a blob using `com.atproto.repo.uploadBlob` (or equivalent). 60 + - [ ] Create a `sh.tangled.repo.pull` record using `com.atproto.repo.createRecord`, including `target` (repo and base branch), `source` (head branch and SHA), `title`, `body`, and the `patchBlob` reference. 54 61 - [ ] Implement `tangled pr list [--json <fields>]` command to list pull requests for the current repository. 55 - - [ ] Use `com.atproto.repo.listRecords` with `collection: "sh.tangled.repo.pull"`. 62 + - [ ] Use `com.atproto.repo.listRecords` with `collection: "sh.tangled.repo.pull"`. 56 63 - [ ] Implement `tangled pr view <id> [--json <fields>]` command to display detailed information about a specific pull request. 57 - - [ ] Use `com.atproto.repo.getRecord` for the `sh.tangled.repo.pull` record. 58 - - [ ] Fetch associated comments using `com.atproto.repo.listRecords` with `collection: "sh.tangled.repo.pull.comment"`. 64 + - [ ] Use `com.atproto.repo.getRecord` for the `sh.tangled.repo.pull` record. 65 + - [ ] Fetch associated comments using `com.atproto.repo.listRecords` with `collection: "sh.tangled.repo.pull.comment"`. 59 66 60 67 ### Phase 2: Working as a Reviewer (Commenting) 68 + 61 69 - [ ] Implement `tangled pr comment <id> [--body <body> | --body-file <file> | -F -]` command. 62 - - [ ] Create a `sh.tangled.repo.pull.comment` record using `com.atproto.repo.createRecord`, linking it to the pull request's AT-URI. 70 + - [ ] Create a `sh.tangled.repo.pull.comment` record using `com.atproto.repo.createRecord`, linking it to the pull request's AT-URI. 63 71 - [ ] Implement `tangled pr review <id> --comment <comment> [--approve | --request-changes]` command. 64 - - [ ] Create a `sh.tangled.repo.pull.comment` record. 65 - - [ ] Update the `sh.tangled.repo.pull.status` record (if applicable) to reflect approval or requested changes. (Further API research might be needed to map approve/request-changes to status updates). 72 + - [ ] Create a `sh.tangled.repo.pull.comment` record. 73 + - [ ] Update the `sh.tangled.repo.pull.status` record (if applicable) to reflect approval or requested changes. (Further API research might be needed to map approve/request-changes to status updates). 66 74 67 75 ### Phase 3: Responding to a Review (Author Workflow) 76 + 68 77 - [ ] This phase primarily involves local Git operations (pushing new commits) and using `tangled pr comment` for clarifications, which are covered by existing or planned commands. 69 78 70 79 ## 8. Output & LLM Integration 80 + 71 81 - [ ] Implement output formatting based on `is-interactive` check. 72 - - [ ] "Human Mode" (TTY): Use `cli-table3` for pretty tables. 73 - - [ ] "Machine Mode" (Pipe/`--json`): Plain text or JSON output. 82 + - [ ] "Human Mode" (TTY): Use `cli-table3` for pretty tables. 83 + - [ ] "Machine Mode" (Pipe/`--json`): Plain text or JSON output. 74 84 - [ ] Implement `--json` flag for structured output. 75 85 - [ ] Implement `--no-input` flag to force CLI to error on unresolved context or missing flags (Fail Fast, Fail Loud principle). 76 86 77 87 ## 9. Testing 88 + 78 89 - [ ] Set up a testing framework (e.g., Jest, Vitest). 79 90 - [ ] Write unit tests for core modules (Auth, Context Resolver, API client). 80 91 - [ ] Write integration tests for CLI commands. 81 92 82 93 ## 10. Documentation & Deployment 94 + 83 95 - [ ] Generate CLI help documentation (`commander` usually handles this). 84 96 - [ ] Consider packaging/distribution strategy (npm, standalone binary). 85 97 86 98 ## 11. Outstanding Issues / Future Considerations (from README) 99 + 87 100 - [ ] Secure cross-platform AT Proto session storage (OS keychain). 88 101 - [ ] Git authentication management similar to GitHub CLI (SSH keys, 1Password integration). 89 102 - [ ] Define clear precedence order for settings resolution (local config, home folder, CLI flags). 90 - - [ ] Consider adding extensions/plugins (Out of Scope for V1, but keep in mind). 103 + - [ ] Consider adding extensions/plugins (Out of Scope for V1, but keep in mind).