@aiwg/cli 2026.10.15 → 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 (180) hide show
  1. package/agentic/code/providers/pi/aiwg-bridge.ts +45 -7
  2. package/dist/src/artifacts/citation-parser.js +7 -6
  3. package/dist/src/artifacts/corpus-tools/citation-densify.js +4 -2
  4. package/dist/src/artifacts/corpus-tools/cli.js +8 -3
  5. package/dist/src/artifacts/corpus-tools/discovery-log.js +26 -24
  6. package/dist/src/artifacts/corpus-tools/expand-cli.js +3 -2
  7. package/dist/src/artifacts/corpus-tools/expand-dates.js +107 -0
  8. package/dist/src/artifacts/corpus-tools/expand-queue.js +4 -1
  9. package/dist/src/artifacts/corpus-tools/expand-review.js +104 -0
  10. package/dist/src/artifacts/corpus-tools/expand-state.js +17 -1
  11. package/dist/src/artifacts/corpus-tools/expand.js +16 -17
  12. package/dist/src/artifacts/corpus-tools/induction-audit.js +7 -6
  13. package/dist/src/artifacts/corpus-tools/integrity-scan.js +3 -3
  14. package/dist/src/artifacts/corpus-tools/radar-shared.js +7 -9
  15. package/dist/src/artifacts/corpus-tools/ref-files.js +11 -0
  16. package/dist/src/artifacts/corpus-tools/resolve-cli.js +11 -3
  17. package/dist/src/artifacts/corpus-tools/resolve.js +23 -9
  18. package/dist/src/artifacts/corpus-tools/retrieval-lab.js +2 -1
  19. package/dist/src/artifacts/corpus-tools/sidecar-lint.js +4 -4
  20. package/dist/src/artifacts/corpus-tools/sidecar-repair.js +2 -1
  21. package/dist/src/artifacts/corpus-views/ref-parser.js +3 -17
  22. package/dist/src/artifacts/graph-query.js +5 -3
  23. package/dist/src/artifacts/hybrid-query.js +11 -2
  24. package/dist/src/artifacts/index-refresh.js +2 -0
  25. package/dist/src/cli/handlers/daemon.js +17 -1
  26. package/dist/src/cli/handlers/doctor-args.js +10 -5
  27. package/dist/src/cli/handlers/doctor-help.js +4 -1
  28. package/dist/src/cli/handlers/index.js +2 -2
  29. package/dist/src/cli/handlers/models-resource-sample.js +10 -0
  30. package/dist/src/cli/handlers/models.js +3 -2
  31. package/dist/src/cli/handlers/regenerate.js +8 -16
  32. package/dist/src/cli/handlers/sessions.js +7 -7
  33. package/dist/src/cli/handlers/subcommands.js +8 -0
  34. package/dist/src/cli/handlers/update.js +157 -0
  35. package/dist/src/cli/handlers/use.js +14 -4
  36. package/dist/src/cli/handlers/utilities.js +3 -560
  37. package/dist/src/cli/handlers/utility-doctor.js +412 -0
  38. package/dist/src/cli/services/deployment-verification.js +0 -1
  39. package/dist/src/config/aiwg-config.js +2 -1
  40. package/dist/src/config/authorization-cli.js +7 -3
  41. package/dist/src/config/dispatch-thresholds-runtime.d.mts +3 -2
  42. package/dist/src/config/dispatch-thresholds-runtime.mjs +17 -7
  43. package/dist/src/config/framework-aliases.js +12 -0
  44. package/dist/src/config/host-resource-report.d.mts +19 -0
  45. package/dist/src/config/host-resource-report.mjs +80 -0
  46. package/dist/src/config/host-resource-runtime.d.mts +34 -0
  47. package/dist/src/config/host-resource-runtime.mjs +293 -0
  48. package/dist/src/config/installed-selection.js +22 -0
  49. package/dist/src/config/worker-invocation-marker.d.mts +1 -0
  50. package/dist/src/config/worker-invocation-marker.mjs +2 -0
  51. package/dist/src/decision/heldout/access.js +74 -0
  52. package/dist/src/decision/heldout/calibration.js +1 -0
  53. package/dist/src/decision/heldout/collector.js +8 -1
  54. package/dist/src/effects/verifiers/file.js +22 -5
  55. package/dist/src/extensions/claude-attribution.js +82 -0
  56. package/dist/src/extensions/claude-hooks-installer.js +115 -69
  57. package/dist/src/extensions/commands/daemon.js +109 -0
  58. package/dist/src/extensions/commands/definitions.js +5 -89
  59. package/dist/src/gates/heldout.js +17 -7
  60. package/dist/src/lint/check-patterns.js +163 -0
  61. package/dist/src/lint/checks.js +268 -0
  62. package/dist/src/lint/reference-resolution.js +54 -0
  63. package/dist/src/lint/runner.js +3 -465
  64. package/dist/src/mcp/helpers.mjs +11 -1
  65. package/dist/src/memory/project-registry.js +44 -4
  66. package/dist/src/models/worker-plan.js +36 -5
  67. package/dist/src/models/wrapper-deployment.js +25 -12
  68. package/dist/src/models/wrapper-enforcement.js +47 -7
  69. package/dist/src/network-analysis/research.js +2 -1
  70. package/dist/src/policy/hitl-check.js +14 -4
  71. package/dist/src/policy/hitl-consume.js +54 -0
  72. package/dist/src/policy/hitl-receipt.js +2 -0
  73. package/dist/src/policy/hitl.js +11 -3
  74. package/dist/src/providers/provider-context-contracts.js +162 -0
  75. package/dist/src/providers/provider-definition-schema.js +136 -0
  76. package/dist/src/providers/provider-definitions.js +8 -1298
  77. package/dist/src/providers/provider-seeds-1.js +360 -0
  78. package/dist/src/providers/provider-seeds-2.js +387 -0
  79. package/dist/src/providers/provider-seeds-3.js +262 -0
  80. package/dist/src/research/clients/arxiv.js +4 -30
  81. package/dist/src/research/clients/base.js +48 -22
  82. package/dist/src/research/identity.js +34 -2
  83. package/dist/src/research/query-cli.js +3 -87
  84. package/dist/src/research/query-options.js +87 -0
  85. package/dist/src/research/reference-match.js +70 -24
  86. package/dist/src/research/services/acquisition.js +9 -7
  87. package/dist/src/research/services/citation.js +5 -2
  88. package/dist/src/research/types.js +2 -0
  89. package/dist/src/serve/mission-conductor.js +48 -4
  90. package/dist/src/sessions/adapters/grok-build-native.js +23 -0
  91. package/dist/src/sessions/adapters/grok-build.js +14 -7
  92. package/dist/src/sessions/workspace-discovery.js +5 -5
  93. package/dist/src/smiths/context-pipeline/aiwg-md.js +16 -46
  94. package/dist/src/smiths/context-pipeline/claude-hook.js +1 -1
  95. package/dist/src/smiths/context-pipeline/code-regions.js +28 -0
  96. package/dist/src/smiths/context-pipeline/finalization.js +81 -51
  97. package/dist/src/smiths/context-pipeline/generator.js +9 -10
  98. package/dist/src/smiths/context-pipeline/managed-hook.js +1 -1
  99. package/dist/src/smiths/context-pipeline/muse-bridge.js +2 -2
  100. package/dist/src/smiths/context-pipeline/provider-policy.js +6 -12
  101. package/dist/src/smiths/context-pipeline/workspace-audit.js +299 -0
  102. package/dist/src/smiths/context-pipeline/workspace-bootstrap.js +148 -0
  103. package/dist/src/smiths/context-pipeline/workspace-context-shared.js +111 -0
  104. package/dist/src/smiths/context-pipeline/workspace-context.js +8 -1373
  105. package/dist/src/smiths/context-pipeline/workspace-doctor.js +192 -0
  106. package/dist/src/smiths/context-pipeline/workspace-document.js +201 -0
  107. package/dist/src/smiths/context-pipeline/workspace-extraction.js +205 -0
  108. package/dist/src/smiths/context-pipeline/workspace-migration.js +250 -0
  109. package/package.json +10 -1
  110. package/schemas/decision/D29Study.v10.schema.json +65 -0
  111. package/tools/agents/deploy-agents.mjs +10 -0
  112. package/tools/agents/providers/claude-post-deploy.mjs +12 -1
  113. package/tools/agents/providers/context-write.mjs +4 -0
  114. package/tools/agents/providers/pi.mjs +3 -1
  115. package/tools/agents/providers/rule-delivery-surface.mjs +332 -0
  116. package/tools/agents/providers/rule-delivery.mjs +20 -1144
  117. package/tools/agents/providers/rule-deployment-commit.mjs +144 -0
  118. package/tools/agents/providers/rule-deployment-prepare.mjs +452 -0
  119. package/tools/agents/providers/rule-deployment-state.mjs +300 -0
  120. package/tools/daemon/README.md +511 -0
  121. package/tools/daemon/adapters/base-adapter.mjs +84 -0
  122. package/tools/daemon/adapters/webhook-adapter.mjs +107 -0
  123. package/tools/daemon/agent-supervisor.mjs +299 -0
  124. package/tools/daemon/automation-engine.mjs +310 -0
  125. package/tools/daemon/autonomous-engine.mjs +346 -0
  126. package/tools/daemon/behavior-loader.mjs +316 -0
  127. package/tools/daemon/behavior.mjs +174 -0
  128. package/tools/daemon/concierge/intent-router.mjs +401 -0
  129. package/tools/daemon/concierge/orchestrator.mjs +272 -0
  130. package/tools/daemon/concierge/response-translator.mjs +462 -0
  131. package/tools/daemon/config.mjs +377 -0
  132. package/tools/daemon/cron-scheduler.mjs +178 -0
  133. package/tools/daemon/daemon-main.mjs +1169 -0
  134. package/tools/daemon/event-router.mjs +84 -0
  135. package/tools/daemon/file-watcher.mjs +383 -0
  136. package/tools/daemon/index.mjs +1181 -0
  137. package/tools/daemon/init-profile.mjs +124 -0
  138. package/tools/daemon/ipc-client.mjs +197 -0
  139. package/tools/daemon/ipc-ops-handlers.mjs +236 -0
  140. package/tools/daemon/ipc-server.mjs +275 -0
  141. package/tools/daemon/maintenance-owner.mjs +79 -0
  142. package/tools/daemon/memory-manager.mjs +386 -0
  143. package/tools/daemon/message-router.mjs +194 -0
  144. package/tools/daemon/provider-watcher.mjs +585 -0
  145. package/tools/daemon/pty-adapter.mjs +420 -0
  146. package/tools/daemon/repl-chat.mjs +359 -0
  147. package/tools/daemon/resource-bounds.mjs +88 -0
  148. package/tools/daemon/sandbox-transport.mjs +295 -0
  149. package/tools/daemon/scheduled-task-runner.mjs +535 -0
  150. package/tools/daemon/task-store.mjs +450 -0
  151. package/tools/daemon/tmux-manager.mjs +324 -0
  152. package/tools/daemon/update-policy.mjs +517 -0
  153. package/tools/daemon/web-server.mjs +399 -0
  154. package/tools/daemon/web-ui/index.html +585 -0
  155. package/tools/daemon/web-ui/styles.css +156 -0
  156. package/tools/docker/Dockerfile.daemon +35 -0
  157. package/tools/docker/container-manager.mjs +291 -0
  158. package/tools/messaging/adapter-registry.mjs +230 -0
  159. package/tools/messaging/adapters/base.mjs +326 -0
  160. package/tools/messaging/adapters/discord.mjs +462 -0
  161. package/tools/messaging/adapters/slack.mjs +402 -0
  162. package/tools/messaging/adapters/telegram.mjs +552 -0
  163. package/tools/messaging/chat-handler.mjs +297 -0
  164. package/tools/messaging/command-router.mjs +269 -0
  165. package/tools/messaging/event-bus.mjs +199 -0
  166. package/tools/messaging/index.mjs +456 -0
  167. package/tools/messaging/message-formatter.mjs +320 -0
  168. package/tools/messaging/room-manager.mjs +277 -0
  169. package/tools/messaging/types.mjs +94 -0
  170. package/tools/providers/pi-bridge-policy.mjs +4 -0
  171. package/tools/ralph-external/daemon-supervisor.mjs +394 -0
  172. package/tools/ralph-external/lib/behavior-registry.mjs +270 -0
  173. package/tools/ralph-external/lib/worker-invocation-processes.mjs +3 -2
  174. package/tools/ralph-external/lib/worker-isolation-args.mjs +217 -0
  175. package/tools/ralph-external/lib/worker-isolation-status.mjs +19 -0
  176. package/tools/ralph-external/lib/worker-isolation.mjs +11 -237
  177. package/tools/ralph-external/lib/worker-overflow.mjs +10 -2
  178. package/tools/ralph-external/lib/worker-unit-cleanup.mjs +72 -0
  179. package/tools/ralph-external/session-launcher.mjs +7 -7
  180. package/tools/scripts/resource-preflight.mjs +3 -242
