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
@@ -5,7 +5,7 @@
5
5
  * owenloop-service repo): owenloop runs two distinct planes. The HUMAN control
6
6
  * plane is the everyday operator surface — starting runs, answering gates,
7
7
  * pushing defs — and it authenticates as the logged-in human. The AGENT plane
8
- * is what a delivery-line worker uses with its own `olp_` bearer. This module
8
+ * is what a Step Agent uses with its own `olp_` bearer. This module
9
9
  * serves the HUMAN plane to a local MCP host (Claude Code) over stdio: it reads
10
10
  * newline-delimited JSON-RPC 2.0 on stdin, translates each `tools/call` into one
11
11
  * authenticated HTTPS request to the hub's `/api/*` REST mirror, and writes the
@@ -20,76 +20,94 @@
20
20
  * header, never a tool result. The server holds NO credential state between
21
21
  * calls — its only state is the resolved origin and the fixed tool list.
22
22
  * 2. `create_agent` MINTS an `olp_` agent token and writes it straight to the
23
- * local store (`storeCredential`, slot `agent:<name>`, scopes `['work']`);
23
+ * local store (`storeCredential`, slot `agent:<name>`, caller-chosen scopes,
24
+ * default `['work']`);
24
25
  * the token is NEVER returned in a tool result, printed, or logged. The
25
26
  * mint response body carries the plaintext in TWO fields (`data.token` AND
26
27
  * the human `text` "Store this secret now…"), so the handler builds its
27
- * result object FROM SCRATCH (`{name, pools, stored:true}`) and never
28
+ * result object FROM SCRATCH (`{name, crews, stored:true}`) and never
28
29
  * passes any field of the raw body outbound.
29
30
  *
