@posthog/agent 2.1.59 → 2.1.62

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.
@@ -1183,7 +1183,7 @@ import { v7 as uuidv7 } from "uuid";
1183
1183
  // package.json
1184
1184
  var package_default = {
1185
1185
  name: "@posthog/agent",
1186
- version: "2.1.59",
1186
+ version: "2.1.62",
1187
1187
  repository: "https://github.com/PostHog/twig",
1188
1188
  description: "TypeScript agent framework wrapping Claude Agent SDK with Git-based task execution for PostHog",
1189
1189
  exports: {
@@ -2060,14 +2060,25 @@ ${text2}${text2.endsWith("\n") ? "" : "\n"}${escapedText}`;
2060
2060
  function messageUpdateType(role) {
2061
2061
  return role === "assistant" ? "agent_message_chunk" : "user_message_chunk";
2062
2062
  }
2063
- function toolMeta(toolName, toolResponse) {
2064
- return toolResponse ? { claudeCode: { toolName, toolResponse } } : { claudeCode: { toolName } };
2063
+ function toolMeta(toolName, toolResponse, parentToolCallId) {
2064
+ const meta = { toolName };
2065
+ if (toolResponse !== void 0) meta.toolResponse = toolResponse;
2066
+ if (parentToolCallId) meta.parentToolCallId = parentToolCallId;
2067
+ return { claudeCode: meta };
2065
2068
  }
2066
- function handleTextChunk(chunk, role) {
2067
- return {
2069
+ function handleTextChunk(chunk, role, parentToolCallId) {
2070
+ const update = {
2068
2071
  sessionUpdate: messageUpdateType(role),
2069
2072
  content: text(chunk.text)
2070
2073
  };
2074
+ if (parentToolCallId) {
2075
+ update._meta = toolMeta(
2076
+ "__text__",
2077
+ void 0,
2078
+ parentToolCallId
2079
+ );
2080
+ }
2081
+ return update;
2071
2082
  }
2072
2083
  function handleImageChunk(chunk, role) {
2073
2084
  return {
@@ -2079,11 +2090,19 @@ function handleImageChunk(chunk, role) {
2079
2090
  )
2080
2091
  };
2081
2092
  }
2082
- function handleThinkingChunk(chunk) {
2083
- return {
2093
+ function handleThinkingChunk(chunk, parentToolCallId) {
2094
+ const update = {
2084
2095
  sessionUpdate: "agent_thought_chunk",
2085
2096
  content: text(chunk.thinking)
2086
2097
  };
2098
+ if (parentToolCallId) {
2099
+ update._meta = toolMeta(
2100
+ "__thinking__",
2101
+ void 0,
2102
+ parentToolCallId
2103
+ );
2104
+ }
2105
+ return update;
2087
2106
  }
2088
2107
  function handleToolUseChunk(chunk, ctx) {
2089
2108
  ctx.toolUseCache[chunk.id] = chunk;
@@ -2104,7 +2123,7 @@ function handleToolUseChunk(chunk, ctx) {
2104
2123
  await ctx.client.sessionUpdate({
2105
2124
  sessionId: ctx.sessionId,
2106
2125
  update: {
2107
- _meta: toolMeta(toolUse.name, toolResponse),
2126
+ _meta: toolMeta(toolUse.name, toolResponse, ctx.parentToolCallId),
2108
2127
  toolCallId: toolUseId,
2109
2128
  sessionUpdate: "tool_call_update"
2110
2129
  }
@@ -2122,7 +2141,7 @@ function handleToolUseChunk(chunk, ctx) {
2122
2141
  } catch {
2123
2142
  }
2124
2143
  return {
2125
- _meta: toolMeta(chunk.name),
2144
+ _meta: toolMeta(chunk.name, void 0, ctx.parentToolCallId),
2126
2145
  toolCallId: chunk.id,
2127
2146
  sessionUpdate: "tool_call",
2128
2147
  rawInput,
@@ -2142,7 +2161,7 @@ function handleToolResultChunk(chunk, ctx) {
2142
2161
  return null;
2143
2162
  }
2144
2163
  return {
2145
- _meta: toolMeta(toolUse.name),
2164
+ _meta: toolMeta(toolUse.name, void 0, ctx.parentToolCallId),
2146
2165
  toolCallId: chunk.tool_use_id,
2147
2166
  sessionUpdate: "tool_call_update",
2148
2167
  status: chunk.is_error ? "failed" : "completed",
@@ -2156,12 +2175,12 @@ function processContentChunk(chunk, role, ctx) {
2156
2175
  switch (chunk.type) {
2157
2176
  case "text":
2158
2177
  case "text_delta":
2159
- return handleTextChunk(chunk, role);
2178
+ return handleTextChunk(chunk, role, ctx.parentToolCallId);
2160
2179
  case "image":
2161
2180
  return handleImageChunk(chunk, role);
2162
2181
  case "thinking":
2163
2182
  case "thinking_delta":
2164
- return handleThinkingChunk(chunk);
2183
+ return handleThinkingChunk(chunk, ctx.parentToolCallId);
2165
2184
  case "tool_use":
2166
2185
  case "server_tool_use":
2167
2186
  case "mcp_tool_use":
@@ -2191,24 +2210,28 @@ function processContentChunk(chunk, role, ctx) {
2191
2210
  return null;
2192
2211
  }
2193
2212
  }
2194
- function toAcpNotifications(content, role, sessionId, toolUseCache, fileContentCache, client, logger) {
2213
+ function toAcpNotifications(content, role, sessionId, toolUseCache, fileContentCache, client, logger, parentToolCallId) {
2195
2214
  if (typeof content === "string") {
2196
- return [
2197
- {
2198
- sessionId,
2199
- update: {
2200
- sessionUpdate: messageUpdateType(role),
2201
- content: text(content)
2202
- }
2203
- }
2204
- ];
2215
+ const update = {
2216
+ sessionUpdate: messageUpdateType(role),
2217
+ content: text(content)
2218
+ };
2219
+ if (parentToolCallId) {
2220
+ update._meta = toolMeta(
2221
+ "__text__",
2222
+ void 0,
2223
+ parentToolCallId
2224
+ );
2225
+ }
2226
+ return [{ sessionId, update }];
2205
2227
  }
2206
2228
  const ctx = {
2207
2229
  sessionId,
2208
2230
  toolUseCache,
2209
2231
  fileContentCache,
2210
2232
  client,
2211
- logger
2233
+ logger,
2234
+ parentToolCallId
2212
2235
  };
2213
2236
  const output = [];
2214
2237
  for (const chunk of content) {
@@ -2219,7 +2242,7 @@ function toAcpNotifications(content, role, sessionId, toolUseCache, fileContentC
2219
2242
  }
2220
2243
  return output;
2221
2244
  }
2222
- function streamEventToAcpNotifications(message, sessionId, toolUseCache, fileContentCache, client, logger) {
2245
+ function streamEventToAcpNotifications(message, sessionId, toolUseCache, fileContentCache, client, logger, parentToolCallId) {
2223
2246
  const event = message.event;
2224
2247
  switch (event.type) {
2225
2248
  case "content_block_start":
@@ -2230,7 +2253,8 @@ function streamEventToAcpNotifications(message, sessionId, toolUseCache, fileCon
2230
2253
  toolUseCache,
2231
2254
  fileContentCache,
2232
2255
  client,
2233
- logger
2256
+ logger,
2257
+ parentToolCallId
2234
2258
  );
2235
2259
  case "content_block_delta":
2236
2260
  return toAcpNotifications(
@@ -2240,7 +2264,8 @@ function streamEventToAcpNotifications(message, sessionId, toolUseCache, fileCon
2240
2264
  toolUseCache,
2241
2265
  fileContentCache,
2242
2266
  client,
2243
- logger
2267
+ logger,
2268
+ parentToolCallId
2244
2269
  );
2245
2270
  case "message_start":
2246
2271
  case "message_delta":
@@ -2353,13 +2378,15 @@ function handleResultMessage(message, context) {
2353
2378
  }
2354
2379
  async function handleStreamEvent(message, context) {
2355
2380
  const { sessionId, client, toolUseCache, fileContentCache, logger } = context;
2381
+ const parentToolCallId = message.parent_tool_use_id ?? void 0;
2356
2382
  for (const notification of streamEventToAcpNotifications(
2357
2383
  message,
2358
2384
  sessionId,
2359
2385
  toolUseCache,
2360
2386
  fileContentCache,
2361
2387
  client,
2362
- logger
2388
+ logger,
2389
+ parentToolCallId
2363
2390
  )) {
2364
2391
  await client.sessionUpdate(notification);
2365
2392
  context.session.notificationHistory.push(notification);
@@ -2411,6 +2438,7 @@ async function handleUserAssistantMessage(message, context) {
2411
2438
  }
2412
2439
  const content = message.message.content;
2413
2440
  const contentToProcess = filterMessageContent(content);
2441
+ const parentToolCallId = "parent_tool_use_id" in message ? message.parent_tool_use_id ?? void 0 : void 0;
2414
2442
  for (const notification of toAcpNotifications(
2415
2443
  contentToProcess,
2416
2444
  message.message.role,
@@ -2418,7 +2446,8 @@ async function handleUserAssistantMessage(message, context) {
2418
2446
  toolUseCache,
2419
2447
  fileContentCache,
2420
2448
  client,
2421
- logger
2449
+ logger,
2450
+ parentToolCallId
2422
2451
  )) {
2423
2452
  await client.sessionUpdate(notification);
2424
2453
  session.notificationHistory.push(notification);
@@ -3700,6 +3729,11 @@ function findCodexBinary(options) {
3700
3729
  if (options.binaryPath && existsSync3(options.binaryPath)) {
3701
3730
  return { command: options.binaryPath, args: configArgs };
3702
3731
  }
3732
+ if (options.binaryPath) {
3733
+ throw new Error(
3734
+ `codex-acp binary not found at ${options.binaryPath}. Run "node apps/twig/scripts/download-binaries.mjs" to download it.`
3735
+ );
3736
+ }
3703
3737
  return { command: "npx", args: ["@zed-industries/codex-acp", ...configArgs] };
3704
3738
  }
3705
3739
  function spawnCodexProcess(options) {