Skip to content

feat(cli): support piped prompts for exec - #5

Merged
echoVic merged 9 commits into
mainfrom
feat/pipe-eval-stdin
Jun 23, 2026
Merged

feat(cli): support piped prompts for exec#5
echoVic merged 9 commits into
mainfrom
feat/pipe-eval-stdin

Conversation

@echoVic

@echoVic echoVic commented Jun 23, 2026

Copy link
Copy Markdown
Owner

Summary

  • allow orca exec to read the prompt from piped stdin when no prompt argument is provided
  • support orca exec - for explicit stdin prompt mode
  • append piped stdin as a <stdin>...</stdin> context block when a prompt argument is also present
  • document stdin-based headless harness usage in README

Validation

  • cargo test --test exec_jsonl -- --nocapture
  • cargo check
  • rustfmt --edition 2024 --check src/cli.rs tests/exec_jsonl.rs

Evaluation

  • Ran a pipe-based agent capability harness against target/debug/orca: 12/12 passed
  • Covered stdin prompt modes, multi-turn fixture, read_file, edit/full-auto, approval denial, subagent, verifier, history resume, budget exhaustion, and server pipe protocol

Notes

  • Full cargo fmt --check still reports pre-existing formatting drift in untouched files.
  • Full cargo test --workspace still fails in unrelated workflow_cli_contract tests.

Summary by CodeRabbit

  • New Features

    • orca exec now supports reading prompts from stdin for headless execution; examples added to documentation
    • Added summary caching layer to improve response performance
    • TUI now displays real-time context token usage and remaining budget
  • Refactor

    • Internal conversation state management restructured to better handle volatile context and summaries
    • Enhanced history resume logic to preserve conversation state across sessions
  • Tests

    • Expanded test coverage for stdin prompt handling, summary rendering determinism, and history state restoration

echoVic added 9 commits June 23, 2026 14:04
1. 移除了自动为对话添加上下文预算提示的逻辑,改为本地实时统计展示
2. 新增ContextUpdated事件和AppState字段跟踪上下文使用情况
3. 在状态栏添加上下文剩余占比指示器,根据剩余比例显示不同颜色
4. 公开ContextConfig::effective_limit方法用于获取有效上下文限制
5. 移除过时的上下文预算提示相关工具函数和测试代码
新增两组测试确保DeepSeek前缀缓存所需的工具列表顺序和JSON序列化结果稳定:
1. 验证MCP工具注册表严格保留工具插入顺序
2. 验证内置+外部工具的输出顺序符合预期且跨构建一致
3. 锁定serde_json序列化始终按字典序排列对象键
重构了Conversation结构体,将计划、目标、技能上下文等临时元数据从消息列表转移到volatile字段中,移除了旧的固定 pinned 系统消息实现:
- 新增VolatileContext结构体管理临时上下文数据
- 替换replace_plan_state/goal_state/skill_context为volatile操作
- 添加strip_legacy_pinned_volatile清理历史遗留的pinned消息
- 修改TUI和运行时加载会话的逻辑,自动清理旧格式数据
- 更新上下文压缩逻辑,包含volatile上下文的token计算和状态继承
- 为DeepSeek API提供者添加volatile上下文叠加到最后一条消息的功能
- 重命名测试用例以匹配新的行为逻辑
1. 为Conversation结构体添加rolling_summary字段并初始化
2. 实现resume_conversation从会话历史加载最新滚动摘要
3. 优化摘要生成逻辑,支持基于已有摘要合并更新
4. 新增多项测试验证滚动摘要的处理流程
重构了对话摘要的存储和处理逻辑,将原有的单一流式滚动摘要替换为包含基线和增量更新的结构化摘要状态:
1. 新增SummaryState结构体管理对话摘要的基线和增量更新
2. 替换旧的append_summary接口为append_summary_state,持久化完整摘要状态
3. 实现摘要自动合并机制,当增量超过阈值时重建基线并清空增量
4. 完善会话恢复逻辑,优先加载持久化的结构化摘要状态
5. 清理旧格式的遗留摘要消息
6. 在API调用时正确注入结构化摘要消息到对话上下文
7. 修正上下文压缩时的token计算逻辑,正确统计摘要状态占用
新增了对话摘要缓存功能,实现基于内容寻址的本地缓存来避免重复调用摘要模型;同时添加了本地提取式压缩逻辑,对超长工具输出进行裁剪以减少token消耗,还补充了相关测试用例。
新增完整的摘要渲染指标统计与缓存隔离机制,修复大输出压缩失效问题:
1. 新增`RenderedSummaryDelta`结构体统一管理摘要渲染指标
2. 重构摘要缓存,增加purpose字段区分增量摘要和基线重建
3. 重写工具输出压缩逻辑,按大小分层处理避免主上下文压缩遮蔽规则
4. 新增示例程序验证压缩率达标情况
5. 新增调试遥测输出,方便性能监控
The Round 7 summary renderer compressed huge tool outputs ~95% relative to
the raw input, but the old main-context path had already micro-compacted to a
smaller size, so under the real API the renderer was more expensive
(huge prompt 5644 vs old micro-masked 2252). Head/tail line/char counts alone
do not bound rendered bytes (long lines blow past them).

