@first-tree-ai/context-tree 0.1.6-alpha.202608310559 → 0.1.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (45) hide show
  1. package/README.md +158 -128
  2. package/dist/cli/index.mjs +1404 -746
  3. package/package.json +7 -28
  4. package/scripts/postinstall.mjs +53 -0
  5. package/skills/context-tree-connect/SKILL.md +36 -0
  6. package/skills/context-tree-connect/agents/openai.yaml +4 -0
  7. package/skills/context-tree-create/SKILL.md +32 -0
  8. package/skills/context-tree-create/agents/openai.yaml +4 -0
  9. package/skills/context-tree-publish/SKILL.md +22 -0
  10. package/skills/context-tree-publish/agents/openai.yaml +4 -0
  11. package/skills/context-tree-read/SKILL.md +34 -37
  12. package/skills/context-tree-read/agents/openai.yaml +2 -2
  13. package/skills/context-tree-setup/SKILL.md +28 -0
  14. package/skills/context-tree-setup/agents/openai.yaml +4 -0
  15. package/skills/context-tree-write/SKILL.md +208 -125
  16. package/skills/context-tree-write/agents/openai.yaml +2 -2
  17. package/.agents/plugins/marketplace.json +0 -19
  18. package/.claude-plugin/marketplace.json +0 -21
  19. package/.claude-plugin/plugin.json +0 -16
  20. package/.codex-plugin/plugin.json +0 -36
  21. package/dist/cli/index.d.mts +0 -1
  22. package/dist/index.d.mts +0 -28
  23. package/dist/index.mjs +0 -1087
  24. package/dist/schemas-BWM6Q6iz.mjs +0 -278
  25. package/dist/schemas-C4bs-FkC.d.mts +0 -394
  26. package/dist/schemas.d.mts +0 -2
  27. package/dist/schemas.mjs +0 -2
  28. package/docs/specification.md +0 -146
  29. package/examples/basic/NODE.md +0 -15
  30. package/examples/basic/members/NODE.md +0 -8
  31. package/examples/basic/members/example-agent/NODE.md +0 -7
  32. package/examples/basic/members/example-agent/memory.md +0 -9
  33. package/examples/basic/systems/NODE.md +0 -10
  34. package/examples/basic/systems/runtime.md +0 -15
  35. package/hooks/hooks.json +0 -26
  36. package/hooks/session-start.mjs +0 -64
  37. package/policy/context-tree-policy.md +0 -158
  38. package/skills/context-tree-init/SKILL.md +0 -51
  39. package/skills/context-tree-init/agents/openai.yaml +0 -4
  40. package/skills/context-tree-init/scripts/context-tree.mjs +0 -41
  41. package/skills/context-tree-link/SKILL.md +0 -45
  42. package/skills/context-tree-link/agents/openai.yaml +0 -4
  43. package/skills/context-tree-link/scripts/context-tree.mjs +0 -41
  44. package/skills/context-tree-read/scripts/context-tree.mjs +0 -41
  45. package/skills/context-tree-write/scripts/context-tree.mjs +0 -41
package/README.md CHANGED
@@ -1,179 +1,209 @@
1
1
  # Context Tree
2
2
 
3
- `@first-tree-ai/context-tree` gives agents durable project context: decisions,
4
- constraints, and relationships stored as Markdown in a private GitHub
5
- repository. It supports Codex and Claude Code through a portable Agent Plugins
6
- v1 package and includes a CLI for shell automation.
3
+ `@first-tree-ai/context-tree` provides durable, structured project context for
4
+ coding agents. It ships a portable core, CLI, templates, and six
5
+ framework-neutral skills.
7
6
 
