Skip to content

Commit 3911abf

Browse files
refactor(agents): extract agents-template-path leaf module (#136)
Break application ↔ agents-init import cycle by moving resolveAgentsTemplateDir to a leaf module. Re-export preserved; docs + boundary verification kit added.
1 parent c4b4b36 commit 3911abf

7 files changed

Lines changed: 72 additions & 37 deletions

File tree

docs/agents.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,7 @@ Warning goes to stderr only so `codemap skill > file.md` stays clean.
170170

171171
| Source | Role |
172172
| ------------------------------------------ | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
173+
| **`src/agents-template-path.ts`** | **`resolveAgentsTemplateDir()`** — leaf bundled `templates/agents/` resolver; shared by init and `application/*` live-fetch without import cycles. |
173174
| **`src/agents-init-targets.ts`** | **`AgentsInitTarget`** + symlink-style integration ids — shared by init and MCP registry without import cycles. |
174175
| **`src/agents-init.ts`** | **`runAgentsInit`**, **`upsertCodemapPointerFile`**, **`listRegularFilesRecursive`**, **`applyAgentsInitTargets`** (per-file **`copyFileSync`** / **`symlinkFilesGranular`**), **`ensureGitignoreCodemapPattern`** (writes `<state-dir>/.gitignore`), **`targetsNeedLinkMode`**. |
175176
| **`src/agents-init-mcp-registry.ts`** | **`AGENTS_INIT_MCP_REGISTRY`** — paths, formats, defaults, docs URLs (source of truth for the MCP table below). |

docs/architecture.md

Lines changed: 50 additions & 22 deletions
Large diffs are not rendered by default.

src/agents-init.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,12 @@ import {
1717
ensureGitignoreCodemapPattern,
1818
listRegularFilesRecursive,
1919
relPathToAbsSegments,
20-
resolveAgentsTemplateDir,
2120
runAgentsInit,
2221
targetsNeedLinkMode,
2322
upsertCodemapPointerFile,
2423
} from "./agents-init";
2524
import { CODEMAP_MCP_PERMISSION_ALLOW } from "./agents-init-mcp";
25+
import { resolveAgentsTemplateDir } from "./agents-template-path";
2626
import {
2727
buildHookBlock,
2828
isCodemapHookInstalled,

src/agents-init.ts

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -10,25 +10,15 @@ import {
1010
writeFileSync,
1111
} from "node:fs";
1212
import { dirname, join, relative } from "node:path";
13-
import { fileURLToPath } from "node:url";
1413

1514
import { applyAgentsInitMcp } from "./agents-init-mcp";
1615
import { resolveAgentsInitMcpTargets } from "./agents-init-mcp-registry";
1716
import type { AgentsInitTarget } from "./agents-init-targets";
17+
import { resolveAgentsTemplateDir } from "./agents-template-path";
1818
import { installGitHooks, uninstallGitHooks } from "./application/git-hooks";
1919
import { ensureStateGitignore, resolveStateDir } from "./application/state-dir";
2020

21-
/**
22-
* Directory containing `rules/` and `skills/` (next to `dist/` in published packages).
23-
*/
24-
export function resolveAgentsTemplateDir(): string {
25-
return join(
26-
dirname(fileURLToPath(import.meta.url)),
27-
"..",
28-
"templates",
29-
"agents",
30-
);
31-
}
21+
export { resolveAgentsTemplateDir } from "./agents-template-path";
3222

3323
/**
3424
* Every regular file path under `dir` relative to `dir` (POSIX-style `/`).

src/agents-template-path.ts

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import { dirname, join } from "node:path";
2+
import { fileURLToPath } from "node:url";
3+
4+
/**
5+
* Bundled `templates/agents/` path — shared by `agents init` and
6+
* `application/*` live-fetch surfaces. Leaf module avoids
7+
* `application → agents-init → application` import cycles.
8+
*/
9+
export function resolveAgentsTemplateDir(): string {
10+
return join(
11+
dirname(fileURLToPath(import.meta.url)),
12+
"..",
13+
"templates",
14+
"agents",
15+
);
16+
}

src/application/agent-content.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
import { existsSync, readdirSync, readFileSync } from "node:fs";
1717
import { join } from "node:path";
1818

19-
import { resolveAgentsTemplateDir } from "../agents-init";
19+
import { resolveAgentsTemplateDir } from "../agents-template-path";
2020
import { createTables } from "../db";
2121
import { openCodemapDatabase } from "../sqlite-db";
2222
import { listQueryRecipeCatalog } from "./query-recipes";

src/application/query-recipes.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { existsSync, statSync } from "node:fs";
22
import { join } from "node:path";
33

4-
import { resolveAgentsTemplateDir } from "../agents-init";
4+
import { resolveAgentsTemplateDir } from "../agents-template-path";
55
import { getProjectRoot, getStateDir } from "../runtime";
66
import { loadAllRecipes } from "./recipes-loader";
77
import type { LoadedRecipe } from "./recipes-loader";

0 commit comments

Comments
 (0)