@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.
Files changed (175) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +8 -2
  3. package/dist/cli.d.ts +9 -0
  4. package/dist/cli.js +88 -0
  5. package/dist/commands/dev.d.ts +44 -0
  6. package/dist/commands/dev.js +115 -0
  7. package/dist/commands/host.d.ts +66 -0
  8. package/dist/commands/host.js +1 -0
  9. package/dist/commands/screenshot-setup-args.d.ts +4 -0
  10. package/dist/commands/screenshot-setup-args.js +35 -0
  11. package/dist/commands/signal-guard.d.ts +29 -0
  12. package/dist/commands/signal-guard.js +52 -0
  13. package/dist/index.d.ts +2 -0
  14. package/dist/index.js +1 -0
  15. package/dist/terminal/actions.d.ts +51 -0
  16. package/dist/terminal/actions.js +60 -0
  17. package/dist/terminal/banner.d.ts +19 -0
  18. package/dist/terminal/banner.js +48 -0
  19. package/dist/terminal/bridge.d.ts +58 -0
  20. package/dist/terminal/bridge.js +103 -0
  21. package/dist/terminal/clipboard.d.ts +46 -0
  22. package/dist/terminal/clipboard.js +85 -0
  23. package/dist/terminal/diagnostics/attach.d.ts +9 -0
  24. package/dist/terminal/diagnostics/attach.js +46 -0
  25. package/dist/terminal/diagnostics/client.d.ts +12 -0
  26. package/dist/terminal/diagnostics/client.js +19 -0
  27. package/dist/terminal/diagnostics/lines.d.ts +17 -0
  28. package/dist/terminal/diagnostics/lines.js +61 -0
  29. package/dist/terminal/dispatch.d.ts +28 -0
  30. package/dist/terminal/dispatch.js +52 -0
  31. package/dist/terminal/feedback.d.ts +14 -0
  32. package/dist/terminal/feedback.js +27 -0
  33. package/dist/terminal/history/bounded.d.ts +37 -0
  34. package/dist/terminal/history/bounded.js +54 -0
  35. package/dist/terminal/host-extras.d.ts +14 -0
  36. package/dist/terminal/host-extras.js +26 -0
  37. package/dist/terminal/info/client.d.ts +20 -0
  38. package/dist/terminal/info/client.js +25 -0
  39. package/dist/terminal/info/generation-client.d.ts +33 -0
  40. package/dist/terminal/info/generation-client.js +32 -0
  41. package/dist/terminal/info/lines.d.ts +19 -0
  42. package/dist/terminal/info/lines.js +33 -0
  43. package/dist/terminal/info/network.d.ts +17 -0
  44. package/dist/terminal/info/network.js +48 -0
  45. package/dist/terminal/info/qr.d.ts +7 -0
  46. package/dist/terminal/info/qr.js +14 -0
  47. package/dist/terminal/keys.d.ts +44 -0
  48. package/dist/terminal/keys.js +60 -0
  49. package/dist/terminal/logs/browser-options.d.ts +9 -0
  50. package/dist/terminal/logs/browser-options.js +19 -0
  51. package/dist/terminal/navigation/browser.d.ts +69 -0
  52. package/dist/terminal/navigation/browser.js +193 -0
  53. package/dist/terminal/navigation/list.d.ts +53 -0
  54. package/dist/terminal/navigation/list.js +104 -0
  55. package/dist/terminal/navigation/search.d.ts +22 -0
  56. package/dist/terminal/navigation/search.js +44 -0
  57. package/dist/terminal/output/decoder.d.ts +24 -0
  58. package/dist/terminal/output/decoder.js +63 -0
  59. package/dist/terminal/output/history.d.ts +43 -0
  60. package/dist/terminal/output/history.js +21 -0
  61. package/dist/terminal/output/pipeline.d.ts +33 -0
  62. package/dist/terminal/output/pipeline.js +59 -0
  63. package/dist/terminal/output/sanitize.d.ts +32 -0
  64. package/dist/terminal/output/sanitize.js +142 -0
  65. package/dist/terminal/panel-model.d.ts +20 -0
  66. package/dist/terminal/panel-model.js +38 -0
  67. package/dist/terminal/panel.d.ts +30 -0
  68. package/dist/terminal/panel.js +53 -0
  69. package/dist/terminal/plain.d.ts +29 -0
  70. package/dist/terminal/plain.js +68 -0
  71. package/dist/terminal/progress/format.d.ts +28 -0
  72. package/dist/terminal/progress/format.js +77 -0
  73. package/dist/terminal/progress/state.d.ts +71 -0
  74. package/dist/terminal/progress/state.js +150 -0
  75. package/dist/terminal/protocol/catalog.d.ts +143 -0
  76. package/dist/terminal/protocol/catalog.js +61 -0
  77. package/dist/terminal/protocol/core.d.ts +117 -0
  78. package/dist/terminal/protocol/core.js +98 -0
  79. package/dist/terminal/protocol/diagnostics.d.ts +79 -0
  80. package/dist/terminal/protocol/diagnostics.js +31 -0
  81. package/dist/terminal/protocol/index.d.ts +22 -0
  82. package/dist/terminal/protocol/index.js +1 -0
  83. package/dist/terminal/protocol/progress.d.ts +67 -0
  84. package/dist/terminal/protocol/progress.js +52 -0
  85. package/dist/terminal/protocol/requests.d.ts +30 -0
  86. package/dist/terminal/protocol/requests.js +13 -0
  87. package/dist/terminal/protocol/session.d.ts +55 -0
  88. package/dist/terminal/protocol/session.js +28 -0
  89. package/dist/terminal/protocol/tests.d.ts +212 -0
  90. package/dist/terminal/protocol/tests.js +87 -0
  91. package/dist/terminal/protocol/watch.d.ts +60 -0
  92. package/dist/terminal/protocol/watch.js +40 -0
  93. package/dist/terminal/requests/browser-options.d.ts +8 -0
  94. package/dist/terminal/requests/browser-options.js +24 -0
  95. package/dist/terminal/requests/history.d.ts +30 -0
  96. package/dist/terminal/requests/history.js +53 -0
  97. package/dist/terminal/retained.d.ts +27 -0
  98. package/dist/terminal/retained.js +21 -0
  99. package/dist/terminal/session-types.d.ts +76 -0
  100. package/dist/terminal/session-types.js +1 -0
  101. package/dist/terminal/session.d.ts +8 -0
  102. package/dist/terminal/session.js +282 -0
  103. package/dist/terminal/shutdown.d.ts +12 -0
  104. package/dist/terminal/shutdown.js +30 -0
  105. package/dist/terminal/stories/client.d.ts +26 -0
  106. package/dist/terminal/stories/client.js +28 -0
  107. package/dist/terminal/stories/handoff.d.ts +39 -0
  108. package/dist/terminal/stories/handoff.js +40 -0
  109. package/dist/terminal/stories/paged.d.ts +70 -0
  110. package/dist/terminal/stories/paged.js +137 -0
  111. package/dist/terminal/stories/render.d.ts +39 -0
  112. package/dist/terminal/stories/render.js +94 -0
  113. package/dist/terminal/stories/state.d.ts +93 -0
  114. package/dist/terminal/stories/state.js +191 -0
  115. package/dist/terminal/stories/target.d.ts +24 -0
  116. package/dist/terminal/stories/target.js +29 -0
  117. package/dist/terminal/style.d.ts +45 -0
  118. package/dist/terminal/style.js +82 -0
  119. package/dist/terminal/support.d.ts +53 -0
  120. package/dist/terminal/support.js +66 -0
  121. package/dist/terminal/surface.d.ts +41 -0
  122. package/dist/terminal/surface.js +200 -0
  123. package/dist/terminal/tests/client.d.ts +21 -0
  124. package/dist/terminal/tests/client.js +12 -0
  125. package/dist/terminal/tests/console.d.ts +95 -0
  126. package/dist/terminal/tests/console.js +202 -0
  127. package/dist/terminal/tests/format.d.ts +18 -0
  128. package/dist/terminal/tests/format.js +55 -0
  129. package/dist/terminal/tests/header.d.ts +16 -0
  130. package/dist/terminal/tests/header.js +90 -0
  131. package/dist/terminal/tests/reporter.d.ts +17 -0
  132. package/dist/terminal/tests/reporter.js +99 -0
  133. package/dist/terminal/tests/results.d.ts +44 -0
  134. package/dist/terminal/tests/results.js +104 -0
  135. package/dist/terminal/tests/scope.d.ts +25 -0
  136. package/dist/terminal/tests/scope.js +25 -0
  137. package/dist/terminal/tests/session.d.ts +11 -0
  138. package/dist/terminal/tests/session.js +24 -0
  139. package/dist/terminal/tests/state.d.ts +57 -0
  140. package/dist/terminal/tests/state.js +134 -0
  141. package/dist/terminal/views/clear-history.d.ts +6 -0
  142. package/dist/terminal/views/clear-history.js +10 -0
  143. package/dist/terminal/views/error.d.ts +8 -0
  144. package/dist/terminal/views/error.js +24 -0
  145. package/dist/terminal/views/frame.d.ts +20 -0
  146. package/dist/terminal/views/frame.js +23 -0
  147. package/dist/terminal/views/help.d.ts +3 -0
  148. package/dist/terminal/views/help.js +32 -0
  149. package/dist/terminal/views/index.d.ts +6 -0
  150. package/dist/terminal/views/index.js +13 -0
  151. package/dist/terminal/views/logs.d.ts +3 -0
  152. package/dist/terminal/views/logs.js +7 -0
  153. package/dist/terminal/views/registry.d.ts +114 -0
  154. package/dist/terminal/views/registry.js +40 -0
  155. package/dist/terminal/views/requests.d.ts +8 -0
  156. package/dist/terminal/views/requests.js +15 -0
  157. package/dist/terminal/views/session.d.ts +9 -0
  158. package/dist/terminal/views/session.js +133 -0
  159. package/dist/terminal/views/stories.d.ts +9 -0
  160. package/dist/terminal/views/stories.js +172 -0
  161. package/dist/terminal/views/tests.d.ts +9 -0
  162. package/dist/terminal/views/tests.js +105 -0
  163. package/dist/terminal/watch/client.d.ts +12 -0
  164. package/dist/terminal/watch/client.js +7 -0
  165. package/dist/terminal/watch/controller.d.ts +30 -0
  166. package/dist/terminal/watch/controller.js +157 -0
  167. package/dist/terminal/watch/format.d.ts +15 -0
  168. package/dist/terminal/watch/format.js +37 -0
  169. package/dist/terminal/watch/session.d.ts +17 -0
  170. package/dist/terminal/watch/session.js +12 -0
  171. package/dist/terminal/width.d.ts +24 -0
  172. package/dist/terminal/width.js +171 -0
  173. package/dist/workbench-url.d.ts +30 -0
  174. package/dist/workbench-url.js +55 -0
  175. package/package.json +54 -3
