agent-trellis 0.11.0 → 0.13.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 (52) hide show
  1. package/dist/adapters/mcpPlan.d.ts +1 -0
  2. package/dist/adapters/mcpPlan.js +14 -5
  3. package/dist/cli.js +18 -2
  4. package/dist/commands/doctor.d.ts +22 -2
  5. package/dist/commands/doctor.js +51 -3
  6. package/dist/commands/mcp.d.ts +13 -2
  7. package/dist/commands/mcp.js +42 -5
  8. package/dist/commands/mcpAuth.d.ts +6 -0
  9. package/dist/commands/mcpAuth.js +38 -10
  10. package/dist/commands/mcpGateway.d.ts +1 -0
  11. package/dist/commands/mcpGateway.js +39 -11
  12. package/dist/commands/mcpRenew.d.ts +52 -0
  13. package/dist/commands/mcpRenew.js +104 -0
  14. package/dist/core/canonical.d.ts +1 -0
  15. package/dist/core/canonical.js +8 -3
  16. package/dist/core/types.d.ts +4 -1
  17. package/dist/core/types.js +3 -0
  18. package/dist/lib/agentBridgeProvider.d.ts +1 -1
  19. package/dist/lib/gatewayBackend.d.ts +16 -0
  20. package/dist/lib/gatewayBackend.js +25 -5
  21. package/dist/lib/mcpConnect.d.ts +6 -3
  22. package/dist/lib/mcpConnect.js +8 -6
  23. package/dist/lib/mcpRuntime.d.ts +6 -2
  24. package/dist/lib/mcpRuntime.js +39 -29
  25. package/dist/lib/mcpStatusProvider.d.ts +36 -2
  26. package/dist/lib/mcpStatusProvider.js +27 -4
  27. package/dist/lib/memoryProvider.d.ts +1 -1
  28. package/dist/lib/oauth/callbackPage.d.ts +11 -0
  29. package/dist/lib/oauth/callbackPage.js +89 -0
  30. package/dist/lib/oauth/discovery.d.ts +1 -0
  31. package/dist/lib/oauth/discovery.js +2 -0
  32. package/dist/lib/oauth/flow.d.ts +4 -0
  33. package/dist/lib/oauth/flow.js +59 -19
  34. package/dist/lib/oauth/refresh.d.ts +1 -0
  35. package/dist/lib/oauth/refresh.js +3 -1
  36. package/dist/lib/oauth/renew.d.ts +75 -0
  37. package/dist/lib/oauth/renew.js +86 -0
  38. package/dist/lib/oauth/store.d.ts +2 -0
  39. package/dist/lib/runtimeControlProvider.d.ts +1 -1
  40. package/dist/lib/skillManifest.d.ts +1 -0
  41. package/dist/lib/skillManifest.js +1 -1
  42. package/dist/lib/skillProvider.d.ts +1 -1
  43. package/dist/lib/taskProvider.d.ts +1 -1
  44. package/dist/lib/upstreamResources.d.ts +23 -0
  45. package/dist/lib/upstreamResources.js +192 -0
  46. package/dist/pi-bridge/bundle.js +37558 -19584
  47. package/docs/architecture.md +14 -13
  48. package/docs/getting-started.md +9 -0
  49. package/docs/mcp-authorization-ownership.md +78 -0
  50. package/docs/mcp-oauth-renewal.md +88 -0
  51. package/docs/skills-over-mcp.md +43 -31
  52. package/package.json +5 -2
@@ -261,9 +261,9 @@ reach such a server at all.
261
261
 
262
262
  Gateway mode does not automatically take ownership of OAuth servers. Mark a
263
263
  server explicitly with `auth: oauth` (or `trellis mcp set <name> --auth oauth`)
