@lyellr88/buddy-mcp 1.1.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 +219 -0
- package/dist/config/claude-config.d.ts +7 -0
- package/dist/config/claude-config.d.ts.map +1 -0
- package/dist/config/claude-config.js +107 -0
- package/dist/config/claude-config.js.map +1 -0
- package/dist/config/hooks.d.ts +22 -0
- package/dist/config/hooks.d.ts.map +1 -0
- package/dist/config/hooks.js +58 -0
- package/dist/config/hooks.js.map +1 -0
- package/dist/config/index.d.ts +4 -0
- package/dist/config/index.d.ts.map +1 -0
- package/dist/config/index.js +6 -0
- package/dist/config/index.js.map +1 -0
- package/dist/config/pet-config.d.ts +12 -0
- package/dist/config/pet-config.d.ts.map +1 -0
- package/dist/config/pet-config.js +150 -0
- package/dist/config/pet-config.js.map +1 -0
- package/dist/constants.d.ts +24 -0
- package/dist/constants.d.ts.map +1 -0
- package/dist/constants.js +94 -0
- package/dist/constants.js.map +1 -0
- package/dist/finder/estimator.d.ts +3 -0
- package/dist/finder/estimator.d.ts.map +1 -0
- package/dist/finder/estimator.js +27 -0
- package/dist/finder/estimator.js.map +1 -0
- package/dist/finder/index.d.ts +3 -0
- package/dist/finder/index.d.ts.map +1 -0
- package/dist/finder/index.js +3 -0
- package/dist/finder/index.js.map +1 -0
- package/dist/finder/orchestrator.d.ts +8 -0
- package/dist/finder/orchestrator.d.ts.map +1 -0
- package/dist/finder/orchestrator.js +163 -0
- package/dist/finder/orchestrator.js.map +1 -0
- package/dist/finder/worker.d.ts +3 -0
- package/dist/finder/worker.d.ts.map +1 -0
- package/dist/finder/worker.js +130 -0
- package/dist/finder/worker.js.map +1 -0
- package/dist/generation/hash.d.ts +5 -0
- package/dist/generation/hash.d.ts.map +1 -0
- package/dist/generation/hash.js +37 -0
- package/dist/generation/hash.js.map +1 -0
- package/dist/generation/index.d.ts +4 -0
- package/dist/generation/index.d.ts.map +1 -0
- package/dist/generation/index.js +4 -0
- package/dist/generation/index.js.map +1 -0
- package/dist/generation/rng.d.ts +4 -0
- package/dist/generation/rng.d.ts.map +1 -0
- package/dist/generation/rng.js +14 -0
- package/dist/generation/rng.js.map +1 -0
- package/dist/generation/roll.d.ts +7 -0
- package/dist/generation/roll.d.ts.map +1 -0
- package/dist/generation/roll.js +51 -0
- package/dist/generation/roll.js.map +1 -0
- package/dist/mcp/index.d.ts +5 -0
- package/dist/mcp/index.d.ts.map +1 -0
- package/dist/mcp/index.js +273 -0
- package/dist/mcp/index.js.map +1 -0
- package/dist/mcp/persistence.d.ts +6 -0
- package/dist/mcp/persistence.d.ts.map +1 -0
- package/dist/mcp/persistence.js +129 -0
- package/dist/mcp/persistence.js.map +1 -0
- package/dist/mcp/state.d.ts +74 -0
- package/dist/mcp/state.d.ts.map +1 -0
- package/dist/mcp/state.js +20 -0
- package/dist/mcp/state.js.map +1 -0
- package/dist/mcp/tools/auto.d.ts +4 -0
- package/dist/mcp/tools/auto.d.ts.map +1 -0
- package/dist/mcp/tools/auto.js +15 -0
- package/dist/mcp/tools/auto.js.map +1 -0
- package/dist/mcp/tools/core.d.ts +2 -0
- package/dist/mcp/tools/core.d.ts.map +1 -0
- package/dist/mcp/tools/core.js +350 -0
- package/dist/mcp/tools/core.js.map +1 -0
- package/dist/mcp/tools/export.d.ts +2 -0
- package/dist/mcp/tools/export.d.ts.map +1 -0
- package/dist/mcp/tools/export.js +161 -0
- package/dist/mcp/tools/export.js.map +1 -0
- package/dist/mcp/tools/interact.d.ts +2 -0
- package/dist/mcp/tools/interact.d.ts.map +1 -0
- package/dist/mcp/tools/interact.js +56 -0
- package/dist/mcp/tools/interact.js.map +1 -0
- package/dist/mcp/tools/stats.d.ts +4 -0
- package/dist/mcp/tools/stats.d.ts.map +1 -0
- package/dist/mcp/tools/stats.js +87 -0
- package/dist/mcp/tools/stats.js.map +1 -0
- package/dist/mcp/watcher.d.ts +3 -0
- package/dist/mcp/watcher.d.ts.map +1 -0
- package/dist/mcp/watcher.js +117 -0
- package/dist/mcp/watcher.js.map +1 -0
- package/dist/patcher/binary-finder.d.ts +3 -0
- package/dist/patcher/binary-finder.d.ts.map +1 -0
- package/dist/patcher/binary-finder.js +169 -0
- package/dist/patcher/binary-finder.js.map +1 -0
- package/dist/patcher/index.d.ts +5 -0
- package/dist/patcher/index.d.ts.map +1 -0
- package/dist/patcher/index.js +5 -0
- package/dist/patcher/index.js.map +1 -0
- package/dist/patcher/patch.d.ts +5 -0
- package/dist/patcher/patch.d.ts.map +1 -0
- package/dist/patcher/patch.js +148 -0
- package/dist/patcher/patch.js.map +1 -0
- package/dist/patcher/preflight.d.ts +5 -0
- package/dist/patcher/preflight.d.ts.map +1 -0
- package/dist/patcher/preflight.js +145 -0
- package/dist/patcher/preflight.js.map +1 -0
- package/dist/patcher/salt-ops.d.ts +18 -0
- package/dist/patcher/salt-ops.d.ts.map +1 -0
- package/dist/patcher/salt-ops.js +93 -0
- package/dist/patcher/salt-ops.js.map +1 -0
- package/dist/personalities.d.ts +10 -0
- package/dist/personalities.d.ts.map +1 -0
- package/dist/personalities.js +295 -0
- package/dist/personalities.js.map +1 -0
- package/dist/presets.d.ts +11 -0
- package/dist/presets.d.ts.map +1 -0
- package/dist/presets.js +207 -0
- package/dist/presets.js.map +1 -0
- package/dist/sprites/data.d.ts +4 -0
- package/dist/sprites/data.d.ts.map +1 -0
- package/dist/sprites/data.js +103 -0
- package/dist/sprites/data.js.map +1 -0
- package/dist/sprites/index.d.ts +3 -0
- package/dist/sprites/index.d.ts.map +1 -0
- package/dist/sprites/index.js +3 -0
- package/dist/sprites/index.js.map +1 -0
- package/dist/sprites/render.d.ts +15 -0
- package/dist/sprites/render.d.ts.map +1 -0
- package/dist/sprites/render.js +77 -0
- package/dist/sprites/render.js.map +1 -0
- package/dist/tui/animator.d.ts +13 -0
- package/dist/tui/animator.d.ts.map +1 -0
- package/dist/tui/animator.js +39 -0
- package/dist/tui/animator.js.map +1 -0
- package/dist/tui/apply/index.d.ts +9 -0
- package/dist/tui/apply/index.d.ts.map +1 -0
- package/dist/tui/apply/index.js +553 -0
- package/dist/tui/apply/index.js.map +1 -0
- package/dist/tui/builder/colors.d.ts +15 -0
- package/dist/tui/builder/colors.d.ts.map +1 -0
- package/dist/tui/builder/colors.js +20 -0
- package/dist/tui/builder/colors.js.map +1 -0
- package/dist/tui/builder/index.d.ts +6 -0
- package/dist/tui/builder/index.d.ts.map +1 -0
- package/dist/tui/builder/index.js +172 -0
- package/dist/tui/builder/index.js.map +1 -0
- package/dist/tui/builder/keyboard.d.ts +17 -0
- package/dist/tui/builder/keyboard.d.ts.map +1 -0
- package/dist/tui/builder/keyboard.js +76 -0
- package/dist/tui/builder/keyboard.js.map +1 -0
- package/dist/tui/builder/preview-panel.d.ts +9 -0
- package/dist/tui/builder/preview-panel.d.ts.map +1 -0
- package/dist/tui/builder/preview-panel.js +103 -0
- package/dist/tui/builder/preview-panel.js.map +1 -0
- package/dist/tui/builder/selection-panel.d.ts +11 -0
- package/dist/tui/builder/selection-panel.d.ts.map +1 -0
- package/dist/tui/builder/selection-panel.js +446 -0
- package/dist/tui/builder/selection-panel.js.map +1 -0
- package/dist/tui/builder/stat-bars.d.ts +4 -0
- package/dist/tui/builder/stat-bars.d.ts.map +1 -0
- package/dist/tui/builder/stat-bars.js +46 -0
- package/dist/tui/builder/stat-bars.js.map +1 -0
- package/dist/tui/builder/state.d.ts +22 -0
- package/dist/tui/builder/state.d.ts.map +1 -0
- package/dist/tui/builder/state.js +92 -0
- package/dist/tui/builder/state.js.map +1 -0
- package/dist/tui/cli.d.ts +3 -0
- package/dist/tui/cli.d.ts.map +1 -0
- package/dist/tui/cli.js +26 -0
- package/dist/tui/cli.js.map +1 -0
- package/dist/tui/commands/buddies.d.ts +2 -0
- package/dist/tui/commands/buddies.d.ts.map +1 -0
- package/dist/tui/commands/buddies.js +172 -0
- package/dist/tui/commands/buddies.js.map +1 -0
- package/dist/tui/commands/current.d.ts +2 -0
- package/dist/tui/commands/current.d.ts.map +1 -0
- package/dist/tui/commands/current.js +35 -0
- package/dist/tui/commands/current.js.map +1 -0
- package/dist/tui/commands/interactive.d.ts +6 -0
- package/dist/tui/commands/interactive.d.ts.map +1 -0
- package/dist/tui/commands/interactive.js +385 -0
- package/dist/tui/commands/interactive.js.map +1 -0
- package/dist/tui/commands/preview.d.ts +3 -0
- package/dist/tui/commands/preview.d.ts.map +1 -0
- package/dist/tui/commands/preview.js +94 -0
- package/dist/tui/commands/preview.js.map +1 -0
- package/dist/tui/commands/rehatch.d.ts +2 -0
- package/dist/tui/commands/rehatch.d.ts.map +1 -0
- package/dist/tui/commands/rehatch.js +30 -0
- package/dist/tui/commands/rehatch.js.map +1 -0
- package/dist/tui/commands/restore.d.ts +2 -0
- package/dist/tui/commands/restore.d.ts.map +1 -0
- package/dist/tui/commands/restore.js +52 -0
- package/dist/tui/commands/restore.js.map +1 -0
- package/dist/tui/commands/share.d.ts +2 -0
- package/dist/tui/commands/share.d.ts.map +1 -0
- package/dist/tui/commands/share.js +105 -0
- package/dist/tui/commands/share.js.map +1 -0
- package/dist/tui/commands/start-screen.d.ts +3 -0
- package/dist/tui/commands/start-screen.d.ts.map +1 -0
- package/dist/tui/commands/start-screen.js +93 -0
- package/dist/tui/commands/start-screen.js.map +1 -0
- package/dist/tui/display.d.ts +5 -0
- package/dist/tui/display.d.ts.map +1 -0
- package/dist/tui/display.js +33 -0
- package/dist/tui/display.js.map +1 -0
- package/dist/tui/format.d.ts +5 -0
- package/dist/tui/format.d.ts.map +1 -0
- package/dist/tui/format.js +21 -0
- package/dist/tui/format.js.map +1 -0
- package/dist/tui/gallery/index.d.ts +12 -0
- package/dist/tui/gallery/index.d.ts.map +1 -0
- package/dist/tui/gallery/index.js +153 -0
- package/dist/tui/gallery/index.js.map +1 -0
- package/dist/tui/gallery/keyboard.d.ts +15 -0
- package/dist/tui/gallery/keyboard.d.ts.map +1 -0
- package/dist/tui/gallery/keyboard.js +41 -0
- package/dist/tui/gallery/keyboard.js.map +1 -0
- package/dist/tui/gallery/profile-list-panel.d.ts +10 -0
- package/dist/tui/gallery/profile-list-panel.d.ts.map +1 -0
- package/dist/tui/gallery/profile-list-panel.js +66 -0
- package/dist/tui/gallery/profile-list-panel.js.map +1 -0
- package/dist/tui/gallery/profile-preview-panel.d.ts +9 -0
- package/dist/tui/gallery/profile-preview-panel.d.ts.map +1 -0
- package/dist/tui/gallery/profile-preview-panel.js +121 -0
- package/dist/tui/gallery/profile-preview-panel.js.map +1 -0
- package/dist/tui/gallery/state.d.ts +13 -0
- package/dist/tui/gallery/state.d.ts.map +1 -0
- package/dist/tui/gallery/state.js +33 -0
- package/dist/tui/gallery/state.js.map +1 -0
- package/dist/tui/index.d.ts +9 -0
- package/dist/tui/index.d.ts.map +1 -0
- package/dist/tui/index.js +9 -0
- package/dist/tui/index.js.map +1 -0
- package/dist/tui/launcher.d.ts +3 -0
- package/dist/tui/launcher.d.ts.map +1 -0
- package/dist/tui/launcher.js +24 -0
- package/dist/tui/launcher.js.map +1 -0
- package/dist/tui/presets/index.d.ts +3 -0
- package/dist/tui/presets/index.d.ts.map +1 -0
- package/dist/tui/presets/index.js +202 -0
- package/dist/tui/presets/index.js.map +1 -0
- package/dist/tui/presets/preset-list-panel.d.ts +9 -0
- package/dist/tui/presets/preset-list-panel.d.ts.map +1 -0
- package/dist/tui/presets/preset-list-panel.js +52 -0
- package/dist/tui/presets/preset-list-panel.js.map +1 -0
- package/dist/tui/prompts.d.ts +13 -0
- package/dist/tui/prompts.d.ts.map +1 -0
- package/dist/tui/prompts.js +126 -0
- package/dist/tui/prompts.js.map +1 -0
- package/dist/tui/start/index.d.ts +3 -0
- package/dist/tui/start/index.d.ts.map +1 -0
- package/dist/tui/start/index.js +170 -0
- package/dist/tui/start/index.js.map +1 -0
- package/dist/types.d.ts +113 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +2 -0
- package/dist/types.js.map +1 -0
- package/package.json +82 -0
|
@@ -0,0 +1,172 @@
|
|
|
1
|
+
import { ISSUE_URL } from '../../constants.js';
|
|
2
|
+
import { createAnimator } from '../../tui/animator.js';
|
|
3
|
+
import { createInitialState, stateToDesiredTraits, firstUnfilledField, } from "./state.js";
|
|
4
|
+
const MIN_COLS = 70;
|
|
5
|
+
const MIN_ROWS = 18;
|
|
6
|
+
export async function canUseBuilder() {
|
|
7
|
+
// Must be a TTY
|
|
8
|
+
if (!process.stdout.isTTY || !process.stdin.isTTY)
|
|
9
|
+
return false;
|
|
10
|
+
// Respect accessibility / dumb terminal
|
|
11
|
+
if (process.env.TERM === 'dumb' || process.env.NO_COLOR !== undefined)
|
|
12
|
+
return false;
|
|
13
|
+
// Must be running under Bun (OpenTUI requires it)
|
|
14
|
+
if (typeof globalThis.Bun === 'undefined')
|
|
15
|
+
return false;
|
|
16
|
+
// Terminal must be large enough
|
|
17
|
+
const cols = process.stdout.columns ?? 0;
|
|
18
|
+
const rows = process.stdout.rows ?? 0;
|
|
19
|
+
if (cols < MIN_COLS || rows < MIN_ROWS)
|
|
20
|
+
return false;
|
|
21
|
+
// Try to load OpenTUI
|
|
22
|
+
try {
|
|
23
|
+
await import('@opentui/core');
|
|
24
|
+
return true;
|
|
25
|
+
}
|
|
26
|
+
catch {
|
|
27
|
+
return false;
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
export async function runBuilder(flags = {}, browseOnly = false) {
|
|
31
|
+
// Dynamic imports to avoid crashing on Node
|
|
32
|
+
const otui = await import('@opentui/core');
|
|
33
|
+
const { createCliRenderer, Box, Text } = otui;
|
|
34
|
+
const { createPreviewPanel } = await import("./preview-panel.js");
|
|
35
|
+
const { createSelectionPanel } = await import("./selection-panel.js");
|
|
36
|
+
const { setupKeyboard } = await import("./keyboard.js");
|
|
37
|
+
const { BORDER_COLOR, DIM_COLOR, FOCUS_BORDER } = await import("./colors.js");
|
|
38
|
+
const initialState = createInitialState(flags);
|
|
39
|
+
let renderer = null;
|
|
40
|
+
try {
|
|
41
|
+
renderer = await createCliRenderer({
|
|
42
|
+
exitOnCtrlC: false,
|
|
43
|
+
screenMode: 'alternate-screen',
|
|
44
|
+
});
|
|
45
|
+
const r = renderer;
|
|
46
|
+
return await new Promise((resolve) => {
|
|
47
|
+
let resolved = false;
|
|
48
|
+
const animator = createAnimator(500);
|
|
49
|
+
let unsubAnimation = null;
|
|
50
|
+
const handleCtrlC = (key) => {
|
|
51
|
+
if (key.ctrl && key.name === 'c') {
|
|
52
|
+
finish(null);
|
|
53
|
+
}
|
|
54
|
+
};
|
|
55
|
+
function finish(result) {
|
|
56
|
+
if (resolved)
|
|
57
|
+
return;
|
|
58
|
+
resolved = true;
|
|
59
|
+
unsubAnimation?.();
|
|
60
|
+
animator.stop();
|
|
61
|
+
r.keyInput.removeListener('keypress', handleCtrlC);
|
|
62
|
+
keyboard.destroy();
|
|
63
|
+
r.destroy();
|
|
64
|
+
renderer = null;
|
|
65
|
+
resolve(result);
|
|
66
|
+
}
|
|
67
|
+
// Root layout: column with main content row + pinned help bar
|
|
68
|
+
const title = browseOnly ? ' buddy-mcp preview ' : ' buddy-mcp ';
|
|
69
|
+
const rootBox = Box({
|
|
70
|
+
id: 'root',
|
|
71
|
+
flexDirection: 'column',
|
|
72
|
+
width: '100%',
|
|
73
|
+
height: '100%',
|
|
74
|
+
borderStyle: 'rounded',
|
|
75
|
+
border: true,
|
|
76
|
+
borderColor: BORDER_COLOR,
|
|
77
|
+
title,
|
|
78
|
+
titleAlignment: 'center',
|
|
79
|
+
padding: 0,
|
|
80
|
+
},
|
|
81
|
+
// Main content row (selection + preview)
|
|
82
|
+
Box({
|
|
83
|
+
id: 'main-row',
|
|
84
|
+
flexDirection: 'row',
|
|
85
|
+
flexGrow: 1,
|
|
86
|
+
width: '100%',
|
|
87
|
+
}),
|
|
88
|
+
// Pinned help bar at bottom -- always visible
|
|
89
|
+
Text({
|
|
90
|
+
id: 'help-bar',
|
|
91
|
+
content: ' \u2191\u2193 select Tab/Enter next Shift+Tab prev Esc cancel',
|
|
92
|
+
fg: DIM_COLOR,
|
|
93
|
+
height: 1,
|
|
94
|
+
flexShrink: 0,
|
|
95
|
+
paddingLeft: 1,
|
|
96
|
+
}));
|
|
97
|
+
r.root.add(rootBox);
|
|
98
|
+
const mainRow = r.root.findDescendantById('main-row');
|
|
99
|
+
const helpBar = r.root.findDescendantById('help-bar');
|
|
100
|
+
if (!mainRow) {
|
|
101
|
+
finish(null);
|
|
102
|
+
return;
|
|
103
|
+
}
|
|
104
|
+
// Selection panel (left) — added first so it's on the left
|
|
105
|
+
const selection = createSelectionPanel(mainRow, initialState, (state) => {
|
|
106
|
+
preview.update(state);
|
|
107
|
+
});
|
|
108
|
+
// Preview panel (right)
|
|
109
|
+
const preview = createPreviewPanel(mainRow);
|
|
110
|
+
// Initial preview render + start animation
|
|
111
|
+
preview.update(initialState);
|
|
112
|
+
unsubAnimation = animator.subscribe((frame) => preview.tick(frame));
|
|
113
|
+
const HELP_DEFAULT = ' \u2191\u2193 select Tab/Enter next Shift+Tab prev Esc cancel';
|
|
114
|
+
const HELP_CONFIRM = browseOnly
|
|
115
|
+
? ' Enter/Y exit Esc/N go back'
|
|
116
|
+
: ' Enter/Y confirm & apply Esc/N go back and edit';
|
|
117
|
+
// Keyboard navigation
|
|
118
|
+
const startField = firstUnfilledField(flags);
|
|
119
|
+
const keyboard = setupKeyboard(r.keyInput, {
|
|
120
|
+
getState: selection.getState,
|
|
121
|
+
focusField: selection.focusField,
|
|
122
|
+
onConfirm: () => {
|
|
123
|
+
if (browseOnly) {
|
|
124
|
+
finish(null);
|
|
125
|
+
}
|
|
126
|
+
else {
|
|
127
|
+
finish(stateToDesiredTraits(selection.getState()));
|
|
128
|
+
}
|
|
129
|
+
},
|
|
130
|
+
onCancel: () => {
|
|
131
|
+
finish(null);
|
|
132
|
+
},
|
|
133
|
+
onEnterConfirmMode: () => {
|
|
134
|
+
if (helpBar) {
|
|
135
|
+
helpBar.content = HELP_CONFIRM;
|
|
136
|
+
helpBar.fg = FOCUS_BORDER;
|
|
137
|
+
}
|
|
138
|
+
},
|
|
139
|
+
onExitConfirmMode: () => {
|
|
140
|
+
if (helpBar) {
|
|
141
|
+
helpBar.content = HELP_DEFAULT;
|
|
142
|
+
helpBar.fg = DIM_COLOR;
|
|
143
|
+
}
|
|
144
|
+
},
|
|
145
|
+
});
|
|
146
|
+
// Focus the first unfilled field
|
|
147
|
+
selection.focusField(startField);
|
|
148
|
+
// Handle Ctrl+C
|
|
149
|
+
r.keyInput.on('keypress', handleCtrlC);
|
|
150
|
+
// Start rendering
|
|
151
|
+
r.auto();
|
|
152
|
+
});
|
|
153
|
+
}
|
|
154
|
+
catch (err) {
|
|
155
|
+
// Clean up on error
|
|
156
|
+
if (renderer) {
|
|
157
|
+
try {
|
|
158
|
+
renderer.destroy();
|
|
159
|
+
}
|
|
160
|
+
catch {
|
|
161
|
+
// ignore cleanup errors
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
// Log the error and return null so the caller can fall back
|
|
165
|
+
console.error(` Builder error: ${err.message}`);
|
|
166
|
+
console.error(` If this persists, please report at: ${ISSUE_URL}`);
|
|
167
|
+
return null;
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
export { createInitialState, stateToDesiredTraits } from "./state.js";
|
|
171
|
+
export { canUseBuilder as canUseOpenTUI };
|
|
172
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/tui/builder/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC;AAC3C,OAAO,EAAE,cAAc,EAAE,MAAM,mBAAmB,CAAC;AACnD,OAAO,EACL,kBAAkB,EAClB,oBAAoB,EACpB,kBAAkB,GAEnB,MAAM,YAAY,CAAC;AAEpB,MAAM,QAAQ,GAAG,EAAE,CAAC;AACpB,MAAM,QAAQ,GAAG,EAAE,CAAC;AAEpB,MAAM,CAAC,KAAK,UAAU,aAAa;IACjC,g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AC;YAEjC,gBAAgB;YAChB,CAAC,CAAC,QAAQ,CAAC,EAAE,CAAC,UAAU,EAAE,WAAW,CAAC,CAAC;YAEvC,kBAAkB;YAClB,CAAC,CAAC,IAAI,EAAE,CAAC;QACX,CAAC,CAAC,CAAC;IACL,CAAC;IAAC,OAAO,GAAG,EAAE,CAAC;QACb,oBAAoB;QACpB,IAAI,QAAQ,EAAE,CAAC;YACb,IAAI,CAAC;gBACH,QAAQ,CAAC,OAAO,EAAE,CAAC;YACrB,CAAC;YAAC,MAAM,CAAC;gBACP,wBAAwB;YAC1B,CAAC;QACH,CAAC;QACD,4DAA4D;QAC5D,OAAO,CAAC,KAAK,CAAC,oBAAqB,GAAa,CAAC,OAAO,EAAE,CAAC,CAAC;QAC5D,OAAO,CAAC,KAAK,CAAC,yCAAyC,SAAS,EAAE,CAAC,CAAC;QACpE,OAAO,IAAI,CAAC;IACd,CAAC;AACH,CAAC;AAED,OAAO,EAAE,kBAAkB,EAAE,oBAAoB,EAAqB,MAAM,YAAY,CAAC;AACzF,OAAO,EAAE,aAAa,IAAI,aAAa,EAAE,CAAC"}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import type { KeyHandler } from '@opentui/core';
|
|
2
|
+
import { type BuilderField, type BuilderState } from './state.ts';
|
|
3
|
+
export interface KeyboardController {
|
|
4
|
+
currentField: () => BuilderField | undefined;
|
|
5
|
+
isConfirming: () => boolean;
|
|
6
|
+
destroy: () => void;
|
|
7
|
+
}
|
|
8
|
+
export interface KeyboardCallbacks {
|
|
9
|
+
getState: () => BuilderState;
|
|
10
|
+
focusField: (field: BuilderField) => void;
|
|
11
|
+
onConfirm: () => void;
|
|
12
|
+
onCancel: () => void;
|
|
13
|
+
onEnterConfirmMode: () => void;
|
|
14
|
+
onExitConfirmMode: () => void;
|
|
15
|
+
}
|
|
16
|
+
export declare function setupKeyboard(keyInput: KeyHandler, callbacks: KeyboardCallbacks): KeyboardController;
|
|
17
|
+
//# sourceMappingURL=keyboard.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"keyboard.d.ts","sourceRoot":"","sources":["../../../src/tui/builder/keyboard.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;AAChD,OAAO,EAAoB,KAAK,YAAY,EAAE,KAAK,YAAY,EAAE,MAAM,YAAY,CAAC;AAEpF,MAAM,WAAW,kBAAkB;IACjC,YAAY,EAAE,MAAM,YAAY,GAAG,SAAS,CAAC;IAC7C,YAAY,EAAE,MAAM,OAAO,CAAC;IAC5B,OAAO,EAAE,MAAM,IAAI,CAAC;CACrB;AAED,MAAM,WAAW,iBAAiB;IAChC,QAAQ,EAAE,MAAM,YAAY,CAAC;IAC7B,UAAU,EAAE,CAAC,KAAK,EAAE,YAAY,KAAK,IAAI,CAAC;IAC1C,SAAS,EAAE,MAAM,IAAI,CAAC;IACtB,QAAQ,EAAE,MAAM,IAAI,CAAC;IACrB,kBAAkB,EAAE,MAAM,IAAI,CAAC;IAC/B,iBAAiB,EAAE,MAAM,IAAI,CAAC;CAC/B;AAED,wBAAgB,aAAa,CAC3B,QAAQ,EAAE,UAAU,EACpB,SAAS,EAAE,iBAAiB,GAC3B,kBAAkB,CA2EpB"}
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
import { getVisibleFields } from "./state.js";
|
|
2
|
+
export function setupKeyboard(keyInput, callbacks) {
|
|
3
|
+
let currentFieldIndex = 0;
|
|
4
|
+
let confirmMode = false;
|
|
5
|
+
function getFields() {
|
|
6
|
+
return getVisibleFields(callbacks.getState());
|
|
7
|
+
}
|
|
8
|
+
function focusCurrent() {
|
|
9
|
+
const fields = getFields();
|
|
10
|
+
if (fields.length === 0)
|
|
11
|
+
return;
|
|
12
|
+
if (currentFieldIndex >= fields.length) {
|
|
13
|
+
currentFieldIndex = fields.length - 1;
|
|
14
|
+
}
|
|
15
|
+
if (currentFieldIndex < 0)
|
|
16
|
+
currentFieldIndex = 0;
|
|
17
|
+
callbacks.focusField(fields[currentFieldIndex]);
|
|
18
|
+
}
|
|
19
|
+
function enterConfirmMode() {
|
|
20
|
+
confirmMode = true;
|
|
21
|
+
callbacks.onEnterConfirmMode();
|
|
22
|
+
}
|
|
23
|
+
function exitConfirmMode() {
|
|
24
|
+
confirmMode = false;
|
|
25
|
+
callbacks.onExitConfirmMode();
|
|
26
|
+
focusCurrent();
|
|
27
|
+
}
|
|
28
|
+
function handleKeyPress(key) {
|
|
29
|
+
if (confirmMode) {
|
|
30
|
+
if (key.name === 'return' || key.name === 'y') {
|
|
31
|
+
callbacks.onConfirm();
|
|
32
|
+
}
|
|
33
|
+
else if (key.name === 'escape' || key.name === 'n') {
|
|
34
|
+
exitConfirmMode();
|
|
35
|
+
}
|
|
36
|
+
return;
|
|
37
|
+
}
|
|
38
|
+
const fields = getFields();
|
|
39
|
+
if (fields.length === 0)
|
|
40
|
+
return;
|
|
41
|
+
if (key.name === 'tab' && !key.shift) {
|
|
42
|
+
currentFieldIndex = (currentFieldIndex + 1) % fields.length;
|
|
43
|
+
focusCurrent();
|
|
44
|
+
}
|
|
45
|
+
else if (key.name === 'tab' && key.shift) {
|
|
46
|
+
currentFieldIndex = (currentFieldIndex - 1 + fields.length) % fields.length;
|
|
47
|
+
focusCurrent();
|
|
48
|
+
}
|
|
49
|
+
else if (key.name === 'return') {
|
|
50
|
+
if (currentFieldIndex < fields.length - 1) {
|
|
51
|
+
currentFieldIndex++;
|
|
52
|
+
focusCurrent();
|
|
53
|
+
}
|
|
54
|
+
else {
|
|
55
|
+
enterConfirmMode();
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
else if (key.name === 'escape') {
|
|
59
|
+
callbacks.onCancel();
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
keyInput.on('keypress', handleKeyPress);
|
|
63
|
+
// Focus the first field
|
|
64
|
+
focusCurrent();
|
|
65
|
+
return {
|
|
66
|
+
currentField: () => {
|
|
67
|
+
const fields = getFields();
|
|
68
|
+
return fields[currentFieldIndex];
|
|
69
|
+
},
|
|
70
|
+
isConfirming: () => confirmMode,
|
|
71
|
+
destroy: () => {
|
|
72
|
+
keyInput.removeListener('keypress', handleKeyPress);
|
|
73
|
+
},
|
|
74
|
+
};
|
|
75
|
+
}
|
|
76
|
+
//# sourceMappingURL=keyboard.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"keyboard.js","sourceRoot":"","sources":["../../../src/tui/builder/keyboard.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,gBAAgB,EAAwC,MAAM,YAAY,CAAC;AAiBpF,MAAM,UAAU,aAAa,CAC3B,QAAoB,EACpB,SAA4B;IAE5B,IAAI,iBAAiB,GAAG,CAAC,CAAC;IAC1B,IAAI,WAAW,GAAG,KAAK,CAAC;IAExB,SAAS,SAAS;QAChB,OAAO,gBAAgB,CAAC,SAAS,CAAC,QAAQ,EAAE,CAAC,CAAC;IAChD,CAAC;IAED,SAAS,YAAY;QACnB,MAAM,MAAM,GAAG,SAAS,EAAE,CAAC;QAC3B,IAAI,MAAM,CAAC,MAAM,KAAK,CAAC;YAAE,OAAO;QAChC,IAAI,iBAAiB,IAAI,MAAM,CAAC,MAAM,EAAE,CAAC;YACvC,iBAAiB,GAAG,MAAM,CAAC,MAAM,GAAG,CAAC,CAAC;QACxC,CAAC;QACD,IAAI,iBAAiB,GAAG,CAAC;YAAE,iBAAiB,GAAG,CAAC,CAAC;QACjD,SAAS,CAAC,UAAU,CAAC,MAAM,CAAC,iBAAiB,CAAC,CAAC,CAAC;IAClD,CAAC;IAED,SAAS,gBAAgB;QACvB,WAAW,GAAG,IAAI,CAAC;QACnB,SAAS,CAAC,kBAAkB,EAAE,CAAC;IACjC,CAAC;IAED,SAAS,eAAe;QACtB,WAAW,GAAG,KAAK,CAAC;QACpB,SAAS,CAAC,iBAAiB,EAAE,CAAC;QAC9B,YAAY,EAAE,CAAC;IACjB,CAAC;IAED,SAAS,cAAc,CAAC,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Q,CAAC,EAAE,CAAC,UAAU,EAAE,cAAc,CAAC,CAAC;IAExC,wBAAwB;IACxB,YAAY,EAAE,CAAC;IAEf,OAAO;QACL,YAAY,EAAE,GAAG,EAAE;YACjB,MAAM,MAAM,GAAG,SAAS,EAAE,CAAC;YAC3B,OAAO,MAAM,CAAC,iBAAiB,CAAC,CAAC;QACnC,CAAC;QACD,YAAY,EAAE,GAAG,EAAE,CAAC,WAAW;QAC/B,OAAO,EAAE,GAAG,EAAE;YACZ,QAAQ,CAAC,cAAc,CAAC,UAAU,EAAE,cAAc,CAAC,CAAC;QACtD,CAAC;KACF,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { Renderable as OTUIRenderable } from '@opentui/core';
|
|
2
|
+
import { type BuilderState } from './state.ts';
|
|
3
|
+
export interface PreviewPanel {
|
|
4
|
+
container: OTUIRenderable;
|
|
5
|
+
update: (state: BuilderState) => void;
|
|
6
|
+
tick: (frame: number) => void;
|
|
7
|
+
}
|
|
8
|
+
export declare function createPreviewPanel(parent: OTUIRenderable): PreviewPanel;
|
|
9
|
+
//# sourceMappingURL=preview-panel.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"preview-panel.d.ts","sourceRoot":"","sources":["../../../src/tui/builder/preview-panel.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,UAAU,IAAI,cAAc,EAAE,MAAM,eAAe,CAAC;AAIlE,OAAO,EAAgB,KAAK,YAAY,EAAE,MAAM,YAAY,CAAC;AAG7D,MAAM,WAAW,YAAY;IAC3B,SAAS,EAAE,cAAc,CAAC;IAC1B,MAAM,EAAE,CAAC,KAAK,EAAE,YAAY,KAAK,IAAI,CAAC;IACtC,IAAI,EAAE,CAAC,KAAK,EAAE,MAAM,KAAK,IAAI,CAAC;CAC/B;AAED,wBAAgB,kBAAkB,CAAC,MAAM,EAAE,cAAc,GAAG,YAAY,CAyGvE"}
|
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
import { Box, Text } from '@opentui/core';
|
|
2
|
+
import { renderAnimatedSprite, IDLE_SEQUENCE } from '../../sprites/index.js';
|
|
3
|
+
import { RARITY_STARS } from '../../constants.js';
|
|
4
|
+
import { RARITY_HEX, BORDER_COLOR } from "./colors.js";
|
|
5
|
+
import { stateToBones } from "./state.js";
|
|
6
|
+
import { renderStatBars } from "./stat-bars.js";
|
|
7
|
+
export function createPreviewPanel(parent) {
|
|
8
|
+
let spriteText = null;
|
|
9
|
+
let titleText = null;
|
|
10
|
+
let detailsText = null;
|
|
11
|
+
let statsText = null;
|
|
12
|
+
let currentState = null;
|
|
13
|
+
let lastRenderedFrame = -1;
|
|
14
|
+
const container = Box({
|
|
15
|
+
id: 'preview-panel',
|
|
16
|
+
borderStyle: 'rounded',
|
|
17
|
+
border: true,
|
|
18
|
+
borderColor: BORDER_COLOR,
|
|
19
|
+
title: ' Live Preview ',
|
|
20
|
+
titleAlignment: 'center',
|
|
21
|
+
flexDirection: 'column',
|
|
22
|
+
width: 40,
|
|
23
|
+
padding: 1,
|
|
24
|
+
paddingTop: 1,
|
|
25
|
+
alignItems: 'center',
|
|
26
|
+
justifyContent: 'flex-start',
|
|
27
|
+
flexShrink: 0,
|
|
28
|
+
},
|
|
29
|
+
// Title line: "dragon ★★★★★"
|
|
30
|
+
Text({ id: 'preview-title', content: '', height: 1 }),
|
|
31
|
+
// Spacer
|
|
32
|
+
Text({ content: '', height: 1 }),
|
|
33
|
+
// Sprite (fixed 5 lines for stability)
|
|
34
|
+
Text({ id: 'preview-sprite', content: '\n\n\n\n', height: 5 }),
|
|
35
|
+
// Spacer
|
|
36
|
+
Text({ content: '', height: 1 }),
|
|
37
|
+
// Details block
|
|
38
|
+
Text({ id: 'preview-details', content: '', height: 4 }),
|
|
39
|
+
// Spacer before stats
|
|
40
|
+
Text({ content: '', height: 1 }),
|
|
41
|
+
// Stats bar chart
|
|
42
|
+
Text({ id: 'preview-stats', content: '', height: 5 }));
|
|
43
|
+
parent.add(container);
|
|
44
|
+
const containerRenderable = parent.findDescendantById('preview-panel');
|
|
45
|
+
spriteText = containerRenderable?.findDescendantById('preview-sprite');
|
|
46
|
+
titleText = containerRenderable?.findDescendantById('preview-title');
|
|
47
|
+
detailsText = containerRenderable?.findDescendantById('preview-details');
|
|
48
|
+
statsText = containerRenderable?.findDescendantById('preview-stats');
|
|
49
|
+
function renderSpriteAtFrame(bones, frame) {
|
|
50
|
+
if (!spriteText)
|
|
51
|
+
return;
|
|
52
|
+
spriteText.content = renderAnimatedSprite(bones, frame);
|
|
53
|
+
}
|
|
54
|
+
function update(state) {
|
|
55
|
+
if (!spriteText || !titleText || !detailsText || !statsText)
|
|
56
|
+
return;
|
|
57
|
+
currentState = state;
|
|
58
|
+
lastRenderedFrame = -1;
|
|
59
|
+
const bones = stateToBones(state);
|
|
60
|
+
const color = RARITY_HEX[state.rarity];
|
|
61
|
+
// Title
|
|
62
|
+
titleText.content = `${state.species} ${RARITY_STARS[state.rarity]}`;
|
|
63
|
+
titleText.fg = color;
|
|
64
|
+
// Sprite — render frame 0, animation will advance via tick()
|
|
65
|
+
renderSpriteAtFrame(bones, 0);
|
|
66
|
+
spriteText.fg = color;
|
|
67
|
+
// Details -- use rarity color for values, dim for labels
|
|
68
|
+
const hatLabel = state.rarity === 'common' ? 'none' : state.hat;
|
|
69
|
+
const detailLines = [
|
|
70
|
+
`Rarity: ${state.rarity}`,
|
|
71
|
+
`Eyes: ${state.eye}`,
|
|
72
|
+
`Hat: ${hatLabel}`,
|
|
73
|
+
`Shiny: ${state.shiny ? 'YES' : 'no'}`,
|
|
74
|
+
];
|
|
75
|
+
detailsText.content = detailLines.join('\n');
|
|
76
|
+
detailsText.fg = color;
|
|
77
|
+
// Stats bar chart
|
|
78
|
+
if (state.statsMode === 'customize') {
|
|
79
|
+
statsText.content = renderStatBars(state.peak, state.dump);
|
|
80
|
+
statsText.fg = color;
|
|
81
|
+
statsText.visible = true;
|
|
82
|
+
}
|
|
83
|
+
else {
|
|
84
|
+
statsText.content = '';
|
|
85
|
+
statsText.visible = false;
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
function tick(frame) {
|
|
89
|
+
if (!currentState || !spriteText)
|
|
90
|
+
return;
|
|
91
|
+
const seqEntry = IDLE_SEQUENCE[frame % IDLE_SEQUENCE.length];
|
|
92
|
+
if (seqEntry === lastRenderedFrame)
|
|
93
|
+
return;
|
|
94
|
+
lastRenderedFrame = seqEntry;
|
|
95
|
+
renderSpriteAtFrame(stateToBones(currentState), frame);
|
|
96
|
+
}
|
|
97
|
+
return {
|
|
98
|
+
container: containerRenderable ?? container,
|
|
99
|
+
update,
|
|
100
|
+
tick,
|
|
101
|
+
};
|
|
102
|
+
}
|
|
103
|
+
//# sourceMappingURL=preview-panel.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"preview-panel.js","sourceRoot":"","sources":["../../../src/tui/builder/preview-panel.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,GAAG,EAAE,IAAI,EAAE,MAAM,eAAe,CAAC;AAE1C,OAAO,EAAE,oBAAoB,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AACzE,OAAO,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC;AAC9C,OAAO,EAAE,UAAU,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AACvD,OAAO,EAAE,YAAY,EAAqB,MAAM,YAAY,CAAC;AAC7D,OAAO,EAAE,cAAc,EAAE,MAAM,gBAAgB,CAAC;AAQhD,MAAM,UAAU,kBAAkB,CAAC,MAAsB;IACvD,IAAI,UAAU,GAA0B,IAAI,CAAC;IAC7C,IAAI,SAAS,GAA0B,IAAI,CAAC;IAC5C,IAAI,WAAW,GAA0B,IAAI,CAAC;IAC9C,IAAI,SAAS,GAA0B,IAAI,CAAC;IAC5C,IAAI,YAAY,GAAwB,IAAI,CAAC;IAC7C,IAAI,iBAAiB,GAAG,CAAC,CAAC,CAAC;IAE3B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Y,KAAK,CAAC,GAAG,EAAE;YACvB,YAAY,QAAQ,EAAE;YACtB,YAAY,KAAK,CAAC,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,IAAI,EAAE;SACzC,CAAC;QACF,WAAW,CAAC,OAAO,GAAG,WAAW,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;QAC7C,WAAW,CAAC,EAAE,GAAG,KAAK,CAAC;QAEvB,kBAAkB;QAClB,IAAI,KAAK,CAAC,SAAS,KAAK,WAAW,EAAE,CAAC;YACpC,SAAS,CAAC,OAAO,GAAG,cAAc,CAAC,KAAK,CAAC,IAAI,EAAE,KAAK,CAAC,IAAI,CAAC,CAAC;YAC3D,SAAS,CAAC,EAAE,GAAG,KAAK,CAAC;YACrB,SAAS,CAAC,OAAO,GAAG,IAAI,CAAC;QAC3B,CAAC;aAAM,CAAC;YACN,SAAS,CAAC,OAAO,GAAG,EAAE,CAAC;YACvB,SAAS,CAAC,OAAO,GAAG,KAAK,CAAC;QAC5B,CAAC;IACH,CAAC;IAED,SAAS,IAAI,CAAC,KAAa;QACzB,IAAI,CAAC,YAAY,IAAI,CAAC,UAAU;YAAE,OAAO;QACzC,MAAM,QAAQ,GAAG,aAAa,CAAC,KAAK,GAAG,aAAa,CAAC,MAAM,CAAC,CAAC;QAC7D,IAAI,QAAQ,KAAK,iBAAiB;YAAE,OAAO;QAC3C,iBAAiB,GAAG,QAAQ,CAAC;QAC7B,mBAAmB,CAAC,YAAY,CAAC,YAAY,CAAC,EAAE,KAAK,CAAC,CAAC;IACzD,CAAC;IAED,OAAO;QACL,SAAS,EAAE,mBAAmB,IAAK,SAAuC;QAC1E,MAAM;QACN,IAAI;KACL,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type { SelectRenderable } from '@opentui/core';
|
|
2
|
+
import type { Renderable as OTUIRenderable } from '@opentui/core';
|
|
3
|
+
import { type BuilderState, type BuilderField } from './state.ts';
|
|
4
|
+
export interface SelectionPanel {
|
|
5
|
+
container: OTUIRenderable;
|
|
6
|
+
selects: Map<BuilderField, SelectRenderable>;
|
|
7
|
+
focusField: (field: BuilderField) => void;
|
|
8
|
+
getState: () => BuilderState;
|
|
9
|
+
}
|
|
10
|
+
export declare function createSelectionPanel(parent: OTUIRenderable, initialState: BuilderState, onChange: (state: BuilderState) => void): SelectionPanel;
|
|
11
|
+
//# sourceMappingURL=selection-panel.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"selection-panel.d.ts","sourceRoot":"","sources":["../../../src/tui/builder/selection-panel.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAiB,gBAAgB,EAAgB,MAAM,eAAe,CAAC;AAEnF,OAAO,KAAK,EAAE,UAAU,IAAI,cAAc,EAAE,MAAM,eAAe,CAAC;AAqBlE,OAAO,EAIL,KAAK,YAAY,EACjB,KAAK,YAAY,EAElB,MAAM,YAAY,CAAC;AAEpB,MAAM,WAAW,cAAc;IAC7B,SAAS,EAAE,cAAc,CAAC;IAC1B,OAAO,EAAE,GAAG,CAAC,YAAY,EAAE,gBAAgB,CAAC,CAAC;IAC7C,UAAU,EAAE,CAAC,KAAK,EAAE,YAAY,KAAK,IAAI,CAAC;IAC1C,QAAQ,EAAE,MAAM,YAAY,CAAC;CAC9B;AAwJD,wBAAgB,oBAAoB,CAClC,MAAM,EAAE,cAAc,EACtB,YAAY,EAAE,YAAY,EAC1B,QAAQ,EAAE,CAAC,KAAK,EAAE,YAAY,KAAK,IAAI,GACtC,cAAc,CAmWhB"}
|