owenloop 0.4.1 → 0.5.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (282) hide show
  1. package/CHANGELOG.md +71 -0
  2. package/README.md +182 -53
  3. package/bin/owenloop.mjs +50 -2
  4. package/dist/packages/work/src/agent/brief.d.ts +176 -0
  5. package/dist/packages/work/src/agent/brief.js +197 -0
  6. package/dist/packages/work/src/agent/loop.d.ts +141 -0
  7. package/dist/packages/work/src/agent/loop.js +669 -0
  8. package/dist/packages/work/src/agent/model-policy.d.ts +49 -0
  9. package/dist/packages/work/src/agent/model-policy.js +138 -0
  10. package/dist/packages/work/src/agent/workdir.d.ts +210 -0
  11. package/dist/packages/work/src/agent/workdir.js +319 -0
  12. package/dist/packages/work/src/bundle/cache.d.ts +92 -0
  13. package/dist/packages/work/src/bundle/cache.js +338 -0
  14. package/dist/packages/work/src/bundle/fetch.d.ts +87 -0
  15. package/dist/packages/work/src/bundle/fetch.js +345 -0
  16. package/dist/packages/work/src/bundle/types.d.ts +164 -0
  17. package/dist/packages/work/src/bundle/types.js +1 -0
  18. package/dist/packages/work/src/consumed-verifier.d.ts +45 -0
  19. package/dist/packages/work/src/consumed-verifier.js +205 -0
  20. package/dist/packages/work/src/credentials/owenloop.d.ts +11 -0
  21. package/dist/packages/work/src/credentials/owenloop.js +28 -0
  22. package/dist/packages/work/src/credentials/reader.d.ts +36 -0
  23. package/dist/packages/work/src/credentials/reader.js +32 -0
  24. package/dist/packages/work/src/credentials/resolve.d.ts +19 -0
  25. package/dist/packages/work/src/credentials/resolve.js +56 -0
  26. package/dist/packages/work/src/exec/instructions.d.ts +99 -0
  27. package/dist/packages/work/src/exec/instructions.js +323 -0
  28. package/dist/packages/work/src/exec/loop.d.ts +40 -0
  29. package/dist/packages/work/src/exec/loop.js +332 -0
  30. package/dist/packages/work/src/exec/payload.d.ts +29 -0
  31. package/dist/packages/work/src/exec/payload.js +54 -0
  32. package/dist/packages/work/src/exec/receipt.d.ts +41 -0
  33. package/dist/packages/work/src/exec/receipt.js +32 -0
  34. package/dist/packages/work/src/exec/runner.d.ts +71 -0
  35. package/dist/packages/work/src/exec/runner.js +256 -0
  36. package/dist/packages/work/src/harness/child-env.d.ts +100 -0
  37. package/dist/packages/work/src/harness/child-env.js +134 -0
  38. package/dist/packages/work/src/harness/claude.d.ts +140 -0
  39. package/dist/packages/work/src/harness/claude.js +837 -0
  40. package/dist/packages/work/src/harness/codex.d.ts +111 -0
  41. package/dist/packages/work/src/harness/codex.js +1024 -0
  42. package/dist/packages/work/src/harness/contract.d.ts +308 -0
  43. package/dist/packages/work/src/harness/contract.js +32 -0
  44. package/dist/packages/work/src/harness/fake.d.ts +59 -0
  45. package/dist/packages/work/src/harness/fake.js +91 -0
  46. package/dist/packages/work/src/harness/jsonrpc-stdio.d.ts +108 -0
  47. package/dist/packages/work/src/harness/jsonrpc-stdio.js +351 -0
  48. package/dist/packages/work/src/harness/permissions.d.ts +75 -0
  49. package/dist/packages/work/src/harness/permissions.js +182 -0
  50. package/dist/packages/work/src/harness/registry.d.ts +47 -0
  51. package/dist/packages/work/src/harness/registry.js +45 -0
  52. package/dist/packages/work/src/harness/session-store.d.ts +181 -0
  53. package/dist/packages/work/src/harness/session-store.js +523 -0
  54. package/dist/packages/work/src/harness/types.d.ts +29 -0
  55. package/dist/packages/work/src/harness/types.js +14 -0
  56. package/dist/packages/work/src/harnesses.d.ts +38 -0
  57. package/dist/packages/work/src/harnesses.js +38 -0
  58. package/dist/packages/work/src/hold/loop.d.ts +36 -0
  59. package/dist/packages/work/src/hold/loop.js +23 -0
  60. package/dist/packages/work/src/hold/mcp.d.ts +75 -0
  61. package/dist/packages/work/src/hold/mcp.js +264 -0
  62. package/dist/packages/work/src/hub/client.d.ts +23 -0
  63. package/dist/packages/work/src/hub/client.js +91 -0
  64. package/dist/packages/work/src/hub/types.d.ts +326 -0
  65. package/dist/packages/work/src/hub/types.js +26 -0
  66. package/dist/packages/work/src/lease/loop.d.ts +94 -0
  67. package/dist/packages/work/src/lease/loop.js +277 -0
  68. package/dist/packages/work/src/main.d.ts +1 -0
  69. package/dist/packages/work/src/main.js +48 -0
  70. package/dist/packages/work/src/mcp/server.d.ts +125 -0
  71. package/dist/packages/work/src/mcp/server.js +320 -0
  72. package/dist/packages/work/src/owenloop-bin.d.ts +1 -0
  73. package/dist/packages/work/src/owenloop-bin.js +18 -0
  74. package/dist/packages/work/src/roles/agent-run.d.ts +124 -0
  75. package/dist/packages/work/src/roles/agent-run.js +529 -0
  76. package/dist/packages/work/src/roles/exec.d.ts +48 -0
  77. package/dist/packages/work/src/roles/exec.js +228 -0
  78. package/dist/packages/work/src/roles/hold.d.ts +72 -0
  79. package/dist/packages/work/src/roles/hold.js +363 -0
  80. package/dist/packages/work/src/roles/join.d.ts +18 -0
  81. package/dist/packages/work/src/roles/join.js +204 -0
  82. package/dist/packages/work/src/roles/lint.d.ts +58 -0
  83. package/dist/packages/work/src/roles/lint.js +234 -0
  84. package/dist/packages/work/src/roles/prepare.d.ts +1 -0
  85. package/dist/packages/work/src/roles/prepare.js +249 -0
  86. package/dist/packages/work/src/roles/release.d.ts +48 -0
  87. package/dist/packages/work/src/roles/release.js +137 -0
  88. package/dist/packages/work/src/roles/sessions.d.ts +61 -0
  89. package/dist/packages/work/src/roles/sessions.js +180 -0
  90. package/dist/packages/work/src/roles/settings.d.ts +6 -0
  91. package/dist/packages/work/src/roles/settings.js +71 -0
  92. package/dist/packages/work/src/roles/shift.d.ts +13 -0
  93. package/dist/packages/work/src/roles/shift.js +250 -0
  94. package/dist/packages/work/src/roles/signals.d.ts +55 -0
  95. package/dist/packages/work/src/roles/signals.js +62 -0
  96. package/dist/packages/work/src/settings/provision.d.ts +21 -0
  97. package/dist/packages/work/src/settings/provision.js +47 -0
  98. package/dist/packages/work/src/settings/settings.d.ts +136 -0
  99. package/dist/packages/work/src/settings/settings.js +155 -0
  100. package/dist/packages/work/src/shift/client.d.ts +24 -0
  101. package/dist/packages/work/src/shift/client.js +124 -0
  102. package/dist/packages/work/src/shift/loop.d.ts +131 -0
  103. package/dist/packages/work/src/shift/loop.js +751 -0
  104. package/dist/packages/work/src/shift/protocol.d.ts +95 -0
  105. package/dist/packages/work/src/shift/protocol.js +24 -0
  106. package/dist/packages/work/src/shift/routing.d.ts +35 -0
  107. package/dist/packages/work/src/shift/routing.js +50 -0
  108. package/dist/packages/work/src/shift/runtime.d.ts +45 -0
  109. package/dist/packages/work/src/shift/runtime.js +337 -0
  110. package/dist/packages/work/src/shift/server.d.ts +23 -0
  111. package/dist/packages/work/src/shift/server.js +716 -0
  112. package/dist/packages/work/src/shift/spawn.d.ts +109 -0
  113. package/dist/packages/work/src/shift/spawn.js +158 -0
  114. package/dist/packages/work/src/shift/state.d.ts +79 -0
  115. package/dist/packages/work/src/shift/state.js +385 -0
  116. package/dist/packages/work/src/submit-proof.d.ts +36 -0
  117. package/dist/packages/work/src/submit-proof.js +93 -0
  118. package/dist/packages/work/src/usage.d.ts +6 -0
  119. package/dist/packages/work/src/usage.js +175 -0
  120. package/dist/src/add.d.ts +189 -0
  121. package/dist/src/add.js +300 -0
  122. package/dist/src/archive.d.ts +97 -0
  123. package/dist/src/archive.js +591 -0
  124. package/dist/src/bundle/index.d.ts +64 -0
  125. package/dist/src/bundle/index.js +508 -0
  126. package/dist/src/bundle/manifest.d.ts +50 -0
  127. package/dist/src/bundle/manifest.js +435 -0
  128. package/dist/src/bundle/runtime.d.ts +26 -0
  129. package/dist/src/bundle/runtime.js +64 -0
  130. package/dist/src/bundle/tar.d.ts +62 -0
  131. package/dist/src/bundle/tar.js +238 -0
  132. package/dist/src/bundle/types.d.ts +105 -0
  133. package/dist/src/bundle/types.js +21 -0
  134. package/dist/{cli.d.ts → src/cli.d.ts} +92 -7
  135. package/dist/src/cli.js +5968 -0
  136. package/dist/{credentials.d.ts → src/credentials.d.ts} +22 -15
  137. package/dist/{credentials.js → src/credentials.js} +35 -31
  138. package/dist/src/crypto/allowed-signers.d.ts +68 -0
  139. package/dist/src/crypto/allowed-signers.js +307 -0
  140. package/dist/src/crypto/canonical.d.ts +8 -0
  141. package/dist/src/crypto/canonical.js +92 -0
  142. package/dist/src/crypto/chain.d.ts +65 -0
  143. package/dist/src/crypto/chain.js +377 -0
  144. package/dist/src/crypto/dsse.d.ts +209 -0
  145. package/dist/src/crypto/dsse.js +282 -0
  146. package/dist/src/crypto/enrollment.d.ts +78 -0
  147. package/dist/src/crypto/enrollment.js +186 -0
  148. package/dist/src/crypto/index.d.ts +48 -0
  149. package/dist/src/crypto/index.js +44 -0
  150. package/dist/src/crypto/keys.d.ts +258 -0
  151. package/dist/src/crypto/keys.js +908 -0
  152. package/dist/src/crypto/org-root.d.ts +33 -0
  153. package/dist/src/crypto/org-root.js +78 -0
  154. package/dist/src/crypto/origin-rules.d.ts +56 -0
  155. package/dist/src/crypto/origin-rules.js +143 -0
  156. package/dist/src/crypto/policy-floor.d.ts +98 -0
  157. package/dist/src/crypto/policy-floor.js +353 -0
  158. package/dist/src/crypto/records.d.ts +316 -0
  159. package/dist/src/crypto/records.js +157 -0
  160. package/dist/src/crypto/scope.d.ts +49 -0
  161. package/dist/src/crypto/scope.js +83 -0
  162. package/dist/src/crypto/ssh.d.ts +171 -0
  163. package/dist/src/crypto/ssh.js +396 -0
  164. package/dist/src/crypto/submission.d.ts +33 -0
  165. package/dist/src/crypto/submission.js +47 -0
  166. package/dist/src/crypto/trust-roots.d.ts +29 -0
  167. package/dist/src/crypto/trust-roots.js +39 -0
  168. package/dist/src/crypto/verify-consumed.d.ts +67 -0
  169. package/dist/src/crypto/verify-consumed.js +259 -0
  170. package/dist/src/crypto/verify-origin.d.ts +50 -0
  171. package/dist/src/crypto/verify-origin.js +151 -0
  172. package/dist/src/crypto/verify-publication.d.ts +60 -0
  173. package/dist/src/crypto/verify-publication.js +150 -0
  174. package/dist/{defs.d.ts → src/defs.d.ts} +24 -1
  175. package/dist/{defs.js → src/defs.js} +181 -61
  176. package/dist/{engine.d.ts → src/engine.d.ts} +105 -9
  177. package/dist/{engine.js → src/engine.js} +251 -47
  178. package/dist/{factory.d.ts → src/factory.d.ts} +16 -0
  179. package/dist/{factory.js → src/factory.js} +16 -4
  180. package/dist/src/global-config.d.ts +59 -0
  181. package/dist/src/global-config.js +84 -0
  182. package/dist/{hub.d.ts → src/hub.d.ts} +280 -31
  183. package/dist/{hub.js → src/hub.js} +493 -52
  184. package/dist/src/index.d.ts +47 -0
  185. package/dist/src/index.js +41 -0
  186. package/dist/src/install.d.ts +538 -0
  187. package/dist/src/install.js +1981 -0
  188. package/dist/src/lock.d.ts +38 -0
  189. package/dist/src/lock.js +325 -0
  190. package/dist/src/mcp/serve.d.ts +109 -0
  191. package/dist/{mcp → src/mcp}/serve.js +335 -75
  192. package/dist/{mcp → src/mcp}/server.d.ts +6 -9
  193. package/dist/{mcp → src/mcp}/server.js +18 -10
  194. package/dist/{model.d.ts → src/model.d.ts} +15 -0
  195. package/dist/{model.js → src/model.js} +112 -2
  196. package/dist/src/order-resolver.d.ts +184 -0
  197. package/dist/src/order-resolver.js +252 -0
  198. package/dist/src/package-version.d.ts +10 -0
  199. package/dist/src/package-version.js +42 -0
  200. package/dist/{paths.d.ts → src/paths.d.ts} +14 -1
  201. package/dist/{paths.js → src/paths.js} +18 -0
  202. package/dist/src/schemas/enrollment-grant.v1.schema.json +90 -0
  203. package/dist/src/schemas/index.d.ts +1416 -0
  204. package/dist/src/schemas/index.js +31 -0
  205. package/dist/src/schemas/order.v1.schema.json +106 -0
  206. package/dist/src/schemas/origin.v1.schema.json +68 -0
  207. package/dist/src/schemas/policy-floor.v1.schema.json +29 -0
  208. package/dist/src/schemas/publication.v1.schema.json +31 -0
  209. package/dist/src/schemas/revocation.v1.schema.json +39 -0
  210. package/dist/src/schemas/submission.v1.schema.json +61 -0
  211. package/dist/src/store/def-source.d.ts +52 -0
  212. package/dist/src/store/def-source.js +335 -0
  213. package/dist/src/store/index-file.d.ts +69 -0
  214. package/dist/src/store/index-file.js +151 -0
  215. package/dist/src/store/index.d.ts +27 -0
  216. package/dist/src/store/index.js +22 -0
  217. package/dist/src/store/ingestor.d.ts +43 -0
  218. package/dist/src/store/ingestor.js +211 -0
  219. package/dist/src/store/install.d.ts +228 -0
  220. package/dist/src/store/install.js +555 -0
  221. package/dist/src/store/instruction-source.d.ts +49 -0
  222. package/dist/src/store/instruction-source.js +298 -0
  223. package/dist/src/store/origin-evidence.d.ts +21 -0
  224. package/dist/src/store/origin-evidence.js +66 -0
  225. package/dist/src/store/pre-commit-verifier.d.ts +68 -0
  226. package/dist/src/store/pre-commit-verifier.js +418 -0
  227. package/dist/src/store/resolve.d.ts +138 -0
  228. package/dist/src/store/resolve.js +363 -0
  229. package/dist/src/store/types.d.ts +288 -0
  230. package/dist/src/store/types.js +356 -0
  231. package/dist/{types.d.ts → src/types.d.ts} +58 -24
  232. package/dist/{untar.d.ts → src/untar.d.ts} +8 -23
  233. package/dist/src/untar.js +38 -0
  234. package/dist/{util.d.ts → src/util.d.ts} +3 -2
  235. package/dist/{util.js → src/util.js} +3 -2
  236. package/dist/{owenwork.d.ts → src/work-settings.d.ts} +22 -22
  237. package/dist/{owenwork.js → src/work-settings.js} +27 -27
  238. package/docs/agent-runner.md +86 -0
  239. package/docs/authoring.md +150 -59
  240. package/docs/bundles.md +250 -0
  241. package/docs/cli.md +1758 -163
  242. package/docs/crypto.md +816 -0
  243. package/docs/design.md +374 -52
  244. package/docs/embedding.md +135 -27
  245. package/docs/wire-contracts.md +380 -0
  246. package/examples/workflows/{command-worker.yaml → command-executor.yaml} +15 -15
  247. package/examples/workflows/compile-dev-playbook.yaml +338 -0
  248. package/examples/workflows/judges/gate-sharpness.md +39 -0
  249. package/examples/workflows/judges/security.md +34 -0
  250. package/package.json +22 -8
  251. package/plugins/claude-code/.claude-plugin/marketplace.json +14 -0
  252. package/plugins/claude-code/plugin/.claude-plugin/plugin.json +8 -0
  253. package/plugins/claude-code/plugin/.mcp.json +14 -0
  254. package/plugins/claude-code/plugin/hooks/hooks.json +26 -0
  255. package/plugins/claude-code/plugin/hooks/session-end.sh +40 -0
  256. package/plugins/claude-code/plugin/hooks/session-start.sh +52 -0
  257. package/plugins/claude-code/plugin/skills/author/SKILL.md +181 -0
  258. package/plugins/claude-code/plugin/skills/conduct/SKILL.md +106 -0
  259. package/plugins/claude-code/plugin/skills/shift/SKILL.md +105 -0
  260. package/plugins/codex/.agents/plugins/marketplace.json +21 -0
  261. package/plugins/codex/plugins/owenloop/.codex-plugin/plugin.json +7 -0
  262. package/plugins/codex/plugins/owenloop/.mcp.json +20 -0
  263. package/plugins/codex/plugins/owenloop/hooks/hooks.json +26 -0
  264. package/plugins/codex/plugins/owenloop/hooks/session-end.sh +40 -0
  265. package/plugins/codex/plugins/owenloop/hooks/session-start.sh +52 -0
  266. package/plugins/codex/plugins/owenloop/skills/author/SKILL.md +181 -0
  267. package/plugins/codex/plugins/owenloop/skills/conduct/SKILL.md +106 -0
  268. package/plugins/codex/plugins/owenloop/skills/shift/SKILL.md +105 -0
  269. package/dist/add.d.ts +0 -384
  270. package/dist/add.js +0 -834
  271. package/dist/cli.js +0 -3270
  272. package/dist/index.d.ts +0 -32
  273. package/dist/index.js +0 -23
  274. package/dist/lock.d.ts +0 -80
  275. package/dist/lock.js +0 -217
  276. package/dist/mcp/serve.d.ts +0 -84
  277. package/dist/untar.js +0 -164
  278. /package/dist/{schema.d.ts → src/schema.d.ts} +0 -0
  279. /package/dist/{schema.js → src/schema.js} +0 -0
  280. /package/dist/{store.d.ts → src/store.d.ts} +0 -0
  281. /package/dist/{store.js → src/store.js} +0 -0
  282. /package/dist/{types.js → src/types.js} +0 -0
