stitchkit-tui 0.2.14 → 0.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (109) hide show
  1. package/README.md +133 -4
  2. package/dist/App.d.ts +2 -2
  3. package/dist/App.d.ts.map +1 -1
  4. package/dist/app-2zw4ra7n.js +638 -0
  5. package/dist/build/index.d.ts +42 -0
  6. package/dist/build/index.d.ts.map +1 -0
  7. package/dist/build/index.js +174 -0
  8. package/dist/cli.js +11 -2195
  9. package/dist/config.d.ts +16 -16
  10. package/dist/config.d.ts.map +1 -1
  11. package/dist/core/chart.d.ts +82 -0
  12. package/dist/core/chart.d.ts.map +1 -0
  13. package/dist/core/collection.d.ts.map +1 -1
  14. package/dist/core/command-palette.d.ts.map +1 -1
  15. package/dist/core/focus.d.ts +33 -0
  16. package/dist/core/focus.d.ts.map +1 -0
  17. package/dist/core/form.d.ts +88 -0
  18. package/dist/core/form.d.ts.map +1 -0
  19. package/dist/core/index.d.ts +17 -0
  20. package/dist/core/index.d.ts.map +1 -1
  21. package/dist/core/index.js +228 -358
  22. package/dist/core/json.d.ts +24 -0
  23. package/dist/core/json.d.ts.map +1 -0
  24. package/dist/core/key-hints.d.ts +28 -0
  25. package/dist/core/key-hints.d.ts.map +1 -0
  26. package/dist/core/keys.d.ts +32 -0
  27. package/dist/core/keys.d.ts.map +1 -0
  28. package/dist/core/labels.d.ts +48 -0
  29. package/dist/core/labels.d.ts.map +1 -0
  30. package/dist/core/list.d.ts +112 -0
  31. package/dist/core/list.d.ts.map +1 -0
  32. package/dist/core/meter.d.ts +61 -0
  33. package/dist/core/meter.d.ts.map +1 -0
  34. package/dist/core/navigation.d.ts +33 -0
  35. package/dist/core/navigation.d.ts.map +1 -0
  36. package/dist/core/notices.d.ts +39 -0
  37. package/dist/core/notices.d.ts.map +1 -0
  38. package/dist/core/progress.d.ts +53 -0
  39. package/dist/core/progress.d.ts.map +1 -0
  40. package/dist/core/search.d.ts +36 -0
  41. package/dist/core/search.d.ts.map +1 -0
  42. package/dist/core/table.d.ts +143 -0
  43. package/dist/core/table.d.ts.map +1 -0
  44. package/dist/core/tabs.d.ts +37 -0
  45. package/dist/core/tabs.d.ts.map +1 -0
  46. package/dist/core/text.d.ts +36 -0
  47. package/dist/core/text.d.ts.map +1 -0
  48. package/dist/core/theme.d.ts +38 -0
  49. package/dist/core/theme.d.ts.map +1 -0
  50. package/dist/gallery/app.d.ts +12 -0
  51. package/dist/gallery/app.d.ts.map +1 -0
  52. package/dist/gallery/catalogue.d.ts +11 -0
  53. package/dist/gallery/catalogue.d.ts.map +1 -0
  54. package/dist/gallery/main.d.ts +3 -0
  55. package/dist/gallery/main.d.ts.map +1 -0
  56. package/dist/gallery/main.js +16 -0
  57. package/dist/gallery/monitor-page.d.ts +8 -0
  58. package/dist/gallery/monitor-page.d.ts.map +1 -0
  59. package/dist/gallery/widgets-page.d.ts +7 -0
  60. package/dist/gallery/widgets-page.d.ts.map +1 -0
  61. package/dist/index-1qacnvfd.js +336 -0
  62. package/dist/index-51qwgt9f.js +172 -0
  63. package/dist/index-ahfc59de.js +495 -0
  64. package/dist/index-djrp2fey.js +1229 -0
  65. package/dist/index-ecpc5qkb.js +245 -0
  66. package/dist/index-m0dhvt6x.js +160 -0
  67. package/dist/index-p6nn7fsx.js +1599 -0
  68. package/dist/index-qhj2ne64.js +106 -0
  69. package/dist/index-wcbe2tnk.js +1237 -0
  70. package/dist/index.js +80 -2219
  71. package/dist/run-zchyzhwy.js +18 -0
  72. package/dist/run.d.ts.map +1 -1
  73. package/dist/status-line.d.ts +2 -2
  74. package/dist/status-line.d.ts.map +1 -1
  75. package/dist/testing/index.d.ts +50 -0
  76. package/dist/testing/index.d.ts.map +1 -0
  77. package/dist/testing/index.js +110 -0
  78. package/dist/transcript.d.ts +2 -1
  79. package/dist/transcript.d.ts.map +1 -1
  80. package/dist/widgets/app.d.ts +77 -0
  81. package/dist/widgets/app.d.ts.map +1 -0
  82. package/dist/widgets/chart.d.ts +32 -0
  83. package/dist/widgets/chart.d.ts.map +1 -0
  84. package/dist/widgets/context.d.ts +29 -0
  85. package/dist/widgets/context.d.ts.map +1 -0
  86. package/dist/widgets/feedback.d.ts +65 -0
  87. package/dist/widgets/feedback.d.ts.map +1 -0
  88. package/dist/widgets/form.d.ts +23 -0
  89. package/dist/widgets/form.d.ts.map +1 -0
  90. package/dist/widgets/index.d.ts +14 -0
  91. package/dist/widgets/index.d.ts.map +1 -0
  92. package/dist/widgets/index.js +89 -0
  93. package/dist/widgets/keyboard.d.ts +28 -0
  94. package/dist/widgets/keyboard.d.ts.map +1 -0
  95. package/dist/widgets/layout.d.ts +51 -0
  96. package/dist/widgets/layout.d.ts.map +1 -0
  97. package/dist/widgets/list.d.ts +32 -0
  98. package/dist/widgets/list.d.ts.map +1 -0
  99. package/dist/widgets/meter.d.ts +26 -0
  100. package/dist/widgets/meter.d.ts.map +1 -0
  101. package/dist/widgets/table.d.ts +25 -0
  102. package/dist/widgets/table.d.ts.map +1 -0
  103. package/dist/widgets/tabs.d.ts +13 -0
  104. package/dist/widgets/tabs.d.ts.map +1 -0
  105. package/dist/widgets/text-view.d.ts +24 -0
  106. package/dist/widgets/text-view.d.ts.map +1 -0
  107. package/dist/widgets/theme.d.ts +23 -0
  108. package/dist/widgets/theme.d.ts.map +1 -0
  109. package/package.json +29 -8
