owenloop 0.5.0 → 0.5.1
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/CHANGELOG.md +45 -0
- package/README.md +137 -35
- package/bin/owenloop.mjs +49 -1
- package/dist/packages/work/src/agent/brief.d.ts +8 -4
- package/dist/packages/work/src/agent/brief.js +7 -3
- package/dist/packages/work/src/agent/loop.d.ts +13 -7
- package/dist/packages/work/src/agent/loop.js +136 -9
- package/dist/packages/work/src/agent/model-policy.d.ts +49 -0
- package/dist/packages/work/src/agent/model-policy.js +138 -0
- package/dist/packages/work/src/bundle/cache.d.ts +7 -5
- package/dist/packages/work/src/bundle/cache.js +20 -6
- package/dist/packages/work/src/bundle/fetch.d.ts +7 -5
- package/dist/packages/work/src/bundle/fetch.js +27 -7
- package/dist/packages/work/src/bundle/types.d.ts +8 -4
- package/dist/packages/work/src/consumed-verifier.d.ts +45 -0
- package/dist/packages/work/src/consumed-verifier.js +205 -0
- package/dist/packages/work/src/exec/instructions.d.ts +99 -0
- package/dist/packages/work/src/exec/instructions.js +323 -0
- package/dist/packages/work/src/exec/loop.d.ts +12 -1
- package/dist/packages/work/src/exec/loop.js +137 -20
- package/dist/packages/work/src/exec/payload.d.ts +29 -0
- package/dist/packages/work/src/exec/payload.js +54 -0
- package/dist/packages/work/src/exec/receipt.d.ts +9 -6
- package/dist/packages/work/src/exec/receipt.js +12 -1
- package/dist/packages/work/src/exec/runner.d.ts +7 -1
- package/dist/packages/work/src/exec/runner.js +74 -3
- package/dist/packages/work/src/harness/child-env.js +7 -0
- package/dist/packages/work/src/harness/claude.d.ts +20 -8
- package/dist/packages/work/src/harness/claude.js +260 -58
- package/dist/packages/work/src/harness/codex.d.ts +5 -4
- package/dist/packages/work/src/harness/codex.js +169 -41
- package/dist/packages/work/src/harness/contract.d.ts +36 -11
- package/dist/packages/work/src/harness/fake.js +1 -0
- package/dist/packages/work/src/harness/jsonrpc-stdio.js +7 -0
- package/dist/packages/work/src/harness/permissions.d.ts +16 -3
- package/dist/packages/work/src/harness/permissions.js +102 -13
- package/dist/packages/work/src/harness/session-store.d.ts +27 -9
- package/dist/packages/work/src/harness/session-store.js +271 -67
- package/dist/packages/work/src/hold/mcp.d.ts +25 -5
- package/dist/packages/work/src/hold/mcp.js +126 -11
- package/dist/packages/work/src/hub/client.d.ts +2 -1
- package/dist/packages/work/src/hub/client.js +14 -1
- package/dist/packages/work/src/hub/types.d.ts +69 -33
- package/dist/packages/work/src/hub/types.js +8 -10
- package/dist/packages/work/src/mcp/server.js +1 -1
- package/dist/packages/work/src/owenloop-bin.d.ts +1 -0
- package/dist/packages/work/src/owenloop-bin.js +18 -0
- package/dist/packages/work/src/roles/agent-run.d.ts +12 -6
- package/dist/packages/work/src/roles/agent-run.js +116 -34
- package/dist/packages/work/src/roles/exec.d.ts +8 -0
- package/dist/packages/work/src/roles/exec.js +27 -2
- package/dist/packages/work/src/roles/hold.d.ts +4 -0
- package/dist/packages/work/src/roles/hold.js +44 -5
- package/dist/packages/work/src/roles/lint.d.ts +3 -4
- package/dist/packages/work/src/roles/lint.js +41 -7
- package/dist/packages/work/src/roles/settings.js +5 -0
- package/dist/packages/work/src/roles/shift.d.ts +1 -0
- package/dist/packages/work/src/roles/shift.js +23 -1
- package/dist/packages/work/src/settings/settings.d.ts +17 -1
- package/dist/packages/work/src/settings/settings.js +39 -0
- package/dist/packages/work/src/shift/loop.d.ts +14 -3
- package/dist/packages/work/src/shift/loop.js +447 -164
- package/dist/packages/work/src/shift/protocol.d.ts +4 -0
- package/dist/packages/work/src/shift/runtime.d.ts +2 -0
- package/dist/packages/work/src/shift/runtime.js +66 -3
- package/dist/packages/work/src/shift/spawn.d.ts +41 -18
- package/dist/packages/work/src/shift/spawn.js +89 -31
- package/dist/packages/work/src/shift/state.d.ts +53 -51
- package/dist/packages/work/src/shift/state.js +325 -102
- package/dist/packages/work/src/submit-proof.d.ts +36 -0
- package/dist/packages/work/src/submit-proof.js +93 -0
- package/dist/src/add.d.ts +64 -259
- package/dist/src/add.js +81 -615
- package/dist/src/archive.d.ts +97 -0
- package/dist/src/archive.js +591 -0
- package/dist/src/bundle/index.d.ts +64 -0
- package/dist/src/bundle/index.js +508 -0
- package/dist/src/bundle/manifest.d.ts +50 -0
- package/dist/src/bundle/manifest.js +435 -0
- package/dist/src/bundle/runtime.d.ts +26 -0
- package/dist/src/bundle/runtime.js +64 -0
- package/dist/src/bundle/tar.d.ts +62 -0
- package/dist/src/bundle/tar.js +238 -0
- package/dist/src/bundle/types.d.ts +105 -0
- package/dist/src/bundle/types.js +21 -0
- package/dist/src/cli.d.ts +90 -20
- package/dist/src/cli.js +2407 -365
- package/dist/src/credentials.d.ts +4 -3
- package/dist/src/credentials.js +21 -19
- package/dist/src/crypto/allowed-signers.d.ts +68 -0
- package/dist/src/crypto/allowed-signers.js +307 -0
- package/dist/src/crypto/canonical.d.ts +8 -0
- package/dist/src/crypto/canonical.js +92 -0
- package/dist/src/crypto/chain.d.ts +65 -0
- package/dist/src/crypto/chain.js +377 -0
- package/dist/src/crypto/dsse.d.ts +209 -0
- package/dist/src/crypto/dsse.js +282 -0
- package/dist/src/crypto/enrollment.d.ts +78 -0
- package/dist/src/crypto/enrollment.js +186 -0
- package/dist/src/crypto/index.d.ts +48 -0
- package/dist/src/crypto/index.js +44 -0
- package/dist/src/crypto/keys.d.ts +258 -0
- package/dist/src/crypto/keys.js +908 -0
- package/dist/src/crypto/org-root.d.ts +33 -0
- package/dist/src/crypto/org-root.js +78 -0
- package/dist/src/crypto/origin-rules.d.ts +56 -0
- package/dist/src/crypto/origin-rules.js +143 -0
- package/dist/src/crypto/policy-floor.d.ts +98 -0
- package/dist/src/crypto/policy-floor.js +353 -0
- package/dist/src/crypto/records.d.ts +316 -0
- package/dist/src/crypto/records.js +157 -0
- package/dist/src/crypto/scope.d.ts +49 -0
- package/dist/src/crypto/scope.js +83 -0
- package/dist/src/crypto/ssh.d.ts +171 -0
- package/dist/src/crypto/ssh.js +396 -0
- package/dist/src/crypto/submission.d.ts +33 -0
- package/dist/src/crypto/submission.js +47 -0
- package/dist/src/crypto/trust-roots.d.ts +29 -0
- package/dist/src/crypto/trust-roots.js +39 -0
- package/dist/src/crypto/verify-consumed.d.ts +67 -0
- package/dist/src/crypto/verify-consumed.js +259 -0
- package/dist/src/crypto/verify-origin.d.ts +50 -0
- package/dist/src/crypto/verify-origin.js +151 -0
- package/dist/src/crypto/verify-publication.d.ts +60 -0
- package/dist/src/crypto/verify-publication.js +150 -0
- package/dist/src/defs.d.ts +24 -1
- package/dist/src/defs.js +145 -25
- package/dist/src/engine.d.ts +99 -3
- package/dist/src/engine.js +238 -34
- package/dist/src/factory.d.ts +16 -0
- package/dist/src/factory.js +16 -4
- package/dist/src/global-config.d.ts +59 -0
- package/dist/src/global-config.js +84 -0
- package/dist/src/hub.d.ts +75 -21
- package/dist/src/hub.js +123 -40
- package/dist/src/index.d.ts +17 -2
- package/dist/src/index.js +20 -2
- package/dist/src/install.d.ts +538 -0
- package/dist/src/install.js +1981 -0
- package/dist/src/lock.d.ts +15 -57
- package/dist/src/lock.js +251 -143
- package/dist/src/mcp/serve.d.ts +46 -22
- package/dist/src/mcp/serve.js +167 -44
- package/dist/src/mcp/server.js +12 -1
- package/dist/src/model.d.ts +15 -0
- package/dist/src/model.js +111 -1
- package/dist/src/order-resolver.d.ts +184 -0
- package/dist/src/order-resolver.js +252 -0
- package/dist/src/package-version.d.ts +10 -0
- package/dist/src/package-version.js +42 -0
- package/dist/src/paths.d.ts +14 -1
- package/dist/src/paths.js +18 -0
- package/dist/src/schemas/enrollment-grant.v1.schema.json +90 -0
- package/dist/src/schemas/index.d.ts +1416 -0
- package/dist/src/schemas/index.js +31 -0
- package/dist/src/schemas/order.v1.schema.json +106 -0
- package/dist/src/schemas/origin.v1.schema.json +68 -0
- package/dist/src/schemas/policy-floor.v1.schema.json +29 -0
- package/dist/src/schemas/publication.v1.schema.json +31 -0
- package/dist/src/schemas/revocation.v1.schema.json +39 -0
- package/dist/src/schemas/submission.v1.schema.json +61 -0
- package/dist/src/store/def-source.d.ts +52 -0
- package/dist/src/store/def-source.js +335 -0
- package/dist/src/store/index-file.d.ts +69 -0
- package/dist/src/store/index-file.js +151 -0
- package/dist/src/store/index.d.ts +27 -0
- package/dist/src/store/index.js +22 -0
- package/dist/src/store/ingestor.d.ts +43 -0
- package/dist/src/store/ingestor.js +211 -0
- package/dist/src/store/install.d.ts +228 -0
- package/dist/src/store/install.js +555 -0
- package/dist/src/store/instruction-source.d.ts +49 -0
- package/dist/src/store/instruction-source.js +298 -0
- package/dist/src/store/origin-evidence.d.ts +21 -0
- package/dist/src/store/origin-evidence.js +66 -0
- package/dist/src/store/pre-commit-verifier.d.ts +68 -0
- package/dist/src/store/pre-commit-verifier.js +418 -0
- package/dist/src/store/resolve.d.ts +138 -0
- package/dist/src/store/resolve.js +363 -0
- package/dist/src/store/types.d.ts +288 -0
- package/dist/src/store/types.js +356 -0
- package/dist/src/types.d.ts +45 -11
- package/dist/src/untar.d.ts +8 -23
- package/dist/src/untar.js +10 -136
- package/docs/agent-runner.md +86 -0
- package/docs/authoring.md +57 -6
- package/docs/bundles.md +250 -0
- package/docs/cli.md +1171 -97
- package/docs/crypto.md +816 -0
- package/docs/design.md +342 -20
- package/docs/embedding.md +132 -25
- package/docs/wire-contracts.md +380 -0
- package/package.json +6 -1
- package/plugins/claude-code/.claude-plugin/marketplace.json +14 -0
- package/plugins/claude-code/plugin/.claude-plugin/plugin.json +8 -0
- package/plugins/claude-code/plugin/.mcp.json +14 -0
- package/plugins/claude-code/plugin/hooks/hooks.json +26 -0
- package/plugins/claude-code/plugin/hooks/session-end.sh +40 -0
- package/plugins/claude-code/plugin/hooks/session-start.sh +52 -0
- package/plugins/claude-code/plugin/skills/author/SKILL.md +181 -0
- package/plugins/claude-code/plugin/skills/conduct/SKILL.md +106 -0
- package/plugins/claude-code/plugin/skills/shift/SKILL.md +105 -0
- package/plugins/codex/.agents/plugins/marketplace.json +21 -0
- package/plugins/codex/plugins/owenloop/.codex-plugin/plugin.json +7 -0
- package/plugins/codex/plugins/owenloop/.mcp.json +20 -0
- package/plugins/codex/plugins/owenloop/hooks/hooks.json +26 -0
- package/plugins/codex/plugins/owenloop/hooks/session-end.sh +40 -0
- package/plugins/codex/plugins/owenloop/hooks/session-start.sh +52 -0
- package/plugins/codex/plugins/owenloop/skills/author/SKILL.md +181 -0
- package/plugins/codex/plugins/owenloop/skills/conduct/SKILL.md +106 -0
- package/plugins/codex/plugins/owenloop/skills/shift/SKILL.md +105 -0
|
@@ -0,0 +1,205 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Driver-side binding for consume-side artifact verification.
|
|
3
|
+
*
|
|
4
|
+
* This module resolves local trust material from injected environment state and
|
|
5
|
+
* gates a complete order before the order reaches an agent prompt or command
|
|
6
|
+
* execution. A failed path refuses the whole order; the gate never removes only
|
|
7
|
+
* the offending value and continues with a partial packet.
|
|
8
|
+
*/
|
|
9
|
+
import { mergePolicyFloorWithLocal, } from "../../../src/crypto/policy-floor.js";
|
|
10
|
+
import { resolveArtifactPolicy, } from "../../../src/store/pre-commit-verifier.js";
|
|
11
|
+
import { loadRevocations, loadRoster, resolveOrgRoot, } from "../../../src/crypto/org-root.js";
|
|
12
|
+
import { verifyConsumed, } from "../../../src/crypto/verify-consumed.js";
|
|
13
|
+
import { validateProducer } from "../../../src/crypto/chain.js";
|
|
14
|
+
/** Missing-org-root warnings are intentionally latched once per order process-wide. */
|
|
15
|
+
const warnedMissingOrgRootOrders = new Set();
|
|
16
|
+
function errorText(error) {
|
|
17
|
+
return error instanceof Error ? error.message : String(error);
|
|
18
|
+
}
|
|
19
|
+
function linkFor(verdict) {
|
|
20
|
+
const match = verdict.reason.match(/^(no-proof|signature|value-digest|version|chain|scope|prerequisite):/);
|
|
21
|
+
if (match !== null)
|
|
22
|
+
return match[1];
|
|
23
|
+
return verdict.kind === 'invalid' ? 'signature' : 'prerequisite';
|
|
24
|
+
}
|
|
25
|
+
function detailFor(verdict) {
|
|
26
|
+
if (verdict.kind === 'verified')
|
|
27
|
+
return 'verified';
|
|
28
|
+
if (verdict.kind === 'absent')
|
|
29
|
+
return 'no proof was supplied';
|
|
30
|
+
const colon = verdict.reason.indexOf(':');
|
|
31
|
+
return colon === -1 ? verdict.reason : verdict.reason.slice(colon + 1).trim();
|
|
32
|
+
}
|
|
33
|
+
function refusal(order, link, path, detail) {
|
|
34
|
+
return {
|
|
35
|
+
ok: false,
|
|
36
|
+
reason: `consumed artifact refusal (${link}) for ${order.workflow}/${order.run} step '${order.step}' artifact '${path}': ${detail}`,
|
|
37
|
+
};
|
|
38
|
+
}
|
|
39
|
+
function policyOutcome(order, hardRule, policy, path, verdict, warnings) {
|
|
40
|
+
if (verdict.kind === 'verified')
|
|
41
|
+
return undefined;
|
|
42
|
+
const link = verdict.kind === 'absent' ? 'no-proof' : linkFor(verdict);
|
|
43
|
+
const detail = detailFor(verdict);
|
|
44
|
+
const mustRefuse = verdict.kind === 'invalid' || hardRule || policy === 'enforce';
|
|
45
|
+
if (mustRefuse)
|
|
46
|
+
return refusal(order, link, path, detail);
|
|
47
|
+
if (policy === 'warn') {
|
|
48
|
+
const missingOrgRoot = verdict.kind === 'unverifiable'
|
|
49
|
+
&& verdict.reason === 'prerequisite: no org-root anchor is configured';
|
|
50
|
+
const orderKey = `${order.workflow}/${order.run}`;
|
|
51
|
+
if (!missingOrgRoot || !warnedMissingOrgRootOrders.has(orderKey)) {
|
|
52
|
+
warnings.push(`consumed artifact warning (${link}) for ${order.workflow}/${order.run} step '${order.step}' artifact '${path}': ${detail}`);
|
|
53
|
+
if (missingOrgRoot)
|
|
54
|
+
warnedMissingOrgRootOrders.add(orderKey);
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
return undefined;
|
|
58
|
+
}
|
|
59
|
+
function parseProofMap(order) {
|
|
60
|
+
if (order.consumesProof === undefined)
|
|
61
|
+
return { kind: 'ok', proofs: {} };
|
|
62
|
+
if (typeof order.consumesProof !== 'string') {
|
|
63
|
+
return { kind: 'unverifiable', reason: 'prerequisite: consumesProof is not a JSON string' };
|
|
64
|
+
}
|
|
65
|
+
let parsed;
|
|
66
|
+
try {
|
|
67
|
+
parsed = JSON.parse(order.consumesProof);
|
|
68
|
+
}
|
|
69
|
+
catch {
|
|
70
|
+
return { kind: 'unverifiable', reason: 'prerequisite: consumesProof is not valid JSON' };
|
|
71
|
+
}
|
|
72
|
+
if (typeof parsed !== 'object' || parsed === null || Array.isArray(parsed)) {
|
|
73
|
+
return { kind: 'unverifiable', reason: 'prerequisite: consumesProof is not a JSON object' };
|
|
74
|
+
}
|
|
75
|
+
const proofs = {};
|
|
76
|
+
for (const [path, value] of Object.entries(parsed)) {
|
|
77
|
+
if (typeof value !== 'string' || value === '') {
|
|
78
|
+
return { kind: 'unverifiable', reason: `prerequisite: consumesProof entry for artifact '${path}' is not a non-empty string` };
|
|
79
|
+
}
|
|
80
|
+
proofs[path] = value;
|
|
81
|
+
}
|
|
82
|
+
return { kind: 'ok', proofs };
|
|
83
|
+
}
|
|
84
|
+
/** Create a verifier bound to one injected local environment and clock. */
|
|
85
|
+
export function createConsumedVerifier(args) {
|
|
86
|
+
const policy = mergePolicyFloorWithLocal('off', args.policyFloor, 'off', resolveArtifactPolicy(args.env, args.artifactPolicy)).artifactPolicy;
|
|
87
|
+
return async (order, opts) => {
|
|
88
|
+
if (Object.keys(order.consumes).length === 0 && order.owes.every((owed) => owed.reasons.length === 0 && owed.proof === undefined)) {
|
|
89
|
+
return { ok: true, order, warnings: [] };
|
|
90
|
+
}
|
|
91
|
+
// One consumer-owned clock sample governs every path in this gate call.
|
|
92
|
+
// Revocation is evaluated at consume time; a later per-path sample would
|
|
93
|
+
// make one order internally inconsistent and defeat the cache key below.
|
|
94
|
+
const at = args.now();
|
|
95
|
+
let root;
|
|
96
|
+
let grants;
|
|
97
|
+
let revocations;
|
|
98
|
+
try {
|
|
99
|
+
root = resolveOrgRoot(args.env);
|
|
100
|
+
grants = loadRoster(args.env);
|
|
101
|
+
revocations = loadRevocations(args.env);
|
|
102
|
+
}
|
|
103
|
+
catch (error) {
|
|
104
|
+
const reason = `prerequisite: local producer trust material could not be loaded: ${errorText(error)}`;
|
|
105
|
+
const warnings = [];
|
|
106
|
+
for (const path of Object.keys(order.consumes)) {
|
|
107
|
+
const result = policyOutcome(order, opts.hardRule, policy, path, { kind: 'unverifiable', reason }, warnings);
|
|
108
|
+
if (result !== undefined)
|
|
109
|
+
return result;
|
|
110
|
+
}
|
|
111
|
+
for (const owed of order.owes) {
|
|
112
|
+
if (owed.reasons.length === 0 && owed.proof === undefined)
|
|
113
|
+
continue;
|
|
114
|
+
const result = policyOutcome(order, opts.hardRule, policy, owed.path, { kind: 'unverifiable', reason }, warnings);
|
|
115
|
+
if (result !== undefined)
|
|
116
|
+
return result;
|
|
117
|
+
}
|
|
118
|
+
return { ok: true, order, warnings };
|
|
119
|
+
}
|
|
120
|
+
const prerequisite = root.kind === 'absent'
|
|
121
|
+
? 'prerequisite: no org-root anchor is configured'
|
|
122
|
+
: undefined;
|
|
123
|
+
const rootPublicKey = root.kind === 'present' ? root.publicKey : '';
|
|
124
|
+
const proofs = parseProofMap(order);
|
|
125
|
+
const warnings = [];
|
|
126
|
+
const chainCache = new Map();
|
|
127
|
+
const chainValidator = (input, options) => {
|
|
128
|
+
const cacheKey = JSON.stringify([input.targetKeyId, input.at]);
|
|
129
|
+
const cached = chainCache.get(cacheKey);
|
|
130
|
+
if (cached !== undefined)
|
|
131
|
+
return cached;
|
|
132
|
+
const pending = validateProducer(input, options);
|
|
133
|
+
chainCache.set(cacheKey, pending);
|
|
134
|
+
return pending;
|
|
135
|
+
};
|
|
136
|
+
const verifierOptions = {
|
|
137
|
+
...(args.signerForPrincipal === undefined ? {} : { signerForPrincipal: args.signerForPrincipal }),
|
|
138
|
+
...(args.namespace === undefined ? {} : { namespace: args.namespace }),
|
|
139
|
+
...(args.maxChainDepth === undefined ? {} : { maxChainDepth: args.maxChainDepth }),
|
|
140
|
+
chainValidator,
|
|
141
|
+
warn: (line) => {
|
|
142
|
+
warnings.push(line);
|
|
143
|
+
},
|
|
144
|
+
};
|
|
145
|
+
for (const [path, value] of Object.entries(order.consumes)) {
|
|
146
|
+
let verdict;
|
|
147
|
+
if (prerequisite !== undefined) {
|
|
148
|
+
verdict = { kind: 'unverifiable', reason: prerequisite };
|
|
149
|
+
}
|
|
150
|
+
else if (proofs.kind === 'unverifiable') {
|
|
151
|
+
verdict = { kind: 'unverifiable', reason: proofs.reason };
|
|
152
|
+
}
|
|
153
|
+
else {
|
|
154
|
+
verdict = await verifyConsumed({
|
|
155
|
+
path,
|
|
156
|
+
value,
|
|
157
|
+
...(proofs.proofs[path] === undefined ? {} : { proof: proofs.proofs[path] }),
|
|
158
|
+
...(order.consumedFingerprint?.[path] === undefined ? {} : { expectedVersion: order.consumedFingerprint[path] }),
|
|
159
|
+
orgRootPublicKey: rootPublicKey,
|
|
160
|
+
grants,
|
|
161
|
+
revocations,
|
|
162
|
+
at,
|
|
163
|
+
demand: args.demand ?? {},
|
|
164
|
+
}, verifierOptions);
|
|
165
|
+
}
|
|
166
|
+
const result = policyOutcome(order, opts.hardRule, policy, path, verdict, warnings);
|
|
167
|
+
if (result !== undefined)
|
|
168
|
+
return result;
|
|
169
|
+
}
|
|
170
|
+
for (const owed of order.owes) {
|
|
171
|
+
if (owed.reasons.length === 0 && owed.proof === undefined)
|
|
172
|
+
continue;
|
|
173
|
+
let verdict;
|
|
174
|
+
if (prerequisite !== undefined) {
|
|
175
|
+
verdict = { kind: 'unverifiable', reason: prerequisite };
|
|
176
|
+
}
|
|
177
|
+
else if (proofs.kind === 'unverifiable') {
|
|
178
|
+
verdict = { kind: 'unverifiable', reason: proofs.reason };
|
|
179
|
+
}
|
|
180
|
+
else {
|
|
181
|
+
verdict = await verifyConsumed({
|
|
182
|
+
path: owed.path,
|
|
183
|
+
value: owed.reasons,
|
|
184
|
+
...(owed.proof === undefined ? {} : { proof: owed.proof }),
|
|
185
|
+
...(owed.version === undefined ? {} : { expectedVersion: owed.version }),
|
|
186
|
+
orgRootPublicKey: rootPublicKey,
|
|
187
|
+
grants,
|
|
188
|
+
revocations,
|
|
189
|
+
at,
|
|
190
|
+
demand: args.demand ?? {},
|
|
191
|
+
}, verifierOptions);
|
|
192
|
+
}
|
|
193
|
+
const result = policyOutcome(order, opts.hardRule, policy, owed.path, verdict, warnings);
|
|
194
|
+
if (result !== undefined)
|
|
195
|
+
return result;
|
|
196
|
+
}
|
|
197
|
+
const deduped = [...new Set(warnings)];
|
|
198
|
+
for (const warning of deduped)
|
|
199
|
+
args.warn?.(warning);
|
|
200
|
+
return { ok: true, order, warnings: deduped };
|
|
201
|
+
};
|
|
202
|
+
}
|
|
203
|
+
export function resetConsumedVerifierWarningsForTests() {
|
|
204
|
+
warnedMissingOrgRootOrders.clear();
|
|
205
|
+
}
|
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Driver-side instruction resolution.
|
|
3
|
+
*
|
|
4
|
+
* A worker packet is a reference packet. The packet's `defDigest` selects
|
|
5
|
+
* instruction bytes from a verified local workflow-store object; command text,
|
|
6
|
+
* prompt text, and step metadata supplied by a remote coordinator are never
|
|
7
|
+
* authoritative. The command resolver returns the exact authored command and
|
|
8
|
+
* does not perform placeholder substitution.
|
|
9
|
+
*/
|
|
10
|
+
import type { BundleIngestor, StoreInstructionSource } from '../../../../src/store/index.ts';
|
|
11
|
+
import type { StepDef, WorkflowDef } from '../../../../src/types.ts';
|
|
12
|
+
import type { DefPolicy, DefVerdict } from '../../../../src/crypto/verify-publication.ts';
|
|
13
|
+
import type { OriginRules } from '../../../../src/crypto/origin-rules.ts';
|
|
14
|
+
import type { OriginVerdict } from '../../../../src/crypto/verify-origin.ts';
|
|
15
|
+
import type { PolicyFloor } from '../../../../src/crypto/records.ts';
|
|
16
|
+
import type { OrderPacket } from '../hub/types.ts';
|
|
17
|
+
import type { ConsumedVerifier } from '../consumed-verifier.ts';
|
|
18
|
+
export type InstructionRefusalKind = 'unknown-digest' | 'unknown-step' | 'ambiguous-step' | 'integrity' | 'no-digest' | 'missing-command' | 'unverified-def' | 'origin-policy' | 'unverified-consumed';
|
|
19
|
+
export interface InstructionRefusal {
|
|
20
|
+
ok: false;
|
|
21
|
+
reason: string;
|
|
22
|
+
kind: InstructionRefusalKind;
|
|
23
|
+
}
|
|
24
|
+
export interface ResolvedCommand {
|
|
25
|
+
ok: true;
|
|
26
|
+
command: string;
|
|
27
|
+
/** Verified installed bundle root, when resolution has bundle provenance. */
|
|
28
|
+
bundleDir?: string;
|
|
29
|
+
}
|
|
30
|
+
export interface ResolvedStep {
|
|
31
|
+
ok: true;
|
|
32
|
+
step: StepDef;
|
|
33
|
+
/** Verified installed bundle root, when resolution has bundle provenance. */
|
|
34
|
+
bundleDir?: string;
|
|
35
|
+
}
|
|
36
|
+
export interface InstructionResolver {
|
|
37
|
+
resolveCommand(order: OrderPacket): Promise<ResolvedCommand | InstructionRefusal>;
|
|
38
|
+
resolveStep(order: OrderPacket): Promise<ResolvedStep | InstructionRefusal>;
|
|
39
|
+
}
|
|
40
|
+
export interface DefinitionVerifierInput {
|
|
41
|
+
defDigest: string;
|
|
42
|
+
definition: WorkflowDef;
|
|
43
|
+
step: StepDef;
|
|
44
|
+
/** Bundle digest and installed object path used to locate publication evidence. */
|
|
45
|
+
bundleDigest: string;
|
|
46
|
+
objectPath: string;
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* Execution-time trust check. The verifier is called after the store has
|
|
50
|
+
* re-verified the installed bytes and before instruction text is returned.
|
|
51
|
+
* Returning a verdict keeps unsigned/unverifiable distinct from an invalid
|
|
52
|
+
* present signature; throwing is treated as an integrity-style refusal.
|
|
53
|
+
*/
|
|
54
|
+
export type DefinitionVerifier = (input: DefinitionVerifierInput) => Promise<DefVerdict> | DefVerdict;
|
|
55
|
+
/** Execution-time origin verifier bound to installed bundle evidence. */
|
|
56
|
+
export interface OriginVerifierInput {
|
|
57
|
+
bundleDigest: string;
|
|
58
|
+
objectPath: string;
|
|
59
|
+
}
|
|
60
|
+
export type OriginVerifier = (input: OriginVerifierInput) => Promise<OriginVerdict> | OriginVerdict;
|
|
61
|
+
export interface StoreInstructionResolverOptions {
|
|
62
|
+
projectRoot?: string;
|
|
63
|
+
globalRoot: string;
|
|
64
|
+
verifier: BundleIngestor;
|
|
65
|
+
source?: StoreInstructionSource;
|
|
66
|
+
/** Optional execution-time publication verifier. Omitted means publication trust is unverifiable and command orders refuse. */
|
|
67
|
+
definitionVerifier?: DefinitionVerifier;
|
|
68
|
+
/** Optional execution-time origin verifier. */
|
|
69
|
+
originVerifier?: OriginVerifier;
|
|
70
|
+
/** Gate dynamic consumed values before a command can reach the shell. */
|
|
71
|
+
consumedVerifier?: ConsumedVerifier;
|
|
72
|
+
/** Explicit publication policy override; otherwise env > settings file > warn. */
|
|
73
|
+
defPolicy?: DefPolicy;
|
|
74
|
+
/** Explicit origin policy override; otherwise env > settings file > warn. */
|
|
75
|
+
originPolicy?: DefPolicy;
|
|
76
|
+
/** Explicit namespace-scoped origin rules. */
|
|
77
|
+
originRules?: OriginRules;
|
|
78
|
+
/** Already-verified organization floor; absent means local policy only. */
|
|
79
|
+
policyFloor?: PolicyFloor;
|
|
80
|
+
/** Diagnostic sink for `defPolicy=warn` and `originPolicy=warn`. Defaults to stderr. */
|
|
81
|
+
warn?: (line: string) => void;
|
|
82
|
+
/** Injected environment used for policy resolution. */
|
|
83
|
+
env?: Record<string, string | undefined>;
|
|
84
|
+
}
|
|
85
|
+
export declare function createStoreInstructionResolver(options: StoreInstructionResolverOptions): InstructionResolver;
|
|
86
|
+
/** Build the production resolver from injected process environment and cwd. */
|
|
87
|
+
export declare function createDefaultStoreInstructionResolver(args: {
|
|
88
|
+
cwd: string;
|
|
89
|
+
env: Record<string, string | undefined>;
|
|
90
|
+
verifier?: BundleIngestor;
|
|
91
|
+
definitionVerifier?: DefinitionVerifier;
|
|
92
|
+
originVerifier?: OriginVerifier;
|
|
93
|
+
consumedVerifier?: ConsumedVerifier;
|
|
94
|
+
defPolicy?: DefPolicy;
|
|
95
|
+
originPolicy?: DefPolicy;
|
|
96
|
+
originRules?: OriginRules;
|
|
97
|
+
policyFloor?: PolicyFloor;
|
|
98
|
+
warn?: (line: string) => void;
|
|
99
|
+
}): InstructionResolver;
|
|
@@ -0,0 +1,323 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Driver-side instruction resolution.
|
|
3
|
+
*
|
|
4
|
+
* A worker packet is a reference packet. The packet's `defDigest` selects
|
|
5
|
+
* instruction bytes from a verified local workflow-store object; command text,
|
|
6
|
+
* prompt text, and step metadata supplied by a remote coordinator are never
|
|
7
|
+
* authoritative. The command resolver returns the exact authored command and
|
|
8
|
+
* does not perform placeholder substitution.
|
|
9
|
+
*/
|
|
10
|
+
import { join } from 'node:path';
|
|
11
|
+
import { createBundleIngestor, createStoreInstructionSource } from "../../../../src/store/index.js";
|
|
12
|
+
import { readWorkflowStoreIndex } from "../../../../src/store/index-file.js";
|
|
13
|
+
import { projectStoreRoot, probeStoreRoot, storeIndexPath, globalStoreRoot } from "../../../../src/store/resolve.js";
|
|
14
|
+
import { compareStoreText, parseWorkflowCoordinate } from "../../../../src/store/types.js";
|
|
15
|
+
import { evaluateOriginRule, matchOriginRule } from "../../../../src/crypto/origin-rules.js";
|
|
16
|
+
import { mergePolicyFloorWithLocal } from "../../../../src/crypto/policy-floor.js";
|
|
17
|
+
import { createExecutionDefinitionVerifier, createExecutionOriginVerifier, resolveDefPolicy, resolveOriginPolicy, resolveArtifactPolicy, resolveOriginRules, } from "../../../../src/store/pre-commit-verifier.js";
|
|
18
|
+
function errorText(error) {
|
|
19
|
+
return error instanceof Error ? error.message : String(error);
|
|
20
|
+
}
|
|
21
|
+
function refusal(kind, order, detail) {
|
|
22
|
+
const digest = order.defDigest === undefined || order.defDigest === '' ? '<missing>' : order.defDigest;
|
|
23
|
+
return {
|
|
24
|
+
ok: false,
|
|
25
|
+
kind,
|
|
26
|
+
reason: `instruction refusal (${kind}) for ${order.workflow}/${order.run} step '${order.step}' defDigest '${digest}': ${detail}`,
|
|
27
|
+
};
|
|
28
|
+
}
|
|
29
|
+
function digestFor(order) {
|
|
30
|
+
if (typeof order.defDigest !== 'string' || order.defDigest.trim() === '') {
|
|
31
|
+
return refusal('no-digest', order, 'the order has no non-empty defDigest');
|
|
32
|
+
}
|
|
33
|
+
return order.defDigest;
|
|
34
|
+
}
|
|
35
|
+
function verdictDescription(verdict) {
|
|
36
|
+
if (verdict.kind === 'verified')
|
|
37
|
+
return 'definition is verified';
|
|
38
|
+
if (verdict.kind === 'unsigned')
|
|
39
|
+
return 'unsigned: definition has no publication signature';
|
|
40
|
+
return `${verdict.kind}: ${verdict.reason}`;
|
|
41
|
+
}
|
|
42
|
+
export function createStoreInstructionResolver(options) {
|
|
43
|
+
const source = options.source ?? createStoreInstructionSource({
|
|
44
|
+
projectRoot: options.projectRoot,
|
|
45
|
+
globalRoot: options.globalRoot,
|
|
46
|
+
verifier: options.verifier,
|
|
47
|
+
});
|
|
48
|
+
const env = options.env ?? {};
|
|
49
|
+
let mergedPolicies;
|
|
50
|
+
const readPolicies = () => {
|
|
51
|
+
mergedPolicies ??= mergePolicyFloorWithLocal(resolveDefPolicy(env, options.defPolicy), options.policyFloor, resolveOriginPolicy(env, options.originPolicy), resolveArtifactPolicy(env));
|
|
52
|
+
return mergedPolicies;
|
|
53
|
+
};
|
|
54
|
+
const readPolicy = () => readPolicies().effective;
|
|
55
|
+
const readOriginPolicy = () => readPolicies().originPolicy;
|
|
56
|
+
let originRules;
|
|
57
|
+
const readOriginRules = () => {
|
|
58
|
+
originRules ??= resolveOriginRules(env, options.originRules);
|
|
59
|
+
return originRules;
|
|
60
|
+
};
|
|
61
|
+
const warn = options.warn ?? ((line) => void console.error(line));
|
|
62
|
+
const resolveVerifiedStep = async (order) => {
|
|
63
|
+
const digest = digestFor(order);
|
|
64
|
+
if (typeof digest !== 'string')
|
|
65
|
+
return digest;
|
|
66
|
+
try {
|
|
67
|
+
const primed = await source.prime(digest);
|
|
68
|
+
if (primed === 'unknown-digest') {
|
|
69
|
+
return refusal('unknown-digest', order, 'no verified local workflow bundle matches the order digest');
|
|
70
|
+
}
|
|
71
|
+
const lookup = source.lookup({ defDigest: digest, step: order.step, key: order.key });
|
|
72
|
+
if (lookup.status === 'unknown-digest') {
|
|
73
|
+
return refusal('integrity', order, 'the primed workflow digest disappeared before instruction lookup');
|
|
74
|
+
}
|
|
75
|
+
if (lookup.status === 'unknown-step') {
|
|
76
|
+
return refusal('unknown-step', order, 'the verified workflow definition has no matching step');
|
|
77
|
+
}
|
|
78
|
+
if (lookup.status === 'ambiguous-step') {
|
|
79
|
+
return refusal('ambiguous-step', order, 'multiple workflows in the verified bundle define the requested step');
|
|
80
|
+
}
|
|
81
|
+
const step = source.getVerifiedStep(digest, order.step);
|
|
82
|
+
if (step === undefined) {
|
|
83
|
+
return refusal('integrity', order, 'the resolved workflow step is unavailable after instruction lookup');
|
|
84
|
+
}
|
|
85
|
+
const definition = source.getVerifiedDefinition(digest, order.step);
|
|
86
|
+
if (definition === undefined)
|
|
87
|
+
return refusal('integrity', order, 'the verified workflow definition is unavailable after priming');
|
|
88
|
+
const object = source.getVerifiedObject(digest);
|
|
89
|
+
if (object === undefined)
|
|
90
|
+
return refusal('integrity', order, 'the verified workflow object metadata is unavailable after priming');
|
|
91
|
+
return { ok: true, definition, step, bundleDigest: object.bundleDigest, objectPath: object.objectPath };
|
|
92
|
+
}
|
|
93
|
+
catch (error) {
|
|
94
|
+
return refusal('integrity', order, errorText(error));
|
|
95
|
+
}
|
|
96
|
+
};
|
|
97
|
+
const trustFor = async (order, resolved) => {
|
|
98
|
+
if (options.definitionVerifier === undefined) {
|
|
99
|
+
return { kind: 'unverifiable', reason: 'execution-time publication verifier is not configured' };
|
|
100
|
+
}
|
|
101
|
+
try {
|
|
102
|
+
return await options.definitionVerifier({ defDigest: order.defDigest, definition: resolved.definition, step: resolved.step, bundleDigest: resolved.bundleDigest, objectPath: resolved.objectPath });
|
|
103
|
+
}
|
|
104
|
+
catch (error) {
|
|
105
|
+
return { kind: 'unverifiable', reason: errorText(error) };
|
|
106
|
+
}
|
|
107
|
+
};
|
|
108
|
+
const refuseUnverified = (order, verdict) => refusal('unverified-def', order, verdictDescription(verdict));
|
|
109
|
+
const recoverOriginRule = (bundleDigest, rules) => {
|
|
110
|
+
const roots = [
|
|
111
|
+
options.projectRoot === undefined ? undefined : projectStoreRoot(options.projectRoot),
|
|
112
|
+
projectStoreRoot(options.globalRoot),
|
|
113
|
+
].filter((root) => root !== undefined);
|
|
114
|
+
const uniqueRoots = [...new Set(roots)];
|
|
115
|
+
const entries = [];
|
|
116
|
+
let foundCoordinate = false;
|
|
117
|
+
for (const root of uniqueRoots) {
|
|
118
|
+
if (probeStoreRoot(root) !== 'dir')
|
|
119
|
+
continue;
|
|
120
|
+
const index = readWorkflowStoreIndex(storeIndexPath(root));
|
|
121
|
+
// Sorted, not index key order: `entries[0]` below supplies the rule KEY
|
|
122
|
+
// named in the refusal message, and the whole list is joined into the
|
|
123
|
+
// ambiguity message. Both would otherwise vary with JSON key order.
|
|
124
|
+
const coordinates = Object.keys(index.entries).sort(compareStoreText);
|
|
125
|
+
for (const coordinate of coordinates) {
|
|
126
|
+
const entry = index.entries[coordinate];
|
|
127
|
+
if (entry.digest !== bundleDigest)
|
|
128
|
+
continue;
|
|
129
|
+
foundCoordinate = true;
|
|
130
|
+
const { namespace } = parseWorkflowCoordinate(coordinate);
|
|
131
|
+
const match = matchOriginRule(rules, namespace);
|
|
132
|
+
if (match !== undefined)
|
|
133
|
+
entries.push({ coordinate, namespace, match });
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
if (!foundCoordinate)
|
|
137
|
+
return { kind: 'unknown' };
|
|
138
|
+
if (entries.length === 0)
|
|
139
|
+
return { kind: 'none' };
|
|
140
|
+
const requirements = new Set(entries.map((entry) => entry.match.value));
|
|
141
|
+
if (requirements.size > 1)
|
|
142
|
+
return { kind: 'ambiguous', entries };
|
|
143
|
+
return { kind: 'match', match: entries[0].match, entries };
|
|
144
|
+
};
|
|
145
|
+
const originFor = async (resolved) => {
|
|
146
|
+
if (options.originVerifier === undefined) {
|
|
147
|
+
return { kind: 'unverifiable', reason: 'execution-time origin verifier is not configured' };
|
|
148
|
+
}
|
|
149
|
+
try {
|
|
150
|
+
return await options.originVerifier({ bundleDigest: resolved.bundleDigest, objectPath: resolved.objectPath });
|
|
151
|
+
}
|
|
152
|
+
catch (error) {
|
|
153
|
+
return { kind: 'unverifiable', reason: errorText(error) };
|
|
154
|
+
}
|
|
155
|
+
};
|
|
156
|
+
const originPolicyWarning = (order, detail) => {
|
|
157
|
+
warn(`workflow definition '${order.defDigest}' was not admitted by origin policy; originPolicy=warn allows execution: ${detail}`);
|
|
158
|
+
};
|
|
159
|
+
const checkOrigin = async (order, resolved) => {
|
|
160
|
+
const rules = readOriginRules();
|
|
161
|
+
const verdict = await originFor(resolved);
|
|
162
|
+
if (verdict.kind === 'invalid') {
|
|
163
|
+
return refusal('origin-policy', order, `invalid origin evidence: ${verdict.reason}`);
|
|
164
|
+
}
|
|
165
|
+
if (Object.keys(rules).length === 0)
|
|
166
|
+
return undefined;
|
|
167
|
+
let resolution;
|
|
168
|
+
try {
|
|
169
|
+
resolution = recoverOriginRule(resolved.bundleDigest, rules);
|
|
170
|
+
}
|
|
171
|
+
catch (error) {
|
|
172
|
+
return refusal('origin-policy', order, `could not recover the definition namespace from workflow-store indexes: ${errorText(error)}`);
|
|
173
|
+
}
|
|
174
|
+
const selectedPolicy = readOriginPolicy();
|
|
175
|
+
if (resolution.kind === 'none')
|
|
176
|
+
return undefined;
|
|
177
|
+
if (resolution.kind === 'unknown') {
|
|
178
|
+
const detail = 'the definition digest is not indexed under any namespace, so its origin rule cannot be determined';
|
|
179
|
+
if (selectedPolicy === 'enforce')
|
|
180
|
+
return refusal('origin-policy', order, detail);
|
|
181
|
+
if (selectedPolicy === 'warn')
|
|
182
|
+
originPolicyWarning(order, detail);
|
|
183
|
+
return undefined;
|
|
184
|
+
}
|
|
185
|
+
if (resolution.kind === 'ambiguous') {
|
|
186
|
+
const detail = resolution.entries
|
|
187
|
+
.map((entry) => `${entry.namespace}=${entry.match.key} (${entry.match.value})`)
|
|
188
|
+
.join(', ');
|
|
189
|
+
const message = `the definition digest is indexed under namespaces with different origin rules: ${detail}`;
|
|
190
|
+
if (selectedPolicy === 'enforce')
|
|
191
|
+
return refusal('origin-policy', order, message);
|
|
192
|
+
if (selectedPolicy === 'warn')
|
|
193
|
+
originPolicyWarning(order, message);
|
|
194
|
+
return undefined;
|
|
195
|
+
}
|
|
196
|
+
const evaluation = evaluateOriginRule(resolution.match.value, verdict);
|
|
197
|
+
if (evaluation.ok)
|
|
198
|
+
return undefined;
|
|
199
|
+
const detail = `${evaluation.kind} — ${evaluation.detail}; rule ${resolution.match.key} requires ${resolution.match.value}`;
|
|
200
|
+
if (selectedPolicy === 'enforce')
|
|
201
|
+
return refusal('origin-policy', order, detail);
|
|
202
|
+
if (selectedPolicy === 'warn')
|
|
203
|
+
originPolicyWarning(order, detail);
|
|
204
|
+
return undefined;
|
|
205
|
+
};
|
|
206
|
+
const hasConsumedData = (order) => Object.keys(order.consumes).length > 0;
|
|
207
|
+
/**
|
|
208
|
+
* A command child receives neither `owes[].reasons` nor `owes[].proof`.
|
|
209
|
+
* Keep the launch gate scoped to dynamic values that can influence the child;
|
|
210
|
+
* the claim-time output version is separate lifecycle metadata retained by the
|
|
211
|
+
* exec holder for receipt signing. Agent holders still verify the complete
|
|
212
|
+
* order because their rendered prompt includes the feedback thread.
|
|
213
|
+
*/
|
|
214
|
+
const commandConsumedOrder = (order) => ({
|
|
215
|
+
...order,
|
|
216
|
+
owes: order.owes.map((owed) => ({
|
|
217
|
+
path: owed.path,
|
|
218
|
+
...(owed.version !== undefined ? { version: owed.version } : {}),
|
|
219
|
+
judgmentRejects: owed.judgmentRejects,
|
|
220
|
+
schemaRejects: owed.schemaRejects,
|
|
221
|
+
reasons: [],
|
|
222
|
+
})),
|
|
223
|
+
});
|
|
224
|
+
const gateConsumed = async (order, hardRule) => {
|
|
225
|
+
if (!hasConsumedData(order))
|
|
226
|
+
return undefined;
|
|
227
|
+
if (options.consumedVerifier === undefined) {
|
|
228
|
+
return refusal('unverified-consumed', order, 'consume-side verifier is not configured; dynamic values cannot be admitted to a command worker');
|
|
229
|
+
}
|
|
230
|
+
try {
|
|
231
|
+
const checked = await options.consumedVerifier(commandConsumedOrder(order), { hardRule });
|
|
232
|
+
if (!checked.ok)
|
|
233
|
+
return refusal('unverified-consumed', order, checked.reason);
|
|
234
|
+
for (const warning of checked.warnings)
|
|
235
|
+
warn(warning);
|
|
236
|
+
return undefined;
|
|
237
|
+
}
|
|
238
|
+
catch (error) {
|
|
239
|
+
return refusal('unverified-consumed', order, `consume-side verification failed: ${errorText(error)}`);
|
|
240
|
+
}
|
|
241
|
+
};
|
|
242
|
+
const resolveAgentStep = async (order) => {
|
|
243
|
+
const resolved = await resolveVerifiedStep(order);
|
|
244
|
+
if (!resolved.ok)
|
|
245
|
+
return resolved;
|
|
246
|
+
const verdict = await trustFor(order, resolved);
|
|
247
|
+
// Read the policy only after the execution-time verdict is known. This
|
|
248
|
+
// keeps invalid signatures fail-closed and leaves command handling below
|
|
249
|
+
// independent from policy lookup.
|
|
250
|
+
if (verdict.kind !== 'verified') {
|
|
251
|
+
const selected = readPolicy();
|
|
252
|
+
if (verdict.kind === 'invalid' || selected === 'enforce')
|
|
253
|
+
return refuseUnverified(order, verdict);
|
|
254
|
+
if (selected === 'warn') {
|
|
255
|
+
warn(`workflow definition '${order.defDigest}' is ${verdict.kind}; defPolicy=warn allows agent execution: ${verdict.kind === 'unverifiable' ? verdict.reason : 'no publication signature'}`);
|
|
256
|
+
}
|
|
257
|
+
}
|
|
258
|
+
const originRefusal = await checkOrigin(order, resolved);
|
|
259
|
+
if (originRefusal !== undefined)
|
|
260
|
+
return originRefusal;
|
|
261
|
+
return { ok: true, step: resolved.step, ...(resolved.objectPath !== undefined ? { bundleDir: resolved.objectPath } : {}) };
|
|
262
|
+
};
|
|
263
|
+
return {
|
|
264
|
+
async resolveCommand(order) {
|
|
265
|
+
const resolved = await resolveVerifiedStep(order);
|
|
266
|
+
if (!resolved.ok)
|
|
267
|
+
return resolved;
|
|
268
|
+
const verdict = await trustFor(order, resolved);
|
|
269
|
+
// HARD RULE: command orders never consult defPolicy before this gate.
|
|
270
|
+
// An unverified definition must never reach `/bin/sh -c`, including off.
|
|
271
|
+
if (verdict.kind !== 'verified')
|
|
272
|
+
return refuseUnverified(order, verdict);
|
|
273
|
+
// HARD RULE: consume-side verification runs before any policy lookup,
|
|
274
|
+
// including origin and artifact policy. A command worker never admits
|
|
275
|
+
// absent, unverifiable, or invalid dynamic evidence under
|
|
276
|
+
// artifactPolicy=off; otherwise a future command interpolation could
|
|
277
|
+
// carry an unverified value into `/bin/sh -c`.
|
|
278
|
+
const consumedRefusal = await gateConsumed(order, true);
|
|
279
|
+
if (consumedRefusal !== undefined)
|
|
280
|
+
return consumedRefusal;
|
|
281
|
+
const originRefusal = await checkOrigin(order, resolved);
|
|
282
|
+
if (originRefusal !== undefined)
|
|
283
|
+
return originRefusal;
|
|
284
|
+
if (typeof resolved.step.command !== 'string' || resolved.step.command.trim() === '') {
|
|
285
|
+
return refusal('missing-command', order, 'the verified step has no non-empty command text');
|
|
286
|
+
}
|
|
287
|
+
// Deliberately return the authored bytes exactly. Runtime substitutions
|
|
288
|
+
// belong to prompts only; this string is passed to `/bin/sh -c`.
|
|
289
|
+
return { ok: true, command: resolved.step.command, ...(resolved.objectPath !== undefined ? { bundleDir: resolved.objectPath } : {}) };
|
|
290
|
+
},
|
|
291
|
+
resolveStep: resolveAgentStep,
|
|
292
|
+
};
|
|
293
|
+
}
|
|
294
|
+
/** Build the production resolver from injected process environment and cwd. */
|
|
295
|
+
export function createDefaultStoreInstructionResolver(args) {
|
|
296
|
+
const home = [args.env.HOME, args.env.USERPROFILE].find((value) => value !== undefined && value.trim() !== '');
|
|
297
|
+
if (home === undefined) {
|
|
298
|
+
throw new Error('cannot locate the global workflow store: set HOME or USERPROFILE');
|
|
299
|
+
}
|
|
300
|
+
const projectRoot = join(args.cwd, 'workflows');
|
|
301
|
+
const globalRoot = globalStoreRoot(home);
|
|
302
|
+
const verifier = args.verifier ?? createBundleIngestor();
|
|
303
|
+
const source = createStoreInstructionSource({
|
|
304
|
+
projectRoot,
|
|
305
|
+
globalRoot,
|
|
306
|
+
verifier,
|
|
307
|
+
});
|
|
308
|
+
return createStoreInstructionResolver({
|
|
309
|
+
projectRoot,
|
|
310
|
+
globalRoot,
|
|
311
|
+
verifier,
|
|
312
|
+
source,
|
|
313
|
+
definitionVerifier: args.definitionVerifier ?? createExecutionDefinitionVerifier({ env: args.env }),
|
|
314
|
+
originVerifier: args.originVerifier ?? createExecutionOriginVerifier({ env: args.env }),
|
|
315
|
+
...(args.consumedVerifier !== undefined ? { consumedVerifier: args.consumedVerifier } : {}),
|
|
316
|
+
...(args.defPolicy !== undefined ? { defPolicy: args.defPolicy } : {}),
|
|
317
|
+
...(args.originPolicy !== undefined ? { originPolicy: args.originPolicy } : {}),
|
|
318
|
+
...(args.originRules !== undefined ? { originRules: args.originRules } : {}),
|
|
319
|
+
...(args.policyFloor !== undefined ? { policyFloor: args.policyFloor } : {}),
|
|
320
|
+
...(args.warn !== undefined ? { warn: args.warn } : {}),
|
|
321
|
+
env: args.env,
|
|
322
|
+
});
|
|
323
|
+
}
|
|
@@ -1,15 +1,26 @@
|
|
|
1
1
|
import type { HubClient } from '../hub/client.ts';
|
|
2
2
|
import type { ContactHolder } from '../hub/types.ts';
|
|
3
3
|
import type { CommandRunner } from './runner.ts';
|
|
4
|
+
import type { InstructionResolver } from './instructions.ts';
|
|
5
|
+
import { type SubmissionKeyManager } from '../submit-proof.ts';
|
|
6
|
+
import type { SshProcessAdapter } from '../../../../src/crypto/ssh.ts';
|
|
4
7
|
/** Discriminated result of an exec run; the role maps these to exit codes. */
|
|
5
|
-
export type ExecOutcome = 'submitted' | 'completed' | 'misroute' | 'killed' | 'lease-lost' | 'ownership-error' | 'hub-unreachable' | 'submit-rejected' | 'submit-failed' | 'stopped';
|
|
8
|
+
export type ExecOutcome = 'submitted' | 'completed' | 'misroute' | 'unresolved-instructions' | 'killed' | 'lease-lost' | 'ownership-error' | 'hub-unreachable' | 'submit-rejected' | 'submit-failed' | 'rejected' | 'judge-rejected' | 'judge-no-verdict' | 'reject-failed' | 'stopped';
|
|
6
9
|
export interface ExecLoopOptions {
|
|
7
10
|
hub: HubClient;
|
|
8
11
|
runner: CommandRunner;
|
|
9
12
|
workflow: string;
|
|
10
13
|
run: string;
|
|
14
|
+
/** Hub origin used to resolve the local machine signing key. */
|
|
15
|
+
origin?: string;
|
|
16
|
+
principalKeys?: SubmissionKeyManager;
|
|
17
|
+
env?: Record<string, string | undefined>;
|
|
18
|
+
/** Injectable ssh-keygen seam for hermetic submit-proof tests. */
|
|
19
|
+
sshProcess?: SshProcessAdapter;
|
|
11
20
|
/** The exec process holder tag `{kind:'exec', id}` — id is `<hostname>:<pid>`. */
|
|
12
21
|
holder: ContactHolder;
|
|
22
|
+
/** Resolves command text from a verified local workflow-store object. */
|
|
23
|
+
instructions: InstructionResolver;
|
|
13
24
|
/** cwd for the command when the order packet carries no `workdir`. */
|
|
14
25
|
cwd: string;
|
|
15
26
|
sleep: (ms: number) => Promise<void>;
|