8
- Each project is explicitly linked to a verified local checkout. Future sessions
9
- resolve that checkout from the project's credential-free Git origin, or from its
10
- real directory when the project is not a Git repository. Context Tree currently
11
- supports repositories on GitHub.com only; GitHub Enterprise Server and other
12
- forges are not supported.
7
+ A Context Tree records current decisions, constraints, relationships, and their
8
+ rationale. Source repositories still own implementation detail, task history,
9
+ and credentials.
10
+
11
+ ## Requirements
12
+
13
+ - Node.js 22.13 or newer
14
+ - Git
15
+ - GitHub CLI (`gh`) only for connecting a GitHub tree or publishing
16
+
17
+ Git and GitHub authentication remain owned by the host tools. Repository inputs
18
+ are credential-free `OWNER/REPO` identities, never URLs containing credentials.
13
19
 
14
20
  ## Install
15
21
 
16
- Node.js 22.13 or newer and npm are required. Git is also required to initialize
17
- trees and use Git-backed workflows.
22
+ ```bash
23
+ npm install --global @first-tree-ai/context-tree
24
+ ```
25
+
26
+ That installs the `context-tree` command and copies the six skills into the
27
+ skill directory of every agent you already have:
28
+
29
+ ```text
30
+ ✓ claude → ~/.claude/skills/ (6 skills)
31
+ ✓ codex → ~/.codex/skills/ (6 skills)
32
+ ```
33
+
34
+ Restart your agent so it discovers them, then try asking:
18
35
 
19
- ### Codex or Claude Code plugin (recommended)
36
+ > Set up a Context Tree for this project, then read the relevant context.
20
37
 
21
- Install the marketplace and plugin, then start a new session so the host can
22
- discover the skills and lifecycle hook.
38
+ > Write this architectural decision to the Context Tree.
23
39
 
24
- For Codex:
40
+ Skill installation is a normal command, so you can re-run it after installing a
41
+ new agent, or scope it to one project:
25
42
 
26
43
  ```bash
27
- codex plugin marketplace add first-tree-ai/context-tree
28
- codex plugin add context-tree@context-tree
44
+ context-tree install # every agent you have
45
+ context-tree install --host codex # one agent
46
+ context-tree install --project . # ./.claude/skills and ./.codex/skills
29
47
  ```
30
48
 
31
- For Claude Code:
49
+ Installing only ever writes `context-tree-*` skill directories, never touches
50
+ skills it does not own, and never creates a configuration directory for an agent
51
+ that is not present. Adding support for another agent is one entry in the host
52
+ table in `src/core/install.ts`.
53
+
54
+ Once a project is connected, `create` and `connect` record the tree in the
55
+ project's own `AGENTS.md`, so any agent that reads instruction files knows the
56
+ tree exists without host-specific configuration.
57
+
58
+ ## Six skills
59
+
60
+ ### Setup
61
+
62
+ `context-tree-setup` orchestrates lifecycle setup for projects with no
63
+ connection. It asks whether to create a new tree or connect an existing one,
64
+ then delegates to the create or connect workflow rather than duplicating
65
+ lifecycle policy. Read and write invoke setup when the current project has no
66
+ connection. Setup never publishes without explicit confirmation.
67
+
68
+ ### Create
32
69
 
33
70
  ```bash
34
- claude plugin marketplace add first-tree-ai/context-tree
35
- claude plugin install context-tree@context-tree
71
+ context-tree create --project-path ./service
36
72
  ```
37
73
 
38
- Marketplace installation requires repository access to
39
- `first-tree-ai/context-tree`. These selectors resolve the npm `latest` package,
40
- which must contain the plugin manifests, hook, four skills and launchers, and
41
- `dist/cli/index.mjs`. Review and trust the session-start hook if your host asks.
74
+ `create` derives `<normalized-project-directory>-context-tree`, scaffolds and
75
+ commits it under `~/.context-tree/trees`, then connects it atomically. It is
76
+ idempotent only while the project remains connected to that managed tree.
42
77
 
43
- The plugin uses its own packaged CLI, so plugin users do not need a global CLI
44
- installation. Try asking:
78
+ ### Connect
45
79
 
46
- > Link this project to my Context Tree, then read the relevant context.
80
+ Connect to an existing managed tree by exact name:
47
81
 
