openpencil/crates/copilot-sdk/AGENTS.md
Kayshen-X f3f57081da chore(crates): move vendored SDKs into workspace as forkable crates
Per user direction "可以不放在 vendor 里面,我们移动到自己的工程,
后面就和他们分叉" — promote the two community SDKs from vendor/ to
crates/ so they become first-class OP workspace members we own and
evolve, instead of read-only vendored snapshots.

Moves:
  vendor/anthropic-agent-sdk/  →  crates/anthropic-agent-sdk/
  vendor/copilot-sdk-rust/     →  crates/copilot-sdk/

Workspace integration:
  - Root `Cargo.toml` exclude list drops both vendor entries; the
    existing `members = ["crates/*"]` glob auto-includes them.
  - `crates/copilot-sdk/Cargo.toml`: stripped all `[[example]]`
    blocks (22 of them) — the examples/ dir was already removed
    during the import, and leaving the entries broke
    `cargo test --workspace --no-run`.
  - `crates/anthropic-agent-sdk/Cargo.toml`: already had its
    `[[example]]` blocks pruned in the previous commit.

Lockfile pins (workspace `Cargo.lock`):
  Pulling reqwest 0.12.28 (via anthropic-agent-sdk) into the
  unified workspace dep graph re-resolved several `icu_*` crates to
  the 2.2 line, which requires rustc 1.86. OP's toolchain is 1.85
  (locked to stay compatible with the skia-safe-op fork). Pinned:
    icu_collections      2.2.0 → 2.1.1
    icu_locale_core      2.2.0 → 2.1.1
    icu_normalizer       2.2.0 → 2.1.1
    icu_normalizer_data  2.2.0 → 2.1.1
    icu_properties       2.2.0 → 2.1.2
    icu_properties_data  2.2.0 → 2.1.2
    icu_provider         2.2.0 → 2.1.1
    idna_adapter         1.2.2 → 1.2.1
  All eight pins are the latest versions on each crate's 2.1.x /
  1.2.x line that compile on rustc 1.85.

Verification:
  - `cargo check -p anthropic-agent-sdk` ✓
  - `cargo check -p copilot-sdk` ✓
  - `cargo test --workspace --no-run` ✓
  - `cargo test -p openpencil-shell-core --lib` → 250 pass
  - `cargo test -p openpencil-desktop chat_` → 16 pass

Next: replace the hand-rolled subprocess parser in chat_subprocess.rs
with thin per-CLI adapters that route Claude Code through
`anthropic_agent_sdk::SubprocessTransport` and Copilot through
`copilot_sdk::Client + Session`. Gemini stays on the generic stdin
bridge until an upstream Rust SDK exists. Codex + OpenCode get an
HttpServerProvider that spawns `<bin> serve` then connects via a
local HTTP client.
2026-05-14 16:49:17 +08:00

1.9 KiB
Raw Blame History

Repository Guidelines

Project Structure

  • src/: library implementation (client, session, transport, jsonrpc, types).
  • examples/: runnable samples (e.g. cargo run --example basic_chat).
  • tests/: integration tests:
    • e2e_tests.rs (feature-gated; requires a real Copilot CLI)
    • snapshot_conformance.rs (feature-gated; optional upstream snapshot suite)
  • .github/workflows/ci.yml: CI for fmt/clippy/test/doc/package.

Build, Test, and Development Commands

  • cargo build: compile the crate.
  • cargo test: run unit + integration tests (feature-gated suites are skipped by default).
  • cargo fmt --all: format code (cargo fmt --all -- --check in CI).
  • cargo clippy --all-targets --all-features -- -D warnings: lint (treat warnings as errors).
  • cargo doc --no-deps: build docs locally.

Feature-gated tests:

  • cargo test --features e2e -- --test-threads=1: E2E tests against the installed/authenticated Copilot CLI.
  • cargo test --features snapshots --test snapshot_conformance: snapshot conformance (set COPILOT_SDK_RUST_SNAPSHOT_DIR or UPSTREAM_SNAPSHOTS if auto-detect fails).

Coding Style & Naming

  • Rust 1.85.0 is pinned in rust-toolchain.toml (Edition 2024).
  • Format with rustfmt; lint with clippy.
  • Keep unsafe out: the crate uses #![forbid(unsafe_code)].
  • Maintain attribution headers at the top of Rust files (tests/attribution_headers.rs enforces this).

Commit & Pull Request Guidelines

  • Commit convention is not established in this repo’s current history; use Conventional Commits (feat:, fix:, docs:, chore:) and keep commits focused.
  • PRs should include: what/why, how to test (commands), and docs/example updates for API or behavior changes.

Security & Configuration Tips

  • The SDK interacts with the Copilot CLI runtime; avoid logging secrets, prompts, or tokens.
  • Ensure copilot is on PATH, or set COPILOT_CLI_PATH to the CLI executable/script.