@histoire/cli 0.0.0-stage → 1.0.0-beta.2
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 +21 -0
- package/README.md +8 -2
- package/dist/cli.d.ts +9 -0
- package/dist/cli.js +88 -0
- package/dist/commands/dev.d.ts +44 -0
- package/dist/commands/dev.js +115 -0
- package/dist/commands/host.d.ts +66 -0
- package/dist/commands/host.js +1 -0
- package/dist/commands/screenshot-setup-args.d.ts +4 -0
- package/dist/commands/screenshot-setup-args.js +35 -0
- package/dist/commands/signal-guard.d.ts +29 -0
- package/dist/commands/signal-guard.js +52 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js +1 -0
- package/dist/terminal/actions.d.ts +51 -0
- package/dist/terminal/actions.js +60 -0
- package/dist/terminal/banner.d.ts +19 -0
- package/dist/terminal/banner.js +48 -0
- package/dist/terminal/bridge.d.ts +58 -0
- package/dist/terminal/bridge.js +103 -0
- package/dist/terminal/clipboard.d.ts +46 -0
- package/dist/terminal/clipboard.js +85 -0
- package/dist/terminal/diagnostics/attach.d.ts +9 -0
- package/dist/terminal/diagnostics/attach.js +46 -0
- package/dist/terminal/diagnostics/client.d.ts +12 -0
- package/dist/terminal/diagnostics/client.js +19 -0
- package/dist/terminal/diagnostics/lines.d.ts +17 -0
- package/dist/terminal/diagnostics/lines.js +61 -0
- package/dist/terminal/dispatch.d.ts +28 -0
- package/dist/terminal/dispatch.js +52 -0
- package/dist/terminal/feedback.d.ts +14 -0
- package/dist/terminal/feedback.js +27 -0
- package/dist/terminal/history/bounded.d.ts +37 -0
- package/dist/terminal/history/bounded.js +54 -0
- package/dist/terminal/host-extras.d.ts +14 -0
- package/dist/terminal/host-extras.js +26 -0
- package/dist/terminal/info/client.d.ts +20 -0
- package/dist/terminal/info/client.js +25 -0
- package/dist/terminal/info/generation-client.d.ts +33 -0
- package/dist/terminal/info/generation-client.js +32 -0
- package/dist/terminal/info/lines.d.ts +19 -0
- package/dist/terminal/info/lines.js +33 -0
- package/dist/terminal/info/network.d.ts +17 -0
- package/dist/terminal/info/network.js +48 -0
- package/dist/terminal/info/qr.d.ts +7 -0
- package/dist/terminal/info/qr.js +14 -0
- package/dist/terminal/keys.d.ts +44 -0
- package/dist/terminal/keys.js +60 -0
- package/dist/terminal/logs/browser-options.d.ts +9 -0
- package/dist/terminal/logs/browser-options.js +19 -0
- package/dist/terminal/navigation/browser.d.ts +69 -0
- package/dist/terminal/navigation/browser.js +193 -0
- package/dist/terminal/navigation/list.d.ts +53 -0
- package/dist/terminal/navigation/list.js +104 -0
- package/dist/terminal/navigation/search.d.ts +22 -0
- package/dist/terminal/navigation/search.js +44 -0
- package/dist/terminal/output/decoder.d.ts +24 -0
- package/dist/terminal/output/decoder.js +63 -0
- package/dist/terminal/output/history.d.ts +43 -0
- package/dist/terminal/output/history.js +21 -0
- package/dist/terminal/output/pipeline.d.ts +33 -0
- package/dist/terminal/output/pipeline.js +59 -0
- package/dist/terminal/output/sanitize.d.ts +32 -0
- package/dist/terminal/output/sanitize.js +142 -0
- package/dist/terminal/panel-model.d.ts +20 -0
- package/dist/terminal/panel-model.js +38 -0
- package/dist/terminal/panel.d.ts +30 -0
- package/dist/terminal/panel.js +53 -0
- package/dist/terminal/plain.d.ts +29 -0
- package/dist/terminal/plain.js +68 -0
- package/dist/terminal/progress/format.d.ts +28 -0
- package/dist/terminal/progress/format.js +77 -0
- package/dist/terminal/progress/state.d.ts +71 -0
- package/dist/terminal/progress/state.js +150 -0
- package/dist/terminal/protocol/catalog.d.ts +143 -0
- package/dist/terminal/protocol/catalog.js +61 -0
- package/dist/terminal/protocol/core.d.ts +117 -0
- package/dist/terminal/protocol/core.js +98 -0
- package/dist/terminal/protocol/diagnostics.d.ts +79 -0
- package/dist/terminal/protocol/diagnostics.js +31 -0
- package/dist/terminal/protocol/index.d.ts +22 -0
- package/dist/terminal/protocol/index.js +1 -0
- package/dist/terminal/protocol/progress.d.ts +67 -0
- package/dist/terminal/protocol/progress.js +52 -0
- package/dist/terminal/protocol/requests.d.ts +30 -0
- package/dist/terminal/protocol/requests.js +13 -0
- package/dist/terminal/protocol/session.d.ts +55 -0
- package/dist/terminal/protocol/session.js +28 -0
- package/dist/terminal/protocol/tests.d.ts +212 -0
- package/dist/terminal/protocol/tests.js +87 -0
- package/dist/terminal/protocol/watch.d.ts +60 -0
- package/dist/terminal/protocol/watch.js +40 -0
- package/dist/terminal/requests/browser-options.d.ts +8 -0
- package/dist/terminal/requests/browser-options.js +24 -0
- package/dist/terminal/requests/history.d.ts +30 -0
- package/dist/terminal/requests/history.js +53 -0
- package/dist/terminal/retained.d.ts +27 -0
- package/dist/terminal/retained.js +21 -0
- package/dist/terminal/session-types.d.ts +76 -0
- package/dist/terminal/session-types.js +1 -0
- package/dist/terminal/session.d.ts +8 -0
- package/dist/terminal/session.js +282 -0
- package/dist/terminal/shutdown.d.ts +12 -0
- package/dist/terminal/shutdown.js +30 -0
- package/dist/terminal/stories/client.d.ts +26 -0
- package/dist/terminal/stories/client.js +28 -0
- package/dist/terminal/stories/handoff.d.ts +39 -0
- package/dist/terminal/stories/handoff.js +40 -0
- package/dist/terminal/stories/paged.d.ts +70 -0
- package/dist/terminal/stories/paged.js +137 -0
- package/dist/terminal/stories/render.d.ts +39 -0
- package/dist/terminal/stories/render.js +94 -0
- package/dist/terminal/stories/state.d.ts +93 -0
- package/dist/terminal/stories/state.js +191 -0
- package/dist/terminal/stories/target.d.ts +24 -0
- package/dist/terminal/stories/target.js +29 -0
- package/dist/terminal/style.d.ts +45 -0
- package/dist/terminal/style.js +82 -0
- package/dist/terminal/support.d.ts +53 -0
- package/dist/terminal/support.js +66 -0
- package/dist/terminal/surface.d.ts +41 -0
- package/dist/terminal/surface.js +200 -0
- package/dist/terminal/tests/client.d.ts +21 -0
- package/dist/terminal/tests/client.js +12 -0
- package/dist/terminal/tests/console.d.ts +95 -0
- package/dist/terminal/tests/console.js +202 -0
- package/dist/terminal/tests/format.d.ts +18 -0
- package/dist/terminal/tests/format.js +55 -0
- package/dist/terminal/tests/header.d.ts +16 -0
- package/dist/terminal/tests/header.js +90 -0
- package/dist/terminal/tests/reporter.d.ts +17 -0
- package/dist/terminal/tests/reporter.js +99 -0
- package/dist/terminal/tests/results.d.ts +44 -0
- package/dist/terminal/tests/results.js +104 -0
- package/dist/terminal/tests/scope.d.ts +25 -0
- package/dist/terminal/tests/scope.js +25 -0
- package/dist/terminal/tests/session.d.ts +11 -0
- package/dist/terminal/tests/session.js +24 -0
- package/dist/terminal/tests/state.d.ts +57 -0
- package/dist/terminal/tests/state.js +134 -0
- package/dist/terminal/views/clear-history.d.ts +6 -0
- package/dist/terminal/views/clear-history.js +10 -0
- package/dist/terminal/views/error.d.ts +8 -0
- package/dist/terminal/views/error.js +24 -0
- package/dist/terminal/views/frame.d.ts +20 -0
- package/dist/terminal/views/frame.js +23 -0
- package/dist/terminal/views/help.d.ts +3 -0
- package/dist/terminal/views/help.js +32 -0
- package/dist/terminal/views/index.d.ts +6 -0
- package/dist/terminal/views/index.js +13 -0
- package/dist/terminal/views/logs.d.ts +3 -0
- package/dist/terminal/views/logs.js +7 -0
- package/dist/terminal/views/registry.d.ts +114 -0
- package/dist/terminal/views/registry.js +40 -0
- package/dist/terminal/views/requests.d.ts +8 -0
- package/dist/terminal/views/requests.js +15 -0
- package/dist/terminal/views/session.d.ts +9 -0
- package/dist/terminal/views/session.js +133 -0
- package/dist/terminal/views/stories.d.ts +9 -0
- package/dist/terminal/views/stories.js +172 -0
- package/dist/terminal/views/tests.d.ts +9 -0
- package/dist/terminal/views/tests.js +105 -0
- package/dist/terminal/watch/client.d.ts +12 -0
- package/dist/terminal/watch/client.js +7 -0
- package/dist/terminal/watch/controller.d.ts +30 -0
- package/dist/terminal/watch/controller.js +157 -0
- package/dist/terminal/watch/format.d.ts +15 -0
- package/dist/terminal/watch/format.js +37 -0
- package/dist/terminal/watch/session.d.ts +17 -0
- package/dist/terminal/watch/session.js +12 -0
- package/dist/terminal/width.d.ts +24 -0
- package/dist/terminal/width.js +171 -0
- package/dist/workbench-url.d.ts +30 -0
- package/dist/workbench-url.js +55 -0
- package/package.json +54 -3
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Creates a stateful remover of untrusted terminal control sequences. State
|
|
3
|
+
* survives between calls, so an escape split across chunks is still removed.
|
|
4
|
+
* Keeps printable text, `\n`, `\r` and `\t`; drops every other C0/C1 control, bidi
|
|
5
|
+
* controls, CSI, OSC, DCS/APC/PM/SOS and two-byte escapes. Unterminated sequences are
|
|
6
|
+
* abandoned at a newline or after a bound instead of swallowing later output.
|
|
7
|
+
*/
|
|
8
|
+
export declare function createControlStripper(): (text: string) => string;
|
|
9
|
+
/**
|
|
10
|
+
* Replaces credentials in a complete text. When the text was cut at a bound, a
|
|
11
|
+
* trailing fragment that starts a credential is removed too.
|
|
12
|
+
* @param text Text to redact.
|
|
13
|
+
* @param secrets Configured credentials; empty strings are ignored.
|
|
14
|
+
* @param truncated Whether the end of the text was cut by a bound.
|
|
15
|
+
*/
|
|
16
|
+
export declare function redactSecrets(text: string, secrets: readonly string[], truncated?: boolean): string;
|
|
17
|
+
/**
|
|
18
|
+
* Sanitizes a complete, self-contained text (controls, then credentials). Carriage returns
|
|
19
|
+
* are dropped too: unlike the streaming decoder, a complete text has no line to rewrite, and
|
|
20
|
+
* a kept `\r` would let one rendered row overwrite itself.
|
|
21
|
+
* @param text Text to sanitize.
|
|
22
|
+
* @param secrets Configured credentials.
|
|
23
|
+
* @param truncated Whether the end of the text was cut by a bound.
|
|
24
|
+
*/
|
|
25
|
+
export declare function sanitizeText(text: string, secrets?: readonly string[], truncated?: boolean): string;
|
|
26
|
+
/**
|
|
27
|
+
* Sanitizes untrusted text shown inside one terminal row: like {@link sanitizeText}, then
|
|
28
|
+
* line breaks and tabs collapse to spaces so the value cannot add rows or break alignment.
|
|
29
|
+
* @param text Text to sanitize.
|
|
30
|
+
* @param secrets Configured credentials.
|
|
31
|
+
*/
|
|
32
|
+
export declare function sanitizeLine(text: string, secrets?: readonly string[]): string;
|
|
@@ -0,0 +1,142 @@
|
|
|
1
|
+
/** Placeholder replacing configured credentials in retained text. */
|
|
2
|
+
const REDACTION = '[credential]';
|
|
3
|
+
/** Longest string-type escape (OSC, DCS, ...) swallowed before the sequence is abandoned. */
|
|
4
|
+
const MAX_STRING_SEQUENCE = 4096;
|
|
5
|
+
/**
|
|
6
|
+
* Whether a code unit is a Unicode bidirectional control (marks, embeddings, isolates). They
|
|
7
|
+
* can visually reorder surrounding text, so retained and rendered text never keeps them.
|
|
8
|
+
* @param code UTF-16 code unit.
|
|
9
|
+
*/
|
|
10
|
+
function isBidiControl(code) {
|
|
11
|
+
return code === 0x061C || code === 0x200E || code === 0x200F || (code >= 0x202A && code <= 0x202E) || (code >= 0x2066 && code <= 0x2069);
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* Creates a stateful remover of untrusted terminal control sequences. State
|
|
15
|
+
* survives between calls, so an escape split across chunks is still removed.
|
|
16
|
+
* Keeps printable text, `\n`, `\r` and `\t`; drops every other C0/C1 control, bidi
|
|
17
|
+
* controls, CSI, OSC, DCS/APC/PM/SOS and two-byte escapes. Unterminated sequences are
|
|
18
|
+
* abandoned at a newline or after a bound instead of swallowing later output.
|
|
19
|
+
*/
|
|
20
|
+
export function createControlStripper() {
|
|
21
|
+
let state = 0 /* State.Text */;
|
|
22
|
+
let stringLength = 0;
|
|
23
|
+
/** Handles one UTF-16 unit; returns it when it is visible text, otherwise ''. */
|
|
24
|
+
function step(char) {
|
|
25
|
+
const code = char.charCodeAt(0);
|
|
26
|
+
switch (state) {
|
|
27
|
+
case 0 /* State.Text */:
|
|
28
|
+
if (code === 0x1B)
|
|
29
|
+
state = 1 /* State.Escape */;
|
|
30
|
+
else if (code === 0x9B)
|
|
31
|
+
state = 2 /* State.Csi */;
|
|
32
|
+
else if (code === 0x9D || code === 0x90 || code === 0x98 || code === 0x9E || code === 0x9F) {
|
|
33
|
+
state = 3 /* State.Str */;
|
|
34
|
+
stringLength = 0;
|
|
35
|
+
}
|
|
36
|
+
else if (code === 0x0A || code === 0x0D || code === 0x09)
|
|
37
|
+
return char;
|
|
38
|
+
else if (code < 0x20 || (code >= 0x7F && code <= 0x9F) || isBidiControl(code))
|
|
39
|
+
return '';
|
|
40
|
+
else
|
|
41
|
+
return char;
|
|
42
|
+
return '';
|
|
43
|
+
case 1 /* State.Escape */:
|
|
44
|
+
if (char === '[')
|
|
45
|
+
state = 2 /* State.Csi */;
|
|
46
|
+
else if (char === ']' || char === 'P' || char === 'X' || char === '^' || char === '_') {
|
|
47
|
+
state = 3 /* State.Str */;
|
|
48
|
+
stringLength = 0;
|
|
49
|
+
}
|
|
50
|
+
else if (code >= 0x20 && code <= 0x2F)
|
|
51
|
+
state = 5 /* State.EscapeIntermediate */;
|
|
52
|
+
else {
|
|
53
|
+
// A lone ESC before a line break must not eat the break.
|
|
54
|
+
state = 0 /* State.Text */;
|
|
55
|
+
return code === 0x0A || code === 0x0D ? char : '';
|
|
56
|
+
}
|
|
57
|
+
return '';
|
|
58
|
+
case 5 /* State.EscapeIntermediate */:
|
|
59
|
+
if (code < 0x20 || code > 0x2F)
|
|
60
|
+
state = 0 /* State.Text */;
|
|
61
|
+
return '';
|
|
62
|
+
case 2 /* State.Csi */:
|
|
63
|
+
if (code >= 0x40 && code <= 0x7E)
|
|
64
|
+
state = 0 /* State.Text */;
|
|
65
|
+
else if (code < 0x20 || code > 0x3F) {
|
|
66
|
+
// Malformed: leave the sequence and treat the unit as ordinary input.
|
|
67
|
+
state = 0 /* State.Text */;
|
|
68
|
+
return step(char);
|
|
69
|
+
}
|
|
70
|
+
return '';
|
|
71
|
+
case 3 /* State.Str */:
|
|
72
|
+
if (code === 0x07 || code === 0x9C)
|
|
73
|
+
state = 0 /* State.Text */;
|
|
74
|
+
else if (code === 0x1B)
|
|
75
|
+
state = 4 /* State.StrEscape */;
|
|
76
|
+
else if (code === 0x0A || ++stringLength > MAX_STRING_SEQUENCE) {
|
|
77
|
+
state = 0 /* State.Text */;
|
|
78
|
+
return step(char);
|
|
79
|
+
}
|
|
80
|
+
return '';
|
|
81
|
+
case 4 /* State.StrEscape */:
|
|
82
|
+
if (char === '\\') {
|
|
83
|
+
state = 0 /* State.Text */;
|
|
84
|
+
return '';
|
|
85
|
+
}
|
|
86
|
+
// ESC inside a string starts a fresh sequence.
|
|
87
|
+
state = 1 /* State.Escape */;
|
|
88
|
+
return step(char);
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
return (text) => {
|
|
92
|
+
let result = '';
|
|
93
|
+
for (let index = 0; index < text.length; index++)
|
|
94
|
+
result += step(text[index]);
|
|
95
|
+
return result;
|
|
96
|
+
};
|
|
97
|
+
}
|
|
98
|
+
/**
|
|
99
|
+
* Replaces credentials in a complete text. When the text was cut at a bound, a
|
|
100
|
+
* trailing fragment that starts a credential is removed too.
|
|
101
|
+
* @param text Text to redact.
|
|
102
|
+
* @param secrets Configured credentials; empty strings are ignored.
|
|
103
|
+
* @param truncated Whether the end of the text was cut by a bound.
|
|
104
|
+
*/
|
|
105
|
+
export function redactSecrets(text, secrets, truncated = false) {
|
|
106
|
+
let result = text;
|
|
107
|
+
for (const secret of secrets) {
|
|
108
|
+
if (!secret)
|
|
109
|
+
continue;
|
|
110
|
+
result = result.replaceAll(secret, REDACTION);
|
|
111
|
+
if (!truncated)
|
|
112
|
+
continue;
|
|
113
|
+
// The cut may have split a credential; drop its visible beginning (4+ units).
|
|
114
|
+
for (let length = Math.min(secret.length - 1, result.length); length >= 4; length--) {
|
|
115
|
+
if (result.endsWith(secret.slice(0, length))) {
|
|
116
|
+
result = result.slice(0, -length);
|
|
117
|
+
break;
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
return result;
|
|
122
|
+
}
|
|
123
|
+
/**
|
|
124
|
+
* Sanitizes a complete, self-contained text (controls, then credentials). Carriage returns
|
|
125
|
+
* are dropped too: unlike the streaming decoder, a complete text has no line to rewrite, and
|
|
126
|
+
* a kept `\r` would let one rendered row overwrite itself.
|
|
127
|
+
* @param text Text to sanitize.
|
|
128
|
+
* @param secrets Configured credentials.
|
|
129
|
+
* @param truncated Whether the end of the text was cut by a bound.
|
|
130
|
+
*/
|
|
131
|
+
export function sanitizeText(text, secrets = [], truncated = false) {
|
|
132
|
+
return redactSecrets(createControlStripper()(text).replaceAll('\r', ''), secrets, truncated);
|
|
133
|
+
}
|
|
134
|
+
/**
|
|
135
|
+
* Sanitizes untrusted text shown inside one terminal row: like {@link sanitizeText}, then
|
|
136
|
+
* line breaks and tabs collapse to spaces so the value cannot add rows or break alignment.
|
|
137
|
+
* @param text Text to sanitize.
|
|
138
|
+
* @param secrets Configured credentials.
|
|
139
|
+
*/
|
|
140
|
+
export function sanitizeLine(text, secrets = []) {
|
|
141
|
+
return sanitizeText(text, secrets).replace(/\s+/g, ' ');
|
|
142
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import type { PanelModel } from './panel.js';
|
|
2
|
+
import type { ProgressSnapshot } from './progress/state.js';
|
|
3
|
+
import type { TerminalView } from './views/registry.js';
|
|
4
|
+
/** Inputs of the panel model that the session owns. */
|
|
5
|
+
export interface PanelModelInput {
|
|
6
|
+
version: string;
|
|
7
|
+
columns: number;
|
|
8
|
+
snapshot: ProgressSnapshot;
|
|
9
|
+
url?: string;
|
|
10
|
+
segments: Iterable<() => string | undefined>;
|
|
11
|
+
feedback?: string;
|
|
12
|
+
/** Registered views, in registration order. */
|
|
13
|
+
views: readonly TerminalView[];
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* Builds the panel model: shortcut hints are the main actions plus registered views,
|
|
17
|
+
* so a view registered by a later slice appears in the panel automatically.
|
|
18
|
+
* @param input Session state.
|
|
19
|
+
*/
|
|
20
|
+
export declare function buildPanelModel(input: PanelModelInput): PanelModel;
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
/** Views whose hints come first (in this order), so a narrow panel drops them last. */
|
|
2
|
+
const LEADING_VIEWS = ['t', 'p'];
|
|
3
|
+
/**
|
|
4
|
+
* Hint of a registered view.
|
|
5
|
+
* @param view Registered view.
|
|
6
|
+
*/
|
|
7
|
+
function viewHint(view) {
|
|
8
|
+
return { key: view.shortcut, label: view.title.toLowerCase() };
|
|
9
|
+
}
|
|
10
|
+
/**
|
|
11
|
+
* Builds the panel model: shortcut hints are the main actions plus registered views,
|
|
12
|
+
* so a view registered by a later slice appears in the panel automatically.
|
|
13
|
+
* @param input Session state.
|
|
14
|
+
*/
|
|
15
|
+
export function buildPanelModel(input) {
|
|
16
|
+
const views = input.views
|
|
17
|
+
.filter(view => view.shortcut !== '?' && !view.run)
|
|
18
|
+
.sort((a, b) => LEADING_VIEWS.indexOf(a.shortcut) - LEADING_VIEWS.indexOf(b.shortcut));
|
|
19
|
+
return {
|
|
20
|
+
version: input.version,
|
|
21
|
+
columns: input.columns,
|
|
22
|
+
snapshot: input.snapshot,
|
|
23
|
+
url: input.url,
|
|
24
|
+
segments: [...input.segments].flatMap(provider => provider() ?? []),
|
|
25
|
+
feedback: input.feedback,
|
|
26
|
+
hints: [
|
|
27
|
+
{ key: 'o', label: 'open' },
|
|
28
|
+
...views.filter(view => LEADING_VIEWS.includes(view.shortcut)).map(viewHint),
|
|
29
|
+
{ key: 'r', label: 'restart' },
|
|
30
|
+
...views.filter(view => !LEADING_VIEWS.includes(view.shortcut)).map(viewHint),
|
|
31
|
+
{ key: 'y', label: 'copy' },
|
|
32
|
+
{ key: 'R', label: 'fresh' },
|
|
33
|
+
{ key: 'c', label: 'clear' },
|
|
34
|
+
{ key: '?', label: 'help' },
|
|
35
|
+
{ key: 'q', label: 'quit' },
|
|
36
|
+
],
|
|
37
|
+
};
|
|
38
|
+
}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import type { ProgressSnapshot } from './progress/state.js';
|
|
2
|
+
import type { Style } from './style.js';
|
|
3
|
+
/** One shortcut hint. */
|
|
4
|
+
export interface PanelHint {
|
|
5
|
+
key: string;
|
|
6
|
+
label: string;
|
|
7
|
+
}
|
|
8
|
+
/** Everything the panel shows. */
|
|
9
|
+
export interface PanelModel {
|
|
10
|
+
version: string;
|
|
11
|
+
columns: number;
|
|
12
|
+
snapshot: ProgressSnapshot;
|
|
13
|
+
/** Workbench address when known. */
|
|
14
|
+
url?: string;
|
|
15
|
+
/** Short segments after the address (counts, test activity) from later slices. */
|
|
16
|
+
segments: readonly string[];
|
|
17
|
+
/** Transient feedback replacing the hints line. */
|
|
18
|
+
feedback?: string;
|
|
19
|
+
/** Hints in display order; the last two (help, quit) survive narrow widths. */
|
|
20
|
+
hints: readonly PanelHint[];
|
|
21
|
+
/** Palette; defaults to the one the environment allows. */
|
|
22
|
+
style?: Style;
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* Renders the pinned panel as exactly `PANEL_HEIGHT` lines, each fitted to the width.
|
|
26
|
+
* Title bar is the brand color (inverse video without color); keys are highlighted and
|
|
27
|
+
* labels dimmed; no borders or edge bars.
|
|
28
|
+
* @param model Panel content.
|
|
29
|
+
*/
|
|
30
|
+
export declare function renderPanel(model: PanelModel): string[];
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import { describeProgress, formatDuration } from './progress/format.js';
|
|
2
|
+
import { defaultStyle } from './style.js';
|
|
3
|
+
import { displayWidth, fitWidth } from './width.js';
|
|
4
|
+
/** Fixed height of the pinned panel, so lifecycle changes never move the log area. */
|
|
5
|
+
const PANEL_HEIGHT = 3;
|
|
6
|
+
/** Lifecycle text: real phases and real counts only, never a fabricated percentage. */
|
|
7
|
+
function statusText(snapshot) {
|
|
8
|
+
const description = describeProgress(snapshot);
|
|
9
|
+
if (snapshot.status === 'ready' || snapshot.status === 'failed' || snapshot.status === 'closed')
|
|
10
|
+
return description;
|
|
11
|
+
const prefix = snapshot.status === 'restarting' && description !== 'Restarting' ? 'Restarting · ' : '';
|
|
12
|
+
return `${prefix}${description} · ${formatDuration(snapshot.elapsedMs)}`;
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* Hint line that fits: when too wide, drops hints from the end but keeps the final two.
|
|
16
|
+
* Fitting works on plain text; keys are highlighted afterwards.
|
|
17
|
+
* @param hints Hints in display order.
|
|
18
|
+
* @param columns Cell budget.
|
|
19
|
+
* @param style Palette.
|
|
20
|
+
*/
|
|
21
|
+
function hintLine(hints, columns, style) {
|
|
22
|
+
const items = hints.map(hint => `${hint.key} ${hint.label}`);
|
|
23
|
+
const join = (list) => list.join(' · ');
|
|
24
|
+
while (displayWidth(join(items)) > columns - 1 && items.length > 2)
|
|
25
|
+
items.splice(items.length - 3, 1);
|
|
26
|
+
const plain = join(items);
|
|
27
|
+
return displayWidth(plain) > columns - 1 ? style.dim(fitWidth(plain, columns - 1)) : style.hints(plain);
|
|
28
|
+
}
|
|
29
|
+
/** Colors the lifecycle text: ready green, failed red, starting and restarting yellow, closed dim. */
|
|
30
|
+
function colorStatus(snapshot, text, style) {
|
|
31
|
+
if (snapshot.status === 'ready')
|
|
32
|
+
return style.success(text);
|
|
33
|
+
if (snapshot.status === 'failed')
|
|
34
|
+
return style.bold(style.error(text));
|
|
35
|
+
return snapshot.status === 'closed' ? style.dim(text) : style.warn(text);
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* Renders the pinned panel as exactly `PANEL_HEIGHT` lines, each fitted to the width.
|
|
39
|
+
* Title bar is the brand color (inverse video without color); keys are highlighted and
|
|
40
|
+
* labels dimmed; no borders or edge bars.
|
|
41
|
+
* @param model Panel content.
|
|
42
|
+
*/
|
|
43
|
+
export function renderPanel(model) {
|
|
44
|
+
const { columns } = model;
|
|
45
|
+
const style = model.style ?? defaultStyle();
|
|
46
|
+
const header = `${style.title(` Histoire ${model.version} `)} ${colorStatus(model.snapshot, statusText(model.snapshot), style)}`;
|
|
47
|
+
const location = model.url
|
|
48
|
+
? `${style.dim('Local')} ${style.accent(model.url)}`
|
|
49
|
+
: style.dim('Waiting for address');
|
|
50
|
+
const rest = model.segments.map(segment => style.dim(segment));
|
|
51
|
+
const footer = model.feedback ? model.feedback : hintLine(model.hints, columns, style);
|
|
52
|
+
return [header, ` ${[location, ...rest].join(style.dim(' · '))}`, ` ${footer}`].map(line => style.seal(fitWidth(line, columns)));
|
|
53
|
+
}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import type { Readable } from 'node:stream';
|
|
2
|
+
import type { ActionHost } from './actions.js';
|
|
3
|
+
/** Plain mode help text. */
|
|
4
|
+
export declare const PLAIN_HELP: string;
|
|
5
|
+
/**
|
|
6
|
+
* Runs one plain command line. Unknown input and not-yet-available commands answer plainly.
|
|
7
|
+
* @param host Action host (feedback goes through `report`).
|
|
8
|
+
* @param input Raw line typed by the user.
|
|
9
|
+
*/
|
|
10
|
+
export declare function runPlainCommand(host: ActionHost, input: string): Promise<void>;
|
|
11
|
+
/** Owner of the line reader on an interactive stdin. */
|
|
12
|
+
export interface PlainInput {
|
|
13
|
+
/** Starts reading newline-terminated commands. Idempotent. */
|
|
14
|
+
attach: () => void;
|
|
15
|
+
/** Stops reading and restores the stream's flow state. Idempotent. */
|
|
16
|
+
detach: () => void;
|
|
17
|
+
readonly attached: boolean;
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* Line reader for interactive plain mode. Never created for non-TTY stdin by the
|
|
21
|
+
* session, so piped input is not consumed and cannot keep the process alive.
|
|
22
|
+
* @param options Input stream and line callback.
|
|
23
|
+
* @param options.stdin Interactive input stream.
|
|
24
|
+
* @param options.onLine Receives each typed line.
|
|
25
|
+
*/
|
|
26
|
+
export declare function createPlainInput(options: {
|
|
27
|
+
stdin: Readable;
|
|
28
|
+
onLine: (line: string) => void;
|
|
29
|
+
}): PlainInput;
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
import { createInterface } from 'node:readline';
|
|
2
|
+
import { openWorkbench, restartRuntime } from './actions.js';
|
|
3
|
+
import { runAndReport } from './tests/reporter.js';
|
|
4
|
+
/** Commands accepted by the interactive plain reporter, in help order. */
|
|
5
|
+
const PLAIN_COMMANDS = ['help', 'restart', 'restart fresh', 'open', 'tests', 'watch', 'stop', 'quit'];
|
|
6
|
+
/** Plain mode help text. */
|
|
7
|
+
export const PLAIN_HELP = `Commands: ${PLAIN_COMMANDS.join(', ')}`;
|
|
8
|
+
/**
|
|
9
|
+
* Runs one plain command line. Unknown input and not-yet-available commands answer plainly.
|
|
10
|
+
* @param host Action host (feedback goes through `report`).
|
|
11
|
+
* @param input Raw line typed by the user.
|
|
12
|
+
*/
|
|
13
|
+
export async function runPlainCommand(host, input) {
|
|
14
|
+
const command = input.trim().toLowerCase().replace(/\s+/g, ' ');
|
|
15
|
+
switch (command) {
|
|
16
|
+
case '': return;
|
|
17
|
+
case 'help': return host.report(PLAIN_HELP);
|
|
18
|
+
case 'restart': return restartRuntime(host, false);
|
|
19
|
+
case 'restart fresh': return restartRuntime(host, true);
|
|
20
|
+
case 'open': return openWorkbench(host);
|
|
21
|
+
case 'quit': return host.quit();
|
|
22
|
+
case 'tests': return host.tests ? runAndReport(host.tests, host.report) : host.report('Tests are not available yet');
|
|
23
|
+
// Stopping switches watching off first, then cancels every terminal-owned operation.
|
|
24
|
+
case 'stop': return host.tests ? host.report(await host.tests.stop()) : host.report('Tests are not available yet');
|
|
25
|
+
// Toggles whole-scope watching through the control the session registered.
|
|
26
|
+
case 'watch': return host.tests ? host.report(await host.tests.toggleWatch()) : host.report('"watch" is not available yet');
|
|
27
|
+
default: return host.report(`Unknown command "${command}". ${PLAIN_HELP}`);
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* Line reader for interactive plain mode. Never created for non-TTY stdin by the
|
|
32
|
+
* session, so piped input is not consumed and cannot keep the process alive.
|
|
33
|
+
* @param options Input stream and line callback.
|
|
34
|
+
* @param options.stdin Interactive input stream.
|
|
35
|
+
* @param options.onLine Receives each typed line.
|
|
36
|
+
*/
|
|
37
|
+
export function createPlainInput(options) {
|
|
38
|
+
let reader;
|
|
39
|
+
let wasFlowing = false;
|
|
40
|
+
return {
|
|
41
|
+
get attached() {
|
|
42
|
+
return reader !== undefined;
|
|
43
|
+
},
|
|
44
|
+
attach() {
|
|
45
|
+
if (reader)
|
|
46
|
+
return;
|
|
47
|
+
wasFlowing = options.stdin.readableFlowing === true;
|
|
48
|
+
// Not a terminal-mode interface: readline must not repaint prompts or echo.
|
|
49
|
+
const created = createInterface({ input: options.stdin, terminal: false });
|
|
50
|
+
reader = created;
|
|
51
|
+
created.on('line', options.onLine);
|
|
52
|
+
// End of input (Ctrl+D) ends reading but not the server.
|
|
53
|
+
created.once('close', () => {
|
|
54
|
+
if (reader === created)
|
|
55
|
+
reader = undefined;
|
|
56
|
+
});
|
|
57
|
+
},
|
|
58
|
+
detach() {
|
|
59
|
+
const current = reader;
|
|
60
|
+
reader = undefined;
|
|
61
|
+
if (!current)
|
|
62
|
+
return;
|
|
63
|
+
current.close();
|
|
64
|
+
if (wasFlowing)
|
|
65
|
+
options.stdin.resume();
|
|
66
|
+
},
|
|
67
|
+
};
|
|
68
|
+
}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import type { RestartCause, StartupPhaseId } from '../protocol/progress.js';
|
|
2
|
+
import type { PhaseSnapshot, ProgressSnapshot } from './state.js';
|
|
3
|
+
/** Short English names of startup phases. */
|
|
4
|
+
export declare const PHASE_TITLES: Record<StartupPhaseId, string>;
|
|
5
|
+
/**
|
|
6
|
+
* Formats a monotonic duration compactly.
|
|
7
|
+
* @param milliseconds Duration in milliseconds.
|
|
8
|
+
*/
|
|
9
|
+
export declare function formatDuration(milliseconds: number): string;
|
|
10
|
+
/**
|
|
11
|
+
* One plain lifecycle line naming why the runtime restarts. The config line keeps
|
|
12
|
+
* the historical `Config changed, restarting` prefix.
|
|
13
|
+
* The source may come from the child, so it is made safe for one terminal row here.
|
|
14
|
+
* @param cause Merged cause of the transition.
|
|
15
|
+
* @param secrets Configured credentials removed from the source.
|
|
16
|
+
*/
|
|
17
|
+
export declare function describeRestartCause(cause: RestartCause, secrets?: readonly string[]): string;
|
|
18
|
+
/**
|
|
19
|
+
* Describes one phase: title, detail, real counts and elapsed time.
|
|
20
|
+
* @param phase Phase snapshot.
|
|
21
|
+
*/
|
|
22
|
+
export declare function describePhase(phase: PhaseSnapshot): string;
|
|
23
|
+
/**
|
|
24
|
+
* Plain description of the current startup: failure, running work, or readiness.
|
|
25
|
+
* Never fabricates a percentage.
|
|
26
|
+
* @param snapshot Current progress view.
|
|
27
|
+
*/
|
|
28
|
+
export declare function describeProgress(snapshot: ProgressSnapshot): string;
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
import { sanitizeLine } from '../output/sanitize.js';
|
|
2
|
+
/** Short English names of startup phases. */
|
|
3
|
+
export const PHASE_TITLES = {
|
|
4
|
+
config: 'Loading configuration',
|
|
5
|
+
vite: 'Starting Vite servers',
|
|
6
|
+
scan: 'Scanning stories',
|
|
7
|
+
markdown: 'Matching Markdown files',
|
|
8
|
+
plugins: 'Running plugin hooks',
|
|
9
|
+
listen: 'Starting server',
|
|
10
|
+
restore: 'Restoring cached catalog',
|
|
11
|
+
collect: 'Collecting stories',
|
|
12
|
+
warmup: 'Warming up client',
|
|
13
|
+
attach: 'Attaching services',
|
|
14
|
+
revalidate: 'Revalidating catalog',
|
|
15
|
+
};
|
|
16
|
+
/**
|
|
17
|
+
* Formats a monotonic duration compactly.
|
|
18
|
+
* @param milliseconds Duration in milliseconds.
|
|
19
|
+
*/
|
|
20
|
+
export function formatDuration(milliseconds) {
|
|
21
|
+
if (milliseconds < 1000)
|
|
22
|
+
return `${Math.round(milliseconds)}ms`;
|
|
23
|
+
if (milliseconds < 60_000)
|
|
24
|
+
return `${(milliseconds / 1000).toFixed(1)}s`;
|
|
25
|
+
const seconds = Math.floor(milliseconds / 1000);
|
|
26
|
+
return `${Math.floor(seconds / 60)}m ${String(seconds % 60).padStart(2, '0')}s`;
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* One plain lifecycle line naming why the runtime restarts. The config line keeps
|
|
30
|
+
* the historical `Config changed, restarting` prefix.
|
|
31
|
+
* The source may come from the child, so it is made safe for one terminal row here.
|
|
32
|
+
* @param cause Merged cause of the transition.
|
|
33
|
+
* @param secrets Configured credentials removed from the source.
|
|
34
|
+
*/
|
|
35
|
+
export function describeRestartCause(cause, secrets = []) {
|
|
36
|
+
const cleaned = cause.source ? sanitizeLine(cause.source, secrets) : undefined;
|
|
37
|
+
const source = cleaned ? ` (${cleaned})` : '';
|
|
38
|
+
switch (cause.kind) {
|
|
39
|
+
case 'config':
|
|
40
|
+
return `Config changed, restarting${source}${cause.fresh ? ' fresh' : ''}...`;
|
|
41
|
+
case 'browser':
|
|
42
|
+
return `Restart requested from the browser${cause.fresh ? ' (fresh)' : ''}...`;
|
|
43
|
+
case 'exit':
|
|
44
|
+
return `${cleaned ?? 'Runtime exited'}, restarting${cause.fresh ? ' fresh' : ''}...`;
|
|
45
|
+
case 'runtime':
|
|
46
|
+
return `${cleaned ?? 'Runtime requested a restart'}, restarting${cause.fresh ? ' fresh' : ''}...`;
|
|
47
|
+
default:
|
|
48
|
+
return cause.fresh ? 'Restarting fresh, skipping cached catalog and dependencies...' : 'Restarting...';
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* Describes one phase: title, detail, real counts and elapsed time.
|
|
53
|
+
* @param phase Phase snapshot.
|
|
54
|
+
*/
|
|
55
|
+
export function describePhase(phase) {
|
|
56
|
+
const detail = phase.label ? ` (${phase.label})` : '';
|
|
57
|
+
const counts = phase.current !== undefined && phase.total !== undefined ? ` ${phase.current}/${phase.total}` : '';
|
|
58
|
+
const suffix = phase.status === 'skipped' ? ' skipped' : phase.status === 'failed' ? ' failed' : phase.status === 'interrupted' ? ' interrupted' : '';
|
|
59
|
+
return `${PHASE_TITLES[phase.phase]}${detail}${counts}${suffix}${phase.status === 'skipped' ? '' : ` ${formatDuration(phase.elapsedMs)}`}`;
|
|
60
|
+
}
|
|
61
|
+
/**
|
|
62
|
+
* Plain description of the current startup: failure, running work, or readiness.
|
|
63
|
+
* Never fabricates a percentage.
|
|
64
|
+
* @param snapshot Current progress view.
|
|
65
|
+
*/
|
|
66
|
+
export function describeProgress(snapshot) {
|
|
67
|
+
if (snapshot.failed)
|
|
68
|
+
return `${describePhase(snapshot.failed)}${snapshot.failed.error ? `: ${snapshot.failed.error}` : ''}`;
|
|
69
|
+
const foreground = snapshot.active.filter(phase => !phase.background);
|
|
70
|
+
if (foreground.length)
|
|
71
|
+
return foreground.map(describePhase).join(' · ');
|
|
72
|
+
if (snapshot.status === 'ready' && snapshot.readyAfterMs !== undefined) {
|
|
73
|
+
const background = snapshot.active.map(describePhase);
|
|
74
|
+
return `Ready in ${formatDuration(snapshot.readyAfterMs)}${background.length ? ` · ${background.join(' · ')}` : ''}`;
|
|
75
|
+
}
|
|
76
|
+
return snapshot.status === 'restarting' ? 'Restarting' : snapshot.status === 'failed' ? 'Failed to start' : 'Starting';
|
|
77
|
+
}
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
import type { PublicState, RuntimeStatus } from '@histoire/dev-proxy/protocol';
|
|
2
|
+
import type { ProgressEvent, RestartCause, StartupPhaseId } from '../protocol/progress.js';
|
|
3
|
+
/** State of one phase as seen by the parent. */
|
|
4
|
+
export interface PhaseSnapshot {
|
|
5
|
+
phase: StartupPhaseId;
|
|
6
|
+
/** `interrupted` marks work that was running when its generation retired. */
|
|
7
|
+
status: 'running' | 'completed' | 'failed' | 'skipped' | 'interrupted';
|
|
8
|
+
/** Current detail such as a plugin name; skip reason on `skipped`. */
|
|
9
|
+
label?: string;
|
|
10
|
+
/** Loaded units, present only with a real `total`. */
|
|
11
|
+
current?: number;
|
|
12
|
+
total?: number;
|
|
13
|
+
/** Work that does not gate readiness. */
|
|
14
|
+
background: boolean;
|
|
15
|
+
/** Live monotonic elapsed time while running, final duration afterwards. */
|
|
16
|
+
elapsedMs: number;
|
|
17
|
+
/** Failure line, on `failed`. */
|
|
18
|
+
error?: string;
|
|
19
|
+
}
|
|
20
|
+
/** Point-in-time view of the current generation's startup. */
|
|
21
|
+
export interface ProgressSnapshot {
|
|
22
|
+
/** Lifecycle mirrored from the proxy. */
|
|
23
|
+
status: RuntimeStatus;
|
|
24
|
+
/** Generation the phases belong to; undefined before the first spawn. */
|
|
25
|
+
generation?: string;
|
|
26
|
+
/** The generation bypasses cached catalog and forces dependency optimization. */
|
|
27
|
+
fresh: boolean;
|
|
28
|
+
/** Reason of the restart that produced this generation; undefined for the initial start. */
|
|
29
|
+
cause?: RestartCause;
|
|
30
|
+
/** Time since the current transition began (frozen once ready, failed or closed). */
|
|
31
|
+
elapsedMs: number;
|
|
32
|
+
/** Total time the last transition took to reach `ready`. */
|
|
33
|
+
readyAfterMs?: number;
|
|
34
|
+
/** Every phase observed for this generation, in start order. */
|
|
35
|
+
phases: PhaseSnapshot[];
|
|
36
|
+
/** Foreground and background phases still running. */
|
|
37
|
+
active: PhaseSnapshot[];
|
|
38
|
+
/** The phase that failed, kept visible until the next generation spawns. */
|
|
39
|
+
failed?: PhaseSnapshot;
|
|
40
|
+
}
|
|
41
|
+
/** Parent-side, session-lifetime mirror of startup progress and restart causes. */
|
|
42
|
+
export interface ProgressState {
|
|
43
|
+
/** Feeds proxy `onStatus` (only status and generation are read). */
|
|
44
|
+
onStatus: (state: Pick<PublicState, 'status'>) => void;
|
|
45
|
+
/** Feeds proxy `onRuntimeStart`: opens a new generation, replacing the previous record. */
|
|
46
|
+
onRuntimeStart: (info: {
|
|
47
|
+
generation: string;
|
|
48
|
+
fresh: boolean;
|
|
49
|
+
}) => void;
|
|
50
|
+
/** Feeds proxy `onRestart`: the cause is attached to the next spawned generation. */
|
|
51
|
+
onRestart: (cause: RestartCause) => void;
|
|
52
|
+
/** Feeds a validated `progress` bridge event; frames of non-current or retired generations are ignored. */
|
|
53
|
+
onProgress: (generation: string, event: ProgressEvent) => void;
|
|
54
|
+
/** Feeds proxy `onRuntimeRetired`: running phases of that generation become `interrupted`. */
|
|
55
|
+
onRetired: (generation: string) => void;
|
|
56
|
+
/** Computes the current view; elapsed values are live. */
|
|
57
|
+
snapshot: () => ProgressSnapshot;
|
|
58
|
+
/** Observes every change (not clock ticks). Returns an unsubscribe function. */
|
|
59
|
+
subscribe: (listener: (snapshot: ProgressSnapshot) => void) => () => void;
|
|
60
|
+
}
|
|
61
|
+
/**
|
|
62
|
+
* Creates the progress mirror. Pure state: no I/O, no runtime imports.
|
|
63
|
+
* Child-provided text (labels, failure lines, restart sources) is made terminal-safe on ingestion.
|
|
64
|
+
* @param options Optional injected monotonic clock (`now`, milliseconds; tests only) and credentials to redact.
|
|
65
|
+
* @param options.now Monotonic clock in milliseconds.
|
|
66
|
+
* @param options.secrets Configured credentials removed from child text.
|
|
67
|
+
*/
|
|
68
|
+
export declare function createProgressState(options?: {
|
|
69
|
+
now?: () => number;
|
|
70
|
+
secrets?: readonly string[];
|
|
71
|
+
}): ProgressState;
|