@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.
@@ -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.5",
1186
+ version: "2.1.13",
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: {
@@ -3081,7 +3081,7 @@ import * as path2 from "path";
3081
3081
  var BRANCH_NAMING_INSTRUCTIONS = `
3082
3082
  # Branch Naming
3083
3083
 
3084
- Before pushing a "workspace-*" branch to origin, rename it to something descriptive based on the work done. Do this automatically without asking the user.
3084
+ 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.
3085
3085
  `;
3086
3086
  function buildSystemPrompt(customPrompt) {
3087
3087
  const defaultPrompt = {
@@ -4251,72 +4251,15 @@ var PostHogAPIClient = class {
4251
4251
  }
4252
4252
  };
4253
4253
 
4254
- // src/otel-log-writer.ts
4255
- import { SeverityNumber } from "@opentelemetry/api-logs";
4256
- import { OTLPLogExporter } from "@opentelemetry/exporter-logs-otlp-http";
4257
- import { resourceFromAttributes } from "@opentelemetry/resources";
4258
- import {
4259
- BatchLogRecordProcessor,
4260
- LoggerProvider
4261
- } from "@opentelemetry/sdk-logs";
4262
- import { ATTR_SERVICE_NAME } from "@opentelemetry/semantic-conventions";
4263
- var OtelLogWriter = class {
4264
- loggerProvider;
4265
- logger;
4266
- constructor(config, sessionContext, _debugLogger) {
4267
- const logsPath = config.logsPath ?? "/i/v1/agent-logs";
4268
- const exporter = new OTLPLogExporter({
4269
- url: `${config.posthogHost}${logsPath}`,
4270
- headers: { Authorization: `Bearer ${config.apiKey}` }
4271
- });
4272
- const processor = new BatchLogRecordProcessor(exporter, {
4273
- scheduledDelayMillis: config.flushIntervalMs ?? 500
4274
- });
4275
- this.loggerProvider = new LoggerProvider({
4276
- resource: resourceFromAttributes({
4277
- [ATTR_SERVICE_NAME]: "twig-agent",
4278
- run_id: sessionContext.runId,
4279
- task_id: sessionContext.taskId,
4280
- device_type: sessionContext.deviceType ?? "local"
4281
- }),
4282
- processors: [processor]
4283
- });
4284
- this.logger = this.loggerProvider.getLogger("agent-session");
4285
- }
4286
- /**
4287
- * Emit an agent event to PostHog Logs via OTEL.
4288
- */
4289
- emit(entry) {
4290
- const { notification } = entry;
4291
- const eventType = notification.notification.method;
4292
- this.logger.emit({
4293
- severityNumber: SeverityNumber.INFO,
4294
- severityText: "INFO",
4295
- body: JSON.stringify(notification),
4296
- attributes: {
4297
- event_type: eventType
4298
- }
4299
- });
4300
- }
4301
- async flush() {
4302
- await this.loggerProvider.forceFlush();
4303
- }
4304
- async shutdown() {
4305
- await this.loggerProvider.shutdown();
4306
- }
4307
- };
4308
-
4309
4254
  // src/session-log-writer.ts
4310
4255
  var SessionLogWriter = class {
4311
4256
  posthogAPI;
4312
- otelConfig;
4313
4257
  pendingEntries = /* @__PURE__ */ new Map();
4314
4258
  flushTimeouts = /* @__PURE__ */ new Map();
4315
4259
  sessions = /* @__PURE__ */ new Map();
4316
4260
  logger;
4317
4261
  constructor(options = {}) {
4318
4262
  this.posthogAPI = options.posthogAPI;
4319
- this.otelConfig = options.otelConfig;
4320
4263
  this.logger = options.logger ?? new Logger({ debug: false, prefix: "[SessionLogWriter]" });
4321
4264
  }
4322
4265
  async flushAll() {
@@ -4330,15 +4273,7 @@ var SessionLogWriter = class {
4330
4273
  if (this.sessions.has(sessionId)) {
4331
4274
  return;
4332
4275
  }
4333
- let otelWriter;
4334
- if (this.otelConfig) {
4335
- otelWriter = new OtelLogWriter(
4336
- this.otelConfig,
4337
- context,
4338
- this.logger.child(`OtelWriter:${sessionId}`)
4339
- );
4340
- }
4341
- this.sessions.set(sessionId, { context, otelWriter });
4276
+ this.sessions.set(sessionId, { context });
4342
4277
  }
4343
4278
  isRegistered(sessionId) {
4344
4279
  return this.sessions.has(sessionId);
@@ -4368,9 +4303,6 @@ var SessionLogWriter = class {
4368
4303
  timestamp,
4369
4304
  notification: message
4370
4305
  };
4371
- if (session.otelWriter) {
4372
- session.otelWriter.emit({ notification: entry });
4373
- }
4374
4306
  if (this.posthogAPI) {
4375
4307
  const pending = this.pendingEntries.get(sessionId) ?? [];
4376
4308
  pending.push(entry);
@@ -4388,9 +4320,6 @@ var SessionLogWriter = class {
4388
4320
  const session = this.sessions.get(sessionId);
4389
4321
  if (!session) return;
4390
4322
  this.emitCoalescedMessage(sessionId, session);
4391
- if (session.otelWriter) {
4392
- await session.otelWriter.flush();
4393
- }
4394
4323
  const pending = this.pendingEntries.get(sessionId);
4395
4324
  if (!this.posthogAPI || !pending?.length) return;
4396
4325
  this.pendingEntries.delete(sessionId);
@@ -4442,9 +4371,6 @@ var SessionLogWriter = class {
4442
4371
  }
4443
4372
  }
4444
4373
  };
4445
- if (session.otelWriter) {
4446
- session.otelWriter.emit({ notification: entry });
4447
- }
4448
4374
  if (this.posthogAPI) {
4449
4375
  const pending = this.pendingEntries.get(sessionId) ?? [];
4450
4376
  pending.push(entry);
@@ -9158,9 +9084,9 @@ var GitOperationManagerImpl = class _GitOperationManagerImpl {
9158
9084
  const scopedGit = createGitClient(repoPath, {
9159
9085
  abortSignal: options.signal
9160
9086
  });
9161
- return operation(scopedGit.env({ GIT_OPTIONAL_LOCKS: "0" }));
9087
+ return operation(scopedGit.env({ ...process.env, GIT_OPTIONAL_LOCKS: "0" }));
9162
9088
  }
9163
- const git = state.client.env({ GIT_OPTIONAL_LOCKS: "0" });
9089
+ const git = state.client.env({ ...process.env, GIT_OPTIONAL_LOCKS: "0" });
9164
9090
  return operation(git);
9165
9091
  }
9166
9092
  async executeWrite(repoPath, operation, options) {
@@ -9177,9 +9103,9 @@ var GitOperationManagerImpl = class _GitOperationManagerImpl {
9177
9103
  const scopedGit = createGitClient(repoPath, {
9178
9104
  abortSignal: options.signal
9179
9105
  });
9180
- return await operation(scopedGit);
9106
+ return await operation(scopedGit.env(process.env));
9181
9107
  }
9182
- return await operation(state.client);
9108
+ return await operation(state.client.env(process.env));
9183
9109
  } catch (error) {
9184
9110
  if (options?.signal?.aborted) {
9185
9111
  await removeLock(repoPath).catch(() => {
@@ -10340,17 +10266,13 @@ var AgentServer = class {
10340
10266
  runId: payload.run_id,
10341
10267
  logger: new Logger({ debug: true, prefix: "[TreeTracker]" })
10342
10268
  });
10343
- const _posthogAPI = new PostHogAPIClient({
10269
+ const posthogAPI = new PostHogAPIClient({
10344
10270
  apiUrl: this.config.apiUrl,
10345
10271
  projectId: this.config.projectId,
10346
10272
  getApiKey: () => this.config.apiKey
10347
10273
  });
10348
10274
  const logWriter = new SessionLogWriter({
10349
- otelConfig: {
10350
- posthogHost: this.config.apiUrl,
10351
- apiKey: this.config.apiKey,
10352
- logsPath: "/i/v1/agent-logs"
10353
- },
10275
+ posthogAPI,
10354
10276
  logger: new Logger({ debug: true, prefix: "[SessionLogWriter]" })
10355
10277
  });
10356
10278
  const acpConnection = createAcpConnection({