owenloop 0.4.1 → 0.5.0

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 (154) hide show
  1. package/CHANGELOG.md +26 -0
  2. package/README.md +58 -31
  3. package/bin/owenloop.mjs +2 -2
  4. package/dist/packages/work/src/agent/brief.d.ts +172 -0
  5. package/dist/packages/work/src/agent/brief.js +193 -0
  6. package/dist/packages/work/src/agent/loop.d.ts +135 -0
  7. package/dist/packages/work/src/agent/loop.js +542 -0
  8. package/dist/packages/work/src/agent/workdir.d.ts +210 -0
  9. package/dist/packages/work/src/agent/workdir.js +319 -0
  10. package/dist/packages/work/src/bundle/cache.d.ts +90 -0
  11. package/dist/packages/work/src/bundle/cache.js +324 -0
  12. package/dist/packages/work/src/bundle/fetch.d.ts +85 -0
  13. package/dist/packages/work/src/bundle/fetch.js +325 -0
  14. package/dist/packages/work/src/bundle/types.d.ts +160 -0
  15. package/dist/packages/work/src/bundle/types.js +1 -0
  16. package/dist/packages/work/src/credentials/owenloop.d.ts +11 -0
  17. package/dist/packages/work/src/credentials/owenloop.js +28 -0
  18. package/dist/packages/work/src/credentials/reader.d.ts +36 -0
  19. package/dist/packages/work/src/credentials/reader.js +32 -0
  20. package/dist/packages/work/src/credentials/resolve.d.ts +19 -0
  21. package/dist/packages/work/src/credentials/resolve.js +56 -0
  22. package/dist/packages/work/src/exec/loop.d.ts +29 -0
  23. package/dist/packages/work/src/exec/loop.js +215 -0
  24. package/dist/packages/work/src/exec/receipt.d.ts +38 -0
  25. package/dist/packages/work/src/exec/receipt.js +21 -0
  26. package/dist/packages/work/src/exec/runner.d.ts +65 -0
  27. package/dist/packages/work/src/exec/runner.js +185 -0
  28. package/dist/packages/work/src/harness/child-env.d.ts +100 -0
  29. package/dist/packages/work/src/harness/child-env.js +127 -0
  30. package/dist/packages/work/src/harness/claude.d.ts +128 -0
  31. package/dist/packages/work/src/harness/claude.js +635 -0
  32. package/dist/packages/work/src/harness/codex.d.ts +110 -0
  33. package/dist/packages/work/src/harness/codex.js +896 -0
  34. package/dist/packages/work/src/harness/contract.d.ts +283 -0
  35. package/dist/packages/work/src/harness/contract.js +32 -0
  36. package/dist/packages/work/src/harness/fake.d.ts +59 -0
  37. package/dist/packages/work/src/harness/fake.js +90 -0
  38. package/dist/packages/work/src/harness/jsonrpc-stdio.d.ts +108 -0
  39. package/dist/packages/work/src/harness/jsonrpc-stdio.js +344 -0
  40. package/dist/packages/work/src/harness/permissions.d.ts +62 -0
  41. package/dist/packages/work/src/harness/permissions.js +93 -0
  42. package/dist/packages/work/src/harness/registry.d.ts +47 -0
  43. package/dist/packages/work/src/harness/registry.js +45 -0
  44. package/dist/packages/work/src/harness/session-store.d.ts +163 -0
  45. package/dist/packages/work/src/harness/session-store.js +319 -0
  46. package/dist/packages/work/src/harness/types.d.ts +29 -0
  47. package/dist/packages/work/src/harness/types.js +14 -0
  48. package/dist/packages/work/src/harnesses.d.ts +38 -0
  49. package/dist/packages/work/src/harnesses.js +38 -0
  50. package/dist/packages/work/src/hold/loop.d.ts +36 -0
  51. package/dist/packages/work/src/hold/loop.js +23 -0
  52. package/dist/packages/work/src/hold/mcp.d.ts +55 -0
  53. package/dist/packages/work/src/hold/mcp.js +149 -0
  54. package/dist/packages/work/src/hub/client.d.ts +22 -0
  55. package/dist/packages/work/src/hub/client.js +78 -0
  56. package/dist/packages/work/src/hub/types.d.ts +290 -0
  57. package/dist/packages/work/src/hub/types.js +28 -0
  58. package/dist/packages/work/src/lease/loop.d.ts +94 -0
  59. package/dist/packages/work/src/lease/loop.js +277 -0
  60. package/dist/packages/work/src/main.d.ts +1 -0
  61. package/dist/packages/work/src/main.js +48 -0
  62. package/dist/packages/work/src/mcp/server.d.ts +125 -0
  63. package/dist/packages/work/src/mcp/server.js +320 -0
  64. package/dist/packages/work/src/roles/agent-run.d.ts +118 -0
  65. package/dist/packages/work/src/roles/agent-run.js +447 -0
  66. package/dist/packages/work/src/roles/exec.d.ts +40 -0
  67. package/dist/packages/work/src/roles/exec.js +203 -0
  68. package/dist/packages/work/src/roles/hold.d.ts +68 -0
  69. package/dist/packages/work/src/roles/hold.js +324 -0
  70. package/dist/packages/work/src/roles/join.d.ts +18 -0
  71. package/dist/packages/work/src/roles/join.js +204 -0
  72. package/dist/packages/work/src/roles/lint.d.ts +59 -0
  73. package/dist/packages/work/src/roles/lint.js +200 -0
  74. package/dist/packages/work/src/roles/prepare.d.ts +1 -0
  75. package/dist/packages/work/src/roles/prepare.js +249 -0
  76. package/dist/packages/work/src/roles/release.d.ts +48 -0
  77. package/dist/packages/work/src/roles/release.js +137 -0
  78. package/dist/packages/work/src/roles/sessions.d.ts +61 -0
  79. package/dist/packages/work/src/roles/sessions.js +180 -0
  80. package/dist/packages/work/src/roles/settings.d.ts +6 -0
  81. package/dist/packages/work/src/roles/settings.js +66 -0
  82. package/dist/packages/work/src/roles/shift.d.ts +12 -0
  83. package/dist/packages/work/src/roles/shift.js +228 -0
  84. package/dist/packages/work/src/roles/signals.d.ts +55 -0
  85. package/dist/packages/work/src/roles/signals.js +62 -0
  86. package/dist/packages/work/src/settings/provision.d.ts +21 -0
  87. package/dist/packages/work/src/settings/provision.js +47 -0
  88. package/dist/packages/work/src/settings/settings.d.ts +120 -0
  89. package/dist/packages/work/src/settings/settings.js +116 -0
  90. package/dist/packages/work/src/shift/client.d.ts +24 -0
  91. package/dist/packages/work/src/shift/client.js +124 -0
  92. package/dist/packages/work/src/shift/loop.d.ts +120 -0
  93. package/dist/packages/work/src/shift/loop.js +468 -0
  94. package/dist/packages/work/src/shift/protocol.d.ts +91 -0
  95. package/dist/packages/work/src/shift/protocol.js +24 -0
  96. package/dist/packages/work/src/shift/routing.d.ts +35 -0
  97. package/dist/packages/work/src/shift/routing.js +50 -0
  98. package/dist/packages/work/src/shift/runtime.d.ts +43 -0
  99. package/dist/packages/work/src/shift/runtime.js +274 -0
  100. package/dist/packages/work/src/shift/server.d.ts +23 -0
  101. package/dist/packages/work/src/shift/server.js +716 -0
  102. package/dist/packages/work/src/shift/spawn.d.ts +86 -0
  103. package/dist/packages/work/src/shift/spawn.js +100 -0
  104. package/dist/packages/work/src/shift/state.d.ts +77 -0
  105. package/dist/packages/work/src/shift/state.js +162 -0
  106. package/dist/packages/work/src/usage.d.ts +6 -0
  107. package/dist/packages/work/src/usage.js +175 -0
  108. package/dist/{cli.d.ts → src/cli.d.ts} +18 -3
  109. package/dist/{cli.js → src/cli.js} +770 -114
  110. package/dist/{credentials.d.ts → src/credentials.d.ts} +18 -12
  111. package/dist/{credentials.js → src/credentials.js} +14 -12
  112. package/dist/{defs.js → src/defs.js} +36 -36
  113. package/dist/{engine.d.ts → src/engine.d.ts} +8 -8
  114. package/dist/{engine.js → src/engine.js} +14 -14
  115. package/dist/{hub.d.ts → src/hub.d.ts} +205 -10
  116. package/dist/{hub.js → src/hub.js} +370 -12
  117. package/dist/{index.d.ts → src/index.d.ts} +1 -1
  118. package/dist/{index.js → src/index.js} +1 -1
  119. package/dist/{mcp → src/mcp}/serve.d.ts +5 -4
  120. package/dist/{mcp → src/mcp}/serve.js +168 -31
  121. package/dist/{mcp → src/mcp}/server.d.ts +6 -9
  122. package/dist/{mcp → src/mcp}/server.js +6 -9
  123. package/dist/{model.js → src/model.js} +1 -1
  124. package/dist/{types.d.ts → src/types.d.ts} +18 -18
  125. package/dist/{util.d.ts → src/util.d.ts} +3 -2
  126. package/dist/{util.js → src/util.js} +3 -2
  127. package/dist/{owenwork.d.ts → src/work-settings.d.ts} +22 -22
  128. package/dist/{owenwork.js → src/work-settings.js} +27 -27
  129. package/docs/authoring.md +93 -53
  130. package/docs/cli.md +597 -76
  131. package/docs/design.md +33 -33
  132. package/docs/embedding.md +10 -9
  133. package/examples/workflows/{command-worker.yaml → command-executor.yaml} +15 -15
  134. package/examples/workflows/compile-dev-playbook.yaml +338 -0
  135. package/examples/workflows/judges/gate-sharpness.md +39 -0
  136. package/examples/workflows/judges/security.md +34 -0
  137. package/package.json +17 -8
  138. /package/dist/{add.d.ts → src/add.d.ts} +0 -0
  139. /package/dist/{add.js → src/add.js} +0 -0
  140. /package/dist/{defs.d.ts → src/defs.d.ts} +0 -0
  141. /package/dist/{factory.d.ts → src/factory.d.ts} +0 -0
  142. /package/dist/{factory.js → src/factory.js} +0 -0
  143. /package/dist/{lock.d.ts → src/lock.d.ts} +0 -0
  144. /package/dist/{lock.js → src/lock.js} +0 -0
  145. /package/dist/{model.d.ts → src/model.d.ts} +0 -0
  146. /package/dist/{paths.d.ts → src/paths.d.ts} +0 -0
  147. /package/dist/{paths.js → src/paths.js} +0 -0
  148. /package/dist/{schema.d.ts → src/schema.d.ts} +0 -0
  149. /package/dist/{schema.js → src/schema.js} +0 -0
  150. /package/dist/{store.d.ts → src/store.d.ts} +0 -0
  151. /package/dist/{store.js → src/store.js} +0 -0
  152. /package/dist/{types.js → src/types.js} +0 -0
  153. /package/dist/{untar.d.ts → src/untar.d.ts} +0 -0
  154. /package/dist/{untar.js → src/untar.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,14 +20,15 @@
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.
@@ -207,17 +208,23 @@ function passthrough(deps, build) {
207
208
  /**
208
209
  * The 17 baseline tools — names, descriptions, and schemas mirror the hub's own
209
210
  * 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).
211
+ * to an H3 `/api/*` REST mirror. Descriptions say "Scoped Identity" for the identity
212
+ * (wire names keep `agent`), never "tool" (model-doc §0/§10).
213
+ *
214
+ * This is not the server's whole tool list. `runMcpCommand` assembles the full
215
+ * set: these 17, plus `createAgentTool`, plus the four crew tools from
216
+ * `buildCrewTools` (below — deliberately NOT folded in here, since they do not
217
+ * mirror the hub's own MCP toolset), plus the conditionally-registered
218
+ * `stageEnrollmentTool`.
212
219
  */
213
220
  function buildBaselineTools(deps) {
214
221
  return [
215
222
  {
216
223
  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).',
224
+ 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
225
  inputSchema: {
219
226
  type: 'object',
220
- properties: { workflow: { type: 'string' }, serve_pools: { type: 'array', items: { type: 'string' } } },
227
+ properties: { workflow: { type: 'string' }, serve_crews: { type: 'array', items: { type: 'string' } } },
221
228
  additionalProperties: false,
222
229
  },
223
230
  handler: passthrough(deps, (a) => ({ method: 'POST', path: '/api/whats_next', body: a })),
@@ -289,7 +296,7 @@ function buildBaselineTools(deps) {
289
296
  },
290
297
  {
291
298
  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.',
299
+ 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
300
  inputSchema: {
294
301
  type: 'object',
295
302
  properties: { name: { type: 'string' } },
@@ -387,20 +394,25 @@ function buildBaselineTools(deps) {
387
394
  },
388
395
  {
389
396
  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).',
397
+ 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
398
  inputSchema: {
392
399
  type: 'object',
393
- properties: { name: { type: 'string' }, serve_pools: { type: 'array', items: { type: 'string' } } },
400
+ properties: {
401
+ name: { type: 'string' },
402
+ serve_crews: { type: 'array', items: { type: 'string' } },
403
+ shift_id: { type: 'string' },
404
+ started_at: { type: 'number' },
405
+ },
394
406
  required: ['name'],
395
407
  additionalProperties: false,
396
408
  },
397
409
  handler: passthrough(deps, (a) => ({ method: 'POST', path: '/api/presence_ping', body: a })),
398
410
  },
399
411
  {
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.",
412
+ name: 'list_shifts',
413
+ 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
414
  inputSchema: { type: 'object', properties: {}, additionalProperties: false },
403
- handler: passthrough(deps, () => ({ method: 'GET', path: '/api/conductors' })),
415
+ handler: passthrough(deps, () => ({ method: 'GET', path: '/api/shifts' })),
404
416
  },
405
417
  {
406
418
  name: 'wake',
@@ -421,22 +433,23 @@ function buildBaselineTools(deps) {
421
433
  /** Legal agent name, mirroring hub.ts's `ACCOUNT_RE` shape — advisory in the schema, ENFORCED in the handler. */
422
434
  const AGENT_NAME_RE = /^[A-Za-z0-9][A-Za-z0-9._-]{0,63}$/;
423
435
  /**
424
- * Tool 18 — `create_agent`. Mints a NEW agent identity and writes its `olp_`
436
+ * Tool 18 — `create_agent`. Mints a NEW Scoped Identity and writes its `olp_`
425
437
  * token straight to the local store; NEVER returns the token. Decision 6: the
426
438
  * mint response leaks the plaintext in `data.token` AND the human `text` field,
427
439
  * 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.
440
+ * validated `token` (to store) and the safe `crews` names (to report), and
441
+ * builds `{name, crews, stored:true}` from scratch.
430
442
  */
431
443
  function createAgentTool(deps) {
432
444
  return {
433
445
  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.',
446
+ 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
447
  inputSchema: {
436
448
  type: 'object',
437
449
  properties: {
438
450
  name: { type: 'string', pattern: '^[A-Za-z0-9][A-Za-z0-9._-]{0,63}$' },
439
- pools: { type: 'array', items: { type: 'string' } },
451
+ crews: { type: 'array', items: { type: 'string' } },
452
+ scopes: { type: 'array', items: { type: 'string' } },
440
453
  },
441
454
  required: ['name'],
442
455
  additionalProperties: false,
@@ -448,10 +461,22 @@ function createAgentTool(deps) {
448
461
  if (typeof name !== 'string' || !AGENT_NAME_RE.test(name)) {
449
462
  return errorText('invalid agent name — expected 1-64 chars matching [A-Za-z0-9][A-Za-z0-9._-]*');
450
463
  }
451
- const pools = args['pools'];
452
- const body = { name, scopes: ['work'] };
453
- if (Array.isArray(pools))
454
- body.pools = pools;
464
+ // `scopes` is optional. When present it must be a non-empty array of
465
+ // non-empty strings — validated BEFORE any network call (the schema is
466
+ // advisory). Absent → the `work`-only default. No scope-NAME check: the
467
+ // hub is the enforcement of record (same stance as crews).
468
+ const scopesArg = args['scopes'];
469
+ let scopes;
470
+ if (scopesArg !== undefined) {
471
+ if (!Array.isArray(scopesArg) || scopesArg.length === 0 || !scopesArg.every((s) => typeof s === 'string' && s !== '')) {
472
+ return errorText('invalid scopes — expected a non-empty array of scope name strings');
473
+ }
474
+ scopes = scopesArg;
475
+ }
476
+ const crews = args['crews'];
477
+ const body = { name, scopes: scopes ?? ['work'] };
478
+ if (Array.isArray(crews))
479
+ body.crews = crews;
455
480
  const r = await callHub(deps, { method: 'POST', path: '/api/mint_agent_token', body });
456
481
  if (r.authFailed)
457
482
  return errorText(r.authMessage ?? loginHint(deps.origin));
@@ -470,12 +495,12 @@ function createAgentTool(deps) {
470
495
  await storeCredential(deps.io, deps.origin, { principal: 'agent', account: name }, { kind: 'agent', accessToken: token });
471
496
  }
472
497
  catch (e) {
473
- return errorText(`${e.message} — the minted token was NOT stored — revoke/re-key the agent '${name}' from the console`);
498
+ return errorText(`${e.message} — the minted token was NOT stored — revoke/re-key the Scoped Identity '${name}' from the console`);
474
499
  }
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 });
500
+ // Success: built from scratch. `crews` (crewNames) is safe; token/text/id
501
+ // /agentId/crewIds from the body must never reach an outbound frame.
502
+ const outCrews = isObject(r.json) && Array.isArray(r.json['crews']) ? r.json['crews'] : [];
503
+ return textResult({ name, crews: outCrews, stored: true });
479
504
  },
480
505
  };
481
506
  }
@@ -483,12 +508,12 @@ function createAgentTool(deps) {
483
508
  function stageEnrollmentTool(deps) {
484
509
  return {
485
510
  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.',
511
+ 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
512
  inputSchema: {
488
513
  type: 'object',
489
514
  properties: {
490
515
  name: { type: 'string', pattern: '^[A-Za-z0-9][A-Za-z0-9._-]{0,63}$' },
491
- pools: { type: 'array', items: { type: 'string' } },
516
+ crews: { type: 'array', items: { type: 'string' } },
492
517
  },
493
518
  required: ['name'],
494
519
  additionalProperties: false,
@@ -496,6 +521,118 @@ function stageEnrollmentTool(deps) {
496
521
  handler: passthrough(deps, (a) => ({ method: 'POST', path: '/api/stage_enrollment', body: a })),
497
522
  };
498
523
  }
524
+ /**
525
+ * Crew management — the MCP counterpart to the `owenloop crew` CLI family
526
+ * (`src/cli.ts`'s `dispatchCrew`, merged as PR #88). All FOUR tools below are
527
+ * plain `passthrough` registrations: the hub's crew response bodies carry no
528
+ * secret (unlike `create_agent`'s mint body), so there is no reason to
529
+ * hand-build a result, and the hub's `/api/*` routes plus the verbs underneath
530
+ * them are already the enforcement of record for every field — a client-side
531
+ * copy of that validation would just be a second place for the rules to drift.
532
+ *
533
+ * CREDENTIAL PLANE: unchanged, and worth restating because it is what makes
534
+ * crew mutation reachable at all from this server. `callHub` always
535
+ * authenticates as the `human` slot (`HUMAN`, above) — `owenloop mcp` never
536
+ * calls the hub as a Scoped Identity. On the hub, `createCrew`, `addCrewMember`,
537
+ * and `removeCrewMember` gate through `assertCrewMutationAllowed`
538
+ * (`packages/hub-core/src/verbs/manage-crews.ts`), which falls through to
539
+ * `assertAllowed(actor, 'manage_crews')` — a verb with NO entry in
540
+ * `AGENT_SCOPE_FOR_VERB` (`rbac.ts`), so an agent-kind actor is refused
541
+ * `ForbiddenError` there no matter what scopes it holds. Because this server
542
+ * always authenticates as a human, that refusal never applies to it. `listCrews`
543
+ * is gated on the separate, agent-reachable `list` verb instead.
544
+ *
545
+ * `delete_crew` IS DELIBERATELY ABSENT, and stays absent — a decision by the
546
+ * repo's human owner, not a technical gap. Deleting a crew transfers its live
547
+ * `order_crews` stamps onto the org's orphan crew and deletes the crew's own
548
+ * membership rows outright; that is not an operation a model-driven host
549
+ * should be able to trigger. Do not add a `delete_crew` tool, an env-flag
550
+ * variant, or a confirmation-style variant — `owenloop crew rm` on the CLI
551
+ * remains the only way to delete a crew. Removing a single MEMBER (below) is a
552
+ * different, reversible operation and stays in scope.
553
+ */
554
+ function buildCrewTools(deps) {
555
+ return [
556
+ {
557
+ name: 'list_crews',
558
+ description: "The org's crews, each with its membership rows inline (principalKind/principalId/addedBy/addedAt) — " +
559
+ 'one call, no per-crew fan-out. An org with no crews at all is a normal empty result, not an error. ' +
560
+ "The org's reserved ORPHAN crew (kind: \"orphan\", or a name starting \"orphan:\") IS returned when it " +
561
+ 'exists and is deliberately NOT filtered out — it is where the hub re-homes work whose crew was ' +
562
+ 'deleted, so a caller has to be able to see where that work went. It is materialized LAZILY: a fresh ' +
563
+ "org has none. Its membership is derived (always the org's current admins) and cannot be edited — " +
564
+ 'add_crew_member/remove_crew_member both refuse it.',
565
+ inputSchema: { type: 'object', properties: {}, additionalProperties: false },
566
+ handler: passthrough(deps, () => ({ method: 'GET', path: '/api/crews' })),
567
+ },
568
+ {
569
+ name: 'create_crew',
570
+ description: "Create a crew on the hub org. `kind` is 'personal' or 'shared', forwarded verbatim — the hub is the " +
571
+ "enforcement of record for legal values ('orphan' is reserved for the hub's own crew and is refused). " +
572
+ "`ownerMemberId` is required for a 'personal' crew and is simply omitted from the request when not " +
573
+ 'passed. NOT admin-only: an org admin may create any crew, AND a non-admin may create a personal crew ' +
574
+ 'they own by passing kind:"personal" with ownerMemberId set to their own member id (the ' +
575
+ 'self-service branch of the mutation gate). A non-admin asking for a shared crew, for a personal crew ' +
576
+ 'owned by someone else, or for a personal crew with ownerMemberId OMITTED, is refused 403 — the hub ' +
577
+ 'deliberately does not infer the caller as the owner.',
578
+ inputSchema: {
579
+ type: 'object',
580
+ properties: {
581
+ name: { type: 'string' },
582
+ kind: { type: 'string' },
583
+ ownerMemberId: { type: 'string' },
584
+ },
585
+ required: ['name', 'kind'],
586
+ additionalProperties: false,
587
+ },
588
+ handler: passthrough(deps, (a) => ({ method: 'POST', path: '/api/create_crew', body: a })),
589
+ },
590
+ {
591
+ name: 'add_crew_member',
592
+ description: "Add one principal to a crew. `principalKind` is 'member' (a human) or 'agent' (a Scoped Identity), " +
593
+ 'forwarded verbatim; the hub validates it. NOT admin-only: an org admin may act on any crew, AND the ' +
594
+ 'OWNER of a personal crew may add members to that crew without being an admin. HTTP 400 (not a ' +
595
+ 'permissions error, and NOT tolerant): an unknown crewId, an unknown principalId, or a principal that ' +
596
+ 'is ALREADY a member — a duplicate add IS an error, unlike remove_crew_member below. REFUSED OUTRIGHT ' +
597
+ "against the org's orphan crew, for every caller including an admin, as a 400 (never a 403 — the " +
598
+ "refusal is identity-independent: it objects to the target crew, not the caller's role). The orphan " +
599
+ "crew's membership is the derived org admin roster and cannot be edited this way.",
600
+ inputSchema: {
601
+ type: 'object',
602
+ properties: {
603
+ crewId: { type: 'string' },
604
+ principalKind: { type: 'string' },
605
+ principalId: { type: 'string' },
606
+ },
607
+ required: ['crewId', 'principalKind', 'principalId'],
608
+ additionalProperties: false,
609
+ },
610
+ handler: passthrough(deps, (a) => ({ method: 'POST', path: '/api/add_crew_member', body: a })),
611
+ },
612
+ {
613
+ name: 'remove_crew_member',
614
+ description: 'Remove one principal from a crew. TOLERANT: removing a principal that was never a member is a normal ' +
615
+ 'success — HTTP 200 with removed:false, NOT a 404. Read the `removed` boolean rather than treating a ' +
616
+ 'false as a failure. An unknown crewId is DIFFERENT and is an HTTP 400 error. NOT admin-only: same ' +
617
+ 'self-service carve-out as add_crew_member — an org admin, or the owner of the personal crew being ' +
618
+ "acted on. REFUSED OUTRIGHT against the org's orphan crew, for every caller including an admin, as a " +
619
+ '400 — and that orphan refusal is NOT tolerant: it throws even when the principal was never a member, ' +
620
+ 'because the objection is to the target crew and is decided before the hub looks at the membership ' +
621
+ 'row. Removing a member is reversible. DELETING a crew is deliberately NOT available on this server at ' +
622
+ 'all — use the `owenloop crew rm` CLI command for that.',
623
+ inputSchema: {
624
+ type: 'object',
625
+ properties: {
626
+ crewId: { type: 'string' },
627
+ principalId: { type: 'string' },
628
+ },
629
+ required: ['crewId', 'principalId'],
630
+ additionalProperties: false,
631
+ },
632
+ handler: passthrough(deps, (a) => ({ method: 'POST', path: '/api/remove_crew_member', body: a })),
633
+ },
634
+ ];
635
+ }
499
636
  // ---- enrollment capability gate (Decision 7) --------------------------------
500
637
  /** The probe deadline; `OWENLOOP_MCP_PROBE_TIMEOUT_MS` overrides the 3000ms default. */
501
638
  function probeTimeoutMs(env) {
@@ -548,7 +685,7 @@ export async function runMcpCommand(io, opts) {
548
685
  return resolved.exitCode;
549
686
  }
550
687
  const deps = { io, origin: resolved.origin };
551
- const tools = [...buildBaselineTools(deps), createAgentTool(deps)];
688
+ const tools = [...buildBaselineTools(deps), createAgentTool(deps), ...buildCrewTools(deps)];
552
689
  if (await shouldRegisterEnrollment(deps))
553
690
  tools.push(stageEnrollmentTool(deps));
554
691
  const server = createMcpServer({
@@ -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
@@ -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
@@ -1628,7 +1628,7 @@ function eligibleOutcomes(def, arts, firing) {
1628
1628
  return ['green'];
1629
1629
  // §24: a judge firing's own verdict is against the judged stem, not against a
1630
1630
  // produce of its own (judge steps declare `produces: []`). Model the two verbs
1631
- // the judge agent can issue (green/reject, Q2) as their own outcomes, entirely
1631
+ // the judge Step Agent can issue (green/reject, Q2) as their own outcomes, entirely
1632
1632
  // separate from the producer-outcome branches below.
1633
1633
  if (step.judges) {
1634
1634
  // §26: if this is the last pending judge and approving would flip the
@@ -137,11 +137,11 @@ export interface Order {
137
137
  /** Declares which kind of executor this order is for. Absent = 'agent'
138
138
  * (today's behavior). Opaque to the engine; carried through verbatim from
139
139
  * the step definition, same pass-through contract as `model`/`x`. */
140
- worker?: string;
141
- /** The command string for a `worker: command` order. Opaque to the engine
140
+ executor?: string;
141
+ /** The command string for a `executor: command` order. Opaque to the engine
142
142
  * — never parsed, never shelled out. */
143
143
  command?: string;
144
- /** Opaque config object for a non-agent/non-command worker type (or
144
+ /** Opaque config object for a non-agent/non-command executor type (or
145
145
  * alongside `command`). Carried through untouched, contents never read. */
146
146
  spec?: Record<string, unknown>;
147
147
  /** §27.3: the step's opaque `x:` extension map, carried through untouched
@@ -256,13 +256,13 @@ export interface ProducePattern {
256
256
  cadence?: string;
257
257
  maxRunsPerDay?: number;
258
258
  /** Declares which kind of executor this judge's synthesized order is for.
259
- * Same opaque-passthrough contract as StepDef.worker — default 'agent'
259
+ * Same opaque-passthrough contract as StepDef.executor — default 'agent'
260
260
  * when omitted. */
261
- worker?: string;
262
- /** Required when worker is 'command'; the command string for that worker
261
+ executor?: string;
262
+ /** Required when executor is 'command'; the command string for that executor
263
263
  * to run. Opaque to the engine — never parsed, never shelled out. */
264
264
  command?: string;
265
- /** Optional opaque config object for a non-agent/non-command worker type
265
+ /** Optional opaque config object for a non-agent/non-command executor type
266
266
  * (or additionally alongside `command`). Shape-checked as a plain map
267
267
  * only (mirrors `x:`'s asExtension contract) — contents never read. */
268
268
  spec?: Record<string, unknown>;
@@ -325,11 +325,11 @@ export interface StepDef {
325
325
  * unchanged). Opaque to the engine beyond the shape rules validateDef
326
326
  * enforces; carried through verbatim on the Order, same contract as
327
327
  * `model`. */
328
- worker?: string;
329
- /** Required when worker is 'command'; the command string for that worker
328
+ executor?: string;
329
+ /** Required when executor is 'command'; the command string for that executor
330
330
  * to run. Opaque to the engine — never parsed, never shelled out. */
331
331
  command?: string;
332
- /** Optional opaque config object for a non-agent/non-command worker type
332
+ /** Optional opaque config object for a non-agent/non-command executor type
333
333
  * (or additionally alongside `command`). Shape-checked as a plain map
334
334
  * only (mirrors `x:`'s asExtension contract) — contents never read. */
335
335
  spec?: Record<string, unknown>;
@@ -347,11 +347,11 @@ export interface StepDef {
347
347
  idleAfterMs?: number;
348
348
  /** Per-step reap TTL override in milliseconds. Falls back to the engine's DEFAULT_REAP_TTL_MS. */
349
349
  reapTtlMs?: number;
350
- /** A2: opaque routing labels for peer-orchestrator claim filtering. A tick
351
- * caller passing a label filter only claims steps whose labels intersect it;
350
+ /** A2: opaque routing capabilities for peer-orchestrator claim filtering. A tick
351
+ * caller passing a capability filter only claims steps whose capabilities intersect it;
352
352
  * absent (or empty, normalized to absent at parse) = claimable by any caller.
353
- * Distinct from `worker`/`workers` (executor-kind), which this never touches. */
354
- labels?: string[];
353
+ * Distinct from `executor`/`executors` (executor-kind), which this never touches. */
354
+ capabilities?: string[];
355
355
  /** A3 (REL-8): per-step OPT-IN max total lease lifetime override in
356
356
  * milliseconds — the cap on `claimedAt + maxLease` past which renewals can no
357
357
  * longer keep a lease fresh. Overrides the engine `maxLeaseMs`; when both are
@@ -399,10 +399,10 @@ export interface WorkflowDef {
399
399
  /** §27.3: opaque workflow-level extension map (`x:`). Validated as a plain
400
400
  * map at load time, never interpreted by the engine. */
401
401
  x?: Record<string, unknown>;
402
- /** Optional allow-list of worker values; when present, validateDef errors
403
- * on any step/judge whose `worker` is not in this list (typo guard).
404
- * Absent = any worker string accepted. */
405
- workers?: string[];
402
+ /** Optional allow-list of executor values; when present, validateDef errors
403
+ * on any step/judge whose `executor` is not in this list (typo guard).
404
+ * Absent = any executor string accepted. */
405
+ executors?: string[];
406
406
  }
407
407
  export interface InputDef {
408
408
  name: string;
@@ -14,8 +14,9 @@
14
14
  * (consumed by both entry-point catches in `cli.ts`). It defaults to `1`, so
15
15
  * every existing `new CliError(msg)` — and `RateLimitError extends CliError`,
16
16
  * which inherits this constructor — keeps its byte-for-byte exit-1 behavior. The
17
- * non-default codes today are `agent new`'s exit 2 (hub unresolvable) and exit 3
18
- * (human credential absent/irrecoverable).
17
+ * non-default codes today are exit 2 (hub unresolvable) and exit 3 (human
18
+ * credential absent/irrecoverable), used by `agent new`, `binding
19
+ * new|rm|list`, and `crew`'s five subcommands.
19
20
  */
20
21
  export declare class CliError extends Error {
21
22
  readonly exitCode: number;
@@ -16,8 +16,9 @@ import { lstatSync, mkdirSync } from 'node:fs';
16
16
  * (consumed by both entry-point catches in `cli.ts`). It defaults to `1`, so
17
17
  * every existing `new CliError(msg)` — and `RateLimitError extends CliError`,
18
18
  * which inherits this constructor — keeps its byte-for-byte exit-1 behavior. The
19
- * non-default codes today are `agent new`'s exit 2 (hub unresolvable) and exit 3
20
- * (human credential absent/irrecoverable).
19
+ * non-default codes today are exit 2 (hub unresolvable) and exit 3 (human
20
+ * credential absent/irrecoverable), used by `agent new`, `binding
21
+ * new|rm|list`, and `crew`'s five subcommands.
21
22
  */
22
23
  export class CliError extends Error {
23
24
  exitCode;
@@ -1,35 +1,35 @@
1
1
  /**
2
- * owenwork settings file writer — the ONE place the owenloop CLI writes into a
3
- * sibling tool's config.
2
+ * execution settings file writer — the ONE place the root `owenloop` CLI writes
3
+ * into the execution-side settings file.
4
4
  *
5
- * `owenwork` (the wiring that runs orders) reads its settings from
6
- * `$XDG_CONFIG_HOME/owenwork/settings.json` (else `$HOME/.config/owenwork/
7
- * settings.json`) and, by design, NEVER writes them — the owenloop CLI's `setup`
8
- * command is the writer, so a fresh `owenloop setup` can point owenwork at the
9
- * hub it just authenticated against.
5
+ * `owenloop work` reads its settings from `$XDG_CONFIG_HOME/owenloop/
6
+ * settings.json` (else `$HOME/.config/owenloop/settings.json`) and, by design,
7
+ * NEVER writes them — the root CLI's `setup` command is the writer, so a fresh
8
+ * `owenloop setup` can point `owenloop work` at the hub it just authenticated
9
+ * against.
10
10
  *
11
11
  * This module writes exactly ONE key — `hubOrigin` — and preserves every other
12
- * key byte-for-byte (forward-compat with owenwork's own `cacheDir`, `agentsDir`,
13
- * `stateDir`, `dispatchCap`, `commandRouting`, and any future/unknown key). It
14
- * never writes a secret: nothing secret is in scope here by construction (the
15
- * hub ORIGIN is public).
12
+ * key byte-for-byte (forward-compat with the execution settings' `cacheDir`,
13
+ * `agentsDir`, `stateDir`, `dispatchCap`, `commandRouting`, and any future or
14
+ * unknown key). It never writes a secret: nothing secret is in scope here by
15
+ * construction (the hub ORIGIN is public).
16
16
  *
17
17
  * Corrupt-file policy: a settings file that exists but does not parse as a JSON
18
18
  * OBJECT is a hard error naming the path — the writer refuses to CLOBBER a file
19
- * it cannot safely merge into. That mirrors owenwork's own validator wording
20
- * family ("not an object").
19
+ * it cannot safely merge into. That mirrors the work settings validator's
20
+ * wording family ("not an object").
21
21
  *
22
22
  * Imports only node builtins, `writeFileAtomic` from hub.ts, and `CliError` from
23
23
  * util.ts — no CLI/engine closure.
24
24
  */
25
25
  /**
26
- * The owenwork settings file path for this environment. `XDG_CONFIG_HOME` (when
27
- * set and non-blank) wins over `HOME`, matching owenwork's own resolution and
26
+ * The execution settings file path for this environment. `XDG_CONFIG_HOME` (when
27
+ * set and non-blank) wins over `HOME`, matching owenloop's own resolution and
28
28
  * the owenloop credential store's `configDir`. Throws when neither is set.
29
29
  */
30
- export declare function owenworkSettingsPath(env: Record<string, string | undefined>): string;
30
+ export declare function owenloopSettingsPath(env: Record<string, string | undefined>): string;
31
31
  /**
32
- * Read and parse the owenwork settings file at `path`.
32
+ * Read and parse the execution settings file at `path`.
33
33
  *
34
34
  * - Missing file → `null` (an absent settings file is not an error; the writer
35
35
  * creates one).
@@ -38,20 +38,20 @@ export declare function owenworkSettingsPath(env: Record<string, string | undefi
38
38
  * `null`, a number, a string) → a hard `CliError` naming the path. The writer
39
39
  * must never clobber a file it cannot merge into.
40
40
  */
41
- export declare function readOwenworkSettingsRaw(path: string): Record<string, unknown> | null;
42
- /** The outcome of a `writeOwenworkHubOrigin` call — the path written and the
41
+ export declare function readOwenloopSettingsRaw(path: string): Record<string, unknown> | null;
42
+ /** The outcome of a `writeOwenloopHubOrigin` call — the path written and the
43
43
  * previous `hubOrigin` value (`undefined` when the key was absent or the file
44
44
  * did not exist), so a caller can report an old→new transition. */
45
- export interface OwenworkWriteResult {
45
+ export interface OwenloopWriteResult {
46
46
  path: string;
47
47
  previous: string | undefined;
48
48
  }
49
49
  /**
50
- * Set ONLY the `hubOrigin` key in the owenwork settings file to `origin`,
50
+ * Set ONLY the `hubOrigin` key in the execution settings file to `origin`,
51
51
  * preserving every other key. Read the existing file (a parse failure is a hard
52
52
  * `CliError` — never clobber), spread it, overwrite `hubOrigin`, `mkdir -p` the
53
53
  * directory, and write atomically (temp + rename via `writeFileAtomic`). The
54
54
  * file is pretty-printed with a trailing newline. Returns the path and the
55
55
  * previous `hubOrigin` (if any).
56
56
  */
57
- export declare function writeOwenworkHubOrigin(env: Record<string, string | undefined>, origin: string): OwenworkWriteResult;
57
+ export declare function writeOwenloopHubOrigin(env: Record<string, string | undefined>, origin: string): OwenloopWriteResult;