···35353636## 4. Tech Stack (TypeScript)
37373838-| Component | Library | Purpose |
3939-| :---------------- | :-------------------- | :----------------------------------------------------------- |
4040-| **Framework** | **commander** | Routing (tangled repo create). |
4141-| **API Client** | **@atproto/api** | Official XRPC client & session management. |
4242-| **Git Context** | **git-url-parse** | **New:** Parses remote URLs to extract the Tangled DID/NSID. |
4343-| **Git Ops** | **simple-git** | Wraps local git operations safely. |
4444-| **Validation** | **zod** | Validates inputs & generates schemas for LLMs. |
4545-| **Interactivity** | **@inquirer/prompts** | Modern prompts for humans. |
4646-| **Formatting** | **cli-table3** | **New:** For gh-style pretty tables in Human Mode. |
3838+| Component | Library | Purpose |
3939+| :---------------- | :-------------------- | :------------------------------------------------------------ |
4040+| **Framework** | **commander** | Routing (tangled repo create). |
4141+| **API Client** | **@atproto/api** | Official XRPC client & session management. |
4242+| **Git Context** | **git-url-parse** | **New:** Parses remote URLs to extract the Tangled DID/NSID. |
4343+| **Git Ops** | **simple-git** | Wraps local git operations safely. |
4444+| **Validation** | **zod** | Validates inputs & generates schemas for LLMs. |
4545+| **Interactivity** | **@inquirer/prompts** | Modern prompts for humans. |
4646+| **Formatting** | **cli-table3** | **New:** For gh-style pretty tables in Human Mode. |
4747| **OS Keychain** | **keytar** | **New:** To securely store session tokens in the OS keychain. |
48484949## 5. Agent Integration (The "LLM Friendly" Layer)
···7171### Rule 4: Flexible Input for Issue Bodies
72727373Following `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:
7474-- `--body "Text"` or `-b "Text"` for a direct string.
7575-- `--body-file ./file.md` or `-F ./file.md` to read from a file.
7676-- `--body-file -` or `-F -` to read from standard input (stdin).
7474+7575+- `--body "Text"` or `-b "Text"` for a direct string.
7676+- `--body-file ./file.md` or `-F ./file.md` to read from a file.
7777+- `--body-file -` or `-F -` to read from standard input (stdin).
77787879### Summary of Improvements
7980···132133133134### 1. (Resolved) SSH Key Management (`gh` Compatibility)
134135135135-* **Original Question:** How does `gh` manage SSH keys, and can we follow that pattern?
136136-* **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.
137137-* **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.
136136+- **Original Question:** How does `gh` manage SSH keys, and can we follow that pattern?
137137+- **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.
138138+- **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.
138139139140### 2. (Decided) Secure Session Storage
140141141141-* **Original Question:** How should we securely store the AT Proto session token?
142142-* **Resolution:** Storing sensitive tokens in plaintext files is not secure.
143143-* **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.
142142+- **Original Question:** How should we securely store the AT Proto session token?
143143+- **Resolution:** Storing sensitive tokens in plaintext files is not secure.
144144+- **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.
144145145146### 3. (Decided) Configuration Resolution Order
146147147147-* **Original Question:** How should settings be resolved from different sources?
148148-* **Resolution:** A clear precedence order is necessary.
149149-* **Our Approach:** The CLI will resolve settings in the following order of precedence (highest first):
150150- 1. Command-line flags (e.g., `--repo-did ...`)
151151- 2. Environment variables (e.g., `TANGLED_REPO_DID=...`)
152152- 3. Project-specific config file (e.g., `.tangled/config.yml` in the current directory)
153153- 4. Global user config file (e.g., `~/.config/tangled/config.yml`)
148148+- **Original Question:** How should settings be resolved from different sources?
149149+- **Resolution:** A clear precedence order is necessary.
150150+- **Our Approach:** The CLI will resolve settings in the following order of precedence (highest first):
151151+ 1. Command-line flags (e.g., `--repo-did ...`)
152152+ 2. Environment variables (e.g., `TANGLED_REPO_DID=...`)
153153+ 3. Project-specific config file (e.g., `.tangled/config.yml` in the current directory)
154154+ 4. Global user config file (e.g., `~/.config/tangled/config.yml`)
154155155155-### 4. (Outstanding) Web-based Authentication Flow
156156+### 4. (Decided for V1) Authentication Flow: App Passwords (PDS)
156157157157-* **Original Question:** Can we allow auth through a web browser?
158158-* **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.
159159-* **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.
158158+- **Original Question:** Can we allow auth through a web browser?
159159+- **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.
160160+- **`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**.
161161+- **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.
162162+- **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.
163163+- **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.
160164161165## 9. Future Expansion Opportunities
162166163167The 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:
164168165165-* **CI/CD Pipelines:** Commands to view pipeline status and manage CI/CD jobs.
166166-* **Repository Secrets:** A dedicated command set for managing CI/CD secrets within a repository (`tangled repo secret ...`).
167167-* **Advanced Git Operations:** Commands to interact with the commit log, diffs, branches, and tags directly via the API, augmenting local `git` commands.
168168-* **Social & Feed Interactions:** Commands for starring repositories, reacting to feed items, and managing the user's social graph (following/unfollowing).
169169-* **Label Management:** Commands to create, apply, and remove labels from issues and pull requests.
170170-* **Collaboration:** Commands to manage repository collaborators.
171171-* **Fork Management:** Commands for forking repositories and managing the sync status of forks.
169169+- **CI/CD Pipelines:** Commands to view pipeline status and manage CI/CD jobs.
170170+- **Repository Secrets:** A dedicated command set for managing CI/CD secrets within a repository (`tangled repo secret ...`).
171171+- **Advanced Git Operations:** Commands to interact with the commit log, diffs, branches, and tags directly via the API, augmenting local `git` commands.
172172+- **Social & Feed Interactions:** Commands for starring repositories, reacting to feed items, and managing the user's social graph (following/unfollowing).
173173+- **Label Management:** Commands to create, apply, and remove labels from issues and pull requests.
174174+- **Collaboration:** Commands to manage repository collaborators.
175175+- **Fork Management:** Commands for forking repositories and managing the sync status of forks.
172176173177## 10. Task Management
174178175175-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.179179+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
···33This document outlines the development tasks for the Tangled CLI, based on the `README.md` and project goals.
4455## 1. Project Setup & Core Structure (Commander.js)
66+67- [ ] Initialize Node.js project.
78- [ ] Install `commander` for CLI routing.
89- [ ] Implement basic CLI command structure (e.g., `tangled --version`, `tangled --help`).
···1011- [ ] Configure linting and formatting (ESLint, Prettier).
11121213## 2. Authentication (Auth)
1414+1315- [ ] Implement `tangled auth login` command.
1414- - [ ] Implement session storage using an OS keychain library (e.g., `keytar`) for secure, cross-platform token management.
1515- - [ ] Integrate `@atproto/api` for XRPC client and session management.
1616- - [ ] Investigate web browser authentication flow.
1616+ - [ ] Collect user's PDS handle and app password.
1717+ - [ ] Implement session storage using an OS keychain library (e.g., `keytar`) for secure, cross-platform token management.
1818+ - [ ] Integrate `@atproto/api` for XRPC client and session management.
1719- [ ] Implement `tangled auth logout` command.
18201921## 3. Git SSH Key Management
2222+2023- [ ] Implement `tangled ssh-key add <public-key-path>` command.
2121- - [ ] 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.
2222- - [ ] The CLI is not responsible for generating SSH keys or managing the local ssh-agent; users are expected to handle these steps externally.
2424+ - [ ] 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.
2525+ - [ ] The CLI is not responsible for generating SSH keys or managing the local ssh-agent; users are expected to handle these steps externally.
2326- [ ] Implement `tangled ssh-key verify` command.
2424- - [ ] 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.
2727+ - [ ] 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.
2528- [ ] Ensure all Git operations leverage SSH keys for authentication, as `tangled.org` exclusively supports SSH for Git.
26292730## 4. Context Engine (Git Integration)
3131+2832- [ ] Integrate `git-url-parse` to resolve Tangled DID/NSID from `.git/config` remote URLs.
2933- [ ] Develop a "Context Resolver" module to infer repository context (DID) from the current working directory.
3034- [ ] Implement fallback mechanisms if no git remote is found or DID cannot be resolved (error handling).
···3337- [ ] 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`).
34383539## 5. Repository Management
4040+3641- [ ] Implement `tangled repo create <repo-name>` command.
3742- [ ] Implement `tangled repo view` command (display repo details).
3838- - [ ] Support `--json` output with field filtering (e.g., `--json name,cloneUrl,description`) using `lodash/pick`).
4343+ - [ ] Support `--json` output with field filtering (e.g., `--json name,cloneUrl,description`) using `lodash/pick`).
39444045## 6. Issue Management
4646+4147- [ ] Implement `tangled issue create "<title>" [--body "<body>" | --body-file <file> | -F -]` command.
4248- [ ] Implement `tangled issue list [--json "id,title"]` command.
4343- - [ ] Support `--json` output with field filtering.
4949+ - [ ] Support `--json` output with field filtering.
44504551## 7. Pull Request Management
46524753This section outlines the phased implementation for Pull Request (PR) support, following `gh` CLI patterns.
48544955### Phase 1: Creating a Pull Request from a Branch (Author Workflow)
5656+5057- [ ] Implement `tangled pr create --base <base-branch> --head <head-branch> --title <title> [--body <body> | --body-file <file> | -F -]` command.
5151- - [ ] Generate the `git diff` patch between the `--head` and `--base` branches.
5252- - [ ] Upload the generated patch as a blob using `com.atproto.repo.uploadBlob` (or equivalent).
5353- - [ ] 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.
5858+ - [ ] Generate the `git diff` patch between the `--head` and `--base` branches.
5959+ - [ ] Upload the generated patch as a blob using `com.atproto.repo.uploadBlob` (or equivalent).
6060+ - [ ] 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.
5461- [ ] Implement `tangled pr list [--json <fields>]` command to list pull requests for the current repository.
5555- - [ ] Use `com.atproto.repo.listRecords` with `collection: "sh.tangled.repo.pull"`.
6262+ - [ ] Use `com.atproto.repo.listRecords` with `collection: "sh.tangled.repo.pull"`.
5663- [ ] Implement `tangled pr view <id> [--json <fields>]` command to display detailed information about a specific pull request.
5757- - [ ] Use `com.atproto.repo.getRecord` for the `sh.tangled.repo.pull` record.
5858- - [ ] Fetch associated comments using `com.atproto.repo.listRecords` with `collection: "sh.tangled.repo.pull.comment"`.
6464+ - [ ] Use `com.atproto.repo.getRecord` for the `sh.tangled.repo.pull` record.
6565+ - [ ] Fetch associated comments using `com.atproto.repo.listRecords` with `collection: "sh.tangled.repo.pull.comment"`.
59666067### Phase 2: Working as a Reviewer (Commenting)
6868+6169- [ ] Implement `tangled pr comment <id> [--body <body> | --body-file <file> | -F -]` command.
6262- - [ ] Create a `sh.tangled.repo.pull.comment` record using `com.atproto.repo.createRecord`, linking it to the pull request's AT-URI.
7070+ - [ ] Create a `sh.tangled.repo.pull.comment` record using `com.atproto.repo.createRecord`, linking it to the pull request's AT-URI.
6371- [ ] Implement `tangled pr review <id> --comment <comment> [--approve | --request-changes]` command.
6464- - [ ] Create a `sh.tangled.repo.pull.comment` record.
6565- - [ ] 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).
7272+ - [ ] Create a `sh.tangled.repo.pull.comment` record.
7373+ - [ ] 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).
66746775### Phase 3: Responding to a Review (Author Workflow)
7676+6877- [ ] 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.
69787079## 8. Output & LLM Integration
8080+7181- [ ] Implement output formatting based on `is-interactive` check.
7272- - [ ] "Human Mode" (TTY): Use `cli-table3` for pretty tables.
7373- - [ ] "Machine Mode" (Pipe/`--json`): Plain text or JSON output.
8282+ - [ ] "Human Mode" (TTY): Use `cli-table3` for pretty tables.
8383+ - [ ] "Machine Mode" (Pipe/`--json`): Plain text or JSON output.
7484- [ ] Implement `--json` flag for structured output.
7585- [ ] Implement `--no-input` flag to force CLI to error on unresolved context or missing flags (Fail Fast, Fail Loud principle).
76867787## 9. Testing
8888+7889- [ ] Set up a testing framework (e.g., Jest, Vitest).
7990- [ ] Write unit tests for core modules (Auth, Context Resolver, API client).
8091- [ ] Write integration tests for CLI commands.
81928293## 10. Documentation & Deployment
9494+8395- [ ] Generate CLI help documentation (`commander` usually handles this).
8496- [ ] Consider packaging/distribution strategy (npm, standalone binary).
85978698## 11. Outstanding Issues / Future Considerations (from README)
9999+87100- [ ] Secure cross-platform AT Proto session storage (OS keychain).
88101- [ ] Git authentication management similar to GitHub CLI (SSH keys, 1Password integration).
89102- [ ] Define clear precedence order for settings resolution (local config, home folder, CLI flags).
9090-- [ ] Consider adding extensions/plugins (Out of Scope for V1, but keep in mind).103103+- [ ] Consider adding extensions/plugins (Out of Scope for V1, but keep in mind).