@adhdev/daemon-core 0.9.82-rc.167 → 0.9.82-rc.169

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
@@ -9940,6 +9940,10 @@ var init_schema_gen = __esm({
9940
9940
  "type": "integer",
9941
9941
  "minimum": 1,
9942
9942
  "default": 2
9943
+ },
9944
+ "continuation_lines": {
9945
+ "type": "boolean",
9946
+ "default": false
9943
9947
  }
9944
9948
  }
9945
9949
  }
@@ -19825,6 +19829,11 @@ function pickApprovalButton(buttons, provider) {
19825
19829
  }
19826
19830
  return { index: -1, label: "" };
19827
19831
  }
19832
+ function pickAutoApprovalButton(buttons) {
19833
+ const labels = (buttons || []).map((button) => String(button || "").trim());
19834
+ const index = labels.findIndex(Boolean);
19835
+ return index >= 0 ? { index, label: labels[index] } : { index: -1, label: "" };
19836
+ }
19828
19837
  function formatAutoApprovalMessage(modalMessage, buttonLabel) {
19829
19838
  const lines = [`Auto-approved${buttonLabel ? `: ${buttonLabel}` : ""}`];
19830
19839
  const cleanMessage = String(modalMessage || "").trim();
@@ -20399,7 +20408,7 @@ ${effect.notification.body || ""}`.trim();
20399
20408
  }
20400
20409
  this.autoApproveBusy = true;
20401
20410
  try {
20402
- const { label: targetButton } = pickApprovalButton(_chatData?.activeModal?.buttons, this.provider);
20411
+ const { label: targetButton } = pickAutoApprovalButton(_chatData?.activeModal?.buttons);
20403
20412
  const script = scriptFn({ action: "approve", button: targetButton, buttonText: targetButton });
20404
20413
  if (!script) return;
20405
20414
  const now = Date.now();
@@ -26865,6 +26874,10 @@ function compilePattern(ref) {
26865
26874
  const flags = ref.flags ?? "gm";
26866
26875
  return new RegExp(ref.pattern, flags.includes("g") ? flags : flags + "g");
26867
26876
  }
26877
+ function compileLinePattern(ref) {
26878
+ const flags = (ref.flags ?? "m").replace(/g/g, "");
26879
+ return new RegExp(ref.pattern, flags);
26880
+ }
26868
26881
  function matchState(state, sections, fullScreen, trace) {
26869
26882
  const haystack = sectionText(sections, state.when.section, fullScreen);
26870
26883
  const re = compileRegex(state.when);
@@ -26885,16 +26898,41 @@ function matchState(state, sections, fullScreen, trace) {
26885
26898
  function extractModal(state, sections, fullScreen, title, trace) {
26886
26899
  if (!state.modal_buttons) return null;
26887
26900
  const hay = sectionText(sections, state.modal_buttons.section, fullScreen);
26888
- const re = compilePattern(state.modal_buttons);
26889
26901
  const buttons = [];
26890
- let m;
26891
- while ((m = re.exec(hay)) !== null) {
26892
- const idx = Number(m[1]);
26893
- const label = String(m[2] ?? "").trim();
26894
- if (!Number.isFinite(idx) || idx <= 0 || !label) continue;
26895
- if (buttons.some((b) => b.index === idx)) continue;
26896
- const key = state.modal_buttons.key_for_index.replace(/\{index\}/g, String(idx));
26897
- buttons.push({ index: idx, label, key });
26902
+ if (state.modal_buttons.continuation_lines) {
26903
+ const re = compileLinePattern(state.modal_buttons);
26904
+ const lines = hay.split("\n");
26905
+ for (let i = 0; i < lines.length; i += 1) {
26906
+ const m = re.exec(lines[i]);
26907
+ if (!m) continue;
26908
+ const idx = Number(m[1]);
26909
+ let label = String(m[2] ?? "").trim();
26910
+ if (!Number.isFinite(idx) || idx <= 0 || !label) continue;
26911
+ let j = i + 1;
26912
+ while (j < lines.length) {
26913
+ const next = lines[j];
26914
+ if (!next.trim()) break;
26915
+ if (re.test(next)) break;
26916
+ if (!/^\s+/.test(next)) break;
26917
+ label += " " + next.trim();
26918
+ j += 1;
26919
+ }
26920
+ if (buttons.some((b) => b.index === idx)) continue;
26921
+ const key = state.modal_buttons.key_for_index.replace(/\{index\}/g, String(idx));
26922
+ buttons.push({ index: idx, label, key });
26923
+ i = j - 1;
26924
+ }
26925
+ } else {
26926
+ const re = compilePattern(state.modal_buttons);
26927
+ let m;
26928
+ while ((m = re.exec(hay)) !== null) {
26929
+ const idx = Number(m[1]);
26930
+ const label = String(m[2] ?? "").trim();
26931
+ if (!Number.isFinite(idx) || idx <= 0 || !label) continue;
26932
+ if (buttons.some((b) => b.index === idx)) continue;
26933
+ const key = state.modal_buttons.key_for_index.replace(/\{index\}/g, String(idx));
26934
+ buttons.push({ index: idx, label, key });
26935
+ }
26898
26936
  }
26899
26937
  buttons.sort((a, b) => a.index - b.index);
26900
26938
  const minCount = state.modal_buttons.min_count ?? 2;
@@ -28402,7 +28440,7 @@ var CliProviderInstance = class {
28402
28440
  if (!modal || buttons.length === 0) {
28403
28441
  return autoApproveActive;
28404
28442
  }
28405
- const { index: buttonIndex, label: buttonLabel } = pickApprovalButton(buttons, this.provider);
28443
+ const { index: buttonIndex, label: buttonLabel } = pickAutoApprovalButton(buttons);
28406
28444
  if (buttonIndex < 0) {
28407
28445
  return autoApproveActive;
28408
28446
  }
@@ -39085,9 +39123,9 @@ var DaemonCommandRouter = class {
39085
39123
  });
39086
39124
  let node;
39087
39125
  if (meshRecord.inline) {
39088
- const { randomUUID: randomUUID10 } = await import("crypto");
39126
+ const { randomUUID: randomUUID11 } = await import("crypto");
39089
39127
  node = {
39090
- id: `node_${randomUUID10().replace(/-/g, "")}`,
39128
+ id: `node_${randomUUID11().replace(/-/g, "")}`,
39091
39129
  workspace: result.worktreePath,
39092
39130
  repoRoot: result.worktreePath,
39093
39131
  daemonId: sourceNode.daemonId,
@@ -41323,8 +41361,7 @@ var AgentStreamPoller = class {
41323
41361
  if (stream?.status === "waiting_approval") {
41324
41362
  const autoApprove = providerLoader.getSettings(stream.agentType).autoApprove !== false;
41325
41363
  if (autoApprove && resolvedActiveSessionId) {
41326
- const provider = providerLoader.getMeta(stream.agentType);
41327
- const { label: buttonLabel } = pickApprovalButton(stream.activeModal?.buttons, provider);
41364
+ const { label: buttonLabel } = pickAutoApprovalButton(stream.activeModal?.buttons);
41328
41365
  const approved = await agentStreamManager.resolveSessionAction(cdp, resolvedActiveSessionId, "approve", buttonLabel);
41329
41366
  if (approved) {
41330
41367
  const effectId = [
@@ -47443,6 +47480,203 @@ var SessionHostPtyTransportFactory = class {
47443
47480
  }
47444
47481
  };
47445
47482
 
47483
+ // src/cli-adapters/raw-terminal-io.ts
47484
+ import { randomUUID as randomUUID10 } from "crypto";
47485
+ import {
47486
+ SessionHostClient as SessionHostClient2
47487
+ } from "@adhdev/session-host-core";
47488
+ var BASE_KEY_SEQUENCES = {
47489
+ enter: "\r",
47490
+ escape: "\x1B",
47491
+ tab: " ",
47492
+ backspace: "\x7F",
47493
+ up: "\x1B[A",
47494
+ down: "\x1B[B",
47495
+ right: "\x1B[C",
47496
+ left: "\x1B[D",
47497
+ home: "\x1B[H",
47498
+ end: "\x1B[F",
47499
+ pageup: "\x1B[5~",
47500
+ pagedown: "\x1B[6~",
47501
+ space: " ",
47502
+ f1: "\x1BOP",
47503
+ f2: "\x1BOQ",
47504
+ f3: "\x1BOR",
47505
+ f4: "\x1BOS",
47506
+ f5: "\x1B[15~",
47507
+ f6: "\x1B[17~",
47508
+ f7: "\x1B[18~",
47509
+ f8: "\x1B[19~",
47510
+ f9: "\x1B[20~",
47511
+ f10: "\x1B[21~",
47512
+ f11: "\x1B[23~",
47513
+ f12: "\x1B[24~"
47514
+ };
47515
+ var SHIFTED_CSI_KEYS = {
47516
+ up: "\x1B[1;2A",
47517
+ down: "\x1B[1;2B",
47518
+ right: "\x1B[1;2C",
47519
+ left: "\x1B[1;2D",
47520
+ home: "\x1B[1;2H",
47521
+ end: "\x1B[1;2F",
47522
+ pageup: "\x1B[5;2~",
47523
+ pagedown: "\x1B[6;2~",
47524
+ f1: "\x1B[1;2P",
47525
+ f2: "\x1B[1;2Q",
47526
+ f3: "\x1B[1;2R",
47527
+ f4: "\x1B[1;2S",
47528
+ f5: "\x1B[15;2~",
47529
+ f6: "\x1B[17;2~",
47530
+ f7: "\x1B[18;2~",
47531
+ f8: "\x1B[19;2~",
47532
+ f9: "\x1B[20;2~",
47533
+ f10: "\x1B[21;2~",
47534
+ f11: "\x1B[23;2~",
47535
+ f12: "\x1B[24;2~"
47536
+ };
47537
+ function isLowercaseLetter(value) {
47538
+ return /^[a-z]$/.test(value);
47539
+ }
47540
+ function encodeControlLetter(letter) {
47541
+ return String.fromCharCode(letter.charCodeAt(0) - 96);
47542
+ }
47543
+ function encodeShiftedKey(key) {
47544
+ if (isLowercaseLetter(key)) return key.toUpperCase();
47545
+ if (key.startsWith("ctrl+") && isLowercaseLetter(key.slice(5))) {
47546
+ return encodeControlLetter(key.slice(5));
47547
+ }
47548
+ if (key.startsWith("alt+") && isLowercaseLetter(key.slice(4))) {
47549
+ return `\x1B${key.slice(4).toUpperCase()}`;
47550
+ }
47551
+ if (key === "tab") return "\x1B[Z";
47552
+ if (key in SHIFTED_CSI_KEYS) return SHIFTED_CSI_KEYS[key];
47553
+ if (key in BASE_KEY_SEQUENCES) return BASE_KEY_SEQUENCES[key];
47554
+ throw new Error(`Unsupported named key: shift+${key}`);
47555
+ }
47556
+ function namedKeyToAnsi(key) {
47557
+ const normalized = String(key || "").trim().toLowerCase();
47558
+ if (normalized in BASE_KEY_SEQUENCES) return BASE_KEY_SEQUENCES[normalized];
47559
+ if (normalized.startsWith("ctrl+") && isLowercaseLetter(normalized.slice(5))) {
47560
+ return encodeControlLetter(normalized.slice(5));
47561
+ }
47562
+ if (normalized.startsWith("alt+") && isLowercaseLetter(normalized.slice(4))) {
47563
+ return `\x1B${normalized.slice(4)}`;
47564
+ }
47565
+ if (normalized.startsWith("shift+")) return encodeShiftedKey(normalized.slice(6));
47566
+ throw new Error(`Unsupported named key: ${key}`);
47567
+ }
47568
+ function namedKeysToAnsi(keys) {
47569
+ if (!Array.isArray(keys)) throw new Error("keys must be an array");
47570
+ return keys.map(namedKeyToAnsi).join("");
47571
+ }
47572
+ var RawTerminalAttachment = class _RawTerminalAttachment {
47573
+ constructor(sessionId, clientId, mode, client) {
47574
+ this.sessionId = sessionId;
47575
+ this.clientId = clientId;
47576
+ this.mode = mode;
47577
+ this.client = client;
47578
+ }
47579
+ closed = false;
47580
+ static async attach(options) {
47581
+ const sessionId = String(options.sessionId || "").trim();
47582
+ if (!sessionId) throw new Error("sessionId is required");
47583
+ const mode = options.mode || "read";
47584
+ const clientId = options.clientId || `raw-terminal-${process.pid}-${randomUUID10().slice(0, 8)}`;
47585
+ const client = options.client || new SessionHostClient2({ endpoint: options.endpoint });
47586
+ await client.connect();
47587
+ const attachResponse = await client.request({
47588
+ type: "attach_session",
47589
+ payload: {
47590
+ sessionId,
47591
+ clientId,
47592
+ clientType: "web",
47593
+ readOnly: mode === "read"
47594
+ }
47595
+ });
47596
+ if (!attachResponse.success) {
47597
+ await client.close().catch(() => {
47598
+ });
47599
+ throw new Error(attachResponse.error || `Failed to attach terminal session ${sessionId}`);
47600
+ }
47601
+ if (mode === "write") {
47602
+ const ownerResponse = await client.request({
47603
+ type: "acquire_write",
47604
+ payload: {
47605
+ sessionId,
47606
+ clientId,
47607
+ ownerType: "user",
47608
+ force: true
47609
+ }
47610
+ });
47611
+ if (!ownerResponse.success) {
47612
+ await client.request({
47613
+ type: "detach_session",
47614
+ payload: { sessionId, clientId }
47615
+ }).catch(() => ({ success: false }));
47616
+ await client.close().catch(() => {
47617
+ });
47618
+ throw new Error(ownerResponse.error || `Failed to acquire terminal session ${sessionId}`);
47619
+ }
47620
+ }
47621
+ return new _RawTerminalAttachment(sessionId, clientId, mode, client);
47622
+ }
47623
+ async readSnapshot() {
47624
+ const response = await this.client.request({
47625
+ type: "get_terminal_snapshot",
47626
+ payload: { sessionId: this.sessionId }
47627
+ });
47628
+ if (!response.success || !response.result) {
47629
+ throw new Error(response.error || `Terminal screen unavailable for ${this.sessionId}`);
47630
+ }
47631
+ return response.result;
47632
+ }
47633
+ async readScreenText() {
47634
+ return (await this.readSnapshot()).text;
47635
+ }
47636
+ async readState() {
47637
+ return (await this.readSnapshot()).state;
47638
+ }
47639
+ async writeInput(text) {
47640
+ if (this.mode !== "write") throw new Error("Raw terminal attachment is read-only");
47641
+ const response = await this.client.request({
47642
+ type: "send_input",
47643
+ payload: {
47644
+ sessionId: this.sessionId,
47645
+ clientId: this.clientId,
47646
+ data: text
47647
+ }
47648
+ });
47649
+ if (!response.success) throw new Error(response.error || `Failed to write terminal input to ${this.sessionId}`);
47650
+ }
47651
+ async writeKeys(keys) {
47652
+ await this.writeInput(namedKeysToAnsi(keys));
47653
+ }
47654
+ async close() {
47655
+ if (this.closed) return;
47656
+ this.closed = true;
47657
+ if (this.mode === "write") {
47658
+ await this.client.request({
47659
+ type: "release_write",
47660
+ payload: { sessionId: this.sessionId, clientId: this.clientId }
47661
+ }).catch(() => ({ success: false }));
47662
+ }
47663
+ await this.client.request({
47664
+ type: "detach_session",
47665
+ payload: { sessionId: this.sessionId, clientId: this.clientId }
47666
+ }).catch(() => ({ success: false }));
47667
+ await this.client.close().catch(() => {
47668
+ });
47669
+ }
47670
+ };
47671
+ async function withRawTerminalAttachment(options, operation) {
47672
+ const attachment = await RawTerminalAttachment.attach(options);
47673
+ try {
47674
+ return await operation(attachment);
47675
+ } finally {
47676
+ await attachment.close();
47677
+ }
47678
+ }
47679
+
47446
47680
  // src/session-host/app-name.ts
47447
47681
  var DEFAULT_SESSION_HOST_APP_NAME = "adhdev";
47448
47682
  var DEFAULT_STANDALONE_SESSION_HOST_APP_NAME = "adhdev-standalone";
@@ -47476,7 +47710,7 @@ function resolveSessionHostAppName(options = {}) {
47476
47710
 
47477
47711
  // src/session-host/runtime-support.ts
47478
47712
  import {
47479
- SessionHostClient as SessionHostClient2,
47713
+ SessionHostClient as SessionHostClient3,
47480
47714
  getDefaultSessionHostEndpoint
47481
47715
  } from "@adhdev/session-host-core";
47482
47716
  var STARTUP_TIMEOUT_MS = DEFAULT_SESSION_HOST_READY_TIMEOUT_MS;
@@ -47506,7 +47740,7 @@ async function assertRequiredRequestTypes(client, requiredRequestTypes) {
47506
47740
  }
47507
47741
  }
47508
47742
  async function canConnect(endpoint, requiredRequestTypes = []) {
47509
- const client = new SessionHostClient2({ endpoint });
47743
+ const client = new SessionHostClient3({ endpoint });
47510
47744
  try {
47511
47745
  await client.connect();
47512
47746
  await assertRequiredRequestTypes(client, requiredRequestTypes);
@@ -47536,7 +47770,7 @@ async function ensureSessionHostReady(options) {
47536
47770
  return endpoint;
47537
47771
  }
47538
47772
  async function listHostedCliRuntimes(endpoint) {
47539
- const client = new SessionHostClient2({ endpoint });
47773
+ const client = new SessionHostClient3({ endpoint });
47540
47774
  try {
47541
47775
  const response = await client.request({
47542
47776
  type: "list_sessions",
@@ -48410,6 +48644,7 @@ export {
48410
48644
  ProviderCliAdapter,
48411
48645
  ProviderInstanceManager,
48412
48646
  ProviderLoader,
48647
+ RawTerminalAttachment,
48413
48648
  STANDALONE_CDP_SCAN_INTERVAL_MS,
48414
48649
  SessionHostPtyTransportFactory,
48415
48650
  SpecDriver,
@@ -48560,6 +48795,8 @@ export {
48560
48795
  markSetupComplete,
48561
48796
  markStaleDirectDispatches,
48562
48797
  maybeRunDaemonUpgradeHelperFromEnv,
48798
+ namedKeyToAnsi,
48799
+ namedKeysToAnsi,
48563
48800
  normalizeActiveChatData,
48564
48801
  normalizeChatMessage,
48565
48802
  normalizeChatMessageKind,
@@ -48640,6 +48877,7 @@ export {
48640
48877
  validateCliProviderManifest,
48641
48878
  validateMeshRefineConfig,
48642
48879
  validateMeshTaskModeRequest,
48643
- validateMeshWorktreeBootstrapConfig
48880
+ validateMeshWorktreeBootstrapConfig,
48881
+ withRawTerminalAttachment
48644
48882
  };
48645
48883
  //# sourceMappingURL=index.mjs.map