@rhei-team/rhei 1.0.0-beta.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.
- package/README.md +1048 -0
- package/bin/rhei-mcp.js +3 -0
- package/dist/index.d.ts +12 -0
- package/dist/index.js +86366 -0
- package/dist/premium/contracts.d.ts +445 -0
- package/dist/premium/contracts.js +97 -0
- package/dist/vendor/rhei-core/briefs.js +1276 -0
- package/dist/vendor/rhei-core/codeAgent.js +615 -0
- package/dist/vendor/rhei-core/codeEditSession.js +293 -0
- package/dist/vendor/rhei-core/codeIntelligence.js +4287 -0
- package/dist/vendor/rhei-core/codeMarket.js +8946 -0
- package/dist/vendor/rhei-core/codeReviewIntelligence.js +5918 -0
- package/dist/vendor/rhei-core/codeSemantics.js +172427 -0
- package/dist/vendor/rhei-core/codeStory.js +667 -0
- package/dist/vendor/rhei-core/codeStrategyPlan.js +663 -0
- package/dist/vendor/rhei-core/codeTrail.js +2781 -0
- package/dist/vendor/rhei-core/codeWorkHandoff.js +281 -0
- package/dist/vendor/rhei-core/contextQuery.js +1119 -0
- package/dist/vendor/rhei-core/contextRouting.js +2052 -0
- package/dist/vendor/rhei-core/evidenceLedger.js +5336 -0
- package/dist/vendor/rhei-core/executionSafety.js +0 -0
- package/dist/vendor/rhei-core/goalIntelligence.js +2218 -0
- package/dist/vendor/rhei-core/model-lanes.js +75 -0
- package/dist/vendor/rhei-core/now.js +127 -0
- package/dist/vendor/rhei-core/package.json +29 -0
- package/dist/vendor/rhei-core/programPlan.js +3153 -0
- package/dist/vendor/rhei-core/search.js +196 -0
- package/dist/vendor/rhei-core/serviceIntelligence.js +1734 -0
- package/dist/vendor/rhei-core/workflowPlan.js +1660 -0
- package/package.json +41 -0
package/README.md
ADDED
|
@@ -0,0 +1,1048 @@
|
|
|
1
|
+
# Rhei MCP Server
|
|
2
|
+
|
|
3
|
+
Local-first MCP server for Rhei Code Context and governed agent handoffs.
|
|
4
|
+
|
|
5
|
+
The default mode requires no remote credentials. It exposes Code Context as the shared agent-facing primitive so Codex CLI, other MCP clients, web Rhei, and local Rhei can all consume the same `AgentWorkBriefV1` handoff instead of passing raw graph output around.
|
|
6
|
+
|
|
7
|
+
The local path follows current MCP TypeScript SDK practice: high-level `McpServer.registerTool`, Zod input/output schemas, read-only tool annotations, `structuredContent` in tool results, and stderr-only server logging so stdout stays reserved for JSON-RPC.
|
|
8
|
+
|
|
9
|
+
## Current Center Of Gravity
|
|
10
|
+
|
|
11
|
+
The current code-intelligence center of gravity is the chain from goal to bounded context, workflow, proof, review, trail, and governed acceptance. See `../../docs/analysis/code-intelligence-center-of-gravity-2026-05-20.md`, especially `MCP And Code Intelligence Spine`, for the compact architecture note.
|
|
12
|
+
|
|
13
|
+
```text
|
|
14
|
+
rhei_code_goal / rhei_context_builder / rhei_code_context_for_goal
|
|
15
|
+
-> ProgramPlanV1 when program-scale
|
|
16
|
+
-> Auto-Sliced ContextPacketV1
|
|
17
|
+
-> ContextReceiptV1 when exported for agent handoff
|
|
18
|
+
-> AgentWorkBriefV1 + CodeContextAgentSurfaceV1
|
|
19
|
+
-> CodeStrategyPlanV1 -> WorkflowPlanV1 -> CodeWorkHandoffV1
|
|
20
|
+
-> RheiCodeSessionV1
|
|
21
|
+
-> proposal / impact / proof / dry-run / diff / validation
|
|
22
|
+
-> ReviewDiff / PR Review / story-scoped CodeTrail / run graph / AgentEditSession
|
|
23
|
+
-> opt-in local Codex or Modal sandbox result import
|
|
24
|
+
-> Writer Arbitration or Discard
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
The ProgramPlan-to-Auto-Sliced-ContextPacket bridge is now a named MCP transition. Program plans remain inventory/routing evidence, and `rhei_code_context_for_goal` exposes `autoSlicedContextPacketTransition` so agents can see the first-safe-workstream handoff, target auto-sliced packet id, missing-ref receipt, truncation receipt, failure receipt, and no-authority guardrails before implementation starts.
|
|
28
|
+
|
|
29
|
+
### Architecture Refactor Notes
|
|
30
|
+
|
|
31
|
+
- The local code-context surface is split into intent-named modules under `src/codeContextTools/` and re-exported by the small `src/codeContextTools.ts` barrel. Keep future seams named by responsibility (`codeGoal*`, `codeIo*`, `toolDefinitions`, `toolDispatcher*`) rather than numbered chunks.
|
|
32
|
+
- `@rhei/core` owns portable `codeSession` and `contextQuery` contracts. MCP adapts those contracts into local receipts/tool payloads; Convex remains the owner of persisted session state and write-authority checks.
|
|
33
|
+
- Runtime freshness is observable through the MCP runtime fingerprint and `reloadStatus`. After changing MCP source or beta package contents, restart/reconnect the MCP client and verify the new `pid`/`loadedAt` reports `status: current` before trusting tool schemas.
|
|
34
|
+
- Context Query handoff is read-only provenance. Web may pass the envelope into workroom `contextHints`, but `advisoryOnly`, `authorizesExecution: false`, and `mutatesWorkingSet: false` semantics must stay intact.
|
|
35
|
+
|
|
36
|
+
## Local Tools
|
|
37
|
+
|
|
38
|
+
Closed beta users should run the default `mcp:rhei` server. That public profile exposes the generic 20-tool surface: `goal`, `context_builder`, `workspace_context`, `manage_selection`, `read_file`, `file_search`, `get_file_tree`, `get_code_structure`, `graph`, `apply_edits`, `file_actions`, `git`, `validate`, `index`, `status`, `ledger`, `agent_run`, `agent_manage`, `oracle_send`, and `oracle_utils`.
|
|
39
|
+
|
|
40
|
+
The detailed `rhei_code_*` tools below are the legacy/full-profile and Rhei self-development reference surface. They are for dogfooding, compatibility, and debugging only; do not use them in tester install instructions. Default local edit availability stays beta/report-only: search, exact reads, proposals, `CodeImpactPredictionV1`, Proof Synapse, dry-run diffs, and validation evidence are advertised so agents can use Rhei before falling back. The full Code Session profile exposes one edit family, `rhei_code_edits`; by default it runs preview -> gated apply attempt -> durable afteredit verification. Missing apply gates return preview plus blockers without writing. Source apply remains tmp/local-beta gated by explicit env, receipts, root allowlists, and Writer Arbitration.
|
|
41
|
+
|
|
42
|
+
| Tool | Purpose |
|
|
43
|
+
| --- | --- |
|
|
44
|
+
| `rhei_code_goal` | Central mode-based goal surface backed by pure `@rhei/core/goalIntelligence` builders plus MCP receipts. `mode=context` wraps compact Code Context, `mode=verify` runs scoped search/read/absence proof with searched scopes/counts/confidence/caveats and Trail evidence, `mode=edit` runs Rhei Edit Transaction V1 over search/read/proposal/dry-run/diff/validation/AgentEditSession/Trail evidence, `mode=trail` summarizes session history, reads, proposal/dry-run ids, final/reverse diffs, validations, human decisions, replay refs, and CodeTrail export evidence, `mode=learn_from_outcome` turns accepted/rejected edits and human rewrites into replay evidence/memory candidates without memory writes, `mode=report` produces safe Markdown diff previews/receipts and optional explicit report writes, `mode=diagnose` attaches diagnostics/Growth Diagnostics/Connected Surface Coverage evidence, `mode=outcome_feedback` captures human rewrites/style/outcome feedback as memory candidates only, `mode=steer` decides whether a new instruction continues/branches/replaces, and the continuity modes emit resume packets, intelligence commit receipts, preference replay plans, diagnostic closure reports, and service-impact evidence. Report-only; no service writes, graph mutation, provider calls, transcript replay, memory promotion, or hidden apply authority. |
|
|
45
|
+
| `rhei_code_io` | Public ergonomic IO wrapper for `read`, `search`, and `edit`. `op=edit` accepts `changes` or multi-file `files`, consumes `workflowPlan` advisory context, defaults to preview, and routes through `rhei_code_edits` so Synapse, diff, receipts, and local-beta/test apply gates stay in one existing writer path. |
|
|
46
|
+
| `rhei_context_builder` / `context_builder` | Fast algorithmic context-builder handoff. The caller gives a goal plus optional `repoPath`, `scopePaths`, `tokenBudget`, `responseType`, `targetAgent`, and `exportResponse`; Rhei returns `ContextReceiptV1`, selected files/slices, symbol summaries, relevant diff status, token accounting, omitted candidates, per-file include reasons, `AgentWorkBriefV1`, a ready-to-send prompt, and optional export path/instruction. It reuses Rhei's deterministic local selector and never calls providers, starts Oracle/agents, mutates graph/canon state, or grants write authority. |
|
|
47
|
+
| `rhei_code_context_for_goal` | Scans a local repo for a user goal, builds bounded `CodeMarketSnapshotV1`, then returns `AgentWorkBriefV1`, compact `CodeContextAgentSurfaceV1`, selected refs, risks, optional report-only lanes, the named `autoSlicedContextPacketTransition` for ProgramPlan inventory -> Auto-Sliced ContextPacket -> AgentWorkBrief, local index status, and optional handoff markdown. |
|
|
48
|
+
| `rhei_service_intelligence_for_goal` | Builds a report-only `ServiceIntelligenceReportV1` from explicit `ServiceConnectionV1`/evidence inputs plus optional `context_for_goal` refs. It emits service/resource edges, absence proof, guardrails, and the next backend/UI/test/docs slice without live runtime-surface ingest, provider calls, graph writes, memory promotion, or canon mutation. |
|
|
49
|
+
| `rhei_code_context_build_work_brief` | Builds an `AgentWorkBriefV1`, compact `CodeContextAgentSurfaceV1`, and deterministic handoff markdown from selected Code Context. |
|
|
50
|
+
| `rhei_code_context_doctor` | Health-check tool for MCP config, repo path, local mode, advertised tools, sample context selection, schema exposure, and no-live invariants. Use when setup looks wrong, not on every task. |
|
|
51
|
+
| `rhei_code_context_runs` | Returns recent process-local context run metadata: request id, goal hash, timings, file counts, token estimates, selected refs, warnings, no-live result, and artifact path. It does not return source contents or raw goal text. |
|
|
52
|
+
| `rhei_code_context_agent_instructions` | Returns the guardrails and expected payload shape for local agents. |
|
|
53
|
+
| `rhei_code_prepare_work` | Builds the central report-only handoff envelope: `CodeStrategyPlanV1` + `WorkflowPlanV1` + `CodeWorkHandoffV1`. It never mutates Code Session and never grants apply authority. |
|
|
54
|
+
| `rhei_code_session_start` | Starts a process-local `RheiCodeSessionV1` facade from a goal plus `rhei_code_context_for_goal` or `CodeWorkHandoffV1` evidence. |
|
|
55
|
+
| `rhei_code_search` | Performs deterministic bounded search through one surface with RepoPrompt-style ergonomics: use an existing `sessionId` or pass `repoPath` plus `query`/`exactText` for a one-call search that auto-starts a read-only session. Includes local lexical/index/codemap ranking plus optional supplied semantic, Qdrant/session-vector, Convex-unified, graph advisory, service-connection, depth, budget, coverage, and next-read controls. |
|
|
56
|
+
| `rhei_code_read` | Reads files with RepoPrompt-style ergonomics: singular `read` string/object, `path`/`file`/`refId`/`ref`/`readSliceId`, batch `read`/`reads`/`paths`/`files`/`refs`/`refIds`, `lines`, `start_line`/`startLine` + `limit`, `end_line`/`endLine`, negative `start_line`, `lines: "-N"`, or pasted `path.ts:-N` tail reads, numeric strings for line/window/token fields, `contentFormat`/`content_format`/`format` controls, and path-only counted full-file reads. Returns baseline hash, token estimate, repeated-read telemetry, full-file reason/warnings, and no write authority. |
|
|
57
|
+
| `rhei_code_session_context` | Reports selected refs, slices, budget, token totals, repeated reads, quality metrics, no-live state, and proposal/dry-run/validation refs without source contents. |
|
|
58
|
+
| `rhei_code_plan_edits` | Creates `CodeWriteProposalV1` only and attaches an explicit `CodeImpactPredictionV1` report-only packet. |
|
|
59
|
+
| `rhei_code_proof_plan` | Creates a report-only Proof Synapse contract: required tests, docs, contracts, validation commands, missing evidence, traceability, and collaboration roles. |
|
|
60
|
+
| `rhei_code_edit_cycle` | Ergonomic loop wrapper for proposal -> `CodeImpactPredictionV1` -> Proof Synapse -> dry-run -> validation. It normalizes `editsByPath`, evaluates same-file edits sequentially, returns separate artifacts, and never calls apply. |
|
|
61
|
+
| `rhei_code_strategy_plan` | Builds a deterministic report-only `CodeStrategyPlanV1` from Code Context, ProgramPlan/MigrationPlan evidence, Code Session slices, explicit connected files, and optional oracle true/false feedback. |
|
|
62
|
+
| `rhei_code_workflow_plan` | Builds a deterministic report-only `WorkflowPlanV1` beside its strategy plan, including service connection gates, adjustable context-injection policy, session selection, and Oracle prompt packets only; no session lookup/mutation, live Oracle, source reads, provider calls, or writes. |
|
|
63
|
+
| `rhei_code_oracle` | Primary Oracle workflow surface. `mode` supports `session_start`, `session_context`, `manage_workspace`, `build_context_bundle`, `export_markdown`, `plan_packets`, `import_feedback`, `refine_workflow`, `summarize_feedback`, and `fork_session`; V1 never calls a live Oracle/provider and never mutates Code Session state. |
|
|
64
|
+
| `rhei_code_agent` | Report-only external-agent handoff/import/ranking surface. `mode` supports `handoff`, `import_result`, `summarize_result`, and `rank_results`; it packages work for agents, imports their reports, and ranks evidence without spawning agents, calling providers, writing files, mutating sessions, or granting apply authority. |
|
|
65
|
+
| `rhei_agent_explore` | Public ergonomic wrapper for short-lived explore handoffs over the same `rhei_code_agent` substrate. `action=start` accepts a full `CodeWorkHandoffV1` or a simple `requiredRefs`/`exactRefs`/`refs`/`files` + `message` request and auto-builds the report-only explore handoff/read-slice envelope; `poll`, `wait`, and `cancel` return deterministic local snapshots. It is process-local, report-only, no-spawn, no-provider, no-write, and no-authority. |
|
|
66
|
+
| `rhei_agent_run` | Public role-labelled wrapper for `explore`, `engineer`, `pair`, `review`, `validate`, and `design` agent work. `action=start` accepts a full `CodeWorkHandoffV1` or a simple `requiredRefs`/`exactRefs`/`refs`/`files` + `message` request and auto-builds the report-only handoff/read-slice envelope. It supports start/lifecycle, steering, result import, summary, ranking snapshots, an explicit local process plane (`executionMode=live`), and an explicit Modal AgentEditSession plane (`executionMode=sandbox`). Fake remains the default local adapter; Codex CLI and Modal sandbox are opt-in. Local Codex sessions start asynchronously with capped logs/cancel/cleanup receipts; Modal callbacks enter through explicit `action=import_result` no-authority result bundles. |
|
|
67
|
+
| `rhei_agent_manage` | Public catalog/session helper for listing roles/workflows, inspecting process-local agent sessions, exporting handoff snapshots, and cleaning local session state. It is not a provider-session controller. |
|
|
68
|
+
| `rhei_code_run` | Report-only process-local run graph switchboard. `mode` supports `start`, `context`, `add_oracle`, `add_agent_handoff`, `import_agent_result`, `switch_active`, `rank_results`, and `summarize`; it links Oracle sessions, Code Sessions, agent handoffs/results, review/proof/diff artifacts, and visible delegation leases without spawning agents or granting write authority. |
|
|
69
|
+
| `rhei_code_review` | Report-only team-aware review intelligence surface. `mode` supports `build_review_diff`, `build_pr_diff`, `rank_proposals`, `record_outcome`, `record_pr_outcomes`, `generate_memory_candidates`, and `summarize_review_room`; it groups session/PR diffs, ranks competing proposals, imports review outcomes, and emits assist-only memory candidates without write authority. |
|
|
70
|
+
| `rhei_code_dry_run_edits` | Checks baseline hashes and expected match counts, then returns an in-memory patch preview. `applyAvailable` is always false. |
|
|
71
|
+
| `rhei_code_session_diff` | Inspects the latest or selected proposal/dry-run as a git-like session diff with path summaries and optional reverse preview. It never writes, reverts, applies, or grants authority. |
|
|
72
|
+
| `rhei_code_validate` | Records validation evidence. Commands are skipped unless `execute: true`; validation never grants apply authority. |
|
|
73
|
+
| `rhei_code_session_act` | Local server helper that explicitly runs one task-level flow: context, session start, exact read, proposal, `CodeImpactPredictionV1`, dry-run, validation, and optional local-beta apply only when the separate apply gates are enabled. |
|
|
74
|
+
| `rhei_code_edits` | Full-profile edit family. The default action runs exact search/replace or create/rewrite preview, attempts apply only when env/receipt/root/Synapse gates allow it, then verifies durable filesystem readback before reporting `applied_verified`. Use `phase=preedit` for preview-only and `phase=afteredit` for rechecking a prior apply. |
|
|
75
|
+
|
|
76
|
+
The default local MCP profile advertises the generic 20-tool public surface listed above. Legacy and granular debug surfaces, including `rhei_code_goal`, `rhei_code_agent`, `rhei_code_session_start/context`, `rhei_code_plan_edits`, `rhei_code_proof_plan`, `rhei_code_edit_cycle`, `rhei_code_dry_run_edits`, `rhei_code_validate`, `rhei_code_strategy_plan`, `rhei_code_workflow_plan`, `rhei_code_context_build_work_brief`, `rhei_code_context_runs`, and `rhei_code_edit_session_handoff`, remain available only with `RHEI_MCP_LOCAL_TOOL_PROFILE=full` or an explicit `RHEI_MCP_LOCAL_TOOL_ALLOWLIST`.
|
|
77
|
+
|
|
78
|
+
## Central Goal Modes
|
|
79
|
+
|
|
80
|
+
Use the generic `goal` tool in the public profile when the caller has an evolving task and needs one stable entry point for context, edit/verify/trail receipts, diagnostics, feedback, steering, continuity, and service-impact evidence. In the full/dogfooding profile, the same legacy envelope is named `rhei_code_goal`; `@rhei/core/goalIntelligence` owns the shared V1 contracts/builders used by MCP and product tests:
|
|
81
|
+
|
|
82
|
+
- `mode=context`: returns a compact `rhei_code_context_for_goal` payload for the current explicit goal.
|
|
83
|
+
- `mode=verify`: runs a one-roof Rhei Verify Transaction V1: context -> Code Session start -> scoped search/prove-absence -> exact reads -> absence proof -> coverage summary -> caveats -> `rhei_code_trail_export`. It supports `searches`, `search`, `query`, `exactText`, `literalText`, `absenceClaim`, `scopePaths`/`scopes`, `candidateRefs`, RepoPrompt-style `read`/`reads` path strings or objects, and top-level `path`/`file` plus `start_line`/`limit` single-read shortcuts. When only explicit reads are supplied, verify skips goal-driven search noise and returns status `read`. Every absence proof includes searched scopes, searched/matched/skipped file counts when available, truncation status, confidence, reason codes, and caveats.
|
|
84
|
+
- `mode=edit`: runs a one-roof Rhei Edit Transaction V1: context -> optional scoped search/read -> multi-edit proposal -> dry-run -> session diff/reverse diff -> validation -> `AgentEditSessionV1` diff/finish receipt -> `rhei_code_trail_export`. It supports `proposedChanges` and `editsByPath`, ordered same-file edits, expected match counts, baseline hashes, validation evidence, final/reverse diff refs, and no hidden apply.
|
|
85
|
+
- `mode=trail`: runs a one-roof Rhei Trail Transaction V1: context -> explicit edit/verify/session evidence normalization -> per-session selected refs/searches/reads/proposals/dry-runs/final diffs/reverse diffs/validations/human decisions/outcome and replay refs -> coverage/caveat summary -> `rhei_code_trail_export`. It supports `trail`, `session`, `sessions`, `sessionIds`, `proposalIds`, `dryRunIds`, `diffRefs`, `reverseDiffRefs`, `validationRefs`, `receiptRefs`, and explicit `writeTrail` only for sanitized JSON inside `repoPath`.
|
|
86
|
+
- `mode=learn_from_outcome`: turns accepted/rejected edits, human rewrites, style preferences, and validation outcomes into replay evidence plus memory candidates only. It emits accepted/rejected refs, human-rewrite hashes, expected replay signals, promotion-required/no-write receipts, and `noMemoryWrite: true`; promotion stays gated outside this tool.
|
|
87
|
+
- `mode=report`: builds safe Markdown report output with a diff preview and report receipt. It accepts `reportPath`, `reportMarkdown`, `receiptRefs`, and `writeReport`; writes happen only when `writeReport: true`, the path resolves inside `repoPath`, and the path is under `docs/` or `.rhei/reports/`.
|
|
88
|
+
- `mode=diagnose`: runs the same bounded context selection with diagnostics and selected-context Growth Diagnostics/Connected Surface Coverage enabled by default. Feed failed commands, validation logs, PR review comments, or child-agent results through `evidenceIntake` or `diagnosticEvidence`.
|
|
89
|
+
- `mode=outcome_feedback`: captures accepted/rejected outcomes, human rewrites, style preferences, and evidence refs as report-only preference signals. It emits `memoryCandidates` with `promotionRequired: true` and `writeAuthority: false`; it never writes memory.
|
|
90
|
+
- `mode=steer`: compares an active goal with an incoming goal. New instructions branch or replace by explicit decision; they do not silently append unless `allowAppend: true` is supplied or the goal similarity is high.
|
|
91
|
+
- `mode=resume`: emits a compact `GoalSessionV1` continuity packet from done/current/stale/open refs, Code Market snapshots, Code Trail refs, PR review refs, commits, validation receipts, and outcome feedback refs. It sets `noTranscriptReplay: true`; resume is receipts and ranked deltas, not hidden long-context accumulation.
|
|
92
|
+
- `mode=intelligence_commit`: emits a report-only intelligence receipt that links git commits to context runs, Code Market snapshots, Code Trail, PR review, validation, outcome feedback, and service evidence. Git stays the source-diff history; the intelligence receipt records why/evidence around it.
|
|
93
|
+
- `mode=preference_replay`: replays human rewrites/style preferences as ranking-bias trial evidence. It can prove `style_preference_reused` or `human_rewrite_pattern_matched` without writing memory.
|
|
94
|
+
- `mode=diagnostic_closure`: links diagnostics, fix refs, validation refs, and outcome evidence so a diagnostic loop can move to `closed_with_validation` or request more `evidenceIntake`.
|
|
95
|
+
- `mode=service_impact`: links `ServiceConnectionV1`/service refs to impacted code/docs/test refs for analysis only. Promotion goes through `rhei_service_intelligence_for_goal`; no connector sync or service graph mutation occurs here.
|
|
96
|
+
|
|
97
|
+
Service connections remain evidence only in this surface. Pass `serviceConnections` or `serviceConnectionIds` to link diagnostics, outcome feedback, continuity, closure, replay, or steering to service context, but use the governed service/memory paths for any real write or promotion.
|
|
98
|
+
|
|
99
|
+
Goal Intelligence persists refs and receipts, not transcripts or full packets: Workroom session ids, CodeTrail refs, PR/review refs, validation refs, service refs, commit refs, and outcome refs. V1 intentionally does not add a dedicated goal-session table or grant hidden resume authority.
|
|
100
|
+
|
|
101
|
+
## Recommended Agent Loop
|
|
102
|
+
|
|
103
|
+
Agents should treat the MCP surface as a small workflow, not a flat list of equal tools:
|
|
104
|
+
|
|
105
|
+
```text
|
|
106
|
+
rhei_code_goal mode=verify
|
|
107
|
+
-> scoped search / prove_absence
|
|
108
|
+
-> exact reads
|
|
109
|
+
-> coverage + absence proof receipt
|
|
110
|
+
-> Trail export
|
|
111
|
+
-> rhei_code_goal mode=edit
|
|
112
|
+
-> context/search/read
|
|
113
|
+
-> multi-edit proposal + dry-run
|
|
114
|
+
-> session diff + reverse preview
|
|
115
|
+
-> validation evidence
|
|
116
|
+
-> AgentEditSession diff/finish receipt
|
|
117
|
+
-> Trail export
|
|
118
|
+
-> rhei_code_goal mode=trail
|
|
119
|
+
-> per-session history + receipts
|
|
120
|
+
-> CodeTrail export summary
|
|
121
|
+
-> rhei_code_goal mode=learn_from_outcome / mode=report
|
|
122
|
+
-> replay evidence or Markdown report receipt
|
|
123
|
+
```
|
|
124
|
+
|
|
125
|
+
For granular full-profile debugging, the same path is still available as `rhei_code_prepare_work -> rhei_code_session_start -> rhei_code_search / rhei_code_read -> rhei_code_edit_cycle -> rhei_code_session_diff -> rhei_code_validate`. The public profile keeps that lower-level complexity behind `rhei_code_goal mode=edit`, `rhei_code_goal mode=trail`, `rhei_code_session_act`, and the AgentEditSession family.
|
|
126
|
+
|
|
127
|
+
Read/search ergonomics intentionally mirror the RepoPrompt `file_search` -> `read_file` loop: `rhei_code_search` can run in an existing `sessionId` or as a one-call `repoPath` + `query`/`exactText` search that auto-starts a read-only session and returns its `sessionId` for follow-up reads. Path-only reads return a counted full-file slice with token/warning receipts, `start_line` + `limit` reads a window, `line`/`lineNumber` reads one line, `lineNumber` + `count` reads a short window, bare `limit` or `count` reads the first N lines, bare `end_line`/`to` reads from line 1 through that line, negative `start_line` or `lines: "-40"` reads from the tail, pasted tail refs like `path.ts:-40` or `file:path.ts#L-40` read the last N lines, pasted refs like `path.ts:12-20`, diagnostic refs like `path.ts:12:4-20:1`, or hash refs like `path.ts#L12C4-L20C1` resolve to path plus lines, and `file`/`ref` are accepted aliases for `path`/`refId`. Numeric strings such as `start_line: "3"`, `limit: "20"`, `maxTokens: "2000"`, and `contextRefLimit: "4"` are accepted anywhere the read/goal surface accepts those numeric controls. `rhei_code_read` can read inside an existing `sessionId` or perform a one-call read with `repoPath` plus singular `read`, `path`/`file`/`ref`, auto-starting a read-only session and returning its `sessionId` for follow-up reads. It also accepts batch `read` arrays, `reads` (strings or read objects), `paths`/`files`/`refs`/`refIds` arrays, direct Code Context or handoff ref lists via `exactRefs`/`selectedRefs`/`requiredRefs`, and whole `contextForGoal`/`workBrief`/`agentSurface`/`handoff` packets that are normalized into bounded connected reads with `contextRefLimit`/`maxContextRefs`, returning per-file receipts plus combined content for a connected multi-file context grab; every read returns a compact `readPlan` and `selectionPreview` with path/range/token/hash metadata so agents can inspect the chosen set before consuming source. Pass `previewOnly: true`, `preview: true`, `planOnly: true`, `includeContent: false`, `returnContent: false`, `omitContent: true`, or `content: false` to resolve that same connected read plan while omitting source content from the response after the file is read for hashes/token estimates. Pass `selectionOnly: true`, `metadataOnly: true`, `readPlanOnly: true`, or `resolveOnly: true` when planning should be source-free: the response resolves paths and line labels for connected multi-file reads without opening source files, so token/hash estimates are intentionally absent. Read objects can use `lineRanges` or aliases `range`/`lineRange`/`line_range`/`ranges`/`line_ranges` with string labels, `start`/`end`, `from`/`to`, `start_line`, `limit`, `count`, and negative tail starts just like top-level reads. Batch reads fail fast by default, or return successful reads plus structured read errors when `continueOnError: true` / `continue_on_error: true` / `allowPartial: true` / `allow_partial: true` is set. By default read content is RepoPrompt-style copyable text without `N:` prefixes; pass `includeLineNumbers: true`, `contentFormat: "numbered"`, or `contentFormat: "annotated"` when line-number receipts should be embedded in the content, and `includeCodemap: true` to attach a compact symbol map for the returned slice. `rhei_code_goal` shares the same top-level `read`/`reads`, `paths`/`files`/`refs`/`refIds`, `exactRefs`/`selectedRefs`/`requiredRefs`, context packet, `path`/`file`/`ref`, pasted line/tail refs, line-window/range aliases, preview/content-omission/selection-only aliases, `continueOnError`/`allowPartial`, and `contentFormat`/`content_format`/`format` shortcuts, so simple verify reads do not require wrapping the request in `read`; compatible multi-file goal aliases execute through one connected `rhei_code_read` batch with a combined `readPlan`/`selectionPreview`, while mixed packet/global read modes fall back to separate reads to preserve semantics. Explicit read paths and typed refs such as `code_file:file:<path>` are forced into Code Context exact refs before broader scan limits can omit them. Use explicit `maxTokens` for large files.
|
|
128
|
+
|
|
129
|
+
Use `rhei_code_oracle` when the workflow needs Oracle packets, external/user feedback import, workflow refinement, or feedback summaries. Use `mode` rather than new one-off tool names:
|
|
130
|
+
|
|
131
|
+
- `session_start`
|
|
132
|
+
- `session_context`
|
|
133
|
+
- `manage_workspace`
|
|
134
|
+
- `build_context_bundle`
|
|
135
|
+
- `export_markdown`
|
|
136
|
+
- `plan_packets`
|
|
137
|
+
- `import_feedback`
|
|
138
|
+
- `refine_workflow`
|
|
139
|
+
- `summarize_feedback`
|
|
140
|
+
- `fork_session`
|
|
141
|
+
|
|
142
|
+
Use `rhei_code_context_doctor` only as a health check for MCP config, repo paths, tool exposure, schema mismatch, sample context selection, or no-live invariants. It is not part of the normal per-task loop.
|
|
143
|
+
|
|
144
|
+
Lower-level tools such as `rhei_code_context_for_goal`, `rhei_code_strategy_plan`, `rhei_code_workflow_plan`, `rhei_code_plan_edits`, `rhei_code_dry_run_edits`, and `rhei_code_proof_plan` remain useful for debugging, evals, and custom orchestration, but the default agent UX should start with the central handoff/edit-cycle loop above.
|
|
145
|
+
|
|
146
|
+
The manual edit loop is still report-only and should be used before fallback when available:
|
|
147
|
+
|
|
148
|
+
```text
|
|
149
|
+
rhei_code_plan_edits
|
|
150
|
+
-> CodeImpactPredictionV1 / Synapse evidence
|
|
151
|
+
-> rhei_code_proof_plan
|
|
152
|
+
-> rhei_code_dry_run_edits
|
|
153
|
+
-> rhei_code_validate
|
|
154
|
+
```
|
|
155
|
+
|
|
156
|
+
Only after `rhei_code_context_doctor` reports the edit loop is not advertised should an agent fall back to external editors for source changes. Even then, fallback does not imply apply authority inside Rhei.
|
|
157
|
+
|
|
158
|
+
For precise edits, search first with `rhei_code_search` using `matchMode: "literal"` or `exactText` to prove the exact snippet and duplicate count. Literal search accepts multi-line `exactText` and anchors `matchedLines`/`nextReadPlan` to the first matched line. Then pass `selectedLines` on each pattern edit; labels may be numeric (`1-8`) or editor-style (`L1-L8`), and dry-runs plus gated apply preflight scope replacements to those line ranges so one-file multi-edits and multi-file edits can avoid over-broad replacements when the same literal appears elsewhere in the file. Dry-run and session-diff previews use ordered unified hunks for normal-sized files, so duplicate-line replacements and same-line-set reorders are shown as real `-`/`+` evidence instead of being hidden by counted-line summaries.
|
|
159
|
+
|
|
160
|
+
`rhei_code_workflow_plan` centralizes source/context injection through `ContextInjectionPolicyV1`. Callers can pass `autoInjection: false` to keep refs path-only/deferred, `autoInjection: true` plus `autoInjectionLimit` to set the source-text budget, or a full `contextInjectionPolicy` with `mode`, `sourceTextTokenLimit`, `maxAutoInjectRefs`, `contextSlicerReviewThreshold`, `forcePaths`, `pathOnlyRefs`, and `deferRefs`. The resolved policy is returned in `workflowPlan.sessionSelect.contextInjection` so UI and agents can show and adjust the same knobs. `pathOnlyRefs` may name future/new files as metadata-only context refs; they do not authorize reads or writes.
|
|
161
|
+
|
|
162
|
+
Use `rhei_code_context_for_goal` when an agent only has a repo path and goal:
|
|
163
|
+
|
|
164
|
+
```json
|
|
165
|
+
{
|
|
166
|
+
"repoPath": "/Users/mibook/saga/rhei",
|
|
167
|
+
"goal": "Improve local Rhei MCP context selector and AgentWorkBrief handoff for Codex CLI",
|
|
168
|
+
"workflowPresetId": "deep_plan",
|
|
169
|
+
"maxFilesToScan": 1200,
|
|
170
|
+
"maxExactFiles": 8,
|
|
171
|
+
"maxEvidenceFiles": 6,
|
|
172
|
+
"maxSymbols": 10,
|
|
173
|
+
"includeMarkdown": true,
|
|
174
|
+
"includeProgramPlan": true,
|
|
175
|
+
"includeSurfaceCoverage": true,
|
|
176
|
+
"includeGrowthDiagnostics": true,
|
|
177
|
+
"plannerHandoffGraphAdvisory": {
|
|
178
|
+
"schemaVersion": 1,
|
|
179
|
+
"kind": "planner_handoff_graph_advisory",
|
|
180
|
+
"source": "mcp_input",
|
|
181
|
+
"basis": "explicit_metadata",
|
|
182
|
+
"recommendedGraphMode": "soft_graph_depth3",
|
|
183
|
+
"selectedGraphMode": "connected_work_shallow",
|
|
184
|
+
"memgraphAllowed": false,
|
|
185
|
+
"depth5Allowed": false,
|
|
186
|
+
"reportOnly": true,
|
|
187
|
+
"advisoryOnly": true,
|
|
188
|
+
"noAuthority": true
|
|
189
|
+
},
|
|
190
|
+
"useLocalIndex": true,
|
|
191
|
+
"writeLocalIndex": true,
|
|
192
|
+
"reportOnlyEvidence": [
|
|
193
|
+
{
|
|
194
|
+
"kind": "connected_surface_coverage",
|
|
195
|
+
"title": "Connected Surface Coverage",
|
|
196
|
+
"summary": "Optional report-only readiness evidence from Rhei local/web."
|
|
197
|
+
},
|
|
198
|
+
{
|
|
199
|
+
"kind": "growth_diagnostics",
|
|
200
|
+
"title": "Growth Diagnostics",
|
|
201
|
+
"summary": "Optional reuse/drift diagnostic evidence; no execution authority."
|
|
202
|
+
},
|
|
203
|
+
{
|
|
204
|
+
"kind": "program_plan",
|
|
205
|
+
"title": "ProgramPlanV1",
|
|
206
|
+
"summary": "Optional program-scale control-plane evidence above bounded Code Context."
|
|
207
|
+
}
|
|
208
|
+
]
|
|
209
|
+
}
|
|
210
|
+
```
|
|
211
|
+
|
|
212
|
+
`rhei_code_context_for_goal` accepts `evidenceIntake` as the preferred CodeEvidencePacketV1 lane, with `refinementEvidence` as a compatibility alias and `diagnosticEvidence` as a convenience lane for command/compiler output. Each lane accepts either structured evidence packets or raw strings, so agents can paste a compiler line, CI excerpt, validation note, or review summary without hand-wrapping it first. Use these after a failed command such as `bunx convex deploy` or `bun test`, or feed compact connected evidence from `rhei_code_validate`, `rhei_code_review`, `rhei_code_agent`, or `rhei_code_run`. The selector extracts repo-relative refs, grouped diagnostics, error codes, focused first-fix slices, and readiness metadata, then promotes matching files into exact context behind explicit `exactRefs`. Large logs are budgeted before parsing, repeated diagnostics are deduped by path/line/column/code, and compact MCP responses expose truncation/dedup counts while omitting raw command output. For diagnostic-only goals, product/UI summaries are suppressed in favor of diagnostic primary refs and first-fix slices. The compact response also includes `contextBudget`, which distinguishes `sourceExactRefs` governed by `maxExactFiles` from broader `agentSurface`/`workBrief` evidence refs such as tests, docs, symbols, and service evidence. For program-scale goals, the compact response includes `autoSlicedContextPacketTransition`, a report-only bridge receipt from `ProgramPlanV1`/path inventory to the required Auto-Sliced `ContextPacketV1` and then `AgentWorkBriefV1`; its `receipts.missingRefs`, `receipts.truncation`, and `receipts.failure` explain missing transition refs, bounded-scan omissions, and blocked handoffs without granting execution or apply authority. The returned `refinementIntelligence`, `editReadiness`, and transition are report-only/advisory.
|
|
213
|
+
|
|
214
|
+
```json
|
|
215
|
+
{
|
|
216
|
+
"repoPath": "/Users/mibook/saga/rhei",
|
|
217
|
+
"goal": "Fix Convex deploy TypeScript diagnostics",
|
|
218
|
+
"evidenceIntake": [
|
|
219
|
+
{
|
|
220
|
+
"kind": "command_diagnostic",
|
|
221
|
+
"command": "bunx convex deploy",
|
|
222
|
+
"rawOutput": "convex/code_layer/teamBridge.ts:376:46 - error TS4111: Property 'projectionKind' comes from an index signature."
|
|
223
|
+
}
|
|
224
|
+
]
|
|
225
|
+
}
|
|
226
|
+
```
|
|
227
|
+
|
|
228
|
+
### Fast Context Builder
|
|
229
|
+
|
|
230
|
+
Use `rhei_context_builder` when an agent needs the right working context and a readable handoff in one call, without starting Oracle, launching subagents, reading source text, or entering the edit loop. `context_builder` is the boring alias for MCP clients that prefer non-branded tool names.
|
|
231
|
+
|
|
232
|
+
```json
|
|
233
|
+
{
|
|
234
|
+
"repoPath": "/Users/mibook/saga/rhei",
|
|
235
|
+
"goal": "Plan the next MCP context-builder reliability slice",
|
|
236
|
+
"scopePaths": ["packages/mcp-server/src", "convex-tests/codeLayer"],
|
|
237
|
+
"tokenBudget": 12000,
|
|
238
|
+
"contextWindowTokens": 60000,
|
|
239
|
+
"packingMode": "budgeted_slices",
|
|
240
|
+
"responseType": "plan",
|
|
241
|
+
"targetAgent": "codex",
|
|
242
|
+
"exportResponse": true,
|
|
243
|
+
"evidenceMlTopFiles": [
|
|
244
|
+
{
|
|
245
|
+
"path": "packages/mcp-server/src/codeContextTools/mcpResultAndContextForGoalTool.ts",
|
|
246
|
+
"score": 0.97,
|
|
247
|
+
"modelId": "impact-ranker-v0"
|
|
248
|
+
}
|
|
249
|
+
],
|
|
250
|
+
"maxFilesToScan": 800,
|
|
251
|
+
"maxExactFiles": 8,
|
|
252
|
+
"maxEvidenceFiles": 6
|
|
253
|
+
}
|
|
254
|
+
```
|
|
255
|
+
|
|
256
|
+
The response centers on `contextReceipt`:
|
|
257
|
+
|
|
258
|
+
- `selectedContext`: exact refs, selected files, planned read slices, related tests/docs/service evidence, and the next `rhei_code_io` read request.
|
|
259
|
+
- `codeMaps`: symbol summaries from the selected refs.
|
|
260
|
+
- `relevantDiffs`: read-only git status for selected refs plus a follow-up diff request.
|
|
261
|
+
- `tokenBudget`: requested budget, observed source-selection token estimate, and `within_budget`/`over_budget` status. In V1 this is reported, while `maxExactFiles` and `maxEvidenceFiles` remain the hard selector bounds.
|
|
262
|
+
- `contextPacking`: target-window fit guidance for 60k/120k/200k models, top-five source estimate, full selected-source estimate, recommended read mode, and Evidence ML top-file alignment.
|
|
263
|
+
- `budgetedContextBundle`: optional `BudgetedContextBundleV1` with packed source when `packingMode` is `top_five_full`, `budgeted_slices`, or `full_selected_when_fits`, or when `includeBudgetedContext` is true.
|
|
264
|
+
- `omittedCandidates`: bounded-scan omissions and non-selected candidate counts.
|
|
265
|
+
- `inclusionReasons`: per-file reason cards, scores, symbols, and token estimates.
|
|
266
|
+
- `sessionAttachment`: `contextReceiptId` and starter args a code session can carry forward.
|
|
267
|
+
- `benchmarkSignals`: elapsed-time target status, file-recall proxy, estimated tool-call reduction, and prompt readability counts.
|
|
268
|
+
- `readyToSendPrompt`: the agent-facing prompt/brief for the selected `responseType`.
|
|
269
|
+
- `export`: when `exportResponse` is true, a markdown handoff under `prompt-exports/` beside the repo root, with `ContextReceiptV1`, `AgentWorkBriefV1`, and the ready prompt.
|
|
270
|
+
|
|
271
|
+
`evidenceMlTopFiles` and `evidenceTopFiles` are advisory ranker lanes for the evidence ML model. These paths are seeded before normal goal-ranked exact refs, then reported back through `contextPacking.evidenceMlAlignment`. They do not grant authority; they only improve right-file recall.
|
|
272
|
+
|
|
273
|
+
Source text is opt-in. Leave `packingMode` unset for metadata-only RepoPrompt-style handoff planning. Use `packingMode: "budgeted_slices"` when the receiving agent needs a markdown export with selected source snippets. Use `top_five_full` for small top-ranked files, and `full_selected_when_fits` when source should only be included if all selected refs fit the requested model window.
|
|
274
|
+
|
|
275
|
+
`rhei_context_builder` is a packaging layer over Rhei's existing deterministic local context selector. It is report-only/advisory, does not read full source contents by default, does not call providers or live graph services, does not start Oracle/agents, and does not grant write authority.
|
|
276
|
+
|
|
277
|
+
`rhei_code_context_for_goal` can also perform an explicit connected read when the standalone read tool is not exposed in a client profile. Pass `read`, `reads`, `paths`, `files`, `refs`, or `refIds` to attach a compact `contextRead` receipt backed by `rhei_code_read`. Use `rhei_code_goal mode=read` or direct read aliases on `rhei_code_goal` when you only want the file slice and receipt; that route skips the goal context scan and omits `contextForGoal`. Use `mode=context` when you want planning context plus a mirrored `contextRead` inside `contextForGoal.contextRead`. Set `includeContent: false`, `previewOnly: true`, or `selectionOnly: true` for a source-free read plan; set `readFromContext: true` to derive the read set from the selected context refs. Plain context calls do not read source content beyond normal bounded selection unless one of these read inputs is present.
|
|
278
|
+
|
|
279
|
+
```json
|
|
280
|
+
{
|
|
281
|
+
"repoPath": "/Users/mibook/saga/rhei",
|
|
282
|
+
"goal": "Plan and read the MCP source refs in one call",
|
|
283
|
+
"paths": [
|
|
284
|
+
"packages/mcp-server/src/codeContextTools.ts",
|
|
285
|
+
"packages/mcp-server/README.md"
|
|
286
|
+
],
|
|
287
|
+
"includeContent": false,
|
|
288
|
+
"contentFormat": "plain"
|
|
289
|
+
}
|
|
290
|
+
```
|
|
291
|
+
|
|
292
|
+
For a slim central read:
|
|
293
|
+
|
|
294
|
+
```json
|
|
295
|
+
{
|
|
296
|
+
"repoPath": "/Users/mibook/saga/rhei",
|
|
297
|
+
"mode": "read",
|
|
298
|
+
"path": "packages/mcp-server/src/codeContextTools.ts",
|
|
299
|
+
"start_line": 1343,
|
|
300
|
+
"limit": 40,
|
|
301
|
+
"includeContent": false
|
|
302
|
+
}
|
|
303
|
+
```
|
|
304
|
+
|
|
305
|
+
The response keeps the structured receipt in `read.receipt` and `contextRead`, including read ids, session/run ids, content/baseline hashes, token estimates, selection previews, lightweight symbol hints, and authority flags. It also includes a compact `contextRead.presentation` for humans:
|
|
306
|
+
|
|
307
|
+
```text
|
|
308
|
+
contextRead OK
|
|
309
|
+
files: 2
|
|
310
|
+
content: omitted
|
|
311
|
+
tokens: ~72.5k source / 0 emitted
|
|
312
|
+
paths:
|
|
313
|
+
- packages/mcp-server/src/codeContextTools.ts
|
|
314
|
+
- packages/mcp-server/README.md
|
|
315
|
+
syntax: lightweight_symbol_scan
|
|
316
|
+
symbols:
|
|
317
|
+
- buildRheiCodeGoalPayload
|
|
318
|
+
- codeGoalMode
|
|
319
|
+
authority: report-only
|
|
320
|
+
```
|
|
321
|
+
|
|
322
|
+
When line windows are requested, the presentation adds readable ranges:
|
|
323
|
+
|
|
324
|
+
```text
|
|
325
|
+
reads:
|
|
326
|
+
- packages/mcp-server/README.md:216-231
|
|
327
|
+
- packages/mcp-server/src/codeContextTools.ts:1738-1775
|
|
328
|
+
```
|
|
329
|
+
|
|
330
|
+
The higher-level goal transactions expose the same compact human lane without replacing their structured receipts. `verify.presentation`, `edit.presentation`, `trail.presentation`, and `report.presentation` summarize status, key counts, receipt count, authority, and a short `markdown` array while the underlying search/read/diff/Trail/report objects remain available for agents:
|
|
331
|
+
|
|
332
|
+
```text
|
|
333
|
+
verify absence_proven
|
|
334
|
+
searches: 2
|
|
335
|
+
reads: 1
|
|
336
|
+
coverage: 2 searched / 1 matched / high
|
|
337
|
+
absenceProof: 1
|
|
338
|
+
receipts: 5
|
|
339
|
+
authority: report-only
|
|
340
|
+
```
|
|
341
|
+
|
|
342
|
+
```text
|
|
343
|
+
edit dry_run_passed
|
|
344
|
+
dryRun: pass
|
|
345
|
+
validation: skipped
|
|
346
|
+
changedFiles: 1
|
|
347
|
+
apply: disabled
|
|
348
|
+
authority: report-only
|
|
349
|
+
```
|
|
350
|
+
|
|
351
|
+
Context responses also include a compact `workflowPlan` by default. It is a report-only bridge for the next agent step: `sessionSelect.exactRefs` names the bounded refs, `sessionSelect.readSlices` gives stable path and line-window hints, and `followups.read.args`, `followups.search.plans[].args`, and `followups.edit.args` are ready-to-run inputs for `rhei_code_read`, `rhei_code_search`, and preview-safe `rhei_code_io op=edit`. These follow-ups never execute during context selection, and their guardrails keep source reads, searches, and edits explicit. Pass `includeWorkflowPlan: false` only when the response must omit this planning lane.
|
|
352
|
+
|
|
353
|
+
By default it does not write snapshots. Set `writeSnapshot: true` only when you explicitly want a local artifact at `.rhei/code-context/latest-code-market-snapshot.json` or `snapshotOutputPath`.
|
|
354
|
+
|
|
355
|
+
The local selector can reuse `.rhei/code-context/local-index.json`. `useLocalIndex` defaults to true; `writeLocalIndex: true` creates or refreshes the cache with path, size, mtime, and hash metadata so repeated local context calls can skip the full repo listing. Use `refreshLocalIndex: true` after large file moves or package reshapes.
|
|
356
|
+
|
|
357
|
+
Every `rhei_code_context_for_goal` response now includes a metadata-only observability block:
|
|
358
|
+
|
|
359
|
+
```json
|
|
360
|
+
{
|
|
361
|
+
"relatedFiles": {
|
|
362
|
+
"exactFiles": ["packages/mcp-server/src/codeContextTools.ts"],
|
|
363
|
+
"relatedTests": ["convex-tests/codeLayer/localCodeContextForGoal.test.ts"],
|
|
364
|
+
"docsEvidence": ["packages/mcp-server/README.md"],
|
|
365
|
+
"serviceConnectionEvidenceRefs": [],
|
|
366
|
+
"all": []
|
|
367
|
+
},
|
|
368
|
+
"observability": {
|
|
369
|
+
"requestId": "rhei-context:...",
|
|
370
|
+
"goalHash": "deterministic-hash",
|
|
371
|
+
"durationMs": 42,
|
|
372
|
+
"phaseDurationsMs": {
|
|
373
|
+
"collectCandidates": 12,
|
|
374
|
+
"initialSelection": 4,
|
|
375
|
+
"finalSelection": 3,
|
|
376
|
+
"toolPayload": 42
|
|
377
|
+
},
|
|
378
|
+
"fileCounts": {
|
|
379
|
+
"scanned": 1200,
|
|
380
|
+
"listed": 3642,
|
|
381
|
+
"considered": 143,
|
|
382
|
+
"exact": 8,
|
|
383
|
+
"relatedTests": 6,
|
|
384
|
+
"docs": 1
|
|
385
|
+
},
|
|
386
|
+
"tokens": {
|
|
387
|
+
"total": 18000,
|
|
388
|
+
"files": 16000,
|
|
389
|
+
"byFile": [
|
|
390
|
+
{
|
|
391
|
+
"path": "packages/mcp-server/src/codeContextTools.ts",
|
|
392
|
+
"roles": ["exact"],
|
|
393
|
+
"tokens": 2400,
|
|
394
|
+
"bytes": 9600,
|
|
395
|
+
"lineCount": 220
|
|
396
|
+
}
|
|
397
|
+
],
|
|
398
|
+
"estimateVersion": "char-div-4-v1"
|
|
399
|
+
},
|
|
400
|
+
"evidenceKinds": ["session_validation"],
|
|
401
|
+
"evidenceCount": 1,
|
|
402
|
+
"primaryRefs": ["packages/mcp-server/src/codeContextTools.ts"],
|
|
403
|
+
"errorCodes": ["TS2305"],
|
|
404
|
+
"readinessStatus": "edit_ready_from_evidence",
|
|
405
|
+
"warnings": [],
|
|
406
|
+
"noLive": { "pass": true }
|
|
407
|
+
}
|
|
408
|
+
}
|
|
409
|
+
```
|
|
410
|
+
|
|
411
|
+
Token counts are deterministic estimates for context sizing and debugging. They are not billing telemetry and should not be used as provider accounting.
|
|
412
|
+
|
|
413
|
+
## `rhei_code_agent` V1 external-agent handoff
|
|
414
|
+
|
|
415
|
+
`rhei_code_agent` is the Rhei-native report-only surface for coordinating external local agents from one parent task without granting write, provider, network, graph, session-mutation, or apply authority. It is distinct from the lower-level Code Session edit tools and is not an executor: it packages agent handoffs, imports agent results, and ranks/summarizes evidence so a human or a later gated workflow can decide what to do next.
|
|
416
|
+
|
|
417
|
+
The public agent family is additive over that same substrate:
|
|
418
|
+
|
|
419
|
+
- `rhei_agent_explore`: `action=start | poll | wait | cancel`, always maps to `explore_agent`.
|
|
420
|
+
- `rhei_agent_run`: `action=start | poll | wait | cancel | get_log | steer | respond | import_result | summarize | rank`, with role labels `explore`, `engineer`, `pair`, `review`, `validate`, and `design`. `executionMode=live` starts the local process plane; `executionMode=sandbox` starts the Modal AgentEditSession plane only when Modal runner env is configured.
|
|
421
|
+
- `rhei_agent_manage`: `action=list_agents | list_sessions | get_log | extract_handoff | handoff | create_session | resume_session | stop_session | cleanup_sessions | list_workflows`.
|
|
422
|
+
|
|
423
|
+
These public tools are the preferred agent-facing entry points and their MCP schemas require `action`, not legacy `mode`. `rhei_code_agent` remains a lower-level compatibility substrate for typed V1 handoffs/imports/ranking and is hidden from the default public MCP profile; use the full profile only for contract tests, migration work, or granular debugging.
|
|
424
|
+
|
|
425
|
+
Public agent boundary: execution planes are explicit. The local process plane is process-local and report-only; the fake adapter remains default, and the Codex CLI adapter is opt-in. The sandbox plane is Modal-backed AgentEditSession handoff only; it reuses allowed paths, denied paths, validation command, callback HMAC, baseline checks, and no-canonical-apply authority. Explicit sandbox callback imports use `rhei_agent_run action=import_result` with the Modal callback envelope; successful imports update the process-local sandbox session, result bundle, summary/ranking surfaces, and public logs without applying source changes. Requests for unsupported live or sandbox actions must return structured boundary receipts rather than silently degrading into another execution plane.
|
|
426
|
+
|
|
427
|
+
V1 role vocabulary is deliberately small:
|
|
428
|
+
|
|
429
|
+
- `explore_agent`: finds required refs, likely risks, missing evidence, and next-read guidance.
|
|
430
|
+
- `engineer_agent`: proposes an edit plan and patch preview only; no source writes or provider calls.
|
|
431
|
+
- `review_agent`: critiques the proposal, proof gaps, risk coverage, and compliance.
|
|
432
|
+
- `validation_agent`: checks commands, evidence receipts, test/docs coverage, and validation gaps.
|
|
433
|
+
- `design_agent`: critiques architecture, product, UX, and workflow shape; produces design notes, risks, alternatives, and decision guidance. It is advisory/report-only by default.
|
|
434
|
+
|
|
435
|
+
There is no core `pair_agent` handoff role in V1. The public `pair` label is a UX/agent-routing convenience on `rhei_agent_run`; it maps to `engineer_agent` and emits `rhei_agent_run:pair_maps_to_engineer_agent_v1` so clients can display the compatibility boundary.
|
|
436
|
+
|
|
437
|
+
The expected multi-agent eval shape is one parent task with three child handoffs:
|
|
438
|
+
|
|
439
|
+
```text
|
|
440
|
+
parent rhei_code_agent task
|
|
441
|
+
-> explore_agent child handoff: required refs + risks
|
|
442
|
+
-> engineer_agent child handoff: proposal + in-memory patch preview
|
|
443
|
+
-> review_agent child handoff: critique + proof gaps
|
|
444
|
+
-> import child results
|
|
445
|
+
-> rank/summarize by required-ref recall, proposal quality, patch preview correctness,
|
|
446
|
+
risk/proof coverage, token use/repeated reads when available, and no-write/no-provider compliance
|
|
447
|
+
```
|
|
448
|
+
|
|
449
|
+
Imported child results must remain evidence. Token counts are context-sizing estimates, repeated-read counts are workflow-quality signals, and patch previews are review artifacts. They do not authorize the apply leg of `rhei_code_edits`, provider calls, live Oracle calls, Memgraph execution, route persistence, or Truth Gate promotion.
|
|
450
|
+
|
|
451
|
+
Focused coverage lives in `convex-tests/codeLayer/rheiCodeAgentHandoff.contract.test.ts`, `convex-tests/codeLayer/codeAgent.test.ts`, and `convex-tests/codeLayer/codeAgentTools.test.ts`. Those tests document the public API, exercise the core `packages/core/src/codeAgent/*` builders, assert the registered `rhei_code_agent` plus `rhei_agent_*` family contracts, cover handoff creation, result import, summary/ranking, required-ref recall, proposal/proof/risk/validation/efficiency signals, and preserve the no-live/no-provider/no-authority guardrails.
|
|
452
|
+
|
|
453
|
+
## `rhei_code_run` V1 run graph switchboard
|
|
454
|
+
|
|
455
|
+
`rhei_code_run` is the process-local parent control-plane for coordinating multiple report-only code workflow artifacts. It is not an executor: it never spawns agents, calls providers, persists to Convex, writes files, promotes canon, or grants apply authority. It records the visible graph that a parent session can inspect before deciding what to do next.
|
|
456
|
+
|
|
457
|
+
Supported modes:
|
|
458
|
+
|
|
459
|
+
- `start`: create a parent `RheiCodeRunGraphV1` with a root node.
|
|
460
|
+
- `add_oracle`: attach an existing Oracle session/reference node.
|
|
461
|
+
- `add_agent_handoff`: attach one or more existing agent handoff references as visible child nodes.
|
|
462
|
+
- `import_agent_result`: import external agent result reports as evidence nodes.
|
|
463
|
+
- `rank_results`: rank imported result nodes by required-ref coverage and readiness signals.
|
|
464
|
+
- `switch_active`: move the active-node pointer for context switching.
|
|
465
|
+
- `context`: return the current active node, visible node ids, delegation leases, and parent control-plane metadata.
|
|
466
|
+
- `summarize`: return node counts, active lease counts, refs, warnings, and next action.
|
|
467
|
+
|
|
468
|
+
Delegated autonomy is modeled as data only. Agent/run nodes can carry a `delegationPolicy` with `allowedRoles`, `maxDepth`, `maxChildren`, token/time budgets, `writeAllowed: false`, `parentCanCancel: true`, and `parentCanSupersede: true`. When a node can delegate, the graph records a `DelegationLeaseV1` with child node ids, status, budget, expiry, `revocable: true`, `reportOnly: true`, `noAuthority: true`, and `noWriteAuthority: true`. Exhausted role/depth/child-count constraints pause the branch and emit warnings; they do not execute cancellation or hidden work.
|
|
469
|
+
|
|
470
|
+
Focused coverage lives in `convex-tests/codeLayer/codeRunTools.test.ts`. The contract test covers one parent run, one Oracle node, two handoff nodes, two imported results, ranking/next action, active-node context switching, visible delegation leases, and paused/warning behavior for bounded child-spawn constraints.
|
|
471
|
+
|
|
472
|
+
## Code Session V1
|
|
473
|
+
|
|
474
|
+
The default V1 session loop is local, read-only, and dry-run only:
|
|
475
|
+
|
|
476
|
+
```text
|
|
477
|
+
rhei_code_context_for_goal
|
|
478
|
+
-> rhei_code_prepare_work
|
|
479
|
+
-> rhei_code_session_start
|
|
480
|
+
-> rhei_code_read exact slices
|
|
481
|
+
-> rhei_code_edit_cycle
|
|
482
|
+
-> rhei_code_session_diff for review / reverse preview / Trail evidence
|
|
483
|
+
-> review separate proposal / impactPrediction / proofPlan / dryRun / validation artifacts
|
|
484
|
+
-> optional rhei_code_io op=edit for two-call workflowPlan -> multi-file preview
|
|
485
|
+
-> optional rhei_code_edits default transaction for low-ceremony preview/apply/verify
|
|
486
|
+
```
|
|
487
|
+
|
|
488
|
+
`rhei_code_edit_cycle` is a clean-loop convenience, not a new authority layer. The granular tools remain available and distinct for proposal, proof, dry-run, validation, and review; low-ceremony edit work goes through `rhei_code_edits` with no phase required for the normal case. Use `phase=preedit` only when an agent wants preview without the apply attempt, and `phase=afteredit` only to re-verify a prior apply. Use `editsByPath` when many edits target one file; grouped changes are flattened in order, pattern `editKind` can be inferred from `search` + `replace`, and dry-run/apply preflight evaluates same-file edits sequentially before any gated write path exists.
|
|
489
|
+
|
|
490
|
+
`rhei_code_session_diff` is the review-facing view of session changes. It can summarize a selected proposal or dry-run, return a compact patch preview, and return a reverse patch preview for agent analysis. The reverse preview is evidence only: `revertAvailable` is false, `sourceWrites` is false, and any future revert/apply path must go through Writer Arbitration. This makes session diffs suitable for Trail projection, PR-session analysis, review-comment learning, and proposal ranking without turning review evidence into write authority.
|
|
491
|
+
|
|
492
|
+
`rhei_code_search` is the single Code Session search surface. Keep basic use as `query` plus optional `facets`; turn on richer behavior with `purpose`, `profile`, `engines`, `depth`, and `budget`. Profiles are `fast_local`, `smart_local`, `semantic_readonly`, `graph_advisory`, `full_readonly_ranked`, plus recall-gradient aliases `action`, `integration`, `audit`, and `prove_absence`. The default profile is `graph_advisory`: local lexical/index/codemap ranking with connected shallow refs and soft graph depth3 advisory evidence. Local MCP never executes Convex, Qdrant, Memgraph, embedding providers, network calls, or writes from search. Semantic/Qdrant/Convex engines consume supplied evidence arrays only, graph refs stay labeled advisory evidence, `memgraph: true` only records a no-live warning, and graph depth above 3 requires `depth5EvalOnly: true` so depth5 cannot become the default path by accident. Search returns per-ref `rankingEvidence`, no-live flags, evidence refs, warnings, and a `nextReadPlan` bounded by the requested token/ref budget.
|
|
493
|
+
|
|
494
|
+
For recall-sensitive questions, use audit purposes: `integration_audit`, `caller_audit`, `surface_audit`, or `prove_absence`, with `coverage: true` and optional `scopePaths`. Audit/prove-absence searches scan the live local filesystem outside the current selected refs unless explicit candidate refs constrain the scope, then return `coverageReceipt` with searched/matched file counts, searched scopes, truncation, matched refs, recommended exact refs, and absence claims. If the scan is truncated or files are skipped, absence confidence is low and warnings include `coverage:absence_not_proven`.
|
|
495
|
+
|
|
496
|
+
MCP tool responses are compact by default for agent use: `rhei_code_context_for_goal` omits full snapshots, raw `observability.tokens.byFile`, prompt text, and duplicated long ref arrays; it keeps counts plus omitted totals so agents can see when to expand. `rhei_code_search` caps returned refs but preserves counts, omitted totals, and absence confidence in `coverageReceipt`.
|
|
497
|
+
|
|
498
|
+
Code Session payloads expose `liveEvidence` and `taskDisplay` so agents can see whether Memgraph/Qdrant/Convex evidence was requested or supplied upstream. These fields are status and routing metadata only. Default mode is `no_live`, graph advisory is `soft_graph_depth3`, Code Session itself does not execute live backends, and local MCP session display does not write Convex task state. Cloud task display requires a cloud/workroom session id from the Convex session layer.
|
|
499
|
+
|
|
500
|
+
`CodeImpactPredictionV1` may consume planner graph refs, service connection ids, receipts, and explicit Synapse impact evidence as labeled advisory evidence. It exposes supplied Synapse evidence as a sanitized `synapseEvidence` packet with `execution.attempted`, `execution.memgraphExecuted`, `execution.providerCalls`, and `execution.writes` forced to `false`. It does not execute Memgraph, call providers, promote graph/service hints to truth, write files, or authorize apply. Writer Arbitration is separate and remains disabled for production V1.
|
|
501
|
+
|
|
502
|
+
|
|
503
|
+
`ProofSynapseV1` is the companion evidence map. Impact Synapse predicts what may be affected; Proof Synapse states what must be proven before the proposal can move forward: focused tests, docs, contracts, validation commands, missing evidence, traceability expectations, collaboration roles, and a dry-run/human-review verdict. It is report-only, advisory-only, no-authority, and cannot approve or apply edits.
|
|
504
|
+
|
|
505
|
+
`rhei_code_session_act` is the local one-call task helper for agents. It keeps the phase objects separate in the response: context selection and Planner Graph Advisory explain why refs were selected, `CodeImpactPredictionV1` predicts impact, `ProofSynapseV1` maps required evidence, dry-run checks the patch, and Writer Arbitration decides whether optional apply can run. Without `applyMode: "local_beta"`, it never writes.
|
|
506
|
+
|
|
507
|
+
## MCP Surface Benchmark Snapshot
|
|
508
|
+
|
|
509
|
+
Rhei's public MCP surface is optimized for agent workflow cost, not raw tool count. The release benchmark compares shared capabilities across Rhei, codedb, codegraph, and RepoPrompt by the bytes an agent actually receives: MCP `structuredContent` plus text content, converted to an approximate token count with `bytes / 4`. Rhei keeps richer receipts available through normal/debug modes, while narrow output modes make the common read/search/graph lanes as small as their equivalent comparator tasks.
|
|
510
|
+
|
|
511
|
+
Current narrow modes:
|
|
512
|
+
|
|
513
|
+
| Mode | Public path | Use |
|
|
514
|
+
| --- | --- | --- |
|
|
515
|
+
| `outputMode=content` | `read_file` | Return only path, line range, and source content for a read slice. |
|
|
516
|
+
| `outputMode=locator` | `file_search mode=symbol` | Return compact symbol rows with `path`, `symbol`, `kind`, `stableKey`, line, and score. |
|
|
517
|
+
| `outputMode=edges` | `graph op=callers/callees/neighbors/impact` | Return compact relationship rows without the full receipt envelope. |
|
|
518
|
+
|
|
519
|
+
Latest local cross-tool run, generated 2026-06-08:
|
|
520
|
+
|
|
521
|
+
| Comparator | Comparable lanes | Rhei tokens | Comparator tokens | Savings | Interpretation |
|
|
522
|
+
| --- | ---: | ---: | ---: | ---: | --- |
|
|
523
|
+
| codedb MCP | read + symbol + callers | ~584 | ~1,395 | ~811 saved, 58% less | Clean same-MCP win across the shared lanes. |
|
|
524
|
+
| RepoPrompt MCP-bound | read + symbol | ~516 | ~784 | ~268 saved, 34% less | RepoPrompt is measured through `bind_context`; it has no callers/callees primitive. |
|
|
525
|
+
| codegraph CLI | symbol + callers | ~222 | ~874 | ~653 saved, 75% less | Directional only: codegraph MCP timed out locally; CLI callers alone is smaller than Rhei by ~32 tokens. |
|
|
526
|
+
| Successful same/bound MCP rows | codedb MCP + RepoPrompt bound | ~1,100 | ~2,179 | ~1,079 saved, 50% less | Best release-safe aggregate claim from the current benchmark. |
|
|
527
|
+
|
|
528
|
+
Per-lane detail:
|
|
529
|
+
|
|
530
|
+
| Lane | Rhei | Comparator | Savings |
|
|
531
|
+
| --- | ---: | ---: | ---: |
|
|
532
|
+
| Read slice vs codedb MCP | ~363 tok | ~860 tok | ~498 tok, 58% |
|
|
533
|
+
| Read slice vs RepoPrompt bound | ~363 tok | ~392 tok | ~29 tok, 7% |
|
|
534
|
+
| Symbol locate vs codedb MCP | ~153 tok | ~295 tok | ~142 tok, 48% |
|
|
535
|
+
| Symbol locate vs RepoPrompt bound | ~153 tok | ~392 tok | ~239 tok, 61% |
|
|
536
|
+
| Callers graph vs codedb MCP | ~69 tok | ~240 tok | ~171 tok, 71% |
|
|
537
|
+
| Callers graph vs codegraph CLI | ~69 tok | ~37 tok | Rhei costs ~32 more tokens, but is faster and MCP-native. |
|
|
538
|
+
|
|
539
|
+
The clean release claim is:
|
|
540
|
+
|
|
541
|
+
```text
|
|
542
|
+
On successful same/bound MCP comparator rows, Rhei's narrow public modes reduce
|
|
543
|
+
agent-facing payload by about 50% overall. Against codedb MCP across read,
|
|
544
|
+
symbol lookup, and callers, Rhei uses about 58% fewer tokens.
|
|
545
|
+
```
|
|
546
|
+
|
|
547
|
+
Benchmark artifacts live under `convex-tests/evals/reports/mcp-compare/`:
|
|
548
|
+
|
|
549
|
+
- `cross-tool-scoreboard.md`: Rhei vs codedb/codegraph/RepoPrompt shared-lane scoreboard.
|
|
550
|
+
- `cross-tool.jsonl`: machine-readable cross-tool measurements.
|
|
551
|
+
- `rhei-surface-overview.md`: Rhei public-surface payload and latency overview.
|
|
552
|
+
- `rhei-surface.jsonl`: machine-readable Rhei surface measurements.
|
|
553
|
+
|
|
554
|
+
Run the current benchmarks from the repo root workspace:
|
|
555
|
+
|
|
556
|
+
```bash
|
|
557
|
+
cd /Users/mibook/Code/saga/rhei
|
|
558
|
+
RP_CLI_WINDOW=1 CODEDB_BIN=codedb CODEGRAPH_BIN=codegraph \
|
|
559
|
+
bun --env-file=.env convex-tests/evals/tools/mcpCrossToolBench.ts
|
|
560
|
+
|
|
561
|
+
RHEI_SURFACE_INCLUDE_CROSS_TOOL=0 MCP_SURFACE_REPO=/Users/mibook/Code/saga/rhei \
|
|
562
|
+
bun --env-file=.env convex-tests/evals/tools/rheiSurfaceOverview.ts
|
|
563
|
+
```
|
|
564
|
+
|
|
565
|
+
For a harder release benchmark, use macro task profiles instead of only per-call micro lanes:
|
|
566
|
+
|
|
567
|
+
| Profile | Measures |
|
|
568
|
+
| --- | --- |
|
|
569
|
+
| `symbol_to_impact` | Locate a symbol, read its definition, find callers/callees, and summarize blast radius. |
|
|
570
|
+
| `change_readiness` | Locate target code, read implementation and tests, graph impact, and recommend validation. |
|
|
571
|
+
| `reuse_or_dead_code` | Search a symbol family, inspect graph neighbors, return reuse/dead-code candidates, and read top evidence. |
|
|
572
|
+
| `root_mismatch_recovery` | Intentionally use a wrapper repo root and measure whether the tool explains the artifact/root mismatch and fix. |
|
|
573
|
+
|
|
574
|
+
Those macro profiles should score total transcript tokens, turns, latency, answer correctness, and recovery quality. They are a better product benchmark than micro payload alone because they measure whether Rhei saves tokens across the whole agent workflow.
|
|
575
|
+
|
|
576
|
+
Latest repeated external JS act benchmark evidence, generated 2026-05-18 from three real Codex CLI runs on the local `escape-string-regexp` fixture, shows the one-call Rhei dry-run loop using a mean 62,229 tokens versus RepoPrompt's mean 233,585 tokens. That is 171,356 fewer tokens per run, a 73.4% reduction, or 26.6% of RepoPrompt token usage. The same token budget therefore buys about 3.75x more bounded edit-session work. The stability signal is as important as the mean: RepoPrompt ranged from 93k to 367k tokens across repeats, while Rhei stayed tightly around 62k-63k with required-ref recall, patch preview correctness, and expected-match correctness all at 1.0. The batch report remains a local fixture benchmark, not a universal production claim; it used read-only sandboxing, approval policy `never`, and no source writes.
|
|
577
|
+
|
|
578
|
+
## Migration Synapse V1
|
|
579
|
+
|
|
580
|
+
Migration Synapse is a ProgramPlan specialization, not a separate execution product. For migration or rewrite goals, `ProgramPlanV1` remains the entry point and can attach `MigrationPlanV1` with `includeMigrationPlan: true` or by automatic migration classification. The migration plan is report-only and contains the migration rulebook, inventory shards, first safe shard, proof strategy, risks, and guardrails.
|
|
581
|
+
|
|
582
|
+
The intended flow is:
|
|
583
|
+
|
|
584
|
+
```text
|
|
585
|
+
ProgramPlanV1
|
|
586
|
+
-> MigrationPlanV1
|
|
587
|
+
-> first safe migration shard
|
|
588
|
+
-> auto-sliced ContextPacketV1
|
|
589
|
+
-> RheiCodeSessionV1
|
|
590
|
+
-> CodeImpactPredictionV1
|
|
591
|
+
-> ProofSynapseV1
|
|
592
|
+
-> dry-run / validation
|
|
593
|
+
-> Writer Arbitration for future apply only
|
|
594
|
+
```
|
|
595
|
+
|
|
596
|
+
The apply leg of `rhei_code_edits` is registered as part of the edit family, but source writes remain disabled unless `RHEI_CODE_SESSION_ENABLE_APPLY_EDITS=1` is set in local beta or disposable benchmark sessions. The tmp test bypass uses `applyMode: "test_bypass"` with `confirmTestOnly: true`, `confirmNoProduction: true`, and a `testBypassReceipt`; the repo path must be under `os.tmpdir()` or `RHEI_CODE_SESSION_APPLY_ROOT_ALLOWLIST`.
|
|
597
|
+
|
|
598
|
+
For low-ceremony local development, `phase: "apply"` with `applyMode: "local"`, `confirmLocalCodebase: true`, `confirmNoProduction: true`, and `executeValidation: true` reruns executable validation when the preview only recorded evidence-only/skipped validation. Apply still reports `productionAuthority: false`, requires the repo path to match the root allowlist, and performs durable readback before afteredit verification.
|
|
599
|
+
|
|
600
|
+
For Rhei self-development local beta only, launch the MCP server with `bun run mcp:rhei:local-beta`, then use `applyMode: "local_beta"` with `confirmLocalBeta: true`, `confirmNoProduction: true`, `localBetaReceipt`, `approvalRef`, and `leaseId`. Do not give this command to closed-beta testers; tester setup should use the default `bun run mcp:rhei` public profile. Local beta still requires a prior `CodeImpactPredictionV1` with sanitized predictive Synapse evidence (`reportOnly`, `advisoryOnly`, `noAuthority`, and no live execution flags), a passing dry-run, baseline hash match, expected match counts, receipts, Trail projection metadata, explicit root allowlist, and protected-path checks. It returns `writer_arbitration_local_beta`, `productionAuthority: false`, and blocks secret-like, generated, vendor, VCS, and build-output paths.
|
|
601
|
+
|
|
602
|
+
`rhei_code_session_start` accepts `contextForGoal` plus the agent-friendly aliases `context`, `contextPacket`, and `contextForGoalPayload`. If no context object is supplied, it uses the most recent process-local `rhei_code_context_for_goal` metadata for the same MCP server process, or a matching `contextRequestId` when supplied. Absolute paths under `repoPath` are normalized back to repo-relative refs before reads/searches are counted.
|
|
603
|
+
|
|
604
|
+
`rhei_code_session_start` accepts explicit `blockedRefs`/`excludedRefs`/`forbiddenRefs` for session policy. Automatic selection and search skip those refs, and exact read/proposal attempts against them fail read-only with a blocked-by-policy error. This is a selection safety constraint only; it is not Writer Arbitration and does not authorize writes.
|
|
605
|
+
|
|
606
|
+
## Code Strategy Plan V1
|
|
607
|
+
|
|
608
|
+
`rhei_code_strategy_plan` is a local, deterministic strategy-prompt surface for the planning handoff between Code Context/ProgramPlan evidence and a later Code Session. It returns `CodeStrategyPlanV1` with connected file groups, generated strategy prompts, oracle boolean feedback metadata, and token estimates by path, group, prompt, and feedback. It never includes source text in the plan.
|
|
609
|
+
|
|
610
|
+
Use it after `rhei_code_context_for_goal`, after a `ProgramPlanV1`/`MigrationPlanV1`, or after `rhei_code_session_context` when an agent needs a more explicit strategy prompt before reading or proposing edits:
|
|
611
|
+
|
|
612
|
+
```json
|
|
613
|
+
{
|
|
614
|
+
"goal": "Plan the next safe implementation slice for CodeStrategyPlan docs",
|
|
615
|
+
"strategyKind": "auto",
|
|
616
|
+
"promptSpecificity": "balanced",
|
|
617
|
+
"contextForGoal": { "...": "rhei_code_context_for_goal payload" },
|
|
618
|
+
"codeSessionContext": { "...": "optional rhei_code_session_context payload" },
|
|
619
|
+
"oracleFeedback": [
|
|
620
|
+
{
|
|
621
|
+
"feedbackId": "feedback:make-validation-more-specific",
|
|
622
|
+
"questionKind": "specific_enough",
|
|
623
|
+
"answer": false,
|
|
624
|
+
"targetPromptId": "prompt:code-strategy:implementation_slice:example:validation"
|
|
625
|
+
}
|
|
626
|
+
]
|
|
627
|
+
}
|
|
628
|
+
```
|
|
629
|
+
|
|
630
|
+
Feedback is report-only metadata. `specific_enough: false` or `too_abstract: true` shifts the target prompt one step more specific; `abstract_enough: false` or `too_specific: true` shifts it one step more abstract. Conflicting feedback is summed and clamped deterministically. It does not approve work, bypass scope, or grant authority.
|
|
631
|
+
|
|
632
|
+
If only `sessionId` is supplied, the tool builds Code Session context from the process-local session and may increment Code Session tool-call telemetry. That mutation is observability-only; it does not read source, write files, call providers, execute commands, or authorize apply.
|
|
633
|
+
|
|
634
|
+
`CodeStrategyPlanV1` guardrails are fixed to `reportOnly`, `advisoryOnly`, `noAuthority`, `noProviderCalls`, `noNetworkCalls`, `noFilesystemSourceScan`, and `workingSetGrantsAuthority: false`. Token estimates use the same `char-div-4-v1` convention as Code Context/Code Session and are context-sizing estimates, not billing telemetry.
|
|
635
|
+
|
|
636
|
+
## Workflow Plan V1
|
|
637
|
+
|
|
638
|
+
`rhei_code_workflow_plan` is a local, deterministic planning surface for the handoff after Code Strategy Plan and before any Code Session/Proof Synapse write flow. It returns the `strategyPlan` and `workflowPlan` side by side with `advisoryOnly: true`, `noAuthority: true`, and a no-live snapshot.
|
|
639
|
+
|
|
640
|
+
Public `workflowKind` values are `orchestrate`, `deep_plan`, `investigate`, `review`, `optimize`, `refactor`, and `export_context`. `workflowKind` chooses the user-facing workflow intent and read-slice priorities. `workflowPreset` chooses planning/token shape (`compact_plan`, `balanced_plan`, or `deep_plan`). Support metadata uses `supportStatus`: active means implemented in V1; planned vocabulary must remain metadata-only and must not add executable workflow kinds.
|
|
641
|
+
|
|
642
|
+
Workflow specializations are internal routing metadata only: `drift_repair`, `migration_slice`, `service_boundary`, `proof_hardening`, `security_review`, `performance_tuning`, and `context_compression`. They may steer prompt packets, service gates, risk emphasis, or read-slice priority inside the planner, but they are not public workflow kinds, public tools, or user-facing workflow names.
|
|
643
|
+
|
|
644
|
+
Legacy compatibility aliases may still be accepted as inputs: `review_proposal` maps to `review`, `optimize_context` maps to `optimize` and may use `context_compression`, `refactor_slice` maps to `refactor`, `migration_slice` maps to `refactor` plus the `migration_slice` specialization, and `drift_repair` maps by intent plus the `drift_repair` specialization. New docs and examples should use the public workflow vocabulary above.
|
|
645
|
+
|
|
646
|
+
Service boundaries are represented as compact control-plane refs only. `serviceConnectionIds` identify connected contracts, while `serviceConnectionGates` explain whether those IDs and service evidence refs are satisfied, need contract context, need a compact ID, or need external evidence. Gates are blocking-before-write, report-only, advisory-only, and no-authority. They may include IDs, evidence refs, context group IDs, and required read-slice IDs; they must not include service contract body text.
|
|
647
|
+
|
|
648
|
+
`sessionSelect` tells an agent what to read next without reading it itself: `exactRefs`, `readSlices`, `avoidRefs`, stop conditions, and a deterministic `char-div-4-v1` read-token budget. Required service evidence slices are selected before optional slices. Overflow and explicitly avoided non-required refs stay in `avoidRefs`.
|
|
649
|
+
|
|
650
|
+
Oracle integration is prompt-packet-only. `OraclePromptPacketV1` carries `workflowKind`, `workflowPreset`, service connection IDs, source strategy identifiers/hashes, context group IDs, selected read-slice IDs, boolean questions, prompt text, and execution flags all set to false. Every active workflow emits a `context_sufficiency` question; service gates add `connected_contract`. `rhei_code_workflow_plan` does not call a live Oracle/provider, fetch source text, mutate Code Session state, execute commands, or write files.
|
|
651
|
+
|
|
652
|
+
`rhei_code_oracle` is the primary Oracle workflow loop for those packets. V1 is still no-live and report-only. Use `mode: "session_start"` / `mode: "session_context"` / `mode: "fork_session"` to manage the process-local Oracle session artifact, `mode: "manage_workspace"` to add/set/remove/get/clear a process-local Oracle workspace selection, `mode: "build_context_bundle"` to materialize bounded `sessionSelect` source slices for Oracle review, `mode: "export_markdown"` to render a shareable markdown packet from a context bundle, `mode: "plan_packets"` to surface/refine prompt packets, `mode: "import_feedback"` to pass external/user Oracle answers, `mode: "refine_workflow"` to recompile the workflow/handoff from imported feedback, and `mode: "summarize_feedback"` to compact the feedback result for review or learning evidence.
|
|
653
|
+
|
|
654
|
+
`mode: "manage_workspace"` is the Rhei-native equivalent of curating an Oracle workspace selection. Pass `workspaceAction: "add" | "set" | "remove" | "clear" | "get"`, use `connectedFiles` or `workspaceFiles` for files and line slices, and use `pathOnlyRefs` / `workspacePathOnlyRefs` for future or new files. This only mutates the process-local Oracle session artifact; it does not read, write, spawn agents, or call providers.
|
|
655
|
+
|
|
656
|
+
`mode: "build_context_bundle"` returns an exportable `OracleContextBundleV1` in the MCP payload and process-local Oracle session. It is not a durable file write. Source text can only come from compiled `sessionSelect.readSlices` / `exactRefs` plus explicit `manage_workspace` selected read slices. Direct `pathOnlyRefs`, `exportedPathOnlyRefs`, and workspace path-only refs are metadata-only and are useful for new-file refs in external-agent handoffs. Supplying `forcePaths` to this mode is ignored with a warning because `forcePaths` belongs in workflow planning, not bundle materialization.
|
|
657
|
+
|
|
658
|
+
`mode: "export_markdown"` returns `markdownExport.markdown` plus token accounting, read receipts, external Oracle model metadata, and return instructions for `mode: "import_feedback"`. It defaults to `externalOracleModel: "gpt-5.5"` and `externalOracleReasoningEffort: "low"` when those fields are omitted. `exportPath` is recorded as a suggested path only; V1 does not write files, call providers, open network connections, or run a live Oracle session.
|
|
659
|
+
|
|
660
|
+
Pass external/user Oracle feedback plus an existing strategy, workflow, handoff, or context payload; the tool recompiles typed artifacts, retargets feedback when generated IDs change, returns token deltas and applied feedback summaries, and keeps `reportOnly`, `advisoryOnly`, `noAuthority`, `noProviderCalls`, and `noSessionMutation` fixed to true.
|
|
661
|
+
|
|
662
|
+
When `sessionId` is supplied without `codeSessionContext`, `rhei_code_workflow_plan` deliberately ignores it and returns `workflow_tool:session_id_ignored_to_avoid_session_mutation`. To include session evidence, callers must pass an already-built `codeSessionContext` payload explicitly.
|
|
663
|
+
|
|
664
|
+
```json
|
|
665
|
+
{
|
|
666
|
+
"goal": "Plan a bounded refactor workflow",
|
|
667
|
+
"contextForGoal": { "...": "rhei_code_context_for_goal payload" },
|
|
668
|
+
"workflowKind": "refactor",
|
|
669
|
+
"workflowPreset": "compact_plan",
|
|
670
|
+
"serviceConnectionIds": ["service:billing-contract"],
|
|
671
|
+
"serviceConnectionRefs": [
|
|
672
|
+
{
|
|
673
|
+
"serviceConnectionId": "service:billing-contract",
|
|
674
|
+
"evidenceRef": "docs/contracts/billing.md",
|
|
675
|
+
"reason": "external API boundary"
|
|
676
|
+
}
|
|
677
|
+
],
|
|
678
|
+
"avoidRefs": ["docs/broad-background.md"],
|
|
679
|
+
"sessionSelectTokenBudget": 2000
|
|
680
|
+
}
|
|
681
|
+
```
|
|
682
|
+
|
|
683
|
+
`plannerHandoffGraphAdvisory` is optional metadata on `rhei_code_context_for_goal` and `rhei_code_context_build_work_brief`. Graph routing advisory explains context selection. It does not authorize graph mutation, provider synthesis, Memgraph execution, code writes, or Truth Gate promotion. The server normalizes unsafe input back to `reportOnly: true`, `advisoryOnly: true`, `noAuthority: true`, `memgraphAllowed: false`, `depth5Allowed: false`, and `synapsePredictionInputAllowed: false`. It is not fed into Synapse prediction unless `rhei_code_plan_edits` is explicitly called in a session flow; it never triggers provider calls, route persistence, UI surfacing, production writes, or graph default changes. Depth5 remains non-default and production default mode remains `convex_local`.
|
|
684
|
+
|
|
685
|
+
Use `rhei_code_context_runs` to inspect recent local calls:
|
|
686
|
+
|
|
687
|
+
```json
|
|
688
|
+
{
|
|
689
|
+
"repoPath": "/Users/mibook/saga/rhei",
|
|
690
|
+
"limit": 5
|
|
691
|
+
}
|
|
692
|
+
```
|
|
693
|
+
|
|
694
|
+
The run log is in-memory for the MCP server process and resets on restart. It stores metadata only: no file contents, no raw goal text, no provider calls, and no production writes.
|
|
695
|
+
|
|
696
|
+
`includeProgramPlan` defaults to auto: program-scale goals get a report-only `ProgramPlanV1`; bounded coding tasks stay on Code Context unless you pass `includeProgramPlan: true`.
|
|
697
|
+
|
|
698
|
+
`reportOnlyEvidence` is optional. It is how local/web Rhei can attach Connected Surface Coverage or Growth Diagnostics summaries to the same Code Context snapshot without giving those diagnostics execution authority. `includeSurfaceCoverage` and `includeGrowthDiagnostics` generate deterministic report-only cards from the selected context only; they do not run live planners, providers, Convex writes, Memgraph, route persistence, or capability runs.
|
|
699
|
+
|
|
700
|
+
Use `rhei_code_context_build_work_brief` when web/local Rhei already supplied Code Context. It accepts either:
|
|
701
|
+
|
|
702
|
+
- `snapshot`: a `CodeMarketSnapshotV1` JSON object.
|
|
703
|
+
- `snapshotPath`: a local path to a `CodeMarketSnapshotV1` JSON file.
|
|
704
|
+
- neither: uses the committed source-backed fixture for smoke testing only.
|
|
705
|
+
|
|
706
|
+
Selection fields:
|
|
707
|
+
|
|
708
|
+
```json
|
|
709
|
+
{
|
|
710
|
+
"snapshotPath": ".rhei/code-context/latest-code-market-snapshot.json",
|
|
711
|
+
"tileIds": ["tile-id-or-stable-key"],
|
|
712
|
+
"clusterIds": ["cluster-id-or-stable-key"],
|
|
713
|
+
"selectedRefIds": ["packages/core/src/codeMarket/workBrief.ts"],
|
|
714
|
+
"selectedRefStableKeys": ["file:repo_rhei_fixture:packages/core/src/codeMarket/workBrief.ts"],
|
|
715
|
+
"userGoal": "Plan the next safe implementation slice.",
|
|
716
|
+
"workflowPresetId": "deep_plan",
|
|
717
|
+
"plannerHandoffGraphAdvisory": {
|
|
718
|
+
"source": "mcp_input",
|
|
719
|
+
"basis": "explicit_metadata",
|
|
720
|
+
"recommendedGraphMode": "soft_graph_depth3",
|
|
721
|
+
"selectedGraphMode": "connected_work_shallow",
|
|
722
|
+
"reportOnly": true,
|
|
723
|
+
"advisoryOnly": true,
|
|
724
|
+
"noAuthority": true
|
|
725
|
+
}
|
|
726
|
+
}
|
|
727
|
+
```
|
|
728
|
+
|
|
729
|
+
The output keeps the governed handoff boundary:
|
|
730
|
+
|
|
731
|
+
- Code Context is bounded evidence, not authority.
|
|
732
|
+
- `contextPlan.exactRefs` is the initial scope.
|
|
733
|
+
- Canon changes, memory promotion, and execution still require explicit gates.
|
|
734
|
+
- No Memgraph, soft-edge projection, provider lane, capability run, route persistence, or UI surfacing is enabled by this server.
|
|
735
|
+
|
|
736
|
+
## Run From Source
|
|
737
|
+
|
|
738
|
+
From `rhei/`:
|
|
739
|
+
|
|
740
|
+
```bash
|
|
741
|
+
bun install
|
|
742
|
+
bun run --silent mcp:rhei
|
|
743
|
+
```
|
|
744
|
+
|
|
745
|
+
For direct package development:
|
|
746
|
+
|
|
747
|
+
```bash
|
|
748
|
+
bun run --cwd packages/mcp-server --silent dev:stdio
|
|
749
|
+
```
|
|
750
|
+
|
|
751
|
+
### CLI install and init
|
|
752
|
+
|
|
753
|
+
The package exposes `mcp-server`, `rhei`, `rhei-mcp`, and `saga-mcp` binaries. The `mcp-server` alias exists so plain scoped npm execution can select the package bin, which makes this work after the bundled package is published:
|
|
754
|
+
|
|
755
|
+
```bash
|
|
756
|
+
npx -y @rhei-team/mcp-server install --target auto --yes --index
|
|
757
|
+
```
|
|
758
|
+
|
|
759
|
+
Explicit-bin forms also work:
|
|
760
|
+
|
|
761
|
+
```bash
|
|
762
|
+
npx -y --package @rhei-team/mcp-server rhei install --target auto --yes --index
|
|
763
|
+
bunx --package @rhei-team/mcp-server rhei install --target auto --yes --index
|
|
764
|
+
pnpm dlx --silent --package @rhei-team/mcp-server rhei install --target auto --yes --index
|
|
765
|
+
```
|
|
766
|
+
|
|
767
|
+
`rhei-mcp` with no subcommand keeps the historical stdio MCP behavior; `rhei mcp` or `rhei serve` starts the MCP server explicitly.
|
|
768
|
+
|
|
769
|
+
Use the installer to register Rhei with local MCP clients:
|
|
770
|
+
|
|
771
|
+
```bash
|
|
772
|
+
rhei install --target auto
|
|
773
|
+
rhei doctor
|
|
774
|
+
rhei print-config --target codex
|
|
775
|
+
rhei uninstall --target codex
|
|
776
|
+
```
|
|
777
|
+
|
|
778
|
+
Supported install targets are `claude`, `codex`, `gemini`, `cursor`, `windsurf`, `devin`, and `opencode`; `auto`, `all`, and comma-separated target lists are accepted. `rhei init --path /path/to/repo --install` registers clients, builds the local index, warms SQL reports, and prints a repository overview.
|
|
779
|
+
|
|
780
|
+
Safe repeat-test loop without touching real MCP client configs:
|
|
781
|
+
|
|
782
|
+
```bash
|
|
783
|
+
tmp_home=$(mktemp -d)
|
|
784
|
+
|
|
785
|
+
HOME="$tmp_home" \
|
|
786
|
+
RHEI_PROGRESS=plain \
|
|
787
|
+
RHEI_MCP_INSTALL_COMMAND=bun \
|
|
788
|
+
RHEI_MCP_INSTALL_ARGS='--cwd /Users/mibook/Code/saga/rhei/packages/mcp-server tsx src/index.ts' \
|
|
789
|
+
bun --cwd /Users/mibook/Code/saga/rhei/packages/mcp-server tsx src/index.ts install \
|
|
790
|
+
--target all \
|
|
791
|
+
--yes \
|
|
792
|
+
--index \
|
|
793
|
+
--path /Users/mibook/Code/saga/rhei
|
|
794
|
+
|
|
795
|
+
HOME="$tmp_home" \
|
|
796
|
+
bun --cwd /Users/mibook/Code/saga/rhei/packages/mcp-server tsx src/index.ts uninstall \
|
|
797
|
+
--target all \
|
|
798
|
+
--yes
|
|
799
|
+
|
|
800
|
+
rm -rf "$tmp_home"
|
|
801
|
+
```
|
|
802
|
+
|
|
803
|
+
### Runtime freshness and restart verification
|
|
804
|
+
|
|
805
|
+
MCP responses include a `runtime.reloadStatus` fingerprint. Source-mode fingerprints hash the MCP server TypeScript files that affect Code Context, Code Session, and facade behavior; dist/beta-mode fingerprints hash the built JavaScript files under `dist/`. If a file changes while a client is connected, compact responses include `reloadStatus.status: "restart_required"` plus a `restartAction` and `restartWorkflow`.
|
|
806
|
+
|
|
807
|
+
Source development loop from `rhei/`:
|
|
808
|
+
|
|
809
|
+
```bash
|
|
810
|
+
bun run mcp:rhei:check # optional typecheck/build gate
|
|
811
|
+
# restart the running MCP launcher / Codex MCP session
|
|
812
|
+
# verify with rhei_code_io op=status or rhei_code_context_doctor until reloadStatus.status is current
|
|
813
|
+
```
|
|
814
|
+
|
|
815
|
+
Beta tarball loop from `rhei/`:
|
|
816
|
+
|
|
817
|
+
```bash
|
|
818
|
+
bun run mcp:rhei:pack-beta
|
|
819
|
+
# reinstall dist/rhei-mcp-beta/artifacts/rhei-mcp-server-<version>.tgz
|
|
820
|
+
# reconnect the MCP client and verify reloadStatus.status is current
|
|
821
|
+
```
|
|
822
|
+
|
|
823
|
+
If `pid` and `loadedAt` do not change after restart, the restart did not reach the connected MCP process.
|
|
824
|
+
|
|
825
|
+
For local Streamable HTTP beta testing:
|
|
826
|
+
|
|
827
|
+
```bash
|
|
828
|
+
RHEI_MCP_HTTP_AUTH_DISABLED=true \
|
|
829
|
+
RHEI_MCP_HTTP_PORT=8788 \
|
|
830
|
+
bun run --silent mcp:rhei:http
|
|
831
|
+
```
|
|
832
|
+
|
|
833
|
+
The HTTP endpoint serves `/mcp` and an unauthenticated `/healthz`. `RHEI_MCP_HTTP_AUTH_DISABLED=true` is accepted only for loopback hosts by default. Use bearer auth outside private local testing:
|
|
834
|
+
|
|
835
|
+
```bash
|
|
836
|
+
RHEI_MCP_TRANSPORT=http \
|
|
837
|
+
RHEI_MCP_HTTP_HOST=0.0.0.0 \
|
|
838
|
+
RHEI_MCP_HTTP_PORT=8788 \
|
|
839
|
+
RHEI_MCP_HTTP_BEARER_TOKEN=<token> \
|
|
840
|
+
RHEI_MCP_INDEXING_ENABLED=false \
|
|
841
|
+
bun run --cwd packages/mcp-server --silent dev:http
|
|
842
|
+
```
|
|
843
|
+
|
|
844
|
+
To deliberately run auth-disabled HTTP on a non-loopback private test network, set `RHEI_MCP_HTTP_ALLOW_INSECURE_NON_LOOPBACK=true`. Do not use that setting for hosted or enterprise endpoints.
|
|
845
|
+
|
|
846
|
+
Remote HTTP mode adds these beta tools:
|
|
847
|
+
|
|
848
|
+
- `rhei_auth_status`: reports transport/auth posture.
|
|
849
|
+
- `rhei_connect_github`: returns the configured GitHub App install URL.
|
|
850
|
+
- `rhei_link_local_repo`: explains that local repo proof requires local stdio MCP.
|
|
851
|
+
- `rhei_index_status`: reports the disabled-by-default indexing contract.
|
|
852
|
+
- `rhei_sync_status`: reports local/cloud sync defaults and consent posture.
|
|
853
|
+
- `rhei_cloud_workspace_status`: reports whether cloud workspace indexing is explicitly enabled.
|
|
854
|
+
|
|
855
|
+
Remote code-context tools require an explicit `repoPath` inside `RHEI_MCP_HTTP_REPO_ALLOWLIST`. Leaving that allowlist empty blocks server filesystem reads, which is the safer default for a public beta endpoint. A hosted MCP endpoint cannot inspect a tester's private laptop checkout; use local stdio `rhei-mcp` when the agent needs local search/read/edit over that checkout.
|
|
856
|
+
|
|
857
|
+
HTTP product boundary:
|
|
858
|
+
|
|
859
|
+
- TS `rhei-mcp` streamable HTTP is the product/enterprise HTTP surface. It owns bearer transport auth, repo allowlists, project-scoped service-principal sync, Convex policy checks, cloud workspace consent, and GitHub App/PAT verification through the Rhei backend.
|
|
860
|
+
- Rust `rhei-code-intelligence mcp-http` is a local/headless structural SQL surface. Its bearer token is local transport auth only; it has no Rhei auth, GitHub auth, Convex sync, provider, embedding, vector, or cloud workspace authority.
|
|
861
|
+
- Local stdio remains the path for agents that need to interact with the developer machine's shell/files/repo checkout. HTTP is the path for controlled remote access where filesystem scope, auth, and policy need to be explicit.
|
|
862
|
+
|
|
863
|
+
Indexing is prepared but gated by explicit flags. With `RHEI_MCP_INDEXING_ENABLED=false`, remote callers can live-scan/read allowlisted repos but cannot pass `writeLocalIndex=true`. With the flag set to `true`, remote allowlisted calls may build the deterministic local index at `.rhei/code-context/local-index.json`. Cloud source indexing is separate and remains off unless `RHEI_MCP_CLOUD_WORKSPACE_ENABLED=true` and `RHEI_MCP_CLOUD_INDEXING_ENABLED=true` are both set for an explicitly consented project.
|
|
864
|
+
|
|
865
|
+
Local/cloud sync defaults are intentionally asymmetric: proof metadata and tool/patch receipts sync by default when backend credentials exist, while selected snippets, summaries, embeddings, raw diffs, and cloud workspace indexing are off by default. Local stdio calls can produce HMAC path/content signatures and Merkle roots for proof receipts without uploading raw source, local filesystem paths, raw refs/goals, or raw origin URLs; the full local daemon tool path queues metadata-only tool, PR review, patch, and validation receipts asynchronously when those backend credentials are present. Use `RHEI_MCP_SYNC_SERVICE_KEY` for project-scoped service-principal sync; legacy bearer/apikey sync remains a migration fallback and cannot grant cloud consent. See `../../docs/plans/local-cloud-sync-boundary-2026-05-22.md`.
|
|
866
|
+
|
|
867
|
+
For dogfooding async receipt sync, call `rhei_sync_status` after a few local tool calls. The response includes `receiptQueue.pendingCount`, enqueue/start/success/failure/retry counters, the last retry/failure reason, and `syncBackend.configured` plus `syncBackend.authMode`. A healthy local loop has `syncBackend.authMode: "service_principal"`, `pendingCount: 0` after the queue drains, and increasing `succeededCount` without persistent `lastFailureReason`.
|
|
868
|
+
|
|
869
|
+
Do not publish the beta Docker image publicly if the repository source should remain private. The hosted endpoint can be shared with testers through URL plus bearer token; registry/image access is operator-only.
|
|
870
|
+
|
|
871
|
+
## Public Package Boundary
|
|
872
|
+
|
|
873
|
+
The npm package is the local runner, MCP client installer, and onboarding/indexing CLI. Treat anything shipped in that package as inspectable by users.
|
|
874
|
+
|
|
875
|
+
Do ship:
|
|
876
|
+
|
|
877
|
+
- Local MCP transport and client registration code.
|
|
878
|
+
- Local deterministic repo scanning, preflight, smoke checks, and report-only receipts.
|
|
879
|
+
- Thin CLI launchers for `mcp-server`, `rhei`, `rhei-mcp`, and `saga-mcp`.
|
|
880
|
+
|
|
881
|
+
Do not ship in the public package:
|
|
882
|
+
|
|
883
|
+
- Eval corpora, benchmark repos, calibration reports, or training datasets.
|
|
884
|
+
- ML ranking models, model weights, prompts used for proprietary ranking, or service-connection enrichment logic that should remain product IP.
|
|
885
|
+
- Hosted backend credentials, API keys, customer data, generated secrets, or local `.env` files.
|
|
886
|
+
|
|
887
|
+
Premium intelligence should run behind authenticated Rhei APIs with project/user/org authorization and license checks. Offline enterprise intelligence should be distributed as a binary-only commercial package when needed, but that is only a friction boundary; any code or binary running on a customer machine must still be treated as reverse-engineerable.
|
|
888
|
+
|
|
889
|
+
The bundled package builder runs `tooling/audit-public-package.ts` before packing. That audit fails if the staged tarball contains denied paths such as evals, fixtures, corpora, model weights, source maps, or missing `npx` bin aliases.
|
|
890
|
+
|
|
891
|
+
The workspace `packages/mcp-server/package.json` is marked `private` to prevent accidental direct publication of the source-build package. Publish only the audited tarball produced under `dist/rhei-mcp-beta/artifacts/`.
|
|
892
|
+
|
|
893
|
+
## Private Local Beta Package
|
|
894
|
+
|
|
895
|
+
For a friend who should test local repo search without receiving the monorepo, ship the compiled beta tarball. From `rhei/`:
|
|
896
|
+
|
|
897
|
+
```bash
|
|
898
|
+
bun run mcp:rhei:pack-beta
|
|
899
|
+
```
|
|
900
|
+
|
|
901
|
+
The script writes a private package under:
|
|
902
|
+
|
|
903
|
+
```text
|
|
904
|
+
dist/rhei-mcp-beta/artifacts/rhei-mcp-server-<version>.tgz
|
|
905
|
+
```
|
|
906
|
+
|
|
907
|
+
The package contains a bundled JS MCP server plus bundled JS slices of the Rhei core modules required by the MCP runtime. It does not contain the whole monorepo, but it is still an inspectable local developer tool. Treat the tarball as private beta software, not a source-secrecy boundary.
|
|
908
|
+
|
|
909
|
+
Friend install smoke:
|
|
910
|
+
|
|
911
|
+
```bash
|
|
912
|
+
mkdir -p /tmp/rhei-mcp-smoke
|
|
913
|
+
cd /tmp/rhei-mcp-smoke
|
|
914
|
+
npm init -y
|
|
915
|
+
npm install /path/to/rhei-mcp-server-1.0.0-beta.0.tgz
|
|
916
|
+
./node_modules/.bin/rhei install --target auto --yes
|
|
917
|
+
./node_modules/.bin/rhei uninstall --target auto --yes
|
|
918
|
+
./node_modules/.bin/rhei-mcp
|
|
919
|
+
```
|
|
920
|
+
|
|
921
|
+
One-shot tarball smoke:
|
|
922
|
+
|
|
923
|
+
```bash
|
|
924
|
+
npx -y --package /path/to/rhei-mcp-server-1.0.0-beta.0.tgz rhei install --target auto --yes
|
|
925
|
+
bunx --package /path/to/rhei-mcp-server-1.0.0-beta.0.tgz rhei install --target auto --yes
|
|
926
|
+
pnpm dlx --silent --package /path/to/rhei-mcp-server-1.0.0-beta.0.tgz rhei install --target auto --yes
|
|
927
|
+
```
|
|
928
|
+
|
|
929
|
+
Public publish command, once the package boundary is approved:
|
|
930
|
+
|
|
931
|
+
```bash
|
|
932
|
+
npm publish dist/rhei-mcp-beta/artifacts/rhei-mcp-server-<version>.tgz --access public
|
|
933
|
+
```
|
|
934
|
+
|
|
935
|
+
Codex config for the tarball install:
|
|
936
|
+
|
|
937
|
+
```toml
|
|
938
|
+
[mcp_servers.Rhei]
|
|
939
|
+
command = "npx"
|
|
940
|
+
args = ["-y", "--package", "/path/to/rhei-mcp-server-1.0.0-beta.0.tgz", "rhei", "mcp"]
|
|
941
|
+
startup_timeout_sec = 60.0
|
|
942
|
+
tool_timeout_sec = 300.0
|
|
943
|
+
```
|
|
944
|
+
|
|
945
|
+
pnpm-backed MCP config for the tarball install:
|
|
946
|
+
|
|
947
|
+
```toml
|
|
948
|
+
[mcp_servers.Rhei]
|
|
949
|
+
command = "pnpm"
|
|
950
|
+
args = ["dlx", "--silent", "--package", "/path/to/rhei-mcp-server-1.0.0-beta.0.tgz", "rhei", "mcp"]
|
|
951
|
+
startup_timeout_sec = 60.0
|
|
952
|
+
tool_timeout_sec = 300.0
|
|
953
|
+
```
|
|
954
|
+
|
|
955
|
+
OpenCode config after local install:
|
|
956
|
+
|
|
957
|
+
```json
|
|
958
|
+
{
|
|
959
|
+
"mcp": {
|
|
960
|
+
"rhei": {
|
|
961
|
+
"type": "local",
|
|
962
|
+
"command": ["./node_modules/.bin/rhei-mcp"],
|
|
963
|
+
"enabled": true
|
|
964
|
+
}
|
|
965
|
+
}
|
|
966
|
+
}
|
|
967
|
+
```
|
|
968
|
+
|
|
969
|
+
First local-index call from their agent:
|
|
970
|
+
|
|
971
|
+
```json
|
|
972
|
+
{
|
|
973
|
+
"repoPath": "/Users/friend/project",
|
|
974
|
+
"goal": "Map auth/session code and related tests",
|
|
975
|
+
"workflowPresetId": "deep_plan",
|
|
976
|
+
"useLocalIndex": true,
|
|
977
|
+
"writeLocalIndex": true
|
|
978
|
+
}
|
|
979
|
+
```
|
|
980
|
+
|
|
981
|
+
This writes `.rhei/code-context/local-index.json` inside their repo. Recommend adding `.rhei/` to their `.gitignore`.
|
|
982
|
+
|
|
983
|
+
## Codex CLI
|
|
984
|
+
|
|
985
|
+
The installer can write the Codex MCP entry automatically:
|
|
986
|
+
|
|
987
|
+
```bash
|
|
988
|
+
rhei install --target codex
|
|
989
|
+
```
|
|
990
|
+
|
|
991
|
+
To configure Codex manually, add an MCP server entry like this to `~/.codex/config.toml` when you want Codex CLI to use local Rhei:
|
|
992
|
+
|
|
993
|
+
```toml
|
|
994
|
+
[mcp_servers.Rhei]
|
|
995
|
+
command = "bun"
|
|
996
|
+
args = ["run", "--silent", "--cwd", "/Users/mibook/saga/rhei", "mcp:rhei"]
|
|
997
|
+
startup_timeout_sec = 20.0
|
|
998
|
+
```
|
|
999
|
+
|
|
1000
|
+
After restarting Codex CLI, call `status` to verify config, repo access, advertised tools, local mode, and no-live invariants. Full-profile dogfooding sessions may also use the legacy `rhei_code_context_doctor` helper.
|
|
1001
|
+
|
|
1002
|
+
If a Codex session was already running before an MCP tool/schema change, restart that Codex session so the client reloads the Rhei MCP tool list. A fresh `bun run --silent mcp:rhei` process will expose the current source immediately, but already-bound clients may keep the old tool schema until restart.
|
|
1003
|
+
|
|
1004
|
+
By default, the local server uses `RHEI_MCP_LOCAL_TOOL_PROFILE=public` and advertises the 20-tool generic agent-facing profile. Set `RHEI_MCP_LOCAL_TOOL_PROFILE=full` only for Rhei dogfooding or compatibility debugging, including legacy edit helpers. For measured single-flow sessions, `RHEI_MCP_LOCAL_TOOL_ALLOWLIST` overrides the profile; for example, `RHEI_MCP_LOCAL_TOOL_ALLOWLIST=context_builder,read_file` exposes only the context-builder/read path. `RHEI_MCP_LOCAL_TOOL_ALLOWLIST=*` or `all` exposes every registered tool, but does not make source apply official; the apply leg still requires `RHEI_CODE_SESSION_ENABLE_APPLY_EDITS=1` plus its local-beta/test receipts and root gates.
|
|
1005
|
+
|
|
1006
|
+
Codex workflow:
|
|
1007
|
+
|
|
1008
|
+
1. First call:
|
|
1009
|
+
|
|
1010
|
+
```json
|
|
1011
|
+
{
|
|
1012
|
+
"repoPath": "/Users/mibook/saga/rhei",
|
|
1013
|
+
"goal": "Plan the next safe implementation slice.",
|
|
1014
|
+
"workflowPresetId": "deep_plan"
|
|
1015
|
+
}
|
|
1016
|
+
```
|
|
1017
|
+
|
|
1018
|
+
2. Read `agentSurface.prompt` first.
|
|
1019
|
+
3. Treat `workBrief.contextPlan.exactRefs` as bounded context. Broaden only with an explicit reason.
|
|
1020
|
+
|
|
1021
|
+
Use `rhei_code_context_build_work_brief` only when local/web Rhei has already exported a snapshot, or with no args for the deterministic fixture smoke test.
|
|
1022
|
+
|
|
1023
|
+
## Implementation Notes
|
|
1024
|
+
|
|
1025
|
+
Local mode intentionally exposes the public read-only/report-only profile by default:
|
|
1026
|
+
|
|
1027
|
+
- `readOnlyHint: true`, `destructiveHint: false`, `idempotentHint: true`, and `openWorldHint: false` are set on local tools.
|
|
1028
|
+
- `rhei_code_edits` uses write-capable MCP annotations because its default transaction can include apply when explicitly enabled for tmp/root-allowlisted benchmark fixtures; preview-only and afteredit-only behavior remain read-only.
|
|
1029
|
+
- Each tool returns both text content and `structuredContent` so clients can display readable JSON while also consuming typed payloads.
|
|
1030
|
+
- Input validation is done with Zod through the high-level SDK server. The legacy low-level server remains only for credentialed remote compatibility.
|
|
1031
|
+
- All runtime logs use stderr. Never write diagnostic logs to stdout in stdio MCP servers.
|
|
1032
|
+
|
|
1033
|
+
## Remote Compatibility
|
|
1034
|
+
|
|
1035
|
+
Legacy remote Saga tools remain available only when API credentials are present:
|
|
1036
|
+
|
|
1037
|
+
```bash
|
|
1038
|
+
RHEI_CONVEX_URL=https://convex.rhei.team RHEI_API_KEY=... bun run --silent mcp:rhei
|
|
1039
|
+
```
|
|
1040
|
+
|
|
1041
|
+
Legacy env aliases such as `SUPABASE_URL`, `SAGA_API_KEY`, and `SAGA_PROJECT_ID` still work for compatibility, but new local agent integrations should use the Rhei Code Context tools above.
|
|
1042
|
+
|
|
1043
|
+
## Development Checks
|
|
1044
|
+
|
|
1045
|
+
```bash
|
|
1046
|
+
bun run --filter @rhei/mcp-server typecheck
|
|
1047
|
+
bun --env-file=.env vitest run convex-tests/codeLayer/localCodeContextForGoal.test.ts convex-tests/codeLayer/codeMarketLocalContextForGoal.test.ts convex-tests/codeLayer/codeContextAgentSurface.test.ts
|
|
1048
|
+
```
|