Skip to content

feat: SDK control protocol for code.* and artifact_chat APIs - #8

Merged
dahai80 merged 6 commits into
mainfrom
feat/sdk-control-code-api
Jul 27, 2026
Merged

dahai80 merged 6 commits into
mainfrom
feat/sdk-control-code-api

Conversation

@dahai80

@dahai80 dahai80 commented Jul 27, 2026

Copy link
Copy Markdown
Owner

Summary

Implements SDK control protocol endpoints for issues #3, #4, #5.

Issue #5 — Command Execution API

  • code_exec: Execute shell commands with cwd, timeout, stdout/stderr capture
  • code_processes: List running child processes (stub — returns empty for now)
  • code_kill: Kill a process by PID with configurable signal

Issue #4 — File Edit API

  • code_file_read: Read file with offset/limit, encoding support
  • code_file_write: Write file with auto-mkdir option
  • code_diff: Generate unified diff between two text contents
  • code_apply_patch: Apply unified diff patch with .bak backup
  • code_search_files: Search by content (grep) or filename (find) — uses spawnSync with arg arrays (no shell injection)

Issue #3 — Artifact Chat API

  • artifact_chat: JSON-RPC call to artifact engine for AI-driven artifact generation/iteration

Changes

  1. src/entrypoints/sdk/controlSchemas.ts: Added 9 request schemas + 9 response schemas, all registered in SDKControlRequestInnerSchema union
  2. src/cli/print.ts: Added handler dispatch for all 9 subtypes in the control_request processing chain
  3. src/services/api/fusion-mlx-adapter.ts: Removed stale debug logs, fixed bare fetch() in retry path to use getOriginalFetch()

Closes #3, Closes #4, Closes #5

🤖 Generated with Claude Code

dahai80 and others added 6 commits July 27, 2026 16:11
Phase 1 - Goal Budget System:
- Goal state manager with priority queue and budget tracking
- GoalCreateTool, GoalGetTool, GoalUpdateTool, GoalSetBudgetTool
- Budget enforcer for turns/tokens/wall-time limits
- /goal command (status, pause, resume, cancel, replace, next)

Phase 2 - Undo/Rewind:
- Undo engine with anchor detection and compaction boundary awareness
- /rewind (alias /undo) command using setMessages for message truncation

Phase 3 - D-Mail & Task Health:
- D-Mail summary registration (registerDmailSummary, getDmailSummary)
- Task health monitor with crash recovery and notification manager
- /btw command for async D-Mail delivery

Phase 4 - Approval & Context:
- /approve-session command (grant, list, clear session-scoped permissions)
- cancelBySource/approveForSession/denyForSession runtime API
- Git context injection for researcher/reviewer/explorer agent types
- Summary continuation hints for brief subagent output

Crash bug fixes:
- context.sessionId does not exist on ToolUseContext — replaced with
  getSessionId() from bootstrap/state.js in 7 files (GoalCreateTool,
  GoalGetTool, GoalSetBudgetTool, GoalUpdateTool, DMailTool,
  /goal command, /save-session command)
- context.getMessages does not exist — rewound /rewind from 'local'
  to 'local-jsx' type, uses setMessages updater to read+truncate
- context.setMessageSlice does not exist — replaced with setMessages
  slice approach in /rewind command
- DMailTool redesigned from message-based checkpoint to summary-based
  registration (tools cannot access conversation messages)

Co-Authored-By: Claude <[email protected]>
These analysis/docs are local-only working references, not part of the
codebase. Added to .gitignore so they stay on disk but out of the repo.

Co-Authored-By: Claude <[email protected]>
1. LOCAL_MODEL_BEHAVIORAL_PROMPT: When provider=fusionMlx, append a
   balanced behavioral prompt (~2.9K tokens) after the default system
   prompt. Covers reasoning, communication, coding, and reliability
   guidelines derived from the vendor-neutral Fable 5 system prompt.
   Only activates for local model provider — no impact on cloud models.

