mirror of
https://github.com/instructkr/claw-code.git
synced 2026-04-06 08:04:50 +08:00
Compare commits
24 Commits
sigrid/rea
...
fix/p0-9-t
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
30883bddbd | ||
|
|
b9c5cc118e | ||
|
|
38fa2778af | ||
|
|
c4d4daa41d | ||
|
|
3df5dece39 | ||
|
|
cd1ee43f33 | ||
|
|
1fb3759e7c | ||
|
|
6b73f7f410 | ||
|
|
f30251a9e1 | ||
|
|
b0b655d417 | ||
|
|
8e72aaee2e | ||
|
|
1ceb077e40 | ||
|
|
58903cef75 | ||
|
|
cad1ac32a0 | ||
|
|
1f52ce25fb | ||
|
|
9350e70bc5 | ||
|
|
25a19792aa | ||
|
|
89a869e261 | ||
|
|
460284e7df | ||
|
|
feddbdd598 | ||
|
|
c99ee2f65d | ||
|
|
78fd0216f4 | ||
|
|
aca03fc3f9 | ||
|
|
9a7aab5259 |
114
PHILOSOPHY.md
Normal file
114
PHILOSOPHY.md
Normal file
@@ -0,0 +1,114 @@
|
||||
# Claw Code Philosophy
|
||||
|
||||
## Stop Staring at the Files
|
||||
|
||||
If you only look at the generated files in this repository, you are looking at the wrong layer.
|
||||
|
||||
The Python rewrite was a byproduct. The Rust rewrite was also a byproduct. The real thing worth studying is the **system that produced them**: a clawhip-based coordination loop where humans give direction and autonomous claws execute the work.
|
||||
|
||||
Claw Code is not just a codebase. It is a public demonstration of what happens when:
|
||||
|
||||
- a human provides clear direction,
|
||||
- multiple coding agents coordinate in parallel,
|
||||
- notification routing is pushed out of the agent context window,
|
||||
- planning, execution, review, and retry loops are automated,
|
||||
- and the human does **not** sit in a terminal micromanaging every step.
|
||||
|
||||
## The Human Interface Is Discord
|
||||
|
||||
The important interface here is not tmux, Vim, SSH, or a terminal multiplexer.
|
||||
|
||||
The real human interface is a Discord channel.
|
||||
|
||||
A person can type a sentence from a phone, walk away, sleep, or do something else. The claws read the directive, break it into tasks, assign roles, write code, run tests, argue over failures, recover, and push when the work passes.
|
||||
|
||||
That is the philosophy: **humans set direction; claws perform the labor.**
|
||||
|
||||
## The Three-Part System
|
||||
|
||||
### 1. OmX (`oh-my-codex`)
|
||||
[oh-my-codex](https://github.com/Yeachan-Heo/oh-my-codex) provides the workflow layer.
|
||||
|
||||
It turns short directives into structured execution:
|
||||
- planning keywords
|
||||
- execution modes
|
||||
- persistent verification loops
|
||||
- parallel multi-agent workflows
|
||||
|
||||
This is the layer that converts a sentence into a repeatable work protocol.
|
||||
|
||||
### 2. clawhip
|
||||
[clawhip](https://github.com/Yeachan-Heo/clawhip) is the event and notification router.
|
||||
|
||||
It watches:
|
||||
- git commits
|
||||
- tmux sessions
|
||||
- GitHub issues and PRs
|
||||
- agent lifecycle events
|
||||
- channel delivery
|
||||
|
||||
Its job is to keep monitoring and delivery **outside** the coding agent's context window so the agents can stay focused on implementation instead of status formatting and notification routing.
|
||||
|
||||
### 3. OmO (`oh-my-openagent`)
|
||||
[oh-my-openagent](https://github.com/code-yeongyu/oh-my-openagent) handles multi-agent coordination.
|
||||
|
||||
This is where planning, handoffs, disagreement resolution, and verification loops happen across agents.
|
||||
|
||||
When Architect, Executor, and Reviewer disagree, OmO provides the structure for that loop to converge instead of collapse.
|
||||
|
||||
## The Real Bottleneck Changed
|
||||
|
||||
The bottleneck is no longer typing speed.
|
||||
|
||||
When agent systems can rebuild a codebase in hours, the scarce resource becomes:
|
||||
- architectural clarity
|
||||
- task decomposition
|
||||
- judgment
|
||||
- taste
|
||||
- conviction about what is worth building
|
||||
- knowing which parts can be parallelized and which parts must stay constrained
|
||||
|
||||
A fast agent team does not remove the need for thinking. It makes clear thinking even more valuable.
|
||||
|
||||
## What Claw Code Demonstrates
|
||||
|
||||
Claw Code demonstrates that a repository can be:
|
||||
|
||||
- **autonomously built in public**
|
||||
- coordinated by claws/lobsters rather than human pair-programming alone
|
||||
- operated through a chat interface
|
||||
- continuously improved by structured planning/execution/review loops
|
||||
- maintained as a showcase of the coordination layer, not just the output files
|
||||
|
||||
The code is evidence.
|
||||
The coordination system is the product lesson.
|
||||
|
||||
## What Still Matters
|
||||
|
||||
As coding intelligence gets cheaper and more available, the durable differentiators are not raw coding output.
|
||||
|
||||
What still matters:
|
||||
- product taste
|
||||
- direction
|
||||
- system design
|
||||
- human trust
|
||||
- operational stability
|
||||
- judgment about what to build next
|
||||
|
||||
In that world, the job of the human is not to out-type the machine.
|
||||
The job of the human is to decide what deserves to exist.
|
||||
|
||||
## Short Version
|
||||
|
||||
**Claw Code is a demo of autonomous software development.**
|
||||
|
||||
Humans provide direction.
|
||||
Claws coordinate, build, test, recover, and push.
|
||||
The repository is the artifact.
|
||||
The philosophy is the system behind it.
|
||||
|
||||
## Related explanation
|
||||
|
||||
For the longer public explanation behind this philosophy, see:
|
||||
|
||||
- https://x.com/realsigridjin/status/2039472968624185713
|
||||
54
README.md
54
README.md
@@ -5,11 +5,11 @@
|
||||
</p>
|
||||
|
||||
<p align="center">
|
||||
<a href="https://star-history.com/#instructkr/claw-code&Date">
|
||||
<a href="https://star-history.com/#ultraworkers/claw-code&Date">
|
||||
<picture>
|
||||
<source media="(prefers-color-scheme: dark)" srcset="https://api.star-history.com/svg?repos=instructkr/claw-code&type=Date&theme=dark" />
|
||||
<source media="(prefers-color-scheme: light)" srcset="https://api.star-history.com/svg?repos=instructkr/claw-code&type=Date" />
|
||||
<img alt="Star History Chart" src="https://api.star-history.com/svg?repos=instructkr/claw-code&type=Date" width="600" />
|
||||
<source media="(prefers-color-scheme: dark)" srcset="https://api.star-history.com/svg?repos=ultraworkers/claw-code&type=Date&theme=dark" />
|
||||
<source media="(prefers-color-scheme: light)" srcset="https://api.star-history.com/svg?repos=ultraworkers/claw-code&type=Date" />
|
||||
<img alt="Star History Chart" src="https://api.star-history.com/svg?repos=ultraworkers/claw-code&type=Date" width="600" />
|
||||
</picture>
|
||||
</a>
|
||||
</p>
|
||||
@@ -19,48 +19,42 @@
|
||||
</p>
|
||||
|
||||
<p align="center">
|
||||
<strong>Better Harness Tools, not merely storing the archive of leaked Claude Code</strong>
|
||||
<strong>Autonomously maintained by lobsters/claws — not by human hands</strong>
|
||||
</p>
|
||||
|
||||
<p align="center">
|
||||
<a href="https://github.com/sponsors/instructkr"><img src="https://img.shields.io/badge/Sponsor-%E2%9D%A4-pink?logo=github&style=for-the-badge" alt="Sponsor on GitHub" /></a>
|
||||
<a href="https://github.com/Yeachan-Heo/clawhip">clawhip</a> ·
|
||||
<a href="https://github.com/code-yeongyu/oh-my-openagent">oh-my-openagent</a> ·
|
||||
<a href="https://github.com/Yeachan-Heo/oh-my-claudecode">oh-my-claudecode</a> ·
|
||||
<a href="https://github.com/Yeachan-Heo/oh-my-codex">oh-my-codex</a> ·
|
||||
<a href="https://discord.gg/6ztZB9jvWq">UltraWorkers Discord</a>
|
||||
</p>
|
||||
|
||||
> [!IMPORTANT]
|
||||
> The active Rust workspace now lives in [`rust/`](./rust). Start with [`USAGE.md`](./USAGE.md) for build, auth, CLI, session, and parity-harness workflows, then use [`rust/README.md`](./rust/README.md) for crate-level details.
|
||||
|
||||
> If you find this work useful, consider [sponsoring @instructkr on GitHub](https://github.com/sponsors/instructkr) to support continued open-source harness engineering research.
|
||||
> Want the bigger idea behind this repo? Read [`PHILOSOPHY.md`](./PHILOSOPHY.md) and Sigrid Jin's public explanation: https://x.com/realsigridjin/status/2039472968624185713
|
||||
|
||||
> Shout-out to the UltraWorkers ecosystem powering this repo: [clawhip](https://github.com/Yeachan-Heo/clawhip), [oh-my-openagent](https://github.com/code-yeongyu/oh-my-openagent), [oh-my-claudecode](https://github.com/Yeachan-Heo/oh-my-claudecode), [oh-my-codex](https://github.com/Yeachan-Heo/oh-my-codex), and the [UltraWorkers Discord](https://discord.gg/6ztZB9jvWq).
|
||||
|
||||
---
|
||||
|
||||
## Backstory
|
||||
|
||||
At 4 AM on March 31, 2026, I woke up to my phone blowing up with notifications. The Claude Code source had been exposed, and the entire dev community was in a frenzy. My girlfriend in Korea was genuinely worried I might face legal action from Anthropic just for having the code on my machine — so I did what any engineer would do under pressure: I sat down, ported the core features to Python from scratch, and pushed it before the sun came up.
|
||||
This repo is maintained by **lobsters/claws**, not by a conventional human-only dev team.
|
||||
|
||||
The whole thing was orchestrated end-to-end using [oh-my-codex (OmX)](https://github.com/Yeachan-Heo/oh-my-codex) by [@bellman_ych](https://x.com/bellman_ych) — a workflow layer built on top of OpenAI's Codex ([@OpenAIDevs](https://x.com/OpenAIDevs)). I used `$team` mode for parallel code review and `$ralph` mode for persistent execution loops with architect-level verification. The entire porting session — from reading the original harness structure to producing a working Python tree with tests — was driven through OmX orchestration.
|
||||
The people behind the system are [Bellman / Yeachan Heo](https://github.com/Yeachan-Heo) and friends like [Yeongyu](https://github.com/code-yeongyu), but the repo itself is being pushed forward by autonomous claw workflows: parallel coding sessions, event-driven orchestration, recovery loops, and machine-readable lane state.
|
||||
|
||||
The result is a clean-room Python rewrite that captures the architectural patterns of Claude Code's agent harness without copying any proprietary source. I'm now actively collaborating with [@bellman_ych](https://x.com/bellman_ych) — the creator of OmX himself — to push this further. The basic Python foundation is already in place and functional, but we're just getting started. **Stay tuned — a much more capable version is on the way.**
|
||||
In practice, that means this project is not just *about* coding agents — it is being **actively built by them**. Features, tests, telemetry, docs, and workflow hardening are landed through claw-driven loops using [clawhip](https://github.com/Yeachan-Heo/clawhip), [oh-my-openagent](https://github.com/code-yeongyu/oh-my-openagent), [oh-my-claudecode](https://github.com/Yeachan-Heo/oh-my-claudecode), and [oh-my-codex](https://github.com/Yeachan-Heo/oh-my-codex).
|
||||
|
||||
https://github.com/instructkr/claw-code
|
||||
This repository exists to prove that an open coding harness can be built **autonomously, in public, and at high velocity** — with humans setting direction and claws doing the grinding.
|
||||
|
||||
See the public build story here:
|
||||
|
||||
https://x.com/realsigridjin/status/2039472968624185713
|
||||
|
||||

|
||||
|
||||
## The Creators Featured in Wall Street Journal For Avid Claude Code Fans
|
||||
|
||||
I've been deeply interested in **harness engineering** — studying how agent systems wire tools, orchestrate tasks, and manage runtime context. This isn't a sudden thing. The Wall Street Journal featured my work earlier this month, documenting how I've been one of the most active power users exploring these systems:
|
||||
|
||||
> AI startup worker Sigrid Jin, who attended the Seoul dinner, single-handedly used 25 billion of Claude Code tokens last year. At the time, usage limits were looser, allowing early enthusiasts to reach tens of billions of tokens at a very low cost.
|
||||
>
|
||||
> Despite his countless hours with Claude Code, Jin isn't faithful to any one AI lab. The tools available have different strengths and weaknesses, he said. Codex is better at reasoning, while Claude Code generates cleaner, more shareable code.
|
||||
>
|
||||
> Jin flew to San Francisco in February for Claude Code's first birthday party, where attendees waited in line to compare notes with Cherny. The crowd included a practicing cardiologist from Belgium who had built an app to help patients navigate care, and a California lawyer who made a tool for automating building permit approvals using Claude Code.
|
||||
>
|
||||
> "It was basically like a sharing party," Jin said. "There were lawyers, there were doctors, there were dentists. They did not have software engineering backgrounds."
|
||||
>
|
||||
> — *The Wall Street Journal*, March 21, 2026, [*"The Trillion Dollar Race to Automate Our Entire Lives"*](https://lnkd.in/gs9td3qd)
|
||||
|
||||

|
||||
|
||||
---
|
||||
|
||||
## Porting Status
|
||||
@@ -174,12 +168,12 @@ The restructuring and documentation work on this repository was AI-assisted and
|
||||
## Community
|
||||
|
||||
<p align="center">
|
||||
<a href="https://instruct.kr/"><img src="assets/instructkr.png" alt="instructkr" width="400" /></a>
|
||||
<a href="https://discord.gg/6ztZB9jvWq"><img src="https://img.shields.io/badge/UltraWorkers-Discord-5865F2?logo=discord&style=for-the-badge" alt="UltraWorkers Discord" /></a>
|
||||
</p>
|
||||
|
||||
Join the [**instructkr Discord**](https://instruct.kr/) — the best Korean language model community. Come chat about LLMs, harness engineering, agent workflows, and everything in between.
|
||||
Join the [**UltraWorkers Discord**](https://discord.gg/6ztZB9jvWq) — the community around clawhip, oh-my-openagent, oh-my-claudecode, oh-my-codex, and claw-code. Come chat about LLMs, harness engineering, agent workflows, and autonomous software development.
|
||||
|
||||
[](https://instruct.kr/)
|
||||
[](https://discord.gg/6ztZB9jvWq)
|
||||
|
||||
## Star History
|
||||
|
||||
|
||||
18
ROADMAP.md
18
ROADMAP.md
@@ -272,6 +272,18 @@ Priority order: P0 = blocks CI/green state, P1 = blocks integration wiring, P2 =
|
||||
|
||||
**P0 — Fix first (CI reliability)**
|
||||
1. Isolate `render_diff_report` tests into tmpdir — flaky under `cargo test --workspace`; reads real working-tree state; breaks CI during active worktree ops
|
||||
2. Expand GitHub CI from single-crate coverage to workspace-grade verification — current `rust-ci.yml` runs `cargo fmt` and `cargo test -p rusty-claude-cli`, but misses broader `cargo test --workspace` coverage that already passes locally
|
||||
3. Add release-grade binary workflow — repo has a Rust CLI and release intent, but no GitHub Actions path that builds tagged artifacts / checks release packaging before a publish step
|
||||
4. Add container-first test/run docs — runtime detects Docker/Podman/container state, but docs do not show a canonical container workflow for `cargo test --workspace`, binary execution, or bind-mounted repo usage
|
||||
5. Surface `doctor` / preflight diagnostics in onboarding docs and help — the CLI already has setup-diagnosis commands and branch preflight machinery, but they are not prominent enough in README/USAGE, so new users still ask manual setup questions instead of running a built-in health check first
|
||||
6. Add branding/source-of-truth residue checks for docs — after repo migration, old org names can survive in badges, star-history URLs, and copied snippets; docs need a consistency pass or CI lint to catch stale branding automatically
|
||||
7. Reconcile README product narrative with current repo reality — top-level docs now say the active workspace is Rust, but later sections still describe the repo as Python-first; users should not have to infer which implementation is canonical
|
||||
8. Eliminate warning spam from first-run help/build path — `cargo run -p rusty-claude-cli -- --help` currently prints a wall of compile warnings before the actual help text, which pollutes the first-touch UX and hides the product surface behind unrelated noise
|
||||
9. Promote `doctor` from slash-only to top-level CLI entrypoint — users naturally try `claw doctor`, but today it errors and tells them to enter a REPL or resume path first; healthcheck flows should be callable directly from the shell
|
||||
10. Make machine-readable status commands actually machine-readable — `status` and `sandbox` accept the global `--output-format json` flag path, but currently still render prose tables, which breaks shell automation and agent-friendly health polling
|
||||
11. Unify legacy config/skill namespaces in user-facing output — `skills` currently surfaces mixed project roots like `.codex` and `.claude`, which leaks historical layers into the current product and makes it unclear which config namespace is canonical
|
||||
12. Honor JSON output on inventory commands like `skills` and `mcp` — these are exactly the commands agents and shell scripts want to inspect programmatically, but `--output-format json` still yields prose, forcing text scraping where structured inventory should exist
|
||||
13. Audit `--output-format` contract across the whole CLI surface — current behavior is inconsistent by subcommand, so agents cannot trust the global flag without command-by-command probing; the format contract itself needs to become deterministic
|
||||
|
||||
**P1 — Next (integration wiring, unblocks verification)**
|
||||
2. Add cross-module integration tests — **done**: 12 integration tests covering worker→recovery→policy, stale_branch→policy, green_contract→policy, reconciliation flows
|
||||
@@ -291,8 +303,14 @@ Priority order: P0 = blocks CI/green state, P1 = blocks integration wiring, P2 =
|
||||
14. **Config merge validation gap** — **done**: `config.rs` hook validation before deep-merge (+56 lines), malformed entries fail with source-path context instead of merged parse errors
|
||||
15. **MCP manager discovery flaky test** — `manager_discovery_report_keeps_healthy_servers_when_one_server_fails` has intermittent timing issues in CI; temporarily ignored, needs root cause fix
|
||||
|
||||
16. **Commit provenance / worktree-aware push events** — clawhip build stream shows duplicate-looking commit messages and worktree-originated pushes without clear supersession indicators; add worktree/branch metadata to push events and de-dup superseded commits in build stream display
|
||||
17. **Orphaned module integration audit** — `session_control` is `pub mod` exported from `runtime` but has zero consumers across the entire workspace (no import, no call site outside its own file). `trust_resolver` types are re-exported from `lib.rs` but never instantiated outside unit tests. These modules implement core clawability contracts (session management, trust resolution) that are structurally dead — built but not wired into the CLI or tools crate. **Action:** audit all `pub mod` / `pub use` exports from `runtime` for actual call sites; either wire orphaned modules into the real execution path or demote to `pub(crate)` / `cfg(test)` to prevent false clawability surface.
|
||||
18. **Context-window preflight gap** — claw-code auto-compacts only after cumulative input crosses a static `100_000`-token threshold, while provider requests derive `max_tokens` from a naive model-name heuristic (`opus` => 32k, else 64k) and do not appear to preflight `estimated_prompt_tokens + requested_output_tokens` against the selected model’s actual context window. Result: giant sessions can be sent upstream and fail hard with provider-side `input_exceeds_context_by_*` errors instead of local preflight compaction/rejection. **Action:** add a model-context registry + request-size preflight before provider call; if projected request exceeds context, emit a structured `context_window_blocked` event and auto-compact or force `/compact` before retry.
|
||||
19. **Subcommand help falls through into runtime/API path** — direct dogfood shows `./target/debug/claw doctor --help` and `./target/debug/claw status --help` do not render local subcommand help. Instead they enter the request path, show `🦀 Thinking...`, then fail with `api returned 500 ... auth_unavailable: no auth available`. Help/usage surfaces must be pure local parsing and never require auth or provider reachability. **Action:** fix argv dispatch so `<subcommand> --help` is intercepted before runtime startup/API client initialization; add regression tests for `doctor --help`, `status --help`, and similar local-info commands.
|
||||
|
||||
**P3 — Swarm efficiency**
|
||||
13. Swarm branch-lock protocol — detect same-module/same-branch collision before parallel workers drift into duplicate implementation
|
||||
14. Commit provenance / worktree-aware push events — emit branch, worktree, superseded-by, and canonical commit lineage so parallel sessions stop producing duplicate-looking push summaries
|
||||
|
||||
## Suggested Session Split
|
||||
|
||||
|
||||
@@ -7,8 +7,10 @@ use crate::types::{MessageRequest, MessageResponse};
|
||||
pub mod anthropic;
|
||||
pub mod openai_compat;
|
||||
|
||||
#[allow(dead_code)]
|
||||
pub type ProviderFuture<'a, T> = Pin<Box<dyn Future<Output = Result<T, ApiError>> + Send + 'a>>;
|
||||
|
||||
#[allow(dead_code)]
|
||||
pub trait Provider {
|
||||
type Stream;
|
||||
|
||||
|
||||
@@ -28,6 +28,7 @@ fn is_binary_file(path: &Path) -> io::Result<bool> {
|
||||
/// Validate that a resolved path stays within the given workspace root.
|
||||
/// Returns the canonical path on success, or an error if the path escapes
|
||||
/// the workspace boundary (e.g. via `../` traversal or symlink).
|
||||
#[allow(dead_code)]
|
||||
fn validate_workspace_boundary(resolved: &Path, workspace_root: &Path) -> io::Result<()> {
|
||||
if !resolved.starts_with(workspace_root) {
|
||||
return Err(io::Error::new(
|
||||
@@ -557,6 +558,7 @@ fn normalize_path_allow_missing(path: &str) -> io::Result<PathBuf> {
|
||||
}
|
||||
|
||||
/// Read a file with workspace boundary enforcement.
|
||||
#[allow(dead_code)]
|
||||
pub fn read_file_in_workspace(
|
||||
path: &str,
|
||||
offset: Option<usize>,
|
||||
@@ -572,6 +574,7 @@ pub fn read_file_in_workspace(
|
||||
}
|
||||
|
||||
/// Write a file with workspace boundary enforcement.
|
||||
#[allow(dead_code)]
|
||||
pub fn write_file_in_workspace(
|
||||
path: &str,
|
||||
content: &str,
|
||||
@@ -586,6 +589,7 @@ pub fn write_file_in_workspace(
|
||||
}
|
||||
|
||||
/// Edit a file with workspace boundary enforcement.
|
||||
#[allow(dead_code)]
|
||||
pub fn edit_file_in_workspace(
|
||||
path: &str,
|
||||
old_string: &str,
|
||||
@@ -602,6 +606,7 @@ pub fn edit_file_in_workspace(
|
||||
}
|
||||
|
||||
/// Check whether a path is a symlink that resolves outside the workspace.
|
||||
#[allow(dead_code)]
|
||||
pub fn is_symlink_escape(path: &Path, workspace_root: &Path) -> io::Result<bool> {
|
||||
let metadata = fs::symlink_metadata(path)?;
|
||||
if !metadata.is_symlink() {
|
||||
|
||||
@@ -4,10 +4,8 @@ use std::fs;
|
||||
use std::path::{Path, PathBuf};
|
||||
use std::time::UNIX_EPOCH;
|
||||
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
use crate::session::{Session, SessionError};
|
||||
use crate::worker_boot::{Worker, WorkerReadySnapshot, WorkerRegistry, WorkerStatus};
|
||||
|
||||
pub const PRIMARY_SESSION_EXTENSION: &str = "jsonl";
|
||||
pub const LEGACY_SESSION_EXTENSION: &str = "json";
|
||||
|
||||
@@ -24,9 +24,10 @@ use std::thread::{self, JoinHandle};
|
||||
use std::time::{Duration, Instant, UNIX_EPOCH};
|
||||
|
||||
use api::{
|
||||
resolve_startup_auth_source, AnthropicClient, AuthSource, ContentBlockDelta, InputContentBlock,
|
||||
InputMessage, MessageRequest, MessageResponse, OutputContentBlock, PromptCache,
|
||||
StreamEvent as ApiStreamEvent, ToolChoice, ToolDefinition, ToolResultContentBlock,
|
||||
oauth_token_is_expired, resolve_startup_auth_source, AnthropicClient, AuthSource,
|
||||
ContentBlockDelta, InputContentBlock, InputMessage, MessageRequest, MessageResponse,
|
||||
OutputContentBlock, PromptCache, StreamEvent as ApiStreamEvent, ToolChoice, ToolDefinition,
|
||||
ToolResultContentBlock,
|
||||
};
|
||||
|
||||
use commands::{
|
||||
@@ -39,14 +40,14 @@ use init::initialize_repo;
|
||||
use plugins::{PluginHooks, PluginManager, PluginManagerConfig, PluginRegistry};
|
||||
use render::{MarkdownStreamState, Spinner, TerminalRenderer};
|
||||
use runtime::{
|
||||
clear_oauth_credentials, format_usd, generate_pkce_pair, generate_state, load_system_prompt,
|
||||
parse_oauth_callback_request_target, pricing_for_model, resolve_sandbox_status,
|
||||
save_oauth_credentials, ApiClient, ApiRequest, AssistantEvent, CompactionConfig, ConfigLoader,
|
||||
ConfigSource, ContentBlock, ConversationMessage, ConversationRuntime, McpServerManager,
|
||||
McpTool, MessageRole, ModelPricing, OAuthAuthorizationRequest, OAuthConfig,
|
||||
OAuthTokenExchangeRequest, PermissionMode, PermissionPolicy, ProjectContext, PromptCacheEvent,
|
||||
ResolvedPermissionMode, RuntimeError, Session, TokenUsage, ToolError, ToolExecutor,
|
||||
UsageTracker,
|
||||
clear_oauth_credentials, format_usd, generate_pkce_pair, generate_state,
|
||||
load_oauth_credentials, load_system_prompt, parse_oauth_callback_request_target,
|
||||
pricing_for_model, resolve_sandbox_status, save_oauth_credentials, ApiClient, ApiRequest,
|
||||
AssistantEvent, CompactionConfig, ConfigLoader, ConfigSource, ContentBlock,
|
||||
ConversationMessage, ConversationRuntime, McpServerManager, McpTool, MessageRole, ModelPricing,
|
||||
OAuthAuthorizationRequest, OAuthConfig, OAuthTokenExchangeRequest, PermissionMode,
|
||||
PermissionPolicy, ProjectContext, PromptCacheEvent, ResolvedPermissionMode, RuntimeError,
|
||||
Session, TokenUsage, ToolError, ToolExecutor, UsageTracker,
|
||||
};
|
||||
use serde::Deserialize;
|
||||
use serde_json::json;
|
||||
@@ -133,12 +134,14 @@ fn run() -> Result<(), Box<dyn std::error::Error>> {
|
||||
.run_turn_with_output(&prompt, output_format)?,
|
||||
CliAction::Login => run_login()?,
|
||||
CliAction::Logout => run_logout()?,
|
||||
CliAction::Doctor => run_doctor()?,
|
||||
CliAction::Init => run_init()?,
|
||||
CliAction::Repl {
|
||||
model,
|
||||
allowed_tools,
|
||||
permission_mode,
|
||||
} => run_repl(model, allowed_tools, permission_mode)?,
|
||||
CliAction::HelpTopic(topic) => print_help_topic(topic),
|
||||
CliAction::Help => print_help(),
|
||||
}
|
||||
Ok(())
|
||||
@@ -180,16 +183,25 @@ enum CliAction {
|
||||
},
|
||||
Login,
|
||||
Logout,
|
||||
Doctor,
|
||||
Init,
|
||||
Repl {
|
||||
model: String,
|
||||
allowed_tools: Option<AllowedToolSet>,
|
||||
permission_mode: PermissionMode,
|
||||
},
|
||||
HelpTopic(LocalHelpTopic),
|
||||
// prompt-mode formatting is only supported for non-interactive runs
|
||||
Help,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
|
||||
enum LocalHelpTopic {
|
||||
Status,
|
||||
Sandbox,
|
||||
Doctor,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
|
||||
enum CliOutputFormat {
|
||||
Text,
|
||||
@@ -341,8 +353,10 @@ fn parse_args(args: &[String]) -> Result<CliAction, String> {
|
||||
if rest.first().map(String::as_str) == Some("--resume") {
|
||||
return parse_resume_args(&rest[1..]);
|
||||
}
|
||||
if let Some(action) = parse_single_word_command_alias(&rest, &model, permission_mode_override)
|
||||
{
|
||||
if let Some(action) = parse_local_help_action(&rest) {
|
||||
return action;
|
||||
}
|
||||
if let Some(action) = parse_single_word_command_alias(&rest, &model, permission_mode_override) {
|
||||
return action;
|
||||
}
|
||||
|
||||
@@ -388,6 +402,24 @@ fn parse_args(args: &[String]) -> Result<CliAction, String> {
|
||||
}
|
||||
}
|
||||
|
||||
fn parse_local_help_action(rest: &[String]) -> Option<Result<CliAction, String>> {
|
||||
if rest.len() != 2 || !is_help_flag(&rest[1]) {
|
||||
return None;
|
||||
}
|
||||
|
||||
let topic = match rest[0].as_str() {
|
||||
"status" => LocalHelpTopic::Status,
|
||||
"sandbox" => LocalHelpTopic::Sandbox,
|
||||
"doctor" => LocalHelpTopic::Doctor,
|
||||
_ => return None,
|
||||
};
|
||||
Some(Ok(CliAction::HelpTopic(topic)))
|
||||
}
|
||||
|
||||
fn is_help_flag(value: &str) -> bool {
|
||||
matches!(value, "--help" | "-h")
|
||||
}
|
||||
|
||||
fn parse_single_word_command_alias(
|
||||
rest: &[String],
|
||||
model: &str,
|
||||
@@ -405,6 +437,7 @@ fn parse_single_word_command_alias(
|
||||
permission_mode: permission_mode_override.unwrap_or_else(default_permission_mode),
|
||||
})),
|
||||
"sandbox" => Some(Ok(CliAction::Sandbox)),
|
||||
"doctor" => Some(Ok(CliAction::Doctor)),
|
||||
other => bare_slash_command_guidance(other).map(Err),
|
||||
}
|
||||
}
|
||||
@@ -741,6 +774,396 @@ fn parse_resume_args(args: &[String]) -> Result<CliAction, String> {
|
||||
})
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
|
||||
enum DiagnosticLevel {
|
||||
Ok,
|
||||
Warn,
|
||||
Fail,
|
||||
}
|
||||
|
||||
impl DiagnosticLevel {
|
||||
fn label(self) -> &'static str {
|
||||
match self {
|
||||
Self::Ok => "ok",
|
||||
Self::Warn => "warn",
|
||||
Self::Fail => "fail",
|
||||
}
|
||||
}
|
||||
|
||||
fn is_failure(self) -> bool {
|
||||
matches!(self, Self::Fail)
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, PartialEq, Eq)]
|
||||
struct DiagnosticCheck {
|
||||
name: &'static str,
|
||||
level: DiagnosticLevel,
|
||||
summary: String,
|
||||
details: Vec<String>,
|
||||
}
|
||||
|
||||
impl DiagnosticCheck {
|
||||
fn new(name: &'static str, level: DiagnosticLevel, summary: impl Into<String>) -> Self {
|
||||
Self {
|
||||
name,
|
||||
level,
|
||||
summary: summary.into(),
|
||||
details: Vec::new(),
|
||||
}
|
||||
}
|
||||
|
||||
fn with_details(mut self, details: Vec<String>) -> Self {
|
||||
self.details = details;
|
||||
self
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, PartialEq, Eq)]
|
||||
struct DoctorReport {
|
||||
checks: Vec<DiagnosticCheck>,
|
||||
}
|
||||
|
||||
impl DoctorReport {
|
||||
fn has_failures(&self) -> bool {
|
||||
self.checks.iter().any(|check| check.level.is_failure())
|
||||
}
|
||||
|
||||
fn render(&self) -> String {
|
||||
let ok_count = self
|
||||
.checks
|
||||
.iter()
|
||||
.filter(|check| check.level == DiagnosticLevel::Ok)
|
||||
.count();
|
||||
let warn_count = self
|
||||
.checks
|
||||
.iter()
|
||||
.filter(|check| check.level == DiagnosticLevel::Warn)
|
||||
.count();
|
||||
let fail_count = self
|
||||
.checks
|
||||
.iter()
|
||||
.filter(|check| check.level == DiagnosticLevel::Fail)
|
||||
.count();
|
||||
let mut lines = vec![
|
||||
"Doctor".to_string(),
|
||||
format!(
|
||||
"Summary\n OK {ok_count}\n Warnings {warn_count}\n Failures {fail_count}"
|
||||
),
|
||||
];
|
||||
lines.extend(self.checks.iter().map(render_diagnostic_check));
|
||||
lines.join("\n\n")
|
||||
}
|
||||
}
|
||||
|
||||
fn render_diagnostic_check(check: &DiagnosticCheck) -> String {
|
||||
let mut lines = vec![format!(
|
||||
"{}\n Status {}\n Summary {}",
|
||||
check.name,
|
||||
check.level.label(),
|
||||
check.summary
|
||||
)];
|
||||
if !check.details.is_empty() {
|
||||
lines.push(" Details".to_string());
|
||||
lines.extend(check.details.iter().map(|detail| format!(" - {detail}")));
|
||||
}
|
||||
lines.join("\n")
|
||||
}
|
||||
|
||||
fn render_doctor_report() -> Result<DoctorReport, Box<dyn std::error::Error>> {
|
||||
let cwd = env::current_dir()?;
|
||||
let config_loader = ConfigLoader::default_for(&cwd);
|
||||
let config = config_loader.load();
|
||||
let discovered_config = config_loader.discover();
|
||||
let project_context = ProjectContext::discover_with_git(&cwd, DEFAULT_DATE)?;
|
||||
let (project_root, git_branch) =
|
||||
parse_git_status_metadata(project_context.git_status.as_deref());
|
||||
let git_summary = parse_git_workspace_summary(project_context.git_status.as_deref());
|
||||
let empty_config = runtime::RuntimeConfig::empty();
|
||||
let sandbox_config = config.as_ref().ok().unwrap_or(&empty_config);
|
||||
let context = StatusContext {
|
||||
cwd: cwd.clone(),
|
||||
session_path: None,
|
||||
loaded_config_files: config
|
||||
.as_ref()
|
||||
.ok()
|
||||
.map_or(0, |runtime_config| runtime_config.loaded_entries().len()),
|
||||
discovered_config_files: discovered_config.len(),
|
||||
memory_file_count: project_context.instruction_files.len(),
|
||||
project_root,
|
||||
git_branch,
|
||||
git_summary,
|
||||
sandbox_status: resolve_sandbox_status(sandbox_config.sandbox(), &cwd),
|
||||
};
|
||||
Ok(DoctorReport {
|
||||
checks: vec![
|
||||
check_auth_health(),
|
||||
check_config_health(&config_loader, config.as_ref()),
|
||||
check_workspace_health(&context),
|
||||
check_sandbox_health(&context.sandbox_status),
|
||||
check_system_health(&cwd, config.as_ref().ok()),
|
||||
],
|
||||
})
|
||||
}
|
||||
|
||||
fn run_doctor() -> Result<(), Box<dyn std::error::Error>> {
|
||||
let report = render_doctor_report()?;
|
||||
println!("{}", report.render());
|
||||
if report.has_failures() {
|
||||
return Err("doctor found failing checks".into());
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn check_auth_health() -> DiagnosticCheck {
|
||||
let api_key_present = env::var("ANTHROPIC_API_KEY")
|
||||
.ok()
|
||||
.is_some_and(|value| !value.trim().is_empty());
|
||||
let auth_token_present = env::var("ANTHROPIC_AUTH_TOKEN")
|
||||
.ok()
|
||||
.is_some_and(|value| !value.trim().is_empty());
|
||||
|
||||
match load_oauth_credentials() {
|
||||
Ok(Some(token_set)) => {
|
||||
let expired = oauth_token_is_expired(&api::OAuthTokenSet {
|
||||
access_token: token_set.access_token.clone(),
|
||||
refresh_token: token_set.refresh_token.clone(),
|
||||
expires_at: token_set.expires_at,
|
||||
scopes: token_set.scopes.clone(),
|
||||
});
|
||||
let mut details = vec![
|
||||
format!(
|
||||
"Environment api_key={} auth_token={}",
|
||||
if api_key_present { "present" } else { "absent" },
|
||||
if auth_token_present {
|
||||
"present"
|
||||
} else {
|
||||
"absent"
|
||||
}
|
||||
),
|
||||
format!(
|
||||
"Saved OAuth expires_at={} refresh_token={} scopes={}",
|
||||
token_set
|
||||
.expires_at
|
||||
.map_or_else(|| "<none>".to_string(), |value| value.to_string()),
|
||||
if token_set.refresh_token.is_some() {
|
||||
"present"
|
||||
} else {
|
||||
"absent"
|
||||
},
|
||||
if token_set.scopes.is_empty() {
|
||||
"<none>".to_string()
|
||||
} else {
|
||||
token_set.scopes.join(",")
|
||||
}
|
||||
),
|
||||
];
|
||||
if expired {
|
||||
details.push(
|
||||
"Suggested action claw login to refresh local OAuth credentials".to_string(),
|
||||
);
|
||||
}
|
||||
DiagnosticCheck::new(
|
||||
"Auth",
|
||||
if expired {
|
||||
DiagnosticLevel::Warn
|
||||
} else {
|
||||
DiagnosticLevel::Ok
|
||||
},
|
||||
if expired {
|
||||
"saved OAuth credentials are present but expired"
|
||||
} else if api_key_present || auth_token_present {
|
||||
"environment and saved credentials are available"
|
||||
} else {
|
||||
"saved OAuth credentials are available"
|
||||
},
|
||||
)
|
||||
.with_details(details)
|
||||
}
|
||||
Ok(None) => DiagnosticCheck::new(
|
||||
"Auth",
|
||||
if api_key_present || auth_token_present {
|
||||
DiagnosticLevel::Ok
|
||||
} else {
|
||||
DiagnosticLevel::Warn
|
||||
},
|
||||
if api_key_present || auth_token_present {
|
||||
"environment credentials are configured"
|
||||
} else {
|
||||
"no API key or saved OAuth credentials were found"
|
||||
},
|
||||
)
|
||||
.with_details(vec![format!(
|
||||
"Environment api_key={} auth_token={}",
|
||||
if api_key_present { "present" } else { "absent" },
|
||||
if auth_token_present {
|
||||
"present"
|
||||
} else {
|
||||
"absent"
|
||||
}
|
||||
)]),
|
||||
Err(error) => DiagnosticCheck::new(
|
||||
"Auth",
|
||||
DiagnosticLevel::Fail,
|
||||
format!("failed to inspect saved credentials: {error}"),
|
||||
),
|
||||
}
|
||||
}
|
||||
|
||||
fn check_config_health(
|
||||
config_loader: &ConfigLoader,
|
||||
config: Result<&runtime::RuntimeConfig, &runtime::ConfigError>,
|
||||
) -> DiagnosticCheck {
|
||||
let discovered = config_loader.discover();
|
||||
let discovered_count = discovered.len();
|
||||
let discovered_paths = discovered
|
||||
.iter()
|
||||
.map(|entry| entry.path.display().to_string())
|
||||
.collect::<Vec<_>>();
|
||||
match config {
|
||||
Ok(runtime_config) => {
|
||||
let loaded_entries = runtime_config.loaded_entries();
|
||||
let mut details = vec![format!(
|
||||
"Config files loaded {}/{}",
|
||||
loaded_entries.len(),
|
||||
discovered_count
|
||||
)];
|
||||
if let Some(model) = runtime_config.model() {
|
||||
details.push(format!("Resolved model {model}"));
|
||||
}
|
||||
details.push(format!(
|
||||
"MCP servers {}",
|
||||
runtime_config.mcp().servers().len()
|
||||
));
|
||||
if discovered_paths.is_empty() {
|
||||
details.push("Discovered files <none>".to_string());
|
||||
} else {
|
||||
details.extend(
|
||||
discovered_paths
|
||||
.into_iter()
|
||||
.map(|path| format!("Discovered file {path}")),
|
||||
);
|
||||
}
|
||||
DiagnosticCheck::new(
|
||||
"Config",
|
||||
if discovered_count == 0 {
|
||||
DiagnosticLevel::Warn
|
||||
} else {
|
||||
DiagnosticLevel::Ok
|
||||
},
|
||||
if discovered_count == 0 {
|
||||
"no config files were found; defaults are active"
|
||||
} else {
|
||||
"runtime config loaded successfully"
|
||||
},
|
||||
)
|
||||
.with_details(details)
|
||||
}
|
||||
Err(error) => DiagnosticCheck::new(
|
||||
"Config",
|
||||
DiagnosticLevel::Fail,
|
||||
format!("runtime config failed to load: {error}"),
|
||||
)
|
||||
.with_details(if discovered_paths.is_empty() {
|
||||
vec!["Discovered files <none>".to_string()]
|
||||
} else {
|
||||
discovered_paths
|
||||
.into_iter()
|
||||
.map(|path| format!("Discovered file {path}"))
|
||||
.collect()
|
||||
}),
|
||||
}
|
||||
}
|
||||
|
||||
fn check_workspace_health(context: &StatusContext) -> DiagnosticCheck {
|
||||
let in_repo = context.project_root.is_some();
|
||||
DiagnosticCheck::new(
|
||||
"Workspace",
|
||||
if in_repo {
|
||||
DiagnosticLevel::Ok
|
||||
} else {
|
||||
DiagnosticLevel::Warn
|
||||
},
|
||||
if in_repo {
|
||||
format!(
|
||||
"project root detected on branch {}",
|
||||
context.git_branch.as_deref().unwrap_or("unknown")
|
||||
)
|
||||
} else {
|
||||
"current directory is not inside a git project".to_string()
|
||||
},
|
||||
)
|
||||
.with_details(vec![
|
||||
format!("Cwd {}", context.cwd.display()),
|
||||
format!(
|
||||
"Project root {}",
|
||||
context
|
||||
.project_root
|
||||
.as_ref()
|
||||
.map_or_else(|| "<none>".to_string(), |path| path.display().to_string())
|
||||
),
|
||||
format!(
|
||||
"Git branch {}",
|
||||
context.git_branch.as_deref().unwrap_or("unknown")
|
||||
),
|
||||
format!("Git state {}", context.git_summary.headline()),
|
||||
format!("Changed files {}", context.git_summary.changed_files),
|
||||
format!(
|
||||
"Memory files {} · config files loaded {}/{}",
|
||||
context.memory_file_count, context.loaded_config_files, context.discovered_config_files
|
||||
),
|
||||
])
|
||||
}
|
||||
|
||||
fn check_sandbox_health(status: &runtime::SandboxStatus) -> DiagnosticCheck {
|
||||
let degraded = status.enabled && !status.active;
|
||||
let mut details = vec![
|
||||
format!("Enabled {}", status.enabled),
|
||||
format!("Active {}", status.active),
|
||||
format!("Supported {}", status.supported),
|
||||
format!("Filesystem mode {}", status.filesystem_mode.as_str()),
|
||||
format!("Filesystem live {}", status.filesystem_active),
|
||||
];
|
||||
if let Some(reason) = &status.fallback_reason {
|
||||
details.push(format!("Fallback reason {reason}"));
|
||||
}
|
||||
DiagnosticCheck::new(
|
||||
"Sandbox",
|
||||
if degraded {
|
||||
DiagnosticLevel::Warn
|
||||
} else {
|
||||
DiagnosticLevel::Ok
|
||||
},
|
||||
if degraded {
|
||||
"sandbox was requested but is not currently active"
|
||||
} else if status.active {
|
||||
"sandbox protections are active"
|
||||
} else {
|
||||
"sandbox is not active for this session"
|
||||
},
|
||||
)
|
||||
.with_details(details)
|
||||
}
|
||||
|
||||
fn check_system_health(cwd: &Path, config: Option<&runtime::RuntimeConfig>) -> DiagnosticCheck {
|
||||
let mut details = vec![
|
||||
format!("OS {} {}", env::consts::OS, env::consts::ARCH),
|
||||
format!("Working dir {}", cwd.display()),
|
||||
format!("Version {}", VERSION),
|
||||
format!("Build target {}", BUILD_TARGET.unwrap_or("<unknown>")),
|
||||
format!("Git SHA {}", GIT_SHA.unwrap_or("<unknown>")),
|
||||
];
|
||||
if let Some(model) = config.and_then(runtime::RuntimeConfig::model) {
|
||||
details.push(format!("Default model {model}"));
|
||||
}
|
||||
DiagnosticCheck::new(
|
||||
"System",
|
||||
DiagnosticLevel::Ok,
|
||||
"captured local runtime metadata",
|
||||
)
|
||||
.with_details(details)
|
||||
}
|
||||
|
||||
fn resume_command_can_absorb_token(current_command: &str, token: &str) -> bool {
|
||||
matches!(
|
||||
SlashCommand::parse(current_command),
|
||||
@@ -1468,6 +1891,10 @@ fn run_resume_command(
|
||||
message: Some(handle_skills_slash_command(args.as_deref(), &cwd)?),
|
||||
})
|
||||
}
|
||||
SlashCommand::Doctor => Ok(ResumeCommandOutcome {
|
||||
session: session.clone(),
|
||||
message: Some(render_doctor_report()?.render()),
|
||||
}),
|
||||
SlashCommand::Unknown(name) => Err(format_unknown_slash_command(name).into()),
|
||||
SlashCommand::Bughunter { .. }
|
||||
| SlashCommand::Commit { .. }
|
||||
@@ -1481,7 +1908,6 @@ fn run_resume_command(
|
||||
| SlashCommand::Permissions { .. }
|
||||
| SlashCommand::Session { .. }
|
||||
| SlashCommand::Plugins { .. }
|
||||
| SlashCommand::Doctor
|
||||
| SlashCommand::Login
|
||||
| SlashCommand::Logout
|
||||
| SlashCommand::Vim
|
||||
@@ -1751,37 +2177,38 @@ impl RuntimeMcpState {
|
||||
.into_iter()
|
||||
.filter(|server_name| !failed_server_names.contains(server_name))
|
||||
.collect::<Vec<_>>();
|
||||
let failed_servers = discovery
|
||||
.failed_servers
|
||||
.iter()
|
||||
.map(|failure| runtime::McpFailedServer {
|
||||
server_name: failure.server_name.clone(),
|
||||
phase: runtime::McpLifecyclePhase::ToolDiscovery,
|
||||
error: runtime::McpErrorSurface::new(
|
||||
runtime::McpLifecyclePhase::ToolDiscovery,
|
||||
Some(failure.server_name.clone()),
|
||||
failure.error.clone(),
|
||||
std::collections::BTreeMap::new(),
|
||||
true,
|
||||
),
|
||||
})
|
||||
.chain(discovery.unsupported_servers.iter().map(|server| {
|
||||
runtime::McpFailedServer {
|
||||
server_name: server.server_name.clone(),
|
||||
phase: runtime::McpLifecyclePhase::ServerRegistration,
|
||||
let failed_servers =
|
||||
discovery
|
||||
.failed_servers
|
||||
.iter()
|
||||
.map(|failure| runtime::McpFailedServer {
|
||||
server_name: failure.server_name.clone(),
|
||||
phase: runtime::McpLifecyclePhase::ToolDiscovery,
|
||||
error: runtime::McpErrorSurface::new(
|
||||
runtime::McpLifecyclePhase::ServerRegistration,
|
||||
Some(server.server_name.clone()),
|
||||
server.reason.clone(),
|
||||
std::collections::BTreeMap::from([(
|
||||
"transport".to_string(),
|
||||
format!("{:?}", server.transport).to_ascii_lowercase(),
|
||||
)]),
|
||||
false,
|
||||
runtime::McpLifecyclePhase::ToolDiscovery,
|
||||
Some(failure.server_name.clone()),
|
||||
failure.error.clone(),
|
||||
std::collections::BTreeMap::new(),
|
||||
true,
|
||||
),
|
||||
}
|
||||
}))
|
||||
.collect::<Vec<_>>();
|
||||
})
|
||||
.chain(discovery.unsupported_servers.iter().map(|server| {
|
||||
runtime::McpFailedServer {
|
||||
server_name: server.server_name.clone(),
|
||||
phase: runtime::McpLifecyclePhase::ServerRegistration,
|
||||
error: runtime::McpErrorSurface::new(
|
||||
runtime::McpLifecyclePhase::ServerRegistration,
|
||||
Some(server.server_name.clone()),
|
||||
server.reason.clone(),
|
||||
std::collections::BTreeMap::from([(
|
||||
"transport".to_string(),
|
||||
format!("{:?}", server.transport).to_ascii_lowercase(),
|
||||
)]),
|
||||
false,
|
||||
),
|
||||
}
|
||||
}))
|
||||
.collect::<Vec<_>>();
|
||||
let degraded_report = (!failed_servers.is_empty()).then(|| {
|
||||
runtime::McpDegradedReport::new(
|
||||
working_servers,
|
||||
@@ -2387,8 +2814,11 @@ impl LiveCli {
|
||||
Self::print_skills(args.as_deref())?;
|
||||
false
|
||||
}
|
||||
SlashCommand::Doctor
|
||||
| SlashCommand::Login
|
||||
SlashCommand::Doctor => {
|
||||
println!("{}", render_doctor_report()?.render());
|
||||
false
|
||||
}
|
||||
SlashCommand::Login
|
||||
| SlashCommand::Logout
|
||||
| SlashCommand::Vim
|
||||
| SlashCommand::Upgrade
|
||||
@@ -3371,6 +3801,33 @@ fn print_sandbox_status_snapshot() -> Result<(), Box<dyn std::error::Error>> {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn render_help_topic(topic: LocalHelpTopic) -> String {
|
||||
match topic {
|
||||
LocalHelpTopic::Status => "Status
|
||||
Usage claw status
|
||||
Purpose show the local workspace snapshot without entering the REPL
|
||||
Output model, permissions, git state, config files, and sandbox status
|
||||
Related /status · claw --resume latest /status"
|
||||
.to_string(),
|
||||
LocalHelpTopic::Sandbox => "Sandbox
|
||||
Usage claw sandbox
|
||||
Purpose inspect the resolved sandbox and isolation state for the current directory
|
||||
Output namespace, network, filesystem, and fallback details
|
||||
Related /sandbox · claw status"
|
||||
.to_string(),
|
||||
LocalHelpTopic::Doctor => "Doctor
|
||||
Usage claw doctor
|
||||
Purpose diagnose local auth, config, workspace, sandbox, and build metadata
|
||||
Output local-only health report; no provider request or session resume required
|
||||
Related /doctor · claw --resume latest /doctor"
|
||||
.to_string(),
|
||||
}
|
||||
}
|
||||
|
||||
fn print_help_topic(topic: LocalHelpTopic) {
|
||||
println!("{}", render_help_topic(topic));
|
||||
}
|
||||
|
||||
fn render_config_report(section: Option<&str>) -> Result<String, Box<dyn std::error::Error>> {
|
||||
let cwd = env::current_dir()?;
|
||||
let loader = ConfigLoader::default_for(&cwd);
|
||||
@@ -5549,6 +6006,11 @@ fn print_help_to(out: &mut impl Write) -> io::Result<()> {
|
||||
)?;
|
||||
writeln!(out, " claw sandbox")?;
|
||||
writeln!(out, " Show the current sandbox isolation snapshot")?;
|
||||
writeln!(out, " claw doctor")?;
|
||||
writeln!(
|
||||
out,
|
||||
" Diagnose local auth, config, workspace, and sandbox health"
|
||||
)?;
|
||||
writeln!(out, " claw dump-manifests")?;
|
||||
writeln!(out, " claw bootstrap-plan")?;
|
||||
writeln!(out, " claw agents")?;
|
||||
@@ -5626,6 +6088,7 @@ fn print_help_to(out: &mut impl Write) -> io::Result<()> {
|
||||
writeln!(out, " claw agents")?;
|
||||
writeln!(out, " claw mcp show my-server")?;
|
||||
writeln!(out, " claw /skills")?;
|
||||
writeln!(out, " claw doctor")?;
|
||||
writeln!(out, " claw login")?;
|
||||
writeln!(out, " claw init")?;
|
||||
Ok(())
|
||||
@@ -5654,8 +6117,8 @@ mod tests {
|
||||
resume_supported_slash_commands, run_resume_command,
|
||||
slash_command_completion_candidates_with_sessions, status_context, validate_no_args,
|
||||
write_mcp_server_fixture, CliAction, CliOutputFormat, CliToolExecutor, GitWorkspaceSummary,
|
||||
InternalPromptProgressEvent, InternalPromptProgressState, LiveCli, SlashCommand,
|
||||
StatusUsage, DEFAULT_MODEL,
|
||||
InternalPromptProgressEvent, InternalPromptProgressState, LiveCli, LocalHelpTopic,
|
||||
SlashCommand, StatusUsage, DEFAULT_MODEL,
|
||||
};
|
||||
use api::{MessageResponse, OutputContentBlock, Usage};
|
||||
use plugins::{
|
||||
@@ -6021,6 +6484,10 @@ mod tests {
|
||||
parse_args(&["logout".to_string()]).expect("logout should parse"),
|
||||
CliAction::Logout
|
||||
);
|
||||
assert_eq!(
|
||||
parse_args(&["doctor".to_string()]).expect("doctor should parse"),
|
||||
CliAction::Doctor
|
||||
);
|
||||
assert_eq!(
|
||||
parse_args(&["init".to_string()]).expect("init should parse"),
|
||||
CliAction::Init
|
||||
@@ -6046,6 +6513,25 @@ mod tests {
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn local_command_help_flags_stay_on_the_local_parser_path() {
|
||||
assert_eq!(
|
||||
parse_args(&["status".to_string(), "--help".to_string()])
|
||||
.expect("status help should parse"),
|
||||
CliAction::HelpTopic(LocalHelpTopic::Status)
|
||||
);
|
||||
assert_eq!(
|
||||
parse_args(&["sandbox".to_string(), "-h".to_string()])
|
||||
.expect("sandbox help should parse"),
|
||||
CliAction::HelpTopic(LocalHelpTopic::Sandbox)
|
||||
);
|
||||
assert_eq!(
|
||||
parse_args(&["doctor".to_string(), "--help".to_string()])
|
||||
.expect("doctor help should parse"),
|
||||
CliAction::HelpTopic(LocalHelpTopic::Doctor)
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn parses_single_word_command_aliases_without_falling_back_to_prompt_mode() {
|
||||
let _guard = env_lock();
|
||||
@@ -7509,8 +7995,12 @@ UU conflicted.rs",
|
||||
let runtime_config = loader.load().expect("runtime config should load");
|
||||
let state = build_runtime_plugin_state_with_loader(&workspace, &loader, &runtime_config)
|
||||
.expect("runtime plugin state should load");
|
||||
let mut executor =
|
||||
CliToolExecutor::new(None, false, state.tool_registry.clone(), state.mcp_state.clone());
|
||||
let mut executor = CliToolExecutor::new(
|
||||
None,
|
||||
false,
|
||||
state.tool_registry.clone(),
|
||||
state.mcp_state.clone(),
|
||||
);
|
||||
|
||||
let search_output = executor
|
||||
.execute("ToolSearch", r#"{"query":"remote","max_results":5}"#)
|
||||
|
||||
@@ -160,6 +160,82 @@ fn config_command_loads_defaults_from_standard_config_locations() {
|
||||
fs::remove_dir_all(temp_dir).expect("cleanup temp dir");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn doctor_command_runs_as_a_local_shell_entrypoint() {
|
||||
// given
|
||||
let temp_dir = unique_temp_dir("doctor-entrypoint");
|
||||
let config_home = temp_dir.join("home").join(".claw");
|
||||
fs::create_dir_all(&config_home).expect("config home should exist");
|
||||
|
||||
// when
|
||||
let output = command_in(&temp_dir)
|
||||
.env("CLAW_CONFIG_HOME", &config_home)
|
||||
.env_remove("ANTHROPIC_API_KEY")
|
||||
.env_remove("ANTHROPIC_AUTH_TOKEN")
|
||||
.env("ANTHROPIC_BASE_URL", "http://127.0.0.1:9")
|
||||
.arg("doctor")
|
||||
.output()
|
||||
.expect("claw doctor should launch");
|
||||
|
||||
// then
|
||||
assert_success(&output);
|
||||
let stdout = String::from_utf8(output.stdout).expect("stdout should be utf8");
|
||||
assert!(stdout.contains("Doctor"));
|
||||
assert!(stdout.contains("Auth"));
|
||||
assert!(stdout.contains("Config"));
|
||||
assert!(stdout.contains("Workspace"));
|
||||
assert!(stdout.contains("Sandbox"));
|
||||
assert!(!stdout.contains("Thinking"));
|
||||
|
||||
fs::remove_dir_all(temp_dir).expect("cleanup temp dir");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn local_subcommand_help_does_not_fall_through_to_runtime_or_provider_calls() {
|
||||
// given
|
||||
let temp_dir = unique_temp_dir("subcommand-help");
|
||||
let config_home = temp_dir.join("home").join(".claw");
|
||||
fs::create_dir_all(&config_home).expect("config home should exist");
|
||||
|
||||
// when
|
||||
let doctor_help = command_in(&temp_dir)
|
||||
.env("CLAW_CONFIG_HOME", &config_home)
|
||||
.env_remove("ANTHROPIC_API_KEY")
|
||||
.env_remove("ANTHROPIC_AUTH_TOKEN")
|
||||
.env("ANTHROPIC_BASE_URL", "http://127.0.0.1:9")
|
||||
.args(["doctor", "--help"])
|
||||
.output()
|
||||
.expect("doctor help should launch");
|
||||
let status_help = command_in(&temp_dir)
|
||||
.env("CLAW_CONFIG_HOME", &config_home)
|
||||
.env_remove("ANTHROPIC_API_KEY")
|
||||
.env_remove("ANTHROPIC_AUTH_TOKEN")
|
||||
.env("ANTHROPIC_BASE_URL", "http://127.0.0.1:9")
|
||||
.args(["status", "--help"])
|
||||
.output()
|
||||
.expect("status help should launch");
|
||||
|
||||
// then
|
||||
assert_success(&doctor_help);
|
||||
let doctor_stdout = String::from_utf8(doctor_help.stdout).expect("stdout should be utf8");
|
||||
assert!(doctor_stdout.contains("Usage claw doctor"));
|
||||
assert!(doctor_stdout.contains("local-only health report"));
|
||||
assert!(!doctor_stdout.contains("Thinking"));
|
||||
|
||||
assert_success(&status_help);
|
||||
let status_stdout = String::from_utf8(status_help.stdout).expect("stdout should be utf8");
|
||||
assert!(status_stdout.contains("Usage claw status"));
|
||||
assert!(status_stdout.contains("local workspace snapshot"));
|
||||
assert!(!status_stdout.contains("Thinking"));
|
||||
|
||||
let doctor_stderr = String::from_utf8(doctor_help.stderr).expect("stderr should be utf8");
|
||||
let status_stderr = String::from_utf8(status_help.stderr).expect("stderr should be utf8");
|
||||
assert!(!doctor_stderr.contains("auth_unavailable"));
|
||||
assert!(!status_stderr.contains("auth_unavailable"));
|
||||
|
||||
fs::remove_dir_all(temp_dir).expect("cleanup temp dir");
|
||||
}
|
||||
|
||||
fn command_in(cwd: &Path) -> Command {
|
||||
let mut command = Command::new(env!("CARGO_BIN_EXE_claw"));
|
||||
command.current_dir(cwd);
|
||||
|
||||
@@ -19,6 +19,7 @@ use crate::AgentOutput;
|
||||
///
|
||||
/// Returns `Some(LaneContext)` with `completed = true` if all conditions met,
|
||||
/// `None` if lane should remain active.
|
||||
#[allow(dead_code)]
|
||||
pub(crate) fn detect_lane_completion(
|
||||
output: &AgentOutput,
|
||||
test_green: bool,
|
||||
@@ -65,6 +66,7 @@ pub(crate) fn detect_lane_completion(
|
||||
}
|
||||
|
||||
/// Evaluates policy actions for a completed lane.
|
||||
#[allow(dead_code)]
|
||||
pub(crate) fn evaluate_completed_lane(
|
||||
context: &LaneContext,
|
||||
) -> Vec<PolicyAction> {
|
||||
|
||||
Reference in New Issue
Block a user