@adhdev/daemon-core 0.9.76-rc.65 → 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
@@ -37,6 +37,7 @@ var init_repo_mesh_types = __esm({
37
37
  requireApprovalForDestructiveGit: true,
38
38
  dirtyWorkspaceBehavior: "warn",
39
39
  maxParallelTasks: 2,
40
+ spawnedSessionVisibility: "visible",
40
41
  sessionCleanupOnNodeRemove: "preserve"
41
42
  };
42
43
  }
@@ -469,6 +470,9 @@ function mergeMeshPolicy(base, patch) {
469
470
  if (!SESSION_CLEANUP_MODES.has(String(policy.sessionCleanupOnNodeRemove))) {
470
471
  policy.sessionCleanupOnNodeRemove = "preserve";
471
472
  }
473
+ if (!SPAWNED_SESSION_VISIBILITY_MODES.has(String(policy.spawnedSessionVisibility))) {
474
+ policy.spawnedSessionVisibility = "visible";
475
+ }
472
476
  return policy;
473
477
  }
474
478
  function listMeshes() {
@@ -573,13 +577,14 @@ function updateNode(meshId, nodeId, opts) {
573
577
  saveMeshConfig(config);
574
578
  return node;
575
579
  }
576
- var SESSION_CLEANUP_MODES;
580
+ var SESSION_CLEANUP_MODES, SPAWNED_SESSION_VISIBILITY_MODES;
577
581
  var init_mesh_config = __esm({
578
582
  "src/config/mesh-config.ts"() {
579
583
  "use strict";
580
584
  init_config();
581
585
  init_repo_mesh_types();
582
586
  SESSION_CLEANUP_MODES = /* @__PURE__ */ new Set(["preserve", "stop", "delete_stopped", "stop_and_delete"]);
587
+ SPAWNED_SESSION_VISIBILITY_MODES = /* @__PURE__ */ new Set(["visible", "hidden"]);
583
588
  }
584
589
  });
585
590
 
@@ -1336,13 +1341,25 @@ import * as os9 from "os";
1336
1341
  import * as path14 from "path";
1337
1342
  import { execSync as execSync3 } from "child_process";
1338
1343
  function stripAnsi(str) {
1339
- 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);
1340
1356
  }
1341
1357
  function stripTerminalNoise(str) {
1342
- 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");
1343
1359
  }
1344
1360
  function sanitizeTerminalText(str) {
1345
- return stripTerminalNoise(stripAnsi(str));
1361
+ const accumulator = new TerminalTranscriptAccumulator();
1362
+ return stripTerminalNoise(stripAnsi(accumulator.append(str)));
1346
1363
  }
1347
1364
  function listCliScriptNames(scripts) {
1348
1365
  if (!scripts) return [];
@@ -1521,11 +1538,160 @@ function normalizeCliProviderForRuntime(raw) {
1521
1538
  }
1522
1539
  };
1523
1540
  }
1524
- var buildCliSpawnEnv;
1541
+ var TerminalTranscriptAccumulator, buildCliSpawnEnv;
1525
1542
  var init_provider_cli_shared = __esm({
1526
1543
  "src/cli-adapters/provider-cli-shared.ts"() {
1527
1544
  "use strict";
1528
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
+ };
1529
1695
  buildCliSpawnEnv = sanitizeSpawnEnv;
1530
1696
  }
1531
1697
  });