2. getChubHint(): Auto-detects chub CLI availability and injects a
   <context_hub_hint> into researcher/explorer/code-reviewer/general-purpose
   sub-agents, guiding them to use 'chub search/get' for up-to-date
   API documentation instead of relying on potentially stale knowledge.

Related: fusion-mlx#218 (core.md injection on inference side)
Related: analysis-prompt.md (integration plan)

Co-Authored-By: Claude <[email protected]>
- Add toMlxModelName() to convert / to -- for MLX server API calls
- Add getOriginalFetch() to capture real fetch before SDK wrapping
- Replace bare fetch() with getOriginalFetch() in retry path
- Fix fusionMlxModel is not defined crash in cloud provider path
- Pre-cache getMlxModelCapabilities before creating fetch interceptor
- Remove all debug console.error logs from debugging session

Both cloud (glm5.1 via LiteLLM) and local MLX providers verified working.

Co-Authored-By: Claude <[email protected]>
…, #4, #5)

- Add Zod schemas for code_exec, code_processes, code_kill,
  code_file_read, code_file_write, code_diff, code_apply_patch,
  code_search_files, artifact_chat in controlSchemas.ts
- Register all new schemas in SDKControlRequestInnerSchema union
- Implement handlers in print.ts dispatch chain:
  - code_exec: spawn with timeout, stdout/stderr capture
  - code_processes: stub (returns empty list)
  - code_kill: process.kill with configurable signal
  - code_file_read: readFile with offset/limit support
  - code_file_write: writeFile with mkdir -p option
  - code_diff: unified diff via 'diff' npm package
  - code_apply_patch: apply unified diff with .bak backup
  - code_search_files: spawnSync find/grep (no shell injection)
  - artifact_chat: JSON-RPC to artifact engine
- Fix fusion-mlx-adapter: remove stale debug logs, fix bare fetch()
  in retry path to use getOriginalFetch()

Co-Authored-By: Claude <[email protected]>
@dahai80
dahai80 merged commit f88c50a into main Jul 27, 2026
1 check passed
@dahai80
dahai80 deleted the feat/sdk-control-code-api branch July 27, 2026 15:29
dahai80 added a commit that referenced this pull request Aug 27, 2026
…2.2) (#161)

ar-plan PR #8: build on the S2.1 shadow write (PR #160) with a pure
projection + dev-only assertion that verifies the event stream is complete.

- deriveMessages(log): Message[] — pure projection. Message-bearing events
  (user_message/assistant_message/tool_result) project to Message[];
  arrays flatten. compact = boundary (truncate prior). turn_start/turn_end/
  error skipped. seq-unordered input → ordered output.
- assertDualWrite(log, mutableMessages, turnId) — dev + FUSION_CODE_EVENT_SOURCING
  only; prod early-returns byte-identical. deepStrictEqual derived vs mutable;
  drift → logForDebugging + throw (fail-visible in dev). Called once per
  turn-end (not per push) to bound cost.
- QueryEngine: wire assertDualWrite before final yield (after capturing
  turnResultUuid — TDZ-safe: declare const first, then assert).

Still no read-path switch — prod reads mutableMessages as before; projection
is dev-assertion + unit-test only. Default-off + env gate preserves byte-
identical-off (PR #7 NOOP_RECORDER pattern continues).

Co-authored-by: Claude Fable 5 <[email protected]>
dahai80 added a commit that referenced this pull request Nov 30, 2026
Documents the #390 line: S1 first-task pass (13-run debugging chain
compressed to one root cause per run), the external-mode architecture
(host loop + FUSION_CODE_SHELL_PREFIX proxy + mirrored workdir), the
89-task network census and A20 freeze, and the ADAPT round-0 data path
dry-validation (ft datasets from-eval: 19 SFT samples + sha256
manifest). A20 baseline section is PENDING until the exclusive engine
window lands the run.

Co-authored-by: Claude Code <[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

1 participant