@@ -0,0 +1,84 @@
1
+ /**
2
+ * `~/.owenloop/config.json` — the CONTROL plane's non-secret configuration file.
3
+ *
4
+ * Sole writer: `owenloop login` (`dispatchLogin` in `src/cli.ts`), which records
5
+ * the hub origin it just authenticated against here, best-effort, after the
6
+ * credential itself has already been stored. Sole reader: `owenloop mcp`'s
7
+ * origin ladder (`resolveMcpOrigin` in `src/mcp/serve.ts`), which needs to know
8
+ * which hub the operator is using WITHOUT enumerating the credential store —
9
+ * the store's `keychain` and `external` backends cannot be listed at all (see
10
+ * `listStoredHubOrigins` in `src/hub.ts`), so a value that lived only inside
11
+ * the credential vault would be unreadable to the server on the majority of
12
+ * real installs (macOS defaults to the keychain backend).
13
+ *
14
+ * This is deliberately a SEPARATE file from `src/work-settings.ts`'s
15
+ * `~/.config/owenloop/settings.json` (or `$XDG_CONFIG_HOME/owenloop/settings.json`
16
+ * when set). That file belongs to the EXECUTION plane: `owenloop setup` is its
17
+ * sole writer, and `owenloop work` role resolution and pre-commit verification
18
+ * are its readers. This file belongs to the CONTROL plane: `owenloop login`
19
+ * writes it, `owenloop mcp` reads it. Nothing reconciles the two if they
20
+ * disagree — e.g. after `owenloop login --hub A` followed by
21
+ * `owenloop setup --hub B` — and that is an accepted cost, not an oversight:
22
+ * the two files answer different questions ("what hub does an agent shift run
23
+ * against" vs. "what hub does the human's MCP session talk to") for two
24
+ * independently-evolving call paths, and forcing one file to answer both would
25
+ * couple them for no benefit. This file is also HOME-rooted, not XDG-aware,
26
+ * unlike `settings.json`: `owenloop mcp` is a human-facing control-plane
27
+ * process, and there is no separate "XDG vs. HOME" precedence to resolve here
28
+ * — the caller supplies `home` directly (see `globalConfigPath`), mirroring
29
+ * how `src/cli.ts`'s `workflowHome` resolves the same value.
30
+ *
31
+ * Never holds a secret: `hub` is an origin URL, nothing else. A read failure
32
+ * of any kind (file absent, invalid JSON, wrong shape, blank `hub`, or a
33
+ * `hub` value that does not normalize to a valid http(s) origin) is reported
34
+ * as `null`, never thrown — this file is one rung of a fallback ladder
35
+ * (`resolveMcpOrigin`), and a corrupt or half-written config must not be able
36
+ * to crash `owenloop mcp` at startup; the ladder simply falls through to the
37
+ * next rung instead.
38
+ */
39
+ import { existsSync, readFileSync } from 'node:fs';
40
+ import { dirname, join } from 'node:path';
41
+ import { mkdirRefusingSymlink } from "./util.js";
42
+ import { normalizeOrigin, writeFileAtomic } from "./hub.js";
43
+ /** `<home>/.owenloop/config.json` — `home` is the caller-resolved `HOME`/`USERPROFILE` value. */
44
+ export function globalConfigPath(home) {
45
+ return join(home, '.owenloop', 'config.json');
46
+ }
47
+ /**
48
+ * Read and validate `path`. Returns `null` — never throws — when the file is
49
+ * absent, is not valid JSON, is not a JSON object, its `hub` field is
50
+ * missing, non-string, or blank, or `hub` does not normalize to a valid
51
+ * http(s) origin (`normalizeOrigin`, `src/hub.ts` — e.g. `"not a url"` or a
52
+ * bare hostname with no scheme). Callers treat `null` as "this rung has
53
+ * nothing to offer" and fall through to the next one. The `hub` on a non-null
54
+ * return is always normalized (scheme required, trailing slash/path
55
+ * stripped) — the same guarantee every other rung of `resolveMcpOrigin`
56
+ * provides, so callers never need to re-normalize what this returns.
57
+ */
58
+ export function readGlobalConfig(path) {
59
+ if (!existsSync(path))
60
+ return null;
61
+ let parsed;
62
+ try {
63
+ parsed = JSON.parse(readFileSync(path, 'utf8'));
64
+ }
65
+ catch {
66
+ return null;
67
+ }
68
+ if (parsed === null || typeof parsed !== 'object')
69
+ return null;
70
+ const hub = parsed.hub;
71
+ if (typeof hub !== 'string' || hub.trim() === '')
72
+ return null;
73
+ try {
74
+ return { version: 1, hub: normalizeOrigin(hub) };
75
+ }
76
+ catch {
77
+ return null;
78
+ }
79
+ }
80
+ /** Write `config` to `path`, creating its parent directory if needed. Atomic (see `writeFileAtomic`). */
81
+ export function writeGlobalConfig(path, config) {
82
+ mkdirRefusingSymlink(dirname(path));
83
+ writeFileAtomic(path, `${JSON.stringify(config, null, 2)}\n`);
84
+ }
@@ -87,6 +87,16 @@
87
87
  * still recognizes byte-identical content and replies `unchanged: true`.
