first-tree 0.0.4 → 0.0.6

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 (54) hide show
  1. package/README.md +36 -13
  2. package/dist/cli.js +5 -5
  3. package/dist/{help-Dtdj91HJ.js → help-DV9-AaFp.js} +1 -1
  4. package/dist/{init--VepFe6N.js → init-BgGH2_yC.js} +57 -11
  5. package/dist/onboarding-D7fGGOMN.js +10 -0
  6. package/dist/onboarding-lASHHmgO.js +2 -0
  7. package/dist/{repo-DY57bMqr.js → repo-Cc5U4DWT.js} +76 -5
  8. package/dist/source-integration-CuKjoheT.js +84 -0
  9. package/dist/{upgrade-Cgx_K2HM.js → upgrade-BvA9oKmi.js} +37 -9
  10. package/dist/{verify-mC9ZTd1f.js → verify-G8gNXzDX.js} +5 -1
  11. package/package.json +11 -9
  12. package/skills/first-tree/SKILL.md +30 -10
  13. package/skills/first-tree/agents/openai.yaml +1 -1
  14. package/skills/first-tree/assets/framework/examples/claude-code/README.md +2 -2
  15. package/skills/first-tree/assets/framework/examples/claude-code/settings.json +1 -1
  16. package/skills/first-tree/assets/framework/helpers/generate-codeowners.ts +1 -1
  17. package/skills/first-tree/assets/framework/helpers/inject-tree-context.sh +0 -0
  18. package/skills/first-tree/assets/framework/helpers/run-review.ts +1 -1
  19. package/skills/first-tree/assets/framework/templates/agents.md.template +2 -2
  20. package/skills/first-tree/assets/framework/templates/members-domain.md.template +1 -1
  21. package/skills/first-tree/assets/framework/templates/root-node.md.template +3 -3
  22. package/skills/first-tree/assets/framework/workflows/codeowners.yml +1 -1
  23. package/skills/first-tree/assets/framework/workflows/pr-review.yml +1 -1
  24. package/skills/first-tree/engine/init.ts +78 -6
  25. package/skills/first-tree/engine/repo.ts +74 -10
  26. package/skills/first-tree/engine/rules/agent-integration.ts +3 -1
  27. package/skills/first-tree/engine/rules/framework.ts +2 -2
  28. package/skills/first-tree/engine/runtime/adapters.ts +6 -2
  29. package/skills/first-tree/engine/runtime/asset-loader.ts +142 -4
  30. package/skills/first-tree/engine/runtime/installer.ts +18 -12
  31. package/skills/first-tree/engine/runtime/source-integration.ts +80 -0
  32. package/skills/first-tree/engine/upgrade.ts +103 -9
  33. package/skills/first-tree/engine/verify.ts +7 -0
  34. package/skills/first-tree/references/maintainer-architecture.md +4 -0
  35. package/skills/first-tree/references/maintainer-thin-cli.md +3 -0
  36. package/skills/first-tree/references/onboarding.md +56 -21
  37. package/skills/first-tree/references/principles.md +97 -57
  38. package/skills/first-tree/references/source-map.md +1 -0
  39. package/skills/first-tree/references/source-workspace-installation.md +52 -0
  40. package/skills/first-tree/references/upgrade-contract.md +67 -26
  41. package/skills/first-tree/scripts/check-skill-sync.sh +2 -0
  42. package/skills/first-tree/scripts/quick_validate.py +0 -0
  43. package/skills/first-tree/scripts/run-local-cli.sh +0 -0
  44. package/skills/first-tree/tests/asset-loader.test.ts +23 -1
  45. package/skills/first-tree/tests/helpers.ts +27 -3
  46. package/skills/first-tree/tests/init.test.ts +72 -3
  47. package/skills/first-tree/tests/repo.test.ts +46 -0
  48. package/skills/first-tree/tests/rules.test.ts +9 -7
  49. package/skills/first-tree/tests/skill-artifacts.test.ts +45 -0
  50. package/skills/first-tree/tests/upgrade.test.ts +58 -3
  51. package/skills/first-tree/tests/verify.test.ts +21 -3
  52. package/dist/installer-cH7N4RNj.js +0 -47
  53. package/dist/onboarding-C9cYSE6F.js +0 -2
  54. package/dist/onboarding-CPP8fF4D.js +0 -10
package/README.md CHANGED
@@ -36,7 +36,8 @@ Although the npm package is named `first-tree`, the installed CLI command is
36
36
  ## Quick Start
37
37
 
38
38
  Recommended workflow: start from your source or workspace repo and let
39
- `context-tree init` create a sibling dedicated tree repo.
39
+ `context-tree init` install local source/workspace integration and create a
40
+ sibling dedicated tree repo.
40
41
 
41
42
  ```bash
42
43
  cd my-app
@@ -52,15 +53,28 @@ git init
52
53
  context-tree init --here
53
54
  ```
54
55
 
55
- - `context-tree init` installs `skills/first-tree/`, creates `NODE.md`,
56
- `AGENTS.md`, `members/NODE.md`, and writes a checklist to
57
- `skills/first-tree/progress.md`.
56
+ - `context-tree init` installs `.agents/skills/first-tree/` and
57
+ `.claude/skills/first-tree/` in the current source/workspace repo, appends a
58
+ single `FIRST-TREE-SOURCE-INTEGRATION:` line to root `AGENTS.md` and
59
+ `CLAUDE.md`, then creates `NODE.md`, tree-scoped `AGENTS.md`,
60
+ `members/NODE.md`, and a checklist in the dedicated tree repo at
61
+ `.agents/skills/first-tree/progress.md`.
62
+ - Never create `NODE.md`, `members/`, or tree-scoped `AGENTS.md` in the
63
+ source/workspace repo. Those files live only in the dedicated `*-context`
64
+ repo.
65
+ - After creating the dedicated tree repo, prefer pushing it to the same GitHub
66
+ organization as the source repo, add it back as a git submodule, and open a
67
+ PR to the source/workspace repo's default branch instead of merging
68
+ automatically.
58
69
  - `context-tree verify` checks both the progress checklist and deterministic
59
70
  tree validation. It is expected to fail until the required onboarding tasks
60
71
  are complete.
61
72
  - `context-tree upgrade` refreshes the installed skill from the currently
