@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
|
@@ -1,4 +1,6 @@
|
|
|
1
1
|
import fs from "node:fs";
|
|
2
|
+
import { parseArgs, usage } from "./query-options.js";
|
|
3
|
+
import { refIdsInText } from "./identity.js";
|
|
2
4
|
import path from "node:path";
|
|
3
5
|
import { parseFrontmatter } from "../artifacts/index-builder.js";
|
|
4
6
|
import { loadGraphIndexFile } from "../artifacts/index-reader.js";
|
|
@@ -36,92 +38,6 @@ const STOPWORDS = new Set([
|
|
|
36
38
|
"say",
|
|
37
39
|
"evidence",
|
|
38
40
|
]);
|
|
39
|
-
function usage() {
|
|
40
|
-
return [
|
|
41
|
-
"Usage: aiwg research-query <question> [--backend fortemi-core|local] [--graph <name>]",
|
|
42
|
-
" [--depth quick|thorough] [--sources-only] [--max-sources N]",
|
|
43
|
-
" [--include-diagnostics] [--json] [--save]",
|
|
44
|
-
].join("\n");
|
|
45
|
-
}
|
|
46
|
-
function flagValue(args, flag, errorMessage) {
|
|
47
|
-
const index = args.indexOf(flag);
|
|
48
|
-
if (index < 0)
|
|
49
|
-
return undefined;
|
|
50
|
-
const value = args[index + 1];
|
|
51
|
-
if (!value || value.startsWith("--")) {
|
|
52
|
-
throw new Error(errorMessage);
|
|
53
|
-
}
|
|
54
|
-
return value;
|
|
55
|
-
}
|
|
56
|
-
function positiveIntegerFlag(args, flag, defaultValue, errorMessage) {
|
|
57
|
-
const value = flagValue(args, flag, errorMessage);
|
|
58
|
-
if (value === undefined)
|
|
59
|
-
return defaultValue;
|
|
60
|
-
const parsed = Number.parseInt(value, 10);
|
|
61
|
-
if (!Number.isInteger(parsed) || parsed < 1 || String(parsed) !== value) {
|
|
62
|
-
throw new Error(errorMessage);
|
|
63
|
-
}
|
|
64
|
-
return parsed;
|
|
65
|
-
}
|
|
66
|
-
function hasFlag(args, flag) {
|
|
67
|
-
return args.includes(flag);
|
|
68
|
-
}
|
|
69
|
-
function stripFlags(args) {
|
|
70
|
-
const valueFlags = new Set([
|
|
71
|
-
"--backend",
|
|
72
|
-
"--graph",
|
|
73
|
-
"--depth",
|
|
74
|
-
"--max-sources",
|
|
75
|
-
]);
|
|
76
|
-
const bareFlags = new Set([
|
|
77
|
-
"--sources-only",
|
|
78
|
-
"--include-diagnostics",
|
|
79
|
-
"--json",
|
|
80
|
-
"--save",
|
|
81
|
-
]);
|
|
82
|
-
const question = [];
|
|
83
|
-
for (let index = 0; index < args.length; index++) {
|
|
84
|
-
const arg = args[index];
|
|
85
|
-
if (valueFlags.has(arg)) {
|
|
86
|
-
index++;
|
|
87
|
-
continue;
|
|
88
|
-
}
|
|
89
|
-
if (bareFlags.has(arg))
|
|
90
|
-
continue;
|
|
91
|
-
question.push(arg);
|
|
92
|
-
}
|
|
93
|
-
return question;
|
|
94
|
-
}
|
|
95
|
-
function parseArgs(args) {
|
|
96
|
-
if (hasFlag(args, "--help") || hasFlag(args, "-h")) {
|
|
97
|
-
console.log(usage());
|
|
98
|
-
process.exit(0);
|
|
99
|
-
}
|
|
100
|
-
const backend = flagValue(args, "--backend", "--backend must be local or fortemi-core");
|
|
101
|
-
if (backend && backend !== "local" && backend !== "fortemi-core") {
|
|
102
|
-
throw new Error("--backend must be local or fortemi-core");
|
|
103
|
-
}
|
|
104
|
-
const depth = (flagValue(args, "--depth", "--depth must be quick or thorough") ?? "thorough");
|
|
105
|
-
if (depth !== "quick" && depth !== "thorough") {
|
|
106
|
-
throw new Error("--depth must be quick or thorough");
|
|
107
|
-
}
|
|
108
|
-
const maxSources = positiveIntegerFlag(args, "--max-sources", 10, "--max-sources must be a positive integer");
|
|
109
|
-
const question = stripFlags(args).join(" ").trim();
|
|
110
|
-
if (!question)
|
|
111
|
-
throw new Error("question is required");
|
|
112
|
-
return {
|
|
113
|
-
question,
|
|
114
|
-
backend: backend ?? "fortemi-core",
|
|
115
|
-
graph: (flagValue(args, "--graph", "--graph requires a graph name") ??
|
|
116
|
-
"project"),
|
|
117
|
-
depth,
|
|
118
|
-
maxSources,
|
|
119
|
-
sourcesOnly: hasFlag(args, "--sources-only"),
|
|
120
|
-
includeDiagnostics: hasFlag(args, "--include-diagnostics"),
|
|
121
|
-
json: hasFlag(args, "--json"),
|
|
122
|
-
save: hasFlag(args, "--save"),
|
|
123
|
-
};
|
|
124
|
-
}
|
|
125
41
|
function tokens(text) {
|
|
126
42
|
return text
|
|
127
43
|
.toLowerCase()
|
|
@@ -141,7 +57,7 @@ function readEntryBody(cwd, entryPath) {
|
|
|
141
57
|
}
|
|
142
58
|
function entryId(entry) {
|
|
143
59
|
const text = [entry.name, entry.title, entry.path].filter(Boolean).join(" ");
|
|
144
|
-
return (text
|
|
60
|
+
return (refIdsInText(text)[0] ??
|
|
145
61
|
text.match(/\bPROF-[A-Z0-9-]+/i)?.[0]?.toUpperCase() ??
|
|
146
62
|
path.basename(entry.path).replace(/\.[^.]+$/, ""));
|
|
147
63
|
}
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
export function usage() {
|
|
2
|
+
return [
|
|
3
|
+
"Usage: aiwg research-query <question> [--backend fortemi-core|local] [--graph <name>]",
|
|
4
|
+
" [--depth quick|thorough] [--sources-only] [--max-sources N]",
|
|
5
|
+
" [--include-diagnostics] [--json] [--save]",
|
|
6
|
+
].join("\n");
|
|
7
|
+
}
|
|
8
|
+
function flagValue(args, flag, errorMessage) {
|
|
9
|
+
const index = args.indexOf(flag);
|
|
10
|
+
if (index < 0)
|
|
11
|
+
return undefined;
|
|
12
|
+
const value = args[index + 1];
|
|
13
|
+
if (!value || value.startsWith("--")) {
|
|
14
|
+
throw new Error(errorMessage);
|
|
15
|
+
}
|
|
16
|
+
return value;
|
|
17
|
+
}
|
|
18
|
+
function positiveIntegerFlag(args, flag, defaultValue, errorMessage) {
|
|
19
|
+
const value = flagValue(args, flag, errorMessage);
|
|
20
|
+
if (value === undefined)
|
|
21
|
+
return defaultValue;
|
|
22
|
+
const parsed = Number.parseInt(value, 10);
|
|
23
|
+
if (!Number.isInteger(parsed) || parsed < 1 || String(parsed) !== value) {
|
|
24
|
+
throw new Error(errorMessage);
|
|
25
|
+
}
|
|
26
|
+
return parsed;
|
|
27
|
+
}
|
|
28
|
+
function hasFlag(args, flag) {
|
|
29
|
+
return args.includes(flag);
|
|
30
|
+
}
|
|
31
|
+
function stripFlags(args) {
|
|
32
|
+
const valueFlags = new Set([
|
|
33
|
+
"--backend",
|
|
34
|
+
"--graph",
|
|
35
|
+
"--depth",
|
|
36
|
+
"--max-sources",
|
|
37
|
+
]);
|
|
38
|
+
const bareFlags = new Set([
|
|
39
|
+
"--sources-only",
|
|
40
|
+
"--include-diagnostics",
|
|
41
|
+
"--json",
|
|
42
|
+
"--save",
|
|
43
|
+
]);
|
|
44
|
+
const question = [];
|
|
45
|
+
for (let index = 0; index < args.length; index++) {
|
|
46
|
+
const arg = args[index];
|
|
47
|
+
if (valueFlags.has(arg)) {
|
|
48
|
+
index++;
|
|
49
|
+
continue;
|
|
50
|
+
}
|
|
51
|
+
if (bareFlags.has(arg))
|
|
52
|
+
continue;
|
|
53
|
+
question.push(arg);
|
|
54
|
+
}
|
|
55
|
+
return question;
|
|
56
|
+
}
|
|
57
|
+
export function parseArgs(args) {
|
|
58
|
+
if (hasFlag(args, "--help") || hasFlag(args, "-h")) {
|
|
59
|
+
console.log(usage());
|
|
60
|
+
process.exit(0);
|
|
61
|
+
}
|
|
62
|
+
const backend = flagValue(args, "--backend", "--backend must be local or fortemi-core");
|
|
63
|
+
if (backend && backend !== "local" && backend !== "fortemi-core") {
|
|
64
|
+
throw new Error("--backend must be local or fortemi-core");
|
|
65
|
+
}
|
|
66
|
+
const depth = (flagValue(args, "--depth", "--depth must be quick or thorough") ?? "thorough");
|
|
67
|
+
if (depth !== "quick" && depth !== "thorough") {
|
|
68
|
+
throw new Error("--depth must be quick or thorough");
|
|
69
|
+
}
|
|
70
|
+
const maxSources = positiveIntegerFlag(args, "--max-sources", 10, "--max-sources must be a positive integer");
|
|
71
|
+
const question = stripFlags(args).join(" ").trim();
|
|
72
|
+
if (!question)
|
|
73
|
+
throw new Error("question is required");
|
|
74
|
+
return {
|
|
75
|
+
question,
|
|
76
|
+
backend: backend ?? "fortemi-core",
|
|
77
|
+
graph: (flagValue(args, "--graph", "--graph requires a graph name") ??
|
|
78
|
+
"project"),
|
|
79
|
+
depth,
|
|
80
|
+
maxSources,
|
|
81
|
+
sourcesOnly: hasFlag(args, "--sources-only"),
|
|
82
|
+
includeDiagnostics: hasFlag(args, "--include-diagnostics"),
|
|
83
|
+
json: hasFlag(args, "--json"),
|
|
84
|
+
save: hasFlag(args, "--save"),
|
|
85
|
+
};
|
|
86
|
+
}
|
|
87
|
+
//# sourceMappingURL=query-options.js.map
|
|
@@ -0,0 +1,135 @@
|
|
|
1
|
+
// Parse partial citations and score distinct candidate identities without choosing close matches.
|
|
2
|
+
import { normalizeIdentity, normalizeTitle, parseArxivId, parseResearchIdentifier } from './identity.js';
|
|
3
|
+
/** Common quoted, APA-style and title-plus-year citations; retain the untouched input. */
|
|
4
|
+
export function parsePartialReference(input, year) {
|
|
5
|
+
const identifier = parseResearchIdentifier(input);
|
|
6
|
+
let rest = identifier ? input.replace(identifier.matched, '') : input;
|
|
7
|
+
rest = rest.replace(/^\s*\[\d+\]\s*/, '').trim();
|
|
8
|
+
const quoted = rest.match(/["“]([^"”]+)["”]/);
|
|
9
|
+
const apa = rest.match(/^(.+?)\s*\(((?:18|19|20|21)\d{2})\)\.?\s+(.+)$/);
|
|
10
|
+
const authorYear = rest.match(/^(.+?(?:et al\.|,\s*[A-Z]\.))\s*((?:18|19|20|21)\d{2})\.?\s+(.+)$/);
|
|
11
|
+
const bibliography = apa ?? authorYear;
|
|
12
|
+
// A number inside a title is not publication metadata; require citation cues.
|
|
13
|
+
const date = (quoted ? rest.replace(quoted[0], '') : rest).match(/\(((?:18|19|20|21)\d{2})\)/);
|
|
14
|
+
const inferredYear = bibliography?.[2] ?? date?.[1];
|
|
15
|
+
const firstAuthor = bibliography?.[1].split(/,|\s+et al\.|\s+and\s+|\s+&\s+/)[0].trim();
|
|
16
|
+
if (quoted)
|
|
17
|
+
rest = quoted[1];
|
|
18
|
+
else if (bibliography)
|
|
19
|
+
rest = bibliography[3].split(/\.\s+/)[0];
|
|
20
|
+
else if (date)
|
|
21
|
+
rest = rest.replace(date[0], '');
|
|
22
|
+
rest = rest.replace(/^[\s.,;:()[\]{}"']+|[\s.,;:()[\]{}"']+$/g, '').trim();
|
|
23
|
+
return { input, identifier, title: normalizeTitle(rest) ? rest : undefined, year: year ?? (inferredYear ? Number(inferredYear) : undefined), firstAuthor };
|
|
24
|
+
}
|
|
25
|
+
/** Token coverage discounted by sequence order; ordered prefixes retain coverage scores. */
|
|
26
|
+
export function titleSimilarity(left, right) {
|
|
27
|
+
if (normalizeTitle(left) && normalizeTitle(left) === normalizeTitle(right))
|
|
28
|
+
return 1;
|
|
29
|
+
const a = normalizeTitle(left).split(' ').filter(Boolean);
|
|
30
|
+
const b = normalizeTitle(right).split(' ').filter(Boolean);
|
|
31
|
+
if (!a.length || !b.length)
|
|
32
|
+
return 0;
|
|
33
|
+
const uniqueA = new Set(a), uniqueB = new Set(b);
|
|
34
|
+
const coverage = [...uniqueA].filter(token => uniqueB.has(token)).length / new Set([...a, ...b]).size;
|
|
35
|
+
const row = Array(b.length + 1).fill(0);
|
|
36
|
+
for (const token of a) {
|
|
37
|
+
let diagonal = 0;
|
|
38
|
+
for (let j = 1; j <= b.length; j++) {
|
|
39
|
+
const previous = row[j];
|
|
40
|
+
row[j] = token === b[j - 1] ? diagonal + 1 : Math.max(row[j], row[j - 1]);
|
|
41
|
+
diagonal = previous;
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
// Repeated tokens must also reduce similarity even when their token sets agree.
|
|
45
|
+
const repetition = Math.min(uniqueA.size / a.length, uniqueB.size / b.length);
|
|
46
|
+
return coverage * row[b.length] / Math.min(a.length, b.length) * repetition;
|
|
47
|
+
}
|
|
48
|
+
/** Incomplete short/generic titles require an ID; unqualified very short titles need metadata. */
|
|
49
|
+
export function needsTitleDisambiguation(reference, candidates, incomplete) {
|
|
50
|
+
if (!reference.title || candidates[0]?.score_parts.identifier === 1)
|
|
51
|
+
return false;
|
|
52
|
+
const title = normalizeTitle(reference.title);
|
|
53
|
+
const tokens = title.split(' ');
|
|
54
|
+
const informative = tokens.filter(token => !/^(?:a|an|the|of|for|in|on|and|with|to|is|all|you)$/.test(token));
|
|
55
|
+
const exact = candidates.filter(candidate => normalizeTitle(candidate.paper.title) === title).length;
|
|
56
|
+
return (incomplete && (tokens.length <= 4 || informative.length <= 4 || exact > 1)) ||
|
|
57
|
+
(tokens.length <= 2 && reference.year === undefined && !reference.firstAuthor);
|
|
58
|
+
}
|
|
59
|
+
function surname(name) {
|
|
60
|
+
return normalizeTitle(name.includes(',') ? name.split(',')[0] : name.trim().split(/\s+/).at(-1) ?? '');
|
|
61
|
+
}
|
|
62
|
+
/** Title weight .9; supplied year and first author each add .05, then renormalize. */
|
|
63
|
+
export function scorePaper(reference, paper, verifiedId = false) {
|
|
64
|
+
const title = reference.title ? titleSimilarity(reference.title, paper.title) : (verifiedId ? 1 : 0);
|
|
65
|
+
const parts = { title };
|
|
66
|
+
let sum = 0.9 * title;
|
|
67
|
+
let weight = 0.9;
|
|
68
|
+
if (reference.year !== undefined) {
|
|
69
|
+
parts.year = paper.year === reference.year ? 1 : 0;
|
|
70
|
+
sum += 0.05 * parts.year;
|
|
71
|
+
weight += 0.05;
|
|
72
|
+
}
|
|
73
|
+
if (reference.firstAuthor) {
|
|
74
|
+
parts.first_author = surname(reference.firstAuthor) === surname(paper.authors[0]?.name ?? '') ? 1 : 0;
|
|
75
|
+
sum += 0.05 * parts.first_author;
|
|
76
|
+
weight += 0.05;
|
|
77
|
+
}
|
|
78
|
+
if (verifiedId)
|
|
79
|
+
parts.identifier = 1;
|
|
80
|
+
return { paper, score: sum / weight, score_parts: parts };
|
|
81
|
+
}
|
|
82
|
+
/** Apply inclusive approved boundaries; epsilon only compensates floating-point subtraction. */
|
|
83
|
+
export function classifyCandidates(candidates) {
|
|
84
|
+
const best = candidates[0]?.score ?? 0;
|
|
85
|
+
if (best + 1e-12 < 0.6)
|
|
86
|
+
return 'unresolved';
|
|
87
|
+
const margin = best - (candidates[1]?.score ?? 0);
|
|
88
|
+
return best + 1e-12 >= 0.92 && margin + 1e-12 >= 0.05 ? 'resolved' : 'ambiguous';
|
|
89
|
+
}
|
|
90
|
+
/** Shared IDs require title similarity >= 0.5; title agreement never establishes identity. */
|
|
91
|
+
export function mergePapers(papers) {
|
|
92
|
+
const ids = ['arxivId', 'doi', 's2PaperId', 'openReviewId', 'aclId'];
|
|
93
|
+
const published = (paper) => Boolean(paper.doi && !parseArxivId(paper.doi));
|
|
94
|
+
const linked = (left, right) => {
|
|
95
|
+
const a = normalizeIdentity(left), b = normalizeIdentity(right);
|
|
96
|
+
if (titleSimilarity(a.title ?? '', b.title ?? '') < 0.5)
|
|
97
|
+
return false;
|
|
98
|
+
if (ids.some(key => a[key] && b[key] && a[key] !== b[key] &&
|
|
99
|
+
!(key === 'doi' && a.arxivId && a.arxivId === b.arxivId && (parseArxivId(a.doi) || parseArxivId(b.doi)))))
|
|
100
|
+
return false;
|
|
101
|
+
return ids.some(key => a[key] && a[key] === b[key]);
|
|
102
|
+
};
|
|
103
|
+
const combine = (left, right) => {
|
|
104
|
+
// A published CrossRef record owns proceedings metadata; other sources fill gaps.
|
|
105
|
+
const preferRight = (published(right) && !published(left)) ||
|
|
106
|
+
(published(right) && right.source === 'crossref' && left.source !== 'crossref');
|
|
107
|
+
const [primary, alternate] = preferRight ? [right, left] : [left, right];
|
|
108
|
+
const result = { ...primary };
|
|
109
|
+
for (const [key, value] of Object.entries(alternate)) {
|
|
110
|
+
if (value !== undefined && (!result[key] ||
|
|
111
|
+
(Array.isArray(result[key]) && result[key].length === 0))) {
|
|
112
|
+
result[key] = value;
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
return result;
|
|
116
|
+
};
|
|
117
|
+
const merged = [];
|
|
118
|
+
for (const paper of papers) {
|
|
119
|
+
// Comparison keys are canonical; OpenReview/ACL spelling remains source metadata.
|
|
120
|
+
const { title: _title, openReviewId: _review, aclId: _acl, ...identity } = normalizeIdentity(paper);
|
|
121
|
+
let work = { ...paper, ...Object.fromEntries(Object.entries(identity).filter(([, value]) => value !== undefined)) };
|
|
122
|
+
// A late S2 bridge may join two components already encountered in source order.
|
|
123
|
+
for (let i = 0; i < merged.length;) {
|
|
124
|
+
if (!linked(work, merged[i])) {
|
|
125
|
+
i++;
|
|
126
|
+
continue;
|
|
127
|
+
}
|
|
128
|
+
work = combine(merged.splice(i, 1)[0], work);
|
|
129
|
+
i = 0;
|
|
130
|
+
}
|
|
131
|
+
merged.push(work);
|
|
132
|
+
}
|
|
133
|
+
return merged;
|
|
134
|
+
}
|
|
135
|
+
//# sourceMappingURL=reference-match.js.map
|
|
@@ -6,6 +6,7 @@
|
|
|
6
6
|
import { promises as fs } from 'fs';
|
|
7
7
|
import { join, dirname } from 'path';
|
|
8
8
|
import { createHash } from 'crypto';
|
|
9
|
+
import { isRefId, refIdFromFilename, refSortKey } from '../identity.js';
|
|
9
10
|
import { UnpaywallClient } from '../clients/unpaywall.js';
|
|
10
11
|
/**
|
|
11
12
|
* Acquisition service for downloading research papers
|
|
@@ -87,8 +88,8 @@ export class AcquisitionService {
|
|
|
87
88
|
}
|
|
88
89
|
// Extract numbers from REF-XXX format
|
|
89
90
|
const refNumbers = refs
|
|
90
|
-
.filter(
|
|
91
|
-
.map((ref) =>
|
|
91
|
+
.filter(isRefId)
|
|
92
|
+
.map((ref) => refSortKey(ref)[0])
|
|
92
93
|
.filter((n) => !isNaN(n));
|
|
93
94
|
// Find next available number
|
|
94
95
|
const maxNumber = refNumbers.length > 0 ? Math.max(...refNumbers) : 0;
|
|
@@ -138,7 +139,7 @@ export class AcquisitionService {
|
|
|
138
139
|
{
|
|
139
140
|
id: 'F1',
|
|
140
141
|
description: 'Assigned globally unique identifier (REF-XXX)',
|
|
141
|
-
met:
|
|
142
|
+
met: isRefId(source.refId),
|
|
142
143
|
},
|
|
143
144
|
{
|
|
144
145
|
id: 'F2',
|
|
@@ -283,12 +284,13 @@ export class AcquisitionService {
|
|
|
283
284
|
async scanExistingRefs() {
|
|
284
285
|
const refs = [];
|
|
285
286
|
try {
|
|
286
|
-
const files = await fs.readdir(this.downloadDir);
|
|
287
|
+
const files = await fs.readdir(this.downloadDir, { withFileTypes: true });
|
|
287
288
|
for (const file of files) {
|
|
288
|
-
if (file.
|
|
289
|
-
|
|
289
|
+
if (!file.isFile())
|
|
290
|
+
continue;
|
|
291
|
+
const refId = refIdFromFilename(file.name, '.pdf');
|
|
292
|
+
if (refId)
|
|
290
293
|
refs.push(refId);
|
|
291
|
-
}
|
|
292
294
|
}
|
|
293
295
|
}
|
|
294
296
|
catch (error) {
|
|
@@ -4,6 +4,7 @@
|
|
|
4
4
|
* @module research/services/citation
|
|
5
5
|
*/
|
|
6
6
|
import { promises as fs } from 'fs';
|
|
7
|
+
import { isRefId, refIdFromFilename } from '../identity.js';
|
|
7
8
|
/**
|
|
8
9
|
* Citation service for managing citations and networks
|
|
9
10
|
*/
|
|
@@ -37,10 +38,12 @@ export class CitationService {
|
|
|
37
38
|
* Validate that a citation exists in corpus
|
|
38
39
|
*/
|
|
39
40
|
async validateCitation(refId, corpusPath) {
|
|
41
|
+
if (!isRefId(refId))
|
|
42
|
+
return false;
|
|
40
43
|
const path = corpusPath || this.corpusPath;
|
|
41
44
|
try {
|
|
42
|
-
const files = await fs.readdir(path);
|
|
43
|
-
return files.some((file) => file.
|
|
45
|
+
const files = await fs.readdir(path, { withFileTypes: true });
|
|
46
|
+
return files.some((file) => file.isFile() && refIdFromFilename(file.name) === refId);
|
|
44
47
|
}
|
|
45
48
|
catch (error) {
|
|
46
49
|
return false;
|
|
@@ -37,6 +37,8 @@ export var ResearchErrorCode;
|
|
|
37
37
|
export class ResearchError extends Error {
|
|
38
38
|
code;
|
|
39
39
|
cause;
|
|
40
|
+
/** Server-directed cooldown, shared by all requests through the client limiter. */
|
|
41
|
+
retryAfterMs;
|
|
40
42
|
constructor(code, message, cause) {
|
|
41
43
|
super(message);
|
|
42
44
|
this.code = code;
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
/** Share compact core rendering between provider deployment and fresh regeneration. */
|
|
2
|
+
import fs from 'node:fs';
|
|
3
|
+
import path from 'node:path';
|
|
4
|
+
import { fileURLToPath } from 'node:url';
|
|
5
|
+
import { findPackageRoot } from '../cli/find-package-root.js';
|
|
6
|
+
import { parseRuleFrontmatter, readCoreBody, validateCoreSet } from './activation.mjs';
|
|
7
|
+
|
|
8
|
+
export function renderCoreStartup(rules) {
|
|
9
|
+
const cores = [...new Map(rules.filter(rule => rule.coreBody !== undefined).map(rule => [rule.name, rule])).values()];
|
|
10
|
+
const errors = validateCoreSet(cores.map(rule => ({ name: rule.name, text: rule.coreBody })));
|
|
11
|
+
if (errors.length) throw new Error(errors.join('; '));
|
|
12
|
+
return cores.length ? `<!-- AIWG:rule-core:start -->\n## Core rules\n\n${cores.map(rule => rule.coreBody).join('\n\n')}\n<!-- AIWG:rule-core:end -->\n` : '';
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
export function ensureCoreStartup(content) {
|
|
16
|
+
// Deployment has already selected and validated the project's core set.
|
|
17
|
+
if (content.includes('<!-- AIWG:rule-core:start -->')) return content;
|
|
18
|
+
const root = findPackageRoot(path.dirname(fileURLToPath(import.meta.url)));
|
|
19
|
+
if (!root) throw new Error('AIWG package unavailable; run aiwg use before regenerating context.');
|
|
20
|
+
const dir = path.join(root, 'agentic/code/addons/aiwg-utils/rules');
|
|
21
|
+
if (!fs.existsSync(dir)) throw new Error('Core rule sources unavailable; run aiwg use before regenerating context.');
|
|
22
|
+
const rules = fs.readdirSync(dir).filter(name => name.endsWith('.md') && !name.endsWith('.core.md')).flatMap(name => {
|
|
23
|
+
const file = path.join(dir, name);
|
|
24
|
+
const parsed = parseRuleFrontmatter(fs.readFileSync(file, 'utf8'));
|
|
25
|
+
if (!parsed.valid) throw new Error(`Invalid core rule source ${file}; run aiwg use after repairing it.`);
|
|
26
|
+
return parsed.rule.activation === 'core' ? [{ name: parsed.data.name || path.basename(file, '.md'), coreBody: readCoreBody(file) }] : [];
|
|
27
|
+
});
|
|
28
|
+
const block = renderCoreStartup(rules);
|
|
29
|
+
if (!block) throw new Error('No core rule sources found; run aiwg use before regenerating context.');
|
|
30
|
+
return `${content}${content.endsWith('\n') ? '\n' : '\n\n'}${block}`;
|
|
31
|
+
}
|
|
@@ -25,6 +25,9 @@
|
|
|
25
25
|
import { routeMission } from './agent-router.js';
|
|
26
26
|
import { StackAdapterRegistry } from './stack-adapters.js';
|
|
27
27
|
import { assertMissionWorkerHandoff } from '../mission-protocol/codecs.js';
|
|
28
|
+
import { lookupEffect, reconcileEffect, recordIntent } from '../effects/ledger.js';
|
|
29
|
+
import { createVerifierRegistry } from '../effects/verifiers/registry.js';
|
|
30
|
+
import { fileDigestVerifier } from '../effects/verifiers/file.js';
|
|
28
31
|
/**
|
|
29
32
|
* The cross-stack Mission conductor. Decomposes a Mission into worker cycles,
|
|
30
33
|
* dispatches each to an executor of the chosen runtime via `routeMission`, and
|
|
@@ -35,11 +38,13 @@ export class MissionConductor {
|
|
|
35
38
|
runWorker;
|
|
36
39
|
scoreOutput;
|
|
37
40
|
scorerId;
|
|
41
|
+
effectLedger;
|
|
38
42
|
constructor(opts = {}) {
|
|
39
43
|
this.adapters = opts.adapters ?? new StackAdapterRegistry();
|
|
40
44
|
this.runWorker = opts.runWorker;
|
|
41
45
|
this.scoreOutput = opts.scoreOutput;
|
|
42
46
|
this.scorerId = opts.scoreOutput ? (opts.scorerId ?? 'custom') : null;
|
|
47
|
+
this.effectLedger = opts.effectLedger;
|
|
43
48
|
}
|
|
44
49
|
/**
|
|
45
50
|
* Conduct a Mission across the given executor pool. Returns the ledger.
|
|
@@ -153,10 +158,49 @@ export class MissionConductor {
|
|
|
153
158
|
}
|
|
154
159
|
let output;
|
|
155
160
|
let cost = 0;
|
|
161
|
+
let reason = routing.selected.matchReason;
|
|
156
162
|
try {
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
163
|
+
let intent;
|
|
164
|
+
let recovered = false;
|
|
165
|
+
const effects = this.effectLedger;
|
|
166
|
+
const reconcile = (id) => reconcileEffect(effects, id, {
|
|
167
|
+
verifiers: createVerifierRegistry([fileDigestVerifier({ root: effects.projectDir })]),
|
|
168
|
+
expected: { previousDigest: cycle.fileEffect.previousDigest ?? null },
|
|
169
|
+
});
|
|
170
|
+
if (cycle.fileEffect) {
|
|
171
|
+
if (!effects)
|
|
172
|
+
throw new Error('file effect requires a host-configured effect ledger');
|
|
173
|
+
const { target, payloadDigest, previousDigest } = cycle.fileEffect;
|
|
174
|
+
intent = await recordIntent(effects, {
|
|
175
|
+
kind: 'file.digest', target, payloadDigest,
|
|
176
|
+
context: { missionId: plan.missionId, cycleId: cycle.id,
|
|
177
|
+
...(previousDigest === undefined ? {} : { previousDigest }) },
|
|
178
|
+
});
|
|
179
|
+
const recorded = await lookupEffect(effects, intent.effectId);
|
|
180
|
+
if (recorded.tombstoned || recorded.records.some(record => record.phase === 'failed')) {
|
|
181
|
+
throw new Error(`file effect ${intent.effectId} replay blocked: terminal outcome or tombstone`);
|
|
182
|
+
}
|
|
183
|
+
recovered = recorded.records.some(record => record.phase === 'completed');
|
|
184
|
+
if (!recovered) {
|
|
185
|
+
const checked = await reconcile(intent.effectId);
|
|
186
|
+
if (checked.result.verification.result === 'unknown') {
|
|
187
|
+
throw new Error(`file effect ${intent.effectId} replay blocked: ${checked.result.verification.reason}`);
|
|
188
|
+
}
|
|
189
|
+
recovered = checked.completed !== null;
|
|
190
|
+
}
|
|
191
|
+
if (recovered)
|
|
192
|
+
reason = `file effect ${intent.effectId} completed; worker replay skipped`;
|
|
193
|
+
}
|
|
194
|
+
if (!recovered) {
|
|
195
|
+
const ran = await this.runWorker(cycle, executor, invocation);
|
|
196
|
+
output = ran.output;
|
|
197
|
+
cost = ran.cost ?? 0;
|
|
198
|
+
if (intent) {
|
|
199
|
+
const checked = await reconcile(intent.effectId);
|
|
200
|
+
if (!checked.completed)
|
|
201
|
+
throw new Error(`file effect ${intent.effectId} completion unverified: ${checked.result.verification.reason}`);
|
|
202
|
+
}
|
|
203
|
+
}
|
|
160
204
|
}
|
|
161
205
|
catch (err) {
|
|
162
206
|
const result = {
|
|
@@ -180,7 +224,7 @@ export class MissionConductor {
|
|
|
180
224
|
primitive: adapter.primitive,
|
|
181
225
|
executorId: executor.executorId,
|
|
182
226
|
routed: true,
|
|
183
|
-
reason
|
|
227
|
+
reason,
|
|
184
228
|
output,
|
|
185
229
|
cost,
|
|
186
230
|
...(graph ? { graph } : {}),
|
|
@@ -15,6 +15,26 @@ export const GROK_BUILD_ACTIVE_SESSIONS_SCHEMA_VERSION = 1;
|
|
|
15
15
|
export const GROK_BUILD_ACTIVE_FRESHNESS_MS = 120_000;
|
|
16
16
|
export const GROK_BUILD_NATIVE_DISCOVERY_MAX_FILES = 10_000;
|
|
17
17
|
const ACTIVE_SESSIONS_MAX_BYTES = 1024 * 1024;
|
|
18
|
+
export function grokBuildNativeEnabled() {
|
|
19
|
+
return process.env.AIWG_GROK_BUILD_NATIVE_EXPERIMENTAL === '1';
|
|
20
|
+
}
|
|
21
|
+
/** One availability message for native readers, discovery and CLI capability reports. */
|
|
22
|
+
export function grokBuildNativeAvailability() {
|
|
23
|
+
const enabled = grokBuildNativeEnabled();
|
|
24
|
+
return {
|
|
25
|
+
reasonCode: enabled ? 'GROK_BUILD_NATIVE_EXPERIMENTAL_ENABLED' : 'GROK_BUILD_NATIVE_EXPERIMENTAL_DISABLED',
|
|
26
|
+
remediation: `Grok Build native ingestion is experimental and ${enabled ? 'enabled but' : 'disabled by default because it is'} `
|
|
27
|
+
+ 'unqualified: no released-binary schema or version range is qualified. '
|
|
28
|
+
+ 'AIWG_GROK_BUILD_NATIVE_EXPERIMENTAL=1 opts in to synthetic v1 chat_history.jsonl and active_sessions.json only; '
|
|
29
|
+
+ 'authorize the sessions root separately with --grok-root and the optional registry file with --grok-active-sessions. '
|
|
30
|
+
+ 'Use `grok export <session-id> <session-id>.md` and import the authorized Markdown file for the documented CLI path.',
|
|
31
|
+
};
|
|
32
|
+
}
|
|
33
|
+
export function assertGrokBuildNativeEnabled() {
|
|
34
|
+
if (!grokBuildNativeEnabled()) {
|
|
35
|
+
throw new SessionContractError('UNSUPPORTED_OPERATION', grokBuildNativeAvailability().remediation);
|
|
36
|
+
}
|
|
37
|
+
}
|
|
18
38
|
const UUID = /^[0-9a-f]{8}-[0-9a-f]{4}-[1-8][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/i;
|
|
19
39
|
// Synthetic native record shape (v1): one JSON object per line. Real
|
|
20
40
|
// chat_history.jsonl schemas are unqualified (real stores are never read),
|
|
@@ -59,6 +79,7 @@ export function grokBuildNativeSessionId(locator) {
|
|
|
59
79
|
}
|
|
60
80
|
/** Enumerate documented `<root>/<url-encoded cwd>/<id>/chat_history.jsonl` paths. */
|
|
61
81
|
export async function* discoverGrokBuildNativeChatHistories(root, maxFiles = GROK_BUILD_NATIVE_DISCOVERY_MAX_FILES) {
|
|
82
|
+
assertGrokBuildNativeEnabled();
|
|
62
83
|
const resolved = resolve(root);
|
|
63
84
|
let workspaces;
|
|
64
85
|
try {
|
|
@@ -125,6 +146,7 @@ export async function grokBuildSourceWorkspaceMatch(locator, workspacePath) {
|
|
|
125
146
|
return matchSessionWorkspace(decoded, workspacePath);
|
|
126
147
|
}
|
|
127
148
|
export async function readGrokBuildNativeChatHistory(source, limits) {
|
|
149
|
+
assertGrokBuildNativeEnabled();
|
|
128
150
|
const sessionId = grokBuildNativeSessionId(source.locator);
|
|
129
151
|
if (source.locatorClass !== GROK_BUILD_NATIVE_LOCATOR_CLASS || !sessionId) {
|
|
130
152
|
throw new SessionContractError('SOURCE_NOT_AUTHORIZED', 'Grok Build native source must be an explicitly authorized chat_history.jsonl path');
|
|
@@ -205,6 +227,7 @@ export function toGrokBuildNativeRecord(sessionId, entry) {
|
|
|
205
227
|
}
|
|
206
228
|
/** Read and validate active_sessions.json (read-only, bounded); throws on misuse. */
|
|
207
229
|
export async function readGrokBuildActiveRegistry(selectedPath, allowedRoots) {
|
|
230
|
+
assertGrokBuildNativeEnabled();
|
|
208
231
|
const authorized = await authorizeSourceFile({
|
|
209
232
|
selectedPath, allowedRoots, maxBytes: ACTIVE_SESSIONS_MAX_BYTES,
|
|
210
233
|
});
|
|
@@ -1,19 +1,19 @@
|
|
|
1
1
|
import { basename, extname } from 'node:path';
|
|
2
2
|
import { SessionContractError, schemaIssueDetail, } from '../contracts.js';
|
|
3
3
|
import { readBoundedText } from '../readers.js';
|
|
4
|
-
import { discoverGrokBuildNativeChatHistories, GROK_BUILD_NATIVE_DISCOVERY_MAX_FILES, GROK_BUILD_NATIVE_LOCATOR_CLASS, GROK_BUILD_NATIVE_SCHEMA_VERSION, grokBuildNativeSessionId, parseGrokBuildNativeCursor, readGrokBuildNativeChatHistory, toGrokBuildNativeRecord, } from './grok-build-native.js';
|
|
4
|
+
import { assertGrokBuildNativeEnabled, discoverGrokBuildNativeChatHistories, GROK_BUILD_NATIVE_DISCOVERY_MAX_FILES, GROK_BUILD_NATIVE_LOCATOR_CLASS, GROK_BUILD_NATIVE_SCHEMA_VERSION, grokBuildNativeSessionId, grokBuildNativeEnabled, parseGrokBuildNativeCursor, readGrokBuildNativeChatHistory, toGrokBuildNativeRecord, } from './grok-build-native.js';
|
|
5
5
|
export const GROK_BUILD_ADAPTER_VERSION = '1.0.0';
|
|
6
6
|
export const GROK_BUILD_CLI_EXPORT_SCHEMA_VERSION = '1.0.0';
|
|
7
7
|
export const GROK_BUILD_CLI_EXPORT_LOCATOR_CLASS = 'grok-build-cli-markdown-export';
|
|
8
8
|
/**
|
|
9
9
|
* Imports the documented `grok export <session-id> <file>` surface plus the
|
|
10
|
-
* native `chat_history.jsonl` store
|
|
11
|
-
* sessions root (`--grok-root`).
|
|
10
|
+
* experimental native `chat_history.jsonl` store with an explicit environment
|
|
11
|
+
* opt-in and an explicitly authorized sessions root (`--grok-root`).
|
|
12
12
|
*
|
|
13
13
|
* The public export contract is intentionally lossy. Native reads use the
|
|
14
14
|
* synthetic v1 schema in grok-build-native.ts (real stores were never
|
|
15
|
-
* inspected); anything outside it fails closed.
|
|
16
|
-
* `grok export`
|
|
15
|
+
* inspected); anything outside it fails closed. This adapter never invokes
|
|
16
|
+
* `grok export` automatically: CLI export remains operator-selected.
|
|
17
17
|
*/
|
|
18
18
|
export class GrokBuildSessionAdapter {
|
|
19
19
|
limits;
|
|
@@ -21,13 +21,18 @@ export class GrokBuildSessionAdapter {
|
|
|
21
21
|
provider = 'grok-build';
|
|
22
22
|
adapterVersion = GROK_BUILD_ADAPTER_VERSION;
|
|
23
23
|
disposition = 'implemented';
|
|
24
|
-
supportedOperations
|
|
25
|
-
|
|
24
|
+
get supportedOperations() {
|
|
25
|
+
return grokBuildNativeEnabled() ? ['discover', 'inspect', 'stream'] : ['inspect', 'stream'];
|
|
26
|
+
}
|
|
27
|
+
get acquisitionModes() {
|
|
28
|
+
return grokBuildNativeEnabled() ? ['manual-export', 'jsonl'] : ['manual-export'];
|
|
29
|
+
}
|
|
26
30
|
constructor(limits, maxFiles = GROK_BUILD_NATIVE_DISCOVERY_MAX_FILES) {
|
|
27
31
|
this.limits = limits;
|
|
28
32
|
this.maxFiles = maxFiles;
|
|
29
33
|
}
|
|
30
34
|
async *discover(scope) {
|
|
35
|
+
assertGrokBuildNativeEnabled();
|
|
31
36
|
if (scope.allowedRoots.length === 0) {
|
|
32
37
|
throw new SessionContractError('SOURCE_NOT_AUTHORIZED', 'Grok Build native discovery requires an explicitly authorized sessions root; pass --grok-root.');
|
|
33
38
|
}
|
|
@@ -53,6 +58,8 @@ export class GrokBuildSessionAdapter {
|
|
|
53
58
|
}
|
|
54
59
|
async *stream(source, cursor) {
|
|
55
60
|
if (source.locatorClass === GROK_BUILD_NATIVE_LOCATOR_CLASS) {
|
|
61
|
+
// The experimental gate answers first, so a disabled gate never reports a locator error.
|
|
62
|
+
assertGrokBuildNativeEnabled();
|
|
56
63
|
const sessionId = grokBuildNativeSessionId(source.locator);
|
|
57
64
|
if (!sessionId) {
|
|
58
65
|
throw new SessionContractError('SOURCE_NOT_AUTHORIZED', 'Grok Build native source must be an explicitly authorized chat_history.jsonl path');
|