264
- and gateway planning keeps it direct. This preserves the native Agent OAuth
265
- flow for Claude Code/Codex/Kiro; Pi's bridge is the client for its direct OAuth
266
- connection and may use Trellis's own OAuth store. Trellis never infers this
264
+ and gateway/runtime planning keeps it native. This preserves each Agent's own
265
+ OAuth identity. Only `auth: { kind: oauth, owner: trellis }` explicitly opts into
266
+ Trellis hosting, with a gateway/runtime route required. Trellis never infers this
267
267
  classification from a URL or a transient 401.
268
268
 
269
269
  The classification optionally carries pre-registered client metadata, for
@@ -288,18 +288,19 @@ be pre-filled.
288
288
  Trellis still implements the client half itself — discovery (RFC 8414 /
289
289
  RFC 9728), dynamic client registration (RFC 7591), authorization code with
290
290
  PKCE S256 (RFC 7636), and the refresh grant — in `src/lib/oauth/`, but that
291
- path is currently used for Pi/direct bridge connections rather than silently
292
- replacing native Agent authorization.
291
+ path is used for explicitly hosted connections. It never imports or silently
292
+ replaces native Agent authorization. See
293
+ [MCP authorization ownership](mcp-authorization-ownership.md).
293
294
 
294
295
  Two rules shape it, both from the constraint that the gateway is spawned
295
296
  silently by an agent with no terminal attached:
296
297
 
297
- - **Only an explicit human authorization command opens a browser.** Native
298
- clients use their own login command for direct OAuth entries. Pi's direct
299
- bridge uses `trellis mcp auth <server>`. The gateway never initiates an
300
- interactive flow and never connects an OAuth-marked server.
298
+ - **Only an explicit human action opens a browser.** Native clients use their
299
+ own authorization entry. Trellis-hosted connections can use the desktop
300
+ Authorize action or `trellis mcp auth <server>`. The gateway never initiates
301
+ an interactive flow and excludes Agent-owned OAuth servers.
301
302
  - **Refreshing is silent, and serialized by a lock.** A `refresh_token`
302
- grant needs neither a browser nor a callback, so the Pi direct bridge can
303
+ grant needs neither a browser nor a callback, so the hosted gateway can
303
304
  do it at connect time. The lock (`~/.trellis/mcp/oauth/<name>.lock`) exists
304
305
  because most authorization servers rotate the refresh token and
305
306
  invalidate its predecessor — two concurrent refreshes would leave one
@@ -312,8 +313,8 @@ non-interactive, no-GUI-session context the gateway runs in — measured,
312
313
  not assumed).
313
314
 
314
315
  In direct mode nothing here changes: each agent keeps using its own native
315
- OAuth flow. In gateway mode, an OAuth-marked server is also kept direct; only
316
- ordinary MCP servers enter the gateway.
316
+ OAuth flow. Gateway/runtime mode retains native entries for Agent-owned OAuth;
317
+ ordinary and explicitly Trellis-owned servers enter the gateway.
317
318
 
318
319
  ## MCP gateway mode
319
320
 
@@ -362,7 +363,7 @@ could reach disk.
362
363
  **What it changes for the agents:** Codex's single-`bearer_token_env_var`
363
364
  limitation stops applying, because Codex no longer receives any server's
364
365
  `headers` — the gateway holds them. OAuth-marked servers are intentionally
365
- kept direct; ordinary remote servers remain shared through the gateway. An
366
+ kept native by default; explicit Trellis ownership enables hosted OAuth. An
366
367
  upstream tool keeps its original name when that name is unique and longer than
367
368
  the short-name threshold; generic short names receive a compact
368
369
  `<server>__<tool>` prefix even when unique. A tool already carrying its source
@@ -907,6 +907,15 @@ An Agent can call the read-only `trellis.mcp.status` Runtime tool to explain
907
907
  this partial state to the user. It reports unavailable or authorization-
908
908
  required servers and gives the next safe action, such as `trellis mcp auth
909
909
  figma`, without exposing tokens or opening a browser from the Agent process.
