@xenosystem/agent-interface-host 0.1.21 → 0.1.23
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/acp/AcpAgentRegistryService.d.ts +13 -4
- package/dist/acp/AcpAgentRegistryService.d.ts.map +1 -1
- package/dist/acp/AcpAgentRegistryService.js +26 -9
- package/dist/acp/AcpAgentRegistryService.js.map +1 -1
- package/dist/acp/AcpAgentTurnExecutionAdapter.d.ts +9 -0
- package/dist/acp/AcpAgentTurnExecutionAdapter.d.ts.map +1 -1
- package/dist/acp/AcpAgentTurnExecutionAdapter.js +49 -3
- package/dist/acp/AcpAgentTurnExecutionAdapter.js.map +1 -1
- package/dist/acp/AcpNativeProviderLauncherResolver.d.ts +20 -3
- package/dist/acp/AcpNativeProviderLauncherResolver.d.ts.map +1 -1
- package/dist/acp/AcpNativeProviderLauncherResolver.js +103 -10
- package/dist/acp/AcpNativeProviderLauncherResolver.js.map +1 -1
- package/dist/acp/AcpProviderModelService.d.ts.map +1 -1
- package/dist/acp/AcpProviderModelService.js +25 -1
- package/dist/acp/AcpProviderModelService.js.map +1 -1
- package/dist/acp/AcpRuntimeEventMapper.d.ts.map +1 -1
- package/dist/acp/AcpRuntimeEventMapper.js +23 -1
- package/dist/acp/AcpRuntimeEventMapper.js.map +1 -1
- package/dist/acp/AcpSessionService.d.ts.map +1 -1
- package/dist/acp/AcpSessionService.js +39 -0
- package/dist/acp/AcpSessionService.js.map +1 -1
- package/dist/acp/acpTypes.d.ts +7 -0
- package/dist/acp/acpTypes.d.ts.map +1 -1
- package/dist/acp/acpTypes.js.map +1 -1
- package/dist/index.d.ts +22 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +102 -2
- package/dist/index.js.map +1 -1
- package/dist/localRpcTransport.d.ts.map +1 -1
- package/dist/localRpcTransport.js +3 -0
- package/dist/localRpcTransport.js.map +1 -1
- package/dist/provider/ProviderLaneService.d.ts +16 -2
- package/dist/provider/ProviderLaneService.d.ts.map +1 -1
- package/dist/provider/ProviderLaneService.js +161 -11
- package/dist/provider/ProviderLaneService.js.map +1 -1
- package/dist/workspace/WorkspaceHostService.d.ts +72 -1
- package/dist/workspace/WorkspaceHostService.d.ts.map +1 -1
- package/dist/workspace/WorkspaceHostService.js +254 -4
- package/dist/workspace/WorkspaceHostService.js.map +1 -1
- package/package.json +8 -8
|
@@ -1,21 +1,67 @@
|
|
|
1
1
|
import { type CommandExecutionPort } from '../isolation/CommandExecution.js';
|
|
2
2
|
import type { CommandStreamPort } from '../isolation/CommandStream.js';
|
|
3
|
-
import type { AgentCockpitErrorCode, AgentHostEventType, AgentHostClientIdentity, AgentWorkspaceAccessContext, AgentWorkspaceCommandRunRequest, AgentWorkspaceCommandRunResult, AgentWorkspaceDirectoryListRequest, AgentWorkspaceDirectoryListResult, AgentWorkspaceFileReadRequest, AgentWorkspaceFileReadResult, AgentWorkspaceFileWriteRequest, AgentWorkspaceFileWriteResult, AgentWorkspaceGrantRequest, AgentWorkspaceGrantResult, AgentWorkspacePtyInputRequest, AgentWorkspacePtyResizeRequest, AgentWorkspacePtySnapshotRequest, AgentWorkspacePtySnapshotResult, AgentWorkspacePtyStartRequest, AgentWorkspacePtyStartResult, ProviderSessionPtyProfile, AgentWorkspaceTerminalControlRequest, AgentWorkspaceTerminalControlResult, AgentWorkspaceTerminalStartRequest, AgentWorkspaceTerminalStartResult } from '@xenosystem/agent-interface-contract';
|
|
3
|
+
import type { AgentCockpitErrorCode, AgentHostEventType, AgentHostClientIdentity, AgentWorkspaceAccessContext, AgentWorkspaceCommandRunRequest, AgentWorkspaceCommandRunResult, AgentWorkspaceDirectoryListRequest, AgentWorkspaceDirectoryListResult, AgentWorkspaceFileReadRequest, AgentWorkspaceFileReadResult, AgentWorkspaceFileWriteRequest, AgentWorkspaceFileWriteResult, AgentWorkspaceGrantRequest, AgentWorkspaceGrantResult, AgentWorkspacePtyInputRequest, AgentWorkspacePtyResizeRequest, AgentWorkspacePtySnapshotRequest, AgentWorkspacePtySnapshotResult, AgentWorkspacePtyStartRequest, AgentWorkspacePtyStartResult, ProviderSessionPtyProfile, XenoSessionPtyProfile, AgentWorkspaceTerminalControlRequest, AgentWorkspaceTerminalControlResult, AgentWorkspaceTerminalStartRequest, AgentWorkspaceTerminalStartResult } from '@xenosystem/agent-interface-contract';
|
|
4
4
|
type WorkspaceEventSink = (type: AgentHostEventType, payload: Record<string, unknown>) => void;
|
|
5
5
|
interface PersistedApplicationGrant {
|
|
6
6
|
path: string;
|
|
7
7
|
source: 'user-picker' | 'legacy-migration' | 'host-managed';
|
|
8
8
|
createdAt: number;
|
|
9
9
|
}
|
|
10
|
+
export interface NativeTranscriptSinkPayload {
|
|
11
|
+
terminalId: string;
|
|
12
|
+
conversationId: string;
|
|
13
|
+
event: Record<string, unknown>;
|
|
14
|
+
}
|
|
10
15
|
export type ProviderSessionPtyResolver = (profile: ProviderSessionPtyProfile, cwd: string, platform?: NodeJS.Platform) => {
|
|
11
16
|
executable: string;
|
|
12
17
|
args: string[];
|
|
18
|
+
startupResponses?: Array<{
|
|
19
|
+
whenNormalizedOutputIncludes: string[];
|
|
20
|
+
inputSequence: Array<{
|
|
21
|
+
input: string;
|
|
22
|
+
delayMs?: number;
|
|
23
|
+
}>;
|
|
24
|
+
}>;
|
|
25
|
+
transcriptStream?: {
|
|
26
|
+
executable: string;
|
|
27
|
+
args: string[];
|
|
28
|
+
cwd?: string;
|
|
29
|
+
env?: NodeJS.ProcessEnv;
|
|
30
|
+
};
|
|
13
31
|
} | {
|
|
14
32
|
error: string;
|
|
15
33
|
code?: AgentCockpitErrorCode;
|
|
16
34
|
} | Promise<{
|
|
17
35
|
executable: string;
|
|
18
36
|
args: string[];
|
|
37
|
+
startupResponses?: Array<{
|
|
38
|
+
whenNormalizedOutputIncludes: string[];
|
|
39
|
+
inputSequence: Array<{
|
|
40
|
+
input: string;
|
|
41
|
+
delayMs?: number;
|
|
42
|
+
}>;
|
|
43
|
+
}>;
|
|
44
|
+
transcriptStream?: {
|
|
45
|
+
executable: string;
|
|
46
|
+
args: string[];
|
|
47
|
+
cwd?: string;
|
|
48
|
+
env?: NodeJS.ProcessEnv;
|
|
49
|
+
};
|
|
50
|
+
} | {
|
|
51
|
+
error: string;
|
|
52
|
+
code?: AgentCockpitErrorCode;
|
|
53
|
+
}>;
|
|
54
|
+
export type XenoSessionPtyResolver = (profile: XenoSessionPtyProfile, cwd: string, platform?: NodeJS.Platform) => {
|
|
55
|
+
executable: string;
|
|
56
|
+
args: string[];
|
|
57
|
+
env?: NodeJS.ProcessEnv;
|
|
58
|
+
} | {
|
|
59
|
+
error: string;
|
|
60
|
+
code?: AgentCockpitErrorCode;
|
|
61
|
+
} | Promise<{
|
|
62
|
+
executable: string;
|
|
63
|
+
args: string[];
|
|
64
|
+
env?: NodeJS.ProcessEnv;
|
|
19
65
|
} | {
|
|
20
66
|
error: string;
|
|
21
67
|
code?: AgentCockpitErrorCode;
|
|
@@ -39,6 +85,9 @@ export interface WorkspaceHostServiceOptions {
|
|
|
39
85
|
*/
|
|
40
86
|
executionEnvironment?: RunCommandExecutionEnvironment;
|
|
41
87
|
providerSessionPtyResolver?: ProviderSessionPtyResolver | undefined;
|
|
88
|
+
xenoSessionPtyResolver?: XenoSessionPtyResolver | undefined;
|
|
89
|
+
/** Exact local Agent-host discovery root inherited by attached XENO CLI processes. */
|
|
90
|
+
xenoAgentHostRoot?: string | undefined;
|
|
42
91
|
}
|
|
43
92
|
/**
|
|
44
93
|
* The slice of `RunExecutionEnvironment` this service needs.
|
|
@@ -101,16 +150,20 @@ export declare class WorkspaceHostService {
|
|
|
101
150
|
private readonly managedConversationRoot;
|
|
102
151
|
private readonly providerSessionTerminalRoot;
|
|
103
152
|
private readonly providerSessionPtyResolver?;
|
|
153
|
+
private readonly xenoSessionPtyResolver?;
|
|
154
|
+
private readonly xenoAgentHostRoot?;
|
|
104
155
|
private readonly terminalSessions;
|
|
105
156
|
private readonly ptySessions;
|
|
106
157
|
private readonly grants;
|
|
107
158
|
private readonly applicationGrants;
|
|
108
159
|
private eventSink;
|
|
160
|
+
private nativeTranscriptSink;
|
|
109
161
|
private nodePtyLoadPromise;
|
|
110
162
|
private nodePtyLoadError;
|
|
111
163
|
private readonly executionEnvironment;
|
|
112
164
|
constructor(options: WorkspaceHostServiceOptions);
|
|
113
165
|
setEventSink(sink: WorkspaceEventSink): void;
|
|
166
|
+
setNativeTranscriptSink(sink: (payload: NativeTranscriptSinkPayload) => void): void;
|
|
114
167
|
/**
|
|
115
168
|
* Creates the neutral, host-owned workspace used by Chat mode. This does not
|
|
116
169
|
* mint a renderer grant: authorization remains scoped to the conversation ID.
|
|
@@ -141,9 +194,15 @@ export declare class WorkspaceHostService {
|
|
|
141
194
|
startTerminal(request: AgentWorkspaceTerminalStartRequest): Promise<AgentWorkspaceTerminalStartResult>;
|
|
142
195
|
stopTerminal(request: AgentWorkspaceTerminalControlRequest): AgentWorkspaceTerminalControlResult;
|
|
143
196
|
startPty(request: AgentWorkspacePtyStartRequest): Promise<AgentWorkspacePtyStartResult>;
|
|
197
|
+
private startNativeTranscriptStream;
|
|
144
198
|
snapshotPty(request: AgentWorkspacePtySnapshotRequest): AgentWorkspacePtySnapshotResult;
|
|
145
199
|
/** Host-only ownership transfer used when a native provider TUI is reattached by another surface. */
|
|
146
200
|
transferPtyOwnership(terminalId: string, ownerInstanceId: string): boolean;
|
|
201
|
+
/** Host-only lookup used to make XENO TUI attach idempotent across surfaces. */
|
|
202
|
+
findXenoPty(conversationId: string): {
|
|
203
|
+
terminalId: string;
|
|
204
|
+
cwd: string;
|
|
205
|
+
} | undefined;
|
|
147
206
|
inputPty(request: AgentWorkspacePtyInputRequest): AgentWorkspaceTerminalControlResult;
|
|
148
207
|
resizePty(request: AgentWorkspacePtyResizeRequest): AgentWorkspaceTerminalControlResult;
|
|
149
208
|
clearPty(request: AgentWorkspaceTerminalControlRequest): AgentWorkspaceTerminalControlResult;
|
|
@@ -172,6 +231,10 @@ export declare class WorkspaceHostService {
|
|
|
172
231
|
private persistGrants;
|
|
173
232
|
private persistApplicationGrants;
|
|
174
233
|
}
|
|
234
|
+
export declare function guardProviderCtrlCQuit(data: string, session: {
|
|
235
|
+
lastProviderInterruptAt?: number;
|
|
236
|
+
}, now: number): string;
|
|
237
|
+
export declare function validateNativeTranscriptEvent(line: string): Record<string, unknown> | null;
|
|
175
238
|
export declare function resolveProviderSessionPtyLaunch(profile: AgentWorkspacePtyStartRequest['profile'], _cwd: string, _platform?: NodeJS.Platform): {
|
|
176
239
|
executable: string;
|
|
177
240
|
args: string[];
|
|
@@ -179,5 +242,13 @@ export declare function resolveProviderSessionPtyLaunch(profile: AgentWorkspaceP
|
|
|
179
242
|
error: string;
|
|
180
243
|
code: AgentCockpitErrorCode;
|
|
181
244
|
};
|
|
245
|
+
export declare function resolveXenoSessionPtyLaunch(profile: XenoSessionPtyProfile, _cwd: string, platform?: NodeJS.Platform): {
|
|
246
|
+
executable: string;
|
|
247
|
+
args: string[];
|
|
248
|
+
env: NodeJS.ProcessEnv;
|
|
249
|
+
} | {
|
|
250
|
+
error: string;
|
|
251
|
+
code: AgentCockpitErrorCode;
|
|
252
|
+
};
|
|
182
253
|
export {};
|
|
183
254
|
//# sourceMappingURL=WorkspaceHostService.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"WorkspaceHostService.d.ts","sourceRoot":"","sources":["../../src/workspace/WorkspaceHostService.ts"],"names":[],"mappings":"AAGA,OAAO,EAAoB,KAAK,oBAAoB,EAAE,MAAM,kCAAkC,CAAA;AAC9F,OAAO,KAAK,EAAE,iBAAiB,EAAwB,MAAM,+BAA+B,CAAA;AAiC5F,OAAO,KAAK,EACV,qBAAqB,EACrB,kBAAkB,EAClB,uBAAuB,EACvB,2BAA2B,EAC3B,+BAA+B,EAC/B,8BAA8B,EAE9B,kCAAkC,EAClC,iCAAiC,EACjC,6BAA6B,EAC7B,4BAA4B,EAC5B,8BAA8B,EAC9B,6BAA6B,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,OAAO,CAAC,GAAG,IAAI,CA2B1F;AAUD,wBAAgB,+BAA+B,CAC7C,OAAO,EAAE,6BAA6B,CAAC,SAAS,CAAC,EACjD,IAAI,EAAE,MAAM,EACZ,SAAS,GAAE,MAAM,CAAC,QAA2B,GAC5C;IAAE,UAAU,EAAE,MAAM,CAAC;IAAC,IAAI,EAAE,MAAM,EAAE,CAAA;CAAE,GAAG;IAAE,KAAK,EAAE,MAAM,CAAC;IAAC,IAAI,EAAE,qBAAqB,CAAA;CAAE,CAWzF;AAED,wBAAgB,2BAA2B,CACzC,OAAO,EAAE,qBAAqB,EAC9B,IAAI,EAAE,MAAM,EACZ,QAAQ,GAAE,MAAM,CAAC,QAA2B,GAC3C;IAAE,UAAU,EAAE,MAAM,CAAC;IAAC,IAAI,EAAE,MAAM,EAAE,CAAC;IAAC,GAAG,EAAE,MAAM,CAAC,UAAU,CAAA;CAAE,GAAG;IAAE,KAAK,EAAE,MAAM,CAAC;IAAC,IAAI,EAAE,qBAAqB,CAAA;CAAE,CAuCjH"}
|
|
@@ -25,6 +25,7 @@ const MAX_FILE_BYTES = 1024 * 1024;
|
|
|
25
25
|
const MAX_COMMAND_OUTPUT_BYTES = 200_000;
|
|
26
26
|
const MAX_PTY_SCROLLBACK_BYTES = 500_000;
|
|
27
27
|
const MAX_GRANTS = 1_000;
|
|
28
|
+
const PROVIDER_CTRL_C_QUIT_GUARD_MS = 2_000;
|
|
28
29
|
/**
|
|
29
30
|
* Host-owned workspace authority, migrated from XENO Hub's workspace IPC
|
|
30
31
|
* implementation. The renderer can narrow trusted grants but cannot mint new
|
|
@@ -37,11 +38,14 @@ export class WorkspaceHostService {
|
|
|
37
38
|
managedConversationRoot;
|
|
38
39
|
providerSessionTerminalRoot;
|
|
39
40
|
providerSessionPtyResolver;
|
|
41
|
+
xenoSessionPtyResolver;
|
|
42
|
+
xenoAgentHostRoot;
|
|
40
43
|
terminalSessions = new Map();
|
|
41
44
|
ptySessions = new Map();
|
|
42
45
|
grants = new Map();
|
|
43
46
|
applicationGrants = new Map();
|
|
44
47
|
eventSink = () => { };
|
|
48
|
+
nativeTranscriptSink = () => { };
|
|
45
49
|
nodePtyLoadPromise = null;
|
|
46
50
|
nodePtyLoadError = null;
|
|
47
51
|
executionEnvironment;
|
|
@@ -57,12 +61,17 @@ export class WorkspaceHostService {
|
|
|
57
61
|
? resolve(options.managedConversationRoot)
|
|
58
62
|
: null;
|
|
59
63
|
this.providerSessionPtyResolver = options.providerSessionPtyResolver;
|
|
64
|
+
this.xenoSessionPtyResolver = options.xenoSessionPtyResolver;
|
|
65
|
+
this.xenoAgentHostRoot = options.xenoAgentHostRoot ? resolve(options.xenoAgentHostRoot) : undefined;
|
|
60
66
|
this.loadGrants();
|
|
61
67
|
this.loadApplicationGrants();
|
|
62
68
|
}
|
|
63
69
|
setEventSink(sink) {
|
|
64
70
|
this.eventSink = sink;
|
|
65
71
|
}
|
|
72
|
+
setNativeTranscriptSink(sink) {
|
|
73
|
+
this.nativeTranscriptSink = sink;
|
|
74
|
+
}
|
|
66
75
|
/**
|
|
67
76
|
* Creates the neutral, host-owned workspace used by Chat mode. This does not
|
|
68
77
|
* mint a renderer grant: authorization remains scoped to the conversation ID.
|
|
@@ -461,7 +470,7 @@ export class WorkspaceHostService {
|
|
|
461
470
|
}
|
|
462
471
|
async startPty(request) {
|
|
463
472
|
let cwd;
|
|
464
|
-
if (request.profile
|
|
473
|
+
if (request.profile && !request.cwd && request.allowedDirectories.length === 0) {
|
|
465
474
|
cwd = this.providerSessionTerminalRoot;
|
|
466
475
|
}
|
|
467
476
|
else {
|
|
@@ -474,7 +483,11 @@ export class WorkspaceHostService {
|
|
|
474
483
|
const terminalId = uniqueId('pty');
|
|
475
484
|
const cols = clampInteger(request.cols, 80, 20, 240);
|
|
476
485
|
const rows = clampInteger(request.rows, 24, 6, 120);
|
|
477
|
-
|
|
486
|
+
// Product/provider control TUIs stay host-local. Their model/tool work is
|
|
487
|
+
// still routed through the Agent host, where the run's execution
|
|
488
|
+
// environment is enforced. Starting the cockpit itself as `/bin/sh -i`
|
|
489
|
+
// would silently replace the requested TUI with a generic sandbox shell.
|
|
490
|
+
const confined = request.profile ? {} : this.confineStream(request.conversationId);
|
|
478
491
|
if (confined.error)
|
|
479
492
|
return ptyStartFailure(confined.error, cwd);
|
|
480
493
|
if (confined.stream) {
|
|
@@ -490,6 +503,9 @@ export class WorkspaceHostService {
|
|
|
490
503
|
try {
|
|
491
504
|
let shell;
|
|
492
505
|
let args;
|
|
506
|
+
let launchEnv;
|
|
507
|
+
let transcriptStream;
|
|
508
|
+
let startupResponses = [];
|
|
493
509
|
if (request.profile?.kind === 'provider-session') {
|
|
494
510
|
const launch = await (this.providerSessionPtyResolver
|
|
495
511
|
? this.providerSessionPtyResolver(request.profile, cwd, process.platform)
|
|
@@ -499,6 +515,24 @@ export class WorkspaceHostService {
|
|
|
499
515
|
}
|
|
500
516
|
shell = launch.executable;
|
|
501
517
|
args = launch.args;
|
|
518
|
+
startupResponses = 'startupResponses' in launch && launch.startupResponses
|
|
519
|
+
? [...launch.startupResponses]
|
|
520
|
+
: [];
|
|
521
|
+
transcriptStream = 'transcriptStream' in launch ? launch.transcriptStream : undefined;
|
|
522
|
+
}
|
|
523
|
+
else if (request.profile?.kind === 'xeno-session') {
|
|
524
|
+
const launch = await (this.xenoSessionPtyResolver
|
|
525
|
+
? this.xenoSessionPtyResolver(request.profile, cwd, process.platform)
|
|
526
|
+
: resolveXenoSessionPtyLaunch(request.profile, cwd, process.platform));
|
|
527
|
+
if ('error' in launch) {
|
|
528
|
+
return ptyStartFailure(launch.error, cwd, launch.code || 'XENO_TUI_UNAVAILABLE');
|
|
529
|
+
}
|
|
530
|
+
shell = launch.executable;
|
|
531
|
+
args = launch.args;
|
|
532
|
+
launchEnv = {
|
|
533
|
+
...launch.env,
|
|
534
|
+
...(this.xenoAgentHostRoot ? { XENO_AGENT_HOST_ROOT: this.xenoAgentHostRoot } : {}),
|
|
535
|
+
};
|
|
502
536
|
}
|
|
503
537
|
else {
|
|
504
538
|
shell = process.platform === 'win32' ? 'powershell.exe' : (process.env.SHELL || '/bin/bash');
|
|
@@ -513,7 +547,7 @@ export class WorkspaceHostService {
|
|
|
513
547
|
cols,
|
|
514
548
|
rows,
|
|
515
549
|
cwd,
|
|
516
|
-
env: { ...process.env, TERM: 'xterm-256color', COLORTERM: 'truecolor' },
|
|
550
|
+
env: { ...process.env, ...launchEnv, TERM: 'xterm-256color', COLORTERM: 'truecolor' },
|
|
517
551
|
...(process.platform === 'win32' ? { useConpty: true, useConptyDll: true } : {}),
|
|
518
552
|
});
|
|
519
553
|
const session = {
|
|
@@ -530,17 +564,45 @@ export class WorkspaceHostService {
|
|
|
530
564
|
kill: () => { processHandle.kill(); },
|
|
531
565
|
},
|
|
532
566
|
output: new ScrollbackBuffer(MAX_PTY_SCROLLBACK_BYTES),
|
|
567
|
+
...(request.conversationId ? { conversationId: request.conversationId } : {}),
|
|
568
|
+
...(request.profile ? { profileKind: request.profile.kind } : {}),
|
|
533
569
|
};
|
|
534
570
|
this.ptySessions.set(terminalId, session);
|
|
571
|
+
if (transcriptStream && request.conversationId) {
|
|
572
|
+
session.transcriptProcess = this.startNativeTranscriptStream(transcriptStream, terminalId, request.conversationId);
|
|
573
|
+
}
|
|
574
|
+
let startupOutput = '';
|
|
535
575
|
processHandle.onData((data) => {
|
|
536
576
|
const active = this.ptySessions.get(terminalId);
|
|
537
577
|
if (!active)
|
|
538
578
|
return;
|
|
539
579
|
active.output.append(data);
|
|
540
580
|
this.eventSink('workspace.pty.data', { terminalId, data, ownerInstanceId: active.ownerInstanceId });
|
|
581
|
+
if (startupResponses.length > 0) {
|
|
582
|
+
startupOutput = `${startupOutput}${data}`.slice(-64_000);
|
|
583
|
+
const normalized = normalizeProviderStartupOutput(startupOutput);
|
|
584
|
+
for (const response of [...startupResponses]) {
|
|
585
|
+
if (!response.whenNormalizedOutputIncludes.every((token) => normalized.includes(token)))
|
|
586
|
+
continue;
|
|
587
|
+
startupResponses = startupResponses.filter((candidate) => candidate !== response);
|
|
588
|
+
let cumulativeDelay = 0;
|
|
589
|
+
for (const step of response.inputSequence) {
|
|
590
|
+
cumulativeDelay += step.delayMs ?? 0;
|
|
591
|
+
if (cumulativeDelay === 0) {
|
|
592
|
+
processHandle.write(step.input);
|
|
593
|
+
continue;
|
|
594
|
+
}
|
|
595
|
+
setTimeout(() => {
|
|
596
|
+
if (this.ptySessions.get(terminalId) === session)
|
|
597
|
+
processHandle.write(step.input);
|
|
598
|
+
}, cumulativeDelay);
|
|
599
|
+
}
|
|
600
|
+
}
|
|
601
|
+
}
|
|
541
602
|
});
|
|
542
603
|
processHandle.onExit(({ exitCode, signal }) => {
|
|
543
604
|
const active = this.ptySessions.get(terminalId);
|
|
605
|
+
active?.transcriptProcess?.kill();
|
|
544
606
|
this.ptySessions.delete(terminalId);
|
|
545
607
|
this.eventSink('workspace.pty.exit', {
|
|
546
608
|
terminalId,
|
|
@@ -555,6 +617,38 @@ export class WorkspaceHostService {
|
|
|
555
617
|
return { success: false, terminalId: null, cwd, error: safeError(error, 'Failed to start PTY terminal.') };
|
|
556
618
|
}
|
|
557
619
|
}
|
|
620
|
+
startNativeTranscriptStream(launch, terminalId, conversationId) {
|
|
621
|
+
const child = spawn(launch.executable, launch.args, {
|
|
622
|
+
cwd: launch.cwd,
|
|
623
|
+
// The resolver supplies the same bounded non-secret runtime environment
|
|
624
|
+
// used by ACP. Reintroducing ambient Host secrets here would turn a
|
|
625
|
+
// read-only transcript follower into a credential disclosure boundary.
|
|
626
|
+
env: launch.env ?? process.env,
|
|
627
|
+
shell: false,
|
|
628
|
+
windowsHide: true,
|
|
629
|
+
stdio: ['pipe', 'pipe', 'pipe'],
|
|
630
|
+
});
|
|
631
|
+
let buffer = '';
|
|
632
|
+
child.stdout.setEncoding('utf8');
|
|
633
|
+
child.stdout.on('data', (chunk) => {
|
|
634
|
+
buffer = `${buffer}${chunk}`;
|
|
635
|
+
if (buffer.length > 2 * 1024 * 1024)
|
|
636
|
+
buffer = buffer.slice(-2 * 1024 * 1024);
|
|
637
|
+
const lines = buffer.split(/\r?\n/u);
|
|
638
|
+
buffer = lines.pop() || '';
|
|
639
|
+
for (const line of lines) {
|
|
640
|
+
if (!line.trim())
|
|
641
|
+
continue;
|
|
642
|
+
const event = validateNativeTranscriptEvent(line);
|
|
643
|
+
if (event)
|
|
644
|
+
this.nativeTranscriptSink({ terminalId, conversationId, event });
|
|
645
|
+
}
|
|
646
|
+
});
|
|
647
|
+
// Diagnostics never carry conversation data into the renderer. Drain the
|
|
648
|
+
// pipe so a noisy follower cannot back-pressure or deadlock its parent PTY.
|
|
649
|
+
child.stderr.resume();
|
|
650
|
+
return child;
|
|
651
|
+
}
|
|
558
652
|
snapshotPty(request) {
|
|
559
653
|
const terminalId = String(request.terminalId || '').trim();
|
|
560
654
|
const session = this.ptySessions.get(terminalId);
|
|
@@ -573,12 +667,29 @@ export class WorkspaceHostService {
|
|
|
573
667
|
session.ownerInstanceId = nextOwner;
|
|
574
668
|
return true;
|
|
575
669
|
}
|
|
670
|
+
/** Host-only lookup used to make XENO TUI attach idempotent across surfaces. */
|
|
671
|
+
findXenoPty(conversationId) {
|
|
672
|
+
const expected = String(conversationId || '').trim();
|
|
673
|
+
if (!expected)
|
|
674
|
+
return undefined;
|
|
675
|
+
for (const session of this.ptySessions.values()) {
|
|
676
|
+
if (session.profileKind === 'xeno-session' && session.conversationId === expected) {
|
|
677
|
+
return { terminalId: session.id, cwd: session.cwd };
|
|
678
|
+
}
|
|
679
|
+
}
|
|
680
|
+
return undefined;
|
|
681
|
+
}
|
|
576
682
|
inputPty(request) {
|
|
577
683
|
const session = this.ptySessions.get(String(request.terminalId || '').trim());
|
|
578
684
|
const denied = this.authorizeSession(request, session);
|
|
579
685
|
if (denied)
|
|
580
686
|
return { success: false, error: denied };
|
|
581
|
-
|
|
687
|
+
const raw = String(request.data || '').slice(0, 100_000);
|
|
688
|
+
const data = session.profileKind === 'provider-session'
|
|
689
|
+
? guardProviderCtrlCQuit(raw, session, Date.now())
|
|
690
|
+
: raw;
|
|
691
|
+
if (data)
|
|
692
|
+
session.process.write(data);
|
|
582
693
|
return { success: true, error: null };
|
|
583
694
|
}
|
|
584
695
|
resizePty(request) {
|
|
@@ -605,6 +716,7 @@ export class WorkspaceHostService {
|
|
|
605
716
|
if (denied)
|
|
606
717
|
return { success: false, error: denied };
|
|
607
718
|
this.ptySessions.delete(session.id);
|
|
719
|
+
session.transcriptProcess?.kill();
|
|
608
720
|
session.process.kill();
|
|
609
721
|
return { success: true, error: null };
|
|
610
722
|
}
|
|
@@ -619,6 +731,10 @@ export class WorkspaceHostService {
|
|
|
619
731
|
}
|
|
620
732
|
this.terminalSessions.clear();
|
|
621
733
|
for (const session of this.ptySessions.values()) {
|
|
734
|
+
try {
|
|
735
|
+
session.transcriptProcess?.kill();
|
|
736
|
+
}
|
|
737
|
+
catch { /* follower already exited */ }
|
|
622
738
|
try {
|
|
623
739
|
session.process.kill();
|
|
624
740
|
}
|
|
@@ -719,6 +835,8 @@ export class WorkspaceHostService {
|
|
|
719
835
|
kill: () => live ? live.kill() : Promise.resolve(),
|
|
720
836
|
}),
|
|
721
837
|
output,
|
|
838
|
+
...(input.request.conversationId ? { conversationId: input.request.conversationId } : {}),
|
|
839
|
+
...(input.request.profile ? { profileKind: input.request.profile.kind } : {}),
|
|
722
840
|
});
|
|
723
841
|
const started = await input.stream.start({
|
|
724
842
|
argv: ['/bin/sh', '-i'],
|
|
@@ -965,6 +1083,67 @@ export class WorkspaceHostService {
|
|
|
965
1083
|
persistJsonAtomically(this.applicationGrantStorePath, payload);
|
|
966
1084
|
}
|
|
967
1085
|
}
|
|
1086
|
+
export function guardProviderCtrlCQuit(data, session, now) {
|
|
1087
|
+
let result = '';
|
|
1088
|
+
for (const char of data) {
|
|
1089
|
+
if (char !== '\u0003') {
|
|
1090
|
+
result += char;
|
|
1091
|
+
if (char.trim())
|
|
1092
|
+
delete session.lastProviderInterruptAt;
|
|
1093
|
+
continue;
|
|
1094
|
+
}
|
|
1095
|
+
const prior = session.lastProviderInterruptAt;
|
|
1096
|
+
if (prior !== undefined && now - prior < PROVIDER_CTRL_C_QUIT_GUARD_MS)
|
|
1097
|
+
continue;
|
|
1098
|
+
session.lastProviderInterruptAt = now;
|
|
1099
|
+
result += char;
|
|
1100
|
+
}
|
|
1101
|
+
return result;
|
|
1102
|
+
}
|
|
1103
|
+
export function validateNativeTranscriptEvent(line) {
|
|
1104
|
+
let parsed;
|
|
1105
|
+
try {
|
|
1106
|
+
parsed = JSON.parse(line);
|
|
1107
|
+
}
|
|
1108
|
+
catch {
|
|
1109
|
+
return null;
|
|
1110
|
+
}
|
|
1111
|
+
if (!parsed || typeof parsed !== 'object' || Array.isArray(parsed))
|
|
1112
|
+
return null;
|
|
1113
|
+
const event = parsed;
|
|
1114
|
+
if (event.version !== 1 || typeof event.type !== 'string' || typeof event.providerId !== 'string')
|
|
1115
|
+
return null;
|
|
1116
|
+
if (event.providerId !== 'codex-local' && event.providerId !== 'claude-local')
|
|
1117
|
+
return null;
|
|
1118
|
+
if (event.type === 'session.bound') {
|
|
1119
|
+
return typeof event.nativeSessionId === 'string'
|
|
1120
|
+
&& /^[A-Za-z0-9][A-Za-z0-9._:-]{0,255}$/u.test(event.nativeSessionId)
|
|
1121
|
+
? event
|
|
1122
|
+
: null;
|
|
1123
|
+
}
|
|
1124
|
+
if (event.type === 'message') {
|
|
1125
|
+
if ((event.role !== 'user' && event.role !== 'assistant')
|
|
1126
|
+
|| typeof event.eventId !== 'string' || event.eventId.length < 1 || event.eventId.length > 200
|
|
1127
|
+
|| typeof event.content !== 'string' || event.content.length < 1 || event.content.length > 2_000_000
|
|
1128
|
+
|| typeof event.nativeSessionId !== 'string'
|
|
1129
|
+
|| !/^[A-Za-z0-9][A-Za-z0-9._:-]{0,255}$/u.test(event.nativeSessionId))
|
|
1130
|
+
return null;
|
|
1131
|
+
return event;
|
|
1132
|
+
}
|
|
1133
|
+
if (event.type === 'warning') {
|
|
1134
|
+
return typeof event.code === 'string' && typeof event.message === 'string' && event.message.length <= 1_000
|
|
1135
|
+
? event
|
|
1136
|
+
: null;
|
|
1137
|
+
}
|
|
1138
|
+
return null;
|
|
1139
|
+
}
|
|
1140
|
+
function normalizeProviderStartupOutput(value) {
|
|
1141
|
+
return value
|
|
1142
|
+
.replace(/\u001b\][^\u0007]*(?:\u0007|\u001b\\)/g, '')
|
|
1143
|
+
.replace(/\u001b\[[0-?]*[ -/]*[@-~]/g, '')
|
|
1144
|
+
.toLowerCase()
|
|
1145
|
+
.replace(/[^a-z0-9]+/g, '');
|
|
1146
|
+
}
|
|
968
1147
|
export function resolveProviderSessionPtyLaunch(profile, _cwd, _platform = process.platform) {
|
|
969
1148
|
if (!profile || profile.kind !== 'provider-session') {
|
|
970
1149
|
return { error: 'Unsupported provider-session terminal profile.', code: 'NATIVE_TUI_UNSUPPORTED' };
|
|
@@ -976,6 +1155,77 @@ export function resolveProviderSessionPtyLaunch(profile, _cwd, _platform = proce
|
|
|
976
1155
|
code: 'NATIVE_TUI_UNSUPPORTED',
|
|
977
1156
|
};
|
|
978
1157
|
}
|
|
1158
|
+
export function resolveXenoSessionPtyLaunch(profile, _cwd, platform = process.platform) {
|
|
1159
|
+
const executable = findXenoCliExecutable(platform);
|
|
1160
|
+
if (!executable) {
|
|
1161
|
+
return {
|
|
1162
|
+
error: 'XENO Agent CLI is not installed or is not discoverable on PATH.',
|
|
1163
|
+
code: 'XENO_TUI_UNAVAILABLE',
|
|
1164
|
+
};
|
|
1165
|
+
}
|
|
1166
|
+
const cliArgs = [profile.mode === 'chat' ? 'chat' : 'agent', '--tui'];
|
|
1167
|
+
const env = {
|
|
1168
|
+
XENO_AGENT_ATTACH: 'require',
|
|
1169
|
+
XENO_AGENT_CONVERSATION_ID: profile.conversationId,
|
|
1170
|
+
XENO_AGENT_HOST_STORAGE_IDENTITY: profile.hostStorageIdentity,
|
|
1171
|
+
XENO_AGENT_WORKSPACE_EPOCH_ID: profile.expectedWorkspaceEpochId,
|
|
1172
|
+
XENO_AGENT_LAUNCH_SOURCE: 'agent-interface',
|
|
1173
|
+
};
|
|
1174
|
+
if (platform === 'win32' && /\.(?:cmd|bat)$/iu.test(executable)) {
|
|
1175
|
+
const command = `"${executable.replace(/"/gu, '""')}" ${cliArgs.join(' ')}`;
|
|
1176
|
+
return {
|
|
1177
|
+
executable: process.env.ComSpec || process.env.COMSPEC || 'cmd.exe',
|
|
1178
|
+
args: ['/d', '/s', '/c', `"${command}"`],
|
|
1179
|
+
env,
|
|
1180
|
+
};
|
|
1181
|
+
}
|
|
1182
|
+
if (/\.(?:cjs|mjs|js)$/iu.test(executable)) {
|
|
1183
|
+
const nodeExecutable = findNodeExecutable(platform);
|
|
1184
|
+
if (!nodeExecutable) {
|
|
1185
|
+
return {
|
|
1186
|
+
error: 'A JavaScript XENO Agent CLI entrypoint was selected, but Node.js is not discoverable on PATH.',
|
|
1187
|
+
code: 'XENO_TUI_UNAVAILABLE',
|
|
1188
|
+
};
|
|
1189
|
+
}
|
|
1190
|
+
return {
|
|
1191
|
+
executable: nodeExecutable,
|
|
1192
|
+
args: [executable, ...cliArgs],
|
|
1193
|
+
env,
|
|
1194
|
+
};
|
|
1195
|
+
}
|
|
1196
|
+
return { executable, args: cliArgs, env };
|
|
1197
|
+
}
|
|
1198
|
+
function findNodeExecutable(platform) {
|
|
1199
|
+
const explicit = String(process.env.XENO_AGENT_NODE_EXECUTABLE || '').trim();
|
|
1200
|
+
if (explicit && existsSync(explicit))
|
|
1201
|
+
return resolve(explicit);
|
|
1202
|
+
if (!process.versions.electron && existsSync(process.execPath))
|
|
1203
|
+
return resolve(process.execPath);
|
|
1204
|
+
const name = platform === 'win32' ? 'node.exe' : 'node';
|
|
1205
|
+
for (const directory of String(process.env.PATH || '').split(platform === 'win32' ? ';' : ':').filter(Boolean)) {
|
|
1206
|
+
const candidate = resolve(directory, name);
|
|
1207
|
+
if (existsSync(candidate))
|
|
1208
|
+
return candidate;
|
|
1209
|
+
}
|
|
1210
|
+
return null;
|
|
1211
|
+
}
|
|
1212
|
+
function findXenoCliExecutable(platform) {
|
|
1213
|
+
const explicit = String(process.env.XENO_AGENT_CLI_EXECUTABLE || '').trim();
|
|
1214
|
+
if (explicit && existsSync(explicit))
|
|
1215
|
+
return resolve(explicit);
|
|
1216
|
+
const names = platform === 'win32' ? ['xeno.cmd', 'xeno.exe', 'xeno.bat'] : ['xeno'];
|
|
1217
|
+
const pathEntries = String(process.env.PATH || '').split(platform === 'win32' ? ';' : ':').filter(Boolean);
|
|
1218
|
+
if (platform === 'win32' && process.env.APPDATA)
|
|
1219
|
+
pathEntries.unshift(join(process.env.APPDATA, 'npm'));
|
|
1220
|
+
for (const directory of pathEntries) {
|
|
1221
|
+
for (const name of names) {
|
|
1222
|
+
const candidate = resolve(directory, name);
|
|
1223
|
+
if (existsSync(candidate))
|
|
1224
|
+
return candidate;
|
|
1225
|
+
}
|
|
1226
|
+
}
|
|
1227
|
+
return null;
|
|
1228
|
+
}
|
|
979
1229
|
function normalizeExistingDirectories(values) {
|
|
980
1230
|
const result = [];
|
|
981
1231
|
const seen = new Set();
|