@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
@@ -14,35 +14,9 @@ import fsp from 'fs/promises';
14
14
  import path from 'path';
15
15
  import { glob } from 'glob';
16
16
  import { minimatch } from 'minimatch';
17
- import { parse } from 'yaml';
18
- /**
19
- * Parse YAML-style frontmatter from a markdown file
20
- * Returns key-value pairs from the --- delimited block
21
- */
22
- function parseFrontmatter(content) {
23
- const match = content.match(/^---\r?\n([\s\S]*?)\r?\n---(?:\r?\n|$)/);
24
- if (!match)
25
- return {};
26
- try {
27
- const parsed = parse(match[1]);
28
- return parsed !== null && typeof parsed === 'object' && !Array.isArray(parsed)
29
- ? parsed
30
- : {};
31
- }
32
- catch {
33
- // Invalid YAML cannot supply required metadata.
34
- return {};
35
- }
36
- }
37
- function isPresent(value) {
38
- if (value == null)
39
- return false;
40
- if (typeof value === 'string')
41
- return value.trim().length > 0;
42
- if (Array.isArray(value))
43
- return value.length > 0;
44
- return true;
45
- }
17
+ import { parseFrontmatter, runCheck } from './checks.js';
18
+ import { buildReferenceIndex } from './reference-resolution.js';
19
+ export { DEFAULT_ABSENCE_MARKERS, DEFAULT_UNCERTAINTY_PATTERNS, DEFAULT_VERIFICATION_TARGETS, DEFAULT_OBSTACLE_PATTERNS, DATED_OUTCOME_PATTERN, CLOSURE_OUTCOME_PATTERN } from './check-patterns.js';
46
20
  /** Resolve project-relative metadata from the nearest repository/workspace marker. */
47
21
  function findProjectRoot(targetDir) {
48
22
  let dir = path.resolve(targetDir);
@@ -56,442 +30,6 @@ function findProjectRoot(targetDir) {
56
30
  dir = parent;
57
31
  }
58
32
  }
