@wjarka/cezarion 0.17.0-dev.3288 → 0.17.0-nightly.20261029.58
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/delegation/routes.d.ts +11 -11
- package/dist/delegation/transport.d.ts +11 -11
- package/dist/server/live-routes.d.ts +6 -6
- package/dist/server/server.d.ts +6 -6
- package/dist/workflows/run.d.ts +38 -1
- package/dist/workflows/run.js +174 -18
- package/dist/workflows/run.js.map +1 -1
- package/package.json +3 -3
- package/dist/workflows/run/human-waits.d.ts +0 -91
- package/dist/workflows/run/human-waits.js +0 -192
- package/dist/workflows/run/human-waits.js.map +0 -1
|
@@ -82,6 +82,17 @@ export declare function createDelegationRoutes(service: DelegationService, crede
|
|
|
82
82
|
"/discover": {
|
|
83
83
|
$post: {
|
|
84
84
|
output: {
|
|
85
|
+
runner: "claude" | "codex" | "cursor" | "omp" | "opencode" | "pi";
|
|
86
|
+
models: {
|
|
87
|
+
id: string;
|
|
88
|
+
label: string;
|
|
89
|
+
description: string;
|
|
90
|
+
effortLevels?: ("high" | "low" | "max" | "medium" | "xhigh")[] | undefined;
|
|
91
|
+
}[];
|
|
92
|
+
source: "cache" | "live" | "unavailable";
|
|
93
|
+
stale: boolean;
|
|
94
|
+
reason?: string | undefined;
|
|
95
|
+
} | {
|
|
85
96
|
scope: "host-default-account";
|
|
86
97
|
runners: {
|
|
87
98
|
status: "connected" | "disconnected" | "not-installed" | "unknown";
|
|
@@ -102,17 +113,6 @@ export declare function createDelegationRoutes(service: DelegationService, crede
|
|
|
102
113
|
reason?: string | undefined;
|
|
103
114
|
}[];
|
|
104
115
|
nextOffset?: number | undefined;
|
|
105
|
-
} | {
|
|
106
|
-
runner: "claude" | "codex" | "cursor" | "omp" | "opencode" | "pi";
|
|
107
|
-
models: {
|
|
108
|
-
id: string;
|
|
109
|
-
label: string;
|
|
110
|
-
description: string;
|
|
111
|
-
effortLevels?: ("high" | "low" | "max" | "medium" | "xhigh")[] | undefined;
|
|
112
|
-
}[];
|
|
113
|
-
source: "cache" | "live" | "unavailable";
|
|
114
|
-
stale: boolean;
|
|
115
|
-
reason?: string | undefined;
|
|
116
116
|
};
|
|
117
117
|
outputFormat: "json";
|
|
118
118
|
status: 200;
|
|
@@ -65,17 +65,6 @@ export declare function createDelegationApp(routes: DelegationRoutes): import("h
|
|
|
65
65
|
authFailureId?: string | undefined;
|
|
66
66
|
runner: "claude" | "codex" | "cursor" | "omp" | "opencode" | "pi";
|
|
67
67
|
}[];
|
|
68
|
-
} | {
|
|
69
|
-
runner: "claude" | "codex" | "cursor" | "omp" | "opencode" | "pi";
|
|
70
|
-
models: {
|
|
71
|
-
id: string;
|
|
72
|
-
label: string;
|
|
73
|
-
description: string;
|
|
74
|
-
effortLevels?: ("high" | "low" | "max" | "medium" | "xhigh")[] | undefined;
|
|
75
|
-
}[];
|
|
76
|
-
source: "cache" | "live" | "unavailable";
|
|
77
|
-
stale: boolean;
|
|
78
|
-
reason?: string | undefined;
|
|
79
68
|
} | {
|
|
80
69
|
tasks: {
|
|
81
70
|
id: string;
|
|
@@ -88,6 +77,17 @@ export declare function createDelegationApp(routes: DelegationRoutes): import("h
|
|
|
88
77
|
reason?: string | undefined;
|
|
89
78
|
}[];
|
|
90
79
|
nextOffset?: number | undefined;
|
|
80
|
+
} | {
|
|
81
|
+
runner: "claude" | "codex" | "cursor" | "omp" | "opencode" | "pi";
|
|
82
|
+
models: {
|
|
83
|
+
id: string;
|
|
84
|
+
label: string;
|
|
85
|
+
description: string;
|
|
86
|
+
effortLevels?: ("high" | "low" | "max" | "medium" | "xhigh")[] | undefined;
|
|
87
|
+
}[];
|
|
88
|
+
source: "cache" | "live" | "unavailable";
|
|
89
|
+
stale: boolean;
|
|
90
|
+
reason?: string | undefined;
|
|
91
91
|
};
|
|
92
92
|
outputFormat: "json";
|
|
93
93
|
status: 200;
|
|
@@ -11,12 +11,6 @@ export declare function createLiveRoutes({ resolveProject, serverGeneration, res
|
|
|
11
11
|
output: {
|
|
12
12
|
generation: string;
|
|
13
13
|
results: ({
|
|
14
|
-
projectId: string;
|
|
15
|
-
runId: string;
|
|
16
|
-
type: "error" | "reset";
|
|
17
|
-
status: 400 | 404 | 409 | 413 | 503;
|
|
18
|
-
error: string;
|
|
19
|
-
} | {
|
|
20
14
|
projectId: string;
|
|
21
15
|
runId: string;
|
|
22
16
|
type: "batch";
|
|
@@ -30,6 +24,12 @@ export declare function createLiveRoutes({ resolveProject, serverGeneration, res
|
|
|
30
24
|
cursor: string;
|
|
31
25
|
afterSeq: number;
|
|
32
26
|
hasMore: boolean;
|
|
27
|
+
} | {
|
|
28
|
+
projectId: string;
|
|
29
|
+
runId: string;
|
|
30
|
+
type: "error" | "reset";
|
|
31
|
+
status: 400 | 404 | 409 | 413 | 503;
|
|
32
|
+
error: string;
|
|
33
33
|
})[];
|
|
34
34
|
};
|
|
35
35
|
outputFormat: "json";
|
package/dist/server/server.d.ts
CHANGED
|
@@ -404,12 +404,6 @@ export declare function createApp(deps: ServerDeps): import("hono/hono-base").Ho
|
|
|
404
404
|
output: {
|
|
405
405
|
generation: string;
|
|
406
406
|
results: ({
|
|
407
|
-
projectId: string;
|
|
408
|
-
runId: string;
|
|
409
|
-
type: "error" | "reset";
|
|
410
|
-
status: 400 | 404 | 409 | 413 | 503;
|
|
411
|
-
error: string;
|
|
412
|
-
} | {
|
|
413
407
|
projectId: string;
|
|
414
408
|
runId: string;
|
|
415
409
|
type: "batch";
|
|
@@ -423,6 +417,12 @@ export declare function createApp(deps: ServerDeps): import("hono/hono-base").Ho
|
|
|
423
417
|
cursor: string;
|
|
424
418
|
afterSeq: number;
|
|
425
419
|
hasMore: boolean;
|
|
420
|
+
} | {
|
|
421
|
+
projectId: string;
|
|
422
|
+
runId: string;
|
|
423
|
+
type: "error" | "reset";
|
|
424
|
+
status: 400 | 404 | 409 | 413 | 503;
|
|
425
|
+
error: string;
|
|
426
426
|
})[];
|
|
427
427
|
};
|
|
428
428
|
outputFormat: "json";
|
package/dist/workflows/run.d.ts
CHANGED
|
@@ -101,7 +101,6 @@ export declare class RunManager {
|
|
|
101
101
|
private readonly repoRoot;
|
|
102
102
|
private readonly active;
|
|
103
103
|
private readonly inputReceiptContext;
|
|
104
|
-
private readonly humanWaits;
|
|
105
104
|
private readonly inputReceiptSteps;
|
|
106
105
|
private readonly inputReceiptHost;
|
|
107
106
|
private readonly queue;
|
|
@@ -1309,18 +1308,56 @@ export declare class RunManager {
|
|
|
1309
1308
|
* item-shape cache are session-scoped, like the mapper state feeding them.
|
|
1310
1309
|
*/
|
|
1311
1310
|
private makeUiSink;
|
|
1311
|
+
/** Ask precedence: the question is pending, and no autonomous nudge goes beside it. Durable
|
|
1312
|
+
* input and waits stay queued until an actual human answer. */
|
|
1312
1313
|
private prepareHumanAsk;
|
|
1314
|
+
/** The human gate a human wait without a card raises (the monitoring line with re-checks off):
|
|
1315
|
+
* `PROSE_HUMAN_GATE` names it in the transcript. Keep the checkpoint through idle closure/restart
|
|
1316
|
+
* and hold worker input until a successful human delivery, just as for a structured ask. */
|
|
1313
1317
|
private raiseHumanGate;
|
|
1318
|
+
/** The open human wait nobody has shown the user yet (hearsay-tools/cezarion#1234): one this
|
|
1319
|
+
* turn registered, or one a failure, close or crash caught before its turn end. */
|
|
1314
1320
|
private unsurfacedHumanWait;
|
|
1321
|
+
/** The human wait this turn end raises: one nobody has seen yet. One registered while a question
|
|
1322
|
+
* is pending waits on that question instead, and raises nothing. */
|
|
1315
1323
|
private turnEndHumanWait;
|
|
1324
|
+
/** An alias's human wait, or the one already open: a run holds one. A full list opens none. */
|
|
1316
1325
|
private openHumanAlias;
|
|
1326
|
+
/** Record which question a human wait is shown as: the pending card or gate, whose answer settles
|
|
1327
|
+
* it. A card shown in place of the wait's own replaces it. A wait already shown is left alone. */
|
|
1317
1328
|
private markHumanWaitSurfaced;
|
|
1329
|
+
/**
|
|
1330
|
+
* Show a human wait outside its turn end (hearsay-tools/cezarion#1234): at a boundary, at the
|
|
1331
|
+
* budget, or from the failure, close and recovery paths, where no turn end will. A card raises
|
|
1332
|
+
* `ask.requested` and goes to a worker's parent; a wait without one raises the human gate. A
|
|
1333
|
+
* question already pending is the one it waits on. A wait already shown is left alone. Cezar's
|
|
1334
|
+
* own wait is shown as its note instead (`showCezarHumanWait`).
|
|
1335
|
+
*/
|
|
1318
1336
|
private surfaceHumanWait;
|
|
1337
|
+
/**
|
|
1338
|
+
* Cezar's own human wait (`no-wait`, `budget`) is shown as a note, recorded as its `askSeq`, and
|
|
1339
|
+
* raises no human gate (hearsay-tools/cezarion#1234). The agent asked nothing: the run waits for
|
|
1340
|
+
* the user as the plain park did before these waits, so worker messages still wake it and its
|
|
1341
|
+
* wait registrations, `cezar_done` and the user's Finish are not refused. The user's message
|
|
1342
|
+
* settles it, and the agent's own wait or question replaces it (`withdrawCezarHumanWaits`).
|
|
1343
|
+
*/
|
|
1319
1344
|
private showCezarHumanWait;
|
|
1345
|
+
/** Cezar waited on the user only because the agent had nothing to wait on: the agent's own wait
|
|
1346
|
+
* or question replaces that wait (hearsay-tools/cezarion#1234). It also ends with the session
|
|
1347
|
+
* that opened it, so a close, an idle close or a failure settles as the plain park did. */
|
|
1320
1348
|
private withdrawCezarHumanWaits;
|
|
1349
|
+
/** Whether a closing session leaves the run waits to park on. Cezar's own human waits end with the
|
|
1350
|
+
* session, even when the store refused their cancellation (`withdrawCezarHumanWaits`). */
|
|
1321
1351
|
private holdsAgentWaits;
|
|
1352
|
+
/** A valid ask line replaces the card of the human wait its turn registered. It is saved
|
|
1353
|
+
* before the turn end can re-enter a boundary (Cursor print's ready callback from
|
|
1354
|
+
* `discardQueuedMessages`), so a wait shown there shows the later card. */
|
|
1322
1355
|
private latchAskLineCard;
|
|
1356
|
+
/** Read fresh: a boundary the turn end re-enters (Cursor print's ready callback from
|
|
1357
|
+
* `discardQueuedMessages`) may have shown the wait already, and its card stands. */
|
|
1323
1358
|
private humanWaitShown;
|
|
1359
|
+
/** The turn end raised a card or the gate: record the human wait it shows. A turn that registered
|
|
1360
|
+
* none opens the ask line's. */
|
|
1324
1361
|
private recordTurnEndQuestion;
|
|
1325
1362
|
/** Native backend asks arrive before turn-end. Persist and park immediately
|
|
1326
1363
|
* so the cockpit shows attention and the run releases its workspace slot. */
|
package/dist/workflows/run.js
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import { HumanWaits } from './run/human-waits.js';
|
|
2
1
|
import { WorktreeAutosave } from './run/worktree-autosave.js';
|
|
3
2
|
import { RunSkills } from './run/run-skills.js';
|
|
4
3
|
import { InboxClaims } from './run/inbox-claims.js';
|
|
@@ -19,7 +18,7 @@ import { cezarAskRequestSchema, cezarDoneRequestSchema, cezarWaitRequestSchema,
|
|
|
19
18
|
import { ciWaitResultSchema } from '../contract/index.js';
|
|
20
19
|
import { NO_WAIT_NUDGE_NOTE, NO_WAIT_NOTE, NO_WAIT_NO_REPLY_NOTE, COMPLETION_NO_REPLY_NOTE, WORKER_FALLBACK_NOTE, WORKER_FALLBACK_REPLY_NOTE, COMPLETION_NUDGE_NOTE, AUTONOMOUS_ASK_NOTE, AUTONOMOUS_NUDGE, decideTurnEnd, stepScopedNudge } from './turn-end.js';
|
|
21
20
|
import { createActiveRun } from './active-run.js';
|
|
22
|
-
import { claudeScheduleWakeupDelay, isRunnerActivity, emitAskRequested, askCardFields, classifyTurnEnd, discardQueuedMessagesOnAsk } from './run/turn-markers.js';
|
|
21
|
+
import { claudeScheduleWakeupDelay, isRunnerActivity, emitAskRequested, askCardFields, humanWaitCard, classifyTurnEnd, discardQueuedMessagesOnAsk } from './run/turn-markers.js';
|
|
23
22
|
export { claudeScheduleWakeupDelay, appendTurnText, trackTurnTail, classifyTurnEnd } from './run/turn-markers.js';
|
|
24
23
|
import { canProceedWithRun, executionBlockedByRootFinish, historyDeletionPending, rootFinishRequested } from './run/run-guards.js';
|
|
25
24
|
import { beginUsageInvocation, recordReportedCost, recordUsageUiEvent, recordUsagePeaks } from './run/usage-accounting.js';
|
|
@@ -113,7 +112,7 @@ import { QUICK_TASK_WORKFLOW, chainStepNote, stepKind, stepToolGrant, toolGrantL
|
|
|
113
112
|
const CHECK_OUTPUT_CAP = 20_000;
|
|
114
113
|
/** An interactive session that hears nothing from the user closes itself. */
|
|
115
114
|
export const IDLE_TIMEOUT_MS = 15 * 60_000;
|
|
116
|
-
import { workerOutcomeKey } from '../runs/transcript-facts.js';
|
|
115
|
+
import { PROSE_HUMAN_GATE, workerOutcomeKey } from '../runs/transcript-facts.js';
|
|
117
116
|
/** #505: a worker question routed to its parent is answered there until it falls back. */
|
|
118
117
|
const ROUTED_QUESTION_REFUSAL = 'This question was sent to the parent task; answer it there.';
|
|
119
118
|
function isSyntheticContinuation(run, step) {
|
|
@@ -222,7 +221,6 @@ export class RunManager {
|
|
|
222
221
|
repoRoot;
|
|
223
222
|
active = new Map();
|
|
224
223
|
inputReceiptContext;
|
|
225
|
-
humanWaits;
|
|
226
224
|
inputReceiptSteps = {
|
|
227
225
|
clearUnread: state => this.clearUnreadInputTimer(state), clearHeld: state => this.clearHeldHumanInputTimer(state),
|
|
228
226
|
noteActivity: (id, state, event) => this.noteNoWaitNudgeContent(id, state, event),
|
|
@@ -464,7 +462,6 @@ export class RunManager {
|
|
|
464
462
|
this.noWaitNudgeReplyMs = options.noWaitNudgeReplyMs ?? NO_WAIT_NUDGE_REPLY_MS;
|
|
465
463
|
this.semaphore = options.semaphore ?? new WorkspaceSemaphore();
|
|
466
464
|
this.inputReceiptContext = { store, repoRoot, dataDir: this.dataDir, semaphore: this.semaphore, disposed: () => this.disposed };
|
|
467
|
-
this.humanWaits = new HumanWaits(this.inputReceiptContext, { routeWorkerQuestion: id => this.routeWorkerQuestion(id) }, MAX_AUTO_CONTINUES);
|
|
468
465
|
this.worktreeAutosave = new WorktreeAutosave(this.inputReceiptContext, { holdForMaintenance: ids => this.holdForMaintenance(ids),
|
|
469
466
|
reapTerminalScratch: id => this.reapTerminalScratch(id), releaseSlot: () => this.releaseSlot(),
|
|
470
467
|
saveWorktree: (id, state, reason) => this.saveWorktree(id, state, reason),
|
|
@@ -6341,19 +6338,178 @@ export class RunManager {
|
|
|
6341
6338
|
emitLive: (event) => this.store.emitEphemeral(runId, { ...event, stepId }),
|
|
6342
6339
|
});
|
|
6343
6340
|
}
|
|
6344
|
-
|
|
6345
|
-
|
|
6346
|
-
|
|
6347
|
-
|
|
6348
|
-
|
|
6349
|
-
|
|
6350
|
-
|
|
6351
|
-
|
|
6352
|
-
|
|
6353
|
-
|
|
6354
|
-
|
|
6355
|
-
|
|
6356
|
-
|
|
6341
|
+
/** Ask precedence: the question is pending, and no autonomous nudge goes beside it. Durable
|
|
6342
|
+
* input and waits stay queued until an actual human answer. */
|
|
6343
|
+
prepareHumanAsk(state) {
|
|
6344
|
+
state.autonomousNudgePending = undefined;
|
|
6345
|
+
state.pendingHumanAsk = true;
|
|
6346
|
+
}
|
|
6347
|
+
/** The human gate a human wait without a card raises (the monitoring line with re-checks off):
|
|
6348
|
+
* `PROSE_HUMAN_GATE` names it in the transcript. Keep the checkpoint through idle closure/restart
|
|
6349
|
+
* and hold worker input until a successful human delivery, just as for a structured ask. */
|
|
6350
|
+
raiseHumanGate(runId, state) {
|
|
6351
|
+
this.store.appendEvent(runId, { type: 'note', stepId: state.currentStepId,
|
|
6352
|
+
code: PROSE_HUMAN_GATE, message: 'waiting for a human response to the assistant’s request' });
|
|
6353
|
+
this.prepareHumanAsk(state);
|
|
6354
|
+
clearUnreadInputTimer(state);
|
|
6355
|
+
clearHeldHumanInputTimer(state);
|
|
6356
|
+
}
|
|
6357
|
+
/** The open human wait nobody has shown the user yet (hearsay-tools/cezarion#1234): one this
|
|
6358
|
+
* turn registered, or one a failure, close or crash caught before its turn end. */
|
|
6359
|
+
unsurfacedHumanWait(runId) {
|
|
6360
|
+
return openWaits(this.store.getRun(runId) ?? {}).find((wait) => wait.kind === 'human' && wait.askSeq === undefined);
|
|
6361
|
+
}
|
|
6362
|
+
/** The human wait this turn end raises: one nobody has seen yet. One registered while a question
|
|
6363
|
+
* is pending waits on that question instead, and raises nothing. */
|
|
6364
|
+
turnEndHumanWait(runId) {
|
|
6365
|
+
const wait = this.unsurfacedHumanWait(runId);
|
|
6366
|
+
if (!wait || !this.hasPendingHumanAsk(runId))
|
|
6367
|
+
return wait;
|
|
6368
|
+
this.markHumanWaitSurfaced(runId, wait);
|
|
6369
|
+
return undefined;
|
|
6370
|
+
}
|
|
6371
|
+
/** An alias's human wait, or the one already open: a run holds one. A full list opens none. */
|
|
6372
|
+
openHumanAlias(runId, state, via, card) {
|
|
6373
|
+
const run = this.store.getRun(runId);
|
|
6374
|
+
if (!run)
|
|
6375
|
+
return undefined;
|
|
6376
|
+
const source = via === 'budget' || via === 'no-wait' || via === 'completion' ? 'cezar' : 'agent';
|
|
6377
|
+
if (source === 'agent')
|
|
6378
|
+
this.withdrawCezarHumanWaits(runId);
|
|
6379
|
+
const open = openWaits(this.store.getRun(runId) ?? run).find((wait) => wait.kind === 'human');
|
|
6380
|
+
if (open || openWaits(this.store.getRun(runId) ?? run).length >= WAIT_LIMIT)
|
|
6381
|
+
return open;
|
|
6382
|
+
const wait = { id: randomUUID(), kind: 'human', source, via,
|
|
6383
|
+
registeredAt: new Date().toISOString(), phase: 'open', turnId: state?.ciTurnId ?? via, ...(card ? askCardFields(card) : {}) };
|
|
6384
|
+
try {
|
|
6385
|
+
this.store.commitWait(runId, wait);
|
|
6386
|
+
}
|
|
6387
|
+
catch (error) {
|
|
6388
|
+
console.warn(`[cez] human wait checkpoint failed: ${error instanceof Error ? error.message : String(error)}`);
|
|
6389
|
+
return undefined;
|
|
6390
|
+
}
|
|
6391
|
+
return wait;
|
|
6392
|
+
}
|
|
6393
|
+
/** Record which question a human wait is shown as: the pending card or gate, whose answer settles
|
|
6394
|
+
* it. A card shown in place of the wait's own replaces it. A wait already shown is left alone. */
|
|
6395
|
+
markHumanWaitSurfaced(runId, wait, shownCard) {
|
|
6396
|
+
const askSeq = this.pendingHumanAskSeq(runId);
|
|
6397
|
+
const latest = this.store.getRun(runId)?.waits?.find((entry) => entry.id === wait.id && entry.kind === 'human');
|
|
6398
|
+
if (askSeq === undefined || !latest || latest.phase !== 'open' || latest.askSeq !== undefined)
|
|
6399
|
+
return;
|
|
6400
|
+
const { questions: _questions, context: _context, ...kept } = latest;
|
|
6401
|
+
const card = shownCard ?? humanWaitCard(latest);
|
|
6402
|
+
try {
|
|
6403
|
+
this.store.commitWait(runId, { ...kept, ...(card ? askCardFields(card) : {}), askSeq });
|
|
6404
|
+
}
|
|
6405
|
+
catch (error) {
|
|
6406
|
+
console.warn(`[cez] human wait checkpoint failed: ${error instanceof Error ? error.message : String(error)}`);
|
|
6407
|
+
}
|
|
6408
|
+
}
|
|
6409
|
+
/**
|
|
6410
|
+
* Show a human wait outside its turn end (hearsay-tools/cezarion#1234): at a boundary, at the
|
|
6411
|
+
* budget, or from the failure, close and recovery paths, where no turn end will. A card raises
|
|
6412
|
+
* `ask.requested` and goes to a worker's parent; a wait without one raises the human gate. A
|
|
6413
|
+
* question already pending is the one it waits on. A wait already shown is left alone. Cezar's
|
|
6414
|
+
* own wait is shown as its note instead (`showCezarHumanWait`).
|
|
6415
|
+
*/
|
|
6416
|
+
surfaceHumanWait(runId, state, wait = this.unsurfacedHumanWait(runId)) {
|
|
6417
|
+
if (!wait || wait.askSeq !== undefined)
|
|
6418
|
+
return;
|
|
6419
|
+
if (wait.source === 'cezar') {
|
|
6420
|
+
this.showCezarHumanWait(runId, state, wait);
|
|
6421
|
+
return;
|
|
6422
|
+
}
|
|
6423
|
+
if (this.pendingHumanAskSeq(runId) === undefined) {
|
|
6424
|
+
const run = this.store.getRun(runId);
|
|
6425
|
+
const stepId = state?.currentStepId ?? run?.currentStepId ?? run?.steps.at(-1)?.id;
|
|
6426
|
+
if (wait.questions) {
|
|
6427
|
+
this.store.appendEvent(runId, { type: 'ask.requested', requestId: randomUUID(), ...askCardFields({ questions: wait.questions, context: wait.context }), ...(stepId ? { stepId } : {}) });
|
|
6428
|
+
if (state)
|
|
6429
|
+
this.prepareHumanAsk(state);
|
|
6430
|
+
}
|
|
6431
|
+
else if (state)
|
|
6432
|
+
this.raiseHumanGate(runId, state);
|
|
6433
|
+
else {
|
|
6434
|
+
this.store.appendEvent(runId, { type: 'note', ...(stepId ? { stepId } : {}), code: PROSE_HUMAN_GATE, message: 'waiting for a human response to the assistant’s request' });
|
|
6435
|
+
}
|
|
6436
|
+
}
|
|
6437
|
+
else if (state)
|
|
6438
|
+
state.pendingHumanAsk = true;
|
|
6439
|
+
this.markHumanWaitSurfaced(runId, wait);
|
|
6440
|
+
this.routeWorkerQuestion(runId);
|
|
6441
|
+
}
|
|
6442
|
+
/**
|
|
6443
|
+
* Cezar's own human wait (`no-wait`, `budget`) is shown as a note, recorded as its `askSeq`, and
|
|
6444
|
+
* raises no human gate (hearsay-tools/cezarion#1234). The agent asked nothing: the run waits for
|
|
6445
|
+
* the user as the plain park did before these waits, so worker messages still wake it and its
|
|
6446
|
+
* wait registrations, `cezar_done` and the user's Finish are not refused. The user's message
|
|
6447
|
+
* settles it, and the agent's own wait or question replaces it (`withdrawCezarHumanWaits`).
|
|
6448
|
+
*/
|
|
6449
|
+
showCezarHumanWait(runId, state, wait, note) {
|
|
6450
|
+
const run = this.store.getRun(runId);
|
|
6451
|
+
const stepId = state?.currentStepId ?? run?.currentStepId ?? run?.steps.at(-1)?.id;
|
|
6452
|
+
const shown = this.store.appendEvent(runId, { type: 'note', ...(stepId ? { stepId } : {}),
|
|
6453
|
+
message: note ?? (wait.via === 'no-wait' ? NO_WAIT_NOTE : wait.via === 'completion' ? 'completion blocked; waiting for you'
|
|
6454
|
+
: `automatic-wake budget spent (${MAX_AUTO_CONTINUES}); waiting for you`) });
|
|
6455
|
+
const latest = run?.waits?.find((entry) => entry.id === wait.id && entry.kind === 'human');
|
|
6456
|
+
if (!latest || latest.phase !== 'open' || latest.askSeq !== undefined)
|
|
6457
|
+
return;
|
|
6458
|
+
try {
|
|
6459
|
+
this.store.commitWait(runId, { ...latest, askSeq: shown.seq });
|
|
6460
|
+
}
|
|
6461
|
+
catch (error) {
|
|
6462
|
+
console.warn(`[cez] human wait checkpoint failed: ${error instanceof Error ? error.message : String(error)}`);
|
|
6463
|
+
}
|
|
6464
|
+
}
|
|
6465
|
+
/** Cezar waited on the user only because the agent had nothing to wait on: the agent's own wait
|
|
6466
|
+
* or question replaces that wait (hearsay-tools/cezarion#1234). It also ends with the session
|
|
6467
|
+
* that opened it, so a close, an idle close or a failure settles as the plain park did. */
|
|
6468
|
+
withdrawCezarHumanWaits(runId) {
|
|
6469
|
+
const ids = openWaits(this.store.getRun(runId) ?? {}).filter(isCezarHumanWait).map(wait => wait.id);
|
|
6470
|
+
if (!ids.length)
|
|
6471
|
+
return;
|
|
6472
|
+
try {
|
|
6473
|
+
this.store.commitOutcome(runId, { kind: 'cancelled', waitIds: ids });
|
|
6474
|
+
}
|
|
6475
|
+
catch (error) {
|
|
6476
|
+
console.warn(`[cez] human wait checkpoint failed: ${error instanceof Error ? error.message : String(error)}`);
|
|
6477
|
+
}
|
|
6478
|
+
}
|
|
6479
|
+
/** Whether a closing session leaves the run waits to park on. Cezar's own human waits end with the
|
|
6480
|
+
* session, even when the store refused their cancellation (`withdrawCezarHumanWaits`). */
|
|
6481
|
+
holdsAgentWaits(runId) {
|
|
6482
|
+
return (this.store.getRun(runId)?.waits ?? []).some(wait => !isCezarHumanWait(wait));
|
|
6483
|
+
}
|
|
6484
|
+
/** A valid ask line replaces the card of the human wait its turn registered. It is saved
|
|
6485
|
+
* before the turn end can re-enter a boundary (Cursor print's ready callback from
|
|
6486
|
+
* `discardQueuedMessages`), so a wait shown there shows the later card. */
|
|
6487
|
+
latchAskLineCard(runId, wait, turn) {
|
|
6488
|
+
if (!wait || !turn.ask || turn.waitCard)
|
|
6489
|
+
return;
|
|
6490
|
+
const latest = this.store.getRun(runId)?.waits?.find((entry) => entry.id === wait.id && entry.kind === 'human');
|
|
6491
|
+
if (!latest || latest.phase !== 'open' || latest.askSeq !== undefined)
|
|
6492
|
+
return;
|
|
6493
|
+
const { context: _replaced, ...kept } = latest;
|
|
6494
|
+
try {
|
|
6495
|
+
this.store.commitWait(runId, { ...kept, ...askCardFields(turn.ask) });
|
|
6496
|
+
}
|
|
6497
|
+
catch (error) {
|
|
6498
|
+
console.warn(`[cez] human wait checkpoint failed: ${error instanceof Error ? error.message : String(error)}`);
|
|
6499
|
+
}
|
|
6500
|
+
}
|
|
6501
|
+
/** Read fresh: a boundary the turn end re-enters (Cursor print's ready callback from
|
|
6502
|
+
* `discardQueuedMessages`) may have shown the wait already, and its card stands. */
|
|
6503
|
+
humanWaitShown(runId, wait) {
|
|
6504
|
+
return !!wait && this.store.getRun(runId)?.waits?.some(entry => entry.id === wait.id && entry.kind === 'human' && entry.askSeq !== undefined) === true;
|
|
6505
|
+
}
|
|
6506
|
+
/** The turn end raised a card or the gate: record the human wait it shows. A turn that registered
|
|
6507
|
+
* none opens the ask line's. */
|
|
6508
|
+
recordTurnEndQuestion(runId, state, wait, ask) {
|
|
6509
|
+
const shown = wait ?? (ask ? this.openHumanAlias(runId, state, 'ask-line', ask) : undefined);
|
|
6510
|
+
if (shown)
|
|
6511
|
+
this.markHumanWaitSurfaced(runId, shown, ask ?? undefined);
|
|
6512
|
+
}
|
|
6357
6513
|
/** Native backend asks arrive before turn-end. Persist and park immediately
|
|
6358
6514
|
* so the cockpit shows attention and the run releases its workspace slot. */
|
|
6359
6515
|
handleRunnerUiEvent(runId, state, sink, event) {
|