48
- > Publish this architectural decision to the Context Tree.
82
+ ```bash
83
+ context-tree connect shared-context-tree --project-path ./service
84
+ ```
85
+
86
+ Or reuse or clone a GitHub tree by repository identity:
49
87
 
50
- ### Global CLI (optional)
88
+ ```bash
89
+ context-tree connect OWNER/REPO --project-path ./service
90
+ ```
51
91
 
52
- Install the package globally only when scripts or terminal workflows need a
53
- `context-tree` command on `PATH`:
92
+ Or connect an existing checkout in place by exact disk path:
54
93
 
55
94
  ```bash
56
- npm install --global @first-tree-ai/context-tree
57
- context-tree --help
95
+ context-tree connect --tree-path /path/to/a/tree --project-path ./service
58
96
  ```
59
97
 
60
- ## CLI workflows
98
+ `connect --tree-path` requires an exact, clean, fully valid Git root with no
99
+ symlink components. Trees without an origin connect as local state;
100
+ credential-free GitHub origins connect as GitHub state. External disk trees
101
+ are never copied, moved, or deleted.
102
+
103
+ An identical connection is idempotent. An explicit connect automatically
104
+ switches the project. GitHub checkouts use the repository's lowercase name in
105
+ the same flat managed namespace as created trees.
61
106
 
62
- ### Initialize or link a tree
107
+ `context-tree list` reports valid, clean managed trees as
108
+ `{ schemaVersion: 1, trees: [{ name, tree }] }`; a missing managed directory
109
+ is an empty list.
63
110
 
64
- Create a new tree and record a local link for the current project:
111
+ ### Read
65
112
 
66
113
  ```bash
67
- context-tree init --repository acme/context --tree-path ./context-tree
114
+ context-tree sync --project-path ./service
115
+ context-tree read product/runtime.md --tree-path /path/from/sync
68
116
  ```
69
117
 
70
- Or link a project to an existing, verified checkout:
118
+ Local trees report their checked-out branch and exact `HEAD` without network
119
+ access. GitHub trees perform one fast-forward-only pull of the checked-out
120
+ branch. Reads navigate from indexes to narrow, task-relevant children.
121
+
122
+ ### Write
71
123
 
72
124
  ```bash
73
- context-tree link --project-path ./service --tree-path ./context-tree
125
+ context-tree prepare-write --project-path ./service
126
+ # Edit only the returned worktreePath.
127
+ context-tree finish-write --project-path ./service \
128
+ --worktree-path /path/from/prepare \
129
+ --message "Record runtime constraint"
74
130
  ```
75
131
 
76
- If `init` omits `--tree-path`, it creates `./REPO`, using the repository name
77
- verbatim as the directory and tree title. Scaffolding is create-only. It runs
78
- ordinary `git init`, configures a credential-free GitHub origin, and creates a
79
- validation workflow pinned to the package version and selected initial branch.
80
- The init skill, rather than the CLI, owns the initial commit and any publication.
132
+ Preparation synchronizes first and creates a random isolated worktree at that
133
+ exact commit. Finishing validates the worktree, stages every pending change,
134
+ creates one unsigned commit using the host identity, and attempts one
135
+ fast-forward merge for local trees or one non-force push for GitHub trees.
136
+
137
+ If the destination advanced, `finish-write` returns `WRITE_OUTDATED` and
138
+ preserves the worktree. Prepare again and reapply the intended semantic change
139
+ once; there is no automatic rebase, retry loop, or pull-request fallback.
81
140
 
82
- ### Resolve, refresh, read, and verify
141
+ A preserved or abandoned write leaves its temporary worktree on disk and a
142
+ `context-tree/write/<name>` branch in the tree. The next `prepare-write` reclaims
143
+ one of these only when it holds no commit your checkout lacks, has no pending
144
+ change, and has gone untouched for twenty-four hours, so a worktree you are still
145
+ editing and a `WRITE_OUTDATED` worktree awaiting its retry are both left alone.
146
+ Those keep their pending edits until you clear them with
147
+ `git worktree remove <path>` and `git branch -D <branch>` in the connected tree.
148
+
149
+ ### Publish
83
150
 
