Overview: design rules, workspace, contracts #58

Open
opened 2026-09-30 09:07:42 +00:00 by hermes · 0 comments
Collaborator

Rust agent harness. pi core (minimal, 4 tools) + built-in pi-lens-style feedback (LSP, linters, tests) + native MCP. All work is tracked in milestones M0-M7.

Design rules

  1. Core stays pi-small: 4 tools (read write edit bash), tiny prompt, no plan mode or sub-agents in v1.
  2. Lens is a built-in crate, not a plugin. It uses the same event bus extensions use.
  3. MCP tools are lazy by default: model sees a one-line index and pulls schemas via mcp_describe. Servers can opt in to eager registration.
  4. Diagnostics injected once per turn end, only if fresh (file seq numbers).

Workspace

crates/
  hx-ai/    providers (anthropic, openai-compat, google), SSE streaming, tool calls, cost
  hx-core/  agent loop, Tool trait, event bus, JSONL session tree, context files, skills, compaction
  hx-tools/ read, write, edit, bash
  hx-lens/  lsp, dispatch, runners, tests, seq-log, triage
  hx-mcp/   client (stdio + streamable HTTP), lazy registry, config
  hx-tui/   ratatui + crossterm
  hx-cli/   clap; modes: interactive, print, json, rpc, mcp-serve

Key crates

tokio, reqwest, eventsource-stream, serde, schemars, rmcp, lsp-types, ignore, notify, similar, tree-sitter, ast-grep-core, ratatui, crossterm, clap, tracing, thiserror, anyhow.

Core contracts

trait Tool { fn spec(&self) -> ToolSpec; async fn call(&self, args: Value, cx: &mut ToolCtx) -> ToolResult; }
enum Event { SessionStart, TurnStart, ToolCall{..}, ToolResult{..}, TurnEnd, AgentEnd, Context }
trait Hook { async fn on(&self, ev: &Event, cx: &mut HookCtx) -> HookAction; } // Continue | Block | Inject(msg) | Mutate

Lens model

  • Change log: monotonic project_seq + per-file seq; every write/edit/format/autofix bumps it with a source tag.
  • Findings carry the file seq they were computed at; stale ones are dropped or age-labelled (freshness gate).
  • Read-guard blocks edit on files not read since last external change.
  • Output: one compact block at turn end, token-capped, grouped by file, errors first.
  • Test selection is heuristic (same crate/package + reverse deps), not coverage-based.

Deliberate simplifications

Subprocess JSON-RPC extensions only (no Lua/WASM), three providers, no sub-agents/plan mode, no Windows, no sandboxing in v1.

Risks

  • LSP servers vary a lot; M3 will take longer than it looks.
  • Turn-end injection can flood context: token cap + freshness gate must be tested early.
  • Lazy MCP saves tokens but adds a round trip per new tool: measure in M6.
Rust agent harness. pi core (minimal, 4 tools) + built-in pi-lens-style feedback (LSP, linters, tests) + native MCP. All work is tracked in milestones M0-M7. ## Design rules 1. Core stays pi-small: 4 tools (`read write edit bash`), tiny prompt, no plan mode or sub-agents in v1. 2. Lens is a built-in crate, not a plugin. It uses the same event bus extensions use. 3. MCP tools are lazy by default: model sees a one-line index and pulls schemas via `mcp_describe`. Servers can opt in to eager registration. 4. Diagnostics injected once per turn end, only if fresh (file seq numbers). ## Workspace ``` crates/ hx-ai/ providers (anthropic, openai-compat, google), SSE streaming, tool calls, cost hx-core/ agent loop, Tool trait, event bus, JSONL session tree, context files, skills, compaction hx-tools/ read, write, edit, bash hx-lens/ lsp, dispatch, runners, tests, seq-log, triage hx-mcp/ client (stdio + streamable HTTP), lazy registry, config hx-tui/ ratatui + crossterm hx-cli/ clap; modes: interactive, print, json, rpc, mcp-serve ``` ## Key crates tokio, reqwest, eventsource-stream, serde, schemars, rmcp, lsp-types, ignore, notify, similar, tree-sitter, ast-grep-core, ratatui, crossterm, clap, tracing, thiserror, anyhow. ## Core contracts ```rust trait Tool { fn spec(&self) -> ToolSpec; async fn call(&self, args: Value, cx: &mut ToolCtx) -> ToolResult; } enum Event { SessionStart, TurnStart, ToolCall{..}, ToolResult{..}, TurnEnd, AgentEnd, Context } trait Hook { async fn on(&self, ev: &Event, cx: &mut HookCtx) -> HookAction; } // Continue | Block | Inject(msg) | Mutate ``` ## Lens model - Change log: monotonic `project_seq` + per-file seq; every write/edit/format/autofix bumps it with a source tag. - Findings carry the file seq they were computed at; stale ones are dropped or age-labelled (freshness gate). - Read-guard blocks `edit` on files not read since last external change. - Output: one compact block at turn end, token-capped, grouped by file, errors first. - Test selection is heuristic (same crate/package + reverse deps), not coverage-based. ## Deliberate simplifications Subprocess JSON-RPC extensions only (no Lua/WASM), three providers, no sub-agents/plan mode, no Windows, no sandboxing in v1. ## Risks - LSP servers vary a lot; M3 will take longer than it looks. - Turn-end injection can flood context: token cap + freshness gate must be tested early. - Lazy MCP saves tokens but adds a round trip per new tool: measure in M6.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: johannes/hx#58