owenloop 0.5.0 → 0.5.2
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 +67 -0
- package/README.md +144 -35
- package/bin/owenloop.mjs +49 -1
- package/dist/packages/work/src/agent/brief.d.ts +29 -4
- package/dist/packages/work/src/agent/brief.js +49 -4
- package/dist/packages/work/src/agent/capability-model.d.ts +123 -0
- package/dist/packages/work/src/agent/capability-model.js +148 -0
- package/dist/packages/work/src/agent/loop.d.ts +56 -7
- package/dist/packages/work/src/agent/loop.js +166 -9
- 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 +29 -1
- package/dist/packages/work/src/exec/loop.js +313 -35
- 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 +84 -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 +30 -10
- package/dist/packages/work/src/harness/session-store.js +317 -89
- package/dist/packages/work/src/hold/mcp.d.ts +25 -5
- package/dist/packages/work/src/hold/mcp.js +134 -12
- package/dist/packages/work/src/hub/client.d.ts +8 -1
- package/dist/packages/work/src/hub/client.js +15 -1
- package/dist/packages/work/src/hub/types.d.ts +137 -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 +115 -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 +6 -0
- package/dist/packages/work/src/roles/hold.js +83 -13
- 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 +19 -2
- package/dist/packages/work/src/roles/shift.d.ts +1 -0
- package/dist/packages/work/src/roles/shift.js +36 -2
- package/dist/packages/work/src/settings/settings.d.ts +70 -1
- package/dist/packages/work/src/settings/settings.js +90 -4
- package/dist/packages/work/src/shift/logretention.d.ts +253 -0
- package/dist/packages/work/src/shift/logretention.js +407 -0
- package/dist/packages/work/src/shift/logsink.d.ts +14 -0
- package/dist/packages/work/src/shift/logsink.js +98 -0
- package/dist/packages/work/src/shift/loop.d.ts +32 -4
- package/dist/packages/work/src/shift/loop.js +687 -166
- package/dist/packages/work/src/shift/protocol.d.ts +128 -1
- package/dist/packages/work/src/shift/protocol.js +14 -0
- package/dist/packages/work/src/shift/runtime.d.ts +16 -0
- package/dist/packages/work/src/shift/runtime.js +291 -5
- package/dist/packages/work/src/shift/server.d.ts +13 -0
- package/dist/packages/work/src/shift/server.js +61 -36
- package/dist/packages/work/src/shift/spawn.d.ts +115 -19
- package/dist/packages/work/src/shift/spawn.js +234 -30
- package/dist/packages/work/src/shift/state.d.ts +76 -49
- package/dist/packages/work/src/shift/state.js +350 -103
- package/dist/packages/work/src/shift/truncate.d.ts +35 -0
- package/dist/packages/work/src/shift/truncate.js +73 -0
- package/dist/packages/work/src/submit-proof.d.ts +61 -0
- package/dist/packages/work/src/submit-proof.js +119 -0
- package/dist/packages/work/src/submit-value.d.ts +48 -0
- package/dist/packages/work/src/submit-value.js +118 -0
- package/dist/packages/work/src/usage.d.ts +1 -1
- package/dist/packages/work/src/usage.js +11 -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/capabilities.d.ts +93 -0
- package/dist/src/capabilities.js +101 -0
- package/dist/src/cli.d.ts +90 -20
- package/dist/src/cli.js +2421 -374
- 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 +319 -0
- package/dist/src/crypto/records.js +168 -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 +335 -27
- package/dist/src/engine.d.ts +211 -6
- package/dist/src/engine.js +459 -59
- 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 +102 -32
- package/dist/src/hub.js +147 -58
- package/dist/src/index.d.ts +19 -2
- package/dist/src/index.js +23 -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 +174 -44
- package/dist/src/mcp/server.js +12 -1
- package/dist/src/model.d.ts +51 -0
- package/dist/src/model.js +157 -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 +1433 -0
- package/dist/src/schemas/index.js +31 -0
- package/dist/src/schemas/order.v1.schema.json +120 -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/store.d.ts +33 -1
- package/dist/src/store.js +57 -4
- package/dist/src/types.d.ts +146 -12
- 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 +64 -6
- package/docs/bundles.md +350 -0
- package/docs/cli.md +1298 -106
- package/docs/crypto.md +832 -0
- package/docs/design.md +342 -20
- package/docs/embedding.md +132 -25
- package/docs/shift-logs.md +642 -0
- package/docs/wire-contracts.md +395 -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
|
@@ -147,16 +147,20 @@ export function readLatestBundle(cacheDir, name) {
|
|
|
147
147
|
}
|
|
148
148
|
return best;
|
|
149
149
|
}
|
|
150
|
+
class StaleStepSpecError extends Error {
|
|
151
|
+
}
|
|
150
152
|
/**
|
|
151
153
|
* Read the normalized step spec for `(name, hash, step)`, or `null` when it is
|
|
152
154
|
* absent, unreadable, or not valid JSON. Layout mirrors `writeBundle`:
|
|
153
155
|
* `<cacheDir>/bundles/<name>/<hash>/steps/<step>.json`.
|
|
154
156
|
*
|
|
155
|
-
*
|
|
156
|
-
*
|
|
157
|
-
*
|
|
158
|
-
* `
|
|
159
|
-
*
|
|
157
|
+
* A missing or corrupt spec returns `null` — a command step has no spec by
|
|
158
|
+
* design, and a hash dir prepared before Phase 5 has none at all. The one
|
|
159
|
+
* deliberate exception is a structurally valid old normalized spec that leaves
|
|
160
|
+
* `filesystem` or `network` buried under `permissions.extensions`: that cache
|
|
161
|
+
* throws with an explicit `owenloop work prepare` repair because returning it
|
|
162
|
+
* would silently discard an authored restriction. There is no fallback to the
|
|
163
|
+
* legacy `templates/<step>.md`.
|
|
160
164
|
*/
|
|
161
165
|
export function readStepSpec(cacheDir, name, hash, step) {
|
|
162
166
|
try {
|
|
@@ -172,9 +176,19 @@ export function readStepSpec(cacheDir, name, hash, step) {
|
|
|
172
176
|
const parsed = JSON.parse(readFileSync(file, 'utf8'));
|
|
173
177
|
if (typeof parsed?.step !== 'string' || typeof parsed?.brief !== 'string')
|
|
174
178
|
return null;
|
|
179
|
+
const extensions = parsed.permissions?.extensions;
|
|
180
|
+
if (extensions !== null && typeof extensions === 'object' && !Array.isArray(extensions)) {
|
|
181
|
+
const stale = ['filesystem', 'network'].filter((key) => key in extensions);
|
|
182
|
+
if (stale.length > 0) {
|
|
183
|
+
throw new StaleStepSpecError(`cached step '${step}' has restriction(s) ${stale.join(', ')} buried in permissions.extensions; ` +
|
|
184
|
+
'rerun `owenloop work prepare`');
|
|
185
|
+
}
|
|
186
|
+
}
|
|
175
187
|
return parsed;
|
|
176
188
|
}
|
|
177
|
-
catch {
|
|
189
|
+
catch (error) {
|
|
190
|
+
if (error instanceof StaleStepSpecError)
|
|
191
|
+
throw error;
|
|
178
192
|
return null;
|
|
179
193
|
}
|
|
180
194
|
}
|
|
@@ -50,11 +50,13 @@ export interface HarnessCarrier {
|
|
|
50
50
|
* forward compat for the day the grammar promotes the field, and it means the
|
|
51
51
|
* promotion needs no owenloop change.
|
|
52
52
|
*
|
|
53
|
-
* Validation is loose but HONEST: a non-map `x.harness`, a non-string
|
|
54
|
-
* `x.harness.id`, a non-string top-level `harness`, or a
|
|
55
|
-
* `x.claude-code` bag is a def error naming the step, never a
|
|
56
|
-
* Absent keys are simply absent — a step with no harness
|
|
57
|
-
* completely normal.
|
|
53
|
+
* Validation is loose but HONEST: a non-map `x.harness`, a non-string or
|
|
54
|
+
* blank `x.harness.id`, a non-string or blank top-level `harness`, or a
|
|
55
|
+
* surviving legacy `x.claude-code` bag is a def error naming the step, never a
|
|
56
|
+
* silent drop. Absent keys are simply absent — a step with no harness
|
|
57
|
+
* declaration is completely normal. Blank is not absent: accepting an explicit
|
|
58
|
+
* empty id would let adapter resolution treat an invalid declaration as though
|
|
59
|
+
* the author had selected the default harness.
|
|
58
60
|
*
|
|
59
61
|
* `label` names the def, `stepName` the step, so an error in a pinned child is
|
|
60
62
|
* attributable. Shared with `owenloop work lint`, which parses raw YAML defs.
|
|
@@ -20,6 +20,7 @@
|
|
|
20
20
|
* a broken closure fails at fetch, never mid-run — see `validateFetchedDef`.
|
|
21
21
|
*/
|
|
22
22
|
import { HubError } from "../hub/types.js";
|
|
23
|
+
import { validateHarnessOptions } from "../harness/permissions.js";
|
|
23
24
|
/** A step is an agent step (spec candidate) when it is not a command/calls step. */
|
|
24
25
|
function isAgentStep(s) {
|
|
25
26
|
return s.executor !== 'command' && s.calls === undefined;
|
|
@@ -61,11 +62,13 @@ function isPlainMap(v) {
|
|
|
61
62
|
* forward compat for the day the grammar promotes the field, and it means the
|
|
62
63
|
* promotion needs no owenloop change.
|
|
63
64
|
*
|
|
64
|
-
* Validation is loose but HONEST: a non-map `x.harness`, a non-string
|
|
65
|
-
* `x.harness.id`, a non-string top-level `harness`, or a
|
|
66
|
-
* `x.claude-code` bag is a def error naming the step, never a
|
|
67
|
-
* Absent keys are simply absent — a step with no harness
|
|
68
|
-
* completely normal.
|
|
65
|
+
* Validation is loose but HONEST: a non-map `x.harness`, a non-string or
|
|
66
|
+
* blank `x.harness.id`, a non-string or blank top-level `harness`, or a
|
|
67
|
+
* surviving legacy `x.claude-code` bag is a def error naming the step, never a
|
|
68
|
+
* silent drop. Absent keys are simply absent — a step with no harness
|
|
69
|
+
* declaration is completely normal. Blank is not absent: accepting an explicit
|
|
70
|
+
* empty id would let adapter resolution treat an invalid declaration as though
|
|
71
|
+
* the author had selected the default harness.
|
|
69
72
|
*
|
|
70
73
|
* `label` names the def, `stepName` the step, so an error in a pinned child is
|
|
71
74
|
* attributable. Shared with `owenloop work lint`, which parses raw YAML defs.
|
|
@@ -73,8 +76,13 @@ function isPlainMap(v) {
|
|
|
73
76
|
export function parseHarnessCarrier(s, label, stepName) {
|
|
74
77
|
const where = `hub workflow '${label}': step '${stepName}'`;
|
|
75
78
|
const topLevel = s['harness'];
|
|
76
|
-
if (topLevel !== undefined
|
|
77
|
-
|
|
79
|
+
if (topLevel !== undefined) {
|
|
80
|
+
if (typeof topLevel !== 'string') {
|
|
81
|
+
throw new Error(`${where} has a non-string harness`);
|
|
82
|
+
}
|
|
83
|
+
if (topLevel.trim() === '') {
|
|
84
|
+
throw new Error(`${where} has an empty or whitespace-only harness`);
|
|
85
|
+
}
|
|
78
86
|
}
|
|
79
87
|
const x = s['x'];
|
|
80
88
|
// A def still carrying the OLD bag key fails HARD here, before anything else
|
|
@@ -106,6 +114,9 @@ export function parseHarnessCarrier(s, label, stepName) {
|
|
|
106
114
|
if (typeof v !== 'string') {
|
|
107
115
|
throw new Error(`${where} has a non-string x.${HARNESS_BAG_KEY}.id`);
|
|
108
116
|
}
|
|
117
|
+
if (v.trim() === '') {
|
|
118
|
+
throw new Error(`${where} has an empty or whitespace-only x.${HARNESS_BAG_KEY}.id`);
|
|
119
|
+
}
|
|
109
120
|
bagId = v;
|
|
110
121
|
continue;
|
|
111
122
|
}
|
|
@@ -154,6 +165,15 @@ function validateDefEnvelope(data, label) {
|
|
|
154
165
|
// still carried through verbatim — `x.owenloop` is a separate live
|
|
155
166
|
// namespace that `src/shift/routing.ts` reads.
|
|
156
167
|
const carrier = parseHarnessCarrier(s, label, s['name']);
|
|
168
|
+
if (carrier.harnessOptions !== undefined) {
|
|
169
|
+
const errors = validateHarnessOptions(carrier.harnessOptions, s['name'])
|
|
170
|
+
.filter((finding) => finding.severity === 'error');
|
|
171
|
+
if (errors.length > 0) {
|
|
172
|
+
throw new Error(errors
|
|
173
|
+
.map((finding) => `hub workflow '${label}': step '${finding.step}' x.harness.${finding.field ?? '<bag>'}: ${finding.message}`)
|
|
174
|
+
.join('; '));
|
|
175
|
+
}
|
|
176
|
+
}
|
|
157
177
|
return {
|
|
158
178
|
name: s['name'],
|
|
159
179
|
consumes: Array.isArray(s['consumes']) ? s['consumes'] : undefined,
|
|
@@ -123,9 +123,10 @@ export interface FetchedBundle extends FetchedDef {
|
|
|
123
123
|
children?: Record<string, FetchedDef>;
|
|
124
124
|
}
|
|
125
125
|
/**
|
|
126
|
-
* The
|
|
127
|
-
*
|
|
128
|
-
*
|
|
126
|
+
* The prepare cache may persist routing metadata for `steps/<step>.json`, but
|
|
127
|
+
* cached instruction text is not authoritative for execution. Runtime workers
|
|
128
|
+
* resolve the verified step body from the local workflow store. The cache
|
|
129
|
+
* replaces the legacy `templates/<step>.md` compiled frontmatter entirely.
|
|
129
130
|
*
|
|
130
131
|
* What is DELIBERATELY not in here: the four substitution tokens
|
|
131
132
|
* (`ORDER_TOKEN`, `ORIGIN_TOKEN`, `ACCOUNT_TOKEN`, `SHIFT_TOKEN`) and the
|
|
@@ -138,7 +139,10 @@ export interface FetchedBundle extends FetchedDef {
|
|
|
138
139
|
*
|
|
139
140
|
* There is no format version and no migration. A hash dir cached before Phase 5
|
|
140
141
|
* simply has no `steps/*.json`; `readStepSpec` fails honestly and the fix is to
|
|
141
|
-
* re-run `owenloop work prepare`.
|
|
142
|
+
* re-run `owenloop work prepare`. A cache normalized before filesystem/network
|
|
143
|
+
* became neutral fields may carry those restrictions under
|
|
144
|
+
* `permissions.extensions`; runtime preflight refuses that shape rather than
|
|
145
|
+
* ignoring the restriction and tells the operator to rerun prepare.
|
|
142
146
|
*/
|
|
143
147
|
export interface NormalizedStepSpec {
|
|
144
148
|
/** The step name — the same string that names the file. */
|
|
@@ -0,0 +1,45 @@
|
|
|
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 type { DefPolicy } from '../../../src/crypto/verify-publication.ts';
|
|
10
|
+
import type { PolicyFloor } from '../../../src/crypto/records.ts';
|
|
11
|
+
import { type VerifyConsumedOptions } from '../../../src/crypto/verify-consumed.ts';
|
|
12
|
+
import type { OrderPacket } from './hub/types.ts';
|
|
13
|
+
export interface ConsumedGateResult {
|
|
14
|
+
ok: true;
|
|
15
|
+
order: OrderPacket;
|
|
16
|
+
warnings: string[];
|
|
17
|
+
}
|
|
18
|
+
export interface ConsumedGateRefusal {
|
|
19
|
+
ok: false;
|
|
20
|
+
reason: string;
|
|
21
|
+
}
|
|
22
|
+
export interface CreateConsumedVerifierArgs {
|
|
23
|
+
env: Record<string, string | undefined>;
|
|
24
|
+
now: () => number;
|
|
25
|
+
artifactPolicy?: DefPolicy;
|
|
26
|
+
policyFloor?: PolicyFloor;
|
|
27
|
+
/** Explicit producer scope demand; the default is no additional demand. */
|
|
28
|
+
demand?: {
|
|
29
|
+
pool?: string;
|
|
30
|
+
label?: string;
|
|
31
|
+
namespace?: string;
|
|
32
|
+
};
|
|
33
|
+
/** Cryptographic seam for hermetic tests and alternate signer backends. */
|
|
34
|
+
signerForPrincipal?: VerifyConsumedOptions['signerForPrincipal'];
|
|
35
|
+
namespace?: string;
|
|
36
|
+
maxChainDepth?: number;
|
|
37
|
+
/** Optional warning sink; the returned warnings remain authoritative for callers. */
|
|
38
|
+
warn?: (line: string) => void;
|
|
39
|
+
}
|
|
40
|
+
export type ConsumedVerifier = (order: OrderPacket, opts: {
|
|
41
|
+
hardRule: boolean;
|
|
42
|
+
}) => Promise<ConsumedGateResult | ConsumedGateRefusal>;
|
|
43
|
+
/** Create a verifier bound to one injected local environment and clock. */
|
|
44
|
+
export declare function createConsumedVerifier(args: CreateConsumedVerifierArgs): ConsumedVerifier;
|
|
45
|
+
export declare function resetConsumedVerifierWarningsForTests(): void;
|
|
@@ -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;
|