Commit b58fc71
feat(core): M1 kernel MVP — DeepSeek provider + 6 P0 tools + agent loop + sessions (#1)
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>1 parent 3b39d99 commit b58fc71
31 files changed
Lines changed: 2810 additions & 42 deletions
File tree
- docs
- milestones
- packages/core/src
- providers
- sessions
- tools
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
| 117 | + | |
| 118 | + | |
| 119 | + | |
| 120 | + | |
| 121 | + | |
| 122 | + | |
| 123 | + | |
| 124 | + | |
| 125 | + | |
| 126 | + | |
| 127 | + | |
| 128 | + | |
| 129 | + | |
| 130 | + | |
| 131 | + | |
| 132 | + | |
| 133 | + | |
| 134 | + | |
| 135 | + | |
| 136 | + | |
| 137 | + | |
| 138 | + | |
| 139 | + | |
| 140 | + | |
| 141 | + | |
| 142 | + | |
| 143 | + | |
| 144 | + | |
| 145 | + | |
| 146 | + | |
| 147 | + | |
| 148 | + | |
| 149 | + | |
| 150 | + | |
| 151 | + | |
| 152 | + | |
| 153 | + | |
| 154 | + | |
| 155 | + | |
| 156 | + | |
| 157 | + | |
| 158 | + | |
| 159 | + | |
| 160 | + | |
| 161 | + | |
| 162 | + | |
| 163 | + | |
| 164 | + | |
| 165 | + | |
| 166 | + | |
| 167 | + | |
| 168 | + | |
| 169 | + | |
| 170 | + | |
| 171 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
0 commit comments