@johannes.latzel/llm-chat-shell 0.1.1 → 0.3.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/dist/index.d.ts +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -1
- package/dist/index.js.map +1 -1
- package/dist/lib/config.d.ts +10 -5
- package/dist/lib/config.d.ts.map +1 -1
- package/dist/lib/config.js +36 -10
- package/dist/lib/config.js.map +1 -1
- package/dist/lib/permission.d.ts +43 -24
- package/dist/lib/permission.d.ts.map +1 -1
- package/dist/lib/permission.js +92 -249
- package/dist/lib/permission.js.map +1 -1
- package/dist/lib/redirect-parser.d.ts +19 -0
- package/dist/lib/redirect-parser.d.ts.map +1 -0
- package/dist/lib/redirect-parser.js +302 -0
- package/dist/lib/redirect-parser.js.map +1 -0
- package/dist/lib/types.d.ts +43 -2
- package/dist/lib/types.d.ts.map +1 -1
- package/dist/lib/types.js +16 -0
- package/dist/lib/types.js.map +1 -1
- package/dist/tools/shell-command-tool.d.ts +14 -5
- package/dist/tools/shell-command-tool.d.ts.map +1 -1
- package/dist/tools/shell-command-tool.js +79 -37
- package/dist/tools/shell-command-tool.js.map +1 -1
- package/dist/tools/shell-permissions-tool.d.ts.map +1 -1
- package/dist/tools/shell-permissions-tool.js +9 -2
- package/dist/tools/shell-permissions-tool.js.map +1 -1
- package/package.json +10 -9
package/dist/lib/permission.js
CHANGED
|
@@ -1,206 +1,7 @@
|
|
|
1
1
|
import { resolve, sep } from 'node:path';
|
|
2
|
-
import
|
|
3
|
-
import {
|
|
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
|
-
}
|
|
2
|
+
import { PermissionAction, PermissionAccess, PermissionDenyReason, PermissionType, RedirectMode } from './types.js';
|
|
3
|
+
import { RuleSet } from '@johannes.latzel/pattern-specific';
|
|
4
|
+
import { parseSubcommands } from './redirect-parser.js';
|
|
204
5
|
/**
|
|
205
6
|
* Whether `target` equals `root` or is located underneath it.
|
|
206
7
|
* The prefix is `root + sep` so that `/ws/a` does not match a sibling like
|
|
@@ -247,6 +48,12 @@ export function workspaceForPath(path, accessRoots) {
|
|
|
247
48
|
* and uses its {@link WorkspacePermissions}. Without a workspace root, the global
|
|
248
49
|
* fallback settings apply.
|
|
249
50
|
*
|
|
51
|
+
* A rule's family is its effective type (`type` or the permissions'
|
|
52
|
+
* `defaultType`): command rules match command cores, redirect rules match
|
|
53
|
+
* redirect targets. The two families never cross — a target can never be
|
|
54
|
+
* evaluated as a command and a command core can never be authorized by a
|
|
55
|
+
* redirect rule. See docs/architecture.md for the full redirect model.
|
|
56
|
+
*
|
|
250
57
|
* When multiple rules match a subcommand, the most specific rule wins.
|
|
251
58
|
* Specificity is determined by four criteria, applied in order:
|
|
252
59
|
*
|
|
@@ -279,6 +86,11 @@ export class PermissionSystem {
|
|
|
279
86
|
/**
|
|
280
87
|
* Check if a command is allowed.
|
|
281
88
|
*
|
|
89
|
+
* Command cores are matched against command rules; redirect targets are
|
|
90
|
+
* matched against redirect rules (family from each rule's effective type).
|
|
91
|
+
* Each fragment's core is checked first, then each of its redirect tokens;
|
|
92
|
+
* the first denial fails the whole command.
|
|
93
|
+
*
|
|
282
94
|
* @param command - Raw shell command (may contain compositions).
|
|
283
95
|
* @param workspaceRoot - Optional resolved workspace root to resolve rules against.
|
|
284
96
|
* @returns The permission check result with action and parsed subcommands.
|
|
@@ -286,67 +98,97 @@ export class PermissionSystem {
|
|
|
286
98
|
check(command, workspaceRoot) {
|
|
287
99
|
const root = workspaceRoot ?? '';
|
|
288
100
|
const perms = this.resolve(root);
|
|
289
|
-
const
|
|
290
|
-
|
|
291
|
-
|
|
101
|
+
const fragments = parseSubcommands(command);
|
|
102
|
+
const subcommands = fragments.map((fragment) => fragment.core);
|
|
103
|
+
if (fragments.length === 0) {
|
|
104
|
+
return { action: PermissionAction.Deny, subcommands: [], fragments };
|
|
292
105
|
}
|
|
293
|
-
for (const
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
106
|
+
for (const fragment of fragments) {
|
|
107
|
+
if (fragment.core.length > 0) {
|
|
108
|
+
const coreResult = this.checkCore(fragment.core, perms, root);
|
|
109
|
+
if (coreResult.action === PermissionAction.Deny) {
|
|
110
|
+
return this.denyResult(subcommands, fragments, coreResult.denyReason);
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
for (const token of fragment.tokens) {
|
|
114
|
+
const tokenResult = this.checkToken(token, perms, root);
|
|
115
|
+
if (tokenResult.action === PermissionAction.Deny) {
|
|
116
|
+
return this.denyResult(subcommands, fragments, tokenResult.denyReason);
|
|
117
|
+
}
|
|
301
118
|
}
|
|
302
119
|
}
|
|
303
|
-
return { action: PermissionAction.Allow, subcommands };
|
|
120
|
+
return { action: PermissionAction.Allow, subcommands, fragments };
|
|
121
|
+
}
|
|
122
|
+
denyResult(subcommands, fragments, denyReason) {
|
|
123
|
+
return {
|
|
124
|
+
action: PermissionAction.Deny,
|
|
125
|
+
subcommands,
|
|
126
|
+
fragments,
|
|
127
|
+
...(denyReason !== undefined ? { denyReason } : {})
|
|
128
|
+
};
|
|
304
129
|
}
|
|
305
130
|
/**
|
|
306
|
-
*
|
|
307
|
-
*
|
|
308
|
-
*
|
|
309
|
-
*
|
|
310
|
-
*
|
|
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'`.
|
|
131
|
+
* Match a single command core against the command rules and return the
|
|
132
|
+
* action of the most specific matching rule, or the default action when
|
|
133
|
+
* no rule matches. A winning allow rule whose access level the workspace
|
|
134
|
+
* cannot satisfy (a write rule in a read-only workspace) is denied with
|
|
135
|
+
* reason `'write-access'`.
|
|
313
136
|
*/
|
|
314
|
-
|
|
315
|
-
const
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
if (matchingRules.length === 0) {
|
|
137
|
+
checkCore(core, perms, workspaceRoot) {
|
|
138
|
+
const commandRules = perms.permissionRules.filter((rule) => this.effectiveType(rule, perms) === PermissionType.Command);
|
|
139
|
+
const best = this.pickMatchingRule(commandRules, core);
|
|
140
|
+
if (best === undefined)
|
|
319
141
|
return { action: perms.defaultPermission };
|
|
142
|
+
return this.decide(best, perms.defaultAccess, workspaceRoot);
|
|
143
|
+
}
|
|
144
|
+
/**
|
|
145
|
+
* Match a single redirect token against the redirect rules.
|
|
146
|
+
*
|
|
147
|
+
* Redirects default to deny: a token with no matching redirect rule is
|
|
148
|
+
* denied. A deny rule denies the token. An allow rule must additionally
|
|
149
|
+
* satisfy the mode-to-tier binding — `output` tokens need a write-class
|
|
150
|
+
* allow rule (gated by workspace writability), `input` tokens a read-class
|
|
151
|
+
* allow rule.
|
|
152
|
+
*/
|
|
153
|
+
checkToken(token, perms, workspaceRoot) {
|
|
154
|
+
const redirectRules = perms.permissionRules.filter((rule) => this.effectiveType(rule, perms) === PermissionType.Redirect);
|
|
155
|
+
const best = this.pickMatchingRule(redirectRules, token.target);
|
|
156
|
+
if (best === undefined || best.action === PermissionAction.Deny) {
|
|
157
|
+
return { action: PermissionAction.Deny, denyReason: PermissionDenyReason.Pattern };
|
|
158
|
+
}
|
|
159
|
+
const required = token.mode === RedirectMode.Output ? PermissionAccess.Write : PermissionAccess.Read;
|
|
160
|
+
const ruleAccess = best.access ?? perms.defaultAccess;
|
|
161
|
+
if (ruleAccess !== required) {
|
|
162
|
+
return { action: PermissionAction.Deny, denyReason: PermissionDenyReason.Pattern };
|
|
163
|
+
}
|
|
164
|
+
if (required === PermissionAccess.Write && !this.canWrite(workspaceRoot)) {
|
|
165
|
+
return { action: PermissionAction.Deny, denyReason: PermissionDenyReason.WriteAccess };
|
|
320
166
|
}
|
|
321
|
-
|
|
322
|
-
|
|
167
|
+
return { action: PermissionAction.Allow };
|
|
168
|
+
}
|
|
169
|
+
/** Effective type of a rule: its explicit type or the permissions' default type. */
|
|
170
|
+
effectiveType(rule, perms) {
|
|
171
|
+
return rule.type ?? perms.defaultType;
|
|
172
|
+
}
|
|
173
|
+
/**
|
|
174
|
+
* Find the most specific rule whose pattern matches `value`, or undefined
|
|
175
|
+
* when no rule matches. See the class doc for the specificity criteria.
|
|
176
|
+
*/
|
|
177
|
+
pickMatchingRule(rules, value) {
|
|
178
|
+
const set = new RuleSet((_current, next) => next);
|
|
179
|
+
for (const rule of rules) {
|
|
180
|
+
set.add(rule);
|
|
323
181
|
}
|
|
324
|
-
|
|
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);
|
|
182
|
+
return set.apply(value);
|
|
342
183
|
}
|
|
343
184
|
/**
|
|
344
185
|
* Apply a single winning rule to a subcommand. An allow rule requiring
|
|
345
|
-
* write access
|
|
186
|
+
* write access (its explicit access or the default access) is denied when
|
|
187
|
+
* the workspace root is not writable.
|
|
346
188
|
*/
|
|
347
|
-
decide(rule, workspaceRoot) {
|
|
189
|
+
decide(rule, defaultAccess, workspaceRoot) {
|
|
348
190
|
if (rule.action === PermissionAction.Allow &&
|
|
349
|
-
rule.access === PermissionAccess.Write &&
|
|
191
|
+
(rule.access ?? defaultAccess) === PermissionAccess.Write &&
|
|
350
192
|
!this.canWrite(workspaceRoot)) {
|
|
351
193
|
return { action: PermissionAction.Deny, denyReason: PermissionDenyReason.WriteAccess };
|
|
352
194
|
}
|
|
@@ -358,4 +200,5 @@ export class PermissionSystem {
|
|
|
358
200
|
};
|
|
359
201
|
}
|
|
360
202
|
}
|
|
203
|
+
export { parseSubcommands };
|
|
361
204
|
//# sourceMappingURL=permission.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"permission.js","sourceRoot":"","sources":["../../src/lib/permission.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,GAAG,EAAE,MAAM,WAAW,CAAC;AACzC,OAAO,
|
|
1
|
+
{"version":3,"file":"permission.js","sourceRoot":"","sources":["../../src/lib/permission.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,GAAG,EAAE,MAAM,WAAW,CAAC;AACzC,OAAO,EACH,gBAAgB,EAChB,gBAAgB,EAChB,oBAAoB,EACpB,cAAc,EACd,YAAY,EAKf,MAAM,YAAY,CAAC;AAEpB,OAAO,EAAE,OAAO,EAAE,MAAM,mCAAmC,CAAC;AAC5D,OAAO,EAAE,gBAAgB,EAAE,MAAM,sBAAsB,CAAC;AAcxD;;;;;GAKG;AACH,SAAS,QAAQ,CAAC,MAAc,EAAE,IAAY;IAC1C,MAAM,MAAM,GAAG,IAAI,CAAC,QAAQ,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,IAAI,GAAG,GAAG,CAAC;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AAK;YACzD,CAAC,IAAI,CAAC,QAAQ,CAAC,aAAa,CAAC,EAC/B,CAAC;YACC,OAAO,EAAE,MAAM,EAAE,gBAAgB,CAAC,IAAI,EAAE,UAAU,EAAE,oBAAoB,CAAC,WAAW,EAAE,CAAC;QAC3F,CAAC;QACD,OAAO;YACH,MAAM,EAAE,IAAI,CAAC,MAAM;YACnB,GAAG,CAAC,IAAI,CAAC,MAAM,KAAK,gBAAgB,CAAC,IAAI;gBACrC,CAAC,CAAC,EAAE,UAAU,EAAE,oBAAoB,CAAC,OAAO,EAAE;gBAC9C,CAAC,CAAC,EAAE,CAAC;SACZ,CAAC;IACN,CAAC;CACJ;AAED,OAAO,EAAE,gBAAgB,EAAE,CAAC"}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { type ParsedSubcommand } from './types.js';
|
|
2
|
+
/**
|
|
3
|
+
* Split a shell command into individual subcommands by shell operators,
|
|
4
|
+
* respecting quoted strings. Operators that trigger a split:
|
|
5
|
+
* - `&&` (logical AND)
|
|
6
|
+
* - `||` (logical OR)
|
|
7
|
+
* - `|` (pipe, except inside a `>|` redirect)
|
|
8
|
+
* - `;` (sequential)
|
|
9
|
+
*
|
|
10
|
+
* Each subcommand keeps its raw text plus its extracted redirect tokens.
|
|
11
|
+
* Redirect-only fragments (e.g. `> file`) are retained: they still create or
|
|
12
|
+
* truncate the target file and must be permission-checked.
|
|
13
|
+
*
|
|
14
|
+
* @param input - Raw shell command string.
|
|
15
|
+
* @returns The individual subcommand fragments with cores and redirect tokens.
|
|
16
|
+
*/
|
|
17
|
+
export declare function parseSubcommands(input: string): ParsedSubcommand[];
|
|
18
|
+
export type { ParsedSubcommand };
|
|
19
|
+
//# sourceMappingURL=redirect-parser.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"redirect-parser.d.ts","sourceRoot":"","sources":["../../src/lib/redirect-parser.ts"],"names":[],"mappings":"AAAA,OAAO,EAAgB,KAAK,gBAAgB,EAAsB,MAAM,YAAY,CAAC;AA4ErF;;;;;;;;;;;;;;GAcG;AACH,wBAAgB,gBAAgB,CAAC,KAAK,EAAE,MAAM,GAAG,gBAAgB,EAAE,CA4ElE;AA8LD,YAAY,EAAE,gBAAgB,EAAE,CAAC"}
|