84
151
  ```bash
85
- context-tree resolve --project-path ./service
86
- context-tree refresh --project-path ./service
87
- context-tree read --tree-path ./context-tree
88
- context-tree read product --tree-path ./context-tree
89
- context-tree verify --tree-path ./context-tree
152
+ context-tree publish --project-path ./service
153
+ # or: context-tree publish OWNER/REPO --project-path ./service
90
154
  ```
91
155
 
92
- `resolve` checks the recorded checkout, origin, cleanliness, and root
93
- `NODE.md`; it does not scan the whole semantic tree. `refresh` discovers the
94
- live default branch, requires it to match the checked-out branch, and
95
- fast-forwards before reads. Agent reads refresh and fully verify the tree, then
96
- report the exact commit SHA. If GitHub is unavailable, a stale read requires
97
- explicit authorization, is clearly labeled, and can never be used as a write
98
- base.
156
+ Publishing requires a clean, valid local tree with no `origin`. It creates one
157
+ new private GitHub repository, pushes the checkout, and then changes the stored
158
+ connection to GitHub state. Those external and local changes are not atomic;
159
+ uncertain or partial outcomes are reported as `PUBLISH_INCOMPLETE` and are not
160
+ automatically inspected or repaired.
99
161
 
100
- Directory reads return the selected `NODE.md` body and metadata plus summaries
101
- of immediate children. Leaf reads return the leaf body without children.
162
+ ## Project identity
102
163
 
103
- ### Prepare and inspect a write
164
+ Git project paths resolve to the exact root of that checkout. A clone or Git
165
+ worktree is independent even if it shares an origin or Git common directory.
166
+ Non-Git projects match only the exact connected directory; nested directories
167
+ do not inherit the connection.
104
168
 
105
- ```bash
106
- context-tree stage --project-path ./service
107
- context-tree diff ./prepared-worktree --base HEAD
169
+ Connection data is written atomically with mode `0600` at
170
+ `~/.context-tree/connections.json`. Duplicate project records are corruption.
171
+ Stored local/GitHub state is not reclassified from mutable remotes.
172
+
173
+ Every command that touches a connected tree reports why it refused:
174
+ `NO_CONNECTION` (nothing connected), `DIRTY_TREE` (your uncommitted edits —
175
+ commit or discard them), `INVALID_TREE` (structure fails `verify`),
176
+ `STALE_CONNECTION` (the stored path is gone; connect again), and
177
+ `CORRUPT_CONNECTION` (unreadable or duplicated records).
178
+
179
+ ## CLI plumbing
180
+
181
+ The public command inventory is:
182
+
183
+ ```text
184
+ install create connect list resolve sync prepare-write
185
+ finish-write publish read verify
108
186
  ```
109
187
 
110
- `stage` fetches the live default branch and creates an isolated worktree at its
111
- exact commit. After edits, `diff` reports all pending changes against the given
112
- base (`HEAD` by default). These are preparation and inspection commands: there
113
- is no CLI publish command. The write skill edits, verifies, reviews, commits,
114
- rebases when necessary, and publishes the result.
188
+ Setup, create, connect, read, write, and publish ship as six skills; setup
189
+ orchestrates the five concrete workflows. `install` is the distribution
190
+ entry point, run for you by `npm install`. `resolve`, `sync`, `prepare-write`,
191
+ `finish-write`, and `verify` are plumbing or diagnostic commands rather than
192
+ separate user intentions; `list` backs setup's connect-target discovery.
193
+ All machine-readable responses use strict schema version `1`.
194
+
195
+ `verify` is intended for CI and diagnostics. Normal skills invoke it only after
196
+ an operation reports invalid tree content.
115
197
 
116
- ### Retrieve the policy
198
+ ## Development
117
199
 
118
200
  ```bash
