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.
- package/README.md +133 -4
- package/dist/App.d.ts +2 -2
- package/dist/App.d.ts.map +1 -1
- package/dist/app-2zw4ra7n.js +638 -0
- package/dist/build/index.d.ts +42 -0
- package/dist/build/index.d.ts.map +1 -0
- package/dist/build/index.js +174 -0
- package/dist/cli.js +11 -2195
- package/dist/config.d.ts +16 -16
- package/dist/config.d.ts.map +1 -1
- package/dist/core/chart.d.ts +82 -0
- package/dist/core/chart.d.ts.map +1 -0
- package/dist/core/collection.d.ts.map +1 -1
- package/dist/core/command-palette.d.ts.map +1 -1
- package/dist/core/focus.d.ts +33 -0
- package/dist/core/focus.d.ts.map +1 -0
- package/dist/core/form.d.ts +88 -0
- package/dist/core/form.d.ts.map +1 -0
- package/dist/core/index.d.ts +17 -0
- package/dist/core/index.d.ts.map +1 -1
- package/dist/core/index.js +228 -358
- package/dist/core/json.d.ts +24 -0
- package/dist/core/json.d.ts.map +1 -0
- package/dist/core/key-hints.d.ts +28 -0
- package/dist/core/key-hints.d.ts.map +1 -0
- package/dist/core/keys.d.ts +32 -0
- package/dist/core/keys.d.ts.map +1 -0
- package/dist/core/labels.d.ts +48 -0
- package/dist/core/labels.d.ts.map +1 -0
- package/dist/core/list.d.ts +112 -0
- package/dist/core/list.d.ts.map +1 -0
- package/dist/core/meter.d.ts +61 -0
- package/dist/core/meter.d.ts.map +1 -0
- package/dist/core/navigation.d.ts +33 -0
- package/dist/core/navigation.d.ts.map +1 -0
- package/dist/core/notices.d.ts +39 -0
- package/dist/core/notices.d.ts.map +1 -0
- package/dist/core/progress.d.ts +53 -0
- package/dist/core/progress.d.ts.map +1 -0
- package/dist/core/search.d.ts +36 -0
- package/dist/core/search.d.ts.map +1 -0
- package/dist/core/table.d.ts +143 -0
- package/dist/core/table.d.ts.map +1 -0
- package/dist/core/tabs.d.ts +37 -0
- package/dist/core/tabs.d.ts.map +1 -0
- package/dist/core/text.d.ts +36 -0
- package/dist/core/text.d.ts.map +1 -0
- package/dist/core/theme.d.ts +38 -0
- package/dist/core/theme.d.ts.map +1 -0
- package/dist/gallery/app.d.ts +12 -0
- package/dist/gallery/app.d.ts.map +1 -0
- package/dist/gallery/catalogue.d.ts +11 -0
- package/dist/gallery/catalogue.d.ts.map +1 -0
- package/dist/gallery/main.d.ts +3 -0
- package/dist/gallery/main.d.ts.map +1 -0
- package/dist/gallery/main.js +16 -0
- package/dist/gallery/monitor-page.d.ts +8 -0
- package/dist/gallery/monitor-page.d.ts.map +1 -0
- package/dist/gallery/widgets-page.d.ts +7 -0
- package/dist/gallery/widgets-page.d.ts.map +1 -0
- package/dist/index-1qacnvfd.js +336 -0
- package/dist/index-51qwgt9f.js +172 -0
- package/dist/index-ahfc59de.js +495 -0
- package/dist/index-djrp2fey.js +1229 -0
- package/dist/index-ecpc5qkb.js +245 -0
- package/dist/index-m0dhvt6x.js +160 -0
- package/dist/index-p6nn7fsx.js +1599 -0
- package/dist/index-qhj2ne64.js +106 -0
- package/dist/index-wcbe2tnk.js +1237 -0
- package/dist/index.js +80 -2219
- package/dist/run-zchyzhwy.js +18 -0
- package/dist/run.d.ts.map +1 -1
- package/dist/status-line.d.ts +2 -2
- package/dist/status-line.d.ts.map +1 -1
- package/dist/testing/index.d.ts +50 -0
- package/dist/testing/index.d.ts.map +1 -0
- package/dist/testing/index.js +110 -0
- package/dist/transcript.d.ts +2 -1
- package/dist/transcript.d.ts.map +1 -1
- package/dist/widgets/app.d.ts +77 -0
- package/dist/widgets/app.d.ts.map +1 -0
- package/dist/widgets/chart.d.ts +32 -0
- package/dist/widgets/chart.d.ts.map +1 -0
- package/dist/widgets/context.d.ts +29 -0
- package/dist/widgets/context.d.ts.map +1 -0
- package/dist/widgets/feedback.d.ts +65 -0
- package/dist/widgets/feedback.d.ts.map +1 -0
- package/dist/widgets/form.d.ts +23 -0
- package/dist/widgets/form.d.ts.map +1 -0
- package/dist/widgets/index.d.ts +14 -0
- package/dist/widgets/index.d.ts.map +1 -0
- package/dist/widgets/index.js +89 -0
- package/dist/widgets/keyboard.d.ts +28 -0
- package/dist/widgets/keyboard.d.ts.map +1 -0
- package/dist/widgets/layout.d.ts +51 -0
- package/dist/widgets/layout.d.ts.map +1 -0
- package/dist/widgets/list.d.ts +32 -0
- package/dist/widgets/list.d.ts.map +1 -0
- package/dist/widgets/meter.d.ts +26 -0
- package/dist/widgets/meter.d.ts.map +1 -0
- package/dist/widgets/table.d.ts +25 -0
- package/dist/widgets/table.d.ts.map +1 -0
- package/dist/widgets/tabs.d.ts +13 -0
- package/dist/widgets/tabs.d.ts.map +1 -0
- package/dist/widgets/text-view.d.ts +24 -0
- package/dist/widgets/text-view.d.ts.map +1 -0
- package/dist/widgets/theme.d.ts +23 -0
- package/dist/widgets/theme.d.ts.map +1 -0
- 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.
|
|
35
|
-
|
|
36
|
-
|
|
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`
|
|
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:
|
|
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,
|
|
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,kBAAkB,EAA2B,MAAM,cAAc,CAAC;AAEhF,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,cAAc,CAAC;AAIpD,OAAO,EAAE,KAAK,2BAA2B,EAA6B,MAAM,eAAe,CAAC;AAsC5F,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,EAAE,CAAC;IACtC,KAAK,EAAE,eAAe,CAAC;IACvB,SAAS,EAAE,MAAM,CAAC;IAClB,UAAU,CAAC,EAAE,2BAA2B,GAAG,KAAK,CAAC;IACjD,SAAS,EAAE,MAAM,CAAC;IAClB,KAAK,EAAE,MAAM,CAAC;IACd,oBAAoB,CAClB,cAAc,EAAE,MAAM,EACtB,MAAM,EAAE,KAAK,GAAG,OAAO,GAAG,QAAQ,GACjC,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IACxB,MAAM,IAAI,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;CAChC,6BAioBA"}
|