@opencorelabs/lucidity 0.7.0 → 0.8.0
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/README.md +9 -2
- package/dist/assets/speech/lucidity-speech +0 -0
- package/dist/automations/agent.d.ts.map +1 -1
- package/dist/automations/agent.js +2 -0
- package/dist/automations/designer.d.ts +1 -1
- package/dist/chat/server.d.ts +1 -0
- package/dist/chat/server.d.ts.map +1 -1
- package/dist/chat/server.js +6 -1
- package/dist/coding/conduct.d.ts +1 -22
- package/dist/coding/conduct.d.ts.map +1 -1
- package/dist/coding/conduct.js +9 -94
- package/dist/coding/runCodeTurn.d.ts +3 -16
- package/dist/coding/runCodeTurn.d.ts.map +1 -1
- package/dist/coding/runCodeTurn.js +157 -165
- package/dist/coding/workspaceRegistry.d.ts +24 -0
- package/dist/coding/workspaceRegistry.d.ts.map +1 -0
- package/dist/coding/workspaceRegistry.js +230 -0
- package/dist/coding/worktree.d.ts +11 -14
- package/dist/coding/worktree.d.ts.map +1 -1
- package/dist/coding/worktree.js +41 -21
- package/dist/config.d.ts +2 -0
- package/dist/config.d.ts.map +1 -1
- package/dist/daemonLease.d.ts +12 -0
- package/dist/daemonLease.d.ts.map +1 -0
- package/dist/daemonLease.js +32 -0
- package/dist/goals/assessment.d.ts +115 -0
- package/dist/goals/assessment.d.ts.map +1 -0
- package/dist/goals/assessment.js +67 -0
- package/dist/goals/notes.d.ts +18 -0
- package/dist/goals/notes.d.ts.map +1 -0
- package/dist/goals/notes.js +72 -0
- package/dist/index.js +57 -15
- package/dist/jobs/goals.d.ts +15 -0
- package/dist/jobs/goals.d.ts.map +1 -0
- package/dist/jobs/goals.js +286 -0
- package/dist/jobs/weeklyReview.d.ts.map +1 -1
- package/dist/jobs/weeklyReview.js +3 -2
- package/dist/queue.d.ts +1 -0
- package/dist/queue.d.ts.map +1 -1
- package/dist/queue.js +4 -0
- package/dist/room/client.d.ts +5 -0
- package/dist/room/client.d.ts.map +1 -1
- package/dist/room/client.js +116 -101
- package/dist/room/computer.d.ts.map +1 -1
- package/dist/room/computer.js +1 -0
- package/dist/room/durablePublish.d.ts +6 -0
- package/dist/room/durablePublish.d.ts.map +1 -0
- package/dist/room/durablePublish.js +19 -0
- package/dist/room/incidents.d.ts +1 -1
- package/dist/room/incidents.d.ts.map +1 -1
- package/dist/room/incidents.js +14 -7
- package/dist/room/turnQueue.d.ts.map +1 -1
- package/dist/room/turnQueue.js +27 -24
- package/dist/runtimeStore.d.ts +44 -0
- package/dist/runtimeStore.d.ts.map +1 -0
- package/dist/runtimeStore.js +188 -0
- package/dist/setup/server.js +1 -1
- package/dist/turnLog.d.ts +10 -40
- package/dist/turnLog.d.ts.map +1 -1
- package/dist/turnLog.js +33 -56
- package/package.json +4 -4
- package/src/automations/agent.ts +2 -0
- package/src/chat/server.ts +7 -1
- package/src/coding/conduct.ts +10 -147
- package/src/coding/runCodeTurn.ts +42 -61
- package/src/coding/workspaceRegistry.ts +210 -0
- package/src/coding/worktree.ts +44 -20
- package/src/config.ts +2 -0
- package/src/daemonLease.ts +33 -0
- package/src/goals/assessment.ts +106 -0
- package/src/goals/notes.ts +88 -0
- package/src/index.ts +57 -18
- package/src/jobs/goals.ts +384 -0
- package/src/jobs/weeklyReview.ts +4 -3
- package/src/queue.ts +4 -0
- package/src/room/client.ts +77 -74
- package/src/room/computer.ts +1 -0
- package/src/room/durablePublish.ts +25 -0
- package/src/room/incidents.ts +16 -8
- package/src/room/turnQueue.ts +26 -27
- package/src/runtimeStore.ts +190 -0
- package/src/setup/server.ts +1 -1
- package/src/turnLog.ts +32 -75
- package/vendor/mcp-server/dist/index.js +2 -0
- package/vendor/mcp-server/dist/tools/goals.d.ts +4 -0
- package/vendor/mcp-server/dist/tools/goals.d.ts.map +1 -0
- package/vendor/mcp-server/dist/tools/goals.js +38 -0
- package/vendor/mcp-server/package.json +1 -1
- package/vendor/mcp-server/src/index.ts +2 -0
- package/vendor/mcp-server/src/tools/goals.ts +62 -0
- package/vendor/runtime/README.md +2 -2
- package/vendor/runtime/dist/executor/asyncQueue.d.ts +1 -0
- package/vendor/runtime/dist/executor/asyncQueue.d.ts.map +1 -1
- package/vendor/runtime/dist/executor/asyncQueue.js +3 -0
- package/vendor/runtime/dist/executor/claudeAgent.d.ts +1 -1
- package/vendor/runtime/dist/executor/claudeAgent.d.ts.map +1 -1
- package/vendor/runtime/dist/executor/claudeAgent.js +20 -9
- package/vendor/runtime/dist/executor/codex.d.ts +1 -0
- package/vendor/runtime/dist/executor/codex.d.ts.map +1 -1
- package/vendor/runtime/dist/executor/codex.js +68 -36
- package/vendor/runtime/dist/executor/codexProtocol/FunctionCallOutputContentItem.d.ts +4 -1
- package/vendor/runtime/dist/executor/codexProtocol/FunctionCallOutputContentItem.d.ts.map +1 -1
- package/vendor/runtime/dist/executor/codexProtocol/Personality.d.ts +3 -0
- package/vendor/runtime/dist/executor/codexProtocol/Personality.d.ts.map +1 -1
- package/vendor/runtime/dist/executor/codexProtocol/PlanType.d.ts +1 -1
- package/vendor/runtime/dist/executor/codexProtocol/PlanType.d.ts.map +1 -1
- package/vendor/runtime/dist/executor/codexProtocol/v2/CyberAccessProgram.d.ts +6 -0
- package/vendor/runtime/dist/executor/codexProtocol/v2/CyberAccessProgram.d.ts.map +1 -0
- package/vendor/runtime/dist/executor/codexProtocol/v2/CyberAccessProgram.js +2 -0
- package/vendor/runtime/dist/executor/codexProtocol/v2/GetAccountRateLimitsResponse.d.ts +5 -0
- package/vendor/runtime/dist/executor/codexProtocol/v2/GetAccountRateLimitsResponse.d.ts.map +1 -1
- package/vendor/runtime/dist/executor/codexProtocol/v2/Model.d.ts +8 -0
- package/vendor/runtime/dist/executor/codexProtocol/v2/Model.d.ts.map +1 -1
- package/vendor/runtime/dist/executor/codexProtocol/v2/ModelAccessPrograms.d.ts +11 -0
- package/vendor/runtime/dist/executor/codexProtocol/v2/ModelAccessPrograms.d.ts.map +1 -0
- package/vendor/runtime/dist/executor/codexProtocol/v2/ModelAccessPrograms.js +2 -0
- package/vendor/runtime/dist/executor/codexProtocol/v2/RateLimitSnapshot.d.ts +4 -0
- package/vendor/runtime/dist/executor/codexProtocol/v2/RateLimitSnapshot.d.ts.map +1 -1
- package/vendor/runtime/dist/executor/codexProtocol/v2/ReviewStartParams.d.ts +2 -0
- package/vendor/runtime/dist/executor/codexProtocol/v2/ReviewStartParams.d.ts.map +1 -1
- package/vendor/runtime/dist/executor/codexProtocol/v2/ThreadResumeParams.d.ts +4 -1
- package/vendor/runtime/dist/executor/codexProtocol/v2/ThreadResumeParams.d.ts.map +1 -1
- package/vendor/runtime/dist/executor/codexProtocol/v2/ThreadStartParams.d.ts +3 -1
- package/vendor/runtime/dist/executor/codexProtocol/v2/ThreadStartParams.d.ts.map +1 -1
- package/vendor/runtime/dist/executor/codexProtocol/v2/TurnStartParams.d.ts +7 -2
- package/vendor/runtime/dist/executor/codexProtocol/v2/TurnStartParams.d.ts.map +1 -1
- package/vendor/runtime/dist/executor/codexProtocol/v2/UserInput.d.ts +3 -0
- package/vendor/runtime/dist/executor/codexProtocol/v2/UserInput.d.ts.map +1 -1
- package/vendor/runtime/dist/executor/codexRpc.d.ts +10 -3
- package/vendor/runtime/dist/executor/codexRpc.d.ts.map +1 -1
- package/vendor/runtime/dist/executor/codexRpc.js +18 -3
- package/vendor/runtime/dist/executor/codexSessions.d.ts +30 -0
- package/vendor/runtime/dist/executor/codexSessions.d.ts.map +1 -0
- package/vendor/runtime/dist/executor/codexSessions.js +88 -0
- package/vendor/runtime/dist/executor/health.d.ts +2 -1
- package/vendor/runtime/dist/executor/health.d.ts.map +1 -1
- package/vendor/runtime/dist/executor/health.js +17 -5
- package/vendor/runtime/dist/executor/liveTurns.d.ts +2 -1
- package/vendor/runtime/dist/executor/liveTurns.d.ts.map +1 -1
- package/vendor/runtime/dist/executor/liveTurns.js +12 -5
- package/vendor/runtime/dist/executor/ownership.d.ts +35 -0
- package/vendor/runtime/dist/executor/ownership.d.ts.map +1 -0
- package/vendor/runtime/dist/executor/ownership.js +99 -0
- package/vendor/runtime/dist/executor/providerRouter.d.ts +1 -0
- package/vendor/runtime/dist/executor/providerRouter.d.ts.map +1 -1
- package/vendor/runtime/dist/executor/providerRouter.js +5 -0
- package/vendor/runtime/dist/executor/types.d.ts +2 -0
- package/vendor/runtime/dist/executor/types.d.ts.map +1 -1
- package/vendor/runtime/dist/index.d.ts +1 -0
- package/vendor/runtime/dist/index.d.ts.map +1 -1
- package/vendor/runtime/dist/index.js +1 -0
- package/vendor/runtime/src/executor/asyncQueue.ts +3 -0
- package/vendor/runtime/src/executor/claudeAgent.ts +16 -9
- package/vendor/runtime/src/executor/codex.ts +75 -44
- package/vendor/runtime/src/executor/codexProtocol/FunctionCallOutputContentItem.ts +1 -1
- package/vendor/runtime/src/executor/codexProtocol/Personality.ts +3 -0
- package/vendor/runtime/src/executor/codexProtocol/PlanType.ts +1 -1
- package/vendor/runtime/src/executor/codexProtocol/README.md +2 -2
- package/vendor/runtime/src/executor/codexProtocol/v2/CyberAccessProgram.ts +9 -0
- package/vendor/runtime/src/executor/codexProtocol/v2/GetAccountRateLimitsResponse.ts +5 -0
- package/vendor/runtime/src/executor/codexProtocol/v2/Model.ts +11 -2
- package/vendor/runtime/src/executor/codexProtocol/v2/ModelAccessPrograms.ts +13 -0
- package/vendor/runtime/src/executor/codexProtocol/v2/RateLimitSnapshot.ts +5 -1
- package/vendor/runtime/src/executor/codexProtocol/v2/ReviewStartParams.ts +2 -0
- package/vendor/runtime/src/executor/codexProtocol/v2/ThreadResumeParams.ts +5 -1
- package/vendor/runtime/src/executor/codexProtocol/v2/ThreadStartParams.ts +4 -1
- package/vendor/runtime/src/executor/codexProtocol/v2/TurnStartParams.ts +7 -2
- package/vendor/runtime/src/executor/codexProtocol/v2/UserInput.ts +1 -1
- package/vendor/runtime/src/executor/codexRpc.ts +22 -4
- package/vendor/runtime/src/executor/codexSessions.ts +108 -0
- package/vendor/runtime/src/executor/health.ts +16 -6
- package/vendor/runtime/src/executor/liveTurns.ts +12 -5
- package/vendor/runtime/src/executor/ownership.ts +76 -0
- package/vendor/runtime/src/executor/providerRouter.ts +6 -0
- package/vendor/runtime/src/executor/types.ts +2 -0
- package/vendor/runtime/src/index.ts +1 -0
- package/vendor/shared/dist/agentCommands.d.ts +1 -0
- package/vendor/shared/dist/agentCommands.d.ts.map +1 -1
- package/vendor/shared/dist/cardStudio.d.ts +41 -0
- package/vendor/shared/dist/cardStudio.d.ts.map +1 -1
- package/vendor/shared/dist/cardStudio.js +13 -3
- package/vendor/shared/dist/computer.d.ts +7 -1
- package/vendor/shared/dist/computer.d.ts.map +1 -1
- package/vendor/shared/dist/computer.js +12 -2
- package/vendor/shared/dist/constants.d.ts +3 -3
- package/vendor/shared/dist/constants.d.ts.map +1 -1
- package/vendor/shared/dist/constants.js +5 -4
- package/vendor/shared/dist/goalNotes.d.ts +4 -0
- package/vendor/shared/dist/goalNotes.d.ts.map +1 -0
- package/vendor/shared/dist/goalNotes.js +23 -0
- package/vendor/shared/dist/goals.d.ts +835 -0
- package/vendor/shared/dist/goals.d.ts.map +1 -0
- package/vendor/shared/dist/goals.js +198 -0
- package/vendor/shared/dist/index.d.ts +3 -0
- package/vendor/shared/dist/index.d.ts.map +1 -1
- package/vendor/shared/dist/index.js +3 -0
- package/vendor/shared/dist/schemas/harness.d.ts +101 -0
- package/vendor/shared/dist/schemas/harness.d.ts.map +1 -1
- package/vendor/shared/dist/schemas/harness.js +6 -0
- package/vendor/shared/dist/workspaces.d.ts +138 -0
- package/vendor/shared/dist/workspaces.d.ts.map +1 -0
- package/vendor/shared/dist/workspaces.js +40 -0
- package/vendor/shared/src/agentCommands.ts +1 -0
- package/vendor/shared/src/cardStudio.ts +13 -3
- package/vendor/shared/src/computer.ts +16 -2
- package/vendor/shared/src/constants.ts +5 -4
- package/vendor/shared/src/goalNotes.ts +23 -0
- package/vendor/shared/src/goals.ts +237 -0
- package/vendor/shared/src/index.ts +4 -0
- package/vendor/shared/src/schemas/harness.ts +6 -0
- package/vendor/shared/src/workspaces.ts +48 -0
- package/dist/coding/fleetIntegrate.d.ts +0 -37
- package/dist/coding/fleetIntegrate.d.ts.map +0 -1
- package/dist/coding/fleetIntegrate.js +0 -64
- package/dist/coding/openFleetPr.d.ts +0 -41
- package/dist/coding/openFleetPr.d.ts.map +0 -1
- package/dist/coding/openFleetPr.js +0 -121
- package/src/coding/fleetIntegrate.ts +0 -95
- package/src/coding/openFleetPr.ts +0 -148
package/dist/room/client.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { publishDurably } from './durablePublish.js';
|
|
1
2
|
import { computerId, computerRuntime } from './computer.js';
|
|
2
3
|
import { DurableTurnQueue } from './turnQueue.js';
|
|
3
4
|
import { WebSocket } from 'ws';
|
|
@@ -95,8 +96,16 @@ export async function dispatchRequest(raw, deps) {
|
|
|
95
96
|
}
|
|
96
97
|
const req = parsed.data;
|
|
97
98
|
const structured = req.kind === 'ask' && (req.dayPlan ? 'day-plan' : req.projectPlan ? 'project-plan' : undefined);
|
|
98
|
-
|
|
99
|
-
|
|
99
|
+
let deferTerminal = false;
|
|
100
|
+
let terminal;
|
|
101
|
+
const send = (frame) => {
|
|
102
|
+
const event = frame;
|
|
103
|
+
if (deferTerminal && event?.requestId === req.id && (['done', 'error', 'cancelled'].includes(String(event.type)) || ['ask', 'briefing', 'attention'].includes(String(event.kind)))) {
|
|
104
|
+
terminal ??= event;
|
|
105
|
+
return;
|
|
106
|
+
}
|
|
107
|
+
sendFrame(structured ? { ...event, purpose: structured } : frame);
|
|
108
|
+
};
|
|
100
109
|
if (req.kind === 'voice-capture' || req.kind === 'voice-capture-status') {
|
|
101
110
|
try {
|
|
102
111
|
if (!deps.captures)
|
|
@@ -274,13 +283,16 @@ export async function dispatchRequest(raw, deps) {
|
|
|
274
283
|
const controller = inFlight?.get(req.targetId);
|
|
275
284
|
if (controller) {
|
|
276
285
|
controller.abort();
|
|
277
|
-
//
|
|
278
|
-
// landing at maxSeq+1) — a later pull then sees a settled turn.
|
|
279
|
-
send({ type: 'cancelled', requestId: req.targetId });
|
|
286
|
+
// The owner publishes cancellation after the provider and workspace are released.
|
|
280
287
|
}
|
|
281
288
|
else {
|
|
282
|
-
// Conductor workers have provider-owned request IDs, separate from the parent lane.
|
|
283
289
|
await deps.controls?.interrupt(req.targetId);
|
|
290
|
+
// Completion can beat Stop while its terminal frame is lost in transit. Replay
|
|
291
|
+
// the actual outcome so the phone settles without rewriting finished work.
|
|
292
|
+
const state = deps.turnLogs.read(req.targetId);
|
|
293
|
+
if (state.terminated)
|
|
294
|
+
for (const frame of state.frames)
|
|
295
|
+
deps.sendRaw(frame);
|
|
284
296
|
}
|
|
285
297
|
return;
|
|
286
298
|
}
|
|
@@ -311,19 +323,6 @@ export async function dispatchRequest(raw, deps) {
|
|
|
311
323
|
// restores its controls instead of waiting forever for another model token.
|
|
312
324
|
if (!state.terminated && inFlight?.has(req.targetId))
|
|
313
325
|
deps.controls?.publishPending(req.targetId);
|
|
314
|
-
// Open log (no terminal) with no live run owning it → the subprocess died (the daemon
|
|
315
|
-
// restarted mid-turn). Settle it with a synthesized, persisted terminal so the phone
|
|
316
|
-
// stops waiting and a repeat pull is idempotent. If it's still in `inFlight`, live
|
|
317
|
-
// frames past maxSeq keep flowing on the current socket (deduped by seq) — leave it.
|
|
318
|
-
if (!state.terminated &&
|
|
319
|
-
!inFlight?.has(req.targetId) &&
|
|
320
|
-
!deps.turnQueue?.owns(req.targetId)) {
|
|
321
|
-
sendRaw(turnLogs.append(req.targetId, {
|
|
322
|
-
type: 'error',
|
|
323
|
-
requestId: req.targetId,
|
|
324
|
-
message: 'Lucid restarted before finishing this turn.',
|
|
325
|
-
}));
|
|
326
|
-
}
|
|
327
326
|
return;
|
|
328
327
|
}
|
|
329
328
|
if ((req.kind === 'ask' || req.kind === 'code') && req.queue) {
|
|
@@ -343,39 +342,26 @@ export async function dispatchRequest(raw, deps) {
|
|
|
343
342
|
}
|
|
344
343
|
if (deps.recordAcceptance &&
|
|
345
344
|
['ask', 'code', 'conduct', 'briefing', 'attention', 'clone'].includes(req.kind)) {
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
345
|
+
try {
|
|
346
|
+
deps.turnLogs.read(req.id); // Adopt legacy receipts before admission.
|
|
347
|
+
const receipt = deps.turnLogs.runtime.accept(req);
|
|
348
|
+
for (const frame of receipt.frames)
|
|
349
349
|
deps.sendRaw(frame);
|
|
350
|
-
|
|
350
|
+
if (receipt.duplicate || inFlight?.has(req.id))
|
|
351
|
+
return;
|
|
351
352
|
}
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
type: 'accepted',
|
|
356
|
-
requestId: req.id,
|
|
357
|
-
scope: {
|
|
358
|
-
kind: req.kind,
|
|
359
|
-
...('repoId' in req ? { repoId: req.repoId } : {}),
|
|
360
|
-
...('workerId' in req ? { workerId: req.workerId } : {}),
|
|
361
|
-
...('mode' in req ? { mode: req.mode } : {}),
|
|
362
|
-
},
|
|
363
|
-
});
|
|
364
|
-
if (!deps.turnLogs.read(req.id).exists) {
|
|
365
|
-
send({
|
|
366
|
-
type: 'error',
|
|
367
|
-
requestId: req.id,
|
|
368
|
-
message: 'Cannot save the request safely on this computer. Check available disk space and retry.',
|
|
369
|
-
});
|
|
353
|
+
catch (error) {
|
|
354
|
+
deps.sendRaw({ type: 'error', requestId: req.id,
|
|
355
|
+
message: `Cannot accept this request safely: ${error instanceof Error ? error.message : String(error)}` });
|
|
370
356
|
return;
|
|
371
357
|
}
|
|
372
|
-
deps.sendRaw(accepted);
|
|
373
358
|
}
|
|
374
359
|
// Own abort controller per request, combined with the daemon-shutdown signal, so a
|
|
375
360
|
// `cancel` message (stop button) can kill just this run without affecting others.
|
|
376
361
|
const ownController = new AbortController();
|
|
377
362
|
const signal = combineSignals(outerSignal, ownController.signal);
|
|
378
363
|
inFlight?.set(req.id, ownController);
|
|
364
|
+
deferTerminal = true;
|
|
379
365
|
// Wait for the lane INSIDE the try, and after `inFlight.set` above — a turn waiting its turn
|
|
380
366
|
// must still be cancellable, and the `signal?.aborted` checks below mean a cancel that lands
|
|
381
367
|
// while queued drops the run instead of starting it late.
|
|
@@ -519,6 +505,11 @@ export async function dispatchRequest(raw, deps) {
|
|
|
519
505
|
nextBefore: result.nextBefore,
|
|
520
506
|
});
|
|
521
507
|
}
|
|
508
|
+
else if (req.kind === 'workspaces') {
|
|
509
|
+
if (!deps.workspaces)
|
|
510
|
+
throw new Error('Update Lucidity on the computer to use persistent workers.');
|
|
511
|
+
send({ requestId: req.id, kind: 'workspaces', snapshot: await deps.workspaces.command(req.command, req.id) });
|
|
512
|
+
}
|
|
522
513
|
else if (req.kind === 'repos') {
|
|
523
514
|
send({
|
|
524
515
|
requestId: req.id,
|
|
@@ -597,21 +588,11 @@ export async function dispatchRequest(raw, deps) {
|
|
|
597
588
|
}
|
|
598
589
|
else if (req.kind === 'conduct') {
|
|
599
590
|
if (deps.conductHandler) {
|
|
600
|
-
|
|
601
|
-
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
repoId: req.repoId,
|
|
606
|
-
phase: req.phase,
|
|
607
|
-
prompt: req.prompt,
|
|
608
|
-
images: req.images,
|
|
609
|
-
plan: req.plan,
|
|
610
|
-
resume: req.resume,
|
|
611
|
-
// Forward it or a quick spawn silently mints a parent task + subtask anyway: the
|
|
612
|
-
// phone sends `ephemeral`, conduct honours it, and this hop used to drop it.
|
|
613
|
-
ephemeral: req.ephemeral,
|
|
614
|
-
}, { send, signal }));
|
|
591
|
+
await deps.conductHandler({ id: req.id, repoId: req.repoId, phase: req.phase, prompt: req.prompt,
|
|
592
|
+
images: req.images, plan: req.plan, resume: req.resume, ephemeral: req.ephemeral }, {
|
|
593
|
+
send, signal,
|
|
594
|
+
runWorker: (worker, workerDeps) => dispatchRequest(JSON.stringify({ ...worker, kind: 'code', stream: true, mode: 'worktree' }), { ...deps, signal, send: workerDeps.send, recordAcceptance: true }),
|
|
595
|
+
});
|
|
615
596
|
}
|
|
616
597
|
else {
|
|
617
598
|
send({
|
|
@@ -653,8 +634,10 @@ export async function dispatchRequest(raw, deps) {
|
|
|
653
634
|
catch (err) {
|
|
654
635
|
// A deadline/cancel abort surfaces as an AbortError ("The operation was aborted").
|
|
655
636
|
// Never forward that literal text to the phone — end the turn quietly instead.
|
|
656
|
-
if (isAbortError(err))
|
|
637
|
+
if (isAbortError(err)) {
|
|
638
|
+
send({ type: 'cancelled', requestId: req.id });
|
|
657
639
|
return;
|
|
640
|
+
}
|
|
658
641
|
const message = err instanceof Error ? err.message : String(err);
|
|
659
642
|
deps.telemetry?.record('dispatch-error', message, req.id);
|
|
660
643
|
send({ type: 'error', requestId: req.id, message });
|
|
@@ -662,6 +645,11 @@ export async function dispatchRequest(raw, deps) {
|
|
|
662
645
|
finally {
|
|
663
646
|
deps.controls?.end(req.id);
|
|
664
647
|
inFlight?.delete(req.id);
|
|
648
|
+
deferTerminal = false;
|
|
649
|
+
if (signal?.aborted)
|
|
650
|
+
send({ type: 'cancelled', requestId: req.id });
|
|
651
|
+
else if (terminal)
|
|
652
|
+
send(terminal);
|
|
665
653
|
}
|
|
666
654
|
}
|
|
667
655
|
const MAX_BACKOFF_MS = 30_000;
|
|
@@ -776,11 +764,23 @@ export function startRoomClient(opts) {
|
|
|
776
764
|
if (typeof rec.type === 'string' &&
|
|
777
765
|
STREAM_EVENT_TYPES.has(rec.type) &&
|
|
778
766
|
typeof rec.requestId === 'string') {
|
|
779
|
-
|
|
767
|
+
publishDurably(turnLogs, { ...rec, requestId: rec.requestId }, inFlight, sendRaw);
|
|
780
768
|
durableQueue?.wake();
|
|
781
769
|
return;
|
|
782
770
|
}
|
|
783
771
|
}
|
|
772
|
+
const buffered = obj;
|
|
773
|
+
if (buffered && typeof buffered.requestId === 'string' && ['ask', 'briefing', 'attention'].includes(String(buffered.kind))) {
|
|
774
|
+
publishDurably(turnLogs, { ...buffered, type: 'done', requestId: buffered.requestId }, inFlight, (frame) => {
|
|
775
|
+
const saved = frame;
|
|
776
|
+
if (saved.type === 'error')
|
|
777
|
+
sendRaw(frame);
|
|
778
|
+
else
|
|
779
|
+
sendRaw({ ...buffered, seq: saved.seq });
|
|
780
|
+
});
|
|
781
|
+
durableQueue?.wake();
|
|
782
|
+
return;
|
|
783
|
+
}
|
|
784
784
|
sendRaw(obj);
|
|
785
785
|
};
|
|
786
786
|
// The phone's repo list — recomputed live so a freshly-cloned repo appears with no restart, and
|
|
@@ -831,47 +831,55 @@ export function startRoomClient(opts) {
|
|
|
831
831
|
}, delay);
|
|
832
832
|
reconnectTimer.unref?.();
|
|
833
833
|
}
|
|
834
|
-
const
|
|
835
|
-
|
|
836
|
-
|
|
837
|
-
|
|
838
|
-
|
|
839
|
-
|
|
840
|
-
|
|
841
|
-
|
|
842
|
-
|
|
843
|
-
|
|
844
|
-
|
|
845
|
-
|
|
846
|
-
|
|
847
|
-
|
|
848
|
-
|
|
849
|
-
|
|
850
|
-
|
|
851
|
-
|
|
852
|
-
|
|
853
|
-
|
|
854
|
-
|
|
855
|
-
|
|
856
|
-
|
|
857
|
-
|
|
858
|
-
|
|
859
|
-
|
|
860
|
-
|
|
861
|
-
|
|
862
|
-
|
|
863
|
-
|
|
864
|
-
|
|
865
|
-
|
|
866
|
-
|
|
867
|
-
|
|
868
|
-
|
|
869
|
-
|
|
870
|
-
|
|
871
|
-
|
|
872
|
-
|
|
873
|
-
|
|
874
|
-
|
|
834
|
+
const pendingRequests = new Set();
|
|
835
|
+
const dispatch = (raw, overrides = {}) => {
|
|
836
|
+
if (stopped)
|
|
837
|
+
return Promise.resolve();
|
|
838
|
+
const pending = dispatchRequest(raw, {
|
|
839
|
+
harness,
|
|
840
|
+
recordAcceptance: true,
|
|
841
|
+
runtime: opts.providerHealth ? () => computerRuntime(opts) : undefined,
|
|
842
|
+
controls: opts.controls,
|
|
843
|
+
models: opts.models,
|
|
844
|
+
commands: opts.commands,
|
|
845
|
+
askContext,
|
|
846
|
+
briefingContext,
|
|
847
|
+
send: turnSend,
|
|
848
|
+
sendRaw,
|
|
849
|
+
turnLogs,
|
|
850
|
+
workspaces: opts.workspaces,
|
|
851
|
+
signal,
|
|
852
|
+
codeHandler,
|
|
853
|
+
conductHandler,
|
|
854
|
+
cloneHandler,
|
|
855
|
+
queue: executionLanes,
|
|
856
|
+
inFlight,
|
|
857
|
+
attention: opts.attention,
|
|
858
|
+
logger: log,
|
|
859
|
+
// Live allowlist (#78) + each row's live branch (#121); shared with pushRepos above.
|
|
860
|
+
listRepos,
|
|
861
|
+
listPrs: (repoId, mode) => resolvePrs(repoId, mode, config),
|
|
862
|
+
getConfig,
|
|
863
|
+
speech: opts.speech,
|
|
864
|
+
captures,
|
|
865
|
+
automations: opts.automations,
|
|
866
|
+
setConfig: setConfig
|
|
867
|
+
? (patch, restart) => {
|
|
868
|
+
const result = setConfig(patch, restart);
|
|
869
|
+
publishComputer();
|
|
870
|
+
return result;
|
|
871
|
+
}
|
|
872
|
+
: undefined,
|
|
873
|
+
requestRestart,
|
|
874
|
+
telemetry,
|
|
875
|
+
machine: config.machineName,
|
|
876
|
+
incidentsDir: opts.incidentsDir,
|
|
877
|
+
turnQueue: durableQueue,
|
|
878
|
+
...overrides,
|
|
879
|
+
}).finally(() => { pendingRequests.delete(pending); });
|
|
880
|
+
pendingRequests.add(pending);
|
|
881
|
+
return pending;
|
|
882
|
+
};
|
|
875
883
|
durableQueue = new DurableTurnQueue({
|
|
876
884
|
dir: turnLogs.queueDirectory(),
|
|
877
885
|
logs: turnLogs,
|
|
@@ -885,6 +893,7 @@ export function startRoomClient(opts) {
|
|
|
885
893
|
? (targetId, prompt) => opts.controls.steer(targetId, prompt)
|
|
886
894
|
: undefined,
|
|
887
895
|
});
|
|
896
|
+
turnLogs.reconcile((id) => durableQueue.owns(id));
|
|
888
897
|
durableQueue.wake();
|
|
889
898
|
if (opts.speech) {
|
|
890
899
|
// Never resume another account's queued commands after replacing credentials.
|
|
@@ -1014,6 +1023,8 @@ export function startRoomClient(opts) {
|
|
|
1014
1023
|
stopped = true;
|
|
1015
1024
|
captures?.stop();
|
|
1016
1025
|
durableQueue?.stop();
|
|
1026
|
+
for (const controller of inFlight.values())
|
|
1027
|
+
controller.abort();
|
|
1017
1028
|
clearInterval(redialWatchdog);
|
|
1018
1029
|
unsubscribeHealth?.();
|
|
1019
1030
|
if (reconnectTimer) {
|
|
@@ -1031,5 +1042,9 @@ export function startRoomClient(opts) {
|
|
|
1031
1042
|
}
|
|
1032
1043
|
if (!stopped)
|
|
1033
1044
|
connect();
|
|
1034
|
-
return { stop, push: sendRaw, pushRepos
|
|
1045
|
+
return { stop, push: sendRaw, pushRepos, async drain() {
|
|
1046
|
+
while (pendingRequests.size)
|
|
1047
|
+
await Promise.allSettled(pendingRequests);
|
|
1048
|
+
await executionLanes.drain();
|
|
1049
|
+
} };
|
|
1035
1050
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"computer.d.ts","sourceRoot":"","sources":["../../src/room/computer.ts"],"names":[],"mappings":"AAIA,OAAO,EAEL,KAAK,eAAe,EAErB,MAAM,kBAAkB,CAAC;AAC1B,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,aAAa,CAAC;AAGrD,gGAAgG;AAChG,wBAAgB,UAAU,CACxB,IAAI,SAA8C,GACjD,MAAM,CAmBR;AAED,wBAAgB,eAAe,CAAC,IAAI,EAAE,iBAAiB,GAAG,eAAe,
|
|
1
|
+
{"version":3,"file":"computer.d.ts","sourceRoot":"","sources":["../../src/room/computer.ts"],"names":[],"mappings":"AAIA,OAAO,EAEL,KAAK,eAAe,EAErB,MAAM,kBAAkB,CAAC;AAC1B,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,aAAa,CAAC;AAGrD,gGAAgG;AAChG,wBAAgB,UAAU,CACxB,IAAI,SAA8C,GACjD,MAAM,CAmBR;AAED,wBAAgB,eAAe,CAAC,IAAI,EAAE,iBAAiB,GAAG,eAAe,CA4CxE"}
|
package/dist/room/computer.js
CHANGED
|
@@ -54,6 +54,7 @@ export function computerRuntime(opts) {
|
|
|
54
54
|
...(opts.commands ? ['commands'] : []),
|
|
55
55
|
...(opts.controls ? ['permission', 'steer'] : []),
|
|
56
56
|
...(opts.codeHandler ? ['code'] : []),
|
|
57
|
+
...(opts.workspaces ? ['workspaces', 'checkout-history'] : []),
|
|
57
58
|
...(opts.conductHandler ? ['conduct'] : []),
|
|
58
59
|
...(opts.cloneHandler ? ['clone'] : []),
|
|
59
60
|
...(opts.attention ? ['attention'] : []),
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import type { TurnLogStore } from '../turnLog.js';
|
|
2
|
+
/** A durability failure stops owned work. Its uncertain outcome is reported only after release. */
|
|
3
|
+
export declare function publishDurably(logs: TurnLogStore, event: Record<string, unknown> & {
|
|
4
|
+
requestId: string;
|
|
5
|
+
}, inFlight: Map<string, AbortController>, send: (frame: unknown) => void): void;
|
|
6
|
+
//# sourceMappingURL=durablePublish.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"durablePublish.d.ts","sourceRoot":"","sources":["../../src/room/durablePublish.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,eAAe,CAAC;AAIlD,mGAAmG;AACnG,wBAAgB,cAAc,CAC5B,IAAI,EAAE,YAAY,EAClB,KAAK,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG;IAAE,SAAS,EAAE,MAAM,CAAA;CAAE,EACtD,QAAQ,EAAE,GAAG,CAAC,MAAM,EAAE,eAAe,CAAC,EACtC,IAAI,EAAE,CAAC,KAAK,EAAE,OAAO,KAAK,IAAI,GAC7B,IAAI,CAcN"}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
const terminalTypes = new Set(['done', 'error', 'cancelled']);
|
|
2
|
+
/** A durability failure stops owned work. Its uncertain outcome is reported only after release. */
|
|
3
|
+
export function publishDurably(logs, event, inFlight, send) {
|
|
4
|
+
let frame;
|
|
5
|
+
try {
|
|
6
|
+
frame = logs.append(event.requestId, event);
|
|
7
|
+
}
|
|
8
|
+
catch (error) {
|
|
9
|
+
for (const controller of inFlight.values())
|
|
10
|
+
controller.abort();
|
|
11
|
+
if (terminalTypes.has(String(event.type)) && !inFlight.has(event.requestId)) {
|
|
12
|
+
send({ type: 'error', requestId: event.requestId, code: 'durability_fault',
|
|
13
|
+
message: "Computer storage failed. This turn's final outcome could not be saved. Free disk space and restart Lucidity, then inspect the workspace before retrying." });
|
|
14
|
+
return;
|
|
15
|
+
}
|
|
16
|
+
throw error;
|
|
17
|
+
}
|
|
18
|
+
send(frame);
|
|
19
|
+
}
|
package/dist/room/incidents.d.ts
CHANGED
|
@@ -17,7 +17,7 @@ import { type InvariantFinding } from './detectors.js';
|
|
|
17
17
|
* - session-reset — delivered and answered, but from a fresh memoryless session (`freshStart`):
|
|
18
18
|
* the turn succeeded yet lost its thread memory.
|
|
19
19
|
*/
|
|
20
|
-
export type IncidentClass = 'ok' | 'cancelled' | 'pending' | 'outbound-loss' | 'inbound-loss' | 'session-reset';
|
|
20
|
+
export type IncidentClass = 'ok' | 'execution-error' | 'history-unavailable' | 'cancelled' | 'pending' | 'outbound-loss' | 'inbound-loss' | 'session-reset';
|
|
21
21
|
/** The daemon's turn-log view of one turn, reduced to what the join needs. */
|
|
22
22
|
export interface DaemonTurnView {
|
|
23
23
|
exists: boolean;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"incidents.d.ts","sourceRoot":"","sources":["../../src/room/incidents.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EACV,YAAY,EACZ,gBAAgB,EAChB,iBAAiB,EAClB,MAAM,kBAAkB,CAAC;AAC1B,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,eAAe,CAAC;AAE/C,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,gBAAgB,CAAC;AACzD,OAAO,EAGL,KAAK,gBAAgB,EACtB,MAAM,gBAAgB,CAAC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Q,CAAC,EAAE,gBAAgB,CAAC;IAC5B,IAAI,CAAC,EAAE,iBAAiB,EAAE,CAAC;IAC3B,GAAG,CAAC,EAAE,MAAM,MAAM,CAAC;CACpB;AAED,+FAA+F;AAC/F,wBAAgB,mBAAmB,CACjC,IAAI,EAAE,oBAAoB,GACzB,cAAc,CAyHhB;AAED;;;;;GAKG;AACH,wBAAgB,mBAAmB,CACjC,MAAM,EAAE,cAAc,EACtB,GAAG,GAAE,MAAsB,EAC3B,GAAG,GAAE,MAAM,MAAiB,GAC3B,MAAM,GAAG,IAAI,CAUf"}
|
package/dist/room/incidents.js
CHANGED
|
@@ -31,7 +31,9 @@ function terminalTypeOf(frames) {
|
|
|
31
31
|
}
|
|
32
32
|
/** Severity for picking which turn a bundle headlines. Higher = worse. */
|
|
33
33
|
const SEVERITY = {
|
|
34
|
+
'execution-error': 4,
|
|
34
35
|
'outbound-loss': 4,
|
|
36
|
+
'history-unavailable': 1,
|
|
35
37
|
'session-reset': 3,
|
|
36
38
|
'inbound-loss': 2,
|
|
37
39
|
pending: 1,
|
|
@@ -49,7 +51,9 @@ export function classifyTurn(phone, daemon) {
|
|
|
49
51
|
return 'session-reset';
|
|
50
52
|
// The phone got a terminal: a real reply, or a daemon error that reached it. Either way the
|
|
51
53
|
// connection worked — an error the phone displayed is not a connection loss.
|
|
52
|
-
if (phone.state === '
|
|
54
|
+
if (phone.state === 'error')
|
|
55
|
+
return 'execution-error';
|
|
56
|
+
if (phone.state === 'done')
|
|
53
57
|
return 'ok';
|
|
54
58
|
if (phone.state === 'cancelled')
|
|
55
59
|
return 'cancelled';
|
|
@@ -63,14 +67,13 @@ export function classifyTurn(phone, daemon) {
|
|
|
63
67
|
return 'inbound-loss'; // Mac wrote frames the phone never saw
|
|
64
68
|
return 'pending'; // Mac still working, phone has caught up — no loss yet
|
|
65
69
|
}
|
|
66
|
-
//
|
|
67
|
-
//
|
|
68
|
-
// is what turns "no record" into a real outbound loss.
|
|
70
|
+
// Missing legacy logs may have expired. Even a settled phone request is not proof
|
|
71
|
+
// that the daemon never accepted it.
|
|
69
72
|
const settled = phone.state === 'timeout' ||
|
|
70
73
|
phone.state === 'lost' ||
|
|
71
74
|
phone.endedAt != null;
|
|
72
75
|
if (phone.staleSend || phone.transport === 'outbox' || settled)
|
|
73
|
-
return '
|
|
76
|
+
return 'history-unavailable';
|
|
74
77
|
return 'pending';
|
|
75
78
|
}
|
|
76
79
|
/** A turn is truly recoverable only when the Mac finished it with a real reply (`done`). An
|
|
@@ -86,13 +89,17 @@ function noteFor(t) {
|
|
|
86
89
|
const id = requestId.slice(0, 8);
|
|
87
90
|
const missed = Math.max(0, daemon.maxSeq - (phone.seq ?? 0));
|
|
88
91
|
switch (t.class) {
|
|
92
|
+
case 'execution-error':
|
|
93
|
+
return `Turn ${id} delivered an execution error${daemon.terminalDetail ? `: ${daemon.terminalDetail}` : '.'} Inspect that failure before retrying; delivery and execution are separate outcomes.`;
|
|
94
|
+
case 'history-unavailable':
|
|
95
|
+
return `No retained receipt for turn ${id}. Its earlier history may have expired or it may never have been accepted. The outcome is unknown; do not rerun it automatically.`;
|
|
89
96
|
case 'outbound-loss':
|
|
90
97
|
return `Turn ${id} (${phone.kind}) left the phone ${phone.staleSend ? 'on a socket that only looked open' : 'via the outbox'} but the daemon's turn log has no record of it — the prompt never reached the Mac.`;
|
|
91
98
|
case 'inbound-loss':
|
|
92
99
|
// Terminal TYPE decides whether this is a waiting reply or a dead turn — the crux the old
|
|
93
100
|
// "recoverable via a pull" note got wrong (it called a restart-killed turn recoverable).
|
|
94
101
|
if (daemon.terminalType === 'error')
|
|
95
|
-
return `The Mac terminated turn ${id} with an error${daemon.terminalDetail ? ` ("${daemon.terminalDetail}")` : ''} at seq ${daemon.maxSeq}; the phone settled '${phone.state}' at seq ${phone.seq ?? 0}
|
|
102
|
+
return `The Mac terminated turn ${id} with an error${daemon.terminalDetail ? ` ("${daemon.terminalDetail}")` : ''} at seq ${daemon.maxSeq}; the phone settled '${phone.state}' at seq ${phone.seq ?? 0}. The recorded error is available by pull. Inspect workspace and provider state before choosing to retry.`;
|
|
96
103
|
if (daemon.terminalType === 'done')
|
|
97
104
|
return `The Mac ran turn ${id} to completion (done at seq ${daemon.maxSeq}) but the phone settled '${phone.state}' at seq ${phone.seq ?? 0} — it is missing ${missed} frame${missed === 1 ? '' : 's'} incl. the reply, which is on disk and recoverable via a pull.`;
|
|
98
105
|
return `The Mac produced ${daemon.maxSeq} frames for turn ${id} (not yet terminated) but the phone settled '${phone.state}' at seq ${phone.seq ?? 0} — it is ${missed} frame${missed === 1 ? '' : 's'} behind; a pull replays the gap.`;
|
|
@@ -110,7 +117,7 @@ function noteFor(t) {
|
|
|
110
117
|
function pickOffender(turns, focusRequestId) {
|
|
111
118
|
if (focusRequestId) {
|
|
112
119
|
const f = turns.find((t) => t.requestId === focusRequestId);
|
|
113
|
-
if (f
|
|
120
|
+
if (f)
|
|
114
121
|
return f;
|
|
115
122
|
}
|
|
116
123
|
const candidates = turns.filter((t) => SEVERITY[t.class] >= 1);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"turnQueue.d.ts","sourceRoot":"","sources":["../../src/room/turnQueue.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"turnQueue.d.ts","sourceRoot":"","sources":["../../src/room/turnQueue.ts"],"names":[],"mappings":"AAQA,OAAO,EAAwB,KAAK,cAAc,EAAE,MAAM,kBAAkB,CAAC;AAC7E,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,eAAe,CAAC;AAClD,OAAO,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AAExC,KAAK,OAAO,GAAG,OAAO,CAAC,cAAc,EAAE;IAAE,IAAI,EAAE,KAAK,GAAG,MAAM,CAAA;CAAE,CAAC,CAAC;AAQjE,wBAAgB,QAAQ,CAAC,GAAG,EAAE,OAAO,GAAG,MAAM,CAI7C;AAED;uFACuF;AACvF,qBAAa,gBAAgB;IAMzB,OAAO,CAAC,QAAQ,CAAC,IAAI;IALvB,OAAO,CAAC,OAAO,CAA4B;IAC3C,OAAO,CAAC,SAAS,CAAqB;IACtC,OAAO,CAAC,OAAO,CAAS;IACxB,OAAO,CAAC,OAAO,CAAS;gBAEL,IAAI,EAAE;QACrB,GAAG,EAAE,MAAM,CAAC;QACZ,IAAI,EAAE,YAAY,CAAC;QACnB,KAAK,EAAE,SAAS,CAAC;QACjB,OAAO,EAAE,CAAC,KAAK,EAAE,OAAO,KAAK,IAAI,CAAC;QAClC,OAAO,EAAE,CAAC,OAAO,EAAE,OAAO,KAAK,OAAO,CAAC,IAAI,CAAC,CAAC;QAC7C,KAAK,CAAC,EAAE,CAAC,QAAQ,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,KAAK,OAAO,CAAC,IAAI,CAAC,CAAC;KAC7D;IAuEH,OAAO,CAAC,IAAI;IAIZ,OAAO,CAAC,OAAO;IAQf,OAAO,CAAC,QAAQ;IAShB,OAAO,CAAC,OAAO;IAQf,OAAO,CAAC,IAAI;IAOZ,IAAI,CAAC,EAAE,EAAE,MAAM,GAAG,OAAO;IAIzB,OAAO,CAAC,EAAE,EAAE,MAAM,GAAG,IAAI;IAQzB,OAAO,CAAC,OAAO,EAAE,OAAO,GAAG,IAAI;IAkD/B;0FACsF;IACtF,OAAO,CAAC,WAAW;IA0CnB,IAAI,IAAI,IAAI;IAwDN,OAAO,CACX,EAAE,EAAE,MAAM,EACV,MAAM,EAAE,QAAQ,GAAG,OAAO,EAC1B,QAAQ,CAAC,EAAE,MAAM,GAChB,OAAO,CAAC,IAAI,CAAC;IAuChB,IAAI,IAAI,IAAI;CAGb"}
|
package/dist/room/turnQueue.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { mkdirSync, readFileSync, readdirSync,
|
|
1
|
+
import { mkdirSync, readFileSync, readdirSync, statSync, unlinkSync, } from 'node:fs';
|
|
2
2
|
import { join } from 'node:path';
|
|
3
3
|
import { HarnessRequestSchema } from '@lucidity/shared';
|
|
4
4
|
export function turnLane(req) {
|
|
@@ -17,6 +17,8 @@ export class DurableTurnQueue {
|
|
|
17
17
|
constructor(deps) {
|
|
18
18
|
this.deps = deps;
|
|
19
19
|
mkdirSync(deps.dir, { recursive: true, mode: 0o700 });
|
|
20
|
+
for (const entry of deps.logs.runtime.list('queue'))
|
|
21
|
+
this.entries.set(entry.request.id, entry);
|
|
20
22
|
for (const name of readdirSync(deps.dir)
|
|
21
23
|
.filter((name) => name.endsWith('.json'))
|
|
22
24
|
.sort()) {
|
|
@@ -26,6 +28,12 @@ export class DurableTurnQueue {
|
|
|
26
28
|
unlinkSync(join(deps.dir, name));
|
|
27
29
|
continue;
|
|
28
30
|
}
|
|
31
|
+
if (this.entries.has(entry.request.id))
|
|
32
|
+
continue;
|
|
33
|
+
this.deps.logs.runtime.set('queue', entry.request.id, entry);
|
|
34
|
+
this.entries.set(entry.request.id, entry);
|
|
35
|
+
}
|
|
36
|
+
for (const entry of this.entries.values()) {
|
|
29
37
|
const parsed = HarnessRequestSchema.parse(entry.request);
|
|
30
38
|
if (parsed.kind !== 'ask' && parsed.kind !== 'code')
|
|
31
39
|
throw new Error('Invalid queued turn');
|
|
@@ -41,7 +49,7 @@ export class DurableTurnQueue {
|
|
|
41
49
|
});
|
|
42
50
|
}
|
|
43
51
|
else {
|
|
44
|
-
this.fail(entry, 'Lucid restarted during this turn. It was not run again. Review
|
|
52
|
+
this.fail(entry, 'Lucid restarted during this turn. It was not run again. Review its work before continuing.', 'interrupted_unknown');
|
|
45
53
|
}
|
|
46
54
|
}
|
|
47
55
|
else if (entry.state === 'skipped' && !terminal) {
|
|
@@ -53,7 +61,7 @@ export class DurableTurnQueue {
|
|
|
53
61
|
else if (entry.state === 'failed' && !terminal) {
|
|
54
62
|
this.publish(parsed.id, {
|
|
55
63
|
type: 'error',
|
|
56
|
-
message: 'This queued turn could not finish. Review it before resending.',
|
|
64
|
+
...(entry.failure ?? { message: 'This queued turn could not finish. Review it before resending.' }),
|
|
57
65
|
});
|
|
58
66
|
}
|
|
59
67
|
}
|
|
@@ -67,12 +75,7 @@ export class DurableTurnQueue {
|
|
|
67
75
|
}
|
|
68
76
|
}
|
|
69
77
|
save(entry) {
|
|
70
|
-
|
|
71
|
-
writeFileSync(`${path}.tmp`, JSON.stringify(entry), {
|
|
72
|
-
mode: 0o600,
|
|
73
|
-
flush: true,
|
|
74
|
-
});
|
|
75
|
-
renameSync(`${path}.tmp`, path);
|
|
78
|
+
this.deps.logs.runtime.set('queue', entry.request.id, entry);
|
|
76
79
|
this.entries.set(entry.request.id, entry);
|
|
77
80
|
}
|
|
78
81
|
publish(id, event) {
|
|
@@ -96,10 +99,11 @@ export class DurableTurnQueue {
|
|
|
96
99
|
.find((frame) => typeof frame.sessionId === 'string')?.sessionId;
|
|
97
100
|
return typeof value === 'string' ? value : undefined;
|
|
98
101
|
}
|
|
99
|
-
fail(entry, message) {
|
|
100
|
-
|
|
102
|
+
fail(entry, message, code) {
|
|
103
|
+
const failure = { message, ...(code ? { code } : {}) };
|
|
104
|
+
this.save({ ...entry, state: 'failed', failure });
|
|
101
105
|
if (!this.deps.logs.read(entry.request.id).terminated)
|
|
102
|
-
this.publish(entry.request.id, { type: 'error',
|
|
106
|
+
this.publish(entry.request.id, { type: 'error', ...failure });
|
|
103
107
|
this.wake();
|
|
104
108
|
}
|
|
105
109
|
owns(id) {
|
|
@@ -150,14 +154,10 @@ export class DurableTurnQueue {
|
|
|
150
154
|
throw new Error('The preceding turn does not belong to this conversation. Refresh it before sending again.');
|
|
151
155
|
}
|
|
152
156
|
const entry = { request, state: 'queued' };
|
|
153
|
-
this.
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
catch (error) {
|
|
158
|
-
this.save({ ...entry, state: 'failed' });
|
|
159
|
-
throw error;
|
|
160
|
-
}
|
|
157
|
+
const accepted = this.deps.logs.runtime.accept(request, entry);
|
|
158
|
+
this.entries.set(request.id, entry);
|
|
159
|
+
for (const frame of accepted.frames)
|
|
160
|
+
this.deps.sendRaw(frame);
|
|
161
161
|
this.wake();
|
|
162
162
|
}
|
|
163
163
|
/** Skipped queue entries inherit their predecessor, so removing B from A→B→C
|
|
@@ -198,12 +198,12 @@ export class DurableTurnQueue {
|
|
|
198
198
|
return { ready: true, resume };
|
|
199
199
|
}
|
|
200
200
|
wake() {
|
|
201
|
-
if (this.stopped || this.pumping)
|
|
201
|
+
if (this.stopped || this.pumping || !this.deps.logs.runtime.writable)
|
|
202
202
|
return;
|
|
203
203
|
this.pumping = true;
|
|
204
204
|
queueMicrotask(() => {
|
|
205
205
|
this.pumping = false;
|
|
206
|
-
if (this.stopped)
|
|
206
|
+
if (this.stopped || !this.deps.logs.runtime.writable)
|
|
207
207
|
return;
|
|
208
208
|
const occupied = new Set();
|
|
209
209
|
for (const [id, entry] of this.entries) {
|
|
@@ -227,7 +227,7 @@ export class DurableTurnQueue {
|
|
|
227
227
|
void this.deps.lanes
|
|
228
228
|
.run(turnLane(entry.request), async () => {
|
|
229
229
|
const current = this.entries.get(id);
|
|
230
|
-
if (this.stopped || current.state !== 'queued')
|
|
230
|
+
if (this.stopped || !this.deps.logs.runtime.writable || current.state !== 'queued')
|
|
231
231
|
return;
|
|
232
232
|
const previous = this.predecessor(current);
|
|
233
233
|
if (!previous.ready)
|
|
@@ -249,7 +249,10 @@ export class DurableTurnQueue {
|
|
|
249
249
|
else
|
|
250
250
|
this.fail(current, 'The turn ended before completion. Review it before resending.');
|
|
251
251
|
})
|
|
252
|
-
.catch((error) =>
|
|
252
|
+
.catch((error) => {
|
|
253
|
+
if (this.deps.logs.runtime.writable)
|
|
254
|
+
this.fail(this.entries.get(id), String(error.message));
|
|
255
|
+
})
|
|
253
256
|
.finally(() => {
|
|
254
257
|
this.scheduled.delete(id);
|
|
255
258
|
this.wake();
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import type { HarnessRequest } from '@lucidity/shared';
|
|
2
|
+
import type { TurnFrame, TurnState } from './turnLog.js';
|
|
3
|
+
export declare function conversationKey(request: {
|
|
4
|
+
kind: string;
|
|
5
|
+
repoId?: string;
|
|
6
|
+
workerId?: string;
|
|
7
|
+
mode?: string;
|
|
8
|
+
}): string;
|
|
9
|
+
/** Local execution authority. Transactions commit before their receipts reach the transport. */
|
|
10
|
+
export declare class RuntimeStore {
|
|
11
|
+
private db;
|
|
12
|
+
private storageError?;
|
|
13
|
+
get writable(): boolean;
|
|
14
|
+
private write;
|
|
15
|
+
constructor(path: string);
|
|
16
|
+
transaction<T>(action: () => T): T;
|
|
17
|
+
get<T>(bucket: string, id: string): T | undefined;
|
|
18
|
+
set(bucket: string, id: string, value: unknown): void;
|
|
19
|
+
list<T>(bucket: string): T[];
|
|
20
|
+
/** The command and its first replayable receipt are one durable operation. */
|
|
21
|
+
accept(request: HarnessRequest, queuedEntry?: unknown): {
|
|
22
|
+
duplicate: boolean;
|
|
23
|
+
frames: TurnFrame[];
|
|
24
|
+
};
|
|
25
|
+
private appendInside;
|
|
26
|
+
append(id: string, event: Record<string, unknown>): TurnFrame;
|
|
27
|
+
status(id: string): Omit<TurnState, 'frames'>;
|
|
28
|
+
read(id: string): TurnState;
|
|
29
|
+
importLog(id: string, state: TurnState): void;
|
|
30
|
+
commands(conversation: string, page?: {
|
|
31
|
+
before?: string;
|
|
32
|
+
after?: string;
|
|
33
|
+
limit: number;
|
|
34
|
+
}): {
|
|
35
|
+
request: HarnessRequest;
|
|
36
|
+
state: TurnState;
|
|
37
|
+
}[];
|
|
38
|
+
latestSession(conversation: string, after?: string): string | undefined;
|
|
39
|
+
lastCommand(conversation: string): string | undefined;
|
|
40
|
+
unfinished(conversation: string): boolean;
|
|
41
|
+
reconcile(owns: (id: string) => boolean): void;
|
|
42
|
+
close(): void;
|
|
43
|
+
}
|
|
44
|
+
//# sourceMappingURL=runtimeStore.d.ts.map
|