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,353 @@
1
+ /**
2
+ * Verification and monotone evaluation of admin-signed organization policy floors.
3
+ *
4
+ * This module consumes the exact DSSE envelope bytes supplied by a caller, verifies
5
+ * the frozen policy-floor record, and validates the signer's enrollment chain and
6
+ * organization-wide scope. It performs no filesystem or network I/O, and a hub or
7
+ * other relaying transport never authors, derives, or defaults a floor here.
8
+ *
9
+ * A floor is a minimum, never a replacement: effective definition policy is the
10
+ * stricter of local policy and the verified floor. Every absent or failed floor
11
+ * returns no floor to the merge function, so untrusted input can stall evaluation
12
+ * but can never weaken the driver's local policy.
13
+ */
14
+ import { decodeBase64Strict, DSSE_SSH_NAMESPACE, dsseVerifyPolicyFloor, DsseEnvelopeError, } from "./dsse.js";
15
+ import { publicKeyDescriptor } from "./keys.js";
16
+ import { createSshSigner, SshSignerError, } from "./ssh.js";
17
+ import { enrollmentGrantSchema, policyFloorSchema, } from "../schemas/index.js";
18
+ import { summarizeIssues, validateValue } from "../schema.js";
19
+ import { validateEnrollmentChain, } from "./chain.js";
20
+ import { axisPermits } from "./scope.js";
21
+ /** Strictness ordering for the existing C2 definition-policy vocabulary. */
22
+ export const DEF_POLICY_RANK = Object.freeze({
23
+ off: 0,
24
+ warn: 1,
25
+ enforce: 2,
26
+ });
27
+ /** Convert the frozen floor's unsigned-definition axis to C2's minimum policy. */
28
+ export function floorDefPolicyMinimum(floor) {
29
+ return floor.unsignedDefs === 'refuse' ? 'enforce' : 'warn';
30
+ }
31
+ /** Convert the frozen floor's origin axis to the parallel local policy. */
32
+ export function originRulesMinimum(floor) {
33
+ return floor.originRules === 'enforced' ? 'enforce' : 'warn';
34
+ }
35
+ /** Convert the frozen floor's unsigned-artifact axis to consume policy. */
36
+ export function artifactPolicyMinimum(floor) {
37
+ return floor.unsignedArtifacts === 'refuse' ? 'enforce' : 'warn';
38
+ }
39
+ /** Return the stricter policy without assigning one policy over the other. */
40
+ export function stricterDefPolicy(a, b) {
41
+ return DEF_POLICY_RANK[a] >= DEF_POLICY_RANK[b] ? a : b;
42
+ }
43
+ /**
44
+ * Presets are concrete wire values, not a second policy-level primitive. The
45
+ * trustMode axis remains informational here; policyFloorGaps reports that
46
+ * unevaluated control rather than pretending this package implements it.
47
+ */
48
+ export const POLICY_FLOOR_PRESETS = Object.freeze({
49
+ L0: Object.freeze({
50
+ trustMode: 'seamless',
51
+ unsignedDefs: 'warn',
52
+ unsignedArtifacts: 'warn',
53
+ originRules: 'advisory',
54
+ }),
55
+ L1: Object.freeze({
56
+ trustMode: 'seamless',
57
+ unsignedDefs: 'refuse',
58
+ unsignedArtifacts: 'refuse',
59
+ originRules: 'advisory',
60
+ }),
61
+ L2: Object.freeze({
62
+ trustMode: 'strict',
63
+ unsignedDefs: 'refuse',
64
+ unsignedArtifacts: 'refuse',
65
+ originRules: 'enforced',
66
+ }),
67
+ });
68
+ /** Report every frozen axis that this engine does not evaluate yet. */
69
+ export function policyFloorGaps(floor) {
70
+ return [
71
+ {
72
+ axis: 'trustMode',
73
+ value: floor.trustMode,
74
+ reason: 'trustMode is carried but not evaluated by this engine; L2 git-pinned roster and sandbox authorship are not delivered here',
75
+ },
76
+ ];
77
+ }
78
+ /**
79
+ * Merge a verified floor as a strictness minimum on both policy axes. The
80
+ * optional origin and artifact arguments preserve the existing positional API;
81
+ * callers that do not resolve either policy receive the neutral local value `off`.
82
+ */
83
+ export function mergePolicyFloorWithLocal(local, floor, localOriginPolicy = 'off', localArtifactPolicy = 'off') {
84
+ if (floor === undefined) {
85
+ return {
86
+ effective: local,
87
+ local,
88
+ raised: false,
89
+ originPolicy: localOriginPolicy,
90
+ artifactPolicy: localArtifactPolicy,
91
+ gaps: [],
92
+ };
93
+ }
94
+ const floorMinimum = floorDefPolicyMinimum(floor);
95
+ const effective = stricterDefPolicy(local, floorMinimum);
96
+ const originPolicy = stricterDefPolicy(localOriginPolicy, originRulesMinimum(floor));
97
+ const artifactPolicy = stricterDefPolicy(localArtifactPolicy, artifactPolicyMinimum(floor));
98
+ return {
99
+ effective,
100
+ local,
101
+ raised: effective !== local,
102
+ originPolicy,
103
+ artifactPolicy,
104
+ gaps: policyFloorGaps(floor),
105
+ };
106
+ }
107
+ function invalid(reason) {
108
+ return { kind: 'invalid', reason };
109
+ }
110
+ function unverifiable(reason) {
111
+ return { kind: 'unverifiable', reason };
112
+ }
113
+ function isJsonObject(value) {
114
+ return typeof value === 'object' && value !== null && !Array.isArray(value);
115
+ }
116
+ function decodePolicyFloor(bytes) {
117
+ let envelope;
118
+ try {
119
+ envelope = JSON.parse(Buffer.from(bytes).toString('utf8'));
120
+ }
121
+ catch {
122
+ return invalid('policy floor envelope is not valid JSON');
123
+ }
124
+ if (!isJsonObject(envelope))
125
+ return invalid('policy floor envelope is not a JSON object');
126
+ const payload = envelope.payload;
127
+ if (typeof payload !== 'string')
128
+ return invalid("policy floor envelope is missing a string 'payload'");
129
+ let payloadBytes;
130
+ try {
131
+ payloadBytes = decodeBase64Strict(payload, { allowEmpty: true });
132
+ }
133
+ catch (error) {
134
+ return invalid(`policy floor payload is not valid Base64: ${error.message}`);
135
+ }
136
+ let decoded;
137
+ try {
138
+ decoded = JSON.parse(payloadBytes.toString('utf8'));
139
+ }
140
+ catch {
141
+ return invalid('policy floor payload is not valid JSON');
142
+ }
143
+ if (!isJsonObject(decoded))
144
+ return invalid('policy floor payload is not a JSON object');
145
+ const shape = validateValue(policyFloorSchema, decoded);
146
+ if (!shape.valid) {
147
+ return invalid(`policy floor record does not match schema: ${summarizeIssues(shape.issues)}`);
148
+ }
149
+ return { envelope, record: decoded };
150
+ }
151
+ function principalText(principal) {
152
+ if (!isJsonObject(principal))
153
+ return undefined;
154
+ if (typeof principal.kind !== 'string' || typeof principal.id !== 'string')
155
+ return undefined;
156
+ return `${principal.kind}:${principal.id}`;
157
+ }
158
+ function parseGrantCandidate(raw, targetKeyId) {
159
+ let envelope;
160
+ try {
161
+ envelope = JSON.parse(Buffer.from(raw).toString('utf8'));
162
+ }
163
+ catch {
164
+ return { kind: 'skip' };
165
+ }
166
+ if (!isJsonObject(envelope) || typeof envelope.payload !== 'string')
167
+ return { kind: 'skip' };
168
+ let payloadBytes;
169
+ try {
170
+ payloadBytes = decodeBase64Strict(envelope.payload, { allowEmpty: true });
171
+ }
172
+ catch {
173
+ return { kind: 'skip' };
174
+ }
175
+ let decoded;
176
+ try {
177
+ decoded = JSON.parse(payloadBytes.toString('utf8'));
178
+ }
179
+ catch {
180
+ return { kind: 'skip' };
181
+ }
182
+ if (!isJsonObject(decoded))
183
+ return { kind: 'skip' };
184
+ const shape = validateValue(enrollmentGrantSchema, decoded);
185
+ if (!shape.valid) {
186
+ const newKey = decoded.newKey;
187
+ if (!isJsonObject(newKey) || newKey.keyid !== targetKeyId)
188
+ return { kind: 'skip' };
189
+ return { kind: 'invalid', reason: `policy floor signer grant does not match schema: ${summarizeIssues(shape.issues)}` };
190
+ }
191
+ const grant = decoded;
192
+ if (grant.newKey.keyid !== targetKeyId)
193
+ return { kind: 'skip' };
194
+ const principal = principalText(grant.principal);
195
+ if (principal === undefined)
196
+ return { kind: 'invalid', reason: `policy floor signer grant for '${targetKeyId}' has an invalid principal` };
197
+ let descriptor;
198
+ try {
199
+ descriptor = publicKeyDescriptor(grant.newKey.openSshPublicKey);
200
+ }
201
+ catch (error) {
202
+ return { kind: 'invalid', reason: `policy floor signer grant for '${targetKeyId}' has an invalid public key: ${error instanceof Error ? error.message : String(error)}` };
203
+ }
204
+ if (descriptor.keyid !== targetKeyId) {
205
+ return {
206
+ kind: 'invalid',
207
+ reason: `policy floor signer grant for '${targetKeyId}' carries public key '${descriptor.keyid}'`,
208
+ };
209
+ }
210
+ return {
211
+ kind: 'match',
212
+ candidate: {
213
+ keyid: descriptor.keyid,
214
+ principal,
215
+ publicKey: descriptor.openSshPublicKey,
216
+ },
217
+ };
218
+ }
219
+ /**
220
+ * Resolve the public key needed for the first DSSE check. The key is only a
221
+ * candidate here; WP-D4 remains the authority that proves the candidate reaches
222
+ * the local org-root anchor and retains the required scope.
223
+ */
224
+ function deriveSignerCandidate(input, targetKeyId) {
225
+ let rootDescriptor;
226
+ let rootError;
227
+ try {
228
+ rootDescriptor = publicKeyDescriptor(input.orgRootPublicKey);
229
+ }
230
+ catch (error) {
231
+ rootError = error instanceof Error ? error.message : String(error);
232
+ }
233
+ if (rootDescriptor?.keyid === targetKeyId) {
234
+ return {
235
+ keyid: rootDescriptor.keyid,
236
+ principal: 'org-root',
237
+ publicKey: rootDescriptor.openSshPublicKey,
238
+ };
239
+ }
240
+ if (!Array.isArray(input.grants))
241
+ return invalid('enrollment roster is not an array');
242
+ const matches = [];
243
+ for (const raw of input.grants) {
244
+ const result = parseGrantCandidate(raw, targetKeyId);
245
+ if (result.kind === 'invalid')
246
+ return invalid(result.reason);
247
+ if (result.kind === 'match')
248
+ matches.push(result.candidate);
249
+ }
250
+ if (matches.length > 1)
251
+ return invalid(`enrollment roster contains more than one signer grant for '${targetKeyId}'`);
252
+ const candidate = matches[0];
253
+ if (candidate !== undefined)
254
+ return candidate;
255
+ if (rootError !== undefined)
256
+ return unverifiable(`cannot use org root public key: ${rootError}`);
257
+ return invalid(`policy floor signer key '${targetKeyId}' is not present in the local enrollment material`);
258
+ }
259
+ function makeSigner(options, candidate) {
260
+ const factory = options.signerForPrincipal ?? ((args) => createSshSigner({
261
+ namespace: options.namespace ?? DSSE_SSH_NAMESPACE,
262
+ verify: args,
263
+ }));
264
+ try {
265
+ return factory({
266
+ principal: candidate.principal,
267
+ allowedSignersText: `${candidate.principal} ${candidate.publicKey}\n`,
268
+ });
269
+ }
270
+ catch (error) {
271
+ if (error instanceof SshSignerError)
272
+ return unverifiable(error.message);
273
+ return unverifiable(`policy floor verification setup failed: ${error instanceof Error ? error.message : String(error)}`);
274
+ }
275
+ }
276
+ function chainOptions(options) {
277
+ return {
278
+ ...(options.signerForPrincipal === undefined ? {} : { signerForPrincipal: options.signerForPrincipal }),
279
+ ...(options.namespace === undefined ? {} : { namespace: options.namespace }),
280
+ ...(options.maxChainDepth === undefined ? {} : { maxChainDepth: options.maxChainDepth }),
281
+ };
282
+ }
283
+ /** A floor signer is admin-level only when all three scope axes are unrestricted. */
284
+ function hasAdminScope(scope) {
285
+ return axisPermits(scope.pools, '*')
286
+ && axisPermits(scope.labels, '*')
287
+ && axisPermits(scope.namespaces, '*');
288
+ }
289
+ /**
290
+ * Verify one exact policy-floor envelope, then validate its signer through WP-D4.
291
+ * The record's unauthenticated fields select candidates only; the verified signer
292
+ * key-id and the chain verdict authorize the floor.
293
+ */
294
+ export async function verifyPolicyFloorRecord(input, options = {}) {
295
+ const decoded = decodePolicyFloor(input.envelopeBytes);
296
+ if ('kind' in decoded)
297
+ return decoded;
298
+ const { envelope, record } = decoded;
299
+ const candidate = deriveSignerCandidate(input, record.signedBy);
300
+ if ('kind' in candidate)
301
+ return candidate;
302
+ if (candidate.keyid !== record.signedBy) {
303
+ return invalid(`policy floor signer candidate '${candidate.keyid}' does not match record signedBy '${record.signedBy}'`);
304
+ }
305
+ const signer = makeSigner(options, candidate);
306
+ if ('kind' in signer)
307
+ return signer;
308
+ try {
309
+ const result = await dsseVerifyPolicyFloor(envelope, signer, { threshold: 1 });
310
+ const verified = result.signers[0];
311
+ if (verified === undefined)
312
+ return invalid('policy floor signature produced no verified signer');
313
+ if (verified.keyid !== record.signedBy) {
314
+ return invalid(`policy floor signer key '${verified.keyid}' does not match record signedBy '${record.signedBy}'`);
315
+ }
316
+ }
317
+ catch (error) {
318
+ if (error instanceof SshSignerError)
319
+ return unverifiable(error.message);
320
+ if (error instanceof DsseEnvelopeError)
321
+ return invalid(`policy floor signature verification failed: ${error.message}`);
322
+ return invalid(`policy floor signature verification failed: ${error instanceof Error ? error.message : String(error)}`);
323
+ }
324
+ finally {
325
+ signer.dispose?.();
326
+ }
327
+ let chain;
328
+ try {
329
+ chain = await validateEnrollmentChain({
330
+ targetKeyId: record.signedBy,
331
+ orgRootPublicKey: input.orgRootPublicKey,
332
+ grants: input.grants,
333
+ ...(input.revocations === undefined ? {} : { revocations: input.revocations }),
334
+ at: input.at,
335
+ }, chainOptions(options));
336
+ }
337
+ catch (error) {
338
+ return unverifiable(`policy floor enrollment-chain validation could not run: ${error instanceof Error ? error.message : String(error)}`);
339
+ }
340
+ if (chain.kind === 'unverifiable')
341
+ return chain;
342
+ if (chain.kind === 'invalid')
343
+ return chain;
344
+ if (!hasAdminScope(chain.effectiveScope)) {
345
+ return invalid(`policy floor signer '${chain.keyid}' lacks unrestricted admin scope on pools, labels, and namespaces`);
346
+ }
347
+ return {
348
+ kind: 'verified',
349
+ record,
350
+ keyid: chain.keyid,
351
+ signerScope: chain.effectiveScope,
352
+ };
353
+ }
@@ -0,0 +1,316 @@
1
+ /**
2
+ * Type-level definitions for the versioned records carried in DSSE envelopes.
3
+ *
4
+ * This module defines shapes only. Signing, verification, enrollment, revocation
5
+ * processing, scope attenuation, and policy evaluation belong to later layers.
6
+ * Field manifests intentionally sit beside each type: TypeScript checks the
7
+ * manifest against the type, while the wire-contract test checks the manifest
8
+ * against the checked-in JSON Schema. Neither side is generated from the other,
9
+ * so a drift changes a deliberate check into a failure instead of being hidden.
10
+ */
11
+ import type { PrincipalKeyRef, PublicKeyDescriptor } from './keys.ts';
12
+ import type { Fingerprint } from '../types.ts';
13
+ /** The fields that are mandatory or optional on a record type. */
14
+ export type RequiredKeys<T> = {
15
+ [K in keyof T]-?: object extends Pick<T, K> ? never : K;
16
+ }[keyof T];
17
+ export type OptionalKeys<T> = {
18
+ [K in keyof T]-?: object extends Pick<T, K> ? K : never;
19
+ }[keyof T];
20
+ export type FieldManifest<T> = {
21
+ [K in RequiredKeys<T>]: 'required';
22
+ } & {
23
+ [K in OptionalKeys<T>]: 'optional';
24
+ };
25
+ /** One value produced by a submission record. */
26
+ export interface SubmissionProducedArtifact {
27
+ artifact: string;
28
+ version: number;
29
+ valueDigest: string;
30
+ }
31
+ /**
32
+ * A countersigned description of one producer result. `defDigest` is a
33
+ * non-empty opaque reference to the instruction snapshot used for the run;
34
+ * the resolver seam deliberately permits values that are not a hex digest.
35
+ * `producerKeyId` uses the existing `SHA256:<unpadded-base64>` public-key
36
+ * fingerprint convention.
37
+ */
38
+ export interface SubmissionRecord {
39
+ run: string;
40
+ workflow: string;
41
+ defDigest: string;
42
+ step: string;
43
+ key: string;
44
+ index?: number;
45
+ produced: SubmissionProducedArtifact[];
46
+ consumedFingerprint: Fingerprint;
47
+ producerKeyId: string;
48
+ timestamp: number;
49
+ }
50
+ export declare const SUBMISSION_FIELDS: {
51
+ readonly run: "required";
52
+ readonly workflow: "required";
53
+ readonly defDigest: "required";
54
+ readonly step: "required";
55
+ readonly key: "required";
56
+ readonly index: "optional";
57
+ readonly produced: "required";
58
+ readonly consumedFingerprint: "required";
59
+ readonly producerKeyId: "required";
60
+ readonly timestamp: "required";
61
+ };
62
+ /**
63
+ * A signed publication of one canonical workflow bundle. `name` and `version`
64
+ * bind the digest to the package identity so a valid signature cannot be
65
+ * replayed as a claim about a different package.
66
+ */
67
+ export interface PublicationRecord {
68
+ /** Lowercase 64-character SHA-256 digest of the canonical bundle tar. */
69
+ digest: string;
70
+ /** The published bundle's package name. */
71
+ name: string;
72
+ /** The published bundle's package version. */
73
+ version: string;
74
+ /** `SHA256:<unpadded-base64>` fingerprint of the publisher's public key. */
75
+ publisherKeyId: string;
76
+ /** Unix epoch milliseconds at signing time. */
77
+ timestamp: number;
78
+ }
79
+ export declare const PUBLICATION_FIELDS: {
80
+ readonly digest: "required";
81
+ readonly name: "required";
82
+ readonly version: "required";
83
+ readonly publisherKeyId: "required";
84
+ readonly timestamp: "required";
85
+ };
86
+ /** Where a published workflow bundle came from. The source is signed content. */
87
+ export interface OriginSourceGit {
88
+ kind: 'git';
89
+ /** Remote identifier exactly as the signer stated it. Never parsed for meaning. */
90
+ repo: string;
91
+ commit: string;
92
+ }
93
+ export interface OriginSourceConsole {
94
+ kind: 'console';
95
+ /** The authoring user identity stated by the console's signing ceremony. */
96
+ user: string;
97
+ }
98
+ export interface OriginSourceAgent {
99
+ kind: 'agent';
100
+ agent: string;
101
+ session: string;
102
+ }
103
+ export type OriginSource = OriginSourceGit | OriginSourceConsole | OriginSourceAgent;
104
+ /** A signed statement of the provenance of one canonical workflow bundle. */
105
+ export interface OriginRecord {
106
+ /** Canonical bundle digest bound by this signed record. */
107
+ digest: string;
108
+ name: string;
109
+ version: string;
110
+ source: OriginSource;
111
+ /** `SHA256:<unpadded-base64>` fingerprint of the key that signed this record. */
112
+ attesterKeyId: string;
113
+ timestamp: number;
114
+ }
115
+ export declare const ORIGIN_FIELDS: {
116
+ readonly digest: "required";
117
+ readonly name: "required";
118
+ readonly version: "required";
119
+ readonly source: "required";
120
+ readonly attesterKeyId: "required";
121
+ readonly timestamp: "required";
122
+ };
123
+ export declare const ORIGIN_SOURCE_GIT_FIELDS: {
124
+ readonly kind: "required";
125
+ readonly repo: "required";
126
+ readonly commit: "required";
127
+ };
128
+ export declare const ORIGIN_SOURCE_CONSOLE_FIELDS: {
129
+ readonly kind: "required";
130
+ readonly user: "required";
131
+ };
132
+ export declare const ORIGIN_SOURCE_AGENT_FIELDS: {
133
+ readonly kind: "required";
134
+ readonly agent: "required";
135
+ readonly session: "required";
136
+ };
137
+ export declare const SUBMISSION_PRODUCED_FIELDS: {
138
+ readonly artifact: "required";
139
+ readonly version: "required";
140
+ readonly valueDigest: "required";
141
+ };
142
+ /**
143
+ * The public key descriptor embedded in an enrollment grant. The field names
144
+ * reuse `PublicKeyDescriptor`; `comment` remains optional on the wire because
145
+ * a grant does not need a human-readable label.
146
+ */
147
+ export type EnrollmentKeyDescriptor = Pick<PublicKeyDescriptor, 'keyid' | 'keyType' | 'openSshPublicKey'> & {
148
+ comment?: string;
149
+ };
150
+ /** A principal identity without the local key-store origin. */
151
+ export type PrincipalReference = Pick<PrincipalKeyRef, 'kind' | 'id'>;
152
+ /** The three scope axes and the delegation limit on an enrollment grant. */
153
+ export interface GrantScope {
154
+ /** `'*'` means every pool; `[]` means no pools. */
155
+ pools: string[] | '*';
156
+ /** `'*'` means every label; `[]` means no labels. */
157
+ labels: string[] | '*';
158
+ /** `'*'` means every namespace; `[]` means no namespaces. */
159
+ namespaces: string[] | '*';
160
+ delegation: GrantDelegation;
161
+ }
162
+ /** A grant that cannot delegate. `maxDepth` is intentionally unreachable. */
163
+ export interface GrantDelegationDenied {
164
+ allowed: false;
165
+ }
166
+ /** A grant that can delegate up to a finite depth or without a depth bound. */
167
+ export interface GrantDelegationAllowed {
168
+ allowed: true;
169
+ maxDepth: number | 'unbounded';
170
+ }
171
+ export type GrantDelegation = GrantDelegationDenied | GrantDelegationAllowed;
172
+ /**
173
+ * A signed enrollment grant. The scope is complete: each axis is required,
174
+ * and `'*'` is distinct from an empty list so later attenuation cannot guess
175
+ * whether an omitted or empty value means nothing or everything.
176
+ */
177
+ export interface EnrollmentGrantRecord {
178
+ newKey: EnrollmentKeyDescriptor;
179
+ principal: PrincipalReference;
180
+ scope: GrantScope;
181
+ grantedBy: string;
182
+ validFrom: number;
183
+ }
184
+ export declare const ENROLLMENT_GRANT_FIELDS: {
185
+ readonly newKey: "required";
186
+ readonly principal: "required";
187
+ readonly scope: "required";
188
+ readonly grantedBy: "required";
189
+ readonly validFrom: "required";
190
+ };
191
+ export declare const ENROLLMENT_KEY_FIELDS: {
192
+ readonly keyid: "required";
193
+ readonly keyType: "required";
194
+ readonly openSshPublicKey: "required";
195
+ readonly comment: "optional";
196
+ };
197
+ export declare const PRINCIPAL_REFERENCE_FIELDS: {
198
+ readonly kind: "required";
199
+ readonly id: "required";
200
+ };
201
+ export declare const GRANT_SCOPE_FIELDS: {
202
+ readonly pools: "required";
203
+ readonly labels: "required";
204
+ readonly namespaces: "required";
205
+ readonly delegation: "required";
206
+ };
207
+ export declare const GRANT_DELEGATION_DENIED_FIELDS: {
208
+ readonly allowed: "required";
209
+ };
210
+ export declare const GRANT_DELEGATION_ALLOWED_FIELDS: {
211
+ readonly allowed: "required";
212
+ readonly maxDepth: "required";
213
+ };
214
+ /**
215
+ * A forward or backdated revocation declaration. Verification must cross-check
216
+ * `backdated` against the two timestamps; keeping both fields makes the cut
217
+ * point explicit while making the signer intent structurally visible.
218
+ */
219
+ export interface RevocationRecord {
220
+ revokedKey: string;
221
+ principal: PrincipalReference;
222
+ revokedBy: string;
223
+ issuedAt: number;
224
+ effectiveFrom: number;
225
+ backdated: boolean;
226
+ reason?: string;
227
+ }
228
+ export declare const REVOCATION_FIELDS: {
229
+ readonly revokedKey: "required";
230
+ readonly principal: "required";
231
+ readonly revokedBy: "required";
232
+ readonly issuedAt: "required";
233
+ readonly effectiveFrom: "required";
234
+ readonly backdated: "required";
235
+ readonly reason: "optional";
236
+ };
237
+ /** The normative axes in a relayed policy floor. */
238
+ export interface PolicyFloor {
239
+ trustMode: 'seamless' | 'strict' | 'paranoid';
240
+ unsignedDefs: 'warn' | 'refuse';
241
+ unsignedArtifacts: 'warn' | 'refuse';
242
+ originRules: 'advisory' | 'enforced';
243
+ }
244
+ /**
245
+ * An admin-signed minimum policy. A local driver may require more than this
246
+ * floor; the record has no ceiling that a relaying transport could use to
247
+ * weaken local policy. `preset` is a label, not a replacement for `floor`.
248
+ */
249
+ export interface PolicyFloorRecord {
250
+ org: string;
251
+ issuedAt: number;
252
+ signedBy: string;
253
+ floor: PolicyFloor;
254
+ preset?: 'L0' | 'L1' | 'L2';
255
+ }
256
+ export declare const POLICY_FLOOR_RECORD_FIELDS: {
257
+ readonly org: "required";
258
+ readonly issuedAt: "required";
259
+ readonly signedBy: "required";
260
+ readonly floor: "required";
261
+ readonly preset: "optional";
262
+ };
263
+ export declare const POLICY_FLOOR_FIELDS: {
264
+ readonly trustMode: "required";
265
+ readonly unsignedDefs: "required";
266
+ readonly unsignedArtifacts: "required";
267
+ readonly originRules: "required";
268
+ };
269
+ /** The existing frozen reference-mode Order is the fifth launch contract. */
270
+ export declare const ORDER_FIELDS: {
271
+ readonly run: "required";
272
+ readonly workflow: "required";
273
+ readonly step: "required";
274
+ readonly key: "required";
275
+ readonly index: "optional";
276
+ readonly defDigest: "required";
277
+ readonly inputs: "required";
278
+ readonly outputs: "required";
279
+ readonly workdir: "optional";
280
+ readonly model: "optional";
281
+ readonly worker: "optional";
282
+ readonly judge: "optional";
283
+ readonly spec: "optional";
284
+ readonly x: "optional";
285
+ readonly consumes: "required";
286
+ readonly consumedFingerprint: "optional";
287
+ readonly owes: "required";
288
+ readonly consumesProof: "optional";
289
+ readonly cause: "optional";
290
+ };
291
+ /** Indexed access pins the already-emitted nested Order shape without cloning it. */
292
+ export declare const ORDER_OWED_FIELDS: {
293
+ readonly path: "required";
294
+ readonly version: "optional";
295
+ readonly judgmentRejects: "required";
296
+ readonly schemaRejects: "required";
297
+ readonly reasons: "required";
298
+ readonly proof: "optional";
299
+ };
300
+ export declare const ORDER_REASON_FIELDS: {
301
+ readonly at: "required";
302
+ readonly action: "required";
303
+ readonly kind: "required";
304
+ readonly by: "required";
305
+ readonly text: "required";
306
+ readonly fromVersion: "optional";
307
+ };
308
+ /** Bind every record definition in this package to a frozen DSSE media type. */
309
+ export declare const RECORD_PAYLOAD_TYPES: {
310
+ readonly enrollmentGrant: "application/vnd.owenloop.enrollment-grant.v1+json";
311
+ readonly revocation: "application/vnd.owenloop.revocation.v1+json";
312
+ readonly submission: "application/vnd.owenloop.submission.v1+json";
313
+ readonly policyFloor: "application/vnd.owenloop.policy-floor.v1+json";
314
+ readonly origin: "application/vnd.owenloop.origin.v1+json";
315
+ readonly publication: "application/vnd.owenloop.publication.v1+json";
316
+ };