first-tree 0.0.2 → 0.0.4

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 (80) hide show
  1. package/README.md +116 -40
  2. package/dist/cli.js +46 -17
  3. package/dist/help-Dtdj91HJ.js +25 -0
  4. package/dist/init--VepFe6N.js +403 -0
  5. package/dist/installer-cH7N4RNj.js +47 -0
  6. package/dist/onboarding-C9cYSE6F.js +2 -0
  7. package/dist/onboarding-CPP8fF4D.js +10 -0
  8. package/dist/repo-DY57bMqr.js +318 -0
  9. package/dist/upgrade-Cgx_K2HM.js +135 -0
  10. package/dist/{verify-CSRIkuoM.js → verify-mC9ZTd1f.js} +118 -29
  11. package/package.json +33 -10
  12. package/skills/first-tree/SKILL.md +113 -0
  13. package/skills/first-tree/agents/openai.yaml +4 -0
  14. package/skills/first-tree/assets/framework/VERSION +1 -0
  15. package/skills/first-tree/assets/framework/examples/claude-code/README.md +14 -0
  16. package/skills/first-tree/assets/framework/examples/claude-code/settings.json +14 -0
  17. package/skills/first-tree/assets/framework/helpers/generate-codeowners.ts +224 -0
  18. package/skills/first-tree/assets/framework/helpers/inject-tree-context.sh +15 -0
  19. package/skills/first-tree/assets/framework/helpers/run-review.ts +193 -0
  20. package/skills/first-tree/assets/framework/manifest.json +11 -0
  21. package/skills/first-tree/assets/framework/prompts/pr-review.md +38 -0
  22. package/skills/first-tree/assets/framework/templates/agents.md.template +49 -0
  23. package/skills/first-tree/assets/framework/templates/member-node.md.template +18 -0
  24. package/skills/first-tree/assets/framework/templates/members-domain.md.template +45 -0
  25. package/skills/first-tree/assets/framework/templates/root-node.md.template +41 -0
  26. package/skills/first-tree/assets/framework/workflows/codeowners.yml +31 -0
  27. package/skills/first-tree/assets/framework/workflows/pr-review.yml +146 -0
  28. package/skills/first-tree/assets/framework/workflows/validate.yml +19 -0
  29. package/skills/first-tree/engine/commands/help.ts +32 -0
  30. package/skills/first-tree/engine/commands/init.ts +1 -0
  31. package/skills/first-tree/engine/commands/upgrade.ts +1 -0
  32. package/skills/first-tree/engine/commands/verify.ts +1 -0
  33. package/skills/first-tree/engine/init.ts +414 -0
  34. package/skills/first-tree/engine/onboarding.ts +10 -0
  35. package/skills/first-tree/engine/repo.ts +360 -0
  36. package/skills/first-tree/engine/rules/agent-instructions.ts +59 -0
  37. package/skills/first-tree/engine/rules/agent-integration.ts +19 -0
  38. package/skills/first-tree/engine/rules/ci-validation.ts +72 -0
  39. package/skills/first-tree/engine/rules/framework.ts +13 -0
  40. package/skills/first-tree/engine/rules/index.ts +41 -0
  41. package/skills/first-tree/engine/rules/members.ts +21 -0
  42. package/skills/first-tree/engine/rules/populate-tree.ts +36 -0
  43. package/skills/first-tree/engine/rules/root-node.ts +41 -0
  44. package/skills/first-tree/engine/runtime/adapters.ts +22 -0
  45. package/skills/first-tree/engine/runtime/asset-loader.ts +141 -0
  46. package/skills/first-tree/engine/runtime/installer.ts +82 -0
  47. package/skills/first-tree/engine/runtime/upgrader.ts +23 -0
  48. package/skills/first-tree/engine/upgrade.ts +233 -0
  49. package/skills/first-tree/engine/validators/members.ts +215 -0
  50. package/skills/first-tree/engine/validators/nodes.ts +559 -0
  51. package/skills/first-tree/engine/verify.ts +155 -0
  52. package/skills/first-tree/references/about.md +36 -0
  53. package/skills/first-tree/references/maintainer-architecture.md +59 -0
  54. package/skills/first-tree/references/maintainer-build-and-distribution.md +59 -0
  55. package/skills/first-tree/references/maintainer-testing.md +58 -0
  56. package/skills/first-tree/references/maintainer-thin-cli.md +38 -0
  57. package/skills/first-tree/references/onboarding.md +185 -0
  58. package/skills/first-tree/references/ownership-and-naming.md +94 -0
  59. package/skills/first-tree/references/principles.md +113 -0
  60. package/skills/first-tree/references/source-map.md +94 -0
  61. package/skills/first-tree/references/upgrade-contract.md +94 -0
  62. package/skills/first-tree/scripts/check-skill-sync.sh +133 -0
  63. package/skills/first-tree/scripts/quick_validate.py +95 -0
  64. package/skills/first-tree/scripts/run-local-cli.sh +35 -0
  65. package/skills/first-tree/tests/asset-loader.test.ts +75 -0
  66. package/skills/first-tree/tests/generate-codeowners.test.ts +94 -0
  67. package/skills/first-tree/tests/helpers.ts +169 -0
  68. package/skills/first-tree/tests/init.test.ts +250 -0
  69. package/skills/first-tree/tests/repo.test.ts +440 -0
  70. package/skills/first-tree/tests/rules.test.ts +413 -0
  71. package/skills/first-tree/tests/run-review.test.ts +155 -0
  72. package/skills/first-tree/tests/skill-artifacts.test.ts +311 -0
  73. package/skills/first-tree/tests/thin-cli.test.ts +104 -0
  74. package/skills/first-tree/tests/upgrade.test.ts +103 -0
  75. package/skills/first-tree/tests/validate-members.test.ts +224 -0
  76. package/skills/first-tree/tests/validate-nodes.test.ts +198 -0
  77. package/skills/first-tree/tests/verify.test.ts +241 -0
  78. package/dist/init-CE_944sb.js +0 -283
  79. package/dist/repo-BByc3VvM.js +0 -111
  80. package/dist/upgrade-Chr7z0CY.js +0 -82