Add a hard per-tool byte budget (medium 900B, huge 700B) applied after the
line/char extract via char-boundary-safe trim, tighten the tiers
(medium 8+6 lines / 384+384 chars, huge 6+4 lines / 320+320 chars), and keep
the size metadata (original_bytes / original_lines|chars / omitted) so the
summarizer still sees this is truncated evidence.

Encode the real-API target as a test: the huge renderer must be no larger
than the micro_compact_tool_output baseline. Add summary_render_realapi
example to verify against billed aux-model prompt_tokens.

Real-API acceptance (deepseek-v4-flash):
  summary_huge_current_original_renderer = 235  (<= old micro-masked 235; target <=2252)
  summary_mid_current_renderer           = 307  (target <3932)
  normal main cache hit                   = 99.2%
  summary cache second lookup            = skips API
@coderabbitai

coderabbitai Bot commented Jun 23, 2026

Copy link
Copy Markdown

Review Change Stack

Caution

Review failed

The pull request is closed.

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 261c3739-772d-49c4-b6f1-9cb696b80730

📥 Commits

Reviewing files that changed from the base of the PR and between e62e2d4 and 754f39a.

⛔ Files ignored due to path filters (1)
  • Cargo.lock is excluded by !**/*.lock
📒 Files selected for processing (19)
  • README.md
  • crates/orca-core/src/conversation.rs
  • crates/orca-mcp/src/client.rs
  • crates/orca-provider/Cargo.toml
  • crates/orca-provider/examples/summary_render_metrics.rs
  • crates/orca-provider/examples/summary_render_realapi.rs
  • crates/orca-provider/src/context.rs
  • crates/orca-provider/src/deepseek_http.rs
  • crates/orca-provider/src/lib.rs
  • crates/orca-provider/src/summary_cache.rs
  • crates/orca-provider/src/tool_schema.rs
  • crates/orca-runtime/src/controller.rs
  • crates/orca-runtime/src/history.rs
  • crates/orca-tui/src/bridge.rs
  • crates/orca-tui/src/types.rs
  • crates/orca-tui/src/ui.rs
  • src/cli.rs
  • tests/exec_jsonl.rs
  • tests/history_contract.rs

📝 Walkthrough

Walkthrough

This PR refactors Conversation to carry VolatileContext (plan/goal/skill) and SummaryState (baseline/deltas) as first-class fields instead of pinned system messages, rewrites the remote summary delta rendering pipeline with deterministic tool-output extraction and SHA-256 disk caching, injects volatile/summary into DeepSeek API messages, updates history persistence and session resume, adds a TUI context usage gauge, and adds stdin-based prompt resolution to orca exec.

Changes

Volatile/Summary State Refactor and Pipeline

Layer / File(s) Summary
VolatileContext, SummaryState, and Conversation struct
crates/orca-core/src/conversation.rs
Adds VolatileContext, SummaryState, and TokenCountable; expands Conversation struct; reworks plan/goal/skill replacement APIs to write volatile fields instead of pinned system messages; adds legacy stripping helpers and tests.
On-disk summary cache module
crates/orca-provider/Cargo.toml, crates/orca-provider/src/lib.rs, crates/orca-provider/src/summary_cache.rs
Introduces summary_cache module with SHA-256 content-addressed key generation (summary_key), lookup/store I/O APIs, cache directory resolution from ORCA_HOME or ~/.orca, and deterministic key/round-trip tests. Adds sha2, dirs, and tempfile dependencies.
Summary delta rendering pipeline
crates/orca-provider/src/context.rs
Rewrites compact_with_summary and summarize_collapsed_messages to micro-compact first, reconstruct original collapsed messages for summary rendering, produce RenderedSummaryDelta via tiered tool-output extraction, manage SummaryState baseline/deltas rebuild, cache requests, and extract assistant_content for storage. Updates token counting to include volatile and summary costs. Adds 600+ lines of compaction and rendering tests.
DeepSeek API message injection for volatile/summary
crates/orca-provider/src/deepseek_http.rs
Rewrites conversation_to_api_messages as an imperative loop that injects [Summary baseline]/[Summary update N] system messages and appends volatile overlay to the last outgoing message. Exposes ApiMessage and conversation_to_api_messages as pub(crate). Adds volatile overlay behavior tests.
History persistence and resume for SummaryState
crates/orca-runtime/src/history.rs
Adds summary_state field to ContextSummaryRecord; adds append_summary_state method; refactors resume_conversation to replay compactions and restore SummaryState from persisted records or rebuild from legacy entries. Adds resume and compaction-replay tests.
Runtime and TUI wiring to new APIs
crates/orca-runtime/src/controller.rs, crates/orca-tui/src/bridge.rs
Updates controller to set skill context via replace_skill_context, switch compaction writes to append_summary_state, remove per-turn budget hint, and fix UpdatePlan message handling. Updates bridge to strip legacy volatile/summary on resume, use append_summary_state in all compaction paths, emit ContextUpdated event, and remove budget hint application.
TUI context usage display
crates/orca-tui/src/types.rs, crates/orca-tui/src/ui.rs
Adds TuiEvent::ContextUpdated with used_tokens/limit_tokens; adds AppState fields and update handler; adds context_cell helper with success/warning/error color thresholds to render_status; tests all three color states.
Examples, determinism tests, and contract test updates
crates/orca-provider/examples/*, crates/orca-provider/src/tool_schema.rs, crates/orca-mcp/src/client.rs, tests/history_contract.rs
Adds summary_render_metrics deterministic harness and summary_render_realapi real-API benchmark; adds tool schema byte-stability and insertion-order tests; adds McpRegistry insertion-order test; flips history_contract skill assertions to absence.

stdin Prompt Resolution for orca exec

Layer / File(s) Summary
CLI stdin resolver, tests, and README docs
README.md, src/cli.rs, tests/exec_jsonl.rs
Adds resolve_exec_prompt_from_stdin to cli.rs supporting - sentinel, no-args stdin read, and piped stdin appended in <stdin>...</stdin> block; updates run_exec with error reporting; adds four integration tests covering all stdin modes; documents headless usage in README.

Sequence Diagram(s)

sequenceDiagram
  participant Controller/Bridge
  participant context.rs
  participant micro_compact
  participant render_summary_delta
  participant summary_cache
  participant DeepSeek API
  participant deepseek_http.rs

  rect rgba(100, 149, 237, 0.5)
    note over Controller/Bridge,deepseek_http.rs: Compaction path
    Controller/Bridge->>context.rs: compact_with_summary(conversation)
    context.rs->>micro_compact: micro_compact_stale_tool_outputs(conversation)
    micro_compact-->>context.rs: micro_compacted (volatile/summary preserved)
    context.rs->>context.rs: summarize_collapsed_messages(collapsed window)
    context.rs->>render_summary_delta: original collapsed messages
    render_summary_delta-->>context.rs: RenderedSummaryDelta
    context.rs->>summary_cache: lookup(scope, purpose, prev, delta_text)
    alt cache miss
      context.rs->>DeepSeek API: request_summary(rendered_delta, prev_summary)
      DeepSeek API-->>context.rs: assistant_content
      context.rs->>summary_cache: store(key, summary)
    end
    context.rs->>context.rs: rebuild SummaryState baseline/deltas
    context.rs-->>Controller/Bridge: updated Conversation (volatile + SummaryState)
    Controller/Bridge->>history.rs: append_summary_state(before, after, summary, &conversation.summary)
  end

  rect rgba(50, 205, 50, 0.5)
    note over deepseek_http.rs,DeepSeek API: Per-turn API call
    deepseek_http.rs->>deepseek_http.rs: conversation_to_api_messages(conversation)
    deepseek_http.rs->>deepseek_http.rs: inject_summary_messages (baseline + deltas) after system msg
    deepseek_http.rs->>deepseek_http.rs: append volatile.render() to last message
    deepseek_http.rs->>DeepSeek API: POST /chat (enriched messages)
  end
Loading

Estimated code review effort

🎯 5 (Critical) | ⏱️ ~120 minutes

Poem

🐇 Hops into the warren with a brand new scheme,
volatile fields and delta caches gleam.
Stdin pipes the prompt when args are bare,
a <stdin> block tucked in with care.
Summary tiers computed, SHA hashed tight,
the context gauge glows green — all feels right!

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feat/pipe-eval-stdin

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@echoVic
echoVic merged commit ad508fd into main Jun 23, 2026
1 check was pending
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant