@hwip/cli 0.1.23 → 0.1.25
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 +25 -1
- package/dist/background-tasks-output.d.ts +28 -0
- package/dist/background-tasks-output.js +107 -0
- package/dist/background-tasks-requests.d.ts +22 -0
- package/dist/background-tasks-requests.js +26 -0
- package/dist/background-tasks-stop.d.ts +43 -0
- package/dist/background-tasks-stop.js +128 -0
- package/dist/background-tasks.d.ts +65 -0
- package/dist/background-tasks.js +225 -0
- package/dist/crypto.d.ts +1 -1
- package/dist/http-failure.d.ts +13 -3
- package/dist/http-failure.js +21 -4
- package/dist/listener.d.ts +65 -0
- package/dist/listener.js +259 -8
- package/dist/subagent-transcripts.d.ts +5 -0
- package/dist/subagent-transcripts.js +5 -5
- package/package.json +1 -1
package/dist/listener.js
CHANGED
|
@@ -26,8 +26,8 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
26
26
|
};
|
|
27
27
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
28
28
|
exports.collectWatchHits = exports.resetPatternWatches = exports.setPatternWatches = exports.withSettledPrompts = exports.PROMPT_SEAL_WAIT_MS = exports.withBlockedPrompts = exports.setPromptSealer = exports.deriveSessionState = exports.resetSessionStates = exports.continueRuns = exports.runIdOfEpoch = exports.__checkoutCacheSize = exports.parseSessionName = exports.resetPaneFitClaims = exports.tmuxTargetFor = exports.subagentTranscriptFor = exports.recordTargets = exports.recordSubagentTranscripts = exports.isSubagentSessionName = exports.detectRemoteAgent = exports.sessionLiveness = exports.sessionExists = exports.liveSessionNames = exports.tmuxArgs = exports.silenceListenerLog = exports.invalidateTmuxSocketCache = exports.wheelInput = exports.wheelEvents = exports.WHEEL_STATE_FORMAT = exports.resolveWheel = exports.resolveKeys = exports.probePane = exports.checkRateLimit = exports.AUTH_FAILURE_CODES = exports.commandsReportDue = exports.commandsFingerprint = exports.COMMAND_SCAN_INTERVAL_MS = exports.sessionsReportDue = exports.sessionsFingerprint = exports.withRunSeqs = exports.staleConnectionAction = exports.askedToReconnect = exports.MAX_STALE_CONNECTION_DROPS = exports.createReportAckWatch = exports.REPORT_ACK_TIMEOUT_MS = exports.SESSION_REPORT_HEARTBEAT_MS = exports.SESSION_REPORT_INTERVAL_MS = exports.heartbeatVerdict = exports.pingDue = exports.PING_IDLE_MS = void 0;
|
|
29
|
-
exports.
|
|
30
|
-
exports.handleListener = exports.liveScheduleRunnerDeps = exports.listenerSettings = exports.resolveWsUrl = exports.streamSession = exports.computeListenerDeviceId = exports.computeBackoff = exports.handlePush = exports.gcAttachments = exports.displayFolder = exports.claimLanFile = exports.saveFileFromS3 = exports.downloadSealedEach = exports.answerFileBound = exports.downloadAttachments = exports.setAttachmentContext = exports.shellTextRefusal = exports.writeRemoteMarker = exports.isInventoried = exports.syncTmuxAgentNames = exports.recordInventory = void 0;
|
|
29
|
+
exports.MAX_PENDING_DECRYPTS = exports.MAX_INPUT_LANES = exports.validateInputMessage = exports.MAX_INPUT_BODY_CHARS = exports.MAX_INPUT_KEYS = exports.handleStreamControl = exports.buildStreamFrame = exports.isStreamCapReached = exports.fitSealedFrame = exports.SEALED_FRAME_MAX_BYTES = exports.stopAllStreams = exports.stopStream = exports.stopStreamOf = exports.handleTurnWatch = exports.sealTurnBatch = exports.resolveWatchTranscript = exports.MAX_CONCURRENT_STREAMS = exports.STREAM_RENEW_FRESH_MS = exports.STREAM_LEASE_MS = exports.claimFrameSend = exports.hasFrameBudget = exports.streamCadence = exports.MAX_FRAMES_PER_SEC = exports.BURST_WINDOW_MS = exports.BURST_INTERVAL_MS = exports.STREAM_INTERVAL_MS = exports.STREAM_CAPTURE_LINES = exports.scheduleInjectSnapshots = exports.historyLinesIn = exports.cursorLineFor = exports.parsePaneGeometry = exports.STREAM_GEOMETRY_FORMAT = exports.handleScreenHistoryRequest = exports.SCREEN_HISTORY_MAX_LINES = exports.handleSessionForgetRequest = exports.handleSessionExitRequest = exports.SESSION_EXIT_STEP_MS = exports.handleSessionResumeRequest = exports.SHELL_START_KIND = exports.handleBackgroundTaskOutputRequest = exports.handleBackgroundTaskStopRequest = exports.handleBackgroundTasksRequest = exports.handleScheduleListRequest = exports.handleFileBlobRequest = exports.handleFileTreeRequest = exports.handleDiffFileRequest = exports.handleDiffFilesRequest = exports.fileViewBytes = exports.handleScreenRequest = exports.setSubscriberTrust = void 0;
|
|
30
|
+
exports.handleListener = exports.liveScheduleRunnerDeps = exports.listenerSettings = exports.resolveWsUrl = exports.streamSession = exports.computeListenerDeviceId = exports.computeBackoff = exports.handlePush = exports.gcAttachments = exports.displayFolder = exports.claimLanFile = exports.saveFileFromS3 = exports.downloadSealedEach = exports.answerFileBound = exports.downloadAttachments = exports.setAttachmentContext = exports.shellTextRefusal = exports.writeRemoteMarker = exports.isInventoried = exports.syncTmuxAgentNames = exports.recordInventory = exports.collectSessionsVerbose = exports.handleCommandInput = exports.pendingInputDecrypts = void 0;
|
|
31
31
|
const child_process_1 = require("child_process");
|
|
32
32
|
const crypto_1 = require("crypto");
|
|
33
33
|
const fs_1 = require("fs");
|
|
@@ -51,6 +51,10 @@ const gate_js_1 = require("./gate.js");
|
|
|
51
51
|
const session_registry_js_1 = require("./session-registry.js");
|
|
52
52
|
const remote_agents_js_1 = require("./remote-agents.js");
|
|
53
53
|
const subagent_transcripts_js_1 = require("./subagent-transcripts.js");
|
|
54
|
+
const background_tasks_js_1 = require("./background-tasks.js");
|
|
55
|
+
const background_tasks_requests_js_1 = require("./background-tasks-requests.js");
|
|
56
|
+
const background_tasks_output_js_1 = require("./background-tasks-output.js");
|
|
57
|
+
const background_tasks_stop_js_1 = require("./background-tasks-stop.js");
|
|
54
58
|
const transcript_tail_js_1 = require("./transcript-tail.js");
|
|
55
59
|
const listener_service_js_1 = require("./listener-service.js");
|
|
56
60
|
const agent_state_js_1 = require("./agent-state.js");
|
|
@@ -1429,6 +1433,232 @@ const handleScheduleListRequest = (req, send) => {
|
|
|
1429
1433
|
return true;
|
|
1430
1434
|
};
|
|
1431
1435
|
exports.handleScheduleListRequest = handleScheduleListRequest;
|
|
1436
|
+
/**
|
|
1437
|
+
* Answer a phone's request for the background commands a Claude session runs
|
|
1438
|
+
* (`Bash` with `run_in_background`). The rows are Claude's descriptions of
|
|
1439
|
+
* them, which can say what a command is for, so the answer is sealed for a key
|
|
1440
|
+
* that checked out and bound to the session — never in the clear, whatever
|
|
1441
|
+
* this listener's seal history. Each task is checked for a live writer on its
|
|
1442
|
+
* output now, not only at the last sweep, so a dead one is not listed.
|
|
1443
|
+
*/
|
|
1444
|
+
const handleBackgroundTasksRequest = (req, send) => {
|
|
1445
|
+
if (req.subtype !== 'agent.tasks.request')
|
|
1446
|
+
return false;
|
|
1447
|
+
if (typeof req.requestId !== 'string' || !req.requestId || req.requestId.length > MAX_REQUEST_ID_LENGTH)
|
|
1448
|
+
return false;
|
|
1449
|
+
if (typeof req.sessionName !== 'string' || !req.sessionName || req.sessionName.length > MAX_REQUEST_ID_LENGTH)
|
|
1450
|
+
return false;
|
|
1451
|
+
if (req.targetDeviceId !== (0, exports.computeListenerDeviceId)())
|
|
1452
|
+
return false;
|
|
1453
|
+
const { requestId, sessionName } = req;
|
|
1454
|
+
const frame = {
|
|
1455
|
+
subtype: 'agent.tasks.result',
|
|
1456
|
+
requestId,
|
|
1457
|
+
sessionName,
|
|
1458
|
+
...(typeof req.deviceId === 'string' && req.deviceId ? { targetDeviceId: req.deviceId } : {}),
|
|
1459
|
+
at: new Date().toISOString(),
|
|
1460
|
+
};
|
|
1461
|
+
const reply = (fields) => { send({ ...frame, ...fields }); };
|
|
1462
|
+
const asker = typeof req.deviceId === 'string' && /^[\w-]{1,64}$/.test(req.deviceId) ? req.deviceId : '';
|
|
1463
|
+
if (!(0, exports.checkRateLimit)(`tasks:list:${asker}`)) {
|
|
1464
|
+
reply({ error: 'rate_limited' });
|
|
1465
|
+
return true;
|
|
1466
|
+
}
|
|
1467
|
+
// No key, no list: a plaintext request is refused even where screens still go out in the clear.
|
|
1468
|
+
if (!asksForSeal(req)) {
|
|
1469
|
+
reply({ error: 'e2ee_required' });
|
|
1470
|
+
return true;
|
|
1471
|
+
}
|
|
1472
|
+
whenSealAdmitted(req, (phoneKey) => {
|
|
1473
|
+
(0, background_tasks_requests_js_1.liveTaskRows)((0, background_tasks_js_1.backgroundTasksFor)(sessionName)?.tasks ?? [])
|
|
1474
|
+
.then(async (tasks) => {
|
|
1475
|
+
await (0, crypto_js_1.initDeviceCrypto)();
|
|
1476
|
+
return (0, crypto_js_1.sealV2)('agent.tasks', JSON.stringify({ v: 1, requestId, at: frame.at, tasks }), phoneKey, sessionName);
|
|
1477
|
+
})
|
|
1478
|
+
.then((encrypted) => reply({ encrypted }))
|
|
1479
|
+
.catch((err) => {
|
|
1480
|
+
// A seal that fails is an error, never a plaintext list.
|
|
1481
|
+
(0, listener_log_js_1.log)(`⧉ tasks ${sessionName}: seal failed (${err instanceof Error ? err.message : err})`);
|
|
1482
|
+
reply({ error: 'encrypt_failed' });
|
|
1483
|
+
});
|
|
1484
|
+
}, (reason) => { reply({ error: reason }); });
|
|
1485
|
+
return true;
|
|
1486
|
+
};
|
|
1487
|
+
exports.handleBackgroundTasksRequest = handleBackgroundTasksRequest;
|
|
1488
|
+
/** Task ids as Claude Code writes them (`STARTED` in background-tasks.ts). */
|
|
1489
|
+
const TASK_ID_PATTERN = /^[A-Za-z0-9]{1,32}$/;
|
|
1490
|
+
/** How far a stop request's own clock may sit from this machine's. */
|
|
1491
|
+
const STOP_CLOCK_SKEW_MS = 5 * 60_000;
|
|
1492
|
+
/**
|
|
1493
|
+
* Stop requests already acted on, by phone key and request id → when. Kept for
|
|
1494
|
+
* twice the skew: an envelope is taken while its own `at` is within the skew
|
|
1495
|
+
* of now, and a phone clock running ahead keeps it takeable past one window
|
|
1496
|
+
* from when it was acted on. In memory only: a listener restarted inside the
|
|
1497
|
+
* window would take a replayed stop again, which can end only a command the
|
|
1498
|
+
* session still runs, found again from this machine's own probes.
|
|
1499
|
+
*/
|
|
1500
|
+
const actedStops = new Map();
|
|
1501
|
+
const MAX_ACTED_STOPS = 512;
|
|
1502
|
+
/** True the first time a phone's request id is seen. */
|
|
1503
|
+
const firstStop = (key, now) => {
|
|
1504
|
+
for (const [seen, at] of actedStops)
|
|
1505
|
+
if (now - at > 2 * STOP_CLOCK_SKEW_MS)
|
|
1506
|
+
actedStops.delete(seen);
|
|
1507
|
+
if (actedStops.has(key))
|
|
1508
|
+
return false;
|
|
1509
|
+
if (actedStops.size >= MAX_ACTED_STOPS)
|
|
1510
|
+
actedStops.delete(actedStops.keys().next().value);
|
|
1511
|
+
actedStops.set(key, now);
|
|
1512
|
+
return true;
|
|
1513
|
+
};
|
|
1514
|
+
/**
|
|
1515
|
+
* Stop a background command a Claude session runs, for a trusted phone. The
|
|
1516
|
+
* one remote path here that ends a process, so the request has to prove who
|
|
1517
|
+
* sent it: it is sealed by the phone's key, which must be the asking device's
|
|
1518
|
+
* trusted key, and names the request, the task and its time inside the seal.
|
|
1519
|
+
* A key alone is public and proves nothing. The phone names a task by id;
|
|
1520
|
+
* which process group that is, and whether it may be signalled at all, is
|
|
1521
|
+
* decided on this machine (`background-tasks-stop.ts`). The answer is a status
|
|
1522
|
+
* in the clear: it says nothing about the task beyond whether it was stopped.
|
|
1523
|
+
*/
|
|
1524
|
+
const handleBackgroundTaskStopRequest = (req, send) => {
|
|
1525
|
+
if (req.subtype !== 'agent.task.stop.request')
|
|
1526
|
+
return false;
|
|
1527
|
+
if (typeof req.requestId !== 'string' || !req.requestId || req.requestId.length > MAX_REQUEST_ID_LENGTH)
|
|
1528
|
+
return false;
|
|
1529
|
+
if (typeof req.sessionName !== 'string' || !req.sessionName || req.sessionName.length > MAX_REQUEST_ID_LENGTH)
|
|
1530
|
+
return false;
|
|
1531
|
+
if (req.targetDeviceId !== (0, exports.computeListenerDeviceId)())
|
|
1532
|
+
return false;
|
|
1533
|
+
const { requestId, sessionName } = req;
|
|
1534
|
+
const frame = {
|
|
1535
|
+
subtype: 'agent.task.stop.result',
|
|
1536
|
+
requestId,
|
|
1537
|
+
sessionName,
|
|
1538
|
+
...(typeof req.deviceId === 'string' && req.deviceId ? { targetDeviceId: req.deviceId } : {}),
|
|
1539
|
+
at: new Date().toISOString(),
|
|
1540
|
+
};
|
|
1541
|
+
const reply = (fields) => { send({ ...frame, ...fields }); };
|
|
1542
|
+
const asker = typeof req.deviceId === 'string' && /^[\w-]{1,64}$/.test(req.deviceId) ? req.deviceId : '';
|
|
1543
|
+
if (!(0, exports.checkRateLimit)(`tasks:stop:${asker}`)) {
|
|
1544
|
+
reply({ error: 'rate_limited' });
|
|
1545
|
+
return true;
|
|
1546
|
+
}
|
|
1547
|
+
if (!asksForSeal(req)) {
|
|
1548
|
+
reply({ error: 'e2ee_required' });
|
|
1549
|
+
return true;
|
|
1550
|
+
}
|
|
1551
|
+
const sealedRequest = req.encrypted;
|
|
1552
|
+
if (!(0, crypto_js_1.isSealedV2)(sealedRequest)) {
|
|
1553
|
+
reply({ error: 'bad_request' });
|
|
1554
|
+
return true;
|
|
1555
|
+
}
|
|
1556
|
+
const answer = async (phoneKey) => {
|
|
1557
|
+
let asked;
|
|
1558
|
+
try {
|
|
1559
|
+
// Untrusted until the checks below: every field is `unknown`.
|
|
1560
|
+
asked = JSON.parse(await (0, crypto_js_1.openV2)('agent.task.stop', sealedRequest, phoneKey, sessionName));
|
|
1561
|
+
}
|
|
1562
|
+
catch {
|
|
1563
|
+
return { error: 'bad_request' };
|
|
1564
|
+
}
|
|
1565
|
+
if (typeof asked !== 'object' || asked === null || asked.v !== 1 || asked.requestId !== requestId)
|
|
1566
|
+
return { error: 'bad_request' };
|
|
1567
|
+
if (typeof asked.taskId !== 'string' || !TASK_ID_PATTERN.test(asked.taskId))
|
|
1568
|
+
return { error: 'bad_request' };
|
|
1569
|
+
const now = Date.now();
|
|
1570
|
+
const at = typeof asked.at === 'string' ? Date.parse(asked.at) : Number.NaN;
|
|
1571
|
+
if (!Number.isFinite(at) || Math.abs(now - at) > STOP_CLOCK_SKEW_MS)
|
|
1572
|
+
return { error: 'bad_request' };
|
|
1573
|
+
// A relay that kept a sealed stop can hand it back; the seal names the request, so the second one is refused.
|
|
1574
|
+
if (!firstStop(`${phoneKey}\n${requestId}`, now))
|
|
1575
|
+
return { error: 'bad_request' };
|
|
1576
|
+
const { taskId } = asked;
|
|
1577
|
+
const running = (0, background_tasks_js_1.backgroundTasksFor)(sessionName);
|
|
1578
|
+
const task = running?.tasks.find((t) => t.id === taskId);
|
|
1579
|
+
if (!task || running?.panePid == null)
|
|
1580
|
+
return { result: 'not_found' };
|
|
1581
|
+
const result = await (0, background_tasks_stop_js_1.stopBackgroundTask)(task, running.panePid);
|
|
1582
|
+
(0, listener_log_js_1.log)(`⧉ tasks ${sessionName}: stop ${taskId} → ${result}`);
|
|
1583
|
+
return { result };
|
|
1584
|
+
};
|
|
1585
|
+
whenSealAdmitted(req, (phoneKey) => {
|
|
1586
|
+
answer(phoneKey)
|
|
1587
|
+
.then(reply)
|
|
1588
|
+
.catch((err) => {
|
|
1589
|
+
(0, listener_log_js_1.log)(`⧉ tasks ${sessionName}: stop failed (${err instanceof Error ? err.message : err})`);
|
|
1590
|
+
reply({ result: 'kill_failed' });
|
|
1591
|
+
});
|
|
1592
|
+
}, (reason) => { reply({ error: reason }); });
|
|
1593
|
+
return true;
|
|
1594
|
+
};
|
|
1595
|
+
exports.handleBackgroundTaskStopRequest = handleBackgroundTaskStopRequest;
|
|
1596
|
+
/**
|
|
1597
|
+
* Answer a phone's request for the end of a background command's output
|
|
1598
|
+
* (`readTaskOutputTail`: the last 16 KB of the file the transcript named, if
|
|
1599
|
+
* it is that task's `tasks/<id>.output`). A log can hold anything a command
|
|
1600
|
+
* printed, so the answer is sealed for a key that checked out and bound to
|
|
1601
|
+
* the session, the request and the task — never in the clear.
|
|
1602
|
+
*/
|
|
1603
|
+
const handleBackgroundTaskOutputRequest = (req, send) => {
|
|
1604
|
+
if (req.subtype !== 'agent.task.output.request')
|
|
1605
|
+
return false;
|
|
1606
|
+
if (typeof req.requestId !== 'string' || !req.requestId || req.requestId.length > MAX_REQUEST_ID_LENGTH)
|
|
1607
|
+
return false;
|
|
1608
|
+
if (typeof req.sessionName !== 'string' || !req.sessionName || req.sessionName.length > MAX_REQUEST_ID_LENGTH)
|
|
1609
|
+
return false;
|
|
1610
|
+
if (req.targetDeviceId !== (0, exports.computeListenerDeviceId)())
|
|
1611
|
+
return false;
|
|
1612
|
+
const { requestId, sessionName } = req;
|
|
1613
|
+
const frame = {
|
|
1614
|
+
subtype: 'agent.task.output.result',
|
|
1615
|
+
requestId,
|
|
1616
|
+
sessionName,
|
|
1617
|
+
...(typeof req.deviceId === 'string' && req.deviceId ? { targetDeviceId: req.deviceId } : {}),
|
|
1618
|
+
at: new Date().toISOString(),
|
|
1619
|
+
};
|
|
1620
|
+
const reply = (fields) => { send({ ...frame, ...fields }); };
|
|
1621
|
+
const asker = typeof req.deviceId === 'string' && /^[\w-]{1,64}$/.test(req.deviceId) ? req.deviceId : '';
|
|
1622
|
+
if (!(0, exports.checkRateLimit)(`tasks:output:${asker}`)) {
|
|
1623
|
+
reply({ error: 'rate_limited' });
|
|
1624
|
+
return true;
|
|
1625
|
+
}
|
|
1626
|
+
if (!asksForSeal(req)) {
|
|
1627
|
+
reply({ error: 'e2ee_required' });
|
|
1628
|
+
return true;
|
|
1629
|
+
}
|
|
1630
|
+
const { taskId } = req;
|
|
1631
|
+
if (typeof taskId !== 'string' || !TASK_ID_PATTERN.test(taskId)) {
|
|
1632
|
+
reply({ error: 'bad_request' });
|
|
1633
|
+
return true;
|
|
1634
|
+
}
|
|
1635
|
+
whenSealAdmitted(req, (phoneKey) => {
|
|
1636
|
+
const task = (0, background_tasks_js_1.backgroundTasksFor)(sessionName)?.tasks.find((t) => t.id === taskId);
|
|
1637
|
+
if (!task)
|
|
1638
|
+
return reply({ error: 'not_found' });
|
|
1639
|
+
const answer = async () => {
|
|
1640
|
+
const tail = await (0, background_tasks_output_js_1.readTaskOutputTail)(task);
|
|
1641
|
+
if ('error' in tail)
|
|
1642
|
+
return { error: tail.error };
|
|
1643
|
+
const body = (0, background_tasks_output_js_1.fitTaskOutputBody)({ requestId, at: frame.at, taskId }, tail, exports.SEALED_FRAME_MAX_BYTES);
|
|
1644
|
+
try {
|
|
1645
|
+
await (0, crypto_js_1.initDeviceCrypto)();
|
|
1646
|
+
return { encrypted: await (0, crypto_js_1.sealV2)('agent.task.output', body, phoneKey, sessionName) };
|
|
1647
|
+
}
|
|
1648
|
+
catch (err) {
|
|
1649
|
+
// A seal that fails is an error, never the output in the clear.
|
|
1650
|
+
(0, listener_log_js_1.log)(`⧉ tasks ${sessionName}: output seal failed (${err instanceof Error ? err.message : err})`);
|
|
1651
|
+
return { error: 'encrypt_failed' };
|
|
1652
|
+
}
|
|
1653
|
+
};
|
|
1654
|
+
answer().then(reply, (err) => {
|
|
1655
|
+
(0, listener_log_js_1.log)(`⧉ tasks ${sessionName}: output read failed (${err instanceof Error ? err.message : err})`);
|
|
1656
|
+
reply({ error: 'read_failed' });
|
|
1657
|
+
});
|
|
1658
|
+
}, (reason) => { reply({ error: reason }); });
|
|
1659
|
+
return true;
|
|
1660
|
+
};
|
|
1661
|
+
exports.handleBackgroundTaskOutputRequest = handleBackgroundTaskOutputRequest;
|
|
1432
1662
|
/** A run id as the registry writes it: tmux `session_created`, epoch seconds. */
|
|
1433
1663
|
const RUN_ID = /^\d{1,12}$/;
|
|
1434
1664
|
/** The name a wrapper family counts from: `hwip-x-3` → `hwip-x`. */
|
|
@@ -3497,6 +3727,8 @@ exports.handleCommandInput = handleCommandInput;
|
|
|
3497
3727
|
* viewer nothing but a re-render.
|
|
3498
3728
|
*/
|
|
3499
3729
|
const subagentScans = new Map();
|
|
3730
|
+
/** Per Claude session: what its transcript says is running in the background. */
|
|
3731
|
+
const backgroundTaskStates = new Map();
|
|
3500
3732
|
/**
|
|
3501
3733
|
* Inventory pass that also records *why* each `hwip-*` session was
|
|
3502
3734
|
* skipped. The verbose log uses the rejection notes to explain empty
|
|
@@ -3524,7 +3756,7 @@ const collectSessionsVerbose = () => {
|
|
|
3524
3756
|
// Invalidate so the next cycle re-runs full discovery instead of
|
|
3525
3757
|
// wedging the listener at "reported 0 session(s)" forever.
|
|
3526
3758
|
(0, tmux_socket_js_1.invalidateTmuxSocketCache)();
|
|
3527
|
-
return { sessions: [], rejected: [], targets: {}, subagentTranscripts: {}, recordable: {} };
|
|
3759
|
+
return { sessions: [], rejected: [], targets: {}, subagentTranscripts: {}, recordable: {}, backgroundTasks: {} };
|
|
3528
3760
|
}
|
|
3529
3761
|
const rawLines = (list.stdout ?? '').split('\n').filter(Boolean);
|
|
3530
3762
|
// Sanity-check that the format separator actually survived. tmux is
|
|
@@ -3587,6 +3819,7 @@ const collectSessionsVerbose = () => {
|
|
|
3587
3819
|
const resumeIdOf = new Map();
|
|
3588
3820
|
const targets = {};
|
|
3589
3821
|
const subagentTranscripts = {};
|
|
3822
|
+
const backgroundTasks = {};
|
|
3590
3823
|
const recordable = {};
|
|
3591
3824
|
for (const [name, group] of groups) {
|
|
3592
3825
|
// Main pane = the lowest (window, pane) index that runs an agent.
|
|
@@ -3664,7 +3897,7 @@ const collectSessionsVerbose = () => {
|
|
|
3664
3897
|
if (resumeId)
|
|
3665
3898
|
resumeIdOf.set(name, resumeId);
|
|
3666
3899
|
targets[name] = main.row.paneId;
|
|
3667
|
-
|
|
3900
|
+
const mainSession = {
|
|
3668
3901
|
name,
|
|
3669
3902
|
attached: group.attached,
|
|
3670
3903
|
agentKind: main.agent.kind,
|
|
@@ -3678,7 +3911,8 @@ const collectSessionsVerbose = () => {
|
|
|
3678
3911
|
runId: (0, exports.runIdOfEpoch)(group.created),
|
|
3679
3912
|
lastActivityAt: epochToIso(group.activity),
|
|
3680
3913
|
...(0, exports.deriveSessionState)(name, main.agent.kind, capturePaneText(name, main.row.paneId)),
|
|
3681
|
-
}
|
|
3914
|
+
};
|
|
3915
|
+
sessions.push(mainSession);
|
|
3682
3916
|
// Subagent panes: every OTHER pane of this session whose tty's
|
|
3683
3917
|
// foreground process group runs a registered agent (measured:
|
|
3684
3918
|
// pane_current_command alone says `bash` for a pi subagent — the
|
|
@@ -3740,6 +3974,15 @@ const collectSessionsVerbose = () => {
|
|
|
3740
3974
|
}
|
|
3741
3975
|
const transcriptPath = main.agent.kind === 'claude' ? mainTranscript : null;
|
|
3742
3976
|
if (transcriptPath) {
|
|
3977
|
+
// Background commands (`Bash` with run_in_background): the phone
|
|
3978
|
+
// shows how many, and asks for the rows themselves sealed.
|
|
3979
|
+
const tracked = backgroundTaskStates.get(name) ?? (0, background_tasks_js_1.initialBackgroundTaskState)();
|
|
3980
|
+
backgroundTaskStates.set(name, tracked);
|
|
3981
|
+
const tasks = (0, background_tasks_js_1.trackBackgroundTasks)(transcriptPath, tracked);
|
|
3982
|
+
if (tasks.length > 0)
|
|
3983
|
+
backgroundTasks[name] = { tasks, panePid: info.panePid ?? null };
|
|
3984
|
+
if (tasks.length > 0)
|
|
3985
|
+
mainSession.backgroundTaskCount = tasks.length;
|
|
3743
3986
|
const scan = subagentScans.get(name) ?? (0, subagent_transcripts_js_1.initialSubagentScanState)();
|
|
3744
3987
|
subagentScans.set(name, scan);
|
|
3745
3988
|
const reserved = new Set(extras.map(paneNum));
|
|
@@ -3781,6 +4024,7 @@ const collectSessionsVerbose = () => {
|
|
|
3781
4024
|
}
|
|
3782
4025
|
}
|
|
3783
4026
|
pruneToLive(subagentScans, new Set(groups.keys()));
|
|
4027
|
+
pruneToLive(backgroundTaskStates, new Set(groups.keys()));
|
|
3784
4028
|
pruneToLive(sessionStates, new Set(sessions.map((s) => s.name)));
|
|
3785
4029
|
// An id two panes both answer to belongs to at most one of them, and the
|
|
3786
4030
|
// sweep cannot tell which — opencode names the busiest session in the
|
|
@@ -3821,7 +4065,7 @@ const collectSessionsVerbose = () => {
|
|
|
3821
4065
|
providerSessionName: s.providerSessionName,
|
|
3822
4066
|
providerSessionNameSource: s.providerSessionNameSource,
|
|
3823
4067
|
})));
|
|
3824
|
-
return { sessions, rejected, targets, subagentTranscripts, recordable };
|
|
4068
|
+
return { sessions, rejected, targets, subagentTranscripts, recordable, backgroundTasks };
|
|
3825
4069
|
};
|
|
3826
4070
|
exports.collectSessionsVerbose = collectSessionsVerbose;
|
|
3827
4071
|
/**
|
|
@@ -3841,6 +4085,7 @@ const collectSessions = () => {
|
|
|
3841
4085
|
// back to the (focus-following) bare session name.
|
|
3842
4086
|
(0, tmux_pane_js_1.recordTargets)(result.targets);
|
|
3843
4087
|
(0, tmux_pane_js_1.recordSubagentTranscripts)(result.subagentTranscripts);
|
|
4088
|
+
(0, background_tasks_js_1.recordBackgroundTasks)(result.backgroundTasks);
|
|
3844
4089
|
return result.sessions;
|
|
3845
4090
|
};
|
|
3846
4091
|
/** Names from the most recent inventory sweep; null until the first one lands —
|
|
@@ -5295,11 +5540,12 @@ const streamSession = (wsUrl, apiKey) => {
|
|
|
5295
5540
|
}
|
|
5296
5541
|
};
|
|
5297
5542
|
const publishSessions = (inventory, sessions) => {
|
|
5298
|
-
const { rejected, targets, subagentTranscripts, recordable } = inventory;
|
|
5543
|
+
const { rejected, targets, subagentTranscripts, recordable, backgroundTasks } = inventory;
|
|
5299
5544
|
(0, exports.recordInventory)(sessions);
|
|
5300
5545
|
worktreeCleanup.observe(sessions.map((s) => s.name));
|
|
5301
5546
|
(0, tmux_pane_js_1.recordTargets)(targets);
|
|
5302
5547
|
(0, tmux_pane_js_1.recordSubagentTranscripts)(subagentTranscripts);
|
|
5548
|
+
(0, background_tasks_js_1.recordBackgroundTasks)(backgroundTasks);
|
|
5303
5549
|
turnRecorder?.observe(recordable);
|
|
5304
5550
|
// Let the user's own status bar say what the phone says. Change-gated
|
|
5305
5551
|
// internally, so an unchanged sweep spawns nothing.
|
|
@@ -5532,7 +5778,11 @@ const streamSession = (wsUrl, apiKey) => {
|
|
|
5532
5778
|
&& !(0, exports.handleFileTreeRequest)(m.data, sendEphemeral)
|
|
5533
5779
|
&& !(0, exports.handleFileBlobRequest)(m.data, sendEphemeral)
|
|
5534
5780
|
// Reading the schedules: files this machine wrote itself, sealed for the asker.
|
|
5535
|
-
&& !(0, exports.handleScheduleListRequest)(m.data, sendEphemeral)
|
|
5781
|
+
&& !(0, exports.handleScheduleListRequest)(m.data, sendEphemeral)
|
|
5782
|
+
// A session's background commands: what Claude said they are, sealed for the asker.
|
|
5783
|
+
&& !(0, exports.handleBackgroundTasksRequest)(m.data, sendEphemeral)
|
|
5784
|
+
&& !(0, exports.handleBackgroundTaskStopRequest)(m.data, sendEphemeral)
|
|
5785
|
+
&& !(0, exports.handleBackgroundTaskOutputRequest)(m.data, sendEphemeral)) {
|
|
5536
5786
|
void (0, exports.handleScreenRequest)(m.data)
|
|
5537
5787
|
.then((reply) => { if (reply)
|
|
5538
5788
|
sendEphemeral(reply); })
|
|
@@ -5871,6 +6121,7 @@ const handleListener = async (args) => {
|
|
|
5871
6121
|
`Tail \`~/.hwip/listener.log\` to follow it, or kill ${otherPid} first.`);
|
|
5872
6122
|
return 0;
|
|
5873
6123
|
}
|
|
6124
|
+
await (0, http_failure_js_1.useHttp1Transport)();
|
|
5874
6125
|
const settings = (0, exports.listenerSettings)(args);
|
|
5875
6126
|
if ('exit' in settings) {
|
|
5876
6127
|
console.error(settings.message);
|
|
@@ -150,6 +150,11 @@ export declare const subagentDirFor: (parentTranscriptPath: string) => string;
|
|
|
150
150
|
* cares about the second.
|
|
151
151
|
*/
|
|
152
152
|
export declare const isSubagentTranscriptPath: (transcriptPath: string) => boolean;
|
|
153
|
+
/** The four ways Claude Code reports a background subagent stopping — measured
|
|
154
|
+
* 2026-09-14 over every parent transcript on this machine (787 completed, 12
|
|
155
|
+
* failed, 12 killed, 2 stopped, nothing else). */
|
|
156
|
+
export declare const TASK_END: RegExp;
|
|
157
|
+
export declare const TASK_ID: RegExp;
|
|
153
158
|
/**
|
|
154
159
|
* The live subagents of one Claude Code session, in chip order (by number).
|
|
155
160
|
*
|
|
@@ -23,7 +23,7 @@
|
|
|
23
23
|
* the alternative failure is this feature vanishing in silence.
|
|
24
24
|
*/
|
|
25
25
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
|
-
exports.scanSubagents = exports.isSubagentTranscriptPath = exports.subagentDirFor = exports.initialSubagentScanState = exports.MAX_SUBAGENT_ROWS = exports.SUBAGENT_STALE_RECHECK_MS = exports.SUBAGENT_CATCH_UP_BYTES = exports.SUBAGENT_END_SLACK_MS = exports.SUBAGENT_ADDRESSABLE_MS = exports.SUBAGENT_LIVE_MS = exports.SUBAGENT_WORKING_MS = void 0;
|
|
26
|
+
exports.scanSubagents = exports.TASK_ID = exports.TASK_END = exports.isSubagentTranscriptPath = exports.subagentDirFor = exports.initialSubagentScanState = exports.MAX_SUBAGENT_ROWS = exports.SUBAGENT_STALE_RECHECK_MS = exports.SUBAGENT_CATCH_UP_BYTES = exports.SUBAGENT_END_SLACK_MS = exports.SUBAGENT_ADDRESSABLE_MS = exports.SUBAGENT_LIVE_MS = exports.SUBAGENT_WORKING_MS = void 0;
|
|
27
27
|
const node_fs_1 = require("node:fs");
|
|
28
28
|
const node_path_1 = require("node:path");
|
|
29
29
|
const transcript_tail_js_1 = require("./transcript-tail.js");
|
|
@@ -147,8 +147,8 @@ const isAgentToolUse = (line) => {
|
|
|
147
147
|
/** The four ways Claude Code reports a background subagent stopping — measured
|
|
148
148
|
* 2026-09-14 over every parent transcript on this machine (787 completed, 12
|
|
149
149
|
* failed, 12 killed, 2 stopped, nothing else). */
|
|
150
|
-
|
|
151
|
-
|
|
150
|
+
exports.TASK_END = /<status>(?:completed|failed|killed|stopped)<\/status>/;
|
|
151
|
+
exports.TASK_ID = /<task-id>([^<]{1,200})<\/task-id>/;
|
|
152
152
|
/**
|
|
153
153
|
* The subagent a parent line says has ended, and when — or null.
|
|
154
154
|
*
|
|
@@ -182,9 +182,9 @@ const subagentEndOf = (line) => {
|
|
|
182
182
|
if (result?.status === 'completed' && typeof result.agentId === 'string')
|
|
183
183
|
return { agentId: result.agentId, at };
|
|
184
184
|
const content = entry.message?.content;
|
|
185
|
-
if (entry.origin?.kind !== 'task-notification' || typeof content !== 'string' || !TASK_END.test(content))
|
|
185
|
+
if (entry.origin?.kind !== 'task-notification' || typeof content !== 'string' || !exports.TASK_END.test(content))
|
|
186
186
|
return null;
|
|
187
|
-
const agentId = TASK_ID.exec(content)?.[1];
|
|
187
|
+
const agentId = exports.TASK_ID.exec(content)?.[1];
|
|
188
188
|
return agentId ? { agentId, at } : null;
|
|
189
189
|
};
|
|
190
190
|
/**
|