Skip to main content

Developing cosh-ng

中文版

This guide gets a new contributor from checkout to a focused, validated change. Read the repository AGENTS.md, src/cosh-ng/AGENTS.md, and this page before editing code; those files contain constraints that are intentionally not duplicated here.

1. Prepare the workspace

cosh-ng is a Linux-first Rust workspace that also builds on macOS. The minimum Rust version is 1.74, and rust-toolchain.toml selects stable Rust with rustfmt and Clippy.

cd src/cosh-ng
rustup show
cargo build --workspace

Do not install packages, change services, or run mutating cosh-cli commands on the development host. Use unit tests, mocks, --dry-run, or an explicitly isolated environment.

2. Understand the runtime boundary

There are five crates but three user-facing processes:

AreaStart readingBoundary
Structured OS operationscrates/cosh-cli/src/main.rsClap to cosh-platform to JSON envelope
Agent runtimecrates/cosh-core/src/main.rsJSONL/registry input to provider, tools, and session state
Interactive terminalcrates/cosh-shell/src/main.rsterminal input, PTY events, cards, and a child cosh-core process
Shared platform codecrates/cosh-platform/src/lib.rsdistro, package, service, audit, checkpoint adapters
Wire and output typescrates/cosh-types/src/lib.rsside-effect-free contracts

cosh-shell does not link to the other workspace crates. It launches cosh-core and communicates over the versioned JSONL/control protocol. That process boundary is a compatibility contract, not an implementation detail.

See Architecture for ownership and data flow.

3. Find the owner before editing

For cosh-shell, new production behavior belongs under an existing owner directory; do not add implementation files directly under src/.

ChangePrimary ownerTypical test target
PTY, OSC, bash/zsh integrationshell_host/shell_host
Input routing and multiline entryraw_input/, input/, slash/raw_cli or logic
Agent lifecycle and event policyagent/logic
Core adapter/control messagesadapter/protocol
Approval and question cardsapproval/, question/, ui/raw_cli
Hookshooks/library tests or logic
Runtime orchestration/state mutationruntime/library tests, then relevant integration target
Agent tools and risk rulestools/library tests and adversarial regressions

Run the layout audit after moving or adding shell code:

crates/cosh-shell/scripts/check-layout.sh

4. Use the narrowest feedback loop

# Shared types/platform/CLI
cargo test --locked -p cosh-types
cargo test --locked -p cosh-platform
cargo test --locked -p cosh-cli --test cli_integration

# Core
cargo test --locked -p cosh-core --lib
cargo test --locked -p cosh-core --test jsonl_protocol

# Shell: fast logic before process-heavy tests
cargo test --locked -p cosh-shell --lib
cargo test --locked -p cosh-shell --test logic
cargo test --locked -p cosh-shell --test protocol

Choose raw_cli when the behavior spawns cosh-shell, renders cards, or crosses the provider handoff. Choose shell_host for PTY, OSC, termios, foreground programs, or native bash/zsh behavior.

5. Validate the final change

Match validation to the change:

  • Documentation-only changes: check links, Markdown formatting, commands, and bilingual parity. Rust tests and builds are unnecessary.
  • Ordinary code changes: run formatting and the tests closest to the changed crate or behavior. Add targeted Clippy or integration checks when they can catch a relevant failure.
  • Large or cross-cutting code changes: run full local gates, persistent ECS, or manual-grade validation only when the current task explicitly requests that depth. Otherwise CI owns broad regression coverage.

When public API or rustdoc changes, also run:

cargo doc --workspace --no-deps

See Testing for target selection and optional gate profiles.

6. Keep contracts explicit

  • Every cosh-cli result uses CoshResponse<T> and a stable exit status.
  • Never reorder ws-ckpt protocol enum variants without coordinating the daemon.
  • A cosh-core protocol change must update protocol types, both producer and consumer, fixtures, and protocol tests together.
  • Security allow rules must tokenize first, reject shell metacharacters, and fail closed. Add tab, newline, and unspaced-metacharacter regressions.
  • Tests must not depend on a real LLM provider or mutate host system state.
  • Do not weaken assertions, inventory floors, or registered layout debt to make a check pass.

Where to go next