@fnndsc/brasa 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/dist/builtins/debug.d.ts +8 -0
- package/dist/builtins/debug.js +39 -0
- package/dist/builtins/debug.js.map +1 -0
- package/dist/builtins/executable.d.ts +22 -0
- package/dist/builtins/executable.js +115 -0
- package/dist/builtins/executable.js.map +1 -0
- package/dist/builtins/fs/cat.d.ts +16 -0
- package/dist/builtins/fs/cat.js +266 -0
- package/dist/builtins/fs/cat.js.map +1 -0
- package/dist/builtins/fs/cd.d.ts +42 -0
- package/dist/builtins/fs/cd.js +193 -0
- package/dist/builtins/fs/cd.js.map +1 -0
- package/dist/builtins/fs/cp.d.ts +10 -0
- package/dist/builtins/fs/cp.js +86 -0
- package/dist/builtins/fs/cp.js.map +1 -0
- package/dist/builtins/fs/download.d.ts +6 -0
- package/dist/builtins/fs/download.js +45 -0
- package/dist/builtins/fs/download.js.map +1 -0
- package/dist/builtins/fs/du.d.ts +58 -0
- package/dist/builtins/fs/du.js +210 -0
- package/dist/builtins/fs/du.js.map +1 -0
- package/dist/builtins/fs/edit.d.ts +7 -0
- package/dist/builtins/fs/edit.js +104 -0
- package/dist/builtins/fs/edit.js.map +1 -0
- package/dist/builtins/fs/ls.d.ts +8 -0
- package/dist/builtins/fs/ls.js +68 -0
- package/dist/builtins/fs/ls.js.map +1 -0
- package/dist/builtins/fs/mkdir.d.ts +9 -0
- package/dist/builtins/fs/mkdir.js +52 -0
- package/dist/builtins/fs/mkdir.js.map +1 -0
- package/dist/builtins/fs/mv.d.ts +10 -0
- package/dist/builtins/fs/mv.js +88 -0
- package/dist/builtins/fs/mv.js.map +1 -0
- package/dist/builtins/fs/pull.args.d.ts +22 -0
- package/dist/builtins/fs/pull.args.js +30 -0
- package/dist/builtins/fs/pull.args.js.map +1 -0
- package/dist/builtins/fs/pull.d.ts +26 -0
- package/dist/builtins/fs/pull.js +445 -0
- package/dist/builtins/fs/pull.js.map +1 -0
- package/dist/builtins/fs/pwd.d.ts +10 -0
- package/dist/builtins/fs/pwd.js +73 -0
- package/dist/builtins/fs/pwd.js.map +1 -0
- package/dist/builtins/fs/rm.d.ts +37 -0
- package/dist/builtins/fs/rm.js +197 -0
- package/dist/builtins/fs/rm.js.map +1 -0
- package/dist/builtins/fs/touch.d.ts +9 -0
- package/dist/builtins/fs/touch.js +76 -0
- package/dist/builtins/fs/touch.js.map +1 -0
- package/dist/builtins/fs/tree.d.ts +15 -0
- package/dist/builtins/fs/tree.js +84 -0
- package/dist/builtins/fs/tree.js.map +1 -0
- package/dist/builtins/fs/upload.d.ts +6 -0
- package/dist/builtins/fs/upload.js +48 -0
- package/dist/builtins/fs/upload.js.map +1 -0
- package/dist/builtins/help.d.ts +74 -0
- package/dist/builtins/help.js +1217 -0
- package/dist/builtins/help.js.map +1 -0
- package/dist/builtins/index.d.ts +45 -0
- package/dist/builtins/index.js +45 -0
- package/dist/builtins/index.js.map +1 -0
- package/dist/builtins/net/connect.d.ts +7 -0
- package/dist/builtins/net/connect.js +42 -0
- package/dist/builtins/net/connect.js.map +1 -0
- package/dist/builtins/net/cubepath.d.ts +18 -0
- package/dist/builtins/net/cubepath.js +102 -0
- package/dist/builtins/net/cubepath.js.map +1 -0
- package/dist/builtins/net/logout.d.ts +6 -0
- package/dist/builtins/net/logout.js +24 -0
- package/dist/builtins/net/logout.js.map +1 -0
- package/dist/builtins/net/pacs.d.ts +24 -0
- package/dist/builtins/net/pacs.js +121 -0
- package/dist/builtins/net/pacs.js.map +1 -0
- package/dist/builtins/net/pacsUtils.d.ts +85 -0
- package/dist/builtins/net/pacsUtils.js +184 -0
- package/dist/builtins/net/pacsUtils.js.map +1 -0
- package/dist/builtins/net/query.d.ts +60 -0
- package/dist/builtins/net/query.js +324 -0
- package/dist/builtins/net/query.js.map +1 -0
- package/dist/builtins/parametersofplugin.d.ts +13 -0
- package/dist/builtins/parametersofplugin.js +43 -0
- package/dist/builtins/parametersofplugin.js.map +1 -0
- package/dist/builtins/pluginExecute.d.ts +27 -0
- package/dist/builtins/pluginExecute.js +165 -0
- package/dist/builtins/pluginExecute.js.map +1 -0
- package/dist/builtins/proc.d.ts +6 -0
- package/dist/builtins/proc.helpers.d.ts +68 -0
- package/dist/builtins/proc.helpers.js +102 -0
- package/dist/builtins/proc.helpers.js.map +1 -0
- package/dist/builtins/proc.js +289 -0
- package/dist/builtins/proc.js.map +1 -0
- package/dist/builtins/res/compute.d.ts +6 -0
- package/dist/builtins/res/compute.js +55 -0
- package/dist/builtins/res/compute.js.map +1 -0
- package/dist/builtins/res/feed.d.ts +6 -0
- package/dist/builtins/res/feed.js +244 -0
- package/dist/builtins/res/feed.js.map +1 -0
- package/dist/builtins/res/feed.notes.d.ts +28 -0
- package/dist/builtins/res/feed.notes.js +24 -0
- package/dist/builtins/res/feed.notes.js.map +1 -0
- package/dist/builtins/res/files.d.ts +18 -0
- package/dist/builtins/res/files.js +85 -0
- package/dist/builtins/res/files.js.map +1 -0
- package/dist/builtins/res/group.d.ts +6 -0
- package/dist/builtins/res/group.js +54 -0
- package/dist/builtins/res/group.js.map +1 -0
- package/dist/builtins/res/pipeline.args.d.ts +22 -0
- package/dist/builtins/res/pipeline.args.js +28 -0
- package/dist/builtins/res/pipeline.args.js.map +1 -0
- package/dist/builtins/res/pipeline.d.ts +20 -0
- package/dist/builtins/res/pipeline.js +252 -0
- package/dist/builtins/res/pipeline.js.map +1 -0
- package/dist/builtins/res/plugin.d.ts +13 -0
- package/dist/builtins/res/plugin.js +140 -0
- package/dist/builtins/res/plugin.js.map +1 -0
- package/dist/builtins/res/plugininstance.d.ts +6 -0
- package/dist/builtins/res/plugininstance.js +53 -0
- package/dist/builtins/res/plugininstance.js.map +1 -0
- package/dist/builtins/res/pluginmeta.d.ts +6 -0
- package/dist/builtins/res/pluginmeta.js +53 -0
- package/dist/builtins/res/pluginmeta.js.map +1 -0
- package/dist/builtins/res/tag.d.ts +6 -0
- package/dist/builtins/res/tag.js +53 -0
- package/dist/builtins/res/tag.js.map +1 -0
- package/dist/builtins/res/workflow.d.ts +6 -0
- package/dist/builtins/res/workflow.js +53 -0
- package/dist/builtins/res/workflow.js.map +1 -0
- package/dist/builtins/store.d.ts +6 -0
- package/dist/builtins/store.js +107 -0
- package/dist/builtins/store.js.map +1 -0
- package/dist/builtins/sys/context.d.ts +6 -0
- package/dist/builtins/sys/context.js +50 -0
- package/dist/builtins/sys/context.js.map +1 -0
- package/dist/builtins/sys/physicalmode.d.ts +8 -0
- package/dist/builtins/sys/physicalmode.js +34 -0
- package/dist/builtins/sys/physicalmode.js.map +1 -0
- package/dist/builtins/sys/timing.d.ts +8 -0
- package/dist/builtins/sys/timing.js +34 -0
- package/dist/builtins/sys/timing.js.map +1 -0
- package/dist/builtins/sys/version.d.ts +15 -0
- package/dist/builtins/sys/version.js +23 -0
- package/dist/builtins/sys/version.js.map +1 -0
- package/dist/builtins/sys/whoami.d.ts +17 -0
- package/dist/builtins/sys/whoami.js +44 -0
- package/dist/builtins/sys/whoami.js.map +1 -0
- package/dist/builtins/utils.d.ts +55 -0
- package/dist/builtins/utils.js +145 -0
- package/dist/builtins/utils.js.map +1 -0
- package/dist/builtins/wildcard.d.ts +26 -0
- package/dist/builtins/wildcard.js +120 -0
- package/dist/builtins/wildcard.js.map +1 -0
- package/dist/command-keys.d.ts +8 -0
- package/dist/command-keys.js +32 -0
- package/dist/command-keys.js.map +1 -0
- package/dist/config/storeConfig.d.ts +57 -0
- package/dist/config/storeConfig.js +78 -0
- package/dist/config/storeConfig.js.map +1 -0
- package/dist/core/chiliDelegate.d.ts +21 -0
- package/dist/core/chiliDelegate.js +32 -0
- package/dist/core/chiliDelegate.js.map +1 -0
- package/dist/core/connect.d.ts +38 -0
- package/dist/core/connect.js +46 -0
- package/dist/core/connect.js.map +1 -0
- package/dist/core/dispatch.d.ts +95 -0
- package/dist/core/dispatch.js +618 -0
- package/dist/core/dispatch.js.map +1 -0
- package/dist/core/engine.d.ts +91 -0
- package/dist/core/engine.js +222 -0
- package/dist/core/engine.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/core/progress.d.ts +50 -0
- package/dist/core/progress.js +21 -0
- package/dist/core/progress.js.map +1 -0
- package/dist/core/promptContext.d.ts +49 -0
- package/dist/core/promptContext.js +39 -0
- package/dist/core/promptContext.js.map +1 -0
- package/dist/core/question.d.ts +27 -0
- package/dist/core/question.js +33 -0
- package/dist/core/question.js.map +1 -0
- package/dist/core/sink.d.ts +207 -0
- package/dist/core/sink.js +329 -0
- package/dist/core/sink.js.map +1 -0
- package/dist/core/surface.d.ts +172 -0
- package/dist/core/surface.js +105 -0
- package/dist/core/surface.js.map +1 -0
- package/dist/core/version.d.ts +20 -0
- package/dist/core/version.js +82 -0
- package/dist/core/version.js.map +1 -0
- package/dist/index.d.ts +31 -0
- package/dist/index.js +32 -0
- package/dist/index.js.map +1 -0
- package/dist/lib/completer/index.d.ts +15 -0
- package/dist/lib/completer/index.js +212 -0
- package/dist/lib/completer/index.js.map +1 -0
- package/dist/lib/completer/pathComplete.helpers.d.ts +22 -0
- package/dist/lib/completer/pathComplete.helpers.js +49 -0
- package/dist/lib/completer/pathComplete.helpers.js.map +1 -0
- package/dist/lib/parser.d.ts +13 -0
- package/dist/lib/parser.js +52 -0
- package/dist/lib/parser.js.map +1 -0
- package/dist/lib/pipe.d.ts +11 -0
- package/dist/lib/pipe.js +90 -0
- package/dist/lib/pipe.js.map +1 -0
- package/dist/lib/prefetch.d.ts +25 -0
- package/dist/lib/prefetch.js +64 -0
- package/dist/lib/prefetch.js.map +1 -0
- package/dist/lib/semicolonParser.d.ts +22 -0
- package/dist/lib/semicolonParser.js +53 -0
- package/dist/lib/semicolonParser.js.map +1 -0
- package/dist/lib/spinner.d.ts +23 -0
- package/dist/lib/spinner.js +71 -0
- package/dist/lib/spinner.js.map +1 -0
- package/dist/lib/vfs/providers/static.d.ts +65 -0
- package/dist/lib/vfs/providers/static.js +164 -0
- package/dist/lib/vfs/providers/static.js.map +1 -0
- package/dist/lib/vfs/providers/static_content.d.ts +27 -0
- package/dist/lib/vfs/providers/static_content.js +180 -0
- package/dist/lib/vfs/providers/static_content.js.map +1 -0
- package/dist/lib/vfs/vfs.d.ts +59 -0
- package/dist/lib/vfs/vfs.js +202 -0
- package/dist/lib/vfs/vfs.js.map +1 -0
- package/dist/session/index.d.ts +76 -0
- package/dist/session/index.js +120 -0
- package/dist/session/index.js.map +1 -0
- package/package.json +58 -0
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @file The session's prompt context: the engine-known facts a prompt reflects.
|
|
3
|
+
*
|
|
4
|
+
* A prompt shows live session state — user, CUBE, working directory, PACS,
|
|
5
|
+
* physical-mode, warm-up progress — plus the last command's outcome. Only the
|
|
6
|
+
* process holding the session can know these, but how they are *rendered*
|
|
7
|
+
* (theme, segments, terminal width) is a frontend concern. This module builds
|
|
8
|
+
* the engine half; each frontend renders it with its own theme, so the daemon
|
|
9
|
+
* ships context and never a themed string.
|
|
10
|
+
*
|
|
11
|
+
* @module
|
|
12
|
+
*/
|
|
13
|
+
import { session } from '../session/index.js';
|
|
14
|
+
import { context_getSingle } from '@fnndsc/salsa';
|
|
15
|
+
import { procCache_get } from '@fnndsc/cumin';
|
|
16
|
+
/**
|
|
17
|
+
* Builds the current session's prompt context.
|
|
18
|
+
*
|
|
19
|
+
* @param options - The last-command inputs the session cannot know.
|
|
20
|
+
* @returns The engine-known prompt facts.
|
|
21
|
+
*/
|
|
22
|
+
export async function sessionPromptContext_build(options = {}) {
|
|
23
|
+
const context = await context_getSingle();
|
|
24
|
+
const cwd = await session.getCWD();
|
|
25
|
+
const isOffline = session.offline;
|
|
26
|
+
const warmupRaw = procCache_get().warmupProgress_get();
|
|
27
|
+
const procWarmup = warmupRaw.active ? { loaded: warmupRaw.loaded } : undefined;
|
|
28
|
+
return {
|
|
29
|
+
user: isOffline ? 'disconnected' : (context.user ?? 'disconnected'),
|
|
30
|
+
uri: isOffline ? 'no-cube' : (context.URL ?? 'no-cube'),
|
|
31
|
+
cwd: isOffline ? '/' : cwd,
|
|
32
|
+
pacsserver: context.pacsserver ?? null,
|
|
33
|
+
physicalMode: session.physicalMode_get(),
|
|
34
|
+
lastExitCode: options.lastExitCode ?? 0,
|
|
35
|
+
lastCommandDurationMs: options.lastCommandDurationMs ?? 0,
|
|
36
|
+
procWarmup,
|
|
37
|
+
};
|
|
38
|
+
}
|
|
39
|
+
//# sourceMappingURL=promptContext.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"promptContext.js","sourceRoot":"","sources":["../../src/core/promptContext.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAEH,OAAO,EAAE,OAAO,EAAE,MAAM,qBAAqB,CAAC;AAC9C,OAAO,EAAE,iBAAiB,EAAE,MAAM,eAAe,CAAC;AAClD,OAAO,EAAiB,aAAa,EAA2B,MAAM,eAAe,CAAC;AAgCtF;;;;;GAKG;AACH,MAAM,CAAC,KAAK,UAAU,0BAA0B,CAC9C,UAAuC,EAAE;IAEzC,MAAM,OAAO,GAAkB,MAAM,iBAAiB,EAAE,CAAC;IACzD,MAAM,GAAG,GAAW,MAAM,OAAO,CAAC,MAAM,EAAE,CAAC;IAC3C,MAAM,SAAS,GAAY,OAAO,CAAC,OAAO,CAAC;IAE3C,MAAM,SAAS,GAAuB,aAAa,EAAE,CAAC,kBAAkB,EAAE,CAAC;IAC3E,MAAM,UAAU,GACd,SAAS,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,MAAM,EAAE,SAAS,CAAC,MAAM,EAAE,CAAC,CAAC,CAAC,SAAS,CAAC;IAE9D,OAAO;QACL,IAAI,EAAmB,SAAS,CAAC,CAAC,CAAC,cAAc,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,IAAI,IAAI,cAAc,CAAC;QACpF,GAAG,EAAoB,SAAS,CAAC,CAAC,CAAC,SAAS,CAAM,CAAC,CAAC,CAAC,OAAO,CAAC,GAAG,IAAK,SAAS,CAAC;QAC/E,GAAG,EAAoB,SAAS,CAAC,CAAC,CAAC,GAAG,CAAY,CAAC,CAAC,GAAG;QACvD,UAAU,EAAa,OAAO,CAAC,UAAU,IAAI,IAAI;QACjD,YAAY,EAAW,OAAO,CAAC,gBAAgB,EAAE;QACjD,YAAY,EAAW,OAAO,CAAC,YAAY,IAAI,CAAC;QAChD,qBAAqB,EAAE,OAAO,CAAC,qBAAqB,IAAI,CAAC;QACzD,UAAU;KACX,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @file Shared question helpers for builtins.
|
|
3
|
+
*
|
|
4
|
+
* Thin adapters over the active {@link Surface}'s prompt operation. Builtins
|
|
5
|
+
* (and the salsa admin-prompt flow, which is handed these functions) call
|
|
6
|
+
* `repl_question` / `repl_questionHidden` and remain unaware of how the host
|
|
7
|
+
* actually reads input — a local readline interface, or a request to a remote
|
|
8
|
+
* surface. The host installs the surface (see `./cliSurface.js`); until it
|
|
9
|
+
* does, the default surface fails these calls with a clear message rather
|
|
10
|
+
* than hanging on a standard input that is not there.
|
|
11
|
+
*
|
|
12
|
+
* @module
|
|
13
|
+
*/
|
|
14
|
+
/**
|
|
15
|
+
* Asks a question through the active surface.
|
|
16
|
+
*
|
|
17
|
+
* @param prompt - The question string to display.
|
|
18
|
+
* @returns The trimmed user answer.
|
|
19
|
+
*/
|
|
20
|
+
export declare function repl_question(prompt: string): Promise<string>;
|
|
21
|
+
/**
|
|
22
|
+
* Asks for a secret (no echo) through the active surface.
|
|
23
|
+
*
|
|
24
|
+
* @param prompt - The prompt string to display.
|
|
25
|
+
* @returns The trimmed secret string.
|
|
26
|
+
*/
|
|
27
|
+
export declare function repl_questionHidden(prompt: string): Promise<string>;
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @file Shared question helpers for builtins.
|
|
3
|
+
*
|
|
4
|
+
* Thin adapters over the active {@link Surface}'s prompt operation. Builtins
|
|
5
|
+
* (and the salsa admin-prompt flow, which is handed these functions) call
|
|
6
|
+
* `repl_question` / `repl_questionHidden` and remain unaware of how the host
|
|
7
|
+
* actually reads input — a local readline interface, or a request to a remote
|
|
8
|
+
* surface. The host installs the surface (see `./cliSurface.js`); until it
|
|
9
|
+
* does, the default surface fails these calls with a clear message rather
|
|
10
|
+
* than hanging on a standard input that is not there.
|
|
11
|
+
*
|
|
12
|
+
* @module
|
|
13
|
+
*/
|
|
14
|
+
import { surface_get } from './surface.js';
|
|
15
|
+
/**
|
|
16
|
+
* Asks a question through the active surface.
|
|
17
|
+
*
|
|
18
|
+
* @param prompt - The question string to display.
|
|
19
|
+
* @returns The trimmed user answer.
|
|
20
|
+
*/
|
|
21
|
+
export function repl_question(prompt) {
|
|
22
|
+
return surface_get().prompt({ message: prompt });
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* Asks for a secret (no echo) through the active surface.
|
|
26
|
+
*
|
|
27
|
+
* @param prompt - The prompt string to display.
|
|
28
|
+
* @returns The trimmed secret string.
|
|
29
|
+
*/
|
|
30
|
+
export function repl_questionHidden(prompt) {
|
|
31
|
+
return surface_get().prompt({ message: prompt, hidden: true });
|
|
32
|
+
}
|
|
33
|
+
//# sourceMappingURL=question.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"question.js","sourceRoot":"","sources":["../../src/core/question.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AAEH,OAAO,EAAE,WAAW,EAAE,MAAM,cAAc,CAAC;AAE3C;;;;;GAKG;AACH,MAAM,UAAU,aAAa,CAAC,MAAc;IAC1C,OAAO,WAAW,EAAE,CAAC,MAAM,CAAC,EAAE,OAAO,EAAE,MAAM,EAAE,CAAC,CAAC;AACnD,CAAC;AAED;;;;;GAKG;AACH,MAAM,UAAU,mBAAmB,CAAC,MAAc;IAChD,OAAO,WAAW,EAAE,CAAC,MAAM,CAAC,EAAE,OAAO,EAAE,MAAM,EAAE,MAAM,EAAE,IAAI,EAAE,CAAC,CAAC;AACjE,CAAC"}
|
|
@@ -0,0 +1,207 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @file Output sink: the seam through which command output leaves the engine.
|
|
3
|
+
*
|
|
4
|
+
* Builtins historically printed straight to process stdout, which fuses the
|
|
5
|
+
* engine to a terminal. The sink inverts that: output is written to whatever
|
|
6
|
+
* sink the host installed, and only the host knows where bytes finally go
|
|
7
|
+
* (a terminal for the CLI REPL, a capture buffer for pipes, a connection for
|
|
8
|
+
* a remote surface).
|
|
9
|
+
*
|
|
10
|
+
* Three channels are distinguished. Data is the command's actual output: it
|
|
11
|
+
* is accumulated into the command's result envelope and is what capture,
|
|
12
|
+
* piping and redirection consume. Err is the error stream: presented to the
|
|
13
|
+
* user, never piped, never captured. Status is ephemeral (spinners,
|
|
14
|
+
* progress, transient messages): displayed live, never accumulated, never
|
|
15
|
+
* piped.
|
|
16
|
+
*
|
|
17
|
+
* This module also provides delivery helpers that bridge envelope-returning
|
|
18
|
+
* builtins into the existing dispatch table, so conversion can proceed one
|
|
19
|
+
* builtin at a time while unconverted builtins keep printing.
|
|
20
|
+
*
|
|
21
|
+
* @see docs/calypso.adoc for the governing design.
|
|
22
|
+
* @module
|
|
23
|
+
*/
|
|
24
|
+
import type { CommandEnvelope } from '@fnndsc/cumin';
|
|
25
|
+
import { type ProgressEvent, type ProgressRenderer } from './progress.js';
|
|
26
|
+
/**
|
|
27
|
+
* Destination for command output, installed by the host.
|
|
28
|
+
*/
|
|
29
|
+
export interface OutputSink {
|
|
30
|
+
/**
|
|
31
|
+
* Writes command output (the data channel).
|
|
32
|
+
*
|
|
33
|
+
* @param chunk - Printable text (ANSI permitted) or raw bytes.
|
|
34
|
+
*/
|
|
35
|
+
data_write(chunk: string | Buffer): void;
|
|
36
|
+
/**
|
|
37
|
+
* Writes error-stream output (the err channel).
|
|
38
|
+
*
|
|
39
|
+
* @param chunk - Printable text (ANSI permitted) or raw bytes.
|
|
40
|
+
*/
|
|
41
|
+
err_write(chunk: string | Buffer): void;
|
|
42
|
+
/**
|
|
43
|
+
* Writes an ephemeral status line (the status channel).
|
|
44
|
+
*
|
|
45
|
+
* @param text - Transient text; consumers may overwrite or drop it.
|
|
46
|
+
*/
|
|
47
|
+
status_write(text: string): void;
|
|
48
|
+
progress_write(event: ProgressEvent): void;
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* Sink that writes both channels to the process's standard output.
|
|
52
|
+
*
|
|
53
|
+
* This is the CLI host's sink and the default, preserving the shell's
|
|
54
|
+
* historical behavior exactly.
|
|
55
|
+
*/
|
|
56
|
+
export declare class StdoutSink implements OutputSink {
|
|
57
|
+
private readonly progressRenderer;
|
|
58
|
+
constructor(progressRenderer?: ProgressRenderer);
|
|
59
|
+
/** @inheritdoc */
|
|
60
|
+
data_write(chunk: string | Buffer): void;
|
|
61
|
+
/** @inheritdoc */
|
|
62
|
+
err_write(chunk: string | Buffer): void;
|
|
63
|
+
/** @inheritdoc */
|
|
64
|
+
status_write(text: string): void;
|
|
65
|
+
progress_write(event: ProgressEvent): void;
|
|
66
|
+
}
|
|
67
|
+
/**
|
|
68
|
+
* Sink that accumulates the data channel in memory and drops status.
|
|
69
|
+
*
|
|
70
|
+
* Used by capture paths and tests; will carry the pipe and redirect
|
|
71
|
+
* machinery once those consume envelopes.
|
|
72
|
+
*/
|
|
73
|
+
export declare class BufferSink implements OutputSink {
|
|
74
|
+
private chunks;
|
|
75
|
+
/** @inheritdoc */
|
|
76
|
+
data_write(chunk: string | Buffer): void;
|
|
77
|
+
/** @inheritdoc */
|
|
78
|
+
err_write(chunk: string | Buffer): void;
|
|
79
|
+
/** @inheritdoc */
|
|
80
|
+
status_write(_text: string): void;
|
|
81
|
+
progress_write(_event: ProgressEvent): void;
|
|
82
|
+
/**
|
|
83
|
+
* Returns everything written to the data channel so far.
|
|
84
|
+
*
|
|
85
|
+
* @returns The accumulated bytes.
|
|
86
|
+
*/
|
|
87
|
+
buffer_get(): Buffer;
|
|
88
|
+
/**
|
|
89
|
+
* Returns the accumulated data channel as UTF-8 text.
|
|
90
|
+
*
|
|
91
|
+
* @returns The accumulated text.
|
|
92
|
+
*/
|
|
93
|
+
text_get(): string;
|
|
94
|
+
}
|
|
95
|
+
/**
|
|
96
|
+
* Sink that captures the data and err channels while passing status through
|
|
97
|
+
* to a live sink, so transients (spinners, progress) remain visible while a
|
|
98
|
+
* legacy printing command's output is being gathered into an envelope.
|
|
99
|
+
*/
|
|
100
|
+
export declare class CaptureSink implements OutputSink {
|
|
101
|
+
private dataChunks;
|
|
102
|
+
private errChunks;
|
|
103
|
+
private live;
|
|
104
|
+
private readonly forwardEnvelopeOutput;
|
|
105
|
+
/**
|
|
106
|
+
* Initializes the capture around a live sink for status passthrough.
|
|
107
|
+
*
|
|
108
|
+
* @param live - The sink that continues to receive status writes.
|
|
109
|
+
*/
|
|
110
|
+
constructor(live: OutputSink, options?: {
|
|
111
|
+
forwardEnvelopeOutput?: boolean;
|
|
112
|
+
});
|
|
113
|
+
/** @inheritdoc */
|
|
114
|
+
data_write(chunk: string | Buffer): void;
|
|
115
|
+
/** @inheritdoc */
|
|
116
|
+
err_write(chunk: string | Buffer): void;
|
|
117
|
+
/** @inheritdoc */
|
|
118
|
+
status_write(text: string): void;
|
|
119
|
+
progress_write(event: ProgressEvent): void;
|
|
120
|
+
/**
|
|
121
|
+
* Returns the captured data channel as UTF-8 text.
|
|
122
|
+
*
|
|
123
|
+
* @returns The captured data text.
|
|
124
|
+
*/
|
|
125
|
+
dataText_get(): string;
|
|
126
|
+
/**
|
|
127
|
+
* Returns the captured err channel as UTF-8 text.
|
|
128
|
+
*
|
|
129
|
+
* @returns The captured error-stream text.
|
|
130
|
+
*/
|
|
131
|
+
errText_get(): string;
|
|
132
|
+
}
|
|
133
|
+
/**
|
|
134
|
+
* Returns the sink in effect for the current async context.
|
|
135
|
+
*
|
|
136
|
+
* Inside a captured command this is that command's capture sink; otherwise it
|
|
137
|
+
* is the host sink.
|
|
138
|
+
*
|
|
139
|
+
* @returns The active output sink.
|
|
140
|
+
*/
|
|
141
|
+
export declare function sink_get(): OutputSink;
|
|
142
|
+
/**
|
|
143
|
+
* Installs the host sink. Called by the host that owns the output destination.
|
|
144
|
+
*
|
|
145
|
+
* This sets the process-wide default, not the per-invocation scope, so a host
|
|
146
|
+
* installs it once at startup. Capture scopes established during command
|
|
147
|
+
* execution take precedence over it via {@link sink_get}.
|
|
148
|
+
*
|
|
149
|
+
* @param sink - The sink to install.
|
|
150
|
+
* @returns The previously installed host sink, so callers can restore it.
|
|
151
|
+
*/
|
|
152
|
+
export declare function sink_set(sink: OutputSink): OutputSink;
|
|
153
|
+
/**
|
|
154
|
+
* Delivers a completed envelope to the active sink.
|
|
155
|
+
*
|
|
156
|
+
* Rendered text goes to the data channel and error-stream text to the err
|
|
157
|
+
* channel. The structured errors field is machine-facing and is not
|
|
158
|
+
* presented here: its terminal presentation, when any, travels in
|
|
159
|
+
* renderedErr.
|
|
160
|
+
*
|
|
161
|
+
* @param envelope - The completed command envelope.
|
|
162
|
+
*/
|
|
163
|
+
export declare function envelope_deliver(envelope: CommandEnvelope): void;
|
|
164
|
+
/**
|
|
165
|
+
* Adapts an envelope-returning builtin to the legacy printing handler shape.
|
|
166
|
+
*
|
|
167
|
+
* This is the compatibility bridge for incremental conversion: converted
|
|
168
|
+
* builtins return envelopes, and this wrapper delivers them through the
|
|
169
|
+
* active sink so the dispatch table, pipes and redirects need no changes.
|
|
170
|
+
* A handler that resolves without an envelope (as stubbed handlers in tests
|
|
171
|
+
* do) is treated as having produced no output.
|
|
172
|
+
*
|
|
173
|
+
* @param handler - An envelope-returning command handler.
|
|
174
|
+
* @returns A handler with the legacy void-returning shape.
|
|
175
|
+
*/
|
|
176
|
+
export declare function envelopeHandler_wrap(handler: (args: string[]) => Promise<CommandEnvelope>): (args: string[]) => Promise<void>;
|
|
177
|
+
/**
|
|
178
|
+
* Adapts a legacy printing builtin to the envelope-returning shape.
|
|
179
|
+
*
|
|
180
|
+
* This is the capture bridge for commands whose rendering lives below the
|
|
181
|
+
* seam (chili's table display prints internally): the handler runs with the
|
|
182
|
+
* data and err channels captured, console printing redirected into the
|
|
183
|
+
* capture, and status passed through live so spinners stay visible. The
|
|
184
|
+
* result is an envelope carrying the exact bytes each stream would have
|
|
185
|
+
* shown, with the status derived from the process exit code the handler set.
|
|
186
|
+
*
|
|
187
|
+
* Bridged commands gain envelope semantics without typed models; native
|
|
188
|
+
* conversion (models, streamed data) remains the end state for commands
|
|
189
|
+
* where a structural consumer exists.
|
|
190
|
+
*
|
|
191
|
+
* @param handler - A legacy printing command handler.
|
|
192
|
+
* @returns An envelope-returning handler with identical observable output.
|
|
193
|
+
*/
|
|
194
|
+
export declare function printingHandler_wrap(handler: (args: string[]) => Promise<void>): (args: string[]) => Promise<CommandEnvelope>;
|
|
195
|
+
/**
|
|
196
|
+
* Strips ANSI escape sequences from text.
|
|
197
|
+
*
|
|
198
|
+
* Applied at the pipe and redirect boundary so downstream consumers receive
|
|
199
|
+
* plain text, the way programs behind a real shell pipe see no color. This
|
|
200
|
+
* is a deliberate, documented deviation from the historical behavior, in
|
|
201
|
+
* which escape bytes leaked into pipes because color detection saw the
|
|
202
|
+
* terminal regardless of capture.
|
|
203
|
+
*
|
|
204
|
+
* @param text - Text possibly containing ANSI sequences.
|
|
205
|
+
* @returns The text with all ANSI sequences removed.
|
|
206
|
+
*/
|
|
207
|
+
export declare function ansi_strip(text: string): string;
|
|
@@ -0,0 +1,329 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @file Output sink: the seam through which command output leaves the engine.
|
|
3
|
+
*
|
|
4
|
+
* Builtins historically printed straight to process stdout, which fuses the
|
|
5
|
+
* engine to a terminal. The sink inverts that: output is written to whatever
|
|
6
|
+
* sink the host installed, and only the host knows where bytes finally go
|
|
7
|
+
* (a terminal for the CLI REPL, a capture buffer for pipes, a connection for
|
|
8
|
+
* a remote surface).
|
|
9
|
+
*
|
|
10
|
+
* Three channels are distinguished. Data is the command's actual output: it
|
|
11
|
+
* is accumulated into the command's result envelope and is what capture,
|
|
12
|
+
* piping and redirection consume. Err is the error stream: presented to the
|
|
13
|
+
* user, never piped, never captured. Status is ephemeral (spinners,
|
|
14
|
+
* progress, transient messages): displayed live, never accumulated, never
|
|
15
|
+
* piped.
|
|
16
|
+
*
|
|
17
|
+
* This module also provides delivery helpers that bridge envelope-returning
|
|
18
|
+
* builtins into the existing dispatch table, so conversion can proceed one
|
|
19
|
+
* builtin at a time while unconverted builtins keep printing.
|
|
20
|
+
*
|
|
21
|
+
* @see docs/calypso.adoc for the governing design.
|
|
22
|
+
* @module
|
|
23
|
+
*/
|
|
24
|
+
import { AsyncLocalStorage } from 'node:async_hooks';
|
|
25
|
+
import { NullProgressRenderer } from './progress.js';
|
|
26
|
+
function sink_streamsEnvelopeOutput(sink) {
|
|
27
|
+
return sink.liveEnvelopeOutput === true;
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* Sink that writes both channels to the process's standard output.
|
|
31
|
+
*
|
|
32
|
+
* This is the CLI host's sink and the default, preserving the shell's
|
|
33
|
+
* historical behavior exactly.
|
|
34
|
+
*/
|
|
35
|
+
export class StdoutSink {
|
|
36
|
+
progressRenderer;
|
|
37
|
+
constructor(progressRenderer = new NullProgressRenderer()) {
|
|
38
|
+
this.progressRenderer = progressRenderer;
|
|
39
|
+
}
|
|
40
|
+
/** @inheritdoc */
|
|
41
|
+
data_write(chunk) {
|
|
42
|
+
process.stdout.write(chunk);
|
|
43
|
+
}
|
|
44
|
+
/** @inheritdoc */
|
|
45
|
+
err_write(chunk) {
|
|
46
|
+
process.stderr.write(chunk);
|
|
47
|
+
}
|
|
48
|
+
/** @inheritdoc */
|
|
49
|
+
status_write(text) {
|
|
50
|
+
process.stdout.write(text);
|
|
51
|
+
}
|
|
52
|
+
progress_write(event) {
|
|
53
|
+
this.progressRenderer.write(event);
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
/**
|
|
57
|
+
* Sink that accumulates the data channel in memory and drops status.
|
|
58
|
+
*
|
|
59
|
+
* Used by capture paths and tests; will carry the pipe and redirect
|
|
60
|
+
* machinery once those consume envelopes.
|
|
61
|
+
*/
|
|
62
|
+
export class BufferSink {
|
|
63
|
+
chunks = [];
|
|
64
|
+
/** @inheritdoc */
|
|
65
|
+
data_write(chunk) {
|
|
66
|
+
this.chunks.push(typeof chunk === 'string' ? Buffer.from(chunk, 'utf-8') : chunk);
|
|
67
|
+
}
|
|
68
|
+
/** @inheritdoc */
|
|
69
|
+
err_write(chunk) {
|
|
70
|
+
// The err channel is never captured: today's pipe and redirect paths
|
|
71
|
+
// inherit stderr, so error output must keep reaching the terminal even
|
|
72
|
+
// while data is being buffered.
|
|
73
|
+
process.stderr.write(chunk);
|
|
74
|
+
}
|
|
75
|
+
/** @inheritdoc */
|
|
76
|
+
status_write(_text) {
|
|
77
|
+
// Status is ephemeral by contract: never accumulated.
|
|
78
|
+
}
|
|
79
|
+
progress_write(_event) {
|
|
80
|
+
// Progress is ephemeral by contract: never accumulated.
|
|
81
|
+
}
|
|
82
|
+
/**
|
|
83
|
+
* Returns everything written to the data channel so far.
|
|
84
|
+
*
|
|
85
|
+
* @returns The accumulated bytes.
|
|
86
|
+
*/
|
|
87
|
+
buffer_get() {
|
|
88
|
+
return Buffer.concat(this.chunks);
|
|
89
|
+
}
|
|
90
|
+
/**
|
|
91
|
+
* Returns the accumulated data channel as UTF-8 text.
|
|
92
|
+
*
|
|
93
|
+
* @returns The accumulated text.
|
|
94
|
+
*/
|
|
95
|
+
text_get() {
|
|
96
|
+
return this.buffer_get().toString('utf-8');
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
/**
|
|
100
|
+
* Sink that captures the data and err channels while passing status through
|
|
101
|
+
* to a live sink, so transients (spinners, progress) remain visible while a
|
|
102
|
+
* legacy printing command's output is being gathered into an envelope.
|
|
103
|
+
*/
|
|
104
|
+
export class CaptureSink {
|
|
105
|
+
dataChunks = [];
|
|
106
|
+
errChunks = [];
|
|
107
|
+
live;
|
|
108
|
+
forwardEnvelopeOutput;
|
|
109
|
+
/**
|
|
110
|
+
* Initializes the capture around a live sink for status passthrough.
|
|
111
|
+
*
|
|
112
|
+
* @param live - The sink that continues to receive status writes.
|
|
113
|
+
*/
|
|
114
|
+
constructor(live, options = {}) {
|
|
115
|
+
this.live = live;
|
|
116
|
+
this.forwardEnvelopeOutput = options.forwardEnvelopeOutput ?? false;
|
|
117
|
+
}
|
|
118
|
+
/** @inheritdoc */
|
|
119
|
+
data_write(chunk) {
|
|
120
|
+
this.dataChunks.push(typeof chunk === 'string' ? Buffer.from(chunk, 'utf-8') : chunk);
|
|
121
|
+
if (this.forwardEnvelopeOutput) {
|
|
122
|
+
this.live.data_write(chunk);
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
/** @inheritdoc */
|
|
126
|
+
err_write(chunk) {
|
|
127
|
+
this.errChunks.push(typeof chunk === 'string' ? Buffer.from(chunk, 'utf-8') : chunk);
|
|
128
|
+
if (this.forwardEnvelopeOutput) {
|
|
129
|
+
this.live.err_write(chunk);
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
/** @inheritdoc */
|
|
133
|
+
status_write(text) {
|
|
134
|
+
this.live.status_write(text);
|
|
135
|
+
}
|
|
136
|
+
progress_write(event) {
|
|
137
|
+
this.live.progress_write(event);
|
|
138
|
+
}
|
|
139
|
+
/**
|
|
140
|
+
* Returns the captured data channel as UTF-8 text.
|
|
141
|
+
*
|
|
142
|
+
* @returns The captured data text.
|
|
143
|
+
*/
|
|
144
|
+
dataText_get() {
|
|
145
|
+
return Buffer.concat(this.dataChunks).toString('utf-8');
|
|
146
|
+
}
|
|
147
|
+
/**
|
|
148
|
+
* Returns the captured err channel as UTF-8 text.
|
|
149
|
+
*
|
|
150
|
+
* @returns The captured error-stream text.
|
|
151
|
+
*/
|
|
152
|
+
errText_get() {
|
|
153
|
+
return Buffer.concat(this.errChunks).toString('utf-8');
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
/**
|
|
157
|
+
* The host sink: the process-wide default installed by whoever owns the output
|
|
158
|
+
* destination (the CLI REPL, the daemon). Defaults to stdout so every entry
|
|
159
|
+
* point behaves as the CLI always has.
|
|
160
|
+
*/
|
|
161
|
+
let hostSink = new StdoutSink();
|
|
162
|
+
/**
|
|
163
|
+
* Per-invocation sink scope.
|
|
164
|
+
*
|
|
165
|
+
* A captured command runs inside {@link AsyncLocalStorage#run}, so its sink
|
|
166
|
+
* follows the async call chain and is isolated from any other command running
|
|
167
|
+
* concurrently in the same process. Outside a scope the store is undefined and
|
|
168
|
+
* the host sink applies. This is what lets one process host several sessions
|
|
169
|
+
* at once without their output stomping a shared global.
|
|
170
|
+
*/
|
|
171
|
+
const sinkScope = new AsyncLocalStorage();
|
|
172
|
+
/**
|
|
173
|
+
* Returns the sink in effect for the current async context.
|
|
174
|
+
*
|
|
175
|
+
* Inside a captured command this is that command's capture sink; otherwise it
|
|
176
|
+
* is the host sink.
|
|
177
|
+
*
|
|
178
|
+
* @returns The active output sink.
|
|
179
|
+
*/
|
|
180
|
+
export function sink_get() {
|
|
181
|
+
return sinkScope.getStore() ?? hostSink;
|
|
182
|
+
}
|
|
183
|
+
/**
|
|
184
|
+
* Installs the host sink. Called by the host that owns the output destination.
|
|
185
|
+
*
|
|
186
|
+
* This sets the process-wide default, not the per-invocation scope, so a host
|
|
187
|
+
* installs it once at startup. Capture scopes established during command
|
|
188
|
+
* execution take precedence over it via {@link sink_get}.
|
|
189
|
+
*
|
|
190
|
+
* @param sink - The sink to install.
|
|
191
|
+
* @returns The previously installed host sink, so callers can restore it.
|
|
192
|
+
*/
|
|
193
|
+
export function sink_set(sink) {
|
|
194
|
+
const previous = hostSink;
|
|
195
|
+
hostSink = sink;
|
|
196
|
+
return previous;
|
|
197
|
+
}
|
|
198
|
+
/**
|
|
199
|
+
* Delivers a completed envelope to the active sink.
|
|
200
|
+
*
|
|
201
|
+
* Rendered text goes to the data channel and error-stream text to the err
|
|
202
|
+
* channel. The structured errors field is machine-facing and is not
|
|
203
|
+
* presented here: its terminal presentation, when any, travels in
|
|
204
|
+
* renderedErr.
|
|
205
|
+
*
|
|
206
|
+
* @param envelope - The completed command envelope.
|
|
207
|
+
*/
|
|
208
|
+
export function envelope_deliver(envelope) {
|
|
209
|
+
const sink = sink_get();
|
|
210
|
+
if (envelope.rendered.length > 0) {
|
|
211
|
+
sink.data_write(envelope.rendered);
|
|
212
|
+
}
|
|
213
|
+
if (envelope.renderedErr !== undefined && envelope.renderedErr.length > 0) {
|
|
214
|
+
sink.err_write(envelope.renderedErr);
|
|
215
|
+
}
|
|
216
|
+
}
|
|
217
|
+
/**
|
|
218
|
+
* Adapts an envelope-returning builtin to the legacy printing handler shape.
|
|
219
|
+
*
|
|
220
|
+
* This is the compatibility bridge for incremental conversion: converted
|
|
221
|
+
* builtins return envelopes, and this wrapper delivers them through the
|
|
222
|
+
* active sink so the dispatch table, pipes and redirects need no changes.
|
|
223
|
+
* A handler that resolves without an envelope (as stubbed handlers in tests
|
|
224
|
+
* do) is treated as having produced no output.
|
|
225
|
+
*
|
|
226
|
+
* @param handler - An envelope-returning command handler.
|
|
227
|
+
* @returns A handler with the legacy void-returning shape.
|
|
228
|
+
*/
|
|
229
|
+
export function envelopeHandler_wrap(handler) {
|
|
230
|
+
return async (args) => {
|
|
231
|
+
const envelope = await handler(args);
|
|
232
|
+
if (!envelope) {
|
|
233
|
+
return;
|
|
234
|
+
}
|
|
235
|
+
envelope_deliver(envelope);
|
|
236
|
+
};
|
|
237
|
+
}
|
|
238
|
+
/**
|
|
239
|
+
* Adapts a legacy printing builtin to the envelope-returning shape.
|
|
240
|
+
*
|
|
241
|
+
* This is the capture bridge for commands whose rendering lives below the
|
|
242
|
+
* seam (chili's table display prints internally): the handler runs with the
|
|
243
|
+
* data and err channels captured, console printing redirected into the
|
|
244
|
+
* capture, and status passed through live so spinners stay visible. The
|
|
245
|
+
* result is an envelope carrying the exact bytes each stream would have
|
|
246
|
+
* shown, with the status derived from the process exit code the handler set.
|
|
247
|
+
*
|
|
248
|
+
* Bridged commands gain envelope semantics without typed models; native
|
|
249
|
+
* conversion (models, streamed data) remains the end state for commands
|
|
250
|
+
* where a structural consumer exists.
|
|
251
|
+
*
|
|
252
|
+
* @param handler - A legacy printing command handler.
|
|
253
|
+
* @returns An envelope-returning handler with identical observable output.
|
|
254
|
+
*/
|
|
255
|
+
export function printingHandler_wrap(handler) {
|
|
256
|
+
return async (args) => {
|
|
257
|
+
const live = sink_get();
|
|
258
|
+
const capture = new CaptureSink(live, {
|
|
259
|
+
forwardEnvelopeOutput: sink_streamsEnvelopeOutput(live),
|
|
260
|
+
});
|
|
261
|
+
// The command's sink is scoped to this async context, so sink_get() (used
|
|
262
|
+
// by spinners, progress and directly-writing builtins) resolves to this
|
|
263
|
+
// capture without a shared global that concurrent commands would stomp.
|
|
264
|
+
// The console/stdout redirect below remains per-invocation: removing it in
|
|
265
|
+
// favour of envelope-returning builtins is tracked separately (#98).
|
|
266
|
+
const originalLog = console.log;
|
|
267
|
+
const originalError = console.error;
|
|
268
|
+
const originalStdoutWrite = process.stdout.write.bind(process.stdout);
|
|
269
|
+
const exitCodeBefore = typeof process.exitCode === 'number' ? process.exitCode : 0;
|
|
270
|
+
console.log = (...logArgs) => {
|
|
271
|
+
const text = logArgs
|
|
272
|
+
.map((arg) => (typeof arg === 'string' ? arg : JSON.stringify(arg)))
|
|
273
|
+
.join(' ');
|
|
274
|
+
capture.data_write(`${text}\n`);
|
|
275
|
+
};
|
|
276
|
+
console.error = (...logArgs) => {
|
|
277
|
+
const text = logArgs
|
|
278
|
+
.map((arg) => (typeof arg === 'string' ? arg : JSON.stringify(arg)))
|
|
279
|
+
.join(' ');
|
|
280
|
+
capture.err_write(`${text}\n`);
|
|
281
|
+
};
|
|
282
|
+
process.stdout.write = ((chunk) => {
|
|
283
|
+
if (typeof chunk === 'string' || Buffer.isBuffer(chunk)) {
|
|
284
|
+
capture.data_write(chunk);
|
|
285
|
+
}
|
|
286
|
+
else if (chunk instanceof Uint8Array) {
|
|
287
|
+
capture.data_write(Buffer.from(chunk));
|
|
288
|
+
}
|
|
289
|
+
return true;
|
|
290
|
+
});
|
|
291
|
+
try {
|
|
292
|
+
await sinkScope.run(capture, async () => {
|
|
293
|
+
await handler(args);
|
|
294
|
+
});
|
|
295
|
+
}
|
|
296
|
+
finally {
|
|
297
|
+
console.log = originalLog;
|
|
298
|
+
console.error = originalError;
|
|
299
|
+
process.stdout.write = originalStdoutWrite;
|
|
300
|
+
}
|
|
301
|
+
const exitCodeAfter = typeof process.exitCode === 'number' ? process.exitCode : 0;
|
|
302
|
+
const failed = exitCodeAfter !== 0 && exitCodeAfter !== exitCodeBefore;
|
|
303
|
+
const rendered = capture.dataText_get();
|
|
304
|
+
const renderedErr = capture.errText_get();
|
|
305
|
+
const envelope = { status: failed ? 'error' : 'ok', rendered };
|
|
306
|
+
if (renderedErr.length > 0) {
|
|
307
|
+
envelope.renderedErr = renderedErr;
|
|
308
|
+
}
|
|
309
|
+
return envelope;
|
|
310
|
+
};
|
|
311
|
+
}
|
|
312
|
+
/** Matches ANSI escape sequences (SGR colors, cursor movement, erase). */
|
|
313
|
+
const ANSI_PATTERN = /\x1b\[[0-9;?]*[a-zA-Z]/g;
|
|
314
|
+
/**
|
|
315
|
+
* Strips ANSI escape sequences from text.
|
|
316
|
+
*
|
|
317
|
+
* Applied at the pipe and redirect boundary so downstream consumers receive
|
|
318
|
+
* plain text, the way programs behind a real shell pipe see no color. This
|
|
319
|
+
* is a deliberate, documented deviation from the historical behavior, in
|
|
320
|
+
* which escape bytes leaked into pipes because color detection saw the
|
|
321
|
+
* terminal regardless of capture.
|
|
322
|
+
*
|
|
323
|
+
* @param text - Text possibly containing ANSI sequences.
|
|
324
|
+
* @returns The text with all ANSI sequences removed.
|
|
325
|
+
*/
|
|
326
|
+
export function ansi_strip(text) {
|
|
327
|
+
return text.replace(ANSI_PATTERN, '');
|
|
328
|
+
}
|
|
329
|
+
//# sourceMappingURL=sink.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"sink.js","sourceRoot":"","sources":["../../src/core/sink.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;GAsBG;AAEH,OAAO,EAAE,iBAAiB,EAAE,MAAM,kBAAkB,CAAC;AAErD,OAAO,EAA6C,oBAAoB,EAAE,MAAM,eAAe,CAAC;AAmChG,SAAS,0BAA0B,CAAC,IAAgB;IAClD,OAAQ,IAAyC,CAAC,kBAAkB,KAAK,IAAI,CAAC;AAChF,CAAC;AAED;;;;;GAKG;AACH,MAAM,OAAO,UAAU;IACJ,gBAAgB,CAAmB;IAEpD,YAAY,mBAAqC,IAAI,oBAAoB,EAAE;QACzE,IAAI,CAAC,gBAAgB,GAAG,gBAAgB,CAAC;IAC3C,CAAC;IAED,kBAAkB;IACX,UAAU,CAAC,KAAsB;QACtC,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC;IAC9B,CAAC;IAED,kBAAkB;IACX,SAAS,CAAC,KAAsB;QACrC,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC;IAC9B,CAAC;IAED,kBAAkB;IACX,YAAY,CAAC,IAAY;QAC9B,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;IAC7B,CAAC;IAEM,cAAc,CAAC,KAAoB;QACxC,IAAI,CAAC,gBAAgB,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC;IACrC,CAAC;CACF;AAED;;;;;GAKG;AACH,MAAM,OAAO,UAAU;IACb,MAAM,GAAa,EAAE,CAAC;IAE9B,kBAAkB;IACX,UAAU,CAAC,KAAsB;QACtC,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,OAAO,KAAK,KAAK,QAAQ,CAAC,CAAC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