62
- running `first-tree` npm package. To force the newest published package for a
63
- one-off upgrade, run `npx first-tree@latest upgrade`.
73
+ running `first-tree` npm package. In a source/workspace repo it refreshes
74
+ only the local installed skill plus the
75
+ `FIRST-TREE-SOURCE-INTEGRATION:` line; use `--tree-path` to upgrade the
76
+ dedicated tree repo. To force the newest published package for a one-off
77
+ upgrade, run `npx first-tree@latest upgrade`.
64
78
 
65
79
  The package carries the bundled canonical skill, so `init` and `upgrade`
66
80
  install from the package payload instead of cloning this source repo at
@@ -70,20 +84,26 @@ runtime.
70
84
 
71
85
  | Command | What it does |
72
86
  | --- | --- |
73
- | `context-tree init` | Create or refresh a dedicated context tree repo; use `--here` to initialize the current repo in place |
87
+ | `context-tree init` | Install source/workspace integration locally and create or refresh a dedicated context tree repo; use `--here` to initialize the current repo in place |
74
88
  | `context-tree verify` | Run verification checks against the current tree |
75
- | `context-tree upgrade` | Refresh the installed skill from the current `first-tree` npm package and write follow-up tasks |
89
+ | `context-tree upgrade` | Refresh the installed skill from the current `first-tree` npm package; in a source/workspace repo it updates only local integration, while tree repos also get follow-up tasks |
76
90
  | `context-tree help onboarding` | Print the onboarding guide |
77
91
  | `context-tree --help` | Show the available commands |
78
92
  | `context-tree --version` | Print the installed CLI version |
79
93
 
80
94
  ## Package Name vs Command
81
95
 
82
- - npm package name: `first-tree`
83
- - installed CLI command: `context-tree`
84
- - installed skill directory inside a user tree: `skills/first-tree/`
85
- - when maintainer docs mention "the `first-tree` skill", they mean that
86
- bundled skill directory, not the npm package name
96
+ - The npm package is `first-tree`.
97
+ - The installed CLI command is `context-tree`.
98
+ - The installed skill directories inside a user tree are
99
+ `.agents/skills/first-tree/` and `.claude/skills/first-tree/`.
100
+ - The published package keeps its bundled canonical source under
101
+ `skills/first-tree/`.
102
+ - When maintainer docs say "the `first-tree` skill", they mean that bundled
103
+ skill directory, not the npm package name.
104
+ - `npx first-tree init` is the quickest one-off entrypoint.
105
+ - `npm install -g first-tree` adds `context-tree` to your PATH for repeated
106
+ use.
87
107
 
88
108
  ## Runtime And Maintainer Prerequisites
89
109
 
@@ -97,6 +117,8 @@ runtime.
97
117
  bundled skill.
98
118
  - `skills/first-tree/` is the canonical source for framework behavior, shipped
99
119
  templates, maintainer references, and validation logic.
120
+ - `context-tree init` installs that bundled skill into `.agents/skills/first-tree/`
121
+ and `.claude/skills/first-tree/` inside user repos.
100
122
  - `evals/` is maintainer-only developer tooling for the source repo. It is
101
123
  intentionally not part of the published package.
102
124
 
@@ -125,6 +147,7 @@ live in `skills/first-tree/`.
125
147
 
126
148
  - User-facing overview: `skills/first-tree/references/about.md`
127
149
  - User onboarding: `skills/first-tree/references/onboarding.md`
150
+ - Source/workspace install contract: `skills/first-tree/references/source-workspace-installation.md`
128
151
  - Maintainer entrypoint: `skills/first-tree/references/source-map.md`
129
152
 
130
153
  If you are maintaining this repo, start with the source map instead of relying
