@adhdev/daemon-core 0.9.76-rc.66 → 0.9.76-rc.67

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.mjs CHANGED
@@ -1341,13 +1341,25 @@ import * as os9 from "os";
1341
1341
  import * as path14 from "path";
1342
1342
  import { execSync as execSync3 } from "child_process";
1343
1343
  function stripAnsi(str) {
1344
- return str.replace(/\x1B\][^\x07]*\x07/g, "").replace(/\x1B\][\s\S]*?\x1B\\/g, "").replace(/\x1B[P^_X][\s\S]*?(?:\x07|\x1B\\)/g, "").replace(/\x1B\[\d*[A-HJKSTfG]/g, " ").replace(/\x1B(?:[@-Z\\-_]|\[[0-?]*[ -/]*[@-~])/g, "").replace(/ +/g, " ");
1344
+ return str.replace(/\x1B\][^\x07]*(?:\x07|\x1B\\)/g, "").replace(/\x1B[P^_X][\s\S]*?(?:\x07|\x1B\\)/g, "").replace(/\x1B(?:[@-Z\\-_]|\[[0-?]*[ -/]*[@-~])/g, "");
1345
+ }
1346
+ function parseCount(params, fallback = 1) {
1347
+ const first = Number(String(params || "").split(";")[0] || fallback);
1348
+ return Math.max(1, Number.isFinite(first) ? first : fallback);
1349
+ }
1350
+ function isCombiningMark(ch) {
1351
+ return /[\u0300-\u036F\u1AB0-\u1AFF\u1DC0-\u1DFF\u20D0-\u20FF\uFE20-\uFE2F]/.test(ch);
1352
+ }
1353
+ function isWideCodePoint(ch) {
1354
+ const cp = ch.codePointAt(0) || 0;
1355
+ return cp >= 4352 && (cp <= 4447 || cp === 9001 || cp === 9002 || cp >= 11904 && cp <= 42191 && cp !== 12351 || cp >= 44032 && cp <= 55203 || cp >= 63744 && cp <= 64255 || cp >= 65040 && cp <= 65049 || cp >= 65072 && cp <= 65135 || cp >= 65280 && cp <= 65376 || cp >= 65504 && cp <= 65510 || cp >= 127744 && cp <= 129791);
1345
1356
  }
1346
1357
  function stripTerminalNoise(str) {
1347
- return String(str || "").replace(/[\x00-\x08\x0B\x0C\x0E-\x1F\x7F-\x9F]/g, "").replace(/(^|[\s([])(?:\??\d{1,4}(?:;\d{1,4})*[A-Za-z])(?=$|[\s)\]])/g, "$1").replace(/(^|[\s([])(?:\[\??\d{1,4}(?:;\d{1,4})*[A-Za-z])(?=$|[\s)\]])/g, "$1").replace(/(^|[\s([])(?:\d{1,4};\?)(?=$|[\s)\]])/g, "$1").replace(/(^|[\s([])(?:\d+\$r[0-9;\" ]*[A-Za-z]?)(?=$|[\s)\]])/g, "$1").replace(/(^|[\s([])(?:>\|[A-Za-z0-9_.:-]+(?:\([^)]*\))?)(?=$|[\s)\]])/g, "$1").replace(/(^|[\s([])(?:[A-Z]\d(?:\s+[A-Z]\d)+)(?=$|[\s)\]])/g, "$1").replace(/(^|[\s([])(?:\d+;[^\s)\]]+)(?=$|[\s)\]])/g, "$1").replace(/\r+/g, "\n").replace(/[ \t]+\n/g, "\n").replace(/\n{3,}/g, "\n\n").replace(/ {2,}/g, " ");
1358
+ return String(str || "").replace(/[\x00-\x08\x0B\x0C\x0E-\x1F\x7F-\x9F]/g, "").replace(/\r+/g, "\n").replace(/[ \t]+\n/g, "\n").replace(/\n{4,}/g, "\n\n\n");
1348
1359
  }
1349
1360
  function sanitizeTerminalText(str) {
1350
- return stripTerminalNoise(stripAnsi(str));
1361
+ const accumulator = new TerminalTranscriptAccumulator();
1362
+ return stripTerminalNoise(stripAnsi(accumulator.append(str)));
1351
1363
  }
1352
1364
  function listCliScriptNames(scripts) {
1353
1365
  if (!scripts) return [];
@@ -1526,11 +1538,160 @@ function normalizeCliProviderForRuntime(raw) {
1526
1538
  }
1527
1539
  };
1528
1540
  }
1529
- var buildCliSpawnEnv;
1541
+ var TerminalTranscriptAccumulator, buildCliSpawnEnv;
1530
1542
  var init_provider_cli_shared = __esm({
1531
1543
  "src/cli-adapters/provider-cli-shared.ts"() {
1532
1544
  "use strict";
1533
1545
  init_spawn_env();
1546
+ TerminalTranscriptAccumulator = class {
1547
+ lines = [[]];
1548
+ row = 0;
1549
+ col = 0;
1550
+ savedCursor = null;
1551
+ pendingEscape = "";
1552
+ append(data) {
1553
+ const input = this.pendingEscape + String(data || "");
1554
+ this.pendingEscape = "";
1555
+ for (let i = 0; i < input.length; i += 1) {
1556
+ let ch = input[i];
1557
+ if (ch === "\x1B") {
1558
+ const consumed = this.consumeEscape(input.slice(i));
1559
+ if (consumed === 0) {
1560
+ this.pendingEscape = input.slice(i);
1561
+ break;
1562
+ }
1563
+ i += consumed - 1;
1564
+ continue;
1565
+ }
1566
+ const cp = input.codePointAt(i);
1567
+ if (cp && cp > 65535) {
1568
+ ch = String.fromCodePoint(cp);
1569
+ i += 1;
1570
+ }
1571
+ this.writeControlOrChar(ch);
1572
+ }
1573
+ return this.getText();
1574
+ }
1575
+ reset() {
1576
+ this.lines = [[]];
1577
+ this.row = 0;
1578
+ this.col = 0;
1579
+ this.savedCursor = null;
1580
+ this.pendingEscape = "";
1581
+ }
1582
+ getText() {
1583
+ return this.lines.map((line) => line.join("").replace(/[ \t]+$/g, "")).join("\n");
1584
+ }
1585
+ ensureRow(row = this.row) {
1586
+ while (this.lines.length <= row) this.lines.push([]);
1587
+ }
1588
+ writeControlOrChar(ch) {
1589
+ if (ch === "\r") {
1590
+ this.col = 0;
1591
+ return;
1592
+ }
1593
+ if (ch === "\n") {
1594
+ this.row += 1;
1595
+ this.col = 0;
1596
+ this.ensureRow();
1597
+ return;
1598
+ }
1599
+ if (ch === "\b") {
1600
+ this.col = Math.max(0, this.col - 1);
1601
+ return;
1602
+ }
1603
+ if (ch < " " || ch === "\x7F") return;
1604
+ this.ensureRow();
1605
+ const line = this.lines[this.row];
1606
+ if (isCombiningMark(ch) && this.col > 0) {
1607
+ line[this.col - 1] = `${line[this.col - 1] || ""}${ch}`;
1608
+ return;
1609
+ }
1610
+ while (line.length < this.col) line.push(" ");
1611
+ line[this.col] = ch;
1612
+ this.col += isWideCodePoint(ch) ? 2 : 1;
1613
+ }
1614
+ consumeEscape(seq) {
1615
+ if (seq.length < 2) return 0;
1616
+ const next = seq[1];
1617
+ if (next === "7") {
1618
+ this.savedCursor = { row: this.row, col: this.col };
1619
+ return 2;
1620
+ }
1621
+ if (next === "8") {
1622
+ if (this.savedCursor) {
1623
+ this.row = this.savedCursor.row;
1624
+ this.col = this.savedCursor.col;
1625
+ this.ensureRow();
1626
+ }
1627
+ return 2;
1628
+ }
1629
+ if (next === "]") {
1630
+ const bel = seq.indexOf("\x07", 2);
1631
+ const st = seq.indexOf("\x1B\\", 2);
1632
+ const end = bel >= 0 && (st < 0 || bel < st) ? bel + 1 : st >= 0 ? st + 2 : 0;
1633
+ return end;
1634
+ }
1635
+ if (next === "[") {
1636
+ const match = seq.match(/^\x1B\[([0-?]*)([ -/]*)([@-~])/);
1637
+ if (!match) return seq.length < 32 ? 0 : 1;
1638
+ this.applyCsi(match[1] || "", match[3]);
1639
+ return match[0].length;
1640
+ }
1641
+ if (/[P^_X]/.test(next)) {
1642
+ const bel = seq.indexOf("\x07", 2);
1643
+ const st = seq.indexOf("\x1B\\", 2);
1644
+ const end = bel >= 0 && (st < 0 || bel < st) ? bel + 1 : st >= 0 ? st + 2 : 0;
1645
+ return end;
1646
+ }
1647
+ return 2;
1648
+ }
1649
+ applyCsi(params, final) {
1650
+ const count = parseCount(params);
1651
+ this.ensureRow();
1652
+ if (final === "A") this.row = Math.max(0, this.row - count);
1653
+ else if (final === "B") this.row += count;
1654
+ else if (final === "C") this.col += count;
1655
+ else if (final === "D") this.col = Math.max(0, this.col - count);
1656
+ else if (final === "G") this.col = Math.max(0, count - 1);
1657
+ else if (final === "H" || final === "f") {
1658
+ const parts = String(params || "").split(";");
1659
+ this.row = Math.max(0, (Number(parts[0] || 1) || 1) - 1);
1660
+ this.col = Math.max(0, (Number(parts[1] || 1) || 1) - 1);
1661
+ } else if (final === "J") {
1662
+ const mode = Number(params || 0) || 0;
1663
+ if (mode === 2 || mode === 3) {
1664
+ this.lines = [[]];
1665
+ this.row = 0;
1666
+ this.col = 0;
1667
+ } else if (mode === 0) {
1668
+ this.lines[this.row] = this.lines[this.row].slice(0, this.col);
1669
+ this.lines.splice(this.row + 1);
1670
+ } else if (mode === 1) {
1671
+ for (let r = 0; r < this.row; r += 1) this.lines[r] = [];
1672
+ const line = this.lines[this.row];
1673
+ for (let c = 0; c <= Math.min(this.col, line.length - 1); c += 1) line[c] = " ";
1674
+ }
1675
+ } else if (final === "K") {
1676
+ const mode = Number(params || 0) || 0;
1677
+ const line = this.lines[this.row];
1678
+ if (mode === 2) this.lines[this.row] = [];
1679
+ else if (mode === 1) {
1680
+ for (let c = 0; c <= Math.min(this.col, line.length - 1); c += 1) line[c] = " ";
1681
+ } else {
1682
+ this.lines[this.row] = line.slice(0, this.col);
1683
+ }
1684
+ } else if (final === "s") {
1685
+ this.savedCursor = { row: this.row, col: this.col };
1686
+ } else if (final === "u") {
1687
+ if (this.savedCursor) {
1688
+ this.row = this.savedCursor.row;
1689
+ this.col = this.savedCursor.col;
1690
+ }
1691
+ }
1692
+ this.ensureRow();
1693
+ }
1694
+ };
1534
1695
  buildCliSpawnEnv = sanitizeSpawnEnv;
1535
1696
  }
1536
1697
  });
@@ -1877,8 +2038,10 @@ var init_provider_cli_adapter = __esm({
1877
2038
  // ─── CLI Scripts (script-based parsing) ───
1878
2039
  cliScripts;
1879
2040
  runtimeSettings = {};
1880
- /** Full accumulated ANSI-stripped PTY output */
2041
+ /** Full accumulated rendered PTY transcript for parser/readback use */
1881
2042
  accumulatedBuffer = "";
2043
+ /** Stateful rendered transcript accumulator; raw debug remains in accumulatedRawBuffer. */
2044
+ transcriptAccumulator = new TerminalTranscriptAccumulator();
1882
2045
  /** Full accumulated raw PTY output (with ANSI) */
1883
2046
  accumulatedRawBuffer = "";
1884
2047
  /** Current visible terminal screen snapshot */
@@ -1944,6 +2107,7 @@ ${lastSnapshot}`;
1944
2107
  }
1945
2108
  resetTerminalScreen(rows, cols) {
1946
2109
  this.terminalScreen.reset(rows, cols);
2110
+ this.transcriptAccumulator.reset();
1947
2111
  this.lastScreenText = "";
1948
2112
  this.lastScreenSnapshot = "";
1949
2113
  this.lastScreenChangeAt = 0;
@@ -2202,6 +2366,7 @@ ${lastSnapshot}`;
2202
2366
  handleOutput(rawData) {
2203
2367
  this.terminalScreen.write(rawData);
2204
2368
  const cleanData = sanitizeTerminalText(rawData);
2369
+ const renderedTranscript = this.transcriptAccumulator.append(rawData);
2205
2370
  const now = Date.now();
2206
2371
  const shouldReadScreen = this.shouldReadTerminalScreenSnapshot(now);
2207
2372
  const screenText = shouldReadScreen ? this.readTerminalScreenText(now) : this.lastScreenText;
@@ -2242,13 +2407,14 @@ ${lastSnapshot}`;
2242
2407
  }
2243
2408
  }
2244
2409
  const prevRecentLen = this.recentOutputBuffer.length;
2245
- const prevAccumulatedLen = this.accumulatedBuffer.length;
2246
2410
  const prevAccumulatedRawLen = this.accumulatedRawBuffer.length;
2247
- this.recentOutputBuffer = appendBoundedText(this.recentOutputBuffer, cleanData, _ProviderCliAdapter.MAX_RECENT_OUTPUT_BUFFER);
2248
- this.accumulatedBuffer = appendBoundedText(this.accumulatedBuffer, cleanData, _ProviderCliAdapter.MAX_ACCUMULATED_BUFFER);
2411
+ const nextAccumulatedBuffer = renderedTranscript.length <= _ProviderCliAdapter.MAX_ACCUMULATED_BUFFER ? renderedTranscript : renderedTranscript.slice(-_ProviderCliAdapter.MAX_ACCUMULATED_BUFFER);
2412
+ const nextRecentOutputBuffer = nextAccumulatedBuffer.slice(-_ProviderCliAdapter.MAX_RECENT_OUTPUT_BUFFER);
2413
+ this.recentOutputBuffer = nextRecentOutputBuffer;
2414
+ this.accumulatedBuffer = nextAccumulatedBuffer;
2249
2415
  this.accumulatedRawBuffer = appendBoundedText(this.accumulatedRawBuffer, rawData, _ProviderCliAdapter.MAX_ACCUMULATED_BUFFER);
2250
- const droppedRecent = this.recordBoundedAppendDrop(prevRecentLen, cleanData.length, this.recentOutputBuffer.length);
2251
- const droppedClean = this.recordBoundedAppendDrop(prevAccumulatedLen, cleanData.length, this.accumulatedBuffer.length);
2416
+ const droppedRecent = Math.max(0, prevRecentLen - this.recentOutputBuffer.length);
2417
+ const droppedClean = Math.max(0, renderedTranscript.length - this.accumulatedBuffer.length);
2252
2418
  const droppedRaw = this.recordBoundedAppendDrop(prevAccumulatedRawLen, rawData.length, this.accumulatedRawBuffer.length);
2253
2419
  this.recentOutputDroppedChars += droppedRecent;
2254
2420
  this.accumulatedBufferDroppedChars += droppedClean;
@@ -20996,6 +21162,15 @@ init_logger();
20996
21162
  function readNonEmptyString(value) {
20997
21163
  return typeof value === "string" && value.trim() ? value.trim() : "";
20998
21164
  }
21165
+ var MESH_COORDINATOR_EVENTS = /* @__PURE__ */ new Set([
21166
+ "agent:generating_completed",
21167
+ "agent:waiting_approval",
21168
+ "agent:stopped",
21169
+ "monitor:long_generating"
21170
+ ]);
21171
+ function isMeshCoordinatorEvent(eventName) {
21172
+ return typeof eventName === "string" && MESH_COORDINATOR_EVENTS.has(eventName);
21173
+ }
20999
21174
  function formatCompletionMetadata(event) {
21000
21175
  const parts = [
21001
21176
  readNonEmptyString(event.targetSessionId) ? `session_id=${readNonEmptyString(event.targetSessionId)}` : "",
@@ -21012,6 +21187,12 @@ function buildMeshSystemMessage(args) {
21012
21187
  if (args.event === "agent:waiting_approval") {
21013
21188
  return `[System] ${args.nodeLabel} is waiting for approval to proceed${metadata}. You may use mesh_read_chat and mesh_approve to handle it.`;
21014
21189
  }
21190
+ if (args.event === "agent:stopped") {
21191
+ return `[System] ${args.nodeLabel} has stopped${metadata}. Use mesh_read_chat once if you need to inspect its last output.`;
21192
+ }
21193
+ if (args.event === "monitor:long_generating") {
21194
+ return `[System] ${args.nodeLabel} has been generating for a long time${metadata}. Use mesh_read_chat once for a status check, but do not poll repeatedly.`;
21195
+ }
21015
21196
  return "";
21016
21197
  }
21017
21198
  function injectMeshSystemMessage(components, args) {
@@ -21037,7 +21218,7 @@ function injectMeshSystemMessage(components, args) {
21037
21218
  }
21038
21219
  function handleMeshForwardEvent(components, payload) {
21039
21220
  const eventName = readNonEmptyString(payload.event);
21040
- if (eventName !== "agent:generating_completed" && eventName !== "agent:waiting_approval") {
21221
+ if (!isMeshCoordinatorEvent(eventName)) {
21041
21222
  return { success: false, error: "unsupported mesh event" };
21042
21223
  }
21043
21224
  const meshId = readNonEmptyString(payload.meshId);
@@ -21058,7 +21239,7 @@ function handleMeshForwardEvent(components, payload) {
21058
21239
  }
21059
21240
  function setupMeshEventForwarding(components) {
21060
21241
  components.instanceManager.onEvent((event) => {
21061
- if (event.event !== "agent:generating_completed" && event.event !== "agent:waiting_approval") return;
21242
+ if (!isMeshCoordinatorEvent(event.event)) return;
21062
21243
  const instanceId = readNonEmptyString(event.instanceId);
21063
21244
  if (!instanceId) return;
21064
21245
  const sourceInstance = components.instanceManager.getInstance(instanceId);