owenloop 0.5.0 → 0.5.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (211) hide show
  1. package/CHANGELOG.md +45 -0
  2. package/README.md +137 -35
  3. package/bin/owenloop.mjs +49 -1
  4. package/dist/packages/work/src/agent/brief.d.ts +8 -4
  5. package/dist/packages/work/src/agent/brief.js +7 -3
  6. package/dist/packages/work/src/agent/loop.d.ts +13 -7
  7. package/dist/packages/work/src/agent/loop.js +136 -9
  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/bundle/cache.d.ts +7 -5
  11. package/dist/packages/work/src/bundle/cache.js +20 -6
  12. package/dist/packages/work/src/bundle/fetch.d.ts +7 -5
  13. package/dist/packages/work/src/bundle/fetch.js +27 -7
  14. package/dist/packages/work/src/bundle/types.d.ts +8 -4
  15. package/dist/packages/work/src/consumed-verifier.d.ts +45 -0
  16. package/dist/packages/work/src/consumed-verifier.js +205 -0
  17. package/dist/packages/work/src/exec/instructions.d.ts +99 -0
  18. package/dist/packages/work/src/exec/instructions.js +323 -0
  19. package/dist/packages/work/src/exec/loop.d.ts +12 -1
  20. package/dist/packages/work/src/exec/loop.js +137 -20
  21. package/dist/packages/work/src/exec/payload.d.ts +29 -0
  22. package/dist/packages/work/src/exec/payload.js +54 -0
  23. package/dist/packages/work/src/exec/receipt.d.ts +9 -6
  24. package/dist/packages/work/src/exec/receipt.js +12 -1
  25. package/dist/packages/work/src/exec/runner.d.ts +7 -1
  26. package/dist/packages/work/src/exec/runner.js +74 -3
  27. package/dist/packages/work/src/harness/child-env.js +7 -0
  28. package/dist/packages/work/src/harness/claude.d.ts +20 -8
  29. package/dist/packages/work/src/harness/claude.js +260 -58
  30. package/dist/packages/work/src/harness/codex.d.ts +5 -4
  31. package/dist/packages/work/src/harness/codex.js +169 -41
  32. package/dist/packages/work/src/harness/contract.d.ts +36 -11
  33. package/dist/packages/work/src/harness/fake.js +1 -0
  34. package/dist/packages/work/src/harness/jsonrpc-stdio.js +7 -0
  35. package/dist/packages/work/src/harness/permissions.d.ts +16 -3
  36. package/dist/packages/work/src/harness/permissions.js +102 -13
  37. package/dist/packages/work/src/harness/session-store.d.ts +27 -9
  38. package/dist/packages/work/src/harness/session-store.js +271 -67
  39. package/dist/packages/work/src/hold/mcp.d.ts +25 -5
  40. package/dist/packages/work/src/hold/mcp.js +126 -11
  41. package/dist/packages/work/src/hub/client.d.ts +2 -1
  42. package/dist/packages/work/src/hub/client.js +14 -1
  43. package/dist/packages/work/src/hub/types.d.ts +69 -33
  44. package/dist/packages/work/src/hub/types.js +8 -10
  45. package/dist/packages/work/src/mcp/server.js +1 -1
  46. package/dist/packages/work/src/owenloop-bin.d.ts +1 -0
  47. package/dist/packages/work/src/owenloop-bin.js +18 -0
  48. package/dist/packages/work/src/roles/agent-run.d.ts +12 -6
  49. package/dist/packages/work/src/roles/agent-run.js +116 -34
  50. package/dist/packages/work/src/roles/exec.d.ts +8 -0
  51. package/dist/packages/work/src/roles/exec.js +27 -2
  52. package/dist/packages/work/src/roles/hold.d.ts +4 -0
  53. package/dist/packages/work/src/roles/hold.js +44 -5
  54. package/dist/packages/work/src/roles/lint.d.ts +3 -4
  55. package/dist/packages/work/src/roles/lint.js +41 -7
  56. package/dist/packages/work/src/roles/settings.js +5 -0
  57. package/dist/packages/work/src/roles/shift.d.ts +1 -0
  58. package/dist/packages/work/src/roles/shift.js +23 -1
  59. package/dist/packages/work/src/settings/settings.d.ts +17 -1
  60. package/dist/packages/work/src/settings/settings.js +39 -0
  61. package/dist/packages/work/src/shift/loop.d.ts +14 -3
  62. package/dist/packages/work/src/shift/loop.js +447 -164
  63. package/dist/packages/work/src/shift/protocol.d.ts +4 -0
  64. package/dist/packages/work/src/shift/runtime.d.ts +2 -0
  65. package/dist/packages/work/src/shift/runtime.js +66 -3
  66. package/dist/packages/work/src/shift/spawn.d.ts +41 -18
  67. package/dist/packages/work/src/shift/spawn.js +89 -31
  68. package/dist/packages/work/src/shift/state.d.ts +53 -51
  69. package/dist/packages/work/src/shift/state.js +325 -102
  70. package/dist/packages/work/src/submit-proof.d.ts +36 -0
  71. package/dist/packages/work/src/submit-proof.js +93 -0
  72. package/dist/src/add.d.ts +64 -259
  73. package/dist/src/add.js +81 -615
  74. package/dist/src/archive.d.ts +97 -0
  75. package/dist/src/archive.js +591 -0
  76. package/dist/src/bundle/index.d.ts +64 -0
  77. package/dist/src/bundle/index.js +508 -0
  78. package/dist/src/bundle/manifest.d.ts +50 -0
  79. package/dist/src/bundle/manifest.js +435 -0
  80. package/dist/src/bundle/runtime.d.ts +26 -0
  81. package/dist/src/bundle/runtime.js +64 -0
  82. package/dist/src/bundle/tar.d.ts +62 -0
  83. package/dist/src/bundle/tar.js +238 -0
  84. package/dist/src/bundle/types.d.ts +105 -0
  85. package/dist/src/bundle/types.js +21 -0
  86. package/dist/src/cli.d.ts +90 -20
  87. package/dist/src/cli.js +2407 -365
  88. package/dist/src/credentials.d.ts +4 -3
  89. package/dist/src/credentials.js +21 -19
  90. package/dist/src/crypto/allowed-signers.d.ts +68 -0
  91. package/dist/src/crypto/allowed-signers.js +307 -0
  92. package/dist/src/crypto/canonical.d.ts +8 -0
  93. package/dist/src/crypto/canonical.js +92 -0
  94. package/dist/src/crypto/chain.d.ts +65 -0
  95. package/dist/src/crypto/chain.js +377 -0
  96. package/dist/src/crypto/dsse.d.ts +209 -0
  97. package/dist/src/crypto/dsse.js +282 -0
  98. package/dist/src/crypto/enrollment.d.ts +78 -0
  99. package/dist/src/crypto/enrollment.js +186 -0
  100. package/dist/src/crypto/index.d.ts +48 -0
  101. package/dist/src/crypto/index.js +44 -0
  102. package/dist/src/crypto/keys.d.ts +258 -0
  103. package/dist/src/crypto/keys.js +908 -0
  104. package/dist/src/crypto/org-root.d.ts +33 -0
  105. package/dist/src/crypto/org-root.js +78 -0
  106. package/dist/src/crypto/origin-rules.d.ts +56 -0
  107. package/dist/src/crypto/origin-rules.js +143 -0
  108. package/dist/src/crypto/policy-floor.d.ts +98 -0
  109. package/dist/src/crypto/policy-floor.js +353 -0
  110. package/dist/src/crypto/records.d.ts +316 -0
  111. package/dist/src/crypto/records.js +157 -0
  112. package/dist/src/crypto/scope.d.ts +49 -0
  113. package/dist/src/crypto/scope.js +83 -0
  114. package/dist/src/crypto/ssh.d.ts +171 -0
  115. package/dist/src/crypto/ssh.js +396 -0
  116. package/dist/src/crypto/submission.d.ts +33 -0
  117. package/dist/src/crypto/submission.js +47 -0
  118. package/dist/src/crypto/trust-roots.d.ts +29 -0
  119. package/dist/src/crypto/trust-roots.js +39 -0
  120. package/dist/src/crypto/verify-consumed.d.ts +67 -0
  121. package/dist/src/crypto/verify-consumed.js +259 -0
  122. package/dist/src/crypto/verify-origin.d.ts +50 -0
  123. package/dist/src/crypto/verify-origin.js +151 -0
  124. package/dist/src/crypto/verify-publication.d.ts +60 -0
  125. package/dist/src/crypto/verify-publication.js +150 -0
  126. package/dist/src/defs.d.ts +24 -1
  127. package/dist/src/defs.js +145 -25
  128. package/dist/src/engine.d.ts +99 -3
  129. package/dist/src/engine.js +238 -34
  130. package/dist/src/factory.d.ts +16 -0
  131. package/dist/src/factory.js +16 -4
  132. package/dist/src/global-config.d.ts +59 -0
  133. package/dist/src/global-config.js +84 -0
  134. package/dist/src/hub.d.ts +75 -21
  135. package/dist/src/hub.js +123 -40
  136. package/dist/src/index.d.ts +17 -2
  137. package/dist/src/index.js +20 -2
  138. package/dist/src/install.d.ts +538 -0
  139. package/dist/src/install.js +1981 -0
  140. package/dist/src/lock.d.ts +15 -57
  141. package/dist/src/lock.js +251 -143
  142. package/dist/src/mcp/serve.d.ts +46 -22
  143. package/dist/src/mcp/serve.js +167 -44
  144. package/dist/src/mcp/server.js +12 -1
  145. package/dist/src/model.d.ts +15 -0
  146. package/dist/src/model.js +111 -1
  147. package/dist/src/order-resolver.d.ts +184 -0
  148. package/dist/src/order-resolver.js +252 -0
  149. package/dist/src/package-version.d.ts +10 -0
  150. package/dist/src/package-version.js +42 -0
  151. package/dist/src/paths.d.ts +14 -1
  152. package/dist/src/paths.js +18 -0
  153. package/dist/src/schemas/enrollment-grant.v1.schema.json +90 -0
  154. package/dist/src/schemas/index.d.ts +1416 -0
  155. package/dist/src/schemas/index.js +31 -0
  156. package/dist/src/schemas/order.v1.schema.json +106 -0
  157. package/dist/src/schemas/origin.v1.schema.json +68 -0
  158. package/dist/src/schemas/policy-floor.v1.schema.json +29 -0
  159. package/dist/src/schemas/publication.v1.schema.json +31 -0
  160. package/dist/src/schemas/revocation.v1.schema.json +39 -0
  161. package/dist/src/schemas/submission.v1.schema.json +61 -0
  162. package/dist/src/store/def-source.d.ts +52 -0
  163. package/dist/src/store/def-source.js +335 -0
  164. package/dist/src/store/index-file.d.ts +69 -0
  165. package/dist/src/store/index-file.js +151 -0
  166. package/dist/src/store/index.d.ts +27 -0
  167. package/dist/src/store/index.js +22 -0
  168. package/dist/src/store/ingestor.d.ts +43 -0
  169. package/dist/src/store/ingestor.js +211 -0
  170. package/dist/src/store/install.d.ts +228 -0
  171. package/dist/src/store/install.js +555 -0
  172. package/dist/src/store/instruction-source.d.ts +49 -0
  173. package/dist/src/store/instruction-source.js +298 -0
  174. package/dist/src/store/origin-evidence.d.ts +21 -0
  175. package/dist/src/store/origin-evidence.js +66 -0
  176. package/dist/src/store/pre-commit-verifier.d.ts +68 -0
  177. package/dist/src/store/pre-commit-verifier.js +418 -0
  178. package/dist/src/store/resolve.d.ts +138 -0
  179. package/dist/src/store/resolve.js +363 -0
  180. package/dist/src/store/types.d.ts +288 -0
  181. package/dist/src/store/types.js +356 -0
  182. package/dist/src/types.d.ts +45 -11
  183. package/dist/src/untar.d.ts +8 -23
  184. package/dist/src/untar.js +10 -136
  185. package/docs/agent-runner.md +86 -0
  186. package/docs/authoring.md +57 -6
  187. package/docs/bundles.md +250 -0
  188. package/docs/cli.md +1171 -97
  189. package/docs/crypto.md +816 -0
  190. package/docs/design.md +342 -20
  191. package/docs/embedding.md +132 -25
  192. package/docs/wire-contracts.md +380 -0
  193. package/package.json +6 -1
  194. package/plugins/claude-code/.claude-plugin/marketplace.json +14 -0
  195. package/plugins/claude-code/plugin/.claude-plugin/plugin.json +8 -0
  196. package/plugins/claude-code/plugin/.mcp.json +14 -0
  197. package/plugins/claude-code/plugin/hooks/hooks.json +26 -0
  198. package/plugins/claude-code/plugin/hooks/session-end.sh +40 -0
  199. package/plugins/claude-code/plugin/hooks/session-start.sh +52 -0
  200. package/plugins/claude-code/plugin/skills/author/SKILL.md +181 -0
  201. package/plugins/claude-code/plugin/skills/conduct/SKILL.md +106 -0
  202. package/plugins/claude-code/plugin/skills/shift/SKILL.md +105 -0
  203. package/plugins/codex/.agents/plugins/marketplace.json +21 -0
  204. package/plugins/codex/plugins/owenloop/.codex-plugin/plugin.json +7 -0
  205. package/plugins/codex/plugins/owenloop/.mcp.json +20 -0
  206. package/plugins/codex/plugins/owenloop/hooks/hooks.json +26 -0
  207. package/plugins/codex/plugins/owenloop/hooks/session-end.sh +40 -0
  208. package/plugins/codex/plugins/owenloop/hooks/session-start.sh +52 -0
  209. package/plugins/codex/plugins/owenloop/skills/author/SKILL.md +181 -0
  210. package/plugins/codex/plugins/owenloop/skills/conduct/SKILL.md +106 -0
  211. package/plugins/codex/plugins/owenloop/skills/shift/SKILL.md +105 -0
