first-tree 0.0.3 → 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 (43) hide show
  1. package/README.md +69 -27
  2. package/dist/cli.js +28 -13
  3. package/dist/{help-xEI-s9iN.js → help-Dtdj91HJ.js} +1 -1
  4. package/dist/{init-DtOjj0wc.js → init--VepFe6N.js} +171 -21
  5. package/dist/{installer-rcZpGLnM.js → installer-cH7N4RNj.js} +2 -2
  6. package/dist/onboarding-C9cYSE6F.js +2 -0
  7. package/dist/onboarding-CPP8fF4D.js +10 -0
  8. package/dist/{repo-BTJG8BU1.js → repo-DY57bMqr.js} +143 -12
  9. package/dist/{upgrade-COGgI7Rj.js → upgrade-Cgx_K2HM.js} +46 -7
  10. package/dist/{verify-CxN6JiV9.js → verify-mC9ZTd1f.js} +66 -6
  11. package/package.json +1 -1
  12. package/skills/first-tree/SKILL.md +8 -4
  13. package/skills/first-tree/assets/framework/VERSION +1 -1
  14. package/skills/first-tree/assets/framework/helpers/run-review.ts +16 -2
  15. package/skills/first-tree/assets/framework/templates/{agent.md.template → agents.md.template} +1 -0
  16. package/skills/first-tree/assets/framework/templates/root-node.md.template +6 -3
  17. package/skills/first-tree/engine/commands/init.ts +1 -1
  18. package/skills/first-tree/engine/commands/upgrade.ts +1 -1
  19. package/skills/first-tree/engine/commands/verify.ts +1 -1
  20. package/skills/first-tree/engine/init.ts +285 -16
  21. package/skills/first-tree/engine/repo.ts +185 -9
  22. package/skills/first-tree/engine/rules/agent-instructions.ts +29 -7
  23. package/skills/first-tree/engine/runtime/asset-loader.ts +7 -0
  24. package/skills/first-tree/engine/upgrade.ts +66 -9
  25. package/skills/first-tree/engine/validators/nodes.ts +48 -3
  26. package/skills/first-tree/engine/verify.ts +61 -3
  27. package/skills/first-tree/references/maintainer-architecture.md +1 -1
  28. package/skills/first-tree/references/maintainer-build-and-distribution.md +3 -0
  29. package/skills/first-tree/references/maintainer-thin-cli.md +1 -1
  30. package/skills/first-tree/references/onboarding.md +32 -9
  31. package/skills/first-tree/references/source-map.md +3 -3
  32. package/skills/first-tree/references/upgrade-contract.md +14 -5
  33. package/skills/first-tree/scripts/check-skill-sync.sh +1 -1
  34. package/skills/first-tree/tests/helpers.ts +24 -4
  35. package/skills/first-tree/tests/init.test.ts +103 -6
  36. package/skills/first-tree/tests/repo.test.ts +87 -9
  37. package/skills/first-tree/tests/rules.test.ts +26 -7
  38. package/skills/first-tree/tests/skill-artifacts.test.ts +4 -0
  39. package/skills/first-tree/tests/thin-cli.test.ts +52 -7
  40. package/skills/first-tree/tests/upgrade.test.ts +19 -5
  41. package/skills/first-tree/tests/verify.test.ts +106 -7
  42. package/dist/onboarding-6Fr5Gkrk.js +0 -2
  43. package/dist/onboarding-B9zPGvvG.js +0 -10
@@ -1,19 +1,23 @@
1
- import { mkdirSync, writeFileSync } from "node:fs";
1
+ import { existsSync, mkdirSync, readFileSync, writeFileSync } from "node:fs";
2
2
  import { join } from "node:path";
3
3
  import { describe, expect, it } from "vitest";
4
+ import { runInit } from "#skill/engine/init.js";
4
5
  import { check, checkProgress, runVerify } from "#skill/engine/verify.js";
5
6
  import { Repo } from "#skill/engine/repo.js";
6
7
  import {
8
+ AGENT_INSTRUCTIONS_FILE,
7
9
  INSTALLED_PROGRESS,
8
10
  LEGACY_PROGRESS,
9
11
  } from "#skill/engine/runtime/asset-loader.js";
