@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.
@@ -0,0 +1,37 @@
1
+ import { type SessionHostEndpoint, type SessionHostRequest, type SessionHostResponse, type SessionTerminalSnapshot, type SessionTerminalState } from '@adhdev/session-host-core';
2
+ type LowercaseLetter = 'a' | 'b' | 'c' | 'd' | 'e' | 'f' | 'g' | 'h' | 'i' | 'j' | 'k' | 'l' | 'm' | 'n' | 'o' | 'p' | 'q' | 'r' | 's' | 't' | 'u' | 'v' | 'w' | 'x' | 'y' | 'z';
3
+ type FunctionKey = 'f1' | 'f2' | 'f3' | 'f4' | 'f5' | 'f6' | 'f7' | 'f8' | 'f9' | 'f10' | 'f11' | 'f12';
4
+ type BaseNamedKey = 'enter' | 'escape' | 'tab' | 'backspace' | 'up' | 'down' | 'left' | 'right' | 'home' | 'end' | 'pageup' | 'pagedown' | 'space' | FunctionKey;
5
+ type ShiftNamedKey = BaseNamedKey | LowercaseLetter | `ctrl+${LowercaseLetter}` | `alt+${LowercaseLetter}`;
6
+ export type NamedKey = BaseNamedKey | `ctrl+${LowercaseLetter}` | `alt+${LowercaseLetter}` | `shift+${ShiftNamedKey}`;
7
+ export declare function namedKeyToAnsi(key: NamedKey | string): string;
8
+ export declare function namedKeysToAnsi(keys: readonly (NamedKey | string)[]): string;
9
+ export interface RawTerminalSessionHostClient {
10
+ connect(): Promise<void>;
11
+ request<T = unknown>(request: SessionHostRequest): Promise<SessionHostResponse<T>>;
12
+ close(): Promise<void>;
13
+ }
14
+ export interface RawTerminalAttachmentOptions {
15
+ endpoint?: SessionHostEndpoint;
16
+ sessionId: string;
17
+ mode?: 'read' | 'write';
18
+ clientId?: string;
19
+ client?: RawTerminalSessionHostClient;
20
+ }
21
+ export declare class RawTerminalAttachment {
22
+ readonly sessionId: string;
23
+ private readonly clientId;
24
+ private readonly mode;
25
+ private readonly client;
26
+ private closed;
27
+ private constructor();
28
+ static attach(options: RawTerminalAttachmentOptions): Promise<RawTerminalAttachment>;
29
+ readSnapshot(): Promise<SessionTerminalSnapshot>;
30
+ readScreenText(): Promise<string>;
31
+ readState(): Promise<SessionTerminalState>;
32
+ writeInput(text: string): Promise<void>;
33
+ writeKeys(keys: readonly (NamedKey | string)[]): Promise<void>;
34
+ close(): Promise<void>;
35
+ }
36
+ export declare function withRawTerminalAttachment<T>(options: RawTerminalAttachmentOptions, operation: (attachment: RawTerminalAttachment) => Promise<T>): Promise<T>;
37
+ export {};
package/dist/index.d.ts CHANGED
@@ -123,6 +123,8 @@ export type { CliAdapter } from './cli-adapter-types.js';
123
123
  export { NodePtyTransportFactory } from './cli-adapters/pty-transport.js';
124
124
  export type { PtyRuntimeTransport, PtyTransportFactory, PtySpawnOptions } from './cli-adapters/pty-transport.js';
125
125
  export { SessionHostPtyTransportFactory } from './cli-adapters/session-host-transport.js';
126
+ export { RawTerminalAttachment, namedKeyToAnsi, namedKeysToAnsi, withRawTerminalAttachment, } from './cli-adapters/raw-terminal-io.js';
127
+ export type { NamedKey, RawTerminalAttachmentOptions, RawTerminalSessionHostClient } from './cli-adapters/raw-terminal-io.js';
126
128
  export type { HostedCliRuntimeDescriptor, CliTransportFactoryParams } from './commands/cli-manager.js';