@@ -4,13 +4,16 @@
4
4
  * A born-bound work-holder: the D2 stamped Step Agent's frontmatter declares
5
5
  * `mcpServers.owenloop = owenloop work hold --order <wf>/<run> --origin <url> --mcp`,
6
6
  * so when the Step Agent session boots it launches THIS as a stdio MCP server. The
7
- * server exposes two bare tools the model uses to do its order:
7
+ * server exposes three bare tools the model uses to do its order:
8
8
  * - `get_order` → the order packet (prompt, inputs, owed outputs) for the run
9
9
  * this holder is bound to. No ids are arguments — they came in on argv, never
10
10
  * through the model.
11
11
  * - `submit` → post a receipt for an owed output path; when the hub reports
12
12
  * the submit CLOSED the run, the lease loop is stopped with `release:false`
13
13
  * (the claim is already gone).
14
+ * - `reject` → invalidate a consumed artifact through the claiming step's
15
+ * server-derived authority; the client never supplies `by`. A CLOSED reject
16
+ * also stops the lease loop without releasing the already-closed claim.
14
17
  *
15
18
  * Underneath the tools, the SAME lease loop the CLI `hold` runs keeps the order's
16
19
  * lease warm: `createHoldMcp` builds the loop with `onOrder` wired to capture the