59
- const DEFAULT_REFERENCE_PATTERN = '\\bREF-\\d{3,}\\b';
60
- /**
61
- * Phrases that mark an identifier as deliberately absent (#2555). A mention
62
- * next to one of these documents a gap rather than pointing at a document, so
63
- * it is not an unresolved reference.
64
- */
65
- export const DEFAULT_ABSENCE_MARKERS = [
66
- '\\bunallocated\\b',
67
- '\\bnot in corpus\\b',
68
- '\\bskipped\\b',
69
- '\\bretired\\b',
70
- '\\bwithdrawn\\b',
71
- '\\bdeliberately (?:absent|unallocated|skipped)\\b',
72
- '\\bnever (?:allocated|assigned)\\b',
73
- '\\bdeduplicat',
74
- ];
75
- // Deliberately NOT markers: "does not exist", "missing", "no longer exists".
76
- // Those are how a broken reference is described, not how a corpus records an
77
- // intentional gap, and treating them as markers would suppress the finding this
78
- // check exists for.
79
- /**
80
- * Verification targets — things the inducting agent could have checked.
81
- *
82
- * Requiring one of these is what separates "the agent skipped a cheap check"
83
- * from "the paper's own claim is unverified". Only the first is a provenance
84
- * gap; the second is legitimate analysis, and #2523 explicitly does not ask
85
- * agents to stop declaring limitations. Validated against a 2,544-reference
86
- * corpus, where grammar-only matching made ~45% of hits paper-claim prose
87
- * ("scaling behavior above 7B is unverified", "Not confirmed (34% vs 51%)").
88
- */
89
- /**
90
- * Split a markdown line into clauses.
91
- *
92
- * Corpus prose keeps whole paragraphs, bullet bodies and changelog table rows on
93
- * a single line, so "same line" is far too coarse a scope for relating an
94
- * unperformed action to its target. Sentence and cell boundaries are the unit
95
- * that actually corresponds to one statement.
96
- */
97
- function splitClauses(line) {
98
- return line
99
- .split(/(?<=[.;:!?])\s+|\s+\u2014\s+|\s+--\s+|\|/g)
100
- .map((c) => c.trim())
101
- .filter(Boolean);
102
- }
103
- export const DEFAULT_VERIFICATION_TARGETS = [
104
- 'openreview',
105
- '(?:acl )?anthology',
106
- 'proceedings',
107
- 'camera[- ]ready',
108
- 'published version',
109
- '\\bPMLR\\b',
110
- '\\bDBLP\\b',
111
- '\\bOpenAlex\\b',
112
- 'semantic scholar',
113
- '\\bpubpeer\\b',
114
- '\\bunpaywall\\b',
115
- 'retraction|correction notice|expression of concern',
116
- 'citation (?:census|count)',
117
- 'influential citation',
118
- '\\bPDF\\b',
119
- 'full[- ]text',
120
- '\\be-?print\\b',
121
- '(?:code|project|dataset|repository|repo)\\s+(?:page|url|link|release|availability)',
122
- '\\bvenue\\b',
123
- '\\bacceptance\\b',
124
- 'source[_ ]type',
125
- ];
126
- /**
127
- * Phrases that assert a check was not performed. Drawn from real induction
128
- * output — each of these has appeared in a corpus reference doc (#2523).
129
- * Only counted when a verification target appears on the same line.
130
- */
131
- export const DEFAULT_UNCERTAINTY_PATTERNS = [
132
- '(?:was|were|is|are) not (?:retrieved|run|performed|attempted|fetched|queried|checked|acquired|probed|verified|confirmed)',
133
- 'not (?:retrieved|run|performed|attempted|fetched|queried|checked|acquired|probed|verified|confirmed)\\b',
134
- // Requires the action to be stated as unperformed. Without the trailing verb
135
- // this matched bare "no search" in unrelated prose and scope statements like
136
- // "no exhaustive census is claimed", neither of which is a skipped check.
137
- 'no (?:\\w+[ -]){0,4}(?:quer(?:y|ies)|search|census|fetch|check|lookup|probe)(?:es|s)?\\s+(?:was |were )?(?:performed|run|attempted|made|conducted|executed)',
138
- '\\b(?:is|remains) unverified\\b',
139
- '\\bunconfirmed\\b',
140
- 'rests on .{0,60} rather than an independent',
141
- ];
142
- /**
143
- * A dated outcome closes an uncertainty (#2523's "records an outcome with a
144
- * date"). The vocabulary is deliberately wider than a verb+date pair: the
145
- * retraction convention recommended alongside this rule writes
146
- * `~~<limitation>~~ **Done YYYY-MM-DD (<what closed it>).**`, which no
147
- * verb+date pattern matches, so a correctly dated retraction was rejected for
148
- * its shape (#2556).
149
- */
150
- export const DATED_OUTCOME_PATTERN = '(?:\\b(?:done|resolved|completed|closed|addressed|fixed|verified|retrieved|archived|queried|fetched|checked|probed|confirmed)\\b[^\\n]{0,60}?\\d{4}-\\d{2}-\\d{2}|\\d{4}-\\d{2}-\\d{2}[^\\n]{0,30}?\\b(?:done|resolved|completed|closed|addressed|fixed)\\b)';
151
- /**
152
- * The closure half of {@link DATED_OUTCOME_PATTERN}. Only explicit closure
153
- * verbs count outside a struck span: a date sitting anywhere near an action
154
- * verb ("...was not retrieved at induction. Induction ran 2026-09-01.") is not
155
- * an outcome, and treating it as one would discharge the very statements this
156
- * rule exists to catch.
157
- */
158
- export const CLOSURE_OUTCOME_PATTERN = '(?:\\b(?:done|resolved|completed|closed|addressed|fixed)\\b[^\\n]{0,60}?\\d{4}-\\d{2}-\\d{2}|\\d{4}-\\d{2}-\\d{2}[^\\n]{0,30}?\\b(?:done|resolved|completed|closed|addressed|fixed)\\b)';
159
- /**
160
- * Spans struck through with `~~…~~` are, by the markup's own meaning, no longer
161
- * asserted. When a dated outcome follows the span on the same line, the pair is
162
- * a completed retraction however long the struck text is — the length of the
163
- * struck span was the hidden variable behind #2556.
164
- */
165
- function retractedWithDatedOutcome(line) {
166
- const dated = new RegExp(DATED_OUTCOME_PATTERN, 'i');
167
- const strikethrough = /~~([\s\S]*?)~~/g;
168
- let match;
169
- while ((match = strikethrough.exec(line)) !== null) {
170
- if (dated.test(line.slice(match.index + match[0].length)))
171
- return true;
172
- }
173
- return false;
174
- }
175
- /** Character offsets of every `~~…~~` span on a line. */
176
- function strikethroughSpans(line) {
177
- const spans = [];
178
- const strikethrough = /~~([\s\S]*?)~~/g;
179
- let match;
180
- while ((match = strikethrough.exec(line)) !== null) {
181
- spans.push({ start: match.index, end: match.index + match[0].length });
182
- }
183
- return spans;
184
- }
185
- export const DEFAULT_OBSTACLE_PATTERNS = [
186
- '\\bHTTP\\s?[45]\\d{2}\\b',
187
- '\\b(?:401|403|404|429|451|503)\\b',
188
- 'paywall',
189
- 'closed[- ]access',
190
- 'requires? (?:a )?(?:credential|token|API key|subscription|login|account)',
191
- '\\b(?:HF_TOKEN|API[_ ]KEY)\\b',
192
- 'rate[- ]limit',
193
- 'anti[- ]bot',
194
- 'cloudflare',
195
- 'captcha',
196
- 'endpoint unknown',
197
- 'no (?:known )?endpoint',
198
- // Obstacle vocabulary observed in a real corpus: these are named obstacles,
199
- // so the statement is already a real outcome rather than a silent skip.
200
- 'proof[- ]of[- ]work',
201
- 'challenge (?:artifact|page|response)',
202
- 'returned challenge',
203
- '\\bgated\\b',
204
- 'did not render',
205
- 'green OA',
206
- // Explicit scope declarations: saying what is deliberately not claimed is an
207
- // outcome, unlike omitting the check and not saying so.
208
- 'is not (?:claimed|asserted)',
209
- 'NOT (?:recorded|asserted) as',
210
- 'evidence boundary',
211
- 'completion_evidence',
212
- 'status:\\s*(?:incomplete|blocked)',
213
- '\\b(?:queried|fetched|checked|probed|confirmed|resolved)\\s+(?:on\\s+)?\\d{4}-\\d{2}-\\d{2}',
214
- '\\bdeferred\\b.{0,40}\\b(?:because|since|due to)\\b',
215
- // An explicit dated closure ("**Done 2026-09-12 (post-induction audit).**"),
216
- // which the verb+date pattern above does not match (#2556).
217
- CLOSURE_OUTCOME_PATTERN,
218
- ];
219
- /**
220
- * Build a target-wide artifact ID index once per lint run.
221
- *
222
- * Reference documents may use either an exact filename (`REF-001.md`) or the
223
- * canonical slugged form (`REF-001-some-title.md`). Indexing the ID prefix also
224
- * makes resolution independent of a particular corpus directory layout.
225
- */
226
- function buildReferenceIndex(allFiles) {
227
- const references = new Set();
228
- for (const file of allFiles) {
229
- if (path.extname(file).toLowerCase() !== '.md')
230
- continue;
231
- const basename = path.basename(file, '.md');
232
- if (/^REF-\d+-(?:citations|radar)$/.test(basename))
233
- continue;
234
- references.add(basename);
235
- const artifactId = basename.match(/^(.+?-\d+)(?:-|$)/);
236
- if (artifactId)
237
- references.add(artifactId[1]);
238
- }
239
- return references;
240
- }
241
- /**
242
- * Preserve support for references stored outside the lint target when a rule
243
- * explicitly supplies basePath. Accept both exact and slugged filenames.
244
- */
245
- function resolvesFromBasePath(refId, targetDir, basePath, projectRoot) {
246
- const candidateDirs = new Set([
247
- path.resolve(projectRoot, basePath),
248
- path.resolve(targetDir, basePath),
249
- path.resolve(process.cwd(), basePath),
250
- ]);
251
- for (const dir of candidateDirs) {
252
- try {
253
- if (fs.existsSync(path.join(dir, `${refId}.md`)))
254
- return true;
255
- if (fs.readdirSync(dir).some(file => file.startsWith(`${refId}-`) && file.endsWith('.md'))) {
256
- return true;
257
- }
258
- }
259
- catch {
260
- // Missing or unreadable candidate directories do not resolve the ID.
261
- }
262
- }
263
- return false;
264
- }
265
- /**
266
- * Run a single check against a file's content and frontmatter
267
- */
268
- function runCheck(check, content, frontmatter, filePath, targetDir, allFiles, referenceIndex, projectRoot) {
269
- const diagnostics = [];
270
- switch (check.type) {
271
- case 'frontmatter-required': {
272
- if (!check.fields)
273
- break;
274
- for (const field of check.fields) {
275
- if (!isPresent(frontmatter[field])) {
276
- diagnostics.push({
277
- ruleId: '',
278
- ruleName: '',
279
- severity: 'error',
280
- file: filePath,
281
- message: `Missing required frontmatter field: ${field}`,
282
- fix: `Add '${field}:' to the YAML frontmatter block`,
283
- });
284
- }
285
- }
286
- break;
287
- }
288
- case 'frontmatter-format': {
289
- if (!check.field || !check.pattern)
290
- break;
291
- const value = frontmatter[check.field];
292
- if (isPresent(value) && typeof value !== 'object' && !new RegExp(check.pattern).test(String(value))) {
293
- diagnostics.push({
294
- ruleId: '',
295
- ruleName: '',
296
- severity: 'warn',
297
- file: filePath,
298
- message: `Frontmatter field '${check.field}' value '${value}' does not match pattern: ${check.pattern}`,
299
- fix: `Update '${check.field}' to match the expected format`,
300
- });
301
- }
302
- break;
303
- }
304
- case 'reference-resolves': {
305
- const refPattern = check.referencePattern || DEFAULT_REFERENCE_PATTERN;
306
- const regex = new RegExp(refPattern, 'g');
307
- const lines = content.split('\n');
308
- const absence = (check.absenceMarkers ?? DEFAULT_ABSENCE_MARKERS).map((p) => new RegExp(p, 'i'));
309
- for (let i = 0; i < lines.length; i++) {
310
- let match;
311
- while ((match = regex.exec(lines[i])) !== null) {
312
- const refId = match[0];
313
- const basePaths = check.basePath
314
- ? [check.basePath]
315
- : ['.aiwg/research/findings', 'findings', 'documentation/references', '.'];
316
- // A corpus documents its deliberate gaps ("REF-2464 remains
317
- // unallocated after deduplication"). Reading that sentence as a
318
- // dangling reference left only two ways to silence an error: delete
319
- // accurate documentation, or allocate a REF that is deliberately
320
- // absent (#2555).
321
- if (absence.some((re) => re.test(lines[i])))
322
- continue;
323
- if (!referenceIndex.has(refId) && !basePaths.some(basePath => resolvesFromBasePath(refId, targetDir, basePath, projectRoot))) {
324
- diagnostics.push({
325
- ruleId: '',
326
- ruleName: '',
327
- severity: 'error',
328
- file: filePath,
329
- message: `Reference '${refId}' does not resolve to an existing file`,
330
- line: i + 1,
331
- });
332
- }
333
- }
334
- }
335
- break;
336
- }
337
- case 'unregistered-uncertainty': {
338
- // An uncertainty written only into prose is invisible to the verification
339
- // contract: it was never a declared check, so it never surfaces as
340
- // `incomplete` and the "never report skipped verification as success" rule
341
- // is never violated. Flag the bare form; accept it once a specific
342
- // obstacle is named or an outcome is recorded (#2523).
343
- const uncertainty = (check.uncertaintyPatterns ?? DEFAULT_UNCERTAINTY_PATTERNS)
344
- .map((p) => new RegExp(p, 'i'));
345
- const targets = (check.verificationTargets ?? DEFAULT_VERIFICATION_TARGETS)
346
- .map((p) => new RegExp(p, 'i'));
347
- const obstacle = (check.obstaclePatterns ?? DEFAULT_OBSTACLE_PATTERNS)
348
- .map((p) => new RegExp(p, 'i'));
349
- const within = check.obstacleWithinLines ?? 2;
350
- const lines = content.split('\n');
351
- for (let i = 0; i < lines.length; i++) {
352
- // Both conditions must hold in the SAME CLAUSE: an unperformed action
353
- // AND something the agent could have acted on. Without the target, the
354
- // match is as likely to be the paper's own limitation, which must stay
355
- // untouched. Without clause scoping, a long markdown line relates two
356
- // unrelated clauses — real corpus prose puts whole paragraphs and
357
- // changelog tables on one line, which produced most false positives.
358
- const clause = splitClauses(lines[i]).find((c) => uncertainty.some((re) => re.test(c)) && targets.some((re) => re.test(c)));
359
- if (!clause)
360
- continue;
361
- // A struck span followed by a dated outcome is a completed retraction,
362
- // whatever its length. Clause scoping otherwise ends the window before
363
- // the `**Done <date>**` that closes it, so the recommended convention
364
- // failed for two-sentence struck text and passed for one (#2556).
365
- const clauseAt = lines[i].indexOf(clause);
366
- const struck = clauseAt >= 0 && strikethroughSpans(lines[i])
367
- .some((span) => clauseAt >= span.start && clauseAt < span.end);
368
- if (struck && retractedWithDatedOutcome(lines[i]))
369
- continue;
370
- // Look in the matching line and the following `within` lines: the
371
- // obstacle normally sits in the same sentence or the next one.
372
- const window = lines.slice(i, i + within + 1).join(' ');
373
- if (obstacle.some((re) => re.test(window)))
374
- continue;
375
- diagnostics.push({
376
- ruleId: '',
377
- ruleName: '',
378
- // Left unset so the rule's declared severity applies (see runRule).
379
- // This is a prose heuristic, so the shipped rule declares `warn`; an
380
- // operator can raise it to error once a corpus is clean.
381
- severity: undefined,
382
- file: filePath,
383
- line: i + 1,
384
- message: `Uncertainty stated without a named obstacle or recorded outcome: ${clause.trim().slice(0, 160)}`,
385
- fix: 'Resolve it if it costs about one request against a known endpoint, or name the specific obstacle (HTTP status, credential required, rate limited, paywalled) so it lands as incomplete/blocked rather than narrative. If the check has since been done, retract the statement with the dated form — `~~<original limitation>~~ **Done YYYY-MM-DD (<what closed it>).** <evidence>` — which closes it whatever the length of the struck text.',
386
- });
387
- }
388
- break;
389
- }
390
- case 'pattern-match': {
391
- if (!check.pattern)
392
- break;
393
- const regex = new RegExp(check.pattern);
394
- if (!regex.test(content)) {
395
- diagnostics.push({
396
- ruleId: '',
397
- ruleName: '',
398
- severity: 'warn',
399
- file: filePath,
400
- message: `File content does not match expected pattern: ${check.pattern}`,
401
- });
402
- }
403
- break;
404
- }
405
- case 'file-exists': {
406
- if (!check.field)
407
- break;
408
- const refPath = frontmatter[check.field];
409
- if (isPresent(refPath)) {
410
- // Project-root-relative is canonical (#3145); target-relative paths
411
- // written for the legacy layout keep resolving.
412
- const found = typeof refPath === 'string' &&
413
- [projectRoot, targetDir].some(base => fs.existsSync(path.resolve(base, refPath)));
414
- if (!found) {
415
- diagnostics.push({
416
- ruleId: '',
417
- ruleName: '',
418
- severity: 'error',
419
- file: filePath,
420
- message: `Referenced file '${refPath}' (from field '${check.field}') does not exist`,
421
- });
422
- }
423
- }
424
- break;
425
- }
426
- case 'id-unique': {
427
- // Handled at ruleset level in runRule
428
- break;
429
- }
430
- case 'id-format': {
431
- if (!check.pattern)
432
- break;
433
- const basename = path.basename(filePath, '.md');
434
- const match = basename.match(new RegExp(check.pattern));
435
- if (!match) {
436
- diagnostics.push({
437
- ruleId: '',
438
- ruleName: '',
439
- severity: 'warn',
440
- file: filePath,
441
- message: `File name '${basename}' does not match expected format: ${check.pattern}`,
442
- fix: `Rename to match the pattern ${check.pattern}`,
443
- });
444
- }
445
- else if (check.field && isPresent(frontmatter[check.field])) {
446
- const identifier = match[1] ?? match[0];
447
- const value = frontmatter[check.field];
448
- if (value !== identifier) {
449
- diagnostics.push({
450
- ruleId: '',
451
- ruleName: '',
452
- severity: 'warn',
453
- file: filePath,
454
- message: `File identifier '${identifier}' does not match frontmatter field '${check.field}': ${String(value)}`,
455
- fix: `Make the filename identifier and '${check.field}' field agree`,
456
- });
457
- }
458
- }
459
- break;
460
- }
461
- case 'cross-ref-bidirectional': {
462
- const refPattern = check.referencePattern || DEFAULT_REFERENCE_PATTERN;
463
- const regex = new RegExp(refPattern, 'g');
464
- const currentBasename = path.basename(filePath, '.md');
465
- const matches = content.match(regex) || [];
466
- for (const ref of matches) {
467
- if (ref === currentBasename)
468
- continue;
469
- // Find the referenced file
470
- const refFile = allFiles.find(f => path.basename(f, '.md') === ref);
471
- if (refFile) {
472
- try {
473
- const refContent = fs.readFileSync(path.resolve(targetDir, refFile), 'utf8');
474
- if (!refContent.includes(currentBasename)) {
475
- diagnostics.push({
476
- ruleId: '',
477
- ruleName: '',
478
- severity: 'info',
479
- file: filePath,
480
- message: `References '${ref}' but '${ref}' does not reference back to '${currentBasename}'`,
481
- fix: `Add a cross-reference to '${currentBasename}' in ${ref}.md`,
482
- });
483
- }
484
- }
485
- catch {
486
- // Skip if can't read
487
- }
488
- }
489
- }
490
- break;
491
- }
492
- }
493
- return diagnostics;
494
- }
495
33
  /**
496
34
  * Candidate paths a rule glob may be written against (#2555).
497
35
  *
@@ -354,7 +354,7 @@ export function mcpJson(data) {
354
354
  /**
355
355
  * Read AIWG CLI command registry to build the command-run allow-list.
356
356
  *
357
- * Lazily loaded from `src/extensions/commands/definitions.ts` — extracts
357
+ * Lazily loaded from `src/extensions/commands/definitions.ts` and its sibling command modules — extracts
358
358
  * `id:` fields. Cached after first read.
359
359
  */