@@ -25,6 +25,9 @@
25
25
  import { routeMission } from './agent-router.js';
26
26
  import { StackAdapterRegistry } from './stack-adapters.js';
27
27
  import { assertMissionWorkerHandoff } from '../mission-protocol/codecs.js';
28
+ import { lookupEffect, reconcileEffect, recordIntent } from '../effects/ledger.js';
29
+ import { createVerifierRegistry } from '../effects/verifiers/registry.js';
30
+ import { fileDigestVerifier } from '../effects/verifiers/file.js';
28
31
  /**
29
32
  * The cross-stack Mission conductor. Decomposes a Mission into worker cycles,
30
33
  * dispatches each to an executor of the chosen runtime via `routeMission`, and
@@ -35,11 +38,13 @@ export class MissionConductor {
35
38
  runWorker;
36
39
  scoreOutput;
37
40
  scorerId;
41
+ effectLedger;
38
42
  constructor(opts = {}) {
39
43
  this.adapters = opts.adapters ?? new StackAdapterRegistry();
40
44
  this.runWorker = opts.runWorker;
41
45
  this.scoreOutput = opts.scoreOutput;
42
46
  this.scorerId = opts.scoreOutput ? (opts.scorerId ?? 'custom') : null;
47
+ this.effectLedger = opts.effectLedger;
43
48
  }
44
49
  /**
45
50
  * Conduct a Mission across the given executor pool. Returns the ledger.
@@ -153,10 +158,49 @@ export class MissionConductor {
153
158
  }
154
159
  let output;
155
160
  let cost = 0;
161
+ let reason = routing.selected.matchReason;
156
162
  try {
157
- const ran = await this.runWorker(cycle, executor, invocation);
158
- output = ran.output;
159
- cost = ran.cost ?? 0;
163
+ let intent;
164
+ let recovered = false;
165
+ const effects = this.effectLedger;
166
+ const reconcile = (id) => reconcileEffect(effects, id, {
167
+ verifiers: createVerifierRegistry([fileDigestVerifier({ root: effects.projectDir })]),
168
+ expected: { previousDigest: cycle.fileEffect.previousDigest ?? null },
169
+ });
170
+ if (cycle.fileEffect) {
171
+ if (!effects)
172
+ throw new Error('file effect requires a host-configured effect ledger');
173
+ const { target, payloadDigest, previousDigest } = cycle.fileEffect;
174
+ intent = await recordIntent(effects, {
175
+ kind: 'file.digest', target, payloadDigest,
176
+ context: { missionId: plan.missionId, cycleId: cycle.id,
177
+ ...(previousDigest === undefined ? {} : { previousDigest }) },
178
+ });
179
+ const recorded = await lookupEffect(effects, intent.effectId);
180
+ if (recorded.tombstoned || recorded.records.some(record => record.phase === 'failed')) {
181
+ throw new Error(`file effect ${intent.effectId} replay blocked: terminal outcome or tombstone`);
182
+ }
183
+ recovered = recorded.records.some(record => record.phase === 'completed');
184
+ if (!recovered) {
185
+ const checked = await reconcile(intent.effectId);
186
+ if (checked.result.verification.result === 'unknown') {
187
+ throw new Error(`file effect ${intent.effectId} replay blocked: ${checked.result.verification.reason}`);
188
+ }
189
+ recovered = checked.completed !== null;
190
+ }
191
+ if (recovered)
192
+ reason = `file effect ${intent.effectId} completed; worker replay skipped`;
193
+ }
194
+ if (!recovered) {
195
+ const ran = await this.runWorker(cycle, executor, invocation);
196
+ output = ran.output;
197
+ cost = ran.cost ?? 0;
198
+ if (intent) {
199
+ const checked = await reconcile(intent.effectId);
200
+ if (!checked.completed)
201
+ throw new Error(`file effect ${intent.effectId} completion unverified: ${checked.result.verification.reason}`);
202
+ }
203
+ }
160
204
  }
161
205
  catch (err) {
162
206
  const result = {
@@ -180,7 +224,7 @@ export class MissionConductor {
180
224
  primitive: adapter.primitive,
181
225
  executorId: executor.executorId,
182
226
  routed: true,
183
- reason: routing.selected.matchReason,
227
+ reason,
184
228
  output,
185
229
  cost,
186
230
  ...(graph ? { graph } : {}),
@@ -15,6 +15,26 @@ export const GROK_BUILD_ACTIVE_SESSIONS_SCHEMA_VERSION = 1;
15
15
  export const GROK_BUILD_ACTIVE_FRESHNESS_MS = 120_000;
16
16
  export const GROK_BUILD_NATIVE_DISCOVERY_MAX_FILES = 10_000;
17
17
  const ACTIVE_SESSIONS_MAX_BYTES = 1024 * 1024;
18
+ export function grokBuildNativeEnabled() {
19
+ return process.env.AIWG_GROK_BUILD_NATIVE_EXPERIMENTAL === '1';
20
+ }
21
+ /** One availability message for native readers, discovery and CLI capability reports. */
22
+ export function grokBuildNativeAvailability() {
23
+ const enabled = grokBuildNativeEnabled();
24
+ return {
25
+ reasonCode: enabled ? 'GROK_BUILD_NATIVE_EXPERIMENTAL_ENABLED' : 'GROK_BUILD_NATIVE_EXPERIMENTAL_DISABLED',
26
+ remediation: `Grok Build native ingestion is experimental and ${enabled ? 'enabled but' : 'disabled by default because it is'} `
27
+ + 'unqualified: no released-binary schema or version range is qualified. '
28
+ + 'AIWG_GROK_BUILD_NATIVE_EXPERIMENTAL=1 opts in to synthetic v1 chat_history.jsonl and active_sessions.json only; '
29
+ + 'authorize the sessions root separately with --grok-root and the optional registry file with --grok-active-sessions. '
30
+ + 'Use `grok export <session-id> <session-id>.md` and import the authorized Markdown file for the documented CLI path.',
31
+ };
32
+ }
33
+ export function assertGrokBuildNativeEnabled() {
34
+ if (!grokBuildNativeEnabled()) {
35
+ throw new SessionContractError('UNSUPPORTED_OPERATION', grokBuildNativeAvailability().remediation);
36
+ }
37
+ }
18
38
  const UUID = /^[0-9a-f]{8}-[0-9a-f]{4}-[1-8][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/i;
19
39
  // Synthetic native record shape (v1): one JSON object per line. Real
20
40
  // chat_history.jsonl schemas are unqualified (real stores are never read),
@@ -59,6 +79,7 @@ export function grokBuildNativeSessionId(locator) {
59
79
  }
60
80
  /** Enumerate documented `<root>/<url-encoded cwd>/<id>/chat_history.jsonl` paths. */
61
81
  export async function* discoverGrokBuildNativeChatHistories(root, maxFiles = GROK_BUILD_NATIVE_DISCOVERY_MAX_FILES) {
82
+ assertGrokBuildNativeEnabled();
62
83
  const resolved = resolve(root);
63
84
  let workspaces;
64
85
  try {
@@ -125,6 +146,7 @@ export async function grokBuildSourceWorkspaceMatch(locator, workspacePath) {
125
146
  return matchSessionWorkspace(decoded, workspacePath);
126
147
  }
127
148
  export async function readGrokBuildNativeChatHistory(source, limits) {
149
+ assertGrokBuildNativeEnabled();
128
150
  const sessionId = grokBuildNativeSessionId(source.locator);
129
151
  if (source.locatorClass !== GROK_BUILD_NATIVE_LOCATOR_CLASS || !sessionId) {
130
152
  throw new SessionContractError('SOURCE_NOT_AUTHORIZED', 'Grok Build native source must be an explicitly authorized chat_history.jsonl path');
@@ -205,6 +227,7 @@ export function toGrokBuildNativeRecord(sessionId, entry) {
205
227
  }
206
228
  /** Read and validate active_sessions.json (read-only, bounded); throws on misuse. */
207
229
  export async function readGrokBuildActiveRegistry(selectedPath, allowedRoots) {
230
+ assertGrokBuildNativeEnabled();
208
231
  const authorized = await authorizeSourceFile({
209
232
  selectedPath, allowedRoots, maxBytes: ACTIVE_SESSIONS_MAX_BYTES,
210
233
  });
@@ -1,19 +1,19 @@
1
1
  import { basename, extname } from 'node:path';
2
2
  import { SessionContractError, schemaIssueDetail, } from '../contracts.js';
3
3
  import { readBoundedText } from '../readers.js';
4
- import { discoverGrokBuildNativeChatHistories, GROK_BUILD_NATIVE_DISCOVERY_MAX_FILES, GROK_BUILD_NATIVE_LOCATOR_CLASS, GROK_BUILD_NATIVE_SCHEMA_VERSION, grokBuildNativeSessionId, parseGrokBuildNativeCursor, readGrokBuildNativeChatHistory, toGrokBuildNativeRecord, } from './grok-build-native.js';
4
+ import { assertGrokBuildNativeEnabled, discoverGrokBuildNativeChatHistories, GROK_BUILD_NATIVE_DISCOVERY_MAX_FILES, GROK_BUILD_NATIVE_LOCATOR_CLASS, GROK_BUILD_NATIVE_SCHEMA_VERSION, grokBuildNativeSessionId, grokBuildNativeEnabled, parseGrokBuildNativeCursor, readGrokBuildNativeChatHistory, toGrokBuildNativeRecord, } from './grok-build-native.js';
5
5
  export const GROK_BUILD_ADAPTER_VERSION = '1.0.0';
6
6
  export const GROK_BUILD_CLI_EXPORT_SCHEMA_VERSION = '1.0.0';
7
7
  export const GROK_BUILD_CLI_EXPORT_LOCATOR_CLASS = 'grok-build-cli-markdown-export';
8
8
  /**
9
9
  * Imports the documented `grok export <session-id> <file>` surface plus the
10
- * native `chat_history.jsonl` store under an explicitly authorized
11
- * sessions root (`--grok-root`).
10
+ * experimental native `chat_history.jsonl` store with an explicit environment
11
+ * opt-in and an explicitly authorized sessions root (`--grok-root`).
12
12
  *
13
13
  * The public export contract is intentionally lossy. Native reads use the
14
14
  * synthetic v1 schema in grok-build-native.ts (real stores were never
15
- * inspected); anything outside it fails closed. AIWG never runs
16
- * `grok export` itself: export remains an operator-selected fallback.
15
+ * inspected); anything outside it fails closed. This adapter never invokes
16
+ * `grok export` automatically: CLI export remains operator-selected.
17
17
  */
18
18
  export class GrokBuildSessionAdapter {
19
19
  limits;
@@ -21,13 +21,18 @@ export class GrokBuildSessionAdapter {
21
21
  provider = 'grok-build';
22
22
  adapterVersion = GROK_BUILD_ADAPTER_VERSION;
23
23
  disposition = 'implemented';
24
- supportedOperations = ['discover', 'inspect', 'stream'];
25
- acquisitionModes = ['manual-export', 'jsonl'];
24
+ get supportedOperations() {
25
+ return grokBuildNativeEnabled() ? ['discover', 'inspect', 'stream'] : ['inspect', 'stream'];
26
+ }
27
+ get acquisitionModes() {
28
+ return grokBuildNativeEnabled() ? ['manual-export', 'jsonl'] : ['manual-export'];
29
+ }
26
30
  constructor(limits, maxFiles = GROK_BUILD_NATIVE_DISCOVERY_MAX_FILES) {
27
31
  this.limits = limits;
28
32
  this.maxFiles = maxFiles;
29
33
  }
30
34
  async *discover(scope) {
35
+ assertGrokBuildNativeEnabled();
31
36
  if (scope.allowedRoots.length === 0) {
32
37
  throw new SessionContractError('SOURCE_NOT_AUTHORIZED', 'Grok Build native discovery requires an explicitly authorized sessions root; pass --grok-root.');
33
38
  }
@@ -53,6 +58,8 @@ export class GrokBuildSessionAdapter {
53
58
  }
54
59
  async *stream(source, cursor) {
55
60
  if (source.locatorClass === GROK_BUILD_NATIVE_LOCATOR_CLASS) {
61
+ // The experimental gate answers first, so a disabled gate never reports a locator error.
62
+ assertGrokBuildNativeEnabled();
56
63
  const sessionId = grokBuildNativeSessionId(source.locator);
57
64
  if (!sessionId) {
58
65
  throw new SessionContractError('SOURCE_NOT_AUTHORIZED', 'Grok Build native source must be an explicitly authorized chat_history.jsonl path');
@@ -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}.`));
@@ -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.
@@ -82,7 +60,7 @@ export async function buildAiwgMdContent(projectPath, stagedClaudeMdContent) {
82
60
  const CONFIG_IMPORT_PATTERN = /^\s*@\S*aiwg\.config\s*$/;
83
61
  const WORKSPACE_IMPORT_PATTERN = /^\s*@(?:\.\.\/)?WORKSPACE\.md\s*$/;
84
62
  const filtered = lines
85
- .filter((line) => !SELF_INCLUDE_PATTERN.test(line))
63
+ .filter((line) => !SELF_INCLUDE_PATTERN.test(line) && !/^\s*@(?:\.\/)?\.aiwg\/AIWG\.md\s*$/.test(line))
86
64
  .map((line) => {
87
65
  if (WORKSPACE_IMPORT_PATTERN.test(line)) {
88
66
  return 'WORKSPACE.md is the canonical project context (loaded by CLAUDE.md; read it first if your harness did not).';
@@ -102,29 +80,21 @@ export async function buildAiwgMdContent(projectPath, stagedClaudeMdContent) {
102
80
  : [
103
81
  firstLine,
104
82
  AIWG_SIGNATURE_COMMENT,
105
- '<!-- AIWG.md is the CLAUDE.md companion for non-Claude providers; same content. -->',
83
+ '<!-- Generated framework context shared by all providers. -->',
106
84
  ...rest,
107
85
  ].join('\n');
108
86
  const withParallelism = replaceOrAppendParallelismBlock(baseContent, parallelismSection);
109
87
  const withFinalization = replaceOrAppendFinalizationBlock(withParallelism, finalizationBlock);
110
- return replaceOrAppendExternalLinksBlock(withFinalization, externalLinksSection);
88
+ return foldNotes(replaceOrAppendExternalLinksBlock(withFinalization, externalLinksSection));
111
89
  }
112
- // Fallback stub.
113
- const normalizedPath = projectControlPath(projectPath, 'AIWG.md');
114
- const normalizedRelative = path.relative(projectPath, normalizedPath).replace(/\\/g, '/');
115
- const normalizedLink = normalizedRelative.startsWith('.') ? normalizedRelative : `./${normalizedRelative}`;
90
+ // A fresh non-Claude project has the same complete framework context.
116
91
  const stub = [
117
- '# AIWG.md',
118
- AIWG_SIGNATURE_COMMENT,
119
- '<!-- CLAUDE.md companion for non-Claude providers. -->',
120
- '',
121
- 'CLAUDE.md was not found at project root. AIWG.md normally mirrors that content.',
122
- `See [${normalizedRelative}](${normalizedLink}) for the project framework context.`,
123
- '',
92
+ '# AIWG.md', AIWG_SIGNATURE_COMMENT,
93
+ '<!-- Generated framework context. Project/operator context belongs in WORKSPACE.md. -->', '',
124
94
  ].join('\n');
125
95
  const withParallelism = replaceOrAppendParallelismBlock(stub, parallelismSection);
126
96
  const withFinalization = replaceOrAppendFinalizationBlock(withParallelism, finalizationBlock);
127
- return replaceOrAppendExternalLinksBlock(withFinalization, externalLinksSection);
97
+ return foldNotes(replaceOrAppendExternalLinksBlock(withFinalization, externalLinksSection));
128
98
  }
129
99
  /**
130
100
  * Public API: build AIWG.md content for a given project.
@@ -133,7 +103,7 @@ export async function buildAiwgMdContent(projectPath, stagedClaudeMdContent) {
133
103
  * AIWG.local.md operator overrides, etc.) have a single entry point in the
134
104
  * surface API without callers reaching into the implementation.
135
105
  */
136
- export async function generateAiwgMd(projectPath) {
137
- return buildAiwgMdContent(projectPath);
106
+ export async function generateAiwgMd(projectPath, stagedClaudeMdContent) {
107
+ return buildAiwgMdContent(projectPath, stagedClaudeMdContent);
138
108
  }
139
109
  //# sourceMappingURL=aiwg-md.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
@@ -8,8 +8,8 @@ import { sanitizeDescription, sanitizeTags } from './sanitizer.js';
8
8
  import { checkPathAllowed } from './allowlist.js';
9
9
  import { generateAiwgMd } from './aiwg-md.js';
10
10
  import { injectSpilloverBlock } from './overflow.js';
11
- import { writeNormalizedAiwgMd } from './finalization.js';
12
- import { shouldEmitAgentsMd, shouldEmitAiwgMd, shouldEmitClaudeMdHook } from './provider-policy.js';
11
+ import { migrateAiwgOperatorNotes } from './finalization.js';
12
+ import { shouldEmitAgentsMd, shouldEmitClaudeMdHook } from './provider-policy.js';
13
13
  import { ensureClaudeMdHook } from './claude-hook.js';
14
14
  import { ensureManagedHook } from './managed-hook.js';
15
15
  import { assertSafeContextFile, writeContextFileSync } from './context-file-safety.js';
@@ -279,10 +279,9 @@ async function writeSpilloverBlock(projectPath, spilloverMarkdown, result) {
279
279
  /**
280
280
  * Generate the canonical graph and provider startup adapters.
281
281
  *
282
- * Skeleton implementation: emits AGENTS.md with link-index sections; AIWG.md
283
- * generation is wired in commit 3 alongside the first issue closure (#1104).
284
- * For now AIWG.md emission delegates to a copy of CLAUDE.md when the source
285
- * is present; otherwise it is skipped with a warning.
282
+ * Root AIWG.md is the single generated framework context, including optional
283
+ * operator notes. Provider adapters declare their supported startup loader;
284
+ * home-only providers can still read the root context explicitly.
286
285
  */
287
286
  export async function generate(opts) {
288
287
  // Check every startup/context output before writing the first one. A linked
@@ -291,7 +290,7 @@ export async function generate(opts) {
291
290
  const plannedFiles = [
292
291
  ...(!opts.skip?.workspaceMd ? ['WORKSPACE.md'] : []),
293
292
  ...(!opts.skip?.agentsMd && shouldEmitAgentsMd(opts.provider) ? ['AGENTS.md'] : []),
294
- ...(!opts.skip?.aiwgMd && shouldEmitAiwgMd(opts.provider) ? ['AIWG.md'] : []),
293
+ ...(!opts.skip?.aiwgMd ? ['AIWG.md'] : []),
295
294
  ...(shouldEmitClaudeMdHook(opts.provider) ? ['CLAUDE.md'] : []),
296
295
  ];
297
296
  for (const file of plannedFiles)
@@ -316,8 +315,6 @@ export async function generate(opts) {
316
315
  if (workspace.backupPath)
317
316
  result.backupPaths.push(workspace.backupPath);
318
317
  }
319
- const normalizedAiwgPath = await writeNormalizedAiwgMd(opts.projectPath);
320
- result.normalizedAiwgMdPath = normalizedAiwgPath;
321
318
  // AGENTS.md emission is gated on the provider's link-mechanism: codex/copilot/
322
319
  // cursor/windsurf/hermes/warp/factory/opencode use AGENTS.md as their bridge
323
320
  // to AIWG.md. Claude uses CLAUDE.md hook instead (#1437); openclaw is
@@ -371,7 +368,7 @@ export async function generate(opts) {
371
368
  // additive hook), so this runs whether or not AGENTS.md itself was rewritten.
372
369
  await writeTwinFiles(opts.provider, opts.projectPath, built.content, opts, result);
373
370
  }
374
- if (!opts.skip?.aiwgMd && shouldEmitAiwgMd(opts.provider)) {
371
+ if (!opts.skip?.aiwgMd) {
375
372
  const aiwgMdPath = path.join(opts.projectPath, 'AIWG.md');
376
373
  let canWrite = true;
377
374
  if (opts.detectExistingFiles && !opts.force) {
@@ -400,6 +397,8 @@ export async function generate(opts) {
400
397
  const content = await generateAiwgMd(opts.projectPath);
401
398
  await atomicWrite(aiwgMdPath, content);
402
399
  result.aiwgMdPath = aiwgMdPath;
400
+ result.normalizedAiwgMdPath = aiwgMdPath; // Compatibility alias: there is only one generated context.
401
+ await migrateAiwgOperatorNotes(opts.projectPath);
403
402
  }
404
403
  }
405
404
  // CLAUDE.md hook emission for the claude provider (#1437). Mirrors how
@@ -29,7 +29,7 @@ export function buildContextHookBlock(provider = 'codex') {
29
29
  '<!--',
30
30
  ' This block is managed by `aiwg regenerate` and `aiwg use`.',
31
31
  ' Operator content above and below this block is preserved on regenerate.',
32
- ' Edit .aiwg/AIWG.md (the normalized source) then run `aiwg regenerate`.',
32
+ ' Edit WORKSPACE.md Project Context or optional .aiwg/AIWG.md operator notes, then run `aiwg regenerate`.',
33
33
  '-->',
34
34
  '',
35
35
  CONTEXT_HOOK_END,