@fnndsc/chell 4.2.8 → 4.3.1
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/builtins/fs/pull.d.ts +2 -2
- package/dist/builtins/fs/pull.js +10 -6
- package/dist/builtins/fs/pull.js.map +1 -1
- package/dist/builtins/help.js +12 -12
- package/dist/builtins/net/query.js +26 -6
- package/dist/builtins/net/query.js.map +1 -1
- package/dist/chell.d.ts +6 -12
- package/dist/chell.js +5 -1187
- package/dist/chell.js.map +1 -1
- package/dist/core/boot.d.ts +7 -0
- package/dist/core/boot.js +601 -0
- package/dist/core/boot.js.map +1 -0
- package/dist/core/dispatch.d.ts +48 -0
- package/dist/core/dispatch.js +544 -0
- package/dist/core/dispatch.js.map +1 -0
- package/dist/core/preprocess.d.ts +46 -0
- package/dist/core/preprocess.js +146 -0
- package/dist/core/preprocess.js.map +1 -0
- package/dist/index.js +1 -1
- package/dist/index.js.map +1 -1
- package/dist/lib/spinner.js +4 -2
- package/dist/lib/spinner.js.map +1 -1
- package/package.json +10 -6
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Spawns the `chili` CLI as a child process.
|
|
3
|
+
*
|
|
4
|
+
* @param command - The command to run (e.g., "feeds").
|
|
5
|
+
* @param args - The arguments to pass to the command.
|
|
6
|
+
* @returns A Promise resolving when the child process exits.
|
|
7
|
+
*/
|
|
8
|
+
export declare function chiliCommand_run(command: string, args: string[]): Promise<void>;
|
|
9
|
+
/**
|
|
10
|
+
* Handles a command entered by the user.
|
|
11
|
+
*
|
|
12
|
+
* @param line - The input line.
|
|
13
|
+
* @returns A Promise that resolves once the command has been processed.
|
|
14
|
+
*/
|
|
15
|
+
export declare function command_handle(line: string): Promise<void>;
|
|
16
|
+
type CommandHandler = (args: string[]) => Promise<void>;
|
|
17
|
+
export declare const COMMAND_HANDLERS: Record<string, CommandHandler>;
|
|
18
|
+
export { COMMAND_HANDLERS_KEYS } from '../command-keys.js';
|
|
19
|
+
/**
|
|
20
|
+
* Expands `$NAME` and `${NAME}` environment references in one token.
|
|
21
|
+
*
|
|
22
|
+
* Applied per token after parsing, so an expanded value can never inject
|
|
23
|
+
* command separators, pipes or redirects (the structural characters were
|
|
24
|
+
* already consumed). References to unset variables are left verbatim —
|
|
25
|
+
* kinder than the shell's silent empty string when a script forgets an
|
|
26
|
+
* export. Shell-escape lines (`!...`) never reach this point; bash does
|
|
27
|
+
* its own expansion there.
|
|
28
|
+
*
|
|
29
|
+
* @param token - A single parsed command token.
|
|
30
|
+
* @returns The token with set environment references substituted.
|
|
31
|
+
*/
|
|
32
|
+
export declare function envRefs_expand(token: string): string;
|
|
33
|
+
/**
|
|
34
|
+
* Dispatches a parsed command to its handler.
|
|
35
|
+
* Expands environment references in the arguments, then checks
|
|
36
|
+
* COMMAND_HANDLERS, then /bin plugin names, then falls back to chili.
|
|
37
|
+
*
|
|
38
|
+
* @param command - The command name.
|
|
39
|
+
* @param args - Parsed arguments.
|
|
40
|
+
*/
|
|
41
|
+
export declare function command_dispatch(command: string, args: string[]): Promise<void>;
|
|
42
|
+
/**
|
|
43
|
+
* Sets the shared stop-on-error flag. Exposed so the boot layer (which owns the
|
|
44
|
+
* `-e` flag and script execution) can drive the flag that the dispatch layer reads.
|
|
45
|
+
*
|
|
46
|
+
* @param value - `true` to abort a batch on the first error.
|
|
47
|
+
*/
|
|
48
|
+
export declare function stopOnError_set(value: boolean): void;
|
|
@@ -0,0 +1,544 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @file Command parsing and dispatch for the ChELL shell.
|
|
3
|
+
*
|
|
4
|
+
* Turns a line of user input into an executed command:
|
|
5
|
+
* - preprocessing (inline shell escape, semicolon batching, redirects, pipes, wildcards, help)
|
|
6
|
+
* - the built-in command table and dispatch to built-ins, simulated plugin exec, or `chili`
|
|
7
|
+
* - output capture for the redirect/pipe paths
|
|
8
|
+
*
|
|
9
|
+
* The startup/connection/REPL glue that drives this layer lives in `./boot.js`.
|
|
10
|
+
*
|
|
11
|
+
* @module
|
|
12
|
+
*/
|
|
13
|
+
import { writeFileSync, appendFileSync } from 'fs';
|
|
14
|
+
import chalk from 'chalk';
|
|
15
|
+
import { spawn } from 'child_process';
|
|
16
|
+
import { session } from '../session/index.js';
|
|
17
|
+
import { builtin_cd, builtin_ls, builtin_pwd, builtin_connect, builtin_logout, builtin_cat, builtin_cp, builtin_mv, builtin_upload, builtin_pacs, builtin_pipeline, builtin_pull, builtin_query, builtin_cubepath, builtin_rm, builtin_touch, builtin_mkdir, builtin_plugin, builtin_feed, builtin_compute, builtin_tag, builtin_group, builtin_pluginmeta, builtin_plugininstance, builtin_workflow, builtin_download, builtin_edit, builtin_files, builtin_links, builtin_dirs, builtin_context, builtin_parametersofplugin, builtin_physicalmode, builtin_prompt, builtin_timing, builtin_whoami, builtin_whereami, builtin_debug, builtin_help, builtin_tree, builtin_du, builtin_store, error_stripDebugPrefix } from '../builtins/index.js';
|
|
18
|
+
import { builtin_executePlugin } from '../builtins/pluginExecute.js';
|
|
19
|
+
import { builtin_proc } from '../builtins/proc.js';
|
|
20
|
+
import { wildcards_expandAll } from '../builtins/wildcard.js';
|
|
21
|
+
import { help_show, args_checkHasHelpFlag } from '../builtins/help.js';
|
|
22
|
+
import { pluginExecutable_handle } from '../builtins/executable.js';
|
|
23
|
+
import { errorStack, Ok, Err } from '@fnndsc/cumin';
|
|
24
|
+
import { vfs } from '../lib/vfs/vfs.js';
|
|
25
|
+
import { args_tokenize } from '../lib/parser.js';
|
|
26
|
+
import { semicolons_parse } from '../lib/semicolonParser.js';
|
|
27
|
+
import { segment_pipeThrough } from '../lib/pipe.js';
|
|
28
|
+
import { pipes_parse, redirect_parse, redirectTarget_resolve, wildcards_expandCheck, command_shellEscape_detect, } from './preprocess.js';
|
|
29
|
+
import { run as chiliRun } from '@fnndsc/chili/run.js';
|
|
30
|
+
/**
|
|
31
|
+
* Spawns the `chili` CLI as a child process.
|
|
32
|
+
*
|
|
33
|
+
* @param command - The command to run (e.g., "feeds").
|
|
34
|
+
* @param args - The arguments to pass to the command.
|
|
35
|
+
* @returns A Promise resolving when the child process exits.
|
|
36
|
+
*/
|
|
37
|
+
export async function chiliCommand_run(command, args) {
|
|
38
|
+
// Run chili in-process. chili shares this process's cumin connection/context,
|
|
39
|
+
// so there is no node subprocess to spawn and no per-command startup cost.
|
|
40
|
+
try {
|
|
41
|
+
await chiliRun([command, ...args]);
|
|
42
|
+
}
|
|
43
|
+
catch (err) {
|
|
44
|
+
const message = err instanceof Error ? err.message : String(err);
|
|
45
|
+
console.error(chalk.red(`chili command '${command}' failed: ${message}`));
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* Executes a shell command on the host system (shell escape with ! prefix).
|
|
50
|
+
*
|
|
51
|
+
* @param shellCommand - The command to execute on the host shell.
|
|
52
|
+
* @returns A Promise that resolves when the command completes.
|
|
53
|
+
*/
|
|
54
|
+
async function shellCommand_execute(shellCommand) {
|
|
55
|
+
return new Promise((resolve) => {
|
|
56
|
+
const child = spawn(shellCommand, {
|
|
57
|
+
shell: true,
|
|
58
|
+
stdio: 'inherit',
|
|
59
|
+
env: process.env
|
|
60
|
+
});
|
|
61
|
+
child.on('close', (code) => {
|
|
62
|
+
if (code !== null && code !== 0) {
|
|
63
|
+
console.error(chalk.red(`Shell command exited with code ${code}`));
|
|
64
|
+
}
|
|
65
|
+
resolve();
|
|
66
|
+
});
|
|
67
|
+
child.on('error', (err) => {
|
|
68
|
+
console.error(chalk.red(`Failed to execute shell command: ${err.message}`));
|
|
69
|
+
resolve();
|
|
70
|
+
});
|
|
71
|
+
});
|
|
72
|
+
}
|
|
73
|
+
/**
|
|
74
|
+
* Handles a command entered by the user.
|
|
75
|
+
*
|
|
76
|
+
* @param line - The input line.
|
|
77
|
+
* @returns A Promise that resolves once the command has been processed.
|
|
78
|
+
*/
|
|
79
|
+
export async function command_handle(line) {
|
|
80
|
+
const trimmedLine = line.trim();
|
|
81
|
+
if (!trimmedLine)
|
|
82
|
+
return;
|
|
83
|
+
// Start timing if enabled
|
|
84
|
+
const timingEnabled = session.timingEnabled_get();
|
|
85
|
+
const startTime = timingEnabled ? performance.now() : 0;
|
|
86
|
+
if (command_shellEscape_detect(trimmedLine)) {
|
|
87
|
+
await shellEscape_handle(trimmedLine, startTime, timingEnabled);
|
|
88
|
+
return;
|
|
89
|
+
}
|
|
90
|
+
const semicolonResult = await semicolons_handle(trimmedLine, startTime, timingEnabled);
|
|
91
|
+
if (!semicolonResult.ok) {
|
|
92
|
+
return;
|
|
93
|
+
}
|
|
94
|
+
if (semicolonResult.value)
|
|
95
|
+
return;
|
|
96
|
+
const redirectResult = await redirect_handle(trimmedLine, startTime, timingEnabled);
|
|
97
|
+
if (!redirectResult.ok) {
|
|
98
|
+
return;
|
|
99
|
+
}
|
|
100
|
+
if (redirectResult.value)
|
|
101
|
+
return;
|
|
102
|
+
const pipeResult = await pipe_handle(trimmedLine, startTime, timingEnabled);
|
|
103
|
+
if (!pipeResult.ok) {
|
|
104
|
+
return;
|
|
105
|
+
}
|
|
106
|
+
if (pipeResult.value)
|
|
107
|
+
return;
|
|
108
|
+
const tokens = args_tokenize(trimmedLine);
|
|
109
|
+
if (tokens.length === 0)
|
|
110
|
+
return;
|
|
111
|
+
let [command, ...args] = tokens;
|
|
112
|
+
// Check for --help flag before any processing
|
|
113
|
+
const helpResult = help_showMaybe(command, args);
|
|
114
|
+
if (helpResult.ok && helpResult.value) {
|
|
115
|
+
return;
|
|
116
|
+
}
|
|
117
|
+
// Expand wildcards for commands that support it
|
|
118
|
+
const expandResult = await wildcards_expand(command, args);
|
|
119
|
+
if (!expandResult.ok) {
|
|
120
|
+
return;
|
|
121
|
+
}
|
|
122
|
+
args = expandResult.value;
|
|
123
|
+
// Attempt to handle as a simulated plugin execution
|
|
124
|
+
if (await pluginExecutable_handle(command, args)) {
|
|
125
|
+
// Display timing if enabled
|
|
126
|
+
command_timingMaybePrint(startTime, timingEnabled);
|
|
127
|
+
return;
|
|
128
|
+
}
|
|
129
|
+
await command_dispatch(command, args);
|
|
130
|
+
// Display timing if enabled
|
|
131
|
+
command_timingMaybePrint(startTime, timingEnabled);
|
|
132
|
+
}
|
|
133
|
+
/**
|
|
134
|
+
* Captures console output during command execution.
|
|
135
|
+
*
|
|
136
|
+
* @param fn - The function to execute while capturing output.
|
|
137
|
+
* @returns The captured output as a string and buffer.
|
|
138
|
+
*/
|
|
139
|
+
async function output_capture(fn) {
|
|
140
|
+
const chunks = [];
|
|
141
|
+
const originalLog = console.log;
|
|
142
|
+
const originalStdoutWrite = process.stdout.write.bind(process.stdout);
|
|
143
|
+
// Override console.log and console.error
|
|
144
|
+
console.log = (...args) => {
|
|
145
|
+
const text = args.map(arg => typeof arg === 'string' ? arg : JSON.stringify(arg)).join(' ') + '\n';
|
|
146
|
+
chunks.push(Buffer.from(text, 'utf-8'));
|
|
147
|
+
};
|
|
148
|
+
// Override process.stdout.write to capture binary data
|
|
149
|
+
process.stdout.write = ((chunk) => {
|
|
150
|
+
if (typeof chunk === 'string') {
|
|
151
|
+
chunks.push(Buffer.from(chunk, 'utf-8'));
|
|
152
|
+
}
|
|
153
|
+
else if (Buffer.isBuffer(chunk)) {
|
|
154
|
+
chunks.push(chunk);
|
|
155
|
+
}
|
|
156
|
+
else if (chunk instanceof Uint8Array) {
|
|
157
|
+
chunks.push(Buffer.from(chunk));
|
|
158
|
+
}
|
|
159
|
+
return true;
|
|
160
|
+
});
|
|
161
|
+
try {
|
|
162
|
+
await fn();
|
|
163
|
+
}
|
|
164
|
+
finally {
|
|
165
|
+
// Restore original console methods and stdout.write
|
|
166
|
+
console.log = originalLog;
|
|
167
|
+
process.stdout.write = originalStdoutWrite;
|
|
168
|
+
}
|
|
169
|
+
const buffer = Buffer.concat(chunks);
|
|
170
|
+
const text = buffer.toString('utf-8');
|
|
171
|
+
return { text, buffer };
|
|
172
|
+
}
|
|
173
|
+
export const COMMAND_HANDLERS = {
|
|
174
|
+
connect: builtin_connect,
|
|
175
|
+
logout: builtin_logout,
|
|
176
|
+
cd: builtin_cd,
|
|
177
|
+
ls: builtin_ls,
|
|
178
|
+
pwd: builtin_pwd,
|
|
179
|
+
cat: builtin_cat,
|
|
180
|
+
rm: builtin_rm,
|
|
181
|
+
cp: builtin_cp,
|
|
182
|
+
mv: builtin_mv,
|
|
183
|
+
touch: builtin_touch,
|
|
184
|
+
mkdir: builtin_mkdir,
|
|
185
|
+
upload: builtin_upload,
|
|
186
|
+
pacs: builtin_pacs,
|
|
187
|
+
pipeline: builtin_pipeline,
|
|
188
|
+
pipelines: builtin_pipeline,
|
|
189
|
+
pull: builtin_pull,
|
|
190
|
+
query: builtin_query,
|
|
191
|
+
cubepath: builtin_cubepath,
|
|
192
|
+
download: builtin_download,
|
|
193
|
+
edit: builtin_edit,
|
|
194
|
+
context: builtin_context,
|
|
195
|
+
parametersofplugin: builtin_parametersofplugin,
|
|
196
|
+
physicalmode: builtin_physicalmode,
|
|
197
|
+
prompt: builtin_prompt,
|
|
198
|
+
timing: builtin_timing,
|
|
199
|
+
whoami: builtin_whoami,
|
|
200
|
+
whereami: builtin_whereami,
|
|
201
|
+
debug: builtin_debug,
|
|
202
|
+
help: builtin_help,
|
|
203
|
+
proc: builtin_proc,
|
|
204
|
+
tree: builtin_tree,
|
|
205
|
+
du: builtin_du,
|
|
206
|
+
store: builtin_store,
|
|
207
|
+
plugin: builtin_plugin,
|
|
208
|
+
plugins: builtin_plugin,
|
|
209
|
+
feed: builtin_feed,
|
|
210
|
+
feeds: builtin_feed,
|
|
211
|
+
compute: builtin_compute,
|
|
212
|
+
computes: builtin_compute,
|
|
213
|
+
tag: builtin_tag,
|
|
214
|
+
tags: builtin_tag,
|
|
215
|
+
group: builtin_group,
|
|
216
|
+
groups: builtin_group,
|
|
217
|
+
pluginmeta: builtin_pluginmeta,
|
|
218
|
+
pluginmetas: builtin_pluginmeta,
|
|
219
|
+
meta: builtin_pluginmeta,
|
|
220
|
+
metas: builtin_pluginmeta,
|
|
221
|
+
plugininstance: builtin_plugininstance,
|
|
222
|
+
plugininstances: builtin_plugininstance,
|
|
223
|
+
instance: builtin_plugininstance,
|
|
224
|
+
instances: builtin_plugininstance,
|
|
225
|
+
job: builtin_plugininstance,
|
|
226
|
+
jobs: builtin_plugininstance,
|
|
227
|
+
workflow: builtin_workflow,
|
|
228
|
+
workflows: builtin_workflow,
|
|
229
|
+
files: builtin_files,
|
|
230
|
+
links: builtin_links,
|
|
231
|
+
dirs: builtin_dirs,
|
|
232
|
+
pacsservers: async (args) => {
|
|
233
|
+
await chiliCommand_run('pacsservers', ['-s', ...args]);
|
|
234
|
+
},
|
|
235
|
+
pacsqueries: async (args) => {
|
|
236
|
+
await chiliCommand_run('pacsqueries', ['-s', ...args]);
|
|
237
|
+
},
|
|
238
|
+
pacsretrieve: async (args) => {
|
|
239
|
+
await chiliCommand_run('pacsretrieve', ['-s', ...args]);
|
|
240
|
+
}
|
|
241
|
+
};
|
|
242
|
+
export { COMMAND_HANDLERS_KEYS } from '../command-keys.js';
|
|
243
|
+
/**
|
|
244
|
+
* Prints elapsed time since startTime if timing is enabled.
|
|
245
|
+
*
|
|
246
|
+
* @param startTime - Timestamp from `performance.now()` at command start.
|
|
247
|
+
* @param enabled - Whether timing display is active.
|
|
248
|
+
*/
|
|
249
|
+
function command_timingMaybePrint(startTime, enabled) {
|
|
250
|
+
if (!enabled)
|
|
251
|
+
return;
|
|
252
|
+
const elapsed = performance.now() - startTime;
|
|
253
|
+
console.log(chalk.gray(`[${elapsed.toFixed(2)}ms]`));
|
|
254
|
+
}
|
|
255
|
+
/**
|
|
256
|
+
* Handles a pipeline name invoked directly as an executable from /bin.
|
|
257
|
+
* Routes flag combinations to the appropriate pipeline subcommand:
|
|
258
|
+
* --nodes / --parameters → pipeline info
|
|
259
|
+
* --source / --readme → pipeline source
|
|
260
|
+
* (bare or --compute) → pipeline run
|
|
261
|
+
*
|
|
262
|
+
* @param name - The pipeline name as typed.
|
|
263
|
+
* @param args - Arguments following the pipeline name.
|
|
264
|
+
*/
|
|
265
|
+
async function pipelineExecutable_handle(name, args) {
|
|
266
|
+
if (args.includes('--nodes') || args.includes('--parameters')) {
|
|
267
|
+
await builtin_pipeline(['info', name]);
|
|
268
|
+
}
|
|
269
|
+
else if (args.includes('--source') || args.includes('--readme')) {
|
|
270
|
+
await builtin_pipeline(['source', name]);
|
|
271
|
+
}
|
|
272
|
+
else {
|
|
273
|
+
await builtin_pipeline(['run', name, ...args]);
|
|
274
|
+
}
|
|
275
|
+
}
|
|
276
|
+
/**
|
|
277
|
+
* Expands `$NAME` and `${NAME}` environment references in one token.
|
|
278
|
+
*
|
|
279
|
+
* Applied per token after parsing, so an expanded value can never inject
|
|
280
|
+
* command separators, pipes or redirects (the structural characters were
|
|
281
|
+
* already consumed). References to unset variables are left verbatim —
|
|
282
|
+
* kinder than the shell's silent empty string when a script forgets an
|
|
283
|
+
* export. Shell-escape lines (`!...`) never reach this point; bash does
|
|
284
|
+
* its own expansion there.
|
|
285
|
+
*
|
|
286
|
+
* @param token - A single parsed command token.
|
|
287
|
+
* @returns The token with set environment references substituted.
|
|
288
|
+
*/
|
|
289
|
+
export function envRefs_expand(token) {
|
|
290
|
+
return token.replace(/\$(?:\{([A-Za-z_][A-Za-z0-9_]*)\}|([A-Za-z_][A-Za-z0-9_]*))/g, (match, braced, bare) => {
|
|
291
|
+
const value = process.env[braced ?? bare ?? ''];
|
|
292
|
+
return value !== undefined ? value : match;
|
|
293
|
+
});
|
|
294
|
+
}
|
|
295
|
+
/**
|
|
296
|
+
* Dispatches a parsed command to its handler.
|
|
297
|
+
* Expands environment references in the arguments, then checks
|
|
298
|
+
* COMMAND_HANDLERS, then /bin plugin names, then falls back to chili.
|
|
299
|
+
*
|
|
300
|
+
* @param command - The command name.
|
|
301
|
+
* @param args - Parsed arguments.
|
|
302
|
+
*/
|
|
303
|
+
export async function command_dispatch(command, args) {
|
|
304
|
+
if (command === 'exit') {
|
|
305
|
+
process.exit(0);
|
|
306
|
+
}
|
|
307
|
+
args = args.map(envRefs_expand);
|
|
308
|
+
const handler = COMMAND_HANDLERS[command];
|
|
309
|
+
if (handler) {
|
|
310
|
+
await handler(args);
|
|
311
|
+
return;
|
|
312
|
+
}
|
|
313
|
+
const binResult = await vfs.data_get('/bin');
|
|
314
|
+
if (binResult.ok) {
|
|
315
|
+
const pluginItem = binResult.value.find(item => item.name === command && item.type === 'plugin');
|
|
316
|
+
const pipelineItem = binResult.value.find(item => item.name === command && item.type === 'pipeline');
|
|
317
|
+
if (pluginItem) {
|
|
318
|
+
await builtin_executePlugin(command, args);
|
|
319
|
+
return;
|
|
320
|
+
}
|
|
321
|
+
if (pipelineItem) {
|
|
322
|
+
await pipelineExecutable_handle(command, args);
|
|
323
|
+
return;
|
|
324
|
+
}
|
|
325
|
+
}
|
|
326
|
+
console.log(chalk.yellow(`Unknown chell command '${command}' -- delegating to chili`));
|
|
327
|
+
await chiliCommand_run(command, ['-s', ...args]);
|
|
328
|
+
}
|
|
329
|
+
/**
|
|
330
|
+
* Executes a shell-escaped command and prints timing if enabled.
|
|
331
|
+
*
|
|
332
|
+
* @param line - Full input line including the leading `!`.
|
|
333
|
+
* @param startTime - Timing reference from `performance.now()`.
|
|
334
|
+
* @param timingEnabled - Whether to print elapsed time after execution.
|
|
335
|
+
*/
|
|
336
|
+
async function shellEscape_handle(line, startTime, timingEnabled) {
|
|
337
|
+
const shellCommand = line.substring(1).trim();
|
|
338
|
+
if (!shellCommand)
|
|
339
|
+
return;
|
|
340
|
+
await shellCommand_execute(shellCommand);
|
|
341
|
+
command_timingMaybePrint(startTime, timingEnabled);
|
|
342
|
+
}
|
|
343
|
+
/**
|
|
344
|
+
* Splits a semicolon-separated command line and executes each segment in sequence.
|
|
345
|
+
* Returns Ok(true) if the line contained semicolons and was handled, Ok(false) if not.
|
|
346
|
+
*
|
|
347
|
+
* @param line - Full input line.
|
|
348
|
+
* @param startTime - Timing reference.
|
|
349
|
+
* @param timingEnabled - Whether to print total elapsed time after all segments.
|
|
350
|
+
*/
|
|
351
|
+
async function semicolons_handle(line, startTime, timingEnabled) {
|
|
352
|
+
const commands = semicolons_parse(line);
|
|
353
|
+
if (commands.length <= 1) {
|
|
354
|
+
return Ok(false);
|
|
355
|
+
}
|
|
356
|
+
for (const cmd of commands) {
|
|
357
|
+
try {
|
|
358
|
+
await command_handle(cmd);
|
|
359
|
+
}
|
|
360
|
+
catch (error) {
|
|
361
|
+
const msg = error instanceof Error ? error.message : String(error);
|
|
362
|
+
console.error(chalk.red(`Command error: ${msg}`));
|
|
363
|
+
if (stopOnError) {
|
|
364
|
+
return Err();
|
|
365
|
+
}
|
|
366
|
+
}
|
|
367
|
+
}
|
|
368
|
+
if (timingEnabled) {
|
|
369
|
+
const elapsed = performance.now() - startTime;
|
|
370
|
+
console.log(chalk.gray(`[Total: ${elapsed.toFixed(2)}ms]`));
|
|
371
|
+
}
|
|
372
|
+
return Ok(true);
|
|
373
|
+
}
|
|
374
|
+
/**
|
|
375
|
+
* Handles output redirection (`>` / `>>`). Captures command output and writes to the target file.
|
|
376
|
+
* Returns Ok(true) if redirection was detected and handled, Ok(false) if not.
|
|
377
|
+
*
|
|
378
|
+
* @param line - Full input line.
|
|
379
|
+
* @param startTime - Timing reference.
|
|
380
|
+
* @param timingEnabled - Whether to print elapsed time after execution.
|
|
381
|
+
*/
|
|
382
|
+
async function redirect_handle(line, startTime, timingEnabled) {
|
|
383
|
+
const redirectInfo = redirect_parse(line);
|
|
384
|
+
if (!redirectInfo) {
|
|
385
|
+
return Ok(false);
|
|
386
|
+
}
|
|
387
|
+
const { buffer } = await chellCommand_executeAndCapture(redirectInfo.command);
|
|
388
|
+
const targetResult = redirectTarget_resolve(redirectInfo.filePath, redirectInfo.command);
|
|
389
|
+
if (!targetResult.ok) {
|
|
390
|
+
const lastError = errorStack.stack_pop();
|
|
391
|
+
console.error(chalk.red(lastError ? lastError.message : 'Redirect error'));
|
|
392
|
+
return Err();
|
|
393
|
+
}
|
|
394
|
+
if (redirectInfo.operator === '>') {
|
|
395
|
+
writeFileSync(targetResult.value, buffer);
|
|
396
|
+
}
|
|
397
|
+
else {
|
|
398
|
+
appendFileSync(targetResult.value, buffer);
|
|
399
|
+
}
|
|
400
|
+
command_timingMaybePrint(startTime, timingEnabled);
|
|
401
|
+
return Ok(true);
|
|
402
|
+
}
|
|
403
|
+
/**
|
|
404
|
+
* Handles pipe chains (`cmd1 | cmd2 | ...`). Executes the first segment in chell and
|
|
405
|
+
* pipes the output through subsequent host-shell processes.
|
|
406
|
+
* Returns Ok(true) if a pipe was detected and handled, Ok(false) if not.
|
|
407
|
+
*
|
|
408
|
+
* @param line - Full input line.
|
|
409
|
+
* @param startTime - Timing reference.
|
|
410
|
+
* @param timingEnabled - Whether to print elapsed time after the chain completes.
|
|
411
|
+
*/
|
|
412
|
+
async function pipe_handle(line, startTime, timingEnabled) {
|
|
413
|
+
const segments = pipes_parse(line);
|
|
414
|
+
if (segments.length <= 1) {
|
|
415
|
+
return Ok(false);
|
|
416
|
+
}
|
|
417
|
+
try {
|
|
418
|
+
await pipe_execute(segments);
|
|
419
|
+
}
|
|
420
|
+
catch (error) {
|
|
421
|
+
const msg = error instanceof Error ? error.message : String(error);
|
|
422
|
+
console.error(chalk.red(`Pipe error: ${msg}`));
|
|
423
|
+
return Err();
|
|
424
|
+
}
|
|
425
|
+
command_timingMaybePrint(startTime, timingEnabled);
|
|
426
|
+
return Ok(true);
|
|
427
|
+
}
|
|
428
|
+
/**
|
|
429
|
+
* Shows help for a command if `--help` or `-h` is present in args.
|
|
430
|
+
* Returns Ok(true) if help was displayed, Ok(false) otherwise.
|
|
431
|
+
*
|
|
432
|
+
* @param command - The command name (used to look up help text).
|
|
433
|
+
* @param args - Parsed argument list.
|
|
434
|
+
*/
|
|
435
|
+
function help_showMaybe(command, args) {
|
|
436
|
+
if (args_checkHasHelpFlag(args, command)) {
|
|
437
|
+
help_show(command);
|
|
438
|
+
return Ok(true);
|
|
439
|
+
}
|
|
440
|
+
return Ok(false);
|
|
441
|
+
}
|
|
442
|
+
/**
|
|
443
|
+
* Expands wildcard patterns in args for commands that support it.
|
|
444
|
+
* Returns Ok(expanded args) or Err if expansion fails.
|
|
445
|
+
*
|
|
446
|
+
* @param command - The command name (determines whether expansion applies).
|
|
447
|
+
* @param args - Raw argument list potentially containing glob patterns.
|
|
448
|
+
*/
|
|
449
|
+
async function wildcards_expand(command, args) {
|
|
450
|
+
if (!wildcards_expandCheck(command)) {
|
|
451
|
+
return Ok(args);
|
|
452
|
+
}
|
|
453
|
+
const expandResult = await wildcards_expandAll(args);
|
|
454
|
+
if (!expandResult.ok) {
|
|
455
|
+
const lastError = errorStack.stack_pop();
|
|
456
|
+
if (lastError) {
|
|
457
|
+
console.error(chalk.red(error_stripDebugPrefix(lastError.message)));
|
|
458
|
+
}
|
|
459
|
+
return Err();
|
|
460
|
+
}
|
|
461
|
+
return Ok(expandResult.value);
|
|
462
|
+
}
|
|
463
|
+
/**
|
|
464
|
+
* Executes a chell command and captures its output.
|
|
465
|
+
* Consults COMMAND_HANDLERS — the single source of truth — so the pipe path
|
|
466
|
+
* is always consistent with the direct-execution path.
|
|
467
|
+
*
|
|
468
|
+
* @param commandLine - The command line to execute.
|
|
469
|
+
* @returns The captured output as text and raw buffer.
|
|
470
|
+
*/
|
|
471
|
+
async function chellCommand_executeAndCapture(commandLine) {
|
|
472
|
+
const trimmedLine = commandLine.trim();
|
|
473
|
+
if (!trimmedLine)
|
|
474
|
+
return { text: '', buffer: Buffer.alloc(0) };
|
|
475
|
+
const tokens = args_tokenize(trimmedLine);
|
|
476
|
+
if (tokens.length === 0) {
|
|
477
|
+
return { text: '', buffer: Buffer.alloc(0) };
|
|
478
|
+
}
|
|
479
|
+
let [command, ...args] = tokens;
|
|
480
|
+
if (wildcards_expandCheck(command)) {
|
|
481
|
+
const expandResult = await wildcards_expandAll(args);
|
|
482
|
+
if (!expandResult.ok) {
|
|
483
|
+
const lastError = errorStack.stack_pop();
|
|
484
|
+
const errorMsg = lastError ? error_stripDebugPrefix(lastError.message) : 'Unknown error';
|
|
485
|
+
return { text: chalk.red(`${errorMsg}\n`), buffer: Buffer.from('') };
|
|
486
|
+
}
|
|
487
|
+
args = expandResult.value;
|
|
488
|
+
}
|
|
489
|
+
return output_capture(async () => {
|
|
490
|
+
if (command === 'exit') {
|
|
491
|
+
process.exit(0);
|
|
492
|
+
}
|
|
493
|
+
if (await pluginExecutable_handle(command, args, { piped: true })) {
|
|
494
|
+
return;
|
|
495
|
+
}
|
|
496
|
+
const handler = COMMAND_HANDLERS[command];
|
|
497
|
+
if (handler) {
|
|
498
|
+
await handler(args);
|
|
499
|
+
return;
|
|
500
|
+
}
|
|
501
|
+
console.log(chalk.yellow(`Unknown chell command '${command}' -- delegating to chili`));
|
|
502
|
+
await chiliCommand_run(command, ['-s', ...args]);
|
|
503
|
+
});
|
|
504
|
+
}
|
|
505
|
+
/**
|
|
506
|
+
* Executes a pipe chain by running the first command in chell and piping through local tools.
|
|
507
|
+
*
|
|
508
|
+
* @param segments - Array of command segments separated by pipes.
|
|
509
|
+
* @returns A Promise that resolves when the pipe chain completes.
|
|
510
|
+
*/
|
|
511
|
+
async function pipe_execute(segments) {
|
|
512
|
+
if (segments.length === 0)
|
|
513
|
+
return;
|
|
514
|
+
// Execute first segment in chell and capture output
|
|
515
|
+
const firstCommand = segments[0];
|
|
516
|
+
const { buffer } = await chellCommand_executeAndCapture(firstCommand);
|
|
517
|
+
if (segments.length === 1) {
|
|
518
|
+
// No pipes, just output the result
|
|
519
|
+
process.stdout.write(buffer);
|
|
520
|
+
return;
|
|
521
|
+
}
|
|
522
|
+
// Chain remaining segments as spawned processes
|
|
523
|
+
let currentInput = buffer;
|
|
524
|
+
for (let i = 1; i < segments.length; i++) {
|
|
525
|
+
currentInput = await segment_pipeThrough(segments[i], currentInput);
|
|
526
|
+
}
|
|
527
|
+
// Output final result
|
|
528
|
+
process.stdout.write(currentInput);
|
|
529
|
+
}
|
|
530
|
+
/**
|
|
531
|
+
* Whether a batch (semicolon list, script) should abort on the first error.
|
|
532
|
+
* Read by {@link semicolons_handle}; set by the boot layer for `-e` / script modes.
|
|
533
|
+
*/
|
|
534
|
+
let stopOnError = false;
|
|
535
|
+
/**
|
|
536
|
+
* Sets the shared stop-on-error flag. Exposed so the boot layer (which owns the
|
|
537
|
+
* `-e` flag and script execution) can drive the flag that the dispatch layer reads.
|
|
538
|
+
*
|
|
539
|
+
* @param value - `true` to abort a batch on the first error.
|
|
540
|
+
*/
|
|
541
|
+
export function stopOnError_set(value) {
|
|
542
|
+
stopOnError = value;
|
|
543
|
+
}
|
|
544
|
+
//# sourceMappingURL=dispatch.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"dispatch.js","sourceRoot":"","sources":["../../src/core/dispatch.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AACH,OAAO,EAAE,aAAa,EAAE,cAAc,EAAE,MAAM,IAAI,CAAC;AACnD,OAAO,KAAK,MAAM,OAAO,CAAC;AAC1B,OAAO,EAAE,KAAK,EAAgB,MAAM,eAAe,CAAC;AACpD,OAAO,EAAE,OAAO,EAAE,MAAM,qBAAqB,CAAC;AAC9C,OAAO,EACL,UAAU,EACV,UAAU,EACV,WAAW,EACX,eAAe,EACf,cAAc,EACd,WAAW,EACX,UAAU,EACV,UAAU,EACV,cAAc,EACd,YAAY,EACZ,gBAAgB,EAChB,YAAY,EACZ,aAAa,EACb,gBAAgB,EAChB,UAAU,EACV,aAAa,EACb,aAAa,EACb,cAAc,EACd,YAAY,EACZ,eAAe,EACf,WAAW,EACX,aAAa,EACb,kBAAkB,EAClB,sBAAsB,EACtB,gBAAgB,EAChB,gBAAgB,EAChB,YAAY,EACZ,aAAa,EACb,aAAa,EACb,YAAY,EACZ,eAAe,EACf,0BAA0B,EAC1B,oBAAoB,EACpB,cAAc,EACd,cAAc,EACd,cAAc,EACd,gBAAgB,EAChB,aAAa,EACb,YAAY,EACZ,YAAY,EACZ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,EAAE,CAAC;QAC1B,mCAAmC;QACnC,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC,MAAM,CAAC,CAAC;QAC7B,OAAO;IACT,CAAC;IAED,gDAAgD;IAChD,IAAI,YAAY,GAAW,MAAM,CAAC;IAClC,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,QAAQ,CAAC,MAAM,EAAE,CAAC,EAAE,EAAE,CAAC;QACzC,YAAY,GAAG,MAAM,mBAAmB,CAAC,QAAQ,CAAC,CAAC,CAAC,EAAE,YAAY,CAAC,CAAC;IACtE,CAAC;IAED,sBAAsB;IACtB,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC,YAAY,CAAC,CAAC;AACrC,CAAC;AAED;;;GAGG;AACH,IAAI,WAAW,GAAY,KAAK,CAAC;AAEjC;;;;;GAKG;AACH,MAAM,UAAU,eAAe,CAAC,KAAc;IAC5C,WAAW,GAAG,KAAK,CAAC;AACtB,CAAC"}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import { Result } from '@fnndsc/cumin';
|
|
2
|
+
/**
|
|
3
|
+
* Determines if a command should have its arguments expanded for wildcards.
|
|
4
|
+
*
|
|
5
|
+
* @param command - The command name.
|
|
6
|
+
* @returns True if wildcards should be expanded.
|
|
7
|
+
*/
|
|
8
|
+
export declare function wildcards_expandCheck(command: string): boolean;
|
|
9
|
+
/**
|
|
10
|
+
* Returns true if the input line is a shell escape (starts with `!`).
|
|
11
|
+
*
|
|
12
|
+
* @param line - Trimmed input line.
|
|
13
|
+
*/
|
|
14
|
+
export declare function command_shellEscape_detect(line: string): boolean;
|
|
15
|
+
/**
|
|
16
|
+
* Parses a command line for pipe operators and returns segments.
|
|
17
|
+
* Respects single and double quotes.
|
|
18
|
+
*
|
|
19
|
+
* @param line - The full command line.
|
|
20
|
+
* @returns An array of command segments.
|
|
21
|
+
*/
|
|
22
|
+
export declare function pipes_parse(line: string): string[];
|
|
23
|
+
/** Parsed output-redirection: command plus target file and append/overwrite. */
|
|
24
|
+
export interface RedirectInfo {
|
|
25
|
+
command: string;
|
|
26
|
+
operator: '>' | '>>';
|
|
27
|
+
filePath: string;
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* Parses a command line for output redirection operators (> or >>).
|
|
31
|
+
* Respects single and double quotes.
|
|
32
|
+
*
|
|
33
|
+
* @param line - The full command line.
|
|
34
|
+
* @returns An object with the command and redirect info, or null if no redirection.
|
|
35
|
+
*/
|
|
36
|
+
export declare function redirect_parse(line: string): RedirectInfo | null;
|
|
37
|
+
/**
|
|
38
|
+
* Resolves the final redirect target path. If the target is an existing directory
|
|
39
|
+
* and the source command is `cat <file>`, resolves to `<dir>/<basename>`.
|
|
40
|
+
* Returns Err (with message on errorStack) when the filename cannot be determined.
|
|
41
|
+
*
|
|
42
|
+
* @param filePath - The redirect target path as written by the user.
|
|
43
|
+
* @param commandLine - The command whose output is being redirected.
|
|
44
|
+
* @returns Ok(resolved path) or Err on failure.
|
|
45
|
+
*/
|
|
46
|
+
export declare function redirectTarget_resolve(filePath: string, commandLine: string): Result<string>;
|