owenloop 0.5.0 → 0.5.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (229) hide show
  1. package/CHANGELOG.md +67 -0
  2. package/README.md +144 -35
  3. package/bin/owenloop.mjs +49 -1
  4. package/dist/packages/work/src/agent/brief.d.ts +29 -4
  5. package/dist/packages/work/src/agent/brief.js +49 -4
  6. package/dist/packages/work/src/agent/capability-model.d.ts +123 -0
  7. package/dist/packages/work/src/agent/capability-model.js +148 -0
  8. package/dist/packages/work/src/agent/loop.d.ts +56 -7
  9. package/dist/packages/work/src/agent/loop.js +166 -9
  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 +29 -1
  20. package/dist/packages/work/src/exec/loop.js +313 -35
  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 +84 -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 +30 -10
  38. package/dist/packages/work/src/harness/session-store.js +317 -89
  39. package/dist/packages/work/src/hold/mcp.d.ts +25 -5
  40. package/dist/packages/work/src/hold/mcp.js +134 -12
  41. package/dist/packages/work/src/hub/client.d.ts +8 -1
  42. package/dist/packages/work/src/hub/client.js +15 -1
  43. package/dist/packages/work/src/hub/types.d.ts +137 -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 +115 -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 +6 -0
  53. package/dist/packages/work/src/roles/hold.js +83 -13
  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 +19 -2
  57. package/dist/packages/work/src/roles/shift.d.ts +1 -0
  58. package/dist/packages/work/src/roles/shift.js +36 -2
  59. package/dist/packages/work/src/settings/settings.d.ts +70 -1
  60. package/dist/packages/work/src/settings/settings.js +90 -4
  61. package/dist/packages/work/src/shift/logretention.d.ts +253 -0
  62. package/dist/packages/work/src/shift/logretention.js +407 -0
  63. package/dist/packages/work/src/shift/logsink.d.ts +14 -0
  64. package/dist/packages/work/src/shift/logsink.js +98 -0
  65. package/dist/packages/work/src/shift/loop.d.ts +32 -4
  66. package/dist/packages/work/src/shift/loop.js +687 -166
  67. package/dist/packages/work/src/shift/protocol.d.ts +128 -1
  68. package/dist/packages/work/src/shift/protocol.js +14 -0
  69. package/dist/packages/work/src/shift/runtime.d.ts +16 -0
  70. package/dist/packages/work/src/shift/runtime.js +291 -5
  71. package/dist/packages/work/src/shift/server.d.ts +13 -0
  72. package/dist/packages/work/src/shift/server.js +61 -36
  73. package/dist/packages/work/src/shift/spawn.d.ts +115 -19
  74. package/dist/packages/work/src/shift/spawn.js +234 -30
  75. package/dist/packages/work/src/shift/state.d.ts +76 -49
  76. package/dist/packages/work/src/shift/state.js +350 -103
  77. package/dist/packages/work/src/shift/truncate.d.ts +35 -0
  78. package/dist/packages/work/src/shift/truncate.js +73 -0
  79. package/dist/packages/work/src/submit-proof.d.ts +61 -0
  80. package/dist/packages/work/src/submit-proof.js +119 -0
  81. package/dist/packages/work/src/submit-value.d.ts +48 -0
  82. package/dist/packages/work/src/submit-value.js +118 -0
  83. package/dist/packages/work/src/usage.d.ts +1 -1
  84. package/dist/packages/work/src/usage.js +11 -0
  85. package/dist/src/add.d.ts +64 -259
  86. package/dist/src/add.js +81 -615
  87. package/dist/src/archive.d.ts +97 -0
  88. package/dist/src/archive.js +591 -0
  89. package/dist/src/bundle/index.d.ts +64 -0
  90. package/dist/src/bundle/index.js +508 -0
  91. package/dist/src/bundle/manifest.d.ts +50 -0
  92. package/dist/src/bundle/manifest.js +435 -0
  93. package/dist/src/bundle/runtime.d.ts +26 -0
  94. package/dist/src/bundle/runtime.js +64 -0
  95. package/dist/src/bundle/tar.d.ts +62 -0
  96. package/dist/src/bundle/tar.js +238 -0
  97. package/dist/src/bundle/types.d.ts +105 -0
  98. package/dist/src/bundle/types.js +21 -0
  99. package/dist/src/capabilities.d.ts +93 -0
  100. package/dist/src/capabilities.js +101 -0
  101. package/dist/src/cli.d.ts +90 -20
  102. package/dist/src/cli.js +2421 -374
  103. package/dist/src/credentials.d.ts +4 -3
  104. package/dist/src/credentials.js +21 -19
  105. package/dist/src/crypto/allowed-signers.d.ts +68 -0
  106. package/dist/src/crypto/allowed-signers.js +307 -0
  107. package/dist/src/crypto/canonical.d.ts +8 -0
  108. package/dist/src/crypto/canonical.js +92 -0
  109. package/dist/src/crypto/chain.d.ts +65 -0
  110. package/dist/src/crypto/chain.js +377 -0
  111. package/dist/src/crypto/dsse.d.ts +209 -0
  112. package/dist/src/crypto/dsse.js +282 -0
  113. package/dist/src/crypto/enrollment.d.ts +78 -0
  114. package/dist/src/crypto/enrollment.js +186 -0
  115. package/dist/src/crypto/index.d.ts +48 -0
  116. package/dist/src/crypto/index.js +44 -0
  117. package/dist/src/crypto/keys.d.ts +258 -0
  118. package/dist/src/crypto/keys.js +908 -0
  119. package/dist/src/crypto/org-root.d.ts +33 -0
  120. package/dist/src/crypto/org-root.js +78 -0
  121. package/dist/src/crypto/origin-rules.d.ts +56 -0
  122. package/dist/src/crypto/origin-rules.js +143 -0
  123. package/dist/src/crypto/policy-floor.d.ts +98 -0
  124. package/dist/src/crypto/policy-floor.js +353 -0
  125. package/dist/src/crypto/records.d.ts +319 -0
  126. package/dist/src/crypto/records.js +168 -0
  127. package/dist/src/crypto/scope.d.ts +49 -0
  128. package/dist/src/crypto/scope.js +83 -0
  129. package/dist/src/crypto/ssh.d.ts +171 -0
  130. package/dist/src/crypto/ssh.js +396 -0
  131. package/dist/src/crypto/submission.d.ts +33 -0
  132. package/dist/src/crypto/submission.js +47 -0
  133. package/dist/src/crypto/trust-roots.d.ts +29 -0
  134. package/dist/src/crypto/trust-roots.js +39 -0
  135. package/dist/src/crypto/verify-consumed.d.ts +67 -0
  136. package/dist/src/crypto/verify-consumed.js +259 -0
  137. package/dist/src/crypto/verify-origin.d.ts +50 -0
  138. package/dist/src/crypto/verify-origin.js +151 -0
  139. package/dist/src/crypto/verify-publication.d.ts +60 -0
  140. package/dist/src/crypto/verify-publication.js +150 -0
  141. package/dist/src/defs.d.ts +24 -1
  142. package/dist/src/defs.js +335 -27
  143. package/dist/src/engine.d.ts +211 -6
  144. package/dist/src/engine.js +459 -59
  145. package/dist/src/factory.d.ts +16 -0
  146. package/dist/src/factory.js +16 -4
  147. package/dist/src/global-config.d.ts +59 -0
  148. package/dist/src/global-config.js +84 -0
  149. package/dist/src/hub.d.ts +102 -32
  150. package/dist/src/hub.js +147 -58
  151. package/dist/src/index.d.ts +19 -2
  152. package/dist/src/index.js +23 -2
  153. package/dist/src/install.d.ts +538 -0
  154. package/dist/src/install.js +1981 -0
  155. package/dist/src/lock.d.ts +15 -57
  156. package/dist/src/lock.js +251 -143
  157. package/dist/src/mcp/serve.d.ts +46 -22
  158. package/dist/src/mcp/serve.js +174 -44
  159. package/dist/src/mcp/server.js +12 -1
  160. package/dist/src/model.d.ts +51 -0
  161. package/dist/src/model.js +157 -1
  162. package/dist/src/order-resolver.d.ts +184 -0
  163. package/dist/src/order-resolver.js +252 -0
  164. package/dist/src/package-version.d.ts +10 -0
  165. package/dist/src/package-version.js +42 -0
  166. package/dist/src/paths.d.ts +14 -1
  167. package/dist/src/paths.js +18 -0
  168. package/dist/src/schemas/enrollment-grant.v1.schema.json +90 -0
  169. package/dist/src/schemas/index.d.ts +1433 -0
  170. package/dist/src/schemas/index.js +31 -0
  171. package/dist/src/schemas/order.v1.schema.json +120 -0
  172. package/dist/src/schemas/origin.v1.schema.json +68 -0
  173. package/dist/src/schemas/policy-floor.v1.schema.json +29 -0
  174. package/dist/src/schemas/publication.v1.schema.json +31 -0
  175. package/dist/src/schemas/revocation.v1.schema.json +39 -0
  176. package/dist/src/schemas/submission.v1.schema.json +61 -0
  177. package/dist/src/store/def-source.d.ts +52 -0
  178. package/dist/src/store/def-source.js +335 -0
  179. package/dist/src/store/index-file.d.ts +69 -0
  180. package/dist/src/store/index-file.js +151 -0
  181. package/dist/src/store/index.d.ts +27 -0
  182. package/dist/src/store/index.js +22 -0
  183. package/dist/src/store/ingestor.d.ts +43 -0
  184. package/dist/src/store/ingestor.js +211 -0
  185. package/dist/src/store/install.d.ts +228 -0
  186. package/dist/src/store/install.js +555 -0
  187. package/dist/src/store/instruction-source.d.ts +49 -0
  188. package/dist/src/store/instruction-source.js +298 -0
  189. package/dist/src/store/origin-evidence.d.ts +21 -0
  190. package/dist/src/store/origin-evidence.js +66 -0
  191. package/dist/src/store/pre-commit-verifier.d.ts +68 -0
  192. package/dist/src/store/pre-commit-verifier.js +418 -0
  193. package/dist/src/store/resolve.d.ts +138 -0
  194. package/dist/src/store/resolve.js +363 -0
  195. package/dist/src/store/types.d.ts +288 -0
  196. package/dist/src/store/types.js +356 -0
  197. package/dist/src/store.d.ts +33 -1
  198. package/dist/src/store.js +57 -4
  199. package/dist/src/types.d.ts +146 -12
  200. package/dist/src/untar.d.ts +8 -23
  201. package/dist/src/untar.js +10 -136
  202. package/docs/agent-runner.md +86 -0
  203. package/docs/authoring.md +64 -6
  204. package/docs/bundles.md +350 -0
  205. package/docs/cli.md +1298 -106
  206. package/docs/crypto.md +832 -0
  207. package/docs/design.md +342 -20
  208. package/docs/embedding.md +132 -25
  209. package/docs/shift-logs.md +642 -0
  210. package/docs/wire-contracts.md +395 -0
  211. package/package.json +6 -1
  212. package/plugins/claude-code/.claude-plugin/marketplace.json +14 -0
  213. package/plugins/claude-code/plugin/.claude-plugin/plugin.json +8 -0
  214. package/plugins/claude-code/plugin/.mcp.json +14 -0
  215. package/plugins/claude-code/plugin/hooks/hooks.json +26 -0
  216. package/plugins/claude-code/plugin/hooks/session-end.sh +40 -0
  217. package/plugins/claude-code/plugin/hooks/session-start.sh +52 -0
  218. package/plugins/claude-code/plugin/skills/author/SKILL.md +181 -0
  219. package/plugins/claude-code/plugin/skills/conduct/SKILL.md +106 -0
  220. package/plugins/claude-code/plugin/skills/shift/SKILL.md +105 -0
  221. package/plugins/codex/.agents/plugins/marketplace.json +21 -0
  222. package/plugins/codex/plugins/owenloop/.codex-plugin/plugin.json +7 -0
  223. package/plugins/codex/plugins/owenloop/.mcp.json +20 -0
  224. package/plugins/codex/plugins/owenloop/hooks/hooks.json +26 -0
  225. package/plugins/codex/plugins/owenloop/hooks/session-end.sh +40 -0
  226. package/plugins/codex/plugins/owenloop/hooks/session-start.sh +52 -0
  227. package/plugins/codex/plugins/owenloop/skills/author/SKILL.md +181 -0
  228. package/plugins/codex/plugins/owenloop/skills/conduct/SKILL.md +106 -0
  229. 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
