@aiwg/cli 2026.10.14 → 2026.10.16

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 (210) hide show
  1. package/agentic/code/addons/aiwg-utils/rules/anti-laziness.core.md +13 -0
  2. package/agentic/code/addons/aiwg-utils/rules/anti-laziness.md +118 -0
  3. package/agentic/code/providers/pi/aiwg-bridge.ts +45 -7
  4. package/dist/src/artifacts/citation-parser.js +7 -6
  5. package/dist/src/artifacts/corpus-tools/citation-densify.js +4 -2
  6. package/dist/src/artifacts/corpus-tools/cli.js +37 -0
  7. package/dist/src/artifacts/corpus-tools/discovery-log.js +27 -25
  8. package/dist/src/artifacts/corpus-tools/expand-cli.js +90 -0
  9. package/dist/src/artifacts/corpus-tools/expand-dates.js +107 -0
  10. package/dist/src/artifacts/corpus-tools/expand-queue.js +41 -0
  11. package/dist/src/artifacts/corpus-tools/expand-review.js +104 -0
  12. package/dist/src/artifacts/corpus-tools/expand-state.js +56 -0
  13. package/dist/src/artifacts/corpus-tools/expand.js +124 -0
  14. package/dist/src/artifacts/corpus-tools/induction-audit.js +7 -6
  15. package/dist/src/artifacts/corpus-tools/integrity-scan.js +3 -3
  16. package/dist/src/artifacts/corpus-tools/radar-shared.js +7 -9
  17. package/dist/src/artifacts/corpus-tools/ref-files.js +11 -0
  18. package/dist/src/artifacts/corpus-tools/resolve-cli.js +99 -0
  19. package/dist/src/artifacts/corpus-tools/resolve-corpus.js +41 -0
  20. package/dist/src/artifacts/corpus-tools/resolve.js +119 -0
  21. package/dist/src/artifacts/corpus-tools/retrieval-lab.js +2 -1
  22. package/dist/src/artifacts/corpus-tools/sidecar-lint.js +4 -4
  23. package/dist/src/artifacts/corpus-tools/sidecar-repair.js +2 -1
  24. package/dist/src/artifacts/corpus-views/ref-parser.js +3 -17
  25. package/dist/src/artifacts/graph-query.js +5 -3
  26. package/dist/src/artifacts/hybrid-query.js +11 -2
  27. package/dist/src/artifacts/index-refresh.js +2 -0
  28. package/dist/src/cli/handlers/daemon.js +17 -1
  29. package/dist/src/cli/handlers/doctor-args.js +45 -0
  30. package/dist/src/cli/handlers/doctor-help.js +8 -3
  31. package/dist/src/cli/handlers/index.js +2 -2
  32. package/dist/src/cli/handlers/models-resource-sample.js +10 -0
  33. package/dist/src/cli/handlers/models.js +3 -2
  34. package/dist/src/cli/handlers/regenerate.js +8 -16
  35. package/dist/src/cli/handlers/sessions.js +7 -7
  36. package/dist/src/cli/handlers/subcommands.js +8 -0
  37. package/dist/src/cli/handlers/update.js +157 -0
  38. package/dist/src/cli/handlers/use.js +14 -4
  39. package/dist/src/cli/handlers/utilities.js +3 -586
  40. package/dist/src/cli/handlers/utility-doctor.js +412 -0
  41. package/dist/src/cli/services/deployment-verification.js +0 -1
  42. package/dist/src/config/aiwg-config.js +2 -1
  43. package/dist/src/config/authorization-cli.js +7 -3
  44. package/dist/src/config/dispatch-thresholds-runtime.d.mts +3 -2
  45. package/dist/src/config/dispatch-thresholds-runtime.mjs +17 -7
  46. package/dist/src/config/framework-aliases.js +12 -0
  47. package/dist/src/config/host-resource-report.d.mts +19 -0
  48. package/dist/src/config/host-resource-report.mjs +80 -0
  49. package/dist/src/config/host-resource-runtime.d.mts +34 -0
  50. package/dist/src/config/host-resource-runtime.mjs +293 -0
  51. package/dist/src/config/installed-selection.js +22 -0
  52. package/dist/src/config/worker-context.js +33 -4
  53. package/dist/src/config/worker-invocation-marker.d.mts +1 -0
  54. package/dist/src/config/worker-invocation-marker.mjs +2 -0
  55. package/dist/src/decision/heldout/access.js +74 -0
  56. package/dist/src/decision/heldout/calibration.js +1 -0
  57. package/dist/src/decision/heldout/collector.js +9 -2
  58. package/dist/src/effects/verifiers/file.js +22 -5
  59. package/dist/src/extensions/claude-attribution.js +82 -0
  60. package/dist/src/extensions/claude-hooks-installer.js +115 -69
  61. package/dist/src/extensions/commands/daemon.js +109 -0
  62. package/dist/src/extensions/commands/definitions.js +5 -89
  63. package/dist/src/features/catalog.js +1 -1
  64. package/dist/src/gates/evaluate.js +2 -2
  65. package/dist/src/gates/heldout.js +52 -0
  66. package/dist/src/gates/index.js +2 -1
  67. package/dist/src/lint/check-patterns.js +163 -0
  68. package/dist/src/lint/checks.js +268 -0
  69. package/dist/src/lint/reference-resolution.js +54 -0
  70. package/dist/src/lint/runner.js +3 -465
  71. package/dist/src/mcp/helpers.mjs +11 -1
  72. package/dist/src/memory/project-registry.js +44 -4
  73. package/dist/src/models/worker-installation-store.mjs +228 -0
  74. package/dist/src/models/worker-installation.mjs +7 -162
  75. package/dist/src/models/worker-plan.js +36 -5
  76. package/dist/src/models/wrapper-deployment.js +25 -12
  77. package/dist/src/models/wrapper-enforcement.js +47 -7
  78. package/dist/src/network-analysis/research.js +2 -1
  79. package/dist/src/policy/hitl-check.js +14 -4
  80. package/dist/src/policy/hitl-consume.js +54 -0
  81. package/dist/src/policy/hitl-receipt.js +2 -0
  82. package/dist/src/policy/hitl.js +11 -3
  83. package/dist/src/providers/provider-context-contracts.js +162 -0
  84. package/dist/src/providers/provider-definition-schema.js +136 -0
  85. package/dist/src/providers/provider-definitions.js +8 -1298
  86. package/dist/src/providers/provider-seeds-1.js +360 -0
  87. package/dist/src/providers/provider-seeds-2.js +387 -0
  88. package/dist/src/providers/provider-seeds-3.js +262 -0
  89. package/dist/src/research/clients/arxiv.js +14 -34
  90. package/dist/src/research/clients/base.js +53 -26
  91. package/dist/src/research/clients/crossref.js +9 -1
  92. package/dist/src/research/clients/semantic-scholar.js +73 -44
  93. package/dist/src/research/identity.js +117 -0
  94. package/dist/src/research/index.js +1 -0
  95. package/dist/src/research/query-cli.js +3 -87
  96. package/dist/src/research/query-options.js +87 -0
  97. package/dist/src/research/reference-match.js +135 -0
  98. package/dist/src/research/services/acquisition.js +9 -7
  99. package/dist/src/research/services/citation.js +5 -2
  100. package/dist/src/research/types.js +2 -0
  101. package/dist/src/rules/core-startup.d.mts +2 -0
  102. package/dist/src/rules/core-startup.mjs +31 -0
  103. package/dist/src/serve/mission-conductor.js +48 -4
  104. package/dist/src/sessions/adapters/grok-build-native.js +23 -0
  105. package/dist/src/sessions/adapters/grok-build.js +14 -7
  106. package/dist/src/sessions/workspace-discovery.js +5 -5
  107. package/dist/src/smiths/context-pipeline/agents-md.js +34 -0
  108. package/dist/src/smiths/context-pipeline/aiwg-md.js +19 -46
  109. package/dist/src/smiths/context-pipeline/bridge-ownership.js +50 -0
  110. package/dist/src/smiths/context-pipeline/claude-hook.js +1 -1
  111. package/dist/src/smiths/context-pipeline/code-regions.js +28 -0
  112. package/dist/src/smiths/context-pipeline/finalization.js +81 -51
  113. package/dist/src/smiths/context-pipeline/generator.js +49 -114
  114. package/dist/src/smiths/context-pipeline/managed-hook.js +11 -1
  115. package/dist/src/smiths/context-pipeline/muse-bridge.js +2 -2
  116. package/dist/src/smiths/context-pipeline/provider-policy.js +6 -12
  117. package/dist/src/smiths/context-pipeline/workspace-audit.js +299 -0
  118. package/dist/src/smiths/context-pipeline/workspace-bootstrap.js +148 -0
  119. package/dist/src/smiths/context-pipeline/workspace-context-shared.js +111 -0
  120. package/dist/src/smiths/context-pipeline/workspace-context.js +8 -1373
  121. package/dist/src/smiths/context-pipeline/workspace-doctor.js +192 -0
  122. package/dist/src/smiths/context-pipeline/workspace-document.js +201 -0
  123. package/dist/src/smiths/context-pipeline/workspace-extraction.js +205 -0
  124. package/dist/src/smiths/context-pipeline/workspace-migration.js +250 -0
  125. package/package.json +13 -2
  126. package/schemas/decision/D29Study.v10.schema.json +65 -0
  127. package/tools/agents/deploy-agents.mjs +12 -123
  128. package/tools/agents/providers/antigravity.mjs +1 -1
  129. package/tools/agents/providers/claude-post-deploy.mjs +12 -1
  130. package/tools/agents/providers/context-write.mjs +16 -0
  131. package/tools/agents/providers/grok-build.mjs +8 -5
  132. package/tools/agents/providers/hermes-skill-lifecycle.mjs +144 -0
  133. package/tools/agents/providers/hermes-startup.mjs +209 -0
  134. package/tools/agents/providers/hermes.mjs +9 -359
  135. package/tools/agents/providers/model-wrapper.mjs +5 -1
  136. package/tools/agents/providers/muse.mjs +3 -3
  137. package/tools/agents/providers/pi.mjs +4 -2
  138. package/tools/agents/providers/rule-delivery-surface.mjs +332 -0
  139. package/tools/agents/providers/rule-delivery.mjs +20 -1346
  140. package/tools/agents/providers/rule-deployment-commit.mjs +144 -0
  141. package/tools/agents/providers/rule-deployment-prepare.mjs +452 -0
  142. package/tools/agents/providers/rule-deployment-state.mjs +300 -0
  143. package/tools/agents/providers/rule-presentation.mjs +13 -4
  144. package/tools/agents/providers/rule-projection.mjs +119 -0
  145. package/tools/agents/providers/rule-startup.mjs +70 -0
  146. package/tools/agents/providers/stale-artifact-prune.mjs +128 -0
  147. package/tools/agents/providers/warp.mjs +2 -2
  148. package/tools/agents/providers/windsurf.mjs +11 -57
  149. package/tools/daemon/README.md +511 -0
  150. package/tools/daemon/adapters/base-adapter.mjs +84 -0
  151. package/tools/daemon/adapters/webhook-adapter.mjs +107 -0
  152. package/tools/daemon/agent-supervisor.mjs +299 -0
  153. package/tools/daemon/automation-engine.mjs +310 -0
  154. package/tools/daemon/autonomous-engine.mjs +346 -0
  155. package/tools/daemon/behavior-loader.mjs +316 -0
  156. package/tools/daemon/behavior.mjs +174 -0
  157. package/tools/daemon/concierge/intent-router.mjs +401 -0
  158. package/tools/daemon/concierge/orchestrator.mjs +272 -0
  159. package/tools/daemon/concierge/response-translator.mjs +462 -0
  160. package/tools/daemon/config.mjs +377 -0
  161. package/tools/daemon/cron-scheduler.mjs +178 -0
  162. package/tools/daemon/daemon-main.mjs +1169 -0
  163. package/tools/daemon/event-router.mjs +84 -0
  164. package/tools/daemon/file-watcher.mjs +383 -0
  165. package/tools/daemon/index.mjs +1181 -0
  166. package/tools/daemon/init-profile.mjs +124 -0
  167. package/tools/daemon/ipc-client.mjs +197 -0
  168. package/tools/daemon/ipc-ops-handlers.mjs +236 -0
  169. package/tools/daemon/ipc-server.mjs +275 -0
  170. package/tools/daemon/maintenance-owner.mjs +79 -0
  171. package/tools/daemon/memory-manager.mjs +386 -0
  172. package/tools/daemon/message-router.mjs +194 -0
  173. package/tools/daemon/provider-watcher.mjs +585 -0
  174. package/tools/daemon/pty-adapter.mjs +420 -0
  175. package/tools/daemon/repl-chat.mjs +359 -0
  176. package/tools/daemon/resource-bounds.mjs +88 -0
  177. package/tools/daemon/sandbox-transport.mjs +295 -0
  178. package/tools/daemon/scheduled-task-runner.mjs +535 -0
  179. package/tools/daemon/task-store.mjs +450 -0
  180. package/tools/daemon/tmux-manager.mjs +324 -0
  181. package/tools/daemon/update-policy.mjs +517 -0
  182. package/tools/daemon/web-server.mjs +399 -0
  183. package/tools/daemon/web-ui/index.html +585 -0
  184. package/tools/daemon/web-ui/styles.css +156 -0
  185. package/tools/docker/Dockerfile.daemon +35 -0
  186. package/tools/docker/container-manager.mjs +291 -0
  187. package/tools/messaging/adapter-registry.mjs +230 -0
  188. package/tools/messaging/adapters/base.mjs +326 -0
  189. package/tools/messaging/adapters/discord.mjs +462 -0
  190. package/tools/messaging/adapters/slack.mjs +402 -0
  191. package/tools/messaging/adapters/telegram.mjs +552 -0
  192. package/tools/messaging/chat-handler.mjs +297 -0
  193. package/tools/messaging/command-router.mjs +269 -0
  194. package/tools/messaging/event-bus.mjs +199 -0
  195. package/tools/messaging/index.mjs +456 -0
  196. package/tools/messaging/message-formatter.mjs +320 -0
  197. package/tools/messaging/room-manager.mjs +277 -0
  198. package/tools/messaging/types.mjs +94 -0
  199. package/tools/plugin/plugin-links.mjs +3 -0
  200. package/tools/providers/pi-bridge-policy.mjs +4 -0
  201. package/tools/ralph-external/daemon-supervisor.mjs +394 -0
  202. package/tools/ralph-external/lib/behavior-registry.mjs +270 -0
  203. package/tools/ralph-external/lib/worker-invocation-processes.mjs +3 -2
  204. package/tools/ralph-external/lib/worker-isolation-args.mjs +217 -0
  205. package/tools/ralph-external/lib/worker-isolation-status.mjs +19 -0
  206. package/tools/ralph-external/lib/worker-isolation.mjs +11 -237
  207. package/tools/ralph-external/lib/worker-overflow.mjs +10 -2
  208. package/tools/ralph-external/lib/worker-unit-cleanup.mjs +72 -0
  209. package/tools/ralph-external/session-launcher.mjs +7 -7
  210. package/tools/scripts/resource-preflight.mjs +3 -242