88
88
  */
89
89
  export declare function hashDefForHub(yaml: string): string;
90
+ /**
91
+ * The production hub. The sole fallback rung for every hub-resolution ladder
92
+ * in this package that has one (`src/cli.ts`'s `resolveHub` and
93
+ * `resolveSetupHub`, `src/mcp/serve.ts`'s `resolveMcpOrigin`) — there must be
94
+ * exactly one literal `'https://api.owenloop.com'` in `src/`, and this is it.
95
+ * `resolveAgentHub` (`src/cli.ts`) deliberately has NO fallback to this
96
+ * constant: it mints credentials, and silently minting on the wrong org is
97
+ * not undone by a retry.
98
+ */
99
+ export declare const DEFAULT_HUB = "https://api.owenloop.com";
90
100
  /**
91
101
  * Normalize a hub URL to a bare origin (`scheme://host[:port]`), stripping any
92
102
  * path, query, trailing slash, and fragment. Requires an http(s) scheme. This
@@ -163,7 +173,7 @@ export type Credential = {
163
173
  * distinct entries that never collide, and neither does `agent:ci` with
164
174
  * `agent:release`.
165
175
  *
166
- * The discriminator is an **account**, never a "label" — labels are a different
176
+ * The discriminator is an **account**, never a "capability" — capabilities are a different
167
177
  * axis of the system and the word is reserved.
168
178
  */
