@aiwg/cli 2026.10.4 → 2026.10.6
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/composition-engine/lib/runtime.mjs +1401 -0
- package/agentic/code/addons/composition-engine/lib/validator.mjs +513 -0
- package/agentic/code/addons/composition-engine/schemas/flow-graph.schema.json +372 -0
- package/agentic/code/providers/model-capabilities.v1.json +74 -50
- package/bin/aiwg.mjs +3 -1
- package/dist/src/artifacts/browser-export.js +1 -0
- package/dist/src/artifacts/citation-parser.js +8 -1
- package/dist/src/artifacts/cli.js +72 -9
- package/dist/src/artifacts/fortemi-core-query-adapter.js +2 -0
- package/dist/src/artifacts/fortemi-core-sync.js +26 -8
- package/dist/src/artifacts/graph-query.js +18 -8
- package/dist/src/artifacts/index-adapters.js +339 -0
- package/dist/src/artifacts/index-builder.js +146 -16
- package/dist/src/artifacts/index-files.js +15 -4
- package/dist/src/artifacts/index-preparation.js +91 -26
- package/dist/src/artifacts/index-reader.js +44 -0
- package/dist/src/artifacts/index-refresh.js +130 -56
- package/dist/src/artifacts/index-status.js +20 -5
- package/dist/src/artifacts/index-worker.mjs +9 -7
- package/dist/src/artifacts/memory-maintenance.js +503 -0
- package/dist/src/artifacts/prebuilt-relations.js +3 -1
- package/dist/src/artifacts/query-engine.js +263 -108
- package/dist/src/artifacts/relations-builder.js +2 -2
- package/dist/src/artifacts/source-graph.js +2 -2
- package/dist/src/artifacts/types.js +9 -1
- package/dist/src/cli/handlers/decision.js +19 -1
- package/dist/src/cli/handlers/guided-setup.js +470 -0
- package/dist/src/cli/handlers/help.js +2 -2
- package/dist/src/cli/handlers/housekeeper.js +1110 -0
- package/dist/src/cli/handlers/index.js +4 -2
- package/dist/src/cli/handlers/init.js +41 -6
- package/dist/src/cli/handlers/local-executor.js +5 -3
- package/dist/src/cli/handlers/mc.js +509 -53
- package/dist/src/cli/handlers/models.js +32 -2
- package/dist/src/cli/handlers/ralph-launcher.js +76 -4
- package/dist/src/cli/handlers/rules.js +1 -1
- package/dist/src/cli/handlers/script-runner.js +73 -2
- package/dist/src/cli/handlers/serve.js +5 -3
- package/dist/src/cli/handlers/sessions.js +40 -6
- package/dist/src/cli/handlers/setup.js +428 -1
- package/dist/src/cli/handlers/skill-lint.js +1 -1
- package/dist/src/cli/handlers/subcommands.js +118 -8
- package/dist/src/cli/handlers/use.js +279 -93
- package/dist/src/cli/handlers/workspace.js +3 -1
- package/dist/src/cli/prompt-utils.js +8 -0
- package/dist/src/cli/router.js +16 -1
- package/dist/src/config/aiwg-config.js +42 -0
- package/dist/src/config/cli.js +7 -3
- package/dist/src/config/decision-config.js +14 -1
- package/dist/src/config/native-sandbox-warnings.js +25 -0
- package/dist/src/contributors/validation.js +6 -5
- package/dist/src/decision/admission.js +7 -3
- package/dist/src/decision/benchmark.js +469 -0
- package/dist/src/decision/ledger.js +22 -3
- package/dist/src/decision/pricing.js +147 -0
- package/dist/src/decision/qualification/gate-evidence.js +18 -15
- package/dist/src/decision/qualification/load-staged.js +539 -0
- package/dist/src/decision/qualification/load.js +109 -33
- package/dist/src/decision/qualification/runner.js +5 -2
- package/dist/src/decision/review/service.js +6 -4
- package/dist/src/decision/review/validate.js +23 -2
- package/dist/src/decision/savings.js +8 -3
- package/dist/src/discovery/index.js +492 -0
- package/dist/src/discovery/interview.js +233 -0
- package/dist/src/discovery/plan-apply.js +571 -0
- package/dist/src/discovery/plan-store.js +171 -0
- package/dist/src/discovery/plan-types.js +2 -0
- package/dist/src/discovery/plan-validation.js +139 -0
- package/dist/src/discovery/types.js +2 -0
- package/dist/src/extensions/commands/definitions.js +49 -9
- package/dist/src/extensions/manifest.js +71 -44
- package/dist/src/extensions/project-local-discovery.js +1 -1
- package/dist/src/extensions/project-quickref.js +18 -17
- package/dist/src/extensions/validation.js +32 -29
- package/dist/src/housekeeper/daemon-config.js +148 -0
- package/dist/src/housekeeper/ipc.js +84 -0
- package/dist/src/housekeeper/lifecycle.js +148 -0
- package/dist/src/housekeeper/platform.js +35 -0
- package/dist/src/housekeeper/status.js +70 -0
- package/dist/src/housekeeper/units.js +114 -0
- package/dist/src/jobs/flow.js +22 -21
- package/dist/src/lint/rule-activation.js +20 -5
- package/dist/src/lint/runner.js +1 -1
- package/dist/src/mcp/cli.mjs +5 -6
- package/dist/src/mcp/config-file.mjs +6 -2
- package/dist/src/mcp/config-layers.mjs +23 -7
- package/dist/src/mcp/profiles.js +18 -31
- package/dist/src/mcp/profiles.mjs +18 -32
- package/dist/src/mcp/registry.js +7 -27
- package/dist/src/mcp/registry.mjs +7 -28
- package/dist/src/mcp/server.mjs +34 -1
- package/dist/src/mcp/tools/agentic-sandbox.mjs +8 -7
- package/dist/src/mcp/tools/command-run.mjs +3 -2
- package/dist/src/mcp/tools/decision.mjs +49 -48
- package/dist/src/mcp/tools/discovery.mjs +46 -21
- package/dist/src/mcp/tools/orchestration.mjs +22 -22
- package/dist/src/mcp/tools/subsystems.mjs +9 -8
- package/dist/src/mcp/tools/worker-invoke.mjs +17 -4
- package/dist/src/mcp/tools/writer-profiles.mjs +1 -1
- package/dist/src/memory/audit.js +719 -0
- package/dist/src/memory/canonical-context.js +392 -13
- package/dist/src/memory/canonical-maintenance.js +95 -0
- package/dist/src/memory/cli-result.js +22 -0
- package/dist/src/memory/cli.js +176 -0
- package/dist/src/memory/context-pack.js +57 -6
- package/dist/src/memory/cost.js +512 -0
- package/dist/src/memory/firewall-classification.d.mts +7 -0
- package/dist/src/memory/firewall-classification.mjs +32 -0
- package/dist/src/memory/index.js +8 -0
- package/dist/src/memory/line-maintenance.js +68 -0
- package/dist/src/memory/maintenance-cli.js +286 -0
- package/dist/src/memory/maintenance-contract.js +136 -0
- package/dist/src/memory/maintenance-index.js +18 -0
- package/dist/src/memory/maintenance-owner.js +2 -0
- package/dist/src/memory/maintenance-record.js +138 -0
- package/dist/src/memory/maintenance.js +254 -0
- package/dist/src/memory/provider-memory-adapter.js +154 -0
- package/dist/src/memory/recommend-cli.js +83 -0
- package/dist/src/memory/recommend.js +269 -0
- package/dist/src/memory/scheduled.js +81 -0
- package/dist/src/memory/taxonomy.js +44 -0
- package/dist/src/mission-protocol/codecs.js +19 -9
- package/dist/src/models/config-loader.js +11 -1
- package/dist/src/models/model-capabilities.v1.json +74 -50
- package/dist/src/models/provider-policy.js +125 -62
- package/dist/src/models/resolver.js +45 -8
- package/dist/src/models/worker-installation.d.mts +7 -0
- package/dist/src/models/worker-installation.mjs +169 -37
- package/dist/src/models/wrapper-route.js +1 -1
- package/dist/src/output-modes/registry.js +8 -7
- package/dist/src/plugin/metadata-validator.js +1 -1
- package/dist/src/providers/deploy-version.d.mts +1 -0
- package/dist/src/providers/deploy-version.mjs +17 -0
- package/dist/src/providers/provider-definitions.js +19 -16
- package/dist/src/providers/skill-ownership.d.mts +11 -2
- package/dist/src/providers/skill-ownership.mjs +35 -17
- package/dist/src/rules/activation.d.mts +11 -2
- package/dist/src/rules/activation.mjs +82 -6
- package/dist/src/rules/inventory.js +1 -1
- package/dist/src/rules/rule-frontmatter.schema.json +2 -0
- package/dist/src/schema/zod-validation.d.mts +6 -0
- package/dist/src/schema/zod-validation.mjs +50 -0
- package/dist/src/serve/executor-registry.js +297 -20
- package/dist/src/serve/executor-token.d.mts +1 -0
- package/dist/src/serve/executor-token.mjs +8 -0
- package/dist/src/serve/shared-host-scheduler.js +1102 -31
- package/dist/src/serve/worker-invocation.js +114 -15
- package/dist/src/sessions/adapters/claude.js +19 -18
- package/dist/src/sessions/adapters/codex.js +33 -19
- package/dist/src/sessions/adapters/copilot.js +14 -13
- package/dist/src/sessions/adapters/cursor.js +19 -18
- package/dist/src/sessions/adapters/deepseek-harness.js +9 -8
- package/dist/src/sessions/adapters/factory.js +11 -10
- package/dist/src/sessions/adapters/generic.js +32 -23
- package/dist/src/sessions/adapters/grokbot.js +35 -35
- package/dist/src/sessions/adapters/hermes.js +20 -19
- package/dist/src/sessions/adapters/muse.js +50 -49
- package/dist/src/sessions/adapters/omp.js +5 -4
- package/dist/src/sessions/adapters/openclaw.js +30 -29
- package/dist/src/sessions/adapters/opencode.js +26 -26
- package/dist/src/sessions/adapters/openhuman.js +24 -23
- package/dist/src/sessions/adapters/pi.js +5 -4
- package/dist/src/sessions/adapters/windsurf.js +8 -8
- package/dist/src/sessions/analytics.js +10 -9
- package/dist/src/sessions/batch-contracts.js +1 -1
- package/dist/src/sessions/batch-import.js +202 -2
- package/dist/src/sessions/candidates.js +7 -6
- package/dist/src/sessions/contracts.js +73 -54
- package/dist/src/sessions/coverage-preflight.js +26 -1
- package/dist/src/sessions/output-registration.js +11 -10
- package/dist/src/sessions/policy.js +18 -7
- package/dist/src/sessions/refresh.js +2 -3
- package/dist/src/sessions/repository.js +4 -2
- package/dist/src/sessions/workspace-discovery.js +92 -26
- package/dist/src/smiths/context-pipeline/aiwg-md.js +18 -1
- package/dist/src/smiths/context-pipeline/claude-hook.js +42 -6
- package/dist/src/smiths/context-pipeline/parallelism-section.js +72 -5
- package/dist/src/smiths/context-pipeline/workspace-context.js +106 -10
- package/dist/src/update/checker.d.mts +4 -0
- package/dist/src/update/checker.mjs +14 -0
- package/dist/src/writing/exemplar-selection.js +6 -6
- package/dist/src/writing/voice-evaluation.js +24 -23
- package/dist/src/writing/writer-migration.js +14 -13
- package/dist/src/writing/writer-profile.js +19 -18
- package/dist/src/writing/writing-brief.js +18 -17
- package/dist/src/writing/writing-receipt.js +47 -46
- package/package.json +5 -2
- package/schemas/decision/DecisionReview.schema.json +78 -1
- package/schemas/mission-v1.schema.json +3 -0
- package/tools/agents/deploy-agents.mjs +67 -39
- package/tools/agents/providers/antigravity.mjs +6 -1
- package/tools/agents/providers/base.mjs +19 -13
- package/tools/agents/providers/claude.mjs +1 -1
- package/tools/agents/providers/codex.mjs +50 -56
- package/tools/agents/providers/copilot.mjs +8 -2
- package/tools/agents/providers/cursor.mjs +1 -1
- package/tools/agents/providers/deepseek-harness.mjs +1 -1
- package/tools/agents/providers/factory.mjs +7 -1
- package/tools/agents/providers/grok-build.mjs +18 -2
- package/tools/agents/providers/grokbot.mjs +1 -1
- package/tools/agents/providers/hermes.mjs +7 -13
- package/tools/agents/providers/muse-hooks.mjs +21 -14
- package/tools/agents/providers/muse.mjs +7 -2
- package/tools/agents/providers/omp.mjs +28 -4
- package/tools/agents/providers/opencode.mjs +14 -5
- package/tools/agents/providers/openhuman.mjs +1 -1
- package/tools/agents/providers/pi.mjs +1 -1
- package/tools/agents/providers/provider-prepare-coordinator.mjs +29 -9
- package/tools/agents/providers/rule-delivery.mjs +263 -71
- package/tools/agents/providers/windsurf.mjs +7 -0
- package/tools/cli/workspace-status.mjs +5 -0
- package/tools/commands/deploy-prompts-codex.mjs +11 -8
- package/tools/ralph-external/lib/codex-adapter.mjs +6 -2
- package/tools/ralph-external/lib/muse-adapter.mjs +12 -2
- package/tools/ralph-external/lib/worker-health.mjs +1 -1
- package/tools/ralph-external/lib/worker-isolation.mjs +65 -9
- package/tools/ralph-external/process-monitor.mjs +7 -4
- package/tools/ralph-external/session-launcher.mjs +280 -32
- package/tools/skills/deploy-skills-codex.mjs +11 -7
- package/vscode-extension/schemas/aiwg.config.v1.json +11 -1
package/dist/src/memory/cli.js
CHANGED
|
@@ -10,7 +10,52 @@
|
|
|
10
10
|
* @issue #966
|
|
11
11
|
*/
|
|
12
12
|
import { runSubsystemCli } from '../storage/subsystem-cli.js';
|
|
13
|
+
import { memoryUsage, memoryInput, MEMORY_EXIT_USAGE } from './cli-result.js';
|
|
14
|
+
import { listProviderMemoryAdapters } from './provider-memory-adapter.js';
|
|
13
15
|
export async function main(args) {
|
|
16
|
+
if (args[0] === 'recommend') {
|
|
17
|
+
const { runMemoryRecommendCli } = await import('./recommend-cli.js');
|
|
18
|
+
return runMemoryRecommendCli(args.slice(1));
|
|
19
|
+
}
|
|
20
|
+
if (['plan', 'apply', 'verify', 'restore'].includes(args[0])) {
|
|
21
|
+
const { runMemoryMaintenanceCli } = await import('./maintenance-cli.js');
|
|
22
|
+
return runMemoryMaintenanceCli(args[0], args.slice(1));
|
|
23
|
+
}
|
|
24
|
+
if (args[0] === 'audit') {
|
|
25
|
+
const { auditMemory, formatMemoryAudit } = await import('./audit.js');
|
|
26
|
+
const opts = memoryUsage(() => parseMemoryAuditOptions(args.slice(1)));
|
|
27
|
+
if (opts.help) {
|
|
28
|
+
console.log(MEMORY_AUDIT_USAGE);
|
|
29
|
+
return;
|
|
30
|
+
}
|
|
31
|
+
const report = await auditMemory(opts);
|
|
32
|
+
if (opts.cost) {
|
|
33
|
+
const { costMemory, formatMemoryCost } = await import('./cost.js');
|
|
34
|
+
const cost = costMemory(report);
|
|
35
|
+
console.log(opts.json ? JSON.stringify(cost, null, 2) : formatMemoryCost(cost));
|
|
36
|
+
return report.findings.length ? 1 : 0;
|
|
37
|
+
}
|
|
38
|
+
console.log(opts.json ? JSON.stringify(report, null, 2) : formatMemoryAudit(report));
|
|
39
|
+
return report.findings.length ? 1 : 0;
|
|
40
|
+
}
|
|
41
|
+
if (args[0] === 'cost') {
|
|
42
|
+
const { auditMemory } = await import('./audit.js');
|
|
43
|
+
const { costMemory, formatMemoryCost } = await import('./cost.js');
|
|
44
|
+
const opts = memoryUsage(() => parseMemoryCostOptions(args.slice(1)));
|
|
45
|
+
if (opts.help) {
|
|
46
|
+
console.log(MEMORY_COST_USAGE);
|
|
47
|
+
return;
|
|
48
|
+
}
|
|
49
|
+
const report = await auditMemory(opts);
|
|
50
|
+
const cost = costMemory(report, await memoryInput(() => resolveMemoryCostInputs(opts)));
|
|
51
|
+
console.log(opts.json ? JSON.stringify(cost, null, 2) : formatMemoryCost(cost));
|
|
52
|
+
return report.findings.length ? 1 : 0;
|
|
53
|
+
}
|
|
54
|
+
if (args.length === 0 || args[0] === '--help' || args[0] === '-h') {
|
|
55
|
+
console.log(MEMORY_AUDIT_USAGE);
|
|
56
|
+
if (args.length)
|
|
57
|
+
return;
|
|
58
|
+
}
|
|
14
59
|
if (args[0] === 'project') {
|
|
15
60
|
await runProjectMemoryCli(args.slice(1));
|
|
16
61
|
return;
|
|
@@ -163,4 +208,135 @@ Subcommands:
|
|
|
163
208
|
The manifest lives at ~/.aiwg/projects/manifest.json and each registered
|
|
164
209
|
project memory root uses a private .aiwg layout under ~/.aiwg/projects/<id>/.aiwg.`);
|
|
165
210
|
}
|
|
211
|
+
export const MEMORY_AUDIT_USAGE = `Usage: aiwg memory audit [--scope global|project|provider] [--provider <id>] [--json] [--cost]
|
|
212
|
+
aiwg memory cost [--scope global|project|provider] [--provider <id>] [--json] [--demote <id|path> ...] [--startup-measurement <file>] [--usage <file>]
|
|
213
|
+
|
|
214
|
+
Read-only static memory and instruction inventory. Defaults to this workspace;
|
|
215
|
+
global roots require --scope global. --scope provider requires --provider <id>.
|
|
216
|
+
Reports include exposure chains, unavailable/opaque surfaces and scan bounds.
|
|
217
|
+
Static eligibility does not establish live context loading. JSON: aiwg.memory-audit.v1.
|
|
218
|
+
--cost renders the same inventory through the resident-cost view (JSON: aiwg.memory-cost.v1).
|
|
219
|
+
The cost subcommand adds --demote previews, a #2936 startup-measurement report
|
|
220
|
+
and caller-supplied usage evidence; all views are read-only and write nothing.
|
|
221
|
+
Read-only recommendations: recommend (use --help for evidence and review export).
|
|
222
|
+
Reviewed lifecycle: plan, apply, verify, restore (use --help for exact-plan options).
|
|
223
|
+
Other memory subcommands: path, list, get, put, delete, append-log, project.
|
|
224
|
+
${MEMORY_EXIT_USAGE}`;
|
|
225
|
+
export const MEMORY_COST_USAGE = `Usage: aiwg memory cost [--scope global|project|provider] [--provider <id>] [--json] [--demote <id|path> ...] [--startup-measurement <file>] [--usage <file>]
|
|
226
|
+
|
|
227
|
+
Read-only resident context cost and memory utility over the static audit inventory.
|
|
228
|
+
Token estimates reuse the existing UTF-8 bytes estimators (#2936 startup measure,
|
|
229
|
+
#2938 inline-budget guard); no new tokenizer. Anything not measurable locally
|
|
230
|
+
stays unknown, never guessed. --demote previews before/after cost with the
|
|
231
|
+
retrieval anchors required to keep demoted content reachable. --usage reads a
|
|
232
|
+
JSON object of { "<item-id>": { retrieved, used, rejected, evidence } } held in
|
|
233
|
+
memory only. JSON: aiwg.memory-cost.v1. Writes nothing.
|
|
234
|
+
${MEMORY_EXIT_USAGE}`;
|
|
235
|
+
export function parseMemoryAuditOptions(args) {
|
|
236
|
+
const opts = {};
|
|
237
|
+
const seen = new Set();
|
|
238
|
+
for (let index = 0; index < args.length; index++) {
|
|
239
|
+
const [flag, inline, ...extra] = args[index].split('=');
|
|
240
|
+
if (!['--scope', '--provider', '--json', '--cost', '--help', '-h'].includes(flag) || extra.length)
|
|
241
|
+
throw new Error(`Unknown memory audit argument: ${args[index]}`);
|
|
242
|
+
if (seen.has(flag))
|
|
243
|
+
throw new Error(`Duplicate memory audit option: ${flag}`);
|
|
244
|
+
seen.add(flag);
|
|
245
|
+
if (flag === '--json' || flag === '--cost' || flag === '--help' || flag === '-h') {
|
|
246
|
+
if (inline !== undefined)
|
|
247
|
+
throw new Error(`${flag} takes no value`);
|
|
248
|
+
if (flag === '--json')
|
|
249
|
+
opts.json = true;
|
|
250
|
+
else if (flag === '--cost')
|
|
251
|
+
opts.cost = true;
|
|
252
|
+
else
|
|
253
|
+
opts.help = true;
|
|
254
|
+
continue;
|
|
255
|
+
}
|
|
256
|
+
const value = inline ?? args[++index];
|
|
257
|
+
if (!value || value.startsWith('-'))
|
|
258
|
+
throw new Error(`${flag} requires a value`);
|
|
259
|
+
if (flag === '--scope') {
|
|
260
|
+
if (!['global', 'project', 'provider'].includes(value))
|
|
261
|
+
throw new Error('--scope must be global, project or provider');
|
|
262
|
+
opts.scope = value;
|
|
263
|
+
}
|
|
264
|
+
else
|
|
265
|
+
opts.provider = value;
|
|
266
|
+
}
|
|
267
|
+
if (opts.scope === 'provider' && !opts.provider && !opts.help)
|
|
268
|
+
throw new Error('--scope provider requires --provider <id>');
|
|
269
|
+
if (!opts.help && opts.provider && !listProviderMemoryAdapters().some(adapter => adapter.providerId === opts.provider))
|
|
270
|
+
throw new Error(`Unknown memory provider '${opts.provider}'`);
|
|
271
|
+
return opts;
|
|
272
|
+
}
|
|
273
|
+
export function parseMemoryCostOptions(args) {
|
|
274
|
+
const opts = { demote: [] };
|
|
275
|
+
const once = new Set();
|
|
276
|
+
for (let index = 0; index < args.length; index++) {
|
|
277
|
+
const [flag, inline, ...extra] = args[index].split('=');
|
|
278
|
+
if (!['--scope', '--provider', '--json', '--demote', '--startup-measurement', '--usage', '--help', '-h'].includes(flag) || extra.length) {
|
|
279
|
+
throw new Error(`Unknown memory cost argument: ${args[index]}`);
|
|
280
|
+
}
|
|
281
|
+
if (flag !== '--demote') {
|
|
282
|
+
if (once.has(flag))
|
|
283
|
+
throw new Error(`Duplicate memory cost option: ${flag}`);
|
|
284
|
+
once.add(flag);
|
|
285
|
+
}
|
|
286
|
+
if (flag === '--json' || flag === '--help' || flag === '-h') {
|
|
287
|
+
if (inline !== undefined)
|
|
288
|
+
throw new Error(`${flag} takes no value`);
|
|
289
|
+
if (flag === '--json')
|
|
290
|
+
opts.json = true;
|
|
291
|
+
else
|
|
292
|
+
opts.help = true;
|
|
293
|
+
continue;
|
|
294
|
+
}
|
|
295
|
+
const value = inline ?? args[++index];
|
|
296
|
+
if (!value || value.startsWith('-'))
|
|
297
|
+
throw new Error(`${flag} requires a value`);
|
|
298
|
+
if (flag === '--scope') {
|
|
299
|
+
if (!['global', 'project', 'provider'].includes(value))
|
|
300
|
+
throw new Error('--scope must be global, project or provider');
|
|
301
|
+
opts.scope = value;
|
|
302
|
+
}
|
|
303
|
+
else if (flag === '--provider')
|
|
304
|
+
opts.provider = value;
|
|
305
|
+
else if (flag === '--demote')
|
|
306
|
+
opts.demote.push(value);
|
|
307
|
+
else if (flag === '--startup-measurement')
|
|
308
|
+
opts.startupMeasurement = value;
|
|
309
|
+
else
|
|
310
|
+
opts.usage = value;
|
|
311
|
+
}
|
|
312
|
+
if (opts.scope === 'provider' && !opts.provider && !opts.help)
|
|
313
|
+
throw new Error('--scope provider requires --provider <id>');
|
|
314
|
+
if (!opts.help && opts.provider && !listProviderMemoryAdapters().some(adapter => adapter.providerId === opts.provider))
|
|
315
|
+
throw new Error(`Unknown memory provider '${opts.provider}'`);
|
|
316
|
+
return opts;
|
|
317
|
+
}
|
|
318
|
+
/** Read-only input resolution for the cost view. Reads input files; writes nothing. */
|
|
319
|
+
export async function resolveMemoryCostInputs(opts) {
|
|
320
|
+
const fs = await import('node:fs/promises');
|
|
321
|
+
const readJson = async (file, label) => {
|
|
322
|
+
let text;
|
|
323
|
+
try {
|
|
324
|
+
text = await fs.readFile(file, 'utf8');
|
|
325
|
+
}
|
|
326
|
+
catch (error) {
|
|
327
|
+
throw new Error(`${label} could not be read: ${error.message}`);
|
|
328
|
+
}
|
|
329
|
+
try {
|
|
330
|
+
return JSON.parse(text);
|
|
331
|
+
}
|
|
332
|
+
catch {
|
|
333
|
+
throw new Error(`${label} is not valid JSON: ${file}`);
|
|
334
|
+
}
|
|
335
|
+
};
|
|
336
|
+
return {
|
|
337
|
+
usage: opts.usage ? (await readJson(opts.usage, 'Usage evidence')) : undefined,
|
|
338
|
+
startupMeasurement: opts.startupMeasurement ? await readJson(opts.startupMeasurement, 'Startup measurement') : undefined,
|
|
339
|
+
demote: opts.demote.length ? [...opts.demote] : undefined,
|
|
340
|
+
};
|
|
341
|
+
}
|
|
166
342
|
//# sourceMappingURL=cli.js.map
|
|
@@ -1,7 +1,8 @@
|
|
|
1
|
-
import { existsSync, readFileSync, readdirSync, realpathSync, statSync, } from 'node:fs';
|
|
1
|
+
import { closeSync, existsSync, openSync, readSync, readFileSync, readdirSync, realpathSync, statSync, } from 'node:fs';
|
|
2
2
|
import { createHash } from 'node:crypto';
|
|
3
3
|
import { relative, resolve, sep } from 'node:path';
|
|
4
4
|
import { loadFortemiCoreMetadataEntries } from '../artifacts/fortemi-core-query-adapter.js';
|
|
5
|
+
import { load as loadYaml } from 'js-yaml';
|
|
5
6
|
const DEFAULT_BUDGET = {
|
|
6
7
|
totalCharacters: 8000,
|
|
7
8
|
lineCharacters: 2000,
|
|
@@ -12,7 +13,7 @@ const DEFAULT_BUDGET = {
|
|
|
12
13
|
const EXCLUDED_STATES = new Set([
|
|
13
14
|
'contradicted', 'superseded', 'revoked', 'origin-unavailable',
|
|
14
15
|
]);
|
|
15
|
-
function sha256(value) {
|
|
16
|
+
export function sha256(value) {
|
|
16
17
|
return `sha256:${createHash('sha256').update(value).digest('hex')}`;
|
|
17
18
|
}
|
|
18
19
|
function projectLocator(root, target) {
|
|
@@ -63,8 +64,16 @@ function lineCandidates(root, taskTerms) {
|
|
|
63
64
|
const parsed = JSON.parse(readFileSync(metadataPath, 'utf8'));
|
|
64
65
|
entries = parsed.entries ?? {};
|
|
65
66
|
}
|
|
66
|
-
|
|
67
|
-
const
|
|
67
|
+
const activeEntry = (entry) => {
|
|
68
|
+
const maintenance = entry.maintenance;
|
|
69
|
+
return entry.status === 'active' && (!maintenance?.placement || maintenance.placement === 'resident')
|
|
70
|
+
&& (!maintenance?.lifecycle || maintenance.lifecycle === 'active');
|
|
71
|
+
};
|
|
72
|
+
return values.filter(text => {
|
|
73
|
+
const matching = Object.values(entries).filter(entry => entry.value === text);
|
|
74
|
+
return matching.length === 0 || matching.some(activeEntry);
|
|
75
|
+
}).map((text, index) => {
|
|
76
|
+
const entry = Object.values(entries).find(candidate => candidate.value === text && activeEntry(candidate));
|
|
68
77
|
const sources = Array.isArray(entry?.sources) ? entry.sources : [];
|
|
69
78
|
const score = lexicalScore(taskTerms, text);
|
|
70
79
|
return {
|
|
@@ -90,6 +99,44 @@ function markdownText(raw) {
|
|
|
90
99
|
.replace(/\s+/g, ' ')
|
|
91
100
|
.trim();
|
|
92
101
|
}
|
|
102
|
+
const WIKI_HEAD_BYTES = 64 * 1024;
|
|
103
|
+
function readWikiHead(target) {
|
|
104
|
+
const descriptor = openSync(target, 'r');
|
|
105
|
+
try {
|
|
106
|
+
const buffer = Buffer.alloc(WIKI_HEAD_BYTES);
|
|
107
|
+
const length = readSync(descriptor, buffer, 0, buffer.length, 0);
|
|
108
|
+
return buffer.toString('utf8', 0, length);
|
|
109
|
+
}
|
|
110
|
+
finally {
|
|
111
|
+
closeSync(descriptor);
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
/** Canonical dispositions override a stale local or remote index snapshot. */
|
|
115
|
+
function ordinaryWikiSource(raw, locator, indexed) {
|
|
116
|
+
if (indexed && (indexed.lifecycle !== 'active' || indexed.placement === 'archived'))
|
|
117
|
+
return false;
|
|
118
|
+
const frontmatter = raw.match(/^---\r?\n([\s\S]*?)\r?\n---(?:\r?\n|$)/);
|
|
119
|
+
if (!frontmatter) {
|
|
120
|
+
if (/^---\r?\n/.test(raw) && Buffer.byteLength(raw) >= WIKI_HEAD_BYTES) {
|
|
121
|
+
console.warn(`context-pack: ${locator}: frontmatter exceeds the 64 KiB scan limit; disposition cannot be verified`);
|
|
122
|
+
return false;
|
|
123
|
+
}
|
|
124
|
+
if (/^---\r?\n/.test(raw)) {
|
|
125
|
+
console.warn(`context-pack: ${locator}: malformed frontmatter without a closing delimiter; including page`);
|
|
126
|
+
return true;
|
|
127
|
+
}
|
|
128
|
+
return !indexed;
|
|
129
|
+
}
|
|
130
|
+
try {
|
|
131
|
+
const data = loadYaml(frontmatter[1]);
|
|
132
|
+
const record = data?.memoryRecord;
|
|
133
|
+
return record ? record.lifecycle === 'active' && record.placement !== 'archived' : !indexed;
|
|
134
|
+
}
|
|
135
|
+
catch (error) {
|
|
136
|
+
console.warn(`context-pack: ${locator}: malformed frontmatter; including page (${error instanceof Error ? error.message : String(error)})`);
|
|
137
|
+
return true;
|
|
138
|
+
}
|
|
139
|
+
}
|
|
93
140
|
function wikiCandidates(root, taskTerms, maxFiles) {
|
|
94
141
|
const wikiRoot = resolve(root, '.aiwg/wiki');
|
|
95
142
|
if (!existsSync(wikiRoot))
|
|
@@ -115,7 +162,9 @@ function wikiCandidates(root, taskTerms, maxFiles) {
|
|
|
115
162
|
continue;
|
|
116
163
|
visited += 1;
|
|
117
164
|
const locator = projectLocator(root, target);
|
|
118
|
-
const raw =
|
|
165
|
+
const raw = readWikiHead(target);
|
|
166
|
+
if (!ordinaryWikiSource(raw, locator))
|
|
167
|
+
continue;
|
|
119
168
|
const text = markdownText(raw).slice(0, 1200);
|
|
120
169
|
const score = lexicalScore(taskTerms, text);
|
|
121
170
|
if (score <= 0)
|
|
@@ -149,7 +198,9 @@ function fortemiWikiCandidates(root, taskTerms, maxFiles) {
|
|
|
149
198
|
if (!existsSync(target))
|
|
150
199
|
continue;
|
|
151
200
|
const locator = projectLocator(root, target);
|
|
152
|
-
const raw =
|
|
201
|
+
const raw = readWikiHead(target);
|
|
202
|
+
if (!ordinaryWikiSource(raw, locator, entry.memoryRecord))
|
|
203
|
+
continue;
|
|
153
204
|
const text = markdownText(raw).slice(0, 1200);
|
|
154
205
|
const score = lexicalScore(taskTerms, [entry.title, entry.summary, text].join(' '));
|
|
155
206
|
if (score <= 0)
|