owenloop 0.4.1 → 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.
Files changed (282) hide show
  1. package/CHANGELOG.md +71 -0
  2. package/README.md +182 -53
  3. package/bin/owenloop.mjs +50 -2
  4. package/dist/packages/work/src/agent/brief.d.ts +176 -0
  5. package/dist/packages/work/src/agent/brief.js +197 -0
  6. package/dist/packages/work/src/agent/loop.d.ts +141 -0
  7. package/dist/packages/work/src/agent/loop.js +669 -0
  8. package/dist/packages/work/src/agent/model-policy.d.ts +49 -0
  9. package/dist/packages/work/src/agent/model-policy.js +138 -0
  10. package/dist/packages/work/src/agent/workdir.d.ts +210 -0
  11. package/dist/packages/work/src/agent/workdir.js +319 -0
  12. package/dist/packages/work/src/bundle/cache.d.ts +92 -0
  13. package/dist/packages/work/src/bundle/cache.js +338 -0
  14. package/dist/packages/work/src/bundle/fetch.d.ts +87 -0
  15. package/dist/packages/work/src/bundle/fetch.js +345 -0
  16. package/dist/packages/work/src/bundle/types.d.ts +164 -0
  17. package/dist/packages/work/src/bundle/types.js +1 -0
  18. package/dist/packages/work/src/consumed-verifier.d.ts +45 -0
  19. package/dist/packages/work/src/consumed-verifier.js +205 -0
  20. package/dist/packages/work/src/credentials/owenloop.d.ts +11 -0
  21. package/dist/packages/work/src/credentials/owenloop.js +28 -0
  22. package/dist/packages/work/src/credentials/reader.d.ts +36 -0
  23. package/dist/packages/work/src/credentials/reader.js +32 -0
  24. package/dist/packages/work/src/credentials/resolve.d.ts +19 -0
  25. package/dist/packages/work/src/credentials/resolve.js +56 -0
  26. package/dist/packages/work/src/exec/instructions.d.ts +99 -0
  27. package/dist/packages/work/src/exec/instructions.js +323 -0
  28. package/dist/packages/work/src/exec/loop.d.ts +40 -0
  29. package/dist/packages/work/src/exec/loop.js +332 -0
  30. package/dist/packages/work/src/exec/payload.d.ts +29 -0
  31. package/dist/packages/work/src/exec/payload.js +54 -0
  32. package/dist/packages/work/src/exec/receipt.d.ts +41 -0
  33. package/dist/packages/work/src/exec/receipt.js +32 -0
  34. package/dist/packages/work/src/exec/runner.d.ts +71 -0
  35. package/dist/packages/work/src/exec/runner.js +256 -0
  36. package/dist/packages/work/src/harness/child-env.d.ts +100 -0
  37. package/dist/packages/work/src/harness/child-env.js +134 -0
  38. package/dist/packages/work/src/harness/claude.d.ts +140 -0
  39. package/dist/packages/work/src/harness/claude.js +837 -0
  40. package/dist/packages/work/src/harness/codex.d.ts +111 -0
  41. package/dist/packages/work/src/harness/codex.js +1024 -0
  42. package/dist/packages/work/src/harness/contract.d.ts +308 -0
  43. package/dist/packages/work/src/harness/contract.js +32 -0
  44. package/dist/packages/work/src/harness/fake.d.ts +59 -0
  45. package/dist/packages/work/src/harness/fake.js +91 -0
  46. package/dist/packages/work/src/harness/jsonrpc-stdio.d.ts +108 -0
  47. package/dist/packages/work/src/harness/jsonrpc-stdio.js +351 -0
  48. package/dist/packages/work/src/harness/permissions.d.ts +75 -0
  49. package/dist/packages/work/src/harness/permissions.js +182 -0
  50. package/dist/packages/work/src/harness/registry.d.ts +47 -0
  51. package/dist/packages/work/src/harness/registry.js +45 -0
  52. package/dist/packages/work/src/harness/session-store.d.ts +181 -0
  53. package/dist/packages/work/src/harness/session-store.js +523 -0
  54. package/dist/packages/work/src/harness/types.d.ts +29 -0
  55. package/dist/packages/work/src/harness/types.js +14 -0
  56. package/dist/packages/work/src/harnesses.d.ts +38 -0
  57. package/dist/packages/work/src/harnesses.js +38 -0
  58. package/dist/packages/work/src/hold/loop.d.ts +36 -0
  59. package/dist/packages/work/src/hold/loop.js +23 -0
  60. package/dist/packages/work/src/hold/mcp.d.ts +75 -0
  61. package/dist/packages/work/src/hold/mcp.js +264 -0
  62. package/dist/packages/work/src/hub/client.d.ts +23 -0
  63. package/dist/packages/work/src/hub/client.js +91 -0
  64. package/dist/packages/work/src/hub/types.d.ts +326 -0
  65. package/dist/packages/work/src/hub/types.js +26 -0
  66. package/dist/packages/work/src/lease/loop.d.ts +94 -0
  67. package/dist/packages/work/src/lease/loop.js +277 -0
  68. package/dist/packages/work/src/main.d.ts +1 -0
  69. package/dist/packages/work/src/main.js +48 -0
  70. package/dist/packages/work/src/mcp/server.d.ts +125 -0
  71. package/dist/packages/work/src/mcp/server.js +320 -0
  72. package/dist/packages/work/src/owenloop-bin.d.ts +1 -0
  73. package/dist/packages/work/src/owenloop-bin.js +18 -0
  74. package/dist/packages/work/src/roles/agent-run.d.ts +124 -0
  75. package/dist/packages/work/src/roles/agent-run.js +529 -0
  76. package/dist/packages/work/src/roles/exec.d.ts +48 -0
  77. package/dist/packages/work/src/roles/exec.js +228 -0
  78. package/dist/packages/work/src/roles/hold.d.ts +72 -0
  79. package/dist/packages/work/src/roles/hold.js +363 -0
  80. package/dist/packages/work/src/roles/join.d.ts +18 -0
  81. package/dist/packages/work/src/roles/join.js +204 -0
  82. package/dist/packages/work/src/roles/lint.d.ts +58 -0
  83. package/dist/packages/work/src/roles/lint.js +234 -0
  84. package/dist/packages/work/src/roles/prepare.d.ts +1 -0
  85. package/dist/packages/work/src/roles/prepare.js +249 -0
  86. package/dist/packages/work/src/roles/release.d.ts +48 -0
  87. package/dist/packages/work/src/roles/release.js +137 -0
  88. package/dist/packages/work/src/roles/sessions.d.ts +61 -0
  89. package/dist/packages/work/src/roles/sessions.js +180 -0
  90. package/dist/packages/work/src/roles/settings.d.ts +6 -0
  91. package/dist/packages/work/src/roles/settings.js +71 -0
  92. package/dist/packages/work/src/roles/shift.d.ts +13 -0
  93. package/dist/packages/work/src/roles/shift.js +250 -0
  94. package/dist/packages/work/src/roles/signals.d.ts +55 -0
  95. package/dist/packages/work/src/roles/signals.js +62 -0
  96. package/dist/packages/work/src/settings/provision.d.ts +21 -0
  97. package/dist/packages/work/src/settings/provision.js +47 -0
  98. package/dist/packages/work/src/settings/settings.d.ts +136 -0
  99. package/dist/packages/work/src/settings/settings.js +155 -0
  100. package/dist/packages/work/src/shift/client.d.ts +24 -0
  101. package/dist/packages/work/src/shift/client.js +124 -0
  102. package/dist/packages/work/src/shift/loop.d.ts +131 -0
  103. package/dist/packages/work/src/shift/loop.js +751 -0
  104. package/dist/packages/work/src/shift/protocol.d.ts +95 -0
  105. package/dist/packages/work/src/shift/protocol.js +24 -0
  106. package/dist/packages/work/src/shift/routing.d.ts +35 -0
  107. package/dist/packages/work/src/shift/routing.js +50 -0
  108. package/dist/packages/work/src/shift/runtime.d.ts +45 -0
  109. package/dist/packages/work/src/shift/runtime.js +337 -0
  110. package/dist/packages/work/src/shift/server.d.ts +23 -0
  111. package/dist/packages/work/src/shift/server.js +716 -0
  112. package/dist/packages/work/src/shift/spawn.d.ts +109 -0
  113. package/dist/packages/work/src/shift/spawn.js +158 -0
  114. package/dist/packages/work/src/shift/state.d.ts +79 -0
  115. package/dist/packages/work/src/shift/state.js +385 -0
  116. package/dist/packages/work/src/submit-proof.d.ts +36 -0
  117. package/dist/packages/work/src/submit-proof.js +93 -0
  118. package/dist/packages/work/src/usage.d.ts +6 -0
  119. package/dist/packages/work/src/usage.js +175 -0
  120. package/dist/src/add.d.ts +189 -0
  121. package/dist/src/add.js +300 -0
  122. package/dist/src/archive.d.ts +97 -0
  123. package/dist/src/archive.js +591 -0
  124. package/dist/src/bundle/index.d.ts +64 -0
  125. package/dist/src/bundle/index.js +508 -0
  126. package/dist/src/bundle/manifest.d.ts +50 -0
  127. package/dist/src/bundle/manifest.js +435 -0
  128. package/dist/src/bundle/runtime.d.ts +26 -0
  129. package/dist/src/bundle/runtime.js +64 -0
  130. package/dist/src/bundle/tar.d.ts +62 -0
  131. package/dist/src/bundle/tar.js +238 -0
  132. package/dist/src/bundle/types.d.ts +105 -0
  133. package/dist/src/bundle/types.js +21 -0
  134. package/dist/{cli.d.ts → src/cli.d.ts} +92 -7
  135. package/dist/src/cli.js +5968 -0
  136. package/dist/{credentials.d.ts → src/credentials.d.ts} +22 -15
  137. package/dist/{credentials.js → src/credentials.js} +35 -31
  138. package/dist/src/crypto/allowed-signers.d.ts +68 -0
  139. package/dist/src/crypto/allowed-signers.js +307 -0
  140. package/dist/src/crypto/canonical.d.ts +8 -0
  141. package/dist/src/crypto/canonical.js +92 -0
  142. package/dist/src/crypto/chain.d.ts +65 -0
  143. package/dist/src/crypto/chain.js +377 -0
  144. package/dist/src/crypto/dsse.d.ts +209 -0
  145. package/dist/src/crypto/dsse.js +282 -0
  146. package/dist/src/crypto/enrollment.d.ts +78 -0
  147. package/dist/src/crypto/enrollment.js +186 -0
  148. package/dist/src/crypto/index.d.ts +48 -0
  149. package/dist/src/crypto/index.js +44 -0
  150. package/dist/src/crypto/keys.d.ts +258 -0
  151. package/dist/src/crypto/keys.js +908 -0
  152. package/dist/src/crypto/org-root.d.ts +33 -0
  153. package/dist/src/crypto/org-root.js +78 -0
  154. package/dist/src/crypto/origin-rules.d.ts +56 -0
  155. package/dist/src/crypto/origin-rules.js +143 -0
  156. package/dist/src/crypto/policy-floor.d.ts +98 -0
  157. package/dist/src/crypto/policy-floor.js +353 -0
  158. package/dist/src/crypto/records.d.ts +316 -0
  159. package/dist/src/crypto/records.js +157 -0
  160. package/dist/src/crypto/scope.d.ts +49 -0
  161. package/dist/src/crypto/scope.js +83 -0
  162. package/dist/src/crypto/ssh.d.ts +171 -0
  163. package/dist/src/crypto/ssh.js +396 -0
  164. package/dist/src/crypto/submission.d.ts +33 -0
  165. package/dist/src/crypto/submission.js +47 -0
  166. package/dist/src/crypto/trust-roots.d.ts +29 -0
  167. package/dist/src/crypto/trust-roots.js +39 -0
  168. package/dist/src/crypto/verify-consumed.d.ts +67 -0
  169. package/dist/src/crypto/verify-consumed.js +259 -0
  170. package/dist/src/crypto/verify-origin.d.ts +50 -0
  171. package/dist/src/crypto/verify-origin.js +151 -0
  172. package/dist/src/crypto/verify-publication.d.ts +60 -0
  173. package/dist/src/crypto/verify-publication.js +150 -0
  174. package/dist/{defs.d.ts → src/defs.d.ts} +24 -1
  175. package/dist/{defs.js → src/defs.js} +181 -61
  176. package/dist/{engine.d.ts → src/engine.d.ts} +105 -9
  177. package/dist/{engine.js → src/engine.js} +251 -47
  178. package/dist/{factory.d.ts → src/factory.d.ts} +16 -0
  179. package/dist/{factory.js → src/factory.js} +16 -4
  180. package/dist/src/global-config.d.ts +59 -0
  181. package/dist/src/global-config.js +84 -0
  182. package/dist/{hub.d.ts → src/hub.d.ts} +280 -31
  183. package/dist/{hub.js → src/hub.js} +493 -52
  184. package/dist/src/index.d.ts +47 -0
  185. package/dist/src/index.js +41 -0
  186. package/dist/src/install.d.ts +538 -0
  187. package/dist/src/install.js +1981 -0
  188. package/dist/src/lock.d.ts +38 -0
  189. package/dist/src/lock.js +325 -0
  190. package/dist/src/mcp/serve.d.ts +109 -0
  191. package/dist/{mcp → src/mcp}/serve.js +335 -75
  192. package/dist/{mcp → src/mcp}/server.d.ts +6 -9
  193. package/dist/{mcp → src/mcp}/server.js +18 -10
  194. package/dist/{model.d.ts → src/model.d.ts} +15 -0
  195. package/dist/{model.js → src/model.js} +112 -2
  196. package/dist/src/order-resolver.d.ts +184 -0
  197. package/dist/src/order-resolver.js +252 -0
  198. package/dist/src/package-version.d.ts +10 -0
  199. package/dist/src/package-version.js +42 -0
  200. package/dist/{paths.d.ts → src/paths.d.ts} +14 -1
  201. package/dist/{paths.js → src/paths.js} +18 -0
  202. package/dist/src/schemas/enrollment-grant.v1.schema.json +90 -0
  203. package/dist/src/schemas/index.d.ts +1416 -0
  204. package/dist/src/schemas/index.js +31 -0
  205. package/dist/src/schemas/order.v1.schema.json +106 -0
  206. package/dist/src/schemas/origin.v1.schema.json +68 -0
  207. package/dist/src/schemas/policy-floor.v1.schema.json +29 -0
  208. package/dist/src/schemas/publication.v1.schema.json +31 -0
  209. package/dist/src/schemas/revocation.v1.schema.json +39 -0
  210. package/dist/src/schemas/submission.v1.schema.json +61 -0
  211. package/dist/src/store/def-source.d.ts +52 -0
  212. package/dist/src/store/def-source.js +335 -0
  213. package/dist/src/store/index-file.d.ts +69 -0
  214. package/dist/src/store/index-file.js +151 -0
  215. package/dist/src/store/index.d.ts +27 -0
  216. package/dist/src/store/index.js +22 -0
  217. package/dist/src/store/ingestor.d.ts +43 -0
  218. package/dist/src/store/ingestor.js +211 -0
  219. package/dist/src/store/install.d.ts +228 -0
  220. package/dist/src/store/install.js +555 -0
  221. package/dist/src/store/instruction-source.d.ts +49 -0
  222. package/dist/src/store/instruction-source.js +298 -0
  223. package/dist/src/store/origin-evidence.d.ts +21 -0
  224. package/dist/src/store/origin-evidence.js +66 -0
  225. package/dist/src/store/pre-commit-verifier.d.ts +68 -0
  226. package/dist/src/store/pre-commit-verifier.js +418 -0
  227. package/dist/src/store/resolve.d.ts +138 -0
  228. package/dist/src/store/resolve.js +363 -0
  229. package/dist/src/store/types.d.ts +288 -0
  230. package/dist/src/store/types.js +356 -0
  231. package/dist/{types.d.ts → src/types.d.ts} +58 -24
  232. package/dist/{untar.d.ts → src/untar.d.ts} +8 -23
  233. package/dist/src/untar.js +38 -0
  234. package/dist/{util.d.ts → src/util.d.ts} +3 -2
  235. package/dist/{util.js → src/util.js} +3 -2
  236. package/dist/{owenwork.d.ts → src/work-settings.d.ts} +22 -22
  237. package/dist/{owenwork.js → src/work-settings.js} +27 -27
  238. package/docs/agent-runner.md +86 -0
  239. package/docs/authoring.md +150 -59
  240. package/docs/bundles.md +250 -0
  241. package/docs/cli.md +1758 -163
  242. package/docs/crypto.md +816 -0
  243. package/docs/design.md +374 -52
  244. package/docs/embedding.md +135 -27
  245. package/docs/wire-contracts.md +380 -0
  246. package/examples/workflows/{command-worker.yaml → command-executor.yaml} +15 -15
  247. package/examples/workflows/compile-dev-playbook.yaml +338 -0
  248. package/examples/workflows/judges/gate-sharpness.md +39 -0
  249. package/examples/workflows/judges/security.md +34 -0
  250. package/package.json +22 -8
  251. package/plugins/claude-code/.claude-plugin/marketplace.json +14 -0
  252. package/plugins/claude-code/plugin/.claude-plugin/plugin.json +8 -0
  253. package/plugins/claude-code/plugin/.mcp.json +14 -0
  254. package/plugins/claude-code/plugin/hooks/hooks.json +26 -0
  255. package/plugins/claude-code/plugin/hooks/session-end.sh +40 -0
  256. package/plugins/claude-code/plugin/hooks/session-start.sh +52 -0
  257. package/plugins/claude-code/plugin/skills/author/SKILL.md +181 -0
  258. package/plugins/claude-code/plugin/skills/conduct/SKILL.md +106 -0
  259. package/plugins/claude-code/plugin/skills/shift/SKILL.md +105 -0
  260. package/plugins/codex/.agents/plugins/marketplace.json +21 -0
  261. package/plugins/codex/plugins/owenloop/.codex-plugin/plugin.json +7 -0
  262. package/plugins/codex/plugins/owenloop/.mcp.json +20 -0
  263. package/plugins/codex/plugins/owenloop/hooks/hooks.json +26 -0
  264. package/plugins/codex/plugins/owenloop/hooks/session-end.sh +40 -0
  265. package/plugins/codex/plugins/owenloop/hooks/session-start.sh +52 -0
  266. package/plugins/codex/plugins/owenloop/skills/author/SKILL.md +181 -0
  267. package/plugins/codex/plugins/owenloop/skills/conduct/SKILL.md +106 -0
  268. package/plugins/codex/plugins/owenloop/skills/shift/SKILL.md +105 -0
  269. package/dist/add.d.ts +0 -384
  270. package/dist/add.js +0 -834
  271. package/dist/cli.js +0 -3270
  272. package/dist/index.d.ts +0 -32
  273. package/dist/index.js +0 -23
  274. package/dist/lock.d.ts +0 -80
  275. package/dist/lock.js +0 -217
  276. package/dist/mcp/serve.d.ts +0 -84
  277. package/dist/untar.js +0 -164
  278. /package/dist/{schema.d.ts → src/schema.d.ts} +0 -0
  279. /package/dist/{schema.js → src/schema.js} +0 -0
  280. /package/dist/{store.d.ts → src/store.d.ts} +0 -0
  281. /package/dist/{store.js → src/store.js} +0 -0
  282. /package/dist/{types.js → src/types.js} +0 -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,11 @@