169
179
  export type CredentialSlotSelector = {
@@ -276,12 +286,32 @@ export interface Keychain {
276
286
  set(service: string, account: string, value: string): void;
277
287
  delete(service: string, account: string): void;
278
288
  }
289
+ /** Minimal command seam for the macOS `security` adapter. */
290
+ export interface MacosSecurityCommand {
291
+ args: string[];
292
+ /** Secret-bearing command input. Never include this value in an error. */
293
+ input?: string;
294
+ captureStdout?: boolean;
295
+ }
296
+ export type MacosSecurityRunner = (command: MacosSecurityCommand) => string;
279
297
  /**
280
- * The default macOS keychain backend (generic passwords under service
281
- * `owenloop:<origin>`, account = the credential slot). The secret is fed through
282
- * the `security -i` command stream on stdin, never as a `-w` argv value, so it
283
- * never appears in `ps`/shell history. Returns `undefined` off macOS or when
284
- * `OWENLOOP_NO_KEYCHAIN=1`, so callers fall back to the 0600 credential file.
298
+ * Build the macOS generic-password backend around an injectable `security`
299
+ * command runner. Status 44 (`errSecItemNotFound`) alone means absence. Every
300
+ * other exit, signal, or start failure is a stable, secret-free error.
301
+ */
302
+ export declare function macosKeychain(runner?: MacosSecurityRunner): Keychain;
303
+ /**
304
+ * Every locally available Keychain backend, independent of the ordinary-store
305
+ * override. Defensive logout uses this resolver so `OWENLOOP_NO_KEYCHAIN=1`
306
+ * cannot hide a credential that would become authoritative again when the
307
+ * override is removed. An injected backend remains available on every platform;
308
+ * otherwise only macOS has a platform backend.
309
+ */
310
+ export declare function resolveLocalKeychain(injected?: Keychain): Keychain | undefined;
311
+ /**
312
+ * The default Keychain selected for ordinary reads and writes. Returns
313
+ * `undefined` off macOS or when `OWENLOOP_NO_KEYCHAIN=1` selects the 0600 file
314
+ * store. Logout deliberately uses `resolveLocalKeychain` instead.
285
315
  */
286
316
  export declare function defaultKeychain(env: Record<string, string | undefined>): Keychain | undefined;
287
317
  /**
@@ -348,7 +378,7 @@ export type ReadStoredCredentialOpts = CredentialSlotSelector & {
348
378
  /**
349
379
  * Read the stored hub credential for `origin` **in the named slot** from the
350
380
  * chosen backend ONLY — the supported, read-only programmatic surface
351
- * (owenwork's CredentialReader seam wires to this once released). Secret hygiene
381
+ * (owenloop's CredentialReader seam wires to this once released). Secret hygiene
352
382
  * is unchanged: this function never logs or echoes the returned credential, and
353
383
  * there is deliberately no write/delete companion on the public surface —
354
384
  * `login` / `logout` remain the only way to store or remove a credential.
@@ -380,24 +410,48 @@ export type ReadStoredCredentialOpts = CredentialSlotSelector & {
380
410
  * never `process.env` directly, so a caller passing `opts.env` stays hermetic;
381
411
  * only the top-level default falls back to `process.env`.
382
412
  *
383
- * **When `OWENLOOP_CREDENTIAL_COMMAND` is configured this function can THROW
384
- * instead of returning `null`**, and it does not consult a store at all. The
385
- * command is authoritative, so a nonzero exit, a timeout, empty output, or
386
- * output that is not a well-formed credential is a loud error naming the origin
387
- * and the slot — never a silent fallthrough to a stale local entry. See
388
- * `runCredentialCommand`. When it is NOT configured, behaviour is exactly what
389
- * it has always been.
413
+ * **An authoritative backend failure throws instead of returning `null`.** For
414
+ * `OWENLOOP_CREDENTIAL_COMMAND`, a nonzero exit, timeout, empty output, or
415
+ * malformed credential is a loud error naming the origin and slot. For the
416
+ * macOS Keychain, every `security` failure except status 44 is a stable,
417
+ * secret-free error. Neither backend falls through to a stale file entry.
390
418
  */
391
419
  export declare function readStoredCredential(origin: string, opts: ReadStoredCredentialOpts): Credential | null;
392
420
  /**
393
421
  * Enumerate the hub origins that have a usable `human` credential stored, or
394
422
  * `null` when the active backend cannot be enumerated.
395
423
  *
396
- * Consumer: `owenloop mcp`'s origin inference (`resolveMcpOrigin` in
397
- * `src/mcp/serve.ts`). When the host spawns the server with neither `--hub` nor
398
- * `OWENLOOP_HUB`, the server tries to infer the single hub the user is logged
399
- * in to. That inference is only sound on the FILE backend, which can list its
400
- * `hubs` map; the keychain and external-command backends cannot enumerate:
424
+ * Callers in `src/cli.ts` share a backend-aware discovery layer, while
425
+ * `src/mcp/serve.ts` consumes this fact directly. Their policies deliberately
426
+ * differ, turning the same three possible results (`null`, `[]`, length>1)
427
+ * into different outcomes:
428
+ *
429
+ * - `resolveAgentHub` (`agent new`, `capability bind|unbind|list`, and
430
+ * `crew`'s subcommands) — mutating, mint-like commands. Every non-single
431
+ * result (`null`, `[]`, or length>1) is an immediate `CliError` (exit 2)
432
+ * naming `--hub <origin>` as the fix. There is no `DEFAULT_HUB` fallback
433
+ * here at all: silently minting against the production hub while the
434
+ * operator is logged into a dev hub would mint on the wrong org, and a mint
435
+ * is not undone by a retry.
436
+ * - `resolveSetupHub` (`setup`, `doctor`) — `null` or `[]` fall back to
437
+ * `DEFAULT_HUB` with a printed notice so the operator can see what
438
+ * happened; length>1 is still a `CliError` (exit 2) naming the origins,
439
+ * because guessing among several logged-in hubs would be silently wrong for
440
+ * someone who has more than one.
441
+ * - `resolvePublishingHub` (`connect`, `push`, `publish`) — one file-backed
442
+ * origin is the global fallback; more than one or none is an exit-2 error.
443
+ * For `null`, and only for `null`, this policy may use the validated
444
+ * execution-settings `hubOrigin` after checking the requested credential
445
+ * slot. It never guesses `DEFAULT_HUB`.
446
+ * - `resolveMcpOrigin` (`owenloop mcp`'s origin ladder) — the most lenient:
447
+ * this is rung 4 of 5, tried only after `--hub`, `OWENLOOP_HUB`, and
448
+ * `~/.owenloop/config.json` have all had nothing to offer. `null`, `[]`,
449
+ * and length>1 are ALL just "this rung has nothing to offer either" and
450
+ * fall through silently to rung 5 (`DEFAULT_HUB`) — there is no error path
451
+ * left to reach from here.
452
+ *
453
+ * The backend determines whether enumeration is even possible in the first
454
+ * place, independent of which of the three callers is asking:
401
455
  *
402
456
  * - **file** → the origins in `readCredentialFile(credentialFilePath(env)).hubs`
403
457
  * whose `human` slot parses as a well-formed `Credential` (`parseCredential`).
@@ -412,10 +466,10 @@ export declare function readStoredCredential(origin: string, opts: ReadStoredCre
412
466
  * - **external** → `null`, for the same reason: the command answers a single
413
467
  * `(origin, slot)` query; it has no listing contract.
414
468
  *
415
- * `null` (cannot enumerate), `[]` (nothing stored), and a length>1 result are
416
- * all distinct signals the caller turns into tailored exit-2 messages — this
417
- * function reports the fact, it never decides the outcome. It never logs or
418
- * echoes any credential; only the origin KEYS (never secrets) are returned.
469
+ * This function only reports the fact (and the backend-level reason behind
470
+ * it); it never decides the outcome — that is each caller's job, per the list
471
+ * above. It never logs or echoes any credential; only the origin KEYS (never
472
+ * secrets) are returned.
419
473
  *
420
474
  * `env`/`keychain` are threaded exactly as `readStoredCredential` threads them,
421
475
  * so a caller passing a fixture `env` stays hermetic.
@@ -557,8 +611,8 @@ export interface MintAgentTokenOk {
557
611
  token: string;
558
612
  /** The minted agent's id — a non-secret handle, safe to print. */
559
613
  agentId: string;
560
- /** Resolved pool NAMES the token was granted on — non-secret. */
561
- pools: string[];
614
+ /** Resolved crew NAMES the token was granted on — non-secret. */
615
+ crews: string[];
562
616
  }
