@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/cli-adapters/raw-terminal-io.d.ts +37 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js +261 -21
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +257 -19
- package/dist/index.mjs.map +1 -1
- package/dist/providers/approval-utils.d.ts +4 -0
- package/dist/providers/spec/schema.gen.d.ts +4 -0
- package/dist/providers/spec/types.d.ts +1 -0
- package/package.json +1 -1
- package/src/agent-stream/poller.ts +2 -3
- package/src/cli-adapters/raw-terminal-io.ts +252 -0
- package/src/index.ts +7 -0
- package/src/providers/approval-utils.d.ts +4 -0
- package/src/providers/approval-utils.ts +8 -0
- package/src/providers/cli-provider-instance.ts +3 -3
- package/src/providers/ide-provider-instance.ts +2 -2
- package/src/providers/spec/evaluator.ts +39 -9
- package/src/providers/spec/schema.gen.ts +4 -0
- package/src/providers/spec/schema.json +2 -1
- package/src/providers/spec/types.ts +1 -0
|
@@ -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
|
@@ -9945,6 +9945,10 @@ var init_schema_gen = __esm({
|
|
|
9945
9945
|
"type": "integer",
|
|
9946
9946
|
"minimum": 1,
|
|
9947
9947
|
"default": 2
|
|
9948
|
+
},
|
|
9949
|
+
"continuation_lines": {
|
|
9950
|
+
"type": "boolean",
|
|
9951
|
+
"default": false
|
|
9948
9952
|
}
|
|
9949
9953
|
}
|
|
9950
9954
|
}
|
|
@@ -12079,6 +12083,7 @@ __export(index_exports, {
|
|
|
12079
12083
|
ProviderCliAdapter: () => ProviderCliAdapter,
|
|
12080
12084
|
ProviderInstanceManager: () => ProviderInstanceManager,
|
|
12081
12085
|
ProviderLoader: () => ProviderLoader,
|
|
12086
|
+
RawTerminalAttachment: () => RawTerminalAttachment,
|
|
12082
12087
|
STANDALONE_CDP_SCAN_INTERVAL_MS: () => STANDALONE_CDP_SCAN_INTERVAL_MS,
|
|
12083
12088
|
SessionHostPtyTransportFactory: () => SessionHostPtyTransportFactory,
|
|
12084
12089
|
SpecDriver: () => SpecDriver,
|
|
@@ -12229,6 +12234,8 @@ __export(index_exports, {
|
|
|
12229
12234
|
markSetupComplete: () => markSetupComplete,
|
|
12230
12235
|
markStaleDirectDispatches: () => markStaleDirectDispatches,
|
|
12231
12236
|
maybeRunDaemonUpgradeHelperFromEnv: () => maybeRunDaemonUpgradeHelperFromEnv,
|
|
12237
|
+
namedKeyToAnsi: () => namedKeyToAnsi,
|
|
12238
|
+
namedKeysToAnsi: () => namedKeysToAnsi,
|
|
12232
12239
|
normalizeActiveChatData: () => normalizeActiveChatData,
|
|
12233
12240
|
normalizeChatMessage: () => normalizeChatMessage,
|
|
12234
12241
|
normalizeChatMessageKind: () => normalizeChatMessageKind,
|
|
@@ -12309,7 +12316,8 @@ __export(index_exports, {
|
|
|
12309
12316
|
validateCliProviderManifest: () => validateCliProviderManifest,
|
|
12310
12317
|
validateMeshRefineConfig: () => validateMeshRefineConfig,
|
|
12311
12318
|
validateMeshTaskModeRequest: () => validateMeshTaskModeRequest,
|
|
12312
|
-
validateMeshWorktreeBootstrapConfig: () => validateMeshWorktreeBootstrapConfig
|
|
12319
|
+
validateMeshWorktreeBootstrapConfig: () => validateMeshWorktreeBootstrapConfig,
|
|
12320
|
+
withRawTerminalAttachment: () => withRawTerminalAttachment
|
|
12313
12321
|
});
|
|
12314
12322
|
module.exports = __toCommonJS(index_exports);
|
|
12315
12323
|
init_repo_mesh_types();
|
|
@@ -20122,6 +20130,11 @@ function pickApprovalButton(buttons, provider) {
|
|
|
20122
20130
|
}
|
|
20123
20131
|
return { index: -1, label: "" };
|
|
20124
20132
|
}
|
|
20133
|
+
function pickAutoApprovalButton(buttons) {
|
|
20134
|
+
const labels = (buttons || []).map((button) => String(button || "").trim());
|
|
20135
|
+
const index = labels.findIndex(Boolean);
|
|
20136
|
+
return index >= 0 ? { index, label: labels[index] } : { index: -1, label: "" };
|
|
20137
|
+
}
|
|
20125
20138
|
function formatAutoApprovalMessage(modalMessage, buttonLabel) {
|
|
20126
20139
|
const lines = [`Auto-approved${buttonLabel ? `: ${buttonLabel}` : ""}`];
|
|
20127
20140
|
const cleanMessage = String(modalMessage || "").trim();
|
|
@@ -20696,7 +20709,7 @@ ${effect.notification.body || ""}`.trim();
|
|
|
20696
20709
|
}
|
|
20697
20710
|
this.autoApproveBusy = true;
|
|
20698
20711
|
try {
|
|
20699
|
-
const { label: targetButton } =
|
|
20712
|
+
const { label: targetButton } = pickAutoApprovalButton(_chatData?.activeModal?.buttons);
|
|
20700
20713
|
const script = scriptFn({ action: "approve", button: targetButton, buttonText: targetButton });
|
|
20701
20714
|
if (!script) return;
|
|
20702
20715
|
const now = Date.now();
|
|
@@ -27162,6 +27175,10 @@ function compilePattern(ref) {
|
|
|
27162
27175
|
const flags = ref.flags ?? "gm";
|
|
27163
27176
|
return new RegExp(ref.pattern, flags.includes("g") ? flags : flags + "g");
|
|
27164
27177
|
}
|
|
27178
|
+
function compileLinePattern(ref) {
|
|
27179
|
+
const flags = (ref.flags ?? "m").replace(/g/g, "");
|
|
27180
|
+
return new RegExp(ref.pattern, flags);
|
|
27181
|
+
}
|
|
27165
27182
|
function matchState(state, sections, fullScreen, trace) {
|
|
27166
27183
|
const haystack = sectionText(sections, state.when.section, fullScreen);
|
|
27167
27184
|
const re = compileRegex(state.when);
|
|
@@ -27182,16 +27199,41 @@ function matchState(state, sections, fullScreen, trace) {
|
|
|
27182
27199
|
function extractModal(state, sections, fullScreen, title, trace) {
|
|
27183
27200
|
if (!state.modal_buttons) return null;
|
|
27184
27201
|
const hay = sectionText(sections, state.modal_buttons.section, fullScreen);
|
|
27185
|
-
const re = compilePattern(state.modal_buttons);
|
|
27186
27202
|
const buttons = [];
|
|
27187
|
-
|
|
27188
|
-
|
|
27189
|
-
const
|
|
27190
|
-
|
|
27191
|
-
|
|
27192
|
-
|
|
27193
|
-
|
|
27194
|
-
|
|
27203
|
+
if (state.modal_buttons.continuation_lines) {
|
|
27204
|
+
const re = compileLinePattern(state.modal_buttons);
|
|
27205
|
+
const lines = hay.split("\n");
|
|
27206
|
+
for (let i = 0; i < lines.length; i += 1) {
|
|
27207
|
+
const m = re.exec(lines[i]);
|
|
27208
|
+
if (!m) continue;
|
|
27209
|
+
const idx = Number(m[1]);
|
|
27210
|
+
let label = String(m[2] ?? "").trim();
|
|
27211
|
+
if (!Number.isFinite(idx) || idx <= 0 || !label) continue;
|
|
27212
|
+
let j = i + 1;
|
|
27213
|
+
while (j < lines.length) {
|
|
27214
|
+
const next = lines[j];
|
|
27215
|
+
if (!next.trim()) break;
|
|
27216
|
+
if (re.test(next)) break;
|
|
27217
|
+
if (!/^\s+/.test(next)) break;
|
|
27218
|
+
label += " " + next.trim();
|
|
27219
|
+
j += 1;
|
|
27220
|
+
}
|
|
27221
|
+
if (buttons.some((b) => b.index === idx)) continue;
|
|
27222
|
+
const key = state.modal_buttons.key_for_index.replace(/\{index\}/g, String(idx));
|
|
27223
|
+
buttons.push({ index: idx, label, key });
|
|
27224
|
+
i = j - 1;
|
|
27225
|
+
}
|
|
27226
|
+
} else {
|
|
27227
|
+
const re = compilePattern(state.modal_buttons);
|
|
27228
|
+
let m;
|
|
27229
|
+
while ((m = re.exec(hay)) !== null) {
|
|
27230
|
+
const idx = Number(m[1]);
|
|
27231
|
+
const label = String(m[2] ?? "").trim();
|
|
27232
|
+
if (!Number.isFinite(idx) || idx <= 0 || !label) continue;
|
|
27233
|
+
if (buttons.some((b) => b.index === idx)) continue;
|
|
27234
|
+
const key = state.modal_buttons.key_for_index.replace(/\{index\}/g, String(idx));
|
|
27235
|
+
buttons.push({ index: idx, label, key });
|
|
27236
|
+
}
|
|
27195
27237
|
}
|
|
27196
27238
|
buttons.sort((a, b) => a.index - b.index);
|
|
27197
27239
|
const minCount = state.modal_buttons.min_count ?? 2;
|
|
@@ -28699,7 +28741,7 @@ var CliProviderInstance = class {
|
|
|
28699
28741
|
if (!modal || buttons.length === 0) {
|
|
28700
28742
|
return autoApproveActive;
|
|
28701
28743
|
}
|
|
28702
|
-
const { index: buttonIndex, label: buttonLabel } =
|
|
28744
|
+
const { index: buttonIndex, label: buttonLabel } = pickAutoApprovalButton(buttons);
|
|
28703
28745
|
if (buttonIndex < 0) {
|
|
28704
28746
|
return autoApproveActive;
|
|
28705
28747
|
}
|
|
@@ -39377,9 +39419,9 @@ var DaemonCommandRouter = class {
|
|
|
39377
39419
|
});
|
|
39378
39420
|
let node;
|
|
39379
39421
|
if (meshRecord.inline) {
|
|
39380
|
-
const { randomUUID:
|
|
39422
|
+
const { randomUUID: randomUUID11 } = await import("crypto");
|
|
39381
39423
|
node = {
|
|
39382
|
-
id: `node_${
|
|
39424
|
+
id: `node_${randomUUID11().replace(/-/g, "")}`,
|
|
39383
39425
|
workspace: result.worktreePath,
|
|
39384
39426
|
repoRoot: result.worktreePath,
|
|
39385
39427
|
daemonId: sourceNode.daemonId,
|
|
@@ -41615,8 +41657,7 @@ var AgentStreamPoller = class {
|
|
|
41615
41657
|
if (stream?.status === "waiting_approval") {
|
|
41616
41658
|
const autoApprove = providerLoader.getSettings(stream.agentType).autoApprove !== false;
|
|
41617
41659
|
if (autoApprove && resolvedActiveSessionId) {
|
|
41618
|
-
const
|
|
41619
|
-
const { label: buttonLabel } = pickApprovalButton(stream.activeModal?.buttons, provider);
|
|
41660
|
+
const { label: buttonLabel } = pickAutoApprovalButton(stream.activeModal?.buttons);
|
|
41620
41661
|
const approved = await agentStreamManager.resolveSessionAction(cdp, resolvedActiveSessionId, "approve", buttonLabel);
|
|
41621
41662
|
if (approved) {
|
|
41622
41663
|
const effectId = [
|
|
@@ -47733,6 +47774,201 @@ var SessionHostPtyTransportFactory = class {
|
|
|
47733
47774
|
}
|
|
47734
47775
|
};
|
|
47735
47776
|
|
|
47777
|
+
// src/cli-adapters/raw-terminal-io.ts
|
|
47778
|
+
var import_crypto6 = require("crypto");
|
|
47779
|
+
var import_session_host_core4 = require("@adhdev/session-host-core");
|
|
47780
|
+
var BASE_KEY_SEQUENCES = {
|
|
47781
|
+
enter: "\r",
|
|
47782
|
+
escape: "\x1B",
|
|
47783
|
+
tab: " ",
|
|
47784
|
+
backspace: "\x7F",
|
|
47785
|
+
up: "\x1B[A",
|
|
47786
|
+
down: "\x1B[B",
|
|
47787
|
+
right: "\x1B[C",
|
|
47788
|
+
left: "\x1B[D",
|
|
47789
|
+
home: "\x1B[H",
|
|
47790
|
+
end: "\x1B[F",
|
|
47791
|
+
pageup: "\x1B[5~",
|
|
47792
|
+
pagedown: "\x1B[6~",
|
|
47793
|
+
space: " ",
|
|
47794
|
+
f1: "\x1BOP",
|
|
47795
|
+
f2: "\x1BOQ",
|
|
47796
|
+
f3: "\x1BOR",
|
|
47797
|
+
f4: "\x1BOS",
|
|
47798
|
+
f5: "\x1B[15~",
|
|
47799
|
+
f6: "\x1B[17~",
|
|
47800
|
+
f7: "\x1B[18~",
|
|
47801
|
+
f8: "\x1B[19~",
|
|
47802
|
+
f9: "\x1B[20~",
|
|
47803
|
+
f10: "\x1B[21~",
|
|
47804
|
+
f11: "\x1B[23~",
|
|
47805
|
+
f12: "\x1B[24~"
|
|
47806
|
+
};
|
|
47807
|
+
var SHIFTED_CSI_KEYS = {
|
|
47808
|
+
up: "\x1B[1;2A",
|
|
47809
|
+
down: "\x1B[1;2B",
|
|
47810
|
+
right: "\x1B[1;2C",
|
|
47811
|
+
left: "\x1B[1;2D",
|
|
47812
|
+
home: "\x1B[1;2H",
|
|
47813
|
+
end: "\x1B[1;2F",
|
|
47814
|
+
pageup: "\x1B[5;2~",
|
|
47815
|
+
pagedown: "\x1B[6;2~",
|
|
47816
|
+
f1: "\x1B[1;2P",
|
|
47817
|
+
f2: "\x1B[1;2Q",
|
|
47818
|
+
f3: "\x1B[1;2R",
|
|
47819
|
+
f4: "\x1B[1;2S",
|
|
47820
|
+
f5: "\x1B[15;2~",
|
|
47821
|
+
f6: "\x1B[17;2~",
|
|
47822
|
+
f7: "\x1B[18;2~",
|
|
47823
|
+
f8: "\x1B[19;2~",
|
|
47824
|
+
f9: "\x1B[20;2~",
|
|
47825
|
+
f10: "\x1B[21;2~",
|
|
47826
|
+
f11: "\x1B[23;2~",
|
|
47827
|
+
f12: "\x1B[24;2~"
|
|
47828
|
+
};
|
|
47829
|
+
function isLowercaseLetter(value) {
|
|
47830
|
+
return /^[a-z]$/.test(value);
|
|
47831
|
+
}
|
|
47832
|
+
function encodeControlLetter(letter) {
|
|
47833
|
+
return String.fromCharCode(letter.charCodeAt(0) - 96);
|
|
47834
|
+
}
|
|
47835
|
+
function encodeShiftedKey(key) {
|
|
47836
|
+
if (isLowercaseLetter(key)) return key.toUpperCase();
|
|
47837
|
+
if (key.startsWith("ctrl+") && isLowercaseLetter(key.slice(5))) {
|
|
47838
|
+
return encodeControlLetter(key.slice(5));
|
|
47839
|
+
}
|
|
47840
|
+
if (key.startsWith("alt+") && isLowercaseLetter(key.slice(4))) {
|
|
47841
|
+
return `\x1B${key.slice(4).toUpperCase()}`;
|
|
47842
|
+
}
|
|
47843
|
+
if (key === "tab") return "\x1B[Z";
|
|
47844
|
+
if (key in SHIFTED_CSI_KEYS) return SHIFTED_CSI_KEYS[key];
|
|
47845
|
+
if (key in BASE_KEY_SEQUENCES) return BASE_KEY_SEQUENCES[key];
|
|
47846
|
+
throw new Error(`Unsupported named key: shift+${key}`);
|
|
47847
|
+
}
|
|
47848
|
+
function namedKeyToAnsi(key) {
|
|
47849
|
+
const normalized = String(key || "").trim().toLowerCase();
|
|
47850
|
+
if (normalized in BASE_KEY_SEQUENCES) return BASE_KEY_SEQUENCES[normalized];
|
|
47851
|
+
if (normalized.startsWith("ctrl+") && isLowercaseLetter(normalized.slice(5))) {
|
|
47852
|
+
return encodeControlLetter(normalized.slice(5));
|
|
47853
|
+
}
|
|
47854
|
+
if (normalized.startsWith("alt+") && isLowercaseLetter(normalized.slice(4))) {
|
|
47855
|
+
return `\x1B${normalized.slice(4)}`;
|
|
47856
|
+
}
|
|
47857
|
+
if (normalized.startsWith("shift+")) return encodeShiftedKey(normalized.slice(6));
|
|
47858
|
+
throw new Error(`Unsupported named key: ${key}`);
|
|
47859
|
+
}
|
|
47860
|
+
function namedKeysToAnsi(keys) {
|
|
47861
|
+
if (!Array.isArray(keys)) throw new Error("keys must be an array");
|
|
47862
|
+
return keys.map(namedKeyToAnsi).join("");
|
|
47863
|
+
}
|
|
47864
|
+
var RawTerminalAttachment = class _RawTerminalAttachment {
|
|
47865
|
+
constructor(sessionId, clientId, mode, client) {
|
|
47866
|
+
this.sessionId = sessionId;
|
|
47867
|
+
this.clientId = clientId;
|
|
47868
|
+
this.mode = mode;
|
|
47869
|
+
this.client = client;
|
|
47870
|
+
}
|
|
47871
|
+
closed = false;
|
|
47872
|
+
static async attach(options) {
|
|
47873
|
+
const sessionId = String(options.sessionId || "").trim();
|
|
47874
|
+
if (!sessionId) throw new Error("sessionId is required");
|
|
47875
|
+
const mode = options.mode || "read";
|
|
47876
|
+
const clientId = options.clientId || `raw-terminal-${process.pid}-${(0, import_crypto6.randomUUID)().slice(0, 8)}`;
|
|
47877
|
+
const client = options.client || new import_session_host_core4.SessionHostClient({ endpoint: options.endpoint });
|
|
47878
|
+
await client.connect();
|
|
47879
|
+
const attachResponse = await client.request({
|
|
47880
|
+
type: "attach_session",
|
|
47881
|
+
payload: {
|
|
47882
|
+
sessionId,
|
|
47883
|
+
clientId,
|
|
47884
|
+
clientType: "web",
|
|
47885
|
+
readOnly: mode === "read"
|
|
47886
|
+
}
|
|
47887
|
+
});
|
|
47888
|
+
if (!attachResponse.success) {
|
|
47889
|
+
await client.close().catch(() => {
|
|
47890
|
+
});
|
|
47891
|
+
throw new Error(attachResponse.error || `Failed to attach terminal session ${sessionId}`);
|
|
47892
|
+
}
|
|
47893
|
+
if (mode === "write") {
|
|
47894
|
+
const ownerResponse = await client.request({
|
|
47895
|
+
type: "acquire_write",
|
|
47896
|
+
payload: {
|
|
47897
|
+
sessionId,
|
|
47898
|
+
clientId,
|
|
47899
|
+
ownerType: "user",
|
|
47900
|
+
force: true
|
|
47901
|
+
}
|
|
47902
|
+
});
|
|
47903
|
+
if (!ownerResponse.success) {
|
|
47904
|
+
await client.request({
|
|
47905
|
+
type: "detach_session",
|
|
47906
|
+
payload: { sessionId, clientId }
|
|
47907
|
+
}).catch(() => ({ success: false }));
|
|
47908
|
+
await client.close().catch(() => {
|
|
47909
|
+
});
|
|
47910
|
+
throw new Error(ownerResponse.error || `Failed to acquire terminal session ${sessionId}`);
|
|
47911
|
+
}
|
|
47912
|
+
}
|
|
47913
|
+
return new _RawTerminalAttachment(sessionId, clientId, mode, client);
|
|
47914
|
+
}
|
|
47915
|
+
async readSnapshot() {
|
|
47916
|
+
const response = await this.client.request({
|
|
47917
|
+
type: "get_terminal_snapshot",
|
|
47918
|
+
payload: { sessionId: this.sessionId }
|
|
47919
|
+
});
|
|
47920
|
+
if (!response.success || !response.result) {
|
|
47921
|
+
throw new Error(response.error || `Terminal screen unavailable for ${this.sessionId}`);
|
|
47922
|
+
}
|
|
47923
|
+
return response.result;
|
|
47924
|
+
}
|
|
47925
|
+
async readScreenText() {
|
|
47926
|
+
return (await this.readSnapshot()).text;
|
|
47927
|
+
}
|
|
47928
|
+
async readState() {
|
|
47929
|
+
return (await this.readSnapshot()).state;
|
|
47930
|
+
}
|
|
47931
|
+
async writeInput(text) {
|
|
47932
|
+
if (this.mode !== "write") throw new Error("Raw terminal attachment is read-only");
|
|
47933
|
+
const response = await this.client.request({
|
|
47934
|
+
type: "send_input",
|
|
47935
|
+
payload: {
|
|
47936
|
+
sessionId: this.sessionId,
|
|
47937
|
+
clientId: this.clientId,
|
|
47938
|
+
data: text
|
|
47939
|
+
}
|
|
47940
|
+
});
|
|
47941
|
+
if (!response.success) throw new Error(response.error || `Failed to write terminal input to ${this.sessionId}`);
|
|
47942
|
+
}
|
|
47943
|
+
async writeKeys(keys) {
|
|
47944
|
+
await this.writeInput(namedKeysToAnsi(keys));
|
|
47945
|
+
}
|
|
47946
|
+
async close() {
|
|
47947
|
+
if (this.closed) return;
|
|
47948
|
+
this.closed = true;
|
|
47949
|
+
if (this.mode === "write") {
|
|
47950
|
+
await this.client.request({
|
|
47951
|
+
type: "release_write",
|
|
47952
|
+
payload: { sessionId: this.sessionId, clientId: this.clientId }
|
|
47953
|
+
}).catch(() => ({ success: false }));
|
|
47954
|
+
}
|
|
47955
|
+
await this.client.request({
|
|
47956
|
+
type: "detach_session",
|
|
47957
|
+
payload: { sessionId: this.sessionId, clientId: this.clientId }
|
|
47958
|
+
}).catch(() => ({ success: false }));
|
|
47959
|
+
await this.client.close().catch(() => {
|
|
47960
|
+
});
|
|
47961
|
+
}
|
|
47962
|
+
};
|
|
47963
|
+
async function withRawTerminalAttachment(options, operation) {
|
|
47964
|
+
const attachment = await RawTerminalAttachment.attach(options);
|
|
47965
|
+
try {
|
|
47966
|
+
return await operation(attachment);
|
|
47967
|
+
} finally {
|
|
47968
|
+
await attachment.close();
|
|
47969
|
+
}
|
|
47970
|
+
}
|
|
47971
|
+
|
|
47736
47972
|
// src/session-host/app-name.ts
|
|
47737
47973
|
var DEFAULT_SESSION_HOST_APP_NAME = "adhdev";
|
|
47738
47974
|
var DEFAULT_STANDALONE_SESSION_HOST_APP_NAME = "adhdev-standalone";
|
|
@@ -47765,7 +48001,7 @@ function resolveSessionHostAppName(options = {}) {
|
|
|
47765
48001
|
}
|
|
47766
48002
|
|
|
47767
48003
|
// src/session-host/runtime-support.ts
|
|
47768
|
-
var
|
|
48004
|
+
var import_session_host_core5 = require("@adhdev/session-host-core");
|
|
47769
48005
|
var STARTUP_TIMEOUT_MS = DEFAULT_SESSION_HOST_READY_TIMEOUT_MS;
|
|
47770
48006
|
var STARTUP_POLL_MS = 200;
|
|
47771
48007
|
var SessionHostCompatibilityError = class extends Error {
|
|
@@ -47793,7 +48029,7 @@ async function assertRequiredRequestTypes(client, requiredRequestTypes) {
|
|
|
47793
48029
|
}
|
|
47794
48030
|
}
|
|
47795
48031
|
async function canConnect(endpoint, requiredRequestTypes = []) {
|
|
47796
|
-
const client = new
|
|
48032
|
+
const client = new import_session_host_core5.SessionHostClient({ endpoint });
|
|
47797
48033
|
try {
|
|
47798
48034
|
await client.connect();
|
|
47799
48035
|
await assertRequiredRequestTypes(client, requiredRequestTypes);
|
|
@@ -47815,7 +48051,7 @@ async function waitForReady(endpoint, timeoutMs = STARTUP_TIMEOUT_MS, requiredRe
|
|
|
47815
48051
|
throw new Error(`Session host did not become ready within ${timeoutMs}ms`);
|
|
47816
48052
|
}
|
|
47817
48053
|
async function ensureSessionHostReady(options) {
|
|
47818
|
-
const endpoint = (0,
|
|
48054
|
+
const endpoint = (0, import_session_host_core5.getDefaultSessionHostEndpoint)(options.appName || "adhdev");
|
|
47819
48055
|
const requiredRequestTypes = options.requiredRequestTypes || [];
|
|
47820
48056
|
if (await canConnect(endpoint, requiredRequestTypes)) return endpoint;
|
|
47821
48057
|
options.spawnHost();
|
|
@@ -47823,7 +48059,7 @@ async function ensureSessionHostReady(options) {
|
|
|
47823
48059
|
return endpoint;
|
|
47824
48060
|
}
|
|
47825
48061
|
async function listHostedCliRuntimes(endpoint) {
|
|
47826
|
-
const client = new
|
|
48062
|
+
const client = new import_session_host_core5.SessionHostClient({ endpoint });
|
|
47827
48063
|
try {
|
|
47828
48064
|
const response = await client.request({
|
|
47829
48065
|
type: "list_sessions",
|
|
@@ -48698,6 +48934,7 @@ var V1_CONTRACT_VERSION = "1.0.0";
|
|
|
48698
48934
|
ProviderCliAdapter,
|
|
48699
48935
|
ProviderInstanceManager,
|
|
48700
48936
|
ProviderLoader,
|
|
48937
|
+
RawTerminalAttachment,
|
|
48701
48938
|
STANDALONE_CDP_SCAN_INTERVAL_MS,
|
|
48702
48939
|
SessionHostPtyTransportFactory,
|
|
48703
48940
|
SpecDriver,
|
|
@@ -48848,6 +49085,8 @@ var V1_CONTRACT_VERSION = "1.0.0";
|
|
|
48848
49085
|
markSetupComplete,
|
|
48849
49086
|
markStaleDirectDispatches,
|
|
48850
49087
|
maybeRunDaemonUpgradeHelperFromEnv,
|
|
49088
|
+
namedKeyToAnsi,
|
|
49089
|
+
namedKeysToAnsi,
|
|
48851
49090
|
normalizeActiveChatData,
|
|
48852
49091
|
normalizeChatMessage,
|
|
48853
49092
|
normalizeChatMessageKind,
|
|
@@ -48928,6 +49167,7 @@ var V1_CONTRACT_VERSION = "1.0.0";
|
|
|
48928
49167
|
validateCliProviderManifest,
|
|
48929
49168
|
validateMeshRefineConfig,
|
|
48930
49169
|
validateMeshTaskModeRequest,
|
|
48931
|
-
validateMeshWorktreeBootstrapConfig
|
|
49170
|
+
validateMeshWorktreeBootstrapConfig,
|
|
49171
|
+
withRawTerminalAttachment
|
|
48932
49172
|
});
|
|
48933
49173
|
//# sourceMappingURL=index.js.map
|