Commit graph

3 commits

Author SHA1 Message Date
Kayshen-X
514bb67215 chore: vendor anthropic-agent-sdk out of crates/ 2026-05-16 13:14:20 +08:00
Kayshen-X
080c8be0eb 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
Kayshen-X
3a0f755c8e chore(vendor): add anthropic-agent-sdk + copilot-sdk-rust as IPC source-of-truth
User direction: instead of hand-rolling subprocess JSON bridges in
`chat_subprocess.rs`, pull the community SDKs into vendor/ + adapt
them. Both repos are MIT-licensed Rust SDKs purpose-built for their
respective CLIs and ship more capable wire-protocol parsers than the
generic line-based approach in this branch's HEAD.

`vendor/anthropic-agent-sdk/` (was bartolli/anthropic-agent-sdk @ main,
2026-05-14):
  - SubprocessTransport for `claude --print --verbose --output-format
    stream-json -- <prompt>`
  - Recognized message envelope (system / user / assistant / result
    shapes per Claude Code's documented headless protocol)
  - Binary-lookup fallback through ~/.npm-global/bin, /usr/local/bin,
    ~/.local/bin, ~/node_modules/.bin, ~/.yarn/bin (via `which` +
    manual probe)
  - Dangerous-env-var scrub (LD_PRELOAD / DYLD_INSERT_LIBRARIES /
    NODE_OPTIONS / ...) for spawn safety
  - CancellationToken-based abort wiring
  - Trimmed locally: removed examples/, demos/, tests/, docs/, .git/.
    Inner `[workspace]` block stripped so OP's root workspace owns the
    build. `typed-builder` pinned to `=0.21.0` because upstream's
    `0.23.2` uses stable `let`-chains (Rust 1.88+) and OP rust-toolchain
    is 1.85 to stay compatible with the skia-safe-op fork.

`vendor/copilot-sdk-rust/` (was copilot-community-sdk/copilot-sdk-rust
@ main, 2026-05-14):
  - LSP-style Content-Length-framed JSON-RPC over stdio for
    `gh copilot` (the new community CLI that succeeds the legacy
    `gh-copilot suggest` subcommand)
  - Client + Session abstraction with event subscription
    (`AssistantMessage` / `SessionIdle` / tool-use events)
  - Trimmed: examples/, tests/, .git/ removed. Cargo.toml unchanged
    (already 2021 edition + 1.85 rust-version + no problematic deps).

Workspace integration:
  - Both directories appear in OP root Cargo.toml's `exclude` list so
    `cargo build --workspace` doesn't try to compile them (each
    declares its own `edition` / `rust-version` distinct from OP).
  - openpencil-desktop will consume them via target-gated path deps
    in the next commit + replace the hand-rolled provider in
    `chat_subprocess.rs` with thin adapters that route per CliName:
      Claude Code → anthropic_agent_sdk::SubprocessTransport
      Copilot     → copilot_sdk::Client + Session
      Gemini      → keep the generic stdin/stdout bridge (no upstream
                    Rust SDK exists yet for the gemini CLI)
      Codex /
      OpenCode    → HttpServer bridge (separate, spawn `<bin> serve`
                    + connect to local 127.0.0.1:port)

Per the user clarification "opencode 和 codex 我们调用 http server, 通过
ipc 启动本地的 server 模式": Codex + OpenCode stay on the HttpServer
path even though they're also spawned subprocesses — the local
server is what we IPC with via HTTP, not their stdio.

Standalone build verified for both vendored crates: ✓ check passes
on rustc 1.85.1 (this host).
2026-05-14 16:36:27 +08:00