@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,228 @@
|
|
|
1
|
+
// Own trusted approval-store I/O, locking, pruning, and explicit approval management.
|
|
2
|
+
import { constants } from 'node:fs';
|
|
3
|
+
import { open, realpath, lstat, stat, mkdir, rename, writeFile, unlink } from 'node:fs/promises';
|
|
4
|
+
import path from 'node:path';
|
|
5
|
+
import { homedir } from 'node:os';
|
|
6
|
+
import { createHash } from 'node:crypto';
|
|
7
|
+
const installedModuleMaxBytes = 5 * 1024 * 1024;
|
|
8
|
+
|
|
9
|
+
// Resolve existing ancestors too: a not-yet-created output can traverse a symlink.
|
|
10
|
+
export async function canonicalFuturePath(filename) {
|
|
11
|
+
try { return await realpath(filename); }
|
|
12
|
+
catch (error) {
|
|
13
|
+
if (error.code !== 'ENOENT') throw error;
|
|
14
|
+
// A dangling link is not a new output: following it may leave the scope.
|
|
15
|
+
try { if ((await lstat(filename)).isSymbolicLink()) throw new Error('Dangling worker path'); }
|
|
16
|
+
catch (statError) { if (statError.code !== 'ENOENT') throw statError; }
|
|
17
|
+
const parent = path.dirname(filename);
|
|
18
|
+
if (parent === filename) throw error;
|
|
19
|
+
return path.join(await canonicalFuturePath(parent), path.basename(filename));
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
export function inside(root, target) {
|
|
24
|
+
const relative = path.relative(root, target);
|
|
25
|
+
return relative === '' || (!relative.startsWith(`..${path.sep}`) && relative !== '..' && !path.isAbsolute(relative));
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
export async function readInstalledFile(filename) {
|
|
29
|
+
const file = await open(filename, 'r');
|
|
30
|
+
try {
|
|
31
|
+
const stat = await file.stat();
|
|
32
|
+
if (!stat.isFile()) throw new Error('Installed module inputs must be regular files');
|
|
33
|
+
if (stat.size > installedModuleMaxBytes) throw new Error('Installed module input exceeds maxBytes (5 MiB)');
|
|
34
|
+
// Bound the actual read too: an fstat size check alone allows concurrent growth.
|
|
35
|
+
const bytes = Buffer.alloc(installedModuleMaxBytes + 1);
|
|
36
|
+
let length = 0;
|
|
37
|
+
while (length < bytes.length) {
|
|
38
|
+
const { bytesRead } = await file.read(bytes, length, bytes.length - length, null);
|
|
39
|
+
if (!bytesRead) break;
|
|
40
|
+
length += bytesRead;
|
|
41
|
+
}
|
|
42
|
+
if (length > installedModuleMaxBytes) throw new Error('Installed module input exceeds maxBytes (5 MiB)');
|
|
43
|
+
return bytes.subarray(0, length);
|
|
44
|
+
} finally {
|
|
45
|
+
await file.close();
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
export function installationStorePath() {
|
|
50
|
+
const root = process.env.AIWG_CONFIG || path.join(homedir(), '.config/aiwg');
|
|
51
|
+
if (!path.isAbsolute(root)) throw new Error('Installation store must be absolute');
|
|
52
|
+
return path.join(root, 'worker-installations.json');
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
// HOME is the operator's trust boundary; custom stores outside it are checked
|
|
56
|
+
// back to /. O_NOFOLLOW on the store itself does not protect its ancestors.
|
|
57
|
+
export async function assertTrustedStoreAncestors(directory) {
|
|
58
|
+
const home = path.resolve(homedir());
|
|
59
|
+
const boundary = inside(home, directory) ? home : path.parse(directory).root;
|
|
60
|
+
// The store directory itself is checked by the caller.
|
|
61
|
+
if (directory === boundary) return;
|
|
62
|
+
const ancestors = [];
|
|
63
|
+
for (let target = path.dirname(directory); ; target = path.dirname(target)) {
|
|
64
|
+
ancestors.push(target);
|
|
65
|
+
if (target === boundary) break;
|
|
66
|
+
}
|
|
67
|
+
for (const target of ancestors.reverse()) {
|
|
68
|
+
const stat = await lstat(target);
|
|
69
|
+
if (!stat.isDirectory() || stat.isSymbolicLink() || stat.mode & 0o022
|
|
70
|
+
|| process.getuid && stat.uid !== 0 && stat.uid !== process.getuid()) {
|
|
71
|
+
throw new Error(`Untrusted installation store ancestor: ${target}`);
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
export async function assertTrustedStore(filename, writableRoots, repairDirectory = false, apply = false) {
|
|
77
|
+
const changes = [];
|
|
78
|
+
const canonical = await canonicalFuturePath(filename);
|
|
79
|
+
if (canonical !== filename) throw new Error('Symlinked installation store');
|
|
80
|
+
for (const root of writableRoots) {
|
|
81
|
+
if (inside(await realpath(root), canonical)) throw new Error('Worker-writable installation store');
|
|
82
|
+
}
|
|
83
|
+
for (const target of [path.dirname(filename), filename]) {
|
|
84
|
+
try {
|
|
85
|
+
const stat = await lstat(target);
|
|
86
|
+
if (process.getuid && stat.uid !== process.getuid()) throw new Error(`Installation store path is owned by another user: ${target}`);
|
|
87
|
+
if (stat.isSymbolicLink() || stat.isFile() && stat.nlink !== 1
|
|
88
|
+
|| target === path.dirname(filename) && !stat.isDirectory()
|
|
89
|
+
|| target === filename && !stat.isFile()) throw new Error(`Untrusted installation store permissions: ${target}`);
|
|
90
|
+
if (stat.mode & 0o022) {
|
|
91
|
+
if (!repairDirectory || target !== path.dirname(filename) || !process.getuid) {
|
|
92
|
+
throw new Error(`Untrusted installation store permissions: ${target}`);
|
|
93
|
+
}
|
|
94
|
+
await assertTrustedStoreAncestors(target);
|
|
95
|
+
changes.push({ path: target, action: 'chmod go-w' });
|
|
96
|
+
if (apply) {
|
|
97
|
+
const handle = await open(target, constants.O_RDONLY | constants.O_NOFOLLOW | constants.O_DIRECTORY);
|
|
98
|
+
try {
|
|
99
|
+
const current = await handle.stat();
|
|
100
|
+
if (current.uid !== process.getuid() || current.ino !== stat.ino || current.dev !== stat.dev) {
|
|
101
|
+
throw new Error(`Installation store directory changed: ${target}`);
|
|
102
|
+
}
|
|
103
|
+
await handle.chmod(current.mode & ~0o022);
|
|
104
|
+
} finally { await handle.close(); }
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
} catch (error) { if (error.code !== 'ENOENT') throw error; }
|
|
108
|
+
}
|
|
109
|
+
return changes;
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
/** Qualification's confirmed write may secure its own directory; ordinary readers never repair. */
|
|
113
|
+
export async function prepareWorkerInstallationStore({ workerWritableRoots, apply = false }) {
|
|
114
|
+
return assertTrustedStore(installationStorePath(), workerWritableRoots, true, apply);
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
export async function readInstallationStore(filename, expectedDigest) {
|
|
118
|
+
try {
|
|
119
|
+
const bytes = await readInstalledFile(filename);
|
|
120
|
+
const digest = `sha256:${createHash('sha256').update(bytes).digest('hex')}`;
|
|
121
|
+
if (expectedDigest !== undefined && digest !== expectedDigest) throw new Error('Installation store binding changed');
|
|
122
|
+
const stored = JSON.parse(bytes.toString('utf8'));
|
|
123
|
+
if (stored.version !== 1 || !Array.isArray(stored.registrations) || stored.registrations.length > 128) {
|
|
124
|
+
throw new Error('Unsupported installation record');
|
|
125
|
+
}
|
|
126
|
+
return { stored, digest };
|
|
127
|
+
} catch (error) {
|
|
128
|
+
if (error.code === 'ENOENT' && expectedDigest === undefined) return { stored: { version: 1, registrations: [] }, digest: null };
|
|
129
|
+
throw error;
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
// Serialize readers and writers; a stale lock fails closed and is never stolen.
|
|
134
|
+
export async function withWorkerInstallationStore(writableRoots, operation) {
|
|
135
|
+
const filename = installationStorePath();
|
|
136
|
+
await assertTrustedStore(filename, writableRoots);
|
|
137
|
+
await mkdir(path.dirname(filename), { recursive: true, mode: 0o700 });
|
|
138
|
+
const lockPath = `${filename}.lock`;
|
|
139
|
+
let lock;
|
|
140
|
+
for (let attempt = 0; attempt < 100; attempt++) {
|
|
141
|
+
try { lock = await open(lockPath, 'wx', 0o600); break; }
|
|
142
|
+
catch (error) {
|
|
143
|
+
if (error.code !== 'EEXIST' || attempt === 99) throw error;
|
|
144
|
+
await new Promise(resolve => setTimeout(resolve, 20));
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
try {
|
|
148
|
+
await assertTrustedStore(filename, writableRoots);
|
|
149
|
+
const { stored } = await readInstallationStore(filename);
|
|
150
|
+
return await operation({ filename, stored });
|
|
151
|
+
} finally {
|
|
152
|
+
await lock.close();
|
|
153
|
+
await unlink(lockPath);
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
export async function writeWorkerInstallationStore(filename, stored, writableRoots) {
|
|
158
|
+
await assertTrustedStore(filename, writableRoots);
|
|
159
|
+
const temporary = `${filename}.${process.pid}.${createHash('sha256').update(String(Math.random())).digest('hex')}.tmp`;
|
|
160
|
+
try {
|
|
161
|
+
await writeFile(temporary, `${JSON.stringify(stored, null, 2)}\n`, { mode: 0o600, flag: 'wx' });
|
|
162
|
+
await rename(temporary, filename);
|
|
163
|
+
} finally {
|
|
164
|
+
await unlink(temporary).catch(error => { if (error.code !== 'ENOENT') throw error; });
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
async function workspaceIdentity(workspace) {
|
|
169
|
+
if (typeof workspace !== 'string' || !path.isAbsolute(workspace)) return workspace;
|
|
170
|
+
try { return await realpath(workspace); }
|
|
171
|
+
catch (error) {
|
|
172
|
+
if (error.code !== 'ENOENT' && error.code !== 'ENOTDIR') throw error;
|
|
173
|
+
return path.resolve(workspace);
|
|
174
|
+
}
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
async function workspaceDeleted(workspace) {
|
|
178
|
+
if (typeof workspace !== 'string' || !path.isAbsolute(workspace)) return false;
|
|
179
|
+
try { return !(await stat(workspace)).isDirectory(); }
|
|
180
|
+
catch (error) {
|
|
181
|
+
// Permission and I/O failures do not establish that a workspace was deleted.
|
|
182
|
+
return error.code === 'ENOENT' || error.code === 'ENOTDIR';
|
|
183
|
+
}
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
export async function retainWorkerApprovals(registrations, record) {
|
|
187
|
+
const retained = [];
|
|
188
|
+
for (const entry of registrations) {
|
|
189
|
+
if (await workspaceDeleted(entry.installation?.cwd)) continue;
|
|
190
|
+
const workspace = await workspaceIdentity(entry.installation?.cwd).catch(() => entry.installation?.cwd);
|
|
191
|
+
if (entry.cli !== record.cli || workspace !== record.installation.cwd) retained.push(entry);
|
|
192
|
+
}
|
|
193
|
+
if (retained.length >= 128) throw new Error('Worker installation store is full (128 workspace approvals); run aiwg doctor --probe-workers --forget-approval <workspace-path> [--cli <name>] --yes before qualifying another workspace');
|
|
194
|
+
return [...retained, record];
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
/** Offline inventory of recorded authority; never load a driver or validate launch eligibility. */
|
|
198
|
+
export async function listWorkerApprovals({ cwd, cli }) {
|
|
199
|
+
return withWorkerInstallationStore([cwd], async ({ stored }) => {
|
|
200
|
+
const approvals = [];
|
|
201
|
+
for (const entry of stored.registrations) {
|
|
202
|
+
if (cli && entry.cli !== cli) continue;
|
|
203
|
+
approvals.push({ cli: entry.cli, workspace: entry.installation?.cwd ?? null,
|
|
204
|
+
workspaceExists: !(await workspaceDeleted(entry.installation?.cwd)) });
|
|
205
|
+
}
|
|
206
|
+
return approvals;
|
|
207
|
+
});
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
/** Explicit revocation by exact canonical workspace, including workspaces already deleted. */
|
|
211
|
+
export async function forgetWorkerApproval({ cwd, workspace, cli, yes }) {
|
|
212
|
+
if (yes !== true) throw new Error('Forgetting worker approvals requires --yes');
|
|
213
|
+
const target = await workspaceIdentity(path.resolve(cwd, workspace));
|
|
214
|
+
return withWorkerInstallationStore([cwd], async ({ filename, stored }) => {
|
|
215
|
+
const removed = [];
|
|
216
|
+
const retained = [];
|
|
217
|
+
for (const entry of stored.registrations) {
|
|
218
|
+
const identity = await workspaceIdentity(entry.installation?.cwd);
|
|
219
|
+
if (identity === target && (!cli || entry.cli === cli)) {
|
|
220
|
+
removed.push({ cli: entry.cli, workspace: entry.installation.cwd });
|
|
221
|
+
} else retained.push(entry);
|
|
222
|
+
}
|
|
223
|
+
if (!removed.length) throw new Error(`No worker approval found for ${target}${cli ? ` (CLI ${cli})` : ''}`);
|
|
224
|
+
stored.registrations = retained;
|
|
225
|
+
await writeWorkerInstallationStore(filename, stored, [cwd]);
|
|
226
|
+
return removed;
|
|
227
|
+
});
|
|
228
|
+
}
|
|
@@ -1,10 +1,10 @@
|
|
|
1
|
+
import { canonicalFuturePath, inside, readInstalledFile, installationStorePath, assertTrustedStore, readInstallationStore, withWorkerInstallationStore, writeWorkerInstallationStore, retainWorkerApprovals } from './worker-installation-store.mjs';
|
|
2
|
+
export { prepareWorkerInstallationStore } from './worker-installation-store.mjs';
|
|
1
3
|
/** Shared installed-worker qualification owner, also used by the Ralph compatibility facade. */
|
|
2
4
|
import { spawn } from 'node:child_process';
|
|
3
5
|
import { buildInstalledWorkerTransport } from './worker-artifact-binding.mjs';
|
|
4
|
-
import {
|
|
5
|
-
import { open, realpath, lstat, mkdir, rename, writeFile, unlink } from 'node:fs/promises';
|
|
6
|
+
import { open, realpath, lstat } from 'node:fs/promises';
|
|
6
7
|
import path from 'node:path';
|
|
7
|
-
import { homedir } from 'node:os';
|
|
8
8
|
import { pathToFileURL } from 'node:url';
|
|
9
9
|
import { createHash } from 'node:crypto';
|
|
10
10
|
import { parse } from 'acorn';
|
|
@@ -225,7 +225,6 @@ const providerRegistry = new Map();
|
|
|
225
225
|
const installedModules = new Map();
|
|
226
226
|
let installedLoad = Promise.resolve();
|
|
227
227
|
// Same default byte ceiling as workerAdapter.catalogAdapter.maxBytes.
|
|
228
|
-
const installedModuleMaxBytes = 5 * 1024 * 1024;
|
|
229
228
|
|
|
230
229
|
async function binaryIdentity(filename, workerWritableRoots) {
|
|
231
230
|
if (typeof filename !== 'string' || !path.isAbsolute(filename) || filename.includes('\0')) throw new Error('Absolute installed binary required');
|
|
@@ -254,20 +253,6 @@ async function binaryIdentity(filename, workerWritableRoots) {
|
|
|
254
253
|
} finally { await handle.close(); }
|
|
255
254
|
}
|
|
256
255
|
|
|
257
|
-
// Resolve existing ancestors too: a not-yet-created output can traverse a symlink.
|
|
258
|
-
async function canonicalFuturePath(filename) {
|
|
259
|
-
try { return await realpath(filename); }
|
|
260
|
-
catch (error) {
|
|
261
|
-
if (error.code !== 'ENOENT') throw error;
|
|
262
|
-
// A dangling link is not a new output: following it may leave the scope.
|
|
263
|
-
try { if ((await lstat(filename)).isSymbolicLink()) throw new Error('Dangling worker path'); }
|
|
264
|
-
catch (statError) { if (statError.code !== 'ENOENT') throw statError; }
|
|
265
|
-
const parent = path.dirname(filename);
|
|
266
|
-
if (parent === filename) throw error;
|
|
267
|
-
return path.join(await canonicalFuturePath(parent), path.basename(filename));
|
|
268
|
-
}
|
|
269
|
-
}
|
|
270
|
-
|
|
271
256
|
export async function inspectWorkerInstallation(instance, request) {
|
|
272
257
|
const { inspectWorkerInvocationProfile, requiredWorkerControls, isOperatorQualifiedWorkerAdapter } = await import('./provider-policy.js');
|
|
273
258
|
const { qualificationDigest } = await import('./qualification-digest.mjs');
|
|
@@ -504,11 +489,6 @@ function runBoundedVersionProbe(executable, argv, environment, cwd, timeoutMs, m
|
|
|
504
489
|
});
|
|
505
490
|
}
|
|
506
491
|
|
|
507
|
-
function inside(root, target) {
|
|
508
|
-
const relative = path.relative(root, target);
|
|
509
|
-
return relative === '' || (!relative.startsWith(`..${path.sep}`) && relative !== '..' && !path.isAbsolute(relative));
|
|
510
|
-
}
|
|
511
|
-
|
|
512
492
|
// Inspect syntax without executing module bodies (including top-level effects).
|
|
513
493
|
// Only statically declared interfaceVersion and callable register exports qualify.
|
|
514
494
|
function checkInstalledExports(source) {
|
|
@@ -559,27 +539,6 @@ function checkInstalledExports(source) {
|
|
|
559
539
|
inspect(ast);
|
|
560
540
|
}
|
|
561
541
|
|
|
562
|
-
async function readInstalledFile(filename) {
|
|
563
|
-
const file = await open(filename, 'r');
|
|
564
|
-
try {
|
|
565
|
-
const stat = await file.stat();
|
|
566
|
-
if (!stat.isFile()) throw new Error('Installed module inputs must be regular files');
|
|
567
|
-
if (stat.size > installedModuleMaxBytes) throw new Error('Installed module input exceeds maxBytes (5 MiB)');
|
|
568
|
-
// Bound the actual read too: an fstat size check alone allows concurrent growth.
|
|
569
|
-
const bytes = Buffer.alloc(installedModuleMaxBytes + 1);
|
|
570
|
-
let length = 0;
|
|
571
|
-
while (length < bytes.length) {
|
|
572
|
-
const { bytesRead } = await file.read(bytes, length, bytes.length - length, null);
|
|
573
|
-
if (!bytesRead) break;
|
|
574
|
-
length += bytesRead;
|
|
575
|
-
}
|
|
576
|
-
if (length > installedModuleMaxBytes) throw new Error('Installed module input exceeds maxBytes (5 MiB)');
|
|
577
|
-
return bytes.subarray(0, length);
|
|
578
|
-
} finally {
|
|
579
|
-
await file.close();
|
|
580
|
-
}
|
|
581
|
-
}
|
|
582
|
-
|
|
583
542
|
async function inspectInstalledModule(entry, workerWritableRoots, platform) {
|
|
584
543
|
if (!entry || !/^installed:[a-z][a-z0-9-]{0,62}$/.test(entry.reference)
|
|
585
544
|
|| typeof entry.packageName !== 'string' || !entry.packageName
|
|
@@ -757,74 +716,6 @@ export function hasProvider(name) {
|
|
|
757
716
|
|
|
758
717
|
// This host-owned record extends the installation owner. It is not project
|
|
759
718
|
// configuration and never accepts module locations from models.json/aiwg.config.
|
|
760
|
-
function installationStorePath() {
|
|
761
|
-
const root = process.env.AIWG_CONFIG || path.join(homedir(), '.config/aiwg');
|
|
762
|
-
if (!path.isAbsolute(root)) throw new Error('Installation store must be absolute');
|
|
763
|
-
return path.join(root, 'worker-installations.json');
|
|
764
|
-
}
|
|
765
|
-
|
|
766
|
-
// HOME is the operator's trust boundary; custom stores outside it are checked
|
|
767
|
-
// back to /. O_NOFOLLOW on the store itself does not protect its ancestors.
|
|
768
|
-
async function assertTrustedStoreAncestors(directory) {
|
|
769
|
-
const home = path.resolve(homedir());
|
|
770
|
-
const boundary = inside(home, directory) ? home : path.parse(directory).root;
|
|
771
|
-
// The store directory itself is checked by the caller.
|
|
772
|
-
if (directory === boundary) return;
|
|
773
|
-
const ancestors = [];
|
|
774
|
-
for (let target = path.dirname(directory); ; target = path.dirname(target)) {
|
|
775
|
-
ancestors.push(target);
|
|
776
|
-
if (target === boundary) break;
|
|
777
|
-
}
|
|
778
|
-
for (const target of ancestors.reverse()) {
|
|
779
|
-
const stat = await lstat(target);
|
|
780
|
-
if (!stat.isDirectory() || stat.isSymbolicLink() || stat.mode & 0o022
|
|
781
|
-
|| process.getuid && stat.uid !== 0 && stat.uid !== process.getuid()) {
|
|
782
|
-
throw new Error(`Untrusted installation store ancestor: ${target}`);
|
|
783
|
-
}
|
|
784
|
-
}
|
|
785
|
-
}
|
|
786
|
-
|
|
787
|
-
async function assertTrustedStore(filename, writableRoots, repairDirectory = false, apply = false) {
|
|
788
|
-
const changes = [];
|
|
789
|
-
const canonical = await canonicalFuturePath(filename);
|
|
790
|
-
if (canonical !== filename) throw new Error('Symlinked installation store');
|
|
791
|
-
for (const root of writableRoots) {
|
|
792
|
-
if (inside(await realpath(root), canonical)) throw new Error('Worker-writable installation store');
|
|
793
|
-
}
|
|
794
|
-
for (const target of [path.dirname(filename), filename]) {
|
|
795
|
-
try {
|
|
796
|
-
const stat = await lstat(target);
|
|
797
|
-
if (process.getuid && stat.uid !== process.getuid()) throw new Error(`Installation store path is owned by another user: ${target}`);
|
|
798
|
-
if (stat.isSymbolicLink() || stat.isFile() && stat.nlink !== 1
|
|
799
|
-
|| target === path.dirname(filename) && !stat.isDirectory()
|
|
800
|
-
|| target === filename && !stat.isFile()) throw new Error(`Untrusted installation store permissions: ${target}`);
|
|
801
|
-
if (stat.mode & 0o022) {
|
|
802
|
-
if (!repairDirectory || target !== path.dirname(filename) || !process.getuid) {
|
|
803
|
-
throw new Error(`Untrusted installation store permissions: ${target}`);
|
|
804
|
-
}
|
|
805
|
-
await assertTrustedStoreAncestors(target);
|
|
806
|
-
changes.push({ path: target, action: 'chmod go-w' });
|
|
807
|
-
if (apply) {
|
|
808
|
-
const handle = await open(target, constants.O_RDONLY | constants.O_NOFOLLOW | constants.O_DIRECTORY);
|
|
809
|
-
try {
|
|
810
|
-
const current = await handle.stat();
|
|
811
|
-
if (current.uid !== process.getuid() || current.ino !== stat.ino || current.dev !== stat.dev) {
|
|
812
|
-
throw new Error(`Installation store directory changed: ${target}`);
|
|
813
|
-
}
|
|
814
|
-
await handle.chmod(current.mode & ~0o022);
|
|
815
|
-
} finally { await handle.close(); }
|
|
816
|
-
}
|
|
817
|
-
}
|
|
818
|
-
} catch (error) { if (error.code !== 'ENOENT') throw error; }
|
|
819
|
-
}
|
|
820
|
-
return changes;
|
|
821
|
-
}
|
|
822
|
-
|
|
823
|
-
/** Qualification's confirmed write may secure its own directory; ordinary readers never repair. */
|
|
824
|
-
export async function prepareWorkerInstallationStore({ workerWritableRoots, apply = false }) {
|
|
825
|
-
return assertTrustedStore(installationStorePath(), workerWritableRoots, true, apply);
|
|
826
|
-
}
|
|
827
|
-
|
|
828
719
|
// Use the existing delivery ledger's host-selected keyring, never public keys
|
|
829
720
|
// supplied by a registration. PAE separates this authority from effect records.
|
|
830
721
|
const qualificationPayloadType = 'application/vnd.aiwg.worker-installation-qualification+json';
|
|
@@ -859,22 +750,6 @@ async function qualificationSignatureFailure(record, trust) {
|
|
|
859
750
|
return result === 'ok' ? null : result === 'signature-invalid' ? result : `signature-${result}`;
|
|
860
751
|
}
|
|
861
752
|
|
|
862
|
-
async function readInstallationStore(filename, expectedDigest) {
|
|
863
|
-
try {
|
|
864
|
-
const bytes = await readInstalledFile(filename);
|
|
865
|
-
const digest = `sha256:${createHash('sha256').update(bytes).digest('hex')}`;
|
|
866
|
-
if (expectedDigest !== undefined && digest !== expectedDigest) throw new Error('Installation store binding changed');
|
|
867
|
-
const stored = JSON.parse(bytes.toString('utf8'));
|
|
868
|
-
if (stored.version !== 1 || !Array.isArray(stored.registrations) || stored.registrations.length > 128) {
|
|
869
|
-
throw new Error('Unsupported installation record');
|
|
870
|
-
}
|
|
871
|
-
return { stored, digest };
|
|
872
|
-
} catch (error) {
|
|
873
|
-
if (error.code === 'ENOENT' && expectedDigest === undefined) return { stored: { version: 1, registrations: [] }, digest: null };
|
|
874
|
-
throw error;
|
|
875
|
-
}
|
|
876
|
-
}
|
|
877
|
-
|
|
878
753
|
/** Offline projection of recorded approvals only. Never imports drivers, reads auth, or probes CLIs.
|
|
879
754
|
* This is historical evidence, not current launch authority; loadRecordedWorkerInstallations
|
|
880
755
|
* performs binary/version/scope checks when dispatch actually requests a binding.
|
|
@@ -935,21 +810,7 @@ export async function recordWorkerInstallation(instance, options) {
|
|
|
935
810
|
await assertTrustedStore(filename, installation.workerWritableRoots);
|
|
936
811
|
// Canonical workspace identity is an exact approval key, never a prefix.
|
|
937
812
|
installation.cwd = await realpath(installation.cwd);
|
|
938
|
-
|
|
939
|
-
// Serialize read/modify/rename across qualifying CLI processes. A stale lock
|
|
940
|
-
// fails closed; qualification never steals another process's lock.
|
|
941
|
-
const lockPath = `${filename}.lock`;
|
|
942
|
-
let lock;
|
|
943
|
-
for (let attempt = 0; attempt < 100; attempt++) {
|
|
944
|
-
try { lock = await open(lockPath, 'wx', 0o600); break; }
|
|
945
|
-
catch (error) {
|
|
946
|
-
if (error.code !== 'EEXIST' || attempt === 99) throw error;
|
|
947
|
-
await new Promise(resolve => setTimeout(resolve, 20));
|
|
948
|
-
}
|
|
949
|
-
}
|
|
950
|
-
try {
|
|
951
|
-
await assertTrustedStore(filename, installation.workerWritableRoots);
|
|
952
|
-
const { stored } = await readInstallationStore(filename);
|
|
813
|
+
return withWorkerInstallationStore(installation.workerWritableRoots, async ({ stored }) => {
|
|
953
814
|
const environmentNames = Object.keys(installation.environment ?? {});
|
|
954
815
|
delete installation.environment;
|
|
955
816
|
delete installation.adapter;
|
|
@@ -966,26 +827,10 @@ export async function recordWorkerInstallation(instance, options) {
|
|
|
966
827
|
if (checkSignature(keyring, signingKey.keyid, sig, qualificationPayloadType, payload, signedAt) !== 'ok') throw new Error('invalid signature');
|
|
967
828
|
record.signature = { keyid: signingKey.keyid, sig, signedAt, projectDir: signingProjectDir, scope: keyring.scope };
|
|
968
829
|
} catch { return { status: 'DISABLED', reason: keyRecoveryMessage }; }
|
|
969
|
-
|
|
970
|
-
|
|
971
|
-
const workspace = typeof entry.installation?.cwd === 'string'
|
|
972
|
-
? await realpath(entry.installation.cwd).catch(() => entry.installation.cwd) : null;
|
|
973
|
-
if (entry.cli !== cli || workspace !== installation.cwd) retained.push(entry);
|
|
974
|
-
}
|
|
975
|
-
// Bound host authority without silently evicting another workspace approval.
|
|
976
|
-
if (retained.length >= 128) throw new Error('Worker installation store is full (128 workspace approvals); remove an obsolete approval before qualifying another workspace');
|
|
977
|
-
stored.registrations = retained;
|
|
978
|
-
stored.registrations.push(record);
|
|
979
|
-
await mkdir(path.dirname(filename), { recursive: true, mode: 0o700 });
|
|
980
|
-
await assertTrustedStore(filename, installation.workerWritableRoots);
|
|
981
|
-
const temporary = `${filename}.${process.pid}.${createHash('sha256').update(String(Math.random())).digest('hex')}.tmp`;
|
|
982
|
-
await writeFile(temporary, `${JSON.stringify(stored, null, 2)}\n`, { mode: 0o600, flag: 'wx' });
|
|
983
|
-
await rename(temporary, filename);
|
|
830
|
+
stored.registrations = await retainWorkerApprovals(stored.registrations, record);
|
|
831
|
+
await writeWorkerInstallationStore(filename, stored, installation.workerWritableRoots);
|
|
984
832
|
return result;
|
|
985
|
-
}
|
|
986
|
-
await lock.close();
|
|
987
|
-
await unlink(lockPath);
|
|
988
|
-
}
|
|
833
|
+
});
|
|
989
834
|
}
|
|
990
835
|
|
|
991
836
|
/** Read recorded host authority, validate installation bytes and the current CLI
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { hostResourceReport } from '../config/host-resource-report.mjs';
|
|
1
2
|
import { workerReviewLineageDiagnostics } from './worker-review-lineage.js';
|
|
2
3
|
// Resolves eligible worker tuples against current config, catalog and installation snapshots.
|
|
3
4
|
import { isFlagshipModel, flagshipElected, normalizeModelTier } from './tiers.js';
|
|
@@ -41,6 +42,10 @@ export function resolveWorkerPlan(snapshot, request, ceilingDefaults = {}) {
|
|
|
41
42
|
policy: structuredClone(policy), origins: structuredClone(snapshot.models.workerPolicyOrigins),
|
|
42
43
|
choice: null, capacity: 'conductor-guidance-only', ceilings: {},
|
|
43
44
|
};
|
|
45
|
+
if (snapshot.hostResources) {
|
|
46
|
+
plan.resources = hostResourceReport({ config: snapshot.config, live: snapshot.hostResources });
|
|
47
|
+
plan.slots = plan.resources.slots;
|
|
48
|
+
}
|
|
44
49
|
const diagnostic = (code, pointer, message) => ({ code, pointer, message });
|
|
45
50
|
const block = (code, pointer, message) => {
|
|
46
51
|
plan.diagnostics.push(diagnostic(code, pointer, message));
|
|
@@ -269,10 +274,29 @@ export function resolveWorkerPlan(snapshot, request, ceilingDefaults = {}) {
|
|
|
269
274
|
if (authority.requiresConfirmation)
|
|
270
275
|
deny('OG_MODEL_UNAPPROVED', '/request/authority', `${authority.rationale.join('; ')}; agents may pass --authorize-premium only after the human explicitly confirmed the premium escalation (escalation-discipline rule)`);
|
|
271
276
|
const installation = parallelism.clis?.[member.cli];
|
|
272
|
-
const
|
|
273
|
-
|
|
274
|
-
parallelism.
|
|
275
|
-
|
|
277
|
+
const admission = parallelism.admission;
|
|
278
|
+
const capEntries = [
|
|
279
|
+
['max_parallel_subagents', parallelism.max_parallel_subagents], ['group.maxParallel', group.maxParallel],
|
|
280
|
+
['admission.groupCaps', admission?.groupCaps?.[groupId]],
|
|
281
|
+
['admission.memberCaps', admission?.memberCaps?.[`${groupId}/${member.id}`]],
|
|
282
|
+
['admission.cliCaps', admission?.cliCaps?.[member.cli]], ['admission.modelCaps', admission?.modelCaps?.[key]],
|
|
283
|
+
['admission.quotaCaps', installation && admission?.quotaCaps?.[installation.quotaScope]],
|
|
284
|
+
];
|
|
285
|
+
const caps = [...capEntries.map(([, value]) => value), snapshot.constraints?.maxParallel, request.maxParallel]
|
|
286
|
+
.filter((value) => value !== undefined);
|
|
287
|
+
// The shared report owns project/group caps; the remaining entries scope the tuple.
|
|
288
|
+
const resources = snapshot.hostResources && hostResourceReport({ config: snapshot.config, live: snapshot.hostResources, group: groupId,
|
|
289
|
+
caps: [...capEntries.slice(3).map(([threshold, limit]) => ({ threshold, limit })),
|
|
290
|
+
{ threshold: 'constraints.maxParallel', limit: snapshot.constraints?.maxParallel, running: 0 },
|
|
291
|
+
{ threshold: 'request.maxParallel', limit: request.maxParallel, running: 0 }] });
|
|
292
|
+
if (resources) {
|
|
293
|
+
if (!plan.eligible.length) {
|
|
294
|
+
plan.resources = resources;
|
|
295
|
+
plan.slots = resources.slots;
|
|
296
|
+
}
|
|
297
|
+
if (!resources.ok)
|
|
298
|
+
deny('OG_ADAPTER_UNQUALIFIED', '/parallelism/admission/hostResources', resources.failures.map(failure => `${failure.signal}: ${failure.reason}`).join('; '));
|
|
299
|
+
}
|
|
276
300
|
const effectiveMaxParallel = caps.length ? Math.min(...caps) : null;
|
|
277
301
|
if (effectiveMaxParallel === 0)
|
|
278
302
|
deny('OG_ADAPTER_UNQUALIFIED', '/constraints/maxParallel', 'Current capacity ceiling is zero');
|
|
@@ -282,7 +306,7 @@ export function resolveWorkerPlan(snapshot, request, ceilingDefaults = {}) {
|
|
|
282
306
|
profile: binding.profile, transport,
|
|
283
307
|
permissions: structuredClone(permissions), context: workerContextHeadroom(request.context, observation),
|
|
284
308
|
observedAt: observation.observedAt, verifiedAt: observation.verifiedAt, observationRef: observation.recordId,
|
|
285
|
-
effectiveMaxParallel, diagnostics: reasons });
|
|
309
|
+
effectiveMaxParallel, ...(resources ? { resources } : {}), diagnostics: reasons });
|
|
286
310
|
}
|
|
287
311
|
if (reasons.some(reason => reason.blocking !== false))
|
|
288
312
|
plan.exclusions.push({ ...tuple, diagnostics: reasons });
|
|
@@ -301,12 +325,19 @@ export function resolveWorkerPlan(snapshot, request, ceilingDefaults = {}) {
|
|
|
301
325
|
if (plan.diagnostics.length)
|
|
302
326
|
plan.selected = null;
|
|
303
327
|
if (plan.selected) {
|
|
328
|
+
if (plan.selected.resources) {
|
|
329
|
+
plan.resources = plan.selected.resources;
|
|
330
|
+
plan.slots = plan.resources.slots;
|
|
331
|
+
}
|
|
304
332
|
plan.policy = groupPolicies.get(plan.selected.group);
|
|
305
333
|
plan.status = 'eligible';
|
|
306
334
|
plan.diagnostics.push(...plan.selected.diagnostics.filter(item => item.code === 'OG_SANDBOX_EXTERNAL'));
|
|
307
335
|
plan.choice = { source: request.choice ? 'conductor' : 'default', rationale: request.choice?.rationale ?? 'Role group order, member priority/declaration order, then qualified effort ladder',
|
|
308
336
|
...(request.substitution && matchesChoice(plan.selected, request.substitution) ? { substitution: structuredClone(request.substitution) } : {}) };
|
|
309
337
|
}
|
|
338
|
+
if (!plan.selected && plan.resources?.slots === 0) {
|
|
339
|
+
block('OG_ADAPTER_UNQUALIFIED', '/parallelism/admission/hostResources', plan.resources.failures.map(failure => `${failure.signal}: ${failure.reason}`).join('; '));
|
|
340
|
+
}
|
|
310
341
|
plan.alternatives = plan.eligible.filter(tuple => tuple !== plan.selected);
|
|
311
342
|
return plan;
|
|
312
343
|
}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { promises as fs } from 'node:fs';
|
|
2
2
|
import path from 'node:path';
|
|
3
3
|
import { load as loadYaml } from 'js-yaml';
|
|
4
|
+
import { getStaticTOMLValue, parseTOML } from 'toml-eslint-parser';
|
|
4
5
|
import { MODEL_WRAPPER_DEFINITIONS } from './wrapper-definitions.js';
|
|
5
6
|
import { isFlagshipModel } from './tiers.js';
|
|
6
7
|
const CLAUDE_ALIASES = {
|
|
@@ -30,19 +31,12 @@ async function collectFiles(root) {
|
|
|
30
31
|
return files.sort();
|
|
31
32
|
}
|
|
32
33
|
function tomlFields(content) {
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
try {
|
|
39
|
-
fields[match[1]] = JSON.parse(`"${match[2]}"`);
|
|
40
|
-
}
|
|
41
|
-
catch {
|
|
42
|
-
fields[match[1]] = match[2];
|
|
43
|
-
}
|
|
34
|
+
try {
|
|
35
|
+
return getStaticTOMLValue(parseTOML(content));
|
|
36
|
+
}
|
|
37
|
+
catch {
|
|
38
|
+
return null;
|
|
44
39
|
}
|
|
45
|
-
return fields;
|
|
46
40
|
}
|
|
47
41
|
function markdownFields(content) {
|
|
48
42
|
const match = content.match(/^---\r?\n([\s\S]*?)\r?\n---(?:\r?\n|$)/);
|
|
@@ -67,6 +61,25 @@ function artifactFields(file, content) {
|
|
|
67
61
|
return markdownFields(content);
|
|
68
62
|
return null;
|
|
69
63
|
}
|
|
64
|
+
/** Read the same deployed artifacts used by verification, without repairing them. */
|
|
65
|
+
export async function readModelWrapperArtifacts(agentsPath) {
|
|
66
|
+
const artifacts = [];
|
|
67
|
+
if (!agentsPath)
|
|
68
|
+
return artifacts;
|
|
69
|
+
for (const file of await collectFiles(agentsPath)) {
|
|
70
|
+
const name = path.basename(file).replace(/(?:\.agent)?\.(?:md|toml|json|yaml|yml)$/i, '');
|
|
71
|
+
const wrapper = MODEL_WRAPPER_DEFINITIONS.find(item => item.name === name);
|
|
72
|
+
if (!wrapper)
|
|
73
|
+
continue;
|
|
74
|
+
let fields = null;
|
|
75
|
+
try {
|
|
76
|
+
fields = artifactFields(file, await fs.readFile(file, 'utf8'));
|
|
77
|
+
}
|
|
78
|
+
catch { /* unresolved metadata */ }
|
|
79
|
+
artifacts.push({ wrapper, file, fields });
|
|
80
|
+
}
|
|
81
|
+
return artifacts;
|
|
82
|
+
}
|
|
70
83
|
function fieldValue(fields, ...names) {
|
|
71
84
|
for (const name of names) {
|
|
72
85
|
const value = fields[name];
|