@@ -24,7 +27,9 @@
24
27
  * clock. The role (`src/roles/hold.ts`) owns the real stdin/stdout pump.
25
28
  */
26
29
  import { textResult } from "../mcp/server.js";
30
+ import { buildSubmitProof } from "../submit-proof.js";
27
31
  import { createHoldLoop } from "./loop.js";
32
+ export const HOLD_MCP_TOOL_NAMES = ['get_order', 'submit', 'reject'];
28
33
  function errMsg(e) {
29
34
  return e instanceof Error ? e.message : String(e);
30
35
  }
@@ -33,20 +38,24 @@ function orderView(res) {
33
38
  return { workflow: res.workflow, run: res.run, order: res.order, text: res.text };
34
39
  }
35
40
  /**
36
- * Build the hold MCP mount: the lease loop plus its two tools. The caller (the
37
- * role) creates the MCP server around `tools`, starts `loop.run()`, and pumps
38
- * stdin — stopping the loop on stdin EOF.
41
+ * Build the hold MCP mount: the lease loop plus a positive tool selection. The
42
+ * default selection is the full `get_order`/`submit`/`reject` surface. A caller
43
+ * can request an exact subset; future registrations do not enter that subset
44
+ * unless the caller names them. The role creates the MCP server around `tools`,
45
+ * starts `loop.run()`, and pumps stdin — stopping the loop on stdin EOF.
39
46
  */