563
617
  /**
564
618
  * Narrow a `POST /api/mint_agent_token` 200 body to its typed success shape,
@@ -571,15 +625,15 @@ export interface MintAgentTokenOk {
571
625
  * FIELD only — it never echoes a field VALUE. A malformed body could still carry
572
626
  * the `olp_` plaintext (in `text`, or in a mistyped `token`), so echoing values
573
627
  * here would be the exact leak §6 forbids. `id`/`agentId` must be non-empty
574
- * strings; `token` a non-empty string starting `olp_`; `pools` an array of
628
+ * strings; `token` a non-empty string starting `olp_`; `crews` an array of
575
629
  * strings (empty allowed defensively — the server always resolves at least one,
576
630
  * but the client does not depend on that to stay leak-safe).
577
631
  */
578
632
  export declare function asMintAgentTokenOk(body: unknown): MintAgentTokenOk;
579
633
  /**
580
- * One agent identity as `GET /api/agent_identities` reports it — the fields the
634
+ * One Scoped Identity as `GET /api/agent_identities` reports it — the fields the
581
635
  * setup converger and the doctor probe consult. The row is non-secret: it names
582
- * agents and their pools, never a token.
636
+ * agents and their crews, never a token.
583
637
  *
584
638
  * `lastContactAt` is identity-level (overwritten on EVERY authenticated contact,
585
639
  * `olp_` or `mcpat_`). `lastUsedAt` is the edge-computed max over the identity's
@@ -592,7 +646,7 @@ export interface AgentIdentitySummary {
592
646
  id: string;
593
647
  name: string;
594
648
  disabled: boolean;
595
- pools: string[];
649
+ crews: string[];
596
650
  lastContactAt: number | null;
597
651
  lastUsedAt: number | null;
598
652
  }
@@ -601,18 +655,213 @@ export interface AgentIdentitySummary {
601
655
  * typed array. Throws on a malformed body (missing `identities` array, or a row
602
656
  * missing `id`/`name`). Non-secret shape — the rows carry no token — so errors
603
657
  * may name indices/fields freely. `lastContactAt`/`lastUsedAt` tolerate `null`
604
- * or absence (→ `null`) but reject a present non-number; `pools` defaults to an
658
+ * or absence (→ `null`) but reject a present non-number; `crews` defaults to an
605
659
  * empty array when absent, rejects a present non-array-of-strings; `disabled`
606
660
  * defaults to `false`.
607
661
  */