1
+ import type { Credential, Keychain } from '../../../../src/hub.ts';
2
+ import type { CredentialReader } from './reader.ts';
3
+ export declare class OwenloopCredentialReader implements CredentialReader {
4
+ private readonly opts;
5
+ constructor(opts: {
6
+ account: string;
7
+ env?: Record<string, string | undefined>;
8
+ keychain?: Keychain;
9
+ });
10
+ read(origin: string): Promise<Credential | null>;
11
+ }
@@ -0,0 +1,28 @@
1
+ /**
2
+ * Live credential reader backed by owenloop 0.4.0's `readStoredCredential`.
3
+ *
4
+ * This is the ONE enforcement point for "owenloop never reads the human slot":
5
+ * it always addresses `principal: 'agent'` with the configured account. A
6
+ * human-only origin therefore reads as absent (`null`) — owenloop's slots are
7
+ * distinct storage keys, so a Scoped Identity read never falls back to `human`.
8
+ *
9
+ * `read()` lets owenloop's THROWS propagate: a remote-plaintext / invalid
10
+ * origin (SEC-2) or an external-credential-command failure are genuine errors,
11
+ * distinct from the `null` "no Scoped Identity key" case that the resolver turns into a
12
+ * refuse-to-start. Read-only by contract — owenloop never writes credentials.
13
+ */
14
+ import { readStoredCredential } from "../../../../src/hub.js";
15
+ export class OwenloopCredentialReader {
16
+ opts;
17
+ constructor(opts) {
18
+ this.opts = opts;
19
+ }
20
+ async read(origin) {
21
+ return readStoredCredential(origin, {
22
+ principal: 'agent',
23
+ account: this.opts.account,
24
+ ...(this.opts.env !== undefined ? { env: this.opts.env } : {}),
25
+ ...(this.opts.keychain !== undefined ? { keychain: this.opts.keychain } : {}),
26
+ });
27
+ }
28
+ }
@@ -0,0 +1,36 @@
1
+ /**
2
+ * Credential read seam. owenloop reads hub credentials through owenloop's
3
+ * store ONLY — it never writes, prints, or stores credentials itself, and it
4
+ * never reads the keychain or `credentials.json` formats directly.
5
+ *
6
+ * The live wiring is against owenloop 0.4.0's `readStoredCredential`
7
+ * (src/credentials/owenloop.ts → `OwenloopCredentialReader`). owenloop reads
8
+ * ONLY the `agent:<account>` slots — never the `human` slot — so a human-only
9
+ * origin reads as absent (`null`), which the roles surface as a clean refuse.
10
+ * `Credential` is re-exported from owenloop below so this seam and the store
11
+ * speak the exact same union.
12
+ */
13
+ /** The root package's stored-credential union (agent / oauth / oauth-pasted). */
14
+ export type { Credential } from '../../../../src/hub.ts';
15
+ import type { Credential } from '../../../../src/hub.ts';
16
+ /**
17
+ * Reads a stored credential for a hub origin. `read` resolves to `null` when
18
+ * no credential is stored for that origin. Read-only by contract.
19
+ */
20
+ export interface CredentialReader {
21
+ read(origin: string): Promise<Credential | null>;
22
+ }
23
+ /**
24
+ * In-memory reader seeded from a `Record<origin, Credential>`. Lives in `src`
25
+ * (not `test/`) because C2+ role tests reuse it to stand in for the real store.
26
+ */
27
+ export declare class FakeCredentialReader implements CredentialReader {
28
+ private readonly store;
29
+ constructor(store?: Record<string, Credential>);
30
+ read(origin: string): Promise<Credential | null>;
31
+ }
32
+ /**
33
+ * Bridge from a stored credential to the bearer token the hub client's
34
+ * `getToken` seam expects. Every credential kind carries an `accessToken`.
35
+ */
36
+ export declare function credentialToToken(c: Credential): string;
@@ -0,0 +1,32 @@
1
+ /**
2
+ * Credential read seam. owenloop reads hub credentials through owenloop's
3
+ * store ONLY — it never writes, prints, or stores credentials itself, and it
4
+ * never reads the keychain or `credentials.json` formats directly.
5
+ *
6
+ * The live wiring is against owenloop 0.4.0's `readStoredCredential`
7
+ * (src/credentials/owenloop.ts → `OwenloopCredentialReader`). owenloop reads
8
+ * ONLY the `agent:<account>` slots — never the `human` slot — so a human-only
9
+ * origin reads as absent (`null`), which the roles surface as a clean refuse.
10
+ * `Credential` is re-exported from owenloop below so this seam and the store
11
+ * speak the exact same union.
12
+ */
13
+ /**
14
+ * In-memory reader seeded from a `Record<origin, Credential>`. Lives in `src`
15
+ * (not `test/`) because C2+ role tests reuse it to stand in for the real store.
16
+ */
17
+ export class FakeCredentialReader {
18
+ store;
19
+ constructor(store = {}) {
20
+ this.store = store;
21
+ }
22
+ async read(origin) {
23
+ return this.store[origin] ?? null;
24
+ }
25
+ }
26
+ /**
27
+ * Bridge from a stored credential to the bearer token the hub client's
28
+ * `getToken` seam expects. Every credential kind carries an `accessToken`.
29
+ */
30
+ export function credentialToToken(c) {
31
+ return c.accessToken;
32
+ }
@@ -0,0 +1,19 @@
1
+ export type BearerResult = {
2
+ ok: true;
3
+ token: string;
4
+ } | {
5
+ ok: false;
6
+ code: number;
7
+ message: string;
8
+ };
9
+ /**
10
+ * The owenloop `--as <slot>` argument for an account: `agent` for the default
11
+ * account, `agent:<account>` otherwise. Grounded from owenloop's `--as`
12
+ * semantics (`human` | `agent` | `agent:<account>`).
13
+ */
14
+ export declare function slotArg(account: string): string;
15
+ export declare function resolveBearer(args: {
16
+ origin: string;
17
+ account: string;
18
+ env: Record<string, string | undefined>;
19
+ }): Promise<BearerResult>;
@@ -0,0 +1,56 @@
1
+ /**
2
+ * The ONE place the bearer-token resolution / refuse / dev-override logic lives,
3
+ * so all five roles share identical precedence instead of re-deriving it:
4
+ *
5
+ * 1. `OWENLOOP_TOKEN` (trimmed, non-empty) — an EXPLICIT dev-only override.
6
+ * When set, it is used verbatim and the store + account are skipped.
7
+ * 2. Otherwise read the `agent:<account>` slot from owenloop's store:
8
+ * - a `Credential` → its bearer token (`credentialToToken`).
9
+ * - `null` → refuse (code 2): no Scoped Identity key for this origin/account,
10
+ * naming a runnable `owenloop login` connect command.
11
+ * - a THROW → error (code 1): a genuine read failure (bad origin /
12
+ * external-command failure), surfaced with its message.
13
+ *
14
+ * The refuse (code 2) is a refuse-to-start precondition, mirroring the old
15
+ * "no token" exit code, so existing exit-code assertions stay valid — only the
16
+ * message text changes. owenloop stays read-only w.r.t. credentials.
17
+ */
18
+ import { OwenloopCredentialReader } from "./owenloop.js";
19
+ import { credentialToToken } from "./reader.js";
20
+ /**
21
+ * The owenloop `--as <slot>` argument for an account: `agent` for the default
22
+ * account, `agent:<account>` otherwise. Grounded from owenloop's `--as`
23
+ * semantics (`human` | `agent` | `agent:<account>`).
24
+ */
25
+ export function slotArg(account) {
26
+ return account === 'default' ? 'agent' : `agent:${account}`;
27
+ }
28
+ export async function resolveBearer(args) {
29
+ const { origin, account, env } = args;
30
+ // 1. Dev-only override: explicit OWENLOOP_TOKEN bypasses the store + account.
31
+ const override = env['OWENLOOP_TOKEN']?.trim();
32
+ if (override !== undefined && override !== '') {
33
+ return { ok: true, token: override };
34
+ }
35
+ // 2. The store: read ONLY the agent:<account> slot (never human).
36
+ let cred;
37
+ try {
38
+ cred = await new OwenloopCredentialReader({ account, env }).read(origin);
39
+ }
40
+ catch (err) {
41
+ const detail = err instanceof Error ? err.message : String(err);
42
+ return {
43
+ ok: false,
44
+ code: 1,
45
+ message: `credential read failed for ${origin} (account "${account}"): ${detail}`,
46
+ };
47
+ }
48
+ if (cred === null) {
49
+ return {
50
+ ok: false,
51
+ code: 2,
52
+ message: `no Scoped Identity key for ${origin} (account "${account}") — run: owenloop login --hub ${origin} --as ${slotArg(account)}`,
53
+ };
54
+ }
55
+ return { ok: true, token: credentialToToken(cred) };
56
+ }
@@ -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;