···2233This document details the analysis of the `tangled.org` API, based on the lexicon files found in the `tangled.org/core` repository, and assesses the feasibility of implementing the commands outlined in `TODO.md`.
4455-## 1. API Structure Overview
55+## API Structure Overview
6677The `tangled.org` API leverages the AT Protocol (ATProto), combining custom lexicons (schemas) for specific data types with generic ATProto repository operations (`com.atproto.repo.*`) for fundamental record management (create, get, list). This approach is common in ATProto-based services.
8899-## 2. Feasibility of `TODO.md` Commands
99+## Feasibility of `TODO.md` Commands
10101111All commands currently outlined in `TODO.md` appear to be implementable with the existing API structure.
12121313-### 2.1. Authentication (`tangled auth login`)
1313+### Authentication (`tangled auth login`)
14141515* **Feasible.** This will utilize the standard AT Protocol `com.atproto.server.createSession` procedure. This procedure is part of the core ATProto specification and would be handled by the `@atproto/api` library, not requiring a specific `tangled.org` lexicon.
16161717-### 2.2. Git SSH Key Management
1717+### Git SSH Key Management
18181919* **`tangled ssh-key add <public-key-path>`**:
2020 * **Feasible (using generic ATProto record creation).** The `core/lexicons/publicKey.json` defines the `sh.tangled.publicKey` record type. To add a user's global SSH public key, the CLI would use the generic ATProto `com.atproto.repo.createRecord` procedure. The `collection` parameter would be set to `sh.tangled.publicKey`, and the public key content (`key`) and a human-readable name (`name`) would be provided as the record data.
···2525 3. Comparing the DID obtained from the SSH output with the DIDs returned by `listKeys` to confirm the key's association.
2626 4. Resolving the DID to a human-readable Bluesky handle using the standard AT Protocol `com.atproto.identity.resolveHandle` procedure (part of `@atproto/api`).
27272828-### 2.3. Repository Management
2828+### Repository Management
29293030* **`tangled repo create <repo-name>`**:
3131 * **Feasible.** The `sh.tangled.repo.create` procedure (defined in `core/lexicons/repo/create.json`) directly supports this. It requires an `rkey` (repository key/name) and can optionally accept a `defaultBranch` and a `source` URL for forking/importing.
3232* **`tangled repo view [--json <fields>]`**:
3333 * **Feasible (using generic ATProto record retrieval).** The `core/lexicons/repo/repo.json` defines the `sh.tangled.repo` record type. To view details of a specific repository, the CLI would use the generic ATProto `com.atproto.repo.getRecord` procedure, specifying `collection: "sh.tangled.repo"` and the appropriate record key (`rkey`).
34343535-### 2.4. Issue Management
3535+### Issue Management
36363737* **`tangled issue create "<title>" [--body "<body>" | --body-file <file> | -F -]`**:
3838 * **Feasible (using generic ATProto record creation).** The `core/lexicons/issue/issue.json` defines the `sh.tangled.repo.issue` record type. To create a new issue, the CLI would use the generic ATProto `com.atproto.repo.createRecord` procedure. The `collection` would be `sh.tangled.repo.issue`, and the `record` data would include the `repo` (AT-URI of the repository), `title`, and `body` (if provided).
3939* **`tangled issue list [--json "id,title"]`**:
4040 * **Feasible (using generic ATProto record listing).** To list issues for a repository, the CLI would use the generic ATProto `com.atproto.repo.listRecords` procedure, specifying `collection: "sh.tangled.repo.issue"`. Client-side filtering by the `repo` field (which is an AT-URI to the parent repository) might be necessary if the API does not offer server-side filtering for this specific collection.
41414242-## 3. API Resources and Actions Missing from Current CLI Plan
4242+## API Resources and Actions Missing from Current CLI Plan
43434444The `tangled.org` API, as revealed by its lexicons, exposes numerous capabilities beyond the current scope of the `TODO.md`. These represent potential future enhancements for the CLI:
45454646-### 3.1. Pull Requests
4646+### Pull Requests
47474848A comprehensive set of lexicons (`pulls/pull.json`, `pulls/open.json`, `pulls/merged.json`, `pulls/comment.json`, `pulls/closed.json`, `pulls/state.json`) indicates a fully-fledged Pull Request system.
4949* **Potential CLI Commands:** `tangled pulls list`, `tangled pulls view <id>`, `tangled pulls create`, `tangled pulls merge`, `tangled pulls close`, `tangled pulls comment`.
50505151-### 3.2. CI/CD Pipelines
5151+### CI/CD Pipelines
52525353Lexicons such as `pipeline/pipeline.json`, `pipeline/status.json`, and `pipeline/cancelPipeline.json` suggest integration with a CI/CD system.
5454* **Potential CLI Commands:** `tangled pipeline status`, `tangled pipeline cancel <id>`.
55555656-### 3.3. Repository Secrets
5656+### Repository Secrets
57575858The `repo/addSecret.json`, `repo/listSecrets.json`, and `repo/removeSecret.json` lexicons allow for managing CI/CD secrets specific to a repository.
5959* **Potential CLI Commands:** `tangled repo secret add <key> <value>`, `tangled repo secret list`, `tangled repo secret remove <key>`.
60606161-### 3.4. Advanced Git Operations
6161+### Advanced Git Operations
62626363Several lexicons expose finer-grained Git operations directly via XRPC, potentially allowing for more integrated Git functionality beyond simple cloning/pushing:
6464* `repo/log.json` (view commit history)
···6969* `git/refUpdate.json` (update Git references)
7070* **Potential CLI Commands:** `tangled repo log`, `tangled repo diff`, `tangled branch list`, etc.
71717272-### 3.5. Social & Feed Interactions
7272+### Social & Feed Interactions
73737474Lexicons like `graph/follow.json`, `feed/star.json`, and `feed/reaction.json` suggest social networking features common in ATProto applications.
7575* **Potential CLI Commands:** `tangled follow <did>`, `tangled star <uri>`, `tangled react <uri>`.
76767777-### 3.6. Labels
7777+### Labels
78787979The `label/definition.json` and `label/op.json` lexicons provide mechanisms for defining and applying labels to various resources (e.g., issues, pull requests).
8080* **Potential CLI Commands:** `tangled label add`, `tangled label list`.
81818282-### 3.7. Repository Collaboration
8282+### Repository Collaboration
83838484The `repo/collaborator.json` lexicon suggests managing collaborators on a repository.
8585* **Potential CLI Commands:** `tangled repo collaborator add`, `tangled repo collaborator list`.
86868787-### 3.8. Forking and Syncing
8787+### Forking and Syncing
88888989`repo/forkSync.json` and `repo/forkStatus.json` point to specific API support for managing repository forks and their synchronization status.
9090* **Potential CLI Commands:** `tangled repo fork`, `tangled repo fork-sync`.
91919292-## 4. Conclusion
9292+## Conclusion
93939494The `tangled.org` API provides a solid foundation for building the planned CLI. All current `TODO.md` items are implementable, primarily by leveraging the `@atproto/api` library's generic record operations in conjunction with `tangled.org`'s custom record definitions and specific procedures. The API also offers a rich set of additional functionalities that can significantly extend the CLI's capabilities in future iterations, particularly around pull requests, CI/CD, and advanced Git management.
+15-15
README.md
···11# Tangled CLI: Architecture & Implementation Plan
2233-## 1. Project Overview
33+## Project Overview
4455**Goal:** Create a context-aware CLI for tangled.org that bridges the gap between the AT Protocol (XRPC) and standard Git. **Philosophy:** Follow the **GitHub CLI (gh)** standard: act as a wrapper that creates a seamless experience where the API and local Git repo feel like one unified tool.
6677-## 2. Prior Art Analysis: GitHub CLI (gh) vs. Tangled CLI
77+## Prior Art Analysis: GitHub CLI (gh) vs. Tangled CLI
8899| Feature | GitHub CLI (gh) Approach | Tangled CLI Strategy |
1010| :------------- | :--------------------------------------------------- | :------------------------------------------------------------------------------------------------------------------------- |
···1414| **Filtering** | \--json name,url (filters fields). | **Plan:** Support basic \--json flag first. Add field filtering (--json "cloneUrl,did") to save LLM context window tokens. |
1515| **Extensions** | Allows custom subcommands. | _Out of Scope for V1._ |
16161717-## 3. High-Level Architecture (Refined)
1717+## High-Level Architecture (Refined)
18181919The CLI acts as a "Context Engine" before it even hits the API.
2020`graph TD`
···3333 `API --> Output`
3434 `Shell --> Output`
35353636-## 4. Tech Stack (TypeScript)
3636+## Tech Stack (TypeScript)
37373838| Component | Library | Purpose |
3939| :---------------- | :-------------------- | :------------------------------------------------------------ |
···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)
4949+## Agent Integration (The "LLM Friendly" Layer)
50505151To make this tool accessible to Claude Code/Gemini, we adopt gh's best patterns:
5252···8383- **Git Config Integration:** Treats the local .git folder as a database of configuration, reducing the need for environment variables or complex flags.
8484- **Flexible Issue Body Input:** Improves usability for both humans and LLMs by allowing diverse input methods for issue descriptions.
85858686-## 6. Examples Tangled CLI Usage
8686+## Examples Tangled CLI Usage
87878888```bash
8989tangled auth login (opens a browser for auth)
···9797tangled pr comment 123 --body "Looks good, small change needed."
9898```
9999100100-## 7. Basic Commands
100100+## Basic Commands
101101102102Basic commands include auth, key management, repo creation, issue management, and pull request management.
103103···127127 `tangled pr review <id> --comment <comment> [--approve | --request-changes]`
128128- Submits a review for a pull request, with optional approval or request for changes.
129129130130-## 8. Design Decisions & Outstanding Issues
130130+## Design Decisions & Outstanding Issues
131131132132This section documents key design decisions and tracks outstanding architectural questions.
133133134134-### 1. (Resolved) SSH Key Management (`gh` Compatibility)
134134+### (Resolved) SSH Key Management (`gh` Compatibility)
135135136136- **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.
139139140140-### 2. (Decided) Secure Session Storage
140140+### (Decided) Secure Session Storage
141141142142- **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.
145145146146-### 3. (Decided) Configuration Resolution Order
146146+### (Decided) Configuration Resolution Order
147147148148- **Original Question:** How should settings be resolved from different sources?
149149- **Resolution:** A clear precedence order is necessary.
···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`)
155155156156-### 4. (Decided for V1) Authentication Flow: App Passwords (PDS)
156156+### (Decided for V1) Authentication Flow: App Passwords (PDS)
157157158158- **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.
···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.
164164165165-## 9. Future Expansion Opportunities
165165+## Future Expansion Opportunities
166166167167The 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:
168168···174174- **Collaboration:** Commands to manage repository collaborators.
175175- **Fork Management:** Commands for forking repositories and managing the sync status of forks.
176176177177-## 10. Task Management
177177+## Task Management
178178179179We'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.
180180181181-## 11. Development
181181+## Development
182182183183### Prerequisites
184184
+11-11
TODO.md
···2233This 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)
55+## Project Setup & Core Structure (Commander.js)
6677- [x] Initialize Node.js project.
88- [x] Install `commander` for CLI routing.
···1111- [x] Configure linting and formatting (Biome).
1212- [x] Configure vitest for testing.
13131414-## 2. Authentication (Auth)
1414+## Authentication (Auth)
15151616- [ ] Implement `tangled auth login` command.
1717 - [ ] Collect user's PDS handle and app password.
···1919 - [ ] Integrate `@atproto/api` for XRPC client and session management.
2020- [ ] Implement `tangled auth logout` command.
21212222-## 3. Git SSH Key Management
2222+## Git SSH Key Management
23232424- [ ] Implement `tangled ssh-key add <public-key-path>` command.
2525 - [ ] 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.
···2828 - [ ] 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.
2929- [ ] Ensure all Git operations leverage SSH keys for authentication, as `tangled.org` exclusively supports SSH for Git.
30303131-## 4. Context Engine (Git Integration)
3131+## Context Engine (Git Integration)
32323333- [ ] Integrate `git-url-parse` to resolve Tangled DID/NSID from `.git/config` remote URLs.
3434- [ ] Develop a "Context Resolver" module to infer repository context (DID) from the current working directory.
···3737- [ ] Implement logic to parse the DID from `ssh -T git@tangled.org` output (will be reused by `tangled ssh-key verify`).
3838- [ ] 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`).
39394040-## 5. Repository Management
4040+## Repository Management
41414242- [ ] Implement `tangled repo create <repo-name>` command.
4343- [ ] Implement `tangled repo view` command (display repo details).
4444 - [ ] Support `--json` output with field filtering (e.g., `--json name,cloneUrl,description`) using `lodash/pick`).
45454646-## 6. Issue Management
4646+## Issue Management
47474848- [ ] Implement `tangled issue create "<title>" [--body "<body>" | --body-file <file> | -F -]` command.
4949- [ ] Implement `tangled issue list [--json "id,title"]` command.
5050 - [ ] Support `--json` output with field filtering.
51515252-## 7. Pull Request Management
5252+## Pull Request Management
53535454This section outlines the phased implementation for Pull Request (PR) support, following `gh` CLI patterns.
5555···77777878- [ ] 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.
79798080-## 8. Output & LLM Integration
8080+## Output & LLM Integration
81818282- [ ] Implement output formatting based on `is-interactive` check.
8383 - [ ] "Human Mode" (TTY): Use `cli-table3` for pretty tables.
···8585- [ ] Implement `--json` flag for structured output.
8686- [ ] Implement `--no-input` flag to force CLI to error on unresolved context or missing flags (Fail Fast, Fail Loud principle).
87878888-## 9. Testing
8888+## Testing
89899090- [ ] Set up a testing framework (e.g., Jest, Vitest).
9191- [ ] Write unit tests for core modules (Auth, Context Resolver, API client).
9292- [ ] Write integration tests for CLI commands.
93939494-## 10. Documentation & Deployment
9494+## Documentation & Deployment
95959696- [ ] Generate CLI help documentation (`commander` usually handles this).
9797- [ ] Consider packaging/distribution strategy (npm, standalone binary).
98989999-## 11. Outstanding Issues / Future Considerations (from README)
9999+## Outstanding Issues / Future Considerations (from README)
100100101101- [ ] Secure cross-platform AT Proto session storage (OS keychain).
102102- [ ] Git authentication management similar to GitHub CLI (SSH keys, 1Password integration).