@warpgogol/forge 6.3.1 → 6.3.3

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 (98) hide show
  1. package/CHANGELOG.md +162 -0
  2. package/bin/cli.js +13 -2
  3. package/dist/os/compass/handlers/compass-docs-scaffold.d.ts.map +1 -1
  4. package/dist/os/compass/handlers/compass-docs-scaffold.js +26 -3
  5. package/dist/os/compass/handlers/compass-docs-scaffold.js.map +1 -1
  6. package/dist/os/core/core.module.d.ts.map +1 -1
  7. package/dist/os/core/core.module.js +6 -8
  8. package/dist/os/core/core.module.js.map +1 -1
  9. package/dist/os/core/handlers/package-health.d.ts.map +1 -1
  10. package/dist/os/core/handlers/package-health.js +178 -4
  11. package/dist/os/core/handlers/package-health.js.map +1 -1
  12. package/dist/src/onboarding/agents-generate.d.ts +2 -0
  13. package/dist/src/onboarding/agents-generate.d.ts.map +1 -1
  14. package/dist/src/onboarding/agents-generate.js +46 -38
  15. package/dist/src/onboarding/agents-generate.js.map +1 -1
  16. package/dist/src/onboarding/compass-docs/semantic-layer-block.d.ts +40 -0
  17. package/dist/src/onboarding/compass-docs/semantic-layer-block.d.ts.map +1 -0
  18. package/dist/src/onboarding/compass-docs/semantic-layer-block.js +116 -0
  19. package/dist/src/onboarding/compass-docs/semantic-layer-block.js.map +1 -0
  20. package/dist/src/onboarding/doctor.d.ts.map +1 -1
  21. package/dist/src/onboarding/doctor.js +72 -33
  22. package/dist/src/onboarding/doctor.js.map +1 -1
  23. package/dist/src/onboarding/init.d.ts.map +1 -1
  24. package/dist/src/onboarding/init.js +35 -4
  25. package/dist/src/onboarding/init.js.map +1 -1
  26. package/dist/src/onboarding/nested-agents-generate.d.ts +2 -0
  27. package/dist/src/onboarding/nested-agents-generate.d.ts.map +1 -1
  28. package/dist/src/onboarding/nested-agents-generate.js +31 -6
  29. package/dist/src/onboarding/nested-agents-generate.js.map +1 -1
  30. package/dist/src/onboarding/nested-agents-templates.d.ts +6 -1
  31. package/dist/src/onboarding/nested-agents-templates.d.ts.map +1 -1
  32. package/dist/src/onboarding/nested-agents-templates.js +20 -5
  33. package/dist/src/onboarding/nested-agents-templates.js.map +1 -1
  34. package/dist/src/onboarding/prettierignore.d.ts +8 -2
  35. package/dist/src/onboarding/prettierignore.d.ts.map +1 -1
  36. package/dist/src/onboarding/prettierignore.js +36 -4
  37. package/dist/src/onboarding/prettierignore.js.map +1 -1
  38. package/dist/src/onboarding/skill-markers.d.ts +1 -0
  39. package/dist/src/onboarding/skill-markers.d.ts.map +1 -1
  40. package/dist/src/onboarding/skill-markers.js +1 -1
  41. package/dist/src/onboarding/skill-markers.js.map +1 -1
  42. package/dist/src/onboarding/upgrade.d.ts +4 -0
  43. package/dist/src/onboarding/upgrade.d.ts.map +1 -1
  44. package/dist/src/onboarding/upgrade.js +73 -9
  45. package/dist/src/onboarding/upgrade.js.map +1 -1
  46. package/dist/src/onboarding/workspace-discovery.d.ts +9 -0
  47. package/dist/src/onboarding/workspace-discovery.d.ts.map +1 -1
  48. package/dist/src/onboarding/workspace-discovery.js +30 -0
  49. package/dist/src/onboarding/workspace-discovery.js.map +1 -1
  50. package/dist/src/utils/generated-marker.d.ts.map +1 -1
  51. package/dist/src/utils/generated-marker.js +14 -6
  52. package/dist/src/utils/generated-marker.js.map +1 -1
  53. package/docs/reference/cli.md +1 -1
  54. package/docs/reference/compass-docs.md +57 -39
  55. package/os/compass/handlers/compass-docs-scaffold.ts +26 -3
  56. package/os/core/core.module.ts +6 -8
  57. package/os/core/docs-archive.test.ts +2 -5
  58. package/os/core/handlers/package-health.test.ts +199 -3
  59. package/os/core/handlers/package-health.ts +188 -4
  60. package/os/rfc/verification-emit.test.ts +1 -1
  61. package/os/rfc/verification-refresh.test.ts +1 -1
  62. package/os/spec/spec-validate.test.ts +4 -4
  63. package/package.json +2 -2
  64. package/profiles/forge-shell.yaml +5 -14
  65. package/profiles/godot-game.yaml +5 -14
  66. package/profiles/phaser-game.yaml +5 -14
  67. package/profiles/typescript.yaml +5 -14
  68. package/skills/fo/fo-handoff/SKILL.md +5 -4
  69. package/skills/fo/fo-step-commit/SKILL.md +4 -1
  70. package/src/onboarding/agents-generate.ts +49 -42
  71. package/src/onboarding/compass-docs/semantic-layer-block.test.ts +137 -0
  72. package/src/onboarding/compass-docs/semantic-layer-block.ts +132 -0
  73. package/src/onboarding/doctor.ts +77 -31
  74. package/src/onboarding/init.ts +35 -4
  75. package/src/onboarding/nested-agents-generate.ts +40 -6
  76. package/src/onboarding/nested-agents-templates.ts +25 -5
  77. package/src/onboarding/prettierignore.ts +45 -2
  78. package/src/onboarding/skill-markers.ts +5 -1
  79. package/src/onboarding/templates/behavioral-layer-core.md +2 -0
  80. package/src/onboarding/templates/root-agents-business.md +1 -0
  81. package/src/onboarding/templates/root-agents-creative.md +1 -0
  82. package/src/onboarding/upgrade.ts +122 -11
  83. package/src/onboarding/workspace-discovery.ts +33 -0
  84. package/src/tests/agents-generate.test.ts +128 -0
  85. package/src/tests/bindings-schema.test.ts +1 -0
  86. package/src/tests/compass-docs-flag.test.ts +2 -0
  87. package/src/tests/compass-docs-scaffold.test.ts +67 -0
  88. package/src/tests/doctor-version-sync.test.ts +155 -0
  89. package/src/tests/file-size-lint.test.ts +7 -5
  90. package/src/tests/fixtures/agents-generate-business-before.txt +8 -2
  91. package/src/tests/forge-config.test.ts +2 -3
  92. package/src/tests/generated-marker.test.ts +17 -0
  93. package/src/tests/prettierignore-manage.test.ts +30 -0
  94. package/src/tests/session-handlers.test.ts +2 -2
  95. package/src/tests/session-pbt.test.ts +1 -1
  96. package/src/tests/skill-agents-sync.test.ts +25 -0
  97. package/src/tests/upgrade.test.ts +82 -1
  98. package/src/utils/generated-marker.ts +15 -6