910
+ Each connected upstream also carries a structured `toolCount`, and an `oauth`
911
+ section reports credential health with explicit ownership: Trellis-owned
912
+ OAuth servers (which connect through the gateway on a Trellis-store token)
913
+ report `valid` / `no-token` / `expired-renewable` / `needs-auth` /
914
+ `unreadable` with `expiresAt` when known; agent-owned servers report
915
+ `agent-managed`, since their authorization lives in the Agent's own client
916
+ and is never inferred from Trellis's store. The classification is read-only
917
+ and shared with `trellis mcp renew` and `trellis doctor`, so the three can
918
+ never disagree.
910
919
 
911
920
  This command only applies to `http`/`sse` servers. stdio servers get
912
921
  their credentials from `env`/`env_aliases` as described above; running
@@ -0,0 +1,78 @@
1
+ # MCP authorization ownership
2
+
3
+ Each Agent-owned connection is authorized by that Agent. Trellis does not read,
4
+ copy or refresh its credentials. Existing `auth: oauth` and metadata-bearing
5
+ OAuth entries default to `owner: agent`. Runtime delivery also retains these
6
+ native OAuth entries beside the Trellis runtime.
7
+
8
+ The MCP desktop view labels native state as unknown and shows the relevant Agent
9
+ entry or guidance. A stray Trellis token does not change that state. The view's
10
+ credential badge describes stored credentials, not connection health.
11
+
12
+ ## Explicit Trellis hosting
13
+
14
+ For providers that accept a Trellis registration, opt in per server:
15
+
16
+ ```yaml
17
+ auth:
18
+ kind: oauth
19
+ owner: trellis
20
+ # Optional provider-published client identifier:
21
+ # client_id: YOUR_REGISTERED_CLIENT_ID
22
+ # client_secret_env: YOUR_CLIENT_SECRET_VARIABLE
23
+ ```
24
+
25
+ Or run `trellis mcp set NAME --auth oauth --auth-owner trellis`, then sync.
26
+ Gateway or runtime delivery must be enabled for the receiving Agent. Plain
27
+ direct routing reports a conflict rather than moving Trellis's identity into a
28
+ native connection. `--auth-owner agent` returns the server to native ownership.
29
+ The desktop owner selector previews a plan and requires Apply before changing
30
+ canonical configuration and syncing it.
31
+
32
+ Remote connections without an OAuth classification can choose an owner directly
33
+ in the desktop selector. Its No OAuth classification option clears that setting;
34
+ neither choice starts a grant automatically.
35
+
36
+ The hosted desktop Authorize button launches the existing PKCE flow in the
37
+ system browser. Progress is observable, cancellation closes the callback, and
38
+ timeouts/provider failures permit retry. Repeated clicks share one active job.
39
+ Tokens are saved in the existing per-server 0600 store, never sent to the UI.
40
+ A changed endpoint/auth configuration during the grant prevents persistence.
41
+ Authorization actions require a trusted desktop/development Origin.
42
+
43
+ New credentials retain their MCP resource and authorization-server issuer.
44
+ Authorization, exchange and refresh send the resource indicator; callback issuer
45
+ is checked when supplied or advertised as required. A changed resource cannot
46
+ receive its previous bound credential. The final save shares the refresh lock,
47
+ so a cancelled grant cannot overwrite a concurrent refresh.
48
+
49
+ The gateway can silently refresh its own hosted credentials; it never opens a
50
+ browser. Agents with native connections continue using their own flows.
51
+
52
+ ## Browser callback feedback
53
+
54
+ The local callback page shows a compact Trellis/service label, one status message,
55
+ one short instruction and a close action, with Chinese or English copy based on
56
+ the browser's preferred language. Receiving an
57
+ authorization response is an intermediate step: validation, token exchange and
58
+ credential storage still determine the final result shown in Trellis or the
59
+ terminal. Cancellation, provider errors and incomplete responses have separate
60
+ messages and guidance for starting again.
61
+
62
+ The page uses no external assets and does not display authorization parameters
63
+ or raw provider descriptions. Responses disable caching and referrer disclosure;
64
+ when JavaScript is available, the page also removes the query and fragment from
65
+ the current browser history entry. The close action offers manual-close guidance
66
+ when a browser blocks it, and manual guidance remains visible without JavaScript.
67
+
68
+ ## Verification
69
+
70
+ Run core tests and typecheck, GUI sidecar tests/typecheck and GUI smoke tests.
71
+ `npm run test:oauth-browser --workspace @trellis/gui` additionally uses installed
72
+ Google Chrome headlessly with a local authorization-server fixture. Set
73
+ `TRELLIS_OAUTH_BROWSER_EXECUTABLE` to use a compatible Chromium executable instead.
74
+ It exercises real browser CORS, PKCE callback, progress, cancellation, retry,
75
+ owner confirmation and callback feedback without contacting a real provider or
76
+ using personal credentials. Set `TRELLIS_OAUTH_SCREENSHOTS` to an output directory
77
+ to save callback desktop/mobile previews during that run.
78
+ Desktop packaging and installed-app acceptance happen after these checks.
@@ -0,0 +1,88 @@
1
+ # Scheduled OAuth renewal — `trellis mcp renew`
2
+
3
+ The gateway and the pi bridge already refresh OAuth tokens silently before
4
+ every upstream call. `trellis mcp renew` moves that renewal *earlier*: run
5
+ on a schedule, it refreshes whatever is expiring and reports — with a
6
+ non-zero exit code — anything that needs a human, before an Agent session
7
+ discovers it as a 401.
8
+
9
+ ```
10
+ trellis mcp renew # refresh what's expiring, report health
11
+ trellis mcp renew --dry-run # report only; no token-endpoint call
12
+ trellis mcp renew --json # machine-readable (no credential material)
13
+ ```
14
+
15
+ Scope is canonical OAuth servers with an explicit `owner: trellis` —
16
+ classification is explicit (mcp-auth-routing-policy), and ownership decides
17
+ whose problem the credential is (trellis-desktop-oauth-ownership): an
18
+ agent-owned server (the default, e.g. scalar `auth: oauth`) is authorized by
19
+ the Agent's own client, never reads Trellis's token store, and is neither
20
+ renewed nor reported here. The command never opens a browser and never
21
+ performs an initial grant; that remains `trellis mcp auth <name>`
22
+ (mcp-gateway-hosting design.md D9). Exit code: `0` when every Trellis-owned
23
+ server is valid or refreshed, `1` when any needs `trellis mcp auth`, has
24
+ never been authorized, or has an unreadable credential file.
25
+
26
+ `trellis doctor` reports the same per-server health read-only (no network,
27
+ no writes) and surfaces an `oauth-expired` finding — contributing to a
28
+ non-zero doctor exit — for credentials that are expired or absent.
29
+
30
+ ## launchd setup (macOS)
31
+
32
+ Trellis has no daemon; periodic renewal belongs to the platform
33
+ scheduler. Save this as `~/Library/LaunchAgents/com.trellis.mcp-renew.plist`,
34
+ adjusting the `trellis` path (`which trellis`):
35
+
36
+ ```xml
37
+ <?xml version="1.0" encoding="UTF-8"?>
38
+ <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
39
+ <plist version="1.0">
40
+ <dict>
41
+ <key>Label</key>
42
+ <string>com.trellis.mcp-renew</string>
43
+ <key>ProgramArguments</key>
44
+ <array>
45
+ <string>/usr/local/bin/trellis</string>
46
+ <string>mcp</string>
47
+ <string>renew</string>
48
+ <string>--json</string>
49
+ </array>
50
+ <key>StartInterval</key>
51
+ <integer>21600</integer>
52
+ <key>ThrottleInterval</key>
53
+ <integer>600</integer>
54
+ <key>StandardOutPath</key>
55
+ <string>/tmp/trellis-mcp-renew.log</string>
56
+ <key>StandardErrorPath</key>
57
+ <string>/tmp/trellis-mcp-renew.log</string>
58
+ </dict>
59
+ </plist>
60
+ ```
61
+
62
+ Then:
63
+
64
+ ```
65
+ launchctl bootstrap gui/$(id -u) ~/Library/LaunchAgents/com.trellis.mcp-renew.plist
66
+ launchctl kickstart gui/$(id -u)/com.trellis.mcp-renew # run once now
67
+ launchctl bootout gui/$(id -u)/com.trellis.mcp-renew # uninstall
68
+ ```
69
+
70
+ Why these knobs:
71
+
72
+ - **`ThrottleInterval`** (design.md D3) caps how close together runs may
73
+ be. A machine waking from sleep with a launchd backlog runs once, not N
74
+ times — refresh-endpoint hammering is the failure mode that gets refresh
75
+ tokens revoked by rate-limiting providers, which is worse than the
76
+ disease this job exists to prevent.
77
+ - **`StartInterval` of 6h** is comfortably inside typical refresh-token
78
+ lifetimes (days to months) while keeping token-endpoint traffic near
79
+ zero: a valid token is a no-op *read*, so most runs make no network
80
+ calls at all.
81
+ - **Overlapping runs are safe**: refresh is serialized by the per-server
82
+ lock (`src/lib/oauth/lock.ts`). A second concurrent run waits, then
83
+ reads the token the first one just wrote.
84
+ - **`--json` to a log** gives you a parseable trail. A `1` exit means
85
+ "something needs `trellis mcp auth <name>`" — the JSON names which.
86
+
87
+ Check on demand: `trellis doctor` shows the same per-server credential
88
+ health.
@@ -24,8 +24,9 @@ The existing surface is unchanged: `trellis.skills.search|read|read_file` and
24
24
  ## The manifest is computed from the bytes served