@@ -1872,8 +2038,10 @@ var init_provider_cli_adapter = __esm({
1872
2038
  // ─── CLI Scripts (script-based parsing) ───
1873
2039
  cliScripts;
1874
2040
  runtimeSettings = {};
1875
- /** Full accumulated ANSI-stripped PTY output */
2041
+ /** Full accumulated rendered PTY transcript for parser/readback use */
1876
2042
  accumulatedBuffer = "";
2043
+ /** Stateful rendered transcript accumulator; raw debug remains in accumulatedRawBuffer. */
2044
+ transcriptAccumulator = new TerminalTranscriptAccumulator();
1877
2045
  /** Full accumulated raw PTY output (with ANSI) */
1878
2046
  accumulatedRawBuffer = "";
1879
2047
  /** Current visible terminal screen snapshot */
@@ -1939,6 +2107,7 @@ ${lastSnapshot}`;
1939
2107
  }
1940
2108
  resetTerminalScreen(rows, cols) {
1941
2109
  this.terminalScreen.reset(rows, cols);
2110
+ this.transcriptAccumulator.reset();
1942
2111
  this.lastScreenText = "";
1943
2112
  this.lastScreenSnapshot = "";
1944
2113
  this.lastScreenChangeAt = 0;
@@ -2197,6 +2366,7 @@ ${lastSnapshot}`;
2197
2366
  handleOutput(rawData) {
2198
2367
  this.terminalScreen.write(rawData);
2199
2368
  const cleanData = sanitizeTerminalText(rawData);
2369
+ const renderedTranscript = this.transcriptAccumulator.append(rawData);
2200
2370
  const now = Date.now();
2201
2371
  const shouldReadScreen = this.shouldReadTerminalScreenSnapshot(now);
2202
2372
  const screenText = shouldReadScreen ? this.readTerminalScreenText(now) : this.lastScreenText;
@@ -2237,13 +2407,14 @@ ${lastSnapshot}`;
2237
2407
  }
2238
2408
  }
2239
2409
  const prevRecentLen = this.recentOutputBuffer.length;
2240
- const prevAccumulatedLen = this.accumulatedBuffer.length;
2241
2410
  const prevAccumulatedRawLen = this.accumulatedRawBuffer.length;
2242
- this.recentOutputBuffer = appendBoundedText(this.recentOutputBuffer, cleanData, _ProviderCliAdapter.MAX_RECENT_OUTPUT_BUFFER);
2243
- 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;
2244
2415
  this.accumulatedRawBuffer = appendBoundedText(this.accumulatedRawBuffer, rawData, _ProviderCliAdapter.MAX_ACCUMULATED_BUFFER);
2245
- const droppedRecent = this.recordBoundedAppendDrop(prevRecentLen, cleanData.length, this.recentOutputBuffer.length);
2246
- 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);
2247
2418
  const droppedRaw = this.recordBoundedAppendDrop(prevAccumulatedRawLen, rawData.length, this.accumulatedRawBuffer.length);
2248
2419
  this.recentOutputDroppedChars += droppedRecent;
2249
2420
  this.accumulatedBufferDroppedChars += droppedClean;
@@ -20991,6 +21162,15 @@ init_logger();
20991
21162
  function readNonEmptyString(value) {
20992
21163
  return typeof value === "string" && value.trim() ? value.trim() : "";
20993
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
+ }
20994
21174
  function formatCompletionMetadata(event) {
20995
21175
  const parts = [
20996
21176
  readNonEmptyString(event.targetSessionId) ? `session_id=${readNonEmptyString(event.targetSessionId)}` : "",
@@ -21007,6 +21187,12 @@ function buildMeshSystemMessage(args) {
21007
21187
  if (args.event === "agent:waiting_approval") {
21008
21188
  return `[System] ${args.nodeLabel} is waiting for approval to proceed${metadata}. You may use mesh_read_chat and mesh_approve to handle it.`;
21009
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
+ }
21010
21196
  return "";
21011
21197
  }
21012
21198
  function injectMeshSystemMessage(components, args) {
@@ -21032,7 +21218,7 @@ function injectMeshSystemMessage(components, args) {
21032
21218
  }
21033
21219
  function handleMeshForwardEvent(components, payload) {
21034
21220
  const eventName = readNonEmptyString(payload.event);
21035
- if (eventName !== "agent:generating_completed" && eventName !== "agent:waiting_approval") {
21221
+ if (!isMeshCoordinatorEvent(eventName)) {
21036
21222
  return { success: false, error: "unsupported mesh event" };
21037
21223
  }
21038
21224
  const meshId = readNonEmptyString(payload.meshId);
@@ -21053,7 +21239,7 @@ function handleMeshForwardEvent(components, payload) {
21053
21239
  }
21054
21240
  function setupMeshEventForwarding(components) {
21055
21241
  components.instanceManager.onEvent((event) => {
21056
- if (event.event !== "agent:generating_completed" && event.event !== "agent:waiting_approval") return;
21242
+ if (!isMeshCoordinatorEvent(event.event)) return;
21057
21243
  const instanceId = readNonEmptyString(event.instanceId);
21058
21244
  if (!instanceId) return;
21059
21245
  const sourceInstance = components.instanceManager.getInstance(instanceId);