@posthog/agent 2.3.74 → 2.3.80

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.
@@ -904,7 +904,7 @@ var import_hono = require("hono");
904
904
  // package.json
905
905
  var package_default = {
906
906
  name: "@posthog/agent",
907
- version: "2.3.74",
907
+ version: "2.3.80",
908
908
  repository: "https://github.com/PostHog/code",
909
909
  description: "TypeScript agent framework wrapping Claude Agent SDK with Git-based task execution for PostHog",
910
910
  exports: {
@@ -3376,8 +3376,37 @@ function handlePlanFileException(context) {
3376
3376
  updatedInput: toolInput
3377
3377
  };
3378
3378
  }
3379
+ function extractDomainFromUrl(url) {
3380
+ try {
3381
+ return new URL(url).hostname;
3382
+ } catch {
3383
+ return null;
3384
+ }
3385
+ }
3386
+ function isDomainAllowed(hostname, allowedDomains) {
3387
+ return allowedDomains.some((pattern) => {
3388
+ if (pattern.startsWith("*.")) {
3389
+ const suffix = pattern.slice(1);
3390
+ return hostname === pattern.slice(2) || hostname.endsWith(suffix);
3391
+ }
3392
+ return hostname === pattern;
3393
+ });
3394
+ }
3379
3395
  async function canUseTool(context) {
3380
- const { toolName, toolInput, session } = context;
3396
+ const { toolName, toolInput, session, allowedDomains } = context;
3397
+ if (allowedDomains && allowedDomains.length > 0) {
3398
+ if (toolName === "WebFetch" || toolName === "WebSearch") {
3399
+ const url = toolInput.url;
3400
+ if (url) {
3401
+ const hostname = extractDomainFromUrl(url);
3402
+ if (hostname && !isDomainAllowed(hostname, allowedDomains)) {
3403
+ const message = `Domain "${hostname}" is not in the allowed list: ${allowedDomains.join(", ")}`;
3404
+ await emitToolDenial(context, message);
3405
+ return { behavior: "deny", message, interrupt: false };
3406
+ }
3407
+ }
3408
+ }
3409
+ }
3381
3410
  if (isToolAllowedForMode(toolName, session.permissionMode)) {
3382
3411
  return {
3383
3412
  behavior: "allow",
@@ -4545,7 +4574,7 @@ var ClaudeAcpAgent = class extends BaseAcpAgent {
4545
4574
  cwd,
4546
4575
  mcpServers,
4547
4576
  permissionMode,
4548
- canUseTool: this.createCanUseTool(sessionId),
4577
+ canUseTool: this.createCanUseTool(sessionId, meta?.allowedDomains),
4549
4578
  logger: this.logger,
4550
4579
  systemPrompt,
4551
4580
  userProvidedOptions: meta?.claudeCode?.options,
@@ -4675,7 +4704,7 @@ var ClaudeAcpAgent = class extends BaseAcpAgent {
4675
4704
  );
4676
4705
  return { sessionId, modes, models, configOptions };
4677
4706
  }
4678
- createCanUseTool(sessionId) {
4707
+ createCanUseTool(sessionId, allowedDomains) {
4679
4708
  return async (toolName, toolInput, { suggestions, toolUseID, signal }) => canUseTool({
4680
4709
  session: this.session,
4681
4710
  toolName,
@@ -4687,7 +4716,8 @@ var ClaudeAcpAgent = class extends BaseAcpAgent {
4687
4716
  sessionId,
4688
4717
  fileContentCache: this.fileContentCache,
4689
4718
  logger: this.logger,
4690
- updateConfigOption: (configId, value) => this.updateConfigOption(configId, value)
4719
+ updateConfigOption: (configId, value) => this.updateConfigOption(configId, value),
4720
+ allowedDomains
4691
4721
  });
4692
4722
  }
4693
4723
  createOnModeChange() {
@@ -12221,6 +12251,7 @@ You MUST NOT create a new branch, close the existing PR, or create a new PR.`
12221
12251
  sessionId: payload.run_id,
12222
12252
  taskRunId: payload.run_id,
12223
12253
  systemPrompt: this.buildSessionSystemPrompt(prUrl),
12254
+ allowedDomains: this.config.allowedDomains,
12224
12255
  ...this.config.claudeCode?.plugins?.length && {
12225
12256
  claudeCode: {
12226
12257
  options: {
@@ -12909,6 +12940,9 @@ program.name("agent-server").description("PostHog cloud agent server - runs in s
12909
12940
  ).option("--baseBranch <branch>", "Base branch for PR creation").option(
12910
12941
  "--claudeCodeConfig <json>",
12911
12942
  "Claude Code config as JSON (systemPrompt, systemPromptAppend, plugins)"
12943
+ ).option(
12944
+ "--allowedDomains <domains>",
12945
+ "Comma-separated list of domains allowed for web tools (WebFetch, WebSearch)"
12912
12946
  ).action(async (options) => {
12913
12947
  const envResult = envSchema.safeParse(process.env);
12914
12948
  if (!envResult.success) {
@@ -12929,6 +12963,7 @@ ${errors}`);
12929
12963
  claudeCodeConfigSchema,
12930
12964
  "--claudeCodeConfig"
12931
12965
  );
12966
+ const allowedDomains = options.allowedDomains ? options.allowedDomains.split(",").map((d) => d.trim()).filter(Boolean) : void 0;
12932
12967
  const server = new AgentServer({
12933
12968
  port: parseInt(options.port, 10),
12934
12969
  jwtPublicKey: env.JWT_PUBLIC_KEY,
@@ -12941,7 +12976,8 @@ ${errors}`);
12941
12976
  runId: options.runId,
12942
12977
  mcpServers,
12943
12978
  baseBranch: options.baseBranch,
12944
- claudeCode
12979
+ claudeCode,
12980
+ allowedDomains
12945
12981
  });
12946
12982
  process.on("SIGINT", async () => {
12947
12983
  await server.stop();