Skip to content
This repository was archived by the owner on Sep 2, 2026. It is now read-only.

[Spec] Stage authority & in-app MCP server - #61

Merged
64ix merged 13 commits into
mainfrom
spec/23-stage-authority-mcp
Aug 24, 2026
Merged

64ix merged 13 commits into
mainfrom
spec/23-stage-authority-mcp

Conversation

@64ix

@64ix 64ix commented Aug 24, 2026 •

Copy link
Copy Markdown
Owner
Files Added Deleted Net
Test 5 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​1277 0 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​1277
Prod 18 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​1295 $\color{#cf222e}{\Huge{\mathbf{−}}}$​49 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​1246

Summary

Implements spec #23: one pure authority guard deciding which caller (agent vs human) may set which workflow stage, exposed through CLI parity (orca worktree set --stage) and Orca's first in-app MCP server. shipped is refused fail-closed for agents with a steering message; the human can place any stage from UI paths, including de-shipping.

Spec & Tickets

Criteria

Criterion Verdict Evidence
Guard matrix tested: every stage × agent/human × governing facts ✅ stage-write-authority.test.ts — 48-cell matrix (7 stages + null-clear × agent/human × no-facts/open-PR/unconsumed-merge)
Agent shipped refused with steering message, no state change ✅ verbatim SHIPPED_STAGE_STEERING_MESSAGE; RPC test asserts updateManagedWorktreeMeta not called
Refusal before any write (fail-closed) ✅ assertStageWriteAllowed first statement in worktree.set / folderWorkspace.update handlers; spy-proofed in tests
Human can set any stage incl. shipped / de-ship via UI paths ✅ guard only wired into RPC handlers; renderer direct IPC (worktrees:updateMeta) untouched
CLI enforces same guard over SSH/remote workspaces ✅ orca worktree set --stage <id|null>; guard lives server-side in RPC; stage_authority_refused in passthrough codes reaches remote shims
Guard consumable as pure module ✅ src/shared/stage-authority/stage-write-authority.ts — pure, serializable decisions; reused by MCP ticket #43
Agent declares stages via MCP tools without asking ✅ declare_stage tool, auto-approved; manifest served by tools/list with zero approval flow (orca-mcp-server.test.ts)
Wrong/missing bearer token rejected ✅ real-server tests over node:http: 401 on wrong + missing token before routing/body parsing
Tools auto-approved and discoverable on intent ✅ tools/list manifest callable immediately post-boot; declare_stage description carries the shipped rule at discovery time
Session identity workspace-scoped ✅ mcp-session-id header binding at initialize; test proves two sessions bound to different workspaces never cross wires
Handler refusals tested at tool-handler boundary ✅ mcp-stage-tools.test.ts: shipped refusal before write with runtime spies untouched; steering message pinned to shared guard module output

Arbitrations (Problem → Resolution)

  • Human caller-kind over RPC: remote/mobile human surfaces stay fail-closed ('agent') until the board specs land; local desktop UI writes via direct IPC which bypasses the guard.
  • "List tasks" = read_board: tasks are workspaces in Orca's model; a separate task-listing tool would duplicate it.
  • MCP discovery publishes a dedicated orca-mcp.json (runtime metadata file is owned/rewritten by runtime-rpc and would clobber merged-in fields).
  • Folder link_issue requires title+url because folder workspaces persist full provider items; git worktrees take just the number.

Changes

Stage authority guard (#39)

  • src/shared/stage-authority/stage-write-authority.ts — pure decision gate: (caller kind, requested stage, governing facts) → allowed/refused + explanation; agents declaring shipped are refused with the steering message regardless of facts.
  • src/main/runtime/rpc/methods/worktree.ts, folder-workspace.ts — guard asserted before any write in worktree.set and folderWorkspace.update.
  • src/main/runtime/rpc/errors.ts — stage_authority_refused joins structured passthrough codes so CLI/SSH shims see typed refusals.
  • src/cli/ — orca worktree set --stage <id|null> flag (tri-state: absent = no change, null = clear), registry parity + help text.

Updated as tickets merge.

In-app MCP server (#43)

  • src/main/mcp/ — stdlib-only (node:http/node:crypto) loopback JSON-RPC server: bearer auth before routing (digest timingSafeEqual), 1 MiB body cap, notifications → 202; tools declare_stage / link_issue / read_board; workspace-bound sessions with idle TTL; per-launch token + endpoint published to <userData>/orca-mcp.json (0600).
  • src/main/index.ts — server constructed beside the runtime RPC, started in headless + desktop paths, teardown joined to the quit barrier.
  • docs/reference/mcp-server.md — discovery/auth/tools reference.

Code-review fixes

  • Folder link_issue derives the provider from the URL host (github/gitlab/jira/linear) and fails closed on unrecognized hosts instead of stamping github.
  • Guard explanations are honest when no provider facts were supplied ("declared implementing (no provider facts consulted)").
  • Dead code removed (McpSessionRegistry.size(), over-exposed metadata path helper), duplicated expression hoisted, comment trims, deferred human-caller-kind wiring documented on StageWriteCallerKind.

QA Plan

  • pnpm test green
  • orca worktree set --stage spec moves a card; --stage shipped is refused with the steering message and no state change
  • MCP server answers initialize/tools/list with a valid bearer token; 401 on wrong/missing token
  • MCP declare_stage with shipped returns refusal text and leaves storage untouched
  • Mobile/web clients render the new stage_authority_refused failure sanely (generic typed failure, no crash)

64ix added 13 commits August 24, 2026 11:25
decideStageWrite/assertStageWriteAllowed gate workflowStage writes by
caller kind: agents may declare working stages and clear but never
shipped (fail-closed with steering message); humans are unrestricted.
Governing facts shape only the explanation and effective stage via the
existing derivation engine.
…e.update (#39)

Guard runs in the handler before any write; agent shipped attempts fail
closed with the steering message as a stage_authority_refused error.
Human UI paths (direct IPC, service layer) stay unrestricted.
--stage <id|null> maps onto the workflowStage RPC param (null clears,
absent leaves unchanged); refusal errors from the host surface verbatim.
No client-side guard: authority lives on the RPC so SSH/remote shims
inherit it.
HTTP JSON-RPC server in the Electron main process exposing agent tools
(declare_stage, link_issue, read_board) behind a per-launch bearer token.
Every stage write routes through assertStageWriteAllowed with callerKind
'agent' BEFORE any store mutation, so shipped refusals surface the steering
message fail-closed. Sessions bind a workspace selector at initialize;
endpoint+token publish to orca-mcp.json for terminal-agent discovery.
Drops an unused protocol constant, routes notification detection through
isNotification(), and adds docs/reference/mcp-server.md covering endpoint
discovery via orca-mcp.json, bearer auth, session binding and stage
authority.
Track the MCP server reference (endpoint+token via orca-mcp.json, bearer
auth, session binding, shipped authority) by allow-listing it like the
other durable reference docs.
…code trims (#43)

- folder link_issue derives provider from URL host and fails closed on unknown hosts
- stage authority explains "no provider facts consulted" when facts absent
- drop unused McpSessionRegistry.size(), unexport getOrcaMcpMetadataPath
- hoist duplicated linkedIssue expression; trim overlong comments
…stituents

string literal tags in 'string | too_large | unreadable' are absorbed by
string, tripping oxlint type-aware rule; failures now ride a kind/reason
discriminant so reasons stay distinct types. Behavior unchanged.
@64ix
64ix marked this pull request as ready for review August 24, 2026 16:35
@64ix
64ix merged commit 1d6b730 into main Aug 24, 2026
101 checks passed
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

In-app MCP server for stage tools Stage authority guard & RPC/CLI enforcement [Spec] Stage authority & in-app MCP server

1 participant