@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.
- package/agentic/code/providers/pi/aiwg-bridge.ts +45 -7
- package/dist/src/artifacts/citation-parser.js +7 -6
- package/dist/src/artifacts/corpus-tools/citation-densify.js +4 -2
- package/dist/src/artifacts/corpus-tools/cli.js +8 -3
- package/dist/src/artifacts/corpus-tools/discovery-log.js +26 -24
- package/dist/src/artifacts/corpus-tools/expand-cli.js +3 -2
- package/dist/src/artifacts/corpus-tools/expand-dates.js +107 -0
- package/dist/src/artifacts/corpus-tools/expand-queue.js +4 -1
- package/dist/src/artifacts/corpus-tools/expand-review.js +104 -0
- package/dist/src/artifacts/corpus-tools/expand-state.js +17 -1
- package/dist/src/artifacts/corpus-tools/expand.js +16 -17
- package/dist/src/artifacts/corpus-tools/induction-audit.js +7 -6
- package/dist/src/artifacts/corpus-tools/integrity-scan.js +3 -3
- package/dist/src/artifacts/corpus-tools/radar-shared.js +7 -9
- package/dist/src/artifacts/corpus-tools/ref-files.js +11 -0
- package/dist/src/artifacts/corpus-tools/resolve-cli.js +11 -3
- package/dist/src/artifacts/corpus-tools/resolve.js +23 -9
- package/dist/src/artifacts/corpus-tools/retrieval-lab.js +2 -1
- package/dist/src/artifacts/corpus-tools/sidecar-lint.js +4 -4
- package/dist/src/artifacts/corpus-tools/sidecar-repair.js +2 -1
- package/dist/src/artifacts/corpus-views/ref-parser.js +3 -17
- package/dist/src/artifacts/graph-query.js +5 -3
- package/dist/src/artifacts/hybrid-query.js +11 -2
- package/dist/src/artifacts/index-refresh.js +2 -0
- package/dist/src/cli/handlers/daemon.js +17 -1
- package/dist/src/cli/handlers/doctor-args.js +10 -5
- package/dist/src/cli/handlers/doctor-help.js +4 -1
- package/dist/src/cli/handlers/index.js +2 -2
- package/dist/src/cli/handlers/models-resource-sample.js +10 -0
- package/dist/src/cli/handlers/models.js +3 -2
- package/dist/src/cli/handlers/regenerate.js +8 -16
- package/dist/src/cli/handlers/sessions.js +7 -7
- package/dist/src/cli/handlers/subcommands.js +8 -0
- package/dist/src/cli/handlers/update.js +157 -0
- package/dist/src/cli/handlers/use.js +14 -4
- package/dist/src/cli/handlers/utilities.js +3 -560
- package/dist/src/cli/handlers/utility-doctor.js +412 -0
- package/dist/src/cli/services/deployment-verification.js +0 -1
- package/dist/src/config/aiwg-config.js +2 -1
- package/dist/src/config/authorization-cli.js +7 -3
- package/dist/src/config/dispatch-thresholds-runtime.d.mts +3 -2
- package/dist/src/config/dispatch-thresholds-runtime.mjs +17 -7
- package/dist/src/config/framework-aliases.js +12 -0
- package/dist/src/config/host-resource-report.d.mts +19 -0
- package/dist/src/config/host-resource-report.mjs +80 -0
- package/dist/src/config/host-resource-runtime.d.mts +34 -0
- package/dist/src/config/host-resource-runtime.mjs +293 -0
- package/dist/src/config/installed-selection.js +22 -0
- package/dist/src/config/worker-invocation-marker.d.mts +1 -0
- package/dist/src/config/worker-invocation-marker.mjs +2 -0
- package/dist/src/decision/heldout/access.js +74 -0
- package/dist/src/decision/heldout/calibration.js +1 -0
- package/dist/src/decision/heldout/collector.js +8 -1
- package/dist/src/effects/verifiers/file.js +22 -5
- package/dist/src/extensions/claude-attribution.js +82 -0
- package/dist/src/extensions/claude-hooks-installer.js +115 -69
- package/dist/src/extensions/commands/daemon.js +109 -0
- package/dist/src/extensions/commands/definitions.js +5 -89
- package/dist/src/gates/heldout.js +17 -7
- package/dist/src/lint/check-patterns.js +163 -0
- package/dist/src/lint/checks.js +268 -0
- package/dist/src/lint/reference-resolution.js +54 -0
- package/dist/src/lint/runner.js +3 -465
- package/dist/src/mcp/helpers.mjs +11 -1
- package/dist/src/memory/project-registry.js +44 -4
- package/dist/src/models/worker-plan.js +36 -5
- package/dist/src/models/wrapper-deployment.js +25 -12
- package/dist/src/models/wrapper-enforcement.js +47 -7
- package/dist/src/network-analysis/research.js +2 -1
- package/dist/src/policy/hitl-check.js +14 -4
- package/dist/src/policy/hitl-consume.js +54 -0
- package/dist/src/policy/hitl-receipt.js +2 -0
- package/dist/src/policy/hitl.js +11 -3
- package/dist/src/providers/provider-context-contracts.js +162 -0
- package/dist/src/providers/provider-definition-schema.js +136 -0
- package/dist/src/providers/provider-definitions.js +8 -1298
- package/dist/src/providers/provider-seeds-1.js +360 -0
- package/dist/src/providers/provider-seeds-2.js +387 -0
- package/dist/src/providers/provider-seeds-3.js +262 -0
- package/dist/src/research/clients/arxiv.js +4 -30
- package/dist/src/research/clients/base.js +48 -22
- package/dist/src/research/identity.js +34 -2
- package/dist/src/research/query-cli.js +3 -87
- package/dist/src/research/query-options.js +87 -0
- package/dist/src/research/reference-match.js +70 -24
- package/dist/src/research/services/acquisition.js +9 -7
- package/dist/src/research/services/citation.js +5 -2
- package/dist/src/research/types.js +2 -0
- package/dist/src/serve/mission-conductor.js +48 -4
- package/dist/src/sessions/adapters/grok-build-native.js +23 -0
- package/dist/src/sessions/adapters/grok-build.js +14 -7
- package/dist/src/sessions/workspace-discovery.js +5 -5
- package/dist/src/smiths/context-pipeline/aiwg-md.js +16 -46
- package/dist/src/smiths/context-pipeline/claude-hook.js +1 -1
- package/dist/src/smiths/context-pipeline/code-regions.js +28 -0
- package/dist/src/smiths/context-pipeline/finalization.js +81 -51
- package/dist/src/smiths/context-pipeline/generator.js +9 -10
- package/dist/src/smiths/context-pipeline/managed-hook.js +1 -1
- package/dist/src/smiths/context-pipeline/muse-bridge.js +2 -2
- package/dist/src/smiths/context-pipeline/provider-policy.js +6 -12
- package/dist/src/smiths/context-pipeline/workspace-audit.js +299 -0
- package/dist/src/smiths/context-pipeline/workspace-bootstrap.js +148 -0
- package/dist/src/smiths/context-pipeline/workspace-context-shared.js +111 -0
- package/dist/src/smiths/context-pipeline/workspace-context.js +8 -1373
- package/dist/src/smiths/context-pipeline/workspace-doctor.js +192 -0
- package/dist/src/smiths/context-pipeline/workspace-document.js +201 -0
- package/dist/src/smiths/context-pipeline/workspace-extraction.js +205 -0
- package/dist/src/smiths/context-pipeline/workspace-migration.js +250 -0
- package/package.json +10 -1
- package/schemas/decision/D29Study.v10.schema.json +65 -0
- package/tools/agents/deploy-agents.mjs +10 -0
- package/tools/agents/providers/claude-post-deploy.mjs +12 -1
- package/tools/agents/providers/context-write.mjs +4 -0
- package/tools/agents/providers/pi.mjs +3 -1
- package/tools/agents/providers/rule-delivery-surface.mjs +332 -0
- package/tools/agents/providers/rule-delivery.mjs +20 -1144
- package/tools/agents/providers/rule-deployment-commit.mjs +144 -0
- package/tools/agents/providers/rule-deployment-prepare.mjs +452 -0
- package/tools/agents/providers/rule-deployment-state.mjs +300 -0
- package/tools/daemon/README.md +511 -0
- package/tools/daemon/adapters/base-adapter.mjs +84 -0
- package/tools/daemon/adapters/webhook-adapter.mjs +107 -0
- package/tools/daemon/agent-supervisor.mjs +299 -0
- package/tools/daemon/automation-engine.mjs +310 -0
- package/tools/daemon/autonomous-engine.mjs +346 -0
- package/tools/daemon/behavior-loader.mjs +316 -0
- package/tools/daemon/behavior.mjs +174 -0
- package/tools/daemon/concierge/intent-router.mjs +401 -0
- package/tools/daemon/concierge/orchestrator.mjs +272 -0
- package/tools/daemon/concierge/response-translator.mjs +462 -0
- package/tools/daemon/config.mjs +377 -0
- package/tools/daemon/cron-scheduler.mjs +178 -0
- package/tools/daemon/daemon-main.mjs +1169 -0
- package/tools/daemon/event-router.mjs +84 -0
- package/tools/daemon/file-watcher.mjs +383 -0
- package/tools/daemon/index.mjs +1181 -0
- package/tools/daemon/init-profile.mjs +124 -0
- package/tools/daemon/ipc-client.mjs +197 -0
- package/tools/daemon/ipc-ops-handlers.mjs +236 -0
- package/tools/daemon/ipc-server.mjs +275 -0
- package/tools/daemon/maintenance-owner.mjs +79 -0
- package/tools/daemon/memory-manager.mjs +386 -0
- package/tools/daemon/message-router.mjs +194 -0
- package/tools/daemon/provider-watcher.mjs +585 -0
- package/tools/daemon/pty-adapter.mjs +420 -0
- package/tools/daemon/repl-chat.mjs +359 -0
- package/tools/daemon/resource-bounds.mjs +88 -0
- package/tools/daemon/sandbox-transport.mjs +295 -0
- package/tools/daemon/scheduled-task-runner.mjs +535 -0
- package/tools/daemon/task-store.mjs +450 -0
- package/tools/daemon/tmux-manager.mjs +324 -0
- package/tools/daemon/update-policy.mjs +517 -0
- package/tools/daemon/web-server.mjs +399 -0
- package/tools/daemon/web-ui/index.html +585 -0
- package/tools/daemon/web-ui/styles.css +156 -0
- package/tools/docker/Dockerfile.daemon +35 -0
- package/tools/docker/container-manager.mjs +291 -0
- package/tools/messaging/adapter-registry.mjs +230 -0
- package/tools/messaging/adapters/base.mjs +326 -0
- package/tools/messaging/adapters/discord.mjs +462 -0
- package/tools/messaging/adapters/slack.mjs +402 -0
- package/tools/messaging/adapters/telegram.mjs +552 -0
- package/tools/messaging/chat-handler.mjs +297 -0
- package/tools/messaging/command-router.mjs +269 -0
- package/tools/messaging/event-bus.mjs +199 -0
- package/tools/messaging/index.mjs +456 -0
- package/tools/messaging/message-formatter.mjs +320 -0
- package/tools/messaging/room-manager.mjs +277 -0
- package/tools/messaging/types.mjs +94 -0
- package/tools/providers/pi-bridge-policy.mjs +4 -0
- package/tools/ralph-external/daemon-supervisor.mjs +394 -0
- package/tools/ralph-external/lib/behavior-registry.mjs +270 -0
- package/tools/ralph-external/lib/worker-invocation-processes.mjs +3 -2
- package/tools/ralph-external/lib/worker-isolation-args.mjs +217 -0
- package/tools/ralph-external/lib/worker-isolation-status.mjs +19 -0
- package/tools/ralph-external/lib/worker-isolation.mjs +11 -237
- package/tools/ralph-external/lib/worker-overflow.mjs +10 -2
- package/tools/ralph-external/lib/worker-unit-cleanup.mjs +72 -0
- package/tools/ralph-external/session-launcher.mjs +7 -7
- package/tools/scripts/resource-preflight.mjs +3 -242
|
@@ -0,0 +1,163 @@
|
|
|
1
|
+
// Shared lint patterns and clause helpers.
|
|
2
|
+
import { REF_ID_PATTERN } from '../research/identity.js';
|
|
3
|
+
export const DEFAULT_REFERENCE_PATTERN = REF_ID_PATTERN;
|
|
4
|
+
/**
|
|
5
|
+
* Phrases that mark an identifier as deliberately absent (#2555). A mention
|
|
6
|
+
* next to one of these documents a gap rather than pointing at a document, so
|
|
7
|
+
* it is not an unresolved reference.
|
|
8
|
+
*/
|
|
9
|
+
export const DEFAULT_ABSENCE_MARKERS = [
|
|
10
|
+
'\\bunallocated\\b',
|
|
11
|
+
'\\bnot in corpus\\b',
|
|
12
|
+
'\\bskipped\\b',
|
|
13
|
+
'\\bretired\\b',
|
|
14
|
+
'\\bwithdrawn\\b',
|
|
15
|
+
'\\bdeliberately (?:absent|unallocated|skipped)\\b',
|
|
16
|
+
'\\bnever (?:allocated|assigned)\\b',
|
|
17
|
+
'\\bdeduplicat',
|
|
18
|
+
];
|
|
19
|
+
// Deliberately NOT markers: "does not exist", "missing", "no longer exists".
|
|
20
|
+
// Those are how a broken reference is described, not how a corpus records an
|
|
21
|
+
// intentional gap, and treating them as markers would suppress the finding this
|
|
22
|
+
// check exists for.
|
|
23
|
+
/**
|
|
24
|
+
* Verification targets — things the inducting agent could have checked.
|
|
25
|
+
*
|
|
26
|
+
* Requiring one of these is what separates "the agent skipped a cheap check"
|
|
27
|
+
* from "the paper's own claim is unverified". Only the first is a provenance
|
|
28
|
+
* gap; the second is legitimate analysis, and #2523 explicitly does not ask
|
|
29
|
+
* agents to stop declaring limitations. Validated against a 2,544-reference
|
|
30
|
+
* corpus, where grammar-only matching made ~45% of hits paper-claim prose
|
|
31
|
+
* ("scaling behavior above 7B is unverified", "Not confirmed (34% vs 51%)").
|
|
32
|
+
*/
|
|
33
|
+
/**
|
|
34
|
+
* Split a markdown line into clauses.
|
|
35
|
+
*
|
|
36
|
+
* Corpus prose keeps whole paragraphs, bullet bodies and changelog table rows on
|
|
37
|
+
* a single line, so "same line" is far too coarse a scope for relating an
|
|
38
|
+
* unperformed action to its target. Sentence and cell boundaries are the unit
|
|
39
|
+
* that actually corresponds to one statement.
|
|
40
|
+
*/
|
|
41
|
+
export function splitClauses(line) {
|
|
42
|
+
return line
|
|
43
|
+
.split(/(?<=[.;:!?])\s+|\s+\u2014\s+|\s+--\s+|\|/g)
|
|
44
|
+
.map((c) => c.trim())
|
|
45
|
+
.filter(Boolean);
|
|
46
|
+
}
|
|
47
|
+
export const DEFAULT_VERIFICATION_TARGETS = [
|
|
48
|
+
'openreview',
|
|
49
|
+
'(?:acl )?anthology',
|
|
50
|
+
'proceedings',
|
|
51
|
+
'camera[- ]ready',
|
|
52
|
+
'published version',
|
|
53
|
+
'\\bPMLR\\b',
|
|
54
|
+
'\\bDBLP\\b',
|
|
55
|
+
'\\bOpenAlex\\b',
|
|
56
|
+
'semantic scholar',
|
|
57
|
+
'\\bpubpeer\\b',
|
|
58
|
+
'\\bunpaywall\\b',
|
|
59
|
+
'retraction|correction notice|expression of concern',
|
|
60
|
+
'citation (?:census|count)',
|
|
61
|
+
'influential citation',
|
|
62
|
+
'\\bPDF\\b',
|
|
63
|
+
'full[- ]text',
|
|
64
|
+
'\\be-?print\\b',
|
|
65
|
+
'(?:code|project|dataset|repository|repo)\\s+(?:page|url|link|release|availability)',
|
|
66
|
+
'\\bvenue\\b',
|
|
67
|
+
'\\bacceptance\\b',
|
|
68
|
+
'source[_ ]type',
|
|
69
|
+
];
|
|
70
|
+
/**
|
|
71
|
+
* Phrases that assert a check was not performed. Drawn from real induction
|
|
72
|
+
* output — each of these has appeared in a corpus reference doc (#2523).
|
|
73
|
+
* Only counted when a verification target appears on the same line.
|
|
74
|
+
*/
|
|
75
|
+
export const DEFAULT_UNCERTAINTY_PATTERNS = [
|
|
76
|
+
'(?:was|were|is|are) not (?:retrieved|run|performed|attempted|fetched|queried|checked|acquired|probed|verified|confirmed)',
|
|
77
|
+
'not (?:retrieved|run|performed|attempted|fetched|queried|checked|acquired|probed|verified|confirmed)\\b',
|
|
78
|
+
// Requires the action to be stated as unperformed. Without the trailing verb
|
|
79
|
+
// this matched bare "no search" in unrelated prose and scope statements like
|
|
80
|
+
// "no exhaustive census is claimed", neither of which is a skipped check.
|
|
81
|
+
'no (?:\\w+[ -]){0,4}(?:quer(?:y|ies)|search|census|fetch|check|lookup|probe)(?:es|s)?\\s+(?:was |were )?(?:performed|run|attempted|made|conducted|executed)',
|
|
82
|
+
'\\b(?:is|remains) unverified\\b',
|
|
83
|
+
'\\bunconfirmed\\b',
|
|
84
|
+
'rests on .{0,60} rather than an independent',
|
|
85
|
+
];
|
|
86
|
+
/**
|
|
87
|
+
* A dated outcome closes an uncertainty (#2523's "records an outcome with a
|
|
88
|
+
* date"). The vocabulary is deliberately wider than a verb+date pair: the
|
|
89
|
+
* retraction convention recommended alongside this rule writes
|
|
90
|
+
* `~~<limitation>~~ **Done YYYY-MM-DD (<what closed it>).**`, which no
|
|
91
|
+
* verb+date pattern matches, so a correctly dated retraction was rejected for
|
|
92
|
+
* its shape (#2556).
|
|
93
|
+
*/
|
|
94
|
+
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)';
|
|
95
|
+
/**
|
|
96
|
+
* The closure half of {@link DATED_OUTCOME_PATTERN}. Only explicit closure
|
|
97
|
+
* verbs count outside a struck span: a date sitting anywhere near an action
|
|
98
|
+
* verb ("...was not retrieved at induction. Induction ran 2026-09-01.") is not
|
|
99
|
+
* an outcome, and treating it as one would discharge the very statements this
|
|
100
|
+
* rule exists to catch.
|
|
101
|
+
*/
|
|
102
|
+
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)';
|
|
103
|
+
/**
|
|
104
|
+
* Spans struck through with `~~…~~` are, by the markup's own meaning, no longer
|
|
105
|
+
* asserted. When a dated outcome follows the span on the same line, the pair is
|
|
106
|
+
* a completed retraction however long the struck text is — the length of the
|
|
107
|
+
* struck span was the hidden variable behind #2556.
|
|
108
|
+
*/
|
|
109
|
+
export function retractedWithDatedOutcome(line) {
|
|
110
|
+
const dated = new RegExp(DATED_OUTCOME_PATTERN, 'i');
|
|
111
|
+
const strikethrough = /~~([\s\S]*?)~~/g;
|
|
112
|
+
let match;
|
|
113
|
+
while ((match = strikethrough.exec(line)) !== null) {
|
|
114
|
+
if (dated.test(line.slice(match.index + match[0].length)))
|
|
115
|
+
return true;
|
|
116
|
+
}
|
|
117
|
+
return false;
|
|
118
|
+
}
|
|
119
|
+
/** Character offsets of every `~~…~~` span on a line. */
|
|
120
|
+
export function strikethroughSpans(line) {
|
|
121
|
+
const spans = [];
|
|
122
|
+
const strikethrough = /~~([\s\S]*?)~~/g;
|
|
123
|
+
let match;
|
|
124
|
+
while ((match = strikethrough.exec(line)) !== null) {
|
|
125
|
+
spans.push({ start: match.index, end: match.index + match[0].length });
|
|
126
|
+
}
|
|
127
|
+
return spans;
|
|
128
|
+
}
|
|
129
|
+
export const DEFAULT_OBSTACLE_PATTERNS = [
|
|
130
|
+
'\\bHTTP\\s?[45]\\d{2}\\b',
|
|
131
|
+
'\\b(?:401|403|404|429|451|503)\\b',
|
|
132
|
+
'paywall',
|
|
133
|
+
'closed[- ]access',
|
|
134
|
+
'requires? (?:a )?(?:credential|token|API key|subscription|login|account)',
|
|
135
|
+
'\\b(?:HF_TOKEN|API[_ ]KEY)\\b',
|
|
136
|
+
'rate[- ]limit',
|
|
137
|
+
'anti[- ]bot',
|
|
138
|
+
'cloudflare',
|
|
139
|
+
'captcha',
|
|
140
|
+
'endpoint unknown',
|
|
141
|
+
'no (?:known )?endpoint',
|
|
142
|
+
// Obstacle vocabulary observed in a real corpus: these are named obstacles,
|
|
143
|
+
// so the statement is already a real outcome rather than a silent skip.
|
|
144
|
+
'proof[- ]of[- ]work',
|
|
145
|
+
'challenge (?:artifact|page|response)',
|
|
146
|
+
'returned challenge',
|
|
147
|
+
'\\bgated\\b',
|
|
148
|
+
'did not render',
|
|
149
|
+
'green OA',
|
|
150
|
+
// Explicit scope declarations: saying what is deliberately not claimed is an
|
|
151
|
+
// outcome, unlike omitting the check and not saying so.
|
|
152
|
+
'is not (?:claimed|asserted)',
|
|
153
|
+
'NOT (?:recorded|asserted) as',
|
|
154
|
+
'evidence boundary',
|
|
155
|
+
'completion_evidence',
|
|
156
|
+
'status:\\s*(?:incomplete|blocked)',
|
|
157
|
+
'\\b(?:queried|fetched|checked|probed|confirmed|resolved)\\s+(?:on\\s+)?\\d{4}-\\d{2}-\\d{2}',
|
|
158
|
+
'\\bdeferred\\b.{0,40}\\b(?:because|since|due to)\\b',
|
|
159
|
+
// An explicit dated closure ("**Done 2026-09-12 (post-induction audit).**"),
|
|
160
|
+
// which the verb+date pattern above does not match (#2556).
|
|
161
|
+
CLOSURE_OUTCOME_PATTERN,
|
|
162
|
+
];
|
|
163
|
+
//# sourceMappingURL=check-patterns.js.map
|
|
@@ -0,0 +1,268 @@
|
|
|
1
|
+
// Run content and frontmatter lint checks.
|
|
2
|
+
import fs from 'node:fs';
|
|
3
|
+
import path from 'node:path';
|
|
4
|
+
import { parse } from 'yaml';
|
|
5
|
+
import { isRefId, refIdFromFilename } from '../research/identity.js';
|
|
6
|
+
import { resolvesFromBasePath } from './reference-resolution.js';
|
|
7
|
+
import { DEFAULT_REFERENCE_PATTERN, DEFAULT_ABSENCE_MARKERS, DEFAULT_UNCERTAINTY_PATTERNS, DEFAULT_VERIFICATION_TARGETS, DEFAULT_OBSTACLE_PATTERNS, splitClauses, strikethroughSpans, retractedWithDatedOutcome } from './check-patterns.js';
|
|
8
|
+
/**
|
|
9
|
+
* Parse YAML-style frontmatter from a markdown file
|
|
10
|
+
* Returns key-value pairs from the --- delimited block
|
|
11
|
+
*/
|
|
12
|
+
export function parseFrontmatter(content) {
|
|
13
|
+
const match = content.match(/^---\r?\n([\s\S]*?)\r?\n---(?:\r?\n|$)/);
|
|
14
|
+
if (!match)
|
|
15
|
+
return {};
|
|
16
|
+
try {
|
|
17
|
+
const parsed = parse(match[1]);
|
|
18
|
+
return parsed !== null && typeof parsed === 'object' && !Array.isArray(parsed)
|
|
19
|
+
? parsed
|
|
20
|
+
: {};
|
|
21
|
+
}
|
|
22
|
+
catch {
|
|
23
|
+
// Invalid YAML cannot supply required metadata.
|
|
24
|
+
return {};
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
function isPresent(value) {
|
|
28
|
+
if (value == null)
|
|
29
|
+
return false;
|
|
30
|
+
if (typeof value === 'string')
|
|
31
|
+
return value.trim().length > 0;
|
|
32
|
+
if (Array.isArray(value))
|
|
33
|
+
return value.length > 0;
|
|
34
|
+
return true;
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* Run a single check against a file's content and frontmatter
|
|
38
|
+
*/
|
|
39
|
+
export function runCheck(check, content, frontmatter, filePath, targetDir, allFiles, referenceIndex, projectRoot) {
|
|
40
|
+
const diagnostics = [];
|
|
41
|
+
switch (check.type) {
|
|
42
|
+
case 'frontmatter-required': {
|
|
43
|
+
if (!check.fields)
|
|
44
|
+
break;
|
|
45
|
+
for (const field of check.fields) {
|
|
46
|
+
if (!isPresent(frontmatter[field])) {
|
|
47
|
+
diagnostics.push({
|
|
48
|
+
ruleId: '',
|
|
49
|
+
ruleName: '',
|
|
50
|
+
severity: 'error',
|
|
51
|
+
file: filePath,
|
|
52
|
+
message: `Missing required frontmatter field: ${field}`,
|
|
53
|
+
fix: `Add '${field}:' to the YAML frontmatter block`,
|
|
54
|
+
});
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
break;
|
|
58
|
+
}
|
|
59
|
+
case 'frontmatter-format': {
|
|
60
|
+
if (!check.field || !check.pattern)
|
|
61
|
+
break;
|
|
62
|
+
const value = frontmatter[check.field];
|
|
63
|
+
if (isPresent(value) && typeof value !== 'object' && !new RegExp(check.pattern).test(String(value))) {
|
|
64
|
+
diagnostics.push({
|
|
65
|
+
ruleId: '',
|
|
66
|
+
ruleName: '',
|
|
67
|
+
severity: 'warn',
|
|
68
|
+
file: filePath,
|
|
69
|
+
message: `Frontmatter field '${check.field}' value '${value}' does not match pattern: ${check.pattern}`,
|
|
70
|
+
fix: `Update '${check.field}' to match the expected format`,
|
|
71
|
+
});
|
|
72
|
+
}
|
|
73
|
+
break;
|
|
74
|
+
}
|
|
75
|
+
case 'reference-resolves': {
|
|
76
|
+
const refPattern = check.referencePattern || DEFAULT_REFERENCE_PATTERN;
|
|
77
|
+
const regex = new RegExp(refPattern, 'g');
|
|
78
|
+
const lines = content.split('\n');
|
|
79
|
+
const absence = (check.absenceMarkers ?? DEFAULT_ABSENCE_MARKERS).map((p) => new RegExp(p, 'i'));
|
|
80
|
+
for (let i = 0; i < lines.length; i++) {
|
|
81
|
+
let match;
|
|
82
|
+
while ((match = regex.exec(lines[i])) !== null) {
|
|
83
|
+
const refId = match[0];
|
|
84
|
+
const basePaths = check.basePath
|
|
85
|
+
? [check.basePath]
|
|
86
|
+
: ['.aiwg/research/findings', 'findings', 'documentation/references', '.'];
|
|
87
|
+
// A corpus documents its deliberate gaps ("REF-2464 remains
|
|
88
|
+
// unallocated after deduplication"). Reading that sentence as a
|
|
89
|
+
// dangling reference left only two ways to silence an error: delete
|
|
90
|
+
// accurate documentation, or allocate a REF that is deliberately
|
|
91
|
+
// absent (#2555).
|
|
92
|
+
if (absence.some((re) => re.test(lines[i])))
|
|
93
|
+
continue;
|
|
94
|
+
if (!referenceIndex.has(refId) && !basePaths.some(basePath => resolvesFromBasePath(refId, targetDir, basePath, projectRoot))) {
|
|
95
|
+
diagnostics.push({
|
|
96
|
+
ruleId: '',
|
|
97
|
+
ruleName: '',
|
|
98
|
+
severity: 'error',
|
|
99
|
+
file: filePath,
|
|
100
|
+
message: `Reference '${refId}' does not resolve to an existing file`,
|
|
101
|
+
line: i + 1,
|
|
102
|
+
});
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
break;
|
|
107
|
+
}
|
|
108
|
+
case 'unregistered-uncertainty': {
|
|
109
|
+
// An uncertainty written only into prose is invisible to the verification
|
|
110
|
+
// contract: it was never a declared check, so it never surfaces as
|
|
111
|
+
// `incomplete` and the "never report skipped verification as success" rule
|
|
112
|
+
// is never violated. Flag the bare form; accept it once a specific
|
|
113
|
+
// obstacle is named or an outcome is recorded (#2523).
|
|
114
|
+
const uncertainty = (check.uncertaintyPatterns ?? DEFAULT_UNCERTAINTY_PATTERNS)
|
|
115
|
+
.map((p) => new RegExp(p, 'i'));
|
|
116
|
+
const targets = (check.verificationTargets ?? DEFAULT_VERIFICATION_TARGETS)
|
|
117
|
+
.map((p) => new RegExp(p, 'i'));
|
|
118
|
+
const obstacle = (check.obstaclePatterns ?? DEFAULT_OBSTACLE_PATTERNS)
|
|
119
|
+
.map((p) => new RegExp(p, 'i'));
|
|
120
|
+
const within = check.obstacleWithinLines ?? 2;
|
|
121
|
+
const lines = content.split('\n');
|
|
122
|
+
for (let i = 0; i < lines.length; i++) {
|
|
123
|
+
// Both conditions must hold in the SAME CLAUSE: an unperformed action
|
|
124
|
+
// AND something the agent could have acted on. Without the target, the
|
|
125
|
+
// match is as likely to be the paper's own limitation, which must stay
|
|
126
|
+
// untouched. Without clause scoping, a long markdown line relates two
|
|
127
|
+
// unrelated clauses — real corpus prose puts whole paragraphs and
|
|
128
|
+
// changelog tables on one line, which produced most false positives.
|
|
129
|
+
const clause = splitClauses(lines[i]).find((c) => uncertainty.some((re) => re.test(c)) && targets.some((re) => re.test(c)));
|
|
130
|
+
if (!clause)
|
|
131
|
+
continue;
|
|
132
|
+
// A struck span followed by a dated outcome is a completed retraction,
|
|
133
|
+
// whatever its length. Clause scoping otherwise ends the window before
|
|
134
|
+
// the `**Done <date>**` that closes it, so the recommended convention
|
|
135
|
+
// failed for two-sentence struck text and passed for one (#2556).
|
|
136
|
+
const clauseAt = lines[i].indexOf(clause);
|
|
137
|
+
const struck = clauseAt >= 0 && strikethroughSpans(lines[i])
|
|
138
|
+
.some((span) => clauseAt >= span.start && clauseAt < span.end);
|
|
139
|
+
if (struck && retractedWithDatedOutcome(lines[i]))
|
|
140
|
+
continue;
|
|
141
|
+
// Look in the matching line and the following `within` lines: the
|
|
142
|
+
// obstacle normally sits in the same sentence or the next one.
|
|
143
|
+
const window = lines.slice(i, i + within + 1).join(' ');
|
|
144
|
+
if (obstacle.some((re) => re.test(window)))
|
|
145
|
+
continue;
|
|
146
|
+
diagnostics.push({
|
|
147
|
+
ruleId: '',
|
|
148
|
+
ruleName: '',
|
|
149
|
+
// Left unset so the rule's declared severity applies (see runRule).
|
|
150
|
+
// This is a prose heuristic, so the shipped rule declares `warn`; an
|
|
151
|
+
// operator can raise it to error once a corpus is clean.
|
|
152
|
+
severity: undefined,
|
|
153
|
+
file: filePath,
|
|
154
|
+
line: i + 1,
|
|
155
|
+
message: `Uncertainty stated without a named obstacle or recorded outcome: ${clause.trim().slice(0, 160)}`,
|
|
156
|
+
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.',
|
|
157
|
+
});
|
|
158
|
+
}
|
|
159
|
+
break;
|
|
160
|
+
}
|
|
161
|
+
case 'pattern-match': {
|
|
162
|
+
if (!check.pattern)
|
|
163
|
+
break;
|
|
164
|
+
const regex = new RegExp(check.pattern);
|
|
165
|
+
if (!regex.test(content)) {
|
|
166
|
+
diagnostics.push({
|
|
167
|
+
ruleId: '',
|
|
168
|
+
ruleName: '',
|
|
169
|
+
severity: 'warn',
|
|
170
|
+
file: filePath,
|
|
171
|
+
message: `File content does not match expected pattern: ${check.pattern}`,
|
|
172
|
+
});
|
|
173
|
+
}
|
|
174
|
+
break;
|
|
175
|
+
}
|
|
176
|
+
case 'file-exists': {
|
|
177
|
+
if (!check.field)
|
|
178
|
+
break;
|
|
179
|
+
const refPath = frontmatter[check.field];
|
|
180
|
+
if (isPresent(refPath)) {
|
|
181
|
+
// Project-root-relative is canonical (#3145); target-relative paths
|
|
182
|
+
// written for the legacy layout keep resolving.
|
|
183
|
+
const found = typeof refPath === 'string' &&
|
|
184
|
+
[projectRoot, targetDir].some(base => fs.existsSync(path.resolve(base, refPath)));
|
|
185
|
+
if (!found) {
|
|
186
|
+
diagnostics.push({
|
|
187
|
+
ruleId: '',
|
|
188
|
+
ruleName: '',
|
|
189
|
+
severity: 'error',
|
|
190
|
+
file: filePath,
|
|
191
|
+
message: `Referenced file '${refPath}' (from field '${check.field}') does not exist`,
|
|
192
|
+
});
|
|
193
|
+
}
|
|
194
|
+
}
|
|
195
|
+
break;
|
|
196
|
+
}
|
|
197
|
+
case 'id-unique': {
|
|
198
|
+
// Handled at ruleset level in runRule
|
|
199
|
+
break;
|
|
200
|
+
}
|
|
201
|
+
case 'id-format': {
|
|
202
|
+
if (!check.pattern)
|
|
203
|
+
break;
|
|
204
|
+
const basename = path.basename(filePath, '.md');
|
|
205
|
+
const match = basename.match(new RegExp(check.pattern));
|
|
206
|
+
if (!match) {
|
|
207
|
+
diagnostics.push({
|
|
208
|
+
ruleId: '',
|
|
209
|
+
ruleName: '',
|
|
210
|
+
severity: 'warn',
|
|
211
|
+
file: filePath,
|
|
212
|
+
message: `File name '${basename}' does not match expected format: ${check.pattern}`,
|
|
213
|
+
fix: `Rename to match the pattern ${check.pattern}`,
|
|
214
|
+
});
|
|
215
|
+
}
|
|
216
|
+
else if (check.field && isPresent(frontmatter[check.field])) {
|
|
217
|
+
const identifier = match[1] ?? match[0];
|
|
218
|
+
const value = frontmatter[check.field];
|
|
219
|
+
if (value !== identifier) {
|
|
220
|
+
diagnostics.push({
|
|
221
|
+
ruleId: '',
|
|
222
|
+
ruleName: '',
|
|
223
|
+
severity: 'warn',
|
|
224
|
+
file: filePath,
|
|
225
|
+
message: `File identifier '${identifier}' does not match frontmatter field '${check.field}': ${String(value)}`,
|
|
226
|
+
fix: `Make the filename identifier and '${check.field}' field agree`,
|
|
227
|
+
});
|
|
228
|
+
}
|
|
229
|
+
}
|
|
230
|
+
break;
|
|
231
|
+
}
|
|
232
|
+
case 'cross-ref-bidirectional': {
|
|
233
|
+
const refPattern = check.referencePattern || DEFAULT_REFERENCE_PATTERN;
|
|
234
|
+
const regex = new RegExp(refPattern, 'g');
|
|
235
|
+
const currentBasename = refIdFromFilename(path.basename(filePath)) ?? path.basename(filePath, '.md');
|
|
236
|
+
const matches = content.match(regex) || [];
|
|
237
|
+
for (const ref of matches) {
|
|
238
|
+
if (ref === currentBasename)
|
|
239
|
+
continue;
|
|
240
|
+
// Find the referenced file
|
|
241
|
+
const refFile = allFiles.find(f => isRefId(ref)
|
|
242
|
+
? refIdFromFilename(path.basename(f)) === ref : path.basename(f, '.md') === ref);
|
|
243
|
+
if (refFile) {
|
|
244
|
+
try {
|
|
245
|
+
const refContent = fs.readFileSync(path.resolve(targetDir, refFile), 'utf8');
|
|
246
|
+
const backlinks = refContent.match(regex) ?? [];
|
|
247
|
+
if (!backlinks.includes(currentBasename)) {
|
|
248
|
+
diagnostics.push({
|
|
249
|
+
ruleId: '',
|
|
250
|
+
ruleName: '',
|
|
251
|
+
severity: 'info',
|
|
252
|
+
file: filePath,
|
|
253
|
+
message: `References '${ref}' but '${ref}' does not reference back to '${currentBasename}'`,
|
|
254
|
+
fix: `Add a cross-reference to '${currentBasename}' in ${ref}.md`,
|
|
255
|
+
});
|
|
256
|
+
}
|
|
257
|
+
}
|
|
258
|
+
catch {
|
|
259
|
+
// Skip if can't read
|
|
260
|
+
}
|
|
261
|
+
}
|
|
262
|
+
}
|
|
263
|
+
break;
|
|
264
|
+
}
|
|
265
|
+
}
|
|
266
|
+
return diagnostics;
|
|
267
|
+
}
|
|
268
|
+
//# sourceMappingURL=checks.js.map
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
// Resolve lint references using exact corpus identities.
|
|
2
|
+
import path from 'node:path';
|
|
3
|
+
import { refFilesForId } from '../artifacts/corpus-tools/ref-files.js';
|
|
4
|
+
import { isRefId, refIdFromFilename } from '../research/identity.js';
|
|
5
|
+
/**
|
|
6
|
+
* Build a target-wide artifact ID index once per lint run.
|
|
7
|
+
*
|
|
8
|
+
* Reference documents may use either an exact filename (`REF-001.md`) or the
|
|
9
|
+
* canonical slugged form (`REF-001-some-title.md`). Indexing the exact ID token also
|
|
10
|
+
* makes resolution independent of a particular corpus directory layout.
|
|
11
|
+
*/
|
|
12
|
+
export function buildReferenceIndex(allFiles) {
|
|
13
|
+
const references = new Set();
|
|
14
|
+
for (const file of allFiles) {
|
|
15
|
+
if (path.extname(file).toLowerCase() !== '.md')
|
|
16
|
+
continue;
|
|
17
|
+
const basename = path.basename(file, '.md');
|
|
18
|
+
if (['-citations.md', '-radar.md'].some(ext => isRefId(path.basename(file).slice(0, -ext.length)) && file.endsWith(ext)))
|
|
19
|
+
continue;
|
|
20
|
+
references.add(basename);
|
|
21
|
+
const ref = refIdFromFilename(path.basename(file));
|
|
22
|
+
if (ref)
|
|
23
|
+
references.add(ref);
|
|
24
|
+
if (/^REF-/.test(basename))
|
|
25
|
+
continue;
|
|
26
|
+
const artifactId = basename.match(/^(.+?-\d+)(?:-|$)/);
|
|
27
|
+
if (artifactId)
|
|
28
|
+
references.add(artifactId[1]);
|
|
29
|
+
}
|
|
30
|
+
return references;
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* Preserve support for references stored outside the lint target when a rule
|
|
34
|
+
* explicitly supplies basePath. Accept both exact and slugged filenames.
|
|
35
|
+
*/
|
|
36
|
+
export function resolvesFromBasePath(refId, targetDir, basePath, projectRoot) {
|
|
37
|
+
const candidateDirs = new Set([
|
|
38
|
+
path.resolve(projectRoot, basePath),
|
|
39
|
+
path.resolve(targetDir, basePath),
|
|
40
|
+
path.resolve(process.cwd(), basePath),
|
|
41
|
+
]);
|
|
42
|
+
for (const dir of candidateDirs) {
|
|
43
|
+
try {
|
|
44
|
+
if (refFilesForId(dir, refId).length > 0) {
|
|
45
|
+
return true;
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
catch {
|
|
49
|
+
// Missing or unreadable candidate directories do not resolve the ID.
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
return false;
|
|
53
|
+
}
|
|
54
|
+
//# sourceMappingURL=reference-resolution.js.map
|