@posthog/agent 2.3.504 → 2.3.508
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/agent.js +154 -10
- package/dist/agent.js.map +1 -1
- package/dist/posthog-api.js +1 -1
- package/dist/posthog-api.js.map +1 -1
- package/dist/server/agent-server.js +166 -12
- package/dist/server/agent-server.js.map +1 -1
- package/dist/server/bin.cjs +166 -12
- package/dist/server/bin.cjs.map +1 -1
- package/package.json +3 -3
- package/src/adapters/claude/hooks.test.ts +125 -1
- package/src/adapters/claude/hooks.ts +24 -0
- package/src/adapters/claude/permissions/permission-handlers.test.ts +152 -0
- package/src/adapters/claude/permissions/permission-handlers.ts +109 -15
- package/src/adapters/claude/permissions/posthog-exec-gate.test.ts +84 -0
- package/src/adapters/claude/permissions/posthog-exec-gate.ts +30 -0
- package/src/adapters/claude/session/settings.test.ts +50 -0
- package/src/adapters/claude/session/settings.ts +48 -0
- package/src/server/agent-server.test.ts +43 -0
- package/src/server/agent-server.ts +16 -2
package/dist/posthog-api.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
// package.json
|
|
2
2
|
var package_default = {
|
|
3
3
|
name: "@posthog/agent",
|
|
4
|
-
version: "2.3.
|
|
4
|
+
version: "2.3.508",
|
|
5
5
|
repository: "https://github.com/PostHog/code",
|
|
6
6
|
description: "TypeScript agent framework wrapping Claude Agent SDK with Git-based task execution for PostHog",
|
|
7
7
|
exports: {
|
package/dist/posthog-api.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../package.json","../src/utils/gateway.ts","../src/posthog-api.ts"],"sourcesContent":["{\n \"name\": \"@posthog/agent\",\n \"version\": \"2.3.504\",\n \"repository\": \"https://github.com/PostHog/code\",\n \"description\": \"TypeScript agent framework wrapping Claude Agent SDK with Git-based task execution for PostHog\",\n \"exports\": {\n \".\": {\n \"types\": \"./dist/index.d.ts\",\n \"import\": \"./dist/index.js\"\n },\n \"./agent\": {\n \"types\": \"./dist/agent.d.ts\",\n \"import\": \"./dist/agent.js\"\n },\n \"./gateway-models\": {\n \"types\": \"./dist/gateway-models.d.ts\",\n \"import\": \"./dist/gateway-models.js\"\n },\n \"./posthog-api\": {\n \"types\": \"./dist/posthog-api.d.ts\",\n \"import\": \"./dist/posthog-api.js\"\n },\n \"./types\": {\n \"types\": \"./dist/types.d.ts\",\n \"import\": \"./dist/types.js\"\n },\n \"./adapters/claude/questions/utils\": {\n \"types\": \"./dist/adapters/claude/questions/utils.d.ts\",\n \"import\": \"./dist/adapters/claude/questions/utils.js\"\n },\n \"./adapters/claude/permissions/permission-options\": {\n \"types\": \"./dist/adapters/claude/permissions/permission-options.d.ts\",\n \"import\": \"./dist/adapters/claude/permissions/permission-options.js\"\n },\n \"./adapters/claude/tools\": {\n \"types\": \"./dist/adapters/claude/tools.d.ts\",\n \"import\": \"./dist/adapters/claude/tools.js\"\n },\n \"./adapters/claude/conversion/tool-use-to-acp\": {\n \"types\": \"./dist/adapters/claude/conversion/tool-use-to-acp.d.ts\",\n \"import\": \"./dist/adapters/claude/conversion/tool-use-to-acp.js\"\n },\n \"./adapters/claude/session/jsonl-hydration\": {\n \"types\": \"./dist/adapters/claude/session/jsonl-hydration.d.ts\",\n \"import\": \"./dist/adapters/claude/session/jsonl-hydration.js\"\n },\n \"./adapters/claude/session/models\": {\n \"types\": \"./dist/adapters/claude/session/models.d.ts\",\n \"import\": \"./dist/adapters/claude/session/models.js\"\n },\n \"./adapters/reasoning-effort\": {\n \"types\": \"./dist/adapters/reasoning-effort.d.ts\",\n \"import\": \"./dist/adapters/reasoning-effort.js\"\n },\n \"./adapters/claude/mcp/tool-metadata\": {\n \"types\": \"./dist/adapters/claude/mcp/tool-metadata.d.ts\",\n \"import\": \"./dist/adapters/claude/mcp/tool-metadata.js\"\n },\n \"./execution-mode\": {\n \"types\": \"./dist/execution-mode.d.ts\",\n \"import\": \"./dist/execution-mode.js\"\n },\n \"./resume\": {\n \"types\": \"./dist/resume.d.ts\",\n \"import\": \"./dist/resume.js\"\n },\n \"./handoff-checkpoint\": {\n \"types\": \"./dist/handoff-checkpoint.d.ts\",\n \"import\": \"./dist/handoff-checkpoint.js\"\n },\n \"./server\": {\n \"types\": \"./dist/server/agent-server.d.ts\",\n \"import\": \"./dist/server/agent-server.js\"\n },\n \"./server/schemas\": {\n \"types\": \"./dist/server/schemas.d.ts\",\n \"import\": \"./dist/server/schemas.js\"\n }\n },\n \"bin\": {\n \"agent-server\": \"./dist/server/bin.cjs\"\n },\n \"type\": \"module\",\n \"keywords\": [\n \"posthog\",\n \"claude\",\n \"agent\",\n \"ai\",\n \"git\",\n \"typescript\"\n ],\n \"author\": \"PostHog\",\n \"license\": \"SEE LICENSE IN LICENSE\",\n \"scripts\": {\n \"build\": \"node ../../scripts/rimraf.mjs dist && tsup\",\n \"dev\": \"tsup --watch\",\n \"test\": \"vitest run\",\n \"test:watch\": \"vitest\",\n \"typecheck\": \"pnpm exec tsc --noEmit\",\n \"prepublishOnly\": \"pnpm run build\",\n \"clean\": \"node ../../scripts/rimraf.mjs dist .turbo\"\n },\n \"engines\": {\n \"node\": \">=20.0.0\"\n },\n \"devDependencies\": {\n \"@posthog/shared\": \"workspace:*\",\n \"@posthog/git\": \"workspace:*\",\n \"@posthog/enricher\": \"workspace:*\",\n \"@types/bun\": \"latest\",\n \"@types/tar\": \"^6.1.13\",\n \"msw\": \"^2.12.7\",\n \"tsup\": \"^8.5.1\",\n \"tsx\": \"^4.20.6\",\n \"typescript\": \"^5.5.0\",\n \"vitest\": \"^2.1.8\"\n },\n \"dependencies\": {\n \"@agentclientprotocol/sdk\": \"0.19.0\",\n \"ajv\": \"^8.17.1\",\n \"@anthropic-ai/claude-agent-sdk\": \"0.2.112\",\n \"@anthropic-ai/sdk\": \"0.89.0\",\n \"@hono/node-server\": \"^1.19.9\",\n \"@opentelemetry/api-logs\": \"^0.208.0\",\n \"@opentelemetry/exporter-logs-otlp-http\": \"^0.208.0\",\n \"@opentelemetry/resources\": \"^2.0.0\",\n \"@opentelemetry/sdk-logs\": \"^0.208.0\",\n \"@opentelemetry/semantic-conventions\": \"^1.28.0\",\n \"@types/jsonwebtoken\": \"^9.0.10\",\n \"commander\": \"^14.0.2\",\n \"hono\": \"^4.11.7\",\n \"jsonwebtoken\": \"^9.0.2\",\n \"minimatch\": \"^10.0.3\",\n \"tar\": \"^7.5.0\",\n \"uuid\": \"13.0.0\",\n \"yoga-wasm-web\": \"^0.3.3\",\n \"zod\": \"^4.2.0\"\n },\n \"files\": [\n \"dist/**/*\",\n \"src/**/*\",\n \"README.md\",\n \"CLAUDE.md\"\n ],\n \"publishConfig\": {\n \"access\": \"public\"\n }\n}\n","export type GatewayProduct = \"posthog_code\" | \"background_agents\";\n\nfunction getGatewayBaseUrl(posthogHost: string): string {\n const url = new URL(posthogHost);\n const hostname = url.hostname;\n\n if (hostname === \"localhost\" || hostname === \"127.0.0.1\") {\n return `${url.protocol}//localhost:3308`;\n }\n\n if (hostname === \"host.docker.internal\") {\n return `${url.protocol}//host.docker.internal:3308`;\n }\n\n const region = hostname.match(/^(us|eu)\\.posthog\\.com$/)?.[1] ?? \"us\";\n return `https://gateway.${region}.posthog.com`;\n}\n\nexport function getLlmGatewayUrl(\n posthogHost: string,\n product: GatewayProduct = \"posthog_code\",\n): string {\n return `${getGatewayBaseUrl(posthogHost)}/${product}`;\n}\n\nexport function getGatewayUsageUrl(\n posthogHost: string,\n product: GatewayProduct = \"posthog_code\",\n): string {\n return `${getGatewayBaseUrl(posthogHost)}/v1/usage/${product}`;\n}\n\nexport function getGatewayInvalidatePlanCacheUrl(\n posthogHost: string,\n product: GatewayProduct = \"posthog_code\",\n): string {\n return `${getGatewayBaseUrl(posthogHost)}/v1/usage/${product}/invalidate-plan-cache`;\n}\n","import packageJson from \"../package.json\" with { type: \"json\" };\nimport type {\n ArtifactType,\n PostHogAPIConfig,\n StoredEntry,\n Task,\n TaskRun,\n TaskRunArtifact,\n} from \"./types\";\nimport {\n getGatewayInvalidatePlanCacheUrl,\n getGatewayUsageUrl,\n getLlmGatewayUrl,\n} from \"./utils/gateway\";\n\nexport {\n getGatewayInvalidatePlanCacheUrl,\n getGatewayUsageUrl,\n getLlmGatewayUrl,\n};\n\nconst DEFAULT_USER_AGENT = `posthog/agent.hog.dev; version: ${packageJson.version}`;\n\nexport interface TaskArtifactUploadPayload {\n name: string;\n type: ArtifactType;\n content: string;\n content_type?: string;\n}\n\nexport type TaskRunUpdate = Partial<\n Pick<\n TaskRun,\n | \"status\"\n | \"branch\"\n | \"stage\"\n | \"error_message\"\n | \"output\"\n | \"state\"\n | \"environment\"\n >\n> & {\n state_remove_keys?: string[];\n};\n\nexport class PostHogAPIClient {\n private config: PostHogAPIConfig;\n\n constructor(config: PostHogAPIConfig) {\n this.config = config;\n }\n\n private get baseUrl(): string {\n const host = this.config.apiUrl.endsWith(\"/\")\n ? this.config.apiUrl.slice(0, -1)\n : this.config.apiUrl;\n return host;\n }\n\n private isAuthFailure(status: number): boolean {\n return status === 401 || status === 403;\n }\n\n private async resolveApiKey(forceRefresh = false): Promise<string> {\n if (forceRefresh && this.config.refreshApiKey) {\n return this.config.refreshApiKey();\n }\n\n return this.config.getApiKey();\n }\n\n private async buildHeaders(\n options: RequestInit,\n forceRefresh = false,\n ): Promise<Headers> {\n const headers = new Headers(options.headers);\n headers.set(\n \"Authorization\",\n `Bearer ${await this.resolveApiKey(forceRefresh)}`,\n );\n headers.set(\"Content-Type\", \"application/json\");\n headers.set(\"User-Agent\", this.config.userAgent ?? DEFAULT_USER_AGENT);\n return headers;\n }\n\n private async performRequest(\n endpoint: string,\n options: RequestInit,\n forceRefresh = false,\n ): Promise<Response> {\n const url = `${this.baseUrl}${endpoint}`;\n\n return fetch(url, {\n ...options,\n headers: await this.buildHeaders(options, forceRefresh),\n });\n }\n\n private async performRequestWithRetry(\n endpoint: string,\n options: RequestInit = {},\n ): Promise<Response> {\n let response = await this.performRequest(endpoint, options);\n\n if (!response.ok && this.isAuthFailure(response.status)) {\n response = await this.performRequest(endpoint, options, true);\n }\n\n return response;\n }\n\n private async apiRequest<T>(\n endpoint: string,\n options: RequestInit = {},\n ): Promise<T> {\n const response = await this.performRequestWithRetry(endpoint, options);\n\n if (!response.ok) {\n let errorMessage: string;\n try {\n const errorResponse = await response.json();\n errorMessage = `Failed request: [${response.status}] ${JSON.stringify(errorResponse)}`;\n } catch {\n errorMessage = `Failed request: [${response.status}] ${response.statusText}`;\n }\n throw new Error(errorMessage);\n }\n\n return response.json();\n }\n\n private getTeamId(): number {\n return this.config.projectId;\n }\n\n async getApiKey(forceRefresh = false): Promise<string> {\n return this.resolveApiKey(forceRefresh);\n }\n\n getLlmGatewayUrl(): string {\n return getLlmGatewayUrl(this.baseUrl);\n }\n\n async getTask(taskId: string): Promise<Task> {\n const teamId = this.getTeamId();\n return this.apiRequest<Task>(`/api/projects/${teamId}/tasks/${taskId}/`);\n }\n\n async getTaskRun(taskId: string, runId: string): Promise<TaskRun> {\n const teamId = this.getTeamId();\n return this.apiRequest<TaskRun>(\n `/api/projects/${teamId}/tasks/${taskId}/runs/${runId}/`,\n );\n }\n\n async resumeRunInCloud(taskId: string, runId: string): Promise<TaskRun> {\n const teamId = this.getTeamId();\n return this.apiRequest<TaskRun>(\n `/api/projects/${teamId}/tasks/${taskId}/runs/${runId}/resume_in_cloud/`,\n { method: \"POST\" },\n );\n }\n\n async updateTaskRun(\n taskId: string,\n runId: string,\n payload: TaskRunUpdate,\n ): Promise<TaskRun> {\n const teamId = this.getTeamId();\n return this.apiRequest<TaskRun>(\n `/api/projects/${teamId}/tasks/${taskId}/runs/${runId}/`,\n {\n method: \"PATCH\",\n body: JSON.stringify(payload),\n },\n );\n }\n\n async setTaskRunOutput(\n taskId: string,\n runId: string,\n output: Record<string, unknown>,\n ): Promise<TaskRun> {\n return this.apiRequest(\n `/api/projects/${this.getTeamId()}/tasks/${taskId}/runs/${runId}/set_output/`,\n {\n method: \"PATCH\",\n body: JSON.stringify(output),\n },\n );\n }\n\n async appendTaskRunLog(\n taskId: string,\n runId: string,\n entries: StoredEntry[],\n ): Promise<TaskRun> {\n const teamId = this.getTeamId();\n return this.apiRequest<TaskRun>(\n `/api/projects/${teamId}/tasks/${taskId}/runs/${runId}/append_log/`,\n {\n method: \"POST\",\n body: JSON.stringify({ entries }),\n },\n );\n }\n\n async relayMessage(\n taskId: string,\n runId: string,\n text: string,\n ): Promise<void> {\n const teamId = this.getTeamId();\n await this.apiRequest<{ status: string }>(\n `/api/projects/${teamId}/tasks/${taskId}/runs/${runId}/relay_message/`,\n {\n method: \"POST\",\n body: JSON.stringify({ text }),\n },\n );\n }\n\n async uploadTaskArtifacts(\n taskId: string,\n runId: string,\n artifacts: TaskArtifactUploadPayload[],\n ): Promise<TaskRunArtifact[]> {\n if (!artifacts.length) {\n return [];\n }\n\n const teamId = this.getTeamId();\n const response = await this.apiRequest<{ artifacts: TaskRunArtifact[] }>(\n `/api/projects/${teamId}/tasks/${taskId}/runs/${runId}/artifacts/`,\n {\n method: \"POST\",\n body: JSON.stringify({ artifacts }),\n },\n );\n\n const manifest = response.artifacts ?? [];\n\n // The backend returns the full run artifact manifest after each upload.\n // Callers want the artifacts corresponding to this upload request only.\n return manifest.slice(-artifacts.length);\n }\n\n /**\n * Download artifact content by storage path\n * Streams the file through the PostHog backend so the sandbox does not need\n * direct access to object storage.\n */\n async downloadArtifact(\n taskId: string,\n runId: string,\n storagePath: string,\n ): Promise<ArrayBuffer | null> {\n const teamId = this.getTeamId();\n\n try {\n const response = await this.performRequestWithRetry(\n `/api/projects/${teamId}/tasks/${taskId}/runs/${runId}/artifacts/download/`,\n {\n method: \"POST\",\n body: JSON.stringify({ storage_path: storagePath }),\n },\n );\n if (!response.ok) {\n throw new Error(`Failed to download artifact: ${response.status}`);\n }\n return response.arrayBuffer();\n } catch {\n return null;\n }\n }\n\n /**\n * Fetch logs for a task run via the logs API endpoint\n * @param taskRun - The task run to fetch logs for\n * @returns Array of stored entries, or empty array if no logs available\n */\n async fetchTaskRunLogs(taskRun: TaskRun): Promise<StoredEntry[]> {\n const teamId = this.getTeamId();\n const endpoint = `/api/projects/${teamId}/tasks/${taskRun.task}/runs/${taskRun.id}/logs`;\n\n try {\n const response = await this.performRequestWithRetry(endpoint);\n\n if (!response.ok) {\n if (response.status === 404) {\n return [];\n }\n throw new Error(\n `Failed to fetch logs: ${response.status} ${response.statusText}`,\n );\n }\n\n const content = await response.text();\n\n if (!content.trim()) {\n return [];\n }\n\n // Parse newline-delimited JSON\n return content\n .trim()\n .split(\"\\n\")\n .map((line) => JSON.parse(line) as StoredEntry);\n } catch (error) {\n throw new Error(\n `Failed to fetch task run logs: ${error instanceof Error ? error.message : String(error)}`,\n );\n }\n }\n}\n"],"mappings":";AAAA;AAAA,EACE,MAAQ;AAAA,EACR,SAAW;AAAA,EACX,YAAc;AAAA,EACd,aAAe;AAAA,EACf,SAAW;AAAA,IACT,KAAK;AAAA,MACH,OAAS;AAAA,MACT,QAAU;AAAA,IACZ;AAAA,IACA,WAAW;AAAA,MACT,OAAS;AAAA,MACT,QAAU;AAAA,IACZ;AAAA,IACA,oBAAoB;AAAA,MAClB,OAAS;AAAA,MACT,QAAU;AAAA,IACZ;AAAA,IACA,iBAAiB;AAAA,MACf,OAAS;AAAA,MACT,QAAU;AAAA,IACZ;AAAA,IACA,WAAW;AAAA,MACT,OAAS;AAAA,MACT,QAAU;AAAA,IACZ;AAAA,IACA,qCAAqC;AAAA,MACnC,OAAS;AAAA,MACT,QAAU;AAAA,IACZ;AAAA,IACA,oDAAoD;AAAA,MAClD,OAAS;AAAA,MACT,QAAU;AAAA,IACZ;AAAA,IACA,2BAA2B;AAAA,MACzB,OAAS;AAAA,MACT,QAAU;AAAA,IACZ;AAAA,IACA,gDAAgD;AAAA,MAC9C,OAAS;AAAA,MACT,QAAU;AAAA,IACZ;AAAA,IACA,6CAA6C;AAAA,MAC3C,OAAS;AAAA,MACT,QAAU;AAAA,IACZ;AAAA,IACA,oCAAo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AAM,UAAU,MAAM,SAAS,KAAK;AAAA,QACrD;AAAA,UACE,QAAQ;AAAA,UACR,MAAM,KAAK,UAAU,EAAE,cAAc,YAAY,CAAC;AAAA,QACpD;AAAA,MACF;AACA,UAAI,CAAC,SAAS,IAAI;AAChB,cAAM,IAAI,MAAM,gCAAgC,SAAS,MAAM,EAAE;AAAA,MACnE;AACA,aAAO,SAAS,YAAY;AAAA,IAC9B,QAAQ;AACN,aAAO;AAAA,IACT;AAAA,EACF;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAOA,MAAM,iBAAiB,SAA0C;AAC/D,UAAM,SAAS,KAAK,UAAU;AAC9B,UAAM,WAAW,iBAAiB,MAAM,UAAU,QAAQ,IAAI,SAAS,QAAQ,EAAE;AAEjF,QAAI;AACF,YAAM,WAAW,MAAM,KAAK,wBAAwB,QAAQ;AAE5D,UAAI,CAAC,SAAS,IAAI;AAChB,YAAI,SAAS,WAAW,KAAK;AAC3B,iBAAO,CAAC;AAAA,QACV;AACA,cAAM,IAAI;AAAA,UACR,yBAAyB,SAAS,MAAM,IAAI,SAAS,UAAU;AAAA,QACjE;AAAA,MACF;AAEA,YAAM,UAAU,MAAM,SAAS,KAAK;AAEpC,UAAI,CAAC,QAAQ,KAAK,GAAG;AACnB,eAAO,CAAC;AAAA,MACV;AAGA,aAAO,QACJ,KAAK,EACL,MAAM,IAAI,EACV,IAAI,CAAC,SAAS,KAAK,MAAM,IAAI,CAAgB;AAAA,IAClD,SAAS,OAAO;AACd,YAAM,IAAI;AAAA,QACR,kCAAkC,iBAAiB,QAAQ,MAAM,UAAU,OAAO,KAAK,CAAC;AAAA,MAC1F;AAAA,IACF;AAAA,EACF;AACF;","names":[]}
|
|
1
|
+
{"version":3,"sources":["../package.json","../src/utils/gateway.ts","../src/posthog-api.ts"],"sourcesContent":["{\n \"name\": \"@posthog/agent\",\n \"version\": \"2.3.508\",\n \"repository\": \"https://github.com/PostHog/code\",\n \"description\": \"TypeScript agent framework wrapping Claude Agent SDK with Git-based task execution for PostHog\",\n \"exports\": {\n \".\": {\n \"types\": \"./dist/index.d.ts\",\n \"import\": \"./dist/index.js\"\n },\n \"./agent\": {\n \"types\": \"./dist/agent.d.ts\",\n \"import\": \"./dist/agent.js\"\n },\n \"./gateway-models\": {\n \"types\": \"./dist/gateway-models.d.ts\",\n \"import\": \"./dist/gateway-models.js\"\n },\n \"./posthog-api\": {\n \"types\": \"./dist/posthog-api.d.ts\",\n \"import\": \"./dist/posthog-api.js\"\n },\n \"./types\": {\n \"types\": \"./dist/types.d.ts\",\n \"import\": \"./dist/types.js\"\n },\n \"./adapters/claude/questions/utils\": {\n \"types\": \"./dist/adapters/claude/questions/utils.d.ts\",\n \"import\": \"./dist/adapters/claude/questions/utils.js\"\n },\n \"./adapters/claude/permissions/permission-options\": {\n \"types\": \"./dist/adapters/claude/permissions/permission-options.d.ts\",\n \"import\": \"./dist/adapters/claude/permissions/permission-options.js\"\n },\n \"./adapters/claude/tools\": {\n \"types\": \"./dist/adapters/claude/tools.d.ts\",\n \"import\": \"./dist/adapters/claude/tools.js\"\n },\n \"./adapters/claude/conversion/tool-use-to-acp\": {\n \"types\": \"./dist/adapters/claude/conversion/tool-use-to-acp.d.ts\",\n \"import\": \"./dist/adapters/claude/conversion/tool-use-to-acp.js\"\n },\n \"./adapters/claude/session/jsonl-hydration\": {\n \"types\": \"./dist/adapters/claude/session/jsonl-hydration.d.ts\",\n \"import\": \"./dist/adapters/claude/session/jsonl-hydration.js\"\n },\n \"./adapters/claude/session/models\": {\n \"types\": \"./dist/adapters/claude/session/models.d.ts\",\n \"import\": \"./dist/adapters/claude/session/models.js\"\n },\n \"./adapters/reasoning-effort\": {\n \"types\": \"./dist/adapters/reasoning-effort.d.ts\",\n \"import\": \"./dist/adapters/reasoning-effort.js\"\n },\n \"./adapters/claude/mcp/tool-metadata\": {\n \"types\": \"./dist/adapters/claude/mcp/tool-metadata.d.ts\",\n \"import\": \"./dist/adapters/claude/mcp/tool-metadata.js\"\n },\n \"./execution-mode\": {\n \"types\": \"./dist/execution-mode.d.ts\",\n \"import\": \"./dist/execution-mode.js\"\n },\n \"./resume\": {\n \"types\": \"./dist/resume.d.ts\",\n \"import\": \"./dist/resume.js\"\n },\n \"./handoff-checkpoint\": {\n \"types\": \"./dist/handoff-checkpoint.d.ts\",\n \"import\": \"./dist/handoff-checkpoint.js\"\n },\n \"./server\": {\n \"types\": \"./dist/server/agent-server.d.ts\",\n \"import\": \"./dist/server/agent-server.js\"\n },\n \"./server/schemas\": {\n \"types\": \"./dist/server/schemas.d.ts\",\n \"import\": \"./dist/server/schemas.js\"\n }\n },\n \"bin\": {\n \"agent-server\": \"./dist/server/bin.cjs\"\n },\n \"type\": \"module\",\n \"keywords\": [\n \"posthog\",\n \"claude\",\n \"agent\",\n \"ai\",\n \"git\",\n \"typescript\"\n ],\n \"author\": \"PostHog\",\n \"license\": \"SEE LICENSE IN LICENSE\",\n \"scripts\": {\n \"build\": \"node ../../scripts/rimraf.mjs dist && tsup\",\n \"dev\": \"tsup --watch\",\n \"test\": \"vitest run\",\n \"test:watch\": \"vitest\",\n \"typecheck\": \"pnpm exec tsc --noEmit\",\n \"prepublishOnly\": \"pnpm run build\",\n \"clean\": \"node ../../scripts/rimraf.mjs dist .turbo\"\n },\n \"engines\": {\n \"node\": \">=20.0.0\"\n },\n \"devDependencies\": {\n \"@posthog/shared\": \"workspace:*\",\n \"@posthog/git\": \"workspace:*\",\n \"@posthog/enricher\": \"workspace:*\",\n \"@types/bun\": \"latest\",\n \"@types/tar\": \"^6.1.13\",\n \"msw\": \"^2.12.7\",\n \"tsup\": \"^8.5.1\",\n \"tsx\": \"^4.20.6\",\n \"typescript\": \"^5.5.0\",\n \"vitest\": \"^2.1.8\"\n },\n \"dependencies\": {\n \"@agentclientprotocol/sdk\": \"0.19.0\",\n \"ajv\": \"^8.17.1\",\n \"@anthropic-ai/claude-agent-sdk\": \"0.2.112\",\n \"@anthropic-ai/sdk\": \"0.89.0\",\n \"@hono/node-server\": \"^1.19.9\",\n \"@opentelemetry/api-logs\": \"^0.208.0\",\n \"@opentelemetry/exporter-logs-otlp-http\": \"^0.208.0\",\n \"@opentelemetry/resources\": \"^2.0.0\",\n \"@opentelemetry/sdk-logs\": \"^0.208.0\",\n \"@opentelemetry/semantic-conventions\": \"^1.28.0\",\n \"@types/jsonwebtoken\": \"^9.0.10\",\n \"commander\": \"^14.0.2\",\n \"hono\": \"^4.11.7\",\n \"jsonwebtoken\": \"^9.0.2\",\n \"minimatch\": \"^10.0.3\",\n \"tar\": \"^7.5.0\",\n \"uuid\": \"13.0.0\",\n \"yoga-wasm-web\": \"^0.3.3\",\n \"zod\": \"^4.2.0\"\n },\n \"files\": [\n \"dist/**/*\",\n \"src/**/*\",\n \"README.md\",\n \"CLAUDE.md\"\n ],\n \"publishConfig\": {\n \"access\": \"public\"\n }\n}\n","export type GatewayProduct = \"posthog_code\" | \"background_agents\";\n\nfunction getGatewayBaseUrl(posthogHost: string): string {\n const url = new URL(posthogHost);\n const hostname = url.hostname;\n\n if (hostname === \"localhost\" || hostname === \"127.0.0.1\") {\n return `${url.protocol}//localhost:3308`;\n }\n\n if (hostname === \"host.docker.internal\") {\n return `${url.protocol}//host.docker.internal:3308`;\n }\n\n const region = hostname.match(/^(us|eu)\\.posthog\\.com$/)?.[1] ?? \"us\";\n return `https://gateway.${region}.posthog.com`;\n}\n\nexport function getLlmGatewayUrl(\n posthogHost: string,\n product: GatewayProduct = \"posthog_code\",\n): string {\n return `${getGatewayBaseUrl(posthogHost)}/${product}`;\n}\n\nexport function getGatewayUsageUrl(\n posthogHost: string,\n product: GatewayProduct = \"posthog_code\",\n): string {\n return `${getGatewayBaseUrl(posthogHost)}/v1/usage/${product}`;\n}\n\nexport function getGatewayInvalidatePlanCacheUrl(\n posthogHost: string,\n product: GatewayProduct = \"posthog_code\",\n): string {\n return `${getGatewayBaseUrl(posthogHost)}/v1/usage/${product}/invalidate-plan-cache`;\n}\n","import packageJson from \"../package.json\" with { type: \"json\" };\nimport type {\n ArtifactType,\n PostHogAPIConfig,\n StoredEntry,\n Task,\n TaskRun,\n TaskRunArtifact,\n} from \"./types\";\nimport {\n getGatewayInvalidatePlanCacheUrl,\n getGatewayUsageUrl,\n getLlmGatewayUrl,\n} from \"./utils/gateway\";\n\nexport {\n getGatewayInvalidatePlanCacheUrl,\n getGatewayUsageUrl,\n getLlmGatewayUrl,\n};\n\nconst DEFAULT_USER_AGENT = `posthog/agent.hog.dev; version: ${packageJson.version}`;\n\nexport interface TaskArtifactUploadPayload {\n name: string;\n type: ArtifactType;\n content: string;\n content_type?: string;\n}\n\nexport type TaskRunUpdate = Partial<\n Pick<\n TaskRun,\n | \"status\"\n | \"branch\"\n | \"stage\"\n | \"error_message\"\n | \"output\"\n | \"state\"\n | \"environment\"\n >\n> & {\n state_remove_keys?: string[];\n};\n\nexport class PostHogAPIClient {\n private config: PostHogAPIConfig;\n\n constructor(config: PostHogAPIConfig) {\n this.config = config;\n }\n\n private get baseUrl(): string {\n const host = this.config.apiUrl.endsWith(\"/\")\n ? this.config.apiUrl.slice(0, -1)\n : this.config.apiUrl;\n return host;\n }\n\n private isAuthFailure(status: number): boolean {\n return status === 401 || status === 403;\n }\n\n private async resolveApiKey(forceRefresh = false): Promise<string> {\n if (forceRefresh && this.config.refreshApiKey) {\n return this.config.refreshApiKey();\n }\n\n return this.config.getApiKey();\n }\n\n private async buildHeaders(\n options: RequestInit,\n forceRefresh = false,\n ): Promise<Headers> {\n const headers = new Headers(options.headers);\n headers.set(\n \"Authorization\",\n `Bearer ${await this.resolveApiKey(forceRefresh)}`,\n );\n headers.set(\"Content-Type\", \"application/json\");\n headers.set(\"User-Agent\", this.config.userAgent ?? DEFAULT_USER_AGENT);\n return headers;\n }\n\n private async performRequest(\n endpoint: string,\n options: RequestInit,\n forceRefresh = false,\n ): Promise<Response> {\n const url = `${this.baseUrl}${endpoint}`;\n\n return fetch(url, {\n ...options,\n headers: await this.buildHeaders(options, forceRefresh),\n });\n }\n\n private async performRequestWithRetry(\n endpoint: string,\n options: RequestInit = {},\n ): Promise<Response> {\n let response = await this.performRequest(endpoint, options);\n\n if (!response.ok && this.isAuthFailure(response.status)) {\n response = await this.performRequest(endpoint, options, true);\n }\n\n return response;\n }\n\n private async apiRequest<T>(\n endpoint: string,\n options: RequestInit = {},\n ): Promise<T> {\n const response = await this.performRequestWithRetry(endpoint, options);\n\n if (!response.ok) {\n let errorMessage: string;\n try {\n const errorResponse = await response.json();\n errorMessage = `Failed request: [${response.status}] ${JSON.stringify(errorResponse)}`;\n } catch {\n errorMessage = `Failed request: [${response.status}] ${response.statusText}`;\n }\n throw new Error(errorMessage);\n }\n\n return response.json();\n }\n\n private getTeamId(): number {\n return this.config.projectId;\n }\n\n async getApiKey(forceRefresh = false): Promise<string> {\n return this.resolveApiKey(forceRefresh);\n }\n\n getLlmGatewayUrl(): string {\n return getLlmGatewayUrl(this.baseUrl);\n }\n\n async getTask(taskId: string): Promise<Task> {\n const teamId = this.getTeamId();\n return this.apiRequest<Task>(`/api/projects/${teamId}/tasks/${taskId}/`);\n }\n\n async getTaskRun(taskId: string, runId: string): Promise<TaskRun> {\n const teamId = this.getTeamId();\n return this.apiRequest<TaskRun>(\n `/api/projects/${teamId}/tasks/${taskId}/runs/${runId}/`,\n );\n }\n\n async resumeRunInCloud(taskId: string, runId: string): Promise<TaskRun> {\n const teamId = this.getTeamId();\n return this.apiRequest<TaskRun>(\n `/api/projects/${teamId}/tasks/${taskId}/runs/${runId}/resume_in_cloud/`,\n { method: \"POST\" },\n );\n }\n\n async updateTaskRun(\n taskId: string,\n runId: string,\n payload: TaskRunUpdate,\n ): Promise<TaskRun> {\n const teamId = this.getTeamId();\n return this.apiRequest<TaskRun>(\n `/api/projects/${teamId}/tasks/${taskId}/runs/${runId}/`,\n {\n method: \"PATCH\",\n body: JSON.stringify(payload),\n },\n );\n }\n\n async setTaskRunOutput(\n taskId: string,\n runId: string,\n output: Record<string, unknown>,\n ): Promise<TaskRun> {\n return this.apiRequest(\n `/api/projects/${this.getTeamId()}/tasks/${taskId}/runs/${runId}/set_output/`,\n {\n method: \"PATCH\",\n body: JSON.stringify(output),\n },\n );\n }\n\n async appendTaskRunLog(\n taskId: string,\n runId: string,\n entries: StoredEntry[],\n ): Promise<TaskRun> {\n const teamId = this.getTeamId();\n return this.apiRequest<TaskRun>(\n `/api/projects/${teamId}/tasks/${taskId}/runs/${runId}/append_log/`,\n {\n method: \"POST\",\n body: JSON.stringify({ entries }),\n },\n );\n }\n\n async relayMessage(\n taskId: string,\n runId: string,\n text: string,\n ): Promise<void> {\n const teamId = this.getTeamId();\n await this.apiRequest<{ status: string }>(\n `/api/projects/${teamId}/tasks/${taskId}/runs/${runId}/relay_message/`,\n {\n method: \"POST\",\n body: JSON.stringify({ text }),\n },\n );\n }\n\n async uploadTaskArtifacts(\n taskId: string,\n runId: string,\n artifacts: TaskArtifactUploadPayload[],\n ): Promise<TaskRunArtifact[]> {\n if (!artifacts.length) {\n return [];\n }\n\n const teamId = this.getTeamId();\n const response = await this.apiRequest<{ artifacts: TaskRunArtifact[] }>(\n `/api/projects/${teamId}/tasks/${taskId}/runs/${runId}/artifacts/`,\n {\n method: \"POST\",\n body: JSON.stringify({ artifacts }),\n },\n );\n\n const manifest = response.artifacts ?? [];\n\n // The backend returns the full run artifact manifest after each upload.\n // Callers want the artifacts corresponding to this upload request only.\n return manifest.slice(-artifacts.length);\n }\n\n /**\n * Download artifact content by storage path\n * Streams the file through the PostHog backend so the sandbox does not need\n * direct access to object storage.\n */\n async downloadArtifact(\n taskId: string,\n runId: string,\n storagePath: string,\n ): Promise<ArrayBuffer | null> {\n const teamId = this.getTeamId();\n\n try {\n const response = await this.performRequestWithRetry(\n `/api/projects/${teamId}/tasks/${taskId}/runs/${runId}/artifacts/download/`,\n {\n method: \"POST\",\n body: JSON.stringify({ storage_path: storagePath }),\n },\n );\n if (!response.ok) {\n throw new Error(`Failed to download artifact: ${response.status}`);\n }\n return response.arrayBuffer();\n } catch {\n return null;\n }\n }\n\n /**\n * Fetch logs for a task run via the logs API endpoint\n * @param taskRun - The task run to fetch logs for\n * @returns Array of stored entries, or empty array if no logs available\n */\n async fetchTaskRunLogs(taskRun: TaskRun): Promise<StoredEntry[]> {\n const teamId = this.getTeamId();\n const endpoint = `/api/projects/${teamId}/tasks/${taskRun.task}/runs/${taskRun.id}/logs`;\n\n try {\n const response = await this.performRequestWithRetry(endpoint);\n\n if (!response.ok) {\n if (response.status === 404) {\n return [];\n }\n throw new Error(\n `Failed to fetch logs: ${response.status} ${response.statusText}`,\n );\n }\n\n const content = await response.text();\n\n if (!content.trim()) {\n return [];\n }\n\n // Parse newline-delimited JSON\n return content\n .trim()\n .split(\"\\n\")\n .map((line) => JSON.parse(line) as StoredEntry);\n } catch (error) {\n throw new Error(\n `Failed to fetch task run logs: ${error instanceof Error ? error.message : String(error)}`,\n );\n }\n }\n}\n"],"mappings":";AAAA;AAAA,EACE,MAAQ;AAAA,EACR,SAAW;AAAA,EACX,YAAc;AAAA,EACd,aAAe;AAAA,EACf,SAAW;AAAA,IACT,KAAK;AAAA,MACH,OAAS;AAAA,MACT,QAAU;AAAA,IACZ;AAAA,IACA,WAAW;AAAA,MACT,OAAS;AAAA,MACT,QAAU;AAAA,IACZ;AAAA,IACA,oBAAoB;AAAA,MAClB,OAAS;AAAA,MACT,QAAU;AAAA,IACZ;AAAA,IACA,iBAAiB;AAAA,MACf,OAAS;AAAA,MACT,QAAU;AAAA,IACZ;AAAA,IACA,WAAW;AAAA,MACT,OAAS;AAAA,MACT,QAAU;AAAA,IACZ;AAAA,IACA,qCAAqC;AAAA,MACnC,OAAS;AAAA,MACT,QAAU;AAAA,IACZ;AAAA,IACA,oDAAoD;AAAA,MAClD,OAAS;AAAA,MACT,QAAU;AAAA,IACZ;AAAA,IACA,2BAA2B;AAAA,MACzB,OAAS;AAAA,MACT,QAAU;AAAA,IACZ;AAAA,IACA,gDAAgD;AAAA,MAC9C,OAAS;AAAA,MACT,QAAU;AAAA,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{
|
|
8601
8601
|
name: "@posthog/agent",
|
|
8602
|
-
version: "2.3.
|
|
8602
|
+
version: "2.3.508",
|
|
8603
8603
|
repository: "https://github.com/PostHog/code",
|
|
8604
8604
|
description: "TypeScript agent framework wrapping Claude Agent SDK with Git-based task execution for PostHog",
|
|
8605
8605
|
exports: {
|
|
@@ -13461,6 +13461,24 @@ function toolContent() {
|
|
|
13461
13461
|
return new ToolContentBuilder();
|
|
13462
13462
|
}
|
|
13463
13463
|
|
|
13464
|
+
// src/adapters/claude/permissions/posthog-exec-gate.ts
|
|
13465
|
+
var POSTHOG_EXEC_TOOL_RE = /^mcp__posthog(?:_[^_]+)*__exec$/;
|
|
13466
|
+
var POSTHOG_CALL_COMMAND_RE = /^\s*call\s+(?:--json\s+)?([a-zA-Z0-9_-]+)/;
|
|
13467
|
+
var POSTHOG_DESTRUCTIVE_SUBTOOL_RE = /(^|-)(partial-update|update|delete|destroy)(-|$)/i;
|
|
13468
|
+
function isPostHogExecTool(toolName) {
|
|
13469
|
+
return POSTHOG_EXEC_TOOL_RE.test(toolName);
|
|
13470
|
+
}
|
|
13471
|
+
function extractPostHogSubTool(toolInput) {
|
|
13472
|
+
if (!toolInput || typeof toolInput !== "object") return null;
|
|
13473
|
+
const command = toolInput.command;
|
|
13474
|
+
if (typeof command !== "string") return null;
|
|
13475
|
+
const match = command.match(POSTHOG_CALL_COMMAND_RE);
|
|
13476
|
+
return match ? match[1] ?? null : null;
|
|
13477
|
+
}
|
|
13478
|
+
function isPostHogDestructiveSubTool(subTool) {
|
|
13479
|
+
return POSTHOG_DESTRUCTIVE_SUBTOOL_RE.test(subTool);
|
|
13480
|
+
}
|
|
13481
|
+
|
|
13464
13482
|
// src/adapters/claude/hooks.ts
|
|
13465
13483
|
function extractTextFromToolResponse(response) {
|
|
13466
13484
|
if (typeof response === "string") return response;
|
|
@@ -13601,6 +13619,19 @@ var createPreToolUseHook = (settingsManager, logger) => async (input, _toolUseID
|
|
|
13601
13619
|
`[PreToolUseHook] Tool: ${toolName}, Decision: ${permissionCheck.decision}, Rule: ${permissionCheck.rule}`
|
|
13602
13620
|
);
|
|
13603
13621
|
}
|
|
13622
|
+
if (permissionCheck.decision === "allow" && isPostHogExecTool(toolName)) {
|
|
13623
|
+
const subTool = extractPostHogSubTool(toolInput);
|
|
13624
|
+
if (subTool && isPostHogDestructiveSubTool(subTool)) {
|
|
13625
|
+
return {
|
|
13626
|
+
continue: true,
|
|
13627
|
+
hookSpecificOutput: {
|
|
13628
|
+
hookEventName: "PreToolUse",
|
|
13629
|
+
permissionDecision: "ask",
|
|
13630
|
+
permissionDecisionReason: `Destructive PostHog sub-tool '${subTool}' requires explicit approval`
|
|
13631
|
+
}
|
|
13632
|
+
};
|
|
13633
|
+
}
|
|
13634
|
+
}
|
|
13604
13635
|
switch (permissionCheck.decision) {
|
|
13605
13636
|
case "allow":
|
|
13606
13637
|
return {
|
|
@@ -15195,6 +15226,12 @@ async function emitToolDenial(context, message) {
|
|
|
15195
15226
|
}
|
|
15196
15227
|
});
|
|
15197
15228
|
}
|
|
15229
|
+
async function buildDenialResult(context, response) {
|
|
15230
|
+
const feedback = response._meta?.customInput?.trim();
|
|
15231
|
+
const message = feedback ? `User refused permission to run tool with feedback: ${feedback}` : "User refused permission to run tool";
|
|
15232
|
+
await emitToolDenial(context, message);
|
|
15233
|
+
return { behavior: "deny", message, interrupt: !feedback };
|
|
15234
|
+
}
|
|
15198
15235
|
function getPlanFromFile(session, fileContentCache) {
|
|
15199
15236
|
return session.lastPlanContent || (session.lastPlanFilePath ? fileContentCache[session.lastPlanFilePath] : void 0);
|
|
15200
15237
|
}
|
|
@@ -15419,12 +15456,8 @@ async function handleDefaultPermissionFlow(context) {
|
|
|
15419
15456
|
behavior: "allow",
|
|
15420
15457
|
updatedInput: toolInput
|
|
15421
15458
|
};
|
|
15422
|
-
} else {
|
|
15423
|
-
const feedback = response._meta?.customInput?.trim();
|
|
15424
|
-
const message = feedback ? `User refused permission to run tool with feedback: ${feedback}` : "User refused permission to run tool";
|
|
15425
|
-
await emitToolDenial(context, message);
|
|
15426
|
-
return { behavior: "deny", message, interrupt: !feedback };
|
|
15427
15459
|
}
|
|
15460
|
+
return buildDenialResult(context, response);
|
|
15428
15461
|
}
|
|
15429
15462
|
function parseMcpToolName(toolName) {
|
|
15430
15463
|
const parts2 = toolName.split("__");
|
|
@@ -15487,10 +15520,61 @@ ${metadata2.description}` : "";
|
|
|
15487
15520
|
updatedInput: toolInput
|
|
15488
15521
|
};
|
|
15489
15522
|
}
|
|
15490
|
-
|
|
15491
|
-
|
|
15492
|
-
|
|
15493
|
-
|
|
15523
|
+
return buildDenialResult(context, response);
|
|
15524
|
+
}
|
|
15525
|
+
async function handlePostHogExecApprovalFlow(context, subTool) {
|
|
15526
|
+
const { toolName, toolInput, toolUseID, client, sessionId, session } = context;
|
|
15527
|
+
const response = await client.requestPermission({
|
|
15528
|
+
options: [
|
|
15529
|
+
{ kind: "allow_once", name: "Yes", optionId: "allow" },
|
|
15530
|
+
{
|
|
15531
|
+
kind: "allow_always",
|
|
15532
|
+
name: "Yes, always allow",
|
|
15533
|
+
optionId: "allow_always"
|
|
15534
|
+
},
|
|
15535
|
+
{
|
|
15536
|
+
kind: "reject_once",
|
|
15537
|
+
name: "Type here to tell the agent what to do differently",
|
|
15538
|
+
optionId: "reject",
|
|
15539
|
+
_meta: { customInput: true }
|
|
15540
|
+
}
|
|
15541
|
+
],
|
|
15542
|
+
sessionId,
|
|
15543
|
+
toolCall: {
|
|
15544
|
+
toolCallId: toolUseID,
|
|
15545
|
+
title: `The agent wants to run \`${subTool}\` on PostHog`,
|
|
15546
|
+
kind: "other",
|
|
15547
|
+
content: [
|
|
15548
|
+
{
|
|
15549
|
+
type: "content",
|
|
15550
|
+
content: text(
|
|
15551
|
+
"This will modify live PostHog data. Approve to run this sub-tool."
|
|
15552
|
+
)
|
|
15553
|
+
}
|
|
15554
|
+
],
|
|
15555
|
+
rawInput: { ...toolInput, toolName }
|
|
15556
|
+
}
|
|
15557
|
+
});
|
|
15558
|
+
if (context.signal?.aborted || response.outcome?.outcome === "cancelled") {
|
|
15559
|
+
throw new Error("Tool use aborted");
|
|
15560
|
+
}
|
|
15561
|
+
if (response.outcome?.outcome === "selected" && (response.outcome.optionId === "allow" || response.outcome.optionId === "allow_always")) {
|
|
15562
|
+
if (response.outcome.optionId === "allow_always") {
|
|
15563
|
+
try {
|
|
15564
|
+
await session.settingsManager.addPostHogExecApproval(subTool);
|
|
15565
|
+
} catch (error) {
|
|
15566
|
+
context.logger.warn(
|
|
15567
|
+
"[canUseTool] Failed to persist PostHog exec approval",
|
|
15568
|
+
{ error: error instanceof Error ? error.message : String(error) }
|
|
15569
|
+
);
|
|
15570
|
+
}
|
|
15571
|
+
}
|
|
15572
|
+
return {
|
|
15573
|
+
behavior: "allow",
|
|
15574
|
+
updatedInput: toolInput
|
|
15575
|
+
};
|
|
15576
|
+
}
|
|
15577
|
+
return buildDenialResult(context, response);
|
|
15494
15578
|
}
|
|
15495
15579
|
function handlePlanFileException(context) {
|
|
15496
15580
|
const { session, toolName, toolInput } = context;
|
|
@@ -15572,6 +15656,24 @@ async function canUseTool(context) {
|
|
|
15572
15656
|
if (approvalState === "needs_approval") {
|
|
15573
15657
|
return handleMcpApprovalFlow(context);
|
|
15574
15658
|
}
|
|
15659
|
+
if (isPostHogExecTool(toolName)) {
|
|
15660
|
+
const subTool = extractPostHogSubTool(toolInput);
|
|
15661
|
+
if (subTool && isPostHogDestructiveSubTool(subTool)) {
|
|
15662
|
+
if (session.permissionMode === "auto" || session.permissionMode === "bypassPermissions") {
|
|
15663
|
+
return {
|
|
15664
|
+
behavior: "allow",
|
|
15665
|
+
updatedInput: toolInput
|
|
15666
|
+
};
|
|
15667
|
+
}
|
|
15668
|
+
if (session.settingsManager.hasPostHogExecApproval(subTool)) {
|
|
15669
|
+
return {
|
|
15670
|
+
behavior: "allow",
|
|
15671
|
+
updatedInput: toolInput
|
|
15672
|
+
};
|
|
15673
|
+
}
|
|
15674
|
+
return handlePostHogExecApprovalFlow(context, subTool);
|
|
15675
|
+
}
|
|
15676
|
+
}
|
|
15575
15677
|
}
|
|
15576
15678
|
if (isToolAllowedForMode(toolName, session.permissionMode)) {
|
|
15577
15679
|
return {
|
|
@@ -16307,6 +16409,7 @@ var SettingsManager = class {
|
|
|
16307
16409
|
ask: []
|
|
16308
16410
|
};
|
|
16309
16411
|
const merged = { permissions };
|
|
16412
|
+
const posthogApprovedExecTools = /* @__PURE__ */ new Set();
|
|
16310
16413
|
for (const settings of allSettings) {
|
|
16311
16414
|
if (settings.permissions) {
|
|
16312
16415
|
if (settings.permissions.allow) {
|
|
@@ -16334,6 +16437,14 @@ var SettingsManager = class {
|
|
|
16334
16437
|
if (settings.model) {
|
|
16335
16438
|
merged.model = settings.model;
|
|
16336
16439
|
}
|
|
16440
|
+
if (settings.posthogApprovedExecTools) {
|
|
16441
|
+
for (const tool of settings.posthogApprovedExecTools) {
|
|
16442
|
+
posthogApprovedExecTools.add(tool);
|
|
16443
|
+
}
|
|
16444
|
+
}
|
|
16445
|
+
}
|
|
16446
|
+
if (posthogApprovedExecTools.size > 0) {
|
|
16447
|
+
merged.posthogApprovedExecTools = Array.from(posthogApprovedExecTools);
|
|
16337
16448
|
}
|
|
16338
16449
|
this.mergedSettings = merged;
|
|
16339
16450
|
}
|
|
@@ -16398,6 +16509,39 @@ var SettingsManager = class {
|
|
|
16398
16509
|
const next = { ...existing, permissions };
|
|
16399
16510
|
await fs7.promises.mkdir(path9.dirname(filePath), { recursive: true });
|
|
16400
16511
|
await writeFileAtomic(filePath, `${JSON.stringify(next, null, 2)}
|
|
16512
|
+
`);
|
|
16513
|
+
this.localSettings = next;
|
|
16514
|
+
this.mergeAllSettings();
|
|
16515
|
+
} finally {
|
|
16516
|
+
this.writeMutex.release();
|
|
16517
|
+
}
|
|
16518
|
+
}
|
|
16519
|
+
hasPostHogExecApproval(subTool) {
|
|
16520
|
+
return this.mergedSettings.posthogApprovedExecTools?.includes(subTool) ?? false;
|
|
16521
|
+
}
|
|
16522
|
+
/**
|
|
16523
|
+
* Persists an approved PostHog MCP `exec` sub-tool (e.g. `experiment-update`)
|
|
16524
|
+
* to the local settings file so future calls skip the prompt. Mirrors
|
|
16525
|
+
* `addAllowRules` — serialised via `writeMutex`, atomic temp-file + rename.
|
|
16526
|
+
*/
|
|
16527
|
+
async addPostHogExecApproval(subTool) {
|
|
16528
|
+
if (!subTool) return;
|
|
16529
|
+
if (!this.initialized) await this.initialize();
|
|
16530
|
+
await this.writeMutex.acquire();
|
|
16531
|
+
try {
|
|
16532
|
+
const filePath = this.getLocalSettingsPath();
|
|
16533
|
+
const existing = await readSettingsFileForUpdate(filePath);
|
|
16534
|
+
const current2 = new Set(existing.posthogApprovedExecTools ?? []);
|
|
16535
|
+
if (current2.has(subTool)) {
|
|
16536
|
+
return;
|
|
16537
|
+
}
|
|
16538
|
+
current2.add(subTool);
|
|
16539
|
+
const next = {
|
|
16540
|
+
...existing,
|
|
16541
|
+
posthogApprovedExecTools: Array.from(current2)
|
|
16542
|
+
};
|
|
16543
|
+
await fs7.promises.mkdir(path9.dirname(filePath), { recursive: true });
|
|
16544
|
+
await writeFileAtomic(filePath, `${JSON.stringify(next, null, 2)}
|
|
16401
16545
|
`);
|
|
16402
16546
|
this.localSettings = next;
|
|
16403
16547
|
this.mergeAllSettings();
|
|
@@ -21747,6 +21891,15 @@ ${attributionInstructions}
|
|
|
21747
21891
|
`;
|
|
21748
21892
|
}
|
|
21749
21893
|
if (!this.config.repositoryPath) {
|
|
21894
|
+
const publishInstructions = this.config.createPr === false ? `
|
|
21895
|
+
When the user asks for code changes:
|
|
21896
|
+
- You may clone a repository and make local edits in that clone
|
|
21897
|
+
- Do NOT create branches, commits, push changes, or open pull requests in this run` : `
|
|
21898
|
+
When the user explicitly asks to clone or work in a GitHub repository:
|
|
21899
|
+
- Clone the repository into /tmp/workspace/repos/<owner>/<repo> using \`gh repo clone <owner>/<repo> /tmp/workspace/repos/<owner>/<repo>\`
|
|
21900
|
+
- Work from inside that cloned repository for follow-up code changes
|
|
21901
|
+
- If the user explicitly asks you to open or update a pull request, create a branch, commit the requested changes, push it, and open a draft pull request from inside the clone
|
|
21902
|
+
- Do NOT create branches, commits, push changes, or open pull requests unless the user explicitly asks for that`;
|
|
21750
21903
|
return `
|
|
21751
21904
|
# Cloud Task Execution \u2014 No Repository Mode
|
|
21752
21905
|
|
|
@@ -21759,11 +21912,12 @@ When the user asks about analytics, data, metrics, events, funnels, dashboards,
|
|
|
21759
21912
|
|
|
21760
21913
|
When the user asks for code changes or software engineering tasks:
|
|
21761
21914
|
- Let them know you can help but don't have a repository connected for this session
|
|
21762
|
-
-
|
|
21915
|
+
- If they have not specified a repository to clone, offer to write code snippets, scripts, or provide guidance
|
|
21916
|
+
${publishInstructions}
|
|
21763
21917
|
|
|
21764
21918
|
Important:
|
|
21765
|
-
- Do NOT create branches, commits, or pull requests in this mode.
|
|
21766
21919
|
- Prefer using MCP tools to answer questions with real data over giving generic advice.
|
|
21920
|
+
${attributionInstructions}
|
|
21767
21921
|
`;
|
|
21768
21922
|
}
|
|
21769
21923
|
if (!shouldAutoCreatePr) {
|