package/dist/cli.js CHANGED
@@ -7,7 +7,7 @@ const USAGE = `usage: context-tree <command>
7
7
  New to context-tree? Run \`context-tree help onboarding\` first.
8
8
 
9
9
  Commands:
10
- init Create or refresh a dedicated context tree repo
10
+ init Install source/workspace integration and create or refresh a dedicated context tree repo
11
11
  verify Run verification checks against a tree repo
12
12
  upgrade Refresh the installed skill in a tree repo
13
13
  help Show help for a topic (e.g. \`help onboarding\`)
@@ -44,18 +44,18 @@ async function runCli(args, output = console.log) {
44
44
  const command = args[0];
45
45
  switch (command) {
46
46
  case "init": {
47
- const { runInit } = await import("./init--VepFe6N.js");
47
+ const { runInit } = await import("./init-BgGH2_yC.js");
48
48
  return runInit(args.slice(1));
49
49
  }
50
50
  case "verify": {
51
- const { runVerify } = await import("./verify-mC9ZTd1f.js");
51
+ const { runVerify } = await import("./verify-G8gNXzDX.js");
52
52
  return runVerify(args.slice(1));
53
53
  }
54
54
  case "upgrade": {
55
- const { runUpgrade } = await import("./upgrade-Cgx_K2HM.js");
55
+ const { runUpgrade } = await import("./upgrade-BvA9oKmi.js");
56
56
  return runUpgrade(args.slice(1));
57
57
  }
58
- case "help": return (await import("./help-Dtdj91HJ.js")).runHelp(args.slice(1), write);
58
+ case "help": return (await import("./help-DV9-AaFp.js")).runHelp(args.slice(1), write);
59
59
  default:
60
60
  write(`Unknown command: ${command}`);
61
61
  write(USAGE);
@@ -12,7 +12,7 @@ async function runHelp(args, output = console.log) {
12
12
  }
13
13
  switch (topic) {
14
14
  case "onboarding": {
15
- const { runOnboarding } = await import("./onboarding-C9cYSE6F.js");
15
+ const { runOnboarding } = await import("./onboarding-lASHHmgO.js");
16
16
  return runOnboarding(output);
17
17
  }
18
18
  default:
@@ -1,6 +1,6 @@
1
- import { a as FRAMEWORK_ASSET_ROOT, c as FRAMEWORK_VERSION, d as LEGACY_AGENT_INSTRUCTIONS_FILE, g as SKILL_ROOT, i as AGENT_INSTRUCTIONS_TEMPLATE, l as FRAMEWORK_WORKFLOWS_DIR, n as Repo, o as FRAMEWORK_EXAMPLES_DIR, r as AGENT_INSTRUCTIONS_FILE, s as FRAMEWORK_TEMPLATES_DIR, t as FRAMEWORK_END_MARKER, u as INSTALLED_PROGRESS } from "./repo-DY57bMqr.js";
2
- import { n as onboarding_default } from "./onboarding-CPP8fF4D.js";
3
- import { n as renderTemplateFile, r as resolveBundledPackageRoot, t as copyCanonicalSkill } from "./installer-cH7N4RNj.js";
1
+ import { D as SOURCE_INTEGRATION_MARKER, O as installedSkillRootsDisplay, _ as LEGACY_EXAMPLES_DIR, d as FRAMEWORK_TEMPLATES_DIR, f as FRAMEWORK_VERSION, g as LEGACY_AGENT_INSTRUCTIONS_FILE, i as AGENT_INSTRUCTIONS_TEMPLATE, l as FRAMEWORK_ASSET_ROOT, m as INSTALLED_PROGRESS, n as Repo, o as CLAUDE_FRAMEWORK_EXAMPLES_DIR, p as FRAMEWORK_WORKFLOWS_DIR, r as AGENT_INSTRUCTIONS_FILE, s as CLAUDE_INSTRUCTIONS_FILE, t as FRAMEWORK_END_MARKER, u as FRAMEWORK_EXAMPLES_DIR, x as LEGACY_SKILL_EXAMPLES_DIR, y as LEGACY_REPO_SKILL_EXAMPLES_DIR } from "./repo-Cc5U4DWT.js";
2
+ import { n as onboarding_default } from "./onboarding-D7fGGOMN.js";
3
+ import { i as resolveBundledPackageRoot, n as copyCanonicalSkill, r as renderTemplateFile, t as upsertSourceIntegrationFiles } from "./source-integration-CuKjoheT.js";
4
4
  import { existsSync, mkdirSync, readFileSync, readdirSync, statSync, writeFileSync } from "node:fs";
5
5
  import { execFileSync } from "node:child_process";
6
6
  import { dirname, join, relative, resolve } from "node:path";
@@ -47,12 +47,24 @@ function evaluate$6(repo) {
47
47
  };
48
48
  }
49
49
  //#endregion
50
+ //#region skills/first-tree/engine/runtime/adapters.ts
51
+ function claudeCodeExampleCandidates() {
52
+ return [
53
+ join(CLAUDE_FRAMEWORK_EXAMPLES_DIR, "claude-code"),
54
+ join(FRAMEWORK_EXAMPLES_DIR, "claude-code"),
55
+ join(LEGACY_REPO_SKILL_EXAMPLES_DIR, "claude-code"),
56
+ join(LEGACY_SKILL_EXAMPLES_DIR, "claude-code"),
57
+ join(LEGACY_EXAMPLES_DIR, "claude-code")
58
+ ];
59
+ }
60
+ //#endregion
50
61
  //#region skills/first-tree/engine/rules/agent-integration.ts
51
62
  var agent_integration_exports = /* @__PURE__ */ __exportAll({ evaluate: () => evaluate$5 });
52
63
  function evaluate$5(repo) {
53
64
  const tasks = [];
65
+ const [claudeExamplePath] = claudeCodeExampleCandidates();
54
66
  if (repo.pathExists(".claude/settings.json")) {
55
- if (!repo.fileContains(".claude/settings.json", "inject-tree-context")) tasks.push(`Add SessionStart hook to \`.claude/settings.json\` (see \`${FRAMEWORK_EXAMPLES_DIR}/claude-code/\`)`);
67
+ if (!repo.fileContains(".claude/settings.json", "inject-tree-context")) tasks.push(`Add SessionStart hook to \`.claude/settings.json\` (see \`${claudeExamplePath}/\`)`);
56
68
  } else if (!repo.anyAgentConfig()) tasks.push(`No agent configuration detected. Configure your agent to load tree context at session start. See \`${FRAMEWORK_EXAMPLES_DIR}/\` for supported agents. You can skip this and set it up later.`);
57
69
  return {
58
70
  group: "Agent Integration",
@@ -106,7 +118,7 @@ If (1): ask the user to provide the key, then run \`gh secret set\` with the sec
106
118
  var framework_exports = /* @__PURE__ */ __exportAll({ evaluate: () => evaluate$3 });
107
119
  function evaluate$3(repo) {
108
120
  const tasks = [];
109
- if (!repo.hasFramework()) tasks.push(`\`${SKILL_ROOT}/\` not found — run \`context-tree init\` to install the framework skill bundled with the current \`first-tree\` package`);
121
+ if (!repo.hasFramework()) tasks.push(`${installedSkillRootsDisplay()} not found — run \`context-tree init\` to install the framework skill bundled with the current \`first-tree\` package`);
110
122
  return {
111
123
  group: "Framework",
112
124
  order: 1,
@@ -193,8 +205,10 @@ function evaluateAll(repo) {
193
205
  const INTERACTIVE_TOOL = "AskUserQuestion";
194
206
  const INIT_USAGE = `usage: context-tree init [--here] [--tree-name NAME] [--tree-path PATH]
195
207
 
196
- By default, running \`context-tree init\` inside a source or workspace repo creates
197
- a sibling dedicated tree repo named \`<repo>-context\`.
208
+ By default, running \`context-tree init\` inside a source or workspace repo installs
209
+ the first-tree skill in the current repo, updates \`AGENTS.md\` and \`CLAUDE.md\`
210
+ with a \`${SOURCE_INTEGRATION_MARKER}\` line, and creates a sibling dedicated tree
211
+ repo named \`<repo>-context\`.
198
212
 
199
213
  Options:
200
214
  --here Initialize the current repo in place
@@ -219,7 +233,7 @@ const TEMPLATE_MAP = [
219
233
  ];
220
234
  function installSkill(source, target) {
221
235
  copyCanonicalSkill(source, target);
222
- console.log(" Installed skills/first-tree/ from the bundled first-tree package");
236
+ console.log(` Installed ${installedSkillRootsDisplay()} from the bundled first-tree package`);
223
237
  }
224
238
  function renderTemplates(target) {
225
239
  const frameworkDir = join(target, FRAMEWORK_ASSET_ROOT);
@@ -234,6 +248,14 @@ function formatTaskList(groups, context) {
234
248
  if (context?.dedicatedTreeRepo) {
235
249
  lines.push("This repository is the dedicated Context Tree. Keep decisions, rationale, cross-domain relationships, and ownership here; keep execution detail in your source repositories.", "");
236
250
  if (context.sourceRepoPath) lines.push(`**Bootstrap source repo:** \`${context.sourceRepoPath}\``, "");
251
+ if (context.sourceRepoName) {
252
+ lines.push(`**Source/workspace contract:** Keep \`${context.sourceRepoName}\` limited to the installed skill plus the \`${SOURCE_INTEGRATION_MARKER}\` lines in \`${AGENT_INSTRUCTIONS_FILE}\` and \`${CLAUDE_INSTRUCTIONS_FILE}\`. Never add \`NODE.md\`, \`members/\`, or tree-scoped \`${AGENT_INSTRUCTIONS_FILE}\` there.`, "");
253
+ lines.push("## Source Workspace Workflow");
254
+ lines.push(`- [ ] Publish this dedicated tree repo to the same GitHub organization as \`${context.sourceRepoName}\``);
255
+ lines.push(`- [ ] Add this tree repo back to \`${context.sourceRepoName}\` as a git submodule after the remote exists`);
256
+ lines.push(`- [ ] Open a PR against the source/workspace repo's default branch with only the installed skill, the \`${SOURCE_INTEGRATION_MARKER}\` marker lines in \`${AGENT_INSTRUCTIONS_FILE}\` / \`${CLAUDE_INSTRUCTIONS_FILE}\`, and the new submodule pointer`);
257
+ lines.push("");
258
+ }
237
259
  lines.push("When you publish this tree repo, keep it in the same GitHub organization as the source repo unless you have a reason not to.", "");
238
260
  }
