@posthog/agent 2.0.0 → 2.0.1
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/LICENSE +1 -1
- package/README.md +221 -219
- package/dist/adapters/claude/conversion/tool-use-to-acp.d.ts +21 -0
- package/dist/adapters/claude/conversion/tool-use-to-acp.js +547 -0
- package/dist/adapters/claude/conversion/tool-use-to-acp.js.map +1 -0
- package/dist/adapters/claude/permissions/permission-options.d.ts +13 -0
- package/dist/adapters/claude/permissions/permission-options.js +117 -0
- package/dist/adapters/claude/permissions/permission-options.js.map +1 -0
- package/dist/adapters/claude/questions/utils.d.ts +132 -0
- package/dist/adapters/claude/questions/utils.js +63 -0
- package/dist/adapters/claude/questions/utils.js.map +1 -0
- package/dist/adapters/claude/tools.d.ts +18 -0
- package/dist/adapters/claude/tools.js +95 -0
- package/dist/adapters/claude/tools.js.map +1 -0
- package/dist/agent-DBQY1BfC.d.ts +123 -0
- package/dist/agent.d.ts +5 -0
- package/dist/agent.js +3656 -0
- package/dist/agent.js.map +1 -0
- package/dist/claude-cli/cli.js +3695 -2746
- package/dist/claude-cli/vendor/ripgrep/COPYING +3 -0
- package/dist/claude-cli/vendor/ripgrep/arm64-darwin/rg +0 -0
- package/dist/claude-cli/vendor/ripgrep/arm64-darwin/ripgrep.node +0 -0
- package/dist/claude-cli/vendor/ripgrep/arm64-linux/rg +0 -0
- package/dist/claude-cli/vendor/ripgrep/arm64-linux/ripgrep.node +0 -0
- package/dist/claude-cli/vendor/ripgrep/x64-darwin/rg +0 -0
- package/dist/claude-cli/vendor/ripgrep/x64-darwin/ripgrep.node +0 -0
- package/dist/claude-cli/vendor/ripgrep/x64-linux/rg +0 -0
- package/dist/claude-cli/vendor/ripgrep/x64-linux/ripgrep.node +0 -0
- package/dist/claude-cli/vendor/ripgrep/x64-win32/rg.exe +0 -0
- package/dist/claude-cli/vendor/ripgrep/x64-win32/ripgrep.node +0 -0
- package/dist/gateway-models.d.ts +24 -0
- package/dist/gateway-models.js +93 -0
- package/dist/gateway-models.js.map +1 -0
- package/dist/index.d.ts +170 -1157
- package/dist/index.js +3252 -5074
- package/dist/index.js.map +1 -1
- package/dist/logger-DDBiMOOD.d.ts +24 -0
- package/dist/posthog-api.d.ts +40 -0
- package/dist/posthog-api.js +175 -0
- package/dist/posthog-api.js.map +1 -0
- package/dist/server/agent-server.d.ts +41 -0
- package/dist/server/agent-server.js +4451 -0
- package/dist/server/agent-server.js.map +1 -0
- package/dist/server/bin.d.ts +1 -0
- package/dist/server/bin.js +4507 -0
- package/dist/server/bin.js.map +1 -0
- package/dist/types.d.ts +129 -0
- package/dist/types.js +1 -0
- package/dist/types.js.map +1 -0
- package/package.json +66 -14
- package/src/acp-extensions.ts +98 -16
- package/src/adapters/acp-connection.ts +494 -0
- package/src/adapters/base-acp-agent.ts +150 -0
- package/src/adapters/claude/claude-agent.ts +596 -0
- package/src/adapters/claude/conversion/acp-to-sdk.ts +102 -0
- package/src/adapters/claude/conversion/sdk-to-acp.ts +571 -0
- package/src/adapters/claude/conversion/tool-use-to-acp.ts +618 -0
- package/src/adapters/claude/hooks.ts +64 -0
- package/src/adapters/claude/mcp/tool-metadata.ts +102 -0
- package/src/adapters/claude/permissions/permission-handlers.ts +433 -0
- package/src/adapters/claude/permissions/permission-options.ts +103 -0
- package/src/adapters/claude/plan/utils.ts +56 -0
- package/src/adapters/claude/questions/utils.ts +92 -0
- package/src/adapters/claude/session/commands.ts +38 -0
- package/src/adapters/claude/session/mcp-config.ts +37 -0
- package/src/adapters/claude/session/models.ts +12 -0
- package/src/adapters/claude/session/options.ts +236 -0
- package/src/adapters/claude/tool-meta.ts +143 -0
- package/src/adapters/claude/tools.ts +53 -688
- package/src/adapters/claude/types.ts +61 -0
- package/src/adapters/codex/spawn.ts +130 -0
- package/src/agent.ts +96 -587
- package/src/execution-mode.ts +43 -0
- package/src/gateway-models.ts +135 -0
- package/src/index.ts +79 -0
- package/src/otel-log-writer.test.ts +105 -0
- package/src/otel-log-writer.ts +94 -0
- package/src/posthog-api.ts +75 -235
- package/src/resume.ts +115 -0
- package/src/sagas/apply-snapshot-saga.test.ts +690 -0
- package/src/sagas/apply-snapshot-saga.ts +88 -0
- package/src/sagas/capture-tree-saga.test.ts +892 -0
- package/src/sagas/capture-tree-saga.ts +141 -0
- package/src/sagas/resume-saga.test.ts +558 -0
- package/src/sagas/resume-saga.ts +332 -0
- package/src/sagas/test-fixtures.ts +250 -0
- package/src/server/agent-server.test.ts +220 -0
- package/src/server/agent-server.ts +748 -0
- package/src/server/bin.ts +88 -0
- package/src/server/jwt.ts +65 -0
- package/src/server/schemas.ts +47 -0
- package/src/server/types.ts +13 -0
- package/src/server/utils/retry.test.ts +122 -0
- package/src/server/utils/retry.ts +61 -0
- package/src/server/utils/sse-parser.test.ts +93 -0
- package/src/server/utils/sse-parser.ts +46 -0
- package/src/session-log-writer.test.ts +140 -0
- package/src/session-log-writer.ts +137 -0
- package/src/test/assertions.ts +114 -0
- package/src/test/controllers/sse-controller.ts +107 -0
- package/src/test/fixtures/api.ts +111 -0
- package/src/test/fixtures/config.ts +33 -0
- package/src/test/fixtures/notifications.ts +92 -0
- package/src/test/mocks/claude-sdk.ts +251 -0
- package/src/test/mocks/msw-handlers.ts +48 -0
- package/src/test/setup.ts +114 -0
- package/src/test/wait.ts +41 -0
- package/src/tree-tracker.ts +173 -0
- package/src/types.ts +54 -137
- package/src/utils/acp-content.ts +58 -0
- package/src/utils/async-mutex.test.ts +104 -0
- package/src/utils/async-mutex.ts +31 -0
- package/src/utils/common.ts +15 -0
- package/src/utils/gateway.ts +9 -6
- package/src/utils/logger.ts +0 -30
- package/src/utils/streams.ts +220 -0
- package/CLAUDE.md +0 -331
- package/src/adapters/claude/claude.ts +0 -1947
- package/src/adapters/claude/mcp-server.ts +0 -810
- package/src/adapters/claude/utils.ts +0 -267
- package/src/adapters/connection.ts +0 -95
- package/src/file-manager.ts +0 -273
- package/src/git-manager.ts +0 -577
- package/src/schemas.ts +0 -241
- package/src/session-store.ts +0 -259
- package/src/task-manager.ts +0 -163
- package/src/todo-manager.ts +0 -180
- package/src/tools/registry.ts +0 -134
- package/src/tools/types.ts +0 -133
- package/src/utils/tapped-stream.ts +0 -60
- package/src/worktree-manager.ts +0 -974
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import type {
|
|
2
|
+
TerminalHandle,
|
|
3
|
+
TerminalOutputResponse,
|
|
4
|
+
} from "@agentclientprotocol/sdk";
|
|
5
|
+
import type {
|
|
6
|
+
Options,
|
|
7
|
+
Query,
|
|
8
|
+
SDKUserMessage,
|
|
9
|
+
} from "@anthropic-ai/claude-agent-sdk";
|
|
10
|
+
import type { Pushable } from "../../utils/streams.js";
|
|
11
|
+
import type { BaseSession } from "../base-acp-agent.js";
|
|
12
|
+
import type { TwigExecutionMode } from "./tools.js";
|
|
13
|
+
|
|
14
|
+
export type BackgroundTerminal =
|
|
15
|
+
| {
|
|
16
|
+
handle: TerminalHandle;
|
|
17
|
+
status: "started";
|
|
18
|
+
lastOutput: TerminalOutputResponse | null;
|
|
19
|
+
}
|
|
20
|
+
| {
|
|
21
|
+
status: "aborted" | "exited" | "killed" | "timedOut";
|
|
22
|
+
pendingOutput: TerminalOutputResponse;
|
|
23
|
+
};
|
|
24
|
+
|
|
25
|
+
export type Session = BaseSession & {
|
|
26
|
+
query: Query;
|
|
27
|
+
input: Pushable<SDKUserMessage>;
|
|
28
|
+
permissionMode: TwigExecutionMode;
|
|
29
|
+
modelId?: string;
|
|
30
|
+
cwd: string;
|
|
31
|
+
taskRunId?: string;
|
|
32
|
+
sessionId?: string;
|
|
33
|
+
lastPlanFilePath?: string;
|
|
34
|
+
lastPlanContent?: string;
|
|
35
|
+
};
|
|
36
|
+
|
|
37
|
+
export type ToolUseCache = {
|
|
38
|
+
[key: string]: {
|
|
39
|
+
type: "tool_use" | "server_tool_use" | "mcp_tool_use";
|
|
40
|
+
id: string;
|
|
41
|
+
name: string;
|
|
42
|
+
input: unknown;
|
|
43
|
+
};
|
|
44
|
+
};
|
|
45
|
+
|
|
46
|
+
export type ToolUpdateMeta = {
|
|
47
|
+
claudeCode?: {
|
|
48
|
+
toolName: string;
|
|
49
|
+
toolResponse?: unknown;
|
|
50
|
+
};
|
|
51
|
+
};
|
|
52
|
+
|
|
53
|
+
export type NewSessionMeta = {
|
|
54
|
+
taskRunId?: string;
|
|
55
|
+
disableBuiltInTools?: boolean;
|
|
56
|
+
systemPrompt?: unknown;
|
|
57
|
+
sessionId?: string;
|
|
58
|
+
claudeCode?: {
|
|
59
|
+
options?: Options;
|
|
60
|
+
};
|
|
61
|
+
};
|
|
@@ -0,0 +1,130 @@
|
|
|
1
|
+
import { type ChildProcess, spawn } from "node:child_process";
|
|
2
|
+
import { existsSync } from "node:fs";
|
|
3
|
+
import type { Readable, Writable } from "node:stream";
|
|
4
|
+
import type { ProcessSpawnedCallback } from "../../types.js";
|
|
5
|
+
import { Logger } from "../../utils/logger.js";
|
|
6
|
+
|
|
7
|
+
export interface CodexProcessOptions {
|
|
8
|
+
cwd?: string;
|
|
9
|
+
apiBaseUrl?: string;
|
|
10
|
+
apiKey?: string;
|
|
11
|
+
model?: string;
|
|
12
|
+
binaryPath?: string;
|
|
13
|
+
logger?: Logger;
|
|
14
|
+
processCallbacks?: ProcessSpawnedCallback;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
export interface CodexProcess {
|
|
18
|
+
process: ChildProcess;
|
|
19
|
+
stdin: Writable;
|
|
20
|
+
stdout: Readable;
|
|
21
|
+
kill: () => void;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
function buildConfigArgs(options: CodexProcessOptions): string[] {
|
|
25
|
+
const args: string[] = [];
|
|
26
|
+
|
|
27
|
+
args.push("-c", `features.remote_models=false`);
|
|
28
|
+
|
|
29
|
+
if (options.apiBaseUrl) {
|
|
30
|
+
args.push("-c", `model_provider="posthog"`);
|
|
31
|
+
args.push("-c", `model_providers.posthog.name="PostHog Gateway"`);
|
|
32
|
+
args.push("-c", `model_providers.posthog.base_url="${options.apiBaseUrl}"`);
|
|
33
|
+
args.push("-c", `model_providers.posthog.wire_api="responses"`);
|
|
34
|
+
args.push(
|
|
35
|
+
"-c",
|
|
36
|
+
`model_providers.posthog.env_key="POSTHOG_GATEWAY_API_KEY"`,
|
|
37
|
+
);
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
if (options.model) {
|
|
41
|
+
args.push("-c", `model="${options.model}"`);
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
return args;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
function findCodexBinary(options: CodexProcessOptions): {
|
|
48
|
+
command: string;
|
|
49
|
+
args: string[];
|
|
50
|
+
} {
|
|
51
|
+
const configArgs = buildConfigArgs(options);
|
|
52
|
+
|
|
53
|
+
if (options.binaryPath && existsSync(options.binaryPath)) {
|
|
54
|
+
return { command: options.binaryPath, args: configArgs };
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
return { command: "npx", args: ["@zed-industries/codex-acp", ...configArgs] };
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
export function spawnCodexProcess(options: CodexProcessOptions): CodexProcess {
|
|
61
|
+
const logger =
|
|
62
|
+
options.logger ?? new Logger({ debug: true, prefix: "[CodexSpawn]" });
|
|
63
|
+
|
|
64
|
+
const env: NodeJS.ProcessEnv = { ...process.env };
|
|
65
|
+
|
|
66
|
+
// Prevent Electron's GPU/Chromium processes from interfering with child
|
|
67
|
+
delete env.ELECTRON_RUN_AS_NODE;
|
|
68
|
+
delete env.ELECTRON_NO_ASAR;
|
|
69
|
+
|
|
70
|
+
if (options.apiKey) {
|
|
71
|
+
env.POSTHOG_GATEWAY_API_KEY = options.apiKey;
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
const { command, args } = findCodexBinary(options);
|
|
75
|
+
|
|
76
|
+
logger.info("Spawning codex-acp process", {
|
|
77
|
+
command,
|
|
78
|
+
args,
|
|
79
|
+
cwd: options.cwd,
|
|
80
|
+
hasApiBaseUrl: !!options.apiBaseUrl,
|
|
81
|
+
hasApiKey: !!options.apiKey,
|
|
82
|
+
binaryPath: options.binaryPath,
|
|
83
|
+
});
|
|
84
|
+
|
|
85
|
+
const child = spawn(command, args, {
|
|
86
|
+
cwd: options.cwd,
|
|
87
|
+
env,
|
|
88
|
+
stdio: ["pipe", "pipe", "pipe"],
|
|
89
|
+
detached: process.platform !== "win32",
|
|
90
|
+
});
|
|
91
|
+
|
|
92
|
+
child.stderr?.on("data", (data: Buffer) => {
|
|
93
|
+
logger.debug("codex-acp stderr:", data.toString());
|
|
94
|
+
});
|
|
95
|
+
|
|
96
|
+
child.on("error", (err) => {
|
|
97
|
+
logger.error("codex-acp process error:", err);
|
|
98
|
+
});
|
|
99
|
+
|
|
100
|
+
child.on("exit", (code, signal) => {
|
|
101
|
+
logger.info("codex-acp process exited", { code, signal });
|
|
102
|
+
if (child.pid && options.processCallbacks?.onProcessExited) {
|
|
103
|
+
options.processCallbacks.onProcessExited(child.pid);
|
|
104
|
+
}
|
|
105
|
+
});
|
|
106
|
+
|
|
107
|
+
if (!child.stdin || !child.stdout) {
|
|
108
|
+
throw new Error("Failed to get stdio streams from codex-acp process");
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
if (child.pid && options.processCallbacks?.onProcessSpawned) {
|
|
112
|
+
options.processCallbacks.onProcessSpawned({
|
|
113
|
+
pid: child.pid,
|
|
114
|
+
command,
|
|
115
|
+
});
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
return {
|
|
119
|
+
process: child,
|
|
120
|
+
stdin: child.stdin,
|
|
121
|
+
stdout: child.stdout,
|
|
122
|
+
kill: () => {
|
|
123
|
+
logger.info("Killing codex-acp process", { pid: child.pid });
|
|
124
|
+
child.stdin?.destroy();
|
|
125
|
+
child.stdout?.destroy();
|
|
126
|
+
child.stderr?.destroy();
|
|
127
|
+
child.kill("SIGTERM");
|
|
128
|
+
},
|
|
129
|
+
};
|
|
130
|
+
}
|