360
360
  let _commandIds = null;
@@ -367,14 +367,24 @@ export async function loadCommandAllowList() {
367
367
  path.resolve(process.cwd(), 'src/extensions/commands/definitions.ts'),
368
368
  ];
369
369
  let text = '';
370
+ let found = null;
370
371
  for (const c of candidates) {
371
372
  try {
372
373
  text = await fs.readFile(c, 'utf-8');
374
+ found = c;
373
375
  break;
374
376
  } catch {
375
377
  // try next
376
378
  }
377
379
  }
380
+ if (text) {
381
+ // definitions.ts imports command groups from sibling modules (for example daemon.ts);
382
+ // read each one it imports so their ids are allowed too. A missing sibling is skipped.
383
+ const dir = path.dirname(found);
384
+ for (const [, name] of text.matchAll(/from '\.\/([A-Za-z0-9-]+)\.js'/g)) {
385
+ try { text += '\n' + await fs.readFile(path.join(dir, `${name}.ts`), 'utf-8'); } catch { /* skipped */ }
386
+ }
387
+ }
378
388
  if (!text) {
379
389
  // Installed packages need not contain TypeScript sources. Ask the CLI for
380
390
  // its versioned canonical registry; human help is incomplete and contains examples.
@@ -6,7 +6,7 @@
6
6
  */
7
7
  import { createHash } from 'node:crypto';
8
8
  import { existsSync } from 'node:fs';
9
- import { mkdir, readFile, rename, rm, writeFile } from 'node:fs/promises';
9
+ import { lstat, mkdir, readFile, readdir, rename, rm, rmdir, writeFile } from 'node:fs/promises';
10
10
  import { homedir } from 'node:os';
11
11
  import path from 'node:path';
12
12
  import { boundedExecFileSync } from '../process/bounded-child-process.mjs';
@@ -159,9 +159,33 @@ export async function relocateProjectMemory(id, newMemoryRoot) {
159
159
  throw new Error(`No project memory entry with id '${id}'`);
160
160
  const oldRoot = entry.memoryRoot;
161
161
  const nextRoot = expandUserPath(newMemoryRoot);
162
- if (oldRoot !== nextRoot && existsSync(oldRoot) && !existsSync(nextRoot)) {
163
- await mkdir(path.dirname(nextRoot), { recursive: true });
164
- await rename(oldRoot, nextRoot);
162
+ if (oldRoot !== nextRoot) {
163
+ const destination = await lstat(nextRoot).catch(error => {
164
+ if (error.code === 'ENOENT')
165
+ return undefined;
166
+ throw error;
167
+ });
168
+ if (destination && (!destination.isDirectory() || (await readdir(nextRoot)).length > 0)) {
169
+ throw new Error(`Cannot relocate project memory from '${oldRoot}' to '${nextRoot}': destination is not empty`);
170
+ }
171
+ if (existsSync(oldRoot)) {
172
+ const createdParents = [];
173
+ try {
174
+ await createRelocationParents(path.dirname(nextRoot), createdParents);
175
+ // Rename can replace an empty directory; do not remove it before a move that may fail.
176
+ await rename(oldRoot, nextRoot);
177
+ }
178
+ catch (error) {
179
+ for (const parent of createdParents.reverse()) {
180
+ // Never remove contents another writer added, or mask the original move error.
181
+ await rmdir(parent).catch(() => { });
182
+ }
183
+ throw error;
184
+ }
185
+ }
186
+ else {
187
+ await ensureMemoryLayout(nextRoot);
188
+ }
165
189
  }
166
190
  else {
167
191
  await ensureMemoryLayout(nextRoot);
@@ -171,6 +195,22 @@ export async function relocateProjectMemory(id, newMemoryRoot) {
171
195
  await writeProjectMemoryManifest(manifest);
172
196
  return entry;
173
197
  }
198
+ // Track only mkdir calls we won, so rollback cannot claim another writer's parents.
199
+ async function createRelocationParents(directory, created) {
200
+ try {
201
+ await mkdir(directory);
202
+ created.push(directory);
203
+ }
204
+ catch (error) {
205
+ const code = error.code;
206
+ if (code === 'EEXIST')
207
+ return;
208
+ if (code !== 'ENOENT')
209
+ throw error;
210
+ await createRelocationParents(path.dirname(directory), created);
211
+ await createRelocationParents(directory, created);
212
+ }
213
+ }
174
214
  export async function removeProjectMemory(id, opts = {}) {
175
215
  const manifest = await readProjectMemoryManifest();
176
216
  const entry = manifest.projects.find((p) => p.id === id);