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

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
@@ -39085,9 +39085,9 @@ var DaemonCommandRouter = class {
39085
39085
  });
39086
39086
  let node;
39087
39087
  if (meshRecord.inline) {
39088
- const { randomUUID: randomUUID10 } = await import("crypto");
39088
+ const { randomUUID: randomUUID11 } = await import("crypto");
39089
39089
  node = {
39090
- id: `node_${randomUUID10().replace(/-/g, "")}`,
39090
+ id: `node_${randomUUID11().replace(/-/g, "")}`,
39091
39091
  workspace: result.worktreePath,
39092
39092
  repoRoot: result.worktreePath,
39093
39093
  daemonId: sourceNode.daemonId,
@@ -47443,6 +47443,203 @@ var SessionHostPtyTransportFactory = class {
47443
47443
  }
47444
47444
  };
47445
47445
 
47446
+ // src/cli-adapters/raw-terminal-io.ts
47447
+ import { randomUUID as randomUUID10 } from "crypto";
47448
+ import {
47449
+ SessionHostClient as SessionHostClient2
47450
+ } from "@adhdev/session-host-core";
47451
+ var BASE_KEY_SEQUENCES = {
47452
+ enter: "\r",
47453
+ escape: "\x1B",
47454
+ tab: " ",
47455
+ backspace: "\x7F",
47456
+ up: "\x1B[A",
47457
+ down: "\x1B[B",
47458
+ right: "\x1B[C",
47459
+ left: "\x1B[D",
47460
+ home: "\x1B[H",
47461
+ end: "\x1B[F",
47462
+ pageup: "\x1B[5~",
47463
+ pagedown: "\x1B[6~",
47464
+ space: " ",
47465
+ f1: "\x1BOP",
47466
+ f2: "\x1BOQ",
47467
+ f3: "\x1BOR",
47468
+ f4: "\x1BOS",
47469
+ f5: "\x1B[15~",
47470
+ f6: "\x1B[17~",
47471
+ f7: "\x1B[18~",
47472
+ f8: "\x1B[19~",
47473
+ f9: "\x1B[20~",
47474
+ f10: "\x1B[21~",
47475
+ f11: "\x1B[23~",
47476
+ f12: "\x1B[24~"
47477
+ };
47478
+ var SHIFTED_CSI_KEYS = {
47479
+ up: "\x1B[1;2A",
47480
+ down: "\x1B[1;2B",
47481
+ right: "\x1B[1;2C",
47482
+ left: "\x1B[1;2D",
47483
+ home: "\x1B[1;2H",
47484
+ end: "\x1B[1;2F",
47485
+ pageup: "\x1B[5;2~",
47486
+ pagedown: "\x1B[6;2~",
47487
+ f1: "\x1B[1;2P",
47488
+ f2: "\x1B[1;2Q",
47489
+ f3: "\x1B[1;2R",
47490
+ f4: "\x1B[1;2S",
47491
+ f5: "\x1B[15;2~",
47492
+ f6: "\x1B[17;2~",
47493
+ f7: "\x1B[18;2~",
47494
+ f8: "\x1B[19;2~",
47495
+ f9: "\x1B[20;2~",
47496
+ f10: "\x1B[21;2~",
47497
+ f11: "\x1B[23;2~",
47498
+ f12: "\x1B[24;2~"
47499
+ };
47500
+ function isLowercaseLetter(value) {
47501
+ return /^[a-z]$/.test(value);
47502
+ }
47503
+ function encodeControlLetter(letter) {
47504
+ return String.fromCharCode(letter.charCodeAt(0) - 96);
47505
+ }
47506
+ function encodeShiftedKey(key) {
47507
+ if (isLowercaseLetter(key)) return key.toUpperCase();
47508
+ if (key.startsWith("ctrl+") && isLowercaseLetter(key.slice(5))) {
47509
+ return encodeControlLetter(key.slice(5));
47510
+ }
47511
+ if (key.startsWith("alt+") && isLowercaseLetter(key.slice(4))) {
47512
+ return `\x1B${key.slice(4).toUpperCase()}`;
47513
+ }
47514
+ if (key === "tab") return "\x1B[Z";
47515
+ if (key in SHIFTED_CSI_KEYS) return SHIFTED_CSI_KEYS[key];
47516
+ if (key in BASE_KEY_SEQUENCES) return BASE_KEY_SEQUENCES[key];
47517
+ throw new Error(`Unsupported named key: shift+${key}`);
47518
+ }
47519
+ function namedKeyToAnsi(key) {
47520
+ const normalized = String(key || "").trim().toLowerCase();
47521
+ if (normalized in BASE_KEY_SEQUENCES) return BASE_KEY_SEQUENCES[normalized];
47522
+ if (normalized.startsWith("ctrl+") && isLowercaseLetter(normalized.slice(5))) {
47523
+ return encodeControlLetter(normalized.slice(5));
47524
+ }
47525
+ if (normalized.startsWith("alt+") && isLowercaseLetter(normalized.slice(4))) {
47526
+ return `\x1B${normalized.slice(4)}`;
47527
+ }
47528
+ if (normalized.startsWith("shift+")) return encodeShiftedKey(normalized.slice(6));
47529
+ throw new Error(`Unsupported named key: ${key}`);
47530
+ }
47531
+ function namedKeysToAnsi(keys) {
47532
+ if (!Array.isArray(keys)) throw new Error("keys must be an array");
47533
+ return keys.map(namedKeyToAnsi).join("");
47534
+ }
47535
+ var RawTerminalAttachment = class _RawTerminalAttachment {
47536
+ constructor(sessionId, clientId, mode, client) {
47537
+ this.sessionId = sessionId;
47538
+ this.clientId = clientId;
47539
+ this.mode = mode;
47540
+ this.client = client;
47541
+ }
47542
+ closed = false;
47543
+ static async attach(options) {
47544
+ const sessionId = String(options.sessionId || "").trim();
47545
+ if (!sessionId) throw new Error("sessionId is required");
47546
+ const mode = options.mode || "read";
47547
+ const clientId = options.clientId || `raw-terminal-${process.pid}-${randomUUID10().slice(0, 8)}`;
47548
+ const client = options.client || new SessionHostClient2({ endpoint: options.endpoint });
47549
+ await client.connect();
47550
+ const attachResponse = await client.request({
47551
+ type: "attach_session",
47552
+ payload: {
47553
+ sessionId,
47554
+ clientId,
47555
+ clientType: "web",
47556
+ readOnly: mode === "read"
47557
+ }
47558
+ });
47559
+ if (!attachResponse.success) {
47560
+ await client.close().catch(() => {
47561
+ });
47562
+ throw new Error(attachResponse.error || `Failed to attach terminal session ${sessionId}`);
47563
+ }
47564
+ if (mode === "write") {
47565
+ const ownerResponse = await client.request({
47566
+ type: "acquire_write",
47567
+ payload: {
47568
+ sessionId,
47569
+ clientId,
47570
+ ownerType: "user",
47571
+ force: true
47572
+ }
47573
+ });
47574
+ if (!ownerResponse.success) {
47575
+ await client.request({
47576
+ type: "detach_session",
47577
+ payload: { sessionId, clientId }
47578
+ }).catch(() => ({ success: false }));
47579
+ await client.close().catch(() => {
47580
+ });
47581
+ throw new Error(ownerResponse.error || `Failed to acquire terminal session ${sessionId}`);
47582
+ }
47583
+ }
47584
+ return new _RawTerminalAttachment(sessionId, clientId, mode, client);
47585
+ }
47586
+ async readSnapshot() {
47587
+ const response = await this.client.request({
47588
+ type: "get_terminal_snapshot",
47589
+ payload: { sessionId: this.sessionId }
47590
+ });
47591
+ if (!response.success || !response.result) {
47592
+ throw new Error(response.error || `Terminal screen unavailable for ${this.sessionId}`);
47593
+ }
47594
+ return response.result;
47595
+ }
47596
+ async readScreenText() {
47597
+ return (await this.readSnapshot()).text;
47598
+ }
47599
+ async readState() {
47600
+ return (await this.readSnapshot()).state;
47601
+ }
47602
+ async writeInput(text) {
47603
+ if (this.mode !== "write") throw new Error("Raw terminal attachment is read-only");
47604
+ const response = await this.client.request({
47605
+ type: "send_input",
47606
+ payload: {
47607
+ sessionId: this.sessionId,
47608
+ clientId: this.clientId,
47609
+ data: text
47610
+ }
47611
+ });
47612
+ if (!response.success) throw new Error(response.error || `Failed to write terminal input to ${this.sessionId}`);
47613
+ }
47614
+ async writeKeys(keys) {
47615
+ await this.writeInput(namedKeysToAnsi(keys));
47616
+ }
47617
+ async close() {
47618
+ if (this.closed) return;
47619
+ this.closed = true;
47620
+ if (this.mode === "write") {
47621
+ await this.client.request({
47622
+ type: "release_write",
47623
+ payload: { sessionId: this.sessionId, clientId: this.clientId }
47624
+ }).catch(() => ({ success: false }));
47625
+ }
47626
+ await this.client.request({
47627
+ type: "detach_session",
47628
+ payload: { sessionId: this.sessionId, clientId: this.clientId }
47629
+ }).catch(() => ({ success: false }));
47630
+ await this.client.close().catch(() => {
47631
+ });
47632
+ }
47633
+ };
47634
+ async function withRawTerminalAttachment(options, operation) {
47635
+ const attachment = await RawTerminalAttachment.attach(options);
47636
+ try {
47637
+ return await operation(attachment);
47638
+ } finally {
47639
+ await attachment.close();
47640
+ }
47641
+ }
47642
+
47446
47643
  // src/session-host/app-name.ts
47447
47644
  var DEFAULT_SESSION_HOST_APP_NAME = "adhdev";
47448
47645
  var DEFAULT_STANDALONE_SESSION_HOST_APP_NAME = "adhdev-standalone";
@@ -47476,7 +47673,7 @@ function resolveSessionHostAppName(options = {}) {
47476
47673
 
47477
47674
  // src/session-host/runtime-support.ts
47478
47675
  import {
47479
- SessionHostClient as SessionHostClient2,
47676
+ SessionHostClient as SessionHostClient3,
47480
47677
  getDefaultSessionHostEndpoint
47481
47678
  } from "@adhdev/session-host-core";
47482
47679
  var STARTUP_TIMEOUT_MS = DEFAULT_SESSION_HOST_READY_TIMEOUT_MS;
@@ -47506,7 +47703,7 @@ async function assertRequiredRequestTypes(client, requiredRequestTypes) {
47506
47703
  }
47507
47704
  }
47508
47705
  async function canConnect(endpoint, requiredRequestTypes = []) {
47509
- const client = new SessionHostClient2({ endpoint });
47706
+ const client = new SessionHostClient3({ endpoint });
47510
47707
  try {
47511
47708
  await client.connect();
47512
47709
  await assertRequiredRequestTypes(client, requiredRequestTypes);
@@ -47536,7 +47733,7 @@ async function ensureSessionHostReady(options) {
47536
47733
  return endpoint;
47537
47734
  }
47538
47735
  async function listHostedCliRuntimes(endpoint) {
47539
- const client = new SessionHostClient2({ endpoint });
47736
+ const client = new SessionHostClient3({ endpoint });
47540
47737
  try {
47541
47738
  const response = await client.request({
47542
47739
  type: "list_sessions",
@@ -48410,6 +48607,7 @@ export {
48410
48607
  ProviderCliAdapter,
48411
48608
  ProviderInstanceManager,
48412
48609
  ProviderLoader,
48610
+ RawTerminalAttachment,
48413
48611
  STANDALONE_CDP_SCAN_INTERVAL_MS,
48414
48612
  SessionHostPtyTransportFactory,
48415
48613
  SpecDriver,
@@ -48560,6 +48758,8 @@ export {
48560
48758
  markSetupComplete,
48561
48759
  markStaleDirectDispatches,
48562
48760
  maybeRunDaemonUpgradeHelperFromEnv,
48761
+ namedKeyToAnsi,
48762
+ namedKeysToAnsi,
48563
48763
  normalizeActiveChatData,
48564
48764
  normalizeChatMessage,
48565
48765
  normalizeChatMessageKind,
@@ -48640,6 +48840,7 @@ export {
48640
48840
  validateCliProviderManifest,
48641
48841
  validateMeshRefineConfig,
48642
48842
  validateMeshTaskModeRequest,
48643
- validateMeshWorktreeBootstrapConfig
48843
+ validateMeshWorktreeBootstrapConfig,
48844
+ withRawTerminalAttachment
48644
48845
  };
48645
48846
  //# sourceMappingURL=index.mjs.map