@posthog/agent 2.3.406 → 2.3.418

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.
@@ -3912,7 +3912,7 @@ function isSupportedReasoningEffort(adapter, modelId, value) {
3912
3912
  }
3913
3913
 
3914
3914
  // src/server/agent-server.ts
3915
- var import_promises5 = require("fs/promises");
3915
+ var import_promises6 = require("fs/promises");
3916
3916
  var import_node_path8 = require("path");
3917
3917
  var import_node_url2 = require("url");
3918
3918
  var import_sdk5 = require("@agentclientprotocol/sdk");
@@ -8266,12 +8266,12 @@ function isTaskError(result) {
8266
8266
  function getErrorMessage(result) {
8267
8267
  return Buffer.concat([...result.stdOut, ...result.stdErr]);
8268
8268
  }
8269
- function errorDetectionHandler(overwrite = false, isError = isTaskError, errorMessage = getErrorMessage) {
8269
+ function errorDetectionHandler(overwrite = false, isError = isTaskError, errorMessage2 = getErrorMessage) {
8270
8270
  return (error, result) => {
8271
8271
  if (!overwrite && error || !isError(result)) {
8272
8272
  return error;
8273
8273
  }
8274
- return errorMessage(result);
8274
+ return errorMessage2(result);
8275
8275
  };
8276
8276
  }
8277
8277
  function errorDetectionPlugin(config) {
@@ -8723,7 +8723,7 @@ var import_zod3 = require("zod");
8723
8723
  // package.json
8724
8724
  var package_default = {
8725
8725
  name: "@posthog/agent",
8726
- version: "2.3.406",
8726
+ version: "2.3.418",
8727
8727
  repository: "https://github.com/PostHog/code",
8728
8728
  description: "TypeScript agent framework wrapping Claude Agent SDK with Git-based task execution for PostHog",
8729
8729
  exports: {
@@ -12906,6 +12906,8 @@ var ParseResult = class {
12906
12906
  return this.calls.filter((c) => CAPTURE_METHODS.has(c.method)).map((c) => ({
12907
12907
  name: c.key,
12908
12908
  line: c.line,
12909
+ keyStartCol: c.keyStartCol,
12910
+ keyEndCol: c.keyEndCol,
12909
12911
  dynamic: c.dynamic ?? false,
12910
12912
  viaWrapper: c.viaWrapper,
12911
12913
  inJsx: c.inJsx
@@ -12916,6 +12918,8 @@ var ParseResult = class {
12916
12918
  method: c.method,
12917
12919
  flagKey: c.key,
12918
12920
  line: c.line,
12921
+ keyStartCol: c.keyStartCol,
12922
+ keyEndCol: c.keyEndCol,
12919
12923
  viaWrapper: c.viaWrapper,
12920
12924
  inJsx: c.inJsx
12921
12925
  }));
@@ -13065,6 +13069,15 @@ var PostHogEnricher = class {
13065
13069
  settled[4]
13066
13070
  );
13067
13071
  }
13072
+ /**
13073
+ * Detect wrapper functions (functions that internally call a PostHog SDK
13074
+ * method) defined in the given source. Used by callers like `enrichSource`
13075
+ * to pick up same-file wrappers such as `track(...)` without threading
13076
+ * through filesystem I/O.
13077
+ */
13078
+ async findWrappersInSource(source, languageId) {
13079
+ return this.detector.findWrappers(source, languageId);
13080
+ }
13068
13081
  async parseFile(filePath) {
13069
13082
  const ext = path32.extname(filePath).toLowerCase();
13070
13083
  const languageId = EXT_TO_LANG_ID[ext];
@@ -19485,14 +19498,14 @@ var PostHogAPIClient = class {
19485
19498
  async apiRequest(endpoint, options = {}) {
19486
19499
  const response = await this.performRequestWithRetry(endpoint, options);
19487
19500
  if (!response.ok) {
19488
- let errorMessage;
19501
+ let errorMessage2;
19489
19502
  try {
19490
19503
  const errorResponse = await response.json();
19491
- errorMessage = `Failed request: [${response.status}] ${JSON.stringify(errorResponse)}`;
19504
+ errorMessage2 = `Failed request: [${response.status}] ${JSON.stringify(errorResponse)}`;
19492
19505
  } catch {
19493
- errorMessage = `Failed request: [${response.status}] ${response.statusText}`;
19506
+ errorMessage2 = `Failed request: [${response.status}] ${response.statusText}`;
19494
19507
  }
19495
- throw new Error(errorMessage);
19508
+ throw new Error(errorMessage2);
19496
19509
  }
19497
19510
  return response.json();
19498
19511
  }
@@ -20278,6 +20291,72 @@ var SessionLogWriter = class _SessionLogWriter {
20278
20291
  }
20279
20292
  };
20280
20293
 
20294
+ // src/server/agentsh-runtime.ts
20295
+ var import_node_child_process5 = require("child_process");
20296
+ var import_promises5 = require("fs/promises");
20297
+ var import_node_util2 = require("util");
20298
+ var AGENTSH_SESSION_ID_FILE = "/tmp/agentsh-session-id";
20299
+ var execFileAsync2 = (0, import_node_util2.promisify)(import_node_child_process5.execFile);
20300
+ function errorMessage(error) {
20301
+ return error instanceof Error ? error.message : String(error);
20302
+ }
20303
+ function parseAgentshVersion(output) {
20304
+ const version = `${output.stdout}
20305
+ ${output.stderr}`.split("\n").map((line) => line.trim()).find(Boolean);
20306
+ return version ?? null;
20307
+ }
20308
+ async function getAgentshVersion() {
20309
+ const { stdout, stderr } = await execFileAsync2("agentsh", ["--version"], {
20310
+ timeout: 5e3
20311
+ });
20312
+ return { stdout, stderr };
20313
+ }
20314
+ async function resolveAgentshRuntimeInfo({
20315
+ sessionIdPath = AGENTSH_SESSION_ID_FILE,
20316
+ readSessionId = async (path16) => (0, import_promises5.readFile)(path16, "utf8"),
20317
+ getVersion = getAgentshVersion
20318
+ } = {}) {
20319
+ let sessionId;
20320
+ try {
20321
+ sessionId = (await readSessionId(sessionIdPath)).trim();
20322
+ } catch (error) {
20323
+ const code = error.code;
20324
+ if (code === "ENOENT") {
20325
+ return null;
20326
+ }
20327
+ throw error;
20328
+ }
20329
+ if (!sessionId) {
20330
+ return null;
20331
+ }
20332
+ try {
20333
+ const output = await getVersion();
20334
+ return {
20335
+ sessionId,
20336
+ version: parseAgentshVersion(output)
20337
+ };
20338
+ } catch (error) {
20339
+ return {
20340
+ sessionId,
20341
+ version: null,
20342
+ versionLookupError: errorMessage(error)
20343
+ };
20344
+ }
20345
+ }
20346
+ async function logAgentshRuntimeInfo(logger, options) {
20347
+ const agentsh = await resolveAgentshRuntimeInfo(options);
20348
+ if (!agentsh) {
20349
+ return;
20350
+ }
20351
+ logger.debug(`Agentsh session ID: ${agentsh.sessionId}`);
20352
+ logger.debug(`Agentsh hardening version: ${agentsh.version ?? "unknown"}`);
20353
+ if (agentsh.versionLookupError) {
20354
+ logger.debug(
20355
+ `Agentsh version lookup failed: ${agentsh.versionLookupError}`
20356
+ );
20357
+ }
20358
+ }
20359
+
20281
20360
  // src/server/cloud-prompt.ts
20282
20361
  function normalizeCloudPromptContent(content) {
20283
20362
  if (typeof content === "string") {
@@ -21117,6 +21196,7 @@ var AgentServer = class {
21117
21196
  this.logger.debug(
21118
21197
  `Agent version: ${this.config.version ?? package_default.version}`
21119
21198
  );
21199
+ await logAgentshRuntimeInfo(this.logger);
21120
21200
  this.logger.debug(`Initial permission mode: ${initialPermissionMode}`);
21121
21201
  this.posthogAPI.updateTaskRun(payload.task_id, payload.run_id, {
21122
21202
  status: "in_progress"
@@ -21135,12 +21215,12 @@ var AgentServer = class {
21135
21215
  }
21136
21216
  classifyAndSignalFailure(payload, phase, error) {
21137
21217
  const { classification, message } = this.extractErrorClassification(error);
21138
- const errorMessage = classification === "upstream_stream_terminated" ? "Upstream LLM stream terminated" : classification === "upstream_connection_error" ? "Upstream LLM connection error" : message || "Agent error";
21218
+ const errorMessage2 = classification === "upstream_stream_terminated" ? "Upstream LLM stream terminated" : classification === "upstream_connection_error" ? "Upstream LLM connection error" : message || "Agent error";
21139
21219
  this.logger.error(`send_${phase}_task_message_failed`, {
21140
21220
  classification,
21141
21221
  message
21142
21222
  });
21143
- return this.signalTaskComplete(payload, "error", errorMessage);
21223
+ return this.signalTaskComplete(payload, "error", errorMessage2);
21144
21224
  }
21145
21225
  async sendInitialTaskMessage(payload, prefetchedRun) {
21146
21226
  if (!this.session) return;
@@ -21448,9 +21528,9 @@ Continue from where you left off. The user is waiting for your response.`
21448
21528
  runId,
21449
21529
  artifact.id ?? safeName
21450
21530
  );
21451
- await (0, import_promises5.mkdir)(artifactDir, { recursive: true });
21531
+ await (0, import_promises6.mkdir)(artifactDir, { recursive: true });
21452
21532
  const artifactPath = (0, import_node_path8.join)(artifactDir, safeName);
21453
- await (0, import_promises5.writeFile)(artifactPath, Buffer.from(data));
21533
+ await (0, import_promises6.writeFile)(artifactPath, Buffer.from(data));
21454
21534
  return resourceLink((0, import_node_url2.pathToFileURL)(artifactPath).toString(), artifact.name, {
21455
21535
  ...artifact.content_type ? { mimeType: artifact.content_type } : {},
21456
21536
  ...typeof artifact.size === "number" ? { size: artifact.size } : {}
@@ -21662,7 +21742,7 @@ ${attributionInstructions}
21662
21742
  });
21663
21743
  }
21664
21744
  }
21665
- async signalTaskComplete(payload, stopReason, errorMessage) {
21745
+ async signalTaskComplete(payload, stopReason, errorMessage2) {
21666
21746
  if (this.session?.payload.run_id === payload.run_id) {
21667
21747
  try {
21668
21748
  await this.session.logWriter.flush(payload.run_id, {
@@ -21686,7 +21766,7 @@ ${attributionInstructions}
21686
21766
  try {
21687
21767
  await this.posthogAPI.updateTaskRun(payload.task_id, payload.run_id, {
21688
21768
  status,
21689
- error_message: errorMessage ?? "Agent error"
21769
+ error_message: errorMessage2 ?? "Agent error"
21690
21770
  });
21691
21771
  this.logger.debug("Task completion signaled", { status, stopReason });
21692
21772
  } catch (error) {