239
261
  lines.push(`**Agent instructions:** Before starting work, analyze the full task list below and identify all information you need from the user. Ask the user for their code repositories or project directories so you can analyze the source yourself — derive project descriptions, domains, and members from the code instead of asking the user to describe them. Collect everything upfront using the **${INTERACTIVE_TOOL}** tool with structured options — present selectable choices (with label and description) so the user can pick instead of typing free-form answers. You may batch up to 4 questions per ${INTERACTIVE_TOOL} call.\n`);
@@ -271,20 +293,44 @@ function runInit(repo, options) {
271
293
  const r = initTarget.repo;
272
294
  const taskListContext = initTarget.dedicatedTreeRepo ? {
273
295
  dedicatedTreeRepo: true,
296
+ sourceRepoName: sourceRepo.repoName(),
274
297
  sourceRepoPath: relativePathFrom(r.root, sourceRepo.root)
275
298
  } : void 0;
299
+ let sourceRoot = null;
300
+ const resolveSourceRoot = () => {
301
+ if (sourceRoot !== null) return sourceRoot;
302
+ sourceRoot = options?.sourceRoot ?? resolveBundledPackageRoot();
303
+ return sourceRoot;
304
+ };
276
305
  if (initTarget.dedicatedTreeRepo) {
277
306
  console.log("Recommended workflow: keep the Context Tree in a dedicated repo separate from your source/workspace repo.");
278
307
  console.log(` Source repo: ${sourceRepo.root}`);
279
308
  console.log(` Tree repo: ${r.root}`);
280
309
  if (initTarget.createdGitRepo) console.log(" Initialized a new git repo for the tree.");
310
+ console.log(` The source/workspace repo should keep only the installed skill and the ${SOURCE_INTEGRATION_MARKER} lines in ${AGENT_INSTRUCTIONS_FILE} and ${CLAUDE_INSTRUCTIONS_FILE}.`);
311
+ console.log(` Never add NODE.md, members/, or tree-scoped ${AGENT_INSTRUCTIONS_FILE} to the source/workspace repo.`);
281
312
  console.log();
282
313
  }
283
- if (!r.hasFramework()) try {
284
- const sourceRoot = options?.sourceRoot ?? resolveBundledPackageRoot();
314
+ if (initTarget.dedicatedTreeRepo) try {
315
+ const resolvedSourceRoot = resolveSourceRoot();
316
+ if (!sourceRepo.hasCurrentInstalledSkill()) {
317
+ console.log("Installing the first-tree skill into the source/workspace repo...");
318
+ installSkill(resolvedSourceRoot, sourceRepo.root);
319
+ }
320
+ const changedFiles = upsertSourceIntegrationFiles(sourceRepo.root, r.repoName()).filter((update) => update.action !== "unchanged").map((update) => update.file);
321
+ if (changedFiles.length > 0) console.log(` Updated source/workspace instructions in ${changedFiles.map((file) => `\`${file}\``).join(" and ")}`);
322
+ else console.log(` Source/workspace instructions already contain ${SOURCE_INTEGRATION_MARKER}`);
323
+ console.log();
324
+ } catch (err) {
325
+ const message = err instanceof Error ? err.message : "unknown error";
326
+ console.error(`Error: ${message}`);
327
+ return 1;
328
+ }
329
+ if (!r.hasCurrentInstalledSkill()) try {
330
+ const resolvedSourceRoot = resolveSourceRoot();
285
331
  console.log("Installing the framework skill bundled with this first-tree package...");
286
332
  console.log("Installing skill and scaffolding...");
287
- installSkill(sourceRoot, r.root);
333
+ installSkill(resolvedSourceRoot, r.root);
288
334
  renderTemplates(r.root);
289
335
  console.log();
290
336
  } catch (err) {
@@ -0,0 +1,10 @@
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 source/workspace Git repository, or an already-created dedicated tree repo\n- Node.js 18+\n- The npm package is `first-tree`, the installed CLI command is\n `context-tree`.\n- `context-tree init` installs the framework skill into\n `.agents/skills/first-tree/` and `.claude/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\nRecommended workflow: run `context-tree init` from your source or workspace repo.\nThe CLI will install the bundled skill in the current repo, update root\n`AGENTS.md` and `CLAUDE.md` with a `FIRST-TREE-SOURCE-INTEGRATION:` line, and\ncreate a sibling dedicated tree repo named `<repo>-context` by default. Tree\nfiles are scaffolded only in the dedicated tree repo.\n\n```bash\ncd my-org\ncontext-tree init\ncd ../my-org-context\n```\n\nIf you already created a dedicated tree repo manually, initialize it in place:\n\n```bash\nmkdir my-org-context && cd my-org-context\ngit init\ncontext-tree init --here\n```\n\nEither way, the framework installs into `.agents/skills/first-tree/` and\n`.claude/skills/first-tree/`, renders scaffolding (`NODE.md`, `AGENTS.md`,\n`members/NODE.md`), and generates a task list in\n`.agents/skills/first-tree/progress.md`.\n\nPublishing tip: keep the tree repo in the same GitHub organization as the\nsource repo unless you have a reason not to.\n\nHard boundary: do **not** create `NODE.md`, `members/`, or tree-scoped\n`AGENTS.md` in the source/workspace repo. Those files belong only in the\ndedicated `*-context` repo.\n\nDefault agent workflow after initialization:\n\n1. Create and push the dedicated `*-context` repo in the same GitHub\n organization as the source repo.\n2. Add the dedicated tree repo back to the source/workspace repo as a `git submodule`.\n3. Open a PR against the source/workspace repo's default branch for the local\n skill integration plus the new submodule pointer. Do not merge it\n automatically.\n\n### Step 2: Work Through the Task List\n\nRead `.agents/skills/first-tree/progress.md`. It contains a checklist tailored\nto 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 `AGENTS.md` below the framework markers\n- Create member nodes under `members/`\n- Optionally configure agent integration (for Claude Code, the installed hook\n assets live under `.claude/skills/first-tree/`)\n- Copy validation workflows from\n `.agents/skills/first-tree/assets/framework/workflows/` to\n `.github/workflows/`\n\nAs you complete each task, check it off in\n`.agents/skills/first-tree/progress.md` by changing `- [ ]` to `- [x]`.\n\n### Step 3: Verify\n\n```bash\ncontext-tree verify\n```\n\nOr, from your source/workspace repo:\n\n```bash\ncontext-tree verify --tree-path ../my-org-context\n```\n\nThis fails if any items in `.agents/skills/first-tree/progress.md` remain\nunchecked, and runs deterministic checks (valid frontmatter, node structure,\nmember nodes exist).\n\nDo not run `context-tree verify` in the source/workspace repo itself. That repo\nonly carries the installed skill plus the\n`FIRST-TREE-SOURCE-INTEGRATION:` line.\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` | Install local source/workspace integration and 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. |\n| `context-tree verify` | Check the installed progress file for unchecked items + run deterministic validation. Use `--tree-path` when invoking from another working directory. |\n| `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. |\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 `.agents/skills/first-tree/` and\n`.claude/skills/first-tree/` from the skill bundled with the currently running\n`first-tree` npm package, preserves your tree content, and generates follow-up\ntasks in `.agents/skills/first-tree/progress.md`.\n\nIf you run `context-tree upgrade` in the source/workspace repo, it refreshes\nonly the local installed skill plus the `FIRST-TREE-SOURCE-INTEGRATION:` lines.\nRun `context-tree upgrade --tree-path ../my-org-context` to upgrade the\ndedicated tree repo itself.\n\nIf your repo still uses the older `skills/first-tree/`,\n`skills/first-tree-cli-framework/`, or `.context-tree/` layouts,\n`context-tree upgrade` will migrate it to the current installed layout 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- `.agents/skills/first-tree/references/principles.md` — Core principles with detailed examples\n- `.agents/skills/first-tree/references/source-workspace-installation.md` — Source/workspace install contract\n- `.agents/skills/first-tree/references/ownership-and-naming.md` — How nodes are named and owned\n- `AGENTS.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 };
@@ -0,0 +1,2 @@
1
+ import { t as runOnboarding } from "./onboarding-D7fGGOMN.js";
2
+ export { runOnboarding };
@@ -2,7 +2,10 @@ import { existsSync, readFileSync, readdirSync, statSync } from "node:fs";
2
2
  import { basename, dirname, join, resolve } from "node:path";
3
3
  //#region skills/first-tree/engine/runtime/asset-loader.ts
4
4
  const SKILL_NAME = "first-tree";
5
- const SKILL_ROOT = join("skills", SKILL_NAME);
5
+ const BUNDLED_SKILL_ROOT = join("skills", SKILL_NAME);
6
+ const SKILL_ROOT = join(".agents", "skills", SKILL_NAME);
7
+ const CLAUDE_SKILL_ROOT = join(".claude", "skills", SKILL_NAME);
8
+ const INSTALLED_SKILL_ROOTS = [SKILL_ROOT, CLAUDE_SKILL_ROOT];
6
9
  join(SKILL_ROOT, "agents");
7
10
  join(SKILL_ROOT, "references");
8
11
  const FRAMEWORK_ASSET_ROOT = join(SKILL_ROOT, "assets", "framework");
@@ -17,6 +20,32 @@ const INSTALLED_PROGRESS = join(SKILL_ROOT, "progress.md");
17
20
  const AGENT_INSTRUCTIONS_FILE = "AGENTS.md";
18
21
  const LEGACY_AGENT_INSTRUCTIONS_FILE = "AGENT.md";
19
22
  const AGENT_INSTRUCTIONS_TEMPLATE = "agents.md.template";
23
+ const CLAUDE_INSTRUCTIONS_FILE = "CLAUDE.md";
24
+ const SOURCE_INTEGRATION_MARKER = "FIRST-TREE-SOURCE-INTEGRATION:";
25
+ const SOURCE_INTEGRATION_FILES = [AGENT_INSTRUCTIONS_FILE, CLAUDE_INSTRUCTIONS_FILE];
26
+ join(CLAUDE_SKILL_ROOT, "agents");
27
+ join(CLAUDE_SKILL_ROOT, "references");
28
+ const CLAUDE_FRAMEWORK_ASSET_ROOT = join(CLAUDE_SKILL_ROOT, "assets", "framework");
29
+ join(CLAUDE_FRAMEWORK_ASSET_ROOT, "manifest.json");
30
+ const CLAUDE_FRAMEWORK_VERSION = join(CLAUDE_FRAMEWORK_ASSET_ROOT, "VERSION");
31
+ join(CLAUDE_FRAMEWORK_ASSET_ROOT, "templates");
32
+ join(CLAUDE_FRAMEWORK_ASSET_ROOT, "workflows");
33
+ join(CLAUDE_FRAMEWORK_ASSET_ROOT, "prompts");
34
+ const CLAUDE_FRAMEWORK_EXAMPLES_DIR = join(CLAUDE_FRAMEWORK_ASSET_ROOT, "examples");
35
+ join(CLAUDE_FRAMEWORK_ASSET_ROOT, "helpers");
36
+ const CLAUDE_INSTALLED_PROGRESS = join(CLAUDE_SKILL_ROOT, "progress.md");
37
+ const LEGACY_REPO_SKILL_ROOT = join("skills", SKILL_NAME);
38
+ join(LEGACY_REPO_SKILL_ROOT, "agents");
39
+ join(LEGACY_REPO_SKILL_ROOT, "references");
40
+ const LEGACY_REPO_SKILL_ASSET_ROOT = join(LEGACY_REPO_SKILL_ROOT, "assets", "framework");
41
+ join(LEGACY_REPO_SKILL_ASSET_ROOT, "manifest.json");
42
+ const LEGACY_REPO_SKILL_VERSION = join(LEGACY_REPO_SKILL_ASSET_ROOT, "VERSION");
43
+ join(LEGACY_REPO_SKILL_ASSET_ROOT, "templates");
44
+ join(LEGACY_REPO_SKILL_ASSET_ROOT, "workflows");
45
+ join(LEGACY_REPO_SKILL_ASSET_ROOT, "prompts");
46
+ const LEGACY_REPO_SKILL_EXAMPLES_DIR = join(LEGACY_REPO_SKILL_ASSET_ROOT, "examples");
47
+ join(LEGACY_REPO_SKILL_ASSET_ROOT, "helpers");
48
+ const LEGACY_REPO_SKILL_PROGRESS = join(LEGACY_REPO_SKILL_ROOT, "progress.md");
20
49
  const LEGACY_SKILL_NAME = "first-tree-cli-framework";
21
50
  const LEGACY_SKILL_ROOT = join("skills", LEGACY_SKILL_NAME);
22
51
  const LEGACY_SKILL_ASSET_ROOT = join(LEGACY_SKILL_ROOT, "assets", "framework");
@@ -24,7 +53,7 @@ const LEGACY_SKILL_VERSION = join(LEGACY_SKILL_ASSET_ROOT, "VERSION");
24
53
  join(LEGACY_SKILL_ASSET_ROOT, "templates");
25
54
  join(LEGACY_SKILL_ASSET_ROOT, "workflows");
26
55
  join(LEGACY_SKILL_ASSET_ROOT, "prompts");
27
- join(LEGACY_SKILL_ASSET_ROOT, "examples");
56
+ const LEGACY_SKILL_EXAMPLES_DIR = join(LEGACY_SKILL_ASSET_ROOT, "examples");
28
57
  const LEGACY_SKILL_PROGRESS = join(LEGACY_SKILL_ROOT, "progress.md");
29
58
  const LEGACY_FRAMEWORK_ROOT = ".context-tree";
30
59
  const LEGACY_VERSION = join(LEGACY_FRAMEWORK_ROOT, "VERSION");
@@ -32,7 +61,7 @@ const LEGACY_PROGRESS = join(LEGACY_FRAMEWORK_ROOT, "progress.md");
32
61
  join(LEGACY_FRAMEWORK_ROOT, "templates");
33
62
  join(LEGACY_FRAMEWORK_ROOT, "workflows");
34
63
  join(LEGACY_FRAMEWORK_ROOT, "prompts");
35
- join(LEGACY_FRAMEWORK_ROOT, "examples");
64
+ const LEGACY_EXAMPLES_DIR = join(LEGACY_FRAMEWORK_ROOT, "examples");
36
65
  function pathExists(root, relPath) {
37
66
  const fullPath = join(root, relPath);
38
67
  try {
@@ -41,9 +70,17 @@ function pathExists(root, relPath) {
41
70
  return false;
42
71
  }
43
72
  }
73
+ function installedSkillRoots() {
74
+ return [...INSTALLED_SKILL_ROOTS];
75
+ }
76
+ function installedSkillRootsDisplay() {
77
+ return installedSkillRoots().map((root) => `\`${root}/\``).join(" and ");
78
+ }
44
79
  function frameworkVersionCandidates() {
45
80
  return [
46
81
  FRAMEWORK_VERSION,
82
+ CLAUDE_FRAMEWORK_VERSION,
83
+ LEGACY_REPO_SKILL_VERSION,
47
84
  LEGACY_SKILL_VERSION,
48
85
  LEGACY_VERSION
49
86
  ];
@@ -51,6 +88,8 @@ function frameworkVersionCandidates() {
51
88
  function progressFileCandidates() {
52
89
  return [
53
90
  INSTALLED_PROGRESS,
91
+ CLAUDE_INSTALLED_PROGRESS,
92
+ LEGACY_REPO_SKILL_PROGRESS,
54
93
  LEGACY_SKILL_PROGRESS,
55
94
  LEGACY_PROGRESS
56
95
  ];
@@ -64,6 +103,8 @@ function resolveFirstExistingPath(root, candidates) {
64
103
  }
65
104
  function detectFrameworkLayout(root) {
66
105
  if (pathExists(root, FRAMEWORK_VERSION)) return "skill";
106
+ if (pathExists(root, CLAUDE_FRAMEWORK_VERSION)) return "claude-skill";
107
+ if (pathExists(root, LEGACY_REPO_SKILL_VERSION)) return "legacy-repo-skill";
67
108
  if (pathExists(root, LEGACY_SKILL_VERSION)) return "legacy-skill";
68
109
  if (pathExists(root, LEGACY_VERSION)) return "legacy";
69
110
  return null;
@@ -74,7 +115,9 @@ const FRONTMATTER_RE = /^---\s*\n(.*?)\n---/s;
74
115
  const OWNERS_RE = /^owners:\s*\[([^\]]*)\]/m;
75
116
  const TITLE_RE = /^title:\s*['"]?(.+?)['"]?\s*$/m;
76
117
  const EMPTY_REPO_ENTRY_ALLOWLIST = new Set([
118
+ ".agents",
77
119
  ".DS_Store",
120
+ ".claude",
78
121
  ".editorconfig",
79
122
  ".gitattributes",
80
123
  ".github",
@@ -188,6 +231,15 @@ var Repo = class {
188
231
  anyAgentConfig() {
189
232
  return [".claude/settings.json", ".codex/config.json"].some((c) => this.pathExists(c));
190
233
  }
234
+ installedSkillRoots() {
235
+ return installedSkillRoots();
236
+ }
237
+ missingInstalledSkillRoots() {
238
+ return this.installedSkillRoots().filter((root) => !this.pathExists(join(root, "SKILL.md")) || !this.pathExists(join(root, "assets", "framework", "VERSION")));
239
+ }
240
+ hasCurrentInstalledSkill() {
241
+ return this.missingInstalledSkillRoots().length === 0;
242
+ }
191
243
  isGitRepo() {
192
244
  return hasGitMetadata(this.root);
193
245
  }
@@ -210,12 +262,16 @@ var Repo = class {
210
262
  const layout = this.frameworkLayout();
211
263
  if (layout === "legacy") return LEGACY_PROGRESS;
212
264
  if (layout === "legacy-skill") return LEGACY_SKILL_PROGRESS;
265
+ if (layout === "legacy-repo-skill") return LEGACY_REPO_SKILL_PROGRESS;
266
+ if (layout === "claude-skill") return CLAUDE_INSTALLED_PROGRESS;
213
267
  return INSTALLED_PROGRESS;
214
268
  }
215
269
  frameworkVersionPath() {
216
270
  const layout = this.frameworkLayout();
217
271
  if (layout === "legacy") return LEGACY_VERSION;
218
272
  if (layout === "legacy-skill") return LEGACY_SKILL_VERSION;
273
+ if (layout === "legacy-repo-skill") return LEGACY_REPO_SKILL_VERSION;
274
+ if (layout === "claude-skill") return CLAUDE_FRAMEWORK_VERSION;
219
275
  return FRAMEWORK_VERSION;
220
276
  }
221
277
  agentInstructionsPath() {
@@ -240,6 +296,15 @@ var Repo = class {
240
296
  if (text === null) return false;
241
297
  return text.includes("<!-- BEGIN CONTEXT-TREE FRAMEWORK") && text.includes("<!-- END CONTEXT-TREE FRAMEWORK -->");
242
298
  }
299
+ hasSourceIntegrationFile(relPath) {
300
+ return this.fileContains(relPath, SOURCE_INTEGRATION_MARKER);
301
+ }
302
+ hasSourceWorkspaceIntegration() {
303
+ return SOURCE_INTEGRATION_FILES.some((file) => this.hasSourceIntegrationFile(file));
304
+ }
305
+ hasTreeContent() {
306
+ return this.progressPath() !== null || this.hasAgentInstructionsMarkers() || this.pathExists("members/NODE.md") || this.frontmatter("NODE.md") !== null;
307
+ }
243
308
  hasMembers() {
244
309
  const membersDir = join(this.root, "members");
245
310
  try {
@@ -287,13 +352,19 @@ var Repo = class {
287
352
  }
288
353
  looksLikeTreeRepo() {
289
354
  if (this.pathExists("package.json") && this.pathExists("src/cli.ts") && this.pathExists("skills/first-tree/SKILL.md") && this.progressPath() === null && this.frontmatter("NODE.md") === null && !this.hasAgentInstructionsMarkers() && !this.pathExists("members/NODE.md")) return false;
290
- return this.progressPath() !== null || this.hasFramework() || this.hasAgentInstructionsMarkers() || this.pathExists("members/NODE.md") || this.frontmatter("NODE.md") !== null;
355
+ if (this.hasTreeContent()) return true;
356
+ if (this.hasFramework() && this.hasSourceWorkspaceIntegration()) return false;
357
+ if (this.hasFramework()) return !this.hasLikelySourceRepoSignals();
358
+ return false;
291
359
  }
292
360
  isLikelyEmptyRepo() {
293
361
  return this.topLevelEntries().filter((entry) => !EMPTY_REPO_ENTRY_ALLOWLIST.has(entry)).length === 0;
294
362
  }
295
363
  isLikelySourceRepo() {
296
364
  if (this.looksLikeTreeRepo()) return false;
365
+ return this.hasLikelySourceRepoSignals();
366
+ }
367
+ hasLikelySourceRepoSignals() {
297
368
  const entries = this.topLevelEntries().filter((entry) => !EMPTY_REPO_ENTRY_ALLOWLIST.has(entry));
298
369
  if (entries.length === 0) return false;
299
370
  let directoryCount = 0;
@@ -315,4 +386,4 @@ function isDirectory(root, relPath) {
315
386
  }
316
387
  }
317
388
  //#endregion
318
- export { FRAMEWORK_ASSET_ROOT as a, FRAMEWORK_VERSION as c, LEGACY_AGENT_INSTRUCTIONS_FILE as d, LEGACY_FRAMEWORK_ROOT as f, SKILL_ROOT as g, SKILL_NAME as h, AGENT_INSTRUCTIONS_TEMPLATE as i, FRAMEWORK_WORKFLOWS_DIR as l, LEGACY_SKILL_ROOT as m, Repo as n, FRAMEWORK_EXAMPLES_DIR as o, LEGACY_SKILL_NAME as p, AGENT_INSTRUCTIONS_FILE as r, FRAMEWORK_TEMPLATES_DIR as s, FRAMEWORK_END_MARKER as t, INSTALLED_PROGRESS as u };
389
+ export { LEGACY_SKILL_ROOT as C, SOURCE_INTEGRATION_MARKER as D, SOURCE_INTEGRATION_FILES as E, installedSkillRootsDisplay as O, LEGACY_SKILL_NAME as S, SKILL_ROOT as T, LEGACY_EXAMPLES_DIR as _, BUNDLED_SKILL_ROOT as a, LEGACY_REPO_SKILL_ROOT as b, CLAUDE_SKILL_ROOT as c, FRAMEWORK_TEMPLATES_DIR as d, FRAMEWORK_VERSION as f, LEGACY_AGENT_INSTRUCTIONS_FILE as g, INSTALLED_SKILL_ROOTS as h, AGENT_INSTRUCTIONS_TEMPLATE as i, FRAMEWORK_ASSET_ROOT as l, INSTALLED_PROGRESS as m, Repo as n, CLAUDE_FRAMEWORK_EXAMPLES_DIR as o, FRAMEWORK_WORKFLOWS_DIR as p, AGENT_INSTRUCTIONS_FILE as r, CLAUDE_INSTRUCTIONS_FILE as s, FRAMEWORK_END_MARKER as t, FRAMEWORK_EXAMPLES_DIR as u, LEGACY_FRAMEWORK_ROOT as v, SKILL_NAME as w, LEGACY_SKILL_EXAMPLES_DIR as x, LEGACY_REPO_SKILL_EXAMPLES_DIR as y };
@@ -0,0 +1,84 @@
1
+ import { C as LEGACY_SKILL_ROOT, D as SOURCE_INTEGRATION_MARKER, E as SOURCE_INTEGRATION_FILES, a as BUNDLED_SKILL_ROOT, b as LEGACY_REPO_SKILL_ROOT, h as INSTALLED_SKILL_ROOTS } from "./repo-Cc5U4DWT.js";
2
+ import { copyFileSync, cpSync, existsSync, mkdirSync, readFileSync, rmSync, writeFileSync } from "node:fs";
3
+ import { fileURLToPath } from "node:url";
4
+ import { dirname, join } from "node:path";
5
+ //#region skills/first-tree/engine/runtime/installer.ts
6
+ function resolveBundledPackageRoot(startUrl = import.meta.url) {
7
+ let dir = dirname(fileURLToPath(startUrl));
8
+ while (true) {
9
+ if (existsSync(join(dir, "package.json")) && existsSync(join(dir, BUNDLED_SKILL_ROOT, "SKILL.md"))) return dir;
10
+ const parent = dirname(dir);
11
+ if (parent === dir) break;
12
+ dir = parent;
13
+ }
14
+ throw new Error("Could not locate the bundled `first-tree` package root. Reinstall the package and try again.");
15
+ }
16
+ function resolveCanonicalSkillRoot(sourceRoot) {
17
+ const directSkillRoot = sourceRoot;
18
+ if (existsSync(join(directSkillRoot, "SKILL.md")) && existsSync(join(directSkillRoot, "assets", "framework", "VERSION"))) return directSkillRoot;
19
+ const nestedSkillRoot = join(sourceRoot, BUNDLED_SKILL_ROOT);
20
+ if (existsSync(join(nestedSkillRoot, "SKILL.md")) && existsSync(join(nestedSkillRoot, "assets", "framework", "VERSION"))) return nestedSkillRoot;
21
+ throw new Error(`Canonical skill not found under ${sourceRoot}. Reinstall the \`first-tree\` package and try again.`);
22
+ }
23
+ function copyCanonicalSkill(sourceRoot, targetRoot) {
24
+ const src = resolveCanonicalSkillRoot(sourceRoot);
25
+ for (const relPath of [
26
+ ...INSTALLED_SKILL_ROOTS,
27
+ LEGACY_REPO_SKILL_ROOT,
28
+ LEGACY_SKILL_ROOT
29
+ ]) {
30
+ const fullPath = join(targetRoot, relPath);
31
+ if (existsSync(fullPath)) rmSync(fullPath, {
32
+ recursive: true,
33
+ force: true
34
+ });
35
+ }
36
+ for (const relPath of INSTALLED_SKILL_ROOTS) {
37
+ const dst = join(targetRoot, relPath);
38
+ mkdirSync(dirname(dst), { recursive: true });
39
+ cpSync(src, dst, { recursive: true });
40
+ }
41
+ }
42
+ function renderTemplateFile(frameworkRoot, templateName, targetRoot, targetPath) {
43
+ const src = join(frameworkRoot, "templates", templateName);
44
+ const dst = join(targetRoot, targetPath);
45
+ if (existsSync(dst) || !existsSync(src)) return false;
46
+ mkdirSync(dirname(dst), { recursive: true });
47
+ copyFileSync(src, dst);
48
+ return true;
49
+ }
50
+ //#endregion
51
+ //#region skills/first-tree/engine/runtime/source-integration.ts
52
+ function buildSourceIntegrationLine(treeRepoName) {
53
+ return `${SOURCE_INTEGRATION_MARKER} Use the installed \`first-tree\` skill here; keep all Context Tree files only in the sibling dedicated \`${treeRepoName}\` repo/submodule and update that tree when decisions or constraints change.`;
54
+ }
55
+ function upsertSourceIntegrationFiles(root, treeRepoName) {
56
+ return SOURCE_INTEGRATION_FILES.map((file) => upsertSourceIntegrationFile(root, file, treeRepoName));
57
+ }
58
+ function upsertSourceIntegrationFile(root, file, treeRepoName) {
59
+ const fullPath = join(root, file);
60
+ const exists = existsSync(fullPath);
61
+ const nextLine = buildSourceIntegrationLine(treeRepoName);
62
+ const normalized = (exists ? readFileSync(fullPath, "utf-8") : null)?.replaceAll("\r\n", "\n") ?? "";
63
+ const lines = normalized === "" ? [] : normalized.split("\n");
64
+ const markerIndex = lines.findIndex((line) => line.startsWith(SOURCE_INTEGRATION_MARKER));
65
+ if (markerIndex >= 0) {
66
+ if (lines[markerIndex] === nextLine) return {
67
+ action: "unchanged",
68
+ file
69
+ };
70
+ lines[markerIndex] = nextLine;
71
+ } else {
72
+ if (lines.length > 0 && lines.at(-1) !== "") lines.push("");
73
+ lines.push(nextLine);
74
+ }
75
+ let nextText = lines.join("\n");
76
+ if (nextText !== "" && !nextText.endsWith("\n")) nextText += "\n";
77
+ writeFileSync(fullPath, nextText);
78
+ return {
79
+ action: exists ? "updated" : "created",
80
+ file
81
+ };
82
+ }
83
+ //#endregion
84
+ export { resolveCanonicalSkillRoot as a, resolveBundledPackageRoot as i, copyCanonicalSkill as n, renderTemplateFile as r, upsertSourceIntegrationFiles as t };