608
662
  export declare function asAgentIdentities(body: unknown): AgentIdentitySummary[];
663
+ /**
664
+ * One **capability route** as the hub reports it — an org-scoped row mapping a
665
+ * workflow-def `capabilities:` entry to a crew. Unrelated to `HubBinding` above, which
666
+ * is this project directory's route to a hub (`owenloop connect`); every
667
+ * symbol in this family is `CapabilityRoute`-prefixed to keep the two apart.
668
+ *
669
+ * One row is ONE `(capability, crew)` PAIR, and a capability may bind MANY crews — so a
670
+ * single capability appears as MANY rows and nothing may key a collection on `capability`.
671
+ *
672
+ * `crewName` is `string | null`. A `null` name IS the **dangling route** case:
673
+ * the bound crew row was deleted, so the hub has no name left to resolve
674
+ * (`manage-capability-routes.ts`'s `toWire`). A dangling route routes nothing and
675
+ * never widens access, and it is deliberately SURFACED rather than filtered out —
676
+ * seeing the row is exactly what tells an operator there is something to clean up.
677
+ *
678
+ * Non-secret: the row names a capability, a crew, and who created it — never a token.
679
+ */
680
+ export interface CapabilityRouteWire {
681
+ capability: string;
682
+ crewId: string;
683
+ crewName: string | null;
684
+ createdBy: string;
685
+ createdAt: number;
686
+ }
687
+ /**
688
+ * `POST /api/add_capability_route`'s 200 body, narrowed.
689
+ *
690
+ * NESTED exactly as the wire nests it: the row lives under `route`, while
691
+ * `alreadyRouted` and `routedCrewCount` live at the BODY's top level. A flat
692
+ * interface would blur where each field actually sits.
693
+ *
694
+ * - `alreadyRouted` — was this exact `(capability, crew)` pair already present? The add
695
+ * is ADDITIVE and idempotent per pair, so a repeat is a 200 no-op, not an
696
+ * error, and `route.createdBy`/`createdAt` then echo the ORIGINAL row.
697
+ * - `routedCrewCount` — how many **LIVE** crews the capability binds AFTER the write. A
698
+ * route whose crew row was deleted routes nothing and is not counted.
699
+ */
700
+ export interface CapabilityRouteAddedWire {
701
+ route: CapabilityRouteWire;
702
+ alreadyRouted: boolean;
703
+ routedCrewCount: number;
704
+ }
705
+ /**
706
+ * Narrow `POST /api/add_capability_route`'s 200 body
707
+ * (`{ text, route, alreadyRouted, routedCrewCount }`). Throws on anything
708
+ * malformed, naming the offending FIELD only — same discipline as
709
+ * `asAgentIdentities`, so no body value is echoed.
710
+ *
711
+ * `route.crewName` is required to be a NON-NULL non-empty string here, on top
712
+ * of `asCapabilityRouteRow`'s lenient check. That is not a contradiction: an add
713
+ * resolves its crew BY NAME, so the crew is live by construction and a `null`
714
+ * name in THIS response is genuinely malformed — whereas a `null` name in a
715
+ * `capability_routes` row is the legitimate dangling-route case. Layering a
716
+ * call-site-specific check on top of the shared row call is the established
717
+ * shape in this family, not a new pattern.
718
+ */
719
+ export declare function asCapabilityRouteAdded(body: unknown): CapabilityRouteAddedWire;
720
+ /**
721
+ * Narrow `POST /api/remove_capability_route`'s 200 body
722
+ * (`{ text, capability, crewId, removed, remainingCrewIds }`).
723
+ *
724
+ * `removed` must be a BOOLEAN — this guard is how the CLI proves the 2xx really
725
+ * was the remove verb's answer. BOTH boolean values are valid, deliberate hub
726
+ * responses:
727
+ * - `true` — the `(capability, crew)` pair was bound and is now removed;
728
+ * - `false` — the pair was never bound, so there was nothing to do. The hub
729
+ * answers this with a 200, never a 404 (the `removeCrewMember` `{existed}`
730
+ * house pattern), and that tolerance is what makes `capability unbind` idempotent.
731
+ *
732
+ * `crewId` is LENIENT (absent or `null` both yield `null`) because `null` is a
733
+ * real hub output, not a defect: `manage-capability-routes.ts` resolves it as
734
+ * `namedCrew?.id ?? thisCapabilityRows.find(...)?.crewId ?? null`, so it is `null`
735
+ * on exactly the tolerant `removed: false` path where the argument matched
736
+ * neither a live crew name nor one of this capability's own route rows. Requiring a
737
+ * non-empty string here would throw on a normal success.
738
+ *
739
+ * `remainingCrewIds` is deliberately NOT lenient — it must be PRESENT and an
740
+ * array of non-empty strings. The asymmetry is the point: for a nullable name,
741
+ * the lenient default (`null`) is the SAFE reading, but defaulting an absent
742
+ * `remainingCrewIds` to `[]` would assert "this capability is now PARKED" — the
743
+ * alarming reading, and exactly the signal an operator acts on — off a malformed
744
+ * body. It lists LIVE crews only, so `[]` genuinely means zero live routes
745
+ * remain (which can happen while a dangling row survives, since such a row routes
746
+ * nothing).
747
+ *
748
+ * The stdout shape built from this is documented in `docs/cli.md`'s
749
+ * "Printed JSON" table under capability routes.
750
+ */
751
+ export declare function asCapabilityRouteRemoved(body: unknown): {
752
+ capability: string;
753
+ crewId: string | null;
754
+ removed: boolean;
755
+ remainingCrewIds: string[];
756
+ };
757
+ /**
758
+ * Narrow `GET /api/capability_routes`'s 200 body (`{ text, routes: [...] }`) to a
759
+ * typed array. An EMPTY array is valid — that is the "this org has no routes
760
+ * yet" case, not an error.
761
+ *
762
+ * Rows are plain `CapabilityRouteWire`, ONE per `(capability, crew)` pair ordered by
763
+ * `capability, crew_id`, so a capability bound to many crews yields MANY rows — the array
764
+ * is forwarded as-is and must never be collapsed into a per-capability map. A row
765
+ * whose `crewName` is `null` is a dangling route and is kept, not dropped.
766
+ */
767
+ export declare function asCapabilityRoutes(body: unknown): CapabilityRouteWire[];
768
+ /**
769
+ * A **crew** as the hub reports it — an org-scoped queue that agent work is
770
+ * stamped to. `kind` is `'personal' | 'shared' | 'orphan'` on the wire, but is
771
+ * deliberately NOT narrowed to that union here: `'orphan'` is a real value
772
+ * `GET /api/crews` returns, and the hub verbs (`packages/hub-core/src/verbs/
773
+ * manage-crews.ts`) are the enforcement of record for the other two — the same
774
+ * stance `agent new` takes for `--crews`.
775
+ */
776
+ export interface CrewWire {
777
+ id: string;
778
+ name: string;
779
+ kind: string;
780
+ ownerMemberId: string | null;
781
+ createdBy: string;
782
+ createdAt: number;
783
+ }
784
+ /** One membership row on a `CrewListingWire` — `principalKind` is `'member' | 'agent'` on the wire, forwarded verbatim. */
785
+ export interface CrewMemberWire {
786
+ principalKind: string;
787
+ principalId: string;
788
+ addedBy: string;
789
+ addedAt: number;
790
+ }
791
+ /**
792
+ * `GET /api/crews`' per-crew listing — a `CrewWire` plus its members inline
793
+ * (one hop, no per-crew fan-out) plus a CLIENT-DERIVED `orphan` boolean. `orphan`
794
+ * never appears on the wire; `asCrews` computes it with the same rule as the
795
+ * hub's own `isOrphanCrew` (`manage-crews.ts:170-172`) so the CLI can mark the
796
+ * org's reserved `orphan:unrouted` crew instead of filtering it out — an
797
+ * operator has to be able to see where a deleted crew's work went.
798
+ */
799
+ export interface CrewListingWire extends CrewWire {
800
+ orphan: boolean;
801
+ members: CrewMemberWire[];
802
+ }
803
+ /**
804
+ * `POST /api/delete_crew`'s 200 body. `deleted` is always present; the six
805
+ * transfer fields are OPTIONAL and, deliberately, absent (not `null`, not `0`)
806
+ * when nothing moved — see `asCrewDeleted`.
807
+ */
808
+ export interface CrewDeletedWire {
809
+ crewId: string;
810
+ deleted: boolean;
811
+ membersRemoved?: number;
812
+ orphanCrewId?: string;
813
+ orphanCrewName?: string;
814
+ stampsTransferred?: number;
815
+ runsTransferred?: string[];
816
+ runningRunsTransferred?: string[];
817
+ }
818
+ /** `POST /api/remove_crew_member`'s 200 body — tolerant of a non-member, exactly like `asCapabilityRouteRemoved`'s `removed`. */
819
+ export interface CrewMemberRemovedWire {
820
+ crewId: string;
821
+ principalId: string;
822
+ removed: boolean;
823
+ }
824
+ /**
825
+ * Narrow `GET /api/crews`'s 200 body (`{ text, crews: [...] }`) to a typed
826
+ * array. An EMPTY array is valid (a brand-new org). `GET /api/crews`
827
+ * deliberately returns the org's reserved orphan crew when it exists — this
828
+ * never filters it out; instead every row gets a derived `orphan` boolean,
829
+ * always present (`true` or `false`), so a scripted consumer never branches on
830
+ * the key's existence.
831
+ */
832
+ export declare function asCrews(body: unknown): CrewListingWire[];
833
+ /**
834
+ * Narrow `POST /api/create_crew`'s 200 body (`{ text, crew }`) to the typed
835
+ * row.
836
+ */
837
+ export declare function asCrewCreated(body: unknown): CrewWire;
838
+ /**
839
+ * Narrow `POST /api/delete_crew`'s 200 body. `crewId` and `deleted` are always
840
+ * present (`deleted` is a genuine boolean — both values are valid, deliberate
841
+ * hub answers, exactly like `asCapabilityRouteRemoved`). Each of the six transfer
842
+ * fields is validated ONLY IF PRESENT and OMITTED from the returned object when
843
+ * absent — never defaulted to `0`, `null`, or `[]`. Absence is the hub's way of
844
+ * saying "nothing moved"; default-filling would assert a transfer that never
845
+ * happened. `runsTransferred`/`runningRunsTransferred` are ARRAYS OF IDS, not
846
+ * counts — `stampsTransferred`/`membersRemoved` are the counts.
847
+ */
848
+ export declare function asCrewDeleted(body: unknown): CrewDeletedWire;
849
+ /** Narrow `POST /api/add_crew_member`'s 200 body (`{ text, member }`) to the typed row. */
850
+ export declare function asCrewMemberAdded(body: unknown): CrewMemberWire;
851
+ /**
852
+ * Narrow `POST /api/remove_crew_member`'s 200 body (`{ text, crewId,
853
+ * principalId, removed }`). `removed` must be a genuine boolean — both values
854
+ * are valid, deliberate hub answers: `false` means the principal was never a
855
+ * member (tolerant, a normal success), exactly like `asCapabilityRouteRemoved`.
856
+ */
857
+ export declare function asCrewMemberRemoved(body: unknown): CrewMemberRemovedWire;
609
858
  /**
610
859
  * Success shape of `POST /api/rekey_agent_token` — the whitelist a caller may
611
860
  * keep. Sibling of `MintAgentTokenOk`, and MUST stay a whitelist for the same
612
861
  * reason: the real 200 body carries a `text` field whose value CONTAINS the new
613
862
  * one-time `olp_` plaintext, so a caller must never spread the raw body.
614
863
  *
615
- * Rekey has NO `pools` field (re-keying preserves the agent's existing pool
864
+ * Rekey has NO `crews` field (re-keying preserves the agent's existing crew
616
865
  * membership — the verb changes none), so `MintAgentTokenOk`/`asMintAgentTokenOk`
617
866
  * cannot be reused. `scopes` and `revokedTokenIds` are non-secret handles.
618
867
  */