@posthog/agent 2.3.398 → 2.3.403
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +11 -14
- package/dist/agent.js +1 -7
- package/dist/agent.js.map +1 -1
- package/dist/handoff-checkpoint.d.ts +0 -2
- package/dist/handoff-checkpoint.js +38 -53
- package/dist/handoff-checkpoint.js.map +1 -1
- package/dist/index.d.ts +0 -2
- package/dist/index.js +0 -2
- package/dist/index.js.map +1 -1
- package/dist/posthog-api.js +1 -5
- package/dist/posthog-api.js.map +1 -1
- package/dist/resume.d.ts +5 -6
- package/dist/resume.js +2 -41
- package/dist/resume.js.map +1 -1
- package/dist/server/agent-server.d.ts +1 -2
- package/dist/server/agent-server.js +103 -768
- package/dist/server/agent-server.js.map +1 -1
- package/dist/server/bin.cjs +101 -766
- package/dist/server/bin.cjs.map +1 -1
- package/dist/types.d.ts +2 -13
- package/dist/types.js.map +1 -1
- package/package.json +3 -7
- package/src/acp-extensions.ts +0 -3
- package/src/handoff-checkpoint.test.ts +3 -17
- package/src/handoff-checkpoint.ts +15 -45
- package/src/resume.ts +5 -11
- package/src/sagas/resume-saga.test.ts +27 -77
- package/src/sagas/resume-saga.ts +3 -44
- package/src/sagas/test-fixtures.ts +17 -76
- package/src/server/agent-server.ts +22 -103
- package/src/test/fixtures/api.ts +2 -15
- package/src/types.ts +0 -16
- package/dist/tree-tracker.d.ts +0 -68
- package/dist/tree-tracker.js +0 -6431
- package/dist/tree-tracker.js.map +0 -1
- package/src/sagas/apply-snapshot-saga.test.ts +0 -690
- package/src/sagas/apply-snapshot-saga.ts +0 -100
- package/src/sagas/capture-tree-saga.test.ts +0 -892
- package/src/sagas/capture-tree-saga.ts +0 -150
- package/src/tree-tracker.ts +0 -173
package/README.md
CHANGED
|
@@ -59,7 +59,7 @@ The same ACP agent runs in both contexts. The difference is how it's connected:
|
|
|
59
59
|
|
|
60
60
|
**Local (PostHog Code desktop):** The agent runs in-process. PostHog Code calls `createAcpConnection()` directly — no HTTP server, no JWT. The bidirectional ACP streams connect client ↔ agent within the same process.
|
|
61
61
|
|
|
62
|
-
**
|
|
62
|
+
**HandoffCheckpointTracker** handles the bridge between these contexts: it captures git checkpoint state plus the object pack/index needed to restore the worktree across cloud and local. This enables the "hand off" flow — start locally, continue in cloud, or vice versa.
|
|
63
63
|
|
|
64
64
|
### Permission modes
|
|
65
65
|
|
|
@@ -108,7 +108,7 @@ start()
|
|
|
108
108
|
├─ Creates synthetic JwtPayload from CLI config
|
|
109
109
|
├─ configureEnvironment() — sets ANTHROPIC_BASE_URL, OPENAI_BASE_URL, etc.
|
|
110
110
|
│ pointing at the PostHog LLM gateway
|
|
111
|
-
├─ Creates
|
|
111
|
+
├─ Creates HandoffCheckpointTracker, SessionLogWriter, PostHogAPIClient
|
|
112
112
|
├─ createAcpConnection() — sets up ACP streams with log tapping
|
|
113
113
|
│
|
|
114
114
|
├─ Wraps client streams with a SECOND tap layer (NdJsonTap)
|
|
@@ -144,9 +144,9 @@ When `POST /command` receives a `user_message`, it doesn't handle it directly
|
|
|
144
144
|
|
|
145
145
|
The `AgentServer` provides a `requestPermission` callback to the `ClientSideConnection` that always selects the "allow" option. In background mode this is necessary (no human to ask). In interactive mode it currently does the same, with a TODO for future per-tool approval via SSE round-trips.
|
|
146
146
|
|
|
147
|
-
###
|
|
147
|
+
### Checkpoint capture
|
|
148
148
|
|
|
149
|
-
After
|
|
149
|
+
After file-mutating tool calls, the server captures a git checkpoint via `HandoffCheckpointTracker` and broadcasts it as a `_posthog/git_checkpoint` SSE event. A final checkpoint is captured during session cleanup. This is how the client restores repo state for cloud↔local handoff.
|
|
150
150
|
|
|
151
151
|
### CLI
|
|
152
152
|
|
|
@@ -200,7 +200,7 @@ For Codex adapters, `agent.run()` also fetches available models from the PostHog
|
|
|
200
200
|
|
|
201
201
|
## Log pipeline and session resume
|
|
202
202
|
|
|
203
|
-
Logs serve two purposes: real-time observability and session resume. Every ACP message that flows through the tapped streams is persisted, creating a complete record of the conversation — user messages, agent responses, tool calls, tool results,
|
|
203
|
+
Logs serve two purposes: real-time observability and session resume. Every ACP message that flows through the tapped streams is persisted, creating a complete record of the conversation — user messages, agent responses, tool calls, tool results, git checkpoints, and metadata events. This record is the single source of truth for resuming a session from any point.
|
|
204
204
|
|
|
205
205
|
### Writing logs
|
|
206
206
|
|
|
@@ -218,10 +218,9 @@ When a session needs to continue (e.g. cloud↔local handoff, or recovering from
|
|
|
218
218
|
```text
|
|
219
219
|
1. fetch_task_run → GET /api/.../runs/{runId}/ to find the log_url
|
|
220
220
|
2. fetch_logs → Download all StoredNotification entries
|
|
221
|
-
3.
|
|
222
|
-
4.
|
|
223
|
-
5.
|
|
224
|
-
6. find_device → Scan backwards for last device info (local vs cloud)
|
|
221
|
+
3. find_git_checkpoint → Scan backwards for latest _posthog/git_checkpoint
|
|
222
|
+
4. rebuild_conversation → Walk log entries to reconstruct conversation turns
|
|
223
|
+
5. find_device → Scan backwards for last device info (local vs cloud)
|
|
225
224
|
```
|
|
226
225
|
|
|
227
226
|
The conversation rebuild (`rebuildConversation`) walks the log entries and reassembles turns from ACP `session/update` notifications:
|
|
@@ -231,9 +230,7 @@ The conversation rebuild (`rebuildConversation`) walks the log entries and reass
|
|
|
231
230
|
- `tool_call` / `tool_call_update` → track tool calls with their inputs
|
|
232
231
|
- `tool_result` → match results back to tool calls by `toolCallId`
|
|
233
232
|
|
|
234
|
-
The result is a `ResumeState` containing the conversation history as `ConversationTurn[]`, the latest
|
|
235
|
-
|
|
236
|
-
Snapshot application can fail without aborting the resume — if the archive URL is missing or the download fails, the saga logs a warning and continues with just the conversation history. The `snapshotApplied` flag in the result tells the caller whether files were actually restored.
|
|
233
|
+
The result is a `ResumeState` containing the conversation history as `ConversationTurn[]`, the latest git checkpoint, and metadata. This feeds into the ACP `session/load` or `_posthog/session/resume` methods on the Claude adapter, which initializes a new Claude SDK query with the rebuilt context.
|
|
237
234
|
|
|
238
235
|
## ACP extensions
|
|
239
236
|
|
|
@@ -250,7 +247,7 @@ ACP defines standard methods like `session/prompt`, `session/update`, and `sessi
|
|
|
250
247
|
**State synchronization** — events that keep the client's view of the agent's state in sync. These are essential for the cloud↔local handoff flow and for the client to render accurate UI.
|
|
251
248
|
|
|
252
249
|
- `_posthog/branch_created` — `{ branch }` — agent created a git branch (client can update branch display)
|
|
253
|
-
- `_posthog/
|
|
250
|
+
- `_posthog/git_checkpoint` — `{ checkpointId, checkpointRef, branch, head, indexTree, worktreeTree, ... }` — git checkpoint captured for resume and handoff. This is the key event for session resume — the resume saga scans backwards for the latest checkpoint to restore files
|
|
254
251
|
- `_posthog/mode_change` — `{ mode, previous_mode }` — permission mode changed (client updates mode selector)
|
|
255
252
|
- `_posthog/compact_boundary` — `{ sessionId, timestamp }` — marks where context compaction occurred, so the client knows the conversation was summarized at this point
|
|
256
253
|
- `_posthog/task_notification` — `{ sessionId, type, message?, data? }` — generic extensible notification for adapter-specific events
|
|
@@ -260,7 +257,7 @@ ACP defines standard methods like `session/prompt`, `session/update`, and `sessi
|
|
|
260
257
|
- `_posthog/user_message` — `{ content }` — user typed a message (translated to `session/prompt`)
|
|
261
258
|
- `_posthog/cancel` — cancel the current operation (translated to `session/cancel`)
|
|
262
259
|
- `_posthog/close` — close the session and clean up
|
|
263
|
-
- `_posthog/session/resume` — `{ sessionId
|
|
260
|
+
- `_posthog/session/resume` — `{ sessionId }` — request to resume a previous session (triggers the resume flow on the Claude adapter)
|
|
264
261
|
|
|
265
262
|
**Debug** — operational visibility without polluting the ACP conversation.
|
|
266
263
|
|
package/dist/agent.js
CHANGED
|
@@ -4030,7 +4030,7 @@ import { v7 as uuidv7 } from "uuid";
|
|
|
4030
4030
|
// package.json
|
|
4031
4031
|
var package_default = {
|
|
4032
4032
|
name: "@posthog/agent",
|
|
4033
|
-
version: "2.3.
|
|
4033
|
+
version: "2.3.403",
|
|
4034
4034
|
repository: "https://github.com/PostHog/code",
|
|
4035
4035
|
description: "TypeScript agent framework wrapping Claude Agent SDK with Git-based task execution for PostHog",
|
|
4036
4036
|
exports: {
|
|
@@ -4098,10 +4098,6 @@ var package_default = {
|
|
|
4098
4098
|
types: "./dist/handoff-checkpoint.d.ts",
|
|
4099
4099
|
import: "./dist/handoff-checkpoint.js"
|
|
4100
4100
|
},
|
|
4101
|
-
"./tree-tracker": {
|
|
4102
|
-
types: "./dist/tree-tracker.d.ts",
|
|
4103
|
-
import: "./dist/tree-tracker.js"
|
|
4104
|
-
},
|
|
4105
4101
|
"./server": {
|
|
4106
4102
|
types: "./dist/server/agent-server.d.ts",
|
|
4107
4103
|
import: "./dist/server/agent-server.js"
|
|
@@ -4197,8 +4193,6 @@ var POSTHOG_NOTIFICATIONS = {
|
|
|
4197
4193
|
CONSOLE: "_posthog/console",
|
|
4198
4194
|
/** Maps taskRunId to agent's sessionId and adapter type (for resumption) */
|
|
4199
4195
|
SDK_SESSION: "_posthog/sdk_session",
|
|
4200
|
-
/** Tree state snapshot captured (git tree hash + file archive) */
|
|
4201
|
-
TREE_SNAPSHOT: "_posthog/tree_snapshot",
|
|
4202
4196
|
/** Git checkpoint captured for handoff */
|
|
4203
4197
|
GIT_CHECKPOINT: "_posthog/git_checkpoint",
|
|
4204
4198
|
/** Agent mode changed (interactive/background) */
|