@@ -0,0 +1,36 @@
1
+ ---
2
+ title: "About Context Tree"
3
+ owners: []
4
+ ---
5
+
6
+ # About Context Tree
7
+
8
+ **context-tree.ai** — The living source of truth for your organization.
9
+
10
+ ---
11
+
12
+ ## The Problem
13
+
14
+ Organizations generate decisions constantly — in PRs, meetings, Slack threads, documents. But none of these systems stay current. PRs get merged, issues get closed, documents decay. The knowledge that produced them scatters and disappears.
15
+
16
+ When an agent — or a new teammate — needs to understand *why* something was built a certain way, there's nowhere to look. The information existed once, but no system kept it alive.
17
+
18
+ ---
19
+
20
+ ## The Idea
21
+
22
+ Context Tree is the **living source of truth** for an organization — a tree-structured knowledge base that agents and humans build and maintain together.
23
+
24
+ Every node represents a domain, decision, or design. Every node has an **owner**. When a decision is made, it is written to the tree. When things change, the tree updates. The tree is never a snapshot — it's the current state.
25
+
26
+ The result is an organization where:
27
+
28
+ - Every agent and every human reads from the same, always-current source
29
+ - Decisions are traceable — the *what*, the *why*, and who owns it
30
+ - Knowledge compounds over time instead of evaporating
31
+
32
+ ---
33
+
34
+ ## Who It's For
35
+
36
+ Agent-centric teams — founders, engineers, and product builders who work alongside AI agents every day and want their organizational knowledge to grow with them, not against them.
@@ -0,0 +1,59 @@
1
+ # Maintainer Architecture
2
+
3
+ This reference explains how to maintain the `first-tree` source repo itself.
4
+
5
+ ## What This Repo Ships
6
+
7
+ - One canonical skill: `skills/first-tree/`
8
+ - One thin CLI package: the `context-tree` command distributed by the `first-tree`
9
+ npm package
10
+ - The published package carries that canonical skill directly; normal install
11
+ and upgrade flows should not depend on cloning this source repo
12
+
13
+ This repo is not a user context tree. User decision content lives in the repos
14
+ that install the framework.
15
+
16
+ ## Canonical Layers
17
+
18
+ 1. `SKILL.md` defines when to use the skill and the maintainer workflow.
19
+ 2. `references/` stores the knowledge an agent needs to maintain the framework
20
+ and the thin CLI without reading repo-local prose.
21
+ 3. `assets/framework/` stores the runtime payload that gets installed into user
22
+ repos.
23
+ 4. `engine/` stores the canonical framework and CLI behavior.
24
+ 5. `tests/` store the canonical skill validation surface.
25
+ 6. The root repo may also keep maintainer-only developer tooling such as
26
+ `evals/` when that tooling should not ship with the skill.
27
+ 7. The root CLI/package files are implementation shell code. They should call
28
+ into the skill-owned engine and validation surface, not become a second
29
+ source of framework knowledge.
30
+
31
+ ## Non-Negotiables
32
+
33
+ - Treat `skills/first-tree/` as the only canonical source.
34
+ - If a maintainer needs information to safely change behavior, move that
35
+ information into `references/`; do not leave it only in root `README.md`,
36
+ `AGENTS.md`, CI comments, or PR descriptions.
37
+ - Keep runtime assets generic. They are copied into every user tree.
38
+ - Keep the CLI thin. Command semantics, upgrade rules, layout contracts, and
39
+ maintainer guidance should belong to the skill.
40
+ - Keep the user tree decision-focused. Execution detail stays in source systems.
41
+
42
+ ## Change Discipline
43
+
44
+ - Path or layout changes: update `references/upgrade-contract.md`, task text,
45
+ validators, and tests together.
46
+ - Shipped payload changes: update `assets/framework/`, the maintainer references
47
+ that describe the contract, and the validation surface together.
48
+ - Thin shell changes: update the relevant maintainer reference before or during
49
+ the code change so the skill remains self-sufficient.
50
+
51
+ ## End-State Target
52
+
53
+ - skill owns knowledge, runtime payload, framework engine, and the canonical
54
+ framework test surface
55
+ - root owns only the light CLI/bootstrap/build shell plus maintainer-only
56
+ developer tooling such as `evals/`
57
+
58
+ When deciding where a new file should live, bias toward the skill unless the
59
+ file is purely package-tooling shell code.
@@ -0,0 +1,59 @@
1
+ # Build And Distribution
2
+
3
+ Use this reference when touching package wiring, release behavior, or the
4
+ distributable contract of `first-tree`.
5
+
6
+ ## Fast Validation
7
+
8
+ Run these commands from the repo root:
9
+
10
+ ```bash
11
+ pnpm validate:skill
12
+ pnpm typecheck
13
+ pnpm test
14
+ pnpm build
15
+ ```
16
+
17
+ ## Packaging Checks
18
+
19
+ When changing package contents, build wiring, or install/upgrade behavior, also
20
+ run:
21
+
22
+ ```bash
23
+ pnpm pack
24
+ ```
25
+
26
+ Inspect the tarball contents before merging packaging changes. The distribution
27
+ must be able to carry the canonical skill and the thin CLI shell without
28
+ requiring repo-local prose.
29
+
30
+ ## Build Responsibilities
31
+
32
+ - `package.json` defines package metadata, scripts, and import aliases.
33
+ - `tsconfig.json` defines TypeScript compile boundaries.
34
+ - `tsdown.config.ts` defines the build entry and asset loaders.
35
+ - `vitest.config.ts` defines unit-test entrypoints, and
36
+ `vitest.eval.config.ts` defines the repo-only maintainer eval entrypoint.
37
+ - `.github/workflows/ci.yml` is the thin CI shell for repo validation.
38
+
39
+ These files are shell surfaces. Their meaning must be documented here or in
40
+ another skill reference, not only in the files themselves.
41
+
42
+ ## Distribution Rules
43
+
44
+ - Do not introduce a second copy of the framework outside the skill.
45
+ - `package.json` must ship `skills/first-tree/` in the published
46
+ package alongside the thin CLI build output.
47
+ - Keep repo-only developer tooling such as root `evals/` out of the published
48
+ package unless it becomes part of the user-facing framework contract.
49
+ - If the CLI needs bundled knowledge or payload files, ship the canonical skill
50
+ with the package rather than copying that information into root docs.
51
+ - Normal `context-tree init` / `context-tree upgrade` flows must install from
52
+ the skill bundled in the running package, not by cloning the source repo.
53
+ - Default dedicated-tree-repo creation must stay local-only. It may create a
54
+ sibling git repo on disk, but it must not require remote repo creation or
55
+ source-repo cloning.
56
+ - If you change anything that gets copied into user repos, bump
57
+ `assets/framework/VERSION` and keep the upgrade task text in sync.
58
+ - If packaging changes alter what gets installed into user repos, update
59
+ `references/upgrade-contract.md`, tests, and validation commands together.
@@ -0,0 +1,58 @@
1
+ # Testing
2
+
3
+ Use this reference when validating framework behavior or changing the testing
4
+ surface.
5
+
6
+ ## Core Checks
7
+
8
+ ```bash
9
+ pnpm validate:skill
10
+ pnpm typecheck
11
+ pnpm test
12
+ pnpm build
13
+ ```
14
+
15
+ ### What Each Check Covers
16
+
17
+ - `pnpm validate:skill` verifies the canonical skill structure and sync rules.
18
+ - `pnpm typecheck` catches TypeScript boundary and import issues.
19
+ - `pnpm test` runs unit tests plus repo-local helper tests that support
20
+ maintainer tooling.
21
+ - `pnpm build` checks the thin CLI bundle.
22
+
23
+ ## Targeted Unit Tests
24
+
25
+ Examples:
26
+
27
+ ```bash
28
+ pnpm test -- skills/first-tree/tests/rules.test.ts
29
+ pnpm test -- skills/first-tree/tests/verify.test.ts
30
+ pnpm test -- skills/first-tree/tests/skill-artifacts.test.ts
31
+ pnpm test -- skills/first-tree/tests/thin-cli.test.ts
32
+ ```
33
+
34
+ If a future refactor changes these paths again, keep the command semantics and
35
+ coverage expectations documented here.
36
+
37
+ ## Packaging Check
38
+
39
+ ```bash
40
+ pnpm pack
41
+ ```
42
+
43
+ Inspect the tarball when package contents or install/upgrade behavior changes.
44
+ The published package should include the thin CLI shell and canonical skill, but
45
+ not repo-only developer tooling such as root `evals/`.
46
+
47
+ ## Repo-Only Evals
48
+
49
+ The end-to-end eval harness is intentionally not part of the distributed skill.
50
+ It lives under root `evals/` for `first-tree` maintainers working in this
51
+ source repo. Use `evals/README.md` when you need to run or update it.
52
+
53
+ ## Change Discipline
54
+
55
+ - Update this reference whenever core test entrypoints or packaging boundaries
56
+ change.
57
+ - If a maintainer would need oral history to know which checks matter, that
58
+ knowledge belongs here.
@@ -0,0 +1,38 @@
1
+ # Thin CLI Shell
2
+
3
+ Use this reference when changing the root CLI/package shell.
4
+
5
+ ## Shell Responsibilities
6
+
7
+ The root shell should do only a few things:
8
+
9
+ - parse commands and flags
10
+ - expose version/help
11
+ - load canonical framework behavior
12
+ - build, validate, and package the distributable
13
+
14
+ If a change requires non-trivial framework knowledge, put that knowledge in the
15
+ skill and have the shell call it.
16
+
17
+ ## Shell Surface
18
+
19
+ These root files are shell code, not canonical knowledge stores:
20
+
21
+ - `src/cli.ts`
22
+ - `src/md.d.ts`
23
+ - `package.json`
24
+ - `tsconfig.json`
25
+ - `tsdown.config.ts`
26
+ - `vitest.config.ts`
27
+ - `vitest.eval.config.ts` (repo-only maintainer eval entrypoint)
28
+ - `.github/workflows/ci.yml`
29
+ - root `README.md` and `AGENTS.md`
30
+
31
+ ## Rules For Shell Changes
32
+
33
+ - Keep root prose short. It should point to the skill, not duplicate the skill.
34
+ - Keep command semantics, install layout rules, and maintainer guidance in the
35
+ skill references.
36
+ - If the shell gains behavior that is not obviously mechanical, move that
37
+ behavior or its contract into the skill.
38
+ - When in doubt, prefer adding a skill reference over expanding root docs.
@@ -0,0 +1,185 @@
1
+ # Context Tree Onboarding
2
+
3
+ You are setting up a **Context Tree** — the living source of truth for an organization. This document tells you what it is and how to bootstrap one.
4
+
5
+ ---
6
+
7
+ ## What Is a Context Tree
8
+
9
+ A Context Tree is a Git repository where every directory is a **domain** and every file is a **node**. Each node captures decisions, designs, and cross-domain relationships — the knowledge that would otherwise scatter across PRs, documents, and people's heads.
10
+
11
+ Key properties:
12
+
13
+ - **Nodes are markdown files.** Each directory has a `NODE.md` that describes the domain. Leaf `.md` files capture specific decisions or designs.
14
+ - **Every node has an owner.** Declared in YAML frontmatter. Owners approve changes to their nodes.
15
+ - **Organized by concern, not by repo or team.** An agent working on "add SSO" finds all auth context in one place — not split across 4 repos.
16
+ - **The tree is never a snapshot — it's the current state.** When decisions change, the tree updates. Stale nodes are bugs.
17
+
18
+ ### Frontmatter Format
19
+
20
+ Every node has frontmatter:
21
+
22
+ ```yaml
23
+ ---
24
+ title: "Auth Architecture"
25
+ owners: [alice, bob]
26
+ soft_links: [/infrastructure/deployments]
27
+ ---
28
+ ```
29
+
30
+ - `owners` — who can approve changes. `owners: []` inherits from parent. `owners: [*]` means anyone.
31
+ - `soft_links` — cross-references to related nodes in other domains.
32
+
33
+ ### What Belongs in the Tree
34
+
35
+ Information an agent needs to **decide** on an approach — not to execute it.
36
+
37
+ **Yes:** "Auth spans 4 repos: backend issues JWTs, frontend uses Better Auth, extension uses OAuth popup, desktop uses localhost callback."
38
+
39
+ **No:** The function signature of `auth_service.verify()` — that's in the code.
40
+
41
+ ---
42
+
43
+ ## Four Principles
44
+
45
+ 1. **Source of truth for decisions, not execution.** The tree captures the *what* and *why*. Execution details stay in source systems.
46
+ 2. **Agents are first-class participants.** The tree is designed for agents to navigate and update.
47
+ 3. **Transparency by default.** Reading is open to all. Writing requires owner approval.
48
+ 4. **Git-native.** Nodes are files, domains are directories. History, ownership, and review follow Git conventions.
49
+
50
+ ---
51
+
52
+ ## How to Set Up a Context Tree
53
+
54
+ ### Prerequisites
55
+
56
+ - A source/workspace Git repository, or an already-created dedicated tree repo
57
+ - Node.js 18+
58
+ - The npm package is `first-tree`, the installed CLI command is
59
+ `context-tree`, and the installed skill directory in the tree is
60
+ `skills/first-tree/`
61
+ - Use `npx first-tree init` for one-off runs, or `npm install -g first-tree`
62
+ to add the `context-tree` command to your PATH
63
+
64
+ ### Step 1: Initialize
65
+
66
+ Recommended workflow: run `context-tree init` from your source or workspace repo.
67
+ The CLI will create a sibling dedicated tree repo named `<repo>-context` by
68
+ default and install the framework there.
69
+
70
+ ```bash
71
+ cd my-org
72
+ context-tree init
73
+ cd ../my-org-context
74
+ ```
75
+
76
+ If you already created a dedicated tree repo manually, initialize it in place:
77
+
78
+ ```bash
79
+ mkdir my-org-context && cd my-org-context
80
+ git init
81
+ context-tree init --here
82
+ ```
83
+
84
+ Either way, the framework installs into `skills/first-tree/`, renders
85
+ scaffolding (`NODE.md`, `AGENTS.md`, `members/NODE.md`), and generates a task
86
+ list in `skills/first-tree/progress.md`.
87
+
88
+ Publishing tip: keep the tree repo in the same GitHub organization as the
89
+ source repo unless you have a reason not to.
90
+
91
+ ### Step 2: Work Through the Task List
92
+
93
+ Read `skills/first-tree/progress.md`. It contains a checklist tailored to the current state of the repo. Complete each task:
94
+
95
+ - Fill in `NODE.md` with your organization name, owners, and domains
96
+ - Add project-specific instructions to `AGENTS.md` below the framework markers
97
+ - Create member nodes under `members/`
98
+ - Optionally configure agent integration (e.g., Claude Code session hooks)
99
+ - Copy validation workflows from `skills/first-tree/assets/framework/workflows/` to `.github/workflows/`
100
+
101
+ As you complete each task, check it off in `skills/first-tree/progress.md` by changing `- [ ]` to `- [x]`.
102
+
103
+ ### Step 3: Verify
104
+
105
+ ```bash
106
+ context-tree verify
107
+ ```
108
+
109
+ Or, from your source/workspace repo:
110
+
111
+ ```bash
112
+ context-tree verify --tree-path ../my-org-context
113
+ ```
114
+
115
+ This fails if any items in `skills/first-tree/progress.md` remain unchecked, and runs deterministic checks (valid frontmatter, node structure, member nodes exist).
116
+
117
+ ### Step 4: Design Your Domains
118
+
119
+ Create top-level directories for your organization's primary concerns. Each needs a `NODE.md`:
120
+
121
+ ```
122
+ my-org-tree/
123
+ NODE.md # root — lists all domains
124
+ engineering/
125
+ NODE.md # decisions about architecture, infra, tooling
126
+ product/
127
+ NODE.md # strategy, roadmap, user research
128
+ marketing/
129
+ NODE.md # positioning, campaigns
130
+ members/
131
+ NODE.md # team members and agents
132
+ alice/
133
+ NODE.md # individual member node
134
+ ```
135
+
136
+ ### Step 5: Populate from Existing Work
137
+
138
+ For each domain, extract knowledge from existing repos, docs, and systems:
139
+
140
+ - Decisions and their rationale
141
+ - Cross-domain relationships and dependencies
142
+ - Constraints that aren't obvious from the code
143
+
144
+ The tree doesn't duplicate source code — it captures what connects things and why they were built that way.
145
+
146
+ ---
147
+
148
+ ## CLI Reference
149
+
150
+ | Command | Description |
151
+ |---------|-------------|
152
+ | `context-tree init` | Create or refresh a dedicated tree repo. By default, running in a source/workspace repo creates a sibling `<repo>-context`; use `--here` to initialize the current repo in place. |
153
+ | `context-tree verify` | Check the installed progress file for unchecked items + run deterministic validation. Use `--tree-path` when invoking from another working directory. |
154
+ | `context-tree upgrade` | Refresh the installed framework skill from the currently running `first-tree` npm package and generate follow-up tasks. Use `--tree-path` when invoking from another working directory. |
155
+ | `context-tree help onboarding` | Print this onboarding guide. |
156
+
157
+ ---
158
+
159
+ ## Upgrading the Framework
160
+
161
+ When the framework updates:
162
+
163
+ ```bash
164
+ context-tree upgrade
165
+ ```
166
+
167
+ `context-tree upgrade` refreshes `skills/first-tree/` from the
168
+ skill bundled with the currently running `first-tree` npm package, preserves your
169
+ tree content, and generates follow-up tasks in
170
+ `skills/first-tree/progress.md`.
171
+
172
+ If your repo still uses the older `skills/first-tree-cli-framework/` path,
173
+ `context-tree upgrade` will migrate it to `skills/first-tree/` first.
174
+
175
+ To pick up a newer framework release, first run a newer package version, for
176
+ example `npx first-tree@latest upgrade`, or update your global `first-tree`
177
+ install before running `context-tree upgrade`.
178
+
179
+ ---
180
+
181
+ ## Further Reading
182
+
183
+ - `skills/first-tree/references/principles.md` — Core principles with detailed examples
184
+ - `skills/first-tree/references/ownership-and-naming.md` — How nodes are named and owned
185
+ - `AGENTS.md` in your tree — The before/during/after workflow for every task
@@ -0,0 +1,94 @@
1
+ ---
2
+ title: "Node Naming and Ownership Model"
3
+ owners: []
4
+ ---
5
+
6
+ # Node Naming and Ownership Model
7
+
8
+ ## Summary
9
+
10
+ This proposal defines how nodes are structured, named, and owned in a Context Tree repository.
11
+
12
+ ## NODE.md as the Parent Node
13
+
14
+ Every folder in the tree **must** contain a `NODE.md` file. This file serves two purposes:
15
+
16
+ 1. **Description** — it is the human- and agent-readable explanation of the domain that folder represents.
17
+ 2. **Ownership** — its frontmatter declares who owns all content within the folder.
18
+
19
+ Example:
20
+
21
+ ```yaml
22
+ # backend/NODE.md
23
+ ---
24
+ title: Backend Architecture
25
+ owners: [alice, bob]
26
+ soft_links: [/infrastructure/deployments]
27
+ ---
28
+
29
+ This subtree covers the backend service architecture, including API design,
30
+ data access patterns, and service-to-service communication.
31
+ ```
32
+
33
+ ## Ownership Rules
34
+
35
+ 1. **NODE.md is the folder-level authority.** Its owners can approve changes to any file within the folder.
36
+
37
+ 2. **Leaf files can declare their own owners.** These owners can approve changes to that specific file. This is additive — `NODE.md` owners retain full authority over all files in the folder.
38
+
39
+ 3. **Multiple owners are allowed.** On both `NODE.md` and leaf files.
40
+
41
+ 4. **Inheritance with override.** Every node must declare an `owners` field. To inherit from the nearest parent `NODE.md` that declares owners, use `owners: []`. Omitting `owners` entirely is not permitted. When a `NODE.md` explicitly declares owners, it fully overrides the parent — the parent folder's owners have no implicit authority over child folders.
42
+
43
+ 5. **Every folder requires a NODE.md.** Creating a subfolder means someone must think about ownership — either declare owners explicitly or inherit from the parent.
44
+
45
+ 6. **Wildcard owner.** `owners: [*]` means anyone can approve changes to that file or folder. When a NODE.md declares `owners: [*]`, anyone can add or edit leaf nodes in that folder without approval. The parent NODE.md owners still retain authority (per rule 1). Use this for open-contribution areas like tips, FAQs, proposals, or community-editable content.
46
+
47
+ ## Example
48
+
49
+ ```
50
+ /backend/
51
+ NODE.md <- owners: [alice]
52
+ auth.md <- owners: [carol]
53
+ storage.md <- owners: [] (inherits from NODE.md)
54
+ tips.md <- owners: [*]
55
+
56
+ /proposals/
57
+ NODE.md <- owners: [*]
58
+ new-feature.md <- owners: [] (inherits from NODE.md)
59
+ ```
60
+
61
+ - **backend/auth.md** — both Alice and Carol can approve changes
62
+ - **backend/storage.md** — only Alice can approve changes (owners: [] inherits from NODE.md)
63
+ - **backend/tips.md** — anyone can approve changes; Alice also retains authority (governed by NODE.md)
64
+ - **backend/NODE.md** — only Alice can approve changes
65
+ - **proposals/new-feature.md** — anyone can approve changes (owners: [] inherits wildcard from NODE.md)
66
+ - **proposals/NODE.md** — anyone can approve changes; parent NODE.md owners still retain authority
67
+
68
+ ## Leaf Files
69
+
70
+ Any `.md` file in a folder other than `NODE.md` is a leaf node. Leaf nodes:
71
+
72
+ - Contain content with optional frontmatter (title, owners, soft_links, etc.)
73
+ - Are always governed by the folder's `NODE.md` ownership in addition to any owners they declare
74
+
75
+ ## CODEOWNERS Generation
76
+
77
+ The CLI can generate a GitHub `CODEOWNERS` file from all `NODE.md` and leaf file frontmatter in the tree. This gives teams PR-level enforcement of the ownership model without custom tooling.
78
+
79
+ Example generated output:
80
+
81
+ ```
82
+ # Auto-generated from Context Tree. Do not edit manually.
83
+ /backend/ @alice
84
+ /backend/auth.md @alice @carol
85
+ /frontend/ @dana @eli
86
+ ```
87
+
88
+ ## Why This Design
89
+
90
+ - **Simple to resolve ownership** — `NODE.md` owners always apply; leaf file owners are additive.
91
+ - **Tree structure enforces clarity** — ownership disagreements at the folder level are resolved by splitting into subtrees.
92
+ - **Folder creation is deliberate** — requiring `NODE.md` with owners prevents folder sprawl.
93
+ - **Flexible without complexity** — leaf files can have specialized owners without introducing override semantics.
94
+ - **Git-native** — everything is a file, versioned, reviewable in PRs.
@@ -0,0 +1,113 @@
1
+ ---
2
+ title: "Tree Principles: Explanation and Examples"
3
+ owners: []
4
+ ---
5
+
6
+ # Tree Principles
7
+
8
+ This document explains the core principles of Context Tree with concrete examples.
9
+
10
+ ---
11
+
12
+ ## 1. Source of truth for decisions, not execution
13
+
14
+ The tree captures the *what* and *why* — strategic choices, cross-domain relationships, constraints. An agent should be able to read the tree and produce a correct approach without consulting source systems.
15
+
16
+ ### Workflow
17
+
18
+ 1. Human says: "Let's add SSO to our product."
19
+ 2. Agent reads relevant tree nodes (e.g., `platform/`, `environment/`).
20
+ 3. Agent writes a top-level design based on tree context alone.
21
+ 4. Human reviews and approves.
22
+ 5. Agent explores source systems to build a detailed execution plan.
23
+ 6. If source systems reveal something the tree didn't capture — update the tree, revisit with the human, then proceed.
24
+ 7. After execution is complete, update the tree to reflect any new decisions.
25
+
26
+ This applies to all tasks — features, campaigns, hiring decisions, refactors. Not every task requires a tree update, but the tree is always the starting point, and the question "does the tree need updating?" is always asked at the end.
27
+
28
+ ### What belongs in the tree
29
+
30
+ - "Auth flows span four repos: backend issues JWTs, frontend uses Better Auth, browser extension authenticates via OAuth popup through the frontend, desktop app uses a localhost callback server."
31
+ - "We chose MinerU for PDF parsing because it handles academic papers with complex layouts better than alternatives we tested."
32
+ - "We target academic researchers and AI-native teams because they have the highest tolerance for an agent-centric workflow."
33
+ - "Q3 campaign focuses on developer communities because enterprise sales cycle is too long for our current stage."
34
+
35
+ ### What does NOT belong in the tree
36
+
37
+ - The function signature of `retrieval_service.search()` — read the code.
38
+ - The database schema for the `chunk_embeddings` table — read the models.
39
+ - The current ad copy for a campaign — read the campaign tool.
40
+ - The current list of API endpoints — read the route files.
41
+ - The exact interview questions for a role — read the hiring doc.
42
+
43
+ ### The test
44
+
45
+ If an agent needs this information to *decide* on an approach, it belongs in the tree. If the agent only needs it to *execute*, it stays in the source system.
46
+
47
+ ### When inconsistency is found
48
+
49
+ If an agent reads the tree, makes a decision, then discovers a source system contradicts the tree — that's a tree bug. The tree must be corrected before proceeding. This is how the tree stays accurate: every completed task is an opportunity to validate and update it.
50
+
51
+ ---
52
+
53
+ ## 2. Agents are first-class participants
54
+
55
+ The tree is designed to be navigated and updated by agents, not just humans. Domains are organized by concern — what an agent needs to know to act — not by repo, team, or org chart.
56
+
57
+ ### Why organize by concern?
58
+
59
+ An agent working on "add SSO support" doesn't think in terms of repos (backend, frontend, extension, desktop) or org structure (engineering vs. product). It needs all auth context — the why, the how, the cross-domain implications — in one place. Organizing by concern puts that context together.
60
+
61
+ ### Domain placement
62
+
63
+ A feature or decision lives in the domain that owns the primary concern, with soft links to other domains for discoverability:
64
+
65
+ - "Add SSO support" → `platform/` (auth decision), soft links to `environment/` (extension/desktop auth flows)
66
+ - "Support PPTX parsing" → `knowledge/` (ingestion). Clear, single domain.
67
+ - "Q3 developer campaign" → `marketing/` (go-to-market), soft link to product domain (feature positioning)
68
+ - "Agent remembers user preferences" → `agent/` (memory)
69
+ - "Hire a frontend engineer" → `people/hiring/` (role decision), soft link to the team they'd join
70
+
71
+ ### When to create subdomains
72
+
73
+ Start flat. Split when an agent can't scan a NODE.md and quickly determine where to go next. If a domain accumulates enough leaf nodes on a single topic, that topic is ready to become a subdomain.
74
+
75
+ ### Whether something belongs in the tree is a judgment call
76
+
77
+ Not every task needs a tree update. A pure UI bug fix probably doesn't. But don't assume — a "simple" feature like dark mode becomes a tree-worthy decision once it involves auto mode, cross-device persistence, or desktop app coordination. Evaluate per task.
78
+
79
+ ---
80
+
81
+ ## 3. Transparency by default
82
+
83
+ All information in the tree is readable by everyone — humans and agents alike. Writing requires owner approval; reading is open.
84
+
85
+ This means any agent can build full context by traversing the tree. No domain is hidden. The ownership model controls who can *change* the tree, not who can *read* it.
86
+
87
+ ---
88
+
89
+ ## 4. Git-native tree structure
90
+
91
+ Each node is a file; each domain is a directory. The tree is a Git repository.
92
+
93
+ ### Why a tree?
94
+
95
+ A tree structure keeps information organized and navigable. Soft links allow cross-references where needed without the complexity of a full graph. An agent can start at any node and traverse up (broader context) or down (more detail) predictably.
96
+
97
+ ### Why Git?
98
+
99
+ History, ownership, and review follow the same model software engineering has refined for decades. Every change is a commit, every decision is reviewable in a PR, and the full history of how the tree evolved is preserved.
100
+
101
+ ### Examples of good nodes
102
+
103
+ **Cross-domain relationships:** "Auth touches 4 repos: backend (JWT issuance), frontend (Better Auth client), browser extension (OAuth popup + device token), desktop (localhost callback server + JWT storage)." — An agent would need to search across all repos to piece this together.
104
+
105
+ **Strategic decisions with rationale:** "We use Reciprocal Rank Fusion to combine vector and BM25 results because pure vector search missed keyword-heavy queries and pure BM25 missed semantic matches." — This is nowhere in the source systems.
106
+
107
+ **Domain state summaries:** "The ingestion pipeline has 6 stages: download → extract → parse → chunk → embed → store. PDF extraction uses MinerU (cloud). PPTX uses python-pptx locally." — An agent could trace this through 6+ files, or read one node.
108
+
109
+ ### Examples of bad nodes
110
+
111
+ - Restating what one source file already says clearly.
112
+ - Documenting stable, well-known patterns (e.g., "we use FastAPI for the backend").
113
+ - Listing things that change frequently without decision implications.