stitchkit-tui 0.3.0 → 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 +61 -16
- package/dist/{app-mqzzrp1t.js → app-2zw4ra7n.js} +36 -16
- 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 +1 -1
- package/dist/config.d.ts +8 -0
- package/dist/config.d.ts.map +1 -1
- package/dist/core/index.js +27 -25
- package/dist/core/labels.d.ts +4 -0
- package/dist/core/labels.d.ts.map +1 -1
- package/dist/core/table.d.ts +18 -1
- package/dist/core/table.d.ts.map +1 -1
- package/dist/gallery/main.js +1 -1
- package/dist/gallery/monitor-page.d.ts.map +1 -1
- package/dist/{index-kz62sdr9.js → index-1qacnvfd.js} +1 -1
- package/dist/index-51qwgt9f.js +172 -0
- package/dist/index-ahfc59de.js +495 -0
- package/dist/{index-z4c2ehg4.js → index-djrp2fey.js} +107 -583
- package/dist/index-m0dhvt6x.js +160 -0
- package/dist/{index-fxx9ktw7.js → index-p6nn7fsx.js} +35 -39
- package/dist/{index-251fexwh.js → index-qhj2ne64.js} +1 -1
- package/dist/{index-54sqbm3r.js → index-wcbe2tnk.js} +168 -285
- package/dist/index.js +7 -4
- package/dist/{run-e1kdpzna.js → run-zchyzhwy.js} +7 -4
- package/dist/run.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/widgets/app.d.ts +77 -0
- package/dist/widgets/app.d.ts.map +1 -0
- package/dist/widgets/form.d.ts.map +1 -1
- package/dist/widgets/index.d.ts +1 -0
- package/dist/widgets/index.d.ts.map +1 -1
- package/dist/widgets/index.js +20 -7
- package/dist/widgets/table.d.ts.map +1 -1
- package/dist/widgets/theme.d.ts +7 -1
- package/dist/widgets/theme.d.ts.map +1 -1
- package/package.json +12 -4
|
@@ -0,0 +1,160 @@
|
|
|
1
|
+
// @bun
|
|
2
|
+
import {
|
|
3
|
+
terminalPalettes2,
|
|
4
|
+
resolveTerminalPalette2,
|
|
5
|
+
terminalLabelsEn2
|
|
6
|
+
} from "./index-ahfc59de.js";
|
|
7
|
+
|
|
8
|
+
// src/widgets/context.tsx
|
|
9
|
+
import { createContext, useContext, useMemo } from "react";
|
|
10
|
+
import { jsx } from "@opentui/react/jsx-runtime";
|
|
11
|
+
var LabelsContext = createContext(terminalLabelsEn2);
|
|
12
|
+
function TerminalLabelsProvider2({
|
|
13
|
+
labels,
|
|
14
|
+
children
|
|
15
|
+
}) {
|
|
16
|
+
return /* @__PURE__ */ jsx(LabelsContext.Provider, {
|
|
17
|
+
value: labels,
|
|
18
|
+
children
|
|
19
|
+
});
|
|
20
|
+
}
|
|
21
|
+
function useTerminalLabels2() {
|
|
22
|
+
return useContext(LabelsContext);
|
|
23
|
+
}
|
|
24
|
+
var FocusContext = createContext(null);
|
|
25
|
+
function TerminalFocusProvider2({
|
|
26
|
+
state,
|
|
27
|
+
dispatch,
|
|
28
|
+
children
|
|
29
|
+
}) {
|
|
30
|
+
const value = useMemo(() => ({ state, dispatch }), [state, dispatch]);
|
|
31
|
+
return /* @__PURE__ */ jsx(FocusContext.Provider, {
|
|
32
|
+
value,
|
|
33
|
+
children
|
|
34
|
+
});
|
|
35
|
+
}
|
|
36
|
+
function useTerminalFocusContext2() {
|
|
37
|
+
return useContext(FocusContext);
|
|
38
|
+
}
|
|
39
|
+
function useTerminalFocused2(focusId, focused) {
|
|
40
|
+
const context = useContext(FocusContext);
|
|
41
|
+
if (focused !== undefined)
|
|
42
|
+
return focused;
|
|
43
|
+
if (focusId === undefined || context === null)
|
|
44
|
+
return true;
|
|
45
|
+
return context.state.focused === focusId;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
// src/widgets/keyboard.ts
|
|
49
|
+
import { useRenderer } from "@opentui/react";
|
|
50
|
+
import { useEffect, useRef } from "react";
|
|
51
|
+
var TerminalKeyPriority2 = Object.freeze({
|
|
52
|
+
input: 300,
|
|
53
|
+
layer: 200,
|
|
54
|
+
widget: 100,
|
|
55
|
+
global: 0
|
|
56
|
+
});
|
|
57
|
+
|
|
58
|
+
class KeyRouter {
|
|
59
|
+
registrations = new Set;
|
|
60
|
+
next = 0;
|
|
61
|
+
constructor(renderer) {
|
|
62
|
+
renderer.keyInput.on("keypress", (key) => this.route(key));
|
|
63
|
+
}
|
|
64
|
+
register(priority, handler) {
|
|
65
|
+
const registration = { order: this.next, priority, handler };
|
|
66
|
+
this.next += 1;
|
|
67
|
+
this.registrations.add(registration);
|
|
68
|
+
return registration;
|
|
69
|
+
}
|
|
70
|
+
unregister(registration) {
|
|
71
|
+
this.registrations.delete(registration);
|
|
72
|
+
}
|
|
73
|
+
route(key) {
|
|
74
|
+
if (key.propagationStopped)
|
|
75
|
+
return;
|
|
76
|
+
const ordered = [...this.registrations].sort((a, b) => b.priority - a.priority || a.order - b.order);
|
|
77
|
+
for (const registration of ordered) {
|
|
78
|
+
if (registration.handler(key)) {
|
|
79
|
+
key.preventDefault();
|
|
80
|
+
key.stopPropagation();
|
|
81
|
+
return;
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
var routers = new WeakMap;
|
|
87
|
+
function routerFor(renderer) {
|
|
88
|
+
const existing = routers.get(renderer);
|
|
89
|
+
if (existing)
|
|
90
|
+
return existing;
|
|
91
|
+
const created = new KeyRouter(renderer);
|
|
92
|
+
routers.set(renderer, created);
|
|
93
|
+
return created;
|
|
94
|
+
}
|
|
95
|
+
function useTerminalKeyboard2(handler, options = {}) {
|
|
96
|
+
const renderer = useRenderer();
|
|
97
|
+
const priority = options.priority ?? TerminalKeyPriority2.widget;
|
|
98
|
+
const active = options.active ?? true;
|
|
99
|
+
const latest = useRef(handler);
|
|
100
|
+
latest.current = handler;
|
|
101
|
+
const live = useRef(active);
|
|
102
|
+
live.current = active;
|
|
103
|
+
useEffect(() => {
|
|
104
|
+
const router = routerFor(renderer);
|
|
105
|
+
const entry = router.register(priority, (key) => live.current && latest.current(key));
|
|
106
|
+
return () => router.unregister(entry);
|
|
107
|
+
}, [renderer, priority]);
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
// src/widgets/theme.tsx
|
|
111
|
+
import { TextAttributes } from "@opentui/core";
|
|
112
|
+
import { useRenderer as useRenderer2 } from "@opentui/react";
|
|
113
|
+
import {
|
|
114
|
+
createContext as createContext2,
|
|
115
|
+
useContext as useContext2,
|
|
116
|
+
useEffect as useEffect2,
|
|
117
|
+
useMemo as useMemo2,
|
|
118
|
+
useState
|
|
119
|
+
} from "react";
|
|
120
|
+
import { jsx as jsx2 } from "@opentui/react/jsx-runtime";
|
|
121
|
+
function terminalToneAttributes2(tone) {
|
|
122
|
+
if (tone === "danger" || tone === "warning")
|
|
123
|
+
return TextAttributes.BOLD;
|
|
124
|
+
if (tone === "muted")
|
|
125
|
+
return TextAttributes.DIM;
|
|
126
|
+
return TextAttributes.NONE;
|
|
127
|
+
}
|
|
128
|
+
var PaletteContext = createContext2(terminalPalettes2.dark);
|
|
129
|
+
function useTerminalPalette2() {
|
|
130
|
+
return useContext2(PaletteContext);
|
|
131
|
+
}
|
|
132
|
+
function useTerminalThemeMode2(mode) {
|
|
133
|
+
const renderer = useRenderer2();
|
|
134
|
+
const [reported, setReported] = useState(renderer.themeMode);
|
|
135
|
+
useEffect2(() => {
|
|
136
|
+
if (mode !== "auto")
|
|
137
|
+
return;
|
|
138
|
+
const update = (next) => setReported(next);
|
|
139
|
+
renderer.on("theme_mode", update);
|
|
140
|
+
setReported(renderer.themeMode);
|
|
141
|
+
return () => {
|
|
142
|
+
renderer.off("theme_mode", update);
|
|
143
|
+
};
|
|
144
|
+
}, [mode, renderer]);
|
|
145
|
+
return mode === "auto" ? reported ?? "dark" : mode;
|
|
146
|
+
}
|
|
147
|
+
function TerminalThemeProvider2({
|
|
148
|
+
mode = "auto",
|
|
149
|
+
palette,
|
|
150
|
+
children
|
|
151
|
+
}) {
|
|
152
|
+
const resolved = useTerminalThemeMode2(mode);
|
|
153
|
+
const value = useMemo2(() => resolveTerminalPalette2(resolved, palette), [resolved, palette]);
|
|
154
|
+
return /* @__PURE__ */ jsx2(PaletteContext.Provider, {
|
|
155
|
+
value,
|
|
156
|
+
children
|
|
157
|
+
});
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
export { TerminalLabelsProvider2, useTerminalLabels2, TerminalFocusProvider2, useTerminalFocusContext2, useTerminalFocused2, TerminalKeyPriority2, useTerminalKeyboard2, terminalToneAttributes2, useTerminalPalette2, useTerminalThemeMode2, TerminalThemeProvider2 };
|
|
@@ -7,7 +7,7 @@ import {
|
|
|
7
7
|
moveTerminalCommandSelection2,
|
|
8
8
|
createTerminalFeedViewport2,
|
|
9
9
|
reduceTerminalFeedViewport2
|
|
10
|
-
} from "./index-
|
|
10
|
+
} from "./index-1qacnvfd.js";
|
|
11
11
|
import {
|
|
12
12
|
createAgentTuiSessionId2,
|
|
13
13
|
createAgentTuiConversationId2,
|
|
@@ -15,8 +15,11 @@ import {
|
|
|
15
15
|
startAgentTuiSessionHost2
|
|
16
16
|
} from "./index-ecpc5qkb.js";
|
|
17
17
|
import {
|
|
18
|
-
|
|
19
|
-
} from "./index-
|
|
18
|
+
useTerminalPalette2
|
|
19
|
+
} from "./index-m0dhvt6x.js";
|
|
20
|
+
import {
|
|
21
|
+
runTerminalApp2
|
|
22
|
+
} from "./index-51qwgt9f.js";
|
|
20
23
|
|
|
21
24
|
// src/commands.ts
|
|
22
25
|
import { z } from "zod";
|
|
@@ -537,8 +540,6 @@ function searchAgentTuiModels2(catalog, query) {
|
|
|
537
540
|
|
|
538
541
|
// src/run.tsx
|
|
539
542
|
import path4 from "path";
|
|
540
|
-
import { createCliRenderer } from "@opentui/core";
|
|
541
|
-
import { createRoot } from "@opentui/react";
|
|
542
543
|
|
|
543
544
|
// src/App.tsx
|
|
544
545
|
import { useKeyboard, useTerminalDimensions } from "@opentui/react";
|
|
@@ -1444,6 +1445,12 @@ function AgentTuiApp({
|
|
|
1444
1445
|
|
|
1445
1446
|
// src/run.tsx
|
|
1446
1447
|
import { jsx as jsx2 } from "@opentui/react/jsx-runtime";
|
|
1448
|
+
function ThemedAgentTuiApp(props) {
|
|
1449
|
+
return /* @__PURE__ */ jsx2(AgentTuiApp, {
|
|
1450
|
+
...props,
|
|
1451
|
+
theme: useTerminalPalette2()
|
|
1452
|
+
});
|
|
1453
|
+
}
|
|
1447
1454
|
function runtimeContext(config) {
|
|
1448
1455
|
return Promise.resolve(config.context());
|
|
1449
1456
|
}
|
|
@@ -1540,41 +1547,26 @@ async function runAgentTui2(config) {
|
|
|
1540
1547
|
conversationId: initialConversationId,
|
|
1541
1548
|
launchMode: config.initialConversationId === undefined ? "fresh" : "explicit"
|
|
1542
1549
|
});
|
|
1543
|
-
const
|
|
1544
|
-
|
|
1545
|
-
|
|
1546
|
-
|
|
1547
|
-
|
|
1548
|
-
|
|
1549
|
-
|
|
1550
|
-
|
|
1551
|
-
|
|
1552
|
-
|
|
1553
|
-
|
|
1554
|
-
|
|
1555
|
-
|
|
1556
|
-
|
|
1557
|
-
schemaVersion: 1,
|
|
1558
|
-
occurredAt: new Date().toISOString(),
|
|
1559
|
-
type: "host-closed",
|
|
1560
|
-
sessionId,
|
|
1561
|
-
conversationId: controller.state().conversationId
|
|
1562
|
-
});
|
|
1563
|
-
await host.close();
|
|
1564
|
-
await controller.close();
|
|
1565
|
-
} finally {
|
|
1566
|
-
await diagnostics.close();
|
|
1567
|
-
renderer.destroy();
|
|
1568
|
-
}
|
|
1569
|
-
})();
|
|
1570
|
-
return closing;
|
|
1550
|
+
const closeHost = async () => {
|
|
1551
|
+
try {
|
|
1552
|
+
diagnostics.record({
|
|
1553
|
+
schemaVersion: 1,
|
|
1554
|
+
occurredAt: new Date().toISOString(),
|
|
1555
|
+
type: "host-closed",
|
|
1556
|
+
sessionId,
|
|
1557
|
+
conversationId: controller.state().conversationId
|
|
1558
|
+
});
|
|
1559
|
+
await host.close();
|
|
1560
|
+
await controller.close();
|
|
1561
|
+
} finally {
|
|
1562
|
+
await diagnostics.close();
|
|
1563
|
+
}
|
|
1571
1564
|
};
|
|
1572
|
-
|
|
1565
|
+
const app = await runTerminalApp2(({ close }) => /* @__PURE__ */ jsx2(ThemedAgentTuiApp, {
|
|
1573
1566
|
controller,
|
|
1574
1567
|
catalog,
|
|
1575
1568
|
...bundle.conversations && { conversations: bundle.conversations },
|
|
1576
1569
|
...config.commands && { commands: config.commands },
|
|
1577
|
-
theme: resolveTerminalPalette2(themeMode, config.theme),
|
|
1578
1570
|
workspace,
|
|
1579
1571
|
...config.statusLine !== undefined && { statusLine: config.statusLine },
|
|
1580
1572
|
sessionId: host.sessionId,
|
|
@@ -1594,10 +1586,14 @@ async function runAgentTui2(config) {
|
|
|
1594
1586
|
});
|
|
1595
1587
|
},
|
|
1596
1588
|
onExit: close
|
|
1597
|
-
})
|
|
1598
|
-
|
|
1599
|
-
|
|
1600
|
-
|
|
1589
|
+
}), {
|
|
1590
|
+
themeMode: config.themeMode ?? "auto",
|
|
1591
|
+
...config.theme && { palette: config.theme },
|
|
1592
|
+
onClose: closeHost,
|
|
1593
|
+
...config.exitSignals && { exitSignals: config.exitSignals },
|
|
1594
|
+
closeTimeoutMs: config.closeTimeoutMs ?? 5000
|
|
1595
|
+
});
|
|
1596
|
+
return { sessionId: host.sessionId, close: app.close };
|
|
1601
1597
|
}
|
|
1602
1598
|
|
|
1603
1599
|
export { AgentTuiCommandOutcomeSchema2, defineTuiCommand2, composeTuiCommands2, resolveTuiCommand2, commandCompletions2, selectedCommandCompletion2, moveCommandCompletionSelection2, resolveTuiCommandSubmission2, AgentTuiComposerSchema2, createAgentTuiComposer2, setAgentTuiDraft2, submitAgentTuiComposer2, navigateAgentTuiHistory2, defineAgentTui2, createFileAgentModelSelectionStore2, createAgentTuiController2, AgentTuiDiagnosticEventSchema2, projectAgentTuiRuntimeDiagnostic2, createAgentTuiDiagnosticRecorder2, isAgentTuiExitKey2, AGENT_TUI_MODEL_RESULT_LIMIT2, searchAgentTuiModels2, defaultAgentTuiStatusLine2, projectAgentTuiTranscript2, defaultAgentTuiRecoveryDecision2, resolveAgentTuiInitialConversationId2, runAgentTui2 };
|