@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.
- package/agentic/code/addons/aiwg-utils/rules/anti-laziness.core.md +13 -0
- package/agentic/code/addons/aiwg-utils/rules/anti-laziness.md +118 -0
- 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 +37 -0
- package/dist/src/artifacts/corpus-tools/discovery-log.js +27 -25
- package/dist/src/artifacts/corpus-tools/expand-cli.js +90 -0
- package/dist/src/artifacts/corpus-tools/expand-dates.js +107 -0
- package/dist/src/artifacts/corpus-tools/expand-queue.js +41 -0
- package/dist/src/artifacts/corpus-tools/expand-review.js +104 -0
- package/dist/src/artifacts/corpus-tools/expand-state.js +56 -0
- package/dist/src/artifacts/corpus-tools/expand.js +124 -0
- 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 +99 -0
- package/dist/src/artifacts/corpus-tools/resolve-corpus.js +41 -0
- package/dist/src/artifacts/corpus-tools/resolve.js +119 -0
- 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 +45 -0
- package/dist/src/cli/handlers/doctor-help.js +8 -3
- 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 -586
- 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-context.js +33 -4
- 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 +9 -2
- 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/features/catalog.js +1 -1
- package/dist/src/gates/evaluate.js +2 -2
- package/dist/src/gates/heldout.js +52 -0
- package/dist/src/gates/index.js +2 -1
- 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-installation-store.mjs +228 -0
- package/dist/src/models/worker-installation.mjs +7 -162
- 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 +14 -34
- package/dist/src/research/clients/base.js +53 -26
- package/dist/src/research/clients/crossref.js +9 -1
- package/dist/src/research/clients/semantic-scholar.js +73 -44
- package/dist/src/research/identity.js +117 -0
- package/dist/src/research/index.js +1 -0
- 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 +135 -0
- 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/rules/core-startup.d.mts +2 -0
- package/dist/src/rules/core-startup.mjs +31 -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/agents-md.js +34 -0
- package/dist/src/smiths/context-pipeline/aiwg-md.js +19 -46
- package/dist/src/smiths/context-pipeline/bridge-ownership.js +50 -0
- 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 +49 -114
- package/dist/src/smiths/context-pipeline/managed-hook.js +11 -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 +13 -2
- package/schemas/decision/D29Study.v10.schema.json +65 -0
- package/tools/agents/deploy-agents.mjs +12 -123
- package/tools/agents/providers/antigravity.mjs +1 -1
- package/tools/agents/providers/claude-post-deploy.mjs +12 -1
- package/tools/agents/providers/context-write.mjs +16 -0
- package/tools/agents/providers/grok-build.mjs +8 -5
- package/tools/agents/providers/hermes-skill-lifecycle.mjs +144 -0
- package/tools/agents/providers/hermes-startup.mjs +209 -0
- package/tools/agents/providers/hermes.mjs +9 -359
- package/tools/agents/providers/model-wrapper.mjs +5 -1
- package/tools/agents/providers/muse.mjs +3 -3
- package/tools/agents/providers/pi.mjs +4 -2
- package/tools/agents/providers/rule-delivery-surface.mjs +332 -0
- package/tools/agents/providers/rule-delivery.mjs +20 -1346
- 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/agents/providers/rule-presentation.mjs +13 -4
- package/tools/agents/providers/rule-projection.mjs +119 -0
- package/tools/agents/providers/rule-startup.mjs +70 -0
- package/tools/agents/providers/stale-artifact-prune.mjs +128 -0
- package/tools/agents/providers/warp.mjs +2 -2
- package/tools/agents/providers/windsurf.mjs +11 -57
- 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/plugin/plugin-links.mjs +3 -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,107 @@
|
|
|
1
|
+
// Resolve seed dates from frontmatter, batched Git addition history, then filesystem mtime.
|
|
2
|
+
import { statSync } from 'node:fs';
|
|
3
|
+
import { relative, resolve, sep } from 'node:path';
|
|
4
|
+
import { boundedExecFileSync } from '../../process/bounded-child-process.mjs';
|
|
5
|
+
function frontmatterDate(record) {
|
|
6
|
+
for (const fields of record.fields) {
|
|
7
|
+
const discovery = fields.discovery;
|
|
8
|
+
for (const value of [fields.inducted, fields.inducted_on, fields.added, fields.created, fields.date, discovery?.date]) {
|
|
9
|
+
const date = value instanceof Date ? value.getTime() : typeof value === 'string' ? Date.parse(value) : NaN;
|
|
10
|
+
if (Number.isFinite(date))
|
|
11
|
+
return date;
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
return undefined;
|
|
15
|
+
}
|
|
16
|
+
function gitAdditionDates(root, records) {
|
|
17
|
+
const dates = new Map();
|
|
18
|
+
let shallow = false;
|
|
19
|
+
const git = (cwd, args) => String(boundedExecFileSync('git', args, 'quick', {
|
|
20
|
+
cwd, encoding: 'utf8', timeout: 30_000, maxBuffer: 64 * 1024 * 1024, stdio: ['ignore', 'pipe', 'pipe'],
|
|
21
|
+
}));
|
|
22
|
+
try {
|
|
23
|
+
const repository = git(root, ['rev-parse', '--show-toplevel']).trim();
|
|
24
|
+
shallow = git(repository, ['rev-parse', '--is-shallow-repository']).trim() === 'true';
|
|
25
|
+
const tracked = new Set(git(repository, ['ls-files', '-z']).split('\0'));
|
|
26
|
+
const pending = new Map();
|
|
27
|
+
for (const record of records) {
|
|
28
|
+
const path = relative(repository, resolve(record.path)).split(sep).join('/');
|
|
29
|
+
if (tracked.has(path))
|
|
30
|
+
pending.set(path, [record.path]);
|
|
31
|
+
}
|
|
32
|
+
if (!pending.size)
|
|
33
|
+
return { dates, shallow };
|
|
34
|
+
// Walk backwards through renames without a pathspec: predecessors may live outside the corpus.
|
|
35
|
+
// NUL-delimited paths also handle spaces, tabs, newlines and Git's quoted-path syntax.
|
|
36
|
+
// Combined diffs expose merge-created files (AA), but omit additions inherited from a
|
|
37
|
+
// parent: those resolve at their original branch commit, not at the merge date.
|
|
38
|
+
const tokens = git(repository, ['log', '--topo-order', '--full-history', '--diff-merges=combined',
|
|
39
|
+
'--format=%x00aiwg-date:%aI %P%x00',
|
|
40
|
+
'--name-status', '-z', '--find-renames', '--diff-filter=AR', '--']).split('\0');
|
|
41
|
+
let date = NaN;
|
|
42
|
+
for (let i = 0; i < tokens.length && pending.size; i++) {
|
|
43
|
+
const token = tokens[i].replace(/^\n+/, '');
|
|
44
|
+
if (token.startsWith('aiwg-date:')) {
|
|
45
|
+
const [authored, parents] = token.slice(10).split(' ');
|
|
46
|
+
// A shallow boundary masquerades as a root addition; its true date is unknown.
|
|
47
|
+
date = shallow && !parents ? NaN : Date.parse(authored);
|
|
48
|
+
continue;
|
|
49
|
+
}
|
|
50
|
+
if (/^A+$/.test(token)) {
|
|
51
|
+
const path = tokens[++i];
|
|
52
|
+
if (Number.isFinite(date))
|
|
53
|
+
for (const original of pending.get(path) ?? [])
|
|
54
|
+
dates.set(original, date);
|
|
55
|
+
pending.delete(path);
|
|
56
|
+
}
|
|
57
|
+
else if (/^R\d+$/.test(token)) {
|
|
58
|
+
const oldPath = tokens[++i];
|
|
59
|
+
const newPath = tokens[++i];
|
|
60
|
+
const originals = pending.get(newPath);
|
|
61
|
+
if (originals) {
|
|
62
|
+
pending.delete(newPath);
|
|
63
|
+
pending.set(oldPath, [...(pending.get(oldPath) ?? []), ...originals]);
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
catch {
|
|
69
|
+
// Missing Git, no repository, unavailable history or a bounded query failure use the same fallback.
|
|
70
|
+
return { dates: new Map(), shallow };
|
|
71
|
+
}
|
|
72
|
+
return { dates, shallow };
|
|
73
|
+
}
|
|
74
|
+
export function expansionDates(root, records) {
|
|
75
|
+
const dates = new Map();
|
|
76
|
+
const missing = [];
|
|
77
|
+
for (const record of records) {
|
|
78
|
+
const date = frontmatterDate(record);
|
|
79
|
+
if (date === undefined)
|
|
80
|
+
missing.push(record);
|
|
81
|
+
else
|
|
82
|
+
dates.set(record.path, date);
|
|
83
|
+
}
|
|
84
|
+
const { dates: additions, shallow } = missing.length ? gitAdditionDates(root, missing) : { dates: new Map(), shallow: false };
|
|
85
|
+
let mtimeCount = 0;
|
|
86
|
+
for (const record of records) {
|
|
87
|
+
try {
|
|
88
|
+
const mtime = statSync(record.path).mtimeMs;
|
|
89
|
+
if (dates.has(record.path))
|
|
90
|
+
continue;
|
|
91
|
+
const date = additions.get(record.path);
|
|
92
|
+
if (date === undefined)
|
|
93
|
+
mtimeCount++;
|
|
94
|
+
dates.set(record.path, date ?? mtime);
|
|
95
|
+
}
|
|
96
|
+
catch (error) {
|
|
97
|
+
if (!['ENOENT', 'ENOTDIR'].includes(error.code ?? ''))
|
|
98
|
+
throw error;
|
|
99
|
+
dates.delete(record.path);
|
|
100
|
+
console.warn(`[aiwg] corpus expand --since: ${record.ref} document disappeared; skipping seed (${record.path}).`);
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
if (mtimeCount)
|
|
104
|
+
console.warn(`[aiwg] corpus expand --since: ${mtimeCount} REFs used document mtime because no Git first-add date was available.${shallow ? ' Shallow Git history may omit first additions; use a full clone for stable --since scoping.' : ''}`);
|
|
105
|
+
return dates;
|
|
106
|
+
}
|
|
107
|
+
//# sourceMappingURL=expand-dates.js.map
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
// Merge recommendation identities and retain auditable convergence, recency and provenance.
|
|
2
|
+
import { identityKeys, normalizeIdentity } from '../../research/identity.js';
|
|
3
|
+
export function rankCandidates(rows) {
|
|
4
|
+
return rows.sort((a, b) => b.score_parts.convergence - a.score_parts.convergence
|
|
5
|
+
|| b.score_parts.recency - a.score_parts.recency
|
|
6
|
+
|| (b.score_parts.overlap ?? -1) - (a.score_parts.overlap ?? -1)
|
|
7
|
+
|| a.paper.id.localeCompare(b.paper.id));
|
|
8
|
+
}
|
|
9
|
+
export class ExpansionQueue {
|
|
10
|
+
rows = new Set();
|
|
11
|
+
byKey = new Map();
|
|
12
|
+
add(paper, refs, previous) {
|
|
13
|
+
const normalized = normalizeIdentity(paper);
|
|
14
|
+
paper = { ...paper, ...Object.fromEntries(Object.entries(normalized).filter(([key, value]) => key !== 'title' && value !== undefined)) };
|
|
15
|
+
const keys = new Set([...identityKeys(paper), ...(previous?.identity_keys ?? [])]);
|
|
16
|
+
const matches = new Set([...keys].flatMap(key => this.byKey.get(key) ? [this.byKey.get(key)] : []));
|
|
17
|
+
const seeds = new Set(refs);
|
|
18
|
+
let review = previous?.review;
|
|
19
|
+
let overlap = previous?.score_parts.overlap ?? null;
|
|
20
|
+
for (const match of matches) {
|
|
21
|
+
this.rows.delete(match);
|
|
22
|
+
for (const key of match.identity_keys)
|
|
23
|
+
keys.add(key);
|
|
24
|
+
for (const ref of match.seed_refs)
|
|
25
|
+
seeds.add(ref);
|
|
26
|
+
paper = { ...match.paper, ...Object.fromEntries(Object.entries(paper).filter(([, value]) => value !== undefined)) };
|
|
27
|
+
if (match.review && (!review || match.review.reviewed_on > review.reviewed_on))
|
|
28
|
+
review = match.review;
|
|
29
|
+
overlap ??= match.score_parts.overlap;
|
|
30
|
+
}
|
|
31
|
+
const seedRefs = [...seeds].sort();
|
|
32
|
+
const row = { ...(review ? { review } : {}), paper, identity_keys: [...keys].sort(), seed_refs: seedRefs,
|
|
33
|
+
score_parts: { convergence: seedRefs.length, recency: paper.year || 0, overlap },
|
|
34
|
+
discovery: { surface: 's2-recommendation', via: `S2 recommendations for ${seedRefs.join(', ')}` } };
|
|
35
|
+
this.rows.add(row);
|
|
36
|
+
for (const key of keys)
|
|
37
|
+
this.byKey.set(key, row);
|
|
38
|
+
}
|
|
39
|
+
ranked() { return rankCandidates([...this.rows]); }
|
|
40
|
+
}
|
|
41
|
+
//# sourceMappingURL=expand-queue.js.map
|
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
// Review persisted expansion identities without requesting papers or triggering induction.
|
|
2
|
+
import { AiwgError } from '../../cli/errors.js';
|
|
3
|
+
import { identityKeys, parseResearchIdentifier } from '../../research/identity.js';
|
|
4
|
+
import { compactState, expansionPaths, readJsonl, writeJsonl, writeQueue } from './expand-state.js';
|
|
5
|
+
import { renderExpansion } from './expand.js';
|
|
6
|
+
export const REVIEW_USAGE = `aiwg corpus review [list] [--json]
|
|
7
|
+
aiwg corpus review accept <id> [--brief] [--write] [--json]
|
|
8
|
+
aiwg corpus review reject <id> [--reason TEXT] [--write] [--json]
|
|
9
|
+
aiwg corpus review defer <id> [--write] [--json]
|
|
10
|
+
IDs: paper.id, full identity keys, bare S2 IDs, or complete DOI/arXiv/OpenReview/ACL/S2 aliases and URLs.
|
|
11
|
+
Default: dry run. Accept/defer retain the candidate with review metadata; reject records its identities in rejected-candidates.jsonl and removes it from the queue.
|
|
12
|
+
--brief emits an induct-research brief to stdout (JSON: brief); it never inducts or files issues.
|
|
13
|
+
Exit codes: 0 complete, 1 usage or storage error.
|
|
14
|
+
`;
|
|
15
|
+
function usage(message) {
|
|
16
|
+
throw new AiwgError({ code: 'ERR_CORPUS_REVIEW_USAGE', message, exitCode: 1, hint: REVIEW_USAGE.trim() });
|
|
17
|
+
}
|
|
18
|
+
function matches(row, id) {
|
|
19
|
+
const recognized = parseResearchIdentifier(id);
|
|
20
|
+
const parsed = recognized?.matched === id ? recognized : undefined;
|
|
21
|
+
const field = parsed && { arxiv: 'arxivId', doi: 'doi', s2: 's2PaperId', openreview: 'openReviewId', acl: 'aclId' }[parsed.kind];
|
|
22
|
+
const keys = new Set([id, ...identityKeys({ s2PaperId: id, ...(field ? { [field]: parsed.id } : {}) })]);
|
|
23
|
+
return row.paper.id === id || [...row.identity_keys, ...identityKeys(row.paper)]
|
|
24
|
+
.some(key => keys.has(key));
|
|
25
|
+
}
|
|
26
|
+
function brief(row) {
|
|
27
|
+
return ['# Induction brief for induct-research', '', `Title: ${row.paper.title}`,
|
|
28
|
+
`Paper ID: ${row.paper.id}`, `IDs: ${row.identity_keys.filter(key => !key.startsWith('title:')).join(', ')}`,
|
|
29
|
+
`Seed REFs: ${row.seed_refs.join(', ')}`,
|
|
30
|
+
`Score components: convergence=${row.score_parts.convergence}, recency=${row.score_parts.recency}, overlap=${row.score_parts.overlap ?? 'not checked'}`,
|
|
31
|
+
`Discovery: ${row.discovery.surface}; via: ${row.discovery.via}`, '',
|
|
32
|
+
'Use induct-research only when explicitly requested. Preserve the seed REFs and discovery provenance in the citation sidecar.', ''].join('\n');
|
|
33
|
+
}
|
|
34
|
+
export async function reviewCli(args, cwd) {
|
|
35
|
+
const positional = [];
|
|
36
|
+
const seen = new Set();
|
|
37
|
+
let reason;
|
|
38
|
+
for (let i = 0; i < args.length; i++) {
|
|
39
|
+
const token = args[i];
|
|
40
|
+
if (!token.startsWith('-')) {
|
|
41
|
+
positional.push(token);
|
|
42
|
+
continue;
|
|
43
|
+
}
|
|
44
|
+
if (!['--json', '--write', '--brief', '--reason'].includes(token))
|
|
45
|
+
usage(`Unknown review option: ${token}`);
|
|
46
|
+
if (seen.has(token))
|
|
47
|
+
usage(`${token} may only be supplied once`);
|
|
48
|
+
seen.add(token);
|
|
49
|
+
if (token === '--reason') {
|
|
50
|
+
reason = args[++i];
|
|
51
|
+
if (!reason?.trim() || reason.startsWith('-'))
|
|
52
|
+
usage('--reason requires text');
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
const action = (positional[0] ?? 'list');
|
|
56
|
+
if (!['list', 'accept', 'reject', 'defer'].includes(action))
|
|
57
|
+
usage(`Unknown review action: ${action}`);
|
|
58
|
+
if (positional.length !== (action === 'list' ? (positional.length ? 1 : 0) : 2))
|
|
59
|
+
usage(`${action} ${action === 'list' ? 'takes no ID' : 'requires one ID'}`);
|
|
60
|
+
if (seen.has('--reason') && action !== 'reject')
|
|
61
|
+
usage('--reason is only valid with reject');
|
|
62
|
+
if (seen.has('--brief') && action !== 'accept')
|
|
63
|
+
usage('--brief is only valid with accept');
|
|
64
|
+
if (seen.has('--write') && action === 'list')
|
|
65
|
+
usage('--write requires accept, reject or defer');
|
|
66
|
+
const paths = expansionPaths(cwd);
|
|
67
|
+
const candidates = readJsonl(paths.queue);
|
|
68
|
+
// Validate all storage before mutating any file, including the ledger compacted on writes.
|
|
69
|
+
const rejected = readJsonl(paths.rejected);
|
|
70
|
+
readJsonl(paths.ledger);
|
|
71
|
+
let change;
|
|
72
|
+
if (action !== 'list') {
|
|
73
|
+
const found = candidates.filter(row => matches(row, positional[1]));
|
|
74
|
+
if (found.length !== 1)
|
|
75
|
+
usage(found.length ? `Ambiguous candidate ID: ${positional[1]}` : `Unknown candidate ID: ${positional[1]}`);
|
|
76
|
+
const before = found[0];
|
|
77
|
+
const after = { ...before, review: {
|
|
78
|
+
status: action === 'accept' ? 'accepted' : action === 'reject' ? 'rejected' : 'deferred',
|
|
79
|
+
reviewed_on: new Date().toISOString(), ...(reason !== undefined ? { reason } : {}),
|
|
80
|
+
} };
|
|
81
|
+
change = { before, after };
|
|
82
|
+
const index = candidates.indexOf(before);
|
|
83
|
+
if (action === 'reject')
|
|
84
|
+
candidates.splice(index, 1);
|
|
85
|
+
else
|
|
86
|
+
candidates[index] = after;
|
|
87
|
+
}
|
|
88
|
+
const result = { dry_run: !seen.has('--write'), action, candidates, ...(change ? { change } : {}),
|
|
89
|
+
...(seen.has('--brief') ? { brief: brief(change.after) } : {}) };
|
|
90
|
+
const report = renderExpansion({ ...result, incomplete: false, scoped: 0, due: 0, remaining: 0,
|
|
91
|
+
processed: [], overlap_errors: [], paths });
|
|
92
|
+
if (seen.has('--write')) {
|
|
93
|
+
// Persist suppression first: a failed queue write cannot resurrect a rejected identity.
|
|
94
|
+
if (action === 'reject')
|
|
95
|
+
writeJsonl(paths.rejected, [...rejected, change.after]);
|
|
96
|
+
writeQueue(paths, candidates, report);
|
|
97
|
+
// Queue/report may already be replaced on compaction failure; expand reconciles
|
|
98
|
+
// from persisted suppression and retries compaction without resurrecting rejections.
|
|
99
|
+
compactState(paths);
|
|
100
|
+
}
|
|
101
|
+
const summary = change ? `${result.dry_run ? 'Dry run' : 'Written'}: ${action} ${change.after.paper.id}${reason ? ` (${reason})` : ''}\n` : '';
|
|
102
|
+
process.stdout.write(seen.has('--json') ? JSON.stringify(result, null, 2) + '\n' : summary + report + (result.brief ?? ''));
|
|
103
|
+
}
|
|
104
|
+
//# sourceMappingURL=expand-review.js.map
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
// Read frontier/queue JSONL and checkpoint queue-before-ledger under the artifact path owner.
|
|
2
|
+
import { appendFileSync, existsSync, mkdirSync, readFileSync, renameSync, rmSync, writeFileSync } from 'node:fs';
|
|
3
|
+
import { join } from 'node:path';
|
|
4
|
+
import { randomUUID } from 'node:crypto';
|
|
5
|
+
import { resolveProjectAiwgDirForWrite } from '../../config/project-artifacts.js';
|
|
6
|
+
export function expansionPaths(cwd) {
|
|
7
|
+
// Validation is read-only, including in dry runs; external roots must be available.
|
|
8
|
+
const artifactRoot = resolveProjectAiwgDirForWrite(cwd);
|
|
9
|
+
const directory = join(artifactRoot, 'research', 'discovery');
|
|
10
|
+
return { directory, ledger: join(directory, 'expansion-state.jsonl'), queue: join(directory, 'candidates.jsonl'),
|
|
11
|
+
rejected: join(directory, 'rejected-candidates.jsonl'), report: join(directory, 'expansion-report.md') };
|
|
12
|
+
}
|
|
13
|
+
export function readJsonl(file) {
|
|
14
|
+
if (!existsSync(file))
|
|
15
|
+
return [];
|
|
16
|
+
return readFileSync(file, 'utf8').split(/\r?\n/).flatMap((line, index) => {
|
|
17
|
+
if (!line.trim())
|
|
18
|
+
return [];
|
|
19
|
+
try {
|
|
20
|
+
return [JSON.parse(line)];
|
|
21
|
+
}
|
|
22
|
+
catch {
|
|
23
|
+
throw new Error(`Invalid JSONL at ${file}:${index + 1}; repair it before expanding`);
|
|
24
|
+
}
|
|
25
|
+
});
|
|
26
|
+
}
|
|
27
|
+
export function writeJsonl(file, rows) {
|
|
28
|
+
const temporary = `${file}.${randomUUID()}.tmp`;
|
|
29
|
+
try {
|
|
30
|
+
writeFileSync(temporary, rows.map(row => JSON.stringify(row)).join('\n') + (rows.length ? '\n' : ''), 'utf8');
|
|
31
|
+
renameSync(temporary, file);
|
|
32
|
+
}
|
|
33
|
+
finally {
|
|
34
|
+
rmSync(temporary, { force: true });
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
export function compactState(paths) {
|
|
38
|
+
const rows = readJsonl(paths.ledger);
|
|
39
|
+
if (rows.length)
|
|
40
|
+
writeJsonl(paths.ledger, [...new Map(rows.map(row => [row.ref, row])).values()]);
|
|
41
|
+
}
|
|
42
|
+
export function writeQueue(paths, rows, report) {
|
|
43
|
+
mkdirSync(paths.directory, { recursive: true });
|
|
44
|
+
for (const [file, content] of [[paths.queue, rows.map(row => JSON.stringify(row)).join('\n') + (rows.length ? '\n' : '')], [paths.report, report]]) {
|
|
45
|
+
const temporary = `${file}.${randomUUID()}.tmp`;
|
|
46
|
+
writeFileSync(temporary, content, 'utf8');
|
|
47
|
+
renameSync(temporary, file);
|
|
48
|
+
}
|
|
49
|
+
if (!existsSync(paths.rejected))
|
|
50
|
+
writeFileSync(paths.rejected, '', { flag: 'wx' });
|
|
51
|
+
}
|
|
52
|
+
export function appendState(paths, row) {
|
|
53
|
+
appendFileSync(paths.ledger, JSON.stringify(row) + '\n', 'utf8');
|
|
54
|
+
compactState(paths);
|
|
55
|
+
}
|
|
56
|
+
//# sourceMappingURL=expand-state.js.map
|
|
@@ -0,0 +1,124 @@
|
|
|
1
|
+
// Traverse the due corpus frontier, suppress known papers, and checkpoint ranked recommendations.
|
|
2
|
+
import { AiwgError } from '../../cli/errors.js';
|
|
3
|
+
import { SemanticScholarClient } from '../../research/clients/semantic-scholar.js';
|
|
4
|
+
import { identityKeys } from '../../research/identity.js';
|
|
5
|
+
import { ResearchError, ResearchErrorCode } from '../../research/types.js';
|
|
6
|
+
import { findInCorpus, loadCorpusIdentities } from './resolve-corpus.js';
|
|
7
|
+
import { ExpansionQueue, rankCandidates } from './expand-queue.js';
|
|
8
|
+
import { appendState, compactState, expansionPaths, readJsonl, writeQueue } from './expand-state.js';
|
|
9
|
+
import { expansionDates } from './expand-dates.js';
|
|
10
|
+
function seedId(record) {
|
|
11
|
+
const preferred = record.fields.map(fields => {
|
|
12
|
+
const keys = identityKeys(fields);
|
|
13
|
+
return keys.find(key => key.startsWith('arxivId:')) ?? keys.find(key => key.startsWith('doi:'));
|
|
14
|
+
});
|
|
15
|
+
if (preferred[0] && preferred[1] && preferred[0] !== preferred[1]) {
|
|
16
|
+
process.stderr.write(`Warning: ${record.ref} primary and sidecar seed IDs differ (${preferred[0]} vs ${preferred[1]}); using primary.\n`);
|
|
17
|
+
}
|
|
18
|
+
// Prefer the primary document and citation frontmatter IDs over body URL fallbacks.
|
|
19
|
+
for (const fields of record.fields) {
|
|
20
|
+
const keys = identityKeys(fields);
|
|
21
|
+
const arxiv = keys.find(key => key.startsWith('arxivId:'));
|
|
22
|
+
const doi = keys.find(key => key.startsWith('doi:'));
|
|
23
|
+
if (arxiv)
|
|
24
|
+
return `arXiv:${arxiv.slice(8)}`;
|
|
25
|
+
if (doi)
|
|
26
|
+
return `DOI:${doi.slice(4)}`;
|
|
27
|
+
}
|
|
28
|
+
const arxiv = [...record.keys].find(key => key.startsWith('arxivId:'));
|
|
29
|
+
return arxiv ? `arXiv:${arxiv.slice(8)}` : null;
|
|
30
|
+
}
|
|
31
|
+
export async function expandCorpus(root, cwd, options) {
|
|
32
|
+
const corpus = loadCorpusIdentities(root);
|
|
33
|
+
if (options.seeds?.some(ref => !corpus.some(record => record.ref === ref))) {
|
|
34
|
+
throw new AiwgError({ code: 'ERR_CORPUS_EXPAND_USAGE', message: 'Every --seeds REF must exist in the corpus', exitCode: 1 });
|
|
35
|
+
}
|
|
36
|
+
const paths = expansionPaths(cwd);
|
|
37
|
+
const previous = new Map(readJsonl(paths.ledger).map(row => [row.ref, row]));
|
|
38
|
+
const rejected = new Set(readJsonl(paths.rejected)
|
|
39
|
+
.flatMap(row => [...identityKeys((row.paper ?? row)),
|
|
40
|
+
...(Array.isArray(row.identity_keys) ? row.identity_keys.filter((key) => typeof key === 'string') : [])]));
|
|
41
|
+
const corpusKeys = new Set(corpus.flatMap(record => [...record.keys]));
|
|
42
|
+
const excluded = (paper, aliases = []) => [...identityKeys(paper), ...aliases]
|
|
43
|
+
.some(key => corpusKeys.has(key) || rejected.has(key));
|
|
44
|
+
const queue = new ExpansionQueue();
|
|
45
|
+
for (const row of readJsonl(paths.queue)) {
|
|
46
|
+
if (!excluded(row.paper, row.identity_keys))
|
|
47
|
+
queue.add(row.paper, row.seed_refs, row);
|
|
48
|
+
}
|
|
49
|
+
const selected = corpus.filter(record => !options.seeds || options.seeds.includes(record.ref));
|
|
50
|
+
const dates = options.since === undefined ? undefined : expansionDates(root, selected);
|
|
51
|
+
const scoped = selected.filter(record => options.since === undefined || dates.get(record.path) >= options.since);
|
|
52
|
+
const now = Date.now();
|
|
53
|
+
const due = scoped.map(record => ({ record, id: seedId(record) })).filter(({ record, id }) => {
|
|
54
|
+
const last = previous.get(record.ref);
|
|
55
|
+
if (!last || last.seed_id !== id)
|
|
56
|
+
return true;
|
|
57
|
+
if (last.status === 'no-id' && !id)
|
|
58
|
+
return false;
|
|
59
|
+
return last.status !== 'explored' || !Number.isFinite(Date.parse(last.explored_on))
|
|
60
|
+
|| now - Date.parse(last.explored_on) >= options.reexploreMs;
|
|
61
|
+
});
|
|
62
|
+
const client = new SemanticScholarClient();
|
|
63
|
+
const result = { dry_run: !options.write, incomplete: false, scoped: scoped.length, due: due.length,
|
|
64
|
+
remaining: Math.max(0, due.length - options.maxSeeds), processed: [], candidates: queue.ranked(), overlap_errors: [], paths };
|
|
65
|
+
for (const { record, id } of due.slice(0, options.maxSeeds)) {
|
|
66
|
+
const row = { ref: record.ref, seed_id: id, explored_on: new Date().toISOString(),
|
|
67
|
+
status: id ? 'explored' : 'no-id', n_returned: 0 };
|
|
68
|
+
if (id) {
|
|
69
|
+
try {
|
|
70
|
+
const papers = await client.recommendations(id, options.perSeed, options.from);
|
|
71
|
+
row.n_returned = papers.length;
|
|
72
|
+
for (const paper of papers) {
|
|
73
|
+
if (paper.year >= options.minYear && !excluded(paper))
|
|
74
|
+
queue.add(paper, [record.ref]);
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
catch (error) {
|
|
78
|
+
row.status = error instanceof ResearchError && error.code === ResearchErrorCode.RF_103 ? 'throttled' : 'not-found';
|
|
79
|
+
row.error = error instanceof Error ? error.message : String(error);
|
|
80
|
+
result.incomplete = true;
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
result.processed.push(row);
|
|
84
|
+
result.candidates = queue.ranked();
|
|
85
|
+
if (options.write) {
|
|
86
|
+
writeQueue(paths, result.candidates, renderExpansion(result));
|
|
87
|
+
appendState(paths, row);
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
if (options.overlap) {
|
|
91
|
+
for (const candidate of result.candidates.slice(0, 20)) {
|
|
92
|
+
if (candidate.score_parts.overlap !== null)
|
|
93
|
+
continue;
|
|
94
|
+
try {
|
|
95
|
+
const refs = new Set((await client.recommendationReferences(candidate.paper.s2PaperId ?? candidate.paper.id))
|
|
96
|
+
.flatMap(paper => findInCorpus(root, paper, corpus).map(match => match.ref)));
|
|
97
|
+
candidate.score_parts.overlap = refs.size;
|
|
98
|
+
}
|
|
99
|
+
catch (error) {
|
|
100
|
+
result.overlap_errors.push({ paper_id: candidate.paper.id, error: error instanceof Error ? error.message : String(error) });
|
|
101
|
+
result.incomplete = true;
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
rankCandidates(result.candidates);
|
|
105
|
+
}
|
|
106
|
+
if (options.write) {
|
|
107
|
+
writeQueue(paths, result.candidates, renderExpansion(result));
|
|
108
|
+
compactState(paths);
|
|
109
|
+
}
|
|
110
|
+
return result;
|
|
111
|
+
}
|
|
112
|
+
export function renderExpansion(result) {
|
|
113
|
+
const lines = ['# Corpus expansion', '', `${result.dry_run ? 'Dry run' : 'Written'}: ${result.processed.length}/${result.due} due seeds; ${result.remaining} remaining; ${result.candidates.length} candidates.`, ''];
|
|
114
|
+
for (const row of result.processed)
|
|
115
|
+
lines.push(`- ${row.ref}: ${row.status} (${row.seed_id ?? 'no ID'}), ${row.n_returned} returned${row.error ? ` — ${row.error}` : ''}`);
|
|
116
|
+
lines.push('', 'Ranking: distinct seed convergence, then publication year, then optional in-corpus reference overlap.', '');
|
|
117
|
+
for (const [index, row] of result.candidates.entries()) {
|
|
118
|
+
lines.push(`## ${index + 1}. ${row.paper.title}`, '', `Review: ${row.review?.status ?? 'pending'}`, `Year: ${row.paper.year}; IDs: ${row.identity_keys.filter(key => !key.startsWith('title:')).join(', ')}`, `Score components: convergence=${row.score_parts.convergence}, recency=${row.score_parts.recency}, overlap=${row.score_parts.overlap ?? 'not checked'}`, `Seed REFs: ${row.seed_refs.join(', ')}`, `Discovery: ${row.discovery.surface}; via: ${row.discovery.via}`, '');
|
|
119
|
+
}
|
|
120
|
+
for (const error of result.overlap_errors)
|
|
121
|
+
lines.push(`Overlap failed for ${error.paper_id}: ${error.error}`);
|
|
122
|
+
return lines.join('\n') + '\n';
|
|
123
|
+
}
|
|
124
|
+
//# sourceMappingURL=expand.js.map
|
|
@@ -15,6 +15,8 @@
|
|
|
15
15
|
* @tests @test/unit/artifacts/induction-audit.test.ts
|
|
16
16
|
*/
|
|
17
17
|
import * as fs from 'fs';
|
|
18
|
+
import { refIdFromFilename } from '../../research/identity.js';
|
|
19
|
+
import { refFilesForId } from './ref-files.js';
|
|
18
20
|
import * as path from 'path';
|
|
19
21
|
import { createHash } from 'crypto';
|
|
20
22
|
import { parseFrontmatter } from '../corpus-views/ref-parser.js';
|
|
@@ -43,24 +45,23 @@ function refFiles(root) {
|
|
|
43
45
|
const dir = path.join(root, ...REFS_DIR);
|
|
44
46
|
if (!fs.existsSync(dir))
|
|
45
47
|
return [];
|
|
46
|
-
return fs.readdirSync(dir).filter(
|
|
48
|
+
return fs.readdirSync(dir, { withFileTypes: true }).filter(f => f.isFile() && refIdFromFilename(f.name)).map(f => f.name).sort();
|
|
47
49
|
}
|
|
48
50
|
function refIdOf(filename) {
|
|
49
|
-
|
|
50
|
-
return m ? m[1] : null;
|
|
51
|
+
return refIdFromFilename(filename);
|
|
51
52
|
}
|
|
52
53
|
function findAnalysis(root, refId) {
|
|
53
54
|
const dir = path.join(root, ...REFS_DIR);
|
|
54
55
|
if (!fs.existsSync(dir))
|
|
55
56
|
return null;
|
|
56
|
-
const m =
|
|
57
|
+
const m = refFilesForId(dir, refId)[0];
|
|
57
58
|
return m ? path.join(dir, m) : null;
|
|
58
59
|
}
|
|
59
60
|
function hasPdf(root, refId) {
|
|
60
61
|
const dir = path.join(root, ...PDFS_DIR);
|
|
61
62
|
if (!fs.existsSync(dir))
|
|
62
63
|
return false;
|
|
63
|
-
return
|
|
64
|
+
return refFilesForId(dir, refId, '.pdf').length > 0;
|
|
64
65
|
}
|
|
65
66
|
/** Audit one ref. Required sections come from its source type's registry entry. */
|
|
66
67
|
function auditRef(root, refId, reg) {
|
|
@@ -182,7 +183,7 @@ function pdfHash(root, refId) {
|
|
|
182
183
|
const dir = path.join(root, ...PDFS_DIR);
|
|
183
184
|
if (!fs.existsSync(dir))
|
|
184
185
|
return null;
|
|
185
|
-
const m =
|
|
186
|
+
const m = refFilesForId(dir, refId, '.pdf')[0];
|
|
186
187
|
if (!m)
|
|
187
188
|
return null;
|
|
188
189
|
return createHash('sha256').update(fs.readFileSync(path.join(dir, m))).digest('hex');
|
|
@@ -16,6 +16,7 @@
|
|
|
16
16
|
* @tests @test/unit/artifacts/integrity-scan.test.ts
|
|
17
17
|
*/
|
|
18
18
|
import * as fs from 'fs';
|
|
19
|
+
import { refIdFromFilename } from '../../research/identity.js';
|
|
19
20
|
import * as path from 'path';
|
|
20
21
|
import { load as loadYaml } from 'js-yaml';
|
|
21
22
|
const TEXT_SUFFIXES = new Set(['.md', '.txt', '.tex', '.bib', '.yaml', '.yml', '.html', '.htm']);
|
|
@@ -56,8 +57,7 @@ export function loadIntegrityPatterns(root) {
|
|
|
56
57
|
}
|
|
57
58
|
const SEVERITY_RANK = { none: 0, low: 1, medium: 2, high: 3, critical: 4 };
|
|
58
59
|
function refFromPath(p) {
|
|
59
|
-
|
|
60
|
-
return m ? m[0] : 'NO-REF';
|
|
60
|
+
return refIdFromFilename(path.basename(p), path.extname(p)) ?? 'NO-REF';
|
|
61
61
|
}
|
|
62
62
|
function excerpt(line, limit = 220) {
|
|
63
63
|
const compact = line.trim().split(/\s+/).join(' ');
|
|
@@ -140,7 +140,7 @@ export function scanCorpus(root, opts = {}) {
|
|
|
140
140
|
: DEFAULT_TARGET_DIRS.map((parts) => path.join(root, ...parts));
|
|
141
141
|
const findings = [];
|
|
142
142
|
for (const file of iterFiles(targets)) {
|
|
143
|
-
if (opts.ref &&
|
|
143
|
+
if (opts.ref && refFromPath(file) !== opts.ref)
|
|
144
144
|
continue;
|
|
145
145
|
findings.push(...scanFile(root, file, patterns));
|
|
146
146
|
}
|
|
@@ -16,6 +16,8 @@
|
|
|
16
16
|
* @source historical: corpus/radar_init.py, corpus/radar_report.py
|
|
17
17
|
*/
|
|
18
18
|
import * as fs from 'fs';
|
|
19
|
+
import { isRefId, refSortKey } from '../../research/identity.js';
|
|
20
|
+
import { refFilesForId } from './ref-files.js';
|
|
19
21
|
import * as path from 'path';
|
|
20
22
|
import { load as loadYaml } from 'js-yaml';
|
|
21
23
|
import { parseFrontmatter, extractRadar } from '../corpus-views/ref-parser.js';
|
|
@@ -30,7 +32,7 @@ export function listRadarRefs(corpusRoot) {
|
|
|
30
32
|
try {
|
|
31
33
|
return fs
|
|
32
34
|
.readdirSync(radarDir(corpusRoot))
|
|
33
|
-
.filter((f) =>
|
|
35
|
+
.filter((f) => f.endsWith('-radar.md') && isRefId(f.slice(0, -9)))
|
|
34
36
|
.map((f) => f.replace(/-radar\.md$/, ''))
|
|
35
37
|
.sort();
|
|
36
38
|
}
|
|
@@ -43,7 +45,7 @@ export function listCitationRefs(corpusRoot) {
|
|
|
43
45
|
try {
|
|
44
46
|
return fs
|
|
45
47
|
.readdirSync(path.join(corpusRoot, ...CITES_DIR))
|
|
46
|
-
.filter((f) =>
|
|
48
|
+
.filter((f) => f.endsWith('-citations.md') && isRefId(f.slice(0, -13)))
|
|
47
49
|
.map((f) => f.replace(/-citations\.md$/, ''))
|
|
48
50
|
.sort();
|
|
49
51
|
}
|
|
@@ -90,10 +92,9 @@ export function loadClusterMap(corpusRoot) {
|
|
|
90
92
|
}
|
|
91
93
|
}
|
|
92
94
|
return (refId) => {
|
|
93
|
-
|
|
94
|
-
if (!m)
|
|
95
|
+
if (!isRefId(refId))
|
|
95
96
|
return '';
|
|
96
|
-
const n =
|
|
97
|
+
const [n] = refSortKey(refId);
|
|
97
98
|
for (const [low, high, tag] of rules) {
|
|
98
99
|
if (n >= low && n <= high)
|
|
99
100
|
return tag;
|
|
@@ -131,10 +132,7 @@ export function readAnalysisGrade(corpusRoot, refId) {
|
|
|
131
132
|
function analysisFiles(corpusRoot, refId) {
|
|
132
133
|
const dir = path.join(corpusRoot, ...REFS_DIR);
|
|
133
134
|
try {
|
|
134
|
-
return
|
|
135
|
-
.readdirSync(dir)
|
|
136
|
-
.filter((f) => f.startsWith(`${refId}-`) && f.endsWith('.md') && !f.startsWith('TEMPLATE'))
|
|
137
|
-
.sort()
|
|
135
|
+
return refFilesForId(dir, refId)
|
|
138
136
|
.map((f) => path.join(dir, f));
|
|
139
137
|
}
|
|
140
138
|
catch {
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
// Locate regular corpus files by exact REF identity and extension.
|
|
2
|
+
import { readdirSync } from 'node:fs';
|
|
3
|
+
import { isRefId, refIdFromFilename } from '../../research/identity.js';
|
|
4
|
+
export function refFilesForId(directory, refId, extension = '.md') {
|
|
5
|
+
if (!isRefId(refId))
|
|
6
|
+
return [];
|
|
7
|
+
return readdirSync(directory, { withFileTypes: true })
|
|
8
|
+
.filter(file => file.isFile() && refIdFromFilename(file.name, extension) === refId)
|
|
9
|
+
.map(file => file.name).sort();
|
|
10
|
+
}
|
|
11
|
+
//# sourceMappingURL=ref-files.js.map
|