replicas-engine 0.1.1186 → 0.1.1188
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-J4AUGWDZ.js → asp-host-LSWA5KWR.js} +2 -2
- package/dist/src/{chunk-KLHDCQAK.js → chunk-DCCLTZ2Z.js} +21 -11
- package/dist/src/{chunk-NQOV2YOZ.js → chunk-TBMJWQJX.js} +1 -1
- package/dist/src/{chunk-WIEXE5ZC.js → chunk-WJLWPHUO.js} +1 -1
- package/dist/src/headless-agent.js +2 -2
- package/dist/src/index.js +133 -24
- package/package.json +1 -1
|
@@ -8,9 +8,9 @@ import {
|
|
|
8
8
|
listRunningCodexModels,
|
|
9
9
|
restartCodexAspHost,
|
|
10
10
|
restartCodexAspHostIfRunning
|
|
11
|
-
} from "./chunk-
|
|
11
|
+
} from "./chunk-DCCLTZ2Z.js";
|
|
12
12
|
import "./chunk-VXPWAQR2.js";
|
|
13
|
-
import "./chunk-
|
|
13
|
+
import "./chunk-WJLWPHUO.js";
|
|
14
14
|
import "./chunk-R6I3LT27.js";
|
|
15
15
|
import "./chunk-UZSNFLDQ.js";
|
|
16
16
|
import "./chunk-4T2K6OBK.js";
|
|
@@ -14,7 +14,7 @@ import {
|
|
|
14
14
|
import {
|
|
15
15
|
AppServerProcess,
|
|
16
16
|
buildCodexAgentEnv
|
|
17
|
-
} from "./chunk-
|
|
17
|
+
} from "./chunk-WJLWPHUO.js";
|
|
18
18
|
import {
|
|
19
19
|
SUBPROCESS_MAX_BUFFER,
|
|
20
20
|
execFileAsync
|
|
@@ -291,7 +291,7 @@ var CodexTokenManager = class extends BaseRefreshManager {
|
|
|
291
291
|
await this.applyCredentialUpdate(++this.credentialGeneration, async () => {
|
|
292
292
|
await this.applyCredentialsResponse(data);
|
|
293
293
|
setAgentCredentialSnapshot("codex", data);
|
|
294
|
-
const { restartCodexAspHostIfRunning: restartCodexAspHostIfRunning2 } = await import("./asp-host-
|
|
294
|
+
const { restartCodexAspHostIfRunning: restartCodexAspHostIfRunning2 } = await import("./asp-host-LSWA5KWR.js");
|
|
295
295
|
await restartCodexAspHostIfRunning2();
|
|
296
296
|
});
|
|
297
297
|
await this.start(true);
|
|
@@ -313,7 +313,7 @@ var CodexTokenManager = class extends BaseRefreshManager {
|
|
|
313
313
|
const accountChanged = ENGINE_ENV.REPLICAS_AGENT_CREDENTIALS.codex?.credentialId !== data.credentialId;
|
|
314
314
|
await this.applyCredentialsResponse(data);
|
|
315
315
|
if (restartOnChange && (accountChanged || CODEX_AUTH_ENV_KEYS.some((key, index) => process.env[key] !== previousEnv[index]))) {
|
|
316
|
-
const { restartCodexAspHostIfRunning: restartCodexAspHostIfRunning2 } = await import("./asp-host-
|
|
316
|
+
const { restartCodexAspHostIfRunning: restartCodexAspHostIfRunning2 } = await import("./asp-host-LSWA5KWR.js");
|
|
317
317
|
await restartCodexAspHostIfRunning2();
|
|
318
318
|
}
|
|
319
319
|
setAgentCredentialSnapshot("codex", data);
|
|
@@ -1274,13 +1274,15 @@ async function normalizeImages(images) {
|
|
|
1274
1274
|
if (image.source.type === "base64") {
|
|
1275
1275
|
normalized.push({
|
|
1276
1276
|
type: "image",
|
|
1277
|
-
source: image.source
|
|
1277
|
+
source: image.source,
|
|
1278
|
+
label: image.label
|
|
1278
1279
|
});
|
|
1279
1280
|
} else if (image.source.type === "url") {
|
|
1280
1281
|
const base64Source = await fetchImageAsBase64(image.source.url);
|
|
1281
1282
|
normalized.push({
|
|
1282
1283
|
type: "image",
|
|
1283
|
-
source: base64Source
|
|
1284
|
+
source: base64Source,
|
|
1285
|
+
label: image.label
|
|
1284
1286
|
});
|
|
1285
1287
|
}
|
|
1286
1288
|
}
|
|
@@ -1829,16 +1831,24 @@ async function buildTurnInput(request) {
|
|
|
1829
1831
|
}
|
|
1830
1832
|
const normalizedImages = await normalizeImages(request.images);
|
|
1831
1833
|
const tempImagePaths = await saveNormalizedImagesToTempFiles(normalizedImages);
|
|
1832
|
-
input.push(...tempImagePaths.
|
|
1833
|
-
|
|
1834
|
-
path: path2
|
|
1835
|
-
}))
|
|
1834
|
+
input.push(...tempImagePaths.flatMap((path2, index) => {
|
|
1835
|
+
const label = normalizedImages[index].label;
|
|
1836
|
+
return [...label ? [{ type: "text", text: label, text_elements: [] }] : [], { type: "localImage", path: path2 }];
|
|
1837
|
+
}));
|
|
1836
1838
|
return { input, tempImagePaths };
|
|
1837
1839
|
}
|
|
1838
|
-
async function buildTurnStartParams(threadId, request, serviceTier) {
|
|
1840
|
+
async function buildTurnStartParams(threadId, request, serviceTier, unreadRequests) {
|
|
1839
1841
|
const effort = toReasoningEffort(request.thinkingLevel);
|
|
1840
1842
|
const model = request.model ?? DEFAULT_MODEL;
|
|
1841
|
-
const
|
|
1843
|
+
const built = [];
|
|
1844
|
+
try {
|
|
1845
|
+
for (const turn of [...unreadRequests, request]) built.push(await buildTurnInput(turn));
|
|
1846
|
+
} catch (error) {
|
|
1847
|
+
await removeTempImageFiles(built.flatMap((turn) => turn.tempImagePaths));
|
|
1848
|
+
throw error;
|
|
1849
|
+
}
|
|
1850
|
+
const input = built.flatMap((turn) => turn.input);
|
|
1851
|
+
const tempImagePaths = built.flatMap((turn) => turn.tempImagePaths);
|
|
1842
1852
|
const { mothershipInstructions } = splitMothershipInstructions(request.customInstructions);
|
|
1843
1853
|
return {
|
|
1844
1854
|
params: {
|
|
@@ -240,7 +240,7 @@ function getCodexModelProvider(method) {
|
|
|
240
240
|
if (method === "foundry") return "azure";
|
|
241
241
|
return method === "ollama" || method === "openai-compatible" ? "replicas_openai_compatible" : "openai";
|
|
242
242
|
}
|
|
243
|
-
var ENGINE_PACKAGE_VERSION = "0.1.
|
|
243
|
+
var ENGINE_PACKAGE_VERSION = "0.1.1188";
|
|
244
244
|
var INITIALIZE_METHOD = "initialize";
|
|
245
245
|
var INITIALIZED_NOTIFICATION = "initialized";
|
|
246
246
|
var ACCOUNT_LOGIN_START_METHOD = "account/login/start";
|
|
@@ -13,11 +13,11 @@ import {
|
|
|
13
13
|
recoverCompletedTurn,
|
|
14
14
|
spawnMuseMsp,
|
|
15
15
|
startMuseSession
|
|
16
|
-
} from "./chunk-
|
|
16
|
+
} from "./chunk-TBMJWQJX.js";
|
|
17
17
|
import {
|
|
18
18
|
AppServerProcess,
|
|
19
19
|
buildCodexAgentEnv
|
|
20
|
-
} from "./chunk-
|
|
20
|
+
} from "./chunk-WJLWPHUO.js";
|
|
21
21
|
import "./chunk-R6I3LT27.js";
|
|
22
22
|
import {
|
|
23
23
|
AGENT,
|
package/dist/src/index.js
CHANGED
|
@@ -64,7 +64,7 @@ import {
|
|
|
64
64
|
spawnMuseMsp,
|
|
65
65
|
startMuseSession,
|
|
66
66
|
uuidV7
|
|
67
|
-
} from "./chunk-
|
|
67
|
+
} from "./chunk-TBMJWQJX.js";
|
|
68
68
|
import {
|
|
69
69
|
publishedPullRequestUrls
|
|
70
70
|
} from "./chunk-NIT22CZW.js";
|
|
@@ -139,7 +139,7 @@ import {
|
|
|
139
139
|
timestampFromSeconds,
|
|
140
140
|
upsertCredentialFileLines,
|
|
141
141
|
writeSecureCredentialFile
|
|
142
|
-
} from "./chunk-
|
|
142
|
+
} from "./chunk-DCCLTZ2Z.js";
|
|
143
143
|
import {
|
|
144
144
|
ENGINE_ENV,
|
|
145
145
|
monolithRequest,
|
|
@@ -151,7 +151,7 @@ import {
|
|
|
151
151
|
} from "./chunk-VXPWAQR2.js";
|
|
152
152
|
import {
|
|
153
153
|
getCodexModelProvider
|
|
154
|
-
} from "./chunk-
|
|
154
|
+
} from "./chunk-WJLWPHUO.js";
|
|
155
155
|
import {
|
|
156
156
|
SUBPROCESS_MAX_BUFFER,
|
|
157
157
|
execAsync,
|
|
@@ -9630,6 +9630,7 @@ var EnvironmentDetailsService = class {
|
|
|
9630
9630
|
details.supportsClaudeGoals = true;
|
|
9631
9631
|
details.supportsGoalUpdates = true;
|
|
9632
9632
|
details.supportsQueuedMessageEditing = true;
|
|
9633
|
+
details.supportsQueueEvents = true;
|
|
9633
9634
|
details.supportsChatForking = true;
|
|
9634
9635
|
details.supportsChatForkMessage = true;
|
|
9635
9636
|
details.supportsDeferredChatForking = true;
|
|
@@ -10614,6 +10615,7 @@ function insertChronologically(existing, additions) {
|
|
|
10614
10615
|
|
|
10615
10616
|
// src/managers/claude-manager.ts
|
|
10616
10617
|
import {
|
|
10618
|
+
getSessionMessages,
|
|
10617
10619
|
query
|
|
10618
10620
|
} from "@anthropic-ai/claude-agent-sdk";
|
|
10619
10621
|
import { randomUUID as randomUUID4 } from "crypto";
|
|
@@ -11158,6 +11160,7 @@ var MessageQueueService = class {
|
|
|
11158
11160
|
processMessage;
|
|
11159
11161
|
onProcessingChanged;
|
|
11160
11162
|
onMessageStarted;
|
|
11163
|
+
onQueueChanged;
|
|
11161
11164
|
acceptanceByMessage = /* @__PURE__ */ new WeakMap();
|
|
11162
11165
|
// A withdrawal mark implies the entry was present when its acceptance
|
|
11163
11166
|
// rejected; intentional removals (remove, clear, drain, steer) can never
|
|
@@ -11168,10 +11171,12 @@ var MessageQueueService = class {
|
|
|
11168
11171
|
activeTurn = null;
|
|
11169
11172
|
constructor(processMessage, onProcessingChanged = () => {
|
|
11170
11173
|
}, onMessageStarted = async () => {
|
|
11174
|
+
}, onQueueChanged = () => {
|
|
11171
11175
|
}) {
|
|
11172
11176
|
this.processMessage = processMessage;
|
|
11173
11177
|
this.onProcessingChanged = onProcessingChanged;
|
|
11174
11178
|
this.onMessageStarted = onMessageStarted;
|
|
11179
|
+
this.onQueueChanged = onQueueChanged;
|
|
11175
11180
|
}
|
|
11176
11181
|
generateMessageId() {
|
|
11177
11182
|
return `msg_${Date.now()}_${++this.messageIdCounter}`;
|
|
@@ -11209,6 +11214,7 @@ var MessageQueueService = class {
|
|
|
11209
11214
|
if (!this.queue.includes(tail) && this.queueCancellationVersion === cancellationVersion && this.acceptanceWithdrawals.delete(tail)) {
|
|
11210
11215
|
this.queue.push(tail);
|
|
11211
11216
|
}
|
|
11217
|
+
this.onQueueChanged();
|
|
11212
11218
|
});
|
|
11213
11219
|
this.acceptanceByMessage.set(tail, acceptance);
|
|
11214
11220
|
await acceptance;
|
|
@@ -11225,6 +11231,7 @@ var MessageQueueService = class {
|
|
|
11225
11231
|
};
|
|
11226
11232
|
if (this.processing) {
|
|
11227
11233
|
this.queue.push(queuedMessage);
|
|
11234
|
+
this.onQueueChanged();
|
|
11228
11235
|
const response2 = {
|
|
11229
11236
|
queued: true,
|
|
11230
11237
|
messageId,
|
|
@@ -11235,6 +11242,7 @@ var MessageQueueService = class {
|
|
|
11235
11242
|
if (index !== -1) {
|
|
11236
11243
|
this.queue.splice(index, 1);
|
|
11237
11244
|
this.acceptanceWithdrawals.add(queuedMessage);
|
|
11245
|
+
this.onQueueChanged();
|
|
11238
11246
|
}
|
|
11239
11247
|
throw error;
|
|
11240
11248
|
});
|
|
@@ -11264,6 +11272,7 @@ var MessageQueueService = class {
|
|
|
11264
11272
|
this.activeTurn = turn;
|
|
11265
11273
|
this.processing = true;
|
|
11266
11274
|
this.onProcessingChanged(true);
|
|
11275
|
+
this.onQueueChanged();
|
|
11267
11276
|
try {
|
|
11268
11277
|
while (true) {
|
|
11269
11278
|
const acceptance = this.acceptanceByMessage.get(queuedMessage);
|
|
@@ -11284,6 +11293,7 @@ var MessageQueueService = class {
|
|
|
11284
11293
|
this.processing = false;
|
|
11285
11294
|
if (this.queue.length === 0) {
|
|
11286
11295
|
this.onProcessingChanged(false);
|
|
11296
|
+
this.onQueueChanged();
|
|
11287
11297
|
}
|
|
11288
11298
|
await this.processNextInQueue();
|
|
11289
11299
|
}
|
|
@@ -11304,6 +11314,7 @@ var MessageQueueService = class {
|
|
|
11304
11314
|
const drained = this.queue;
|
|
11305
11315
|
this.queueCancellationVersion++;
|
|
11306
11316
|
this.queue = [];
|
|
11317
|
+
this.onQueueChanged();
|
|
11307
11318
|
return drained;
|
|
11308
11319
|
}
|
|
11309
11320
|
cancelActiveTurn() {
|
|
@@ -11319,17 +11330,20 @@ var MessageQueueService = class {
|
|
|
11319
11330
|
const queuedMessage = this.queue.find((item) => item.id === messageId);
|
|
11320
11331
|
if (!queuedMessage) return false;
|
|
11321
11332
|
queuedMessage.message = message;
|
|
11333
|
+
this.onQueueChanged();
|
|
11322
11334
|
return true;
|
|
11323
11335
|
}
|
|
11324
11336
|
takeFromQueue(messageId) {
|
|
11325
11337
|
const index = this.queue.findIndex((m) => m.id === messageId);
|
|
11326
11338
|
if (index === -1) return null;
|
|
11327
11339
|
const [message] = this.queue.splice(index, 1);
|
|
11340
|
+
this.onQueueChanged();
|
|
11328
11341
|
return { message, index };
|
|
11329
11342
|
}
|
|
11330
11343
|
restoreToQueue(message, index) {
|
|
11331
11344
|
const clamped = Math.max(0, Math.min(index, this.queue.length));
|
|
11332
11345
|
this.queue.splice(clamped, 0, message);
|
|
11346
|
+
this.onQueueChanged();
|
|
11333
11347
|
}
|
|
11334
11348
|
resumeIfIdle() {
|
|
11335
11349
|
if (this.processing || this.queue.length === 0) return;
|
|
@@ -11348,6 +11362,7 @@ var MessageQueueService = class {
|
|
|
11348
11362
|
if (index === clamped) return true;
|
|
11349
11363
|
const [item] = this.queue.splice(index, 1);
|
|
11350
11364
|
this.queue.splice(clamped, 0, item);
|
|
11365
|
+
this.onQueueChanged();
|
|
11351
11366
|
return true;
|
|
11352
11367
|
}
|
|
11353
11368
|
/**
|
|
@@ -11357,6 +11372,7 @@ var MessageQueueService = class {
|
|
|
11357
11372
|
this.queueCancellationVersion++;
|
|
11358
11373
|
this.queue = [];
|
|
11359
11374
|
this.processing = false;
|
|
11375
|
+
this.onQueueChanged();
|
|
11360
11376
|
}
|
|
11361
11377
|
};
|
|
11362
11378
|
|
|
@@ -11392,6 +11408,7 @@ var CodingAgentManager = class {
|
|
|
11392
11408
|
hostOnTurnComplete;
|
|
11393
11409
|
onProcessingChanged;
|
|
11394
11410
|
onMessageStarted;
|
|
11411
|
+
onQueueChanged;
|
|
11395
11412
|
onModelSwitched;
|
|
11396
11413
|
authFallback;
|
|
11397
11414
|
subagentMcpChatId;
|
|
@@ -11399,6 +11416,7 @@ var CodingAgentManager = class {
|
|
|
11399
11416
|
usesAutoCompactTokens;
|
|
11400
11417
|
autoCompactTokens = null;
|
|
11401
11418
|
unreadSteers = /* @__PURE__ */ new Map();
|
|
11419
|
+
steersInFlight = /* @__PURE__ */ new Map();
|
|
11402
11420
|
lastSenderKey;
|
|
11403
11421
|
onLastSenderKeyChanged;
|
|
11404
11422
|
constructor(options) {
|
|
@@ -11420,6 +11438,8 @@ var CodingAgentManager = class {
|
|
|
11420
11438
|
});
|
|
11421
11439
|
this.onMessageStarted = options.onMessageStarted ?? (async () => {
|
|
11422
11440
|
});
|
|
11441
|
+
this.onQueueChanged = options.onQueueChanged ?? (() => {
|
|
11442
|
+
});
|
|
11423
11443
|
this.onModelSwitched = options.onModelSwitched ?? (async () => {
|
|
11424
11444
|
});
|
|
11425
11445
|
this.lastSenderKey = options.lastSenderKey ?? null;
|
|
@@ -11489,16 +11509,21 @@ var CodingAgentManager = class {
|
|
|
11489
11509
|
this.messageQueue = new MessageQueueService(
|
|
11490
11510
|
async (request, signal) => {
|
|
11491
11511
|
await Promise.all([this.refreshSubagentMcp(), this.refreshAutoCompactTokens()]);
|
|
11492
|
-
if (signal.aborted) return;
|
|
11493
11512
|
const { request: delivered, senderKey } = this.withSenderLine(request);
|
|
11513
|
+
const stopped = signal.aborted;
|
|
11514
|
+
if (stopped && !await this.keepStoppedRequest(delivered)) return;
|
|
11494
11515
|
await this.saveLastSenderKey(senderKey);
|
|
11495
|
-
await processMessage(delivered, signal);
|
|
11516
|
+
if (!stopped) await processMessage(delivered, signal);
|
|
11496
11517
|
},
|
|
11497
11518
|
this.onProcessingChanged,
|
|
11498
|
-
this.onMessageStarted
|
|
11519
|
+
this.onMessageStarted,
|
|
11520
|
+
this.onQueueChanged
|
|
11499
11521
|
);
|
|
11500
11522
|
this.initialized = this.initialize();
|
|
11501
11523
|
}
|
|
11524
|
+
async keepStoppedRequest(_request) {
|
|
11525
|
+
return false;
|
|
11526
|
+
}
|
|
11502
11527
|
// Integration turns (Slack, GitHub, Linear) carry no sender fields and name their sender in the text, so they reset the key.
|
|
11503
11528
|
withSenderLine(request) {
|
|
11504
11529
|
if (request.goalMode || request.message.trimStart().startsWith("/")) return { request, senderKey: this.lastSenderKey };
|
|
@@ -11547,6 +11572,7 @@ ${request.message}` }, senderKey };
|
|
|
11547
11572
|
const queuedMessages = this.messageQueue.drainQueue();
|
|
11548
11573
|
const unreadSteers = [...this.unreadSteers.values()];
|
|
11549
11574
|
this.unreadSteers.clear();
|
|
11575
|
+
this.onQueueChanged();
|
|
11550
11576
|
this.messageQueue.cancelActiveTurn();
|
|
11551
11577
|
const isProcessing = this.isProcessing() || (this.hasActiveBackgroundTasks?.() ?? false);
|
|
11552
11578
|
if (isProcessing) {
|
|
@@ -11554,6 +11580,7 @@ ${request.message}` }, senderKey };
|
|
|
11554
11580
|
await this.interruptActiveTurn();
|
|
11555
11581
|
} catch (error) {
|
|
11556
11582
|
for (const steer of unreadSteers) this.unreadSteers.set(steer.message.id, steer);
|
|
11583
|
+
this.onQueueChanged();
|
|
11557
11584
|
this.restoreQueuedMessages(queuedMessages.map((message, index) => ({ message, index })));
|
|
11558
11585
|
throw error;
|
|
11559
11586
|
}
|
|
@@ -11590,7 +11617,7 @@ ${request.message}` }, senderKey };
|
|
|
11590
11617
|
getQueue() {
|
|
11591
11618
|
return [
|
|
11592
11619
|
...[...this.unreadSteers.values()].map(({ message, steeredAt }) => ({ ...toQueuedMessageInfo(message), steeredAt })),
|
|
11593
|
-
...this.messageQueue.getQueue().map(toQueuedMessageInfo)
|
|
11620
|
+
...[...this.steersInFlight.values(), ...this.messageQueue.getQueue()].map(toQueuedMessageInfo)
|
|
11594
11621
|
];
|
|
11595
11622
|
}
|
|
11596
11623
|
async removeFromQueue(messageId, persistRemoval) {
|
|
@@ -11637,6 +11664,7 @@ ${request.message}` }, senderKey };
|
|
|
11637
11664
|
if (!taken) {
|
|
11638
11665
|
return { success: false, queue: this.getQueue() };
|
|
11639
11666
|
}
|
|
11667
|
+
this.steersInFlight.set(messageId, taken.message);
|
|
11640
11668
|
let steered = false;
|
|
11641
11669
|
const { request: withSender, senderKey } = this.withSenderLine(taken.message);
|
|
11642
11670
|
const note = wrapInTag("You received this message while working. The chat folds everything before your last message of this turn, so that message must answer it too, even if you already did earlier.", REPLICAS_INSTRUCTIONS_TAG);
|
|
@@ -11649,8 +11677,13 @@ ${note}` };
|
|
|
11649
11677
|
} catch (error) {
|
|
11650
11678
|
console.error("[CodingAgentManager] steerRequest threw, keeping message queued:", error);
|
|
11651
11679
|
}
|
|
11652
|
-
|
|
11653
|
-
|
|
11680
|
+
this.steersInFlight.delete(messageId);
|
|
11681
|
+
if (steered) {
|
|
11682
|
+
this.unreadSteers.set(messageId, { message: taken.message, delivered, steeredAt: (/* @__PURE__ */ new Date()).toISOString() });
|
|
11683
|
+
this.onQueueChanged();
|
|
11684
|
+
} else {
|
|
11685
|
+
this.restoreQueuedMessages([{ message: taken.message, index: 0 }]);
|
|
11686
|
+
}
|
|
11654
11687
|
return { success: steered, queue: this.getQueue() };
|
|
11655
11688
|
}
|
|
11656
11689
|
async sendNow(messageId) {
|
|
@@ -11678,6 +11711,7 @@ ${note}` };
|
|
|
11678
11711
|
requeueUnreadSteers() {
|
|
11679
11712
|
const steers = [...this.unreadSteers.values()].map(({ message }) => message);
|
|
11680
11713
|
this.unreadSteers.clear();
|
|
11714
|
+
this.onQueueChanged();
|
|
11681
11715
|
this.restoreQueuedMessages(steers.map((message) => ({ message, index: 0 })));
|
|
11682
11716
|
if (steers.length > 0) {
|
|
11683
11717
|
this.saveLastSenderKey(null).catch((error) => {
|
|
@@ -11687,7 +11721,7 @@ ${note}` };
|
|
|
11687
11721
|
}
|
|
11688
11722
|
markSteerRead(messageId) {
|
|
11689
11723
|
const steer = this.unreadSteers.get(messageId);
|
|
11690
|
-
this.unreadSteers.delete(messageId);
|
|
11724
|
+
if (this.unreadSteers.delete(messageId)) this.onQueueChanged();
|
|
11691
11725
|
return steer?.delivered ?? this.messageQueue.takeFromQueue(messageId)?.message;
|
|
11692
11726
|
}
|
|
11693
11727
|
canDeliverSteersNow() {
|
|
@@ -12650,6 +12684,8 @@ var ClaudeManager = class _ClaudeManager extends CodingAgentManager {
|
|
|
12650
12684
|
pendingInterrupt = false;
|
|
12651
12685
|
// Claude Code writes a started prompt to the session transcript even when the turn then fails, so a retry must not resend it.
|
|
12652
12686
|
turnPromptRecorded = false;
|
|
12687
|
+
// Claude Code never sees a prompt stopped before it started, so it is sent again with the next message.
|
|
12688
|
+
unreadPrompt = null;
|
|
12653
12689
|
backgroundTasks = new ClaudeBackgroundTasks();
|
|
12654
12690
|
backgroundRecoveryAttempted = false;
|
|
12655
12691
|
// Ultracode workflow child agents never reach the SDK stream (forwardSubagentText
|
|
@@ -12696,6 +12732,19 @@ var ClaudeManager = class _ClaudeManager extends CodingAgentManager {
|
|
|
12696
12732
|
await this.abortAllPendingToolInputs();
|
|
12697
12733
|
await this.tearDownSession(true);
|
|
12698
12734
|
}
|
|
12735
|
+
// Stop can tear a session down before its command_lifecycle event is read, so the transcript decides.
|
|
12736
|
+
async dropRecordedUnreadPrompt() {
|
|
12737
|
+
const unread = this.unreadPrompt;
|
|
12738
|
+
if (unread && this.sessionId && (await getSessionMessages(this.sessionId, { dir: this.workingDirectory })).some(({ uuid }) => uuid === unread.uuid)) {
|
|
12739
|
+
this.unreadPrompt = null;
|
|
12740
|
+
}
|
|
12741
|
+
}
|
|
12742
|
+
async keepStoppedRequest(request) {
|
|
12743
|
+
await this.dropRecordedUnreadPrompt();
|
|
12744
|
+
const { uuid, message } = await this.buildUserMessage(request);
|
|
12745
|
+
this.unreadPrompt = { uuid, content: [...this.unreadPrompt?.content ?? [], ...message.content] };
|
|
12746
|
+
return true;
|
|
12747
|
+
}
|
|
12699
12748
|
canDeliverSteersNow() {
|
|
12700
12749
|
return this.activeQuery !== null && this.backgroundTasks.foreground.size > 0;
|
|
12701
12750
|
}
|
|
@@ -13232,23 +13281,32 @@ var ClaudeManager = class _ClaudeManager extends CodingAgentManager {
|
|
|
13232
13281
|
if (!promptStream || !activeQuery) {
|
|
13233
13282
|
throw new Error("Claude session unavailable after ensureSession");
|
|
13234
13283
|
}
|
|
13284
|
+
await this.dropRecordedUnreadPrompt();
|
|
13285
|
+
const prompt = goalCommand ? [{ type: "text", text: `/goal ${goalObjective ?? "clear"}` }] : userMessage.message.content;
|
|
13286
|
+
const content = [...this.unreadPrompt?.content ?? [], ...prompt];
|
|
13235
13287
|
if (this.pendingInterrupt || options.signal?.aborted) {
|
|
13236
13288
|
this.pendingInterrupt = false;
|
|
13289
|
+
this.unreadPrompt = { uuid: userMessage.uuid, content };
|
|
13237
13290
|
return;
|
|
13238
13291
|
}
|
|
13239
13292
|
this.turnPromptRecorded = false;
|
|
13240
|
-
|
|
13241
|
-
|
|
13242
|
-
|
|
13243
|
-
|
|
13244
|
-
|
|
13245
|
-
|
|
13246
|
-
|
|
13247
|
-
|
|
13248
|
-
|
|
13249
|
-
|
|
13250
|
-
|
|
13251
|
-
|
|
13293
|
+
try {
|
|
13294
|
+
await new Promise((resolve7, reject) => {
|
|
13295
|
+
const steers = options.steers ?? /* @__PURE__ */ new Map();
|
|
13296
|
+
this.pendingTurn = {
|
|
13297
|
+
resolve: resolve7,
|
|
13298
|
+
reject,
|
|
13299
|
+
sawActivity: false,
|
|
13300
|
+
steers,
|
|
13301
|
+
userMessageUuids: /* @__PURE__ */ new Set([userMessage.uuid, ...steers.keys()])
|
|
13302
|
+
};
|
|
13303
|
+
promptStream.push({ ...userMessage, message: { role: "user", content } });
|
|
13304
|
+
for (const { userMessage: steer } of steers.values()) promptStream.push({ ...steer, priority: "next" });
|
|
13305
|
+
});
|
|
13306
|
+
} finally {
|
|
13307
|
+
if (this.turnPromptRecorded) this.unreadPrompt = null;
|
|
13308
|
+
else if (options.signal?.aborted) this.unreadPrompt = { uuid: userMessage.uuid, content };
|
|
13309
|
+
}
|
|
13252
13310
|
}
|
|
13253
13311
|
async buildUserMessage({ message, images }) {
|
|
13254
13312
|
const content = [
|
|
@@ -13260,6 +13318,7 @@ var ClaudeManager = class _ClaudeManager extends CodingAgentManager {
|
|
|
13260
13318
|
if (images && images.length > 0) {
|
|
13261
13319
|
const normalizedImages = await normalizeImages(images);
|
|
13262
13320
|
for (const image of normalizedImages) {
|
|
13321
|
+
if (image.label) content.push({ type: "text", text: image.label });
|
|
13263
13322
|
content.push({
|
|
13264
13323
|
type: "image",
|
|
13265
13324
|
source: {
|
|
@@ -14099,6 +14158,8 @@ var CodexAspManager = class extends CodingAgentManager {
|
|
|
14099
14158
|
slashCommandsCache = null;
|
|
14100
14159
|
slashCommandsRequest = null;
|
|
14101
14160
|
steeredTempImagePaths = [];
|
|
14161
|
+
// Codex never sees a message stopped before its turn started, so it is sent again with the next one.
|
|
14162
|
+
unreadRequests = [];
|
|
14102
14163
|
compacting = false;
|
|
14103
14164
|
steerLock = new AsyncLock();
|
|
14104
14165
|
onCodexTurnStarted;
|
|
@@ -14144,6 +14205,11 @@ var CodexAspManager = class extends CodingAgentManager {
|
|
|
14144
14205
|
}
|
|
14145
14206
|
return super.interrupt(persistRemoval);
|
|
14146
14207
|
}
|
|
14208
|
+
async keepStoppedRequest(request) {
|
|
14209
|
+
if (isCompactCommand(request.message) || getGoalCommand(request.message, request.goalMode)) return false;
|
|
14210
|
+
this.unreadRequests.push(request);
|
|
14211
|
+
return true;
|
|
14212
|
+
}
|
|
14147
14213
|
async interruptActiveTurn() {
|
|
14148
14214
|
if (!this.currentThreadId || !this.activeTurnId) {
|
|
14149
14215
|
return;
|
|
@@ -14459,7 +14525,10 @@ var CodexAspManager = class extends CodingAgentManager {
|
|
|
14459
14525
|
const threadId = await this.ensureThread(host, request, developerInstructions);
|
|
14460
14526
|
const serviceTier = await this.resolveRequestedServiceTier(host, request);
|
|
14461
14527
|
await this.applyThreadServiceTier(host, threadId, serviceTier);
|
|
14462
|
-
if (signal.aborted)
|
|
14528
|
+
if (signal.aborted) {
|
|
14529
|
+
await this.keepStoppedRequest(request);
|
|
14530
|
+
return;
|
|
14531
|
+
}
|
|
14463
14532
|
const runTurn = options.runTurn ?? ((aspHost, aspThreadId) => this.runTurn(aspHost, aspThreadId, request, serviceTier, signal));
|
|
14464
14533
|
let completedTurn;
|
|
14465
14534
|
try {
|
|
@@ -14593,17 +14662,28 @@ ${text.slice(-24e3)}`
|
|
|
14593
14662
|
}
|
|
14594
14663
|
}
|
|
14595
14664
|
async runTurn(host, threadId, request, serviceTier, signal) {
|
|
14596
|
-
const { params, tempImagePaths } = await buildTurnStartParams(threadId, request, serviceTier)
|
|
14665
|
+
const { params, tempImagePaths } = await buildTurnStartParams(threadId, request, serviceTier, this.unreadRequests).catch((error) => {
|
|
14666
|
+
this.unreadRequests = this.unreadRequests.map((unread) => ({ ...unread, images: void 0 }));
|
|
14667
|
+
throw error;
|
|
14668
|
+
});
|
|
14597
14669
|
return this.observeTurn(host, threadId, request, signal, async () => {
|
|
14598
14670
|
const turnStartResponse = await host.client.request(
|
|
14599
14671
|
TURN_START_METHOD,
|
|
14600
14672
|
params
|
|
14601
14673
|
);
|
|
14674
|
+
this.unreadRequests = [];
|
|
14602
14675
|
return { turn: turnStartResponse.turn, tempImagePaths };
|
|
14603
14676
|
});
|
|
14604
14677
|
}
|
|
14605
14678
|
async runGoalTurn(host, threadId, request, objective, signal) {
|
|
14606
14679
|
const { mothershipInstructions } = splitMothershipInstructions(request.customInstructions);
|
|
14680
|
+
const unreadContent = await Promise.all(this.unreadRequests.map(async (unread) => [
|
|
14681
|
+
{ type: "input_text", text: unread.message },
|
|
14682
|
+
...(await normalizeImages(unread.images ?? [])).map((image) => ({ type: "input_image", image_url: `data:${image.source.media_type};base64,${image.source.data}` }))
|
|
14683
|
+
])).catch((error) => {
|
|
14684
|
+
this.unreadRequests = this.unreadRequests.map((unread) => ({ ...unread, images: void 0 }));
|
|
14685
|
+
throw error;
|
|
14686
|
+
});
|
|
14607
14687
|
return this.observeTurn(host, threadId, request, signal, async () => {
|
|
14608
14688
|
if (mothershipInstructions) {
|
|
14609
14689
|
await host.client.request(THREAD_INJECT_ITEMS_METHOD, {
|
|
@@ -14611,6 +14691,13 @@ ${text.slice(-24e3)}`
|
|
|
14611
14691
|
items: [{ type: "message", role: "developer", content: [{ type: "input_text", text: wrapInTag(mothershipInstructions, MOTHERSHIP_INSTRUCTIONS_TAG) }] }]
|
|
14612
14692
|
});
|
|
14613
14693
|
}
|
|
14694
|
+
if (unreadContent.length > 0) {
|
|
14695
|
+
await host.client.request(THREAD_INJECT_ITEMS_METHOD, {
|
|
14696
|
+
threadId,
|
|
14697
|
+
items: [{ type: "message", role: "user", content: unreadContent.flat() }]
|
|
14698
|
+
});
|
|
14699
|
+
this.unreadRequests = [];
|
|
14700
|
+
}
|
|
14614
14701
|
const response = await host.client.request(
|
|
14615
14702
|
THREAD_GOAL_SET_METHOD,
|
|
14616
14703
|
{ threadId, objective, status: "active" }
|
|
@@ -15912,6 +15999,7 @@ ${typeof pending.subject.command === "string" ? pending.subject.command : JSON.s
|
|
|
15912
15999
|
const input = [{ type: "text", text }];
|
|
15913
16000
|
for (const image of images ?? []) {
|
|
15914
16001
|
if (image.source.type !== "base64") throw new Error("Muse requires images to be base64 encoded.");
|
|
16002
|
+
if (image.label) input.push({ type: "text", text: image.label });
|
|
15915
16003
|
input.push({ type: "image", mediaType: image.source.media_type, base64Data: image.source.data });
|
|
15916
16004
|
}
|
|
15917
16005
|
return input;
|
|
@@ -59896,6 +59984,17 @@ var ChatService = class {
|
|
|
59896
59984
|
queue: chat.provider.getQueue()
|
|
59897
59985
|
};
|
|
59898
59986
|
}
|
|
59987
|
+
publishQueueIfChanged(chatId) {
|
|
59988
|
+
const chat = this.getRuntimeChat(chatId);
|
|
59989
|
+
if (!chat) return;
|
|
59990
|
+
const payload = this.getChatQueue(chatId);
|
|
59991
|
+
const serialized = JSON.stringify(payload);
|
|
59992
|
+
if (serialized === chat.publishedQueue) return;
|
|
59993
|
+
chat.publishedQueue = serialized;
|
|
59994
|
+
this.publish({ type: "chat.queue.changed", payload }).catch((error) => {
|
|
59995
|
+
console.error("[ChatService] Failed to publish chat queue:", { chatId, error });
|
|
59996
|
+
});
|
|
59997
|
+
}
|
|
59899
59998
|
async forgetPendingMessages(chat, messageIds) {
|
|
59900
59999
|
if (messageIds.length === 0) return;
|
|
59901
60000
|
const removed = new Set(messageIds);
|
|
@@ -59982,6 +60081,7 @@ var ChatService = class {
|
|
|
59982
60081
|
const result = await chat.provider.steerFromQueue(messageId);
|
|
59983
60082
|
if (result.success) {
|
|
59984
60083
|
chat.pendingMessageIds = chat.pendingMessageIds.filter((pendingMessageId) => pendingMessageId !== messageId);
|
|
60084
|
+
this.publishQueueIfChanged(chatId);
|
|
59985
60085
|
}
|
|
59986
60086
|
return result;
|
|
59987
60087
|
}
|
|
@@ -59990,6 +60090,7 @@ var ChatService = class {
|
|
|
59990
60090
|
const result = await chat.provider.sendNow(messageId);
|
|
59991
60091
|
if (result.success && !result.queue.some(({ id, steeredAt }) => id === messageId && !steeredAt)) {
|
|
59992
60092
|
chat.pendingMessageIds = chat.pendingMessageIds.filter((pendingMessageId) => pendingMessageId !== messageId);
|
|
60093
|
+
this.publishQueueIfChanged(chatId);
|
|
59993
60094
|
}
|
|
59994
60095
|
return result;
|
|
59995
60096
|
}
|
|
@@ -60370,6 +60471,7 @@ var ChatService = class {
|
|
|
60370
60471
|
if (processing) return;
|
|
60371
60472
|
this.handleProcessingStopped(persisted.id);
|
|
60372
60473
|
};
|
|
60474
|
+
const onQueueChanged = () => queueMicrotask(() => this.publishQueueIfChanged(persisted.id));
|
|
60373
60475
|
const fallbackContext = () => {
|
|
60374
60476
|
const chat = this.chats.get(persisted.id);
|
|
60375
60477
|
return {
|
|
@@ -60403,6 +60505,7 @@ var ChatService = class {
|
|
|
60403
60505
|
onEvent: onProviderEvent,
|
|
60404
60506
|
onProcessingChanged,
|
|
60405
60507
|
onMessageStarted,
|
|
60508
|
+
onQueueChanged,
|
|
60406
60509
|
onUsageUpdate: onProviderUsage,
|
|
60407
60510
|
fallbackContext,
|
|
60408
60511
|
chatId: persisted.id,
|
|
@@ -60454,6 +60557,7 @@ var ChatService = class {
|
|
|
60454
60557
|
turnRequest: null,
|
|
60455
60558
|
turnAnswer: null,
|
|
60456
60559
|
turnCompletion: null,
|
|
60560
|
+
publishedQueue: null,
|
|
60457
60561
|
idleReleaseTimer: null,
|
|
60458
60562
|
release: null,
|
|
60459
60563
|
errorNotificationTargets: /* @__PURE__ */ new Map(),
|
|
@@ -60797,6 +60901,10 @@ var ChatService = class {
|
|
|
60797
60901
|
...input
|
|
60798
60902
|
};
|
|
60799
60903
|
const chatId = "chat" in event.payload && event.payload.chat ? event.payload.chat.id : "chatId" in event.payload ? event.payload.chatId : void 0;
|
|
60904
|
+
if (event.type === "chat.queue.changed") {
|
|
60905
|
+
await eventService.publish(event);
|
|
60906
|
+
return;
|
|
60907
|
+
}
|
|
60800
60908
|
const chat = chatId ? this.chats.get(chatId) : void 0;
|
|
60801
60909
|
if (chat) {
|
|
60802
60910
|
chat.historyVersion = event.id;
|
|
@@ -60805,6 +60913,7 @@ var ChatService = class {
|
|
|
60805
60913
|
}
|
|
60806
60914
|
}
|
|
60807
60915
|
await eventService.publish(event);
|
|
60916
|
+
if (chatId) this.publishQueueIfChanged(chatId);
|
|
60808
60917
|
}
|
|
60809
60918
|
async observeCurrentBranches(chat) {
|
|
60810
60919
|
try {
|