@gkorepanov/ccodex 0.4.23 → 0.4.24
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/service.d.ts +1 -1
- package/dist/claude/service.js +13 -4
- package/dist/claude/service.js.map +1 -1
- package/dist/claude/session/providerRuntimeFactory.js +15 -7
- package/dist/claude/session/providerRuntimeFactory.js.map +1 -1
- package/dist/claude/session/runtime.d.ts +10 -0
- package/dist/claude/session/runtime.js +44 -2
- package/dist/claude/session/runtime.js.map +1 -1
- package/dist/claude/session/session.js +30 -19
- package/dist/claude/session/session.js.map +1 -1
- package/dist/daemon/ownership.js +9 -1
- package/dist/daemon/ownership.js.map +1 -1
- package/dist/gateway/clientConnection.js +21 -12
- package/dist/gateway/clientConnection.js.map +1 -1
- package/dist/gateway/optimisticSideThreads.d.ts +11 -5
- package/dist/gateway/optimisticSideThreads.js +103 -47
- package/dist/gateway/optimisticSideThreads.js.map +1 -1
- package/dist/gateway/server.js +31 -1
- package/dist/gateway/server.js.map +1 -1
- package/dist/gateway/stockSideThreads.d.ts +3 -6
- package/dist/gateway/stockSideThreads.js +38 -43
- package/dist/gateway/stockSideThreads.js.map +1 -1
- package/dist/gateway/threadList.d.ts +3 -3
- package/dist/gateway/threadList.js +15 -5
- package/dist/gateway/threadList.js.map +1 -1
- package/dist/handoff/service.js +1 -0
- package/dist/handoff/service.js.map +1 -1
- package/dist/handoff/store.d.ts +21 -0
- package/dist/handoff/store.js +15 -0
- package/dist/handoff/store.js.map +1 -1
- package/legal/THIRD_PARTY_NOTICES.md +0 -27
- package/package.json +4 -4
|
@@ -3,6 +3,8 @@ import { type InterruptCancellation } from "../interruptCompat.js";
|
|
|
3
3
|
import type { ClaudeQueryFactory } from "../queryFactory.js";
|
|
4
4
|
import { type ClaudeProviderFact } from "./providerFacts.js";
|
|
5
5
|
export type ClaudeRuntimeFact = ClaudeProviderFact;
|
|
6
|
+
/** Longest stretch a buffered SDK batch may hold the event loop before socket reads get a turn. */
|
|
7
|
+
export declare const EVENT_LOOP_YIELD_BUDGET_MS = 20;
|
|
6
8
|
export interface ClaudeRuntimeSettings {
|
|
7
9
|
readonly model: string;
|
|
8
10
|
readonly permissionMode: PermissionMode;
|
|
@@ -27,6 +29,7 @@ export declare class ClaudeRuntime {
|
|
|
27
29
|
private closed;
|
|
28
30
|
private closing;
|
|
29
31
|
private exited;
|
|
32
|
+
private awaitingNext;
|
|
30
33
|
private readonly capabilities;
|
|
31
34
|
private readonly ownedMessageIds;
|
|
32
35
|
private stderrTail;
|
|
@@ -50,5 +53,12 @@ export declare class ClaudeRuntime {
|
|
|
50
53
|
interruptOwned(ownedMessageIds?: ReadonlySet<string>): Promise<InterruptCancellation>;
|
|
51
54
|
close(): Promise<void>;
|
|
52
55
|
private consume;
|
|
56
|
+
/**
|
|
57
|
+
* Resolves once every SDK message buffered before now has been submitted.
|
|
58
|
+
* SDK callbacks (canUseTool, hooks, elicitation) bypass the message stream;
|
|
59
|
+
* gating them here keeps a callback from outrunning the message that
|
|
60
|
+
* precedes it while the consumer yields the event loop mid-batch.
|
|
61
|
+
*/
|
|
62
|
+
drained(): Promise<void>;
|
|
53
63
|
private markExited;
|
|
54
64
|
}
|
|
@@ -1,6 +1,9 @@
|
|
|
1
|
+
import { setImmediate as yieldToEventLoop } from "node:timers/promises";
|
|
1
2
|
import { AsyncQueue } from "../asyncQueue.js";
|
|
2
3
|
import { interruptAndCancelOwned } from "../interruptCompat.js";
|
|
3
4
|
import { normalizeProviderMessage, } from "./providerFacts.js";
|
|
5
|
+
/** Longest stretch a buffered SDK batch may hold the event loop before socket reads get a turn. */
|
|
6
|
+
export const EVENT_LOOP_YIELD_BUDGET_MS = 20;
|
|
4
7
|
export class ClaudeRuntimeStartupError extends Error {
|
|
5
8
|
retryableEarlyExit;
|
|
6
9
|
constructor(message, retryableEarlyExit, options) {
|
|
@@ -24,6 +27,7 @@ export class ClaudeRuntime {
|
|
|
24
27
|
closed = false;
|
|
25
28
|
closing = false;
|
|
26
29
|
exited = false;
|
|
30
|
+
awaitingNext = false;
|
|
27
31
|
capabilities = new Set();
|
|
28
32
|
ownedMessageIds = new Set();
|
|
29
33
|
stderrTail = "";
|
|
@@ -138,9 +142,36 @@ export class ClaudeRuntime {
|
|
|
138
142
|
async consume() {
|
|
139
143
|
let exitSubmitted = false;
|
|
140
144
|
try {
|
|
141
|
-
|
|
145
|
+
// A buffered SDK batch resolves through microtasks only, so the poll
|
|
146
|
+
// phase never runs and every stock/App socket stays unread until the
|
|
147
|
+
// batch drains. Hop a macrotask once a batch has held the loop for the
|
|
148
|
+
// budget; hopping after every message would widen the window in which
|
|
149
|
+
// an SDK callback (canUseTool) outruns its preceding message.
|
|
150
|
+
const iterator = this.query[Symbol.asyncIterator]();
|
|
151
|
+
let loopHeldSince = performance.now();
|
|
152
|
+
for (;;) {
|
|
153
|
+
const waitedFrom = performance.now();
|
|
154
|
+
this.awaitingNext = true;
|
|
155
|
+
const next = await iterator.next();
|
|
156
|
+
this.awaitingNext = false;
|
|
157
|
+
if (next.done)
|
|
158
|
+
break;
|
|
159
|
+
// A next() that had to wait means the loop ran other work meanwhile;
|
|
160
|
+
// only an instantly resolved (buffered) message accrues held time.
|
|
161
|
+
if (performance.now() - waitedFrom >= 1)
|
|
162
|
+
loopHeldSince = performance.now();
|
|
142
163
|
this.providerOutputSeen = true;
|
|
143
|
-
|
|
164
|
+
try {
|
|
165
|
+
await this.submitFact(normalizeProviderMessage(this.runtimeGeneration, next.value));
|
|
166
|
+
}
|
|
167
|
+
catch (error) {
|
|
168
|
+
await iterator.return?.(undefined).catch(() => undefined);
|
|
169
|
+
throw error;
|
|
170
|
+
}
|
|
171
|
+
if (performance.now() - loopHeldSince >= EVENT_LOOP_YIELD_BUDGET_MS) {
|
|
172
|
+
await yieldToEventLoop();
|
|
173
|
+
loopHeldSince = performance.now();
|
|
174
|
+
}
|
|
144
175
|
}
|
|
145
176
|
this.markExited();
|
|
146
177
|
exitSubmitted = true;
|
|
@@ -160,6 +191,17 @@ export class ClaudeRuntime {
|
|
|
160
191
|
});
|
|
161
192
|
}
|
|
162
193
|
}
|
|
194
|
+
/**
|
|
195
|
+
* Resolves once every SDK message buffered before now has been submitted.
|
|
196
|
+
* SDK callbacks (canUseTool, hooks, elicitation) bypass the message stream;
|
|
197
|
+
* gating them here keeps a callback from outrunning the message that
|
|
198
|
+
* precedes it while the consumer yields the event loop mid-batch.
|
|
199
|
+
*/
|
|
200
|
+
async drained() {
|
|
201
|
+
do
|
|
202
|
+
await yieldToEventLoop();
|
|
203
|
+
while (!this.awaitingNext && !this.exited);
|
|
204
|
+
}
|
|
163
205
|
markExited(error) {
|
|
164
206
|
this.exited = true;
|
|
165
207
|
this.rejectInitializationExit(this.initializationFailure(error ?? new Error(`Claude runtime generation ${this.runtimeGeneration} exited during initialization.`)));
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"runtime.js","sourceRoot":"","sources":["../../../src/claude/session/runtime.ts"],"names":[],"mappings":"AAOA,OAAO,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AAC9C,OAAO,EAAE,uBAAuB,EAA8B,MAAM,uBAAuB,CAAC;AAE5F,OAAO,EACL,wBAAwB,GAEzB,MAAM,oBAAoB,CAAC;
|
|
1
|
+
{"version":3,"file":"runtime.js","sourceRoot":"","sources":["../../../src/claude/session/runtime.ts"],"names":[],"mappings":"AAOA,OAAO,EAAE,YAAY,IAAI,gBAAgB,EAAE,MAAM,sBAAsB,CAAC;AACxE,OAAO,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AAC9C,OAAO,EAAE,uBAAuB,EAA8B,MAAM,uBAAuB,CAAC;AAE5F,OAAO,EACL,wBAAwB,GAEzB,MAAM,oBAAoB,CAAC;AAI5B,mGAAmG;AACnG,MAAM,CAAC,MAAM,0BAA0B,GAAG,EAAE,CAAC;AAU7C,MAAM,OAAO,yBAA0B,SAAQ,KAAK;IAGhC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ration: startup.runtimeGeneration,
|
|
674
674
|
fact: { type: "sync" },
|
|
675
675
|
source: { providerEventId: null, providerEventType: null },
|
|
676
|
-
});
|
|
676
|
+
}).catch(() => undefined);
|
|
677
677
|
return candidate;
|
|
678
678
|
}
|
|
679
679
|
catch (error) {
|
|
@@ -1217,13 +1217,23 @@ export class ClaudeSession {
|
|
|
1217
1217
|
});
|
|
1218
1218
|
}
|
|
1219
1219
|
if (failure) {
|
|
1220
|
+
this.runtimeDependencies?.logger.error("claude.provider.projection-failed", {
|
|
1221
|
+
threadId: this.threadId, providerEventType: fact.providerEventType, error: failure,
|
|
1222
|
+
});
|
|
1220
1223
|
await this.submitProviderProjection(fact.runtimeGeneration, {
|
|
1221
|
-
type: "
|
|
1224
|
+
type: "runtimeFailed",
|
|
1222
1225
|
runtimeGeneration: fact.runtimeGeneration,
|
|
1223
1226
|
message: `Claude provider projection failed: ${failure}`,
|
|
1224
1227
|
codexErrorInfo: null,
|
|
1225
1228
|
});
|
|
1226
1229
|
runtime.beginClose();
|
|
1230
|
+
// Retire outside the provider consumer: close() drains that same
|
|
1231
|
+
// consumer, so awaiting it here would deadlock.
|
|
1232
|
+
void this.retireRuntime(`Claude provider projection failed: ${failure}`).catch((error) => {
|
|
1233
|
+
this.runtimeDependencies?.logger.error("claude.runtime.retirement-failed", {
|
|
1234
|
+
threadId: this.threadId, error: String(error),
|
|
1235
|
+
});
|
|
1236
|
+
});
|
|
1227
1237
|
}
|
|
1228
1238
|
});
|
|
1229
1239
|
}
|
|
@@ -1455,7 +1465,7 @@ export class ClaudeSession {
|
|
|
1455
1465
|
type: "runtimeLineage",
|
|
1456
1466
|
action: "catalogInvalidated",
|
|
1457
1467
|
runtimeGeneration,
|
|
1458
|
-
});
|
|
1468
|
+
}).catch(() => undefined);
|
|
1459
1469
|
}
|
|
1460
1470
|
}
|
|
1461
1471
|
await this.submitProviderProjection(runtimeGeneration, {
|
|
@@ -1533,7 +1543,7 @@ export class ClaudeSession {
|
|
|
1533
1543
|
type: "runtimeLineage",
|
|
1534
1544
|
action: "catalogInvalidated",
|
|
1535
1545
|
runtimeGeneration,
|
|
1536
|
-
});
|
|
1546
|
+
}).catch(() => undefined);
|
|
1537
1547
|
}
|
|
1538
1548
|
if (result.status === "completed" && message.subtype === "success") {
|
|
1539
1549
|
if (message.structured_output !== undefined) {
|
|
@@ -1585,7 +1595,7 @@ export class ClaudeSession {
|
|
|
1585
1595
|
action: "authFailure",
|
|
1586
1596
|
runtimeGeneration,
|
|
1587
1597
|
reason: message.error,
|
|
1588
|
-
});
|
|
1598
|
+
}).catch(() => undefined);
|
|
1589
1599
|
await this.providerSystemMessage(projection, runtimeGeneration, `Claude authentication failed: ${message.error}`, "error");
|
|
1590
1600
|
}
|
|
1591
1601
|
else if (message.output.length > 0) {
|
|
@@ -3787,7 +3797,9 @@ export class ClaudeSession {
|
|
|
3787
3797
|
...record,
|
|
3788
3798
|
thread: {
|
|
3789
3799
|
...record.thread,
|
|
3790
|
-
status: { type: command.type === "runtimeFailed" ? "systemError"
|
|
3800
|
+
status: { type: command.type === "runtimeFailed" ? "systemError"
|
|
3801
|
+
: record.thread.ephemeral && record.thread.threadSource === "user" && !record.thread.parentThreadId
|
|
3802
|
+
? "idle" : "notLoaded" },
|
|
3791
3803
|
updatedAt: Math.floor(Date.now() / 1_000),
|
|
3792
3804
|
},
|
|
3793
3805
|
};
|
|
@@ -4455,7 +4467,7 @@ export class ClaudeSession {
|
|
|
4455
4467
|
type: "cancelInteraction",
|
|
4456
4468
|
runtimeGeneration: command.runtimeGeneration,
|
|
4457
4469
|
requestId: command.requestId,
|
|
4458
|
-
});
|
|
4470
|
+
}).catch(() => undefined);
|
|
4459
4471
|
};
|
|
4460
4472
|
if (command.signal?.aborted)
|
|
4461
4473
|
queueMicrotask(cancel);
|
|
@@ -5370,26 +5382,21 @@ export class ClaudeSession {
|
|
|
5370
5382
|
}
|
|
5371
5383
|
else if (fact.type === "taskNotification" && active) {
|
|
5372
5384
|
active.notifications += 1;
|
|
5373
|
-
if (active.request && !active.request.started)
|
|
5374
|
-
active.request.covers = active.notifications;
|
|
5375
5385
|
if (active.result && (!active.commandObserved || active.commandCompleted))
|
|
5376
5386
|
this.scheduleContinuation(true);
|
|
5377
5387
|
}
|
|
5378
5388
|
else if (fact.type === "request" && active) {
|
|
5379
|
-
if (!fact.messageStarted
|
|
5380
|
-
|
|
5381
|
-
active.request = { covers: active.notifications, started: false };
|
|
5382
|
-
this.cancelContinuation();
|
|
5383
|
-
}
|
|
5384
|
-
else if (!active.request && (this.hasNotifications() || active.result)) {
|
|
5385
|
-
active.request = { covers: active.notifications, started: false };
|
|
5389
|
+
if (!fact.messageStarted || !active.request) {
|
|
5390
|
+
active.request = { covers: active.notifications, beforeFirstToken: active.notifications, started: false };
|
|
5386
5391
|
this.cancelContinuation();
|
|
5387
5392
|
}
|
|
5388
5393
|
if (fact.messageStarted) {
|
|
5389
5394
|
if (active.result && (this.hasNotifications() || active.goals > 0))
|
|
5390
5395
|
delete active.result;
|
|
5391
|
-
if (active.request)
|
|
5396
|
+
if (active.request && !active.request.started) {
|
|
5397
|
+
active.request.beforeFirstToken = active.notifications;
|
|
5392
5398
|
active.request.started = true;
|
|
5399
|
+
}
|
|
5393
5400
|
active.goalInFlight = active.goals > 0;
|
|
5394
5401
|
this.cancelContinuation();
|
|
5395
5402
|
}
|
|
@@ -5413,7 +5420,11 @@ export class ClaudeSession {
|
|
|
5413
5420
|
active.goalInFlight = false;
|
|
5414
5421
|
}
|
|
5415
5422
|
if (active.request) {
|
|
5416
|
-
|
|
5423
|
+
// A human request cannot consume notifications that arrive while it is
|
|
5424
|
+
// already in flight. A task-notification request may announce its own
|
|
5425
|
+
// notification after requesting, but before its first streamed token.
|
|
5426
|
+
const covers = fact.origin === "task-notification" ? active.request.beforeFirstToken : active.request.covers;
|
|
5427
|
+
active.acknowledged = Math.max(active.acknowledged, covers);
|
|
5417
5428
|
delete active.request;
|
|
5418
5429
|
}
|
|
5419
5430
|
else if (fact.origin === "task-notification")
|
|
@@ -5805,7 +5816,7 @@ export class ClaudeSession {
|
|
|
5805
5816
|
const generation = this.lifecycle.notifications;
|
|
5806
5817
|
this.continuationTimer = setTimeout(() => {
|
|
5807
5818
|
void this.submit({ type: "lifecycle", runtimeGeneration: this.runtimeGeneration,
|
|
5808
|
-
fact: { type: "timer", generation }, source: nullSource });
|
|
5819
|
+
fact: { type: "timer", generation }, source: nullSource }).catch(() => undefined);
|
|
5809
5820
|
}, 5_000);
|
|
5810
5821
|
this.continuationTimer.unref();
|
|
5811
5822
|
}
|