@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,8 @@
1
+ import type { TerminalViewFactory } from './registry.js';
2
+ /**
3
+ * `e`: opens the newest retained error in detail. Errors are structured console errors,
4
+ * diagnostics and stderr lines (the stderr fallback); earlier ones stay reachable from the
5
+ * list. A failed startup phase is shown above as structured context. Ordinary stderr never
6
+ * changes the runtime state, this screen only reads history.
7
+ */
8
+ export declare const createErrorView: TerminalViewFactory;
@@ -0,0 +1,24 @@
1
+ import { logBrowserOptions } from '../logs/browser-options.js';
2
+ import { createHistoryBrowser } from '../navigation/browser.js';
3
+ import { PHASE_TITLES } from '../progress/format.js';
4
+ import { defaultStyle } from '../style.js';
5
+ /**
6
+ * `e`: opens the newest retained error in detail. Errors are structured console errors,
7
+ * diagnostics and stderr lines (the stderr fallback); earlier ones stay reachable from the
8
+ * list. A failed startup phase is shown above as structured context. Ordinary stderr never
9
+ * changes the runtime state, this screen only reads history.
10
+ */
11
+ export const createErrorView = (host) => {
12
+ const browser = createHistoryBrowser({
13
+ ...logBrowserOptions(host, record => record.level === 'error'),
14
+ title: 'Latest error',
15
+ noun: 'errors',
16
+ empty: 'No errors',
17
+ startInDetail: true,
18
+ header() {
19
+ const failed = host.progress.snapshot().failed;
20
+ return failed ? [defaultStyle().error(`${PHASE_TITLES[failed.phase]} failed${failed.error ? `: ${failed.error}` : ''}`)] : [];
21
+ },
22
+ });
23
+ return { id: 'error', shortcut: 'e', title: 'Latest error', ...browser };
24
+ };
@@ -0,0 +1,20 @@
1
+ import type { Style } from '../style.js';
2
+ /**
3
+ * Lays out a full-screen view: brand title bar, body rows, footer hint on the last row.
4
+ * Every line is fitted to the width; the result is exactly `rows` lines.
5
+ * @param options Title, body lines (already wrapped/fitted or not), footer text and screen size.
6
+ * @param options.title Header text.
7
+ * @param options.body Content rows; extra rows are cut.
8
+ * @param options.footer Hint row.
9
+ * @param options.columns Screen width.
10
+ * @param options.rows Screen height.
11
+ * @param options.style Palette; defaults to the one the environment allows.
12
+ */
13
+ export declare function renderViewFrame(options: {
14
+ title: string;
15
+ body: readonly string[];
16
+ footer: string;
17
+ columns: number;
18
+ rows: number;
19
+ style?: Style;
20
+ }): string[];
@@ -0,0 +1,23 @@
1
+ import { defaultStyle } from '../style.js';
2
+ import { displayWidth, fitWidth } from '../width.js';
3
+ /**
4
+ * Lays out a full-screen view: brand title bar, body rows, footer hint on the last row.
5
+ * Every line is fitted to the width; the result is exactly `rows` lines.
6
+ * @param options Title, body lines (already wrapped/fitted or not), footer text and screen size.
7
+ * @param options.title Header text.
8
+ * @param options.body Content rows; extra rows are cut.
9
+ * @param options.footer Hint row.
10
+ * @param options.columns Screen width.
11
+ * @param options.rows Screen height.
12
+ * @param options.style Palette; defaults to the one the environment allows.
13
+ */
14
+ export function renderViewFrame(options) {
15
+ const style = options.style ?? defaultStyle();
16
+ const height = Math.max(1, options.rows - 2);
17
+ const title = fitWidth(` ${options.title} `, options.columns);
18
+ const lines = [style.seal(style.title(`${title}${' '.repeat(Math.max(0, options.columns - displayWidth(title)))}`))];
19
+ for (let index = 0; index < height; index++)
20
+ lines.push(fitWidth(options.body[index] ?? '', options.columns));
21
+ lines.push(style.seal(fitWidth(style.hints(options.footer), options.columns)));
22
+ return lines.slice(0, options.rows);
23
+ }
@@ -0,0 +1,3 @@
1
+ import type { TerminalViewFactory } from './registry.js';
2
+ /** Help screen: lists every main key and whether its view exists in this build. */
3
+ export declare const createHelpView: TerminalViewFactory;
@@ -0,0 +1,32 @@
1
+ import { MAIN_ACTIONS } from '../actions.js';
2
+ import { createListNavigation } from '../navigation/list.js';
3
+ import { defaultStyle } from '../style.js';
4
+ import { renderViewFrame } from './frame.js';
5
+ /** Help screen: lists every main key and whether its view exists in this build. */
6
+ export const createHelpView = (host) => {
7
+ const navigation = createListNavigation({ id: ([key, description]) => `${key}\u0000${description}` });
8
+ /** Key column width: the longest key (`Esc or q`) plus a gap. */
9
+ const KEY_WIDTH = 10;
10
+ /** Rows as `[key, description]`, rebuilt on each render so late-registered views appear. */
11
+ function rows() {
12
+ const lines = MAIN_ACTIONS.map(action => [action.key, action.description]);
13
+ for (const entry of host.shortcuts()) {
14
+ if (entry.shortcut !== '?')
15
+ lines.push([entry.shortcut, `${entry.title}${entry.available ? '' : ' (not available yet)'}`]);
16
+ }
17
+ lines.push(['?', 'Show this help'], ['Ctrl+C', 'Quit from anywhere'], ['Esc or q', 'Leave a screen']);
18
+ return lines;
19
+ }
20
+ return {
21
+ id: 'help',
22
+ shortcut: '?',
23
+ title: 'Help',
24
+ handleKey: key => navigation.handleKey(key, Math.max(1, host.size().rows - 3)),
25
+ render(size) {
26
+ const style = defaultStyle();
27
+ navigation.setItems(rows());
28
+ const { items } = navigation.window(size.rows - 2);
29
+ return renderViewFrame({ title: 'Histoire help', body: items.map(([key, description]) => `${style.key(key)}${' '.repeat(Math.max(2, KEY_WIDTH - key.length))}${description}`), style, footer: 'Up/Down scroll · Esc back', ...size });
30
+ },
31
+ };
32
+ };
@@ -0,0 +1,6 @@
1
+ import type { TerminalViewFactory } from './registry.js';
2
+ /**
3
+ * The only shared list of views: later slices add one import and one entry each.
4
+ * Order is registration order (help text order for views).
5
+ */
6
+ export declare const viewFactories: readonly TerminalViewFactory[];
@@ -0,0 +1,13 @@
1
+ import { createClearHistoryView } from './clear-history.js';
2
+ import { createErrorView } from './error.js';
3
+ import { createHelpView } from './help.js';
4
+ import { createLogsView } from './logs.js';
5
+ import { createRequestsView } from './requests.js';
6
+ import { createSessionView } from './session.js';
7
+ import { createStoriesView } from './stories.js';
8
+ import { createTestsView } from './tests.js';
9
+ /**
10
+ * The only shared list of views: later slices add one import and one entry each.
11
+ * Order is registration order (help text order for views).
12
+ */
13
+ export const viewFactories = [createHelpView, createSessionView, createLogsView, createErrorView, createRequestsView, createStoriesView, createTestsView, createClearHistoryView];
@@ -0,0 +1,3 @@
1
+ import type { TerminalViewFactory } from './registry.js';
2
+ /** `l`: every retained log entry, newest followed, searchable, with detail and copy. */
3
+ export declare const createLogsView: TerminalViewFactory;
@@ -0,0 +1,7 @@
1
+ import { logBrowserOptions } from '../logs/browser-options.js';
2
+ import { createHistoryBrowser } from '../navigation/browser.js';
3
+ /** `l`: every retained log entry, newest followed, searchable, with detail and copy. */
4
+ export const createLogsView = (host) => {
5
+ const browser = createHistoryBrowser({ ...logBrowserOptions(host), title: 'Logs', noun: 'log entries', empty: 'No log entries' });
6
+ return { id: 'logs', shortcut: 'l', title: 'Logs', ...browser };
7
+ };
@@ -0,0 +1,114 @@
1
+ import type { TerminalBridge } from '../bridge.js';
2
+ import type { ClipboardWriter } from '../clipboard.js';
3
+ import type { TerminalKey } from '../keys.js';
4
+ import type { LogHistory } from '../output/history.js';
5
+ import type { ProgressState } from '../progress/state.js';
6
+ import type { RequestHistory } from '../requests/history.js';
7
+ import type { RetainedHistories } from '../retained.js';
8
+ import type { TestsConsole } from '../tests/console.js';
9
+ /** Screen size handed to renderers. */
10
+ export interface ViewSize {
11
+ columns: number;
12
+ rows: number;
13
+ }
14
+ /** A titled block of plain text lines contributed to the session info screen (diagnostics, counts). */
15
+ export interface InfoSection {
16
+ title: string;
17
+ lines: string[];
18
+ }
19
+ /** Everything a view may use; views never import each other or reach into the session. */
20
+ export interface TerminalViewHost {
21
+ /** Generic command/event bridge to the current runtime generation. Typed wrappers live beside each view's state module. */
22
+ bridge: TerminalBridge;
23
+ /** Session log history. */
24
+ logs: LogHistory;
25
+ /** Session history of public HTTP exchanges. */
26
+ requests: RequestHistory;
27
+ /** Startup progress and restart causes. */
28
+ progress: ProgressState;
29
+ /** Public workbench URL when known. */
30
+ url: () => string | undefined;
31
+ /** Current terminal size. */
32
+ size: () => ViewSize;
33
+ /** One transient feedback line (shown in the main panel after leaving a view, or in the view footer). */
34
+ notify: (text: string) => void;
35
+ /** Repaints the active view; call after state changed. No-op when the view is not shown. */
36
+ requestRender: () => void;
37
+ /** Returns to the main screen. */
38
+ close: () => void;
39
+ /** Leaves the current screen and opens the view registered for a main-screen shortcut; ignored when none is registered. */
40
+ openView: (shortcut: string) => void;
41
+ /** Manual test scope, runs, stop and results shared with the main panel and plain commands. */
42
+ tests: TestsConsole;
43
+ /** System clipboard. */
44
+ copy: ClipboardWriter;
45
+ /** Opens a workbench URL path (resolved against the public address) in the browser. */
46
+ openBrowser: (path?: string) => Promise<void>;
47
+ /** Every contracted shortcut with its title and whether a view is registered for it. */
48
+ shortcuts: () => {
49
+ shortcut: string;
50
+ title: string;
51
+ available: boolean;
52
+ }[];
53
+ /** Deletable histories (`x`). Views owning a bounded history register it here so deletion reaches it. */
54
+ retained: RetainedHistories;
55
+ /** Base URLs other machines can reach, derived from the configured binding; empty for a loopback-only listener. */
56
+ networkUrls: () => string[];
57
+ /** Adds a titled block to the session info screen; the provider is called on every render and may return undefined. Returns a remover. */
58
+ addInfoSection: (provider: () => InfoSection | undefined) => () => void;
59
+ /** Current info sections, in registration order (read by the session info screen). */
60
+ infoSections: () => InfoSection[];
61
+ /** Adds a short text segment to the main panel (counts, test activity). Returns a remover. */
62
+ addPanelSegment: (provider: () => string | undefined) => () => void;
63
+ }
64
+ /**
65
+ * A main-screen shortcut target. A view either owns a full screen (`render` + `handleKey`)
66
+ * or is an instant action (`run`), e.g. clearing retained history.
67
+ */
68
+ export interface TerminalView {
69
+ /** Stable unique identifier. */
70
+ id: string;
71
+ /** Single printable character that opens the view from the main screen. */
72
+ shortcut: string;
73
+ /** Title shown in the screen header and help. */
74
+ title: string;
75
+ /** Instant action; when present the view never takes over the screen. */
76
+ run?: () => void;
77
+ /** Called when the screen opens. */
78
+ enter?: () => void;
79
+ /** Called when the screen closes. */
80
+ leave?: () => void;
81
+ /** True while a text prompt (search) needs every key; main keys, `q` and Escape are then not interpreted by the session. */
82
+ capturesInput?: () => boolean;
83
+ /** Handles a key; return true when consumed. Unconsumed `Escape` and `q` return to main. */
84
+ handleKey?: (key: TerminalKey) => boolean;
85
+ /** Full-screen lines (at most `rows`); the session fits them to the width. */
86
+ render?: (size: ViewSize) => string[];
87
+ }
88
+ /** Creates a view bound to the session host. Listed once in `views/index.ts`. */
89
+ export type TerminalViewFactory = (host: TerminalViewHost) => TerminalView;
90
+ /** Frozen main-screen shortcut table of the contract: shortcut and the label shown while unavailable. */
91
+ export declare const PLANNED_VIEWS: Readonly<Record<string, string>>;
92
+ /** Registered views keyed by shortcut. */
93
+ export interface ViewRegistry {
94
+ /** Adds a view; throws on duplicate id or shortcut, or a shortcut outside the contract table. */
95
+ register: (view: TerminalView) => void;
96
+ /** View opened by a main-screen character. */
97
+ byShortcut: (char: string) => TerminalView | undefined;
98
+ /** Label of a contracted view that is not registered yet. */
99
+ unavailableLabel: (char: string) => string | undefined;
100
+ /** Registered views in registration order. */
101
+ list: () => readonly TerminalView[];
102
+ /** Every contracted shortcut with its title and availability. */
103
+ summary: () => {
104
+ shortcut: string;
105
+ title: string;
106
+ available: boolean;
107
+ }[];
108
+ }
109
+ /**
110
+ * Creates the registry and instantiates the factories.
111
+ * @param host Host handed to every factory.
112
+ * @param factories View factories, normally the list in `views/index.ts`.
113
+ */
114
+ export declare function createViewRegistry(host: TerminalViewHost, factories: readonly TerminalViewFactory[]): ViewRegistry;
@@ -0,0 +1,40 @@
1
+ import { RESERVED_SHORTCUTS } from '../actions.js';
2
+ /** Frozen main-screen shortcut table of the contract: shortcut and the label shown while unavailable. */
3
+ export const PLANNED_VIEWS = {
4
+ 'i': 'Session info',
5
+ 'l': 'Logs',
6
+ 'e': 'Latest error',
7
+ 'n': 'Requests',
8
+ 'p': 'Stories',
9
+ 't': 'Tests',
10
+ 'x': 'Clear history',
11
+ '?': 'Help',
12
+ };
13
+ /**
14
+ * Creates the registry and instantiates the factories.
15
+ * @param host Host handed to every factory.
16
+ * @param factories View factories, normally the list in `views/index.ts`.
17
+ */
18
+ export function createViewRegistry(host, factories) {
19
+ const views = new Map();
20
+ const register = (view) => {
21
+ if (RESERVED_SHORTCUTS.includes(view.shortcut))
22
+ throw new Error(`Shortcut "${view.shortcut}" is reserved by a main action`);
23
+ if (!(view.shortcut in PLANNED_VIEWS))
24
+ throw new Error(`Shortcut "${view.shortcut}" is not part of the main key table`);
25
+ if (!view.run && !(view.render && view.handleKey))
26
+ throw new Error(`View "${view.id}" needs run, or render and handleKey`);
27
+ if (views.has(view.shortcut) || [...views.values()].some(other => other.id === view.id))
28
+ throw new Error(`Duplicate view "${view.id}" or shortcut "${view.shortcut}"`);
29
+ views.set(view.shortcut, view);
30
+ };
31
+ for (const factory of factories)
32
+ register(factory(host));
33
+ return {
34
+ register,
35
+ byShortcut: char => views.get(char),
36
+ unavailableLabel: char => views.has(char) ? undefined : PLANNED_VIEWS[char],
37
+ list: () => [...views.values()],
38
+ summary: () => Object.entries(PLANNED_VIEWS).map(([shortcut, title]) => ({ shortcut, title: views.get(shortcut)?.title ?? title, available: views.has(shortcut) })),
39
+ };
40
+ }
@@ -0,0 +1,8 @@
1
+ import type { TerminalViewFactory } from './registry.js';
2
+ /**
3
+ * `n`: public HTTP requests (method, pathname, status, outcome, duration), newest followed,
4
+ * searchable, with detail and copy. Also registers the history with `x` and contributes the
5
+ * runtime diagnostics block to the session screen and panel (the view is the domain's
6
+ * session-lifetime entry point).
7
+ */
8
+ export declare const createRequestsView: TerminalViewFactory;
@@ -0,0 +1,15 @@
1
+ import { attachDiagnostics } from '../diagnostics/attach.js';
2
+ import { createHistoryBrowser } from '../navigation/browser.js';
3
+ import { requestBrowserOptions } from '../requests/browser-options.js';
4
+ /**
5
+ * `n`: public HTTP requests (method, pathname, status, outcome, duration), newest followed,
6
+ * searchable, with detail and copy. Also registers the history with `x` and contributes the
7
+ * runtime diagnostics block to the session screen and panel (the view is the domain's
8
+ * session-lifetime entry point).
9
+ */
10
+ export const createRequestsView = (host) => {
11
+ host.retained.register({ id: 'requests', label: 'requests', count: () => host.requests.entries().length, clear: () => host.requests.clear() });
12
+ attachDiagnostics(host);
13
+ const browser = createHistoryBrowser({ ...requestBrowserOptions(host), title: 'Requests', noun: 'requests', empty: 'No requests yet' });
14
+ return { id: 'requests', shortcut: 'n', title: 'Requests', ...browser };
15
+ };
@@ -0,0 +1,9 @@
1
+ import type { TerminalViewFactory } from './registry.js';
2
+ /**
3
+ * `i`: versions, project, actual bound addresses, uptime, phase durations, restart reason and
4
+ * collection/MCP summary. Runtime facts come from `session.get` of the current generation;
5
+ * addresses and lifecycle come from live parent state. Other slices add blocks with
6
+ * `host.addInfoSection`. Up/Down select an address, `y` copies it, `o` opens it, `r` toggles
7
+ * its QR code.
8
+ */
9
+ export declare const createSessionView: TerminalViewFactory;
@@ -0,0 +1,133 @@
1
+ import { createSessionInfoClient } from '../info/client.js';
2
+ import { buildSessionLines } from '../info/lines.js';
3
+ import { renderQrRows } from '../info/qr.js';
4
+ import { createListNavigation } from '../navigation/list.js';
5
+ import { displayWidth } from '../width.js';
6
+ import { renderViewFrame } from './frame.js';
7
+ /**
8
+ * `i`: versions, project, actual bound addresses, uptime, phase durations, restart reason and
9
+ * collection/MCP summary. Runtime facts come from `session.get` of the current generation;
10
+ * addresses and lifecycle come from live parent state. Other slices add blocks with
11
+ * `host.addInfoSection`. Up/Down select an address, `y` copies it, `o` opens it, `r` toggles
12
+ * its QR code.
13
+ */
14
+ export const createSessionView = (host) => {
15
+ const client = createSessionInfoClient(host.bridge, host.progress, () => host.requestRender());
16
+ const navigation = createListNavigation({ id: row => row.id });
17
+ const startedAt = Date.now();
18
+ let unsubscribe;
19
+ let lastGeneration;
20
+ /** Rendered QR rows per address: a pending render, its rows, or why it failed. */
21
+ const qrCodes = new Map();
22
+ let qrShown = false;
23
+ /** Local address first, then every reachable network address with the workbench path. */
24
+ function urlRows() {
25
+ const local = host.url();
26
+ if (!local)
27
+ return [];
28
+ const path = new URL(local).pathname;
29
+ // An explicit `--host <ip>` makes the local address equal to the network one: list it once.
30
+ const network = host.networkUrls().map(base => new URL(path, base).href).filter(url => url !== local);
31
+ return [{ id: 'local', url: local, label: 'Local' }, ...network.map((url, index) => ({ id: `network:${index}`, url, label: 'Network' }))];
32
+ }
33
+ /** QR rows for an address once rendered; the first request starts the render and repaints when done. */
34
+ function qrFor(url) {
35
+ const cached = qrCodes.get(url);
36
+ if (cached === undefined) {
37
+ const pending = renderQrRows(url).then(rows => void qrCodes.set(url, rows), error => void qrCodes.set(url, error instanceof Error ? error : new Error(String(error)))).finally(() => host.requestRender());
38
+ qrCodes.set(url, pending);
39
+ return undefined;
40
+ }
41
+ return cached instanceof Promise ? undefined : cached;
42
+ }
43
+ /**
44
+ * QR block for the selected address. A code that does not fit is replaced by a notice:
45
+ * a clipped code cannot be scanned.
46
+ * @param url Selected address.
47
+ * @param room Body rows and columns left below the address list.
48
+ * @param room.rows Free body rows.
49
+ * @param room.columns Screen width.
50
+ */
51
+ function qrLines(url, room) {
52
+ if (!qrShown || !url)
53
+ return [];
54
+ const code = qrFor(url);
55
+ if (!code)
56
+ return [];
57
+ if (code instanceof Error)
58
+ return ['', ` QR code unavailable: ${code.message}`];
59
+ // Body rows carry a one-column indent on top of the block's own two.
60
+ if (code.length + 1 > room.rows || displayWidth(code[0] ?? '') + 3 > room.columns)
61
+ return ['', ' Terminal too small for the QR code'];
62
+ return ['', ...code.map(row => ` ${row}`)];
63
+ }
64
+ /** Refreshes runtime facts when the generation or its readiness changed. */
65
+ function onProgress() {
66
+ const { generation, status } = host.progress.snapshot();
67
+ const key = `${generation}:${status}`;
68
+ if (key !== lastGeneration) {
69
+ lastGeneration = key;
70
+ void client.refresh();
71
+ }
72
+ host.requestRender();
73
+ }
74
+ return {
75
+ id: 'session',
76
+ shortcut: 'i',
77
+ title: 'Session info',
78
+ enter() {
79
+ lastGeneration = undefined;
80
+ unsubscribe = host.progress.subscribe(onProgress);
81
+ onProgress();
82
+ },
83
+ leave() {
84
+ unsubscribe?.();
85
+ unsubscribe = undefined;
86
+ },
87
+ handleKey(key) {
88
+ const rows = urlRows();
89
+ navigation.setItems(rows);
90
+ if (navigation.handleKey(key, 1))
91
+ return true;
92
+ const selected = navigation.selectedItem();
93
+ if (key.char === 'y' && selected) {
94
+ void host.copy(selected.url).then(result => host.notify(result.ok ? `Copied ${selected.label.toLowerCase()} address${result.note ? ` (${result.note})` : ''}` : `Copy unavailable: ${result.reason}. Address is still shown`));
95
+ }
96
+ else if (key.char === 'o' && selected) {
97
+ host.notify('Opening workbench');
98
+ void host.openBrowser(selected.url).catch(error => host.notify(`Failed: ${error instanceof Error ? error.message : String(error)}`));
99
+ }
100
+ else if (key.char === 'r') {
101
+ qrShown = !qrShown;
102
+ if (qrShown && selected)
103
+ qrFor(selected.url);
104
+ }
105
+ else if (key.char === 'u') {
106
+ void client.refresh();
107
+ }
108
+ else {
109
+ return false;
110
+ }
111
+ return true;
112
+ },
113
+ render(size) {
114
+ const rows = urlRows();
115
+ navigation.setItems(rows);
116
+ const { info, problem } = client.current();
117
+ const selectedId = navigation.selectedId();
118
+ const addresses = rows.length
119
+ ? rows.map(row => `${row.id === selectedId ? '›' : ' '} ${row.label.padEnd(9)} ${row.url}`)
120
+ : [' Address not known yet'];
121
+ if (!host.networkUrls().length)
122
+ addresses.push(' Network none available');
123
+ const lines = [
124
+ ...addresses,
125
+ ...qrLines(navigation.selectedItem()?.url, { rows: size.rows - 2 - addresses.length, columns: size.columns }),
126
+ '',
127
+ ...buildSessionLines({ snapshot: host.progress.snapshot(), info, infoProblem: problem, uptimeMs: Date.now() - startedAt }),
128
+ ...host.infoSections().flatMap(section => ['', `\u001B[1m${section.title}\u001B[22m`, ...section.lines.map(line => ` ${line}`)]),
129
+ ];
130
+ return renderViewFrame({ title: 'Session info', body: lines.map(line => ` ${line}`), footer: 'Up/Down address · y copy · o open · r QR code · u refresh · Esc back', ...size });
131
+ },
132
+ };
133
+ };
@@ -0,0 +1,9 @@
1
+ import type { TerminalViewFactory } from './registry.js';
2
+ /**
3
+ * `p`: browse the canonical catalog. Enter on a story lists its variants, Enter on a variant
4
+ * (or on a story without variants) opens it in the workbench; `o` opens the selection, `y`
5
+ * copies its address, `t` opens the tests screen on the exact target, `/` searches the whole
6
+ * catalog. Selection is kept by ID through revisions and restarts; a target the catalog no
7
+ * longer confirms is not actionable.
8
+ */
9
+ export declare const createStoriesView: TerminalViewFactory;