Skip to content

fix(div-anthropic): D3-1 彻底移除 @anthropic-ai/claude-agent-sdk - #68

Merged
dahai80 merged 2 commits into
mainfrom
fix/div-anthropic-d3-remove-claude-agent-sdk
Aug 19, 2026
Merged

dahai80 merged 2 commits into
mainfrom
fix/div-anthropic-d3-remove-claude-agent-sdk

Conversation

@dahai80

@dahai80 dahai80 commented Aug 19, 2026

Copy link
Copy Markdown
Owner

背景

D3 评估 issue #65 第一包: @anthropic-ai/claude-agent-sdk。原 issue 假设「降级 devDeps」, 审计后发现可彻底移除 (更彻底, 更干净)。

根因

src/cli/print.ts:132 是全仓唯一 import, 纯 import type { PermissionMode }, 编译期擦除, 0 运行时引用。

本地 src/types/permissions.ts:29 已定义等价 PermissionMode:

  • EXTERNAL_PERMISSION_MODES = 6 模式 (acceptEdits/auto/bypassPermissions/default/dontAsk/plan), 与 SDK 的 6 模式完全一致
  • 本地 PermissionMode = 6 模式 + "bubble" (超集)

print.ts:1083 的 newMode as PermissionMode (SDK) 是冗余 downcast:

  • listener newMode 入参已是本地 PermissionMode (sessionState.ts:27 导入本地)
  • 赋值目标 message.ts:113 permissionMode?: 字段也是本地 PermissionMode
  • if-guard (1071-1077) 已将 newMode 收窄到 6 个被保护字面量

→ cast 可删除, newMode 原样赋值。

改动

  • package.json: 移除 @anthropic-ai/claude-agent-sdk 依赖
  • src/cli/print.ts: 删除 line 132 SDK type import, line 1083 删除冗余 cast

验证

  • typecheck 0 错误
  • build 通过 (3715 模块, 与移除前一致 — type import 编译期擦除, 二进制无变化)
  • 单元测试 116/116, 集成测试 324/324, 0 fail
  • source/tests/scripts: 0 处 claude-agent-sdk 引用
  • 编译后二进制: 0 处 claude-agent-sdk 字符串
  • 跨包: sandbox-runtime/mcpb 均未声明 claude-agent-sdk 依赖, 无传递拉取

关联

Closes #65 (D3 三包评估全部完成: claude-agent-sdk 移除, sandbox-runtime/mcpb 保留 — 评估结论见 #65 评论)

dahai80 and others added 2 commits August 19, 2026 18:05
D3 评估 issue #65 第一包: claude-agent-sdk 经审计可彻底移除 (非仅降级 devDeps)。

根因: src/cli/print.ts:132 是全仓唯一 import, 纯 `import type { PermissionMode }`,
编译期擦除, 0 运行时引用。本地 src/types/permissions.ts 已定义等价 PermissionMode
(= InternalPermissionMode = ExternalPermissionMode | "auto" | "bubble"), 且
EXTERNAL_PERMISSION_MODES 6 个模式 (acceptEdits/auto/bypassPermissions/default/
dontAsk/plan) 与 SDK 的 6 个模式完全一致。

print.ts:1083 的 `newMode as PermissionMode` (SDK 类型) 是冗余 downcast:
- listener newMode 入参已是本地 PermissionMode (sessionState.ts:27 导入本地类型)
- 赋值目标 message.ts:113 permissionMode?: 字段也是本地 PermissionMode
- if-guard (1071-1077) 已将 newMode 收窄到 6 个被保护字面量
故 cast 可直接删除, newMode 原样赋值。

验证:
- typecheck 0 错误
- build 通过 (3715 模块, 与移除前一致 — type import 编译期已擦除, 二进制无变化)
- 单元测试 116/116, 集成测试 324/324, 0 fail
- source/tests/scripts: 0 处 claude-agent-sdk 引用
- 编译后二进制: 0 处 claude-agent-sdk 字符串