10
12
  import {
11
13
  useTmpDir,
14
+ makeAgentsMd,
12
15
  makeFramework,
13
16
  makeLegacyFramework,
14
17
  makeNode,
15
- makeAgentMd,
18
+ makeSourceRepo,
16
19
  makeMembers,
20
+ makeSourceSkill,
17
21
  } from "./helpers.js";
18
22
 
19
23
  // --- check ---
@@ -88,10 +92,7 @@ function buildFullRepo(root: string): void {
88
92
  join(root, "NODE.md"),
89
93
  "---\ntitle: My Org\nowners: [alice]\n---\n# Content\n",
90
94
  );
91
- writeFileSync(
92
- join(root, "AGENT.md"),
93
- "<!-- BEGIN CONTEXT-TREE FRAMEWORK -->\nstuff\n<!-- END CONTEXT-TREE FRAMEWORK -->\n",
94
- );
95
+ makeAgentsMd(root, { markers: true });
95
96
  makeMembers(root, 1);
96
97
  }
97
98
 
@@ -108,6 +109,74 @@ describe("runVerify all passing", () => {
108
109
  const ret = runVerify(repo, passValidator);
109
110
  expect(ret).toBe(0);
110
111
  });
112
+
113
+ it("passes after a real init flow when only the user tree remains to validate", () => {
114
+ const repoDir = useTmpDir();
115
+ const sourceDir = useTmpDir();
116
+ mkdirSync(join(repoDir.path, ".git"));
117
+ makeSourceSkill(sourceDir.path, "0.2.0");
118
+
119
+ expect(runInit(new Repo(repoDir.path), { sourceRoot: sourceDir.path })).toBe(0);
120
+
121
+ writeFileSync(
122
+ join(repoDir.path, "NODE.md"),
123
+ [
124
+ "---",
125
+ 'title: "Example Tree"',
126
+ "owners: [alice]",
127
+ "---",
128
+ "",
129
+ "# Example Tree",
130
+ "",
131
+ "A repository initialized from the bundled skill for verification coverage.",
132
+ "",
133
+ "## Domains",
134
+ "",
135
+ "- **[members/](members/NODE.md)** — Team member definitions and responsibilities.",
136
+ "",
137
+ ].join("\n"),
138
+ );
139
+
140
+ const agentPath = join(repoDir.path, AGENT_INSTRUCTIONS_FILE);
141
+ writeFileSync(
142
+ agentPath,
143
+ `${readFileSync(agentPath, "utf-8").trim()}\n\nProject-specific verification instructions.\n`,
144
+ );
145
+
146
+ mkdirSync(join(repoDir.path, "members", "alice"), { recursive: true });
147
+ writeFileSync(
148
+ join(repoDir.path, "members", "alice", "NODE.md"),
149
+ [
150
+ "---",
151
+ 'title: "Alice"',
152
+ "owners: [alice]",
153
+ 'type: "human"',
154
+ 'role: "Maintainer"',
155
+ "domains:",
156
+ ' - "members"',
157
+ "---",
158
+ "",
159
+ "# Alice",
160
+ "",
161
+ "## About",
162
+ "",
163
+ "Maintains the initialized tree and keeps the docs current.",
164
+ "",
165
+ "## Current Focus",
166
+ "",
167
+ "Validating the init-to-verify workflow.",
168
+ "",
169
+ ].join("\n"),
170
+ );
171
+
172
+ const progressPath = join(repoDir.path, INSTALLED_PROGRESS);
173
+ writeFileSync(
174
+ progressPath,
175
+ readFileSync(progressPath, "utf-8").replace(/^- \[ \]/gm, "- [x]"),
176
+ );
177
+
178
+ expect(runVerify(new Repo(repoDir.path))).toBe(0);
179
+ });
111
180
  });
112
181
 
113
182
  // --- runVerify — failing checks ---
@@ -120,7 +189,7 @@ describe("runVerify failing", () => {
120
189
  expect(ret).toBe(1);
121
190
  });
122
191
 
