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.
- package/CHANGELOG.md +71 -0
- package/README.md +182 -53
- package/bin/owenloop.mjs +50 -2
- package/dist/packages/work/src/agent/brief.d.ts +176 -0
- package/dist/packages/work/src/agent/brief.js +197 -0
- package/dist/packages/work/src/agent/loop.d.ts +141 -0
- package/dist/packages/work/src/agent/loop.js +669 -0
- package/dist/packages/work/src/agent/model-policy.d.ts +49 -0
- package/dist/packages/work/src/agent/model-policy.js +138 -0
- package/dist/packages/work/src/agent/workdir.d.ts +210 -0
- package/dist/packages/work/src/agent/workdir.js +319 -0
- package/dist/packages/work/src/bundle/cache.d.ts +92 -0
- package/dist/packages/work/src/bundle/cache.js +338 -0
- package/dist/packages/work/src/bundle/fetch.d.ts +87 -0
- package/dist/packages/work/src/bundle/fetch.js +345 -0
- package/dist/packages/work/src/bundle/types.d.ts +164 -0
- package/dist/packages/work/src/bundle/types.js +1 -0
- package/dist/packages/work/src/consumed-verifier.d.ts +45 -0
- package/dist/packages/work/src/consumed-verifier.js +205 -0
- package/dist/packages/work/src/credentials/owenloop.d.ts +11 -0
- package/dist/packages/work/src/credentials/owenloop.js +28 -0
- package/dist/packages/work/src/credentials/reader.d.ts +36 -0
- package/dist/packages/work/src/credentials/reader.js +32 -0
- package/dist/packages/work/src/credentials/resolve.d.ts +19 -0
- package/dist/packages/work/src/credentials/resolve.js +56 -0
- package/dist/packages/work/src/exec/instructions.d.ts +99 -0
- package/dist/packages/work/src/exec/instructions.js +323 -0
- package/dist/packages/work/src/exec/loop.d.ts +40 -0
- package/dist/packages/work/src/exec/loop.js +332 -0
- package/dist/packages/work/src/exec/payload.d.ts +29 -0
- package/dist/packages/work/src/exec/payload.js +54 -0
- package/dist/packages/work/src/exec/receipt.d.ts +41 -0
- package/dist/packages/work/src/exec/receipt.js +32 -0
- package/dist/packages/work/src/exec/runner.d.ts +71 -0
- package/dist/packages/work/src/exec/runner.js +256 -0
- package/dist/packages/work/src/harness/child-env.d.ts +100 -0
- package/dist/packages/work/src/harness/child-env.js +134 -0
- package/dist/packages/work/src/harness/claude.d.ts +140 -0
- package/dist/packages/work/src/harness/claude.js +837 -0
- package/dist/packages/work/src/harness/codex.d.ts +111 -0
- package/dist/packages/work/src/harness/codex.js +1024 -0
- package/dist/packages/work/src/harness/contract.d.ts +308 -0
- package/dist/packages/work/src/harness/contract.js +32 -0
- package/dist/packages/work/src/harness/fake.d.ts +59 -0
- package/dist/packages/work/src/harness/fake.js +91 -0
- package/dist/packages/work/src/harness/jsonrpc-stdio.d.ts +108 -0
- package/dist/packages/work/src/harness/jsonrpc-stdio.js +351 -0
- package/dist/packages/work/src/harness/permissions.d.ts +75 -0
- package/dist/packages/work/src/harness/permissions.js +182 -0
- package/dist/packages/work/src/harness/registry.d.ts +47 -0
- package/dist/packages/work/src/harness/registry.js +45 -0
- package/dist/packages/work/src/harness/session-store.d.ts +181 -0
- package/dist/packages/work/src/harness/session-store.js +523 -0
- package/dist/packages/work/src/harness/types.d.ts +29 -0
- package/dist/packages/work/src/harness/types.js +14 -0
- package/dist/packages/work/src/harnesses.d.ts +38 -0
- package/dist/packages/work/src/harnesses.js +38 -0
- package/dist/packages/work/src/hold/loop.d.ts +36 -0
- package/dist/packages/work/src/hold/loop.js +23 -0
- package/dist/packages/work/src/hold/mcp.d.ts +75 -0
- package/dist/packages/work/src/hold/mcp.js +264 -0
- package/dist/packages/work/src/hub/client.d.ts +23 -0
- package/dist/packages/work/src/hub/client.js +91 -0
- package/dist/packages/work/src/hub/types.d.ts +326 -0
- package/dist/packages/work/src/hub/types.js +26 -0
- package/dist/packages/work/src/lease/loop.d.ts +94 -0
- package/dist/packages/work/src/lease/loop.js +277 -0
- package/dist/packages/work/src/main.d.ts +1 -0
- package/dist/packages/work/src/main.js +48 -0
- package/dist/packages/work/src/mcp/server.d.ts +125 -0
- package/dist/packages/work/src/mcp/server.js +320 -0
- package/dist/packages/work/src/owenloop-bin.d.ts +1 -0
- package/dist/packages/work/src/owenloop-bin.js +18 -0
- package/dist/packages/work/src/roles/agent-run.d.ts +124 -0
- package/dist/packages/work/src/roles/agent-run.js +529 -0
- package/dist/packages/work/src/roles/exec.d.ts +48 -0
- package/dist/packages/work/src/roles/exec.js +228 -0
- package/dist/packages/work/src/roles/hold.d.ts +72 -0
- package/dist/packages/work/src/roles/hold.js +363 -0
- package/dist/packages/work/src/roles/join.d.ts +18 -0
- package/dist/packages/work/src/roles/join.js +204 -0
- package/dist/packages/work/src/roles/lint.d.ts +58 -0
- package/dist/packages/work/src/roles/lint.js +234 -0
- package/dist/packages/work/src/roles/prepare.d.ts +1 -0
- package/dist/packages/work/src/roles/prepare.js +249 -0
- package/dist/packages/work/src/roles/release.d.ts +48 -0
- package/dist/packages/work/src/roles/release.js +137 -0
- package/dist/packages/work/src/roles/sessions.d.ts +61 -0
- package/dist/packages/work/src/roles/sessions.js +180 -0
- package/dist/packages/work/src/roles/settings.d.ts +6 -0
- package/dist/packages/work/src/roles/settings.js +71 -0
- package/dist/packages/work/src/roles/shift.d.ts +13 -0
- package/dist/packages/work/src/roles/shift.js +250 -0
- package/dist/packages/work/src/roles/signals.d.ts +55 -0
- package/dist/packages/work/src/roles/signals.js +62 -0
- package/dist/packages/work/src/settings/provision.d.ts +21 -0
- package/dist/packages/work/src/settings/provision.js +47 -0
- package/dist/packages/work/src/settings/settings.d.ts +136 -0
- package/dist/packages/work/src/settings/settings.js +155 -0
- package/dist/packages/work/src/shift/client.d.ts +24 -0
- package/dist/packages/work/src/shift/client.js +124 -0
- package/dist/packages/work/src/shift/loop.d.ts +131 -0
- package/dist/packages/work/src/shift/loop.js +751 -0
- package/dist/packages/work/src/shift/protocol.d.ts +95 -0
- package/dist/packages/work/src/shift/protocol.js +24 -0
- package/dist/packages/work/src/shift/routing.d.ts +35 -0
- package/dist/packages/work/src/shift/routing.js +50 -0
- package/dist/packages/work/src/shift/runtime.d.ts +45 -0
- package/dist/packages/work/src/shift/runtime.js +337 -0
- package/dist/packages/work/src/shift/server.d.ts +23 -0
- package/dist/packages/work/src/shift/server.js +716 -0
- package/dist/packages/work/src/shift/spawn.d.ts +109 -0
- package/dist/packages/work/src/shift/spawn.js +158 -0
- package/dist/packages/work/src/shift/state.d.ts +79 -0
- package/dist/packages/work/src/shift/state.js +385 -0
- package/dist/packages/work/src/submit-proof.d.ts +36 -0
- package/dist/packages/work/src/submit-proof.js +93 -0
- package/dist/packages/work/src/usage.d.ts +6 -0
- package/dist/packages/work/src/usage.js +175 -0
- package/dist/src/add.d.ts +189 -0
- package/dist/src/add.js +300 -0
- package/dist/src/archive.d.ts +97 -0
- package/dist/src/archive.js +591 -0
- package/dist/src/bundle/index.d.ts +64 -0
- package/dist/src/bundle/index.js +508 -0
- package/dist/src/bundle/manifest.d.ts +50 -0
- package/dist/src/bundle/manifest.js +435 -0
- package/dist/src/bundle/runtime.d.ts +26 -0
- package/dist/src/bundle/runtime.js +64 -0
- package/dist/src/bundle/tar.d.ts +62 -0
- package/dist/src/bundle/tar.js +238 -0
- package/dist/src/bundle/types.d.ts +105 -0
- package/dist/src/bundle/types.js +21 -0
- package/dist/{cli.d.ts → src/cli.d.ts} +92 -7
- package/dist/src/cli.js +5968 -0
- package/dist/{credentials.d.ts → src/credentials.d.ts} +22 -15
- package/dist/{credentials.js → src/credentials.js} +35 -31
- package/dist/src/crypto/allowed-signers.d.ts +68 -0
- package/dist/src/crypto/allowed-signers.js +307 -0
- package/dist/src/crypto/canonical.d.ts +8 -0
- package/dist/src/crypto/canonical.js +92 -0
- package/dist/src/crypto/chain.d.ts +65 -0
- package/dist/src/crypto/chain.js +377 -0
- package/dist/src/crypto/dsse.d.ts +209 -0
- package/dist/src/crypto/dsse.js +282 -0
- package/dist/src/crypto/enrollment.d.ts +78 -0
- package/dist/src/crypto/enrollment.js +186 -0
- package/dist/src/crypto/index.d.ts +48 -0
- package/dist/src/crypto/index.js +44 -0
- package/dist/src/crypto/keys.d.ts +258 -0
- package/dist/src/crypto/keys.js +908 -0
- package/dist/src/crypto/org-root.d.ts +33 -0
- package/dist/src/crypto/org-root.js +78 -0
- package/dist/src/crypto/origin-rules.d.ts +56 -0
- package/dist/src/crypto/origin-rules.js +143 -0
- package/dist/src/crypto/policy-floor.d.ts +98 -0
- package/dist/src/crypto/policy-floor.js +353 -0
- package/dist/src/crypto/records.d.ts +316 -0
- package/dist/src/crypto/records.js +157 -0
- package/dist/src/crypto/scope.d.ts +49 -0
- package/dist/src/crypto/scope.js +83 -0
- package/dist/src/crypto/ssh.d.ts +171 -0
- package/dist/src/crypto/ssh.js +396 -0
- package/dist/src/crypto/submission.d.ts +33 -0
- package/dist/src/crypto/submission.js +47 -0
- package/dist/src/crypto/trust-roots.d.ts +29 -0
- package/dist/src/crypto/trust-roots.js +39 -0
- package/dist/src/crypto/verify-consumed.d.ts +67 -0
- package/dist/src/crypto/verify-consumed.js +259 -0
- package/dist/src/crypto/verify-origin.d.ts +50 -0
- package/dist/src/crypto/verify-origin.js +151 -0
- package/dist/src/crypto/verify-publication.d.ts +60 -0
- package/dist/src/crypto/verify-publication.js +150 -0
- package/dist/{defs.d.ts → src/defs.d.ts} +24 -1
- package/dist/{defs.js → src/defs.js} +181 -61
- package/dist/{engine.d.ts → src/engine.d.ts} +105 -9
- package/dist/{engine.js → src/engine.js} +251 -47
- package/dist/{factory.d.ts → src/factory.d.ts} +16 -0
- package/dist/{factory.js → src/factory.js} +16 -4
- package/dist/src/global-config.d.ts +59 -0
- package/dist/src/global-config.js +84 -0
- package/dist/{hub.d.ts → src/hub.d.ts} +280 -31
- package/dist/{hub.js → src/hub.js} +493 -52
- package/dist/src/index.d.ts +47 -0
- package/dist/src/index.js +41 -0
- package/dist/src/install.d.ts +538 -0
- package/dist/src/install.js +1981 -0
- package/dist/src/lock.d.ts +38 -0
- package/dist/src/lock.js +325 -0
- package/dist/src/mcp/serve.d.ts +109 -0
- package/dist/{mcp → src/mcp}/serve.js +335 -75
- package/dist/{mcp → src/mcp}/server.d.ts +6 -9
- package/dist/{mcp → src/mcp}/server.js +18 -10
- package/dist/{model.d.ts → src/model.d.ts} +15 -0
- package/dist/{model.js → src/model.js} +112 -2
- package/dist/src/order-resolver.d.ts +184 -0
- package/dist/src/order-resolver.js +252 -0
- package/dist/src/package-version.d.ts +10 -0
- package/dist/src/package-version.js +42 -0
- package/dist/{paths.d.ts → src/paths.d.ts} +14 -1
- package/dist/{paths.js → src/paths.js} +18 -0
- package/dist/src/schemas/enrollment-grant.v1.schema.json +90 -0
- package/dist/src/schemas/index.d.ts +1416 -0
- package/dist/src/schemas/index.js +31 -0
- package/dist/src/schemas/order.v1.schema.json +106 -0
- package/dist/src/schemas/origin.v1.schema.json +68 -0
- package/dist/src/schemas/policy-floor.v1.schema.json +29 -0
- package/dist/src/schemas/publication.v1.schema.json +31 -0
- package/dist/src/schemas/revocation.v1.schema.json +39 -0
- package/dist/src/schemas/submission.v1.schema.json +61 -0
- package/dist/src/store/def-source.d.ts +52 -0
- package/dist/src/store/def-source.js +335 -0
- package/dist/src/store/index-file.d.ts +69 -0
- package/dist/src/store/index-file.js +151 -0
- package/dist/src/store/index.d.ts +27 -0
- package/dist/src/store/index.js +22 -0
- package/dist/src/store/ingestor.d.ts +43 -0
- package/dist/src/store/ingestor.js +211 -0
- package/dist/src/store/install.d.ts +228 -0
- package/dist/src/store/install.js +555 -0
- package/dist/src/store/instruction-source.d.ts +49 -0
- package/dist/src/store/instruction-source.js +298 -0
- package/dist/src/store/origin-evidence.d.ts +21 -0
- package/dist/src/store/origin-evidence.js +66 -0
- package/dist/src/store/pre-commit-verifier.d.ts +68 -0
- package/dist/src/store/pre-commit-verifier.js +418 -0
- package/dist/src/store/resolve.d.ts +138 -0
- package/dist/src/store/resolve.js +363 -0
- package/dist/src/store/types.d.ts +288 -0
- package/dist/src/store/types.js +356 -0
- package/dist/{types.d.ts → src/types.d.ts} +58 -24
- package/dist/{untar.d.ts → src/untar.d.ts} +8 -23
- package/dist/src/untar.js +38 -0
- package/dist/{util.d.ts → src/util.d.ts} +3 -2
- package/dist/{util.js → src/util.js} +3 -2
- package/dist/{owenwork.d.ts → src/work-settings.d.ts} +22 -22
- package/dist/{owenwork.js → src/work-settings.js} +27 -27
- package/docs/agent-runner.md +86 -0
- package/docs/authoring.md +150 -59
- package/docs/bundles.md +250 -0
- package/docs/cli.md +1758 -163
- package/docs/crypto.md +816 -0
- package/docs/design.md +374 -52
- package/docs/embedding.md +135 -27
- package/docs/wire-contracts.md +380 -0
- package/examples/workflows/{command-worker.yaml → command-executor.yaml} +15 -15
- package/examples/workflows/compile-dev-playbook.yaml +338 -0
- package/examples/workflows/judges/gate-sharpness.md +39 -0
- package/examples/workflows/judges/security.md +34 -0
- package/package.json +22 -8
- package/plugins/claude-code/.claude-plugin/marketplace.json +14 -0
- package/plugins/claude-code/plugin/.claude-plugin/plugin.json +8 -0
- package/plugins/claude-code/plugin/.mcp.json +14 -0
- package/plugins/claude-code/plugin/hooks/hooks.json +26 -0
- package/plugins/claude-code/plugin/hooks/session-end.sh +40 -0
- package/plugins/claude-code/plugin/hooks/session-start.sh +52 -0
- package/plugins/claude-code/plugin/skills/author/SKILL.md +181 -0
- package/plugins/claude-code/plugin/skills/conduct/SKILL.md +106 -0
- package/plugins/claude-code/plugin/skills/shift/SKILL.md +105 -0
- package/plugins/codex/.agents/plugins/marketplace.json +21 -0
- package/plugins/codex/plugins/owenloop/.codex-plugin/plugin.json +7 -0
- package/plugins/codex/plugins/owenloop/.mcp.json +20 -0
- package/plugins/codex/plugins/owenloop/hooks/hooks.json +26 -0
- package/plugins/codex/plugins/owenloop/hooks/session-end.sh +40 -0
- package/plugins/codex/plugins/owenloop/hooks/session-start.sh +52 -0
- package/plugins/codex/plugins/owenloop/skills/author/SKILL.md +181 -0
- package/plugins/codex/plugins/owenloop/skills/conduct/SKILL.md +106 -0
- package/plugins/codex/plugins/owenloop/skills/shift/SKILL.md +105 -0
- package/dist/add.d.ts +0 -384
- package/dist/add.js +0 -834
- package/dist/cli.js +0 -3270
- package/dist/index.d.ts +0 -32
- package/dist/index.js +0 -23
- package/dist/lock.d.ts +0 -80
- package/dist/lock.js +0 -217
- package/dist/mcp/serve.d.ts +0 -84
- package/dist/untar.js +0 -164
- /package/dist/{schema.d.ts → src/schema.d.ts} +0 -0
- /package/dist/{schema.js → src/schema.js} +0 -0
- /package/dist/{store.d.ts → src/store.d.ts} +0 -0
- /package/dist/{store.js → src/store.js} +0 -0
- /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
|
|
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
|
|
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,
|
|
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
|
|
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 {
|
|
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.
|
|
47
|
-
*
|
|
48
|
-
*
|
|
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
|
|
52
|
-
* Rung 3
|
|
53
|
-
*
|
|
54
|
-
*
|
|
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
|
-
*
|
|
57
|
-
*
|
|
58
|
-
*
|
|
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
|
|
94
|
+
return normalizeOrigin(explicit);
|
|
65
95
|
}
|
|
66
96
|
catch (e) {
|
|
67
97
|
throw new CliError(e.message);
|
|
68
98
|
}
|
|
69
99
|
}
|
|
70
|
-
const
|
|
71
|
-
if (
|
|
72
|
-
const
|
|
73
|
-
|
|
74
|
-
|
|
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
|
-
|
|
81
|
-
|
|
82
|
-
|
|
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
|
|
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 "
|
|
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
|
|
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' },
|
|
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:
|
|
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/
|
|
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
|
|
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: {
|
|
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: '
|
|
401
|
-
description: "Your principal's registered
|
|
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/
|
|
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
|
|
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 `
|
|
429
|
-
* builds `{name,
|
|
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
|
|
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
|
-
|
|
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
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
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
|
|
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. `
|
|
476
|
-
// /agentId/
|
|
477
|
-
const
|
|
478
|
-
return textResult({ name,
|
|
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
|
|
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
|
-
|
|
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:
|
|
541
|
-
*
|
|
542
|
-
*
|
|
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
|
|
546
|
-
|
|
547
|
-
|
|
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:
|
|
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
|
|
6
|
-
* `src/mcp/server.ts`
|
|
7
|
-
* `textResult` / the error-code consts / `LineStream`).
|
|
8
|
-
*
|
|
9
|
-
*
|
|
10
|
-
*
|
|
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
|