跨包检查: sandbox-runtime / mcpb 均未声明 claude-agent-sdk 为依赖, 无传递拉取。

Co-Authored-By: Claude Fable 5 <[email protected]>
CI `bun install --frozen-lockfile` 因 package.json 移除 claude-agent-sdk 后
lockfile 未同步而失败。重新生成 bun.lock:

- 移除 @anthropic-ai/claude-agent-sdk 及 8 个平台原生子包
  (darwin/linux/win × arm64/x64/musl)
- 附带消除 claude-agent-sdk 的传递依赖 @anthropic-ai/sdk (即此前已移除的 SDK)
  — claude-agent-sdk deps 含 `@anthropic-ai/sdk: ^0.93.0`, 之前仅顶层移除,
    通过 claude-agent-sdk 仍被间接拉取; 本次彻底切断该传递路径

Co-Authored-By: Claude Fable 5 <[email protected]>
@dahai80
dahai80 merged commit 23f64d9 into main Aug 19, 2026
1 check passed
@dahai80
dahai80 deleted the fix/div-anthropic-d3-remove-claude-agent-sdk branch August 19, 2026 10:09
dahai80 added a commit that referenced this pull request Aug 27, 2026
Closes #154. Completes the retrieve half deferred by #151 (which landed
turn-end commit only). fusion-cowork #68 and fusion-agent-studio #247
already have both commit+retrieve; this brings fusion-code to parity.

## What

At main-agent turn start (processUserInput), recall relevant cross-session
memory from fusion-memory (fm-server) and inject it as an attachment message
on the same path as UserPromptSubmit hook additionalContext. The agent now
starts each turn with relevant prior context, not stateless.

## How

- src/services/memory/retrieveContext.ts (new) — retrieveMemorySection():
  calls the existing retrieveContext RPC + formatContextToPrompt (both added
  by #151 but unwired), returns a <fusion_memory_context> section string or
  . Main-agent guard (!agentId), fail-empty (logForDebugging, never throws).
  Env override: FUSION_MEMORY_RETRIEVE_TOP_K / FUSION_MEMORY_RETRIEVE_BUDGET.
- src/utils/processUserInput/processUserInput.ts (edit) — after UserPromptSubmit
  hooks, on the happy path with real input and !context.agentId, fire-and-forget
  retrieveMemorySection and push the section as a hook_additional_context
  attachment message. Mirrors the existing hook additionalContext push. Skips
  silently if fm-server down or FUSION_MEMORY_API_KEY unset.

## Degradation

fm-server down / FUSION_MEMORY_API_KEY unset / no memory matched -> section
is empty, nothing injected, debug log only. Never blocks the main loop.
100% offline — HTTP only to 127.0.0.1.

## Tests

10 tests in retrieveContext.test.ts (subagent skip, empty input, success
format, RPC error, HTTP non-2xx, fetch throw, missing API key, no-match,
top_k env override, invalid env fallback). Full memory suite 25 pass,
bun run build green.
dahai80 added a commit that referenced this pull request Aug 30, 2026
…t 1.1.1 slice #68)

resume() useCallback 子块 (24-LOC) 外移到 resumeSessionHooksCheck.ts
runResumeSessionHooks(ctx): fire SessionEnd hooks for current session +
processSessionStartHooks (fork source "fork") → push hookMessages into
conversation. return-value-threading (#63 pattern): messages array passed
via ctx, helper pushes directly (not returned). byte-identical behavior.

REPL 5203→5195 (−8). Gates: typecheck 0 / 921 tests / biome clean / build:dev.

Co-Authored-By: Claude Fable 5 <[email protected]>
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.

div-anthropic D3: 评估 claude-agent-sdk / sandbox-runtime / mcpb 三个 Anthropic/MCP 依赖的解耦可行性

1 participant