@pentoshi/clai 3.9.4 → 3.9.6
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/agent/context-manager.d.ts +4 -4
- package/dist/agent/context-manager.js +4 -4
- package/dist/agent/reliability-policy.d.ts +2 -2
- package/dist/agent/request-budget.d.ts +1 -1
- package/dist/agent/request-budget.js +1 -1
- package/dist/agent/request-budget.js.map +1 -1
- package/dist/app/controllers/session-controller.d.ts +0 -8
- package/dist/app/controllers/session-controller.js +4 -20
- package/dist/app/controllers/session-controller.js.map +1 -1
- package/dist/index.js +8 -21
- package/dist/index.js.map +1 -1
- package/dist/repl.js +0 -10
- package/dist/repl.js.map +1 -1
- package/dist/store/config.js +1 -1
- package/dist/store/config.js.map +1 -1
- package/dist/tools/definitions.js +0 -95
- package/dist/tools/definitions.js.map +1 -1
- package/dist/tools/jobs.js +70 -2
- package/dist/tools/jobs.js.map +1 -1
- package/dist/tools/registry.js +0 -4
- package/dist/tools/registry.js.map +1 -1
- package/dist/tui-v2/bootstrap/composition-root.d.ts +0 -3
- package/dist/tui-v2/bootstrap/composition-root.js +0 -3
- package/dist/tui-v2/bootstrap/composition-root.js.map +1 -1
- package/dist/tui-v2/bootstrap/start-tui-v2.js +0 -10
- package/dist/tui-v2/bootstrap/start-tui-v2.js.map +1 -1
- package/dist/types.d.ts +0 -5
- package/dist/version.generated.d.ts +2 -2
- package/dist/version.generated.js +2 -2
- package/package.json +1 -1
- package/dist/app/adapters/current-interactive-sessions-adapter.d.ts +0 -4
- package/dist/app/adapters/current-interactive-sessions-adapter.js +0 -11
- package/dist/app/adapters/current-interactive-sessions-adapter.js.map +0 -1
- package/dist/app/controllers/cancel-all-result.d.ts +0 -8
- package/dist/app/controllers/cancel-all-result.js +0 -32
- package/dist/app/controllers/cancel-all-result.js.map +0 -1
- package/dist/app/ports/interactive-sessions-port.d.ts +0 -21
- package/dist/app/ports/interactive-sessions-port.js +0 -9
- package/dist/app/ports/interactive-sessions-port.js.map +0 -1
- package/dist/interactive-session/artifact-writer.d.ts +0 -54
- package/dist/interactive-session/artifact-writer.js +0 -161
- package/dist/interactive-session/artifact-writer.js.map +0 -1
- package/dist/interactive-session/cleanup.d.ts +0 -36
- package/dist/interactive-session/cleanup.js +0 -157
- package/dist/interactive-session/cleanup.js.map +0 -1
- package/dist/interactive-session/config.d.ts +0 -118
- package/dist/interactive-session/config.js +0 -141
- package/dist/interactive-session/config.js.map +0 -1
- package/dist/interactive-session/input-policy.d.ts +0 -41
- package/dist/interactive-session/input-policy.js +0 -163
- package/dist/interactive-session/input-policy.js.map +0 -1
- package/dist/interactive-session/manager.d.ts +0 -107
- package/dist/interactive-session/manager.js +0 -927
- package/dist/interactive-session/manager.js.map +0 -1
- package/dist/interactive-session/output-store.d.ts +0 -81
- package/dist/interactive-session/output-store.js +0 -239
- package/dist/interactive-session/output-store.js.map +0 -1
- package/dist/interactive-session/output-view.d.ts +0 -20
- package/dist/interactive-session/output-view.js +0 -142
- package/dist/interactive-session/output-view.js.map +0 -1
- package/dist/interactive-session/recovery-journal.d.ts +0 -55
- package/dist/interactive-session/recovery-journal.js +0 -115
- package/dist/interactive-session/recovery-journal.js.map +0 -1
- package/dist/interactive-session/registry.d.ts +0 -59
- package/dist/interactive-session/registry.js +0 -170
- package/dist/interactive-session/registry.js.map +0 -1
- package/dist/interactive-session/runtime.d.ts +0 -107
- package/dist/interactive-session/runtime.js +0 -191
- package/dist/interactive-session/runtime.js.map +0 -1
- package/dist/interactive-session/session-runtime.d.ts +0 -50
- package/dist/interactive-session/session-runtime.js +0 -63
- package/dist/interactive-session/session-runtime.js.map +0 -1
- package/dist/interactive-session/streaming-redactor.d.ts +0 -53
- package/dist/interactive-session/streaming-redactor.js +0 -263
- package/dist/interactive-session/streaming-redactor.js.map +0 -1
- package/dist/interactive-session/telemetry.d.ts +0 -30
- package/dist/interactive-session/telemetry.js +0 -47
- package/dist/interactive-session/telemetry.js.map +0 -1
- package/dist/interactive-session/transport-factory.d.ts +0 -8
- package/dist/interactive-session/transport-factory.js +0 -16
- package/dist/interactive-session/transport-factory.js.map +0 -1
- package/dist/interactive-session/transport-node-pty.d.ts +0 -49
- package/dist/interactive-session/transport-node-pty.js +0 -219
- package/dist/interactive-session/transport-node-pty.js.map +0 -1
- package/dist/interactive-session/transport-pipe.d.ts +0 -9
- package/dist/interactive-session/transport-pipe.js +0 -215
- package/dist/interactive-session/transport-pipe.js.map +0 -1
- package/dist/interactive-session/transport.d.ts +0 -104
- package/dist/interactive-session/transport.js +0 -89
- package/dist/interactive-session/transport.js.map +0 -1
- package/dist/interactive-session/types.d.ts +0 -254
- package/dist/interactive-session/types.js +0 -191
- package/dist/interactive-session/types.js.map +0 -1
- package/dist/os/process-identity.d.ts +0 -46
- package/dist/os/process-identity.js +0 -147
- package/dist/os/process-identity.js.map +0 -1
- package/dist/tools/interactive-session-tools.d.ts +0 -11
- package/dist/tools/interactive-session-tools.js +0 -261
- package/dist/tools/interactive-session-tools.js.map +0 -1
|
@@ -1,254 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Public domain contracts for agent-controlled interactive terminal sessions.
|
|
3
|
-
*
|
|
4
|
-
* Deliberate non-goals encoded here: no user keyboard passthrough, no transfer
|
|
5
|
-
* of the host controlling terminal, no reattachment after restart, no screen
|
|
6
|
-
* emulation, and no command rewriting. Nothing in this module carries raw
|
|
7
|
-
* commands, input bytes, environment values, or unredacted output.
|
|
8
|
-
*/
|
|
9
|
-
export type SessionOperation = "start" | "send" | "read" | "status" | "list" | "resize" | "close";
|
|
10
|
-
export type SessionState = "starting" | "running" | "closing" | "exited" | "failed" | "closed";
|
|
11
|
-
export declare const TERMINAL_SESSION_STATES: readonly SessionState[];
|
|
12
|
-
export declare function isTerminalState(state: SessionState): boolean;
|
|
13
|
-
export type TerminationReason = "process-exit" | "explicit-close" | "cancelled" | "idle-timeout" | "lifetime-timeout" | "conversation-teardown" | "app-shutdown" | "output-limit" | "launch-failure";
|
|
14
|
-
export type SessionTransportKind = "pty" | "pipe";
|
|
15
|
-
export type TerminalMode = "required" | "preferred" | "pipe";
|
|
16
|
-
export type OutputStream = "terminal" | "stdout" | "stderr";
|
|
17
|
-
export type OutputView = "plain" | "encoded";
|
|
18
|
-
export interface TerminalDimensions {
|
|
19
|
-
readonly columns: number;
|
|
20
|
-
readonly rows: number;
|
|
21
|
-
}
|
|
22
|
-
export type ControlInput = "interrupt" | "eof" | "suspend" | "escape" | "tab" | "backspace" | "up" | "down" | "left" | "right";
|
|
23
|
-
export declare const CONTROL_INPUTS: readonly ControlInput[];
|
|
24
|
-
export type SubmitBehavior = "enter" | "none";
|
|
25
|
-
export type SessionInput = {
|
|
26
|
-
readonly kind: "text";
|
|
27
|
-
readonly text: string;
|
|
28
|
-
readonly submit: SubmitBehavior;
|
|
29
|
-
} | {
|
|
30
|
-
readonly kind: "control";
|
|
31
|
-
readonly control: ControlInput;
|
|
32
|
-
} | {
|
|
33
|
-
readonly kind: "eof";
|
|
34
|
-
};
|
|
35
|
-
export type SessionInputKind = SessionInput["kind"];
|
|
36
|
-
export interface ProcessOutcome {
|
|
37
|
-
readonly exitCode?: number | undefined;
|
|
38
|
-
readonly signal?: string | undefined;
|
|
39
|
-
readonly endedAt: number;
|
|
40
|
-
}
|
|
41
|
-
export type ProcessIdentityComparison = "match" | "mismatch" | "gone" | "unknown";
|
|
42
|
-
export interface OutputEvent {
|
|
43
|
-
/** Inclusive canonical safe-byte offset. */
|
|
44
|
-
readonly startCursor: number;
|
|
45
|
-
/** Exclusive canonical safe-byte offset. */
|
|
46
|
-
readonly endCursor: number;
|
|
47
|
-
readonly stream: OutputStream;
|
|
48
|
-
readonly observedAt: number;
|
|
49
|
-
readonly bytes: Uint8Array;
|
|
50
|
-
}
|
|
51
|
-
export interface PresentedOutputEvent {
|
|
52
|
-
readonly startCursor: number;
|
|
53
|
-
readonly endCursor: number;
|
|
54
|
-
readonly stream: OutputStream;
|
|
55
|
-
readonly observedAt: number;
|
|
56
|
-
/** Inert text for `plain`, base64 for `encoded`. */
|
|
57
|
-
readonly content: string;
|
|
58
|
-
readonly decodingLoss?: boolean | undefined;
|
|
59
|
-
}
|
|
60
|
-
export interface ArtifactReference {
|
|
61
|
-
readonly path: string;
|
|
62
|
-
readonly bytes: number;
|
|
63
|
-
readonly droppedBytes: number;
|
|
64
|
-
readonly redacted: boolean;
|
|
65
|
-
}
|
|
66
|
-
export interface ArtifactReceipt extends ArtifactReference {
|
|
67
|
-
readonly chunks: readonly string[];
|
|
68
|
-
readonly sha256: string;
|
|
69
|
-
}
|
|
70
|
-
export interface OutputPage {
|
|
71
|
-
readonly events: readonly PresentedOutputEvent[];
|
|
72
|
-
readonly requestedCursor: number;
|
|
73
|
-
readonly nextCursor: number;
|
|
74
|
-
readonly hasMore: boolean;
|
|
75
|
-
readonly earliestAvailableCursor: number;
|
|
76
|
-
readonly latestCursor: number;
|
|
77
|
-
readonly view: OutputView;
|
|
78
|
-
readonly decodingLoss: boolean;
|
|
79
|
-
readonly omittedBytes?: number | undefined;
|
|
80
|
-
readonly artifact: ArtifactReference;
|
|
81
|
-
}
|
|
82
|
-
export interface InteractiveSessionRecord {
|
|
83
|
-
readonly id: string;
|
|
84
|
-
readonly ownerId: string;
|
|
85
|
-
state: SessionState;
|
|
86
|
-
readonly transport: SessionTransportKind;
|
|
87
|
-
readonly startedAt: number;
|
|
88
|
-
lastActivityAt: number;
|
|
89
|
-
endedAt?: number | undefined;
|
|
90
|
-
dimensions?: TerminalDimensions | undefined;
|
|
91
|
-
degradedReason?: "PTY_UNAVAILABLE" | undefined;
|
|
92
|
-
processOutcome?: ProcessOutcome | undefined;
|
|
93
|
-
terminationReason?: TerminationReason | undefined;
|
|
94
|
-
artifact: ArtifactReceipt;
|
|
95
|
-
earliestCursor: number;
|
|
96
|
-
latestCursor: number;
|
|
97
|
-
inputClosed: boolean;
|
|
98
|
-
cleanupVerified?: boolean | undefined;
|
|
99
|
-
}
|
|
100
|
-
/** Immutable, non-disclosing projection handed to callers. */
|
|
101
|
-
export interface SessionSummary {
|
|
102
|
-
readonly id: string;
|
|
103
|
-
readonly state: SessionState;
|
|
104
|
-
readonly transport: SessionTransportKind;
|
|
105
|
-
readonly startedAt: number;
|
|
106
|
-
readonly lastActivityAt: number;
|
|
107
|
-
readonly endedAt?: number | undefined;
|
|
108
|
-
readonly dimensions?: TerminalDimensions | undefined;
|
|
109
|
-
readonly degradedReason?: "PTY_UNAVAILABLE" | undefined;
|
|
110
|
-
readonly processOutcome?: ProcessOutcome | undefined;
|
|
111
|
-
readonly terminationReason?: TerminationReason | undefined;
|
|
112
|
-
readonly earliestCursor: number;
|
|
113
|
-
readonly latestCursor: number;
|
|
114
|
-
readonly inputClosed: boolean;
|
|
115
|
-
readonly artifact: ArtifactReference;
|
|
116
|
-
readonly cleanupVerified?: boolean | undefined;
|
|
117
|
-
}
|
|
118
|
-
export interface OwnerScoped {
|
|
119
|
-
readonly ownerId: string;
|
|
120
|
-
}
|
|
121
|
-
export interface StartRequest extends OwnerScoped {
|
|
122
|
-
readonly command: string;
|
|
123
|
-
readonly cwd?: string | undefined;
|
|
124
|
-
readonly terminalMode?: TerminalMode | undefined;
|
|
125
|
-
readonly columns?: number | undefined;
|
|
126
|
-
readonly rows?: number | undefined;
|
|
127
|
-
readonly idleTimeoutMs?: number | undefined;
|
|
128
|
-
readonly lifetimeTimeoutMs?: number | undefined;
|
|
129
|
-
readonly deadlineMs?: number | undefined;
|
|
130
|
-
readonly signal?: AbortSignal | undefined;
|
|
131
|
-
}
|
|
132
|
-
export interface SendRequest extends OwnerScoped {
|
|
133
|
-
readonly id: string;
|
|
134
|
-
readonly input: SessionInput;
|
|
135
|
-
readonly cursor?: number | undefined;
|
|
136
|
-
readonly quietMs?: number | undefined;
|
|
137
|
-
readonly deadlineMs?: number | undefined;
|
|
138
|
-
readonly view?: OutputView | undefined;
|
|
139
|
-
readonly signal?: AbortSignal | undefined;
|
|
140
|
-
}
|
|
141
|
-
export interface ReadRequest extends OwnerScoped {
|
|
142
|
-
readonly id: string;
|
|
143
|
-
readonly cursor: number;
|
|
144
|
-
readonly waitMs?: number | undefined;
|
|
145
|
-
readonly view?: OutputView | undefined;
|
|
146
|
-
readonly signal?: AbortSignal | undefined;
|
|
147
|
-
}
|
|
148
|
-
export interface ResizeRequest extends OwnerScoped, TerminalDimensions {
|
|
149
|
-
readonly id: string;
|
|
150
|
-
}
|
|
151
|
-
export interface CloseRequest extends OwnerScoped {
|
|
152
|
-
readonly id: string;
|
|
153
|
-
readonly deadlineMs?: number | undefined;
|
|
154
|
-
}
|
|
155
|
-
export interface StartResult {
|
|
156
|
-
readonly operation: "start";
|
|
157
|
-
readonly sessionId: string;
|
|
158
|
-
readonly state: SessionState;
|
|
159
|
-
readonly transport: SessionTransportKind;
|
|
160
|
-
readonly dimensions?: TerminalDimensions | undefined;
|
|
161
|
-
readonly degradedReason?: "PTY_UNAVAILABLE" | undefined;
|
|
162
|
-
readonly cursor: number;
|
|
163
|
-
readonly artifact: ArtifactReference;
|
|
164
|
-
readonly retriedLaunch?: boolean | undefined;
|
|
165
|
-
}
|
|
166
|
-
export type DeliveryStatus = "delivered" | "not-delivered" | "unknown";
|
|
167
|
-
export interface SendResult {
|
|
168
|
-
readonly operation: "send";
|
|
169
|
-
readonly sessionId: string;
|
|
170
|
-
readonly inputSequence: number;
|
|
171
|
-
readonly delivery: DeliveryStatus;
|
|
172
|
-
readonly deliveredBytes: number;
|
|
173
|
-
readonly state: SessionState;
|
|
174
|
-
readonly page?: OutputPage | undefined;
|
|
175
|
-
readonly error?: StableError | undefined;
|
|
176
|
-
}
|
|
177
|
-
export interface ReadResult {
|
|
178
|
-
readonly operation: "read";
|
|
179
|
-
readonly sessionId: string;
|
|
180
|
-
readonly state: SessionState;
|
|
181
|
-
readonly page?: OutputPage | undefined;
|
|
182
|
-
readonly error?: StableError | undefined;
|
|
183
|
-
}
|
|
184
|
-
export interface StatusResult {
|
|
185
|
-
readonly operation: "status";
|
|
186
|
-
readonly session: SessionSummary;
|
|
187
|
-
}
|
|
188
|
-
export interface ListResult {
|
|
189
|
-
readonly operation: "list";
|
|
190
|
-
readonly sessions: readonly SessionSummary[];
|
|
191
|
-
}
|
|
192
|
-
export interface ResizeResult {
|
|
193
|
-
readonly operation: "resize";
|
|
194
|
-
readonly sessionId: string;
|
|
195
|
-
readonly state: SessionState;
|
|
196
|
-
readonly dimensions: TerminalDimensions;
|
|
197
|
-
}
|
|
198
|
-
export interface CloseResult {
|
|
199
|
-
readonly operation: "close";
|
|
200
|
-
readonly sessionId: string;
|
|
201
|
-
readonly state: SessionState;
|
|
202
|
-
readonly terminationReason?: TerminationReason | undefined;
|
|
203
|
-
readonly processOutcome?: ProcessOutcome | undefined;
|
|
204
|
-
readonly cleanupVerified: boolean;
|
|
205
|
-
readonly artifact: ArtifactReference;
|
|
206
|
-
readonly error?: StableError | undefined;
|
|
207
|
-
}
|
|
208
|
-
export interface CloseOwnerResult {
|
|
209
|
-
readonly closed: number;
|
|
210
|
-
readonly failures: readonly StableError[];
|
|
211
|
-
}
|
|
212
|
-
export interface CloseAllResult extends CloseOwnerResult {
|
|
213
|
-
readonly owners: number;
|
|
214
|
-
}
|
|
215
|
-
export type InteractiveSessionToolResult = StartResult | SendResult | ReadResult | StatusResult | ListResult | ResizeResult | CloseResult;
|
|
216
|
-
export declare const STABLE_ERROR_CODES: readonly ["INVALID_REQUEST", "INVALID_CONFIGURATION", "SESSION_NOT_FOUND", "LIMIT_REACHED", "PTY_UNAVAILABLE", "SESSION_NOT_RUNNING", "SESSION_CLOSING", "INPUT_CLOSED", "INPUT_REJECTED", "INPUT_DELIVERY_UNKNOWN", "UNSUPPORTED_CONTROL", "UNSUPPORTED_OPERATION", "BACKPRESSURE", "DEADLINE_EXCEEDED", "CANCELLED", "OUTPUT_GAP", "LAUNCH_FAILED", "PERSIST_FAILED", "CLEANUP_FAILED"];
|
|
217
|
-
export type StableErrorCode = (typeof STABLE_ERROR_CODES)[number];
|
|
218
|
-
export type StableErrorDetailValue = string | number | boolean;
|
|
219
|
-
/**
|
|
220
|
-
* Detail keys are allowlisted so a native error, command line, or output byte
|
|
221
|
-
* can never reach a model, transcript, or log through an error payload.
|
|
222
|
-
*/
|
|
223
|
-
export declare const STABLE_ERROR_DETAIL_KEYS: readonly ["earliestAvailableCursor", "latestCursor", "requestedCursor", "omittedBytes", "deliveredBytes", "queuedBytes", "limitBytes", "liveSessions", "limit", "inputSequence", "control", "transport", "terminalMode", "field", "columns", "rows", "elapsedMs", "deadlineMs", "survivingDescendants", "cleanupVerified", "terminationReason", "reason", "artifactPath"];
|
|
224
|
-
export type StableErrorDetailKey = (typeof STABLE_ERROR_DETAIL_KEYS)[number];
|
|
225
|
-
export interface StableError {
|
|
226
|
-
readonly code: StableErrorCode;
|
|
227
|
-
readonly message: string;
|
|
228
|
-
readonly retryable: boolean;
|
|
229
|
-
readonly operation: SessionOperation;
|
|
230
|
-
readonly sessionId?: string | undefined;
|
|
231
|
-
readonly state?: SessionState | undefined;
|
|
232
|
-
readonly details?: Readonly<Partial<Record<StableErrorDetailKey, StableErrorDetailValue>>> | undefined;
|
|
233
|
-
}
|
|
234
|
-
export interface SessionErrorInit {
|
|
235
|
-
readonly code: StableErrorCode;
|
|
236
|
-
readonly operation: SessionOperation;
|
|
237
|
-
readonly message: string;
|
|
238
|
-
readonly sessionId?: string | undefined;
|
|
239
|
-
readonly state?: SessionState | undefined;
|
|
240
|
-
readonly details?: Readonly<Partial<Record<StableErrorDetailKey, StableErrorDetailValue>>> | undefined;
|
|
241
|
-
/** Only `LAUNCH_FAILED` and `PERSIST_FAILED` may set this explicitly. */
|
|
242
|
-
readonly retryable?: boolean | undefined;
|
|
243
|
-
}
|
|
244
|
-
/** Single construction point for every interactive-session failure. */
|
|
245
|
-
export declare function sessionError(init: SessionErrorInit): StableError;
|
|
246
|
-
/** Carrier so internal layers can reject with a StableError and be unwrapped. */
|
|
247
|
-
export declare class SessionErrorException extends Error {
|
|
248
|
-
readonly stable: StableError;
|
|
249
|
-
constructor(stable: StableError);
|
|
250
|
-
}
|
|
251
|
-
export declare function throwSessionError(init: SessionErrorInit): never;
|
|
252
|
-
export declare function asStableError(value: unknown, fallback: SessionErrorInit): StableError;
|
|
253
|
-
export declare function toSummary(record: InteractiveSessionRecord): SessionSummary;
|
|
254
|
-
export declare function artifactReference(receipt: ArtifactReceipt): ArtifactReference;
|
|
@@ -1,191 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Public domain contracts for agent-controlled interactive terminal sessions.
|
|
3
|
-
*
|
|
4
|
-
* Deliberate non-goals encoded here: no user keyboard passthrough, no transfer
|
|
5
|
-
* of the host controlling terminal, no reattachment after restart, no screen
|
|
6
|
-
* emulation, and no command rewriting. Nothing in this module carries raw
|
|
7
|
-
* commands, input bytes, environment values, or unredacted output.
|
|
8
|
-
*/
|
|
9
|
-
export const TERMINAL_SESSION_STATES = [
|
|
10
|
-
"exited",
|
|
11
|
-
"failed",
|
|
12
|
-
"closed",
|
|
13
|
-
];
|
|
14
|
-
export function isTerminalState(state) {
|
|
15
|
-
return TERMINAL_SESSION_STATES.includes(state);
|
|
16
|
-
}
|
|
17
|
-
export const CONTROL_INPUTS = [
|
|
18
|
-
"interrupt",
|
|
19
|
-
"eof",
|
|
20
|
-
"suspend",
|
|
21
|
-
"escape",
|
|
22
|
-
"tab",
|
|
23
|
-
"backspace",
|
|
24
|
-
"up",
|
|
25
|
-
"down",
|
|
26
|
-
"left",
|
|
27
|
-
"right",
|
|
28
|
-
];
|
|
29
|
-
// --- Stable errors -----------------------------------------------------
|
|
30
|
-
export const STABLE_ERROR_CODES = [
|
|
31
|
-
"INVALID_REQUEST",
|
|
32
|
-
"INVALID_CONFIGURATION",
|
|
33
|
-
"SESSION_NOT_FOUND",
|
|
34
|
-
"LIMIT_REACHED",
|
|
35
|
-
"PTY_UNAVAILABLE",
|
|
36
|
-
"SESSION_NOT_RUNNING",
|
|
37
|
-
"SESSION_CLOSING",
|
|
38
|
-
"INPUT_CLOSED",
|
|
39
|
-
"INPUT_REJECTED",
|
|
40
|
-
"INPUT_DELIVERY_UNKNOWN",
|
|
41
|
-
"UNSUPPORTED_CONTROL",
|
|
42
|
-
"UNSUPPORTED_OPERATION",
|
|
43
|
-
"BACKPRESSURE",
|
|
44
|
-
"DEADLINE_EXCEEDED",
|
|
45
|
-
"CANCELLED",
|
|
46
|
-
"OUTPUT_GAP",
|
|
47
|
-
"LAUNCH_FAILED",
|
|
48
|
-
"PERSIST_FAILED",
|
|
49
|
-
"CLEANUP_FAILED",
|
|
50
|
-
];
|
|
51
|
-
/**
|
|
52
|
-
* Detail keys are allowlisted so a native error, command line, or output byte
|
|
53
|
-
* can never reach a model, transcript, or log through an error payload.
|
|
54
|
-
*/
|
|
55
|
-
export const STABLE_ERROR_DETAIL_KEYS = [
|
|
56
|
-
"earliestAvailableCursor",
|
|
57
|
-
"latestCursor",
|
|
58
|
-
"requestedCursor",
|
|
59
|
-
"omittedBytes",
|
|
60
|
-
"deliveredBytes",
|
|
61
|
-
"queuedBytes",
|
|
62
|
-
"limitBytes",
|
|
63
|
-
"liveSessions",
|
|
64
|
-
"limit",
|
|
65
|
-
"inputSequence",
|
|
66
|
-
"control",
|
|
67
|
-
"transport",
|
|
68
|
-
"terminalMode",
|
|
69
|
-
"field",
|
|
70
|
-
"columns",
|
|
71
|
-
"rows",
|
|
72
|
-
"elapsedMs",
|
|
73
|
-
"deadlineMs",
|
|
74
|
-
"survivingDescendants",
|
|
75
|
-
"cleanupVerified",
|
|
76
|
-
"terminationReason",
|
|
77
|
-
"reason",
|
|
78
|
-
"artifactPath",
|
|
79
|
-
];
|
|
80
|
-
const MAX_ERROR_MESSAGE_CHARS = 400;
|
|
81
|
-
const MAX_ERROR_DETAIL_CHARS = 120;
|
|
82
|
-
/**
|
|
83
|
-
* Retryability describes whether a fresh caller-decided attempt could help. It
|
|
84
|
-
* never authorizes an automatic retry, and it is false for every code whose
|
|
85
|
-
* failure could already have produced a process or input side effect.
|
|
86
|
-
*/
|
|
87
|
-
const NON_RETRYABLE_CODES = new Set([
|
|
88
|
-
"INVALID_REQUEST",
|
|
89
|
-
"INVALID_CONFIGURATION",
|
|
90
|
-
"SESSION_NOT_FOUND",
|
|
91
|
-
"PTY_UNAVAILABLE",
|
|
92
|
-
"SESSION_NOT_RUNNING",
|
|
93
|
-
"SESSION_CLOSING",
|
|
94
|
-
"INPUT_CLOSED",
|
|
95
|
-
"INPUT_REJECTED",
|
|
96
|
-
"INPUT_DELIVERY_UNKNOWN",
|
|
97
|
-
"UNSUPPORTED_CONTROL",
|
|
98
|
-
"UNSUPPORTED_OPERATION",
|
|
99
|
-
"DEADLINE_EXCEEDED",
|
|
100
|
-
"CANCELLED",
|
|
101
|
-
"OUTPUT_GAP",
|
|
102
|
-
"CLEANUP_FAILED",
|
|
103
|
-
]);
|
|
104
|
-
const RETRYABLE_CODES = new Set([
|
|
105
|
-
"LIMIT_REACHED",
|
|
106
|
-
"BACKPRESSURE",
|
|
107
|
-
]);
|
|
108
|
-
function boundDetailValue(value) {
|
|
109
|
-
if (typeof value !== "string")
|
|
110
|
-
return value;
|
|
111
|
-
return value.length > MAX_ERROR_DETAIL_CHARS
|
|
112
|
-
? `${value.slice(0, MAX_ERROR_DETAIL_CHARS)}…`
|
|
113
|
-
: value;
|
|
114
|
-
}
|
|
115
|
-
function resolveRetryable(init) {
|
|
116
|
-
if (NON_RETRYABLE_CODES.has(init.code))
|
|
117
|
-
return false;
|
|
118
|
-
if (RETRYABLE_CODES.has(init.code))
|
|
119
|
-
return init.retryable ?? true;
|
|
120
|
-
// LAUNCH_FAILED / PERSIST_FAILED are retryable only when the caller proved no
|
|
121
|
-
// process side effect was possible.
|
|
122
|
-
return init.retryable ?? false;
|
|
123
|
-
}
|
|
124
|
-
/** Single construction point for every interactive-session failure. */
|
|
125
|
-
export function sessionError(init) {
|
|
126
|
-
const details = {};
|
|
127
|
-
for (const key of STABLE_ERROR_DETAIL_KEYS) {
|
|
128
|
-
const value = init.details?.[key];
|
|
129
|
-
if (value !== undefined)
|
|
130
|
-
details[key] = boundDetailValue(value);
|
|
131
|
-
}
|
|
132
|
-
const message = init.message.length > MAX_ERROR_MESSAGE_CHARS
|
|
133
|
-
? `${init.message.slice(0, MAX_ERROR_MESSAGE_CHARS)}…`
|
|
134
|
-
: init.message;
|
|
135
|
-
return {
|
|
136
|
-
code: init.code,
|
|
137
|
-
message,
|
|
138
|
-
retryable: resolveRetryable(init),
|
|
139
|
-
operation: init.operation,
|
|
140
|
-
...(init.sessionId !== undefined ? { sessionId: init.sessionId } : {}),
|
|
141
|
-
...(init.state !== undefined ? { state: init.state } : {}),
|
|
142
|
-
...(Object.keys(details).length > 0 ? { details } : {}),
|
|
143
|
-
};
|
|
144
|
-
}
|
|
145
|
-
/** Carrier so internal layers can reject with a StableError and be unwrapped. */
|
|
146
|
-
export class SessionErrorException extends Error {
|
|
147
|
-
stable;
|
|
148
|
-
constructor(stable) {
|
|
149
|
-
super(stable.message);
|
|
150
|
-
this.stable = stable;
|
|
151
|
-
this.name = "SessionErrorException";
|
|
152
|
-
}
|
|
153
|
-
}
|
|
154
|
-
export function throwSessionError(init) {
|
|
155
|
-
throw new SessionErrorException(sessionError(init));
|
|
156
|
-
}
|
|
157
|
-
export function asStableError(value, fallback) {
|
|
158
|
-
return value instanceof SessionErrorException
|
|
159
|
-
? value.stable
|
|
160
|
-
: sessionError(fallback);
|
|
161
|
-
}
|
|
162
|
-
export function toSummary(record) {
|
|
163
|
-
return {
|
|
164
|
-
id: record.id,
|
|
165
|
-
state: record.state,
|
|
166
|
-
transport: record.transport,
|
|
167
|
-
startedAt: record.startedAt,
|
|
168
|
-
lastActivityAt: record.lastActivityAt,
|
|
169
|
-
...(record.endedAt !== undefined ? { endedAt: record.endedAt } : {}),
|
|
170
|
-
...(record.dimensions ? { dimensions: { ...record.dimensions } } : {}),
|
|
171
|
-
...(record.degradedReason ? { degradedReason: record.degradedReason } : {}),
|
|
172
|
-
...(record.processOutcome ? { processOutcome: { ...record.processOutcome } } : {}),
|
|
173
|
-
...(record.terminationReason ? { terminationReason: record.terminationReason } : {}),
|
|
174
|
-
earliestCursor: record.earliestCursor,
|
|
175
|
-
latestCursor: record.latestCursor,
|
|
176
|
-
inputClosed: record.inputClosed,
|
|
177
|
-
artifact: artifactReference(record.artifact),
|
|
178
|
-
...(record.cleanupVerified !== undefined
|
|
179
|
-
? { cleanupVerified: record.cleanupVerified }
|
|
180
|
-
: {}),
|
|
181
|
-
};
|
|
182
|
-
}
|
|
183
|
-
export function artifactReference(receipt) {
|
|
184
|
-
return {
|
|
185
|
-
path: receipt.path,
|
|
186
|
-
bytes: receipt.bytes,
|
|
187
|
-
droppedBytes: receipt.droppedBytes,
|
|
188
|
-
redacted: receipt.redacted,
|
|
189
|
-
};
|
|
190
|
-
}
|
|
191
|
-
//# sourceMappingURL=types.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/interactive-session/types.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAmBH,MAAM,CAAC,MAAM,uBAAuB,GAA4B;IAC9D,QAAQ;IACR,QAAQ;IACR,QAAQ;CACT,CAAC;AAEF,MAAM,UAAU,eAAe,CAAC,KAAmB;IACjD,OAAO,uBAAuB,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC;AACjD,CAAC;AAmCD,MAAM,CAAC,MAAM,cAAc,GAA4B;IACrD,WAAW;IACX,KAAK;IACL,SAAS;IACT,QAAQ;IACR,KAAK;IACL,WAAW;IACX,IAAI;IACJ,MAAM;IACN,MAAM;IACN,OAAO;CACR,CAAC;AA0OF,0EAA0E;AAE1E,MAAM,CAAC,MAAM,kBAAkB,GAAG;IAChC,iBAAiB;IACjB,uBAAuB;IACvB,mBAAmB;IACnB,eAAe;IACf,iBAAiB;IACjB,qBAAqB;IACrB,iBAAiB;IACjB,cAAc;IACd,gBAAgB;IAChB,wBAAwB;IACxB,qBAAqB;IACrB,uB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,cAAc,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;QAC3E,GAAG,CAAC,MAAM,CAAC,cAAc,CAAC,CAAC,CAAC,EAAE,cAAc,EAAE,EAAE,GAAG,MAAM,CAAC,cAAc,EAAE,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;QAClF,GAAG,CAAC,MAAM,CAAC,iBAAiB,CAAC,CAAC,CAAC,EAAE,iBAAiB,EAAE,MAAM,CAAC,iBAAiB,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;QACpF,cAAc,EAAE,MAAM,CAAC,cAAc;QACrC,YAAY,EAAE,MAAM,CAAC,YAAY;QACjC,WAAW,EAAE,MAAM,CAAC,WAAW;QAC/B,QAAQ,EAAE,iBAAiB,CAAC,MAAM,CAAC,QAAQ,CAAC;QAC5C,GAAG,CAAC,MAAM,CAAC,eAAe,KAAK,SAAS;YACtC,CAAC,CAAC,EAAE,eAAe,EAAE,MAAM,CAAC,eAAe,EAAE;YAC7C,CAAC,CAAC,EAAE,CAAC;KACR,CAAC;AACJ,CAAC;AAED,MAAM,UAAU,iBAAiB,CAAC,OAAwB;IACxD,OAAO;QACL,IAAI,EAAE,OAAO,CAAC,IAAI;QAClB,KAAK,EAAE,OAAO,CAAC,KAAK;QACpB,YAAY,EAAE,OAAO,CAAC,YAAY;QAClC,QAAQ,EAAE,OAAO,CAAC,QAAQ;KAC3B,CAAC;AACJ,CAAC"}
|
|
@@ -1,46 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Cross-platform process identity: hashed evidence that a pid still refers to
|
|
3
|
-
* the process we launched, so a recycled pid can never be signalled by cleanup
|
|
4
|
-
* or startup reconciliation.
|
|
5
|
-
*
|
|
6
|
-
* Evidence is a process start time only. The command line is deliberately
|
|
7
|
-
* excluded because `sh -c "cmd"` execs into `cmd`, mutating `ps command=`
|
|
8
|
-
* mid-run and making a live process fail its own identity check.
|
|
9
|
-
*/
|
|
10
|
-
export type ProcessIdentityComparison = "match" | "mismatch" | "gone" | "unknown";
|
|
11
|
-
/** Raw start-time evidence provider. Injected so platforms and tests differ. */
|
|
12
|
-
export interface ProcessIdentityProvider {
|
|
13
|
-
readonly platform: NodeJS.Platform | "test";
|
|
14
|
-
/** Raw, unhashed evidence, or undefined when it cannot be read. */
|
|
15
|
-
capture(pid: number): string | undefined;
|
|
16
|
-
}
|
|
17
|
-
export declare const defaultProcessIdentityProvider: ProcessIdentityProvider;
|
|
18
|
-
export declare class ProcessIdentityTracker {
|
|
19
|
-
private readonly provider;
|
|
20
|
-
private readonly now;
|
|
21
|
-
private readonly alive;
|
|
22
|
-
private readonly cache;
|
|
23
|
-
constructor(provider?: ProcessIdentityProvider, now?: () => number, alive?: (pid: number | undefined) => boolean);
|
|
24
|
-
/** Hashed identity for a pid, or undefined when evidence is unavailable. */
|
|
25
|
-
capture(pid: number | undefined, options?: {
|
|
26
|
-
refresh?: boolean;
|
|
27
|
-
}): string | undefined;
|
|
28
|
-
/**
|
|
29
|
-
* Compare a recorded identity against the live process. `unknown` never
|
|
30
|
-
* authorizes signalling: evidence was unreadable, so ownership is unproven.
|
|
31
|
-
*/
|
|
32
|
-
compare(pid: number | undefined, expected: string | undefined): ProcessIdentityComparison;
|
|
33
|
-
forget(pid: number | undefined): void;
|
|
34
|
-
private prune;
|
|
35
|
-
}
|
|
36
|
-
/** Shared tracker used by the job manager and interactive sessions. */
|
|
37
|
-
export declare const processIdentityTracker: ProcessIdentityTracker;
|
|
38
|
-
/**
|
|
39
|
-
* Legacy-compatible helper. Windows returns undefined here because the job
|
|
40
|
-
* manager's existing liveness contract treats an absent identity as "unproven"
|
|
41
|
-
* and must keep behaving exactly as before this extraction.
|
|
42
|
-
*/
|
|
43
|
-
export declare function processIdentity(pid: number | undefined, options?: {
|
|
44
|
-
refresh?: boolean;
|
|
45
|
-
}): string | undefined;
|
|
46
|
-
export declare function forgetProcessIdentity(pid: number | undefined): void;
|
|
@@ -1,147 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Cross-platform process identity: hashed evidence that a pid still refers to
|
|
3
|
-
* the process we launched, so a recycled pid can never be signalled by cleanup
|
|
4
|
-
* or startup reconciliation.
|
|
5
|
-
*
|
|
6
|
-
* Evidence is a process start time only. The command line is deliberately
|
|
7
|
-
* excluded because `sh -c "cmd"` execs into `cmd`, mutating `ps command=`
|
|
8
|
-
* mid-run and making a live process fail its own identity check.
|
|
9
|
-
*/
|
|
10
|
-
import { execFileSync } from "node:child_process";
|
|
11
|
-
import { createHash } from "node:crypto";
|
|
12
|
-
import { readFileSync } from "node:fs";
|
|
13
|
-
import { processAlive } from "./process-tree.js";
|
|
14
|
-
const IDENTITY_TTL_MS = 15_000;
|
|
15
|
-
const IDENTITY_CACHE_MAX = 512;
|
|
16
|
-
const PROBE_TIMEOUT_MS = 2_000;
|
|
17
|
-
function hashEvidence(raw) {
|
|
18
|
-
return createHash("sha256").update(raw).digest("hex");
|
|
19
|
-
}
|
|
20
|
-
function readLinuxProcessStart(pid) {
|
|
21
|
-
try {
|
|
22
|
-
const raw = readFileSync(`/proc/${pid}/stat`, "utf8");
|
|
23
|
-
const commEnd = raw.lastIndexOf(")");
|
|
24
|
-
if (commEnd < 0)
|
|
25
|
-
return undefined;
|
|
26
|
-
const fields = raw.slice(commEnd + 2).trim().split(/\s+/);
|
|
27
|
-
// Evidence format is intentionally identical to the pre-extraction job
|
|
28
|
-
// manager so persisted registry identities keep comparing equal.
|
|
29
|
-
const startTime = fields[19];
|
|
30
|
-
return startTime && startTime.length > 0 ? startTime : undefined;
|
|
31
|
-
}
|
|
32
|
-
catch {
|
|
33
|
-
return undefined;
|
|
34
|
-
}
|
|
35
|
-
}
|
|
36
|
-
function readPsProcessStart(pid) {
|
|
37
|
-
try {
|
|
38
|
-
const raw = execFileSync("ps", ["-p", String(pid), "-o", "lstart="], {
|
|
39
|
-
encoding: "utf8",
|
|
40
|
-
timeout: PROBE_TIMEOUT_MS,
|
|
41
|
-
stdio: ["ignore", "pipe", "ignore"],
|
|
42
|
-
}).trim();
|
|
43
|
-
return raw.length > 0 ? raw : undefined;
|
|
44
|
-
}
|
|
45
|
-
catch {
|
|
46
|
-
return undefined;
|
|
47
|
-
}
|
|
48
|
-
}
|
|
49
|
-
function readWindowsProcessStart(pid) {
|
|
50
|
-
const query = `(Get-CimInstance Win32_Process -Filter "ProcessId=${pid}").CreationDate`;
|
|
51
|
-
for (const shell of ["powershell.exe", "pwsh.exe"]) {
|
|
52
|
-
try {
|
|
53
|
-
const raw = execFileSync(shell, ["-NoProfile", "-NonInteractive", "-Command", query], {
|
|
54
|
-
encoding: "utf8",
|
|
55
|
-
timeout: PROBE_TIMEOUT_MS,
|
|
56
|
-
windowsHide: true,
|
|
57
|
-
stdio: ["ignore", "pipe", "ignore"],
|
|
58
|
-
}).trim();
|
|
59
|
-
if (raw.length > 0)
|
|
60
|
-
return raw;
|
|
61
|
-
}
|
|
62
|
-
catch {
|
|
63
|
-
// Try the next shell; an unavailable query yields `unknown`, not a match.
|
|
64
|
-
}
|
|
65
|
-
}
|
|
66
|
-
return undefined;
|
|
67
|
-
}
|
|
68
|
-
export const defaultProcessIdentityProvider = {
|
|
69
|
-
platform: process.platform,
|
|
70
|
-
capture(pid) {
|
|
71
|
-
if (process.platform === "linux")
|
|
72
|
-
return readLinuxProcessStart(pid);
|
|
73
|
-
if (process.platform === "win32")
|
|
74
|
-
return readWindowsProcessStart(pid);
|
|
75
|
-
return readPsProcessStart(pid);
|
|
76
|
-
},
|
|
77
|
-
};
|
|
78
|
-
export class ProcessIdentityTracker {
|
|
79
|
-
provider;
|
|
80
|
-
now;
|
|
81
|
-
alive;
|
|
82
|
-
cache = new Map();
|
|
83
|
-
constructor(provider = defaultProcessIdentityProvider, now = Date.now, alive = processAlive) {
|
|
84
|
-
this.provider = provider;
|
|
85
|
-
this.now = now;
|
|
86
|
-
this.alive = alive;
|
|
87
|
-
}
|
|
88
|
-
/** Hashed identity for a pid, or undefined when evidence is unavailable. */
|
|
89
|
-
capture(pid, options = {}) {
|
|
90
|
-
if (!pid || pid <= 0)
|
|
91
|
-
return undefined;
|
|
92
|
-
const now = this.now();
|
|
93
|
-
const cached = this.cache.get(pid);
|
|
94
|
-
if (cached && !options.refresh && now - cached.at < IDENTITY_TTL_MS) {
|
|
95
|
-
return cached.value;
|
|
96
|
-
}
|
|
97
|
-
const raw = this.provider.capture(pid);
|
|
98
|
-
const value = raw ? hashEvidence(raw) : undefined;
|
|
99
|
-
this.cache.set(pid, { value, at: now });
|
|
100
|
-
this.prune(now);
|
|
101
|
-
return value;
|
|
102
|
-
}
|
|
103
|
-
/**
|
|
104
|
-
* Compare a recorded identity against the live process. `unknown` never
|
|
105
|
-
* authorizes signalling: evidence was unreadable, so ownership is unproven.
|
|
106
|
-
*/
|
|
107
|
-
compare(pid, expected) {
|
|
108
|
-
if (!pid || pid <= 0)
|
|
109
|
-
return "gone";
|
|
110
|
-
if (!this.alive(pid))
|
|
111
|
-
return "gone";
|
|
112
|
-
const current = this.capture(pid, { refresh: true });
|
|
113
|
-
if (!current || !expected)
|
|
114
|
-
return "unknown";
|
|
115
|
-
return current === expected ? "match" : "mismatch";
|
|
116
|
-
}
|
|
117
|
-
forget(pid) {
|
|
118
|
-
if (pid)
|
|
119
|
-
this.cache.delete(pid);
|
|
120
|
-
}
|
|
121
|
-
prune(now) {
|
|
122
|
-
if (this.cache.size <= IDENTITY_CACHE_MAX)
|
|
123
|
-
return;
|
|
124
|
-
for (const [pid, entry] of this.cache) {
|
|
125
|
-
if (now - entry.at >= IDENTITY_TTL_MS)
|
|
126
|
-
this.cache.delete(pid);
|
|
127
|
-
}
|
|
128
|
-
if (this.cache.size > IDENTITY_CACHE_MAX)
|
|
129
|
-
this.cache.clear();
|
|
130
|
-
}
|
|
131
|
-
}
|
|
132
|
-
/** Shared tracker used by the job manager and interactive sessions. */
|
|
133
|
-
export const processIdentityTracker = new ProcessIdentityTracker();
|
|
134
|
-
/**
|
|
135
|
-
* Legacy-compatible helper. Windows returns undefined here because the job
|
|
136
|
-
* manager's existing liveness contract treats an absent identity as "unproven"
|
|
137
|
-
* and must keep behaving exactly as before this extraction.
|
|
138
|
-
*/
|
|
139
|
-
export function processIdentity(pid, options = {}) {
|
|
140
|
-
if (process.platform === "win32")
|
|
141
|
-
return undefined;
|
|
142
|
-
return processIdentityTracker.capture(pid, options);
|
|
143
|
-
}
|
|
144
|
-
export function forgetProcessIdentity(pid) {
|
|
145
|
-
processIdentityTracker.forget(pid);
|
|
146
|
-
}
|
|
147
|
-
//# sourceMappingURL=process-identity.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"process-identity.js","sourceRoot":"","sources":["../../src/os/process-identity.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,OAAO,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAClD,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AACzC,OAAO,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AACvC,OAAO,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAC;AAWjD,MAAM,eAAe,GAAG,MAAM,CAAC;AAC/B,MAAM,kBAAkB,GAAG,GAAG,CAAC;AAC/B,MAAM,gBAAgB,GAAG,KAAK,CAAC;AAE/B,SAAS,YAAY,CAAC,GAAW;IAC/B,OAAO,UAAU,CAAC,QAAQ,CAAC,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;AACxD,CAAC;AAED,SAAS,qBAAqB,CAAC,GAAW;IACxC,IAAI,CAAC;QACH,MAAM,GAAG,GAAG,YAAY,CAAC,SAAS,GAAG,OAAO,EAAE,MAAM,CAAC,CAAC;QACtD,MAAM,OAAO,GAAG,GAAG,CAAC,WAAW,CAAC,GAAG,CAAC,CAAC;QACrC,IAAI,OAAO,GAAG,CAAC;YAAE,OAAO,SAAS,CAAC;QAClC,MAAM,MAAM,GAAG,GAAG,CAAC,KAAK,CAAC,OAAO,GAAG,CAAC,CAAC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CAAC,KAAK,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC;QAChE,CAAC;QACD,IAAI,IAAI,CAAC,KAAK,CAAC,IAAI,GAAG,kBAAkB;YAAE,IAAI,CAAC,KAAK,CAAC,KAAK,EAAE,CAAC;IAC/D,CAAC;CACF;AAED,uEAAuE;AACvE,MAAM,CAAC,MAAM,sBAAsB,GAAG,IAAI,sBAAsB,EAAE,CAAC;AAEnE;;;;GAIG;AACH,MAAM,UAAU,eAAe,CAC7B,GAAuB,EACvB,UAAiC,EAAE;IAEnC,IAAI,OAAO,CAAC,QAAQ,KAAK,OAAO;QAAE,OAAO,SAAS,CAAC;IACnD,OAAO,sBAAsB,CAAC,OAAO,CAAC,GAAG,EAAE,OAAO,CAAC,CAAC;AACtD,CAAC;AAED,MAAM,UAAU,qBAAqB,CAAC,GAAuB;IAC3D,sBAAsB,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC;AACrC,CAAC"}
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Tool adapter for the seven additive `terminal.*` operations.
|
|
3
|
-
*
|
|
4
|
-
* Existing shell and job tools are untouched. Every handler requires an owning
|
|
5
|
-
* conversation id, projects a concise ANSI-free `output` for providers and
|
|
6
|
-
* transcripts, and returns the structured result under `interactiveSession`.
|
|
7
|
-
*/
|
|
8
|
-
import { InteractiveSessionManager } from "../interactive-session/manager.js";
|
|
9
|
-
import type { ToolHandler } from "./tool-types.js";
|
|
10
|
-
export declare const INTERACTIVE_SESSION_TOOL_NAMES: readonly ["terminal.start", "terminal.send", "terminal.read", "terminal.status", "terminal.list", "terminal.resize", "terminal.close"];
|
|
11
|
-
export declare function createInteractiveSessionHandlers(manager?: InteractiveSessionManager): Record<(typeof INTERACTIVE_SESSION_TOOL_NAMES)[number], ToolHandler>;
|