40
47
  export function createHoldMcp(deps) {
41
48
  const { hub, workflow, run } = deps;
42
49
  const holderReq = deps.holder !== undefined ? { holder: deps.holder } : {};
43
- // Captured from the loop's first contact so `get_order` needn't re-fetch (and
44
- // re-contend the pickup window). Falls back to a live fetch if a tool call
45
- // beats first contact.
50
+ // The loop's first contact arrives synchronously, but consume-side verification
51
+ // is asynchronous. Keep the unverified response in a private pending slot until
52
+ // a tool call gates it; only a gated response may populate `captured` and reach
53
+ // either the model or submit-proof construction.
54
+ let firstContact;
46
55
  let captured;
47
56
  // Set the moment the lease loop's run() settles (lease-lost, completed,
48
57
  // released, …): from then on this mount no longer holds the order, so BOTH
49
- // tools fast-fail with isError and never touch the hub again (plan section 4
58
+ // registered tools fast-fail with isError and never touch the hub again (plan section 4
50
59
  // — a lost claim must not be worked or double-submitted).
51
60
  let terminal;
52
61
  const inner = createHoldLoop({
@@ -59,7 +68,7 @@ export function createHoldMcp(deps) {
59
68
  out: deps.err,
60
69
  err: deps.err,
61
70
  onOrder: (res) => {
62
- captured = res;
71
+ firstContact = res;
63
72
  },
64
73
  ...(deps.holder !== undefined ? { holder: deps.holder } : {}),
65
74
  ...(deps.heartbeatIntervalMs !== undefined ? { heartbeatIntervalMs: deps.heartbeatIntervalMs } : {}),
@@ -81,6 +90,30 @@ export function createHoldMcp(deps) {
81
90
  return undefined;
82
91
  return textResult({ error: `order no longer held (${terminal}) — stop` }, true);
83
92
  }
93
+ async function gate(res) {
94
+ if (res.order === null)
95
+ return undefined;
96
+ const hasConsumedData = Object.keys(res.order.consumes).length > 0
97
+ || res.order.owes.some((owed) => owed.reasons.length > 0 || owed.proof !== undefined);
98
+ if (deps.consumedVerifier === undefined) {
99
+ if (!hasConsumedData)
100
+ return undefined;
101
+ return textResult({
102
+ error: `consumed artifact refusal (prerequisite) for ${res.workflow}/${res.run}: consume-side verifier is not configured; dynamic values cannot be admitted to the MCP model`,
103
+ }, true);
104
+ }
105
+ try {
106
+ const checked = await deps.consumedVerifier(res.order, { hardRule: false });
107
+ if (!checked.ok)
108
+ return textResult({ error: checked.reason }, true);
109
+ for (const warning of checked.warnings)
110
+ deps.err(warning);
111
+ return undefined;
112
+ }
113
+ catch (error) {
114
+ return textResult({ error: `consumed artifact refusal (prerequisite) for ${res.workflow}/${res.run}: ${errMsg(error)}` }, true);
115
+ }
116
+ }
84
117
  const getOrderTool = {
85
118
  name: 'get_order',
86
119
  description: "Return this work-holder's order — the prompt, consumed inputs, and owed output paths for the run it is bound to. Takes no arguments (the run is fixed at launch).",
@@ -89,10 +122,24 @@ export function createHoldMcp(deps) {
89
122
  const gone = terminalGuard();
90
123
  if (gone !== undefined)
91
124
  return gone;
92
- if (captured !== undefined)
125
+ if (captured !== undefined) {
126
+ const refused = await gate(captured);
127
+ if (refused !== undefined)
128
+ return refused;
93
129
  return textResult(orderView(captured));
130
+ }
131
+ if (firstContact !== undefined) {
132
+ const refused = await gate(firstContact);
133
+ if (refused !== undefined)
134
+ return refused;
135
+ captured = firstContact;
136
+ return textResult(orderView(firstContact));
137
+ }
94
138
  try {
95
139
  const res = await hub.getOrder({ workflow, run, ...holderReq });
140
+ const refused = await gate(res);
141
+ if (refused !== undefined)
142
+ return refused;
96
143
  captured = res;
97
144
  return textResult(orderView(res));
98
145
  }
@@ -127,12 +174,39 @@ export function createHoldMcp(deps) {
127
174
  }
128
175
  const done = args['done'];
129
176
  try {
177
+ // Submit is also a dynamic-data boundary. Fetch and gate the bound
178
+ // packet even when no origin was supplied for submit-proof signing;
179
+ // otherwise a direct submit call could bypass MCP consume-side
180
+ // verification without first calling get_order.
181
+ let orderResponse = captured ?? firstContact;
182
+ if (orderResponse === undefined) {
183
+ orderResponse = await hub.getOrder({ workflow, run, ...holderReq });
184
+ }
185
+ const refused = await gate(orderResponse);
186
+ if (refused !== undefined)
187
+ return refused;
188
+ captured = orderResponse;
189
+ let proof;
190
+ if (deps.origin !== undefined && orderResponse.order !== null) {
191
+ proof = await buildSubmitProof({
192
+ origin: deps.origin,
193
+ order: orderResponse.order,
194
+ path,
195
+ value: args['value'],
196
+ now: deps.now,
197
+ warn: deps.err,
198
+ ...(deps.principalKeys !== undefined ? { principalKeys: deps.principalKeys } : {}),
199
+ ...(deps.env !== undefined ? { env: deps.env } : {}),
200
+ ...(deps.sshProcess !== undefined ? { sshProcess: deps.sshProcess } : {}),
201
+ });
202
+ }
130
203
  const res = await hub.submit({
131
204
  workflow,
132
205
  run,
133
206
  path,
134
207
  value: args['value'],
135
208
  ...(typeof done === 'boolean' ? { done } : {}),
209
+ ...(proof !== undefined ? { proof } : {}),
136
210
  ...holderReq,
137
211
  });
138
212
  // The run closed — stop holding WITHOUT releasing (the claim is gone).
@@ -145,5 +219,46 @@ export function createHoldMcp(deps) {
145
219
  }
146
220
  },
147
221
  };
148
- return { tools: [getOrderTool, submitTool], loop };
222
+ const rejectTool = {
223
+ name: 'reject',
224
+ description: 'Reject a consumed artifact path with a reason. The hub derives the rejecting step from this held run; the client cannot supply `by`.',
225
+ inputSchema: {
226
+ type: 'object',
227
+ required: ['path', 'text'],
228
+ properties: {
229
+ path: { type: 'string', description: 'The consumed artifact path to reject.' },
230
+ text: { type: 'string', description: 'The reason for rejecting the artifact.' },
231
+ },
232
+ additionalProperties: false,
233
+ },
234
+ handler: async (args) => {
235
+ const gone = terminalGuard();
236
+ if (gone !== undefined)
237
+ return gone;
238
+ const path = args['path'];
239
+ const text = args['text'];
240
+ if (typeof path !== 'string' || path.trim() === '') {
241
+ return textResult({ error: 'reject requires a non-empty string "path"' }, true);
242
+ }
243
+ if (typeof text !== 'string' || text.trim() === '') {
244
+ return textResult({ error: 'reject requires a non-empty string "text"' }, true);
245
+ }
246
+ try {
247
+ const res = await hub.reject({ workflow, run, path, text });
248
+ if (res.closed === true)
249
+ loop.stop('submitted', { release: false });
250
+ return textResult({ ok: res.ok, closed: res.closed ?? false, text: res.text });
251
+ }
252
+ catch (e) {
253
+ return textResult({ error: errMsg(e) }, true);
254
+ }
255
+ },
256
+ };
257
+ const registrations = {
258
+ get_order: getOrderTool,
259
+ submit: submitTool,
260
+ reject: rejectTool,
261
+ };
262
+ const selected = deps.tools ?? HOLD_MCP_TOOL_NAMES;
263
+ return { tools: selected.map((name) => registrations[name]), loop };
149
264
  }
@@ -1,4 +1,4 @@
1
- import type { GetOrderRequest, GetOrderResponse, HeartbeatRequest, HeartbeatResponse, PresencePingRequest, PresencePingResponse, ReleaseRequest, ReleaseResponse, SubmitRequest, SubmitResponse, WakeResponse, WhatsNextRequest, WhatsNextResponse, WhoamiResponse } from './types.ts';
1
+ import type { GetOrderRequest, GetOrderResponse, HeartbeatRequest, HeartbeatResponse, PresencePingRequest, PresencePingResponse, ReleaseRequest, ReleaseResponse, RejectRequest, RejectResponse, SubmitRequest, SubmitResponse, WakeResponse, WhatsNextRequest, WhatsNextResponse, WhoamiResponse } from './types.ts';
2
2
  export interface HubClientOptions {
3
3
  /** Hub origin, e.g. `https://hub.owenloop.dev` (no trailing slash needed). */
4
4
  origin: string;
@@ -13,6 +13,7 @@ export interface HubClient {
13
13
  heartbeat(req: HeartbeatRequest): Promise<HeartbeatResponse>;
14
14
  release(req: ReleaseRequest): Promise<ReleaseResponse>;
15
15
  submit(req: SubmitRequest): Promise<SubmitResponse>;
16
+ reject(req: RejectRequest): Promise<RejectResponse>;
16
17
  whoami(): Promise<WhoamiResponse>;
17
18
  /** B5 cheap wake pre-check; `cursor` rides the query string only when set. */
18
19
  wake(cursor?: number): Promise<WakeResponse>;
@@ -28,6 +28,18 @@ export function createHubClient(opts) {
28
28
  'content-type': 'application/json',
29
29
  };
30
30
  }
31
+ function retryAfterMs(res) {
32
+ const raw = res.headers.get('retry-after')?.trim();
33
+ if (!raw)
34
+ return undefined;
35
+ const seconds = Number(raw);
36
+ if (Number.isFinite(seconds) && seconds >= 0)
37
+ return Math.ceil(seconds * 1_000);
38
+ const at = Date.parse(raw);
39
+ if (!Number.isFinite(at))
40
+ return undefined;
41
+ return Math.max(0, at - Date.now());
42
+ }
31
43
  async function parse(res) {
32
44
  const raw = await res.text();
33
45
  if (!res.ok) {
@@ -43,7 +55,7 @@ export function createHubClient(opts) {
43
55
  catch {
44
56
  // Not JSON — keep the raw text as the message.
45
57
  }
46
- throw new HubError(res.status, message, code);
58
+ throw new HubError(res.status, message, code, retryAfterMs(res));
47
59
  }
48
60
  return JSON.parse(raw);
49
61
  }
@@ -69,6 +81,7 @@ export function createHubClient(opts) {
69
81
  heartbeat: (req) => post('heartbeat', req),
70
82
  release: (req) => post('release', req),
71
83
  submit: (req) => post('submit', req),
84
+ reject: (req) => post('reject', req),
72
85
  whoami: () => get('whoami'),
73
86
  // Cursor is an opaque non-negative integer; omit it entirely to bootstrap
74
87
  // (the hub treats missing/invalid as a `changed: true` first sweep).
@@ -1,13 +1,7 @@
1
1
  /**
2
- * Typed request/response shapes for the hub verb surface owenloop's roles call.
3
- *
4
- * These mirror `apps/hub-edge/src/api/routes.ts` on owenloop-service `origin/main`
5
- * (B3 lifecycle verbs are merged). Every REST verb returns `{ text, ...data }`
6
- * where `data` is always an object, so each response extends `HubResponse`.
7
- *
8
- * Response payloads are typed LOOSELY on purpose: the roles that consume the
9
- * data fields (whats_next orders, get_order body, …) land in C3–C5. Honest-loose
10
- * (`unknown[]` + a TODO) beats invented-precise shapes no consumer reads yet.
2
+ * Typed request/response shapes for the remote coordinator's transport surface.
3
+ * Every response carries human-readable `text` plus the verb-specific data.
4
+ * Payloads stay loose where callers do not consume a field directly.
11
5
  */
12
6
  /** Common envelope: every verb returns a human-readable `text` plus verb data. */
13
7
  export interface HubResponse {
@@ -19,18 +13,31 @@ export interface WhatsNextRequest {
19
13
  serve_crews?: string[];
20
14
  }
21
15
  /**
22
- * One work order from a per-workflow `whats_next` sweep. Mirrors hub-core
23
- * `verbs/whats-next.ts` `WorkOrder` exactly. `run` IS the order id used by
24
- * every other hub verb; `step` is the def step name (matched against the
25
- * cached bundle to classify command vs agent). Fields the shift does not
26
- * read yet (consumes/expected_outputs/feedback/advisory/submit_hint) are
27
- * mirrored for completeness — C4/C5 consume them.
16
+ * One work order from a per-workflow `whats_next` sweep. `run` is the order
17
+ * identifier used by the other transport verbs. The work order is routing and
18
+ * dynamic input data; authored instruction text is resolved from the local
19
+ * workflow store by the worker.
28
20
  */
29
21
  export interface WorkOrder {
30
22
  workflow: string;
31
23
  run: string;
32
24
  step: string;
33
- prompt: string;
25
+ /** Target reference-order fields; optional because the deployed hub may omit them. */
26
+ key?: string;
27
+ index?: number;
28
+ defDigest?: string;
29
+ /** Authoritative worker lane on modern whats_next responses. */
30
+ worker?: string;
31
+ consumedFingerprint?: Record<string, number>;
32
+ owes?: Array<{
33
+ path: string;
34
+ /** Claim-time committed version when a version-aware hub projects it. */
35
+ version?: number;
36
+ judgmentRejects: number;
37
+ schemaRejects: number;
38
+ reasons: ReasonEntry[];
39
+ proof?: string;
40
+ }>;
34
41
  consumes: Record<string, unknown>;
35
42
  expected_outputs: Array<{
36
43
  path: string;
@@ -151,12 +158,11 @@ export interface Lease {
151
158
  outcome?: string;
152
159
  }
153
160
  /**
154
- * The persisted A1 order packet get_order re-serves, mirroring owenloop engine
155
- * `Order` (verified against owenloop-service `packages/engine-do/dist/vendor/
156
- * engine/engine.d.ts` on 2026-07-17). exec reads `command`/`executor`/`workdir`
157
- * to run the order and `owes` to know which output paths to submit the receipt
158
- * to; every other field is carried for completeness. `command` is opaque — the
159
- * engine never parses it; exec is the one process that shells it out.
161
+ * The persisted order packet re-served by the transport. The packet carries
162
+ * the definition projection digest and dynamic routing/state fields only.
163
+ * Workers must resolve authored command or prompt text from the local store.
164
+ * Proof/version fields describe the target protocol and remain optional because
165
+ * the deployed hub can omit them; optionality does not imply end-to-end support.
160
166
  */
161
167
  export interface OrderPacket {
162
168
  run: string;
@@ -164,26 +170,34 @@ export interface OrderPacket {
164
170
  step: string;
165
171
  key: string;
166
172
  index?: number;
173
+ /** Projection digest identifying the installed definition snapshot. */
174
+ defDigest: string;
167
175
  inputs: string[];
168
176
  outputs: string[];
169
- /** Opaque location hint — exec's command cwd when set. */
177
+ /** Opaque location hint — the worker's cwd when set. */
170
178
  workdir?: string;
171
179
  model?: string;
172
- /** Executor kind; `'command'` for a command order, absent = `'agent'`. */
173
- executor?: string;
174
- /** The command string for a `executor: command` order (opaque). */
175
- command?: string;
180
+ /** Worker kind; `'command'` for command orders, absent means agent. */
181
+ worker?: string;
182
+ /** Artifact stem this order's judge step must verdict, when present. */
183
+ judge?: string;
176
184
  spec?: Record<string, unknown>;
177
185
  x?: Record<string, unknown>;
178
- prompt: string;
179
186
  consumes: Record<string, unknown>;
180
- /** The owed outputs + their reason threads — exec submits the receipt to each. */
187
+ /** Claim-time consumed versions when a compatible hub preserves the map. */
188
+ consumedFingerprint?: Record<string, number>;
189
+ /** Target-protocol proof map; the deployed hub currently omits this field. */
190
+ consumesProof?: string;
191
+ /** The owed outputs and their reason threads. */
181
192
  owes: Array<{
182
193
  path: string;
183
- acceptance: string;
194
+ /** Claim-time committed version when a version-aware hub projects it. */
195
+ version?: number;
184
196
  judgmentRejects: number;
185
197
  schemaRejects: number;
186
198
  reasons: ReasonEntry[];
199
+ /** Target-protocol reason-thread proof; the deployed hub may omit it. */
200
+ proof?: string;
187
201
  }>;
188
202
  cause?: string;
189
203
  }
@@ -249,6 +263,8 @@ export interface SubmitRequest {
249
263
  path: string;
250
264
  value: unknown;
251
265
  done?: boolean;
266
+ /** Target-protocol DSSE envelope; production submit transport currently drops it. */
267
+ proof?: string;
252
268
  /** W7: who produced this submission (D4) — carried on all three submit paths. */
253
269
  holder?: ContactHolder;
254
270
  }
@@ -258,13 +274,31 @@ export interface SubmitRequest {
258
274
  * commit verdict: `green`/`submitted` are success (the value landed);
259
275
  * `schema-rejected`/`born-rejected`/`artifact-too-large`/
260
276
  * `artifact-normalization-failed` are failures. `closed` reports whether that
261
- * submit closed the run (only present on a `green`/`submitted` outcome). exec
262
- * treats any non-green/submitted outcome as a failed submit (exit 1).
277
+ * submit closed the run (only present on a `green`/`submitted` outcome). The
278
+ * deployed response does not return the committed version, the next target
279
+ * version, proof acceptance, or an idempotency result. exec treats any
280
+ * non-green/submitted outcome as a failed submit (exit 1).
263
281
  */
264
282
  export interface SubmitResponse extends HubResponse {
265
283
  outcome?: string;
266
284
  closed?: boolean;
267
285
  }
286
+ /**
287
+ * Invalidate an artifact through the claiming worker's consume-edge authority.
288
+ * `by` is deliberately absent: the hub derives the actor from the claiming
289
+ * run's step, so a worker cannot impersonate another step.
290
+ */
291
+ export interface RejectRequest {
292
+ workflow: string;
293
+ run: string;
294
+ path: string;
295
+ text: string;
296
+ }
297
+ /** The reject verb's flattened response envelope. */
298
+ export interface RejectResponse extends HubResponse {
299
+ ok: boolean;
300
+ closed?: boolean;
301
+ }
268
302
  export interface WhoamiResponse extends HubResponse {
269
303
  orgId: string;
270
304
  orgName: string;
@@ -286,5 +320,7 @@ export interface WhoamiResponse extends HubResponse {
286
320
  export declare class HubError extends Error {
287
321
  readonly status: number;
288
322
  readonly code?: string;
289
- constructor(status: number, message: string, code?: string);
323
+ /** Server-requested delay before retrying, normalized from Retry-After. */
324
+ readonly retryAfterMs?: number;
325
+ constructor(status: number, message: string, code?: string, retryAfterMs?: number);
290
326
  }
@@ -1,13 +1,7 @@
1
1
  /**
2
- * Typed request/response shapes for the hub verb surface owenloop's roles call.
3
- *
4
- * These mirror `apps/hub-edge/src/api/routes.ts` on owenloop-service `origin/main`
5
- * (B3 lifecycle verbs are merged). Every REST verb returns `{ text, ...data }`
6
- * where `data` is always an object, so each response extends `HubResponse`.
7
- *
8
- * Response payloads are typed LOOSELY on purpose: the roles that consume the
9
- * data fields (whats_next orders, get_order body, …) land in C3–C5. Honest-loose
10
- * (`unknown[]` + a TODO) beats invented-precise shapes no consumer reads yet.
2
+ * Typed request/response shapes for the remote coordinator's transport surface.
3
+ * Every response carries human-readable `text` plus the verb-specific data.
4
+ * Payloads stay loose where callers do not consume a field directly.
11
5
  */
12
6
  // ---- errors -----------------------------------------------------------------
13
7
  /**
@@ -18,11 +12,15 @@
18
12
  export class HubError extends Error {
19
13
  status;
20
14
  code;
21
- constructor(status, message, code) {
15
+ /** Server-requested delay before retrying, normalized from Retry-After. */
16
+ retryAfterMs;
17
+ constructor(status, message, code, retryAfterMs) {
22
18
  super(message);
23
19
  this.name = 'HubError';
24
20
  this.status = status;
25
21
  if (code !== undefined)
26
22
  this.code = code;
23
+ if (retryAfterMs !== undefined)
24
+ this.retryAfterMs = retryAfterMs;
27
25
  }
28
26
  }
@@ -37,7 +37,7 @@ const RECOGNIZED_PROTOCOL_VERSIONS = new Set([
37
37
  '2024-11-05',
38
38
  '2025-03-26',
39
39
  '2025-06-18',
40
- '2025-11-05',
40
+ '2025-11-25',
41
41
  ]);
42
42
  /** The version we answer with when the client's is missing or unrecognized. */
43
43
  const OUR_PROTOCOL_VERSION = '2025-06-18';
@@ -0,0 +1 @@
1
+ export declare function resolveOwenloopBin(): string;
@@ -0,0 +1,18 @@
1
+ /**
2
+ * Resolve this installation's packaged Owenloop entrypoint.
3
+ *
4
+ * Source-driven tests import `packages/work/src/**`, while built/runtime code
5
+ * imports `dist/packages/work/src/**`; those layouts are one parent apart.
6
+ * Every child Owenloop process must use this resolver so a stale executable
7
+ * earlier on PATH cannot split a Shift, its worker, and the worker's born-bound
8
+ * MCP server across different installations.
9
+ */
10
+ import { existsSync } from 'node:fs';
11
+ import { fileURLToPath } from 'node:url';
12
+ export function resolveOwenloopBin() {
13
+ const candidates = [
14
+ new URL('../../../bin/owenloop.mjs', import.meta.url),
15
+ new URL('../../../../bin/owenloop.mjs', import.meta.url),
16
+ ].map((url) => fileURLToPath(url));
17
+ return candidates.find((candidate) => existsSync(candidate)) ?? candidates[0];
18
+ }
@@ -30,12 +30,10 @@
30
30
  *
31
31
  * ── WHERE THE STEP SPEC COMES FROM ──
32
32
  *
33
- * The spawn argv (D6) carries only `<workflow>/<run>`, `--origin`, `--shift`
34
- * and `--harness` — no def name and no def hash, both of which the bundle cache
35
- * needs. So the worker resolves the def name ITSELF: one non-claiming
36
- * `whats_next({workflow})` returns `def` in per-workflow mode, which feeds
37
- * `readDispatchBundle(cacheDir, def)` → `bundle.def.hash` → `readStepSpec(...)`.
38
- * That keeps the argv exactly as D6 specifies and adds no new settings surface.
33
+ * The order packet carries a `defDigest` reference but no authoritative prompt,
34
+ * harness, or permission text. The worker resolves the digest and step name
35
+ * through the verified local workflow store. The prepare cache remains available
36
+ * for routing and session state, but never supplies execution instructions.
39
37
  *
40
38
  * ── CREDENTIALS ──
41
39
  *
@@ -71,6 +69,8 @@
71
69
  */
72
70
  import '../harnesses.ts';
73
71
  import { type AgentRunOutcome } from '../agent/loop.ts';
72
+ import { type InstructionResolver } from '../exec/instructions.ts';
73
+ import { type ConsumedVerifier } from '../consumed-verifier.ts';
74
74
  import { type HubClient } from '../hub/client.ts';
75
75
  import { type SignalHost } from './signals.ts';
76
76
  interface ParsedArgs {
@@ -105,6 +105,12 @@ export interface RunDeps {
105
105
  hub?: HubClient;
106
106
  out?: (line: string) => void;
107
107
  err?: (line: string) => void;
108
+ /** Store-backed instruction resolver; injected tests may provide a fake. */
109
+ instructions?: InstructionResolver;
110
+ /** Consume-side verifier; injected tests may provide a fake. */
111
+ consumedVerifier?: ConsumedVerifier;
112
+ /** Environment used to derive the global workflow-store root. */
113
+ env?: Record<string, string | undefined>;
108
114
  /** cwd for an order that carries no `workdir` (default `process.cwd()`). */
109
115
  cwd?: string;
110
116
  /**