@@ -0,0 +1,37 @@
1
+ /** Entry of a bounded history: carries the stable session identifier. */
2
+ export interface HistoryEntry {
3
+ /** Stable, strictly increasing session identifier (survives eviction, clearing and restarts). */
4
+ id: number;
5
+ }
6
+ /** Retention bounds of a history. */
7
+ export interface HistoryLimits<T> {
8
+ /** Most entries retained. */
9
+ entries: number;
10
+ /** Most retained weight (e.g. UTF-8 bytes); needs `weigh`. */
11
+ maxWeight?: number;
12
+ /** Cost of one entry against `maxWeight`. */
13
+ weigh?: (entry: T) => number;
14
+ }
15
+ /** Session-lifetime history bounded by entry count and optional weight. */
16
+ export interface BoundedHistory<T extends HistoryEntry> {
17
+ /** Assigns the next identifier, retains the built entry and evicts oldest ones beyond the bounds. */
18
+ append: (build: (id: number) => T) => T;
19
+ /** Currently retained entries, oldest first. */
20
+ entries: () => readonly T[];
21
+ /** Number of entries evicted by bounds since the session began (not by `clear`). */
22
+ readonly omitted: number;
23
+ /** Retained weight. */
24
+ readonly weight: number;
25
+ /** Deletes retained entries; identifiers keep increasing. */
26
+ clear: () => void;
27
+ /** Notifies after each append or clear; returns an unsubscribe function. */
28
+ subscribe: (listener: () => void) => () => void;
29
+ /** Notifies listeners without changing entries (state kept next to the history changed). */
30
+ touch: () => void;
31
+ }
32
+ /**
33
+ * Creates the retention core shared by log and request histories: stable increasing IDs,
34
+ * oldest-first eviction with an omission count, and fault-isolated change listeners.
35
+ * @param limits Entry and optional weight bounds.
36
+ */
37
+ export declare function createBoundedHistory<T extends HistoryEntry>(limits: HistoryLimits<T>): BoundedHistory<T>;
@@ -0,0 +1,54 @@
1
+ /**
2
+ * Creates the retention core shared by log and request histories: stable increasing IDs,
3
+ * oldest-first eviction with an omission count, and fault-isolated change listeners.
4
+ * @param limits Entry and optional weight bounds.
5
+ */
6
+ export function createBoundedHistory(limits) {
7
+ const weigh = limits.weigh ?? (() => 0);
8
+ const maxWeight = limits.maxWeight ?? Number.POSITIVE_INFINITY;
9
+ const records = [];
10
+ const listeners = new Set();
11
+ let nextId = 1;
12
+ let weight = 0;
13
+ let omitted = 0;
14
+ /** Listener faults must not break the producer. */
15
+ function notify() {
16
+ for (const listener of [...listeners]) {
17
+ try {
18
+ listener();
19
+ }
20
+ catch { }
21
+ }
22
+ }
23
+ return {
24
+ get omitted() {
25
+ return omitted;
26
+ },
27
+ get weight() {
28
+ return weight;
29
+ },
30
+ append(build) {
31
+ const record = build(nextId++);
32
+ records.push(record);
33
+ weight += weigh(record);
34
+ // Always keep the newest entry, even if it alone exceeds the weight bound.
35
+ while (records.length > 1 && (records.length > limits.entries || weight > maxWeight)) {
36
+ weight -= weigh(records.shift());
37
+ omitted++;
38
+ }
39
+ notify();
40
+ return record;
41
+ },
42
+ entries: () => records,
43
+ clear() {
44
+ records.length = 0;
45
+ weight = 0;
46
+ notify();
47
+ },
48
+ subscribe(listener) {
49
+ listeners.add(listener);
50
+ return () => listeners.delete(listener);
51
+ },
52
+ touch: notify,
53
+ };
54
+ }
@@ -0,0 +1,14 @@
1
+ import type { SessionHostExtras } from './session-types.js';
2
+ import type { TerminalViewHost } from './views/registry.js';
3
+ /** Pieces of the view host that depend only on options, not on the session's screen state. */
4
+ export type HostExtras = Pick<TerminalViewHost, 'retained' | 'networkUrls' | 'addInfoSection' | 'infoSections'>;
5
+ /**
6
+ * Builds the retained-history registry, network URL derivation and info sections of the view host.
7
+ * @param options Session options subset.
8
+ * @param options.logs Session log history, always deletable through `x`.
9
+ * @param options.retained Registry shared with the dev command, created here when absent.
10
+ * @param options.host The `--host` value.
11
+ * @param options.interfaces Network interface source (tests).
12
+ * @param publicUrl Reads the bound public URL (changes on port fallback).
13
+ */
14
+ export declare function createHostExtras(options: SessionHostExtras, publicUrl: () => string | undefined): HostExtras;
@@ -0,0 +1,26 @@
1
+ import { networkInterfaces } from 'node:os';
2
+ import { deriveNetworkUrls } from './info/network.js';
3
+ import { createRetainedHistories } from './retained.js';
4
+ /**
5
+ * Builds the retained-history registry, network URL derivation and info sections of the view host.
6
+ * @param options Session options subset.
7
+ * @param options.logs Session log history, always deletable through `x`.
8
+ * @param options.retained Registry shared with the dev command, created here when absent.
9
+ * @param options.host The `--host` value.
10
+ * @param options.interfaces Network interface source (tests).
11
+ * @param publicUrl Reads the bound public URL (changes on port fallback).
12
+ */
13
+ export function createHostExtras(options, publicUrl) {
14
+ const retained = options.retained ?? createRetainedHistories();
15
+ retained.register({ id: 'logs', label: 'log entries', count: () => options.logs.entries().length, clear: () => options.logs.clear() });
16
+ const sections = new Set();
17
+ return {
18
+ retained,
19
+ networkUrls: () => deriveNetworkUrls({ host: options.host, publicUrl: publicUrl(), interfaces: (options.interfaces ?? networkInterfaces)() }),
20
+ addInfoSection(provider) {
21
+ sections.add(provider);
22
+ return () => void sections.delete(provider);
23
+ },
24
+ infoSections: () => [...sections].flatMap(provider => provider() ?? []),
25
+ };
26
+ }
@@ -0,0 +1,20 @@
1
+ import type { TerminalBridge } from '../bridge.js';
2
+ import type { ProgressState } from '../progress/state.js';
3
+ import type { SessionInfoDto } from '../protocol/session.js';
4
+ /** Runtime-provided session facts for the generation that is current right now. */
5
+ export interface SessionInfoClient {
6
+ /** Reply for the current generation, or why there is none. Never an earlier generation's reply. */
7
+ current: () => {
8
+ info?: SessionInfoDto;
9
+ problem?: string;
10
+ };
11
+ /** Asks the current runtime again; resolves when the answer (or failure) has been recorded. */
12
+ refresh: () => Promise<void>;
13
+ }
14
+ /**
15
+ * Creates the typed `session.get` wrapper over the generation-tagged client.
16
+ * @param bridge Command bridge.
17
+ * @param progress Progress mirror (current generation and readiness).
18
+ * @param changed Called when a reply or failure was recorded (repaint).
19
+ */
20
+ export declare function createSessionInfoClient(bridge: TerminalBridge, progress: ProgressState, changed: () => void): SessionInfoClient;
@@ -0,0 +1,25 @@
1
+ import { isSessionInfo } from '../protocol/session.js';
2
+ import { createGenerationClient } from './generation-client.js';
3
+ /**
4
+ * Creates the typed `session.get` wrapper over the generation-tagged client.
5
+ * @param bridge Command bridge.
6
+ * @param progress Progress mirror (current generation and readiness).
7
+ * @param changed Called when a reply or failure was recorded (repaint).
8
+ */
9
+ export function createSessionInfoClient(bridge, progress, changed) {
10
+ const client = createGenerationClient({
11
+ read: () => bridge.send('session.get', {}),
12
+ validate: isSessionInfo,
13
+ progress,
14
+ changed,
15
+ unusable: 'Runtime sent unusable session details',
16
+ unavailable: 'Runtime details unavailable',
17
+ });
18
+ return {
19
+ current() {
20
+ const { value, problem } = client.current();
21
+ return { info: value, problem };
22
+ },
23
+ refresh: client.refresh,
24
+ };
25
+ }
@@ -0,0 +1,33 @@
1
+ import type { ProgressState } from '../progress/state.js';
2
+ /** Runtime-provided value for the generation that is current right now. */
3
+ export interface GenerationClient<T> {
4
+ /** Reply for the current generation, or why there is none. Never an earlier generation's reply. */
5
+ current: () => {
6
+ value?: T;
7
+ problem?: string;
8
+ };
9
+ /** Asks the current runtime again; resolves when the answer (or failure) has been recorded. */
10
+ refresh: () => Promise<void>;
11
+ }
12
+ /** Inputs of {@link createGenerationClient}. */
13
+ export interface GenerationClientOptions<T> {
14
+ /** Performs the bridge read. */
15
+ read: () => Promise<unknown>;
16
+ /** Validates the untrusted reply; anything else is discarded. */
17
+ validate: (value: unknown) => value is T;
18
+ /** Progress mirror (current generation and readiness). */
19
+ progress: ProgressState;
20
+ /** Called when a reply or failure was recorded (repaint). */
21
+ changed: () => void;
22
+ /** Problem text for an unusable reply. */
23
+ unusable: string;
24
+ /** Prefix of the problem text for a failed read; the failure message follows. */
25
+ unavailable: string;
26
+ }
27
+ /**
28
+ * Creates a generation-tagged read: the reply is stored with the generation it was
29
+ * requested for and is hidden as soon as the progress state moves to another one, so a
30
+ * retired runtime's answer is never shown as current.
31
+ * @param options Read, validation and wording.
32
+ */
33
+ export declare function createGenerationClient<T>(options: GenerationClientOptions<T>): GenerationClient<T>;
@@ -0,0 +1,32 @@
1
+ /**
2
+ * Creates a generation-tagged read: the reply is stored with the generation it was
3
+ * requested for and is hidden as soon as the progress state moves to another one, so a
4
+ * retired runtime's answer is never shown as current.
5
+ * @param options Read, validation and wording.
6
+ */
7
+ export function createGenerationClient(options) {
8
+ const { progress } = options;
9
+ let stored;
10
+ return {
11
+ current() {
12
+ const { generation, status } = progress.snapshot();
13
+ if (!generation || status !== 'ready')
14
+ return { problem: status === 'ready' ? 'Waiting for the runtime' : undefined };
15
+ return stored?.generation === generation ? { value: stored.value, problem: stored.problem } : {};
16
+ },
17
+ async refresh() {
18
+ const { generation, status } = progress.snapshot();
19
+ if (!generation || status !== 'ready')
20
+ return;
21
+ try {
22
+ const value = await options.read();
23
+ stored = options.validate(value) ? { generation, value } : { generation, problem: options.unusable };
24
+ }
25
+ catch (error) {
26
+ stored = { generation, problem: `${options.unavailable}: ${error instanceof Error ? error.message : String(error)}` };
27
+ }
28
+ // A reply that arrives after a restart belongs to a retired generation: dropped by `current`.
29
+ options.changed();
30
+ },
31
+ };
32
+ }
@@ -0,0 +1,19 @@
1
+ import type { ProgressSnapshot } from '../progress/state.js';
2
+ import type { SessionInfoDto } from '../protocol/session.js';
3
+ /** Everything the session screen shows, gathered from live parent state and the current child reply. */
4
+ export interface SessionLinesInput {
5
+ snapshot: ProgressSnapshot;
6
+ /** Reply of the current generation only; undefined while unknown or retired. */
7
+ info?: SessionInfoDto;
8
+ /** Why `info` is missing, when known. */
9
+ infoProblem?: string;
10
+ /** Time since the CLI started. */
11
+ uptimeMs: number;
12
+ }
13
+ /**
14
+ * Plain rows of the session screen (without URL rows, which the view makes selectable).
15
+ * Runtime facts come only from `info`, which the caller drops when its generation retired,
16
+ * so a previous generation's version or phase is never shown as current.
17
+ * @param input Live state.
18
+ */
19
+ export declare function buildSessionLines(input: SessionLinesInput): string[];
@@ -0,0 +1,33 @@
1
+ import { sanitizeLine } from '../output/sanitize.js';
2
+ import { describePhase, describeProgress, describeRestartCause, formatDuration } from '../progress/format.js';
3
+ /** Aligned `label value` row; the value may come from the child, so it is made safe here. */
4
+ const field = (label, value) => `${label.padEnd(10)} ${sanitizeLine(value)}`;
5
+ /** Reason line without the trailing ellipsis of the lifecycle notice. */
6
+ const reason = (snapshot) => snapshot.cause ? describeRestartCause(snapshot.cause).replace(/\.\.\.$/, '') : 'Initial start';
7
+ /**
8
+ * Plain rows of the session screen (without URL rows, which the view makes selectable).
9
+ * Runtime facts come only from `info`, which the caller drops when its generation retired,
10
+ * so a previous generation's version or phase is never shown as current.
11
+ * @param input Live state.
12
+ */
13
+ export function buildSessionLines(input) {
14
+ const { snapshot, info } = input;
15
+ const lines = [
16
+ field('Status', snapshot.status === 'ready' ? describeProgress(snapshot) : `${snapshot.status[0].toUpperCase()}${snapshot.status.slice(1)} · ${describeProgress(snapshot)}`),
17
+ field('Started', reason(snapshot)),
18
+ field('Uptime', formatDuration(input.uptimeMs)),
19
+ ];
20
+ const finished = snapshot.phases.filter(phase => phase.status === 'completed' || phase.status === 'skipped');
21
+ if (finished.length)
22
+ lines.push(field('Phases', finished.map(describePhase).join(' · ')));
23
+ if (info) {
24
+ lines.push(field('Histoire', info.histoire), field('Node', info.node), field('Vite', info.vite), field('Root', info.root), field('Config', info.configFile ?? 'none found'));
25
+ if (info.collection)
26
+ lines.push(field('Stories', `${info.collection.stories} stories · ${info.collection.variants} variants · ${info.collection.outcome}${info.collection.diagnostics ? ` · ${info.collection.diagnostics} issues` : ''}`));
27
+ lines.push(field('MCP', info.mcp.enabled ? `${info.mcp.url ?? 'starting'}${info.mcp.tokenRequired ? ' (bearer token required)' : ''}` : 'disabled'));
28
+ }
29
+ else {
30
+ lines.push(field('Runtime', input.infoProblem ?? 'Waiting for the runtime'));
31
+ }
32
+ return lines;
33
+ }
@@ -0,0 +1,17 @@
1
+ import type { NetworkInterfaceInfo } from 'node:os';
2
+ /** Interface table shape of `os.networkInterfaces()`. */
3
+ export type InterfaceTable = Record<string, readonly NetworkInterfaceInfo[] | undefined>;
4
+ /**
5
+ * Derives the addresses other machines can use from the configured binding, never from
6
+ * a loopback-only listener, and never inventing one when no interface is reachable.
7
+ * @param options Binding and environment.
8
+ * @param options.host The `--host` value: undefined/false keep the default loopback binding, `true` listens everywhere, a string binds that address.
9
+ * @param options.publicUrl Bound public URL; supplies port and protocol (its hostname is ignored).
10
+ * @param options.interfaces Network interfaces (`os.networkInterfaces()`).
11
+ * @returns Absolute base URLs, one per reachable address.
12
+ */
13
+ export declare function deriveNetworkUrls(options: {
14
+ host: string | boolean | undefined;
15
+ publicUrl: string | undefined;
16
+ interfaces: InterfaceTable;
17
+ }): string[];
@@ -0,0 +1,48 @@
1
+ /** Whether a configured binding only accepts connections from this machine. */
2
+ function isLoopbackHost(host) {
3
+ const name = host.trim().toLowerCase().replace(/^\[|\]$/g, '');
4
+ return name === 'localhost' || name.endsWith('.localhost') || name === '::1' || name === '0:0:0:0:0:0:0:1' || /^127\./.test(name);
5
+ }
6
+ /** Whether a configured binding listens on every interface. */
7
+ function isWildcardHost(host) {
8
+ const name = host.trim().replace(/^\[|\]$/g, '');
9
+ return name === '0.0.0.0' || name === '::' || name === '0:0:0:0:0:0:0:0';
10
+ }
11
+ /**
12
+ * Derives the addresses other machines can use from the configured binding, never from
13
+ * a loopback-only listener, and never inventing one when no interface is reachable.
14
+ * @param options Binding and environment.
15
+ * @param options.host The `--host` value: undefined/false keep the default loopback binding, `true` listens everywhere, a string binds that address.
16
+ * @param options.publicUrl Bound public URL; supplies port and protocol (its hostname is ignored).
17
+ * @param options.interfaces Network interfaces (`os.networkInterfaces()`).
18
+ * @returns Absolute base URLs, one per reachable address.
19
+ */
20
+ export function deriveNetworkUrls(options) {
21
+ const { host, publicUrl } = options;
22
+ if (!publicUrl || host === undefined || host === false)
23
+ return [];
24
+ let base;
25
+ try {
26
+ base = new URL(publicUrl);
27
+ }
28
+ catch {
29
+ return [];
30
+ }
31
+ let addresses;
32
+ if (host === true || isWildcardHost(host)) {
33
+ // Wildcard: every external IPv4 address (IPv6 link-local ones are not shareable). `::` also accepts IPv4 on dual-stack systems.
34
+ addresses = Object.values(options.interfaces).flatMap(list => list ?? []).filter(entry => !entry.internal && entry.family === 'IPv4').map(entry => entry.address);
35
+ }
36
+ else if (isLoopbackHost(host)) {
37
+ return [];
38
+ }
39
+ else {
40
+ addresses = [host.replace(/^\[|\]$/g, '')];
41
+ }
42
+ return [...new Set(addresses)].map((address) => {
43
+ const url = new URL(base.href);
44
+ // Bare IPv6 literals need brackets, otherwise the hostname setter ignores them.
45
+ url.hostname = address.includes(':') ? `[${address}]` : address;
46
+ return url.href;
47
+ });
48
+ }
@@ -0,0 +1,7 @@
1
+ /**
2
+ * Renders a URL as a QR code with two modules per terminal row (half blocks).
3
+ * Loads `uqr` on first use so the parent's startup graph stays light.
4
+ * @param url Address to encode.
5
+ * @returns One string per terminal row, each colored independently of the terminal theme.
6
+ */
7
+ export declare function renderQrRows(url: string): Promise<string[]>;
@@ -0,0 +1,14 @@
1
+ /** Forces light modules on a dark ground so the code scans on both light and dark terminal themes. */
2
+ const LIGHT_ON_DARK = '\u001B[97;40m';
3
+ /** Restores default foreground and background. */
4
+ const DEFAULT_COLORS = '\u001B[39;49m';
5
+ /**
6
+ * Renders a URL as a QR code with two modules per terminal row (half blocks).
7
+ * Loads `uqr` on first use so the parent's startup graph stays light.
8
+ * @param url Address to encode.
9
+ * @returns One string per terminal row, each colored independently of the terminal theme.
10
+ */
11
+ export async function renderQrRows(url) {
12
+ const { renderUnicodeCompact } = await import('uqr');
13
+ return renderUnicodeCompact(url, { border: 2 }).split('\n').map(row => `${LIGHT_ON_DARK}${row}${DEFAULT_COLORS}`);
14
+ }
@@ -0,0 +1,44 @@
1
+ import type { ReadStream } from 'node:tty';
2
+ /** Normalized key press delivered to the terminal session. */
3
+ export interface TerminalKey {
4
+ /** Key name: `up`, `down`, `pageup`, `pagedown`, `home`, `end`, `return`, `escape`, `tab`, `backspace`, `delete`, or the lowercase letter. */
5
+ name: string;
6
+ /** Printable text exactly as typed (`R`, `/`, `é`); undefined for control and navigation keys. */
7
+ char?: string;
8
+ ctrl: boolean;
9
+ meta: boolean;
10
+ shift: boolean;
11
+ }
12
+ /** Stream surface the input owner needs; `process.stdin` satisfies it. */
13
+ export type KeyInputStream = Pick<ReadStream, 'on' | 'off' | 'resume' | 'pause' | 'setRawMode' | 'isRaw' | 'readableFlowing' | 'listenerCount'>;
14
+ /** Owner of raw mode and the keypress subscription of one input stream. */
15
+ export interface KeyInput {
16
+ /** Enters raw mode and starts delivering keys. Idempotent. */
17
+ attach: () => void;
18
+ /** Restores the raw/flow state seen at attach and removes only the owned listener. Idempotent. */
19
+ detach: () => void;
20
+ /** Whether keys are currently delivered. */
21
+ readonly attached: boolean;
22
+ }
23
+ /**
24
+ * Normalizes a `node:readline` keypress event.
25
+ * @param text Decoded text of the event.
26
+ * @param key Readline's key description.
27
+ */
28
+ export declare function normalizeKey(text: string | undefined, key: {
29
+ name?: string;
30
+ ctrl?: boolean;
31
+ meta?: boolean;
32
+ shift?: boolean;
33
+ } | undefined): TerminalKey;
34
+ /**
35
+ * Owns raw input for the panel. Only one instance may be attached to a stream at a time
36
+ * (the session guarantees it); attach and detach are paired and preserve the prior state.
37
+ * @param options Input stream and key callback.
38
+ * @param options.stdin Input stream whose raw mode and flow state are borrowed.
39
+ * @param options.onKey Receives each decoded key.
40
+ */
41
+ export declare function createKeyInput(options: {
42
+ stdin: KeyInputStream;
43
+ onKey: (key: TerminalKey) => void;
44
+ }): KeyInput;
@@ -0,0 +1,60 @@
1
+ import { emitKeypressEvents } from 'node:readline';
2
+ /** Lone Escape is reported after this delay; short so leaving views feels immediate. */
3
+ const ESCAPE_TIMEOUT_MS = 100;
4
+ /**
5
+ * Normalizes a `node:readline` keypress event.
6
+ * @param text Decoded text of the event.
7
+ * @param key Readline's key description.
8
+ */
9
+ export function normalizeKey(text, key) {
10
+ const ctrl = key?.ctrl === true;
11
+ const meta = key?.meta === true;
12
+ const printable = !ctrl && !meta && text !== undefined && text.length > 0 && !/[\u0000-\u001F\u007F-\u009F]/.test(text);
13
+ return {
14
+ name: key?.name ?? text ?? '',
15
+ ...(printable ? { char: text } : {}),
16
+ ctrl,
17
+ meta,
18
+ shift: key?.shift === true || (printable && text !== text.toLowerCase()),
19
+ };
20
+ }
21
+ /**
22
+ * Owns raw input for the panel. Only one instance may be attached to a stream at a time
23
+ * (the session guarantees it); attach and detach are paired and preserve the prior state.
24
+ * @param options Input stream and key callback.
25
+ * @param options.stdin Input stream whose raw mode and flow state are borrowed.
26
+ * @param options.onKey Receives each decoded key.
27
+ */
28
+ export function createKeyInput(options) {
29
+ const { stdin } = options;
30
+ let listener;
31
+ let wasRaw = false;
32
+ let wasFlowing = false;
33
+ return {
34
+ get attached() {
35
+ return listener !== undefined;
36
+ },
37
+ attach() {
38
+ if (listener)
39
+ return;
40
+ // Idempotent per stream; the escape timeout only applies when this call is the first.
41
+ emitKeypressEvents(stdin, { escapeCodeTimeout: ESCAPE_TIMEOUT_MS });
42
+ wasRaw = stdin.isRaw === true;
43
+ wasFlowing = stdin.readableFlowing === true;
44
+ listener = (text, key) => options.onKey(normalizeKey(text, key));
45
+ stdin.on('keypress', listener);
46
+ stdin.setRawMode(true);
47
+ stdin.resume();
48
+ },
49
+ detach() {
50
+ if (!listener)
51
+ return;
52
+ stdin.off('keypress', listener);
53
+ listener = undefined;
54
+ stdin.setRawMode(wasRaw);
55
+ // A stream we started reading must not keep the process alive after release.
56
+ if (!wasFlowing)
57
+ stdin.pause();
58
+ },
59
+ };
60
+ }
@@ -0,0 +1,9 @@
1
+ import type { HistoryBrowserOptions } from '../navigation/browser.js';
2
+ import type { LogRecord } from '../output/history.js';
3
+ import type { TerminalViewHost } from '../views/registry.js';
4
+ /**
5
+ * Browser options shared by every screen over the session log history (logs, latest error).
6
+ * @param host View host; `logs` is the session history.
7
+ * @param filter Keeps only the records the screen shows.
8
+ */
9
+ export declare function logBrowserOptions(host: Pick<TerminalViewHost, 'size' | 'notify' | 'copy' | 'requestRender' | 'logs'>, filter?: (record: LogRecord) => boolean): Pick<HistoryBrowserOptions<LogRecord>, 'host' | 'items' | 'id' | 'rank' | 'text' | 'label' | 'tone' | 'omitted' | 'subscribe'>;
@@ -0,0 +1,19 @@
1
+ /**
2
+ * Browser options shared by every screen over the session log history (logs, latest error).
3
+ * @param host View host; `logs` is the session history.
4
+ * @param filter Keeps only the records the screen shows.
5
+ */
6
+ export function logBrowserOptions(host, filter = () => true) {
7
+ const history = host.logs;
8
+ return {
9
+ host,
10
+ items: () => history.entries().filter(filter),
11
+ id: record => String(record.id),
12
+ rank: record => record.id,
13
+ text: record => record.truncated ? `${record.text} … (${record.truncated} characters cut)` : record.text,
14
+ label: record => `#${record.id} ${record.source === 'diagnostic' ? 'histoire' : record.source}`,
15
+ tone: record => record.level === 'error' ? 'error' : record.level === 'warn' ? 'warn' : record.level === 'debug' ? 'dim' : undefined,
16
+ omitted: () => history.omitted,
17
+ subscribe: listener => history.subscribe(listener),
18
+ };
19
+ }
@@ -0,0 +1,69 @@
1
+ import type { TerminalKey } from '../keys.js';
2
+ import type { TerminalViewHost } from '../views/registry.js';
3
+ import type { ListNavigation } from './list.js';
4
+ import type { SearchInput } from './search.js';
5
+ /** Host capabilities the browser needs; a subset of the view host. */
6
+ export type BrowserHost = Pick<TerminalViewHost, 'size' | 'notify' | 'copy' | 'requestRender'>;
7
+ /** What a history provides to be browsed; entries need a stable ID and a monotonic rank. */
8
+ export interface HistoryBrowserOptions<T> {
9
+ host: BrowserHost;
10
+ /** Screen header. */
11
+ title: string;
12
+ /** Plural noun used in counts, e.g. `log entries`. */
13
+ noun: string;
14
+ /** Retained entries, oldest first. */
15
+ items: () => readonly T[];
16
+ /** Stable identity of an entry. */
17
+ id: (item: T) => string;
18
+ /** Increasing order key (the session ID); lets a vanished selection move to the nearest retained entry. */
19
+ rank: (item: T) => number;
20
+ /** Full sanitized text: searched, shown in detail and copied. */
21
+ text: (item: T) => string;
22
+ /** Short plain label shown before the first line, e.g. `12 stderr`. */
23
+ label: (item: T) => string;
24
+ /** Marks rows that deserve attention; only the label is colored. */
25
+ tone?: (item: T) => 'error' | 'warn' | 'dim' | undefined;
26
+ /** Entries evicted by retention bounds since the session began. */
27
+ omitted: () => number;
28
+ /** Observes appends and deletions; returns an unsubscribe function. */
29
+ subscribe: (listener: () => void) => () => void;
30
+ /** Extra lines above the list (e.g. a failed phase). */
31
+ header?: () => string[];
32
+ /** Text shown while nothing matches; a function when it depends on live state. */
33
+ empty: string | (() => string);
34
+ /** Open the newest entry in detail on every entry to the screen (latest error). */
35
+ startInDetail?: boolean;
36
+ /** Keep the cursor on the newest entry (append-only histories); `false` for result lists that start at the top. Default `true`. */
37
+ follow?: boolean;
38
+ /** Replaces the status line above the list (receives the number of matching entries). */
39
+ status?: (shown: number) => string;
40
+ /** Replaces the list footer hint. */
41
+ footer?: string;
42
+ }
43
+ /** View pieces of a browser, spread into a `TerminalView`. */
44
+ export interface HistoryBrowser<T> {
45
+ enter: () => void;
46
+ leave: () => void;
47
+ capturesInput: () => boolean;
48
+ handleKey: (key: TerminalKey) => boolean;
49
+ render: (size: {
50
+ columns: number;
51
+ rows: number;
52
+ }) => string[];
53
+ /** Selection, scrolling and follow state (exposed for tests and sibling views). */
54
+ navigation: ListNavigation<T>;
55
+ /** The `/` prompt. */
56
+ search: SearchInput;
57
+ /** Opens the selected entry in detail. */
58
+ openDetail: () => void;
59
+ /** Whether an entry is open in detail (it then owns every key). */
60
+ detailOpen: () => boolean;
61
+ }
62
+ /**
63
+ * Builds list + detail + search + copy behavior over any bounded history. Logs, the
64
+ * latest-error screen and (slice 06) requests share it instead of cloning navigation.
65
+ * Selection is kept by stable ID: appends never move it, eviction moves it to the nearest
66
+ * retained entry, scrolling pauses following and End resumes.
67
+ * @param options History access and presentation.
68
+ */
69
+ export declare function createHistoryBrowser<T>(options: HistoryBrowserOptions<T>): HistoryBrowser<T>;