@johannes.latzel/llm-chat-shell 0.1.0
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/LICENSE +7 -0
- package/README.md +43 -0
- package/dist/index.d.ts +9 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +9 -0
- package/dist/index.js.map +1 -0
- package/dist/lib/bash-executor.d.ts +125 -0
- package/dist/lib/bash-executor.d.ts.map +1 -0
- package/dist/lib/bash-executor.js +314 -0
- package/dist/lib/bash-executor.js.map +1 -0
- package/dist/lib/config.d.ts +79 -0
- package/dist/lib/config.d.ts.map +1 -0
- package/dist/lib/config.js +216 -0
- package/dist/lib/config.js.map +1 -0
- package/dist/lib/env.d.ts +34 -0
- package/dist/lib/env.d.ts.map +1 -0
- package/dist/lib/env.js +77 -0
- package/dist/lib/env.js.map +1 -0
- package/dist/lib/job-registry.d.ts +55 -0
- package/dist/lib/job-registry.d.ts.map +1 -0
- package/dist/lib/job-registry.js +116 -0
- package/dist/lib/job-registry.js.map +1 -0
- package/dist/lib/permission.d.ts +101 -0
- package/dist/lib/permission.d.ts.map +1 -0
- package/dist/lib/permission.js +361 -0
- package/dist/lib/permission.js.map +1 -0
- package/dist/lib/session-manager.d.ts +148 -0
- package/dist/lib/session-manager.d.ts.map +1 -0
- package/dist/lib/session-manager.js +264 -0
- package/dist/lib/session-manager.js.map +1 -0
- package/dist/lib/session-queue.d.ts +58 -0
- package/dist/lib/session-queue.d.ts.map +1 -0
- package/dist/lib/session-queue.js +123 -0
- package/dist/lib/session-queue.js.map +1 -0
- package/dist/lib/session-registry.d.ts +140 -0
- package/dist/lib/session-registry.d.ts.map +1 -0
- package/dist/lib/session-registry.js +267 -0
- package/dist/lib/session-registry.js.map +1 -0
- package/dist/lib/types.d.ts +155 -0
- package/dist/lib/types.d.ts.map +1 -0
- package/dist/lib/types.js +37 -0
- package/dist/lib/types.js.map +1 -0
- package/dist/tools/shell-command-tool.d.ts +30 -0
- package/dist/tools/shell-command-tool.d.ts.map +1 -0
- package/dist/tools/shell-command-tool.js +138 -0
- package/dist/tools/shell-command-tool.js.map +1 -0
- package/dist/tools/shell-create-tool.d.ts +12 -0
- package/dist/tools/shell-create-tool.d.ts.map +1 -0
- package/dist/tools/shell-create-tool.js +24 -0
- package/dist/tools/shell-create-tool.js.map +1 -0
- package/dist/tools/shell-job-status-tool.d.ts +13 -0
- package/dist/tools/shell-job-status-tool.d.ts.map +1 -0
- package/dist/tools/shell-job-status-tool.js +59 -0
- package/dist/tools/shell-job-status-tool.js.map +1 -0
- package/dist/tools/shell-jobs-tool.d.ts +12 -0
- package/dist/tools/shell-jobs-tool.d.ts.map +1 -0
- package/dist/tools/shell-jobs-tool.js +28 -0
- package/dist/tools/shell-jobs-tool.js.map +1 -0
- package/dist/tools/shell-package.d.ts +54 -0
- package/dist/tools/shell-package.d.ts.map +1 -0
- package/dist/tools/shell-package.js +77 -0
- package/dist/tools/shell-package.js.map +1 -0
- package/dist/tools/shell-permissions-tool.d.ts +15 -0
- package/dist/tools/shell-permissions-tool.d.ts.map +1 -0
- package/dist/tools/shell-permissions-tool.js +38 -0
- package/dist/tools/shell-permissions-tool.js.map +1 -0
- package/package.json +87 -0
|
@@ -0,0 +1,361 @@
|
|
|
1
|
+
import { resolve, sep } from 'node:path';
|
|
2
|
+
import picomatch from 'picomatch';
|
|
3
|
+
import { PermissionAction, PermissionAccess, PermissionDenyReason } from './types.js';
|
|
4
|
+
/**
|
|
5
|
+
* Split a shell command into individual subcommands by shell operators,
|
|
6
|
+
* respecting quoted strings. Operators that trigger a split:
|
|
7
|
+
* - `&&` (logical AND)
|
|
8
|
+
* - `||` (logical OR)
|
|
9
|
+
* - `|` (pipe)
|
|
10
|
+
* - `;` (sequential)
|
|
11
|
+
*
|
|
12
|
+
* After splitting, shell redirects are stripped from each subcommand.
|
|
13
|
+
*
|
|
14
|
+
* @param input - Raw shell command string.
|
|
15
|
+
* @returns Array of individual subcommands (with redirects stripped).
|
|
16
|
+
*/
|
|
17
|
+
export function parseSubcommands(input) {
|
|
18
|
+
const trimmed = input.trim();
|
|
19
|
+
if (trimmed.length === 0)
|
|
20
|
+
return [];
|
|
21
|
+
const subcommands = [];
|
|
22
|
+
let current = '';
|
|
23
|
+
let inQuote = null;
|
|
24
|
+
for (let i = 0; i < trimmed.length; i++) {
|
|
25
|
+
const ch = trimmed[i];
|
|
26
|
+
// Handle escape sequences inside quotes
|
|
27
|
+
if (inQuote !== null && ch === '\\' && i + 1 < trimmed.length) {
|
|
28
|
+
current += ch + trimmed[i + 1];
|
|
29
|
+
i++;
|
|
30
|
+
continue;
|
|
31
|
+
}
|
|
32
|
+
// Handle quote toggling
|
|
33
|
+
if (ch === '"' || ch === "'") {
|
|
34
|
+
current += ch;
|
|
35
|
+
if (inQuote === ch) {
|
|
36
|
+
// Closing quote
|
|
37
|
+
inQuote = null;
|
|
38
|
+
}
|
|
39
|
+
else if (inQuote === null) {
|
|
40
|
+
// Opening quote
|
|
41
|
+
inQuote = ch;
|
|
42
|
+
}
|
|
43
|
+
// Different quote type inside current quote — already added as literal
|
|
44
|
+
continue;
|
|
45
|
+
}
|
|
46
|
+
// Skip processing operators if inside quotes
|
|
47
|
+
if (inQuote !== null) {
|
|
48
|
+
current += ch;
|
|
49
|
+
continue;
|
|
50
|
+
}
|
|
51
|
+
// Check for 2-char operators (&&, ||)
|
|
52
|
+
if (i + 1 < trimmed.length) {
|
|
53
|
+
const two = trimmed.substring(i, i + 2);
|
|
54
|
+
if (two === '&&' || two === '||') {
|
|
55
|
+
const sub = stripRedirects(current.trim());
|
|
56
|
+
if (sub.length > 0)
|
|
57
|
+
subcommands.push(sub);
|
|
58
|
+
current = '';
|
|
59
|
+
i += 1; // skip operator chars
|
|
60
|
+
continue;
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
// Check for 1-char operators (|, ;)
|
|
64
|
+
if (ch === '|' || ch === ';') {
|
|
65
|
+
const sub = stripRedirects(current.trim());
|
|
66
|
+
if (sub.length > 0)
|
|
67
|
+
subcommands.push(sub);
|
|
68
|
+
current = '';
|
|
69
|
+
continue;
|
|
70
|
+
}
|
|
71
|
+
current += ch;
|
|
72
|
+
}
|
|
73
|
+
// Flush remaining buffer
|
|
74
|
+
const sub = stripRedirects(current.trim());
|
|
75
|
+
if (sub.length > 0)
|
|
76
|
+
subcommands.push(sub);
|
|
77
|
+
return subcommands;
|
|
78
|
+
}
|
|
79
|
+
/**
|
|
80
|
+
* Redirect operator patterns, ordered from longest to shortest to avoid
|
|
81
|
+
* partial matches (e.g. `2>&1` before `2>`, `&>` before `>`).
|
|
82
|
+
*/
|
|
83
|
+
const REDIRECT_PATTERNS = [/&>/, /2>&1/, /2>>/, /2>/, />>/, /</, />/];
|
|
84
|
+
/**
|
|
85
|
+
* Skip past a redirect target after the operator has been matched.
|
|
86
|
+
* Handles three target forms:
|
|
87
|
+
* - `&N` — file descriptor target (e.g. `&1`)
|
|
88
|
+
* - `"..."` / `'...'` — quoted filename
|
|
89
|
+
* - unquoted word — bare filename or path
|
|
90
|
+
*
|
|
91
|
+
* @param target - The string immediately after the redirect operator.
|
|
92
|
+
* @returns The remaining string after the target has been consumed.
|
|
93
|
+
*/
|
|
94
|
+
function skipRedirectTarget(target) {
|
|
95
|
+
if (target.length === 0)
|
|
96
|
+
return '';
|
|
97
|
+
const first = target[0];
|
|
98
|
+
if (first === '&') {
|
|
99
|
+
// File descriptor target like `&1` — skip `&` and any trailing digits
|
|
100
|
+
let i = 1;
|
|
101
|
+
while (i < target.length && /\d/.test(target[i]))
|
|
102
|
+
i++;
|
|
103
|
+
return target.substring(i);
|
|
104
|
+
}
|
|
105
|
+
if (first === '"' || first === "'") {
|
|
106
|
+
// Quoted target — find matching close quote, respecting escapes
|
|
107
|
+
let end = 1;
|
|
108
|
+
while (end < target.length && target[end] !== first) {
|
|
109
|
+
if (target[end] === '\\')
|
|
110
|
+
end++;
|
|
111
|
+
end++;
|
|
112
|
+
}
|
|
113
|
+
return target.substring(end + 1);
|
|
114
|
+
}
|
|
115
|
+
// Unquoted target — skip until whitespace
|
|
116
|
+
let end = 0;
|
|
117
|
+
while (end < target.length && /\S/.test(target[end]))
|
|
118
|
+
end++;
|
|
119
|
+
return target.substring(end);
|
|
120
|
+
}
|
|
121
|
+
/**
|
|
122
|
+
* Strip shell redirect operators and their targets from a subcommand.
|
|
123
|
+
* Redirects stripped: >, >>, <, 2>, 2>>, 2>&1, &>
|
|
124
|
+
*
|
|
125
|
+
* @param subcommand - A single subcommand string.
|
|
126
|
+
* @returns The subcommand with redirects removed.
|
|
127
|
+
*/
|
|
128
|
+
function stripRedirects(subcommand) {
|
|
129
|
+
let result = subcommand;
|
|
130
|
+
for (let changed = true; changed;) {
|
|
131
|
+
let earliest = -1;
|
|
132
|
+
let earliestLen = 0;
|
|
133
|
+
for (const pattern of REDIRECT_PATTERNS) {
|
|
134
|
+
const match = result.match(pattern);
|
|
135
|
+
if (match !== null && match.index !== undefined) {
|
|
136
|
+
if (earliest === -1 || match.index < earliest) {
|
|
137
|
+
earliest = match.index;
|
|
138
|
+
earliestLen = match[0].length;
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
if (earliest === -1)
|
|
143
|
+
break;
|
|
144
|
+
const after = skipRedirectTarget(result.substring(earliest + earliestLen).replace(/^\s+/, ''));
|
|
145
|
+
result = result.substring(0, earliest).trim() + after.trim();
|
|
146
|
+
changed = true;
|
|
147
|
+
}
|
|
148
|
+
return result;
|
|
149
|
+
}
|
|
150
|
+
/** Check whether a string matches a glob pattern using picomatch. */
|
|
151
|
+
function matchesPattern(str, pattern) {
|
|
152
|
+
return picomatch.isMatch(str, pattern);
|
|
153
|
+
}
|
|
154
|
+
/**
|
|
155
|
+
* Check whether pattern A "dominates" pattern B, meaning A is more concrete
|
|
156
|
+
* (more specific) than B. This is the primary specificity criterion.
|
|
157
|
+
*
|
|
158
|
+
* A dominates B when A is a literal string (no wildcards) and B as a glob
|
|
159
|
+
* pattern matches A. Intuitively: if B is broad enough to match the literal
|
|
160
|
+
* text of A, then B is more general and A is more concrete.
|
|
161
|
+
*
|
|
162
|
+
* This check only applies when A has no wildcards. When both patterns contain
|
|
163
|
+
* wildcards, the literal-match test can produce false positives (e.g. `ls ?`
|
|
164
|
+
* matches the literal "ls *", but that doesn't make `ls *` more general).
|
|
165
|
+
* In those cases, we fall through to wildcard count and literal character
|
|
166
|
+
* count instead.
|
|
167
|
+
*
|
|
168
|
+
* Examples:
|
|
169
|
+
* `git push` dominates `git *` — `git *` matches the literal "git push"
|
|
170
|
+
* `git push origin main` dominates `git push *` — `git push *` matches "git push origin main"
|
|
171
|
+
* `rm -rf /tmp` dominates `rm *` — `rm *` matches the literal "rm -rf /tmp"
|
|
172
|
+
*
|
|
173
|
+
* @returns True if A is more concrete than B.
|
|
174
|
+
*/
|
|
175
|
+
function dominates(a, b) {
|
|
176
|
+
if (countWildcards(a) > 0)
|
|
177
|
+
return false;
|
|
178
|
+
return matchesPattern(a, b);
|
|
179
|
+
}
|
|
180
|
+
/**
|
|
181
|
+
* Count the number of wildcard characters (`*` and `?`) in a pattern.
|
|
182
|
+
* Fewer wildcards means a more specific (concrete) pattern.
|
|
183
|
+
*/
|
|
184
|
+
function countWildcards(pattern) {
|
|
185
|
+
let count = 0;
|
|
186
|
+
for (let i = 0; i < pattern.length; i++) {
|
|
187
|
+
if (pattern[i] === '*' || pattern[i] === '?')
|
|
188
|
+
count++;
|
|
189
|
+
}
|
|
190
|
+
return count;
|
|
191
|
+
}
|
|
192
|
+
/**
|
|
193
|
+
* Count the number of literal (non-wildcard) characters in a pattern.
|
|
194
|
+
* More literal characters means a more specific (concrete) pattern.
|
|
195
|
+
*/
|
|
196
|
+
function countLiterals(pattern) {
|
|
197
|
+
let count = 0;
|
|
198
|
+
for (let i = 0; i < pattern.length; i++) {
|
|
199
|
+
if (pattern[i] !== '*' && pattern[i] !== '?')
|
|
200
|
+
count++;
|
|
201
|
+
}
|
|
202
|
+
return count;
|
|
203
|
+
}
|
|
204
|
+
/**
|
|
205
|
+
* Whether `target` equals `root` or is located underneath it.
|
|
206
|
+
* The prefix is `root + sep` so that `/ws/a` does not match a sibling like
|
|
207
|
+
* `/ws/abc`. A root that is itself the filesystem root (`/`) needs no extra
|
|
208
|
+
* separator, otherwise the prefix would wrongly become `//`.
|
|
209
|
+
*/
|
|
210
|
+
function isWithin(target, root) {
|
|
211
|
+
const prefix = root.endsWith(sep) ? root : root + sep;
|
|
212
|
+
return target === root || target.startsWith(prefix);
|
|
213
|
+
}
|
|
214
|
+
/**
|
|
215
|
+
* Find the deepest access root that contains `path`.
|
|
216
|
+
*
|
|
217
|
+
* A path is inside a root when it equals the root or lies under it. Roots are
|
|
218
|
+
* resolved before comparison, so relative inputs (e.g. `src`) work too. Among
|
|
219
|
+
* all roots that contain the path, the one with the longest path is the
|
|
220
|
+
* deepest (most specific) match — e.g. `/ws/a/deep` wins over `/ws/a` for
|
|
221
|
+
* `/ws/a/deep/file`, since containing roots are always strictly nested.
|
|
222
|
+
*
|
|
223
|
+
* Returns `''` when no root contains `path`; callers treat that as "no
|
|
224
|
+
* workspace" and fall back to the global permission settings.
|
|
225
|
+
*
|
|
226
|
+
* @param path - Absolute or relative path to locate within the workspace.
|
|
227
|
+
* @param accessRoots - Access root paths from `Workspace.getAccesses()`.
|
|
228
|
+
* @returns The deepest containing access root, or `''` when outside every root.
|
|
229
|
+
*/
|
|
230
|
+
export function workspaceForPath(path, accessRoots) {
|
|
231
|
+
const resolved = resolve(path);
|
|
232
|
+
let deepest = '';
|
|
233
|
+
for (const root of accessRoots) {
|
|
234
|
+
const resolvedRoot = resolve(root);
|
|
235
|
+
if (!isWithin(resolved, resolvedRoot))
|
|
236
|
+
continue;
|
|
237
|
+
if (resolvedRoot.length > deepest.length)
|
|
238
|
+
deepest = resolvedRoot;
|
|
239
|
+
}
|
|
240
|
+
return deepest;
|
|
241
|
+
}
|
|
242
|
+
/**
|
|
243
|
+
* Permission system that parses composed shell commands into subcommands
|
|
244
|
+
* and checks each against glob patterns.
|
|
245
|
+
*
|
|
246
|
+
* Rules are resolved per workspace: the check takes an optional workspace root
|
|
247
|
+
* and uses its {@link WorkspacePermissions}. Without a workspace root, the global
|
|
248
|
+
* fallback settings apply.
|
|
249
|
+
*
|
|
250
|
+
* When multiple rules match a subcommand, the most specific rule wins.
|
|
251
|
+
* Specificity is determined by four criteria, applied in order:
|
|
252
|
+
*
|
|
253
|
+
* 1. **Dominance**: A literal pattern A dominates pattern B when B as a
|
|
254
|
+
* glob matches A as a literal string. Only applies when A has no wildcards,
|
|
255
|
+
* because wildcard-containing patterns can produce false positives.
|
|
256
|
+
* Example: `git push` dominates `git *` because `git *` matches "git push".
|
|
257
|
+
*
|
|
258
|
+
* 2. **Wildcard count**: Fewer wildcards (`*`, `?`) means more specific.
|
|
259
|
+
* Example: `git push` (0 wildcards) beats `git push *` (1 wildcard).
|
|
260
|
+
*
|
|
261
|
+
* 3. **Literal character count**: More literal characters means more specific.
|
|
262
|
+
* Example: `git push *` (9 literals) beats `git p*` (5 literals).
|
|
263
|
+
*
|
|
264
|
+
* 4. **First declared**: If criteria 1–3 don't differentiate, the rule
|
|
265
|
+
* appearing earlier in the configuration wins (stable ordering).
|
|
266
|
+
*/
|
|
267
|
+
export class PermissionSystem {
|
|
268
|
+
resolve;
|
|
269
|
+
canWrite;
|
|
270
|
+
/**
|
|
271
|
+
* @param config - Shell configuration providing per-workspace and global permission settings.
|
|
272
|
+
* @param canWrite - Optional predicate reporting whether a workspace root grants write access.
|
|
273
|
+
* When omitted, write-classified rules are always satisfiable (legacy behavior).
|
|
274
|
+
*/
|
|
275
|
+
constructor(config, canWrite) {
|
|
276
|
+
this.resolve = (workspaceRoot) => config.resolvePermissions(workspaceRoot);
|
|
277
|
+
this.canWrite = canWrite ?? (() => true);
|
|
278
|
+
}
|
|
279
|
+
/**
|
|
280
|
+
* Check if a command is allowed.
|
|
281
|
+
*
|
|
282
|
+
* @param command - Raw shell command (may contain compositions).
|
|
283
|
+
* @param workspaceRoot - Optional resolved workspace root to resolve rules against.
|
|
284
|
+
* @returns The permission check result with action and parsed subcommands.
|
|
285
|
+
*/
|
|
286
|
+
check(command, workspaceRoot) {
|
|
287
|
+
const root = workspaceRoot ?? '';
|
|
288
|
+
const perms = this.resolve(root);
|
|
289
|
+
const subcommands = parseSubcommands(command);
|
|
290
|
+
if (subcommands.length === 0) {
|
|
291
|
+
return { action: PermissionAction.Deny, subcommands: [] };
|
|
292
|
+
}
|
|
293
|
+
for (const sub of subcommands) {
|
|
294
|
+
const result = this.checkSubcommand(sub, perms, root);
|
|
295
|
+
if (result.action === PermissionAction.Deny) {
|
|
296
|
+
return {
|
|
297
|
+
action: PermissionAction.Deny,
|
|
298
|
+
subcommands,
|
|
299
|
+
...(result.denyReason !== undefined ? { denyReason: result.denyReason } : {})
|
|
300
|
+
};
|
|
301
|
+
}
|
|
302
|
+
}
|
|
303
|
+
return { action: PermissionAction.Allow, subcommands };
|
|
304
|
+
}
|
|
305
|
+
/**
|
|
306
|
+
* Find the most specific matching rule for a subcommand.
|
|
307
|
+
*
|
|
308
|
+
* Collects all rules whose pattern matches the subcommand, then sorts
|
|
309
|
+
* them by specificity (see class doc). Returns the action of the most
|
|
310
|
+
* specific rule, or the default action if no rules match. A winning
|
|
311
|
+
* allow rule whose access level the workspace cannot satisfy (a write
|
|
312
|
+
* rule in a read-only workspace) is denied with reason `'write-access'`.
|
|
313
|
+
*/
|
|
314
|
+
checkSubcommand(subcommand, perms, workspaceRoot) {
|
|
315
|
+
const matchingRules = perms.permissionRules
|
|
316
|
+
.map((rule, index) => ({ rule, index }))
|
|
317
|
+
.filter(({ rule }) => matchesPattern(subcommand, rule.pattern));
|
|
318
|
+
if (matchingRules.length === 0) {
|
|
319
|
+
return { action: perms.defaultPermission };
|
|
320
|
+
}
|
|
321
|
+
if (matchingRules.length === 1) {
|
|
322
|
+
return this.decide(matchingRules[0].rule, workspaceRoot);
|
|
323
|
+
}
|
|
324
|
+
matchingRules.sort((a, b) => {
|
|
325
|
+
const aDominates = dominates(a.rule.pattern, b.rule.pattern);
|
|
326
|
+
const bDominates = dominates(b.rule.pattern, a.rule.pattern);
|
|
327
|
+
if (aDominates && !bDominates)
|
|
328
|
+
return -1;
|
|
329
|
+
if (!aDominates && bDominates)
|
|
330
|
+
return 1;
|
|
331
|
+
const aWildcards = countWildcards(a.rule.pattern);
|
|
332
|
+
const bWildcards = countWildcards(b.rule.pattern);
|
|
333
|
+
if (aWildcards !== bWildcards)
|
|
334
|
+
return aWildcards - bWildcards;
|
|
335
|
+
const aLiterals = countLiterals(a.rule.pattern);
|
|
336
|
+
const bLiterals = countLiterals(b.rule.pattern);
|
|
337
|
+
if (aLiterals !== bLiterals)
|
|
338
|
+
return bLiterals - aLiterals;
|
|
339
|
+
return a.index - b.index;
|
|
340
|
+
});
|
|
341
|
+
return this.decide(matchingRules[0].rule, workspaceRoot);
|
|
342
|
+
}
|
|
343
|
+
/**
|
|
344
|
+
* Apply a single winning rule to a subcommand. An allow rule requiring
|
|
345
|
+
* write access is denied when the workspace root is not writable.
|
|
346
|
+
*/
|
|
347
|
+
decide(rule, workspaceRoot) {
|
|
348
|
+
if (rule.action === PermissionAction.Allow &&
|
|
349
|
+
rule.access === PermissionAccess.Write &&
|
|
350
|
+
!this.canWrite(workspaceRoot)) {
|
|
351
|
+
return { action: PermissionAction.Deny, denyReason: PermissionDenyReason.WriteAccess };
|
|
352
|
+
}
|
|
353
|
+
return {
|
|
354
|
+
action: rule.action,
|
|
355
|
+
...(rule.action === PermissionAction.Deny
|
|
356
|
+
? { denyReason: PermissionDenyReason.Pattern }
|
|
357
|
+
: {})
|
|
358
|
+
};
|
|
359
|
+
}
|
|
360
|
+
}
|
|
361
|
+
//# sourceMappingURL=permission.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"permission.js","sourceRoot":"","sources":["../../src/lib/permission.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE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,IAAI;gBACrC,CAAC,CAAC,EAAE,UAAU,EAAE,oBAAoB,CAAC,OAAO,EAAE;gBAC9C,CAAC,CAAC,EAAE,CAAC;SACZ,CAAC;IACN,CAAC;CACJ"}
|
|
@@ -0,0 +1,148 @@
|
|
|
1
|
+
import type { Workspace } from '@johannes.latzel/llm-chat-workspace';
|
|
2
|
+
import type { ShellCommandResult, ShellExecutorFactory, ShellJob, ShellSessionInfo } from './types.js';
|
|
3
|
+
import type { ShellConfiguration } from './config.js';
|
|
4
|
+
export type { ShellExecutorFactory, ShellSessionDeathReason } from './types.js';
|
|
5
|
+
/**
|
|
6
|
+
* Manages shell session lifecycle as a registry of {@link ShellExecutor} instances.
|
|
7
|
+
* Each session is its own executor. Tracks active sessions and enforces limits.
|
|
8
|
+
*
|
|
9
|
+
* The class composes a {@link JobRegistry} (bounded store of every job, live
|
|
10
|
+
* or finished), a {@link SessionRegistry} (live sessions plus tombstones), and
|
|
11
|
+
* a {@link SessionQueue} (the per-session FIFO worker loop), and coordinates
|
|
12
|
+
* them with the idle-expiry sweeper and the teardown of dead or closed
|
|
13
|
+
* sessions.
|
|
14
|
+
*
|
|
15
|
+
* Because a shell executes a single command at a time, every command submitted to
|
|
16
|
+
* a session (foreground or background) is queued in FIFO order and run by a single
|
|
17
|
+
* per-session worker loop. Foreground calls block until their job completes;
|
|
18
|
+
* background submissions return immediately with a {@link ShellJob} to poll.
|
|
19
|
+
* Finished jobs stay queryable by ID in a bounded registry, even after their
|
|
20
|
+
* session dies.
|
|
21
|
+
*
|
|
22
|
+
* Sessions idle for longer than `config.sessionTimeout` are expired by a background
|
|
23
|
+
* sweeper, and sessions whose underlying process died are pruned, so `maxSessions`
|
|
24
|
+
* slots are never permanently lost. Sessions with queued or running jobs are never
|
|
25
|
+
* expired. Dead sessions are recorded as tombstones so stale session IDs keep
|
|
26
|
+
* producing descriptive errors instead of a bare "not found".
|
|
27
|
+
*
|
|
28
|
+
* The manager owns the single mutex that gates the operations which span an
|
|
29
|
+
* `await`: session creation (its factory call is awaited while holding the
|
|
30
|
+
* lock, so concurrent creates cannot both pass the `maxSessions` check),
|
|
31
|
+
* teardown, and expiry are serialized against each other and against
|
|
32
|
+
* submissions. The components themselves are lock-free — their operations are
|
|
33
|
+
* synchronous and therefore atomic under the single-threaded event loop, so
|
|
34
|
+
* they interleave safely with the manager's mutex-protected blocks. The
|
|
35
|
+
* worker loop runs outside the mutex by design: its per-job bookkeeping is a
|
|
36
|
+
* single synchronous block, and the session's `processing` flag guarantees at
|
|
37
|
+
* most one worker. Executor close is single-owner: whoever removes a session
|
|
38
|
+
* from the registry closes its executor (a teardown caller, or the worker on
|
|
39
|
+
* a naturally dead session).
|
|
40
|
+
*/
|
|
41
|
+
export declare class ShellSessionManager {
|
|
42
|
+
private config;
|
|
43
|
+
readonly workspace: Workspace;
|
|
44
|
+
private sessions;
|
|
45
|
+
private jobs;
|
|
46
|
+
private queue;
|
|
47
|
+
private mutex;
|
|
48
|
+
private sweeper;
|
|
49
|
+
constructor(factory: ShellExecutorFactory, config: ShellConfiguration, workspace: Workspace);
|
|
50
|
+
/**
|
|
51
|
+
* Create a new shell session.
|
|
52
|
+
* @param cwd - Optional working directory for this session. Must resolve to a subpath
|
|
53
|
+
* of the configured workspace access dirs. Symlinks are resolved when the
|
|
54
|
+
* workspace has `resolveSymlinks` enabled.
|
|
55
|
+
* @returns The session ID.
|
|
56
|
+
* @throws Error if max sessions reached or cwd is outside the accessible directories.
|
|
57
|
+
*/
|
|
58
|
+
createSession(cwd?: string): Promise<string>;
|
|
59
|
+
/**
|
|
60
|
+
* Return the workspace root a session is currently bound to.
|
|
61
|
+
* @throws Error if session does not exist.
|
|
62
|
+
*/
|
|
63
|
+
getSessionWorkspaceRoot(sessionId: string): Promise<string>;
|
|
64
|
+
/**
|
|
65
|
+
* Return the working directory a session's jobs run in.
|
|
66
|
+
* @throws Error if session does not exist.
|
|
67
|
+
*/
|
|
68
|
+
getSessionCwd(sessionId: string): Promise<string>;
|
|
69
|
+
/**
|
|
70
|
+
* Permanently rebind a session to a different workspace root and working
|
|
71
|
+
* directory. Subsequent permission checks use the new root and jobs run in
|
|
72
|
+
* the new cwd.
|
|
73
|
+
* @throws Error if session does not exist.
|
|
74
|
+
*/
|
|
75
|
+
rebindSession(sessionId: string, workspaceRoot: string, cwd: string): Promise<void>;
|
|
76
|
+
/**
|
|
77
|
+
* Run a command in the foreground: enqueue it and block until the shell gets
|
|
78
|
+
* to it and it completes (or fails). Commands already queued on the same
|
|
79
|
+
* session (including background jobs) run first.
|
|
80
|
+
*
|
|
81
|
+
* @param options - `cwd` is the working directory the command runs in
|
|
82
|
+
* (defaults to the session's cwd); `timeout` overrides the
|
|
83
|
+
* idle timeout (ms, capped at `config.maxTimeout`); omitted
|
|
84
|
+
* uses `ctrlCTimeout`.
|
|
85
|
+
* @throws Error if the session does not exist or the job failed before running.
|
|
86
|
+
*/
|
|
87
|
+
executeCommand(sessionId: string, command: string, options?: {
|
|
88
|
+
timeout?: number;
|
|
89
|
+
cwd?: string;
|
|
90
|
+
}): Promise<ShellCommandResult>;
|
|
91
|
+
/**
|
|
92
|
+
* Submit a command to run in the background and return immediately with a
|
|
93
|
+
* {@link ShellJob}. The job runs when the shell is free (FIFO queue per
|
|
94
|
+
* session); poll {@link getJobStatus} for progress and results.
|
|
95
|
+
*
|
|
96
|
+
* @param options - `cwd` is the working directory the job runs in
|
|
97
|
+
* (defaults to the session's cwd); `timeout` overrides the
|
|
98
|
+
* idle timeout (ms, capped at `config.maxTimeout`); omitted
|
|
99
|
+
* uses `backgroundTimeout`.
|
|
100
|
+
* @throws Error if the session does not exist.
|
|
101
|
+
*/
|
|
102
|
+
submitCommand(sessionId: string, command: string, options?: {
|
|
103
|
+
timeout?: number;
|
|
104
|
+
cwd?: string;
|
|
105
|
+
}): Promise<ShellJob>;
|
|
106
|
+
/**
|
|
107
|
+
* Return the current status and (once finished) results of a job.
|
|
108
|
+
* @throws Error if the job was evicted from the registry or never existed.
|
|
109
|
+
*/
|
|
110
|
+
getJobStatus(jobId: string): Promise<ShellJob>;
|
|
111
|
+
/**
|
|
112
|
+
* List the retained jobs submitted to a session, oldest first. Works even
|
|
113
|
+
* after the session has died, as long as its jobs are still in the registry.
|
|
114
|
+
* @throws Error if the session is unknown and has no retained jobs.
|
|
115
|
+
*/
|
|
116
|
+
listJobs(sessionId: string): Promise<ShellJob[]>;
|
|
117
|
+
/**
|
|
118
|
+
* Snapshot the active shell sessions with their current load. Pending
|
|
119
|
+
* (queued) jobs are counted; the running job (if any) is identified.
|
|
120
|
+
*/
|
|
121
|
+
listSessions(): Promise<ShellSessionInfo[]>;
|
|
122
|
+
/**
|
|
123
|
+
* List every retained job across all sessions, oldest first. Jobs that
|
|
124
|
+
* completed or failed remain in the registry until evicted.
|
|
125
|
+
*/
|
|
126
|
+
listAllJobs(): Promise<ShellJob[]>;
|
|
127
|
+
/**
|
|
128
|
+
* Close a shell session and clean up its executor. Queued jobs fail with a
|
|
129
|
+
* descriptive reason; the session is tombstoned so later references produce
|
|
130
|
+
* a descriptive error.
|
|
131
|
+
*/
|
|
132
|
+
closeSession(sessionId: string): Promise<void>;
|
|
133
|
+
/**
|
|
134
|
+
* Close all active sessions and stop the idle-expiry sweeper.
|
|
135
|
+
*/
|
|
136
|
+
close(): Promise<void>;
|
|
137
|
+
/** Alias for {@link close}: closes all sessions and stops background timers. */
|
|
138
|
+
dispose(): Promise<void>;
|
|
139
|
+
/**
|
|
140
|
+
* Expire sessions that have been idle (no queued or running jobs) for at least
|
|
141
|
+
* `config.sessionTimeout`. Sessions with pending jobs are never expired.
|
|
142
|
+
*/
|
|
143
|
+
private expireIdleSessions;
|
|
144
|
+
/** Start the idle-expiry sweeper, ticking every sessionTimeout/2 (min 1s). */
|
|
145
|
+
private startSweeper;
|
|
146
|
+
private stopSweeper;
|
|
147
|
+
}
|
|
148
|
+
//# sourceMappingURL=session-manager.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"session-manager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