123
- it("fails when AGENT.md is missing", () => {
192
+ it("fails when AGENTS.md is missing", () => {
124
193
  const tmp = useTmpDir();
125
194
  makeFramework(tmp.path);
126
195
  writeFileSync(
@@ -132,6 +201,28 @@ describe("runVerify failing", () => {
132
201
  expect(ret).toBe(1);
133
202
  });
134
203
 
204
+ it("fails when only legacy AGENT.md exists", () => {
205
+ const tmp = useTmpDir();
206
+ mkdirSync(join(tmp.path, ".git"));
207
+ makeFramework(tmp.path);
208
+ makeNode(tmp.path);
209
+ makeAgentsMd(tmp.path, { legacyName: true, markers: true, userContent: true });
210
+ makeMembers(tmp.path, 1);
211
+ const repo = new Repo(tmp.path);
212
+ const ret = runVerify(repo, passValidator);
213
+ expect(existsSync(join(tmp.path, AGENT_INSTRUCTIONS_FILE))).toBe(false);
214
+ expect(ret).toBe(1);
215
+ });
216
+
217
+ it("fails when legacy AGENT.md remains alongside AGENTS.md", () => {
218
+ const tmp = useTmpDir();
219
+ buildFullRepo(tmp.path);
220
+ makeAgentsMd(tmp.path, { legacyName: true, markers: true, userContent: true });
221
+ const repo = new Repo(tmp.path);
222
+ const ret = runVerify(repo, passValidator);
223
+ expect(ret).toBe(1);
224
+ });
225
+
135
226
  it("fails when node validation returns non-zero", () => {
136
227
  const tmp = useTmpDir();
137
228
  buildFullRepo(tmp.path);
@@ -139,4 +230,12 @@ describe("runVerify failing", () => {
139
230
  const ret = runVerify(repo, failValidator);
140
231
  expect(ret).toBe(1);
141
232
  });
233
+
234
+ it("gives a dedicated-tree hint when run from a source repo", () => {
235
+ const tmp = useTmpDir();
236
+ makeSourceRepo(tmp.path);
237
+ const repo = new Repo(tmp.path);
238
+ const ret = runVerify(repo, passValidator);
239
+ expect(ret).toBe(1);
240
+ });
142
241
  });
@@ -1,2 +0,0 @@
1
- import { t as runOnboarding } from "./onboarding-B9zPGvvG.js";
2
- export { runOnboarding };
@@ -1,10 +0,0 @@
1
- //#region skills/first-tree/references/onboarding.md
2
- var onboarding_default = "# Context Tree Onboarding\n\nYou 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.\n\n---\n\n## What Is a Context Tree\n\nA 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.\n\nKey properties:\n\n- **Nodes are markdown files.** Each directory has a `NODE.md` that describes the domain. Leaf `.md` files capture specific decisions or designs.\n- **Every node has an owner.** Declared in YAML frontmatter. Owners approve changes to their nodes.\n- **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.\n- **The tree is never a snapshot — it's the current state.** When decisions change, the tree updates. Stale nodes are bugs.\n\n### Frontmatter Format\n\nEvery node has frontmatter:\n\n```yaml\n---\ntitle: \"Auth Architecture\"\nowners: [alice, bob]\nsoft_links: [/infrastructure/deployments]\n---\n```\n\n- `owners` — who can approve changes. `owners: []` inherits from parent. `owners: [*]` means anyone.\n- `soft_links` — cross-references to related nodes in other domains.\n\n### What Belongs in the Tree\n\nInformation an agent needs to **decide** on an approach — not to execute it.\n\n**Yes:** \"Auth spans 4 repos: backend issues JWTs, frontend uses Better Auth, extension uses OAuth popup, desktop uses localhost callback.\"\n\n**No:** The function signature of `auth_service.verify()` — that's in the code.\n\n---\n\n## Four Principles\n\n1. **Source of truth for decisions, not execution.** The tree captures the *what* and *why*. Execution details stay in source systems.\n2. **Agents are first-class participants.** The tree is designed for agents to navigate and update.\n3. **Transparency by default.** Reading is open to all. Writing requires owner approval.\n4. **Git-native.** Nodes are files, domains are directories. History, ownership, and review follow Git conventions.\n\n---\n\n## How to Set Up a Context Tree\n\n### Prerequisites\n\n- A Git repository for your tree (separate from your code repos)\n- Node.js 18+\n- The npm package is `first-tree`, the installed CLI command is\n `context-tree`, and the installed skill directory in the tree is\n `skills/first-tree/`\n- Use `npx first-tree init` for one-off runs, or `npm install -g first-tree`\n to add the `context-tree` command to your PATH\n\n### Step 1: Initialize\n\n```bash\nmkdir my-org-tree && cd my-org-tree\ngit init\ncontext-tree init\n```\n\nThis installs the framework skill into `skills/first-tree/`, renders scaffolding (`NODE.md`, `AGENT.md`, `members/NODE.md`), and generates a task list in `skills/first-tree/progress.md`.\n\n### Step 2: Work Through the Task List\n\nRead `skills/first-tree/progress.md`. It contains a checklist tailored to the current state of the repo. Complete each task:\n\n- Fill in `NODE.md` with your organization name, owners, and domains\n- Add project-specific instructions to `AGENT.md` below the framework markers\n- Create member nodes under `members/`\n- Optionally configure agent integration (e.g., Claude Code session hooks)\n- Copy validation workflows from `skills/first-tree/assets/framework/workflows/` to `.github/workflows/`\n\nAs you complete each task, check it off in `skills/first-tree/progress.md` by changing `- [ ]` to `- [x]`.\n\n### Step 3: Verify\n\n```bash\ncontext-tree verify\n```\n\nThis fails if any items in `skills/first-tree/progress.md` remain unchecked, and runs deterministic checks (valid frontmatter, node structure, member nodes exist).\n\n### Step 4: Design Your Domains\n\nCreate top-level directories for your organization's primary concerns. Each needs a `NODE.md`:\n\n```\nmy-org-tree/\n NODE.md # root — lists all domains\n engineering/\n NODE.md # decisions about architecture, infra, tooling\n product/\n NODE.md # strategy, roadmap, user research\n marketing/\n NODE.md # positioning, campaigns\n members/\n NODE.md # team members and agents\n alice/\n NODE.md # individual member node\n```\n\n### Step 5: Populate from Existing Work\n\nFor each domain, extract knowledge from existing repos, docs, and systems:\n\n- Decisions and their rationale\n- Cross-domain relationships and dependencies\n- Constraints that aren't obvious from the code\n\nThe tree doesn't duplicate source code — it captures what connects things and why they were built that way.\n\n---\n\n## CLI Reference\n\n| Command | Description |\n|---------|-------------|\n| `context-tree init` | Bootstrap a new tree. Installs the framework skill, renders templates, generates a task list. |\n| `context-tree verify` | Check the installed progress file for unchecked items + run deterministic validation. |\n| `context-tree upgrade` | Refresh the installed framework skill from the currently running `first-tree` npm package and generate follow-up tasks. |\n| `context-tree help onboarding` | Print this onboarding guide. |\n\n---\n\n## Upgrading the Framework\n\nWhen the framework updates:\n\n```bash\ncontext-tree upgrade\n```\n\n`context-tree upgrade` refreshes `skills/first-tree/` from the\nskill bundled with the currently running `first-tree` npm package, preserves your\ntree content, and generates follow-up tasks in\n`skills/first-tree/progress.md`.\n\nIf your repo still uses the older `skills/first-tree-cli-framework/` path,\n`context-tree upgrade` will migrate it to `skills/first-tree/` first.\n\nTo pick up a newer framework release, first run a newer package version, for\nexample `npx first-tree@latest upgrade`, or update your global `first-tree`\ninstall before running `context-tree upgrade`.\n\n---\n\n## Further Reading\n\n- `skills/first-tree/references/principles.md` — Core principles with detailed examples\n- `skills/first-tree/references/ownership-and-naming.md` — How nodes are named and owned\n- `AGENT.md` in your tree — The before/during/after workflow for every task\n";
3
- //#endregion
4
- //#region skills/first-tree/engine/onboarding.ts
5
- function runOnboarding(output = console.log) {
6
- output(onboarding_default);
7
- return 0;
8
- }
9
- //#endregion
10
- export { onboarding_default as n, runOnboarding as t };