119
- context-tree policy
201
+ pnpm install
202
+ pnpm check
203
+ pnpm typecheck
204
+ pnpm test
205
+ pnpm check:package
120
206
  ```
121
207
 
122
- This returns the canonical policy packaged with the installed version.
123
-
124
- ## Command reference
125
-
126
- | Command | Purpose | Essential arguments and options |
127
- | --- | --- | --- |
128
- | `link` | Link a project to a verified checkout | `--project-path <path>`, `--tree-path <path>` |
129
- | `resolve` | Resolve a project's recorded link | `--project-path <path>` (default `.`) |
130
- | `refresh` | Fast-forward a linked tree to its live default branch | `--project-path <path>` (default `.`) |
131
- | `stage` | Prepare an isolated worktree for a write | `--project-path <path>` (default `.`) |
132
- | `diff` | Inspect changes in a prepared worktree | `[tree-path]` (default `.`), `--base <ref>` (default `HEAD`) |
133
- | `init` | Scaffold a new tree | `--repository <owner/repo>`, optional `--tree-path <path>` |
134
- | `policy` | Print the packaged Context Tree policy | None |
135
- | `read` | Read a node or Markdown leaf | `[path]` (default `.`), `--tree-path <path>` (default `.`) |
136
- | `verify` | Validate tree structure and safety | `--tree-path <path>` (default `.`) |
137
-
138
- Successful commands and runtime or argument failures emit one
139
- `schemaVersion: 1` JSON object on stdout. Help and version output are plain
140
- text. An invalid `verify` report is still emitted and exits with status 1. The
141
- strict Zod schemas are the source of truth for public wire contracts.
142
-
143
- Links are machine-local internal state in
144
- `~/.context-tree/connections.json`; do not edit this file manually. Managed
145
- clones default to `~/.context-tree/checkouts/OWNER/REPO`. Resolution does not
146
- search for moved checkouts, so use the link skill again to repair a stale link.
147
-
148
- ## Safety and lifecycle
149
-
150
- - **Credentials:** The core and CLI neither manage credentials nor perform
151
- authenticated GitHub operations. Repository URLs containing credentials are
152
- rejected and never logged; host Git and GitHub CLI own authentication.
153
- - **Checkout validation:** Linking requires a clean, exact Git root with a safe
154
- GitHub origin and a fully valid tree. Resolution fails closed for symlinks,
155
- moved paths, dirty trees, origin mismatches, and invalid roots. `init` has a
156
- narrow exception for its four new uncommitted scaffold files.
157
- - **Git operations:** Reads fast-forward only. Writes start from a freshly
158
- fetched default-branch commit in an isolated worktree and never force-push.
159
- Commit SHAs identify shared snapshots.
160
- - **Hooks:** Session and subagent hooks inject only a resolved tree identity and
161
- path. They are silent when no link matches and never fetch, clone, or mutate.
162
- They use only the plugin's packaged CLI and warn if it is unavailable.
163
- - **Write fallback:** The write skill retries bounded concurrent updates. If a
164
- direct push is denied or retries are exhausted, it opens a conflict-free PR
165
- from the latest default branch without merging it or requesting reviewers.
166
- Each write and commit is scoped to one concrete source.
167
-
168
- For tree structure, link replacement rules, validation boundaries, memory
169
- selection, read/write lifecycle details, and exact public contracts, see the
170
- [Context Tree format specification](docs/specification.md).
171
-
172
- ## Compatibility
173
-
174
- The package uses `.codex-plugin/plugin.json` and `.claude-plugin/plugin.json` as
175
- host adapters for installation and lifecycle integration. It intentionally
176
- omits a root `plugin.json`: Codex 0.151.0 treats that portable manifest as an
177
- alternate plugin shape and fails to discover bundled lifecycle hooks. Both
178
- marketplaces install the same npm package, and all plugin components use its
179
- private packaged CLI at the same version rather than a global `PATH` command.
208
+ See [docs/specification.md](docs/specification.md) for contracts and safety
209
+ invariants.