@gkorepanov/ccodex 0.4.17 → 0.4.19
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/config/compatibility.json +1 -1
- package/dist/claude/developerInstructions.d.ts +2 -0
- package/dist/claude/developerInstructions.js +9 -0
- package/dist/claude/developerInstructions.js.map +1 -0
- package/dist/claude/inputMapper.js +9 -0
- package/dist/claude/inputMapper.js.map +1 -1
- package/dist/claude/service.d.ts +6 -0
- package/dist/claude/service.js +38 -4
- package/dist/claude/service.js.map +1 -1
- package/dist/claude/session/codexRollout.d.ts +26 -0
- package/dist/claude/session/codexRollout.js +139 -0
- package/dist/claude/session/codexRollout.js.map +1 -0
- package/dist/claude/session/commands.d.ts +10 -0
- package/dist/claude/session/providerRuntimeFactory.js +6 -1
- package/dist/claude/session/providerRuntimeFactory.js.map +1 -1
- package/dist/claude/session/session.d.ts +15 -1
- package/dist/claude/session/session.js +182 -5
- package/dist/claude/session/session.js.map +1 -1
- package/dist/cli/args.d.ts +1 -0
- package/dist/cli/args.js +24 -1
- package/dist/cli/args.js.map +1 -1
- package/dist/cli/main.js +3 -1
- package/dist/cli/main.js.map +1 -1
- package/dist/daemon/probe.js +3 -0
- package/dist/daemon/probe.js.map +1 -1
- package/dist/desktop/launchConfig.d.ts +1 -0
- package/dist/desktop/launchConfig.js +71 -0
- package/dist/desktop/launchConfig.js.map +1 -0
- package/dist/desktop/stdioFrontend.d.ts +1 -0
- package/dist/desktop/stdioFrontend.js +6 -2
- package/dist/desktop/stdioFrontend.js.map +1 -1
- package/dist/gateway/clientConnection.js +18 -19
- package/dist/gateway/clientConnection.js.map +1 -1
- package/dist/gateway/threadList.js +4 -1
- package/dist/gateway/threadList.js.map +1 -1
- package/dist/handoff/service.js +6 -1
- package/dist/handoff/service.js.map +1 -1
- package/dist/protocol/appContext.d.ts +1 -0
- package/dist/protocol/appContext.js +5 -0
- package/dist/protocol/appContext.js.map +1 -0
- package/dist/store/sqliteStore.js +17 -0
- package/dist/store/sqliteStore.js.map +1 -1
- package/package.json +4 -4
|
@@ -0,0 +1,139 @@
|
|
|
1
|
+
import { closeSync, openSync, readSync, readdirSync, statSync } from "node:fs";
|
|
2
|
+
import { homedir } from "node:os";
|
|
3
|
+
import { join } from "node:path";
|
|
4
|
+
export const CODEX_MCP_TOOLS = new Set(["mcp__codex__codex", "mcp__codex__codex-reply"]);
|
|
5
|
+
export const CODEX_MCP_PROMPT_LABEL = "◆ CCodex │ Codex MCP prompt";
|
|
6
|
+
export const CODEX_MCP_MESSAGE_LABEL = "◆ CCodex │ Codex MCP message";
|
|
7
|
+
export const CODEX_MCP_REASONING_LABEL = "◆ CCodex │ Codex MCP reasoning";
|
|
8
|
+
function codexSessionsDir() {
|
|
9
|
+
return join(process.env.CODEX_HOME ?? join(homedir(), ".codex"), "sessions");
|
|
10
|
+
}
|
|
11
|
+
function dayDirsNewestFirst(root, limit) {
|
|
12
|
+
const numericDesc = (values) => values.filter((value) => /^\d+$/.test(value)).sort((a, b) => Number(b) - Number(a));
|
|
13
|
+
const days = [];
|
|
14
|
+
let entries;
|
|
15
|
+
try {
|
|
16
|
+
entries = readdirSync(root);
|
|
17
|
+
}
|
|
18
|
+
catch {
|
|
19
|
+
return [];
|
|
20
|
+
}
|
|
21
|
+
for (const year of numericDesc(entries)) {
|
|
22
|
+
for (const month of numericDesc(readdirSync(join(root, year)))) {
|
|
23
|
+
for (const day of numericDesc(readdirSync(join(root, year, month)))) {
|
|
24
|
+
days.push(join(root, year, month, day));
|
|
25
|
+
if (days.length >= limit)
|
|
26
|
+
return days;
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
return days;
|
|
31
|
+
}
|
|
32
|
+
function sessionMeta(path) {
|
|
33
|
+
// The session_meta line embeds the full codex base instructions, so it can be
|
|
34
|
+
// tens of kilobytes long — read a bounded head and require a complete line.
|
|
35
|
+
let head;
|
|
36
|
+
try {
|
|
37
|
+
const buffer = Buffer.alloc(262_144);
|
|
38
|
+
const fd = openSync(path, "r");
|
|
39
|
+
try {
|
|
40
|
+
head = buffer.subarray(0, readSync(fd, buffer, 0, buffer.length, 0)).toString("utf8");
|
|
41
|
+
}
|
|
42
|
+
finally {
|
|
43
|
+
closeSync(fd);
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
catch {
|
|
47
|
+
return undefined;
|
|
48
|
+
}
|
|
49
|
+
const end = head.indexOf("\n");
|
|
50
|
+
if (end === -1)
|
|
51
|
+
return undefined;
|
|
52
|
+
const line = head.slice(0, end);
|
|
53
|
+
try {
|
|
54
|
+
const parsed = JSON.parse(line);
|
|
55
|
+
if (parsed.type !== "session_meta")
|
|
56
|
+
return undefined;
|
|
57
|
+
const timestamp = parsed.payload?.timestamp ? Date.parse(parsed.payload.timestamp) : Number.NaN;
|
|
58
|
+
return {
|
|
59
|
+
...(parsed.payload?.source === undefined ? {} : { source: parsed.payload.source }),
|
|
60
|
+
...(Number.isNaN(timestamp) ? {} : { timestampMs: timestamp }),
|
|
61
|
+
};
|
|
62
|
+
}
|
|
63
|
+
catch {
|
|
64
|
+
return undefined;
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
export function defaultCodexRolloutLocator(sessionsDir = codexSessionsDir()) {
|
|
68
|
+
return {
|
|
69
|
+
byThreadId(threadId) {
|
|
70
|
+
const suffix = `-${threadId}.jsonl`;
|
|
71
|
+
for (const day of dayDirsNewestFirst(sessionsDir, 366)) {
|
|
72
|
+
for (const entry of readdirSync(day)) {
|
|
73
|
+
if (entry.endsWith(suffix))
|
|
74
|
+
return join(day, entry);
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
return undefined;
|
|
78
|
+
},
|
|
79
|
+
freshMcpSession(notBeforeMs, claimed) {
|
|
80
|
+
const candidates = [];
|
|
81
|
+
for (const day of dayDirsNewestFirst(sessionsDir, 2)) {
|
|
82
|
+
for (const entry of readdirSync(day)) {
|
|
83
|
+
if (!entry.endsWith(".jsonl"))
|
|
84
|
+
continue;
|
|
85
|
+
const path = join(day, entry);
|
|
86
|
+
if (claimed.has(path))
|
|
87
|
+
continue;
|
|
88
|
+
try {
|
|
89
|
+
if (statSync(path).mtimeMs < notBeforeMs - 5_000)
|
|
90
|
+
continue;
|
|
91
|
+
}
|
|
92
|
+
catch {
|
|
93
|
+
continue;
|
|
94
|
+
}
|
|
95
|
+
const meta = sessionMeta(path);
|
|
96
|
+
if (meta?.source !== "mcp")
|
|
97
|
+
continue;
|
|
98
|
+
if (meta.timestampMs === undefined || meta.timestampMs < notBeforeMs - 5_000)
|
|
99
|
+
continue;
|
|
100
|
+
candidates.push({ path, timestampMs: meta.timestampMs });
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
return candidates.sort((a, b) => a.timestampMs - b.timestampMs)[0]?.path;
|
|
104
|
+
},
|
|
105
|
+
};
|
|
106
|
+
}
|
|
107
|
+
/** Consumes complete journal lines from `buffer` + `chunk`, returning mapped events and the unparsed tail. */
|
|
108
|
+
export function parseRolloutChunk(buffer, chunk) {
|
|
109
|
+
const combined = buffer + chunk;
|
|
110
|
+
const boundary = combined.lastIndexOf("\n");
|
|
111
|
+
if (boundary === -1)
|
|
112
|
+
return { rest: combined, events: [] };
|
|
113
|
+
const events = [];
|
|
114
|
+
for (const line of combined.slice(0, boundary).split("\n")) {
|
|
115
|
+
if (!line.trim())
|
|
116
|
+
continue;
|
|
117
|
+
let parsed;
|
|
118
|
+
try {
|
|
119
|
+
parsed = JSON.parse(line);
|
|
120
|
+
}
|
|
121
|
+
catch {
|
|
122
|
+
continue;
|
|
123
|
+
}
|
|
124
|
+
if (parsed.type !== "event_msg")
|
|
125
|
+
continue;
|
|
126
|
+
const payload = parsed.payload;
|
|
127
|
+
if (payload?.type === "agent_message" && typeof payload.message === "string" && payload.message) {
|
|
128
|
+
events.push({ kind: "message", text: payload.message });
|
|
129
|
+
}
|
|
130
|
+
else if (payload?.type === "agent_reasoning" && typeof payload.text === "string" && payload.text) {
|
|
131
|
+
events.push({ kind: "reasoning", text: payload.text });
|
|
132
|
+
}
|
|
133
|
+
else if (payload?.type === "task_complete") {
|
|
134
|
+
events.push({ kind: "turnComplete" });
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
return { rest: combined.slice(boundary + 1), events };
|
|
138
|
+
}
|
|
139
|
+
//# sourceMappingURL=codexRollout.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"codexRollout.js","sourceRoot":"","sources":["../../../src/claude/session/codexRollout.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,QAAQ,EAAE,QAAQ,EAAE,WAAW,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAC;AAC/E,OAAO,EAAE,OAAO,EAAE,MAAM,SAAS,CAAC;AAClC,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AAEjC,MAAM,CAAC,MAAM,eAAe,GAAG,IAAI,GAAG,CAAC,CAAC,mBAAmB,EAAE,yBAAyB,CAAC,CAAC,CAAC;AACzF,MAAM,CAAC,MAAM,sBAAsB,GAAG,6BAA6B,CAAC;AACpE,MAAM,CAAC,MAAM,uBAAuB,GAAG,8BAA8B,CAAC;AACtE,MAAM,CAAC,MAAM,yBAAyB,GAAG,gCAAgC,CAAC;AAe1E,SAAS,gBAAgB;IACvB,OAAO,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,UAAU,IAAI,IAAI,CAAC,OAAO,EAAE,EAAE,QAAQ,CAAC,EAAE,UAAU,CAAC,CAAC;AAC/E,CAAC;AAED,SAAS,kBAAkB,CAAC,IAAY,EAAE,KAAa;IACrD,MAAM,WAAW,GAAG,CAAC,MAAgB,EAAE,EAAE,CACvC,MAAM,CAAC,MAAM,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,OAAO,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC,MAAM,CAAC,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O,EAAE,IAAI,KAAK,iBAAiB,IAAI,OAAO,OAAO,CAAC,IAAI,KAAK,QAAQ,IAAI,OAAO,CAAC,IAAI,EAAE,CAAC;YACnG,MAAM,CAAC,IAAI,CAAC,EAAE,IAAI,EAAE,WAAW,EAAE,IAAI,EAAE,OAAO,CAAC,IAAI,EAAE,CAAC,CAAC;QACzD,CAAC;aAAM,IAAI,OAAO,EAAE,IAAI,KAAK,eAAe,EAAE,CAAC;YAC7C,MAAM,CAAC,IAAI,CAAC,EAAE,IAAI,EAAE,cAAc,EAAE,CAAC,CAAC;QACxC,CAAC;IACH,CAAC;IACD,OAAO,EAAE,IAAI,EAAE,QAAQ,CAAC,KAAK,CAAC,QAAQ,GAAG,CAAC,CAAC,EAAE,MAAM,EAAE,CAAC;AACxD,CAAC"}
|
|
@@ -81,6 +81,7 @@ export type RuntimeTurnStage = {
|
|
|
81
81
|
readonly kind: "staged";
|
|
82
82
|
} | {
|
|
83
83
|
readonly kind: "busy";
|
|
84
|
+
readonly activeTurnId: string | null;
|
|
84
85
|
} | {
|
|
85
86
|
readonly kind: "stale";
|
|
86
87
|
readonly reason: "runtime" | "settings";
|
|
@@ -110,6 +111,9 @@ export type MainStreamFact = {
|
|
|
110
111
|
} | {
|
|
111
112
|
readonly kind: "instantAgent";
|
|
112
113
|
readonly text: string;
|
|
114
|
+
} | {
|
|
115
|
+
readonly kind: "instantReasoning";
|
|
116
|
+
readonly text: string;
|
|
113
117
|
} | {
|
|
114
118
|
readonly kind: "settle";
|
|
115
119
|
readonly phase: "commentary" | "final_answer";
|
|
@@ -727,6 +731,12 @@ export type ClaudeSessionCommand = {
|
|
|
727
731
|
readonly type: "captureToolFileAfter";
|
|
728
732
|
readonly runtimeGeneration: number;
|
|
729
733
|
readonly providerId: string;
|
|
734
|
+
} | {
|
|
735
|
+
readonly type: "codexMcpCallBegin";
|
|
736
|
+
readonly runtimeGeneration: number;
|
|
737
|
+
readonly providerId: string;
|
|
738
|
+
readonly ownerProviderId?: string;
|
|
739
|
+
readonly input: Record<string, unknown>;
|
|
730
740
|
} | {
|
|
731
741
|
readonly type: "hook";
|
|
732
742
|
readonly runtimeGeneration: number;
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { normalizeClaudeModelIdentifier } from "../modelSelection.js";
|
|
2
2
|
import { claudeEnvironment } from "../environment.js";
|
|
3
3
|
import { ProviderRuntime, } from "./providerRuntime.js";
|
|
4
|
+
import { CCODEX_APP_UI_INSTRUCTIONS, claudeDeveloperInstructions, } from "../developerInstructions.js";
|
|
4
5
|
const unsupportedProviderReviewTools = ["SendFeedback", "ProposeSkills"];
|
|
5
6
|
export class StaleClaudeRuntimeSettingsError extends Error {
|
|
6
7
|
reason;
|
|
@@ -12,7 +13,11 @@ export class StaleClaudeRuntimeSettingsError extends Error {
|
|
|
12
13
|
}
|
|
13
14
|
}
|
|
14
15
|
function appendInstructions(startup) {
|
|
15
|
-
const parts = [
|
|
16
|
+
const parts = [
|
|
17
|
+
CCODEX_APP_UI_INSTRUCTIONS,
|
|
18
|
+
startup.baseInstructions,
|
|
19
|
+
claudeDeveloperInstructions(startup.developerInstructions),
|
|
20
|
+
];
|
|
16
21
|
if (startup.personality === "friendly")
|
|
17
22
|
parts.push("Use a friendly, collaborative communication style.");
|
|
18
23
|
if (startup.personality === "pragmatic")
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"providerRuntimeFactory.js","sourceRoot":"","sources":["../../../src/claude/session/providerRuntimeFactory.ts"],"names":[],"mappings":"AAYA,OAAO,EAAE,8BAA8B,EAAE,MAAM,sBAAsB,CAAC;AACtE,OAAO,EAAE,iBAAiB,EAAE,MAAM,mBAAmB,CAAC;AACtD,OAAO,EACL,eAAe,GAGhB,MAAM,sBAAsB,CAAC;
|
|
1
|
+
{"version":3,"file":"providerRuntimeFactory.js","sourceRoot":"","sources":["../../../src/claude/session/providerRuntimeFactory.ts"],"names":[],"mappings":"AAYA,OAAO,EAAE,8BAA8B,EAAE,MAAM,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,CAAC,CAAC,EAAE,CAAC;QAC3E,GAAG,CAAC,cAAc,CAAC,CAAC,CAAC,EAAE,MAAM,EAAE,cAAc,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;QACrD,GAAG,CAAC,OAAO,CAAC,gBAAgB,KAAK,MAAM;YACrC,CAAC,CAAC,EAAE,QAAQ,EAAE,EAAE,IAAI,EAAE,UAAU,EAAE,OAAO,EAAE,SAAS,EAAW,EAAE;YACjE,CAAC,CAAC,OAAO,CAAC,gBAAgB;gBACxB,CAAC,CAAC,EAAE,QAAQ,EAAE,EAAE,IAAI,EAAE,UAAU,EAAE,OAAO,EAAE,YAAY,EAAW,EAAE;gBACpE,CAAC,CAAC,EAAE,CAAC;QACT,GAAG,CAAC,YAAY;YACd,CAAC,CAAC,EAAE,YAAY,EAAE,EAAE,IAAI,EAAE,aAAa,EAAE,MAAM,EAAE,YAAY,EAAW,EAAE;YAC1E,CAAC,CAAC,EAAE,CAAC;QACP,GAAG,EAAE,iBAAiB,EAAE;QACxB,MAAM,EAAE,CAAC,IAAI,EAAE,EAAE,CAAC,MAAM,CAAC,KAAK,CAAC,eAAe,EAAE,EAAE,QAAQ,EAAE,OAAO,CAAC,QAAQ,EAAE,MAAM,EAAE,IAAI,EAAE,CAAC;KAChG,EACD,YAAY,EACZ,UAAU,CACX,CAAC;AACJ,CAAC"}
|
|
@@ -1,11 +1,13 @@
|
|
|
1
1
|
import type { Turn } from "../../codex/generated/v2/Turn.js";
|
|
2
2
|
import type { ClaudeSessionHandle } from "../sessionRegistry.js";
|
|
3
3
|
import { MetricsRegistry } from "../../observability/metrics.js";
|
|
4
|
+
import { RpcError } from "../../protocol/errors.js";
|
|
4
5
|
import type { ClaudeSessionCommand, PreparedSessionTurn, RuntimeInspection, SessionLifecycleUpdate } from "./commands.js";
|
|
5
6
|
import type { ClaudeOutputAdapter } from "./outputAdapter.js";
|
|
6
7
|
import { type ClaudeSessionRepository } from "./repository.js";
|
|
7
8
|
import { ShellRunner } from "./shellRunner.js";
|
|
8
9
|
import { type BackgroundOutputReader } from "./backgroundOutput.js";
|
|
10
|
+
import { type CodexRolloutLocator } from "./codexRollout.js";
|
|
9
11
|
import type { TurnStartParams } from "../../codex/generated/v2/TurnStartParams.js";
|
|
10
12
|
import type { TurnSteerParams } from "../../codex/generated/v2/TurnSteerParams.js";
|
|
11
13
|
import type { ThreadBackgroundTerminal } from "../../codex/generated/v2/ThreadBackgroundTerminal.js";
|
|
@@ -36,6 +38,10 @@ export interface PreparedRuntimeTurn {
|
|
|
36
38
|
discard(): Promise<void>;
|
|
37
39
|
attach(turn: PreparedSessionTurn["turn"]): () => Promise<void>;
|
|
38
40
|
}
|
|
41
|
+
export declare class ActiveClaudeTurnError extends RpcError {
|
|
42
|
+
readonly turnId: string;
|
|
43
|
+
constructor(threadId: string, turnId: string);
|
|
44
|
+
}
|
|
39
45
|
export declare class ClaudeSession implements ClaudeSessionHandle<ClaudeSessionCommand> {
|
|
40
46
|
private readonly threadId;
|
|
41
47
|
private readonly repository;
|
|
@@ -47,6 +53,7 @@ export declare class ClaudeSession implements ClaudeSessionHandle<ClaudeSessionC
|
|
|
47
53
|
private readonly shellRunner;
|
|
48
54
|
private readonly backgroundOutputReader;
|
|
49
55
|
private readonly runtimeDependencies?;
|
|
56
|
+
private readonly codexRolloutLocator;
|
|
50
57
|
private readonly mailbox;
|
|
51
58
|
private readonly consumer;
|
|
52
59
|
private runtimeLineage;
|
|
@@ -63,6 +70,8 @@ export declare class ClaudeSession implements ClaudeSessionHandle<ClaudeSessionC
|
|
|
63
70
|
private runtimeGeneration;
|
|
64
71
|
private readonly scopes;
|
|
65
72
|
private readonly tasks;
|
|
73
|
+
private readonly codexMcpTailers;
|
|
74
|
+
private readonly codexRolloutClaims;
|
|
66
75
|
private compaction;
|
|
67
76
|
private automaticCompaction;
|
|
68
77
|
private readonly compactionActions;
|
|
@@ -93,7 +102,7 @@ export declare class ClaudeSession implements ClaudeSessionHandle<ClaudeSessionC
|
|
|
93
102
|
private hookDisplayOrder;
|
|
94
103
|
private adminOperation;
|
|
95
104
|
private shell;
|
|
96
|
-
constructor(threadId: string, repository: ClaudeSessionRepository, output: ClaudeOutputAdapter, capacity?: number, metrics?: MetricsRegistry, onLifecycle?: (update: SessionLifecycleUpdate) => void, onChildCreated?: (threadId: string) => void, onChildRemoved?: (threadId: string) => void, shellRunner?: ShellRunner, backgroundOutputReader?: BackgroundOutputReader, runtimeDependencies?: ClaudeSessionRuntimeDependencies | undefined);
|
|
105
|
+
constructor(threadId: string, repository: ClaudeSessionRepository, output: ClaudeOutputAdapter, capacity?: number, metrics?: MetricsRegistry, onLifecycle?: (update: SessionLifecycleUpdate) => void, onChildCreated?: (threadId: string) => void, onChildRemoved?: (threadId: string) => void, shellRunner?: ShellRunner, backgroundOutputReader?: BackgroundOutputReader, runtimeDependencies?: ClaudeSessionRuntimeDependencies | undefined, codexRolloutLocator?: CodexRolloutLocator);
|
|
97
106
|
submit<Result>(command: ClaudeSessionCommand): Promise<Result>;
|
|
98
107
|
private submitLineage;
|
|
99
108
|
private submitRuntimeEffect;
|
|
@@ -262,6 +271,11 @@ export declare class ClaudeSession implements ClaudeSessionHandle<ClaudeSessionC
|
|
|
262
271
|
private findTool;
|
|
263
272
|
private toolOwner;
|
|
264
273
|
private captureToolFileBefore;
|
|
274
|
+
private codexMcpCallBegin;
|
|
275
|
+
private ensureCodexRolloutTailer;
|
|
276
|
+
private drainCodexRollout;
|
|
277
|
+
private finishCodexRolloutTailer;
|
|
278
|
+
private stopCodexRolloutTailer;
|
|
265
279
|
private captureToolFileAfter;
|
|
266
280
|
private acceptHook;
|
|
267
281
|
private syncInteractionStatus;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { v7 as uuidv7 } from "uuid";
|
|
2
2
|
import { AsyncLocalStorage } from "node:async_hooks";
|
|
3
3
|
import { MetricsRegistry } from "../../observability/metrics.js";
|
|
4
|
-
import { invalidParams } from "../../protocol/errors.js";
|
|
4
|
+
import { invalidParams, RpcError } from "../../protocol/errors.js";
|
|
5
5
|
import { classifyClaudeResult, classifyClaudeRuntimeError, } from "../resultClassifier.js";
|
|
6
6
|
import { runtimeWorkspaceRoots, settingsGeneration, withSettingsFrom } from "../../store/HybridStore.js";
|
|
7
7
|
import { addUsage } from "./usage.js";
|
|
@@ -17,7 +17,9 @@ import { bindGoalTurn, consumeGoalContinuation, dispatchGoal, finishGoalTurn, go
|
|
|
17
17
|
import { ShellRunner } from "./shellRunner.js";
|
|
18
18
|
import { diffFile, snapshotFile } from "../fileSnapshots.js";
|
|
19
19
|
import { appendHookProgress, completeHookRun, startHookRun } from "../hookMapper.js";
|
|
20
|
+
import { stat } from "node:fs/promises";
|
|
20
21
|
import { readBackgroundOutput } from "./backgroundOutput.js";
|
|
22
|
+
import { CODEX_MCP_MESSAGE_LABEL, CODEX_MCP_PROMPT_LABEL, CODEX_MCP_REASONING_LABEL, CODEX_MCP_TOOLS, defaultCodexRolloutLocator, parseRolloutChunk, } from "./codexRollout.js";
|
|
21
23
|
import { createGoalMcpServer } from "../goalTools.js";
|
|
22
24
|
import { mapUserInput } from "../inputMapper.js";
|
|
23
25
|
import { bashCommandActions } from "../commandActions.js";
|
|
@@ -107,6 +109,13 @@ function commandLane(command) {
|
|
|
107
109
|
return "provider";
|
|
108
110
|
return "normal";
|
|
109
111
|
}
|
|
112
|
+
export class ActiveClaudeTurnError extends RpcError {
|
|
113
|
+
turnId;
|
|
114
|
+
constructor(threadId, turnId) {
|
|
115
|
+
super(-32602, `Thread '${threadId}' already has an active turn.`);
|
|
116
|
+
this.turnId = turnId;
|
|
117
|
+
}
|
|
118
|
+
}
|
|
110
119
|
export class ClaudeSession {
|
|
111
120
|
threadId;
|
|
112
121
|
repository;
|
|
@@ -118,6 +127,7 @@ export class ClaudeSession {
|
|
|
118
127
|
shellRunner;
|
|
119
128
|
backgroundOutputReader;
|
|
120
129
|
runtimeDependencies;
|
|
130
|
+
codexRolloutLocator;
|
|
121
131
|
mailbox;
|
|
122
132
|
consumer;
|
|
123
133
|
runtimeLineage = { state: "absent" };
|
|
@@ -134,6 +144,8 @@ export class ClaudeSession {
|
|
|
134
144
|
runtimeGeneration;
|
|
135
145
|
scopes = new Map();
|
|
136
146
|
tasks = new Map();
|
|
147
|
+
codexMcpTailers = new Map();
|
|
148
|
+
codexRolloutClaims = new Set();
|
|
137
149
|
compaction;
|
|
138
150
|
automaticCompaction;
|
|
139
151
|
compactionActions = [];
|
|
@@ -164,7 +176,7 @@ export class ClaudeSession {
|
|
|
164
176
|
hookDisplayOrder = 0;
|
|
165
177
|
adminOperation;
|
|
166
178
|
shell;
|
|
167
|
-
constructor(threadId, repository, output, capacity, metrics = new MetricsRegistry(), onLifecycle = () => undefined, onChildCreated = () => undefined, onChildRemoved = () => undefined, shellRunner = new ShellRunner(), backgroundOutputReader = readBackgroundOutput, runtimeDependencies) {
|
|
179
|
+
constructor(threadId, repository, output, capacity, metrics = new MetricsRegistry(), onLifecycle = () => undefined, onChildCreated = () => undefined, onChildRemoved = () => undefined, shellRunner = new ShellRunner(), backgroundOutputReader = readBackgroundOutput, runtimeDependencies, codexRolloutLocator = defaultCodexRolloutLocator()) {
|
|
168
180
|
this.threadId = threadId;
|
|
169
181
|
this.repository = repository;
|
|
170
182
|
this.output = output;
|
|
@@ -175,6 +187,7 @@ export class ClaudeSession {
|
|
|
175
187
|
this.shellRunner = shellRunner;
|
|
176
188
|
this.backgroundOutputReader = backgroundOutputReader;
|
|
177
189
|
this.runtimeDependencies = runtimeDependencies;
|
|
190
|
+
this.codexRolloutLocator = codexRolloutLocator;
|
|
178
191
|
this.mailbox = new ClaudeMailbox(capacity);
|
|
179
192
|
this.consumer = this.run();
|
|
180
193
|
}
|
|
@@ -769,6 +782,8 @@ export class ClaudeSession {
|
|
|
769
782
|
messageUuid,
|
|
770
783
|
});
|
|
771
784
|
if (staged.kind === "busy") {
|
|
785
|
+
if (staged.activeTurnId)
|
|
786
|
+
throw new ActiveClaudeTurnError(this.threadId, staged.activeTurnId);
|
|
772
787
|
throw invalidParams(`Thread '${this.threadId}' already has an active turn.`);
|
|
773
788
|
}
|
|
774
789
|
if (staged.kind === "stale") {
|
|
@@ -2089,6 +2104,15 @@ export class ClaudeSession {
|
|
|
2089
2104
|
toolName: input.tool_name,
|
|
2090
2105
|
input: toolInput,
|
|
2091
2106
|
});
|
|
2107
|
+
if (CODEX_MCP_TOOLS.has(input.tool_name)) {
|
|
2108
|
+
await this.submitProviderProjection(runtimeGeneration, {
|
|
2109
|
+
type: "codexMcpCallBegin",
|
|
2110
|
+
runtimeGeneration,
|
|
2111
|
+
providerId: toolUseId,
|
|
2112
|
+
...(input.agent_id ? { ownerProviderId: input.agent_id } : {}),
|
|
2113
|
+
input: toolInput,
|
|
2114
|
+
});
|
|
2115
|
+
}
|
|
2092
2116
|
}
|
|
2093
2117
|
if (policy.decision === "defer" || policy.decision === "ask")
|
|
2094
2118
|
return { continue: true };
|
|
@@ -2284,6 +2308,9 @@ export class ClaudeSession {
|
|
|
2284
2308
|
const backgroundId = backgroundTaskId(message);
|
|
2285
2309
|
const itemIds = [];
|
|
2286
2310
|
for (const result of toolResults(message)) {
|
|
2311
|
+
if (this.codexMcpTailers.has(result.toolUseId)) {
|
|
2312
|
+
await this.finishCodexRolloutTailer(result.toolUseId);
|
|
2313
|
+
}
|
|
2287
2314
|
const outputFile = backgroundOutputFile(result.output);
|
|
2288
2315
|
const projected = backgroundId
|
|
2289
2316
|
? await this.applyProviderMainStream(projection, runtimeGeneration, {
|
|
@@ -4061,7 +4088,10 @@ export class ClaudeSession {
|
|
|
4061
4088
|
return { kind: "staged" };
|
|
4062
4089
|
}
|
|
4063
4090
|
if (this.stagedRuntimeTurns.size)
|
|
4064
|
-
return {
|
|
4091
|
+
return {
|
|
4092
|
+
kind: "busy",
|
|
4093
|
+
activeTurnId: this.scopes.get(this.threadId)?.turnId ?? null,
|
|
4094
|
+
};
|
|
4065
4095
|
}
|
|
4066
4096
|
if (command.runtimeGeneration !== this.runtimeGeneration
|
|
4067
4097
|
|| command.settingsGeneration !== settingsGeneration(record)) {
|
|
@@ -4085,7 +4115,10 @@ export class ClaudeSession {
|
|
|
4085
4115
|
}
|
|
4086
4116
|
if (this.interruptFence || this.transportStopFence
|
|
4087
4117
|
|| this.lifecycle || this.compaction || record.thread.status.type === "active") {
|
|
4088
|
-
return {
|
|
4118
|
+
return {
|
|
4119
|
+
kind: "busy",
|
|
4120
|
+
activeTurnId: this.scopes.get(this.threadId)?.turnId ?? null,
|
|
4121
|
+
};
|
|
4089
4122
|
}
|
|
4090
4123
|
this.stagedRuntimeTurns.add(command.messageUuid);
|
|
4091
4124
|
this.emitLifecycle();
|
|
@@ -4248,6 +4281,8 @@ export class ClaudeSession {
|
|
|
4248
4281
|
}
|
|
4249
4282
|
case "captureToolFileBefore":
|
|
4250
4283
|
return this.captureToolFileBefore(command);
|
|
4284
|
+
case "codexMcpCallBegin":
|
|
4285
|
+
return this.codexMcpCallBegin(command);
|
|
4251
4286
|
case "captureToolFileAfter":
|
|
4252
4287
|
return this.captureToolFileAfter(command.runtimeGeneration, command.providerId);
|
|
4253
4288
|
case "hook":
|
|
@@ -5995,6 +6030,131 @@ export class ClaudeSession {
|
|
|
5995
6030
|
tool.fileSnapshot = snapshot;
|
|
5996
6031
|
return true;
|
|
5997
6032
|
}
|
|
6033
|
+
codexMcpCallBegin(command) {
|
|
6034
|
+
if (command.runtimeGeneration !== this.runtimeGeneration || this.interruptFence || this.dropLateFacts)
|
|
6035
|
+
return false;
|
|
6036
|
+
let owner = this.toolOwner(command.providerId);
|
|
6037
|
+
if (!owner && command.ownerProviderId) {
|
|
6038
|
+
owner = this.toolOwner(command.ownerProviderId);
|
|
6039
|
+
const task = [...this.tasks.values()].find((candidate) => taskUsesProvider(candidate, command.ownerProviderId) || candidate.taskId === command.ownerProviderId);
|
|
6040
|
+
if (task?.childThreadId)
|
|
6041
|
+
owner = this.scopes.get(task.childThreadId);
|
|
6042
|
+
}
|
|
6043
|
+
owner ??= this.scopes.get(this.threadId);
|
|
6044
|
+
if (!owner)
|
|
6045
|
+
return false;
|
|
6046
|
+
const prompt = typeof command.input.prompt === "string" ? command.input.prompt : "";
|
|
6047
|
+
if (prompt) {
|
|
6048
|
+
this.projectMainStream(owner.ownerThreadId, {
|
|
6049
|
+
kind: "instantAgent",
|
|
6050
|
+
text: `${CODEX_MCP_PROMPT_LABEL}\n\n${prompt}`,
|
|
6051
|
+
}, nullSource);
|
|
6052
|
+
}
|
|
6053
|
+
this.ensureCodexRolloutTailer(command.providerId, owner.ownerThreadId, typeof command.input.threadId === "string" ? command.input.threadId : undefined);
|
|
6054
|
+
return true;
|
|
6055
|
+
}
|
|
6056
|
+
ensureCodexRolloutTailer(providerId, ownerThreadId, codexThreadId) {
|
|
6057
|
+
if (this.codexMcpTailers.has(providerId))
|
|
6058
|
+
return;
|
|
6059
|
+
const runtimeGeneration = this.runtimeGeneration;
|
|
6060
|
+
if (runtimeGeneration === undefined)
|
|
6061
|
+
return;
|
|
6062
|
+
const tailer = {
|
|
6063
|
+
runtimeGeneration, ownerThreadId, codexThreadId,
|
|
6064
|
+
notBeforeMs: Date.now(), offset: 0, buffer: "",
|
|
6065
|
+
decoder: new TextDecoder(),
|
|
6066
|
+
timer: setInterval(() => { void this.drainCodexRollout(providerId).catch(() => undefined); }, 250),
|
|
6067
|
+
stopped: false, sawTurnComplete: false,
|
|
6068
|
+
};
|
|
6069
|
+
tailer.timer.unref();
|
|
6070
|
+
this.codexMcpTailers.set(providerId, tailer);
|
|
6071
|
+
void this.drainCodexRollout(providerId).catch(() => undefined);
|
|
6072
|
+
}
|
|
6073
|
+
async drainCodexRollout(providerId, final = false) {
|
|
6074
|
+
const tailer = this.codexMcpTailers.get(providerId);
|
|
6075
|
+
if (!tailer || tailer.stopped)
|
|
6076
|
+
return;
|
|
6077
|
+
if (tailer.reading) {
|
|
6078
|
+
const reading = tailer.reading;
|
|
6079
|
+
await reading;
|
|
6080
|
+
if (tailer.reading === reading)
|
|
6081
|
+
tailer.reading = undefined;
|
|
6082
|
+
if (final)
|
|
6083
|
+
await this.drainCodexRollout(providerId, true);
|
|
6084
|
+
return;
|
|
6085
|
+
}
|
|
6086
|
+
const reading = (async () => {
|
|
6087
|
+
if (!tailer.file) {
|
|
6088
|
+
if (tailer.codexThreadId) {
|
|
6089
|
+
// Continuation of an existing codex thread: the journal already holds
|
|
6090
|
+
// prior turns, so start from its current end.
|
|
6091
|
+
const file = this.codexRolloutLocator.byThreadId(tailer.codexThreadId);
|
|
6092
|
+
if (!file)
|
|
6093
|
+
return;
|
|
6094
|
+
tailer.offset = await stat(file).then((info) => info.size, () => 0);
|
|
6095
|
+
tailer.file = file;
|
|
6096
|
+
}
|
|
6097
|
+
else {
|
|
6098
|
+
const file = this.codexRolloutLocator.freshMcpSession(tailer.notBeforeMs, this.codexRolloutClaims);
|
|
6099
|
+
if (!file)
|
|
6100
|
+
return;
|
|
6101
|
+
tailer.file = file;
|
|
6102
|
+
}
|
|
6103
|
+
this.codexRolloutClaims.add(tailer.file);
|
|
6104
|
+
}
|
|
6105
|
+
tailer.offset = await this.backgroundOutputReader(tailer.file, tailer.offset, async (bytes) => {
|
|
6106
|
+
if (tailer.stopped)
|
|
6107
|
+
return;
|
|
6108
|
+
const { rest, events } = parseRolloutChunk(tailer.buffer, tailer.decoder.decode(bytes, { stream: true }));
|
|
6109
|
+
tailer.buffer = rest;
|
|
6110
|
+
for (const event of events) {
|
|
6111
|
+
if (event.kind === "turnComplete") {
|
|
6112
|
+
tailer.sawTurnComplete = true;
|
|
6113
|
+
continue;
|
|
6114
|
+
}
|
|
6115
|
+
await this.submit({
|
|
6116
|
+
type: "mainStream",
|
|
6117
|
+
runtimeGeneration: tailer.runtimeGeneration,
|
|
6118
|
+
ownerThreadId: tailer.ownerThreadId,
|
|
6119
|
+
source: { providerEventId: null, providerEventType: "codex_rollout" },
|
|
6120
|
+
fact: event.kind === "message"
|
|
6121
|
+
? { kind: "instantAgent", text: `${CODEX_MCP_MESSAGE_LABEL}\n\n${event.text}` }
|
|
6122
|
+
: { kind: "instantReasoning", text: `${CODEX_MCP_REASONING_LABEL}\n\n${event.text}` },
|
|
6123
|
+
});
|
|
6124
|
+
}
|
|
6125
|
+
});
|
|
6126
|
+
})();
|
|
6127
|
+
tailer.reading = reading;
|
|
6128
|
+
try {
|
|
6129
|
+
await reading;
|
|
6130
|
+
}
|
|
6131
|
+
finally {
|
|
6132
|
+
if (tailer.reading === reading)
|
|
6133
|
+
tailer.reading = undefined;
|
|
6134
|
+
}
|
|
6135
|
+
}
|
|
6136
|
+
async finishCodexRolloutTailer(providerId) {
|
|
6137
|
+
const tailer = this.codexMcpTailers.get(providerId);
|
|
6138
|
+
if (!tailer)
|
|
6139
|
+
return;
|
|
6140
|
+
for (let attempt = 0; attempt < 3 && !tailer.stopped; attempt += 1) {
|
|
6141
|
+
await this.drainCodexRollout(providerId, true).catch(() => undefined);
|
|
6142
|
+
if (tailer.sawTurnComplete)
|
|
6143
|
+
break;
|
|
6144
|
+
await new Promise((resolve) => setTimeout(resolve, 250));
|
|
6145
|
+
}
|
|
6146
|
+
this.stopCodexRolloutTailer(providerId);
|
|
6147
|
+
}
|
|
6148
|
+
stopCodexRolloutTailer(providerId) {
|
|
6149
|
+
const tailer = this.codexMcpTailers.get(providerId);
|
|
6150
|
+
if (!tailer)
|
|
6151
|
+
return;
|
|
6152
|
+
tailer.stopped = true;
|
|
6153
|
+
clearInterval(tailer.timer);
|
|
6154
|
+
if (tailer.file)
|
|
6155
|
+
this.codexRolloutClaims.delete(tailer.file);
|
|
6156
|
+
this.codexMcpTailers.delete(providerId);
|
|
6157
|
+
}
|
|
5998
6158
|
async captureToolFileAfter(runtimeGeneration, providerId) {
|
|
5999
6159
|
if (runtimeGeneration !== this.runtimeGeneration || this.interruptFence || this.dropLateFacts)
|
|
6000
6160
|
return false;
|
|
@@ -6299,6 +6459,19 @@ export class ClaudeSession {
|
|
|
6299
6459
|
itemIds = [item.id];
|
|
6300
6460
|
break;
|
|
6301
6461
|
}
|
|
6462
|
+
case "instantReasoning": {
|
|
6463
|
+
const item = { type: "reasoning", id: uuidv7(), summary: [fact.text], content: [] };
|
|
6464
|
+
turn.items.push(item);
|
|
6465
|
+
this.publishTurn(turn, "item/started", {
|
|
6466
|
+
item, threadId: state.ownerThreadId, turnId: turn.id, startedAtMs: Date.now(),
|
|
6467
|
+
}, source);
|
|
6468
|
+
this.publishTurn(turn, "item/reasoning/summaryTextDelta", {
|
|
6469
|
+
threadId: state.ownerThreadId, turnId: turn.id, itemId: item.id, delta: fact.text, summaryIndex: 0,
|
|
6470
|
+
}, source);
|
|
6471
|
+
this.completeStreamItem(turn, state, item.id, source);
|
|
6472
|
+
itemIds = [item.id];
|
|
6473
|
+
break;
|
|
6474
|
+
}
|
|
6302
6475
|
case "settle":
|
|
6303
6476
|
this.settleAgentMessages(turn, state, fact.phase, source);
|
|
6304
6477
|
break;
|
|
@@ -6431,8 +6604,10 @@ export class ClaudeSession {
|
|
|
6431
6604
|
if (itemIds.has(id))
|
|
6432
6605
|
state.blockItems.delete(index);
|
|
6433
6606
|
for (const [id, candidate] of state.tools)
|
|
6434
|
-
if (itemIds.has(candidate.itemId))
|
|
6607
|
+
if (itemIds.has(candidate.itemId)) {
|
|
6435
6608
|
state.tools.delete(id);
|
|
6609
|
+
this.stopCodexRolloutTailer(id);
|
|
6610
|
+
}
|
|
6436
6611
|
for (const [id, task] of this.tasks)
|
|
6437
6612
|
if (itemIds.has(task.itemId)) {
|
|
6438
6613
|
this.stopBackgroundTailer(task);
|
|
@@ -6535,6 +6710,8 @@ export class ClaudeSession {
|
|
|
6535
6710
|
disposeRuntimeOperations() {
|
|
6536
6711
|
for (const task of this.tasks.values())
|
|
6537
6712
|
this.stopBackgroundTailer(task);
|
|
6713
|
+
for (const providerId of [...this.codexMcpTailers.keys()])
|
|
6714
|
+
this.stopCodexRolloutTailer(providerId);
|
|
6538
6715
|
for (const state of this.scopes.values()) {
|
|
6539
6716
|
for (const tool of state.tools.values())
|
|
6540
6717
|
delete tool.fileSnapshot;
|