package/README.md CHANGED
@@ -31,9 +31,136 @@ const panes = createTerminalPaneState({
31
31
  });
32
32
  ```
33
33
 
34
- `stitchkit-tui/core` imports no React, OpenTUI or agent-runtime code. It owns only identity-stable
35
- collections, feed viewport state, split panes, command selection and confirmed operations. Session
36
- cards, process supervision, restart policy and runtime adapters remain with the embedding product.
34
+ `stitchkit-tui/core` imports no React, OpenTUI or agent-runtime code. Session cards, process
35
+ supervision, restart policy and runtime adapters remain with the embedding product.
36
+
37
+ ## Building terminal applications
38
+
39
+ `stitchkit-tui/widgets` turns that state into finished screens — a CLI front-end, a monitor, a
40
+ dashboard, an agent console — on OpenTUI. See every widget live first:
41
+
42
+ ```bash
43
+ bunx stitchkit-tui-gallery
44
+ ```
45
+
46
+ F1–F3 switch between a method catalogue (sections, fuzzy search, a form generated from JSON Schema,
47
+ a confirmation, a spinner, a JSON result, toasts), a process monitor and the small widgets; Ctrl+T
48
+ cycles auto/dark/light and Ctrl+L switches English/Russian.
49
+
50
+ ```tsx
51
+ import { useTerminalDimensions } from '@opentui/react';
52
+ import { useReducer } from 'react';
53
+ import {
54
+ createTerminalList,
55
+ reduceTerminalList,
56
+ terminalLabelsRu,
57
+ } from 'stitchkit-tui/core';
58
+ import {
59
+ runTerminalApp,
60
+ TerminalAppShell,
61
+ TerminalList,
62
+ terminalListKeymap,
63
+ } from 'stitchkit-tui/widgets';
64
+
65
+ function Home() {
66
+ const { width, height } = useTerminalDimensions();
67
+ const [list, dispatch] = useReducer(reduceTerminalList, undefined, () =>
68
+ createTerminalList({
69
+ sections: [{ id: 'methods', title: 'Методы' }],
70
+ items: [
71
+ { key: 'search', title: 'Поиск по всем методам', description: 'Найти метод по имени и описанию' },
72
+ { key: 'docs_read', title: 'docs_read', section: 'methods', meta: 'content' },
73
+ ],
74
+ }),
75
+ );
76
+ return (
77
+ <TerminalAppShell
78
+ breadcrumbs={['Каталог', 'Главная']}
79
+ status={[[{ text: 'Каталог загружен' }, { text: '42 метода' }]]}
80
+ bindings={terminalListKeymap(terminalLabelsRu, { searchable: true })}
81
+ width={width}
82
+ height={height}
83
+ >
84
+ <TerminalList state={list} onAction={dispatch} searchable width={width} height={height - 4} />
85
+ </TerminalAppShell>
86
+ );
87
+ }
88
+
89
+ // The renderer, the theme and labels providers, an error boundary that shows the cause
90
+ // on screen, and an exit on Ctrl-C, a kill, a closed window (SIGHUP) or any other signal OpenTUI
91
+ // catches — so no orphan keeps drawing.
92
+ await runTerminalApp(<Home />, { labels: terminalLabelsRu });
93
+ ```
94
+
95
+ What the widgets promise:
96
+
97
+ - **State is yours.** Every widget renders a `create…`/`reduce…` state from `stitchkit-tui/core`
98
+ and reports actions; the application keeps it in `useReducer` or a store and can test it without a
99
+ terminal.
100
+ - **Keys are data.** A keymap answers keys and draws the footer, which shortens labels and drops the
101
+ least important hints to fit the width. Focus is a ring plus layers: a dialog takes the keyboard
102
+ and returns it.
103
+ - **Foreign text is sanitized.** Anything shown from data passes `sanitizeTerminalText`; JSON is
104
+ printed toned and escaped.
105
+ - **Live screens stay put.** Tables and lists draw only their window, rows are rewritten in place,
106
+ every line has a fixed position, and a time series is bounded by its window. A screen that
107
+ lives for hours runs React's production build (below), because the development build records a
108
+ measure for every render and Bun keeps them.
109
+ - **Words and colours have one source.** `TerminalLabels` (English and Russian bundled) and one
110
+ semantic `TerminalPalette` per terminal background, followed automatically in `auto` mode.
111
+
112
+ ### React's production build
113
+
114
+ Choose it when the code is **compiled**, never by setting `NODE_ENV` at run time. Bun compiles
115
+ JSX to `jsxDEV` when it does not find a `tsconfig.json` with `jsx` from the working directory — a
116
+ start from a monorepo root — and React's production runtime has no `jsxDEV`: the screen stays
117
+ blank. OpenTUI's own root error boundary is compiled the same way, so it cannot show that error
118
+ either; `runTerminalApp`'s boundary can.
119
+
120
+ - An executable: `compileTerminalApp` (below) defines `process.env.NODE_ENV` as `"production"`.
121
+ - From source: `bun --define process.env.NODE_ENV='"production"' src/main.tsx`, and put
122
+ `/** @jsxImportSource @opentui/react */` at the top of each screen file so its JSX does not
123
+ depend on which `tsconfig.json` Bun finds.
124
+
125
+ ### One executable for any platform
126
+
127
+ `bun build --compile --target=bun-linux-x64` on a Mac fails with `Could not resolve:
128
+ "@opentui/core-linux-x64"`: OpenTUI imports one native package per platform and a package manager
129
+ installs only the current machine's. `compileTerminalApp` adds the target's package — the version
130
+ the installed `@opentui/core` pins, downloaded from the registry and checked against the sha512 in
131
+ `bun.lock` — and replaces every other platform's with a module that throws. Musl targets are
132
+ refused: OpenTUI picks musl at run time from `OPENTUI_LIBC`.
133
+
134
+ ```ts
135
+ import { compileTerminalApp } from 'stitchkit-tui/build';
136
+
137
+ await compileTerminalApp({ entry: 'src/main.tsx', outfile: 'dist/app-linux-x64', target: 'bun-linux-x64' });
138
+ ```
139
+
140
+ `terminalNativePlugin({ target })` is the same step as a plugin for a `Bun.build` of your own.
141
+
142
+ ### Testing a screen
143
+
144
+ `renderTerminalTest` renders a screen inside the kit's providers on a test terminal and drives it
145
+ by real keys. Every step runs inside React's `act`, so the effects of the screen a key opened — its
146
+ keyboard subscription too — have run before the next key, and a lone Esc waits out the input
147
+ parser's escape timeout. A test has no `act` and no sleeps:
148
+
149
+ ```tsx
150
+ import { renderTerminalTest } from 'stitchkit-tui/testing';
151
+
152
+ const screen = await renderTerminalTest(<Catalogue />, { width: 100, height: 30 });
153
+ await screen.press('RETURN');
154
+ await screen.type('alpha');
155
+ expect(await screen.press('ESCAPE')).toContain('› docs_read');
156
+ await screen.close();
157
+ ```
158
+
159
+ Run tests under React's development build (the default of `bun test`): the production build has
160
+ no `act`.
161
+
162
+ React, `@opentui/core` and `@opentui/react` are peers: install them in the application, so one copy
163
+ of each drives the whole tree. `stitchkit` is needed only for the agent host below.
37
164
 
38
165
  Every normal launch starts a fresh durable conversation. Use `/resume` (or `/sessions`) to pick
39
166
  an earlier conversation, and `/clear` to leave the current one resumable while starting clean.
@@ -61,7 +188,9 @@ await runAgentTui(config);
61
188
  Omit `statusLine` for the default projection, provide a formatter to replace every row, or set it
62
189
  to `false` to hide the status line. The formatter receives the selected catalog entry, workspace,
63
190
  activity, local identities and the canonical durable snapshot; it does not receive guessed token
64
- counts. `theme` remains an independent semantic color override.
191
+ counts. `theme` overrides colours of the kit's `TerminalPalette`, and `themeMode` picks the dark or
192
+ light palette. The host starts through `runTerminalApp`: Ctrl-C, a kill and a closed window (SIGHUP) close
193
+ the session and exit the process; a host that owns its process passes `exitSignals: []`.
65
194
 
66
195
  The bundled CLI loads `stitchkit.agent.ts` by default:
67
196
 
package/dist/App.d.ts CHANGED
@@ -1,14 +1,14 @@
1
1
  import type { AgentConversationReader, AgentModelCatalog } from 'stitchkit/agent-runtime';
2
2
  import { type AgentTuiCommand } from './commands';
3
- import type { AgentTuiTheme } from './config';
4
3
  import type { AgentTuiController } from './controller';
4
+ import type { TerminalPalette } from './core/theme';
5
5
  import { type AgentTuiStatusLineFormatter } from './status-line';
6
6
  export declare function AgentTuiApp<CONTEXT>({ controller, catalog, conversations, commands: customCommands, theme, workspace, statusLine, sessionId, title, onConversationChange, onExit, }: {
7
7
  controller: AgentTuiController<CONTEXT>;
8
8
  catalog: AgentModelCatalog;
9
9
  conversations?: AgentConversationReader;
10
10
  commands?: readonly AgentTuiCommand[];
11
- theme: AgentTuiTheme;
11
+ theme: TerminalPalette;
12
12
  workspace: string;
13
13
  statusLine?: AgentTuiStatusLineFormatter | false;
14
14
  sessionId: string;
package/dist/App.d.ts.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"App.d.ts","sourceRoot":"","sources":["../src/App.tsx"],"names":[],"mappings":"AAGA,OAAO,KAAK,EACV,uBAAuB,EAEvB,iBAAiB,EAClB,MAAM,yBAAyB,CAAC;AAEjC,OAAO,EACL,KAAK,eAAe,EAKrB,MAAM,YAAY,CAAC;AAOpB,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,UAAU,CAAC;AAC9C,OAAO,KAAK,EAAE,kBAAkB,EAA2B,MAAM,cAAc,CAAC;AAKhF,OAAO,EACL,KAAK,2BAA2B,EAGjC,MAAM,eAAe,CAAC;AAkDvB,wBAAgB,WAAW,CAAC,OAAO,EAAE,EACnC,UAAU,EACV,OAAO,EACP,aAAa,EACb,QAAQ,EAAE,cAAmB,EAC7B,KAAK,EACL,SAAS,EACT,UAAU,EACV,SAAS,EACT,KAAK,EACL,oBAAoB,EACpB,MAAM,GACP,EAAE;IACD,UAAU,EAAE,kBAAkB,CAAC,OAAO,CAAC,CAAC;IACxC,OAAO,EAAE,iBAAiB,CAAC;IAC3B,aAAa,CAAC,EAAE,uBAAuB,CAAC;IACxC,QAAQ,CAAC,EAAE,SAAS,eAAe,E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