@aiwg/cli 2026.11.4 → 2026.11.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/providers/capability-matrix.yaml +75 -5
- package/agentic/code/providers/model-capabilities.v1.json +44 -36
- package/bin/aiwg.mjs +6 -4
- package/dist/src/activity-log/cli.js +1 -1
- package/dist/src/agents/agent-deployer.js +1 -1
- package/dist/src/artifacts/audit/types.js +1 -1
- package/dist/src/artifacts/discover-facets.js +1 -1
- package/dist/src/artifacts/enrichment/prompt.js +1 -1
- package/dist/src/artifacts/enrichment/types.js +1 -1
- package/dist/src/artifacts/index-builder.js +4 -2
- package/dist/src/artifacts/query-engine-rules.js +2 -2
- package/dist/src/artifacts/types.js +1 -1
- package/dist/src/artifacts/views/definition.js +1 -1
- package/dist/src/artifacts/views/types.js +1 -1
- package/dist/src/catalog/cli.js +1 -1
- package/dist/src/catalog/cli.mjs +1 -1
- package/dist/src/catalog/loader.js +1 -1
- package/dist/src/catalog/loader.mjs +1 -1
- package/dist/src/catalog/types.js +1 -1
- package/dist/src/cli/cli-extension-loader.js +19 -5
- package/dist/src/cli/cli-extension-paths.js +65 -0
- package/dist/src/cli/handlers/best-practices-audit.js +1 -1
- package/dist/src/cli/handlers/help.js +3 -4
- package/dist/src/cli/handlers/index.js +1 -1
- package/dist/src/cli/handlers/marketplace-plugin-search.js +37 -0
- package/dist/src/cli/handlers/marketplace.js +3 -1
- package/dist/src/cli/handlers/models.js +1 -1
- package/dist/src/cli/handlers/ralph-launcher.js +8 -2
- package/dist/src/cli/handlers/ralph.js +1 -1
- package/dist/src/cli/handlers/runtime-info.js +1 -1
- package/dist/src/cli/handlers/scaffolding.js +2 -2
- package/dist/src/cli/handlers/script-runner.js +8 -5
- package/dist/src/cli/handlers/sdlc-accelerate.js +1 -1
- package/dist/src/cli/handlers/steward-format.js +12 -0
- package/dist/src/cli/handlers/subcommands-bundles.js +1 -1
- package/dist/src/cli/handlers/subcommands-list-format.js +19 -1
- package/dist/src/cli/handlers/types.js +1 -1
- package/dist/src/cli/handlers/use.js +15 -6
- package/dist/src/cli/handlers/utilities.js +1 -1
- package/dist/src/cli/handlers/utility-doctor.js +4 -0
- package/dist/src/cli/handlers/version.js +1 -1
- package/dist/src/cli/handlers/workspace.js +1 -1
- package/dist/src/cli/help-generator.js +9 -11
- package/dist/src/cli/hooks/builtin/activity-log-hook.js +1 -1
- package/dist/src/cli/router.js +1 -1
- package/dist/src/cli/workflow-orchestrator.js +1 -1
- package/dist/src/config/worker-context.js +37 -7
- package/dist/src/config/worker-parallelism.js +11 -0
- package/dist/src/contributors/detect.js +1 -1
- package/dist/src/contributors/discover.js +1 -1
- package/dist/src/contributors/heuristic.js +1 -1
- package/dist/src/contributors/index.js +1 -1
- package/dist/src/contributors/types.js +1 -1
- package/dist/src/contributors/validation.js +1 -1
- package/dist/src/effects/worker-delivery.js +83 -0
- package/dist/src/extensions/capability-index.js +1 -1
- package/dist/src/extensions/commands/definitions.js +2 -2
- package/dist/src/extensions/deployment-registration.js +1 -1
- package/dist/src/extensions/index.js +1 -1
- package/dist/src/extensions/loader.js +1 -1
- package/dist/src/extensions/manifest.js +10 -2
- package/dist/src/extensions/project-local-activity.js +1 -1
- package/dist/src/extensions/project-local-discovery.js +23 -3
- package/dist/src/extensions/project-local-doctor.js +7 -3
- package/dist/src/extensions/project-local-promote.js +3 -3
- package/dist/src/extensions/project-local-remove.js +3 -3
- package/dist/src/extensions/project-local-scaffold.js +20 -8
- package/dist/src/extensions/registry.js +1 -1
- package/dist/src/extensions/shadow-resolver.js +1 -1
- package/dist/src/extensions/types.js +1 -1
- package/dist/src/extensions/upstream-registry.js +1 -1
- package/dist/src/extensions/validation.js +1 -1
- package/dist/src/intake/git-history-analyzer.js +1 -1
- package/dist/src/kb/cli.js +1 -1
- package/dist/src/marketplace/plugin-directory.js +36 -0
- package/dist/src/marketplace/plugin-search.js +180 -0
- package/dist/src/mcp/cli.mjs +2 -2
- package/dist/src/mcp/helpers.mjs +1 -1
- package/dist/src/mcp/http-tools.mjs +8 -6
- package/dist/src/mcp/http-transport.mjs +3 -1
- package/dist/src/mcp/server.mjs +1 -1
- package/dist/src/mcp/tools/command-run.mjs +1 -1
- package/dist/src/mcp/tools/discovery.mjs +1 -1
- package/dist/src/mcp/tools/subsystems.mjs +1 -1
- package/dist/src/mcp/tools/worker-invoke.mjs +68 -22
- package/dist/src/mcp/tools/worker-local-only-preflight.mjs +79 -0
- package/dist/src/mcp/tools/worker-recorded-launch.mjs +26 -0
- package/dist/src/mcp/tools/worker-stdin-runtime.mjs +33 -6
- package/dist/src/mcp/tools/worker-verify-deliver-schema.mjs +33 -0
- package/dist/src/mcp/tools/worker-verify-deliver.mjs +27 -0
- package/dist/src/models/catalog-policy.js +2 -2
- package/dist/src/models/conductor-data-policy.mjs +83 -14
- package/dist/src/models/config-loader.js +2 -2
- package/dist/src/models/factory-models.js +144 -0
- package/dist/src/models/index.js +2 -2
- package/dist/src/models/local-endpoint-models.js +155 -0
- package/dist/src/models/model-capabilities.v1.json +44 -36
- package/dist/src/models/model-discovery.js +16 -8
- package/dist/src/models/opencode-worker-model.mjs +16 -0
- package/dist/src/models/resolver.js +2 -2
- package/dist/src/models/worker-installation.d.mts +2 -0
- package/dist/src/models/worker-installation.mjs +16 -5
- package/dist/src/models/worker-invocation-policy.js +25 -1
- package/dist/src/models/worker-plan.js +1 -1
- package/dist/src/models/wrapper-enforcement.js +1 -1
- package/dist/src/plugin/plugin-installer.js +2 -2
- package/dist/src/plugin/registry-validator.js +2 -2
- package/dist/src/plugin/skill-command-translator.js +1 -1
- package/dist/src/policy/repo-access.js +3 -1
- package/dist/src/providers/capability-matrix.yaml +75 -5
- package/dist/src/providers/deployment-ownership.mjs +8 -1
- package/dist/src/providers/deployment-preservation.mjs +44 -3
- package/dist/src/providers/grok-build-acp.js +13 -5
- package/dist/src/providers/grok-build-dispatch.js +35 -2
- package/dist/src/providers/grok-build-headless.js +2 -1
- package/dist/src/rlm/cache/hash.js +1 -1
- package/dist/src/rlm/cache/store.js +1 -1
- package/dist/src/rlm/cache/types.js +1 -1
- package/dist/src/serve/worker-invocation-preparation.js +13 -0
- package/dist/src/serve/worker-invocation.js +21 -6
- package/dist/src/serve/worker-stdin-frame.mjs +1 -1
- package/dist/src/sessions/adapters/grok-build-native-records.js +77 -7
- package/dist/src/sessions/adapters/grok-build-native.js +148 -1
- package/dist/src/sessions/adapters/grok-build.js +36 -14
- package/dist/src/sessions/normalization.js +1 -1
- package/dist/src/skills/run.js +0 -11
- package/dist/src/smiths/agentsmith/generator.js +1 -1
- package/dist/src/smiths/context-pipeline/index.js +1 -1
- package/dist/src/smiths/context-pipeline/provider-policy.js +1 -1
- package/dist/src/smiths/context-pipeline/types.js +1 -1
- package/dist/src/smiths/context-pipeline/workspace-doctor.js +4 -0
- package/dist/src/smiths/hook-bridge/factory-trust.js +2 -2
- package/dist/src/smiths/hook-bridge/hermes-prompt-discovery.js +10 -7
- package/dist/src/smiths/hook-bridge/hermes-trust.js +65 -0
- package/dist/src/smiths/mcpsmith/analyzers/cli-analyzer.js +2 -2
- package/dist/src/smiths/mcpsmith/generator.js +2 -2
- package/dist/src/smiths/mcpsmith/index.js +2 -2
- package/dist/src/smiths/mcpsmith/types.js +2 -2
- package/dist/src/smiths/skillsmith/collision-detector.js +1 -1
- package/dist/src/smiths/skillsmith/namespace-adapter.js +1 -1
- package/dist/src/smiths/toolsmith/runtime-discovery.mjs +2 -2
- package/dist/src/smiths/toolsmith/types.js +2 -2
- package/dist/src/storage/backends/fortemi.js +1 -1
- package/dist/src/storage/backends/fs.js +1 -1
- package/dist/src/storage/backends/logseq.js +1 -1
- package/dist/src/storage/backends/obsidian.js +1 -1
- package/dist/src/storage/cli.js +2 -2
- package/dist/src/storage/config.js +1 -1
- package/dist/src/storage/index.js +1 -1
- package/dist/src/storage/subsystem-cli.js +1 -1
- package/dist/src/storage/types.js +1 -1
- package/dist/src/testing/generators/test-case-generator.js +1 -1
- package/dist/src/writing/validation-engine.js +1 -1
- package/package.json +11 -1
- package/schemas/models/model-catalog.v1.schema.json +6 -3
- package/tools/agents/deploy-agents.mjs +4 -2
- package/tools/agents/deploy-options.mjs +2 -0
- package/tools/agents/providers/base-inventory.mjs +3 -1
- package/tools/agents/providers/base-kernel-skills.mjs +11 -5
- package/tools/agents/providers/conductor-data-guard.mjs +1 -1
- package/tools/agents/providers/grok-build.mjs +31 -40
- package/tools/agents/providers/model-wrapper.mjs +2 -5
- package/tools/agents/providers/rule-deployment-commit.mjs +3 -0
- package/tools/agents/providers/rule-deployment-prepare.mjs +2 -2
- package/tools/agents/providers/rule-projection.mjs +39 -4
- package/tools/agents/providers/skill-copy-prune.mjs +12 -0
- package/tools/agents/providers/stale-artifact-prune.mjs +24 -10
- package/tools/ralph-external/lib/claude-adapter.mjs +2 -0
- package/tools/ralph-external/lib/factory-adapter.mjs +6 -2
- package/tools/ralph-external/lib/mcp-worker-launch.mjs +67 -0
- package/tools/ralph-external/lib/opencode-adapter.mjs +9 -7
- package/tools/ralph-external/lib/trusted-verification.mjs +1021 -0
- package/tools/ralph-external/lib/typed-stop-delivery.mjs +46 -0
- package/tools/ralph-external/lib/verification-isolation.mjs +509 -0
- package/tools/ralph-external/lib/worker-context.mjs +3 -3
- package/tools/ralph-external/lib/worker-delivery-guards.mjs +95 -0
- package/tools/ralph-external/lib/worker-delivery-record.mjs +15 -0
- package/tools/ralph-external/lib/worker-final.mjs +4 -1
- package/tools/ralph-external/lib/worker-inputs.mjs +20 -1
- package/tools/ralph-external/lib/worker-isolation-status.mjs +3 -0
- package/tools/ralph-external/lib/worker-isolation.mjs +1 -0
- package/tools/ralph-external/lib/worker-launch-cli.mjs +8 -0
- package/tools/ralph-external/lib/worker-local-only-paths.mjs +45 -0
- package/tools/ralph-external/lib/worker-prompt.mjs +4 -1
- package/tools/ralph-external/lib/worker-retry-evidence.mjs +2 -1
- package/tools/ralph-external/lib/worker-run-directory.mjs +45 -0
- package/tools/ralph-external/lib/worker-termination.mjs +21 -12
- package/tools/ralph-external/lib/worker-unit-cleanup.mjs +10 -2
- package/tools/ralph-external/lib/worker-verification-cli.mjs +164 -0
- package/tools/ralph-external/lib/worktree-preparation.mjs +417 -0
- package/tools/ralph-external/session-launcher.mjs +30 -32
- package/vscode-extension/schemas/aiwg.config.v1.json +27 -0
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
// Refuse unsafe publication requests before protected checks execute.
|
|
2
|
+
import { closeSync, fstatSync, realpathSync } from 'node:fs';
|
|
3
|
+
import { basename, dirname, isAbsolute, join, resolve } from 'node:path';
|
|
4
|
+
import { boundedPrivateRead } from './worker-inputs.mjs';
|
|
5
|
+
import { parseStrictWorkerJson } from './strict-worker-json.mjs';
|
|
6
|
+
import { digestArtifactFd, pinArtifact, resolveWorktreeRoot } from './trusted-verification.mjs';
|
|
7
|
+
|
|
8
|
+
export class WorkerDeliveryRefusal extends Error {
|
|
9
|
+
constructor(code, message) {
|
|
10
|
+
super(`${code}: ${message}`);
|
|
11
|
+
this.code = code;
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
const refuse = (code, message) => { throw new WorkerDeliveryRefusal(code, message); };
|
|
15
|
+
|
|
16
|
+
export function requireDeliveryArtifact(artifactPath, finalPath) {
|
|
17
|
+
if (!artifactPath) refuse('ARTIFACT_REQUIRED', 'publication requires explicit artifact_path / --artifact');
|
|
18
|
+
if (finalPath && realpathSync(artifactPath) === realpathSync(finalPath)) {
|
|
19
|
+
refuse('ARTIFACT_REQUIRED', 'artifact_path / --artifact must name a deliverable, never the worker final / handoff wrapper');
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
export async function readDeliveryExit(runDir, inspect) {
|
|
24
|
+
try {
|
|
25
|
+
const exit = JSON.parse((await boundedPrivateRead(join(runDir, 'exit.json'), 1048576, inspect, true, true)).toString('utf8'));
|
|
26
|
+
if (typeof exit?.endedAt !== 'string' || !/^\d{4}-\d\d-\d\dT\d\d:\d\d:\d\d(?:\.\d+)?(?:Z|[+-]\d\d:\d\d)$/.test(exit.endedAt)
|
|
27
|
+
|| !Number.isFinite(Date.parse(exit.endedAt))) {
|
|
28
|
+
throw new Error('exit.json requires an ISO endedAt');
|
|
29
|
+
}
|
|
30
|
+
return exit;
|
|
31
|
+
} catch (error) {
|
|
32
|
+
refuse('EXIT_EVIDENCE_MISSING', `publication requires readable launcher exit.json with endedAt (${error.message})`);
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
const probes = new Set(['test', '[', 'stat', 'ls', 'true', 'file', 'wc']);
|
|
37
|
+
// This is a narrow argv heuristic, not proof that a check asserts correctness.
|
|
38
|
+
// Probe binaries with only path/flag operands cannot qualify. Other checks
|
|
39
|
+
// must mention the artifact, its basename, or a containing directory in args.
|
|
40
|
+
export function isContentFreeCheck(check, artifactPath) {
|
|
41
|
+
const args = check.args ?? [];
|
|
42
|
+
let command = check.command;
|
|
43
|
+
try { command = realpathSync(command); } catch { /* The verifier refuses unavailable binaries. */ }
|
|
44
|
+
const pathOrFlag = arg => arg.startsWith('-') || isAbsolute(arg) || arg === basename(artifactPath) || !/[;&|<>$`"'(){}]/.test(arg);
|
|
45
|
+
if ((probes.has(basename(check.command)) || probes.has(basename(command))) && args.every(pathOrFlag)) return true;
|
|
46
|
+
const references = [artifactPath, basename(artifactPath)];
|
|
47
|
+
for (let directory = dirname(artifactPath); directory !== dirname(directory); directory = dirname(directory)) references.push(directory);
|
|
48
|
+
return !args.some(arg => references.some(ref => arg.includes(ref)));
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
async function claimedArtifacts(finalPath, inspect) {
|
|
52
|
+
if (!finalPath) return [];
|
|
53
|
+
const bytes = await boundedPrivateRead(finalPath, 1048576, inspect);
|
|
54
|
+
let final;
|
|
55
|
+
try { final = parseStrictWorkerJson(new TextDecoder('utf-8', { fatal: true }).decode(bytes), 64); }
|
|
56
|
+
catch (error) {
|
|
57
|
+
// Unstructured handoff text is supported; ambiguous JSON claims are not.
|
|
58
|
+
if (error.code === 'SYNTAX') return [];
|
|
59
|
+
throw error;
|
|
60
|
+
}
|
|
61
|
+
return [final?.artifacts, final?.result?.artifacts].flatMap(value => Array.isArray(value) ? value : []);
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
export async function prepareWorkerDeliveryGuard({ worktreeRoot, artifactPath, finalPath, checks, exit, inspect }) {
|
|
65
|
+
const claims = await claimedArtifacts(finalPath, inspect);
|
|
66
|
+
// Run on the verifier's own pinned descriptor and digest, leaving no gap
|
|
67
|
+
// between request validation and the bytes the checks will accept.
|
|
68
|
+
const guard = (pinned, digest) => {
|
|
69
|
+
const cutoff = Date.parse(exit.endedAt) + 2000;
|
|
70
|
+
if (pinned.stat.ctimeMs > cutoff || pinned.stat.mtimeMs > cutoff) {
|
|
71
|
+
refuse('ARTIFACT_CHANGED_AFTER_EXIT', 'artifact ctime or mtime is later than launcher endedAt (2 s clock slack)');
|
|
72
|
+
}
|
|
73
|
+
const matching = claims.filter(claim => {
|
|
74
|
+
if (typeof claim?.path !== 'string' || typeof claim.digest !== 'string') return false;
|
|
75
|
+
const path = resolve(worktreeRoot, claim.path);
|
|
76
|
+
if (path === resolve(artifactPath)) return true;
|
|
77
|
+
try { return realpathSync(path) === pinned.realPath; } catch { return false; }
|
|
78
|
+
});
|
|
79
|
+
if (matching.some(claim => claim.digest !== digest)) {
|
|
80
|
+
refuse('ARTIFACT_CHANGED_AFTER_EXIT', 'artifact digest does not match the worker final claim');
|
|
81
|
+
}
|
|
82
|
+
const after = fstatSync(pinned.fd);
|
|
83
|
+
if (after.ctimeMs !== pinned.stat.ctimeMs || after.mtimeMs !== pinned.stat.mtimeMs || after.size !== pinned.stat.size) {
|
|
84
|
+
refuse('ARTIFACT_CHANGED_AFTER_EXIT', 'artifact changed while checking exit evidence');
|
|
85
|
+
}
|
|
86
|
+
if (!checks.some(check => !isContentFreeCheck(check, pinned.realPath))) {
|
|
87
|
+
refuse('CHECKS_CONTENT_FREE', 'publication requires a content check referencing the artifact path, basename, or containing directory');
|
|
88
|
+
}
|
|
89
|
+
};
|
|
90
|
+
// Refuse before probing isolation, then repeat on the verifier's exact pin.
|
|
91
|
+
const pinned = pinArtifact(resolveWorktreeRoot(worktreeRoot), artifactPath);
|
|
92
|
+
try { guard(pinned, digestArtifactFd(pinned)); }
|
|
93
|
+
finally { closeSync(pinned.fd); }
|
|
94
|
+
return guard;
|
|
95
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
// Connect the installed verifier to the existing host-configured signed effects ledger.
|
|
2
|
+
import { importImpl } from '../../_resolve-impl.mjs';
|
|
3
|
+
|
|
4
|
+
async function ledgerFor(projectDir) {
|
|
5
|
+
const { effectSession, openLedger } = await importImpl(import.meta.url, 'effects/host.js');
|
|
6
|
+
return openLedger(await effectSession(projectDir, 'delivery'));
|
|
7
|
+
}
|
|
8
|
+
export async function prepareDeliveryRecord(projectDir, metadata) {
|
|
9
|
+
const { prepareWorkerDelivery } = await importImpl(import.meta.url, 'effects/worker-delivery.js');
|
|
10
|
+
return prepareWorkerDelivery(await ledgerFor(projectDir), metadata);
|
|
11
|
+
}
|
|
12
|
+
export async function lookupDeliveryRecord(projectDir, destination) {
|
|
13
|
+
const { lookupWorkerDelivery } = await importImpl(import.meta.url, 'effects/worker-delivery.js');
|
|
14
|
+
return lookupWorkerDelivery(await ledgerFor(projectDir), destination);
|
|
15
|
+
}
|
|
@@ -130,7 +130,10 @@ export async function collectWorkerFinal({ path, workdir, driver, output, invoca
|
|
|
130
130
|
}
|
|
131
131
|
} else {
|
|
132
132
|
const decoded = scan(finalBytes);
|
|
133
|
-
|
|
133
|
+
// A worker-written final that is already workerClaims is used as written. Adapter extraction
|
|
134
|
+
// (for example Muse's JSONL event parser) applies only to vendor-shaped files (#4158).
|
|
135
|
+
claims = driver.extractFinal && !validateWorkerPayload('workerClaims', decoded).valid
|
|
136
|
+
? driver.extractFinal(finalBytes.toString('utf8')) : decoded;
|
|
134
137
|
}
|
|
135
138
|
if (!parseError) {
|
|
136
139
|
const validation = validateWorkerPayload('workerClaims', claims);
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
// Read bounded worker inputs through pinned, no-follow directory handles.
|
|
2
2
|
import { constants } from 'node:fs';
|
|
3
3
|
import { open } from 'node:fs/promises';
|
|
4
|
-
import { isAbsolute } from 'node:path';
|
|
4
|
+
import { basename, dirname, isAbsolute } from 'node:path';
|
|
5
5
|
|
|
6
6
|
// Linux directory handles pin each ancestor. O_NOFOLLOW on a pathname alone
|
|
7
7
|
// cannot protect an ancestor that the worker replaces after inspection.
|
|
@@ -19,6 +19,25 @@ export async function withWorkerPath(filename, operation) {
|
|
|
19
19
|
} finally { await directory.close(); }
|
|
20
20
|
}
|
|
21
21
|
|
|
22
|
+
// Reuse one pinned directory for a batch of direct-child operations. Every
|
|
23
|
+
// ancestor and the directory itself are still opened with O_NOFOLLOW;
|
|
24
|
+
// callers retain the leaf operation's own no-follow/exclusive-create checks.
|
|
25
|
+
export async function withWorkerDirectory(directory, operation) {
|
|
26
|
+
return withWorkerPath(directory, async anchored => {
|
|
27
|
+
const handle = await open(anchored, constants.O_RDONLY | constants.O_DIRECTORY | constants.O_NOFOLLOW);
|
|
28
|
+
try {
|
|
29
|
+
return await operation(async (filename, action) => {
|
|
30
|
+
if (filename.includes('\0') || filename.split('/').includes('..')
|
|
31
|
+
|| (filename !== directory && dirname(filename) !== directory)) {
|
|
32
|
+
throw new Error('Invalid worker path outside pinned directory');
|
|
33
|
+
}
|
|
34
|
+
const leaf = filename === directory ? '.' : basename(filename);
|
|
35
|
+
return action(`/proc/self/fd/${handle.fd}/${leaf}`);
|
|
36
|
+
});
|
|
37
|
+
} finally { await handle.close(); }
|
|
38
|
+
});
|
|
39
|
+
}
|
|
40
|
+
|
|
22
41
|
// #2915 review 4 (finding 4): `privateOutput: true` REPAIRS a loose mode
|
|
23
42
|
// (chmod 0600) rather than rejecting it — correct for the worker's own
|
|
24
43
|
// final-output file, which the launcher itself created and is free to
|
|
@@ -9,6 +9,9 @@ function emptyCgroup(fields, readCgroup) {
|
|
|
9
9
|
if (!['inactive', 'failed'].includes(fields.ActiveState)) return false;
|
|
10
10
|
// A loaded inactive unit can have released its cgroup entirely.
|
|
11
11
|
if (fields.LoadState === 'loaded' && fields.ControlGroup === '') return true;
|
|
12
|
+
// systemd garbage-collects a unit that exited successfully once it is inactive and its cgroup is
|
|
13
|
+
// released; the same not-found/inactive/MainPID=0 shape parseShellUnitStatus accepts (#4158).
|
|
14
|
+
if (fields.LoadState === 'not-found' && fields.MainPID === '0' && (fields.ControlGroup ?? '') === '') return true;
|
|
12
15
|
const group = fields.ControlGroup;
|
|
13
16
|
if (!group?.startsWith('/') || group === '/' || group.split('/').includes('..')) return false;
|
|
14
17
|
try { return /^populated 0$/m.test(readCgroup(`/sys/fs/cgroup${group}/cgroup.events`, 'utf8')); }
|
|
@@ -249,6 +249,7 @@ export function launchIsolatedWorker({
|
|
|
249
249
|
const outcome = {
|
|
250
250
|
launched: Number.isInteger(child.pid) && child.pid > 0,
|
|
251
251
|
mode: detected.mode, child, pid: child.pid,
|
|
252
|
+
ownedGroup: ownedGroup === true,
|
|
252
253
|
...(attached ? { transportSupervisor: true } : {}),
|
|
253
254
|
diagnostic: nativeSandbox ? 'Native CLI sandbox boundary; no cgroup resource confinement' : `launched without resource confinement: ${detected.reason}`,
|
|
254
255
|
gate: resolvedGate,
|
|
@@ -11,6 +11,14 @@ export function workerFinalFailureMessage(result) {
|
|
|
11
11
|
+ (failure.scanError ? ` (scan failed: ${failure.scanError})` : '');
|
|
12
12
|
}
|
|
13
13
|
|
|
14
|
+
/** Rule 9 step 9: never nest --launch-worker inside the confined conductor unit (#4163). A
|
|
15
|
+
* guardrail for honest mistakes, not a security boundary: the nested sandbox fails either way. */
|
|
16
|
+
export function confinedConductorLaunchRefusal(env = process.env) {
|
|
17
|
+
if (env.AIWG_CONFINED_CONDUCTOR !== '1') return null;
|
|
18
|
+
return 'OG_CONFINED_LAUNCH_REFUSED: --launch-worker cannot run inside a confined conductor unit (its worker sandbox would nest and fail). '
|
|
19
|
+
+ 'Launch workers with the aiwg MCP worker-invoke tool (operation "run", transport "shell", run_dir) and follow them with operation "status". No worker was started.';
|
|
20
|
+
}
|
|
21
|
+
|
|
14
22
|
export function parseWorkerLaunchArgs(args) {
|
|
15
23
|
const result = {};
|
|
16
24
|
const seen = new Set();
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
// Remove declared local-only inputs from conductor-owned worker worktrees before deployment.
|
|
2
|
+
import { spawnSync } from 'node:child_process';
|
|
3
|
+
import { lstatSync, rmSync } from 'node:fs';
|
|
4
|
+
import path from 'node:path';
|
|
5
|
+
import { importImpl } from '../../_resolve-impl.mjs';
|
|
6
|
+
|
|
7
|
+
function existingTarget(worktreePath, relative) {
|
|
8
|
+
let target = worktreePath;
|
|
9
|
+
for (const component of relative.split('/')) {
|
|
10
|
+
target = path.join(target, component);
|
|
11
|
+
let info;
|
|
12
|
+
try { info = lstatSync(target); } catch (error) {
|
|
13
|
+
if (error.code === 'ENOENT' || error.code === 'ENOTDIR') return null;
|
|
14
|
+
throw error;
|
|
15
|
+
}
|
|
16
|
+
if (info.isSymbolicLink()) throw new Error(`refusing symlinked local-only path component: ${relative}`);
|
|
17
|
+
}
|
|
18
|
+
return target;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
export async function excludeWorkerLocalOnlyPaths({ repoRoot, worktreePath, spawn = spawnSync, timeoutMs = 30000 }) {
|
|
22
|
+
const { readAiwgConfig } = await importImpl(import.meta.url, 'config/aiwg-config.js');
|
|
23
|
+
const { ConfigLoader } = await importImpl(import.meta.url, 'models/config-loader.js');
|
|
24
|
+
const { collectLocalOnlyPaths } = await importImpl(import.meta.url, 'models/conductor-data-policy.mjs');
|
|
25
|
+
const config = await readAiwgConfig(repoRoot);
|
|
26
|
+
const models = await new ConfigLoader(repoRoot).load(config?.parallelism);
|
|
27
|
+
const paths = collectLocalOnlyPaths(models.defaults.workerSelection, config?.parallelism);
|
|
28
|
+
// Validate every component before changing the index or removing anything.
|
|
29
|
+
const targets = paths.map(relative => ({ relative, target: existingTarget(worktreePath, relative) }))
|
|
30
|
+
.filter(entry => entry.target !== null);
|
|
31
|
+
if (!targets.length) return [];
|
|
32
|
+
|
|
33
|
+
const git = (args, input) => {
|
|
34
|
+
const result = spawn('git', args, { cwd: worktreePath, encoding: 'utf8', timeout: timeoutMs, input });
|
|
35
|
+
if (result.error) throw new Error(`git ${args.join(' ')} failed to run: ${result.error.message}`);
|
|
36
|
+
if (result.status !== 0) throw new Error(`git ${args.join(' ')} exited ${result.status}: ${String(result.stderr ?? '').trim()}`);
|
|
37
|
+
return String(result.stdout ?? '');
|
|
38
|
+
};
|
|
39
|
+
// Literal pathspecs include tracked descendants, without treating names as glob syntax.
|
|
40
|
+
const tracked = git(['ls-files', '-z', '--', ...targets.map(({ relative }) => `:(literal)${relative}`)]);
|
|
41
|
+
if (tracked) git(['update-index', '--skip-worktree', '-z', '--stdin'], tracked);
|
|
42
|
+
// rm unlinks descendant symlinks themselves; it never traverses their targets.
|
|
43
|
+
for (const { target } of targets) rmSync(target, { recursive: true, force: true });
|
|
44
|
+
return targets.map(({ relative }) => relative);
|
|
45
|
+
}
|
|
@@ -9,7 +9,10 @@ Required minimal wrapper example (replace the summary and report your actual sta
|
|
|
9
9
|
Allowed status: completed, partial, blocked, failed. Keep all seven fields; add no other top-level fields.
|
|
10
10
|
Put the answer in summary or a separate task artifact. For each listed artifact use
|
|
11
11
|
{"path":"answer.json","digest":"sha256:<64 lowercase hex characters>","change":"created"}
|
|
12
|
-
with a real digest and a file beneath the worker tree.
|
|
12
|
+
with a real digest and a file beneath the worker tree. Each claim and check is an object, never a string:
|
|
13
|
+
{"id":"claim-1","text":"What you did or found","evidence":[{"ref":"answer.json","digest":"sha256:<64 lowercase hex characters>"}]}
|
|
14
|
+
{"checkId":"check-1","exitCode":0,"evidence":{"ref":"answer.json","digest":"sha256:<64 lowercase hex characters>"},"environment":"worker tree"}
|
|
15
|
+
Evidence items use "ref", not "path". Each limitation is a plain string. Empty collections are allowed.
|
|
13
16
|
Keep this JSON separate from stdout, stderr and last-message captures. A file at the worker-tree root
|
|
14
17
|
does not satisfy a different declared final-output path. Worker claims remain unverified.
|
|
15
18
|
|
|
@@ -151,9 +151,10 @@ async function assertNoOpenPredecessor({ runDir, captureRoot, saved, inspect, re
|
|
|
151
151
|
const filename = join(previousDir, 'invocation.json');
|
|
152
152
|
if (!await inspect(filename, 'file')) continue;
|
|
153
153
|
const record = JSON.parse((await boundedPrivateRead(filename, 1048576, inspect, true, true)).toString('utf8'));
|
|
154
|
-
if (record.origin
|
|
154
|
+
if (!['launcher', 'shell-handoff'].includes(record.origin) || ((record.taskBindingDigest ?? record.taskDigest) !== taskDigest
|
|
155
155
|
&& !await matchesTaskIdentity(record, saved))) continue;
|
|
156
156
|
try {
|
|
157
|
+
if (record.origin === 'shell-handoff') throw new Error('Raw shell predecessor termination is unknown');
|
|
157
158
|
// Reuse the authenticated owned-stop loader, including missing exits.
|
|
158
159
|
await verifyRetryPredecessor({ invocationId: record.invocationId, runDir: previousDir }, { inspect, workerWritableRoots });
|
|
159
160
|
} catch (cause) {
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
// Create private in-project run parents without following symlinked components.
|
|
2
|
+
import { lstat, mkdir } from 'node:fs/promises';
|
|
3
|
+
import { dirname, isAbsolute, join, parse, relative, resolve } from 'node:path';
|
|
4
|
+
import { withWorkerPath } from './worker-inputs.mjs';
|
|
5
|
+
|
|
6
|
+
export async function createAttemptRunDirectory(runDir, projectRoot = process.cwd()) {
|
|
7
|
+
if (!isAbsolute(runDir) || runDir.includes('\0') || runDir.split('/').includes('..')) {
|
|
8
|
+
throw new Error('Invalid worker run directory path');
|
|
9
|
+
}
|
|
10
|
+
const parent = dirname(runDir);
|
|
11
|
+
const root = resolve(projectRoot);
|
|
12
|
+
const rel = relative(root, parent);
|
|
13
|
+
const inProject = rel === '' || (!isAbsolute(rel) && rel !== '..' && !rel.startsWith('../'));
|
|
14
|
+
if (inProject) {
|
|
15
|
+
await withWorkerPath(root, async target => {
|
|
16
|
+
const stat = await lstat(target);
|
|
17
|
+
if (stat.isSymbolicLink() || !stat.isDirectory()) throw new Error('Invalid conductor project root');
|
|
18
|
+
});
|
|
19
|
+
}
|
|
20
|
+
let current = parse(parent).root;
|
|
21
|
+
for (const segment of parent.slice(current.length).split('/').filter(Boolean)) {
|
|
22
|
+
current = join(current, segment);
|
|
23
|
+
try {
|
|
24
|
+
const stat = await lstat(current);
|
|
25
|
+
if (stat.isSymbolicLink() || !stat.isDirectory()) {
|
|
26
|
+
throw new Error(`Worker run directory parent must be a directory without symlinks: ${current}`);
|
|
27
|
+
}
|
|
28
|
+
} catch (error) {
|
|
29
|
+
if (error.code !== 'ENOENT') throw error;
|
|
30
|
+
if (!inProject) {
|
|
31
|
+
throw new Error(`Worker run directory parent does not exist: ${parent}; create it (mode 0700) before launch`);
|
|
32
|
+
}
|
|
33
|
+
await withWorkerPath(current, async target => {
|
|
34
|
+
try { await mkdir(target, { mode: 0o700 }); } catch (error) {
|
|
35
|
+
if (error.code !== 'EEXIST') throw error;
|
|
36
|
+
}
|
|
37
|
+
const stat = await lstat(target);
|
|
38
|
+
if (stat.isSymbolicLink() || !stat.isDirectory()) {
|
|
39
|
+
throw new Error(`Worker run directory parent must be a directory without symlinks: ${current}`);
|
|
40
|
+
}
|
|
41
|
+
});
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
await withWorkerPath(runDir, target => mkdir(target, { mode: 0o700 }));
|
|
45
|
+
}
|
|
@@ -8,7 +8,7 @@ const TERMINATION_BUDGET_MS = 2000;
|
|
|
8
8
|
const TERMINATION_ATTEMPT_MS = 100;
|
|
9
9
|
const TERMINATION_MAX_ATTEMPTS = 21;
|
|
10
10
|
|
|
11
|
-
export function observeWorkerTermination({ mode, native, workerExited, identity,
|
|
11
|
+
export function observeWorkerTermination({ mode, native, workerExited, identity, detachedPid,
|
|
12
12
|
supervisor = sampleWorkerIdentity(process.pid), kill = process.kill, invocationId,
|
|
13
13
|
scan = scanWorkerInvocationProcesses, groupStates = sampleGroupStates, deadline, now = () => performance.now() } = {}) {
|
|
14
14
|
if (mode === 'systemd-unit') {
|
|
@@ -18,20 +18,33 @@ export function observeWorkerTermination({ mode, native, workerExited, identity,
|
|
|
18
18
|
? 'unit inactive evidence' : native?.cgroupEmpty !== true ? 'empty unit cgroup (TasksCurrent=0)' : null };
|
|
19
19
|
}
|
|
20
20
|
if (!workerExited) return { confirmed: false, missing: 'launcher-observed worker exit' };
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
21
|
+
// A successful detached spawn establishes pgid=pid even if /proc vanished
|
|
22
|
+
// before capture. This is read-only containment evidence, never a recovered
|
|
23
|
+
// birth identity or signal authority. The launcher's birth is a conservative
|
|
24
|
+
// lower bound for descendants; without worker birth, unreadable processes
|
|
25
|
+
// retain the scan's stricter fail-closed handling (no ancestry exclusions).
|
|
26
|
+
const group = identity ?? (Number.isSafeInteger(detachedPid) && supervisor?.pid === process.pid
|
|
27
|
+
&& /^\d+$/.test(supervisor.startTicks ?? '') ? {
|
|
28
|
+
pid: detachedPid, pgid: detachedPid, uid: supervisor.uid,
|
|
29
|
+
host: supervisor.host, bootId: supervisor.bootId, startTicks: supervisor.startTicks,
|
|
30
|
+
} : null);
|
|
31
|
+
if (!group || group.pid !== group.pgid || group.uid !== process.getuid?.()
|
|
32
|
+
|| !supervisor || group.host !== supervisor.host || group.bootId !== supervisor.bootId
|
|
33
|
+
|| !isSafeWorkerGroupTarget(group.pgid, supervisor)) {
|
|
24
34
|
return { confirmed: false, missing: 'launcher-owned process group identity on this host and boot' };
|
|
25
35
|
}
|
|
36
|
+
const scanOptions = { invocationId, startTicks: group.startTicks, uid: group.uid, now,
|
|
37
|
+
deadline: deadline ?? now() + TERMINATION_BUDGET_MS,
|
|
38
|
+
...(identity ? { workerPid: identity.pid, workerPgid: identity.pgid, workerSession: identity.sessionId } : {}) };
|
|
26
39
|
let groupEmpty = false;
|
|
27
40
|
try {
|
|
28
|
-
kill(-
|
|
41
|
+
kill(-group.pgid, 0);
|
|
29
42
|
// Signal 0 also reaches zombies. A reaper that never waits (a container's
|
|
30
43
|
// PID 1) can leave killed members as zombies indefinitely; a group whose
|
|
31
44
|
// remaining members are all zombies has no live process (#3853).
|
|
32
45
|
// Absence from /proc is never proof; only observed zombies explaining
|
|
33
46
|
// signal 0, with no live or unreadable member, count as an empty group.
|
|
34
|
-
const states = groupStates(
|
|
47
|
+
const states = groupStates(group.pgid);
|
|
35
48
|
groupEmpty = !!states && states.zombies > 0 && states.live === 0 && states.unreadable === 0;
|
|
36
49
|
}
|
|
37
50
|
catch (error) {
|
|
@@ -42,16 +55,12 @@ export function observeWorkerTermination({ mode, native, workerExited, identity,
|
|
|
42
55
|
if (error.code === 'ESRCH') {
|
|
43
56
|
// A standalone observation gets one scan, at most 2 s. An explicit
|
|
44
57
|
// deadline leaves the shared budget and retries to its caller.
|
|
45
|
-
return scan(
|
|
46
|
-
deadline: deadline ?? now() + TERMINATION_BUDGET_MS,
|
|
47
|
-
workerPid: identity.pid, workerPgid: identity.pgid, workerSession: identity.sessionId });
|
|
58
|
+
return scan(scanOptions);
|
|
48
59
|
}
|
|
49
60
|
return { confirmed: false, missing: `empty owned process group (signal-0 returned ${error.code ?? 'unknown'})` };
|
|
50
61
|
}
|
|
51
62
|
if (groupEmpty) {
|
|
52
|
-
return scan(
|
|
53
|
-
deadline: deadline ?? now() + TERMINATION_BUDGET_MS,
|
|
54
|
-
workerPid: identity.pid, workerPgid: identity.pgid, workerSession: identity.sessionId });
|
|
63
|
+
return scan(scanOptions);
|
|
55
64
|
}
|
|
56
65
|
return { confirmed: false, missing: 'empty owned process group (signal-0 still finds members)', retryable: true };
|
|
57
66
|
}
|
|
@@ -25,10 +25,18 @@ export function resetRecordedWorkerUnit(outcome, native, { spawn = spawnSync, lo
|
|
|
25
25
|
try {
|
|
26
26
|
const client = resolveSystemdClient('systemctl');
|
|
27
27
|
const options = { encoding: 'utf8', timeout: 500, killSignal: 'SIGKILL', env: buildSystemdClientEnv({ envNames: [] }) };
|
|
28
|
-
const shown = spawn(client, ['--user', 'show', '-p', '
|
|
28
|
+
const shown = spawn(client, ['--user', 'show', '-p', 'LoadState', '-p', 'Description', '--', owner.unit], options);
|
|
29
29
|
if (shown.error || shown.status !== 0) throw new Error(shown.error?.message ?? (String(shown.stderr ?? '').trim() || 'ownership query failed'));
|
|
30
|
+
const properties = Object.fromEntries(String(shown.stdout ?? '').trim().split('\n').map(line => {
|
|
31
|
+
const separator = line.indexOf('=');
|
|
32
|
+
return [line.slice(0, separator), line.slice(separator + 1)];
|
|
33
|
+
}));
|
|
34
|
+
if (properties.LoadState === 'not-found') {
|
|
35
|
+
owners.delete(outcome?.child ?? outcome);
|
|
36
|
+
return true;
|
|
37
|
+
}
|
|
30
38
|
// A failed submission may have collided with somebody else's existing unit.
|
|
31
|
-
if (
|
|
39
|
+
if (properties.Description !== owner.description) {
|
|
32
40
|
owners.delete(outcome?.child ?? outcome);
|
|
33
41
|
throw new Error('unit ownership does not match this launch');
|
|
34
42
|
}
|
|
@@ -0,0 +1,164 @@
|
|
|
1
|
+
// Expose the installed trusted verifier through the existing worker-run CLI.
|
|
2
|
+
import { prepareDeliveryRecord, lookupDeliveryRecord } from './worker-delivery-record.mjs';
|
|
3
|
+
import { deliverTypedStop } from './typed-stop-delivery.mjs';
|
|
4
|
+
import { createHash } from 'node:crypto';
|
|
5
|
+
import { closeSync, lstatSync, mkdtempSync, readSync, realpathSync, renameSync, rmSync, writeFileSync } from 'node:fs';
|
|
6
|
+
import { basename, dirname, relative, sep, isAbsolute, join } from 'node:path';
|
|
7
|
+
import { fileURLToPath } from 'node:url';
|
|
8
|
+
import { importImpl } from '../../_resolve-impl.mjs';
|
|
9
|
+
import { boundedPrivateRead } from './worker-inputs.mjs';
|
|
10
|
+
import { verifyRetryPredecessor } from '../session-launcher.mjs';
|
|
11
|
+
import { pinArtifact, resolveWorktreeRoot, verifyWorkerArtifact } from './trusted-verification.mjs';
|
|
12
|
+
import { missingRequiredCapabilities, probeVerificationIsolationCapabilities } from './verification-isolation.mjs';
|
|
13
|
+
import { WorkerDeliveryRefusal, requireDeliveryArtifact, readDeliveryExit, prepareWorkerDeliveryGuard } from './worker-delivery-guards.mjs';
|
|
14
|
+
|
|
15
|
+
const usage = 'Usage: ralph-external --verify-worker --run-dir ABS_DIR --check JSON [--check JSON] [--artifact ABS_FILE] [--deliverable ABS_FILE] [--check-descendants] [--json] (lookup: --verify-worker --delivery-status --deliverable ABS_FILE --json)';
|
|
16
|
+
const checkKeys = new Set(['id', 'command', 'args', 'cwd', 'envNames', 'timeoutMs']);
|
|
17
|
+
const absolute = value => typeof value === 'string' && isAbsolute(value) && !value.includes('\0');
|
|
18
|
+
|
|
19
|
+
export function parseWorkerVerificationArgs(args) {
|
|
20
|
+
const result = { checks: [], json: false };
|
|
21
|
+
const seen = new Set();
|
|
22
|
+
for (let i = 0; i < args.length; i++) {
|
|
23
|
+
const flag = args[i];
|
|
24
|
+
if (flag !== '--check' && seen.has(flag)) throw new Error(`Duplicate verification option: ${flag}`);
|
|
25
|
+
seen.add(flag);
|
|
26
|
+
if (flag === '--verify-worker') continue;
|
|
27
|
+
if (flag === '--check-descendants') { result.checkDescendants = true; continue; }
|
|
28
|
+
if (flag === '--delivery-status') { result.deliveryStatus = true; continue; }
|
|
29
|
+
if (flag === '--json') { result.json = true; continue; }
|
|
30
|
+
if (!['--run-dir', '--artifact', '--deliverable', '--check'].includes(flag)) throw new Error(`Unsupported verification option: ${flag}`);
|
|
31
|
+
const value = args[++i];
|
|
32
|
+
if (!value || value.startsWith('--')) throw new Error(`${flag} requires a value`);
|
|
33
|
+
if (flag !== '--check') {
|
|
34
|
+
if (!absolute(value)) throw new Error(`${flag} requires an absolute NUL-free path`);
|
|
35
|
+
result[flag === '--run-dir' ? 'runDir' : flag === '--artifact' ? 'artifactPath' : 'deliverablePath'] = value;
|
|
36
|
+
continue;
|
|
37
|
+
}
|
|
38
|
+
if (Buffer.byteLength(value) > 65536 || result.checks.length >= 32) throw new Error('Protected check input exceeds bounds');
|
|
39
|
+
const check = JSON.parse(value);
|
|
40
|
+
if (!check || Array.isArray(check) || typeof check !== 'object' || Object.keys(check).some(key => !checkKeys.has(key))
|
|
41
|
+
|| typeof check.id !== 'string' || !check.id || result.checks.some(entry => entry.id === check.id)
|
|
42
|
+
|| !absolute(check.command) || check.args !== undefined && (!Array.isArray(check.args) || check.args.some(arg => typeof arg !== 'string' || arg.includes('\0')))
|
|
43
|
+
|| check.cwd !== undefined && !absolute(check.cwd)
|
|
44
|
+
|| check.envNames !== undefined && (!Array.isArray(check.envNames) || check.envNames.some(name => typeof name !== 'string' || !/^[A-Za-z_][A-Za-z0-9_]*$/.test(name)))
|
|
45
|
+
|| check.timeoutMs !== undefined && (!Number.isSafeInteger(check.timeoutMs) || check.timeoutMs <= 0 || check.timeoutMs > 86400000)) {
|
|
46
|
+
throw new Error('Invalid protected check: require a unique id, absolute command, and optional args/cwd/envNames/timeoutMs; isolation overrides are forbidden');
|
|
47
|
+
}
|
|
48
|
+
result.checks.push(check);
|
|
49
|
+
}
|
|
50
|
+
if (!seen.has('--verify-worker') || (result.deliveryStatus ? !result.deliverablePath || result.runDir || result.checks.length || result.artifactPath || result.checkDescendants : !result.runDir || !result.checks.length)) throw new Error(usage);
|
|
51
|
+
return result;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
// Publish only bytes matching this verifier call's acceptance; logs are never authority.
|
|
55
|
+
export function deliverVerifiedArtifact(result, { artifactPath, deliverablePath, worktreeRoot, writableRoots = [] }) {
|
|
56
|
+
if (result.status !== 'accepted' || !deliverablePath) return;
|
|
57
|
+
const root = resolveWorktreeRoot(worktreeRoot);
|
|
58
|
+
const parent = realpathSync(dirname(deliverablePath));
|
|
59
|
+
const destination = join(parent, basename(deliverablePath));
|
|
60
|
+
for (const tree of [root, ...writableRoots]) {
|
|
61
|
+
const rel = relative(realpathSync(tree), destination);
|
|
62
|
+
if (rel === '' || rel !== '..' && !rel.startsWith('..' + sep) && !isAbsolute(rel)) {
|
|
63
|
+
throw new Error('--deliverable must be outside worker-writable roots');
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
let existing;
|
|
67
|
+
try { existing = lstatSync(destination); } catch (error) { if (error.code !== 'ENOENT') throw error; }
|
|
68
|
+
if (existing && (!existing.isFile() || existing.nlink !== 1)) throw new Error('--deliverable must be a regular non-linked file or an absent path');
|
|
69
|
+
const pinned = pinArtifact(root, artifactPath);
|
|
70
|
+
let bytes;
|
|
71
|
+
try {
|
|
72
|
+
// Bounded by pinArtifact's size limit, plus one byte to detect growth.
|
|
73
|
+
const buffer = Buffer.alloc(pinned.stat.size + 1);
|
|
74
|
+
let offset = 0, count;
|
|
75
|
+
while (offset < buffer.length && (count = readSync(pinned.fd, buffer, offset, buffer.length - offset, offset)) > 0) offset += count;
|
|
76
|
+
bytes = buffer.subarray(0, offset);
|
|
77
|
+
if (`sha256:${createHash('sha256').update(bytes).digest('hex')}` !== result.artifactDigest) {
|
|
78
|
+
throw new Error('artifact digest changed after acceptance; refusing --deliverable');
|
|
79
|
+
}
|
|
80
|
+
} finally { closeSync(pinned.fd); }
|
|
81
|
+
const staging = mkdtempSync(join(parent, '.aiwg-deliver-'));
|
|
82
|
+
try {
|
|
83
|
+
const staged = join(staging, 'artifact');
|
|
84
|
+
writeFileSync(staged, bytes, { flag: 'wx', mode: 0o600 });
|
|
85
|
+
renameSync(staged, destination);
|
|
86
|
+
} finally { rmSync(staging, { recursive: true, force: true }); }
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
export async function verifyWorkerRun(request, dependencies = {}) {
|
|
90
|
+
if (Object.hasOwn(request, 'typedStop')) return deliverTypedStop(request, { prepareRecord: dependencies.prepareRecord ?? prepareDeliveryRecord });
|
|
91
|
+
try { return await verifyWorkerRunRequest(request, dependencies); }
|
|
92
|
+
catch (error) {
|
|
93
|
+
if (!(error instanceof WorkerDeliveryRefusal)) throw error;
|
|
94
|
+
return { status: 'rejected', verifierId: 'trusted-verification@1', runnerRef: new URL('./trusted-verification.mjs', import.meta.url).href,
|
|
95
|
+
artifactDigest: null, evidence: [], findings: [error.message], errorCode: error.code,
|
|
96
|
+
controlledContext: 'publication request refused before protected checks', isolation: { mode: 'n/a', degraded: [] } };
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
async function verifyWorkerRunRequest({ runDir, checks, artifactPath, deliverablePath, checkDescendants = false, projectDir = process.cwd() }, { prepareRecord = prepareDeliveryRecord } = {}) {
|
|
101
|
+
const { inspectWorkerPath: inspect } = await importImpl(import.meta.url, 'serve/worker-invocation-paths.js');
|
|
102
|
+
const record = JSON.parse((await boundedPrivateRead(join(runDir, 'invocation.json'), 1048576, inspect, true, true)).toString('utf8'));
|
|
103
|
+
const worktreeRoot = record.worktree?.path;
|
|
104
|
+
if (deliverablePath) requireDeliveryArtifact(artifactPath, record.paths?.final);
|
|
105
|
+
artifactPath ??= record.paths?.final;
|
|
106
|
+
if (!absolute(worktreeRoot) || !absolute(artifactPath)) throw new Error('Launcher record requires absolute worktree and artifact paths');
|
|
107
|
+
// Independently loaded installed qualifications own writable roots; the record
|
|
108
|
+
// being authenticated cannot declare the only roots used to authenticate it.
|
|
109
|
+
const { loadWorkerInputs } = await importImpl(import.meta.url, 'cli/handlers/models.js');
|
|
110
|
+
const inputs = await loadWorkerInputs({ cwd: projectDir, args: [], rawArgs: [],
|
|
111
|
+
frameworkRoot: fileURLToPath(new URL('../../../', import.meta.url)) });
|
|
112
|
+
const writableRoots = Object.values(inputs.drivers).flatMap(driver => driver.qualification.installation?.workerWritableRoots ?? []);
|
|
113
|
+
if (!writableRoots.length) throw new Error('Trusted worker installation writable roots are required; run verification from the configured conductor project');
|
|
114
|
+
// Reuse the launcher's owned-record and confirmed-stop checks. Never run checks
|
|
115
|
+
// concurrently with a worker, or read check definitions out of worker metadata.
|
|
116
|
+
const exit = deliverablePath ? await readDeliveryExit(runDir, inspect) : null;
|
|
117
|
+
await verifyRetryPredecessor({ runDir, invocationId: record.invocationId }, { inspect, workerWritableRoots: [worktreeRoot, ...writableRoots], checkDescendants });
|
|
118
|
+
const guardArtifact = deliverablePath ? await prepareWorkerDeliveryGuard({ worktreeRoot, artifactPath, finalPath: record.paths?.final, checks, exit, inspect }) : undefined;
|
|
119
|
+
const capabilities = probeVerificationIsolationCapabilities();
|
|
120
|
+
const missing = missingRequiredCapabilities(capabilities);
|
|
121
|
+
const runnerRef = new URL('./trusted-verification.mjs', import.meta.url).href;
|
|
122
|
+
if (capabilities.mode !== 'systemd-unit' || missing.length) {
|
|
123
|
+
return { status: 'blocked', verifierId: 'trusted-verification@1', runnerRef, artifactDigest: null, evidence: [],
|
|
124
|
+
findings: [`ISOLATION_UNAVAILABLE: required verification isolation is unavailable (${missing.join(', ')}); use a host with enforced write/home/network confinement`],
|
|
125
|
+
controlledContext: 'protected checks refused before execution', isolation: { mode: capabilities.mode, degraded: capabilities.degraded }, errorCode: 'ISOLATION_UNAVAILABLE' };
|
|
126
|
+
}
|
|
127
|
+
// CLI arguments are conductor-owned protected definitions. Register exactly
|
|
128
|
+
// their binaries, never a manifest, PATH search, directory or worker claim.
|
|
129
|
+
const result = verifyWorkerArtifact({ worktreeRoot, artifactPath, checks, guardArtifact,
|
|
130
|
+
allowedCheckBinaries: checks.map(check => check.command), runnerRef });
|
|
131
|
+
if (result.status === 'accepted' && deliverablePath) {
|
|
132
|
+
const complete = await prepareRecord(projectDir, { artifactDigest: result.artifactDigest, deliverablePath,
|
|
133
|
+
verifierId: result.verifierId, runDir, invocationId: record.invocationId });
|
|
134
|
+
deliverVerifiedArtifact(result, { artifactPath, deliverablePath, worktreeRoot, writableRoots });
|
|
135
|
+
result.deliveryRecord = await complete();
|
|
136
|
+
}
|
|
137
|
+
return result;
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
export async function runWorkerVerificationCli(args, { stdout = console.log, stderr = console.error } = {}) {
|
|
141
|
+
let result;
|
|
142
|
+
try {
|
|
143
|
+
const request = parseWorkerVerificationArgs(args);
|
|
144
|
+
if (request.deliveryStatus) {
|
|
145
|
+
const delivery = await lookupDeliveryRecord(process.cwd(), request.deliverablePath);
|
|
146
|
+
stdout(args.includes('--json') ? JSON.stringify(delivery) : `Deliverable: ${delivery.verified ? 'verified' : 'unverified'}`);
|
|
147
|
+
return delivery.verified ? 0 : 1;
|
|
148
|
+
}
|
|
149
|
+
result = await verifyWorkerRun(request);
|
|
150
|
+
} catch (error) {
|
|
151
|
+
result = { status: 'rejected', verifierId: 'trusted-verification@1', runnerRef: new URL('./trusted-verification.mjs', import.meta.url).href,
|
|
152
|
+
artifactDigest: null, evidence: [], findings: [error.message], errorCode: 'VERIFICATION_REQUEST_FAILED',
|
|
153
|
+
controlledContext: 'verification request refused', isolation: { mode: 'n/a', degraded: [] } };
|
|
154
|
+
}
|
|
155
|
+
const exitCode = result.status === 'accepted' ? 0 : result.status === 'blocked' ? 2 : 1;
|
|
156
|
+
const output = { version: 1, kind: 'worker-verification', ...result, exitCode };
|
|
157
|
+
if (args.includes('--json')) stdout(JSON.stringify(output));
|
|
158
|
+
else {
|
|
159
|
+
stdout(`Worker verification: ${result.status}`);
|
|
160
|
+
for (const finding of result.findings) stdout(finding);
|
|
161
|
+
}
|
|
162
|
+
if (exitCode) stderr(`Worker verification ${result.status}: ${result.errorCode ?? result.findings.join('; ')}`);
|
|
163
|
+
return exitCode;
|
|
164
|
+
}
|