30
- * The transport core is in `./server.ts` (a copy of owenwork's; see its header).
31
+ * The transport core is in `./server.ts` (a copy of owenloop's; see its header).
31
32
  * Everything owenloop-specific — origin resolution, the authenticated hub
32
33
  * client, the tool registrations, the enrollment capability gate, and the
33
34
  * command body — lives here.
34
35
  */
36
+ import { packageVersion } from "../package-version.js";
35
37
  import { CliError } from "../util.js";
38
+ import { DSSE_SSH_NAMESPACE, PrincipalKeyManager, buildSubmissionRecord, createSshSigner, signSubmission, } from "../crypto/index.js";
36
39
  import { authHeader, ensureFreshOAuth, hubFetch, refreshOAuth, storeCredential, } from "../credentials.js";
37
- import { credentialBackend, listStoredHubOrigins, normalizeOrigin, readStoredCredential, resolveEndpoint, } from "../hub.js";
40
+ import { DEFAULT_HUB, listStoredHubOrigins, normalizeOrigin, readStoredCredential, resolveEndpoint, } from "../hub.js";
41
+ import { globalConfigPath, readGlobalConfig } from "../global-config.js";
38
42
  import { createMcpServer, pumpStdin, textResult } from "./server.js";
39
43
  /** The human control plane authenticates as the human slot, always. */
40
44
  const HUMAN = { principal: 'human' };
41
45
  const isObject = (v) => typeof v === 'object' && v !== null && !Array.isArray(v);
46
+ // ---- origin resolution ------------------------------------------------------
42
47
  /**
43
48
  * Resolve the hub origin this server binds to, precedence:
44
49
  * 1. `--hub <origin>` flag,
45
50
  * 2. `OWENLOOP_HUB` env,
46
- * 3. if the FILE credential backend holds exactly ONE hub with a valid `human`
47
- * slot, use it,
48
- * 4. else exit 2 with a message naming BOTH remedies.
51
+ * 3. `~/.owenloop/config.json` (written by `owenloop login`; see
52
+ * `src/global-config.ts`'s header for why this is a separate file from
53
+ * the execution plane's `settings.json`),
54
+ * 4. if the FILE credential backend holds exactly ONE hub with a valid
55
+ * `human` slot, use it (back-compat for a login that predates rung 3),
56
+ * 5. else `DEFAULT_HUB` (`src/hub.ts`) — the production hub.
49
57
  *
50
58
  * Rungs 1–2 normalize the origin (a malformed value throws a `CliError` → the
51
- * command's exit-1 path via `mainAsync`'s catch, matching every other command).
52
- * Rung 3 is file-backend-only because only the file backend can enumerate
53
- * (`listStoredHubOrigins`); `null` (cannot enumerate — keychain/external), `[]`
54
- * (nothing stored), and length>1 (ambiguous) each get a tailored exit-2 message.
59
+ * command's exit-1 path via `mainAsync`'s catch, matching every other
60
+ * command). Rung 3 reads `home` from `io.env.HOME`/`io.env.USERPROFILE` (the
61
+ * first non-blank of the two, mirroring `src/cli.ts`'s `workflowHome`) — but
62
+ * unlike `workflowHome`, an absent home does NOT throw here: it just means
63
+ * this rung has nothing to offer, same as a missing or malformed config file
64
+ * (`readGlobalConfig` never throws; see its doc comment in
65
+ * `src/global-config.ts`). Rung 4 is file-backend-only because only the file
66
+ * backend can enumerate (`listStoredHubOrigins`); `null` (cannot enumerate —
67
+ * keychain/external), `[]` (nothing stored), and length>1 (ambiguous) are ALL
68
+ * just "this rung has nothing to offer" and fall through to rung 5 — none of
69
+ * them is an error here.
55
70
  *
56
- * DELIBERATELY there is NO silent production fallback (the CLI's `resolveHub`
57
- * `DEFAULT_HUB` rung): a control-plane server must never bind to a hub the
58
- * operator did not name.
71
+ * This function used to stop at what is now rung 4 and exit 2 instead of
72
+ * falling through, with a comment reading: "DELIBERATELY there is NO silent
73
+ * production fallback (the CLI's `resolveHub` `DEFAULT_HUB` rung): a
74
+ * control-plane server must never bind to a hub the operator did not name."
75
+ * Two things were wrong with that rule:
76
+ * 1. `resolveHub` (`src/cli.ts:2667-2674`) — used by `login` (`:2869`),
77
+ * `logout` (`:3173`), and `connect` (`:3193`) — ALREADY falls back to
78
+ * `DEFAULT_HUB`. `capability` and `crew` use `resolveAgentHub` instead;
79
+ * that resolver has no `DEFAULT_HUB` rung and still exits 2. The `login`
80
+ * command that CREATES credentials defaults to production while MCP's
81
+ * startup origin resolution exited 2 before it could reach any read or
82
+ * write tool. That asymmetry was the real inconsistency.
83
+ * 2. The no-fallback rule bought no safety. With no credential for the
84
+ * resolved origin, the server fails at the FIRST TOOL CALL with
85
+ * `loginHint` (below): "not logged in to <origin> — run `owenloop login
86
+ * --hub <origin>` in a terminal, then retry". That is a strictly better
87
+ * failure than dying before `initialize` — the host shows an actionable
88
+ * tool error instead of a dead server.
59
89
  */
60
90
  export function resolveMcpOrigin(io, hubFlag) {
61
91
  const explicit = hubFlag ?? io.env.OWENLOOP_HUB;
62
92
  if (explicit !== undefined && explicit.trim() !== '') {
63
93
  try {
64
- return { origin: normalizeOrigin(explicit) };
94
+ return normalizeOrigin(explicit);
65
95
  }
66
96
  catch (e) {
67
97
  throw new CliError(e.message);
68
98
  }
69
99
  }
70
- const origins = listStoredHubOrigins(io.env, io.keychain);
71
- if (origins === null) {
72
- const backend = credentialBackend(io.env, io.keychain);
73
- const which = backend.kind === 'external' ? 'external-command' : 'keychain';
74
- return {
75
- exitCode: 2,
76
- message: `cannot list stored hubs from the ${which} credential store — ` +
77
- 'pass --hub <origin> (or set OWENLOOP_HUB)',
78
- };
100
+ const home = [io.env.HOME, io.env.USERPROFILE].find((value) => value !== undefined && value.trim() !== '');
101
+ if (home !== undefined) {
102
+ const config = readGlobalConfig(globalConfigPath(home));
103
+ if (config !== null)
104
+ return config.hub;
79
105
  }
80
- if (origins.length === 0) {
81
- return {
82
- exitCode: 2,
83
- message: 'no hub credentials stored — run `owenloop login --hub <origin>` first, or pass --hub <origin>',
84
- };
85
- }
86
- if (origins.length > 1) {
87
- return {
88
- exitCode: 2,
89
- message: `multiple hubs in the credential store (${origins.join(', ')}) — pass --hub <origin>`,
90
- };
106
+ const origins = listStoredHubOrigins(io.env, io.keychain);
107
+ if (origins !== null && origins.length === 1) {
108
+ return origins[0];
91
109
  }
92
- return { origin: origins[0] };
110
+ return DEFAULT_HUB;
93
111
  }
94
112
  // ---- the authenticated hub client -------------------------------------------
95
113
  /** The non-interactive "you are not authenticated" instruction (Decision 8). */
@@ -204,20 +222,118 @@ function passthrough(deps, build) {
204
222
  return toolResultFromRest(r);
205
223
  };
206
224
  }
225
+ let warnedMcpUnsigned = false;
226
+ /** Sign the baseline MCP submit when a claimed order can be resolved locally. */
227
+ async function signMcpSubmit(deps, args) {
228
+ const workflow = args['workflow'];
229
+ const run = args['run'];
230
+ const path = args['path'];
231
+ if (typeof workflow !== 'string' || typeof run !== 'string' || typeof path !== 'string' || !('value' in args)) {
232
+ return undefined;
233
+ }
234
+ let keys;
235
+ try {
236
+ keys = deps.io.principalKeys ?? new PrincipalKeyManager({ env: deps.io.env });
237
+ }
238
+ catch (e) {
239
+ warnMcpUnsigned(deps, `machine signing is unavailable (${e.message}); submitting without a proof`);
240
+ return undefined;
241
+ }
242
+ const ref = keys.resolveRef(deps.origin, 'machine');
243
+ if (ref === null) {
244
+ warnMcpUnsigned(deps, `no machine signing key for ${deps.origin}; submitting without a proof`);
245
+ return undefined;
246
+ }
247
+ const inspected = await keys.inspect(ref);
248
+ if (!inspected.exists || inspected.publicKey === undefined) {
249
+ warnMcpUnsigned(deps, `machine signing key for ${deps.origin} is unavailable; submitting without a proof`);
250
+ return undefined;
251
+ }
252
+ const orderResponse = await callHub(deps, {
253
+ method: 'POST',
254
+ path: '/api/get_order',
255
+ body: { workflow, run },
256
+ });
257
+ if (!isOk(orderResponse.status) || !isObject(orderResponse.json) || !isObject(orderResponse.json['order'])) {
258
+ warnMcpUnsigned(deps, `order metadata for ${workflow}/${run} was unavailable; submitting without a proof`);
259
+ return undefined;
260
+ }
261
+ const order = orderResponse.json['order'];
262
+ const version = outputVersion(order, path);
263
+ if (version === undefined) {
264
+ warnMcpUnsigned(deps, `order ${workflow}/${run} omitted authoritative version metadata for output '${path}'; submitting without a proof`);
265
+ return undefined;
266
+ }
267
+ const consumedFingerprint = submissionFingerprint(order, deps);
268
+ if (consumedFingerprint === undefined)
269
+ return undefined;
270
+ const record = buildSubmissionRecord({
271
+ run: order.run,
272
+ workflow: order.workflow,
273
+ defDigest: order.defDigest,
274
+ step: order.step,
275
+ key: order.key,
276
+ ...(order.index !== undefined ? { index: order.index } : {}),
277
+ produced: [{ artifact: path, version, value: args['value'] }],
278
+ consumedFingerprint,
279
+ producerKeyId: inspected.publicKey.keyid,
280
+ timestamp: Date.now(),
281
+ });
282
+ return keys.withSigningKey(ref, async (keyPath) => {
283
+ const signer = createSshSigner({
284
+ namespace: DSSE_SSH_NAMESPACE,
285
+ signKeyPath: keyPath,
286
+ ...(deps.io.sshProcess !== undefined ? { process: deps.io.sshProcess } : {}),
287
+ });
288
+ return signSubmission(record, signer);
289
+ });
290
+ }
291
+ function submissionFingerprint(order, deps) {
292
+ if (order.consumedFingerprint !== undefined)
293
+ return order.consumedFingerprint;
294
+ if (order.inputs.length > 0 || Object.keys(order.consumes).length > 0) {
295
+ warnMcpUnsigned(deps, `order ${order.workflow}/${order.run} omitted its consumed fingerprint; submitting without a proof`);
296
+ return undefined;
297
+ }
298
+ return {};
299
+ }
300
+ /**
301
+ * Resolve a signed submit version from authoritative immutable metadata only.
302
+ * Judge claims name the already-submitted version in their fingerprint. Producer
303
+ * claims do not name a retry-safe target: `owes[].version` is claim-time state and
304
+ * can be stale after a refinement, lost response, unsigned commit, or restart.
305
+ */
306
+ function outputVersion(order, path) {
307
+ if (order.judge === path)
308
+ return order.consumedFingerprint?.[path];
309
+ return undefined;
310
+ }
311
+ function warnMcpUnsigned(deps, reason) {
312
+ if (warnedMcpUnsigned)
313
+ return;
314
+ warnedMcpUnsigned = true;
315
+ deps.io.err(`owenloop mcp: ${reason}`);
316
+ }
207
317
  /**
208
318
  * The 17 baseline tools — names, descriptions, and schemas mirror the hub's own
209
319
  * HTTP-MCP toolset (owenloop-service `apps/hub-edge/src/mcp/tools.ts`); each maps
210
- * to an H3 `/api/*` REST mirror. Descriptions say "agent" for the identity,
211
- * never "tool" (model-doc §0/§10).
320
+ * to an H3 `/api/*` REST mirror. Descriptions say "Scoped Identity" for the identity
321
+ * (wire names keep `agent`), never "tool" (model-doc §0/§10).
322
+ *
323
+ * This is not the server's whole tool list. `runMcpCommand` assembles the full
324
+ * set: these 17, plus `createAgentTool`, plus the four crew tools from
325
+ * `buildCrewTools` (below — deliberately NOT folded in here, since they do not
326
+ * mirror the hub's own MCP toolset), plus the conditionally-registered
327
+ * `stageEnrollmentTool`.
212
328
  */
213
329
  function buildBaselineTools(deps) {
214
330
  return [
215
331
  {
216
332
  name: 'whats_next',
217
- description: 'THE verb. With workflow: ticks it and returns the next work order(s), or a status summary if none. Without workflow: the inbox of started instances. Serves only YOUR OWN runs by default. Pass serve_pools to partition your own runs further (intersects with each step\'s labels; absent or [] = no label filter). serve_pools is ignored in inbox mode (no workflow).',
333
+ description: 'THE verb. With workflow: ticks it and returns the next work order(s), or a status summary if none. Without workflow: the inbox of started instances. Serves only YOUR OWN runs by default. Pass serve_crews to partition your own runs further (intersects with each step\'s capabilities; absent or [] = no capability filter). serve_crews is ignored in inbox mode (no workflow).',
218
334
  inputSchema: {
219
335
  type: 'object',
220
- properties: { workflow: { type: 'string' }, serve_pools: { type: 'array', items: { type: 'string' } } },
336
+ properties: { workflow: { type: 'string' }, serve_crews: { type: 'array', items: { type: 'string' } } },
221
337
  additionalProperties: false,
222
338
  },
223
339
  handler: passthrough(deps, (a) => ({ method: 'POST', path: '/api/whats_next', body: a })),
@@ -237,7 +353,23 @@ function buildBaselineTools(deps) {
237
353
  required: ['workflow', 'run', 'path', 'value'],
238
354
  additionalProperties: false,
239
355
  },
240
- handler: passthrough(deps, (a) => ({ method: 'POST', path: '/api/submit', body: a })),
356
+ handler: async (args) => {
357
+ let proof;
358
+ try {
359
+ proof = await signMcpSubmit(deps, args);
360
+ }
361
+ catch (e) {
362
+ // A configured signer/tool failure is a submit error, not an
363
+ // unsigned fallback. The missing-key cases are handled inside the
364
+ // helper and remain compatible with pre-WP-D2 clients.
365
+ return errorText(e.message);
366
+ }
367
+ const body = proof === undefined ? args : { ...args, proof };
368
+ const r = await callHub(deps, { method: 'POST', path: '/api/submit', body });
369
+ if (r.authFailed)
370
+ return errorText(r.authMessage ?? loginHint(deps.origin));
371
+ return toolResultFromRest(r);
372
+ },
241
373
  },
242
374
  {
243
375
  name: 'reject_artifact',
@@ -289,7 +421,7 @@ function buildBaselineTools(deps) {
289
421
  },
290
422
  {
291
423
  name: 'get_workflow',
292
- description: 'Def summary and full workflow bundle: steps with consumes/produces, schemas, judges, each step\'s prompt body, model/worker/command, and x extension bags, plus mermaid source and the def content hash/version.',
424
+ description: 'Def summary and full workflow bundle: steps with consumes/produces, schemas, judges, each step\'s prompt body, model/executor/command, and x extension bags, plus mermaid source and the def content hash/version.',
293
425
  inputSchema: {
294
426
  type: 'object',
295
427
  properties: { name: { type: 'string' } },
@@ -387,20 +519,25 @@ function buildBaselineTools(deps) {
387
519
  },
388
520
  {
389
521
  name: 'presence_ping',
390
- description: 'Register or refresh this conductor in the presence registry (name + the labels it serves). Call it on a ~60s cadence; the entry reads as offline after ~3 min of missed pings. Observability only. Omitting serve_pools stores an empty label set (overwrite, NOT keep-previous).',
522
+ description: 'Register or refresh this Shift in the presence registry: its name, the crews it serves, and optionally which process incarnation is reporting. Call it on a ~60s cadence; the entry reads as offline once ~3 min have passed since its last ping — derived when the registry is read, nothing sweeps it. Observability only: it never affects serving and never wakes anyone. This is NOT the lease heartbeat — that is the separate `heartbeat` tool, one per claimed run, whose lapse gets the claim reaped. Every field is overwrite, NOT keep-previous: omitting serve_crews stores an empty set, which means "every crew this principal belongs to" (the same reading whats_next gives an empty serve_crews) and NOT "no crews"; omitting shift_id/started_at clears them.',
391
523
  inputSchema: {
392
524
  type: 'object',
393
- properties: { name: { type: 'string' }, serve_pools: { type: 'array', items: { type: 'string' } } },
525
+ properties: {
526
+ name: { type: 'string' },
527
+ serve_crews: { type: 'array', items: { type: 'string' } },
528
+ shift_id: { type: 'string' },
529
+ started_at: { type: 'number' },
530
+ },
394
531
  required: ['name'],
395
532
  additionalProperties: false,
396
533
  },
397
534
  handler: passthrough(deps, (a) => ({ method: 'POST', path: '/api/presence_ping', body: a })),
398
535
  },
399
536
  {
400
- name: 'list_conductors',
401
- description: "Your principal's registered conductors, each with an online/offline flag (derived from its last ping), the labels it serves, and how long since it was last seen.",
537
+ name: 'list_shifts',
538
+ description: "Your principal's registered Shifts, each with an online/offline flag (derived at read time from its last ping, ~3 min), how long since it was last seen, the crews it serves (returned as `crews`; an empty list means every crew this principal belongs to, not none), and the reporting process incarnation (`shiftId`/`startedAt`) when the hub recorded one.",
402
539
  inputSchema: { type: 'object', properties: {}, additionalProperties: false },
403
- handler: passthrough(deps, () => ({ method: 'GET', path: '/api/conductors' })),
540
+ handler: passthrough(deps, () => ({ method: 'GET', path: '/api/shifts' })),
404
541
  },
405
542
  {
406
543
  name: 'wake',
@@ -421,22 +558,23 @@ function buildBaselineTools(deps) {
421
558
  /** Legal agent name, mirroring hub.ts's `ACCOUNT_RE` shape — advisory in the schema, ENFORCED in the handler. */
422
559
  const AGENT_NAME_RE = /^[A-Za-z0-9][A-Za-z0-9._-]{0,63}$/;
423
560
  /**
424
- * Tool 18 — `create_agent`. Mints a NEW agent identity and writes its `olp_`
561
+ * Tool 18 — `create_agent`. Mints a NEW Scoped Identity and writes its `olp_`
425
562
  * token straight to the local store; NEVER returns the token. Decision 6: the
426
563
  * mint response leaks the plaintext in `data.token` AND the human `text` field,
427
564
  * so this handler never passes the raw body outbound — it takes only the
428
- * validated `token` (to store) and the safe `pools` names (to report), and
429
- * builds `{name, pools, stored:true}` from scratch.
565
+ * validated `token` (to store) and the safe `crews` names (to report), and
566
+ * builds `{name, crews, stored:true}` from scratch.
430
567
  */
431
568
  function createAgentTool(deps) {
432
569
  return {
433
570
  name: 'create_agent',
434
- description: 'Create a NEW agent identity on the hub and store its credential locally. NEVER returns the token — it is written to this machine\'s credential store only. Refuses a name that is already taken. Mints with `work` scope.',
571
+ description: 'Create a NEW Scoped Identity on the hub and store its credential locally. NEVER returns the token — it is written to this machine\'s credential store only. Refuses a name that is already taken. Mints with `work` scope by default; pass `scopes` (e.g. ["work","run"]) to choose.',
435
572
  inputSchema: {
436
573
  type: 'object',
437
574
  properties: {
438
575
  name: { type: 'string', pattern: '^[A-Za-z0-9][A-Za-z0-9._-]{0,63}$' },
439
- pools: { type: 'array', items: { type: 'string' } },
576
+ crews: { type: 'array', items: { type: 'string' } },
577
+ scopes: { type: 'array', items: { type: 'string' } },
440
578
  },
441
579
  required: ['name'],
442
580
  additionalProperties: false,
@@ -448,10 +586,22 @@ function createAgentTool(deps) {
448
586
  if (typeof name !== 'string' || !AGENT_NAME_RE.test(name)) {
449
587
  return errorText('invalid agent name — expected 1-64 chars matching [A-Za-z0-9][A-Za-z0-9._-]*');
450
588
  }
451
- const pools = args['pools'];
452
- const body = { name, scopes: ['work'] };
453
- if (Array.isArray(pools))
454
- body.pools = pools;
589
+ // `scopes` is optional. When present it must be a non-empty array of
590
+ // non-empty strings — validated BEFORE any network call (the schema is
591
+ // advisory). Absent → the `work`-only default. No scope-NAME check: the
592
+ // hub is the enforcement of record (same stance as crews).
593
+ const scopesArg = args['scopes'];
594
+ let scopes;
595
+ if (scopesArg !== undefined) {
596
+ if (!Array.isArray(scopesArg) || scopesArg.length === 0 || !scopesArg.every((s) => typeof s === 'string' && s !== '')) {
597
+ return errorText('invalid scopes — expected a non-empty array of scope name strings');
598
+ }
599
+ scopes = scopesArg;
600
+ }
601
+ const crews = args['crews'];
602
+ const body = { name, scopes: scopes ?? ['work'] };
603
+ if (Array.isArray(crews))
604
+ body.crews = crews;
455
605
  const r = await callHub(deps, { method: 'POST', path: '/api/mint_agent_token', body });
456
606
  if (r.authFailed)
457
607
  return errorText(r.authMessage ?? loginHint(deps.origin));
@@ -470,12 +620,12 @@ function createAgentTool(deps) {
470
620
  await storeCredential(deps.io, deps.origin, { principal: 'agent', account: name }, { kind: 'agent', accessToken: token });
471
621
  }
472
622
  catch (e) {
473
- return errorText(`${e.message} — the minted token was NOT stored — revoke/re-key the agent '${name}' from the console`);
623
+ return errorText(`${e.message} — the minted token was NOT stored — revoke/re-key the Scoped Identity '${name}' from the console`);
474
624
  }
475
- // Success: built from scratch. `pools` (poolNames) is safe; token/text/id
476
- // /agentId/poolIds from the body must never reach an outbound frame.
477
- const outPools = isObject(r.json) && Array.isArray(r.json['pools']) ? r.json['pools'] : [];
478
- return textResult({ name, pools: outPools, stored: true });
625
+ // Success: built from scratch. `crews` (crewNames) is safe; token/text/id
626
+ // /agentId/crewIds from the body must never reach an outbound frame.
627
+ const outCrews = isObject(r.json) && Array.isArray(r.json['crews']) ? r.json['crews'] : [];
628
+ return textResult({ name, crews: outCrews, stored: true });
479
629
  },
480
630
  };
481
631
  }
@@ -483,12 +633,12 @@ function createAgentTool(deps) {
483
633
  function stageEnrollmentTool(deps) {
484
634
  return {
485
635
  name: 'stage_enrollment',
486
- description: 'Stage an agent enrollment on the hub, returning a join code the new agent redeems. A join code is transferred authority, not a credential — it is safe to surface.',
636
+ description: 'Stage a Scoped Identity enrollment on the hub, returning a join code the enrolling machine redeems. A join code is transferred authority, not a credential — it is safe to surface.',
487
637
  inputSchema: {
488
638
  type: 'object',
489
639
  properties: {
490
640
  name: { type: 'string', pattern: '^[A-Za-z0-9][A-Za-z0-9._-]{0,63}$' },
491
- pools: { type: 'array', items: { type: 'string' } },
641
+ crews: { type: 'array', items: { type: 'string' } },
492
642
  },
493
643
  required: ['name'],
494
644
  additionalProperties: false,
@@ -496,6 +646,118 @@ function stageEnrollmentTool(deps) {
496
646
  handler: passthrough(deps, (a) => ({ method: 'POST', path: '/api/stage_enrollment', body: a })),
497
647
  };
498
648
  }
649
+ /**
650
+ * Crew management — the MCP counterpart to the `owenloop crew` CLI family
651
+ * (`src/cli.ts`'s `dispatchCrew`, merged as PR #88). All FOUR tools below are
652
+ * plain `passthrough` registrations: the hub's crew response bodies carry no
653
+ * secret (unlike `create_agent`'s mint body), so there is no reason to
654
+ * hand-build a result, and the hub's `/api/*` routes plus the verbs underneath
655
+ * them are already the enforcement of record for every field — a client-side
656
+ * copy of that validation would just be a second place for the rules to drift.
657
+ *
658
+ * CREDENTIAL PLANE: unchanged, and worth restating because it is what makes
659
+ * crew mutation reachable at all from this server. `callHub` always
660
+ * authenticates as the `human` slot (`HUMAN`, above) — `owenloop mcp` never
661
+ * calls the hub as a Scoped Identity. On the hub, `createCrew`, `addCrewMember`,
662
+ * and `removeCrewMember` gate through `assertCrewMutationAllowed`
663
+ * (`packages/hub-core/src/verbs/manage-crews.ts`), which falls through to
664
+ * `assertAllowed(actor, 'manage_crews')` — a verb with NO entry in
665
+ * `AGENT_SCOPE_FOR_VERB` (`rbac.ts`), so an agent-kind actor is refused
666
+ * `ForbiddenError` there no matter what scopes it holds. Because this server
667
+ * always authenticates as a human, that refusal never applies to it. `listCrews`
668
+ * is gated on the separate, agent-reachable `list` verb instead.
669
+ *
670
+ * `delete_crew` IS DELIBERATELY ABSENT, and stays absent — a decision by the
671
+ * repo's human owner, not a technical gap. Deleting a crew transfers its live
672
+ * `order_crews` stamps onto the org's orphan crew and deletes the crew's own
673
+ * membership rows outright; that is not an operation a model-driven host
674
+ * should be able to trigger. Do not add a `delete_crew` tool, an env-flag
675
+ * variant, or a confirmation-style variant — `owenloop crew rm` on the CLI
676
+ * remains the only way to delete a crew. Removing a single MEMBER (below) is a
677
+ * different, reversible operation and stays in scope.
678
+ */
679
+ function buildCrewTools(deps) {
680
+ return [
681
+ {
682
+ name: 'list_crews',
683
+ description: "The org's crews, each with its membership rows inline (principalKind/principalId/addedBy/addedAt) — " +
684
+ 'one call, no per-crew fan-out. An org with no crews at all is a normal empty result, not an error. ' +
685
+ "The org's reserved ORPHAN crew (kind: \"orphan\", or a name starting \"orphan:\") IS returned when it " +
686
+ 'exists and is deliberately NOT filtered out — it is where the hub re-homes work whose crew was ' +
687
+ 'deleted, so a caller has to be able to see where that work went. It is materialized LAZILY: a fresh ' +
688
+ "org has none. Its membership is derived (always the org's current admins) and cannot be edited — " +
689
+ 'add_crew_member/remove_crew_member both refuse it.',
690
+ inputSchema: { type: 'object', properties: {}, additionalProperties: false },
691
+ handler: passthrough(deps, () => ({ method: 'GET', path: '/api/crews' })),
692
+ },
693
+ {
694
+ name: 'create_crew',
695
+ description: "Create a crew on the hub org. `kind` is 'personal' or 'shared', forwarded verbatim — the hub is the " +
696
+ "enforcement of record for legal values ('orphan' is reserved for the hub's own crew and is refused). " +
697
+ "`ownerMemberId` is required for a 'personal' crew and is simply omitted from the request when not " +
698
+ 'passed. NOT admin-only: an org admin may create any crew, AND a non-admin may create a personal crew ' +
699
+ 'they own by passing kind:"personal" with ownerMemberId set to their own member id (the ' +
700
+ 'self-service branch of the mutation gate). A non-admin asking for a shared crew, for a personal crew ' +
701
+ 'owned by someone else, or for a personal crew with ownerMemberId OMITTED, is refused 403 — the hub ' +
702
+ 'deliberately does not infer the caller as the owner.',
703
+ inputSchema: {
704
+ type: 'object',
705
+ properties: {
706
+ name: { type: 'string' },
707
+ kind: { type: 'string' },
708
+ ownerMemberId: { type: 'string' },
709
+ },
710
+ required: ['name', 'kind'],
711
+ additionalProperties: false,
712
+ },
713
+ handler: passthrough(deps, (a) => ({ method: 'POST', path: '/api/create_crew', body: a })),
714
+ },
715
+ {
716
+ name: 'add_crew_member',
717
+ description: "Add one principal to a crew. `principalKind` is 'member' (a human) or 'agent' (a Scoped Identity), " +
718
+ 'forwarded verbatim; the hub validates it. NOT admin-only: an org admin may act on any crew, AND the ' +
719
+ 'OWNER of a personal crew may add members to that crew without being an admin. HTTP 400 (not a ' +
720
+ 'permissions error, and NOT tolerant): an unknown crewId, an unknown principalId, or a principal that ' +
721
+ 'is ALREADY a member — a duplicate add IS an error, unlike remove_crew_member below. REFUSED OUTRIGHT ' +
722
+ "against the org's orphan crew, for every caller including an admin, as a 400 (never a 403 — the " +
723
+ "refusal is identity-independent: it objects to the target crew, not the caller's role). The orphan " +
724
+ "crew's membership is the derived org admin roster and cannot be edited this way.",
725
+ inputSchema: {
726
+ type: 'object',
727
+ properties: {
728
+ crewId: { type: 'string' },
729
+ principalKind: { type: 'string' },
730
+ principalId: { type: 'string' },
731
+ },
732
+ required: ['crewId', 'principalKind', 'principalId'],
733
+ additionalProperties: false,
734
+ },
735
+ handler: passthrough(deps, (a) => ({ method: 'POST', path: '/api/add_crew_member', body: a })),
736
+ },
737
+ {
738
+ name: 'remove_crew_member',
739
+ description: 'Remove one principal from a crew. TOLERANT: removing a principal that was never a member is a normal ' +
740
+ 'success — HTTP 200 with removed:false, NOT a 404. Read the `removed` boolean rather than treating a ' +
741
+ 'false as a failure. An unknown crewId is DIFFERENT and is an HTTP 400 error. NOT admin-only: same ' +
742
+ 'self-service carve-out as add_crew_member — an org admin, or the owner of the personal crew being ' +
743
+ "acted on. REFUSED OUTRIGHT against the org's orphan crew, for every caller including an admin, as a " +
744
+ '400 — and that orphan refusal is NOT tolerant: it throws even when the principal was never a member, ' +
745
+ 'because the objection is to the target crew and is decided before the hub looks at the membership ' +
746
+ 'row. Removing a member is reversible. DELETING a crew is deliberately NOT available on this server at ' +
747
+ 'all — use the `owenloop crew rm` CLI command for that.',
748
+ inputSchema: {
749
+ type: 'object',
750
+ properties: {
751
+ crewId: { type: 'string' },
752
+ principalId: { type: 'string' },
753
+ },
754
+ required: ['crewId', 'principalId'],
755
+ additionalProperties: false,
756
+ },
757
+ handler: passthrough(deps, (a) => ({ method: 'POST', path: '/api/remove_crew_member', body: a })),
758
+ },
759
+ ];
760
+ }
499
761
  // ---- enrollment capability gate (Decision 7) --------------------------------
500
762
  /** The probe deadline; `OWENLOOP_MCP_PROBE_TIMEOUT_MS` overrides the 3000ms default. */
501
763
  function probeTimeoutMs(env) {
@@ -537,23 +799,21 @@ async function shouldRegisterEnrollment(deps) {
537
799
  /**
538
800
  * Run the `owenloop mcp` command: resolve the origin, decide the enrollment
539
801
  * gate, build the tool list, construct the JSON-RPC server, and pump stdin until
540
- * EOF. Returns the process exit code: 2 on an origin-ambiguity (message to
541
- * stderr, nothing to stdout — stdout is the protocol channel), else 0 on stdin
542
- * EOF. A malformed `--hub`/`OWENLOOP_HUB` throws a `CliError` (exit-1 path).
802
+ * EOF. Returns the process exit code: always 0 on stdin EOF — origin
803
+ * resolution has no exit-2 path of its own anymore (see `resolveMcpOrigin`;
804
+ * it always resolves to some origin, falling back as far as `DEFAULT_HUB`).
805
+ * A malformed `--hub`/`OWENLOOP_HUB` still throws a `CliError` (exit-1 path,
806
+ * via `mainAsync`'s catch).
543
807
  */
544
808
  export async function runMcpCommand(io, opts) {
545
- const resolved = resolveMcpOrigin(io, opts.hubFlag);
546
- if ('exitCode' in resolved) {
547
- io.err(resolved.message);
548
- return resolved.exitCode;
549
- }
550
- const deps = { io, origin: resolved.origin };
551
- const tools = [...buildBaselineTools(deps), createAgentTool(deps)];
809
+ const origin = resolveMcpOrigin(io, opts.hubFlag);
810
+ const deps = { io, origin };
811
+ const tools = [...buildBaselineTools(deps), createAgentTool(deps), ...buildCrewTools(deps)];
552
812
  if (await shouldRegisterEnrollment(deps))
553
813
  tools.push(stageEnrollmentTool(deps));
554
814
  const server = createMcpServer({
555
815
  name: 'owenloop-cli-mcp',
556
- version: '0.0.1',
816
+ version: packageVersion(),
557
817
  tools,
558
818
  write: (msg) => io.out(JSON.stringify(msg)),
559
819
  err: (line) => io.err(line),
@@ -2,15 +2,12 @@
2
2
  * A minimal, dependency-light MCP server core — newline-delimited JSON-RPC 2.0
3
3
  * over stdio, hand-rolled (O2 plan Decision 1).
4
4
  *
5
- * PROVENANCE: this is a near-verbatim copy of owenwork's proven
6
- * `src/mcp/server.ts` transport core (`createMcpServer` / `pumpStdin` /
7
- * `textResult` / the error-code consts / `LineStream`). Only this header was
8
- * changed. Consolidating the two copies into one shared package is DELIBERATELY
9
- * DEFERRED (per the O2 brief): owenloop and owenwork are separate packages with
10
- * no shared dependency today, and duplicating ~400 lines of a stable, test-pinned
11
- * transport is cheaper than standing up a shared module for it now. owenloop's
12
- * own `test/mcpcore.test.ts` re-proves the copied behavior against this file, so
13
- * drift is caught here rather than assumed.
5
+ * PROVENANCE: this transport core was ported from the execution subsystem's
6
+ * proven `src/mcp/server.ts` implementation (`createMcpServer` / `pumpStdin` /
7
+ * `textResult` / the error-code consts / `LineStream`). The implementation now
8
+ * lives in the root package so engine and execution commands ship together.
9
+ * `test/mcpcore.test.ts` re-proves the transport behavior against this file,
10
+ * so later changes are caught rather than assumed.
14
11
  *
15
12
  * WHY hand-rolled, not `@modelcontextprotocol/sdk`: this repo's posture is two
16
13
  * runtime deps (`@cfworker/json-schema` + `yaml`). The SDK drags zod and a