cc-viewer 1.9.22 → 1.9.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/LICENSE.md +28 -0
- package/README.md +2 -2
- package/cli.js +25 -1
- package/dist/assets/App-BwRRqrP5.css +1 -0
- package/dist/assets/App-Cfmm41z0.js +2 -0
- package/dist/assets/ArchivePreview-BKXTsPsN.css +1 -0
- package/dist/assets/ArchivePreview-dKWXN9Zp.js +1 -0
- package/dist/assets/{MdxEditorPanel-CmHF9Mz1.js → MdxEditorPanel-CT6w8hjl.js} +1 -1
- package/dist/assets/Mobile-noWViQpL.js +1 -0
- package/dist/assets/{ProxyStatsModal-Ogrx3mxS.js → ProxyStatsModal-BeCRPqaC.js} +1 -1
- package/dist/assets/{_baseUniq-CsF04anE.js → _baseUniq-BGBEhBne.js} +1 -1
- package/dist/assets/{arc-BOacYe6N.js → arc-4pbWOEmh.js} +1 -1
- package/dist/assets/{architectureDiagram-Q4EWVU46-BSUEfjC_.js → architectureDiagram-Q4EWVU46-BHZPDnby.js} +1 -1
- package/dist/assets/{blockDiagram-DXYQGD6D-CC37UGtW.js → blockDiagram-DXYQGD6D-DszLU7Pg.js} +1 -1
- package/dist/assets/{c4Diagram-AHTNJAMY-IzgRD4uO.js → c4Diagram-AHTNJAMY-DbDJNYxl.js} +1 -1
- package/dist/assets/{channel-C6PxyQUn.js → channel-BpIsxDHj.js} +1 -1
- package/dist/assets/{chunk-4BX2VUAB-cdQt_dcU.js → chunk-4BX2VUAB-ChcBwBh2.js} +1 -1
- package/dist/assets/{chunk-4TB4RGXK-BpTDA_Pb.js → chunk-4TB4RGXK-DzBEAck_.js} +1 -1
- package/dist/assets/{chunk-55IACEB6-CcitNo0P.js → chunk-55IACEB6-9UDvmw07.js} +1 -1
- package/dist/assets/{chunk-EDXVE4YY-BjKwZ9I7.js → chunk-EDXVE4YY-DHEU2DKg.js} +1 -1
- package/dist/assets/{chunk-FMBD7UC4-vZDVX3tI.js → chunk-FMBD7UC4-sysT0Sy2.js} +1 -1
- package/dist/assets/{chunk-OYMX7WX6-DGkYahGo.js → chunk-OYMX7WX6-DLXt2vYo.js} +1 -1
- package/dist/assets/{chunk-QZHKN3VN-C9065hSE.js → chunk-QZHKN3VN-CDIkC7QK.js} +1 -1
- package/dist/assets/{chunk-YZCP3GAM-D_pcTg6_.js → chunk-YZCP3GAM-D9b_INz7.js} +1 -1
- package/dist/assets/classDiagram-6PBFFD2Q-4Lh0SB4X.js +1 -0
- package/dist/assets/classDiagram-v2-HSJHXN6E-4Lh0SB4X.js +1 -0
- package/dist/assets/clone-cWiXtXrO.js +1 -0
- package/dist/assets/{cose-bilkent-S5V4N54A-BPPFMIGv.js → cose-bilkent-S5V4N54A-DJQwV_Dp.js} +1 -1
- package/dist/assets/{dagre-KV5264BT-fjzhKO5o.js → dagre-KV5264BT-bl9Pq21t.js} +1 -1
- package/dist/assets/{diagram-5BDNPKRD-5L6FzTry.js → diagram-5BDNPKRD-BA8CJxzI.js} +1 -1
- package/dist/assets/{diagram-G4DWMVQ6-GOwcGpff.js → diagram-G4DWMVQ6-DzSQULuz.js} +1 -1
- package/dist/assets/{diagram-MMDJMWI5-BDsFE25W.js → diagram-MMDJMWI5-DhfHWnT4.js} +1 -1
- package/dist/assets/{diagram-TYMM5635-BqjpbSGH.js → diagram-TYMM5635-BbAoFfGS.js} +1 -1
- package/dist/assets/{erDiagram-SMLLAGMA-DWO3Dk1v.js → erDiagram-SMLLAGMA-CMjA2eBk.js} +1 -1
- package/dist/assets/{flowDiagram-DWJPFMVM-Br4nNBVd.js → flowDiagram-DWJPFMVM-bOubqgJ6.js} +1 -1
- package/dist/assets/{ganttDiagram-T4ZO3ILL-9sN-VOhw.js → ganttDiagram-T4ZO3ILL-BUIu7WwI.js} +1 -1
- package/dist/assets/{gitGraphDiagram-UUTBAWPF-BsPcTAKr.js → gitGraphDiagram-UUTBAWPF-B_vrztDU.js} +1 -1
- package/dist/assets/{graph-o31GzaB6.js → graph-BR3YGx52.js} +1 -1
- package/dist/assets/{index-DAjx9lT3.js → index-B88yR2TU.js} +1 -1
- package/dist/assets/{index-PDvAAbti.js → index-BMpUfdYI.js} +1 -1
- package/dist/assets/{index-DyV81jSF.js → index-BQx5MOpr.js} +1 -1
- package/dist/assets/index-Ca3a2tOc.js +2 -0
- package/dist/assets/{index-CuvDJTY7.js → index-ClTuiPoz.js} +1 -1
- package/dist/assets/{index-tZqiJJGq.js → index-DtZAmvwJ.js} +1 -1
- package/dist/assets/{index-B3b0lRUB.js → index-DwMyfQJq.js} +1 -1
- package/dist/assets/{index-CXMr3tiK.js → index-mvm_Pxcf.js} +1 -1
- package/dist/assets/{infoDiagram-42DDH7IO-VUMzEo4o.js → infoDiagram-42DDH7IO-Co9Db2ir.js} +1 -1
- package/dist/assets/{ishikawaDiagram-UXIWVN3A-BuzrU3sx.js → ishikawaDiagram-UXIWVN3A-4z7EydCd.js} +1 -1
- package/dist/assets/{journeyDiagram-VCZTEJTY-BZtR5BAF.js → journeyDiagram-VCZTEJTY-CtLfbhYE.js} +1 -1
- package/dist/assets/{jszip.min-CtodH5MV.js → jszip.min-DtbrAiWv.js} +1 -1
- package/dist/assets/{kanban-definition-6JOO6SKY-Cj_97xXb.js → kanban-definition-6JOO6SKY-9ZrhOvdX.js} +1 -1
- package/dist/assets/{layout-Du0I-tlh.js → layout-Ddo06NJO.js} +1 -1
- package/dist/assets/{linear-BJtxCASI.js → linear-BZUsBSwS.js} +1 -1
- package/dist/assets/{mermaid.core-QlorX0Yw.js → mermaid.core-O-x0KuTp.js} +2 -2
- package/dist/assets/{min-BVnQfunZ.js → min-PzJh19JL.js} +1 -1
- package/dist/assets/{mindmap-definition-QFDTVHPH-Bh_KL4qU.js → mindmap-definition-QFDTVHPH-C3MVo-7p.js} +1 -1
- package/dist/assets/{pieDiagram-DEJITSTG-Bvv0rC_q.js → pieDiagram-DEJITSTG-CMn9-kQc.js} +1 -1
- package/dist/assets/{quadrantDiagram-34T5L4WZ-Bw8cGCRU.js → quadrantDiagram-34T5L4WZ-9eyqTdkj.js} +1 -1
- package/dist/assets/{requirementDiagram-MS252O5E-Cg9jQ71h.js → requirementDiagram-MS252O5E-BJbuDOpR.js} +1 -1
- package/dist/assets/{sankeyDiagram-XADWPNL6-BXJo6-CD.js → sankeyDiagram-XADWPNL6-CzQ1KxD3.js} +1 -1
- package/dist/assets/seqResourceLoaders-DH-Nl0yh.css +41 -0
- package/dist/assets/seqResourceLoaders-DeqzMajS.js +2 -0
- package/dist/assets/{sequenceDiagram-FGHM5R23-D7zpGxwq.js → sequenceDiagram-FGHM5R23-CfmSEAYp.js} +1 -1
- package/dist/assets/{stateDiagram-FHFEXIEX-Der2CqR1.js → stateDiagram-FHFEXIEX-Brw2ZXQC.js} +1 -1
- package/dist/assets/{stateDiagram-v2-QKLJ7IA2-DetvG_Lc.js → stateDiagram-v2-QKLJ7IA2-Dnyo23Rp.js} +1 -1
- package/dist/assets/{timeline-definition-GMOUNBTQ-0UenzEZ6.js → timeline-definition-GMOUNBTQ-DNi7GnlG.js} +1 -1
- package/dist/assets/{vendor-antd-I6I2F7Rv.js → vendor-antd-DWLgSkPo.js} +1 -1
- package/dist/assets/{vendor-codemirror-Zkm6UHQg.js → vendor-codemirror-CKsm_iG4.js} +1 -1
- package/dist/assets/{vendor-mdxeditor-CC09MDyZ.js → vendor-mdxeditor-Dah6NK0y.js} +2 -2
- package/dist/assets/{vendor-qrcode-gZpmSeeh.js → vendor-qrcode-CDcb8weP.js} +1 -1
- package/dist/assets/{vendor-virtuoso-BGwznQ5y.js → vendor-virtuoso-DKUobZpA.js} +1 -1
- package/dist/assets/{vennDiagram-DHZGUBPP-COzYyZ5h.js → vennDiagram-DHZGUBPP-Cdkdx7gB.js} +1 -1
- package/dist/assets/{wardley-RL74JXVD-VZdOtN8t.js → wardley-RL74JXVD-YKzsVN4U.js} +1 -1
- package/dist/assets/{wardleyDiagram-NUSXRM2D-CVkL75Qy.js → wardleyDiagram-NUSXRM2D-gBsb6aut.js} +1 -1
- package/dist/assets/{xychartDiagram-5P7HB3ND-6CHBAYyF.js → xychartDiagram-5P7HB3ND-Bh63NWof.js} +1 -1
- package/dist/index.html +4 -4
- package/findcc.js +4 -4
- package/node_modules/@ccv/core/src/ask-auto-answer.js +122 -0
- package/node_modules/@ccv/core/src/contentFilter.js +4 -1
- package/node_modules/@ccv/core/src/ultraplanTemplates.js +199 -0
- package/package.json +1 -1
- package/server/i18n.js +4 -20
- package/server/lib/ask/ask-bridge.js +4 -1
- package/server/lib/ask/ask-reaper.js +1 -0
- package/server/lib/ask-auto-answer.js +153 -0
- package/server/lib/auto-approve.js +3 -1
- package/server/lib/binary-sniff.js +35 -0
- package/server/lib/ensure-hooks.js +134 -2
- package/server/lib/im/im-bridge-core.js +16 -0
- package/server/lib/scheduled-task-executor.js +14 -2
- package/server/lib/scheduled-task-store.js +129 -18
- package/server/lib/sdk-manager.js +178 -30
- package/server/pty-manager.js +103 -4
- package/server/routes/ask-perm.js +87 -6
- package/server/routes/files-content.js +46 -8
- package/server/routes/scheduled-tasks.js +13 -0
- package/server/server.js +100 -0
- package/server/system-prompt-templates/presets/kimi-k3.md +8 -0
- package/dist/assets/App-BN3viVRq.js +0 -2
- package/dist/assets/App-BvVdj099.css +0 -1
- package/dist/assets/Mobile-nbI6IeX_.js +0 -1
- package/dist/assets/classDiagram-6PBFFD2Q-BUmU_G-i.js +0 -1
- package/dist/assets/classDiagram-v2-HSJHXN6E-BUmU_G-i.js +0 -1
- package/dist/assets/clone-CvoOne2K.js +0 -1
- package/dist/assets/index-DoFyHmPM.js +0 -2
- package/dist/assets/seqResourceLoaders-DbccWwKz.css +0 -41
- package/dist/assets/seqResourceLoaders-n9iXZRHx.js +0 -2
|
@@ -36,12 +36,20 @@ import { createHash, randomBytes } from 'node:crypto';
|
|
|
36
36
|
import { registerSdkSessionLister } from './sdk-session-index.js';
|
|
37
37
|
import { readPrefsRaw } from './prefs-store.js';
|
|
38
38
|
import { projectKeyForCwd } from './system-prompt-snapshots.js';
|
|
39
|
+
import { AGENT_PROMPT_SNIPPET_LEN } from '@ccv/core/contentFilter';
|
|
39
40
|
import {
|
|
40
41
|
computeAutoApprove,
|
|
41
42
|
createAutoApproveState,
|
|
42
43
|
cancelAutoApproveState,
|
|
43
44
|
replayAutoApproveFields,
|
|
44
45
|
} from './auto-approve.js';
|
|
46
|
+
import {
|
|
47
|
+
computeAskAutoAnswer,
|
|
48
|
+
createAskAutoAnswerState,
|
|
49
|
+
cancelAskAutoAnswerState,
|
|
50
|
+
replayAskAutoAnswerFields,
|
|
51
|
+
pickAutoAnswers,
|
|
52
|
+
} from './ask-auto-answer.js';
|
|
45
53
|
|
|
46
54
|
let _query;
|
|
47
55
|
try {
|
|
@@ -328,18 +336,17 @@ function _isBareClearCommand(text) {
|
|
|
328
336
|
* delta for the client to apply, and `skip_transcript` is forwarded as
|
|
329
337
|
* `skipTranscript` so the UI stage can decide whether to hide ambient tasks.
|
|
330
338
|
*
|
|
331
|
-
* Two constraints the UI stage MUST respect
|
|
339
|
+
* Two constraints the UI stage MUST respect:
|
|
332
340
|
* - TWO status vocabularies share the wire: `task_notification.status` is
|
|
333
341
|
* `completed|failed|stopped`, while `task_updated.patch.status` is
|
|
334
342
|
* `pending|running|completed|failed|killed` — adjacent but disjoint domains.
|
|
335
343
|
* A client that naively merges `{...task, ...frame}` then `{...frame.patch}`
|
|
336
344
|
* will mis-render; discriminate by `subtype` before reading `status`.
|
|
337
|
-
* -
|
|
338
|
-
*
|
|
339
|
-
*
|
|
340
|
-
*
|
|
341
|
-
*
|
|
342
|
-
* reducer semantics rather than growing a second table here).
|
|
345
|
+
* - The live relay is delta-only, but every frame is ALSO folded into a bounded
|
|
346
|
+
* per-session table (taskId → latest folded state, cap 64, reset on session
|
|
347
|
+
* boundaries) and replayed as an authoritative `sdk-task-snapshot` on WS
|
|
348
|
+
* reconnect — a frame missed during a gap is recoverable, and an empty table
|
|
349
|
+
* replays as `tasks: []` so the client reconciles to "no tasks".
|
|
343
350
|
*
|
|
344
351
|
* Note: the 4 subtypes relayed here are the PUBLIC contract (sdk.d.ts SDKMessage
|
|
345
352
|
* union). The SDK additionally emits @internal `task_summary` / `post_turn_summary`
|
|
@@ -386,6 +393,41 @@ function _normalizeSdkTask(msg) {
|
|
|
386
393
|
return out;
|
|
387
394
|
}
|
|
388
395
|
|
|
396
|
+
/**
|
|
397
|
+
* Fold one normalized sdk-task frame into a server-side table entry (the latest
|
|
398
|
+
* known state per taskId). task_started seeds; task_progress/updated merge fields
|
|
399
|
+
* (patch.status is authoritative for updated); task_notification marks terminal.
|
|
400
|
+
* Kept deliberately small — the full prompt is retained only as a bounded snippet,
|
|
401
|
+
* shared via @ccv/core's AGENT_PROMPT_SNIPPET_LEN so the client tracker truncates
|
|
402
|
+
* identically.
|
|
403
|
+
*/
|
|
404
|
+
const _SDK_TASK_TERMINAL = new Set(['completed', 'failed', 'stopped', 'killed']);
|
|
405
|
+
function _foldSdkTask(prev, frame) {
|
|
406
|
+
const next = { ...(prev || {}), taskId: frame.taskId };
|
|
407
|
+
if (frame.sessionId != null) next.sessionId = frame.sessionId;
|
|
408
|
+
if (frame.toolUseId != null) next.toolUseId = frame.toolUseId;
|
|
409
|
+
if (frame.taskType != null) next.taskType = frame.taskType;
|
|
410
|
+
if (frame.description != null) next.description = frame.description;
|
|
411
|
+
if (frame.patch && frame.patch.description != null) next.description = frame.patch.description; // task_updated delta
|
|
412
|
+
if (frame.summary != null) next.summary = frame.summary;
|
|
413
|
+
if (frame.prompt != null) next.promptSnippet = String(frame.prompt).slice(0, AGENT_PROMPT_SNIPPET_LEN);
|
|
414
|
+
// Retained so getSdkTaskSnapshot can hide ambient tasks from the replay while the
|
|
415
|
+
// entry still participates in session-boundary detection (a skipTranscript first
|
|
416
|
+
// frame may be the only task frame carrying the new sessionId).
|
|
417
|
+
if (frame.skipTranscript != null) next.skipTranscript = frame.skipTranscript === true;
|
|
418
|
+
if (frame.workflowName != null) next.workflowName = frame.workflowName;
|
|
419
|
+
if (frame.lastToolName != null) next.lastToolName = frame.lastToolName;
|
|
420
|
+
if (frame.usage != null) next.usage = frame.usage;
|
|
421
|
+
// Status: notification carries the terminal word; updated carries it in patch.
|
|
422
|
+
if (frame.subtype === 'task_notification' && frame.status != null) next.status = frame.status;
|
|
423
|
+
else if (frame.patch && frame.patch.status != null) next.status = frame.patch.status;
|
|
424
|
+
else if (frame.status != null) next.status = frame.status;
|
|
425
|
+
else if (!next.status) next.status = frame.subtype === 'task_started' ? 'running' : 'pending';
|
|
426
|
+
next.terminal = _SDK_TASK_TERMINAL.has(next.status);
|
|
427
|
+
next.updatedAt = Date.now();
|
|
428
|
+
return next;
|
|
429
|
+
}
|
|
430
|
+
|
|
389
431
|
// ── Per-session factory ──────────────────────────────────────────────────────
|
|
390
432
|
// ONE closure = ONE workspace's resident SDK session. Every variable the current
|
|
391
433
|
// (single-session) module held in module-level `let` lives here EXCEPT the ones
|
|
@@ -491,6 +533,15 @@ function _createSession(key, cwd) {
|
|
|
491
533
|
// turn-correlated, so it gets no turn-end/compact trigger and none of the in-flight gate
|
|
492
534
|
// (fetching/queued/seq) machinery above. It reuses the same CTX_USAGE_TIMEOUT_MS bound.
|
|
493
535
|
let _lastMcpStatus = null;
|
|
536
|
+
// Bounded server-side sdk-task table (review: stale active-agents strip). Until now
|
|
537
|
+
// the relay was stateless — a frame missed during a WS gap was unrecoverable, so a
|
|
538
|
+
// late/refreshed client never learned an in-flight agent, and a client whose
|
|
539
|
+
// terminal frame was lost kept the agent "active" forever. This bounded map (one
|
|
540
|
+
// entry per taskId, per sessionId) lets a reconnecting client reconcile to the
|
|
541
|
+
// server's authoritative view. Cleared on session boundaries like _lastInitSnapshot.
|
|
542
|
+
let _sdkTaskTable = new Map(); // taskId -> normalized sdk-task frame (latest)
|
|
543
|
+
let _sdkTaskTableSessionId = null; // sessionId the table belongs to
|
|
544
|
+
const _SDK_TASK_TABLE_CAP = 64; // bounded: oldest evicted beyond this
|
|
494
545
|
// Pending canUseTool promises: id → { kind, resolve, replay, startedAt, timeoutMs }
|
|
495
546
|
// replay is the exact broadcast payload that announced this approval — retained so a
|
|
496
547
|
// fresh WS connection can re-announce it (server.js connection replay), otherwise a
|
|
@@ -1556,6 +1607,14 @@ function _createSession(key, cwd) {
|
|
|
1556
1607
|
// /clear may reinitialize instead of returning a normal result. The new session is
|
|
1557
1608
|
// now authoritative, so context reads may resume (without resuming the old session).
|
|
1558
1609
|
if (_ctxUsageClearPending && msg.session_id) _ctxUsageClearPending = false;
|
|
1610
|
+
// Session boundary for the task table: /clear re-inits with a new session_id but
|
|
1611
|
+
// may emit no task frame until the next task starts (the task-frame boundary in
|
|
1612
|
+
// the task branch only fires once one arrives), and a task that was in flight
|
|
1613
|
+
// gets no terminal frame — without this reset a reconnect would resurrect it.
|
|
1614
|
+
if (msg.session_id && msg.session_id !== _sdkTaskTableSessionId) {
|
|
1615
|
+
_sdkTaskTable = new Map();
|
|
1616
|
+
_sdkTaskTableSessionId = msg.session_id;
|
|
1617
|
+
}
|
|
1559
1618
|
if (_broadcastWs && Array.isArray(msg.slash_commands) && msg.slash_commands.length > 0
|
|
1560
1619
|
&& msg.session_id !== _initAnnouncedSid) {
|
|
1561
1620
|
_initAnnouncedSid = msg.session_id;
|
|
@@ -1602,10 +1661,26 @@ function _createSession(key, cwd) {
|
|
|
1602
1661
|
// SDK background-task / subagent progress (SDK 0.2.x system subtypes). The TODO
|
|
1603
1662
|
// HUD (TaskProgressHud) is hook-fed and never fires in SDK mode; this is a
|
|
1604
1663
|
// separate, lossless relay so clients can observe task lifecycle (incl.
|
|
1605
|
-
// failed/stopped/killed terminal states the TODO HUD vocabulary lacks).
|
|
1606
|
-
//
|
|
1607
|
-
//
|
|
1608
|
-
|
|
1664
|
+
// failed/stopped/killed terminal states the TODO HUD vocabulary lacks). Folded
|
|
1665
|
+
// into a bounded server-side table for reconnect replay (a frame lost in a WS
|
|
1666
|
+
// gap is no longer unrecoverable); merge semantics stay client-side.
|
|
1667
|
+
const sdkTaskFrame = { type: 'sdk-task', cwd: _cwd, instanceKey, ..._normalizeSdkTask(msg) };
|
|
1668
|
+
// Maintain the authoritative table (sessionId-scoped, bounded). A new sessionId
|
|
1669
|
+
// resets the table so a /clear or in-place resume never leaks the prior session's
|
|
1670
|
+
// tasks into a reconnecting client's view.
|
|
1671
|
+
if (sdkTaskFrame.taskId) {
|
|
1672
|
+
if (sdkTaskFrame.sessionId && sdkTaskFrame.sessionId !== _sdkTaskTableSessionId) {
|
|
1673
|
+
_sdkTaskTable = new Map();
|
|
1674
|
+
_sdkTaskTableSessionId = sdkTaskFrame.sessionId;
|
|
1675
|
+
}
|
|
1676
|
+
_sdkTaskTable.delete(sdkTaskFrame.taskId); // re-insert for LRU order
|
|
1677
|
+
_sdkTaskTable.set(sdkTaskFrame.taskId, _foldSdkTask(_sdkTaskTable.get(sdkTaskFrame.taskId), sdkTaskFrame));
|
|
1678
|
+
while (_sdkTaskTable.size > _SDK_TASK_TABLE_CAP) {
|
|
1679
|
+
const oldest = _sdkTaskTable.keys().next().value;
|
|
1680
|
+
_sdkTaskTable.delete(oldest);
|
|
1681
|
+
}
|
|
1682
|
+
}
|
|
1683
|
+
_broadcastWs(sdkTaskFrame);
|
|
1609
1684
|
}
|
|
1610
1685
|
break;
|
|
1611
1686
|
|
|
@@ -2062,11 +2137,25 @@ function _createSession(key, cwd) {
|
|
|
2062
2137
|
// server/lib/ask/ask-constants.js.
|
|
2063
2138
|
const askTimeoutMs = ASK_TIMEOUT_MS;
|
|
2064
2139
|
const askStartedAt = Date.now();
|
|
2065
|
-
|
|
2140
|
+
// Server-side hosting ("问答题自动托管"): approvalModal.askAutoAnswerMinutes
|
|
2141
|
+
// (0 = instant, N = N minutes) answers the ask at the wall-clock deadline even
|
|
2142
|
+
// with no browser connected. Unlike plan/perm this deliberately applies to
|
|
2143
|
+
// unattended scheduled-task runs (ctx != null): hosting is opt-in (default off)
|
|
2144
|
+
// and the 0-minute tier exists precisely for those flows — without it an
|
|
2145
|
+
// ephemeral run would hang the full 24h. The pick prefers the first option
|
|
2146
|
+
// carrying a localized "Recommended" marker, else the first option.
|
|
2147
|
+
const askAuto = computeAskAutoAnswer(_cwd);
|
|
2148
|
+
const askAutoAnswers = askAuto.enabled ? pickAutoAnswers(input.questions) : null;
|
|
2149
|
+
const askHosting = askAuto.enabled && !!askAutoAnswers;
|
|
2150
|
+
const askPayload = { type: 'sdk-ask-pending', id, questions: input.questions, startedAt: askStartedAt, timeoutMs: askTimeoutMs, cwd: _cwd, sessionId: effSessionId(), instanceKey, ...origin,
|
|
2151
|
+
// Always stamp the hosting fields (null when off) so a client whose global pref
|
|
2152
|
+
// disagrees with the fork-resolved server value never re-arms locally.
|
|
2153
|
+
...replayAskAutoAnswerFields(askHosting ? askAuto : null, false) };
|
|
2066
2154
|
if (_broadcastWs) {
|
|
2067
2155
|
_broadcastWs(askPayload);
|
|
2068
2156
|
}
|
|
2069
|
-
const answers = await _waitForApproval(id, askTimeoutMs, 'ask', askPayload, options?.signal, ctx
|
|
2157
|
+
const answers = await _waitForApproval(id, askTimeoutMs, 'ask', askPayload, options?.signal, ctx,
|
|
2158
|
+
askHosting ? askAuto : null, askHosting ? askAutoAnswers : undefined);
|
|
2070
2159
|
if (answers === null) {
|
|
2071
2160
|
return { behavior: 'deny', message: 'Timeout waiting for user answer' };
|
|
2072
2161
|
}
|
|
@@ -2190,7 +2279,7 @@ function _createSession(key, cwd) {
|
|
|
2190
2279
|
} catch (err) { console.warn('[sdk-manager] approval-dismiss broadcast threw:', err?.message); }
|
|
2191
2280
|
}
|
|
2192
2281
|
|
|
2193
|
-
function _waitForApproval(id, timeoutMs, kind, replay = null, signal = null, ctx = null, autoMeta = null) {
|
|
2282
|
+
function _waitForApproval(id, timeoutMs, kind, replay = null, signal = null, ctx = null, autoMeta = null, autoValue = undefined) {
|
|
2194
2283
|
// Record the id on the ephemeral run's ctx ONLY when it actually parks (the three
|
|
2195
2284
|
// callers below sit after every auto-allow/hard-deny early-return, so an auto-allowed
|
|
2196
2285
|
// tool never lands here) — keeps ctx.approvalIds bounded (review P3: no unbounded growth).
|
|
@@ -2226,15 +2315,25 @@ function _createSession(key, cwd) {
|
|
|
2226
2315
|
},
|
|
2227
2316
|
};
|
|
2228
2317
|
_pendingApprovals.set(id, entry);
|
|
2229
|
-
// Arm the server-side fallback AFTER the entry is in the map: instant (-1
|
|
2230
|
-
// synchronously and resolves through
|
|
2318
|
+
// Arm the server-side fallback AFTER the entry is in the map: instant (-1 for
|
|
2319
|
+
// plan/perm, 0 minutes for ask hosting) fires synchronously and resolves through
|
|
2320
|
+
// the same first-wins wrapper. Ask hosting arms its own state factory (minute
|
|
2321
|
+
// semantics) and resolves the pre-picked answers map; plan/perm keep the generic
|
|
2322
|
+
// auto-approve state. A null autoValue (no selectable option) never reaches here —
|
|
2323
|
+
// the ask caller passes autoMeta only when answers were actually picked, otherwise
|
|
2324
|
+
// resolve(null) would be misread as the timeout/deny path.
|
|
2231
2325
|
if (autoMeta?.enabled) {
|
|
2232
|
-
|
|
2326
|
+
const fireResolveValue = autoValue !== undefined
|
|
2327
|
+
? autoValue
|
|
2328
|
+
: (kind === 'plan' ? { approve: true, feedback: '' } : { decision: 'allow' });
|
|
2329
|
+
const fireResolvedType = kind === 'ask' ? 'sdk-ask-resolved' : (kind === 'plan' ? 'sdk-plan-resolved' : 'perm-hook-resolved');
|
|
2330
|
+
const fireReason = kind === 'ask' ? 'auto-answered' : 'auto-approved';
|
|
2331
|
+
entry.auto = (kind === 'ask' ? createAskAutoAnswerState : createAutoApproveState)(autoMeta, () => {
|
|
2233
2332
|
const p = _pendingApprovals.get(id);
|
|
2234
2333
|
if (!p || p.autoCancelled) return;
|
|
2235
|
-
p.resolve(
|
|
2334
|
+
p.resolve(fireResolveValue);
|
|
2236
2335
|
try {
|
|
2237
|
-
_broadcastWs?.({ type:
|
|
2336
|
+
_broadcastWs?.({ type: fireResolvedType, id, reason: fireReason, cwd: _cwd, sessionId: (ctx && ctx.sessionId) || _sessionId || null, instanceKey });
|
|
2238
2337
|
} catch (err) { reportSwallowed('sdk-manager.auto-approve-broadcast', err); }
|
|
2239
2338
|
});
|
|
2240
2339
|
}
|
|
@@ -2282,30 +2381,44 @@ function _createSession(key, cwd) {
|
|
|
2282
2381
|
if (remaining <= 0) continue;
|
|
2283
2382
|
out.push({
|
|
2284
2383
|
id, kind: p.kind || null, replay: p.replay || null, remainingMs: remaining,
|
|
2285
|
-
|
|
2384
|
+
// Ask hosting replays under its own field names (autoAnswerAt/…) — an ask
|
|
2385
|
+
// entry must never advertise autoApproveAt (plan/perm-only contract, pinned
|
|
2386
|
+
// by sdk-manager-auto-approve.test.js).
|
|
2387
|
+
...(p.kind === 'ask'
|
|
2388
|
+
? replayAskAutoAnswerFields(p.auto, p.autoCancelled)
|
|
2389
|
+
: replayAutoApproveFields(p.auto, p.autoCancelled)),
|
|
2286
2390
|
});
|
|
2287
2391
|
}
|
|
2288
2392
|
return out;
|
|
2289
2393
|
}
|
|
2290
2394
|
|
|
2291
2395
|
/**
|
|
2292
|
-
* Cancel the SERVER-SIDE auto-approve countdown for a pending plan/perm
|
|
2293
|
-
* (client clicked the countdown-cancel button). Unlike cancelApproval this does NOT
|
|
2396
|
+
* Cancel the SERVER-SIDE auto-approve / hosting countdown for a pending plan/perm/ask
|
|
2397
|
+
* approval (client clicked the countdown-cancel button). Unlike cancelApproval this does NOT
|
|
2294
2398
|
* resolve the approval — it stays pending for a manual decision; only the fallback
|
|
2295
2399
|
* timer is destroyed and the cancelled flag is replayed to fresh clients so they
|
|
2296
2400
|
* never re-arm. Returns true when the id matched a pending approval of that kind
|
|
2297
2401
|
* (even on a repeat cancel — the state change is durable while pending); false when
|
|
2298
2402
|
* nothing matched (caller falls back to the legacy relay-only behavior).
|
|
2403
|
+
* For ask specifically, false is also returned when no hosting timer was armed
|
|
2404
|
+
* (hosting off / no selectable option) so the caller can fall through to the
|
|
2405
|
+
* PTY-hook entry.
|
|
2299
2406
|
*/
|
|
2300
2407
|
function _autoCancelApproval(id, kind) {
|
|
2301
|
-
|
|
2302
|
-
if (kind !== 'plan' && kind !== 'perm') return false;
|
|
2408
|
+
if (kind !== 'plan' && kind !== 'perm' && kind !== 'ask') return false;
|
|
2303
2409
|
const pending = _pendingApprovals.get(id);
|
|
2410
|
+
// A kind-collision (the id belongs to a plan/perm pending) must NOT be treated as
|
|
2411
|
+
// handled: return false so the caller falls through to the PTY-hook entry, which may
|
|
2412
|
+
// legitimately own that ask id. Without this the hosting cancel is silently dropped.
|
|
2304
2413
|
if (!pending || pending.kind !== kind) return false;
|
|
2305
|
-
|
|
2414
|
+
// Ask with no armed hosting timer: nothing to cancel, but the durable latch is still
|
|
2415
|
+
// stamped (harmless) and the caller falls through to relay the broadcast so sibling
|
|
2416
|
+
// tabs stop their countdown.
|
|
2417
|
+
if (kind === 'ask' && !pending.auto) return false;
|
|
2418
|
+
const first = kind === 'ask' ? cancelAskAutoAnswerState(pending) : cancelAutoApproveState(pending);
|
|
2306
2419
|
if (first && _broadcastWs) {
|
|
2307
2420
|
try {
|
|
2308
|
-
_broadcastWs({ type: kind === 'plan' ? 'sdk-plan-auto-cancel' : 'perm-hook-auto-cancel', id, cwd: _cwd, sessionId: _sessionId || null, instanceKey });
|
|
2421
|
+
_broadcastWs({ type: kind === 'plan' ? 'sdk-plan-auto-cancel' : (kind === 'ask' ? 'ask-auto-cancel' : 'perm-hook-auto-cancel'), id, cwd: _cwd, sessionId: _sessionId || null, instanceKey });
|
|
2309
2422
|
} catch (err) { reportSwallowed('sdk-manager.auto-cancel-broadcast', err); }
|
|
2310
2423
|
}
|
|
2311
2424
|
return true;
|
|
@@ -2627,6 +2740,8 @@ function _createSession(key, cwd) {
|
|
|
2627
2740
|
_lastInitSnapshot = null; // don't replay the OLD session's sdk-init to the new one
|
|
2628
2741
|
_lastSkillsSnapshot = null; // same for the skill surface
|
|
2629
2742
|
_lastSessionState = null; // same for the session-state snapshot — new session starts idle
|
|
2743
|
+
_sdkTaskTable = new Map(); // drop the outgoing session's task table
|
|
2744
|
+
_sdkTaskTableSessionId = null;
|
|
2630
2745
|
_clearStateHeartbeat();
|
|
2631
2746
|
_suspectGeneration = false;
|
|
2632
2747
|
_lastFailedTurn = null; // the failure belongs to the outgoing session — never retry it into this one
|
|
@@ -2651,6 +2766,8 @@ function _createSession(key, cwd) {
|
|
|
2651
2766
|
_initAnnouncedSid = '';
|
|
2652
2767
|
_lastInitSnapshot = null;
|
|
2653
2768
|
_lastSkillsSnapshot = null;
|
|
2769
|
+
_sdkTaskTable = new Map(); // full reset: drop the task table too
|
|
2770
|
+
_sdkTaskTableSessionId = null;
|
|
2654
2771
|
// Tell clients BEFORE nulling the snapshot: a re-init/launch mid-turn would
|
|
2655
2772
|
// otherwise leave the spinner lit with no frame ever clearing it (the new
|
|
2656
2773
|
// session starts idle and the state-change guard would swallow the first
|
|
@@ -2725,6 +2842,19 @@ function _createSession(key, cwd) {
|
|
|
2725
2842
|
getContextUsageSnapshot: () => _lastContextUsage,
|
|
2726
2843
|
getMcpStatusSnapshot: () => _lastMcpStatus,
|
|
2727
2844
|
getSkillsSnapshot: () => _lastSkillsSnapshot,
|
|
2845
|
+
// Authoritative sdk-task table for WS reconnect replay: a refreshed/reconnected
|
|
2846
|
+
// client reconciles its delta-only tracker to this snapshot (sessionId-scoped).
|
|
2847
|
+
// ALWAYS returns a frame — an empty `tasks: []` is authoritative ("no tasks"),
|
|
2848
|
+
// otherwise a client that missed the session boundary keeps its stale agents.
|
|
2849
|
+
// skipTranscript entries are tracked (they carry the session boundary) but hidden
|
|
2850
|
+
// from the replay, matching the live path that never shows ambient tasks.
|
|
2851
|
+
getSdkTaskSnapshot: () => ({
|
|
2852
|
+
type: 'sdk-task-snapshot',
|
|
2853
|
+
cwd: _cwd,
|
|
2854
|
+
instanceKey,
|
|
2855
|
+
sessionId: _sdkTaskTableSessionId,
|
|
2856
|
+
tasks: [..._sdkTaskTable.values()].filter((t) => t.skipTranscript !== true),
|
|
2857
|
+
}),
|
|
2728
2858
|
fetchContextUsage: async () => {
|
|
2729
2859
|
// On-demand fetch for the HTTP route: refresh the snapshot, broadcast to all clients,
|
|
2730
2860
|
// then reply. Unlike _refreshContextUsage this bypasses the in-flight gate (an explicit
|
|
@@ -2961,10 +3091,11 @@ export function cancelApproval(id, reason) {
|
|
|
2961
3091
|
}
|
|
2962
3092
|
|
|
2963
3093
|
/**
|
|
2964
|
-
* Cancel the server-side auto-approve countdown for a plan/perm approval,
|
|
2965
|
-
*
|
|
2966
|
-
*
|
|
2967
|
-
*
|
|
3094
|
+
* Cancel the server-side auto-approve countdown for a plan/perm approval, or the
|
|
3095
|
+
* hosting ("问答题自动托管") timer for an AskUserQuestion approval, scanning EVERY
|
|
3096
|
+
* session (auto-cancel WS handlers). The approval stays pending for a manual
|
|
3097
|
+
* decision. Returns false when no pending approval matched, so the caller can fall
|
|
3098
|
+
* back to the legacy relay-only broadcast.
|
|
2968
3099
|
*/
|
|
2969
3100
|
export function autoCancelApproval(id, kind) {
|
|
2970
3101
|
for (const sess of new Set([..._sessions.values(), ..._ephemeralHosts])) {
|
|
@@ -3236,6 +3367,23 @@ export function getMcpStatusSnapshot(anchor) {
|
|
|
3236
3367
|
return sess ? sess.getMcpStatusSnapshot() : null;
|
|
3237
3368
|
}
|
|
3238
3369
|
|
|
3370
|
+
/**
|
|
3371
|
+
* WS reconnect replay getter for the authoritative sdk-task table.
|
|
3372
|
+
*
|
|
3373
|
+
* `anchor` (optional, skills-snapshot parity — resolved by _sessionForAnchor):
|
|
3374
|
+
* - { instanceKey } exact registered instance
|
|
3375
|
+
* - { cwd } exact normalized cwd
|
|
3376
|
+
* - { project } sanitized/raw basename; ambiguous → null
|
|
3377
|
+
* No anchor → the ACTIVE session. Returns the always-present `sdk-task-snapshot`
|
|
3378
|
+
* frame ({ type, cwd, instanceKey, sessionId, tasks }) — tasks may be empty — or
|
|
3379
|
+
* null only when the anchor resolves to no registered session (the caller sends
|
|
3380
|
+
* nothing; an anchor failure must not replay a foreign workspace's table).
|
|
3381
|
+
*/
|
|
3382
|
+
export function getSdkTaskSnapshot(anchor) {
|
|
3383
|
+
const sess = anchor ? _sessionForAnchor(anchor) : _active();
|
|
3384
|
+
return sess ? sess.getSdkTaskSnapshot() : null;
|
|
3385
|
+
}
|
|
3386
|
+
|
|
3239
3387
|
/**
|
|
3240
3388
|
* On-demand context-usage fetch for the HTTP route (see the Session factory's
|
|
3241
3389
|
* fetchContextUsage). No anchor → the active session. Returns
|
package/server/pty-manager.js
CHANGED
|
@@ -1,13 +1,14 @@
|
|
|
1
1
|
import { resolveNativePath, LOG_DIR } from '../findcc.js';
|
|
2
2
|
import { normalizeSessionCwd } from './lib/v2/layout.js';
|
|
3
3
|
import { fileURLToPath } from 'node:url';
|
|
4
|
-
import { join, dirname, sep } from 'node:path';
|
|
5
|
-
import { chmodSync, statSync } from 'node:fs';
|
|
4
|
+
import { join, dirname, sep, resolve } from 'node:path';
|
|
5
|
+
import { chmodSync, statSync, existsSync } from 'node:fs';
|
|
6
6
|
import { platform, arch, homedir } from 'node:os';
|
|
7
7
|
import { createRequire } from 'node:module';
|
|
8
8
|
import { prepareEmbeddedShellSpawn, stripClaudeNoFlickerUnlessOptedIn, applyClaudeAltScreenPref } from './lib/terminal-env.js';
|
|
9
9
|
import { killPtyTree } from './lib/term-signals.js';
|
|
10
10
|
import { findSafeSliceStart, splitTrailingIncomplete } from './lib/ansi-safe-slice.js';
|
|
11
|
+
import { imDir } from './lib/im/im-lock.js';
|
|
11
12
|
import { resolveSpawnModel } from './lib/spawn-model-resolver.js';
|
|
12
13
|
import { mergeSettingsIntoArgs } from './lib/settings-merge.js';
|
|
13
14
|
import { projectKeyForCwd } from './lib/system-prompt-snapshots.js';
|
|
@@ -18,6 +19,7 @@ import { randomBytes } from 'node:crypto';
|
|
|
18
19
|
import { withDefaultThinkingDisplay, resolveLaunchSystemPrompt, insertBeforeDashDash } from './lib/launch-config.js';
|
|
19
20
|
export { withDefaultThinkingDisplay } from './lib/launch-config.js';
|
|
20
21
|
import { reportSwallowed } from './lib/error-report.js';
|
|
22
|
+
import { ensureOnboardingAndTrust } from './lib/ensure-hooks.js';
|
|
21
23
|
import { t, tFor } from './i18n.js';
|
|
22
24
|
|
|
23
25
|
const __filename = fileURLToPath(import.meta.url);
|
|
@@ -389,6 +391,21 @@ async function _spawnClaudeImpl(key, proxyPort, cwd, extraArgs = [], claudePath
|
|
|
389
391
|
env.CCV_PROXY_MODE = '1'; // tell interceptor.js not to start a server again
|
|
390
392
|
env.CCV_LOG_DIR = LOG_DIR; // let the forked Claude Code process find the same
|
|
391
393
|
// profile.json etc. resources
|
|
394
|
+
// IM worker CodeFuse config-dir fallback is handled in cli.js runImMode
|
|
395
|
+
// (before runCliMode), so that ensureHooks() writes to the same directory
|
|
396
|
+
// the child will read. Here we only need to inherit the already-resolved
|
|
397
|
+
// CLAUDE_CONFIG_DIR from process.env (which the env copy above already does).
|
|
398
|
+
// Pre-seed onboarding + trust state so Claude never blocks on interactive
|
|
399
|
+
// confirmation dialogs ("Yes, I accept" / "Yes, I trust this folder") in
|
|
400
|
+
// headless environments. Only applies to the IM worker's OWN working directory
|
|
401
|
+
// (imDir) — a user-launched workspace inside an IM worker must NOT silently
|
|
402
|
+
// accept trust on behalf of the user (security boundary).
|
|
403
|
+
if (process.env.CCV_IM_PLATFORM && cwd) {
|
|
404
|
+
const imWorkspace = imDir(process.env.CCV_IM_PLATFORM);
|
|
405
|
+
if (resolve(cwd) === resolve(imWorkspace)) {
|
|
406
|
+
ensureOnboardingAndTrust({ configDir: env.CLAUDE_CONFIG_DIR, workspacePath: cwd });
|
|
407
|
+
}
|
|
408
|
+
}
|
|
392
409
|
// Self-report project (2026-10, multi-PTY): every main-PTY claude ALSO tags its
|
|
393
410
|
// requests with `x-ccv-project-dir` = its own cwd, so the writer routes its
|
|
394
411
|
// writes to ITS project — not the (possibly re-bound) server project. This is
|
|
@@ -599,8 +616,8 @@ async function _spawnClaudeImpl(key, proxyPort, cwd, extraArgs = [], claudePath
|
|
|
599
616
|
let command = claudePath;
|
|
600
617
|
let args = ['--settings', settingsJson, ...launchArgs];
|
|
601
618
|
|
|
602
|
-
// If it is the npm version (cli.js), it must run under node
|
|
603
|
-
if (isNpmVersion && claudePath.endsWith('.js')) {
|
|
619
|
+
// If it is the npm version (cli.js / cli.cjs), it must run under node
|
|
620
|
+
if (isNpmVersion && (claudePath.endsWith('.js') || claudePath.endsWith('.cjs'))) {
|
|
604
621
|
command = nodePath;
|
|
605
622
|
args = [claudePath, '--settings', settingsJson, ...launchArgs];
|
|
606
623
|
}
|
|
@@ -616,9 +633,13 @@ async function _spawnClaudeImpl(key, proxyPort, cwd, extraArgs = [], claudePath
|
|
|
616
633
|
// A (re)spawn starts a fresh conversation — drop any sessionId a prior life
|
|
617
634
|
// on this record resolved to, so a stale sid never misroutes a send.
|
|
618
635
|
if (s.sessionId) { sidToKey.delete(s.sessionId); s.sessionId = null; }
|
|
636
|
+
// Clear any latched boot-blocked state from a previous life on this record —
|
|
637
|
+
// the respawn may succeed where the prior attempt was blocked.
|
|
638
|
+
s._bootBlockedState = null;
|
|
619
639
|
// Boot-window anchor for the injection fallback tiers below (same clock as the
|
|
620
640
|
// comparison — _now(), never Date.now(), so tests can steer both ends together).
|
|
621
641
|
const spawnedAt = _now();
|
|
642
|
+
s._spawnedAt = spawnedAt; // also stored on the record for getPtyBootState()
|
|
622
643
|
|
|
623
644
|
s.ptyProcess = pty.spawn(command, args, {
|
|
624
645
|
name: 'xterm-256color',
|
|
@@ -1531,6 +1552,84 @@ export function getOutputBuffer() {
|
|
|
1531
1552
|
return s ? s.outputBuffer : '';
|
|
1532
1553
|
}
|
|
1533
1554
|
|
|
1555
|
+
// ─── PTY boot-state detection ───
|
|
1556
|
+
// Patterns that indicate the Claude PTY is blocked on an interactive dialog
|
|
1557
|
+
// instead of being ready to accept prompts. Used by the IM bridge to fail fast
|
|
1558
|
+
// with a clear error instead of letting the message sit until the 120s timeout.
|
|
1559
|
+
//
|
|
1560
|
+
// IMPORTANT: Ink renders dialog options as separately positioned words using
|
|
1561
|
+
// cursor-forward ANSI sequences (ESC[<n>G) instead of literal spaces. The raw
|
|
1562
|
+
// output looks like: "Yes,\x1b[12GI\x1b[14Gtrust\x1b[20Gthis\x1b[25Gfolder".
|
|
1563
|
+
// We normalize the buffer by stripping ANSI sequences before matching.
|
|
1564
|
+
//
|
|
1565
|
+
// To avoid false positives from normal conversation (e.g. a user asking about
|
|
1566
|
+
// "trust" or "onboarding"), detection is only active during a boot window
|
|
1567
|
+
// (first N ms after spawn) and only scans the last portion of the buffer.
|
|
1568
|
+
// Once a dialog is detected during the window, the state is LATCHED — it
|
|
1569
|
+
// persists until the PTY exits, so a user messaging minutes after boot still
|
|
1570
|
+
// gets the fail-fast error instead of the 120s timeout.
|
|
1571
|
+
const _BOOT_WINDOW_MS = 30_000; // 30s after spawn — enough for slow container starts
|
|
1572
|
+
const _BOOT_SCAN_TAIL = 4096; // only scan the last 4KB (current screenful)
|
|
1573
|
+
|
|
1574
|
+
// Strip ANSI escape sequences (cursor movement, colors, etc.) so that Ink's
|
|
1575
|
+
// positioned rendering ("Yes,\x1b[12GI\x1b[14Gtrust...") becomes plain text
|
|
1576
|
+
// ("Yes, I trust this folder").
|
|
1577
|
+
function _stripAnsi(str) {
|
|
1578
|
+
// eslint-disable-next-line no-control-regex
|
|
1579
|
+
return str.replace(/\x1b\[[0-9;]*[a-zA-Z]/g, ' ');
|
|
1580
|
+
}
|
|
1581
|
+
|
|
1582
|
+
const _BOOT_PATTERNS = {
|
|
1583
|
+
'blocked-on-trust': [
|
|
1584
|
+
/yes,?\s+i\s+trust\s+this\s+folder/i,
|
|
1585
|
+
/do\s+you\s+trust\s+this\s+folder/i,
|
|
1586
|
+
],
|
|
1587
|
+
'blocked-on-onboarding': [
|
|
1588
|
+
/yes,?\s+i\s+accept/i,
|
|
1589
|
+
],
|
|
1590
|
+
};
|
|
1591
|
+
|
|
1592
|
+
/**
|
|
1593
|
+
* Detect whether the active PTY is ready, still booting, blocked on an
|
|
1594
|
+
* interactive dialog, or has exited. Returns one of:
|
|
1595
|
+
* 'ready' — PTY is running and no blocking dialog detected
|
|
1596
|
+
* 'booting' — PTY is running but within the boot window
|
|
1597
|
+
* 'blocked-on-trust' — "Yes, I trust this folder" dialog detected (latched)
|
|
1598
|
+
* 'blocked-on-onboarding' — onboarding/first-run dialog detected (latched)
|
|
1599
|
+
* 'exited' — PTY process has exited
|
|
1600
|
+
* 'no-pty' — no PTY record exists
|
|
1601
|
+
*
|
|
1602
|
+
* Latching: once a dialog is detected during the boot window, the state is
|
|
1603
|
+
* stored on the record and returned for the PTY's lifetime. This prevents
|
|
1604
|
+
* the 30s window from expiring while the dialog is still on screen.
|
|
1605
|
+
*/
|
|
1606
|
+
export function getPtyBootState() {
|
|
1607
|
+
const s = _active();
|
|
1608
|
+
if (!s) return 'no-pty';
|
|
1609
|
+
if (!s.ptyProcess) return 'exited';
|
|
1610
|
+
// Return latched state if a dialog was previously detected.
|
|
1611
|
+
if (s._bootBlockedState) return s._bootBlockedState;
|
|
1612
|
+
// Only detect blocking dialogs during the boot window. After that, any
|
|
1613
|
+
// match would be a false positive from normal conversation content.
|
|
1614
|
+
const elapsed = _now() - (s._spawnedAt || 0);
|
|
1615
|
+
if (elapsed > _BOOT_WINDOW_MS) return 'ready';
|
|
1616
|
+
const buf = s.outputBuffer || '';
|
|
1617
|
+
if (buf.length < 50) return 'booting';
|
|
1618
|
+
// Only scan the tail of the buffer — the current screen content. Older
|
|
1619
|
+
// output may contain legitimate uses of trigger words from conversation.
|
|
1620
|
+
const tail = _stripAnsi(buf.slice(-_BOOT_SCAN_TAIL));
|
|
1621
|
+
for (const [state, patterns] of Object.entries(_BOOT_PATTERNS)) {
|
|
1622
|
+
for (const re of patterns) {
|
|
1623
|
+
if (re.test(tail)) {
|
|
1624
|
+
// Latch the state so it persists beyond the boot window.
|
|
1625
|
+
s._bootBlockedState = state;
|
|
1626
|
+
return state;
|
|
1627
|
+
}
|
|
1628
|
+
}
|
|
1629
|
+
}
|
|
1630
|
+
return 'ready';
|
|
1631
|
+
}
|
|
1632
|
+
|
|
1534
1633
|
/**
|
|
1535
1634
|
* Launch-or-reattach for a workspace cwd (2026-10-06, multi-instance). Now that spawnClaude
|
|
1536
1635
|
* mints a fresh instanceKey per call and no longer kills an existing same-cwd record, an
|