@@ -26,11 +29,26 @@
26
29
  import { type ToolRegistration } from '../mcp/server.ts';
27
30
  import type { HubClient } from '../hub/client.ts';
28
31
  import type { ContactHolder } from '../hub/types.ts';
32
+ import { type SubmissionKeyManager } from '../submit-proof.ts';
33
+ import type { SshProcessAdapter } from '../../../../src/crypto/ssh.ts';
34
+ import type { ConsumedVerifier } from '../consumed-verifier.ts';
29
35
  import { type HoldLoop } from './loop.ts';
36
+ export declare const HOLD_MCP_TOOL_NAMES: readonly ["get_order", "submit", "reject"];
37
+ export type HoldMcpToolName = (typeof HOLD_MCP_TOOL_NAMES)[number];
30
38
  export interface HoldMcpDeps {
31
39
  hub: HubClient;
32
40
  workflow: string;
33
41
  run: string;
42
+ /** Positive registration list. Absent exposes the full three-tool server. */
43
+ tools?: readonly HoldMcpToolName[];
44
+ /** Hub origin used to resolve the local machine signing key. */
45
+ origin?: string;
46
+ principalKeys?: SubmissionKeyManager;
47
+ env?: Record<string, string | undefined>;
48
+ /** Injectable ssh-keygen seam for hermetic submit-proof tests. */
49
+ sshProcess?: SshProcessAdapter;
50
+ /** Gate dynamic consumed values before the packet reaches the model. */
51
+ consumedVerifier?: ConsumedVerifier;
34
52
  /** B3 holder tag; rides get_order/heartbeat when known. */
35
53
  holder?: ContactHolder;
36
54
  sleep: (ms: number) => Promise<void>;
@@ -42,14 +60,16 @@ export interface HoldMcpDeps {
42
60
  jumpToleranceMs?: number;
43
61
  }
44
62
  export interface HoldMcpMount {
45
- /** The two tools (`get_order`, `submit`) for the MCP server. */
63
+ /** Exactly the selected registrations; full mode has all three tools. */
46
64
  tools: ToolRegistration[];
47
65
  /** The lease loop kept warm underneath — the role runs and stops it. */
48
66
  loop: HoldLoop;
49
67
  }
50
68
  /**
51
- * Build the hold MCP mount: the lease loop plus its two tools. The caller (the
52
- * role) creates the MCP server around `tools`, starts `loop.run()`, and pumps
53
- * stdin — stopping the loop on stdin EOF.
69
+ * Build the hold MCP mount: the lease loop plus a positive tool selection. The
70
+ * default selection is the full `get_order`/`submit`/`reject` surface. A caller
71
+ * can request an exact subset; future registrations do not enter that subset
72
+ * unless the caller names them. The role creates the MCP server around `tools`,
73
+ * starts `loop.run()`, and pumps stdin — stopping the loop on stdin EOF.
54
74
  */
55
75
  export declare function createHoldMcp(deps: HoldMcpDeps): HoldMcpMount;
@@ -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,10 @@
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";
31
+ import { normalizeSubmitValue } from "../submit-value.js";
27
32
  import { createHoldLoop } from "./loop.js";
33
+ export const HOLD_MCP_TOOL_NAMES = ['get_order', 'submit', 'reject'];
28
34
  function errMsg(e) {
29
35
  return e instanceof Error ? e.message : String(e);
30
36
  }
@@ -33,20 +39,24 @@ function orderView(res) {
33
39
  return { workflow: res.workflow, run: res.run, order: res.order, text: res.text };
34
40
  }
35
41
  /**
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.
42
+ * Build the hold MCP mount: the lease loop plus a positive tool selection. The
43
+ * default selection is the full `get_order`/`submit`/`reject` surface. A caller
44
+ * can request an exact subset; future registrations do not enter that subset
45
+ * unless the caller names them. The role creates the MCP server around `tools`,
46
+ * starts `loop.run()`, and pumps stdin — stopping the loop on stdin EOF.
39
47
  */
40
48
  export function createHoldMcp(deps) {
41
49
  const { hub, workflow, run } = deps;
42
50
  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.
51
+ // The loop's first contact arrives synchronously, but consume-side verification
52
+ // is asynchronous. Keep the unverified response in a private pending slot until
53
+ // a tool call gates it; only a gated response may populate `captured` and reach
54
+ // either the model or submit-proof construction.
55
+ let firstContact;
46
56
  let captured;
47
57
  // Set the moment the lease loop's run() settles (lease-lost, completed,
48
58
  // 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
59
+ // registered tools fast-fail with isError and never touch the hub again (plan section 4
50
60
  // — a lost claim must not be worked or double-submitted).
51
61
  let terminal;
52
62
  const inner = createHoldLoop({
@@ -59,7 +69,7 @@ export function createHoldMcp(deps) {
59
69
  out: deps.err,
60
70
  err: deps.err,
61
71
  onOrder: (res) => {
62
- captured = res;
72
+ firstContact = res;
63
73
  },
64
74
  ...(deps.holder !== undefined ? { holder: deps.holder } : {}),
65
75
  ...(deps.heartbeatIntervalMs !== undefined ? { heartbeatIntervalMs: deps.heartbeatIntervalMs } : {}),
@@ -81,6 +91,30 @@ export function createHoldMcp(deps) {
81
91
  return undefined;
82
92
  return textResult({ error: `order no longer held (${terminal}) — stop` }, true);
83
93
  }
94
+ async function gate(res) {
95
+ if (res.order === null)
96
+ return undefined;
97
+ const hasConsumedData = Object.keys(res.order.consumes).length > 0
98
+ || res.order.owes.some((owed) => owed.reasons.length > 0 || owed.proof !== undefined);
99
+ if (deps.consumedVerifier === undefined) {
100
+ if (!hasConsumedData)
101
+ return undefined;
102
+ return textResult({
103
+ 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`,
104
+ }, true);
105
+ }
106
+ try {
107
+ const checked = await deps.consumedVerifier(res.order, { hardRule: false });
108
+ if (!checked.ok)
109
+ return textResult({ error: checked.reason }, true);
110
+ for (const warning of checked.warnings)
111
+ deps.err(warning);
112
+ return undefined;
113
+ }
114
+ catch (error) {
115
+ return textResult({ error: `consumed artifact refusal (prerequisite) for ${res.workflow}/${res.run}: ${errMsg(error)}` }, true);
116
+ }
117
+ }
84
118
  const getOrderTool = {
85
119
  name: 'get_order',
86
120
  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 +123,24 @@ export function createHoldMcp(deps) {
89
123
  const gone = terminalGuard();
90
124
  if (gone !== undefined)
91
125
  return gone;
92
- if (captured !== undefined)
126
+ if (captured !== undefined) {
127
+ const refused = await gate(captured);
128
+ if (refused !== undefined)
129
+ return refused;
93
130
  return textResult(orderView(captured));
131
+ }
132
+ if (firstContact !== undefined) {
133
+ const refused = await gate(firstContact);
134
+ if (refused !== undefined)
135
+ return refused;
136
+ captured = firstContact;
137
+ return textResult(orderView(firstContact));
138
+ }
94
139
  try {
95
140
  const res = await hub.getOrder({ workflow, run, ...holderReq });
141
+ const refused = await gate(res);
142
+ if (refused !== undefined)
143
+ return refused;
96
144
  captured = res;
97
145
  return textResult(orderView(res));
98
146
  }
@@ -126,13 +174,46 @@ export function createHoldMcp(deps) {
126
174
  return textResult({ error: 'submit requires a "value"' }, true);
127
175
  }
128
176
  const done = args['done'];
177
+ // Normalize a JSON-encoded string value to the object the hub would
178
+ // store BEFORE signing it. Signing the string instead makes the hub drop
179
+ // the proof (it stores normalized bytes the signature does not cover),
180
+ // silently, on both sides — see `../submit-value.ts`. One value is used
181
+ // for both the proof and the wire so the two can never diverge.
182
+ const value = normalizeSubmitValue(args['value']);
129
183
  try {
184
+ // Submit is also a dynamic-data boundary. Fetch and gate the bound
185
+ // packet even when no origin was supplied for submit-proof signing;
186
+ // otherwise a direct submit call could bypass MCP consume-side
187
+ // verification without first calling get_order.
188
+ let orderResponse = captured ?? firstContact;
189
+ if (orderResponse === undefined) {
190
+ orderResponse = await hub.getOrder({ workflow, run, ...holderReq });
191
+ }
192
+ const refused = await gate(orderResponse);
193
+ if (refused !== undefined)
194
+ return refused;
195
+ captured = orderResponse;
196
+ let proof;
197
+ if (deps.origin !== undefined && orderResponse.order !== null) {
198
+ proof = await buildSubmitProof({
199
+ origin: deps.origin,
200
+ order: orderResponse.order,
201
+ path,
202
+ value,
203
+ now: deps.now,
204
+ warn: deps.err,
205
+ ...(deps.principalKeys !== undefined ? { principalKeys: deps.principalKeys } : {}),
206
+ ...(deps.env !== undefined ? { env: deps.env } : {}),
207
+ ...(deps.sshProcess !== undefined ? { sshProcess: deps.sshProcess } : {}),
208
+ });
209
+ }
130
210
  const res = await hub.submit({
131
211
  workflow,
132
212
  run,
133
213
  path,
134
- value: args['value'],
214
+ value,
135
215
  ...(typeof done === 'boolean' ? { done } : {}),
216
+ ...(proof !== undefined ? { proof } : {}),
136
217
  ...holderReq,
137
218
  });
138
219
  // The run closed — stop holding WITHOUT releasing (the claim is gone).
@@ -145,5 +226,46 @@ export function createHoldMcp(deps) {
145
226
  }
146
227
  },
147
228
  };
148
- return { tools: [getOrderTool, submitTool], loop };
229
+ const rejectTool = {
230
+ name: 'reject',
231
+ description: 'Reject a consumed artifact path with a reason. The hub derives the rejecting step from this held run; the client cannot supply `by`.',
232
+ inputSchema: {
233
+ type: 'object',
234
+ required: ['path', 'text'],
235
+ properties: {
236
+ path: { type: 'string', description: 'The consumed artifact path to reject.' },
237
+ text: { type: 'string', description: 'The reason for rejecting the artifact.' },
238
+ },
239
+ additionalProperties: false,
240
+ },
241
+ handler: async (args) => {
242
+ const gone = terminalGuard();
243
+ if (gone !== undefined)
244
+ return gone;
245
+ const path = args['path'];
246
+ const text = args['text'];
247
+ if (typeof path !== 'string' || path.trim() === '') {
248
+ return textResult({ error: 'reject requires a non-empty string "path"' }, true);
249
+ }
250
+ if (typeof text !== 'string' || text.trim() === '') {
251
+ return textResult({ error: 'reject requires a non-empty string "text"' }, true);
252
+ }
253
+ try {
254
+ const res = await hub.reject({ workflow, run, path, text });
255
+ if (res.closed === true)
256
+ loop.stop('submitted', { release: false });
257
+ return textResult({ ok: res.ok, closed: res.closed ?? false, text: res.text });
258
+ }
259
+ catch (e) {
260
+ return textResult({ error: errMsg(e) }, true);
261
+ }
262
+ },
263
+ };
264
+ const registrations = {
265
+ get_order: getOrderTool,
266
+ submit: submitTool,
267
+ reject: rejectTool,
268
+ };
269
+ const selected = deps.tools ?? HOLD_MCP_TOOL_NAMES;
270
+ return { tools: selected.map((name) => registrations[name]), loop };
149
271
  }
@@ -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, ReportResolutionRequest, ReportResolutionResponse, 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,13 @@ 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>;
17
+ /**
18
+ * Plan §6: record what this shift resolved the order's compound capability to,
19
+ * BEFORE the harness launches. Idempotent on the hub by order id, so a
20
+ * re-dispatch no-ops rather than overwriting the first (pre-spend) record.
21
+ */
22
+ reportResolution(req: ReportResolutionRequest): Promise<ReportResolutionResponse>;
16
23
  whoami(): Promise<WhoamiResponse>;
17
24
  /** B5 cheap wake pre-check; `cursor` rides the query string only when set. */
18
25
  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,8 @@ 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),
85
+ reportResolution: (req) => post('report_resolution', req),
72
86
  whoami: () => get('whoami'),
73
87
  // Cursor is an opaque non-negative integer; omit it entirely to bootstrap
74
88
  // (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,37 @@ 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
+ /**
35
+ * The TARGET version for this owed output when a version-aware hub
36
+ * projects it: the version the next successful producer commit lands
37
+ * (claim-time committed version + 1), NOT the currently-committed one.
38
+ * It is what a producer signs in its submission proof and what a
39
+ * downstream consumer checks that proof against.
40
+ */
41
+ version?: number;
42
+ judgmentRejects: number;
43
+ schemaRejects: number;
44
+ reasons: ReasonEntry[];
45
+ proof?: string;
46
+ }>;
34
47
  consumes: Record<string, unknown>;
35
48
  expected_outputs: Array<{
36
49
  path: string;
@@ -151,12 +164,11 @@ export interface Lease {
151
164
  outcome?: string;
152
165
  }
153
166
  /**
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.
167
+ * The persisted order packet re-served by the transport. The packet carries
168
+ * the definition projection digest and dynamic routing/state fields only.
169
+ * Workers must resolve authored command or prompt text from the local store.
170
+ * Proof/version fields describe the target protocol and remain optional because
171
+ * the deployed hub can omit them; optionality does not imply end-to-end support.
160
172
  */
161
173
  export interface OrderPacket {
162
174
  run: string;
@@ -164,26 +176,63 @@ export interface OrderPacket {
164
176
  step: string;
165
177
  key: string;
166
178
  index?: number;
179
+ /** Projection digest identifying the installed definition snapshot. */
180
+ defDigest: string;
167
181
  inputs: string[];
168
182
  outputs: string[];
169
- /** Opaque location hint — exec's command cwd when set. */
183
+ /** Opaque location hint — the worker's cwd when set. */
170
184
  workdir?: string;
185
+ /**
186
+ * THE COMPOSED CAPABILITIES this order was offered under, in the step's
187
+ * authored order — `['build:deep']` for a `build` step on a `deep` run. This
188
+ * is the key into the shift's `capabilityModels` map (see
189
+ * `src/agent/capability-model.ts`), and therefore what decides which model and
190
+ * effort run. Absent from a pre-modifier hub, which is why the worker treats
191
+ * an empty list as "nothing to resolve against" and refuses rather than
192
+ * guessing.
193
+ */
194
+ capabilities?: string[];
195
+ /** The run's routing modifier (`deep`), as the caller asked for at start_run. */
196
+ modifier?: string;
197
+ /**
198
+ * `true` when the engine re-offered this step at its escalation target instead
199
+ * of the run's own modifier. The worker does not act on it; it goes in the
200
+ * brief so the agent knows it is on the recovery path.
201
+ */
202
+ escalated?: boolean;
203
+ /**
204
+ * DEPRECATED, and no longer read by the agent loop. The def's authored tier
205
+ * name (`strong`) from the pre-modifier scheme. The hub still projects it for
206
+ * older workers; this one resolves from `capabilities` alone.
207
+ */
171
208
  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;
209
+ /** Worker kind; `'command'` for command orders, absent means agent. */
210
+ worker?: string;
211
+ /** Artifact stem this order's judge step must verdict, when present. */
212
+ judge?: string;
176
213
  spec?: Record<string, unknown>;
177
214
  x?: Record<string, unknown>;
178
- prompt: string;
179
215
  consumes: Record<string, unknown>;
180
- /** The owed outputs + their reason threads — exec submits the receipt to each. */
216
+ /** Claim-time consumed versions when a compatible hub preserves the map. */
217
+ consumedFingerprint?: Record<string, number>;
218
+ /** Serialized submission proof for the consumed values, projected by a
219
+ * proof-aware hub. Absent from any hub that does not store submit proofs;
220
+ * consume-side verification then reports the artifact as unproven. */
221
+ consumesProof?: string;
222
+ /** The owed outputs and their reason threads. */
181
223
  owes: Array<{
182
224
  path: string;
183
- acceptance: string;
225
+ /** Target version for this output's next successful commit (claim-time
226
+ * committed version + 1), issued by a version-aware hub inside the claim
227
+ * transaction. This is what a producer signs in its submission proof.
228
+ * Absent from a hub that is not version-aware, which leaves the producer
229
+ * submit unsigned. */
230
+ version?: number;
184
231
  judgmentRejects: number;
185
232
  schemaRejects: number;
186
233
  reasons: ReasonEntry[];
234
+ /** Target-protocol reason-thread proof; the deployed hub may omit it. */
235
+ proof?: string;
187
236
  }>;
188
237
  cause?: string;
189
238
  }
@@ -209,6 +258,39 @@ export interface HeartbeatRequest {
209
258
  holder?: ContactHolder;
210
259
  }
211
260
  export type HeartbeatResponse = HubResponse;
261
+ /**
262
+ * Which settings row served the order, mirroring hub-core's `ResolutionMatch`.
263
+ * `refused` is a real, reportable outcome: the shift found no row and will not
264
+ * launch anything, and that is exactly the fact worth recording.
265
+ */
266
+ export type ResolutionMatch = 'exact' | 'bare' | 'refused';
267
+ export interface ResolutionPayload {
268
+ /** The settings key that matched (`build:deep`, or `build` on a bare match). */
269
+ capability: string;
270
+ match: ResolutionMatch;
271
+ /** Absent on `refused`, and on a command order, which selects no model. */
272
+ model?: string;
273
+ effort?: string;
274
+ harness?: string;
275
+ }
276
+ export interface ReportResolutionRequest {
277
+ workflow: string;
278
+ run: string;
279
+ resolution: ResolutionPayload;
280
+ }
281
+ /**
282
+ * The hub is idempotent by order id: `recorded: false` means a report for this
283
+ * run already stood and was left unchanged. `claimed` is the live lease state,
284
+ * disclosed and never enforced — a `false` here means the order is no longer
285
+ * this worker's to run.
286
+ */
287
+ export interface ReportResolutionResponse extends HubResponse {
288
+ workflow: string;
289
+ run: string;
290
+ step: string;
291
+ recorded: boolean;
292
+ claimed: boolean;
293
+ }
212
294
  export type ReleaseRequest = {
213
295
  session: string;
214
296
  } | {
@@ -249,6 +331,8 @@ export interface SubmitRequest {
249
331
  path: string;
250
332
  value: unknown;
251
333
  done?: boolean;
334
+ /** Target-protocol DSSE envelope; production submit transport currently drops it. */
335
+ proof?: string;
252
336
  /** W7: who produced this submission (D4) — carried on all three submit paths. */
253
337
  holder?: ContactHolder;
254
338
  }
@@ -258,13 +342,31 @@ export interface SubmitRequest {
258
342
  * commit verdict: `green`/`submitted` are success (the value landed);
259
343
  * `schema-rejected`/`born-rejected`/`artifact-too-large`/
260
344
  * `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).
345
+ * submit closed the run (only present on a `green`/`submitted` outcome). The
346
+ * deployed response does not return the committed version, the next target
347
+ * version, proof acceptance, or an idempotency result. exec treats any
348
+ * non-green/submitted outcome as a failed submit (exit 1).
263
349
  */
264
350
  export interface SubmitResponse extends HubResponse {
265
351
  outcome?: string;
266
352
  closed?: boolean;
267
353
  }
354
+ /**
355
+ * Invalidate an artifact through the claiming worker's consume-edge authority.
356
+ * `by` is deliberately absent: the hub derives the actor from the claiming
357
+ * run's step, so a worker cannot impersonate another step.
358
+ */
359
+ export interface RejectRequest {
360
+ workflow: string;
361
+ run: string;
362
+ path: string;
363
+ text: string;
364
+ }
365
+ /** The reject verb's flattened response envelope. */
366
+ export interface RejectResponse extends HubResponse {
367
+ ok: boolean;
368
+ closed?: boolean;
369
+ }
268
370
  export interface WhoamiResponse extends HubResponse {
269
371
  orgId: string;
270
372
  orgName: string;
@@ -286,5 +388,7 @@ export interface WhoamiResponse extends HubResponse {
286
388
  export declare class HubError extends Error {
287
389
  readonly status: number;
288
390
  readonly code?: string;
289
- constructor(status: number, message: string, code?: string);
391
+ /** Server-requested delay before retrying, normalized from Retry-After. */
392
+ readonly retryAfterMs?: number;
393
+ constructor(status: number, message: string, code?: string, retryAfterMs?: number);
290
394
  }
@@ -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
+ }