@posthog/agent 2.1.5 → 2.1.13

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.
@@ -1175,7 +1175,7 @@ var import_uuid = require("uuid");
1175
1175
  // package.json
1176
1176
  var package_default = {
1177
1177
  name: "@posthog/agent",
1178
- version: "2.1.5",
1178
+ version: "2.1.13",
1179
1179
  repository: "https://github.com/PostHog/twig",
1180
1180
  description: "TypeScript agent framework wrapping Claude Agent SDK with Git-based task execution for PostHog",
1181
1181
  exports: {
@@ -3073,7 +3073,7 @@ var path2 = __toESM(require("path"), 1);
3073
3073
  var BRANCH_NAMING_INSTRUCTIONS = `
3074
3074
  # Branch Naming
3075
3075
 
3076
- Before pushing a "workspace-*" branch to origin, rename it to something descriptive based on the work done. Do this automatically without asking the user.
3076
+ When working in a detached HEAD state, create a descriptive branch name based on the work being done before committing. Do this automatically without asking the user.
3077
3077
  `;
3078
3078
  function buildSystemPrompt(customPrompt) {
3079
3079
  const defaultPrompt = {
@@ -4243,69 +4243,15 @@ var PostHogAPIClient = class {
4243
4243
  }
4244
4244
  };
4245
4245
 
4246
- // src/otel-log-writer.ts
4247
- var import_api_logs = require("@opentelemetry/api-logs");
4248
- var import_exporter_logs_otlp_http = require("@opentelemetry/exporter-logs-otlp-http");
4249
- var import_resources = require("@opentelemetry/resources");
4250
- var import_sdk_logs = require("@opentelemetry/sdk-logs");
4251
- var import_semantic_conventions = require("@opentelemetry/semantic-conventions");
4252
- var OtelLogWriter = class {
4253
- loggerProvider;
4254
- logger;
4255
- constructor(config, sessionContext, _debugLogger) {
4256
- const logsPath = config.logsPath ?? "/i/v1/agent-logs";
4257
- const exporter = new import_exporter_logs_otlp_http.OTLPLogExporter({
4258
- url: `${config.posthogHost}${logsPath}`,
4259
- headers: { Authorization: `Bearer ${config.apiKey}` }
4260
- });
4261
- const processor = new import_sdk_logs.BatchLogRecordProcessor(exporter, {
4262
- scheduledDelayMillis: config.flushIntervalMs ?? 500
4263
- });
4264
- this.loggerProvider = new import_sdk_logs.LoggerProvider({
4265
- resource: (0, import_resources.resourceFromAttributes)({
4266
- [import_semantic_conventions.ATTR_SERVICE_NAME]: "twig-agent",
4267
- run_id: sessionContext.runId,
4268
- task_id: sessionContext.taskId,
4269
- device_type: sessionContext.deviceType ?? "local"
4270
- }),
4271
- processors: [processor]
4272
- });
4273
- this.logger = this.loggerProvider.getLogger("agent-session");
4274
- }
4275
- /**
4276
- * Emit an agent event to PostHog Logs via OTEL.
4277
- */
4278
- emit(entry) {
4279
- const { notification } = entry;
4280
- const eventType = notification.notification.method;
4281
- this.logger.emit({
4282
- severityNumber: import_api_logs.SeverityNumber.INFO,
4283
- severityText: "INFO",
4284
- body: JSON.stringify(notification),
4285
- attributes: {
4286
- event_type: eventType
4287
- }
4288
- });
4289
- }
4290
- async flush() {
4291
- await this.loggerProvider.forceFlush();
4292
- }
4293
- async shutdown() {
4294
- await this.loggerProvider.shutdown();
4295
- }
4296
- };
4297
-
4298
4246
  // src/session-log-writer.ts
4299
4247
  var SessionLogWriter = class {
4300
4248
  posthogAPI;
4301
- otelConfig;
4302
4249
  pendingEntries = /* @__PURE__ */ new Map();
4303
4250
  flushTimeouts = /* @__PURE__ */ new Map();
4304
4251
  sessions = /* @__PURE__ */ new Map();
4305
4252
  logger;
4306
4253
  constructor(options = {}) {
4307
4254
  this.posthogAPI = options.posthogAPI;
4308
- this.otelConfig = options.otelConfig;
4309
4255
  this.logger = options.logger ?? new Logger({ debug: false, prefix: "[SessionLogWriter]" });
4310
4256
  }
4311
4257
  async flushAll() {
@@ -4319,15 +4265,7 @@ var SessionLogWriter = class {
4319
4265
  if (this.sessions.has(sessionId)) {
4320
4266
  return;
4321
4267
  }
4322
- let otelWriter;
4323
- if (this.otelConfig) {
4324
- otelWriter = new OtelLogWriter(
4325
- this.otelConfig,
4326
- context,
4327
- this.logger.child(`OtelWriter:${sessionId}`)
4328
- );
4329
- }
4330
- this.sessions.set(sessionId, { context, otelWriter });
4268
+ this.sessions.set(sessionId, { context });
4331
4269
  }
4332
4270
  isRegistered(sessionId) {
4333
4271
  return this.sessions.has(sessionId);
@@ -4357,9 +4295,6 @@ var SessionLogWriter = class {
4357
4295
  timestamp,
4358
4296
  notification: message
4359
4297
  };
4360
- if (session.otelWriter) {
4361
- session.otelWriter.emit({ notification: entry });
4362
- }
4363
4298
  if (this.posthogAPI) {
4364
4299
  const pending = this.pendingEntries.get(sessionId) ?? [];
4365
4300
  pending.push(entry);
@@ -4377,9 +4312,6 @@ var SessionLogWriter = class {
4377
4312
  const session = this.sessions.get(sessionId);
4378
4313
  if (!session) return;
4379
4314
  this.emitCoalescedMessage(sessionId, session);
4380
- if (session.otelWriter) {
4381
- await session.otelWriter.flush();
4382
- }
4383
4315
  const pending = this.pendingEntries.get(sessionId);
4384
4316
  if (!this.posthogAPI || !pending?.length) return;
4385
4317
  this.pendingEntries.delete(sessionId);
@@ -4431,9 +4363,6 @@ var SessionLogWriter = class {
4431
4363
  }
4432
4364
  }
4433
4365
  };
4434
- if (session.otelWriter) {
4435
- session.otelWriter.emit({ notification: entry });
4436
- }
4437
4366
  if (this.posthogAPI) {
4438
4367
  const pending = this.pendingEntries.get(sessionId) ?? [];
4439
4368
  pending.push(entry);
@@ -9147,9 +9076,9 @@ var GitOperationManagerImpl = class _GitOperationManagerImpl {
9147
9076
  const scopedGit = createGitClient(repoPath, {
9148
9077
  abortSignal: options.signal
9149
9078
  });
9150
- return operation(scopedGit.env({ GIT_OPTIONAL_LOCKS: "0" }));
9079
+ return operation(scopedGit.env({ ...process.env, GIT_OPTIONAL_LOCKS: "0" }));
9151
9080
  }
9152
- const git = state.client.env({ GIT_OPTIONAL_LOCKS: "0" });
9081
+ const git = state.client.env({ ...process.env, GIT_OPTIONAL_LOCKS: "0" });
9153
9082
  return operation(git);
9154
9083
  }
9155
9084
  async executeWrite(repoPath, operation, options) {
@@ -9166,9 +9095,9 @@ var GitOperationManagerImpl = class _GitOperationManagerImpl {
9166
9095
  const scopedGit = createGitClient(repoPath, {
9167
9096
  abortSignal: options.signal
9168
9097
  });
9169
- return await operation(scopedGit);
9098
+ return await operation(scopedGit.env(process.env));
9170
9099
  }
9171
- return await operation(state.client);
9100
+ return await operation(state.client.env(process.env));
9172
9101
  } catch (error) {
9173
9102
  if (options?.signal?.aborted) {
9174
9103
  await removeLock(repoPath).catch(() => {
@@ -10329,17 +10258,13 @@ var AgentServer = class {
10329
10258
  runId: payload.run_id,
10330
10259
  logger: new Logger({ debug: true, prefix: "[TreeTracker]" })
10331
10260
  });
10332
- const _posthogAPI = new PostHogAPIClient({
10261
+ const posthogAPI = new PostHogAPIClient({
10333
10262
  apiUrl: this.config.apiUrl,
10334
10263
  projectId: this.config.projectId,
10335
10264
  getApiKey: () => this.config.apiKey
10336
10265
  });
10337
10266
  const logWriter = new SessionLogWriter({
10338
- otelConfig: {
10339
- posthogHost: this.config.apiUrl,
10340
- apiKey: this.config.apiKey,
10341
- logsPath: "/i/v1/agent-logs"
10342
- },
10267
+ posthogAPI,
10343
10268
  logger: new Logger({ debug: true, prefix: "[SessionLogWriter]" })
10344
10269
  });
10345
10270
  const acpConnection = createAcpConnection({