127
129
  export { DEFAULT_SESSION_HOST_APP_NAME, DEFAULT_STANDALONE_SESSION_HOST_APP_NAME, resolveSessionHostAppName, resolveSessionHostAppNameResolution, } from './session-host/app-name.js';
128
130
  export type { SessionHostAppNameResolution } from './session-host/app-name.js';
package/dist/index.js CHANGED
@@ -12079,6 +12079,7 @@ __export(index_exports, {
12079
12079
  ProviderCliAdapter: () => ProviderCliAdapter,
12080
12080
  ProviderInstanceManager: () => ProviderInstanceManager,
12081
12081
  ProviderLoader: () => ProviderLoader,
12082
+ RawTerminalAttachment: () => RawTerminalAttachment,
12082
12083
  STANDALONE_CDP_SCAN_INTERVAL_MS: () => STANDALONE_CDP_SCAN_INTERVAL_MS,
12083
12084
  SessionHostPtyTransportFactory: () => SessionHostPtyTransportFactory,
12084
12085
  SpecDriver: () => SpecDriver,
@@ -12229,6 +12230,8 @@ __export(index_exports, {
12229
12230
  markSetupComplete: () => markSetupComplete,
12230
12231
  markStaleDirectDispatches: () => markStaleDirectDispatches,
12231
12232
  maybeRunDaemonUpgradeHelperFromEnv: () => maybeRunDaemonUpgradeHelperFromEnv,
12233
+ namedKeyToAnsi: () => namedKeyToAnsi,
12234
+ namedKeysToAnsi: () => namedKeysToAnsi,
12232
12235
  normalizeActiveChatData: () => normalizeActiveChatData,
12233
12236
  normalizeChatMessage: () => normalizeChatMessage,
12234
12237
  normalizeChatMessageKind: () => normalizeChatMessageKind,
@@ -12309,7 +12312,8 @@ __export(index_exports, {
12309
12312
  validateCliProviderManifest: () => validateCliProviderManifest,
12310
12313
  validateMeshRefineConfig: () => validateMeshRefineConfig,
12311
12314
  validateMeshTaskModeRequest: () => validateMeshTaskModeRequest,
12312
- validateMeshWorktreeBootstrapConfig: () => validateMeshWorktreeBootstrapConfig
12315
+ validateMeshWorktreeBootstrapConfig: () => validateMeshWorktreeBootstrapConfig,
12316
+ withRawTerminalAttachment: () => withRawTerminalAttachment
12313
12317
  });
12314
12318
  module.exports = __toCommonJS(index_exports);
12315
12319
  init_repo_mesh_types();
@@ -39377,9 +39381,9 @@ var DaemonCommandRouter = class {
39377
39381
  });
39378
39382
  let node;
39379
39383
  if (meshRecord.inline) {
39380
- const { randomUUID: randomUUID10 } = await import("crypto");
39384
+ const { randomUUID: randomUUID11 } = await import("crypto");
39381
39385
  node = {
39382
- id: `node_${randomUUID10().replace(/-/g, "")}`,
39386
+ id: `node_${randomUUID11().replace(/-/g, "")}`,
39383
39387
  workspace: result.worktreePath,
39384
39388
  repoRoot: result.worktreePath,
39385
39389
  daemonId: sourceNode.daemonId,
@@ -47733,6 +47737,201 @@ var SessionHostPtyTransportFactory = class {
47733
47737
  }
47734
47738
  };
47735
47739
 
47740
+ // src/cli-adapters/raw-terminal-io.ts
47741
+ var import_crypto6 = require("crypto");
47742
+ var import_session_host_core4 = require("@adhdev/session-host-core");
47743
+ var BASE_KEY_SEQUENCES = {
47744
+ enter: "\r",
47745
+ escape: "\x1B",
47746
+ tab: " ",
47747
+ backspace: "\x7F",
47748
+ up: "\x1B[A",
47749
+ down: "\x1B[B",
47750
+ right: "\x1B[C",
47751
+ left: "\x1B[D",
47752
+ home: "\x1B[H",
47753
+ end: "\x1B[F",
47754
+ pageup: "\x1B[5~",
47755
+ pagedown: "\x1B[6~",
47756
+ space: " ",
47757
+ f1: "\x1BOP",
47758
+ f2: "\x1BOQ",
47759
+ f3: "\x1BOR",
47760
+ f4: "\x1BOS",
47761
+ f5: "\x1B[15~",
47762
+ f6: "\x1B[17~",
47763
+ f7: "\x1B[18~",
47764
+ f8: "\x1B[19~",
47765
+ f9: "\x1B[20~",
47766
+ f10: "\x1B[21~",
47767
+ f11: "\x1B[23~",
47768
+ f12: "\x1B[24~"
47769
+ };
47770
+ var SHIFTED_CSI_KEYS = {
47771
+ up: "\x1B[1;2A",
47772
+ down: "\x1B[1;2B",
47773
+ right: "\x1B[1;2C",
47774
+ left: "\x1B[1;2D",
47775
+ home: "\x1B[1;2H",
47776
+ end: "\x1B[1;2F",
47777
+ pageup: "\x1B[5;2~",
47778
+ pagedown: "\x1B[6;2~",
47779
+ f1: "\x1B[1;2P",
47780
+ f2: "\x1B[1;2Q",
47781
+ f3: "\x1B[1;2R",
47782
+ f4: "\x1B[1;2S",
47783
+ f5: "\x1B[15;2~",
47784
+ f6: "\x1B[17;2~",
47785
+ f7: "\x1B[18;2~",
47786
+ f8: "\x1B[19;2~",
47787
+ f9: "\x1B[20;2~",
47788
+ f10: "\x1B[21;2~",
47789
+ f11: "\x1B[23;2~",
47790
+ f12: "\x1B[24;2~"
47791
+ };
47792
+ function isLowercaseLetter(value) {
47793
+ return /^[a-z]$/.test(value);
47794
+ }
47795
+ function encodeControlLetter(letter) {
47796
+ return String.fromCharCode(letter.charCodeAt(0) - 96);
47797
+ }
47798
+ function encodeShiftedKey(key) {
47799
+ if (isLowercaseLetter(key)) return key.toUpperCase();
47800
+ if (key.startsWith("ctrl+") && isLowercaseLetter(key.slice(5))) {
47801
+ return encodeControlLetter(key.slice(5));
47802
+ }
47803
+ if (key.startsWith("alt+") && isLowercaseLetter(key.slice(4))) {
47804
+ return `\x1B${key.slice(4).toUpperCase()}`;
47805
+ }
47806
+ if (key === "tab") return "\x1B[Z";
47807
+ if (key in SHIFTED_CSI_KEYS) return SHIFTED_CSI_KEYS[key];
47808
+ if (key in BASE_KEY_SEQUENCES) return BASE_KEY_SEQUENCES[key];
47809
+ throw new Error(`Unsupported named key: shift+${key}`);
47810
+ }
47811
+ function namedKeyToAnsi(key) {
47812
+ const normalized = String(key || "").trim().toLowerCase();
47813
+ if (normalized in BASE_KEY_SEQUENCES) return BASE_KEY_SEQUENCES[normalized];
47814
+ if (normalized.startsWith("ctrl+") && isLowercaseLetter(normalized.slice(5))) {
47815
+ return encodeControlLetter(normalized.slice(5));
47816
+ }
47817
+ if (normalized.startsWith("alt+") && isLowercaseLetter(normalized.slice(4))) {
47818
+ return `\x1B${normalized.slice(4)}`;
47819
+ }
47820
+ if (normalized.startsWith("shift+")) return encodeShiftedKey(normalized.slice(6));
47821
+ throw new Error(`Unsupported named key: ${key}`);
47822
+ }
47823
+ function namedKeysToAnsi(keys) {
47824
+ if (!Array.isArray(keys)) throw new Error("keys must be an array");
47825
+ return keys.map(namedKeyToAnsi).join("");
47826
+ }
47827
+ var RawTerminalAttachment = class _RawTerminalAttachment {
47828
+ constructor(sessionId, clientId, mode, client) {
47829
+ this.sessionId = sessionId;
47830
+ this.clientId = clientId;
47831
+ this.mode = mode;
47832
+ this.client = client;
47833
+ }
47834
+ closed = false;
47835
+ static async attach(options) {
47836
+ const sessionId = String(options.sessionId || "").trim();
47837
+ if (!sessionId) throw new Error("sessionId is required");
47838
+ const mode = options.mode || "read";
47839
+ const clientId = options.clientId || `raw-terminal-${process.pid}-${(0, import_crypto6.randomUUID)().slice(0, 8)}`;
47840
+ const client = options.client || new import_session_host_core4.SessionHostClient({ endpoint: options.endpoint });
47841
+ await client.connect();
47842
+ const attachResponse = await client.request({
47843
+ type: "attach_session",
47844
+ payload: {
47845
+ sessionId,
47846
+ clientId,
47847
+ clientType: "web",
47848
+ readOnly: mode === "read"
47849
+ }
47850
+ });
47851
+ if (!attachResponse.success) {
47852
+ await client.close().catch(() => {
47853
+ });
47854
+ throw new Error(attachResponse.error || `Failed to attach terminal session ${sessionId}`);
47855
+ }
47856
+ if (mode === "write") {
47857
+ const ownerResponse = await client.request({
47858
+ type: "acquire_write",
47859
+ payload: {
47860
+ sessionId,
47861
+ clientId,
47862
+ ownerType: "user",
47863
+ force: true
47864
+ }
47865
+ });
47866
+ if (!ownerResponse.success) {
47867
+ await client.request({
47868
+ type: "detach_session",
47869
+ payload: { sessionId, clientId }
47870
+ }).catch(() => ({ success: false }));
47871
+ await client.close().catch(() => {
47872
+ });
47873
+ throw new Error(ownerResponse.error || `Failed to acquire terminal session ${sessionId}`);
47874
+ }
47875
+ }
47876
+ return new _RawTerminalAttachment(sessionId, clientId, mode, client);
47877
+ }
47878
+ async readSnapshot() {
47879
+ const response = await this.client.request({
47880
+ type: "get_terminal_snapshot",
47881
+ payload: { sessionId: this.sessionId }
47882
+ });
47883
+ if (!response.success || !response.result) {
47884
+ throw new Error(response.error || `Terminal screen unavailable for ${this.sessionId}`);
47885
+ }
47886
+ return response.result;
47887
+ }
47888
+ async readScreenText() {
47889
+ return (await this.readSnapshot()).text;
47890
+ }
47891
+ async readState() {
47892
+ return (await this.readSnapshot()).state;
47893
+ }
47894
+ async writeInput(text) {
47895
+ if (this.mode !== "write") throw new Error("Raw terminal attachment is read-only");
47896
+ const response = await this.client.request({
47897
+ type: "send_input",
47898
+ payload: {
47899
+ sessionId: this.sessionId,
47900
+ clientId: this.clientId,
47901
+ data: text
47902
+ }
47903
+ });
47904
+ if (!response.success) throw new Error(response.error || `Failed to write terminal input to ${this.sessionId}`);
47905
+ }
47906
+ async writeKeys(keys) {
47907
+ await this.writeInput(namedKeysToAnsi(keys));
47908
+ }
47909
+ async close() {
47910
+ if (this.closed) return;
47911
+ this.closed = true;
47912
+ if (this.mode === "write") {
47913
+ await this.client.request({
47914
+ type: "release_write",
47915
+ payload: { sessionId: this.sessionId, clientId: this.clientId }
47916
+ }).catch(() => ({ success: false }));
47917
+ }
47918
+ await this.client.request({
47919
+ type: "detach_session",
47920
+ payload: { sessionId: this.sessionId, clientId: this.clientId }
47921
+ }).catch(() => ({ success: false }));
47922
+ await this.client.close().catch(() => {
47923
+ });
47924
+ }
47925
+ };
47926
+ async function withRawTerminalAttachment(options, operation) {
47927
+ const attachment = await RawTerminalAttachment.attach(options);
47928
+ try {
47929
+ return await operation(attachment);
47930
+ } finally {
47931
+ await attachment.close();
47932
+ }
47933
+ }
47934
+
47736
47935
  // src/session-host/app-name.ts
47737
47936
  var DEFAULT_SESSION_HOST_APP_NAME = "adhdev";
47738
47937
  var DEFAULT_STANDALONE_SESSION_HOST_APP_NAME = "adhdev-standalone";
@@ -47765,7 +47964,7 @@ function resolveSessionHostAppName(options = {}) {
47765
47964
  }
47766
47965
 
47767
47966
  // src/session-host/runtime-support.ts
47768
- var import_session_host_core4 = require("@adhdev/session-host-core");
47967
+ var import_session_host_core5 = require("@adhdev/session-host-core");
47769
47968
  var STARTUP_TIMEOUT_MS = DEFAULT_SESSION_HOST_READY_TIMEOUT_MS;
47770
47969
  var STARTUP_POLL_MS = 200;
47771
47970
  var SessionHostCompatibilityError = class extends Error {
@@ -47793,7 +47992,7 @@ async function assertRequiredRequestTypes(client, requiredRequestTypes) {
47793
47992
  }
47794
47993
  }
47795
47994
  async function canConnect(endpoint, requiredRequestTypes = []) {
47796
- const client = new import_session_host_core4.SessionHostClient({ endpoint });
47995
+ const client = new import_session_host_core5.SessionHostClient({ endpoint });
47797
47996
  try {
47798
47997
  await client.connect();
47799
47998
  await assertRequiredRequestTypes(client, requiredRequestTypes);
@@ -47815,7 +48014,7 @@ async function waitForReady(endpoint, timeoutMs = STARTUP_TIMEOUT_MS, requiredRe
47815
48014
  throw new Error(`Session host did not become ready within ${timeoutMs}ms`);
47816
48015
  }
47817
48016
  async function ensureSessionHostReady(options) {
47818
- const endpoint = (0, import_session_host_core4.getDefaultSessionHostEndpoint)(options.appName || "adhdev");
48017
+ const endpoint = (0, import_session_host_core5.getDefaultSessionHostEndpoint)(options.appName || "adhdev");
47819
48018
  const requiredRequestTypes = options.requiredRequestTypes || [];
47820
48019
  if (await canConnect(endpoint, requiredRequestTypes)) return endpoint;
47821
48020
  options.spawnHost();
@@ -47823,7 +48022,7 @@ async function ensureSessionHostReady(options) {
47823
48022
  return endpoint;
47824
48023
  }
47825
48024
  async function listHostedCliRuntimes(endpoint) {
47826
- const client = new import_session_host_core4.SessionHostClient({ endpoint });
48025
+ const client = new import_session_host_core5.SessionHostClient({ endpoint });
47827
48026
  try {
47828
48027
  const response = await client.request({
47829
48028
  type: "list_sessions",
@@ -48698,6 +48897,7 @@ var V1_CONTRACT_VERSION = "1.0.0";
48698
48897
  ProviderCliAdapter,
48699
48898
  ProviderInstanceManager,
48700
48899
  ProviderLoader,
48900
+ RawTerminalAttachment,
48701
48901
  STANDALONE_CDP_SCAN_INTERVAL_MS,
48702
48902
  SessionHostPtyTransportFactory,
48703
48903
  SpecDriver,
@@ -48848,6 +49048,8 @@ var V1_CONTRACT_VERSION = "1.0.0";
48848
49048
  markSetupComplete,
48849
49049
  markStaleDirectDispatches,
48850
49050
  maybeRunDaemonUpgradeHelperFromEnv,
49051
+ namedKeyToAnsi,
49052
+ namedKeysToAnsi,
48851
49053
  normalizeActiveChatData,
48852
49054
  normalizeChatMessage,
48853
49055
  normalizeChatMessageKind,
@@ -48928,6 +49130,7 @@ var V1_CONTRACT_VERSION = "1.0.0";
48928
49130
  validateCliProviderManifest,
48929
49131
  validateMeshRefineConfig,
48930
49132
  validateMeshTaskModeRequest,
48931
- validateMeshWorktreeBootstrapConfig
49133
+ validateMeshWorktreeBootstrapConfig,
49134
+ withRawTerminalAttachment
48932
49135
  });
48933
49136
  //# sourceMappingURL=index.js.map