@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.
package/dist/index.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- export { A as AcpConnection, a as AcpConnectionConfig, b as Agent, c as AgentAdapter, C as CodexProcessOptions, I as InProcessAcpConnection, O as OtelLogConfig, d as OtelLogWriter, S as SessionContext, e as SessionLogWriter, f as SessionLogWriterOptions, g as createAcpConnection } from './agent-kRbaLUfe.js';
1
+ export { A as AcpConnection, a as AcpConnectionConfig, b as Agent, c as AgentAdapter, C as CodexProcessOptions, I as InProcessAcpConnection, O as OtelLogConfig, d as OtelLogWriter, S as SessionContext, e as SessionLogWriter, f as SessionLogWriterOptions, g as createAcpConnection } from './agent-LrKyX9KN.js';
2
2
  import { McpServerConfig } from '@anthropic-ai/claude-agent-sdk';
3
3
  import { L as Logger } from './logger-DDBiMOOD.js';
4
4
  export { a as LoggerConfig } from './logger-DDBiMOOD.js';
package/dist/index.js CHANGED
@@ -1174,7 +1174,7 @@ import { v7 as uuidv7 } from "uuid";
1174
1174
  // package.json
1175
1175
  var package_default = {
1176
1176
  name: "@posthog/agent",
1177
- version: "2.1.5",
1177
+ version: "2.1.13",
1178
1178
  repository: "https://github.com/PostHog/twig",
1179
1179
  description: "TypeScript agent framework wrapping Claude Agent SDK with Git-based task execution for PostHog",
1180
1180
  exports: {
@@ -3107,7 +3107,7 @@ import * as path2 from "path";
3107
3107
  var BRANCH_NAMING_INSTRUCTIONS = `
3108
3108
  # Branch Naming
3109
3109
 
3110
- Before pushing a "workspace-*" branch to origin, rename it to something descriptive based on the work done. Do this automatically without asking the user.
3110
+ 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.
3111
3111
  `;
3112
3112
  function buildSystemPrompt(customPrompt) {
3113
3113
  const defaultPrompt = {
@@ -4277,72 +4277,15 @@ var PostHogAPIClient = class {
4277
4277
  }
4278
4278
  };
4279
4279
 
4280
- // src/otel-log-writer.ts
4281
- import { SeverityNumber } from "@opentelemetry/api-logs";
4282
- import { OTLPLogExporter } from "@opentelemetry/exporter-logs-otlp-http";
4283
- import { resourceFromAttributes } from "@opentelemetry/resources";
4284
- import {
4285
- BatchLogRecordProcessor,
4286
- LoggerProvider
4287
- } from "@opentelemetry/sdk-logs";
4288
- import { ATTR_SERVICE_NAME } from "@opentelemetry/semantic-conventions";
4289
- var OtelLogWriter = class {
4290
- loggerProvider;
4291
- logger;
4292
- constructor(config, sessionContext, _debugLogger) {
4293
- const logsPath = config.logsPath ?? "/i/v1/agent-logs";
4294
- const exporter = new OTLPLogExporter({
4295
- url: `${config.posthogHost}${logsPath}`,
4296
- headers: { Authorization: `Bearer ${config.apiKey}` }
4297
- });
4298
- const processor = new BatchLogRecordProcessor(exporter, {
4299
- scheduledDelayMillis: config.flushIntervalMs ?? 500
4300
- });
4301
- this.loggerProvider = new LoggerProvider({
4302
- resource: resourceFromAttributes({
4303
- [ATTR_SERVICE_NAME]: "twig-agent",
4304
- run_id: sessionContext.runId,
4305
- task_id: sessionContext.taskId,
4306
- device_type: sessionContext.deviceType ?? "local"
4307
- }),
4308
- processors: [processor]
4309
- });
4310
- this.logger = this.loggerProvider.getLogger("agent-session");
4311
- }
4312
- /**
4313
- * Emit an agent event to PostHog Logs via OTEL.
4314
- */
4315
- emit(entry) {
4316
- const { notification } = entry;
4317
- const eventType = notification.notification.method;
4318
- this.logger.emit({
4319
- severityNumber: SeverityNumber.INFO,
4320
- severityText: "INFO",
4321
- body: JSON.stringify(notification),
4322
- attributes: {
4323
- event_type: eventType
4324
- }
4325
- });
4326
- }
4327
- async flush() {
4328
- await this.loggerProvider.forceFlush();
4329
- }
4330
- async shutdown() {
4331
- await this.loggerProvider.shutdown();
4332
- }
4333
- };
4334
-
4335
4280
  // src/session-log-writer.ts
4336
4281
  var SessionLogWriter = class {
4337
4282
  posthogAPI;
4338
- otelConfig;
4339
4283
  pendingEntries = /* @__PURE__ */ new Map();
4340
4284
  flushTimeouts = /* @__PURE__ */ new Map();
4341
4285
  sessions = /* @__PURE__ */ new Map();
4342
4286
  logger;
4343
4287
  constructor(options = {}) {
4344
4288
  this.posthogAPI = options.posthogAPI;
4345
- this.otelConfig = options.otelConfig;
4346
4289
  this.logger = options.logger ?? new Logger({ debug: false, prefix: "[SessionLogWriter]" });
4347
4290
  }
4348
4291
  async flushAll() {
@@ -4356,15 +4299,7 @@ var SessionLogWriter = class {
4356
4299
  if (this.sessions.has(sessionId)) {
4357
4300
  return;
4358
4301
  }
4359
- let otelWriter;
4360
- if (this.otelConfig) {
4361
- otelWriter = new OtelLogWriter(
4362
- this.otelConfig,
4363
- context,
4364
- this.logger.child(`OtelWriter:${sessionId}`)
4365
- );
4366
- }
4367
- this.sessions.set(sessionId, { context, otelWriter });
4302
+ this.sessions.set(sessionId, { context });
4368
4303
  }
4369
4304
  isRegistered(sessionId) {
4370
4305
  return this.sessions.has(sessionId);
@@ -4394,9 +4329,6 @@ var SessionLogWriter = class {
4394
4329
  timestamp,
4395
4330
  notification: message
4396
4331
  };
4397
- if (session.otelWriter) {
4398
- session.otelWriter.emit({ notification: entry });
4399
- }
4400
4332
  if (this.posthogAPI) {
4401
4333
  const pending = this.pendingEntries.get(sessionId) ?? [];
4402
4334
  pending.push(entry);
@@ -4414,9 +4346,6 @@ var SessionLogWriter = class {
4414
4346
  const session = this.sessions.get(sessionId);
4415
4347
  if (!session) return;
4416
4348
  this.emitCoalescedMessage(sessionId, session);
4417
- if (session.otelWriter) {
4418
- await session.otelWriter.flush();
4419
- }
4420
4349
  const pending = this.pendingEntries.get(sessionId);
4421
4350
  if (!this.posthogAPI || !pending?.length) return;
4422
4351
  this.pendingEntries.delete(sessionId);
@@ -4468,9 +4397,6 @@ var SessionLogWriter = class {
4468
4397
  }
4469
4398
  }
4470
4399
  };
4471
- if (session.otelWriter) {
4472
- session.otelWriter.emit({ notification: entry });
4473
- }
4474
4400
  if (this.posthogAPI) {
4475
4401
  const pending = this.pendingEntries.get(sessionId) ?? [];
4476
4402
  pending.push(entry);
@@ -4504,22 +4430,11 @@ var Agent = class {
4504
4430
  if (config.posthog) {
4505
4431
  this.posthogAPI = new PostHogAPIClient(config.posthog);
4506
4432
  }
4507
- if (!config.skipLogPersistence) {
4508
- if (config.otelTransport) {
4509
- this.sessionLogWriter = new SessionLogWriter({
4510
- otelConfig: {
4511
- posthogHost: config.otelTransport.host,
4512
- apiKey: config.otelTransport.apiKey,
4513
- logsPath: config.otelTransport.logsPath
4514
- },
4515
- logger: this.logger.child("SessionLogWriter")
4516
- });
4517
- } else if (config.posthog) {
4518
- this.sessionLogWriter = new SessionLogWriter({
4519
- posthogAPI: this.posthogAPI,
4520
- logger: this.logger.child("SessionLogWriter")
4521
- });
4522
- }
4433
+ if (config.posthog && !config.skipLogPersistence) {
4434
+ this.sessionLogWriter = new SessionLogWriter({
4435
+ posthogAPI: this.posthogAPI,
4436
+ logger: this.logger.child("SessionLogWriter")
4437
+ });
4523
4438
  }
4524
4439
  }
4525
4440
  _configureLlmGateway(_adapter) {
@@ -4617,6 +4532,61 @@ var Agent = class {
4617
4532
  }
4618
4533
  };
4619
4534
 
4535
+ // src/otel-log-writer.ts
4536
+ import { SeverityNumber } from "@opentelemetry/api-logs";
4537
+ import { OTLPLogExporter } from "@opentelemetry/exporter-logs-otlp-http";
4538
+ import { resourceFromAttributes } from "@opentelemetry/resources";
4539
+ import {
4540
+ BatchLogRecordProcessor,
4541
+ LoggerProvider
4542
+ } from "@opentelemetry/sdk-logs";
4543
+ import { ATTR_SERVICE_NAME } from "@opentelemetry/semantic-conventions";
4544
+ var OtelLogWriter = class {
4545
+ loggerProvider;
4546
+ logger;
4547
+ constructor(config, sessionContext, _debugLogger) {
4548
+ const logsPath = config.logsPath ?? "/i/v1/agent-logs";
4549
+ const exporter = new OTLPLogExporter({
4550
+ url: `${config.posthogHost}${logsPath}`,
4551
+ headers: { Authorization: `Bearer ${config.apiKey}` }
4552
+ });
4553
+ const processor = new BatchLogRecordProcessor(exporter, {
4554
+ scheduledDelayMillis: config.flushIntervalMs ?? 500
4555
+ });
4556
+ this.loggerProvider = new LoggerProvider({
4557
+ resource: resourceFromAttributes({
4558
+ [ATTR_SERVICE_NAME]: "twig-agent",
4559
+ run_id: sessionContext.runId,
4560
+ task_id: sessionContext.taskId,
4561
+ device_type: sessionContext.deviceType ?? "local"
4562
+ }),
4563
+ processors: [processor]
4564
+ });
4565
+ this.logger = this.loggerProvider.getLogger("agent-session");
4566
+ }
4567
+ /**
4568
+ * Emit an agent event to PostHog Logs via OTEL.
4569
+ */
4570
+ emit(entry) {
4571
+ const { notification } = entry;
4572
+ const eventType = notification.notification.method;
4573
+ this.logger.emit({
4574
+ severityNumber: SeverityNumber.INFO,
4575
+ severityText: "INFO",
4576
+ body: JSON.stringify(notification),
4577
+ attributes: {
4578
+ event_type: eventType
4579
+ }
4580
+ });
4581
+ }
4582
+ async flush() {
4583
+ await this.loggerProvider.forceFlush();
4584
+ }
4585
+ async shutdown() {
4586
+ await this.loggerProvider.shutdown();
4587
+ }
4588
+ };
4589
+
4620
4590
  // ../shared/dist/index.js
4621
4591
  var consoleLogger = {
4622
4592
  info: (_message, _data) => {
@@ -9442,9 +9412,9 @@ var GitOperationManagerImpl = class _GitOperationManagerImpl {
9442
9412
  const scopedGit = createGitClient(repoPath, {
9443
9413
  abortSignal: options.signal
9444
9414
  });
9445
- return operation(scopedGit.env({ GIT_OPTIONAL_LOCKS: "0" }));
9415
+ return operation(scopedGit.env({ ...process.env, GIT_OPTIONAL_LOCKS: "0" }));
9446
9416
  }
9447
- const git = state.client.env({ GIT_OPTIONAL_LOCKS: "0" });
9417
+ const git = state.client.env({ ...process.env, GIT_OPTIONAL_LOCKS: "0" });
9448
9418
  return operation(git);
9449
9419
  }
9450
9420
  async executeWrite(repoPath, operation, options) {
@@ -9461,9 +9431,9 @@ var GitOperationManagerImpl = class _GitOperationManagerImpl {
9461
9431
  const scopedGit = createGitClient(repoPath, {
9462
9432
  abortSignal: options.signal
9463
9433
  });
9464
- return await operation(scopedGit);
9434
+ return await operation(scopedGit.env(process.env));
9465
9435
  }
9466
- return await operation(state.client);
9436
+ return await operation(state.client.env(process.env));
9467
9437
  } catch (error) {
9468
9438
  if (options?.signal?.aborted) {
9469
9439
  await removeLock(repoPath).catch(() => {