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
|
@@ -0,0 +1,298 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Store-backed reference instruction resolution.
|
|
3
|
+
*
|
|
4
|
+
* The engine's `OrderInstructionSource.lookup` seam is synchronous because the
|
|
5
|
+
* engine performs lookup inside the same SQLite transaction that claims an
|
|
6
|
+
* order. A store lookup is filesystem I/O, so callers must first `prime` the
|
|
7
|
+
* requested order digest. `lookup` then reads only the verified definition held
|
|
8
|
+
* in the in-memory cache populated by that prime.
|
|
9
|
+
*/
|
|
10
|
+
import { dirname, join } from 'node:path';
|
|
11
|
+
import { readFileSync } from 'node:fs';
|
|
12
|
+
import { parseManifestBytes } from "../bundle/manifest.js";
|
|
13
|
+
import { defInstructionDigest } from "../order-resolver.js";
|
|
14
|
+
import { finalizeDefs, loadDefFile } from "../defs.js";
|
|
15
|
+
import { readWorkflowStoreIndex } from "./index-file.js";
|
|
16
|
+
import { StoreIntegrityError, compareStoreText, defDigest, objectDirForDigest, } from "./types.js";
|
|
17
|
+
import { coordinateDigestRead, projectStoreRoot, probeObjectDir, probeStoreRoot, storeIndexPath, } from "./resolve.js";
|
|
18
|
+
export class StoreInstructionSourceError extends Error {
|
|
19
|
+
name = 'StoreInstructionSourceError';
|
|
20
|
+
code;
|
|
21
|
+
constructor(message) {
|
|
22
|
+
super(message);
|
|
23
|
+
this.code = 'digest-of-unavailable';
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
function indexedBundleDigests(root) {
|
|
27
|
+
if (probeStoreRoot(root) !== 'dir')
|
|
28
|
+
return [];
|
|
29
|
+
const index = readWorkflowStoreIndex(storeIndexPath(root));
|
|
30
|
+
// Enumeration order only — every candidate is tried and matched by exact
|
|
31
|
+
// digest, so this never selects a version. It is sorted, and sorted without
|
|
32
|
+
// `localeCompare`, so the order candidates are inspected (and therefore which
|
|
33
|
+
// integrity failure is reported first) is identical on every host.
|
|
34
|
+
return Object.values(index.entries)
|
|
35
|
+
.map((entry) => defDigest(entry.digest))
|
|
36
|
+
.sort(compareStoreText);
|
|
37
|
+
}
|
|
38
|
+
async function verifiedCandidateObject(root, bundleDigest, level, verifier) {
|
|
39
|
+
if (probeStoreRoot(root) !== 'dir') {
|
|
40
|
+
throw new StoreIntegrityError('object-missing', bundleDigest, `${level}-level workflow store is absent`);
|
|
41
|
+
}
|
|
42
|
+
const objectPath = objectDirForDigest(root, bundleDigest);
|
|
43
|
+
if (probeObjectDir(objectPath, bundleDigest, level) !== 'dir') {
|
|
44
|
+
throw new StoreIntegrityError('object-missing', bundleDigest, `${level}-level index references a missing workflow object`);
|
|
45
|
+
}
|
|
46
|
+
try {
|
|
47
|
+
const verify = verifier.verifyInstalledObjectAfterCoordination ?? verifier.verifyInstalledObject;
|
|
48
|
+
await verify.call(verifier, { objectDir: objectPath, digest: bundleDigest });
|
|
49
|
+
}
|
|
50
|
+
catch (error) {
|
|
51
|
+
throw new StoreIntegrityError('object-corrupt', bundleDigest, `${level}-level object failed verification: ${error.message}`);
|
|
52
|
+
}
|
|
53
|
+
return objectPath;
|
|
54
|
+
}
|
|
55
|
+
function asDefDigest(raw) {
|
|
56
|
+
try {
|
|
57
|
+
return defDigest(raw);
|
|
58
|
+
}
|
|
59
|
+
catch {
|
|
60
|
+
return undefined;
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
export function createStoreInstructionSource(args) {
|
|
64
|
+
const projectRoot = args.projectRoot === undefined ? undefined : projectStoreRoot(args.projectRoot);
|
|
65
|
+
const globalRoot = projectStoreRoot(args.globalRoot);
|
|
66
|
+
const cache = new Map();
|
|
67
|
+
const inFlight = new Map();
|
|
68
|
+
const loadCandidate = async (requestedDigest, bundleDigest, root, level) => coordinateDigestRead(root, bundleDigest, async () => {
|
|
69
|
+
const objectPath = await verifiedCandidateObject(root, bundleDigest, level, args.verifier);
|
|
70
|
+
const manifest = parseManifestBytes(readFileSync(join(objectPath, 'bundle.yaml')));
|
|
71
|
+
const loaded = new Map();
|
|
72
|
+
for (const [workflowName, workflowPath] of Object.entries(manifest.workflows)) {
|
|
73
|
+
const def = loadDefFile(join(objectPath, workflowPath));
|
|
74
|
+
if (def.name !== workflowName) {
|
|
75
|
+
throw new StoreIntegrityError('object-corrupt', bundleDigest, `workflow '${workflowPath}' has definition name '${def.name}', expected '${workflowName}'`);
|
|
76
|
+
}
|
|
77
|
+
loaded.set(def.name, def);
|
|
78
|
+
}
|
|
79
|
+
const finalized = finalizeDefs(loaded);
|
|
80
|
+
// Hub-backed orders use the immutable bundle digest as their execution
|
|
81
|
+
// identity. Keep every workflow from that exact verified object in the
|
|
82
|
+
// cache; the later step lookup selects a unique definition and refuses an
|
|
83
|
+
// ambiguous step name instead of choosing one by manifest order.
|
|
84
|
+
if (requestedDigest === bundleDigest) {
|
|
85
|
+
cache.set(requestedDigest, [...finalized.values()].map((def) => ({
|
|
86
|
+
def,
|
|
87
|
+
bundleDigest,
|
|
88
|
+
objectPath,
|
|
89
|
+
})));
|
|
90
|
+
return true;
|
|
91
|
+
}
|
|
92
|
+
// Plain-YAML/local-engine orders retain the per-definition projection
|
|
93
|
+
// digest path for backwards compatibility.
|
|
94
|
+
for (const def of finalized.values()) {
|
|
95
|
+
if (defInstructionDigest(def) === requestedDigest) {
|
|
96
|
+
cache.set(requestedDigest, [{ def, bundleDigest, objectPath }]);
|
|
97
|
+
return true;
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
return false;
|
|
101
|
+
});
|
|
102
|
+
const candidateFailureForRefusal = (error) => error instanceof StoreIntegrityError && error.code === 'object-missing' ? undefined : error;
|
|
103
|
+
const scanTier = async (requestedDigest, bundleDigests, root, level) => {
|
|
104
|
+
let firstFailure;
|
|
105
|
+
let inspectedCleanCandidate = false;
|
|
106
|
+
for (const bundleDigest of bundleDigests) {
|
|
107
|
+
try {
|
|
108
|
+
if (await loadCandidate(requestedDigest, bundleDigest, root, level)) {
|
|
109
|
+
return { matched: true, firstFailure, inspectedCleanCandidate: true };
|
|
110
|
+
}
|
|
111
|
+
inspectedCleanCandidate = true;
|
|
112
|
+
}
|
|
113
|
+
catch (error) {
|
|
114
|
+
firstFailure ??= candidateFailureForRefusal(error);
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
return { matched: false, firstFailure, inspectedCleanCandidate };
|
|
118
|
+
};
|
|
119
|
+
const evictObject = (bundleDigest, objectPath) => {
|
|
120
|
+
for (const [instructionDigest, cached] of cache) {
|
|
121
|
+
const retained = cached.filter((candidate) => candidate.bundleDigest !== bundleDigest || candidate.objectPath !== objectPath);
|
|
122
|
+
if (retained.length === 0)
|
|
123
|
+
cache.delete(instructionDigest);
|
|
124
|
+
else if (retained.length !== cached.length)
|
|
125
|
+
cache.set(instructionDigest, retained);
|
|
126
|
+
}
|
|
127
|
+
};
|
|
128
|
+
const verifyCached = async (requestedDigest) => {
|
|
129
|
+
const cached = cache.get(requestedDigest);
|
|
130
|
+
if (cached === undefined)
|
|
131
|
+
return false;
|
|
132
|
+
const verified = new Set();
|
|
133
|
+
for (const candidate of cached) {
|
|
134
|
+
const key = `${candidate.bundleDigest}:${candidate.objectPath}`;
|
|
135
|
+
if (verified.has(key))
|
|
136
|
+
continue;
|
|
137
|
+
verified.add(key);
|
|
138
|
+
const root = dirname(dirname(dirname(candidate.objectPath)));
|
|
139
|
+
try {
|
|
140
|
+
await coordinateDigestRead(root, candidate.bundleDigest, async () => {
|
|
141
|
+
const verify = args.verifier.verifyInstalledObjectAfterCoordination ?? args.verifier.verifyInstalledObject;
|
|
142
|
+
await verify.call(args.verifier, {
|
|
143
|
+
objectDir: candidate.objectPath,
|
|
144
|
+
digest: candidate.bundleDigest,
|
|
145
|
+
});
|
|
146
|
+
});
|
|
147
|
+
}
|
|
148
|
+
catch (error) {
|
|
149
|
+
evictObject(candidate.bundleDigest, candidate.objectPath);
|
|
150
|
+
throw error;
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
return true;
|
|
154
|
+
};
|
|
155
|
+
const primeOnce = async (requestedDigest) => {
|
|
156
|
+
if (await verifyCached(requestedDigest))
|
|
157
|
+
return 'resolved';
|
|
158
|
+
/**
|
|
159
|
+
* A bundle identity is already content-addressed: only an index row carrying
|
|
160
|
+
* that exact digest is a candidate. Missing exact objects are stale rows and
|
|
161
|
+
* may fall through; corrupt exact objects remain hard integrity refusals.
|
|
162
|
+
*/
|
|
163
|
+
const loadExactIndexed = async (bundleDigests, root, level) => {
|
|
164
|
+
const exact = asDefDigest(requestedDigest);
|
|
165
|
+
if (exact === undefined || !bundleDigests.includes(exact))
|
|
166
|
+
return false;
|
|
167
|
+
try {
|
|
168
|
+
return await loadCandidate(requestedDigest, exact, root, level);
|
|
169
|
+
}
|
|
170
|
+
catch (error) {
|
|
171
|
+
if (error instanceof StoreIntegrityError && error.code === 'object-missing')
|
|
172
|
+
return false;
|
|
173
|
+
throw error;
|
|
174
|
+
}
|
|
175
|
+
};
|
|
176
|
+
const projectDigests = projectRoot === undefined
|
|
177
|
+
? undefined
|
|
178
|
+
: indexedBundleDigests(projectRoot);
|
|
179
|
+
if (projectRoot !== undefined &&
|
|
180
|
+
projectDigests !== undefined &&
|
|
181
|
+
await loadExactIndexed(projectDigests, projectRoot, 'project')) {
|
|
182
|
+
return 'resolved';
|
|
183
|
+
}
|
|
184
|
+
if (projectRoot === globalRoot && projectDigests !== undefined) {
|
|
185
|
+
const projectOutcome = await scanTier(requestedDigest, projectDigests, projectRoot, 'project');
|
|
186
|
+
if (projectOutcome.matched)
|
|
187
|
+
return 'resolved';
|
|
188
|
+
if (projectOutcome.firstFailure !== undefined && !projectOutcome.inspectedCleanCandidate) {
|
|
189
|
+
throw projectOutcome.firstFailure;
|
|
190
|
+
}
|
|
191
|
+
return 'unknown-digest';
|
|
192
|
+
}
|
|
193
|
+
// Probe an exact global identity before scanning unrelated project bundles.
|
|
194
|
+
// A corrupt global index is deferred until after the project projection scan,
|
|
195
|
+
// so a clean project projection still resolves without global availability.
|
|
196
|
+
let globalDigests;
|
|
197
|
+
let globalIndexFailure;
|
|
198
|
+
try {
|
|
199
|
+
globalDigests = indexedBundleDigests(globalRoot);
|
|
200
|
+
}
|
|
201
|
+
catch (error) {
|
|
202
|
+
globalIndexFailure = error;
|
|
203
|
+
}
|
|
204
|
+
if (globalDigests !== undefined &&
|
|
205
|
+
await loadExactIndexed(globalDigests, globalRoot, 'global')) {
|
|
206
|
+
return 'resolved';
|
|
207
|
+
}
|
|
208
|
+
// Projection digests predate bundle identities, so every indexed bundle is a
|
|
209
|
+
// candidate. Preserve project-first precedence and integrity behavior for
|
|
210
|
+
// this legacy path after exact identities have been ruled out.
|
|
211
|
+
if (projectRoot !== undefined && projectDigests !== undefined) {
|
|
212
|
+
const projectOutcome = await scanTier(requestedDigest, projectDigests, projectRoot, 'project');
|
|
213
|
+
if (projectOutcome.matched)
|
|
214
|
+
return 'resolved';
|
|
215
|
+
if (projectOutcome.firstFailure !== undefined)
|
|
216
|
+
throw projectOutcome.firstFailure;
|
|
217
|
+
}
|
|
218
|
+
if (globalIndexFailure !== undefined)
|
|
219
|
+
throw globalIndexFailure;
|
|
220
|
+
const globalOutcome = await scanTier(requestedDigest, globalDigests ?? [], globalRoot, 'global');
|
|
221
|
+
if (globalOutcome.matched)
|
|
222
|
+
return 'resolved';
|
|
223
|
+
if (globalOutcome.firstFailure !== undefined && !globalOutcome.inspectedCleanCandidate) {
|
|
224
|
+
throw globalOutcome.firstFailure;
|
|
225
|
+
}
|
|
226
|
+
return 'unknown-digest';
|
|
227
|
+
};
|
|
228
|
+
const prime = (requestedDigest) => {
|
|
229
|
+
const existing = inFlight.get(requestedDigest);
|
|
230
|
+
if (existing !== undefined)
|
|
231
|
+
return existing;
|
|
232
|
+
const operation = (async () => {
|
|
233
|
+
let result = await primeOnce(requestedDigest);
|
|
234
|
+
if (result === 'unknown-digest' && args.onMissing !== undefined) {
|
|
235
|
+
const action = await args.onMissing.onMissing(requestedDigest);
|
|
236
|
+
if (action === 'retry')
|
|
237
|
+
result = await primeOnce(requestedDigest);
|
|
238
|
+
}
|
|
239
|
+
return result;
|
|
240
|
+
})();
|
|
241
|
+
inFlight.set(requestedDigest, operation);
|
|
242
|
+
// Do not use a detached `finally()` here: a rejected finally-chain promise
|
|
243
|
+
// would become an unhandled rejection while the caller is already handling
|
|
244
|
+
// the original integrity refusal.
|
|
245
|
+
void operation.then(() => inFlight.delete(requestedDigest), () => inFlight.delete(requestedDigest));
|
|
246
|
+
return operation;
|
|
247
|
+
};
|
|
248
|
+
const definitionsForStep = (requestedDigest, stepName) => cache.get(requestedDigest)?.filter((candidate) => candidate.def.steps.some((step) => step.name === stepName)) ?? [];
|
|
249
|
+
const definitionForStep = (requestedDigest, stepName) => {
|
|
250
|
+
const matches = definitionsForStep(requestedDigest, stepName);
|
|
251
|
+
return matches.length === 1 ? matches[0] : undefined;
|
|
252
|
+
};
|
|
253
|
+
return {
|
|
254
|
+
digestOf: (_def) => {
|
|
255
|
+
throw new StoreInstructionSourceError('store-backed instruction source cannot emit a digest from an uninstalled definition; install and index the workflow bundle first');
|
|
256
|
+
},
|
|
257
|
+
lookup: (ref) => {
|
|
258
|
+
if (!cache.has(ref.defDigest))
|
|
259
|
+
return { status: 'unknown-digest' };
|
|
260
|
+
const matches = definitionsForStep(ref.defDigest, ref.step);
|
|
261
|
+
if (matches.length === 0)
|
|
262
|
+
return { status: 'unknown-step' };
|
|
263
|
+
if (matches.length > 1)
|
|
264
|
+
return { status: 'ambiguous-step' };
|
|
265
|
+
const cached = matches[0];
|
|
266
|
+
const step = cached.def.steps.find((candidate) => candidate.name === ref.step);
|
|
267
|
+
if (step === undefined)
|
|
268
|
+
return { status: 'unknown-step' };
|
|
269
|
+
return {
|
|
270
|
+
status: 'resolved',
|
|
271
|
+
instructions: {
|
|
272
|
+
prompt: step.body,
|
|
273
|
+
...(step.command !== undefined ? { command: step.command } : {}),
|
|
274
|
+
maxAttempts: step.maxAttempts,
|
|
275
|
+
},
|
|
276
|
+
};
|
|
277
|
+
},
|
|
278
|
+
prime,
|
|
279
|
+
getVerifiedStep: (requestedDigest, stepName) => {
|
|
280
|
+
const cached = definitionForStep(requestedDigest, stepName);
|
|
281
|
+
return cached?.def.steps.find((step) => step.name === stepName);
|
|
282
|
+
},
|
|
283
|
+
getVerifiedDefinition: (requestedDigest, stepName) => {
|
|
284
|
+
const cached = stepName === undefined
|
|
285
|
+
? cache.get(requestedDigest)
|
|
286
|
+
: [definitionForStep(requestedDigest, stepName)].filter((candidate) => candidate !== undefined);
|
|
287
|
+
return cached?.length === 1 ? cached[0].def : undefined;
|
|
288
|
+
},
|
|
289
|
+
getVerifiedObject: (requestedDigest) => {
|
|
290
|
+
const cached = cache.get(requestedDigest)?.[0];
|
|
291
|
+
return cached === undefined ? undefined : { bundleDigest: cached.bundleDigest, objectPath: cached.objectPath };
|
|
292
|
+
},
|
|
293
|
+
};
|
|
294
|
+
}
|
|
295
|
+
/** A small helper for callers that receive a raw order digest before priming. */
|
|
296
|
+
export function isResolvableOrderDigest(value) {
|
|
297
|
+
return asDefDigest(value) !== undefined;
|
|
298
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Retention of signed workflow-origin sidecars in the content-addressed store.
|
|
3
|
+
*
|
|
4
|
+
* Origin evidence is mutable store state, not immutable bundle content. The
|
|
5
|
+
* exact sidecar bytes are retained under `<root>/.owenloop/origins/` so
|
|
6
|
+
* execution can verify the statement again against current trust roots.
|
|
7
|
+
*/
|
|
8
|
+
import type { DefDigest } from './types.ts';
|
|
9
|
+
/** Return the canonical on-disk path for one bundle's retained origin bytes. */
|
|
10
|
+
export declare function originEvidencePath(root: string, digest: string): string;
|
|
11
|
+
/**
|
|
12
|
+
* Retain exact origin sidecar bytes outside the immutable object. A later
|
|
13
|
+
* unsigned dedupe does not call this function, so existing evidence remains.
|
|
14
|
+
*/
|
|
15
|
+
export declare function persistOriginEvidence(objectDir: string, digest: DefDigest, dsseBytes: Uint8Array): void;
|
|
16
|
+
/**
|
|
17
|
+
* Read retained origin bytes for an installed object. Missing evidence returns
|
|
18
|
+
* `undefined`; a symlink, wrong file type, or read failure throws so callers
|
|
19
|
+
* can report an unverifiable or invalid execution-time verdict.
|
|
20
|
+
*/
|
|
21
|
+
export declare function readOriginEvidence(objectPath: string, digest: string): Uint8Array | undefined;
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Retention of signed workflow-origin sidecars in the content-addressed store.
|
|
3
|
+
*
|
|
4
|
+
* Origin evidence is mutable store state, not immutable bundle content. The
|
|
5
|
+
* exact sidecar bytes are retained under `<root>/.owenloop/origins/` so
|
|
6
|
+
* execution can verify the statement again against current trust roots.
|
|
7
|
+
*/
|
|
8
|
+
import { lstatSync, mkdirSync, readFileSync, renameSync, rmSync, writeFileSync, } from 'node:fs';
|
|
9
|
+
import { dirname, join } from 'node:path';
|
|
10
|
+
import { defDigest } from "./types.js";
|
|
11
|
+
function ensureDirectory(path) {
|
|
12
|
+
const existing = lstatSync(path, { throwIfNoEntry: false });
|
|
13
|
+
if (existing !== undefined) {
|
|
14
|
+
if (existing.isSymbolicLink() || !existing.isDirectory()) {
|
|
15
|
+
throw new Error(`origin evidence directory is not a real directory: ${path}`);
|
|
16
|
+
}
|
|
17
|
+
return;
|
|
18
|
+
}
|
|
19
|
+
mkdirSync(path, { recursive: true, mode: 0o700 });
|
|
20
|
+
}
|
|
21
|
+
function storeRootFromStaging(objectDir) {
|
|
22
|
+
return dirname(dirname(objectDir));
|
|
23
|
+
}
|
|
24
|
+
function storeRootFromObject(objectPath) {
|
|
25
|
+
return dirname(dirname(dirname(objectPath)));
|
|
26
|
+
}
|
|
27
|
+
/** Return the canonical on-disk path for one bundle's retained origin bytes. */
|
|
28
|
+
export function originEvidencePath(root, digest) {
|
|
29
|
+
return join(root, '.owenloop', 'origins', `${digest}.dsse`);
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* Retain exact origin sidecar bytes outside the immutable object. A later
|
|
33
|
+
* unsigned dedupe does not call this function, so existing evidence remains.
|
|
34
|
+
*/
|
|
35
|
+
export function persistOriginEvidence(objectDir, digest, dsseBytes) {
|
|
36
|
+
const root = storeRootFromStaging(objectDir);
|
|
37
|
+
const stateDir = join(root, '.owenloop');
|
|
38
|
+
const evidenceDir = join(stateDir, 'origins');
|
|
39
|
+
ensureDirectory(stateDir);
|
|
40
|
+
ensureDirectory(evidenceDir);
|
|
41
|
+
const target = originEvidencePath(root, digest);
|
|
42
|
+
const temporary = `${target}.tmp-${process.pid}-${Date.now()}-${Math.random().toString(36).slice(2)}`;
|
|
43
|
+
try {
|
|
44
|
+
writeFileSync(temporary, dsseBytes, { mode: 0o600 });
|
|
45
|
+
renameSync(temporary, target);
|
|
46
|
+
}
|
|
47
|
+
finally {
|
|
48
|
+
rmSync(temporary, { force: true });
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* Read retained origin bytes for an installed object. Missing evidence returns
|
|
53
|
+
* `undefined`; a symlink, wrong file type, or read failure throws so callers
|
|
54
|
+
* can report an unverifiable or invalid execution-time verdict.
|
|
55
|
+
*/
|
|
56
|
+
export function readOriginEvidence(objectPath, digest) {
|
|
57
|
+
const validated = defDigest(digest);
|
|
58
|
+
const target = originEvidencePath(storeRootFromObject(objectPath), validated);
|
|
59
|
+
const stat = lstatSync(target, { throwIfNoEntry: false });
|
|
60
|
+
if (stat === undefined)
|
|
61
|
+
return undefined;
|
|
62
|
+
if (stat.isSymbolicLink() || !stat.isFile()) {
|
|
63
|
+
throw new Error(`stored origin evidence is not a regular file: ${target}`);
|
|
64
|
+
}
|
|
65
|
+
return readFileSync(target);
|
|
66
|
+
}
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Production implementation of the workflow-store pre-commit verifier.
|
|
3
|
+
*
|
|
4
|
+
* The verifier runs after bundle/engine validation and before the install
|
|
5
|
+
* transaction swaps an object or writes the index. It therefore refuses by
|
|
6
|
+
* throwing, while warnings are sent through the injected diagnostic stream.
|
|
7
|
+
* No verdict or sidecar is written into the immutable object directory.
|
|
8
|
+
*/
|
|
9
|
+
import type { PreCommitVerifier } from './install.ts';
|
|
10
|
+
import { type DefPolicy, type DefVerdict, type VerifyPublicationOptions } from '../crypto/verify-publication.ts';
|
|
11
|
+
import { type OriginPolicy, type OriginRules } from '../crypto/origin-rules.ts';
|
|
12
|
+
import { type OriginVerdict } from '../crypto/verify-origin.ts';
|
|
13
|
+
import type { PolicyFloor } from '../crypto/records.ts';
|
|
14
|
+
export interface PreCommitVerifierOptions {
|
|
15
|
+
/** Environment used for policy and trust-root resolution. */
|
|
16
|
+
env?: Record<string, string | undefined>;
|
|
17
|
+
/** Base directory for relative bundle paths supplied through CliIO.cwd. */
|
|
18
|
+
cwd?: string;
|
|
19
|
+
/** Explicit publication policy, useful for embedding and hermetic tests. */
|
|
20
|
+
policy?: DefPolicy;
|
|
21
|
+
/** Explicit consumed-artifact policy, useful for embedding and hermetic tests. */
|
|
22
|
+
artifactPolicy?: DefPolicy;
|
|
23
|
+
/** Explicit origin policy, useful for embedding and hermetic tests. */
|
|
24
|
+
originPolicy?: OriginPolicy;
|
|
25
|
+
/** Explicit namespace-scoped origin rules. */
|
|
26
|
+
originRules?: OriginRules;
|
|
27
|
+
/** Already-verified organization floor; absent means local policy only. */
|
|
28
|
+
policyFloor?: PolicyFloor;
|
|
29
|
+
/** Diagnostic sink for `warn` policy decisions. */
|
|
30
|
+
warn?: (line: string) => void;
|
|
31
|
+
/** Optional signer seam for hermetic publication-verification tests. */
|
|
32
|
+
signerForPrincipal?: VerifyPublicationOptions['signerForPrincipal'];
|
|
33
|
+
/** SSHSIG namespace override for a host-specific signer adapter. */
|
|
34
|
+
namespace?: string;
|
|
35
|
+
}
|
|
36
|
+
/** Resolve publication policy with explicit > env > settings > default precedence. */
|
|
37
|
+
export declare function resolveDefPolicy(env: Record<string, string | undefined>, explicit?: DefPolicy): DefPolicy;
|
|
38
|
+
/** Resolve origin policy with the same four-layer precedence as defPolicy. */
|
|
39
|
+
export declare function resolveOriginPolicy(env: Record<string, string | undefined>, explicit?: OriginPolicy): OriginPolicy;
|
|
40
|
+
/** Resolve consumed-artifact policy with the same four-layer precedence. */
|
|
41
|
+
export declare function resolveArtifactPolicy(env: Record<string, string | undefined>, explicit?: DefPolicy): DefPolicy;
|
|
42
|
+
/** Resolve namespace rules with explicit > settings > empty precedence. */
|
|
43
|
+
export declare function resolveOriginRules(env: Record<string, string | undefined>, explicit?: OriginRules): OriginRules;
|
|
44
|
+
/**
|
|
45
|
+
* Build the execution-time verifier used by the production store resolver.
|
|
46
|
+
* Installed objects carry exact signed evidence in the store state directory;
|
|
47
|
+
* the verifier reads that evidence and performs a fresh signature decision.
|
|
48
|
+
*/
|
|
49
|
+
export interface ExecutionDefinitionVerifierInput {
|
|
50
|
+
bundleDigest: string;
|
|
51
|
+
objectPath: string;
|
|
52
|
+
}
|
|
53
|
+
export declare function createExecutionDefinitionVerifier(options?: PreCommitVerifierOptions): (input: ExecutionDefinitionVerifierInput) => Promise<DefVerdict>;
|
|
54
|
+
/** Input required by the execution-time origin verifier. */
|
|
55
|
+
export interface ExecutionOriginVerifierInput {
|
|
56
|
+
bundleDigest: string;
|
|
57
|
+
objectPath: string;
|
|
58
|
+
}
|
|
59
|
+
/**
|
|
60
|
+
* Build the execution-time origin verifier. Installed origin evidence is read
|
|
61
|
+
* from mutable store state and re-verified against the current allowed_signers
|
|
62
|
+
* trust root; no cached origin verdict is trusted.
|
|
63
|
+
*/
|
|
64
|
+
export declare function createExecutionOriginVerifier(options?: PreCommitVerifierOptions): (input: ExecutionOriginVerifierInput) => Promise<OriginVerdict>;
|
|
65
|
+
/** Production adapter bound by the root CLI's `defaultIO()`. */
|
|
66
|
+
export declare function createPreCommitVerifier(options?: PreCommitVerifierOptions): PreCommitVerifier;
|
|
67
|
+
/** Alias emphasizing the adapter's role in the install transaction. */
|
|
68
|
+
export declare const createProductionPreCommitVerifier: typeof createPreCommitVerifier;
|