25
25
 
26
26
  `digest` is `sha256:` plus 64 lowercase hex characters of the raw bytes;
27
- `size` is their length. The same reader produces the manifest and the
28
- `resources/read` response, so they cannot disagree. Invalid UTF-8 is returned as
27
+ `size` is their length. The manifest and `resources/read` use the same bounded
28
+ byte reader. Hosts still verify the retained manifest: a file can change between
29
+ listing and reading. Invalid UTF-8 is returned as
29
30
  a base64 `blob` rather than lossy `text`, so the bytes a host verifies are the
30
31
  bytes that were hashed.
31
32
 
@@ -48,32 +49,43 @@ rewrite entry and content together. A matching digest tells a host the bytes
48
49
  match the manifest; it says nothing about whether the content is safe. Nothing in
49
50
  Trellis treats a match as an authorization.
50
51
 
51
- ## The extension is not declared yet
52
-
53
- The extension is declared through `server/discover`, introduced with protocol
54
- revision 2026-07-28. The MCP SDK Trellis uses speaks at most 2025-11-25 and has
55
- neither `server/discover` nor `skills/*`, and the specification defines no
56
- declaration for the `initialize` handshake. Declaring it in another field would
57
- invent a protocol, and a conforming client only issues `skills/list` after
58
- observing a declaration anyway.
59
-
60
- So on today's SDK the runtime declares nothing, answers `skills/list` and
61
- `skills/get` through the SDK's fallback for unregistered methods, and serves
62
- `skill://` as ordinary resources — which the specification expressly allows. Once
63
- the SDK exposes `server/discover`, the declaration is a one-place change. Any other
64
- unknown method still gets JSON-RPC `-32601`.
65
-
66
- ## Relaying skills from upstream servers is not implemented
67
-
68
- Today an upstream server's skills are not relayed — the gateway backend
69
- aggregates tools only. When a change adds that, it must:
70
-
71
- - identify a skill by (upstream label, URI) together, never by URI alone, with a
72
- namespace per upstream;
73
- - never let an upstream skill shadow a canonical skill or another upstream's;
74
- - bind reads to the originating upstream, with no cross-upstream reads;
75
- - pass the upstream manifest through unchanged or re-derive it from the relayed
76
- bytes — never pair an upstream digest with different bytes;
77
- - not write an upstream skill into `~/.trellis/skills` automatically. The
78
- specification requires per-skill user approval before such content is used, and
79
- materializing it would bypass that.
52
+ ## Discovery and protocol compatibility
53
+
54
+ The runtime uses the official TypeScript SDK v2 serving entry. Modern clients
55
+ discover resources and the `io.modelcontextprotocol/skills` extension through
56
+ `server/discover`; legacy clients can still initialize and call existing tools
57
+ and resources. Merely constructing a v2 Server is not sufficient: the runtime
58
+ explicitly uses `serveStdio` to select modern or legacy behavior.
59
+
60
+ Skills list/get are registered custom methods with parameter/result schemas.
61
+ The SDK handles modern request metadata, result discrimination and server
62
+ identity. Unknown methods still return JSON-RPC `-32601`. A legacy host can use
63
+ ordinary resources/tools even if it does not understand the Skills extension.
64
+
65
+ ## Upstream resources and skills
66
+
67
+ The gateway negotiates modern or legacy upstream behavior. Legacy HTTP+SSE uses
68
+ its existing transport. An upstream with resources but no tools remains valid.
69
+ Declared modern Skills catalogs are paginated, validated and relayed:
70
+
71
+ - URIs use a reversible `trellis-upstream://` namespace per source, preserving
72
+ final path segments and relative references. Provenance records the original
73
+ server label and URI. Canonical and equal-named upstream skills stay distinct.
74
+ - Listing does not fetch file content. Supporting files become readable from a
75
+ complete manifest, even when absent from `resources/list`; direct `skills/get`
76
+ also works for unlisted skills.
77
+ - Reads go back to the registered source and preserve exact bytes, digest and
78
+ size. Skill content is rejected if digest, size or SKILL.md frontmatter differ
79
+ from the entry. Refresh the entry before reading changed content.
80
+ - Dynamic skill manifests are currently declined with a diagnostic. Manifests
81
+ are bounded to 512 files and 16 MiB per skill; unsupported or malformed entries
82
+ do not remove other skills.
83
+ - No upstream skill is installed into `~/.trellis/skills`, activated, or given
84
+ execution permissions by the relay. The consuming host retains its own approval
85
+ and integrity checks.
86
+
87
+ Authorization ownership and the desktop flow are documented in
88
+ [MCP authorization ownership](mcp-authorization-ownership.md).
89
+
90
+ Protocol references: [SDK v2 migration](https://ts.sdk.modelcontextprotocol.io/v2/migration/support-2026-07-28)
91
+ and [Skills extension](https://modelcontextprotocol.io/extensions/skills/overview).
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "agent-trellis",
3
- "version": "0.11.0",
3
+ "version": "0.13.0",
4
4
  "description": "A unified Code Agent Runtime for Skills, MCP, Memory, and shared instructions across Claude Code, Codex, Kiro, pi, Kimi Code, and ZCode.",
5
5
  "license": "MIT",
6
6
  "author": "Paul Leo",
@@ -61,7 +61,10 @@
61
61
  },
62
62
  "dependencies": {
63
63
  "@clack/prompts": "^1.8.1",
64
+ "@modelcontextprotocol/client": "^2.3.1",
64
65
  "@modelcontextprotocol/sdk": "^1.30.0",
65
- "yaml": "^2.9.1"
66
+ "@modelcontextprotocol/server": "^2.3.1",
67
+ "yaml": "^2.9.1",
68
+ "zod": "^4.6.5"
66
69
  }
67
70
  }