@@ -4,7 +4,7 @@ import { basename, dirname, join, resolve } from 'node:path';
4
4
  import { inspectMuseNativeWorkspace } from './adapters/muse.js';
5
5
  import { readOmpSessionHeader } from './adapters/omp.js';
6
6
  import { grokbotConversationIdFromLocator } from './adapters/grokbot-locator.js';
7
- import { GROK_BUILD_ACTIVE_FRESHNESS_MS, grokBuildLiveState, grokBuildSourceWorkspaceMatch, readGrokBuildActiveRegistry, } from './adapters/grok-build-native.js';
7
+ import { GROK_BUILD_ACTIVE_FRESHNESS_MS, grokBuildLiveState, grokBuildNativeAvailability, grokBuildSourceWorkspaceMatch, readGrokBuildActiveRegistry, } from './adapters/grok-build-native.js';
8
8
  import { hermesSnapshotStagingDir } from './adapters/hermes-state-db.js';
9
9
  import { resolveOmpPaths } from '../providers/omp-paths.mjs';
10
10
  import { readAiwgConfig } from '../config/aiwg-config.js';
@@ -18,7 +18,7 @@ import { matchImportExclusion, nativeSessionIdFromLocator, resolveImportExclusio
18
18
  export const DISCOVERY_MANIFEST_VERSION = '1.0.0';
19
19
  const MANUAL_EXPORT_PROVIDERS = new Set([
20
20
  'copilot', 'opencode', 'openclaw', 'openhuman',
21
- 'warp', 'devin-desktop', 'generic',
21
+ 'warp', 'devin-desktop', 'generic', 'grok-build',
22
22
  ]);
23
23
  export async function discoverWorkspaceHistories(options) {
24
24
  const registry = options.registry ?? createSessionAdapterRegistry();
@@ -173,7 +173,7 @@ export async function discoverWorkspaceHistories(options) {
173
173
  || entry.provider === 'grokbot' || entry.provider === 'grok-build'
174
174
  || entry.provider === 'hermes')
175
175
  && entry.roots.length === 0;
176
- const expectedFlag = entry.provider === 'deepseek-harness' ? 'dsh' : entry.provider;
176
+ const expectedFlag = entry.provider === 'deepseek-harness' ? 'dsh' : entry.provider === 'grok-build' ? 'grok' : entry.provider;
177
177
  const rootKind = entry.provider === 'hermes' ? 'Hermes home (state.db is snapshotted read-only)' : 'sessions root';
178
178
  reports.set(entry.provider, providerReport(entry.provider, needsExplicitRoot ? 'export-required' : 'unavailable', needsExplicitRoot ? 'manual-export' : 'discoverable', [], needsExplicitRoot
179
179
  ? 'SHARED_ROOT_AUTHORIZATION_REQUIRED'
@@ -382,9 +382,9 @@ export async function discoverWorkspaceHistories(options) {
382
382
  continue;
383
383
  }
384
384
  const grokBuild = provider === 'grok-build';
385
- reports.set(provider, providerReport(provider, manual ? 'export-required' : 'not-checked', manual ? 'manual-export' : 'unsupported', [], grokBuild ? 'CLI_EXPORT_REQUIRED'
385
+ reports.set(provider, providerReport(provider, manual ? 'export-required' : 'not-checked', manual ? 'manual-export' : 'unsupported', [], grokBuild ? grokBuildNativeAvailability().reasonCode
386
386
  : manual ? 'EXPLICIT_EXPORT_REQUIRED' : 'PROVIDER_NOT_CHECKED', grokBuild
387
- ? 'Run `grok sessions list` or `grok sessions search`, then export an authorized session with `grok export <id> <id>.md`; Grok Build resolves $GROK_HOME itself.'
387
+ ? grokBuildNativeAvailability().remediation
388
388
  : manual
389
389
  ? `Select and authorize a supported ${provider} export before importing it.`
390
390
  : `No discovery strategy is registered for ${provider}.`));
@@ -0,0 +1,34 @@
1
+ import { buildProviderBootstrapBlock } from './workspace-context.js';
2
+ const AIWG_SIGNATURE_COMMENT = '<!-- aiwg-managed -->';
3
+ /**
4
+ * Build the full AGENTS.md content (in-memory; does not write).
5
+ *
6
+ * Per operator direction (#1239): AGENTS.md is a thin pointer to AIWG.md at
7
+ * project root. AIWG.md mirrors CLAUDE.md (ADR-1 §0.5) and contains the full
8
+ * framework guidance — including the kernel-skill discovery pattern
9
+ * (`aiwg discover` / `aiwg show`). Inlining a full link-index here pushed the
10
+ * file past Codex's 32KB cap on real deploys, triggered auto-split, and ran
11
+ * every artifact description through the sanitizer (rejecting any with
12
+ * backticks). The thin-pointer body sidesteps all of that: zero warnings on
13
+ * any provider, regardless of how many artifacts are deployed.
14
+ *
15
+ * `opts.sections` is accepted for backwards compatibility with callers that
16
+ * still aggregate a link-index (no internal use). `splitOccurred` is always
17
+ * false; `spilloverContent` is always empty. The `partitionForOverflow` /
18
+ * spillover utilities remain exported for any external consumer.
19
+ */
20
+ export async function buildAgentsMd(opts) {
21
+ const warnings = [];
22
+ const parts = [];
23
+ parts.push('# AGENTS.md');
24
+ parts.push(`${AIWG_SIGNATURE_COMMENT}`);
25
+ parts.push('<!-- Generated by AIWG. Edit AGENTS.override.md for operator additions. -->');
26
+ parts.push('');
27
+ parts.push(buildProviderBootstrapBlock(opts.provider));
28
+ parts.push('');
29
+ if (opts.projectContext && opts.projectContext.trim().length > 0) {
30
+ warnings.push('projectContext is no longer inlined in provider startup files; place it in the protected WORKSPACE.md operator section.');
31
+ }
32
+ return { content: parts.join('\n'), warnings, spilloverContent: '', splitOccurred: false };
33
+ }
34
+ //# sourceMappingURL=agents-md.js.map
@@ -1,22 +1,7 @@
1
- /**
2
- * AIWG.md generator — content-rich CLAUDE.md companion for non-Claude providers.
3
- *
4
- * Per ADR-1 §0.5: AIWG.md at project root has the same content shape as
5
- * CLAUDE.md. Both files `@`-reference the project's `.aiwg/AIWG.md` (the
6
- * source of truth). Non-Claude providers reach AIWG.md transitively via the
7
- * provider startup adapters. WORKSPACE.md and AIWG.md contain
8
- * identical framework prose; they exist as two named files because Claude
9
- * Code looks for `CLAUDE.md` and the seven AGENTS.md providers reach
10
- * AIWG.md via the AGENTS.md hook-up.
11
- *
12
- * Generation strategy: read the project's CLAUDE.md (which already exists in
13
- * a properly-configured repo) and emit AIWG.md as the same content with the
14
- * AIWG signature comment in place. If CLAUDE.md is absent (early-init repos),
15
- * fall back to a minimal stub that points readers at `.aiwg/AIWG.md`.
16
- */
1
+ // Render the single generated root framework context and fold in optional operator notes.
17
2
  import { promises as fs } from 'node:fs';
18
3
  import * as path from 'node:path';
19
- import { projectControlPath } from '../../config/project-artifacts.js';
4
+ import { readAiwgOperatorNotes } from './finalization.js';
20
5
  import { buildClaudeHookBlock, CLAUDE_HOOK_START, CLAUDE_HOOK_END } from './claude-hook.js';
21
6
  import { dedupeProviderBootstrap } from './workspace-context.js';
22
7
  import { dominantLineEnding, withLineEnding } from './line-endings.js';
@@ -24,18 +9,6 @@ import { buildParallelismSection, replaceOrAppendParallelismBlock } from './para
24
9
  import { buildContextFinalizationBlock, replaceOrAppendFinalizationBlock } from './finalization.js';
25
10
  import { buildExternalLinksSection, replaceOrAppendExternalLinksBlock, } from './external-links-section.js';
26
11
  const AIWG_SIGNATURE_COMMENT = '<!-- aiwg-managed -->';
27
- /**
28
- * Build the AIWG.md content for emission at project root.
29
- *
30
- * - When CLAUDE.md exists at project root: copy its content with the AIWG
31
- * signature comment inserted in the second line so future runs of the
32
- * generator know the file is AIWG-managed.
33
- * - When CLAUDE.md does not exist: emit a minimal stub directing readers to
34
- * the project's `.aiwg/AIWG.md` source.
35
- *
36
- * Returns the rendered content as a string. Caller is responsible for the
37
- * atomic-write emission and the operator-claimed-file detection.
38
- */
39
12
  export async function buildAiwgMdContent(projectPath, stagedClaudeMdContent) {
40
13
  let claudeMdContent = stagedClaudeMdContent;
41
14
  if (stagedClaudeMdContent === undefined) {
@@ -55,6 +28,11 @@ export async function buildAiwgMdContent(projectPath, stagedClaudeMdContent) {
55
28
  const parallelismSection = await buildParallelismSection(projectPath);
56
29
  const finalizationBlock = await buildContextFinalizationBlock(projectPath, path.join(projectPath, 'AIWG.md'));
57
30
  const externalLinksSection = await buildExternalLinksSection(projectPath);
31
+ const { notes } = await readAiwgOperatorNotes(projectPath);
32
+ const foldNotes = (content) => {
33
+ content = content.replace(/<!-- AIWG:operator-notes:start -->[\s\S]*?<!-- AIWG:operator-notes:end -->\r?\n?/g, '');
34
+ return notes.trim() ? `${content.trimEnd()}\n\n<!-- AIWG:operator-notes:start -->\n${notes}\n<!-- AIWG:operator-notes:end -->\n` : content;
35
+ };
58
36
  if (claudeMdContent) {
59
37
  // Insert the AIWG signature comment as the second line.
60
38
  // Top line is typically `# AIWG` or `# Project` heading; preserve it.
@@ -62,6 +40,9 @@ export async function buildAiwgMdContent(projectPath, stagedClaudeMdContent) {
62
40
  // that managed block here too so legacy duplicate policy never reaches
63
41
  // AIWG.md, even on the first refresh. Operator content stays untouched.
64
42
  claudeMdContent = dedupeProviderBootstrap(claudeMdContent);
43
+ // Each provider startup owns core and hooks; mirroring them would load a
44
+ // second copy through the shared framework companion.
45
+ claudeMdContent = claudeMdContent.replace(/<!-- AIWG:(rule-core|rule-startup|rule-hook-[\w-]+):start -->[\s\S]*?<!-- AIWG:\1:end -->\r?\n?/g, '');
65
46
  const start = claudeMdContent.indexOf(CLAUDE_HOOK_START);
66
47
  const end = claudeMdContent.indexOf(CLAUDE_HOOK_END, start);
67
48
  if (start >= 0 && end >= start) {
@@ -79,7 +60,7 @@ export async function buildAiwgMdContent(projectPath, stagedClaudeMdContent) {
79
60
  const CONFIG_IMPORT_PATTERN = /^\s*@\S*aiwg\.config\s*$/;
80
61
  const WORKSPACE_IMPORT_PATTERN = /^\s*@(?:\.\.\/)?WORKSPACE\.md\s*$/;
81
62
  const filtered = lines
82
- .filter((line) => !SELF_INCLUDE_PATTERN.test(line))
63
+ .filter((line) => !SELF_INCLUDE_PATTERN.test(line) && !/^\s*@(?:\.\/)?\.aiwg\/AIWG\.md\s*$/.test(line))
83
64
  .map((line) => {
84
65
  if (WORKSPACE_IMPORT_PATTERN.test(line)) {
85
66
  return 'WORKSPACE.md is the canonical project context (loaded by CLAUDE.md; read it first if your harness did not).';
@@ -99,29 +80,21 @@ export async function buildAiwgMdContent(projectPath, stagedClaudeMdContent) {
99
80
  : [
100
81
  firstLine,
101
82
  AIWG_SIGNATURE_COMMENT,
102
- '<!-- AIWG.md is the CLAUDE.md companion for non-Claude providers; same content. -->',
83
+ '<!-- Generated framework context shared by all providers. -->',
103
84
  ...rest,
104
85
  ].join('\n');
105
86
  const withParallelism = replaceOrAppendParallelismBlock(baseContent, parallelismSection);
106
87
  const withFinalization = replaceOrAppendFinalizationBlock(withParallelism, finalizationBlock);
107
- return replaceOrAppendExternalLinksBlock(withFinalization, externalLinksSection);
88
+ return foldNotes(replaceOrAppendExternalLinksBlock(withFinalization, externalLinksSection));
108
89
  }
109
- // Fallback stub.
110
- const normalizedPath = projectControlPath(projectPath, 'AIWG.md');
111
- const normalizedRelative = path.relative(projectPath, normalizedPath).replace(/\\/g, '/');
112
- const normalizedLink = normalizedRelative.startsWith('.') ? normalizedRelative : `./${normalizedRelative}`;
90
+ // A fresh non-Claude project has the same complete framework context.
113
91
  const stub = [
114
- '# AIWG.md',
115
- AIWG_SIGNATURE_COMMENT,
116
- '<!-- CLAUDE.md companion for non-Claude providers. -->',
117
- '',
118
- 'CLAUDE.md was not found at project root. AIWG.md normally mirrors that content.',
119
- `See [${normalizedRelative}](${normalizedLink}) for the project framework context.`,
120
- '',
92
+ '# AIWG.md', AIWG_SIGNATURE_COMMENT,
93
+ '<!-- Generated framework context. Project/operator context belongs in WORKSPACE.md. -->', '',
121
94
  ].join('\n');
122
95
  const withParallelism = replaceOrAppendParallelismBlock(stub, parallelismSection);
123
96
  const withFinalization = replaceOrAppendFinalizationBlock(withParallelism, finalizationBlock);
124
- return replaceOrAppendExternalLinksBlock(withFinalization, externalLinksSection);
97
+ return foldNotes(replaceOrAppendExternalLinksBlock(withFinalization, externalLinksSection));
125
98
  }
126
99
  /**
127
100
  * Public API: build AIWG.md content for a given project.
@@ -130,7 +103,7 @@ export async function buildAiwgMdContent(projectPath, stagedClaudeMdContent) {
130
103
  * AIWG.local.md operator overrides, etc.) have a single entry point in the
131
104
  * surface API without callers reaching into the implementation.
132
105
  */
133
- export async function generateAiwgMd(projectPath) {
134
- return buildAiwgMdContent(projectPath);
106
+ export async function generateAiwgMd(projectPath, stagedClaudeMdContent) {
107
+ return buildAiwgMdContent(projectPath, stagedClaudeMdContent);
135
108
  }
136
109
  //# sourceMappingURL=aiwg-md.js.map
@@ -0,0 +1,50 @@
1
+ // Migrate startup ownership without nesting markers or discarding operator text.
2
+ export const AGENTS_HEADER = '# AGENTS.md\n<!-- aiwg-managed -->\n<!-- Generated by AIWG. Edit AGENTS.override.md for operator additions. -->\n';
3
+ const bootstrapBlock = /<!-- AIWG:provider-bootstrap:start -->[\s\S]*?<!-- AIWG:provider-bootstrap:end -->/g;
4
+ export const hasRuleStartup = (content) => /<!-- AIWG:rule-hook-[\w-]+:start -->/.test(content);
5
+ export function retireLegacyBridge(content) {
6
+ return content.replace(/\n\n---\n\n<!-- BEGIN AIWG-managed \(auto-generated;[^\n]*-->[\s\S]*?<!-- END AIWG-managed -->\n?/g, '\n')
7
+ .replace(/<!-- BEGIN AIWG-managed \(auto-generated;[^\n]*-->[\s\S]*?<!-- END AIWG-managed -->\n?/g, '');
8
+ }
9
+ export function normalizeRuleStartup(content, bootstrap, agentsHeader = false, retireLegacy = true) {
10
+ if (retireLegacy)
11
+ content = retireLegacyBridge(content);
12
+ // Retire context-hook's generated body; retain agents-md's enclosed content.
13
+ content = content.replace(/<!-- AIWG:context-hook:start -->[\s\S]*?<!-- AIWG:context-hook:end -->\r?\n?/g, '')
14
+ .replace(/<!-- AIWG:agents-md:(?:start|end) -->\r?\n?/g, '')
15
+ .replace(/\n## For Hermes Sessions\n\nHermes does not auto-load AIWG\.md\. Browse AIWG capabilities with:\n\n- `artifact-read AIWG\.md` through AIWG MCP\.\n- `aiwg discover "<intent>"` and `aiwg show <type> <name>`\.\n- `delegate_task` through the AIWG-orchestrate skill\.\n/, '');
16
+ if (retireLegacy)
17
+ content = content.replace(/## Framework Context\r?\n[\s\S]*?\*See `AGENTS.override.md` for operator-authored additions\.\*\r?\n?/g, '');
18
+ if (content.includes('<!-- AIWG:rule-core:start -->')) {
19
+ content = content.replace(/<!-- AIWG:core-rules:(?:start|end) -->\r?\n?/g, '');
20
+ }
21
+ let installed = false;
22
+ content = content.replace(bootstrapBlock, () => {
23
+ if (installed)
24
+ return '';
25
+ installed = true;
26
+ return bootstrap;
27
+ });
28
+ if (!installed)
29
+ content = `${content}${content.endsWith('\n') ? '\n' : '\n\n'}${bootstrap}\n`;
30
+ if (agentsHeader && !content.startsWith(AGENTS_HEADER)) {
31
+ content = content.replace(/^# AGENTS\.md\r?\n/gm, '')
32
+ .replace(/^<!-- (?:aiwg-managed|Generated by AIWG\.[^\n]*) -->\r?\n?/gm, '');
33
+ // Round 3 left the old generated Framework Context separator at the top.
34
+ content = content.replace(/^(?:[ \t]*\r?\n)*---[ \t]*\r?\n/, '').replace(/^\s+/, '');
35
+ content = `${AGENTS_HEADER}\n${content}`;
36
+ }
37
+ return content;
38
+ }
39
+ export function preserveBridgeOperatorText(existing, generated) {
40
+ if (!generated.startsWith(AGENTS_HEADER) || !existing)
41
+ return generated;
42
+ const fallback = generated.match(bootstrapBlock)?.[0];
43
+ if (!fallback)
44
+ return generated;
45
+ // Rule deployment owns the bootstrap when its hooks are present. Standalone
46
+ // regeneration supplies it only for files without an installed rule startup.
47
+ const bootstrap = hasRuleStartup(existing) ? existing.match(bootstrapBlock)?.[0] || fallback : fallback;
48
+ return normalizeRuleStartup(existing, bootstrap, true);
49
+ }
50
+ //# sourceMappingURL=bridge-ownership.js.map
@@ -40,7 +40,7 @@ export function buildClaudeHookBlock(_policy = {}) {
40
40
  '<!--',
41
41
  ' This block is managed by `aiwg regenerate` and `aiwg use`.',
42
42
  ' Operator content above and below this block is preserved on regenerate.',
43
- ' To change AIWG.md content, edit .aiwg/AIWG.md (the normalized source)',
43
+ ' Edit WORKSPACE.md Project Context or optional .aiwg/AIWG.md operator notes,',
44
44
  ' then run `aiwg regenerate`.',
45
45
  '-->',
46
46
  '',
@@ -0,0 +1,28 @@
1
+ // Mask Markdown examples without changing source offsets.
2
+ /**
3
+ * Blank out fenced code blocks and inline code spans, preserving offsets and line
4
+ * structure, so link extraction sees only prose. Illustrative paths inside an
5
+ * example block are documentation, not context links the graph should resolve (#2536).
6
+ */
7
+ export function maskCodeRegions(content) {
8
+ const lines = content.split('\n');
9
+ let fence = null;
10
+ const masked = lines.map((line) => {
11
+ const openOrClose = /^\s{0,3}(`{3,}|~{3,})(.*)$/.exec(line);
12
+ if (fence) {
13
+ // A closing fence uses the same character, is at least as long, and carries no info string.
14
+ if (openOrClose && openOrClose[1][0] === fence.marker && openOrClose[1].length >= fence.length && openOrClose[2].trim() === '') {
15
+ fence = null;
16
+ }
17
+ return ' '.repeat(line.length);
18
+ }
19
+ if (openOrClose) {
20
+ fence = { marker: openOrClose[1][0], length: openOrClose[1].length };
21
+ return ' '.repeat(line.length);
22
+ }
23
+ // Inline code spans: a run of N backticks closes on the next run of exactly N.
24
+ return line.replace(/(`+)(?:[^`]|(?!\1)`)*?\1/g, (span) => ' '.repeat(span.length));
25
+ });
26
+ return masked.join('\n');
27
+ }
28
+ //# sourceMappingURL=code-regions.js.map
@@ -1,4 +1,5 @@
1
- import { writeContextFileSync } from './context-file-safety.js';
1
+ import { maskCodeRegions } from './code-regions.js';
2
+ import { assertSafeContextFile, writeContextFileSync } from './context-file-safety.js';
2
3
  /**
3
4
  * Context-finalization pass for generated provider context files.
4
5
  *
@@ -8,7 +9,7 @@ import { writeContextFileSync } from './context-file-safety.js';
8
9
  */
9
10
  import { promises as fs } from 'node:fs';
10
11
  import * as path from 'node:path';
11
- import { projectAiwgPath, projectControlPath, resolveProjectAiwgDir, } from '../../config/project-artifacts.js';
12
+ import { projectControlPath, } from '../../config/project-artifacts.js';
12
13
  import { renderTrackerProtocol, resolveTrackerAuthority } from '../../tracker/capability-protocol.js';
13
14
  import { readConfig, readGitRemoteUrls } from '../../tracker/project-inputs.js';
14
15
  import { DECISION_COMPACT_ANCHOR, inspectDecisionOffloadActivation } from '../../decision/offload-activation.js';
@@ -46,8 +47,7 @@ export async function buildContextFinalizationBlock(projectPath, documentPath =
46
47
  const installed = Object.entries(config?.installed ?? {});
47
48
  const installedNames = installed.map(([name]) => name);
48
49
  const providerDeployments = new Set();
49
- const normalizedAiwgMdPath = displayProjectPath(projectPath, projectControlPath(projectPath, 'AIWG.md'));
50
- const normalizedAiwgMdLabel = `\`${normalizedAiwgMdPath}\``;
50
+ const notesPath = displayProjectPath(projectPath, projectControlPath(projectPath, 'AIWG.md'));
51
51
  for (const [, entry] of installed) {
52
52
  for (const provider of Object.keys(entry.deployedTo ?? {})) {
53
53
  providerDeployments.add(provider);
@@ -66,7 +66,7 @@ export async function buildContextFinalizationBlock(projectPath, documentPath =
66
66
  `- Configured providers: ${formatList(providers)}`,
67
67
  `- Installed frameworks/addons: ${formatList(installedNames)}`,
68
68
  `- Recorded deployments: ${formatList([...providerDeployments].sort())}`,
69
- `- Normalized project context: \`${normalizedAiwgMdPath}\``,
69
+ '- Generated framework context: `AIWG.md`',
70
70
  '',
71
71
  '### Capability Routing',
72
72
  '',
@@ -82,9 +82,10 @@ export async function buildContextFinalizationBlock(projectPath, documentPath =
82
82
  '',
83
83
  '### Source Model',
84
84
  '',
85
- `- ${normalizedAiwgMdLabel} is the normalized project-local context entry point.`,
86
- '- Root `AIWG.md` is the generated cross-provider companion loaded through `AGENTS.md` and provider twins.',
87
- `- \`AGENTS.md\`, \`WARP.md\`, \`.hermes.md\`, and \`.github/copilot-instructions.md\` are provider-facing bridges, not replacements for ${normalizedAiwgMdLabel}.`,
85
+ '- Root `AIWG.md` is the single generated framework context loaded through provider startup hooks.',
86
+ `- Optional \`${notesPath}\` contains only operator-authored notes, folded into root AIWG.md on regenerate.`,
87
+ '- Edit WORKSPACE.md Project Context for project conventions; edit .aiwg/AIWG.md only for optional framework notes, then run `aiwg regenerate`.',
88
+ '- `AGENTS.md`, `CLAUDE.md`, `WARP.md`, `.hermes.md`, and `.github/copilot-instructions.md` are provider-facing bridges.',
88
89
  ...(decision.shouldAnchor ? ['', '## Compact Instructions', '', DECISION_COMPACT_ANCHOR] : []),
89
90
  FINALIZATION_END,
90
91
  '',
@@ -99,53 +100,82 @@ export function replaceOrAppendFinalizationBlock(content, block) {
99
100
  const trimmed = content.replace(/\s+$/, '');
100
101
  return `${trimmed}\n\n${block}`;
101
102
  }
103
+ /** Compatibility renderer: normalized context now lives at the project root. */
102
104
  export async function buildNormalizedAiwgMd(projectPath, existing = '') {
103
- const normalizedDocumentPath = projectControlPath(projectPath, 'AIWG.md');
104
- const block = await buildContextFinalizationBlock(projectPath, normalizedDocumentPath);
105
- const externalLinksSection = await buildExternalLinksSection(projectPath);
106
- const normalizedAiwgMdPath = displayProjectPath(projectPath, projectControlPath(projectPath, 'AIWG.md'));
107
- const base = existing.trim().length > 0
108
- ? existing
109
- : [
110
- '# AIWG.md',
111
- AIWG_SIGNATURE_COMMENT,
112
- '<!-- Normalized project-local AIWG context. Operator notes may live outside AIWG-managed blocks. -->',
113
- '',
114
- `This file is the stable \`${normalizedAiwgMdPath}\` entry point for AIWG skills, rules, and generated provider context.`,
115
- '',
116
- ].join('\n');
117
- const signed = base.includes(AIWG_SIGNATURE_COMMENT)
118
- ? base
119
- : base.replace(/^([^\n]*)(\n|$)/, `$1\n${AIWG_SIGNATURE_COMMENT}\n`);
120
- const withFinalization = replaceOrAppendFinalizationBlock(signed, block);
121
- return replaceOrAppendExternalLinksBlock(withFinalization, externalLinksSection);
105
+ const block = await buildContextFinalizationBlock(projectPath);
106
+ const base = existing || '# AIWG.md\n<!-- aiwg-managed -->\n';
107
+ const signed = base.includes(AIWG_SIGNATURE_COMMENT) ? base : `${AIWG_SIGNATURE_COMMENT}\n${base}`;
108
+ return replaceOrAppendExternalLinksBlock(replaceOrAppendFinalizationBlock(signed, block), await buildExternalLinksSection(projectPath));
122
109
  }
123
- export async function writeNormalizedAiwgMd(projectPath) {
124
- const targetPath = projectControlPath(projectPath, 'AIWG.md');
125
- let existing = '';
126
- try {
127
- existing = await fs.readFile(targetPath, 'utf8');
128
- }
129
- catch (err) {
130
- if (err.code !== 'ENOENT')
131
- throw err;
110
+ /** Remove only the contiguous legacy wrapper at the head, never quoted body lines. */
111
+ function stripLegacyNotesHeader(content) {
112
+ const lines = content.replace(/^\uFEFF/, '').split(/(?<=\n)/);
113
+ const wrappers = [
114
+ /^# AIWG\.md$/,
115
+ /^<!-- aiwg-managed -->$/,
116
+ /^<!-- Normalized project-local AIWG context\. Operator notes may live outside AIWG-managed blocks\. -->$/,
117
+ /^This file is the stable `[^`]+` entry point for AIWG skills, rules, and generated provider context\.$/,
118
+ ];
119
+ const removed = new Set();
120
+ for (let i = 0; i < Math.min(lines.length, 12); i++) {
121
+ const line = lines[i].replace(/\r?\n$/, '');
122
+ if (!line.trim())
123
+ continue;
124
+ const wrapper = wrappers.findIndex(pattern => pattern.test(line));
125
+ if (wrapper < 0 || removed.has(wrapper))
126
+ break;
127
+ removed.add(wrapper);
128
+ lines[i] = '';
132
129
  }
133
- const content = await buildNormalizedAiwgMd(projectPath, existing);
134
- await fs.mkdir(path.dirname(targetPath), { recursive: true });
135
- const normalizedContent = content.endsWith('\n') ? content : `${content}\n`;
136
- writeContextFileSync(targetPath, normalizedContent, 'utf8');
137
- const artifactRoot = resolveProjectAiwgDir(projectPath);
138
- const artifactPath = projectAiwgPath(projectPath, 'AIWG.md');
139
- if (artifactPath !== targetPath) {
140
- try {
141
- await fs.access(artifactRoot);
142
- writeContextFileSync(artifactPath, normalizedContent, 'utf8');
143
- }
144
- catch (error) {
145
- if (error.code !== 'ENOENT')
146
- throw error;
130
+ return lines.join('');
131
+ }
132
+ /** Strip only known generated wrappers; unknown text always belongs to the operator. */
133
+ export function extractAiwgOperatorNotes(existing) {
134
+ if (!existing.includes(AIWG_SIGNATURE_COMMENT))
135
+ return existing;
136
+ let notes = stripLegacyNotesHeader(existing);
137
+ for (const [start, end] of [
138
+ [FINALIZATION_START, FINALIZATION_END],
139
+ ['<!-- aiwg-external-links:start -->', '<!-- aiwg-external-links:end -->'],
140
+ ]) {
141
+ const pattern = new RegExp(`${start}[\\s\\S]*?${end}\\r?\\n?`, 'g');
142
+ // Match in masked prose, then cut those exact offsets from the original.
143
+ const matches = [...maskCodeRegions(notes).matchAll(pattern)];
144
+ for (const match of matches.reverse()) {
145
+ notes = notes.slice(0, match.index) + notes.slice(match.index + match[0].length);
147
146
  }
148
147
  }
149
- return targetPath;
148
+ return notes.trim() ? notes.replace(/^(?:\r?\n)+/, '') : '';
149
+ }
150
+ export async function readAiwgOperatorNotes(projectPath) {
151
+ const target = projectControlPath(projectPath, 'AIWG.md');
152
+ await assertSafeContextFile(target);
153
+ let existing = null;
154
+ try {
155
+ existing = await fs.readFile(target, 'utf8');
156
+ }
157
+ catch (error) {
158
+ if (error.code !== 'ENOENT')
159
+ throw error;
160
+ }
161
+ return { path: target, existing, notes: extractAiwgOperatorNotes(existing ?? '') };
162
+ }
163
+ /** Keep legacy files notes-only; journal even an empty migration for rollback. */
164
+ export async function migrateAiwgOperatorNotes(projectPath) {
165
+ const { path: target, existing, notes } = await readAiwgOperatorNotes(projectPath);
166
+ if (existing !== null && existing !== notes)
167
+ writeContextFileSync(target, notes, 'utf8');
168
+ }
169
+ /** Compatibility writer used by init: emit only the generated root context. */
170
+ export async function writeNormalizedAiwgMd(projectPath, stagedClaudeMdContent) {
171
+ const target = path.join(projectPath, 'AIWG.md');
172
+ await assertSafeContextFile(target);
173
+ const { isOverwriteSafe } = await import('./generator.js');
174
+ if (!(await isOverwriteSafe(target)))
175
+ return target;
176
+ const { buildAiwgMdContent } = await import('./aiwg-md.js');
177
+ writeContextFileSync(target, await buildAiwgMdContent(projectPath, stagedClaudeMdContent), 'utf8');
178
+ await migrateAiwgOperatorNotes(projectPath);
179
+ return target;
150
180
  }
151
181
  //# sourceMappingURL=finalization.js.map