replicas-engine 0.1.792 → 0.1.794
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/src/{asp-host-PBOXFMW6.js → asp-host-7MK76RUF.js} +4 -4
- package/dist/src/{chunk-SXPLAER7.js → chunk-I7R6CFGP.js} +4 -4
- package/dist/src/{chunk-SAAXKNYR.js → chunk-OMD6VAVE.js} +2 -2
- package/dist/src/{chunk-FWOLDPOO.js → chunk-QLOVT464.js} +1 -1
- package/dist/src/{chunk-AG2K2YOL.js → chunk-TWYPZ3JQ.js} +3 -1
- package/dist/src/{chunk-4HOBB56C.js → chunk-W3VEIZU4.js} +2 -2
- package/dist/src/{chunk-4TBKZTNN.js → chunk-YTUHYLO6.js} +17 -14
- package/dist/src/command-protection-hook.js +3 -3
- package/dist/src/deepseek-command-protection-plugin.js +4 -4
- package/dist/src/headless-agent.js +2 -2
- package/dist/src/index.js +237 -89
- package/dist/src/post-tool-pr-hook.js +2 -2
- package/dist/src/relay-mcp.js +1 -1
- package/package.json +1 -1
|
@@ -5,11 +5,11 @@ import {
|
|
|
5
5
|
getCodexAspHost,
|
|
6
6
|
restartCodexAspHost,
|
|
7
7
|
restartCodexAspHostIfRunning
|
|
8
|
-
} from "./chunk-
|
|
9
|
-
import "./chunk-
|
|
10
|
-
import "./chunk-
|
|
8
|
+
} from "./chunk-I7R6CFGP.js";
|
|
9
|
+
import "./chunk-TWYPZ3JQ.js";
|
|
10
|
+
import "./chunk-W3VEIZU4.js";
|
|
11
11
|
import "./chunk-UZSNFLDQ.js";
|
|
12
|
-
import "./chunk-
|
|
12
|
+
import "./chunk-YTUHYLO6.js";
|
|
13
13
|
import "./chunk-VEQXQN22.js";
|
|
14
14
|
export {
|
|
15
15
|
getCodexAspHost,
|
|
@@ -5,18 +5,18 @@ import {
|
|
|
5
5
|
ENGINE_ENV,
|
|
6
6
|
monolithRequest,
|
|
7
7
|
setAgentCredentialSnapshot
|
|
8
|
-
} from "./chunk-
|
|
8
|
+
} from "./chunk-TWYPZ3JQ.js";
|
|
9
9
|
import {
|
|
10
10
|
AppServerProcess,
|
|
11
11
|
buildCodexAgentEnv
|
|
12
|
-
} from "./chunk-
|
|
12
|
+
} from "./chunk-W3VEIZU4.js";
|
|
13
13
|
import {
|
|
14
14
|
CODEX_AUTH_ENV_KEYS,
|
|
15
15
|
CODEX_AUTH_ENV_KEYS_BY_METHOD,
|
|
16
16
|
codexAuthEnvFromResponse,
|
|
17
17
|
createErrorResult,
|
|
18
18
|
createSuccessResult
|
|
19
|
-
} from "./chunk-
|
|
19
|
+
} from "./chunk-YTUHYLO6.js";
|
|
20
20
|
|
|
21
21
|
// src/managers/codex-token-manager.ts
|
|
22
22
|
import { promises as fs } from "fs";
|
|
@@ -232,7 +232,7 @@ var CodexTokenManager = class extends BaseRefreshManager {
|
|
|
232
232
|
const data = await response.json();
|
|
233
233
|
await this.applyCredentialsResponse(data);
|
|
234
234
|
if (restartOnChange && CODEX_AUTH_ENV_KEYS.some((key, index) => process.env[key] !== previousEnv[index])) {
|
|
235
|
-
const { restartCodexAspHostIfRunning: restartCodexAspHostIfRunning2 } = await import("./asp-host-
|
|
235
|
+
const { restartCodexAspHostIfRunning: restartCodexAspHostIfRunning2 } = await import("./asp-host-7MK76RUF.js");
|
|
236
236
|
await restartCodexAspHostIfRunning2();
|
|
237
237
|
}
|
|
238
238
|
if (data.scope) {
|
|
@@ -3,12 +3,12 @@ import { createRequire as __createRequire } from 'node:module';
|
|
|
3
3
|
const require = __createRequire(import.meta.url);
|
|
4
4
|
import {
|
|
5
5
|
monolithRequest
|
|
6
|
-
} from "./chunk-
|
|
6
|
+
} from "./chunk-TWYPZ3JQ.js";
|
|
7
7
|
import {
|
|
8
8
|
extractCommandProtectionCommandText,
|
|
9
9
|
findGitCommitSignals,
|
|
10
10
|
findPrMergeSignals
|
|
11
|
-
} from "./chunk-
|
|
11
|
+
} from "./chunk-YTUHYLO6.js";
|
|
12
12
|
|
|
13
13
|
// src/services/command-protection-service.ts
|
|
14
14
|
var DEFAULT_COMMAND_PROTECTION_BLOCK_MESSAGE = "Blocked by Replicas command protection.";
|
|
@@ -4,7 +4,7 @@ const require = __createRequire(import.meta.url);
|
|
|
4
4
|
import {
|
|
5
5
|
findCodeHostPullRequestUrls,
|
|
6
6
|
mayCreatePullRequest
|
|
7
|
-
} from "./chunk-
|
|
7
|
+
} from "./chunk-YTUHYLO6.js";
|
|
8
8
|
|
|
9
9
|
// src/services/post-tool-pr-notifier.ts
|
|
10
10
|
async function notifyPostToolUse(toolName, toolInput, toolResult) {
|
|
@@ -15,7 +15,7 @@ import {
|
|
|
15
15
|
isValidRelayBaseProvider,
|
|
16
16
|
parsePosixEnvFile,
|
|
17
17
|
readReplicasRuntimeEnv
|
|
18
|
-
} from "./chunk-
|
|
18
|
+
} from "./chunk-YTUHYLO6.js";
|
|
19
19
|
|
|
20
20
|
// src/engine-env.ts
|
|
21
21
|
import { readFileSync as readFileSync2 } from "fs";
|
|
@@ -112,10 +112,12 @@ var IS_WARMING_MODE = process.argv.includes("--warming");
|
|
|
112
112
|
function loadEngineEnv() {
|
|
113
113
|
loadRuntimeEnvFile();
|
|
114
114
|
const HOME_DIR = homedir2();
|
|
115
|
+
const backgroundTaskTimeoutMs = Number(readEnv("REPLICAS_CLAUDE_BACKGROUND_TASK_TIMEOUT_MS"));
|
|
115
116
|
const env = {
|
|
116
117
|
// Defined: always available
|
|
117
118
|
REPLICAS_ENGINE_SECRET: requireDefined(readEnv("REPLICAS_ENGINE_SECRET"), "REPLICAS_ENGINE_SECRET"),
|
|
118
119
|
REPLICAS_ENGINE_PORT: parsePort(readEnv("REPLICAS_ENGINE_PORT")),
|
|
120
|
+
REPLICAS_CLAUDE_BACKGROUND_TASK_TIMEOUT_MS: Number.isInteger(backgroundTaskTimeoutMs) && backgroundTaskTimeoutMs >= 1e3 && backgroundTaskTimeoutMs <= 2147483647 ? backgroundTaskTimeoutMs : 36e5,
|
|
119
121
|
REPLICAS_MONOLITH_URL: requireValidURL(
|
|
120
122
|
requireDefined(readReplicasRuntimeEnv(readEnv, REPLICAS_RUNTIME_ENV_ALIASES.monolithUrl), "REPLICAS_MONOLITH_URL"),
|
|
121
123
|
"REPLICAS_MONOLITH_URL"
|
|
@@ -4,7 +4,7 @@ const require = __createRequire(import.meta.url);
|
|
|
4
4
|
import {
|
|
5
5
|
HOOK_EXEC_MAX_BUFFER_BYTES,
|
|
6
6
|
isVersionBelow
|
|
7
|
-
} from "./chunk-
|
|
7
|
+
} from "./chunk-YTUHYLO6.js";
|
|
8
8
|
|
|
9
9
|
// src/utils/codex-agent-env.ts
|
|
10
10
|
function buildCodexAgentEnv(source = process.env) {
|
|
@@ -241,7 +241,7 @@ var DEFAULT_CODEX_ARGS = [
|
|
|
241
241
|
var MIN_CODEX_CLI_VERSION = "0.153.3";
|
|
242
242
|
var CODEX_UPGRADE_TIMEOUT_MS = 12e4;
|
|
243
243
|
var codexCliVersionEnsured = null;
|
|
244
|
-
var ENGINE_PACKAGE_VERSION = "0.1.
|
|
244
|
+
var ENGINE_PACKAGE_VERSION = "0.1.794";
|
|
245
245
|
var INITIALIZE_METHOD = "initialize";
|
|
246
246
|
var INITIALIZED_NOTIFICATION = "initialized";
|
|
247
247
|
var ACCOUNT_LOGIN_START_METHOD = "account/login/start";
|
|
@@ -153,7 +153,7 @@ var GPT_5_6_TERRA_MODEL = "gpt-5.6-terra";
|
|
|
153
153
|
var GPT_5_6_LUNA_MODEL = "gpt-5.6-luna";
|
|
154
154
|
var DEFAULT_CODEX_MODEL = GPT_5_6_SOL_MODEL;
|
|
155
155
|
var DEFAULT_CURSOR_MODEL = "composer-2.5";
|
|
156
|
-
var DEFAULT_OPENCODE_MODEL = "z-ai/glm-5.
|
|
156
|
+
var DEFAULT_OPENCODE_MODEL = "z-ai/glm-5.3";
|
|
157
157
|
var GLM_5_3_FLASH_MODEL = "z-ai/glm-5.3-flash";
|
|
158
158
|
var OX_ALPHA_MODEL = "stealth/ox-alpha";
|
|
159
159
|
var DEEPSEEK_V4_PRO_MODEL = "deepseek/deepseek-v4-pro-0813";
|
|
@@ -164,17 +164,22 @@ var DEFAULT_KIMI_MODEL = "moonshotai/kimi-k2.6";
|
|
|
164
164
|
var MUSE_SPARK_1_3_MODEL = "muse-spark-1.3";
|
|
165
165
|
var DEFAULT_MUSE_MODEL = "muse-spark-1.2";
|
|
166
166
|
var DEFAULT_PI_MODEL = DEFAULT_OPENCODE_MODEL;
|
|
167
|
-
var
|
|
167
|
+
var DEFAULT_OPENROUTER_MODELS = [
|
|
168
168
|
DEFAULT_OPENCODE_MODEL,
|
|
169
|
+
DEEPSEEK_V4_PRO_MODEL,
|
|
170
|
+
"moonshotai/kimi-k3",
|
|
171
|
+
"google/gemini-3.8-flash"
|
|
172
|
+
];
|
|
173
|
+
var OPENROUTER_MODELS = [
|
|
174
|
+
...DEFAULT_OPENROUTER_MODELS,
|
|
175
|
+
"z-ai/glm-5.2",
|
|
176
|
+
"moonshotai/kimi-k2.6",
|
|
169
177
|
GLM_5_3_FLASH_MODEL,
|
|
170
178
|
OX_ALPHA_MODEL,
|
|
171
|
-
DEEPSEEK_V4_PRO_MODEL,
|
|
172
179
|
DEEPSEEK_V4_FLASH_MODEL,
|
|
173
180
|
"minimax/minimax-m3",
|
|
174
181
|
"xiaomi/mimo-v2.5-pro",
|
|
175
|
-
"
|
|
176
|
-
"meta/muse-spark-1.3",
|
|
177
|
-
"google/gemini-3.8-flash"
|
|
182
|
+
"meta/muse-spark-1.3"
|
|
178
183
|
];
|
|
179
184
|
function prioritizeDeepseekModels(models) {
|
|
180
185
|
return [
|
|
@@ -283,12 +288,12 @@ var AGENT_MODELS = {
|
|
|
283
288
|
CLAUDE_HAIKU_4_5_MODEL,
|
|
284
289
|
"kimi-k2.5"
|
|
285
290
|
],
|
|
286
|
-
deepseek: prioritizeDeepseekModels(
|
|
291
|
+
deepseek: prioritizeDeepseekModels(DEFAULT_OPENROUTER_MODELS),
|
|
287
292
|
fx: [DEFAULT_FX_MODEL],
|
|
288
293
|
kimi: [DEFAULT_KIMI_MODEL],
|
|
289
294
|
muse: [MUSE_SPARK_1_3_MODEL, DEFAULT_MUSE_MODEL],
|
|
290
|
-
opencode: [...
|
|
291
|
-
pi: [...
|
|
295
|
+
opencode: [...DEFAULT_OPENROUTER_MODELS, ...ASTER_MODELS],
|
|
296
|
+
pi: [...DEFAULT_OPENROUTER_MODELS, ...ASTER_MODELS],
|
|
292
297
|
relay: [CLAUDE_FABLE_5_1_MODEL, CLAUDE_FABLE_5_MODEL, CLAUDE_OPUS_5_MODEL, CLAUDE_OPUS_4_8_MODEL, CLAUDE_SONNET_5_MODEL]
|
|
293
298
|
};
|
|
294
299
|
var DEFAULT_STATIC_AGENT_MODELS = {
|
|
@@ -322,7 +327,8 @@ var MODEL_LABELS = {
|
|
|
322
327
|
[GPT_5_6_TERRA_MODEL]: "GPT-5.6 Terra",
|
|
323
328
|
[GPT_5_6_LUNA_MODEL]: "GPT-5.6 Luna",
|
|
324
329
|
"gpt-5.5": "GPT-5.5",
|
|
325
|
-
[DEFAULT_OPENCODE_MODEL]: "GLM 5.
|
|
330
|
+
[DEFAULT_OPENCODE_MODEL]: "GLM 5.3 via OpenRouter",
|
|
331
|
+
"z-ai/glm-5.2": "GLM 5.2 via OpenRouter",
|
|
326
332
|
[GLM_5_3_FLASH_MODEL]: "GLM 5.3 Flash via OpenRouter",
|
|
327
333
|
[OX_ALPHA_MODEL]: "Ox Alpha via OpenRouter",
|
|
328
334
|
[DEEPSEEK_V4_PRO_MODEL]: "DeepSeek V4 Pro via OpenRouter",
|
|
@@ -330,6 +336,7 @@ var MODEL_LABELS = {
|
|
|
330
336
|
"minimax/minimax-m3": "MiniMax M3 via OpenRouter",
|
|
331
337
|
"xiaomi/mimo-v2.5-pro": "MiMo V2.5 Pro via OpenRouter",
|
|
332
338
|
"moonshotai/kimi-k2.6": "Kimi K2.6 via OpenRouter",
|
|
339
|
+
"moonshotai/kimi-k3": "Kimi K3 via OpenRouter",
|
|
333
340
|
[MUSE_SPARK_1_3_MODEL]: "Muse Spark 1.3",
|
|
334
341
|
[DEFAULT_MUSE_MODEL]: "Muse Spark 1.2",
|
|
335
342
|
"meta/muse-spark-1.3": "Muse Spark 1.3 via OpenRouter",
|
|
@@ -1499,9 +1506,6 @@ function normalizeBackgroundTaskStatus(status) {
|
|
|
1499
1506
|
}
|
|
1500
1507
|
return "in_progress";
|
|
1501
1508
|
}
|
|
1502
|
-
function isTerminalBackgroundTaskStatus(status) {
|
|
1503
|
-
return normalizeBackgroundTaskStatus(status) !== "in_progress";
|
|
1504
|
-
}
|
|
1505
1509
|
|
|
1506
1510
|
// ../shared/src/display-message/constants.ts
|
|
1507
1511
|
var USER_MESSAGE_MATCH_GRACE_PERIOD_MS = 3e4;
|
|
@@ -7703,7 +7707,6 @@ export {
|
|
|
7703
7707
|
getChatHistoryPageWindow,
|
|
7704
7708
|
paginateChatHistory,
|
|
7705
7709
|
coerceBackgroundTaskPayload,
|
|
7706
|
-
isTerminalBackgroundTaskStatus,
|
|
7707
7710
|
isGitHubUrl,
|
|
7708
7711
|
decodePathSegments,
|
|
7709
7712
|
extractErrorText,
|
|
@@ -3,12 +3,12 @@ import { createRequire as __createRequire } from 'node:module';
|
|
|
3
3
|
const require = __createRequire(import.meta.url);
|
|
4
4
|
import {
|
|
5
5
|
evaluateCommandProtection
|
|
6
|
-
} from "./chunk-
|
|
7
|
-
import "./chunk-
|
|
6
|
+
} from "./chunk-OMD6VAVE.js";
|
|
7
|
+
import "./chunk-TWYPZ3JQ.js";
|
|
8
8
|
import {
|
|
9
9
|
isRecord
|
|
10
10
|
} from "./chunk-UZSNFLDQ.js";
|
|
11
|
-
import "./chunk-
|
|
11
|
+
import "./chunk-YTUHYLO6.js";
|
|
12
12
|
import "./chunk-VEQXQN22.js";
|
|
13
13
|
|
|
14
14
|
// src/command-protection-hook.ts
|
|
@@ -3,13 +3,13 @@ import { createRequire as __createRequire } from 'node:module';
|
|
|
3
3
|
const require = __createRequire(import.meta.url);
|
|
4
4
|
import {
|
|
5
5
|
evaluateCommandProtection
|
|
6
|
-
} from "./chunk-
|
|
6
|
+
} from "./chunk-OMD6VAVE.js";
|
|
7
7
|
import {
|
|
8
8
|
notifyPostToolUse
|
|
9
|
-
} from "./chunk-
|
|
10
|
-
import "./chunk-
|
|
9
|
+
} from "./chunk-QLOVT464.js";
|
|
10
|
+
import "./chunk-TWYPZ3JQ.js";
|
|
11
11
|
import "./chunk-UZSNFLDQ.js";
|
|
12
|
-
import "./chunk-
|
|
12
|
+
import "./chunk-YTUHYLO6.js";
|
|
13
13
|
import "./chunk-VEQXQN22.js";
|
|
14
14
|
|
|
15
15
|
// src/deepseek-command-protection-plugin.ts
|
|
@@ -8,12 +8,12 @@ import {
|
|
|
8
8
|
import {
|
|
9
9
|
AppServerProcess,
|
|
10
10
|
buildCodexAgentEnv
|
|
11
|
-
} from "./chunk-
|
|
11
|
+
} from "./chunk-W3VEIZU4.js";
|
|
12
12
|
import {
|
|
13
13
|
AGENT,
|
|
14
14
|
getMemoryOutputSafetyViolation,
|
|
15
15
|
headlessAgentRequestSchema
|
|
16
|
-
} from "./chunk-
|
|
16
|
+
} from "./chunk-YTUHYLO6.js";
|
|
17
17
|
import "./chunk-VEQXQN22.js";
|
|
18
18
|
|
|
19
19
|
// src/headless-agent.ts
|
package/dist/src/index.js
CHANGED
|
@@ -91,7 +91,7 @@ import {
|
|
|
91
91
|
evaluateCommandProtection,
|
|
92
92
|
extractToolCommand,
|
|
93
93
|
reportCommandProtectionBlock
|
|
94
|
-
} from "./chunk-
|
|
94
|
+
} from "./chunk-OMD6VAVE.js";
|
|
95
95
|
import {
|
|
96
96
|
ACCOUNT_RATE_LIMITS_UPDATED_METHOD,
|
|
97
97
|
AGENT_MESSAGE_DELTA_METHOD,
|
|
@@ -124,20 +124,20 @@ import {
|
|
|
124
124
|
recordCredentialFallback,
|
|
125
125
|
recordExhaustedCredential,
|
|
126
126
|
restartCodexAspHost
|
|
127
|
-
} from "./chunk-
|
|
127
|
+
} from "./chunk-I7R6CFGP.js";
|
|
128
128
|
import {
|
|
129
129
|
ENGINE_ENV,
|
|
130
130
|
IS_WARMING_MODE,
|
|
131
131
|
monolithRequest,
|
|
132
132
|
monolithService,
|
|
133
133
|
setAgentCredentialSnapshot
|
|
134
|
-
} from "./chunk-
|
|
134
|
+
} from "./chunk-TWYPZ3JQ.js";
|
|
135
135
|
import {
|
|
136
136
|
AspClient,
|
|
137
137
|
SUBPROCESS_MAX_BUFFER,
|
|
138
138
|
execAsync,
|
|
139
139
|
execFileAsync
|
|
140
|
-
} from "./chunk-
|
|
140
|
+
} from "./chunk-W3VEIZU4.js";
|
|
141
141
|
import {
|
|
142
142
|
isRecord as isRecord2
|
|
143
143
|
} from "./chunk-UZSNFLDQ.js";
|
|
@@ -298,7 +298,6 @@ import {
|
|
|
298
298
|
isNonEmptyString,
|
|
299
299
|
isRecord,
|
|
300
300
|
isSkillRegistryManifest,
|
|
301
|
-
isTerminalBackgroundTaskStatus,
|
|
302
301
|
isTokenUsageCounts,
|
|
303
302
|
isTokenUsageUploadRecord,
|
|
304
303
|
isTransientErrorText,
|
|
@@ -338,7 +337,7 @@ import {
|
|
|
338
337
|
spawnRelaySubagentRequestSchema,
|
|
339
338
|
stripAgentDiagnosticErrors,
|
|
340
339
|
withTimeout
|
|
341
|
-
} from "./chunk-
|
|
340
|
+
} from "./chunk-YTUHYLO6.js";
|
|
342
341
|
import {
|
|
343
342
|
__commonJS,
|
|
344
343
|
__export,
|
|
@@ -12494,16 +12493,65 @@ function updateClaudeSessionActivity(activity, message) {
|
|
|
12494
12493
|
function isClaudeSessionActive(activity) {
|
|
12495
12494
|
return activity.state !== "idle";
|
|
12496
12495
|
}
|
|
12497
|
-
|
|
12498
|
-
|
|
12499
|
-
|
|
12500
|
-
|
|
12501
|
-
|
|
12502
|
-
|
|
12503
|
-
|
|
12504
|
-
|
|
12505
|
-
|
|
12506
|
-
|
|
12496
|
+
|
|
12497
|
+
// src/managers/claude-background-tasks.ts
|
|
12498
|
+
var ClaudeBackgroundTasks = class {
|
|
12499
|
+
active = /* @__PURE__ */ new Map();
|
|
12500
|
+
persistentMonitors = /* @__PURE__ */ new Set();
|
|
12501
|
+
reset() {
|
|
12502
|
+
this.active.clear();
|
|
12503
|
+
this.persistentMonitors.clear();
|
|
12504
|
+
}
|
|
12505
|
+
update(message, now = Date.now()) {
|
|
12506
|
+
if (message.type === "assistant") {
|
|
12507
|
+
for (const block of message.message.content) {
|
|
12508
|
+
if (block.type === "tool_use" && block.name === "Monitor" && typeof block.input === "object" && block.input !== null && "persistent" in block.input && block.input.persistent === true) {
|
|
12509
|
+
this.persistentMonitors.add(block.id);
|
|
12510
|
+
}
|
|
12511
|
+
}
|
|
12512
|
+
return;
|
|
12513
|
+
}
|
|
12514
|
+
if (message.type !== "system") return;
|
|
12515
|
+
if (message.subtype === "background_tasks_changed") {
|
|
12516
|
+
const liveIds = /* @__PURE__ */ new Set();
|
|
12517
|
+
for (const task2 of message.tasks) {
|
|
12518
|
+
if (task2.ambient) continue;
|
|
12519
|
+
liveIds.add(task2.task_id);
|
|
12520
|
+
const existing = this.active.get(task2.task_id);
|
|
12521
|
+
this.active.set(task2.task_id, {
|
|
12522
|
+
...existing,
|
|
12523
|
+
description: task2.description,
|
|
12524
|
+
startedAt: existing?.startedAt ?? now,
|
|
12525
|
+
persistentMonitor: existing?.persistentMonitor || this.persistentMonitors.has(task2.task_id)
|
|
12526
|
+
});
|
|
12527
|
+
}
|
|
12528
|
+
for (const id of this.active.keys()) {
|
|
12529
|
+
if (!liveIds.has(id)) {
|
|
12530
|
+
this.active.delete(id);
|
|
12531
|
+
this.persistentMonitors.delete(id);
|
|
12532
|
+
}
|
|
12533
|
+
}
|
|
12534
|
+
return;
|
|
12535
|
+
}
|
|
12536
|
+
const payload = coerceBackgroundTaskPayload(message);
|
|
12537
|
+
if (!payload) return;
|
|
12538
|
+
const toolUseId = "tool_use_id" in message ? message.tool_use_id : void 0;
|
|
12539
|
+
if (toolUseId && this.persistentMonitors.has(toolUseId)) {
|
|
12540
|
+
this.persistentMonitors.add(payload.taskId);
|
|
12541
|
+
this.persistentMonitors.delete(toolUseId);
|
|
12542
|
+
}
|
|
12543
|
+
const status = payload.subtype === "task_updated" ? payload.patch?.status : payload.status;
|
|
12544
|
+
const task = this.active.get(payload.taskId);
|
|
12545
|
+
if (!task) return;
|
|
12546
|
+
task.description = payload.description ?? payload.patch?.description ?? task.description;
|
|
12547
|
+
task.persistentMonitor ||= this.persistentMonitors.has(payload.taskId);
|
|
12548
|
+
if (status === "paused") task.pausedAt ??= now;
|
|
12549
|
+
else if (status === "running" && task.pausedAt !== void 0) {
|
|
12550
|
+
task.startedAt += now - task.pausedAt;
|
|
12551
|
+
task.pausedAt = void 0;
|
|
12552
|
+
}
|
|
12553
|
+
}
|
|
12554
|
+
};
|
|
12507
12555
|
|
|
12508
12556
|
// src/managers/relay-mcp-config.ts
|
|
12509
12557
|
import { existsSync as existsSync7 } from "fs";
|
|
@@ -12540,7 +12588,6 @@ function relayCodexMcpConfig(parentChatId) {
|
|
|
12540
12588
|
}
|
|
12541
12589
|
|
|
12542
12590
|
// src/managers/claude-manager.ts
|
|
12543
|
-
var CLAUDE_ACTIVITY_STATUS_EVENT_TYPE = "claude-activity-status";
|
|
12544
12591
|
var PromptStream = class {
|
|
12545
12592
|
queue = [];
|
|
12546
12593
|
closed = false;
|
|
@@ -12629,7 +12676,9 @@ var COMMAND_PROTECTION_SAFE_TOOLS = /* @__PURE__ */ new Set([
|
|
|
12629
12676
|
var CLAUDE_PARTIAL_MESSAGE_FLUSH_MS = 80;
|
|
12630
12677
|
var CLAUDE_SLASH_COMMANDS_CACHE_MS = 6e4;
|
|
12631
12678
|
var CLAUDE_SLASH_COMMANDS_DISCOVERY_TIMEOUT_MS = 3e4;
|
|
12632
|
-
var CLAUDE_BACKGROUND_CONTINUATION_GRACE_MS =
|
|
12679
|
+
var CLAUDE_BACKGROUND_CONTINUATION_GRACE_MS = 1e4;
|
|
12680
|
+
var CLAUDE_BACKGROUND_RECOVERY_START_TIMEOUT_MS = 6e4;
|
|
12681
|
+
var CLAUDE_BACKGROUND_STOP_TIMEOUT_MS = 5e3;
|
|
12633
12682
|
function supportsClaudeThinkingDisplay(model) {
|
|
12634
12683
|
const normalized = (normalizeClaudeModel(model) ?? model).toLowerCase();
|
|
12635
12684
|
return AGENT_MODELS.claude.includes(normalized) || /^claude-(?:opus|sonnet|haiku)-[4-9]/.test(normalized);
|
|
@@ -12784,8 +12833,10 @@ var ClaudeManager = class _ClaudeManager extends CodingAgentManager {
|
|
|
12784
12833
|
sessionActivity = createClaudeSessionActivity();
|
|
12785
12834
|
backgroundContinuationTimer = null;
|
|
12786
12835
|
pendingInterrupt = false;
|
|
12787
|
-
|
|
12788
|
-
|
|
12836
|
+
backgroundTasks = new ClaudeBackgroundTasks();
|
|
12837
|
+
backgroundWatchdogTimer = null;
|
|
12838
|
+
backgroundRecoveryAttempted = false;
|
|
12839
|
+
backgroundWatchdogTriggered = false;
|
|
12789
12840
|
// Set when background tasks outlive a turn; cleared once their completion
|
|
12790
12841
|
// has been reported through onTurnComplete.
|
|
12791
12842
|
pendingBackgroundCompletion = false;
|
|
@@ -12808,13 +12859,8 @@ var ClaudeManager = class _ClaudeManager extends CodingAgentManager {
|
|
|
12808
12859
|
}
|
|
12809
12860
|
async interruptActiveTurn() {
|
|
12810
12861
|
this.pendingInterrupt = true;
|
|
12811
|
-
const query2 = this.activeQuery;
|
|
12812
|
-
if (query2) {
|
|
12813
|
-
const taskIds = [...this.activeBackgroundTasks];
|
|
12814
|
-
await Promise.allSettled(taskIds.map((taskId) => query2.stopTask(taskId)));
|
|
12815
|
-
await query2.interrupt();
|
|
12816
|
-
}
|
|
12817
12862
|
await this.abortAllPendingToolInputs();
|
|
12863
|
+
await this.tearDownSession(true);
|
|
12818
12864
|
}
|
|
12819
12865
|
keepSteeredMessageQueued() {
|
|
12820
12866
|
return true;
|
|
@@ -12844,10 +12890,10 @@ var ClaudeManager = class _ClaudeManager extends CodingAgentManager {
|
|
|
12844
12890
|
return this.authRetrying;
|
|
12845
12891
|
}
|
|
12846
12892
|
isProcessing() {
|
|
12847
|
-
return super.isProcessing() || isClaudeSessionActive(this.sessionActivity) || this.
|
|
12893
|
+
return super.isProcessing() || isClaudeSessionActive(this.sessionActivity) || this.hasActiveBackgroundTasks();
|
|
12848
12894
|
}
|
|
12849
12895
|
hasActiveBackgroundTasks() {
|
|
12850
|
-
return this.
|
|
12896
|
+
return this.backgroundTasks.active.size > 0 || this.pendingBackgroundCompletion && (isClaudeSessionActive(this.sessionActivity) || this.backgroundContinuationTimer !== null) && !this.messageQueue.isProcessing();
|
|
12851
12897
|
}
|
|
12852
12898
|
async listSlashCommands() {
|
|
12853
12899
|
await this.initialized;
|
|
@@ -13212,8 +13258,10 @@ var ClaudeManager = class _ClaudeManager extends CodingAgentManager {
|
|
|
13212
13258
|
});
|
|
13213
13259
|
}
|
|
13214
13260
|
}
|
|
13261
|
+
const userMessageUuid = randomUUID5();
|
|
13215
13262
|
const userMessage = {
|
|
13216
13263
|
type: "user",
|
|
13264
|
+
uuid: userMessageUuid,
|
|
13217
13265
|
message: {
|
|
13218
13266
|
role: "user",
|
|
13219
13267
|
content
|
|
@@ -13224,7 +13272,10 @@ var ClaudeManager = class _ClaudeManager extends CodingAgentManager {
|
|
|
13224
13272
|
if (!options.skipUserMessageRecord) {
|
|
13225
13273
|
await this.recordEvent(userMessage, request.messageId);
|
|
13226
13274
|
}
|
|
13227
|
-
const combinedInstructions =
|
|
13275
|
+
const combinedInstructions = [
|
|
13276
|
+
this.buildCombinedInstructions(customInstructions, true),
|
|
13277
|
+
"Background tasks must have a concrete completion condition. Use foreground commands for sequential work and managed workspace services for servers. Reserve persistent Monitor tasks for ongoing watches the user requested. You may end a turn while actual background work continues, but do not promise a later update unless a task was successfully launched. Report completion or failure when its notification arrives; do not restart timed-out work automatically."
|
|
13278
|
+
].filter(Boolean).join("\n\n");
|
|
13228
13279
|
const resolvedModel = normalizeClaudeModel(model) || DEFAULT_CLAUDE_MODEL;
|
|
13229
13280
|
const claudeCodeModel = toClaudeCodeModel(resolvedModel);
|
|
13230
13281
|
const resolvedPermissionMode = planMode ? "plan" : "bypassPermissions";
|
|
@@ -13257,7 +13308,7 @@ var ClaudeManager = class _ClaudeManager extends CodingAgentManager {
|
|
|
13257
13308
|
return;
|
|
13258
13309
|
}
|
|
13259
13310
|
await new Promise((resolve7, reject) => {
|
|
13260
|
-
this.pendingTurn = { resolve: resolve7, reject, sawActivity: false };
|
|
13311
|
+
this.pendingTurn = { resolve: resolve7, reject, sawActivity: false, userMessageUuid };
|
|
13261
13312
|
promptStream.push(userMessage);
|
|
13262
13313
|
});
|
|
13263
13314
|
}
|
|
@@ -13403,10 +13454,6 @@ var ClaudeManager = class _ClaudeManager extends CodingAgentManager {
|
|
|
13403
13454
|
this.activeSessionModel = claudeCodeModel;
|
|
13404
13455
|
this.activeSessionPermissionMode = resolvedPermissionMode;
|
|
13405
13456
|
this.sessionLinearForwarder = new LinearEventForwarder(ENGINE_ENV.REPLICAS_LINEAR_SESSION_ID);
|
|
13406
|
-
this.activeBackgroundTasks.clear();
|
|
13407
|
-
this.ambientBackgroundTasks.clear();
|
|
13408
|
-
this.clearBackgroundContinuationTimer();
|
|
13409
|
-
resetClaudeSessionActivity(this.sessionActivity);
|
|
13410
13457
|
this.sessionLoop = this.runSessionLoop(response).catch((err) => {
|
|
13411
13458
|
console.error("[ClaudeManager] Session loop crashed:", err);
|
|
13412
13459
|
});
|
|
@@ -13424,7 +13471,7 @@ var ClaudeManager = class _ClaudeManager extends CodingAgentManager {
|
|
|
13424
13471
|
try {
|
|
13425
13472
|
while (true) {
|
|
13426
13473
|
const next = await iterator.next();
|
|
13427
|
-
if (next.done) break;
|
|
13474
|
+
if (next.done || this.activeQuery !== response) break;
|
|
13428
13475
|
const msg = next.value;
|
|
13429
13476
|
if (!msg) break;
|
|
13430
13477
|
const authErrorMessage = _ClaudeManager.detectAuthErrorInMessage(msg);
|
|
@@ -13465,27 +13512,32 @@ var ClaudeManager = class _ClaudeManager extends CodingAgentManager {
|
|
|
13465
13512
|
if (this.pendingTurn && _ClaudeManager.isTurnActivity(msg)) {
|
|
13466
13513
|
this.pendingTurn.sawActivity = true;
|
|
13467
13514
|
}
|
|
13468
|
-
if (msg.type === "result"
|
|
13515
|
+
if (msg.type === "result" && (msg.subtype !== "success" || msg.num_turns !== 0 || msg.result !== "") || _ClaudeManager.isTurnActivity(msg)) {
|
|
13469
13516
|
this.clearBackgroundContinuationTimer();
|
|
13470
13517
|
}
|
|
13471
13518
|
updateClaudeSessionActivity(this.sessionActivity, msg);
|
|
13472
|
-
const hadActiveBackgroundTasks = this.
|
|
13473
|
-
|
|
13474
|
-
|
|
13519
|
+
const hadActiveBackgroundTasks = this.backgroundTasks.active.size > 0;
|
|
13520
|
+
this.backgroundTasks.update(msg);
|
|
13521
|
+
this.scheduleBackgroundWatchdog();
|
|
13522
|
+
if (hadActiveBackgroundTasks && this.backgroundTasks.active.size === 0) {
|
|
13475
13523
|
this.startBackgroundContinuationGrace();
|
|
13476
13524
|
}
|
|
13477
|
-
if (!this.pendingTurn && this.
|
|
13525
|
+
if (!this.pendingTurn && this.backgroundTasks.active.size > 0) {
|
|
13478
13526
|
this.pendingBackgroundCompletion = true;
|
|
13479
13527
|
}
|
|
13480
13528
|
await this.handleMessage(msg);
|
|
13529
|
+
if (this.activeQuery !== response) break;
|
|
13481
13530
|
if (linearSessionId && this.sessionLinearForwarder) {
|
|
13482
13531
|
this.sessionLinearForwarder.processClaudeEventForPlan(msg);
|
|
13483
13532
|
this.sessionLinearForwarder.sendEvent(convertClaudeEvent(msg, linearSessionId));
|
|
13484
13533
|
}
|
|
13485
13534
|
if (msg.type === "result") {
|
|
13486
13535
|
await this.recordContextUsage(response);
|
|
13536
|
+
if (this.activeQuery !== response) break;
|
|
13487
13537
|
this.sessionLinearForwarder?.flushThoughtAsResponse();
|
|
13488
|
-
this.
|
|
13538
|
+
if (msg.user_message_uuid ? msg.user_message_uuid === this.pendingTurn?.userMessageUuid : !msg.origin || msg.origin.kind === "human") {
|
|
13539
|
+
this.resolvePendingTurn();
|
|
13540
|
+
}
|
|
13489
13541
|
}
|
|
13490
13542
|
this.maybeCompleteBackgroundTurn();
|
|
13491
13543
|
}
|
|
@@ -13498,6 +13550,7 @@ var ClaudeManager = class _ClaudeManager extends CodingAgentManager {
|
|
|
13498
13550
|
console.error("[ClaudeManager] Session loop crashed:", error);
|
|
13499
13551
|
}
|
|
13500
13552
|
} finally {
|
|
13553
|
+
if (this.activeQuery !== response) return;
|
|
13501
13554
|
const pending = this.pendingTurn;
|
|
13502
13555
|
const pendingError = loopError ? pending?.sawActivity && _ClaudeManager.isTransientTurnError(loopError) ? new ClaudeTransientTurnError("Claude session ended unexpectedly mid-response", true) : loopError : pending && !pending.sawActivity ? new ClaudeTransientTurnError("Claude session ended unexpectedly before producing a response") : new Error("Claude session ended unexpectedly");
|
|
13503
13556
|
if (_ClaudeManager.isTransientTurnError(pendingError) || _ClaudeManager.isAuthError(pendingError)) {
|
|
@@ -13507,12 +13560,15 @@ var ClaudeManager = class _ClaudeManager extends CodingAgentManager {
|
|
|
13507
13560
|
this.sessionLinearForwarder?.flushThoughtAsResponse();
|
|
13508
13561
|
}
|
|
13509
13562
|
this.failPendingTurn(pendingError);
|
|
13510
|
-
|
|
13511
|
-
|
|
13512
|
-
|
|
13513
|
-
|
|
13514
|
-
|
|
13515
|
-
|
|
13563
|
+
const orphanedBackgroundCompletion = this.pendingBackgroundCompletion && !this.messageQueue.isProcessing();
|
|
13564
|
+
this.settleBackgroundTasks("Claude session ended before this task completed.");
|
|
13565
|
+
this.clearSessionState();
|
|
13566
|
+
try {
|
|
13567
|
+
response.close();
|
|
13568
|
+
} catch {
|
|
13569
|
+
}
|
|
13570
|
+
if (orphanedBackgroundCompletion) {
|
|
13571
|
+
this.notifyBackgroundTurnComplete();
|
|
13516
13572
|
}
|
|
13517
13573
|
}
|
|
13518
13574
|
}
|
|
@@ -13526,8 +13582,10 @@ var ClaudeManager = class _ClaudeManager extends CodingAgentManager {
|
|
|
13526
13582
|
this.sessionLoop = null;
|
|
13527
13583
|
this.clearBackgroundContinuationTimer();
|
|
13528
13584
|
resetClaudeSessionActivity(this.sessionActivity);
|
|
13529
|
-
this.
|
|
13530
|
-
this.
|
|
13585
|
+
this.backgroundTasks.reset();
|
|
13586
|
+
this.clearBackgroundWatchdog();
|
|
13587
|
+
this.backgroundRecoveryAttempted = false;
|
|
13588
|
+
this.backgroundWatchdogTriggered = false;
|
|
13531
13589
|
this.pendingBackgroundCompletion = false;
|
|
13532
13590
|
for (const timer of this.partialMessageFlushTimers.values()) {
|
|
13533
13591
|
clearTimeout(timer);
|
|
@@ -13540,12 +13598,14 @@ var ClaudeManager = class _ClaudeManager extends CodingAgentManager {
|
|
|
13540
13598
|
if (!pending) return;
|
|
13541
13599
|
this.pendingTurn = null;
|
|
13542
13600
|
this.pendingInterrupt = false;
|
|
13543
|
-
this.pendingBackgroundCompletion = this.
|
|
13601
|
+
this.pendingBackgroundCompletion = this.backgroundTasks.active.size > 0 || this.backgroundContinuationTimer !== null;
|
|
13602
|
+
if (!this.pendingBackgroundCompletion) this.backgroundWatchdogTriggered = false;
|
|
13544
13603
|
pending.resolve();
|
|
13545
13604
|
}
|
|
13546
13605
|
maybeCompleteBackgroundTurn() {
|
|
13547
|
-
if (!this.pendingBackgroundCompletion || this.pendingTurn || this.messageQueue.isProcessing() || this.
|
|
13606
|
+
if (!this.pendingBackgroundCompletion || this.pendingTurn || this.messageQueue.isProcessing() || this.backgroundTasks.active.size > 0 || this.backgroundContinuationTimer !== null || isClaudeSessionActive(this.sessionActivity)) return;
|
|
13548
13607
|
this.pendingBackgroundCompletion = false;
|
|
13608
|
+
this.backgroundWatchdogTriggered = false;
|
|
13549
13609
|
this.notifyBackgroundTurnComplete();
|
|
13550
13610
|
}
|
|
13551
13611
|
notifyBackgroundTurnComplete() {
|
|
@@ -13562,24 +13622,128 @@ var ClaudeManager = class _ClaudeManager extends CodingAgentManager {
|
|
|
13562
13622
|
}
|
|
13563
13623
|
startBackgroundContinuationGrace() {
|
|
13564
13624
|
this.clearBackgroundContinuationTimer();
|
|
13565
|
-
|
|
13566
|
-
this.
|
|
13567
|
-
|
|
13568
|
-
|
|
13569
|
-
|
|
13570
|
-
|
|
13571
|
-
|
|
13625
|
+
const query2 = this.activeQuery;
|
|
13626
|
+
if (!query2 || this.pendingInterrupt) return;
|
|
13627
|
+
this.backgroundRecoveryAttempted = false;
|
|
13628
|
+
this.backgroundContinuationTimer = setTimeout(() => this.recoverBackgroundContinuation(query2), CLAUDE_BACKGROUND_CONTINUATION_GRACE_MS);
|
|
13629
|
+
}
|
|
13630
|
+
recoverBackgroundContinuation(query2) {
|
|
13631
|
+
if (this.activeQuery !== query2) return;
|
|
13632
|
+
this.backgroundContinuationTimer = null;
|
|
13633
|
+
if (!this.pendingBackgroundCompletion || this.pendingInterrupt) return;
|
|
13634
|
+
if (this.backgroundTasks.active.size > 0) return;
|
|
13635
|
+
if (this.sessionActivity.state === "running" && !this.pendingTurn) return;
|
|
13636
|
+
if (this.pendingTurn || this.messageQueue.isProcessing() || this.isAwaitingInput() || this.sessionActivity.state === "requires_action") {
|
|
13637
|
+
this.backgroundContinuationTimer = setTimeout(() => this.recoverBackgroundContinuation(query2), CLAUDE_BACKGROUND_CONTINUATION_GRACE_MS);
|
|
13638
|
+
return;
|
|
13639
|
+
}
|
|
13640
|
+
if (this.backgroundRecoveryAttempted) {
|
|
13641
|
+
void this.failBackgroundSession(query2, "Claude did not resume after its background tasks finished. The session was stopped; send a message to continue.");
|
|
13642
|
+
return;
|
|
13643
|
+
}
|
|
13644
|
+
this.backgroundRecoveryAttempted = true;
|
|
13645
|
+
this.activePromptStream?.push({
|
|
13646
|
+
type: "user",
|
|
13647
|
+
uuid: randomUUID5(),
|
|
13648
|
+
isSynthetic: true,
|
|
13649
|
+
session_id: this.sessionId ?? "",
|
|
13650
|
+
parent_tool_use_id: null,
|
|
13651
|
+
message: {
|
|
13652
|
+
role: "user",
|
|
13653
|
+
content: `${this.backgroundWatchdogTriggered ? "Replicas cancelled background work because it exceeded its time limit; this was a watchdog cancellation, not a user cancellation. " : ""}Your background tasks have finished. Process their completion notifications and report the actual results. Continue only work that remains from the user request; do not repeat completed actions or restart finished tasks.`
|
|
13654
|
+
}
|
|
13655
|
+
});
|
|
13656
|
+
this.backgroundContinuationTimer = setTimeout(() => this.recoverBackgroundContinuation(query2), CLAUDE_BACKGROUND_RECOVERY_START_TIMEOUT_MS);
|
|
13657
|
+
}
|
|
13658
|
+
clearBackgroundWatchdog() {
|
|
13659
|
+
if (this.backgroundWatchdogTimer) clearTimeout(this.backgroundWatchdogTimer);
|
|
13660
|
+
this.backgroundWatchdogTimer = null;
|
|
13661
|
+
}
|
|
13662
|
+
scheduleBackgroundWatchdog() {
|
|
13663
|
+
this.clearBackgroundWatchdog();
|
|
13664
|
+
const query2 = this.activeQuery;
|
|
13665
|
+
if (!query2) return;
|
|
13666
|
+
let deadline = Infinity;
|
|
13667
|
+
for (const task of this.backgroundTasks.active.values()) {
|
|
13668
|
+
if (task.stopRequestedAt !== void 0) {
|
|
13669
|
+
deadline = Math.min(deadline, task.stopRequestedAt + CLAUDE_BACKGROUND_STOP_TIMEOUT_MS);
|
|
13670
|
+
} else if (task.pausedAt === void 0 && !task.persistentMonitor) {
|
|
13671
|
+
deadline = Math.min(deadline, task.startedAt + ENGINE_ENV.REPLICAS_CLAUDE_BACKGROUND_TASK_TIMEOUT_MS);
|
|
13672
|
+
}
|
|
13673
|
+
}
|
|
13674
|
+
if (!Number.isFinite(deadline)) return;
|
|
13675
|
+
this.backgroundWatchdogTimer = setTimeout(() => this.checkBackgroundTasks(query2), Math.max(0, deadline - Date.now()));
|
|
13676
|
+
}
|
|
13677
|
+
checkBackgroundTasks(query2) {
|
|
13678
|
+
if (this.activeQuery !== query2) return;
|
|
13679
|
+
this.backgroundWatchdogTimer = null;
|
|
13680
|
+
const now = Date.now();
|
|
13681
|
+
for (const [id, task] of this.backgroundTasks.active) {
|
|
13682
|
+
if (task.stopRequestedAt !== void 0) {
|
|
13683
|
+
if (now - task.stopRequestedAt >= CLAUDE_BACKGROUND_STOP_TIMEOUT_MS) {
|
|
13684
|
+
void this.failBackgroundSession(query2, "A background task did not stop after reaching its time limit. Claude and its remaining tasks were stopped; send a message to continue.");
|
|
13685
|
+
return;
|
|
13686
|
+
}
|
|
13687
|
+
continue;
|
|
13688
|
+
}
|
|
13689
|
+
if (task.pausedAt !== void 0 || task.persistentMonitor || now - task.startedAt < ENGINE_ENV.REPLICAS_CLAUDE_BACKGROUND_TASK_TIMEOUT_MS) continue;
|
|
13690
|
+
if (this.isAwaitingInput() || this.sessionActivity.state === "requires_action") {
|
|
13691
|
+
task.startedAt = now;
|
|
13692
|
+
continue;
|
|
13693
|
+
}
|
|
13694
|
+
task.stopRequestedAt = now;
|
|
13695
|
+
if (!this.backgroundWatchdogTriggered) {
|
|
13696
|
+
this.backgroundWatchdogTriggered = true;
|
|
13697
|
+
this.activePromptStream?.push({
|
|
13698
|
+
type: "user",
|
|
13699
|
+
uuid: randomUUID5(),
|
|
13700
|
+
isSynthetic: true,
|
|
13701
|
+
shouldQuery: false,
|
|
13702
|
+
session_id: this.sessionId ?? "",
|
|
13703
|
+
parent_tool_use_id: null,
|
|
13704
|
+
message: {
|
|
13705
|
+
role: "user",
|
|
13706
|
+
content: "Replicas is cancelling background work that exceeded its execution time limit. Report its stop notifications as watchdog timeouts, not user cancellations. Do not restart timed-out work unless the user asks."
|
|
13707
|
+
}
|
|
13708
|
+
});
|
|
13709
|
+
}
|
|
13710
|
+
void this.recordEvent({
|
|
13711
|
+
type: "system",
|
|
13712
|
+
subtype: "task_updated",
|
|
13713
|
+
task_id: id,
|
|
13714
|
+
uuid: randomUUID5(),
|
|
13715
|
+
session_id: this.sessionId ?? "",
|
|
13716
|
+
patch: { description: task.description, error: "Background task exceeded its execution time limit. Replicas requested cancellation." }
|
|
13717
|
+
});
|
|
13718
|
+
void query2.stopTask(id).catch((error) => {
|
|
13719
|
+
console.warn("[ClaudeManager] Background task stop failed:", error);
|
|
13720
|
+
});
|
|
13721
|
+
}
|
|
13722
|
+
this.scheduleBackgroundWatchdog();
|
|
13723
|
+
}
|
|
13724
|
+
async failBackgroundSession(query2, message) {
|
|
13725
|
+
if (this.activeQuery !== query2) return;
|
|
13726
|
+
await this.emitTerminalErrorResult(message, [message]);
|
|
13727
|
+
await this.abortAllPendingToolInputs();
|
|
13728
|
+
if (this.activeQuery === query2) await this.tearDownSession();
|
|
13729
|
+
}
|
|
13730
|
+
async dispose() {
|
|
13731
|
+
await this.abortAllPendingToolInputs();
|
|
13732
|
+
await this.tearDownSession();
|
|
13572
13733
|
}
|
|
13573
13734
|
clearBackgroundContinuationTimer() {
|
|
13574
13735
|
if (!this.backgroundContinuationTimer) return;
|
|
13575
13736
|
clearTimeout(this.backgroundContinuationTimer);
|
|
13576
13737
|
this.backgroundContinuationTimer = null;
|
|
13577
13738
|
}
|
|
13578
|
-
async tearDownSession() {
|
|
13739
|
+
async tearDownSession(interrupted = false) {
|
|
13579
13740
|
const query2 = this.activeQuery;
|
|
13580
13741
|
const stream = this.activePromptStream;
|
|
13581
13742
|
const loop = this.sessionLoop;
|
|
13582
|
-
this.
|
|
13743
|
+
const notifyCompletion = this.pendingBackgroundCompletion && !this.messageQueue.isProcessing();
|
|
13744
|
+
this.settleBackgroundTasks();
|
|
13745
|
+
if (interrupted) this.resolvePendingTurn();
|
|
13746
|
+
else this.failPendingTurn(new Error("Claude session torn down"));
|
|
13583
13747
|
this.clearSessionState();
|
|
13584
13748
|
if (query2) {
|
|
13585
13749
|
try {
|
|
@@ -13595,34 +13759,18 @@ var ClaudeManager = class _ClaudeManager extends CodingAgentManager {
|
|
|
13595
13759
|
} catch {
|
|
13596
13760
|
}
|
|
13597
13761
|
}
|
|
13762
|
+
if (notifyCompletion) this.notifyBackgroundTurnComplete();
|
|
13598
13763
|
}
|
|
13599
|
-
|
|
13600
|
-
|
|
13601
|
-
|
|
13602
|
-
|
|
13603
|
-
|
|
13604
|
-
|
|
13605
|
-
|
|
13606
|
-
|
|
13607
|
-
|
|
13608
|
-
|
|
13609
|
-
activeTasks.clear();
|
|
13610
|
-
for (const task of message.tasks) {
|
|
13611
|
-
if (task.ambient) ambientTasks.add(task.task_id);
|
|
13612
|
-
else ambientTasks.delete(task.task_id);
|
|
13613
|
-
if (!task.ambient) activeTasks.add(task.task_id);
|
|
13614
|
-
}
|
|
13615
|
-
return;
|
|
13616
|
-
}
|
|
13617
|
-
const payload = coerceBackgroundTaskPayload(message);
|
|
13618
|
-
if (!payload) return;
|
|
13619
|
-
if (payload.ambient === true) ambientTasks.add(payload.taskId);
|
|
13620
|
-
else if (payload.ambient === false) ambientTasks.delete(payload.taskId);
|
|
13621
|
-
const status = payload.subtype === "task_updated" ? payload.patch?.status : payload.status;
|
|
13622
|
-
if (isTerminalBackgroundTaskStatus(status) || ambientTasks.has(payload.taskId)) {
|
|
13623
|
-
activeTasks.delete(payload.taskId);
|
|
13624
|
-
} else {
|
|
13625
|
-
activeTasks.add(payload.taskId);
|
|
13764
|
+
settleBackgroundTasks(error) {
|
|
13765
|
+
for (const taskId of this.backgroundTasks.active.keys()) {
|
|
13766
|
+
void this.recordEvent({
|
|
13767
|
+
type: "system",
|
|
13768
|
+
subtype: "task_updated",
|
|
13769
|
+
task_id: taskId,
|
|
13770
|
+
uuid: randomUUID5(),
|
|
13771
|
+
session_id: this.sessionId ?? "",
|
|
13772
|
+
patch: { status: error ? "failed" : "killed", ...error ? { error } : {} }
|
|
13773
|
+
});
|
|
13626
13774
|
}
|
|
13627
13775
|
}
|
|
13628
13776
|
buildContextUsagePayload(usage) {
|
|
@@ -13705,7 +13853,7 @@ var ClaudeManager = class _ClaudeManager extends CodingAgentManager {
|
|
|
13705
13853
|
return null;
|
|
13706
13854
|
}
|
|
13707
13855
|
static isTurnActivity(message) {
|
|
13708
|
-
return message.type === "assistant" || message.type === "stream_event";
|
|
13856
|
+
return (message.type === "assistant" || message.type === "stream_event") && message.parent_tool_use_id === null;
|
|
13709
13857
|
}
|
|
13710
13858
|
// Done at the message-stream layer (rather than letting the failure flow
|
|
13711
13859
|
// downstream as a normal result) so we can suppress emission before the
|
|
@@ -62454,7 +62602,7 @@ var ChatService = class {
|
|
|
62454
62602
|
}
|
|
62455
62603
|
}).catch(() => {
|
|
62456
62604
|
});
|
|
62457
|
-
if (event.type === "replicas-tool-input-request" || event.type === "replicas-tool-input-resolved" || event.type === "compaction-status" || event.type === AUTH_RETRY_STATUS_EVENT_TYPE || event.type === AUTH_FALLBACK_EVENT_TYPE || event.type === CURSOR_CONNECTION_STATUS_EVENT_TYPE || event.type === CHAT_GOAL_EVENT_TYPE || event.type ===
|
|
62605
|
+
if (event.type === "replicas-tool-input-request" || event.type === "replicas-tool-input-resolved" || event.type === "compaction-status" || event.type === AUTH_RETRY_STATUS_EVENT_TYPE || event.type === AUTH_FALLBACK_EVENT_TYPE || event.type === CURSOR_CONNECTION_STATUS_EVENT_TYPE || event.type === CHAT_GOAL_EVENT_TYPE || event.type === "claude-result" || event.type === "claude-system" && (event.payload.subtype === "init" || event.payload.subtype === "session_state_changed" || event.payload.subtype === "background_tasks_changed" || coerceBackgroundTaskPayload(event.payload) !== null)) {
|
|
62458
62606
|
this.publish({
|
|
62459
62607
|
type: "chat.updated",
|
|
62460
62608
|
payload: { chat: this.toSummary(chat) }
|
|
@@ -3,11 +3,11 @@ import { createRequire as __createRequire } from 'node:module';
|
|
|
3
3
|
const require = __createRequire(import.meta.url);
|
|
4
4
|
import {
|
|
5
5
|
notifyPostToolUse
|
|
6
|
-
} from "./chunk-
|
|
6
|
+
} from "./chunk-QLOVT464.js";
|
|
7
7
|
import {
|
|
8
8
|
isRecord
|
|
9
9
|
} from "./chunk-UZSNFLDQ.js";
|
|
10
|
-
import "./chunk-
|
|
10
|
+
import "./chunk-YTUHYLO6.js";
|
|
11
11
|
import "./chunk-VEQXQN22.js";
|
|
12
12
|
|
|
13
13
|
// src/post-tool-pr-hook.ts
|
package/dist/src/relay-mcp.js
CHANGED