feat(core): M1 kernel MVP — DeepSeek provider + 6 P0 tools + agent loop + sessions#1
Merged
Conversation
…op + sessions
Implements DEVELOPMENT_PLAN.md §6 M1 in full (except trust dialog, deferred to
M2 where the CLI/onboarding surface lives — kernel exposes the session/snapshot
primitives that M2 will consume).
What ships
----------
- DeepSeekProvider (packages/core/src/providers/deepseek.ts)
- OpenAI-compatible streaming via injected `fetch`
- Handles `content`, `reasoning_content`, `tool_calls` deltas
- Dual credential (apiKey X-Api-Key OR authToken Bearer)
- DEEPSEEK_MODELS and EFFORT_PARAMS enforce 8192 max_tokens hard limit
- anthropicShapeToOpenAI boundary converter (StoredMessage[] ↔ chat.completions)
- 6 P0 tools (packages/core/src/tools/{read,write,edit,bash,grep,glob}.ts)
- Read: numbered lines + offset/limit + line-width truncation
- Write: creates parent dirs
- Edit: exact-string replacement, fails on non-unique unless replace_all
- Bash: spawn /bin/sh -c, timeout, stdout/stderr capture, 30KB cap each
- Grep: ripgrep via execFile, graceful (no matches) handling
- Glob: built-in fs.glob (Node 22+), mtime-desc sort
- ToolRegistry + BUILTIN_TOOLS for one-line wire-up
- Sessions (packages/core/src/sessions/)
- jsonl message log + .meta.json sidecar
- Snapshots (sha256-keyed blobs + manifest.jsonl) — pre/post Edit/Write
- SessionManager facade (create / load / list / append / snapshot)
- Agent loop (packages/core/src/agent.ts)
- provider ↔ tools ↔ session orchestration
- history-snapshotting per turn (provider sees stable input)
- automatic snapshot on Edit/Write tool calls
- AbortSignal-aware, maxTurns cap, comprehensive AgentEvent stream
Tests (62 passed, 4 skipped, 0 failed in ~1.3s)
-----------------------------------------------
- providers/deepseek.test.ts (13) — streaming text / reasoning_content / tool calls /
msg-shape conversion / auth variants / model invariants
- tools/{read,write,edit,bash,grep,glob}.test.ts (31 tests) — real fs / real exec
- sessions/{storage,snapshots}.test.ts (11) — round-trip, manifest, restore
- agent.test.ts (7) — end_turn / tool dispatch / unknown tool / maxTurns /
abort / session+snapshots / multi-turn history feedback
Mock strategy: MockProvider for agent tests (deterministic), mockFetch returning
SSE chunks for provider tests. Zero new test deps.
Docs
----
- docs/core-api.md — full public API surface + storage layout + what M1 doesn't
- docs/milestones/M1.md — milestone postmortem, design decisions, known gaps
Verified
--------
pnpm typecheck → green
pnpm build → all packages emit dist/
pnpm test → 62 passed / 4 skipped (ripgrep-dependent) / 0 failed
pnpm format:check → all conformant
Bugs found and fixed in-flight
------------------------------
- `apiKey ?? authToken` failed for `apiKey: ''` (nullish only) — switched to `||`
- `messages: history` passed by reference let later turns mutate earlier calls' record
→ `messages: [...history]` snapshot per call
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
oratis
added a commit
that referenced
this pull request
May 27, 2026
Implements docs/design/sandbox-plan-worktree.md §5.1 decision flow.
Shipped
-------
- harness/tool-dispatcher.ts (105 lines)
· dispatchToolCall() combines:
1. evaluatePermission (existing M2)
2. evaluateMode (existing M3a)
3. PreToolUse hook (existing M3a HookDispatcher)
· Returns DispatchVerdict { decision, source, reason, hook?, ... }
· plan-blocked short-circuits before hooks (matches invariant #1)
· Hook JSON output decision=deny/ask overrides mode allow
· Hook non-zero exit code → deny
- agent.ts integration:
· New RunAgentOptions fields: mode, permissions, hooks, approval
· Tool-call loop now consults dispatcher when mode is set
· 'ask' verdict invokes ApprovalCallback (caller-supplied)
· 'deny' / 'plan-blocked' produce tool_result with is_error=true,
fed back to LLM so it can recover
· PostToolUse hook fires after every tool execution
· Backwards compatible: when mode is unset, M1 behavior (allow all)
Tests
-----
- harness/tool-dispatcher.test.ts (9 tests)
All paths of the §5.1 decision tree, including plan short-circuit,
acceptEdits with permission-deny still winning, hook JSON override,
hook non-zero exit, dontAsk strict deny.
Total: 206 passed / 4 skipped / 0 failed (was 197).
Deferred to M3c
---------------
MCP client / compaction / statusLine / /init multi-phase / auto-classifier
mode / hook handler types beyond `command` / hook `if` field.
CLI REPL not yet plumbed with mode (M3c). Mode-aware gating only activates
when a caller passes `mode:` to `runAgent` — current REPL still uses M1
path.
Verified
--------
pnpm typecheck → green
pnpm test → 206 passed / 4 skipped
pnpm format:check → conformant
Co-authored-by: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
oratis
added a commit
that referenced
this pull request
May 28, 2026
This session ("继续推进" from v2) added 5 PRs on top of #1-#16:
· #17 M3c-rest tools (TodoWrite + WebFetch + WebSearch)
· #18 M3.5 attack tests + security-model.md
· #19 M8 headless mode (-p / --print)
· #20 M5.2 plugin live wire-up
· #21 system-reminder injector
Test count: 313 → 387 (+74).
Scope completion estimate: 65-70% → 72-78%.
Major remaining items: M6 Mac Electron (still 0%), M7 file panel (depends
on M6), and the M3c-rest/M8/M5.2 leftovers itemized in the body.
Co-authored-by: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Test plan
CI will additionally validate: link-check job (all M0 docs present), lint stub.
Documentation
Release notes label
Checklist
Related
Follows: `chore(m0): initial M0 skeleton` (3b39d99) on `main`.
Closes: M1 milestone.
Design decisions called out for review
DeepCode-internal `ContentBlock` types (not Anthropic SDK types). Providers convert at boundary via `anthropicShapeToOpenAI()`. Avoids hard SDK dependency.
History snapshotted per provider call — `messages: [...history]` instead of `messages: history`. Prevents subsequent-turn mutations from leaking into earlier calls' provider record. Caught by test, fixed in M1.
`apiKey || authToken` not `??` — empty string isn't nullish; `??` left empty apiKey through. Caught by test.
Bash `run_in_background` deliberate stub — returns error pointing to M3.15.3. Defers entire background-task infrastructure to where its design lives (TaskCreate/Monitor).
Snapshot blob storage colocated with sessions — `//snapshots/{NNNNN-ts-hash.blob, manifest.jsonl}`. Same storage that §3.15.9 rewind UX will read in M7.
Co-Authored-By: Claude Opus 4.7 (1M context) noreply@anthropic.com