@datename/fastcode-termux 0.1.6 → 0.1.8-beta.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 +4 -0
- package/README.md +67 -16
- package/dist/agent/approval-json.d.ts +43 -0
- package/dist/agent/approval-json.js +69 -0
- package/dist/agent/approval-native.d.ts +3 -0
- package/dist/agent/approval-native.js +165 -0
- package/dist/agent/approval-store.d.ts +16 -0
- package/dist/agent/approval-store.js +21 -0
- package/dist/agent/approval.d.ts +83 -0
- package/dist/agent/approval.js +42 -0
- package/dist/agent/compaction.d.ts +41 -0
- package/dist/agent/compaction.js +270 -0
- package/dist/agent/context.d.ts +29 -0
- package/dist/agent/context.js +62 -0
- package/dist/agent/guards.d.ts +24 -16
- package/dist/agent/guards.js +1167 -18
- package/dist/agent/ignore.d.ts +11 -0
- package/dist/agent/ignore.js +129 -0
- package/dist/agent/policy/defaults.d.ts +16 -0
- package/dist/agent/policy/defaults.js +17 -0
- package/dist/agent/policy/egress.d.ts +32 -0
- package/dist/agent/policy/egress.js +280 -0
- package/dist/agent/process-tree.d.ts +22 -0
- package/dist/agent/process-tree.js +102 -0
- package/dist/agent/protocol-mode.d.ts +6 -0
- package/dist/agent/protocol-mode.js +51 -0
- package/dist/agent/protocol.d.ts +20 -1
- package/dist/agent/protocol.js +169 -39
- package/dist/agent/registry.d.ts +19 -0
- package/dist/agent/registry.js +247 -0
- package/dist/agent/runner.d.ts +127 -0
- package/dist/agent/runner.js +391 -0
- package/dist/agent/shell-ast.d.ts +11 -0
- package/dist/agent/shell-ast.js +204 -0
- package/dist/agent/shell-session.d.ts +51 -0
- package/dist/agent/shell-session.js +611 -0
- package/dist/agent/stream.d.ts +29 -0
- package/dist/agent/stream.js +103 -0
- package/dist/agent/tool-schemas.d.ts +2 -0
- package/dist/agent/tool-schemas.js +82 -0
- package/dist/agent/tools/append_file.d.ts +2 -0
- package/dist/agent/tools/append_file.js +28 -0
- package/dist/agent/tools/apply_patch.d.ts +10 -0
- package/dist/agent/tools/apply_patch.js +92 -0
- package/dist/agent/tools/copy_file.d.ts +2 -0
- package/dist/agent/tools/copy_file.js +53 -0
- package/dist/agent/tools/delete_file.d.ts +2 -0
- package/dist/agent/tools/delete_file.js +43 -0
- package/dist/agent/tools/grep.d.ts +2 -0
- package/dist/agent/tools/grep.js +54 -0
- package/dist/agent/tools/index.d.ts +2 -0
- package/dist/agent/tools/index.js +32 -0
- package/dist/agent/tools/list_files.d.ts +2 -0
- package/dist/agent/tools/list_files.js +17 -0
- package/dist/agent/tools/make_dir.d.ts +2 -0
- package/dist/agent/tools/make_dir.js +26 -0
- package/dist/agent/tools/move_path.d.ts +9 -0
- package/dist/agent/tools/move_path.js +73 -0
- package/dist/agent/tools/paths.d.ts +7 -0
- package/dist/agent/tools/paths.js +84 -0
- package/dist/agent/tools/pwd.d.ts +2 -0
- package/dist/agent/tools/pwd.js +10 -0
- package/dist/agent/tools/read_file.d.ts +2 -0
- package/dist/agent/tools/read_file.js +81 -0
- package/dist/agent/tools/read_many.d.ts +2 -0
- package/dist/agent/tools/read_many.js +43 -0
- package/dist/agent/tools/readers.d.ts +58 -0
- package/dist/agent/tools/readers.js +426 -0
- package/dist/agent/tools/replace_in_file.d.ts +2 -0
- package/dist/agent/tools/replace_in_file.js +63 -0
- package/dist/agent/tools/shell.d.ts +2 -0
- package/dist/agent/tools/shell.js +48 -0
- package/dist/agent/tools/stat_path.d.ts +2 -0
- package/dist/agent/tools/stat_path.js +31 -0
- package/dist/agent/tools/types.d.ts +65 -0
- package/dist/agent/tools/types.js +1 -0
- package/dist/agent/tools/validate.d.ts +19 -0
- package/dist/agent/tools/validate.js +92 -0
- package/dist/agent/tools/write_file.d.ts +2 -0
- package/dist/agent/tools/write_file.js +28 -0
- package/dist/agent/tools.d.ts +3 -1
- package/dist/agent/tools.js +2 -377
- package/dist/app.d.ts +2 -1
- package/dist/app.js +846 -173
- package/dist/cli-main.js +363 -0
- package/dist/cli.js +444 -333
- package/dist/commands/about.js +1 -1
- package/dist/commands/attach.d.ts +9 -0
- package/dist/commands/attach.js +15 -0
- package/dist/commands/bg.d.ts +7 -0
- package/dist/commands/bg.js +9 -0
- package/dist/commands/cancel.d.ts +10 -0
- package/dist/commands/cancel.js +10 -0
- package/dist/commands/clear.d.ts +1 -0
- package/dist/commands/clear.js +1 -1
- package/dist/commands/compact.d.ts +22 -0
- package/dist/commands/compact.js +34 -0
- package/dist/commands/context.d.ts +7 -0
- package/dist/commands/context.js +25 -0
- package/dist/commands/edit.d.ts +10 -0
- package/dist/commands/edit.js +36 -0
- package/dist/commands/effort.d.ts +25 -0
- package/dist/commands/effort.js +48 -0
- package/dist/commands/expand.d.ts +10 -0
- package/dist/commands/expand.js +8 -0
- package/dist/commands/index.js +24 -0
- package/dist/commands/jobs.d.ts +7 -0
- package/dist/commands/jobs.js +17 -0
- package/dist/commands/kill.d.ts +7 -0
- package/dist/commands/kill.js +13 -0
- package/dist/commands/login.d.ts +6 -4
- package/dist/commands/login.js +24 -22
- package/dist/commands/logout.js +8 -16
- package/dist/commands/model.d.ts +1 -0
- package/dist/commands/model.js +10 -22
- package/dist/commands/provider.d.ts +1 -2
- package/dist/commands/provider.js +4 -11
- package/dist/commands/skills.js +34 -4
- package/dist/commands/steer.d.ts +11 -0
- package/dist/commands/steer.js +13 -0
- package/dist/commands/threads.d.ts +9 -0
- package/dist/commands/threads.js +26 -0
- package/dist/commands/whoami.js +6 -5
- package/dist/config/store.d.ts +53 -12
- package/dist/config/store.js +163 -73
- package/dist/config/trust.d.ts +30 -8
- package/dist/config/trust.js +139 -14
- package/dist/headless.d.ts +7 -0
- package/dist/headless.js +213 -0
- package/dist/index.js +19 -3
- package/dist/lib/debug.d.ts +2 -0
- package/dist/lib/debug.js +22 -0
- package/dist/lib/diagnostics.d.ts +48 -4
- package/dist/lib/diagnostics.js +90 -8
- package/dist/lib/highlight-subset.d.ts +21 -0
- package/dist/lib/highlight-subset.js +88 -0
- package/dist/lib/http.d.ts +11 -1
- package/dist/lib/http.js +62 -4
- package/dist/lib/lifecycle.d.ts +5 -0
- package/dist/lib/lifecycle.js +62 -0
- package/dist/lib/markdown.js +22 -4
- package/dist/lib/model-meta.d.ts +19 -0
- package/dist/lib/model-meta.js +113 -0
- package/dist/lib/native-tools.d.ts +12 -0
- package/dist/lib/native-tools.js +21 -0
- package/dist/lib/net.d.ts +33 -0
- package/dist/lib/net.js +168 -0
- package/dist/patch/apply.d.ts +15 -0
- package/dist/patch/apply.js +172 -0
- package/dist/patch/parse.d.ts +29 -0
- package/dist/patch/parse.js +112 -0
- package/dist/patch/plan.d.ts +49 -0
- package/dist/patch/plan.js +273 -0
- package/dist/providers/anthropic.d.ts +1 -0
- package/dist/providers/anthropic.js +12 -0
- package/dist/providers/custom.d.ts +9 -0
- package/dist/providers/deepseek.d.ts +10 -0
- package/dist/providers/deepseek.js +3 -2
- package/dist/providers/google.d.ts +9 -0
- package/dist/providers/groq.d.ts +10 -0
- package/dist/providers/groq.js +2 -1
- package/dist/providers/index.d.ts +10 -201
- package/dist/providers/index.js +30 -0
- package/dist/providers/mistral.d.ts +10 -0
- package/dist/providers/mistral.js +2 -1
- package/dist/providers/moonshot.d.ts +10 -0
- package/dist/providers/moonshot.js +2 -1
- package/dist/providers/ollama.d.ts +9 -0
- package/dist/providers/openai.d.ts +10 -0
- package/dist/providers/openai.js +2 -1
- package/dist/providers/openaiCompatible.d.ts +33 -2
- package/dist/providers/openaiCompatible.js +78 -16
- package/dist/providers/openrouter.d.ts +10 -0
- package/dist/providers/openrouter.js +2 -1
- package/dist/providers/qwen.d.ts +10 -0
- package/dist/providers/qwen.js +2 -1
- package/dist/providers/spec.d.ts +12 -0
- package/dist/providers/spec.js +29 -0
- package/dist/providers/xai.d.ts +10 -0
- package/dist/providers/xai.js +2 -1
- package/dist/providers/zhipu.d.ts +10 -0
- package/dist/providers/zhipu.js +2 -1
- package/dist/session/log.d.ts +49 -14
- package/dist/session/log.js +236 -11
- package/dist/session/projection.d.ts +76 -0
- package/dist/session/projection.js +526 -0
- package/dist/skills/manager.d.ts +15 -0
- package/dist/skills/manager.js +135 -18
- package/dist/types.d.ts +75 -1
- package/dist/ui/Message.d.ts +1 -7
- package/dist/ui/Message.js +13 -2
- package/dist/ui/Picker.d.ts +8 -0
- package/dist/ui/Picker.js +24 -0
- package/dist/ui/Prompt.d.ts +1 -2
- package/dist/ui/Prompt.js +2 -2
- package/dist/ui/Spinner.js +11 -5
- package/dist/ui/StatusBar.d.ts +2 -1
- package/dist/ui/StatusBar.js +6 -5
- package/package.json +3 -2
- package/src/agent/approval-json.ts +103 -0
- package/src/agent/approval-native.ts +168 -0
- package/src/agent/approval-store.ts +38 -0
- package/src/agent/approval.ts +94 -0
- package/src/agent/compaction.ts +321 -0
- package/src/agent/context.ts +97 -0
- package/src/agent/guards.ts +1239 -19
- package/src/agent/ignore.ts +147 -0
- package/src/agent/policy/defaults.ts +34 -0
- package/src/agent/policy/egress.ts +335 -0
- package/src/agent/process-tree.ts +114 -0
- package/src/agent/protocol-mode.ts +59 -0
- package/src/agent/protocol.ts +191 -40
- package/src/agent/registry.ts +270 -0
- package/src/agent/runner.ts +486 -0
- package/src/agent/shell-ast.ts +227 -0
- package/src/agent/shell-session.ts +673 -0
- package/src/agent/stream.ts +143 -0
- package/src/agent/tool-schemas.ts +86 -0
- package/src/agent/tools/append_file.ts +30 -0
- package/src/agent/tools/apply_patch.ts +95 -0
- package/src/agent/tools/copy_file.ts +56 -0
- package/src/agent/tools/delete_file.ts +45 -0
- package/src/agent/tools/grep.ts +57 -0
- package/src/agent/tools/index.ts +34 -0
- package/src/agent/tools/list_files.ts +19 -0
- package/src/agent/tools/make_dir.ts +28 -0
- package/src/agent/tools/move_path.ts +83 -0
- package/src/agent/tools/paths.ts +92 -0
- package/src/agent/tools/pwd.ts +12 -0
- package/src/agent/tools/read_file.ts +84 -0
- package/src/agent/tools/read_many.ts +45 -0
- package/src/agent/tools/readers.ts +491 -0
- package/src/agent/tools/replace_in_file.ts +66 -0
- package/src/agent/tools/shell.ts +53 -0
- package/src/agent/tools/stat_path.ts +33 -0
- package/src/agent/tools/types.ts +84 -0
- package/src/agent/tools/validate.ts +104 -0
- package/src/agent/tools/write_file.ts +30 -0
- package/src/agent/tools.ts +3 -377
- package/src/app.ts +853 -170
- package/src/{cli.ts → cli-main.ts} +64 -9
- package/src/commands/about.ts +1 -1
- package/src/commands/attach.ts +16 -0
- package/src/commands/bg.ts +9 -0
- package/src/commands/cancel.ts +10 -0
- package/src/commands/clear.ts +1 -1
- package/src/commands/compact.ts +35 -0
- package/src/commands/context.ts +26 -0
- package/src/commands/edit.ts +37 -0
- package/src/commands/effort.ts +49 -0
- package/src/commands/expand.ts +8 -0
- package/src/commands/index.ts +24 -0
- package/src/commands/jobs.ts +18 -0
- package/src/commands/kill.ts +14 -0
- package/src/commands/login.ts +24 -22
- package/src/commands/logout.ts +8 -16
- package/src/commands/model.ts +10 -22
- package/src/commands/provider.ts +4 -11
- package/src/commands/skills.ts +34 -4
- package/src/commands/steer.ts +13 -0
- package/src/commands/threads.ts +28 -0
- package/src/commands/whoami.ts +6 -5
- package/src/config/store.ts +168 -77
- package/src/config/trust.ts +181 -22
- package/src/headless.ts +225 -0
- package/src/index.ts +19 -3
- package/src/lib/debug.ts +24 -0
- package/src/lib/diagnostics.ts +90 -8
- package/src/lib/highlight-subset.ts +93 -0
- package/src/lib/http.ts +66 -4
- package/src/lib/lifecycle.ts +69 -0
- package/src/lib/markdown.ts +22 -4
- package/src/lib/model-meta.ts +138 -0
- package/src/lib/native-tools.ts +32 -0
- package/src/lib/net.ts +204 -0
- package/src/patch/apply.ts +194 -0
- package/src/patch/parse.ts +131 -0
- package/src/patch/plan.ts +317 -0
- package/src/providers/anthropic.ts +13 -1
- package/src/providers/deepseek.ts +3 -2
- package/src/providers/groq.ts +2 -1
- package/src/providers/index.ts +32 -1
- package/src/providers/mistral.ts +2 -1
- package/src/providers/moonshot.ts +2 -1
- package/src/providers/openai.ts +2 -1
- package/src/providers/openaiCompatible.ts +104 -19
- package/src/providers/openrouter.ts +2 -1
- package/src/providers/qwen.ts +2 -1
- package/src/providers/spec.ts +42 -0
- package/src/providers/xai.ts +2 -1
- package/src/providers/zhipu.ts +2 -1
- package/src/session/log.ts +311 -29
- package/src/session/projection.ts +621 -0
- package/src/skills/manager.ts +140 -18
- package/src/types/highlight-shims.d.ts +14 -0
- package/src/types.ts +79 -2
- package/src/ui/Message.ts +13 -2
- package/src/ui/Picker.ts +24 -0
- package/src/ui/Prompt.ts +2 -2
- package/src/ui/Spinner.ts +11 -5
- package/src/ui/StatusBar.ts +6 -5
- package/tsconfig.json +1 -0
- /package/dist/{cli.d.ts → cli-main.d.ts} +0 -0
|
@@ -0,0 +1,227 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Limited bash AST second opinion for Guardrails.
|
|
3
|
+
*
|
|
4
|
+
* This is deliberately not a replacement for the shape matcher. It only
|
|
5
|
+
* extracts the three entry classes we can safely re-feed into the existing
|
|
6
|
+
* classifier:
|
|
7
|
+
*
|
|
8
|
+
* 1. shell `-c` literal strings
|
|
9
|
+
* 2. `find ... -exec ... ;/+`
|
|
10
|
+
* 3. eval / source / `.` literal command strings
|
|
11
|
+
*
|
|
12
|
+
* plus one same-scope assignment (`X=rm; $X -rf /`). It only reports Hard
|
|
13
|
+
* Block upgrades; parse failures return no findings so the shape matcher's
|
|
14
|
+
* result is never downgraded.
|
|
15
|
+
*/
|
|
16
|
+
import parse from "bash-parser";
|
|
17
|
+
|
|
18
|
+
export interface ShellAstHard {
|
|
19
|
+
code: string;
|
|
20
|
+
target: string;
|
|
21
|
+
reason: string;
|
|
22
|
+
alternatives: string[];
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
export interface ShellAstAnalysis {
|
|
26
|
+
derived: string[];
|
|
27
|
+
hard?: ShellAstHard;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
const MAX_DEPTH = 4;
|
|
31
|
+
|
|
32
|
+
export function analyzeShellAst(command: string): ShellAstAnalysis {
|
|
33
|
+
return analyze(command, 0);
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
function analyze(command: string, depth: number): ShellAstAnalysis {
|
|
37
|
+
if (depth > MAX_DEPTH)
|
|
38
|
+
return { derived: [] };
|
|
39
|
+
let ast: any;
|
|
40
|
+
try {
|
|
41
|
+
ast = parse(command, { mode: "bash" });
|
|
42
|
+
}
|
|
43
|
+
catch {
|
|
44
|
+
return { derived: [] };
|
|
45
|
+
}
|
|
46
|
+
const derived: string[] = [];
|
|
47
|
+
let hard: ShellAstHard | undefined;
|
|
48
|
+
const scope = new Map<string, string>();
|
|
49
|
+
|
|
50
|
+
const addDerived = (value: string) => {
|
|
51
|
+
const trimmed = value.trim();
|
|
52
|
+
if (trimmed && !derived.includes(trimmed))
|
|
53
|
+
derived.push(trimmed);
|
|
54
|
+
};
|
|
55
|
+
const addHard = (finding: ShellAstHard) => {
|
|
56
|
+
if (!hard)
|
|
57
|
+
hard = finding;
|
|
58
|
+
};
|
|
59
|
+
const wordText = (word: any): string => typeof word?.text === "string" ? word.text : "";
|
|
60
|
+
const wordIsDynamic = (word: any): boolean => {
|
|
61
|
+
if (Array.isArray(word?.expansion) && word.expansion.length > 0)
|
|
62
|
+
return true;
|
|
63
|
+
const text = wordText(word);
|
|
64
|
+
return /\$|`/.test(text);
|
|
65
|
+
};
|
|
66
|
+
const words = (value: any): any[] => Array.isArray(value) ? value : [];
|
|
67
|
+
const walkWord = (word: any) => {
|
|
68
|
+
for (const expansion of words(word?.expansion)) {
|
|
69
|
+
if (expansion?.type === "CommandExpansion") {
|
|
70
|
+
if (typeof expansion.command === "string")
|
|
71
|
+
addDerived(expansion.command);
|
|
72
|
+
if (expansion.commandAST)
|
|
73
|
+
walkNode(expansion.commandAST, scope, depth + 1);
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
};
|
|
77
|
+
const walkList = (commands: any[], assignments: Map<string, string>, level: number) => {
|
|
78
|
+
for (const node of commands)
|
|
79
|
+
walkNode(node, assignments, level);
|
|
80
|
+
};
|
|
81
|
+
const handleCommand = (node: any, assignments: Map<string, string>) => {
|
|
82
|
+
const prefix = words(node?.prefix);
|
|
83
|
+
for (const assignment of prefix) {
|
|
84
|
+
const text = wordText(assignment);
|
|
85
|
+
const eq = text.indexOf("=");
|
|
86
|
+
if (eq <= 0)
|
|
87
|
+
continue;
|
|
88
|
+
const name = text.slice(0, eq);
|
|
89
|
+
const value = text.slice(eq + 1);
|
|
90
|
+
// One same-scope assignment, literal values only. Nested command
|
|
91
|
+
// substitution / variable values are intentionally not tracked.
|
|
92
|
+
if (/^[A-Za-z_][A-Za-z0-9_]*$/.test(name) && value && !/[$`]/.test(value))
|
|
93
|
+
assignments.set(name, value);
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
const nameWord = node?.name;
|
|
97
|
+
const name = wordText(nameWord);
|
|
98
|
+
const suffix = words(node?.suffix);
|
|
99
|
+
const parameter = words(nameWord?.expansion).find((entry: any) => entry?.type === "ParameterExpansion")?.parameter;
|
|
100
|
+
if (parameter && assignments.has(parameter) && (name === `$${parameter}` || name === `\${${parameter}}`)) {
|
|
101
|
+
const suffixText = suffix.map(wordText);
|
|
102
|
+
// bash-parser strips double quotes; a suffix that looks like a
|
|
103
|
+
// redirect/operator may be a quoted literal argument. Do not turn
|
|
104
|
+
// it into a false Hard Block.
|
|
105
|
+
if (suffixText.every((text) => !/[<>|;&]/.test(text))) {
|
|
106
|
+
const resolved = `${assignments.get(parameter)} ${suffixText.join(" ")}`.trim();
|
|
107
|
+
if (resolved)
|
|
108
|
+
addDerived(resolved);
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
if (name === "eval" || name === "source" || name === ".") {
|
|
113
|
+
if (suffix.length === 0)
|
|
114
|
+
return;
|
|
115
|
+
if (suffix.some(wordIsDynamic)) {
|
|
116
|
+
addHard({
|
|
117
|
+
code: "dynamic_execution",
|
|
118
|
+
target: name,
|
|
119
|
+
reason: "non-literal-eval-source",
|
|
120
|
+
alternatives: [
|
|
121
|
+
"Use a literal, reviewed command string; dynamic eval/source cannot be audited.",
|
|
122
|
+
],
|
|
123
|
+
});
|
|
124
|
+
return;
|
|
125
|
+
}
|
|
126
|
+
addDerived(suffix.map(wordText).join(" "));
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
if (SHELL_COMMAND_NAMES.has(name)) {
|
|
130
|
+
const cIndex = suffix.findIndex((word: any) => /^-[a-z]*c$/i.test(wordText(word)));
|
|
131
|
+
if (cIndex >= 0 && suffix[cIndex + 1]) {
|
|
132
|
+
const script = suffix[cIndex + 1];
|
|
133
|
+
if (wordIsDynamic(script)) {
|
|
134
|
+
addHard({
|
|
135
|
+
code: "dynamic_execution",
|
|
136
|
+
target: `${name} -c`,
|
|
137
|
+
reason: "non-literal-shell-command",
|
|
138
|
+
alternatives: [
|
|
139
|
+
"Pass a literal, reviewed script string instead of a variable/command substitution.",
|
|
140
|
+
],
|
|
141
|
+
});
|
|
142
|
+
return;
|
|
143
|
+
}
|
|
144
|
+
addDerived(wordText(script));
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
if (name === "env") {
|
|
149
|
+
const start = suffix.findIndex((word: any) => {
|
|
150
|
+
const value = wordText(word);
|
|
151
|
+
return value && !value.startsWith("-") && !/^[A-Za-z_][A-Za-z0-9_]*=/.test(value);
|
|
152
|
+
});
|
|
153
|
+
if (start >= 0)
|
|
154
|
+
addDerived(suffix.slice(start).map(wordText).join(" "));
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
if (name === "find") {
|
|
158
|
+
const execIndex = suffix.findIndex((word: any) => {
|
|
159
|
+
const value = wordText(word);
|
|
160
|
+
return value === "-exec" || value === "-execdir";
|
|
161
|
+
});
|
|
162
|
+
if (execIndex >= 0) {
|
|
163
|
+
const inner: string[] = [];
|
|
164
|
+
for (const word of suffix.slice(execIndex + 1)) {
|
|
165
|
+
const value = wordText(word);
|
|
166
|
+
if (value === ";" || value === "+")
|
|
167
|
+
break;
|
|
168
|
+
inner.push(value);
|
|
169
|
+
}
|
|
170
|
+
const executable = (inner[0] ?? "").replace(/\\/g, "/").split("/").pop()?.toLowerCase() ?? "";
|
|
171
|
+
if (inner.length > 0 && INSPECT_EXECUTABLES.has(executable))
|
|
172
|
+
addDerived(inner.join(" "));
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
for (const word of words(node?.prefix))
|
|
176
|
+
walkWord(word);
|
|
177
|
+
for (const word of words(node?.suffix))
|
|
178
|
+
walkWord(word);
|
|
179
|
+
};
|
|
180
|
+
const walkNode = (node: any, assignments: Map<string, string>, level: number): void => {
|
|
181
|
+
if (!node || typeof node !== "object" || level > MAX_DEPTH)
|
|
182
|
+
return;
|
|
183
|
+
if (Array.isArray(node)) {
|
|
184
|
+
for (const item of node)
|
|
185
|
+
walkNode(item, assignments, level);
|
|
186
|
+
return;
|
|
187
|
+
}
|
|
188
|
+
switch (node.type) {
|
|
189
|
+
case "Command":
|
|
190
|
+
handleCommand(node, assignments);
|
|
191
|
+
return;
|
|
192
|
+
case "Script":
|
|
193
|
+
case "CompoundList":
|
|
194
|
+
walkList(words(node.commands), new Map(assignments), level);
|
|
195
|
+
return;
|
|
196
|
+
case "Pipeline":
|
|
197
|
+
walkList(words(node.commands), assignments, level);
|
|
198
|
+
return;
|
|
199
|
+
case "LogicalExpression":
|
|
200
|
+
walkNode(node.left, assignments, level);
|
|
201
|
+
walkNode(node.right, assignments, level);
|
|
202
|
+
return;
|
|
203
|
+
case "Subshell":
|
|
204
|
+
walkNode(node.list, new Map(assignments), level + 1);
|
|
205
|
+
return;
|
|
206
|
+
case "CommandExpansion":
|
|
207
|
+
walkNode(node.commandAST, assignments, level + 1);
|
|
208
|
+
return;
|
|
209
|
+
default:
|
|
210
|
+
for (const value of Object.values(node))
|
|
211
|
+
walkNode(value, assignments, level);
|
|
212
|
+
}
|
|
213
|
+
};
|
|
214
|
+
|
|
215
|
+
walkNode(ast, scope, depth);
|
|
216
|
+
return hard ? { derived, hard } : { derived };
|
|
217
|
+
}
|
|
218
|
+
|
|
219
|
+
const SHELL_COMMAND_NAMES = new Set(["sh", "bash", "zsh", "dash", "ksh", "fish"]);
|
|
220
|
+
const INSPECT_EXECUTABLES = new Set([
|
|
221
|
+
"sh", "bash", "zsh", "dash", "ksh", "fish", "eval", "source", ".",
|
|
222
|
+
"rm", "rmdir", "rd", "del", "erase", "unlink", "shred", "truncate",
|
|
223
|
+
"git", "dd", "mkfs", "mke2fs", "fdisk", "diskpart", "format",
|
|
224
|
+
"docker", "kubectl", "chmod", "chown", "chgrp", "shutdown", "reboot",
|
|
225
|
+
"poweroff", "halt", "systemctl", "find", "curl", "wget", "base64",
|
|
226
|
+
"nc", "ncat", "netcat", "socat", "mv", "cp", "install", "tar", "rsync",
|
|
227
|
+
]);
|