@adhdev/daemon-core 0.9.82-rc.293 → 0.9.82-rc.294
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/index.js +195 -18
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +195 -18
- package/dist/index.mjs.map +1 -1
- package/dist/providers/spec/cli-adapter.d.ts +14 -0
- package/dist/providers/types/interactive-prompt.d.ts +19 -0
- package/package.json +2 -2
- package/src/config/chat-history.ts +255 -10
- package/src/mesh/coordinator-prompt.ts +1 -0
- package/src/providers/cli-provider-instance.ts +36 -14
- package/src/providers/spec/cli-adapter.ts +40 -0
- package/src/providers/types/interactive-prompt.ts +1 -1
|
@@ -132,6 +132,20 @@ export declare class SpecCliAdapter implements CliAdapter {
|
|
|
132
132
|
*/
|
|
133
133
|
private maybeClearResolvedClaudeTuiPrompt;
|
|
134
134
|
private maybeCaptureClaudeTuiPrompt;
|
|
135
|
+
/**
|
|
136
|
+
* The TUI prompt is captured on the FIRST frame that renders the
|
|
137
|
+
* "Enter to select" footer. At that instant the option rows' checkbox
|
|
138
|
+
* column may not have drawn yet, so `detectClaudeTuiMultiSelect` returns
|
|
139
|
+
* false and the prompt is frozen as single-select — the dashboard then
|
|
140
|
+
* renders radio buttons even though the picker is multi-select.
|
|
141
|
+
*
|
|
142
|
+
* While the same TUI prompt is still on screen, re-check the live snapshot:
|
|
143
|
+
* if checkbox glyphs have since appeared, promote any single-select
|
|
144
|
+
* question to multi-select and re-emit status. Promotion is one-way
|
|
145
|
+
* (false→true only) — once a question is known multi-select we never demote
|
|
146
|
+
* it, since the glyph column can scroll out of view on later frames.
|
|
147
|
+
*/
|
|
148
|
+
private maybeUpgradeClaudeTuiMultiSelect;
|
|
135
149
|
private readClaudeTuiHeaders;
|
|
136
150
|
private captureClaudeTuiPrompt;
|
|
137
151
|
getDebugState(): Record<string, any>;
|
|
@@ -33,6 +33,25 @@ export interface ClaudeInteractiveTuiPage {
|
|
|
33
33
|
screenText: string;
|
|
34
34
|
header?: string;
|
|
35
35
|
}
|
|
36
|
+
/**
|
|
37
|
+
* Decide whether a captured claude-cli AskUserQuestion TUI page is multi-select.
|
|
38
|
+
*
|
|
39
|
+
* The original heuristic only matched the footer hint `/Space to select|toggle
|
|
40
|
+
* selections/i`. That string drifts between claude-cli versions, so when it
|
|
41
|
+
* changed the dashboard silently fell back to multiSelect:false and rendered
|
|
42
|
+
* single-select (radio) controls even though the on-screen picker showed
|
|
43
|
+
* checkboxes — the user could not check more than one box. (The CLI's own
|
|
44
|
+
* terminal still rendered `[ ]` correctly because it never depends on this
|
|
45
|
+
* parse.)
|
|
46
|
+
*
|
|
47
|
+
* Make detection robust by ALSO recognising the actual checkbox markers the
|
|
48
|
+
* multi-select picker draws on its option rows (`[ ]` / `[x]` / `☐` / `☒` /
|
|
49
|
+
* `◻` / `◼`). Single-select rows are drawn with a `❯`/number cursor only and
|
|
50
|
+
* carry none of these box glyphs, so their presence is a reliable signal. The
|
|
51
|
+
* broadened footer patterns ("Space to", "toggle", "select multiple") are kept
|
|
52
|
+
* as a secondary signal for layouts that render markers differently.
|
|
53
|
+
*/
|
|
54
|
+
export declare function detectClaudeTuiMultiSelect(screenText: string): boolean;
|
|
36
55
|
export declare function detectClaudeAskUserQuestionPromptFromTuiPages(pages: ClaudeInteractiveTuiPage[], options: {
|
|
37
56
|
promptId: string;
|
|
38
57
|
providerType?: string;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@adhdev/daemon-core",
|
|
3
|
-
"version": "0.9.82-rc.
|
|
3
|
+
"version": "0.9.82-rc.294",
|
|
4
4
|
"description": "ADHDev daemon core — CDP, IDE detection, providers, command execution",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
@@ -46,7 +46,7 @@
|
|
|
46
46
|
"author": "vilmire",
|
|
47
47
|
"license": "AGPL-3.0-or-later",
|
|
48
48
|
"dependencies": {
|
|
49
|
-
"@adhdev/mesh-shared": "0.9.82-rc.
|
|
49
|
+
"@adhdev/mesh-shared": "0.9.82-rc.294",
|
|
50
50
|
"@adhdev/session-host-core": "*",
|
|
51
51
|
"@agentclientprotocol/sdk": "^0.16.1",
|
|
52
52
|
"ajv": "^8.20.0",
|
|
@@ -1234,6 +1234,241 @@ function isBoundedTailRequest(limit: number, offset: number, excludeRecentCount:
|
|
|
1234
1234
|
return true;
|
|
1235
1235
|
}
|
|
1236
1236
|
|
|
1237
|
+
// Byte threshold below which a file is small enough that reading the whole
|
|
1238
|
+
// thing is cheaper than seeking. Reverse-seek pays off only on large files.
|
|
1239
|
+
const REVERSE_TAIL_SMALL_FILE_BYTES = 64 * 1024;
|
|
1240
|
+
// Chunk size for backward reads. We read the file tail one chunk at a time
|
|
1241
|
+
// (newest bytes first) until we have collected enough complete lines.
|
|
1242
|
+
const REVERSE_TAIL_CHUNK_BYTES = 64 * 1024;
|
|
1243
|
+
|
|
1244
|
+
// Per-(file path) incremental tail cache. A hot session's daily JSONL file grows
|
|
1245
|
+
// append-only while it generates; the size+mtime signature on the bounded-tail
|
|
1246
|
+
// read cache therefore invalidates on every append and forces a full re-read.
|
|
1247
|
+
// Here we keep the most recently decoded tail LINES for a file plus the byte
|
|
1248
|
+
// length we read them from. When the file has only grown (append-only: size
|
|
1249
|
+
// increased, the previously-read prefix is unchanged) we read just the new bytes
|
|
1250
|
+
// from `size` onward and splice them onto the retained tail — no full re-parse.
|
|
1251
|
+
// Truncation/rotation (size shrank, or a fresh inode) drops the entry and falls
|
|
1252
|
+
// back to a full reverse-seek.
|
|
1253
|
+
interface IncrementalTailCacheEntry {
|
|
1254
|
+
// File length (bytes) we have already consumed into `lines`.
|
|
1255
|
+
size: number;
|
|
1256
|
+
mtimeMs: number;
|
|
1257
|
+
// Decoded complete lines (oldest-first) covering at least the tail window.
|
|
1258
|
+
// Bounded to TAIL_LINES_RETAINED so memory stays flat for huge files.
|
|
1259
|
+
lines: string[];
|
|
1260
|
+
// True when `lines` is the entire file (head reached), so older pages can
|
|
1261
|
+
// trust that nothing precedes the retained window.
|
|
1262
|
+
coversWholeFile: boolean;
|
|
1263
|
+
}
|
|
1264
|
+
|
|
1265
|
+
// How many trailing lines we retain per file. The bounded-tail caller never
|
|
1266
|
+
// asks for more than BOUNDED_TAIL_MAX_LIMIT + slack; keep a generous multiple so
|
|
1267
|
+
// repeated reads at the same window are served incrementally.
|
|
1268
|
+
const TAIL_LINES_RETAINED = BOUNDED_TAIL_MAX_LIMIT + 2 * BOUNDED_TAIL_SLACK;
|
|
1269
|
+
const INCREMENTAL_TAIL_CACHE_MAX_ENTRIES = 64;
|
|
1270
|
+
const incrementalTailCache = new Map<string, IncrementalTailCacheEntry>();
|
|
1271
|
+
|
|
1272
|
+
function evictIncrementalTailCache(): void {
|
|
1273
|
+
while (incrementalTailCache.size > INCREMENTAL_TAIL_CACHE_MAX_ENTRIES) {
|
|
1274
|
+
const oldest = incrementalTailCache.keys().next().value;
|
|
1275
|
+
if (oldest === undefined) break;
|
|
1276
|
+
incrementalTailCache.delete(oldest);
|
|
1277
|
+
}
|
|
1278
|
+
}
|
|
1279
|
+
|
|
1280
|
+
// Split a Buffer into complete lines plus a leftover head fragment, partitioning
|
|
1281
|
+
// only on the newline byte (0x0A). 0x0A never appears inside a multibyte UTF-8
|
|
1282
|
+
// sequence, so decoding each complete byte segment is boundary-safe. The leftover
|
|
1283
|
+
// (bytes before the first newline) is returned undecoded so a caller stitching
|
|
1284
|
+
// chunks together never splits a multibyte char.
|
|
1285
|
+
function splitBufferLines(buf: Buffer): { head: Buffer; lines: string[] } {
|
|
1286
|
+
const lines: string[] = [];
|
|
1287
|
+
let lineEnd = buf.length;
|
|
1288
|
+
let firstNewline = -1;
|
|
1289
|
+
for (let i = buf.length - 1; i >= 0; i--) {
|
|
1290
|
+
if (buf[i] !== 0x0a) continue;
|
|
1291
|
+
if (i + 1 < lineEnd) {
|
|
1292
|
+
lines.push(buf.toString('utf-8', i + 1, lineEnd));
|
|
1293
|
+
}
|
|
1294
|
+
lineEnd = i;
|
|
1295
|
+
firstNewline = i;
|
|
1296
|
+
}
|
|
1297
|
+
// Lines were collected newest-first; restore oldest-first for the segment
|
|
1298
|
+
// that follows the first (lowest-index) newline.
|
|
1299
|
+
lines.reverse();
|
|
1300
|
+
const head = firstNewline >= 0 ? buf.subarray(0, firstNewline) : buf;
|
|
1301
|
+
return { head, lines };
|
|
1302
|
+
}
|
|
1303
|
+
|
|
1304
|
+
// Read the last bytes of a file, newest-first, until we have at least `needed`
|
|
1305
|
+
// complete lines (or reach the start of the file). Returns lines oldest-first and
|
|
1306
|
+
// whether the whole file was consumed. Boundary-safe: lines are cut on the
|
|
1307
|
+
// newline byte only, so multibyte UTF-8 chars are never split, and a trailing
|
|
1308
|
+
// partial line (no terminating newline) is preserved as a complete final line.
|
|
1309
|
+
function readReverseTailLines(filePath: string, needed: number): { lines: string[]; coversWholeFile: boolean; size: number; mtimeMs: number } {
|
|
1310
|
+
const fd = fs.openSync(filePath, 'r');
|
|
1311
|
+
try {
|
|
1312
|
+
const stat = fs.fstatSync(fd);
|
|
1313
|
+
const size = stat.size;
|
|
1314
|
+
let position = size;
|
|
1315
|
+
// `carry` holds bytes belonging to a line that straddles the current
|
|
1316
|
+
// chunk boundary (its start is in an older, not-yet-read chunk).
|
|
1317
|
+
let carry: Buffer = Buffer.alloc(0);
|
|
1318
|
+
const collected: string[] = [];
|
|
1319
|
+
|
|
1320
|
+
while (position > 0 && collected.length < needed) {
|
|
1321
|
+
const chunkSize = Math.min(REVERSE_TAIL_CHUNK_BYTES, position);
|
|
1322
|
+
position -= chunkSize;
|
|
1323
|
+
const chunk = Buffer.alloc(chunkSize);
|
|
1324
|
+
fs.readSync(fd, chunk, 0, chunkSize, position);
|
|
1325
|
+
const combined = carry.length ? Buffer.concat([chunk, carry]) : chunk;
|
|
1326
|
+
const { head, lines } = splitBufferLines(combined);
|
|
1327
|
+
// `head` is the (possibly partial) line whose start lies further back;
|
|
1328
|
+
// hold it for the next (older) chunk to complete.
|
|
1329
|
+
carry = head;
|
|
1330
|
+
// `lines` are oldest-first within this combined buffer; prepend them
|
|
1331
|
+
// ahead of what we already collected (which is strictly newer).
|
|
1332
|
+
for (let i = lines.length - 1; i >= 0; i--) {
|
|
1333
|
+
collected.push(lines[i]);
|
|
1334
|
+
}
|
|
1335
|
+
}
|
|
1336
|
+
|
|
1337
|
+
const reachedStart = position <= 0;
|
|
1338
|
+
if (reachedStart && carry.length) {
|
|
1339
|
+
// Leftover head at the start of the file is itself a complete line.
|
|
1340
|
+
collected.push(carry.toString('utf-8'));
|
|
1341
|
+
}
|
|
1342
|
+
// `collected` is newest-first; restore oldest-first.
|
|
1343
|
+
collected.reverse();
|
|
1344
|
+
return { lines: collected, coversWholeFile: reachedStart, size, mtimeMs: stat.mtimeMs };
|
|
1345
|
+
} finally {
|
|
1346
|
+
fs.closeSync(fd);
|
|
1347
|
+
}
|
|
1348
|
+
}
|
|
1349
|
+
|
|
1350
|
+
// Return the tail lines (oldest-first) for a single history file, reading as
|
|
1351
|
+
// little of the file as possible. Strategy:
|
|
1352
|
+
// - Small files: one readFileSync (seeking is not worth the syscalls).
|
|
1353
|
+
// - Large files: reverse byte-seek for the newest `needed` lines.
|
|
1354
|
+
// - Append-only growth since the last read: read only the appended bytes and
|
|
1355
|
+
// splice them onto the retained tail (no full re-parse) — this is what keeps
|
|
1356
|
+
// a hot, still-generating session cheap to poll.
|
|
1357
|
+
// `needed` is a soft floor; we may return more (whole small files / retained
|
|
1358
|
+
// window). Lines include any trailing partial (unterminated) final line.
|
|
1359
|
+
function readFileTailLines(filePath: string, needed: number): { lines: string[]; coversWholeFile: boolean } {
|
|
1360
|
+
let stat: fs.Stats;
|
|
1361
|
+
try {
|
|
1362
|
+
stat = fs.statSync(filePath);
|
|
1363
|
+
} catch {
|
|
1364
|
+
return { lines: [], coversWholeFile: true };
|
|
1365
|
+
}
|
|
1366
|
+
const size = stat.size;
|
|
1367
|
+
const mtimeMs = stat.mtimeMs;
|
|
1368
|
+
if (size === 0) {
|
|
1369
|
+
incrementalTailCache.delete(filePath);
|
|
1370
|
+
return { lines: [], coversWholeFile: true };
|
|
1371
|
+
}
|
|
1372
|
+
|
|
1373
|
+
const cached = incrementalTailCache.get(filePath);
|
|
1374
|
+
if (cached) {
|
|
1375
|
+
if (cached.size === size && cached.mtimeMs === mtimeMs) {
|
|
1376
|
+
// Unchanged since last read — reuse retained tail. Refresh LRU.
|
|
1377
|
+
incrementalTailCache.delete(filePath);
|
|
1378
|
+
incrementalTailCache.set(filePath, cached);
|
|
1379
|
+
if (cached.coversWholeFile || cached.lines.length >= needed) {
|
|
1380
|
+
return { lines: cached.lines, coversWholeFile: cached.coversWholeFile };
|
|
1381
|
+
}
|
|
1382
|
+
// Retained window is smaller than this request needs; fall through
|
|
1383
|
+
// to a fresh reverse-seek for the larger window.
|
|
1384
|
+
} else if (size > cached.size) {
|
|
1385
|
+
// Append-only growth: the prefix [0, cached.size) is assumed
|
|
1386
|
+
// unchanged (JSONL is append-only). Read just the new bytes and
|
|
1387
|
+
// stitch them — but verify the byte at cached.size-1 is still the
|
|
1388
|
+
// newline that terminated our last retained line, so a rewrite that
|
|
1389
|
+
// happens to grow the file (compaction) is detected and rejected.
|
|
1390
|
+
const incremental = tryIncrementalTailGrowth(filePath, cached, size, mtimeMs, needed);
|
|
1391
|
+
if (incremental) return { lines: incremental.lines, coversWholeFile: incremental.coversWholeFile };
|
|
1392
|
+
}
|
|
1393
|
+
// size shrank (truncation/rotation) or incremental failed → drop & reload.
|
|
1394
|
+
incrementalTailCache.delete(filePath);
|
|
1395
|
+
}
|
|
1396
|
+
|
|
1397
|
+
if (size <= REVERSE_TAIL_SMALL_FILE_BYTES) {
|
|
1398
|
+
let content: string;
|
|
1399
|
+
try {
|
|
1400
|
+
content = fs.readFileSync(filePath, 'utf-8');
|
|
1401
|
+
} catch {
|
|
1402
|
+
return { lines: [], coversWholeFile: true };
|
|
1403
|
+
}
|
|
1404
|
+
const lines = content.split('\n');
|
|
1405
|
+
// A trailing newline yields a final empty element; drop only that one so
|
|
1406
|
+
// an unterminated partial last line is still preserved.
|
|
1407
|
+
if (lines.length && lines[lines.length - 1] === '') lines.pop();
|
|
1408
|
+
storeIncrementalTailCache(filePath, size, mtimeMs, lines, true);
|
|
1409
|
+
return { lines, coversWholeFile: true };
|
|
1410
|
+
}
|
|
1411
|
+
|
|
1412
|
+
let result: { lines: string[]; coversWholeFile: boolean; size: number; mtimeMs: number };
|
|
1413
|
+
try {
|
|
1414
|
+
result = readReverseTailLines(filePath, needed);
|
|
1415
|
+
} catch {
|
|
1416
|
+
return { lines: [], coversWholeFile: true };
|
|
1417
|
+
}
|
|
1418
|
+
storeIncrementalTailCache(filePath, result.size, result.mtimeMs, result.lines, result.coversWholeFile);
|
|
1419
|
+
return { lines: result.lines, coversWholeFile: result.coversWholeFile };
|
|
1420
|
+
}
|
|
1421
|
+
|
|
1422
|
+
// Read appended bytes [cached.size, size) and splice them onto the retained tail.
|
|
1423
|
+
// Returns null if the prior byte is not a newline (the retained tail did not end
|
|
1424
|
+
// on a record boundary, e.g. the file was rewritten) so the caller can full-reload.
|
|
1425
|
+
function tryIncrementalTailGrowth(
|
|
1426
|
+
filePath: string,
|
|
1427
|
+
cached: IncrementalTailCacheEntry,
|
|
1428
|
+
size: number,
|
|
1429
|
+
mtimeMs: number,
|
|
1430
|
+
needed: number,
|
|
1431
|
+
): { lines: string[]; coversWholeFile: boolean } | null {
|
|
1432
|
+
const fd = fs.openSync(filePath, 'r');
|
|
1433
|
+
try {
|
|
1434
|
+
// Confirm the byte ending the previously-read prefix is still a newline.
|
|
1435
|
+
if (cached.size > 0) {
|
|
1436
|
+
const boundary = Buffer.alloc(1);
|
|
1437
|
+
fs.readSync(fd, boundary, 0, 1, cached.size - 1);
|
|
1438
|
+
if (boundary[0] !== 0x0a) return null;
|
|
1439
|
+
}
|
|
1440
|
+
const appendedLength = size - cached.size;
|
|
1441
|
+
const appended = Buffer.alloc(appendedLength);
|
|
1442
|
+
fs.readSync(fd, appended, 0, appendedLength, cached.size);
|
|
1443
|
+
const newLines = appended.toString('utf-8').split('\n');
|
|
1444
|
+
if (newLines.length && newLines[newLines.length - 1] === '') newLines.pop();
|
|
1445
|
+
const merged = cached.lines.concat(newLines);
|
|
1446
|
+
// Keep memory flat: retain only the trailing window.
|
|
1447
|
+
const trimmed = merged.length > TAIL_LINES_RETAINED
|
|
1448
|
+
? merged.slice(merged.length - TAIL_LINES_RETAINED)
|
|
1449
|
+
: merged;
|
|
1450
|
+
const coversWholeFile = cached.coversWholeFile && trimmed.length === merged.length;
|
|
1451
|
+
storeIncrementalTailCache(filePath, size, mtimeMs, trimmed, coversWholeFile);
|
|
1452
|
+
if (coversWholeFile || trimmed.length >= needed) {
|
|
1453
|
+
return { lines: trimmed, coversWholeFile };
|
|
1454
|
+
}
|
|
1455
|
+
// Should not happen (we only grew), but be safe.
|
|
1456
|
+
return { lines: trimmed, coversWholeFile };
|
|
1457
|
+
} catch {
|
|
1458
|
+
return null;
|
|
1459
|
+
} finally {
|
|
1460
|
+
fs.closeSync(fd);
|
|
1461
|
+
}
|
|
1462
|
+
}
|
|
1463
|
+
|
|
1464
|
+
function storeIncrementalTailCache(filePath: string, size: number, mtimeMs: number, lines: string[], coversWholeFile: boolean): void {
|
|
1465
|
+
const retained = lines.length > TAIL_LINES_RETAINED ? lines.slice(lines.length - TAIL_LINES_RETAINED) : lines;
|
|
1466
|
+
const covers = coversWholeFile && retained.length === lines.length;
|
|
1467
|
+
incrementalTailCache.delete(filePath);
|
|
1468
|
+
incrementalTailCache.set(filePath, { size, mtimeMs, lines: retained, coversWholeFile: covers });
|
|
1469
|
+
evictIncrementalTailCache();
|
|
1470
|
+
}
|
|
1471
|
+
|
|
1237
1472
|
// Read newest-first only as many files as needed to cover the requested window
|
|
1238
1473
|
// plus slack. listHistoryFiles already returns files reversed (newest-first), so
|
|
1239
1474
|
// we accumulate (de-duped) candidates from the end and stop once we have enough,
|
|
@@ -1250,19 +1485,22 @@ function readBoundedTailRecords(
|
|
|
1250
1485
|
|
|
1251
1486
|
for (let f = 0; f < files.length; f++) {
|
|
1252
1487
|
const filePath = path.join(dir, files[f]);
|
|
1253
|
-
|
|
1254
|
-
|
|
1255
|
-
|
|
1256
|
-
|
|
1257
|
-
|
|
1258
|
-
|
|
1259
|
-
const
|
|
1260
|
-
|
|
1261
|
-
//
|
|
1488
|
+
// Read only the file tail needed to top up the window — for a large
|
|
1489
|
+
// single-day file this seeks the last `needed` lines instead of parsing
|
|
1490
|
+
// the whole file. We re-derive the per-file floor each iteration from how
|
|
1491
|
+
// many records are still missing (plus slack so dedup at the boundary is
|
|
1492
|
+
// stable), capped at `needed`.
|
|
1493
|
+
const remaining = Math.max(0, needed - collected.length);
|
|
1494
|
+
const perFileNeeded = Math.min(needed, remaining + BOUNDED_TAIL_SLACK);
|
|
1495
|
+
const { lines, coversWholeFile } = readFileTailLines(filePath, perFileNeeded);
|
|
1496
|
+
// Walk this file's tail lines newest-first so we fill the tail window from
|
|
1497
|
+
// the bottom. seen-dedup keeps the same first-wins-by-newest semantics the
|
|
1262
1498
|
// full read produced (files are processed newest-first there too).
|
|
1263
1499
|
for (let i = lines.length - 1; i >= 0; i--) {
|
|
1500
|
+
const line = lines[i];
|
|
1501
|
+
if (!line) continue;
|
|
1264
1502
|
try {
|
|
1265
|
-
const parsed = JSON.parse(
|
|
1503
|
+
const parsed = JSON.parse(line) as HistoryMessage;
|
|
1266
1504
|
const sanitizedMessage = sanitizeHistoryMessage(agentType, parsed);
|
|
1267
1505
|
if (!sanitizedMessage) continue;
|
|
1268
1506
|
const hash = buildHistoryMessageHash(agentType, sanitizedMessage);
|
|
@@ -1271,6 +1509,13 @@ function readBoundedTailRecords(
|
|
|
1271
1509
|
collected.push(sanitizedMessage);
|
|
1272
1510
|
} catch { /* skip invalid lines */ }
|
|
1273
1511
|
}
|
|
1512
|
+
// If we only read this file's tail (its head was not reached), older
|
|
1513
|
+
// messages remain within this very file — the conversation is NOT fully
|
|
1514
|
+
// represented even if this is the last file, so hasMore must stay true.
|
|
1515
|
+
if (!coversWholeFile) {
|
|
1516
|
+
readAllFiles = false;
|
|
1517
|
+
break;
|
|
1518
|
+
}
|
|
1274
1519
|
// Stop once we have the window AND there is at least one more file (so a
|
|
1275
1520
|
// potential older boundary message exists). If this is the last file we
|
|
1276
1521
|
// fall through and mark the whole history as read.
|
|
@@ -384,6 +384,7 @@ function buildRulesSection(coordinatorCliType?: string): string {
|
|
|
384
384
|
- **Verify via git, not source.** Use \`mesh_git_status\` to confirm side effects. Treat agent summaries as self-reports, not verification.
|
|
385
385
|
- **Limit parallelism.** Start with 1–2 tasks; scale only on success. Never duplicate a session because \`mesh_read_chat\` shows no final message while tool/terminal activity is ongoing. This caps *concurrent* load — it does not mean serialize independent work: when a new, independent request arrives and there is headroom under \`maxParallelTasks\`, dispatch it right away rather than waiting for an in-flight task or a user nudge (read-only diagnosis especially, since it has no merge cost).
|
|
386
386
|
- **Check history first.** Call \`mesh_task_history\` at session start to avoid duplicate work and inform recovery. On failure, read task history before retrying.
|
|
387
|
+
- **Sequence shared-base-moving merges.** Parallel dispatch is encouraged, but merging one worktree can advance another in-flight worktree's base — especially the oss submodule pointer — turning a clean fast-forward into a diverged rebase (patch-equivalence correctly blocks this). Before merging an in-flight worktree while siblings are also in flight, land in an intentional order, re-clone long-running worktrees from the advanced base, or expect to manually rebase + ff-only the laggards; merging an independent fix mid-flight can strand siblings into a rebase.
|
|
387
388
|
- **Converge branches.** After worktree tasks: refine/fast-forward, or classify as \`pushed_feature_branch_needs_merge\` / \`blocked_review\` / \`cleanup_candidate\` / \`not_mergeable\`. Clean up with \`mesh_remove_node\`.
|
|
388
389
|
- **Refinery is config-driven.** \`mesh_refine_node\` must run validation from \`.adhdev/refine.{json,yaml,yml}\` or \`repo-mesh.refine.*\`. Heuristics are scaffolding only.
|
|
389
390
|
- **Submodule reachability = publish-needed.** \`submodule_reachability_failed\` → classify as \`blocked_review\`, request user approval to push to submodule main, then rerun \`mesh_refine_node\`.
|
|
@@ -37,6 +37,18 @@ type PersistableCliHistoryMessage = {
|
|
|
37
37
|
receivedAt?: number;
|
|
38
38
|
};
|
|
39
39
|
|
|
40
|
+
// Status snapshots only ever surface the newest messages: the cloud 'live'
|
|
41
|
+
// profile drops chat messages entirely (loaded lazily via read_chat on
|
|
42
|
+
// subscribe) and the 'full' profile caps activeChat.messages to the last 60
|
|
43
|
+
// (see status/normalize.ts). Unread/completion markers walk only the tail.
|
|
44
|
+
// So getState()'s saved-history hydration — which runs once per resume/manual
|
|
45
|
+
// CLI session on every status report — must read only a bounded tail, not the
|
|
46
|
+
// entire transcript. A full MAX_SAFE_INTEGER read here makes the initial
|
|
47
|
+
// status report O(transcript) × N(sessions), which is the real cold first-
|
|
48
|
+
// connection bottleneck on chat-heavy machines. The window comfortably exceeds
|
|
49
|
+
// the 60-message snapshot cap so dedup/collapse at the boundary stays stable.
|
|
50
|
+
const STATUS_HYDRATION_TAIL_LIMIT = 200;
|
|
51
|
+
|
|
40
52
|
type CompletedDebouncePending = {
|
|
41
53
|
chatTitle: string;
|
|
42
54
|
duration: number;
|
|
@@ -2190,13 +2202,21 @@ export class CliProviderInstance implements ProviderInstance {
|
|
|
2190
2202
|
return newestMessageAt === 0;
|
|
2191
2203
|
}
|
|
2192
2204
|
|
|
2193
|
-
private syncCanonicalSavedHistoryIfNeeded(): boolean {
|
|
2205
|
+
private syncCanonicalSavedHistoryIfNeeded(options: { full?: boolean } = {}): boolean {
|
|
2194
2206
|
if (!this.providerSessionId) return false;
|
|
2195
2207
|
const canonicalHistory = this.provider.nativeHistory;
|
|
2196
2208
|
if (!canonicalHistory) return false;
|
|
2197
2209
|
|
|
2210
|
+
// Per-status-report hydration reads only a bounded tail (snapshot needs at
|
|
2211
|
+
// most the newest 60). The once-per-resume restore path passes full:true
|
|
2212
|
+
// because seedSessionHistory needs the COMPLETE transcript to seed dedup
|
|
2213
|
+
// state. The read-cache key encodes the window so the bounded and full
|
|
2214
|
+
// reads don't share/clobber each other's 2s cache entry.
|
|
2215
|
+
const limit = options.full ? Number.MAX_SAFE_INTEGER : STATUS_HYDRATION_TAIL_LIMIT;
|
|
2216
|
+
const windowTag = options.full ? 'full' : `tail:${STATUS_HYDRATION_TAIL_LIMIT}`;
|
|
2217
|
+
|
|
2198
2218
|
if (isNativeSourceCanonicalHistory(canonicalHistory)) {
|
|
2199
|
-
const cacheKey = [this.type, this.providerSessionId, this.workingDir].join('\0');
|
|
2219
|
+
const cacheKey = [this.type, this.providerSessionId, this.workingDir, windowTag].join('\0');
|
|
2200
2220
|
const now = Date.now();
|
|
2201
2221
|
if (cacheKey === this.lastNativeSourceCanonicalCacheKey && now - this.lastNativeSourceCanonicalCheckAt < 2_000) {
|
|
2202
2222
|
return true;
|
|
@@ -2209,7 +2229,7 @@ export class CliProviderInstance implements ProviderInstance {
|
|
|
2209
2229
|
historySessionId: this.providerSessionId,
|
|
2210
2230
|
workspace: this.workingDir,
|
|
2211
2231
|
offset: 0,
|
|
2212
|
-
limit
|
|
2232
|
+
limit,
|
|
2213
2233
|
historyBehavior: this.provider.historyBehavior,
|
|
2214
2234
|
scripts: this.provider.scripts as any,
|
|
2215
2235
|
});
|
|
@@ -2226,7 +2246,7 @@ export class CliProviderInstance implements ProviderInstance {
|
|
|
2226
2246
|
}
|
|
2227
2247
|
|
|
2228
2248
|
try {
|
|
2229
|
-
const cacheKey = [this.type, this.providerSessionId, this.workingDir, canonicalHistory.mode || 'materialized-mirror'].join('\0');
|
|
2249
|
+
const cacheKey = [this.type, this.providerSessionId, this.workingDir, canonicalHistory.mode || 'materialized-mirror', windowTag].join('\0');
|
|
2230
2250
|
const now = Date.now();
|
|
2231
2251
|
if (cacheKey === this.lastNativeSourceCanonicalCacheKey && now - this.lastNativeSourceCanonicalCheckAt < 2_000) {
|
|
2232
2252
|
return true;
|
|
@@ -2237,15 +2257,14 @@ export class CliProviderInstance implements ProviderInstance {
|
|
|
2237
2257
|
if (!materializeProviderNativeHistory(this.type, canonicalHistory, this.providerSessionId, this.workingDir, this.provider.scripts as any)) {
|
|
2238
2258
|
return false;
|
|
2239
2259
|
}
|
|
2240
|
-
//
|
|
2241
|
-
//
|
|
2242
|
-
//
|
|
2243
|
-
//
|
|
2244
|
-
//
|
|
2245
|
-
//
|
|
2246
|
-
//
|
|
2247
|
-
|
|
2248
|
-
const restoredHistory = readChatHistory(this.type, 0, Number.MAX_SAFE_INTEGER, this.providerSessionId, 0, this.provider.historyBehavior);
|
|
2260
|
+
// Bounded by default: the per-status-report path only needs the newest
|
|
2261
|
+
// STATUS_HYDRATION_TAIL_LIMIT messages because the snapshot caps
|
|
2262
|
+
// activeChat.messages to the last 60 (status/normalize.ts) and loads
|
|
2263
|
+
// the rest lazily via read_chat on subscribe. The once-per-resume
|
|
2264
|
+
// restore path passes full:true so seedSessionHistory still sees the
|
|
2265
|
+
// COMPLETE transcript for prefix-dedup seeding. readChatHistory serves
|
|
2266
|
+
// a bounded limit as an O(tail) read.
|
|
2267
|
+
const restoredHistory = readChatHistory(this.type, 0, limit, this.providerSessionId, 0, this.provider.historyBehavior);
|
|
2249
2268
|
this.lastPersistedHistoryMessages = restoredHistory.messages.map((message) => ({
|
|
2250
2269
|
role: message.role,
|
|
2251
2270
|
content: message.content,
|
|
@@ -2261,7 +2280,10 @@ export class CliProviderInstance implements ProviderInstance {
|
|
|
2261
2280
|
|
|
2262
2281
|
private restorePersistedHistoryFromCurrentSession(): void {
|
|
2263
2282
|
if (!this.providerSessionId) return;
|
|
2264
|
-
|
|
2283
|
+
// Restore is the once-per-resume seeding path: it needs the COMPLETE
|
|
2284
|
+
// transcript so seedSessionHistory can prime dedup state. Pass full so the
|
|
2285
|
+
// hydration read is unbounded here (and only here).
|
|
2286
|
+
this.syncCanonicalSavedHistoryIfNeeded({ full: true });
|
|
2265
2287
|
const restoredHistory = isNativeSourceCanonicalHistory(this.provider.nativeHistory)
|
|
2266
2288
|
? readProviderChatHistory(this.type, {
|
|
2267
2289
|
canonicalHistory: this.provider.nativeHistory,
|
|
@@ -31,6 +31,7 @@ import {
|
|
|
31
31
|
buildClaudeInteractiveToolResult,
|
|
32
32
|
detectClaudeAskUserQuestionPromptFromJson,
|
|
33
33
|
detectClaudeAskUserQuestionPromptFromTuiPages,
|
|
34
|
+
detectClaudeTuiMultiSelect,
|
|
34
35
|
type ClaudeInteractiveTuiPage,
|
|
35
36
|
type InteractivePrompt,
|
|
36
37
|
type InteractivePromptResponse,
|
|
@@ -445,12 +446,14 @@ export class SpecCliAdapter implements CliAdapter {
|
|
|
445
446
|
}
|
|
446
447
|
this.maybeClearResolvedClaudeTuiPrompt();
|
|
447
448
|
this.maybeCaptureClaudeTuiPrompt();
|
|
449
|
+
this.maybeUpgradeClaudeTuiMultiSelect();
|
|
448
450
|
this.statusCallback?.();
|
|
449
451
|
return;
|
|
450
452
|
case 'pty_data':
|
|
451
453
|
this.detectInteractivePromptFromPtyChunk(ev.chunk);
|
|
452
454
|
this.maybeClearResolvedClaudeTuiPrompt();
|
|
453
455
|
this.maybeCaptureClaudeTuiPrompt();
|
|
456
|
+
this.maybeUpgradeClaudeTuiMultiSelect();
|
|
454
457
|
try { this.ptyDataCallback?.(ev.chunk); } catch { /* ignore */ }
|
|
455
458
|
return;
|
|
456
459
|
case 'exit':
|
|
@@ -614,6 +617,43 @@ export class SpecCliAdapter implements CliAdapter {
|
|
|
614
617
|
});
|
|
615
618
|
}
|
|
616
619
|
|
|
620
|
+
/**
|
|
621
|
+
* The TUI prompt is captured on the FIRST frame that renders the
|
|
622
|
+
* "Enter to select" footer. At that instant the option rows' checkbox
|
|
623
|
+
* column may not have drawn yet, so `detectClaudeTuiMultiSelect` returns
|
|
624
|
+
* false and the prompt is frozen as single-select — the dashboard then
|
|
625
|
+
* renders radio buttons even though the picker is multi-select.
|
|
626
|
+
*
|
|
627
|
+
* While the same TUI prompt is still on screen, re-check the live snapshot:
|
|
628
|
+
* if checkbox glyphs have since appeared, promote any single-select
|
|
629
|
+
* question to multi-select and re-emit status. Promotion is one-way
|
|
630
|
+
* (false→true only) — once a question is known multi-select we never demote
|
|
631
|
+
* it, since the glyph column can scroll out of view on later frames.
|
|
632
|
+
*/
|
|
633
|
+
private maybeUpgradeClaudeTuiMultiSelect(): void {
|
|
634
|
+
if (this.cliType !== 'claude-cli'
|
|
635
|
+
|| this.interactivePromptTransport !== 'tui'
|
|
636
|
+
|| !this.activeInteractivePrompt) return;
|
|
637
|
+
const questions = this.activeInteractivePrompt.questions;
|
|
638
|
+
// The live snapshot only shows the CURRENTLY focused question's rows, so
|
|
639
|
+
// we can only attribute the glyphs to a specific question when there is
|
|
640
|
+
// exactly one. Multi-question prompts are tab-captured per page at
|
|
641
|
+
// capture time and aren't re-evaluated here to avoid cross-contaminating
|
|
642
|
+
// a mixed single/multi prompt.
|
|
643
|
+
if (questions.length !== 1) return;
|
|
644
|
+
if (questions[0].multiSelect) return;
|
|
645
|
+
let screenText = '';
|
|
646
|
+
try {
|
|
647
|
+
screenText = this.driver.snapshot();
|
|
648
|
+
} catch {
|
|
649
|
+
return;
|
|
650
|
+
}
|
|
651
|
+
if (!screenText.includes('Enter to select')) return;
|
|
652
|
+
if (!detectClaudeTuiMultiSelect(screenText)) return;
|
|
653
|
+
questions[0].multiSelect = true;
|
|
654
|
+
this.statusCallback?.();
|
|
655
|
+
}
|
|
656
|
+
|
|
617
657
|
private readClaudeTuiHeaders(screenText: string): string[] {
|
|
618
658
|
const navLine = screenText.split(/\r?\n/).find(line => line.includes('✔ Submit') && /[☐☒]/.test(line));
|
|
619
659
|
if (!navLine) return [];
|
|
@@ -180,7 +180,7 @@ function isClaudeTuiSelectFooter(text: string): boolean {
|
|
|
180
180
|
* broadened footer patterns ("Space to", "toggle", "select multiple") are kept
|
|
181
181
|
* as a secondary signal for layouts that render markers differently.
|
|
182
182
|
*/
|
|
183
|
-
function detectClaudeTuiMultiSelect(screenText: string): boolean {
|
|
183
|
+
export function detectClaudeTuiMultiSelect(screenText: string): boolean {
|
|
184
184
|
if (/Space to (?:select|toggle)|toggle selection|select multiple|select all that apply/i.test(screenText)) {
|
|
185
185
|
return true;
|
|
186
186
|
}
|