@@ -629,26 +629,17 @@ workspace:
629
629
  - path: tools/kernel.config.ts
630
630
  content: |
631
631
  import { defineKernelConfig } from "@warpgogol/werkstatt-engine/kernel/types";
632
+ import { forgeModuleLoaders } from "@warpgogol/werkstatt-engine/kernel/module-map";
632
633
  import { werkstattGodotPlugin } from "@warpgogol/werkstatt-godot-game";
633
634
 
634
635
  export default defineKernelConfig({
635
636
  name: "__PROJECT_NAME__",
636
637
  description: "__PROJECT_NAME__ workshop",
637
638
  moduleLoaders: {
638
- "forge-core": async () => (await import("@warpgogol/forge/os/core")).forgeCoreModule,
639
- "forge-rfc": async () => (await import("@warpgogol/forge/os/rfc-module")).forgeRfcModule,
640
- "forge-adr": async () => (await import("@warpgogol/forge/os/adr-module")).forgeAdrModule,
641
- "forge-plan": async () => (await import("@warpgogol/forge/os/plan-module")).forgePlanModule,
642
- "forge-audit": async () => (await import("@warpgogol/forge/os/audit-module")).forgeAuditModule,
643
- "forge-compass": async () => (await import("@warpgogol/forge/os/compass")).forgeCompassModule,
644
- "forge-naming": async () => (await import("@warpgogol/forge/os/naming-module")).forgeNamingModule,
645
- "forge-workflow": async () => (await import("@warpgogol/forge/os/workflow-module")).forgeWorkflowModule,
646
- "forge-session": async () => (await import("@warpgogol/forge/os/session-module")).forgeSessionModule,
647
- "forge-mission": async () => (await import("@warpgogol/forge/os/mission-module")).forgeMissionModule,
648
- "forge-spec": async () => (await import("@warpgogol/forge/os/spec-module")).forgeSpecModule,
649
- "forge-exploration": async () => (await import("@warpgogol/forge/os/exploration")).forgeExplorationModule,
650
- "forge-program": async () => (await import("@warpgogol/forge/os/program")).forgeProgramModule,
651
- "forge-werkstatt": async () => (await import("@warpgogol/forge/os/werkstatt")).forgeWerkstattModule,
639
+ // Forge governance modules — single-sourced in
640
+ // @warpgogol/werkstatt-engine/kernel/module-map (WORKSHOP_MODULE_MAP.forge).
641
+ // Do not add forge loaders here; new forge modules join the map once.
642
+ ...forgeModuleLoaders(),
652
643
  mission: async () => (await import("@warpgogol/werkstatt-engine/mission-module")).createMissionModule(),
653
644
  sternsystem: async () => (await import("@warpgogol/werkstatt-engine/sternsystem-module")).createSternsystemModule(),
654
645
  bordbuch: async () => (await import("@warpgogol/werkstatt-engine/bordbuch-module")).createBordbuchModule(),
@@ -232,26 +232,17 @@ workspace:
232
232
  - path: tools/kernel.config.ts
233
233
  content: |
234
234
  import { defineKernelConfig } from "@warpgogol/werkstatt-engine/kernel/types";
235
+ import { forgeModuleLoaders } from "@warpgogol/werkstatt-engine/kernel/module-map";
235
236
  import { werkstattPhaserPlugin } from "@warpgogol/werkstatt-phaser-game";
236
237
 
237
238
  export default defineKernelConfig({
238
239
  name: "__PROJECT_NAME__",
239
240
  description: "__PROJECT_NAME__ workshop",
240
241
  moduleLoaders: {
241
- "forge-core": async () => (await import("@warpgogol/forge/os/core")).forgeCoreModule,
242
- "forge-rfc": async () => (await import("@warpgogol/forge/os/rfc-module")).forgeRfcModule,
243
- "forge-adr": async () => (await import("@warpgogol/forge/os/adr-module")).forgeAdrModule,
244
- "forge-plan": async () => (await import("@warpgogol/forge/os/plan-module")).forgePlanModule,
245
- "forge-audit": async () => (await import("@warpgogol/forge/os/audit-module")).forgeAuditModule,
246
- "forge-compass": async () => (await import("@warpgogol/forge/os/compass")).forgeCompassModule,
247
- "forge-naming": async () => (await import("@warpgogol/forge/os/naming-module")).forgeNamingModule,
248
- "forge-workflow": async () => (await import("@warpgogol/forge/os/workflow-module")).forgeWorkflowModule,
249
- "forge-session": async () => (await import("@warpgogol/forge/os/session-module")).forgeSessionModule,
250
- "forge-mission": async () => (await import("@warpgogol/forge/os/mission-module")).forgeMissionModule,
251
- "forge-spec": async () => (await import("@warpgogol/forge/os/spec-module")).forgeSpecModule,
252
- "forge-exploration": async () => (await import("@warpgogol/forge/os/exploration")).forgeExplorationModule,
253
- "forge-program": async () => (await import("@warpgogol/forge/os/program")).forgeProgramModule,
254
- "forge-werkstatt": async () => (await import("@warpgogol/forge/os/werkstatt")).forgeWerkstattModule,
242
+ // Forge governance modules — single-sourced in
243
+ // @warpgogol/werkstatt-engine/kernel/module-map (WORKSHOP_MODULE_MAP.forge).
244
+ // Do not add forge loaders here; new forge modules join the map once.
245
+ ...forgeModuleLoaders(),
255
246
  mission: async () => (await import("@warpgogol/werkstatt-engine/mission-module")).createMissionModule(),
256
247
  sternsystem: async () => (await import("@warpgogol/werkstatt-engine/sternsystem-module")).createSternsystemModule(),
257
248
  bordbuch: async () => (await import("@warpgogol/werkstatt-engine/bordbuch-module")).createBordbuchModule(),
@@ -462,25 +462,16 @@ workspace:
462
462
  - path: tools/kernel.config.ts
463
463
  content: |
464
464
  import { defineKernelConfig } from "@warpgogol/werkstatt-engine/kernel/types";
465
+ import { forgeModuleLoaders } from "@warpgogol/werkstatt-engine/kernel/module-map";
465
466
 
466
467
  export default defineKernelConfig({
467
468
  name: "__PROJECT_NAME__",
468
469
  description: "__PROJECT_NAME__ TypeScript TurboRepo workshop",
469
470
  moduleLoaders: {
470
- "forge-core": async () => (await import("@warpgogol/forge/os/core")).forgeCoreModule,
471
- "forge-rfc": async () => (await import("@warpgogol/forge/os/rfc-module")).forgeRfcModule,
472
- "forge-adr": async () => (await import("@warpgogol/forge/os/adr-module")).forgeAdrModule,
473
- "forge-plan": async () => (await import("@warpgogol/forge/os/plan-module")).forgePlanModule,
474
- "forge-audit": async () => (await import("@warpgogol/forge/os/audit-module")).forgeAuditModule,
475
- "forge-compass": async () => (await import("@warpgogol/forge/os/compass")).forgeCompassModule,
476
- "forge-naming": async () => (await import("@warpgogol/forge/os/naming-module")).forgeNamingModule,
477
- "forge-workflow": async () => (await import("@warpgogol/forge/os/workflow-module")).forgeWorkflowModule,
478
- "forge-session": async () => (await import("@warpgogol/forge/os/session-module")).forgeSessionModule,
479
- "forge-mission": async () => (await import("@warpgogol/forge/os/mission-module")).forgeMissionModule,
480
- "forge-spec": async () => (await import("@warpgogol/forge/os/spec-module")).forgeSpecModule,
481
- "forge-exploration": async () => (await import("@warpgogol/forge/os/exploration")).forgeExplorationModule,
482
- "forge-program": async () => (await import("@warpgogol/forge/os/program")).forgeProgramModule,
483
- "forge-werkstatt": async () => (await import("@warpgogol/forge/os/werkstatt")).forgeWerkstattModule,
471
+ // Forge governance modules — single-sourced in
472
+ // @warpgogol/werkstatt-engine/kernel/module-map (WORKSHOP_MODULE_MAP.forge).
473
+ // Do not add forge loaders here; new forge modules join the map once.
474
+ ...forgeModuleLoaders(),
484
475
  "typescript-checks": async () => (await import("@warpgogol/werkstatt-typescript/checks/module")).createTypescriptCheckModule(),
485
476
  },
486
477
  });
@@ -1,6 +1,6 @@
1
1
  ---
2
2
  name: fo-handoff
3
- description: Compact the current conversation into a handoff document for another agent to pick up. Saves to docs/handoffs/ (resolved from forge.yaml paths.handoffsDir) and commits via ecosystem.commit.
3
+ description: Compact the conversation into a handoff document for another agent. Saves to docs/handoffs/ (paths.handoffsDir) and commits via the project's commit command (ecosystem.commit where registered).
4
4
  invocation: user
5
5
  category: fo
6
6
  concerns: document-only
@@ -11,7 +11,7 @@ triggerPhrases: ["create a handoff document", "compact conversation for next age
11
11
 
12
12
  <!--
13
13
  <MODULE_CONTRACT>
14
- <purpose>fo-handoff skill — Compact the current conversation into a handoff document for another agent to pick up. Saves to docs/handoffs/ (resolved from forge.yaml paths.handoffsDir) and commits via ecosystem.commit.</purpose>
14
+ <purpose>fo-handoff skill — Compact the current conversation into a handoff document for another agent to pick up. Saves to docs/handoffs/ (resolved from forge.yaml paths.handoffsDir) and commits via the project's commit command (ecosystem.commit where registered).</purpose>
15
15
  <non-goals>
16
16
  <item>Do not execute skill logic — this document instructs agents; it is not runnable code.</item>
17
17
  </non-goals>
@@ -20,6 +20,7 @@ triggerPhrases: ["create a handoff document", "compact conversation for next age
20
20
  <item>RFC-1097: sweep — SKILL.md headers + classification fixes
21
21
 
22
22
  Sweep batch 1: add Compass v2 headers to 45 SKILL.md files (purpose derived from frontmatter description). Fix non-skill-markdown exclusion to check filename not workspace-relative path (packages/AGENTS.md escaped it). Add .coverage to ignoredDirs.</item>
23
+ <item>fix: commit references resolve by project type — ecosystem.commit where registered, plain git commit in forge workshops</item>
23
24
  </CHANGE_SUMMARY>
24
25
  -->
25
26
 
@@ -69,7 +70,7 @@ If the operator passed arguments, treat them as a description of what the next s
69
70
 
70
71
  ### 4. Commit
71
72
 
72
- Commit the handoff document so it survives stash operations and is available to the next session. Delegate the commit mechanics to `fo-step-commit` (it resolves the project's commit command and staging rules); where the project has no such skill, use its declared ecosystem commit command.
73
+ Commit the handoff document so it survives stash operations and is available to the next session. Delegate the commit mechanics to `fo-step-commit` (it resolves the project's commit command and staging rules); where the project has no such skill, use the commit command the project declares — `ecosystem.commit` where it is registered, plain `git commit` otherwise.
73
74
 
74
75
  ### 5. Report
75
76
 
@@ -78,7 +79,7 @@ Tell the operator the absolute path of the handoff document and suggest opening
78
79
  ## Constraints
79
80
 
80
81
  - **Save to `docs/handoffs/`** (or the directory resolved from `forge.yaml` `paths.handoffsDir`). Never save to `/tmp/` or other temporary directories.
81
- - **Commit the handoff document** after saving (via `fo-step-commit` or the project's ecosystem commit command).
82
+ - **Commit the handoff document** after saving (via `fo-step-commit` or the project's commit command — `ecosystem.commit` where registered, `git commit` otherwise).
82
83
  - **Do not duplicate existing artifacts.** Reference them by path or URL.
83
84
  - **Redact sensitive information.** API keys, passwords, PII.
84
85
  - **Stage only the handoff file.** See `_shared/fo-pipeline-conventions.md` §Commit discipline.
@@ -28,6 +28,7 @@ triggerPhrases:
28
28
 
29
29
  Sweep batch 1: add Compass v2 headers to 45 SKILL.md files (purpose derived from frontmatter description). Fix non-skill-markdown exclusion to check filename not workspace-relative path (packages/AGENTS.md escaped it). Add .coverage to ignoredDirs.</item>
30
30
  <item>RFC-1247: triggerPhrases vocabulary sync — mined operator phrasing applied to this skill's trigger set.</item>
31
+ <item>fix: step 5 resolves the commit path by project type — plain git commit in forge workshops where ecosystem.commit is not registered</item>
31
32
  </CHANGE_SUMMARY>
32
33
  -->
33
34
 
@@ -50,7 +51,9 @@ After every standalone operator request that produces file changes, perform the
50
51
  2. **Verify diff before staging.** Run `git diff` (not just `git diff --cached`) on every file the agent touched in this request, in each dirty tree. Confirm the changes are the agent's own work and not foreign changes from another session. If foreign changes are found, exclude them from staging.
51
52
  3. **Stage only agent-changed files.** Stage only the files the agent modified in this request. Never use `git add -A` or `git add .` — another agent or session may have unrelated changes in the working tree. Stage files by explicit path: `git add <path1> <path2> ...`.
52
53
  4. **Form commit message.** Write a conventional commit message (`fix:`, `feat:`, `refactor:`, `docs:`, `chore:`) based on the work performed in this request. The agent determines the type and description from the context of the request.
53
- 5. **Commit in monorepo.** Use `pnpm exec werkstatt run ecosystem.commit --message "<message>"` to commit in the werkstatt monorepo. This handles platform-scope version bumps and X-Platform-Bump trailers automatically. Stage files with `git add <paths>` first (the pre-commit hook blocks raw `git commit` for platform-scope files). For non-platform-only changes (docs/**), `ecosystem.commit` delegates to a plain `git commit` without version bump.
54
+ 5. **Commit in monorepo.** Pick the commit path by project type:
55
+ - **`ecosystem.commit` projects** — the Werkstatt platform monorepo and site-workshops that load the site check module (detect: `packages/werkstatt-site/` or `node_modules/@warpgogol/werkstatt-site/` exists): use `pnpm exec werkstatt run ecosystem.commit --message "<message>"`. It handles platform-scope version bumps and X-Platform-Bump trailers automatically. Stage files with `git add <paths>` first (the pre-commit hook blocks raw `git commit` for platform-scope files). For non-platform-only changes (docs/**), `ecosystem.commit` delegates to a plain `git commit` without version bump.
56
+ - **Forge workshops without `ecosystem.commit`** (no `werkstatt-site` in dependencies — typescript/forge-shell/knowledge profiles): run plain `git commit -m "<message>"` on the staged paths. No platform-scope gate applies.
54
57
  6. **Commit in mission workpiece (if applicable).** If the agent changed files in the active mission workpiece, commit there via `git commit` in the workpiece directory.
55
58
  7. **Verify clean trees.** After all commits, run `bash scripts/check-clean-trees.sh` again. If any tree is still dirty, report to the operator.
56
59
 
@@ -7,8 +7,6 @@
7
7
  </non-goals>
8
8
  </MODULE_CONTRACT>
9
9
  <CHANGE_SUMMARY>
10
- <item>RFC-0643: terminology substitution on final content, root template selection by register, details field in result.</item>
11
- <item>RFC-0664: added project memory layer read discipline section to generated AGENTS.md.</item>
12
10
  <item>RFC-1253: emit "Semantic layer — read first" block listing bound paths.compassDocs before the Skills table when the binding resolves non-empty.</item>
13
11
  <item>RFC-1097: step 6 — compass.migrate codemod run
14
12
 
@@ -16,7 +14,9 @@ Mechanical v1 to v2 header migration across the workspace: 942 files rewritten
16
14
  <item>RFC-1097: sweep — packages/forge + services clean
17
15
 
18
16
  Sweep batch 2: real KEY_DECISIONS on 10 files, expanded purposes (CONTRACT-02/PURPOSE-02), headers on mission/index + gen-upstreams, sanitizeItemText in summary.record (literal Compass tags corrupted history), excludedPaths for wrangler types, test-fixtures testPattern. forge+services now 0 diagnostics under --mode error.</item>
19
- <history>RFC-0391, RFC-0393, RFC-0548, RFC-0549, RFC-0551, RFC-0611, RFC-0640</history>
17
+ <item>Single blank line after the generated header — header ends in a newline so "\n\n" produced two blank lines that prettier collapsed, ping-ponging doctor's stale check. wsTypes resolution moved to shared resolveWorkspaceTypes.</item>
18
+ <item>Semantic-layer block rendered marker-wrapped via shared semantic-layer-block module and injected/refreshed inside hand-written roots carrying the sentinel or a pasted region; result gains injected[] (consumer field report follow-up to RFC-1253).</item>
19
+ <history>RFC-0391, RFC-0393, RFC-0548, RFC-0549, RFC-0551, RFC-0611, RFC-0640, RFC-0643, RFC-0664</history>
20
20
  </CHANGE_SUMMARY>
21
21
  */
22
22
 
@@ -29,9 +29,9 @@ import { resolveAllTerminology } from "../profiles/terminology-utils.ts";
29
29
  import { FORGE_SKILLS } from "../registry.ts";
30
30
  import { alignMarkdownTable, buildGeneratedHeader, hasEditableGeneratedMarker, hasGeneratedMarker, mergeEditableGenerated, writeFileIfChanged } from "../utils/index.ts";
31
31
  import { generateNestedAgentsMd } from "./nested-agents-generate.ts";
32
- import { listStackProfiles } from "../profiles/stack-profile.ts";
32
+ import { injectSemanticLayerBlock, semanticLayerLines } from "./compass-docs/semantic-layer-block.ts";
33
+ import { resolveWorkspaceTypes } from "./workspace-discovery.ts";
33
34
  import type { StackProfile } from "../profiles/stack-profile.ts";
34
- import type { ProfileWorkspaceType } from "../profiles/profile-schema.ts";
35
35
  import type {
36
36
  ForgeCommandInput,
37
37
  ForgeCommandResult,
@@ -236,6 +236,8 @@ interface AgentsGenerateResult {
236
236
  configPath: string;
237
237
  generated: string[];
238
238
  skipped: string[];
239
+ /** Hand-written files that accepted the marker-guarded semantic-layer block. */
240
+ injected: string[];
239
241
  errors: string[];
240
242
  renderedFiles?: { [relPath: string]: string };
241
243
  details?: Array<{ path: string; domain?: string; register?: string; workspaceType?: string }>;
@@ -266,6 +268,7 @@ export async function runAgentsGenerate(
266
268
  configPath: "forge.yaml",
267
269
  generated: [],
268
270
  skipped: [],
271
+ injected: [],
269
272
  errors: [msg],
270
273
  },
271
274
  exitCode: 1,
@@ -306,21 +309,15 @@ export async function runAgentsGenerate(
306
309
 
307
310
  // RFC-1253: Compass corpus read-first block — only when the binding
308
311
  // resolves non-empty (DNA-90: instructions live where agents read them).
312
+ // Marker-wrapped so hand-written files that pasted it stay refreshable.
309
313
  const compassDocsReadFirst = resolveBinding(config, "paths.compassDocs");
310
- if (Array.isArray(compassDocsReadFirst) && compassDocsReadFirst.length > 0) {
311
- dynamicLines.push("## Semantic layer — read first");
312
- dynamicLines.push("");
313
- dynamicLines.push(
314
- "This repository carries a machine-readable Compass corpus — the semantic layer that answers \u201cwhat reads X, what breaks if I change Y\u201d without a full repository re-scan. For repository-wide, cross-workspace, architectural, shared-package, or high-risk tasks, read these documents before planning or editing code:",
315
- );
316
- dynamicLines.push("");
317
- for (const doc of compassDocsReadFirst) {
318
- dynamicLines.push(`- \`${doc}\``);
319
- }
320
- dynamicLines.push("");
321
- dynamicLines.push(
322
- "Treat these XML documents as the primary semantic layer for AI work and keep them synchronized with code, architecture, and verification changes.",
323
- );
314
+ const semanticLayerDocs = (Array.isArray(compassDocsReadFirst) ? compassDocsReadFirst : []).filter(
315
+ (d): d is string => typeof d === "string",
316
+ );
317
+ const semanticLayerBlock =
318
+ semanticLayerDocs.length > 0 ? semanticLayerLines(semanticLayerDocs).join("\n") : "";
319
+ if (semanticLayerBlock) {
320
+ dynamicLines.push(semanticLayerBlock);
324
321
  dynamicLines.push("");
325
322
  }
326
323
 
@@ -408,8 +405,9 @@ export async function runAgentsGenerate(
408
405
  const dynamicSections = dynamicLines.join("\n");
409
406
  let content = replaceProjectPlaceholders(rootTemplate, config, dynamicSections);
410
407
 
411
- // Prepend generated header (above template content)
412
- content = header + "\n\n" + content;
408
+ // Prepend generated header (above template content) — header ends in a
409
+ // newline, so a single "\n" here yields the prettier-normal one blank line.
410
+ content = header + "\n" + content;
413
411
 
414
412
  // RFC-0643: Apply terminology substitution on final assembled content
415
413
  const resolvedTerminology = resolveAllTerminology(config, profile);
@@ -417,6 +415,7 @@ export async function runAgentsGenerate(
417
415
 
418
416
  const generated: string[] = [];
419
417
  const skipped: string[] = [];
418
+ const injected: string[] = [];
420
419
  const renderedFiles: { [relPath: string]: string } = {};
421
420
  const details: Array<{ path: string; domain?: string; register?: string; workspaceType?: string }> = [];
422
421
  details.push({
@@ -429,7 +428,24 @@ export async function runAgentsGenerate(
429
428
  renderedFiles["AGENTS.md"] = content;
430
429
  generated.push("AGENTS.md");
431
430
  } else if (rootSkipped) {
432
- skipped.push("AGENTS.md (hand-written)");
431
+ // Marker-guarded opt-in: a hand-written root carrying the semantic-layer
432
+ // sentinel (or a pasted marked region) gets the block refreshed —
433
+ // surrounding prose is never touched.
434
+ let rootInjected = false;
435
+ if (semanticLayerBlock) {
436
+ try {
437
+ const existing = await fio.readFile(agentsMdPath);
438
+ const injection = injectSemanticLayerBlock(existing, semanticLayerBlock);
439
+ if (injection.changed) {
440
+ await writeFileIfChanged(agentsMdPath, injection.content, fio);
441
+ rootInjected = true;
442
+ }
443
+ } catch {
444
+ // Unreadable — leave the hand-written file alone.
445
+ }
446
+ }
447
+ skipped.push(`AGENTS.md (hand-written${rootInjected ? " — semantic-layer injected" : ""})`);
448
+ if (rootInjected) injected.push("AGENTS.md");
433
449
  } else {
434
450
  // RFC-1153: merge instead of overwrite — preserve the custom tail below
435
451
  // the forge:custom boundary; fail-closed skip when no boundary resolves.
@@ -466,29 +482,19 @@ export async function runAgentsGenerate(
466
482
  }
467
483
 
468
484
  // Nested AGENTS.md generation (RFC-0611)
469
- // RFC-0640: load workspaceTypes from stack profile for profile-driven detection
470
- // RFC-0643: prefer config.profile (loaded by loadForgeConfig), fallback to stack-based lookup
471
- let workspaceTypes: ProfileWorkspaceType[] | undefined;
472
- if (profile?.workspaceTypes && profile.workspaceTypes.length > 0) {
473
- workspaceTypes = profile.workspaceTypes;
474
- } else {
475
- try {
476
- const forgeRoot = resolveForgeRoot(workspaceRoot);
477
- const profiles = listStackProfiles(forgeRoot);
478
- for (const stackId of config.project.stack) {
479
- const stackProfile = profiles.find((p) => p.id === stackId);
480
- if (stackProfile?.workspaceTypes && stackProfile.workspaceTypes.length > 0) {
481
- workspaceTypes = stackProfile.workspaceTypes;
482
- break;
483
- }
484
- }
485
- } catch {
486
- // forge root not resolvable — fallback to hardcoded detection
487
- }
485
+ // RFC-0640/RFC-0643: resolveWorkspaceTypes prefers config.profile (loaded by
486
+ // loadForgeConfig), falls back to the stack-based catalog lookup.
487
+ let forgeRootForTypes: string | undefined;
488
+ try {
489
+ forgeRootForTypes = resolveForgeRoot(workspaceRoot);
490
+ } catch {
491
+ // forge root not resolvable — fallback to hardcoded detection
488
492
  }
493
+ const workspaceTypes = resolveWorkspaceTypes(config, forgeRootForTypes);
489
494
  const nestedResult = await generateNestedAgentsMd(workspaceRoot, config, dryRun, workspaceTypes, fio);
490
495
  generated.push(...nestedResult.generated);
491
496
  skipped.push(...nestedResult.skipped);
497
+ injected.push(...nestedResult.injected);
492
498
  Object.assign(renderedFiles, nestedResult.renderedFiles);
493
499
 
494
500
  // RFC-0643: add details for nested files
@@ -516,6 +522,7 @@ export async function runAgentsGenerate(
516
522
  configPath: "forge.yaml",
517
523
  generated,
518
524
  skipped,
525
+ injected,
519
526
  errors: [],
520
527
  details,
521
528
  ...(rootSkipped ? { rootSkipped: true, rootSkipReason: "hand-written" } : {}),
@@ -524,6 +531,6 @@ export async function runAgentsGenerate(
524
531
  exitCode: 0,
525
532
  summary: dryRun
526
533
  ? `forge.agents.generate: [dry-run] would generate ${generated.length} file(s), skip ${skipped.length}`
527
- : `forge.agents.generate: OK — ${generated.length} file(s) generated, ${skipped.length} skipped${rootSkipped ? " (root AGENTS.md hand-written — skipped)" : ""}`,
534
+ : `forge.agents.generate: OK — ${generated.length} file(s) generated, ${skipped.length} skipped${injected.length > 0 ? `, ${injected.length} semantic-layer injected` : ""}${rootSkipped ? " (root AGENTS.md hand-written — skipped)" : ""}`,
528
535
  };
529
536
  }
@@ -0,0 +1,137 @@
1
+ /*
2
+ <MODULE_CONTRACT>
3
+ <purpose>
4
+ Unit tests for the shared semantic-layer block — marker-wrapped render shape
5
+ and the opt-in/refresh injection contract for hand-written AGENTS.md files
6
+ (consumer field report follow-up to RFC-1253).
7
+ </purpose>
8
+ </MODULE_CONTRACT>
9
+ */
10
+
11
+ import { describe, it, expect } from "vitest";
12
+ import {
13
+ SEMANTIC_LAYER_BEGIN,
14
+ SEMANTIC_LAYER_END,
15
+ SEMANTIC_LAYER_OPT_IN,
16
+ ensureSemanticLayerBlock,
17
+ injectSemanticLayerBlock,
18
+ semanticLayerLines,
19
+ } from "./semantic-layer-block.ts";
20
+
21
+ const DOCS = ["docs/requirements.xml", "docs/technology.xml"];
22
+
23
+ describe("semanticLayerLines", () => {
24
+ it("wraps the block in forge:begin/forge:end semantic-layer markers", () => {
25
+ const lines = semanticLayerLines(DOCS);
26
+ expect(lines[0]).toBe(SEMANTIC_LAYER_BEGIN);
27
+ expect(lines[lines.length - 1]).toBe(SEMANTIC_LAYER_END);
28
+ const text = lines.join("\n");
29
+ expect(text).toContain("## Semantic layer — read first");
30
+ expect(text).toContain("- `docs/requirements.xml`");
31
+ expect(text).toContain("- `docs/technology.xml`");
32
+ });
33
+ });
34
+
35
+ describe("injectSemanticLayerBlock", () => {
36
+ const block = semanticLayerLines(DOCS).join("\n");
37
+
38
+ it("expands the first bare opt-in sentinel into a full marked region", () => {
39
+ const source = ["# Guide", "", "Intro.", "", SEMANTIC_LAYER_OPT_IN, "", "Tail.", ""].join("\n");
40
+ const res = injectSemanticLayerBlock(source, block);
41
+ expect(res.region).toBe("expanded");
42
+ expect(res.changed).toBe(true);
43
+ expect(res.content).toContain(SEMANTIC_LAYER_BEGIN);
44
+ expect(res.content).toContain("## Semantic layer — read first");
45
+ expect(res.content).toContain("`docs/technology.xml`");
46
+ expect(res.content).not.toContain(SEMANTIC_LAYER_OPT_IN);
47
+ expect(res.content).toContain("Intro.");
48
+ expect(res.content).toContain("Tail.");
49
+ });
50
+
51
+ it("refreshes an existing region in place — stale content replaced, prose kept", () => {
52
+ const stale = [
53
+ SEMANTIC_LAYER_BEGIN,
54
+ "",
55
+ "## Semantic layer — read first",
56
+ "",
57
+ "STALE",
58
+ "",
59
+ SEMANTIC_LAYER_END,
60
+ ].join("\n");
61
+ const source = `before\n\n${stale}\n\nafter\n`;
62
+ const res = injectSemanticLayerBlock(source, block);
63
+ expect(res.region).toBe("refreshed");
64
+ expect(res.changed).toBe(true);
65
+ expect(res.content).not.toContain("STALE");
66
+ expect(res.content).toBe(`before\n\n${block}\n\nafter\n`);
67
+ });
68
+
69
+ it("is idempotent — an up-to-date region reports no change", () => {
70
+ const source = `before\n${block}\nafter\n`;
71
+ const res = injectSemanticLayerBlock(source, block);
72
+ expect(res.region).toBe("refreshed");
73
+ expect(res.changed).toBe(false);
74
+ expect(res.content).toBe(source);
75
+ });
76
+
77
+ it("leaves files without markers untouched", () => {
78
+ const source = "# Guide\n\nNo markers here.\n";
79
+ const res = injectSemanticLayerBlock(source, block);
80
+ expect(res.region).toBe("none");
81
+ expect(res.changed).toBe(false);
82
+ expect(res.content).toBe(source);
83
+ });
84
+
85
+ it("refreshes every complete region when several exist", () => {
86
+ const stale = `${SEMANTIC_LAYER_BEGIN}\nstale\n${SEMANTIC_LAYER_END}`;
87
+ const source = `${stale}\nmiddle\n${stale}\n`;
88
+ const res = injectSemanticLayerBlock(source, block);
89
+ expect(res.region).toBe("refreshed");
90
+ expect(res.content).toBe(`${block}\nmiddle\n${block}\n`);
91
+ });
92
+
93
+ it("ignores an unbalanced begin marker and still expands the opt-in sentinel", () => {
94
+ const source = `${SEMANTIC_LAYER_BEGIN}\nnever closed\n\n${SEMANTIC_LAYER_OPT_IN}\n`;
95
+ const res = injectSemanticLayerBlock(source, block);
96
+ expect(res.region).toBe("expanded");
97
+ // The dangling begin line is preserved verbatim above the new region.
98
+ expect(res.content).toBe(`${SEMANTIC_LAYER_BEGIN}\nnever closed\n\n${block}\n`);
99
+ });
100
+
101
+ it("normalizes CRLF input to LF", () => {
102
+ const source = `intro\r\n${SEMANTIC_LAYER_OPT_IN}\r\ntail\r\n`;
103
+ const res = injectSemanticLayerBlock(source, block);
104
+ expect(res.changed).toBe(true);
105
+ expect(res.content).not.toContain("\r\n");
106
+ expect(res.content).toContain(block);
107
+ });
108
+ });
109
+
110
+ describe("ensureSemanticLayerBlock", () => {
111
+ const block = semanticLayerLines(DOCS).join("\n");
112
+ const FOOTER = "See the root `AGENTS.md` for project-wide rules, skills, and capabilities.";
113
+
114
+ it("inserts the block before the footer so the footer stays last", () => {
115
+ const source = `# Guide\n\nbody\n\n${FOOTER}\n`;
116
+ const out = ensureSemanticLayerBlock(source, block, FOOTER);
117
+ expect(out.indexOf("## Semantic layer — read first")).toBeLessThan(out.indexOf(FOOTER));
118
+ expect(out.trimEnd().endsWith(FOOTER)).toBe(true);
119
+ expect(out).toContain("body");
120
+ });
121
+
122
+ it("appends the block at the end when no footer is found", () => {
123
+ const source = `# Guide\n\nbody\n`;
124
+ const out = ensureSemanticLayerBlock(source, block, FOOTER);
125
+ expect(out).toBe(`# Guide\n\nbody\n\n${block}\n`);
126
+ });
127
+
128
+ it("returns content that already carries the region unchanged", () => {
129
+ const source = `# Guide\n\n${block}\n\n${FOOTER}\n`;
130
+ expect(ensureSemanticLayerBlock(source, block, FOOTER)).toBe(source);
131
+ });
132
+
133
+ it("returns content unchanged when the block is empty", () => {
134
+ const source = `# Guide\n\n${FOOTER}\n`;
135
+ expect(ensureSemanticLayerBlock(source, "", FOOTER)).toBe(source);
136
+ });
137
+ });
@@ -0,0 +1,132 @@
1
+ /*
2
+ <MODULE_CONTRACT>
3
+ <purpose>Canonical "Semantic layer — read first" AGENTS.md block for the Compass docs corpus: one renderer shared by the generated root, nested workspace guides, and the marker-guarded injection path for hand-written AGENTS.md files. Keeps the read-first contract identical on every surface it lands on.</purpose>
4
+ <non-goals>
5
+ <item>Do not read forge.yaml, resolve bindings, or touch the filesystem — pure string functions only; callers resolve paths.compassDocs and perform I/O.</item>
6
+ <item>Do not merge or preserve authored content — injection only refreshes the marker-guarded region; everything outside the markers stays verbatim.</item>
7
+ </non-goals>
8
+ </MODULE_CONTRACT>
9
+ <KEY_DECISIONS>
10
+ <item>Markers are the contract — a region pasted into a hand-written file stays refreshable through the same injection path.</item>
11
+ <item>forge:semantic-layer sentinel opts hand-written files in; the marked region refreshes in place thereafter.</item>
12
+ <item>Regions beat stray sentinels — the block appears at most once per file.</item>
13
+ </KEY_DECISIONS>
14
+ <CHANGE_SUMMARY>
15
+ <item>created — shared read-first block renderer, marker-guarded injection for hand-written AGENTS.md, and ensureSemanticLayerBlock for renders that bypass the fallback template (consumer field report follow-up to RFC-1253).</item>
16
+ </CHANGE_SUMMARY>
17
+ */
18
+
19
+ /** Opt-in sentinel for hand-written AGENTS.md files — expands into a full marked region. */
20
+ export const SEMANTIC_LAYER_OPT_IN = "<!-- forge:semantic-layer -->";
21
+ /** Region markers emitted around the generated block and matched by injection. */
22
+ export const SEMANTIC_LAYER_BEGIN = "<!-- forge:begin semantic-layer -->";
23
+ export const SEMANTIC_LAYER_END = "<!-- forge:end semantic-layer -->";
24
+
25
+ /**
26
+ * The canonical read-first block, marker-wrapped. `compassDocs` is the bound
27
+ * `paths.compassDocs` list — callers filter non-string entries before calling.
28
+ */
29
+ export function semanticLayerLines(compassDocs: readonly string[]): string[] {
30
+ const lines = [
31
+ SEMANTIC_LAYER_BEGIN,
32
+ "",
33
+ "## Semantic layer — read first",
34
+ "",
35
+ "This repository carries a machine-readable Compass corpus — the semantic layer that answers “what reads X, what breaks if I change Y” without a full repository re-scan. For repository-wide, cross-workspace, architectural, shared-package, or high-risk tasks, read these documents before planning or editing code:",
36
+ "",
37
+ ];
38
+ for (const doc of compassDocs) lines.push(`- \`${doc}\``);
39
+ lines.push(
40
+ "",
41
+ "Treat these XML documents as the primary semantic layer for AI work and keep them synchronized with code, architecture, and verification changes.",
42
+ "",
43
+ SEMANTIC_LAYER_END,
44
+ );
45
+ return lines;
46
+ }
47
+
48
+ export interface SemanticLayerInjection {
49
+ content: string;
50
+ changed: boolean;
51
+ /** How the block landed: existing region refreshed, opt-in expanded, or no anchor found. */
52
+ region: "refreshed" | "expanded" | "none";
53
+ }
54
+
55
+ /**
56
+ * Guarantee the block is present in generated render output — a safety net for
57
+ * content paths that bypass {@link semanticLayerLines} (e.g. a profile-authored
58
+ * nested template selected over the fallback render). Content already carrying
59
+ * the region is returned as-is; otherwise the block is inserted before
60
+ * `footerLine` (the canonical merge boundary stays the last substantive line)
61
+ * or appended when no footer is found.
62
+ */
63
+ export function ensureSemanticLayerBlock(
64
+ content: string,
65
+ block: string,
66
+ footerLine?: string,
67
+ ): string {
68
+ if (!block || content.includes(SEMANTIC_LAYER_BEGIN)) return content;
69
+ const lines = content.replace(/\r\n/g, "\n").split("\n");
70
+ const blockLines = block.split("\n");
71
+ const footerIdx = footerLine
72
+ ? lines.findIndex((line) => line.trim() === footerLine)
73
+ : -1;
74
+ if (footerIdx === -1) {
75
+ while (lines.length > 0 && lines[lines.length - 1]!.trim() === "") lines.pop();
76
+ return [...lines, "", ...blockLines, ""].join("\n");
77
+ }
78
+ const lead = footerIdx > 0 && lines[footerIdx - 1]!.trim() !== "" ? [""] : [];
79
+ lines.splice(footerIdx, 0, ...lead, ...blockLines, "");
80
+ return lines.join("\n");
81
+ }
82
+
83
+ /**
84
+ * Inject or refresh the marker-guarded semantic-layer region in file content.
85
+ * `block` is the marker-wrapped render ({@link semanticLayerLines} joined).
86
+ *
87
+ * - Every complete `forge:begin semantic-layer` … `forge:end semantic-layer`
88
+ * region is replaced with the current block (content refresh is free).
89
+ * - When no region exists, the first bare `forge:semantic-layer` sentinel line
90
+ * expands into a full region.
91
+ * - Files carrying neither anchor return unchanged — injection is opt-in only.
92
+ *
93
+ * Matching normalizes CRLF to LF (the DNA-58 convention shared with
94
+ * editable-region.ts); marker lines match on trimmed equality.
95
+ */
96
+ export function injectSemanticLayerBlock(content: string, block: string): SemanticLayerInjection {
97
+ const text = content.replace(/\r\n/g, "\n");
98
+ const lines = text.split("\n");
99
+
100
+ // Pass 1: refresh complete begin..end regions.
101
+ const out: string[] = [];
102
+ let changed = false;
103
+ let refreshed = false;
104
+ let i = 0;
105
+ while (i < lines.length) {
106
+ if (lines[i]!.trim() === SEMANTIC_LAYER_BEGIN) {
107
+ let j = i + 1;
108
+ while (j < lines.length && lines[j]!.trim() !== SEMANTIC_LAYER_END) j++;
109
+ if (j < lines.length) {
110
+ if (lines.slice(i, j + 1).join("\n") !== block) changed = true;
111
+ out.push(block);
112
+ refreshed = true;
113
+ i = j + 1;
114
+ continue;
115
+ }
116
+ // Unbalanced begin (no matching end) — fall through, leave the line alone.
117
+ }
118
+ out.push(lines[i]!);
119
+ i++;
120
+ }
121
+ if (refreshed) {
122
+ return { content: out.join("\n"), changed, region: "refreshed" };
123
+ }
124
+
125
+ // Pass 2: no region — expand the first bare opt-in sentinel.
126
+ const idx = out.findIndex((line) => line.trim() === SEMANTIC_LAYER_OPT_IN);
127
+ if (idx === -1) {
128
+ return { content: text, changed: false, region: "none" };
129
+ }
130
+ out[idx] = block;
131
+ return { content: out.join("\n"), changed: true, region: "expanded" };
132
+ }