praxo-cli 0.0.0-stage → 0.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.
Files changed (82) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +159 -2
  3. package/dist/app.js +75 -0
  4. package/dist/bin.js +21 -0
  5. package/dist/cli/commands/ai.command.js +189 -0
  6. package/dist/cli/commands/cmd.command.js +265 -0
  7. package/dist/cli/commands/completion.command.js +334 -0
  8. package/dist/cli/commands/config.command.js +27 -0
  9. package/dist/cli/commands/decision.command.js +287 -0
  10. package/dist/cli/commands/doctor.command.js +45 -0
  11. package/dist/cli/commands/project.command.js +24 -0
  12. package/dist/cli/commands/search.command.js +59 -0
  13. package/dist/cli/commands/sync.command.js +122 -0
  14. package/dist/cli/commands/transfer.command.js +148 -0
  15. package/dist/cli/index.js +156 -0
  16. package/dist/cli/output.js +133 -0
  17. package/dist/cli/prompts.js +68 -0
  18. package/dist/features/ai/client.js +238 -0
  19. package/dist/features/ai/output.js +7 -0
  20. package/dist/features/ai/providers.js +52 -0
  21. package/dist/features/ai/schemas.js +43 -0
  22. package/dist/features/ai/service.js +183 -0
  23. package/dist/features/commands/executor.js +54 -0
  24. package/dist/features/commands/repository.js +61 -0
  25. package/dist/features/commands/safety.js +154 -0
  26. package/dist/features/commands/service.js +254 -0
  27. package/dist/features/commands/template.js +153 -0
  28. package/dist/features/decisions/repository.js +53 -0
  29. package/dist/features/decisions/service.js +209 -0
  30. package/dist/features/decisions/stats.js +84 -0
  31. package/dist/features/decisions/status.js +7 -0
  32. package/dist/features/projects/repository.js +51 -0
  33. package/dist/features/projects/service.js +74 -0
  34. package/dist/features/sync/git.js +207 -0
  35. package/dist/features/sync/merge.js +194 -0
  36. package/dist/features/sync/repository.js +151 -0
  37. package/dist/features/sync/sanitizer.js +21 -0
  38. package/dist/features/sync/service.js +199 -0
  39. package/dist/features/sync/snapshot.js +230 -0
  40. package/dist/infrastructure/credentials/store.js +105 -0
  41. package/dist/infrastructure/database/client.js +41 -0
  42. package/dist/infrastructure/database/migrate.js +102 -0
  43. package/dist/infrastructure/database/schema.js +138 -0
  44. package/dist/infrastructure/git/detector.js +48 -0
  45. package/dist/shared/clipboard.js +19 -0
  46. package/dist/shared/config.js +163 -0
  47. package/dist/shared/doctor.js +47 -0
  48. package/dist/shared/errors.js +19 -0
  49. package/dist/shared/global-search.js +51 -0
  50. package/dist/shared/input.js +37 -0
  51. package/dist/shared/links.js +48 -0
  52. package/dist/shared/paths.js +14 -0
  53. package/dist/shared/query.js +10 -0
  54. package/dist/shared/redaction.js +54 -0
  55. package/dist/shared/search.js +39 -0
  56. package/dist/shared/sync-metadata.js +7 -0
  57. package/dist/shared/tags.js +91 -0
  58. package/dist/shared/transfer/archive.js +197 -0
  59. package/dist/shared/transfer/markdown.js +53 -0
  60. package/dist/shared/transfer/service.js +278 -0
  61. package/dist/tui/Workspace.js +121 -0
  62. package/dist/tui/components/AiPanel.js +200 -0
  63. package/dist/tui/components/Catalog.js +47 -0
  64. package/dist/tui/components/Confirm.js +28 -0
  65. package/dist/tui/components/Form.js +113 -0
  66. package/dist/tui/components/HelpModal.js +44 -0
  67. package/dist/tui/components/Inspection.js +28 -0
  68. package/dist/tui/components/KeyHints.js +7 -0
  69. package/dist/tui/components/SearchInput.js +31 -0
  70. package/dist/tui/components/SyncPanel.js +93 -0
  71. package/dist/tui/index.js +18 -0
  72. package/dist/tui/screens/Commands.js +383 -0
  73. package/dist/tui/screens/DecisionForms.js +117 -0
  74. package/dist/tui/screens/Decisions.js +260 -0
  75. package/dist/tui/screens/Lookup.js +96 -0
  76. package/dist/tui/theme.js +47 -0
  77. package/drizzle/0000_initial.sql +105 -0
  78. package/drizzle/0001_v11_sync.sql +117 -0
  79. package/drizzle/meta/0000_snapshot.json +735 -0
  80. package/drizzle/meta/0001_snapshot.json +867 -0
  81. package/drizzle/meta/_journal.json +20 -0
  82. package/package.json +77 -4
@@ -0,0 +1,200 @@
1
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
+ import { Spinner } from '@inkjs/ui';
3
+ import { Box, Text, useInput } from 'ink';
4
+ import { useCallback, useEffect, useState } from 'react';
5
+ import { messageOf } from '../../shared/errors.js';
6
+ import { Confirm } from './Confirm.js';
7
+ import { Form } from './Form.js';
8
+ import { Inspection } from './Inspection.js';
9
+ const lines = (text) => text.split(/\r?\n/u);
10
+ export function AiSettings({ app, onClose, onSaved, }) {
11
+ let current;
12
+ try {
13
+ current = app.ai.settings();
14
+ }
15
+ catch (error) {
16
+ return _jsx(Inspection, { title: "AI \u914D\u7F6E\u9519\u8BEF", lines: [messageOf(error)], onClose: onClose });
17
+ }
18
+ return (_jsx(Form, { title: "\u914D\u7F6E AI \u52A9\u624B", onCancel: onClose, fields: [
19
+ {
20
+ key: 'provider',
21
+ label: '服务商',
22
+ initial: current?.provider ?? 'deepseek',
23
+ placeholder: 'deepseek / gemini',
24
+ },
25
+ {
26
+ key: 'model',
27
+ label: '模型',
28
+ initial: current?.model,
29
+ placeholder: '留空使用默认模型(deepseek-chat / gemini-2.5-flash)',
30
+ },
31
+ {
32
+ key: 'key',
33
+ label: 'API Key',
34
+ secret: true,
35
+ placeholder: '保存到系统凭据库,或设置 PRAXO_*_API_KEY',
36
+ },
37
+ ], onSave: async (values) => {
38
+ const provider = values.provider?.trim();
39
+ const model = values.model?.trim();
40
+ const changedProvider = Boolean(current && provider && provider !== current.provider);
41
+ await app.ai.configure({
42
+ provider,
43
+ model: changedProvider && model === current?.model ? undefined : model || undefined,
44
+ }, values.key || undefined);
45
+ onSaved();
46
+ } }));
47
+ }
48
+ export function useAiApproval() {
49
+ const [approval, setApproval] = useState();
50
+ useEffect(() => () => approval?.done(false), [approval]);
51
+ const request = useCallback((locations) => new Promise((done) => setApproval({ locations, done })), []);
52
+ const panel = approval && (_jsx(Confirm, { title: "\u53D1\u9001\u8131\u654F\u540E\u7684\u8BF7\u6C42", tone: "danger", onAccept: () => {
53
+ approval.done(true);
54
+ setApproval(undefined);
55
+ }, onCancel: () => {
56
+ approval.done(false);
57
+ setApproval(undefined);
58
+ }, children: _jsxs(Text, { children: ["\u5DF2\u8131\u654F ", approval.locations.join('、')] }) }));
59
+ return { request, panel };
60
+ }
61
+ function DraftEditor({ draft, onClose, onSave, }) {
62
+ return (_jsx(Form, { title: "\u7F16\u8F91 AI \u8349\u7A3F", onCancel: onClose, fields: [
63
+ { key: 'name', label: '名称', initial: draft.name },
64
+ { key: 'template', label: '命令', initial: draft.template },
65
+ { key: 'note', label: '说明', initial: draft.note },
66
+ { key: 'type', label: '类型', initial: draft.type },
67
+ { key: 'tags', label: '标签', initial: draft.tags.join(', ') },
68
+ ], onSave: (values) => onSave({
69
+ ...draft,
70
+ name: values.name ?? '',
71
+ template: values.template ?? '',
72
+ note: values.note ?? '',
73
+ type: values.type ?? '',
74
+ tags: values.tags
75
+ ?.split(',')
76
+ .map((tag) => tag.trim())
77
+ .filter(Boolean) ?? [],
78
+ }) }));
79
+ }
80
+ function DraftPreview({ app, value, onClose, onSaved, }) {
81
+ const [preview, setPreview] = useState(value);
82
+ const [mode, setMode] = useState();
83
+ const [message, setMessage] = useState();
84
+ function save(approved) {
85
+ try {
86
+ onSaved(app.ai.saveDraft(preview.draft, true, approved).id);
87
+ }
88
+ catch (error) {
89
+ setMessage(messageOf(error));
90
+ setMode(undefined);
91
+ }
92
+ }
93
+ useInput((input, key) => {
94
+ if (key.escape)
95
+ onClose();
96
+ if (!key.ctrl && !key.meta && input.toLowerCase() === 'e')
97
+ setMode('edit');
98
+ if (!key.ctrl && !key.meta && input.toLowerCase() === 'c') {
99
+ void app.ai.copyDraft(preview.draft).then(() => setMessage('已复制草稿'), (error) => setMessage(messageOf(error)));
100
+ }
101
+ if (key.return) {
102
+ if (preview.danger)
103
+ setMode('risk');
104
+ else
105
+ save(false);
106
+ }
107
+ }, { isActive: !mode });
108
+ if (mode === 'edit')
109
+ return (_jsx(DraftEditor, { draft: preview.draft, onClose: () => setMode(undefined), onSave: (draft) => {
110
+ setPreview(app.ai.assessDraft(draft));
111
+ setMessage(undefined);
112
+ setMode(undefined);
113
+ } }));
114
+ if (mode === 'risk')
115
+ return (_jsxs(Confirm, { title: "\u786E\u8BA4\u4FDD\u5B58\u98CE\u9669\u547D\u4EE4", tone: "danger", onAccept: () => save(true), onCancel: () => setMode(undefined), children: [_jsx(Text, { children: preview.draft.template }), _jsx(Text, { children: preview.risk })] }));
116
+ return (_jsxs(Box, { flexDirection: "column", children: [_jsxs(Text, { bold: true, children: [preview.draft.name, " \u00B7 ", preview.draft.platform] }), _jsx(Text, { children: preview.draft.template }), _jsx(Text, { children: preview.draft.note }), _jsxs(Text, { dimColor: true, children: [preview.risk, preview.draft.tags.length ? ' · ' + preview.draft.tags.join(', ') : ''] }), message && _jsx(Text, { children: message }), _jsx(Text, { dimColor: true, children: "Enter \u4FDD\u5B58 \u00B7 E \u7F16\u8F91 \u00B7 C \u590D\u5236 \u00B7 Esc \u53D6\u6D88" })] }));
117
+ }
118
+ function AiResult({ app, job, onClose, onChanged, }) {
119
+ const [result, setResult] = useState();
120
+ const [partial, setPartial] = useState('');
121
+ const [error, setError] = useState();
122
+ const [save, setSave] = useState(false);
123
+ const { request, panel } = useAiApproval();
124
+ useEffect(() => {
125
+ const controller = new AbortController();
126
+ const options = { signal: controller.signal, approve: request };
127
+ let shown = '';
128
+ const timer = setInterval(() => setPartial(shown), 80);
129
+ const operation = job.type === 'generate'
130
+ ? app.ai.generate(job.description, options)
131
+ : job.type === 'explain'
132
+ ? app.ai.explain(job.command, options, (chunk) => {
133
+ shown += chunk;
134
+ })
135
+ : job.type === 'challenge'
136
+ ? app.ai.challenge(job.id, options)
137
+ : app.ai.summary('180d', undefined, options);
138
+ void operation
139
+ .then((value) => {
140
+ if (!controller.signal.aborted)
141
+ setResult(value);
142
+ }, (failure) => {
143
+ if (!controller.signal.aborted)
144
+ setError(messageOf(failure));
145
+ })
146
+ .finally(() => clearInterval(timer));
147
+ return () => {
148
+ clearInterval(timer);
149
+ controller.abort();
150
+ };
151
+ }, [app, job, request]);
152
+ useInput((_input, key) => {
153
+ if (key.escape)
154
+ onClose();
155
+ }, { isActive: !panel && result === undefined && !error });
156
+ if (panel)
157
+ return panel;
158
+ if (error)
159
+ return _jsx(Inspection, { title: "AI \u8BF7\u6C42\u5931\u8D25", lines: [error], onClose: onClose });
160
+ if (result === undefined)
161
+ return (_jsxs(Box, { flexDirection: "column", children: [_jsx(Spinner, { label: "AI \u8BF7\u6C42\u4E2D \u00B7 Esc \u53D6\u6D88" }), partial !== '' && _jsx(Text, { children: lines(partial).slice(-8).join('\n') })] }));
162
+ if (typeof result !== 'string')
163
+ return _jsx(DraftPreview, { app: app, value: result, onClose: onClose, onSaved: onChanged });
164
+ if (save && job.type === 'challenge')
165
+ return (_jsx(Confirm, { title: "\u4FDD\u5B58\u4E3A\u51B3\u7B56 AI \u5907\u6CE8", onCancel: () => setSave(false), onAccept: () => {
166
+ try {
167
+ app.ai.saveChallenge(job.id, result, true);
168
+ onChanged(job.id);
169
+ }
170
+ catch (failure) {
171
+ setError(messageOf(failure));
172
+ }
173
+ } }));
174
+ return (_jsx(Inspection, { title: job.type === 'challenge'
175
+ ? 'AI 决策质疑'
176
+ : job.type === 'summary'
177
+ ? 'AI 周期总结 · 180 天'
178
+ : 'AI 命令解释', lines: lines(result), onClose: onClose, action: job.type === 'challenge'
179
+ ? { key: 's', label: '保存备注', run: () => setSave(true) }
180
+ : undefined }));
181
+ }
182
+ export function AiPanel({ app, task, onClose, onChanged, }) {
183
+ const [configured, setConfigured] = useState(() => {
184
+ try {
185
+ return Boolean(app.ai.settings());
186
+ }
187
+ catch {
188
+ return false;
189
+ }
190
+ });
191
+ const [job, setJob] = useState(() => task.type === 'generate' ? undefined : task);
192
+ if (!configured)
193
+ return _jsx(AiSettings, { app: app, onClose: onClose, onSaved: () => setConfigured(true) });
194
+ if (job)
195
+ return _jsx(AiResult, { app: app, job: job, onClose: onClose, onChanged: onChanged });
196
+ return (_jsx(Form, { title: "\u751F\u6210\u547D\u4EE4\u8349\u7A3F", fields: [{ key: 'prompt', label: '描述要完成的任务' }], onCancel: onClose, onSave: (data) => {
197
+ if (data.prompt?.trim())
198
+ setJob({ type: 'generate', description: data.prompt });
199
+ } }));
200
+ }
@@ -0,0 +1,47 @@
1
+ import { jsxs as _jsxs, jsx as _jsx } from "react/jsx-runtime";
2
+ import { Box, Text, useWindowSize } from 'ink';
3
+ import { useState } from 'react';
4
+ import { panelCount, theme, WIDE_BREAKPOINT } from '../theme.js';
5
+ /** 管理列表选中态、详情展开态与 3 段焦点环(搜索输入/列表/详情)。 */
6
+ export function useCatalog(items, initialId) {
7
+ const [selectedId, select] = useState(initialId);
8
+ const [detail, setDetail] = useState(Boolean(initialId));
9
+ const [focus, setFocus] = useState(initialId ? 3 : 2);
10
+ const index = Math.max(0, items.findIndex((item) => item.id === selectedId));
11
+ const item = items[index];
12
+ function move(delta) {
13
+ if (!items.length)
14
+ return;
15
+ select(items[Math.min(items.length - 1, Math.max(0, index + delta))]?.id);
16
+ }
17
+ function jump(target) {
18
+ if (!items.length)
19
+ return;
20
+ select(target === 'start' ? items[0]?.id : items[items.length - 1]?.id);
21
+ }
22
+ function tab(backward, hasDetails) {
23
+ const order = hasDetails ? [0, 2, 3] : [0, 2];
24
+ const pos = Math.max(0, order.indexOf(focus));
25
+ const next = order[(pos + (backward ? order.length - 1 : 1)) % order.length] ?? 2;
26
+ setFocus(next);
27
+ }
28
+ return { index, item, move, jump, detail, setDetail, select, focus, setFocus, tab };
29
+ }
30
+ /** 极简细线分栏布局:去掉厚重套娃边框,以留白与单细线分隔列表和详情。 */
31
+ export function Catalog({ items, index, showDetails, focus, label, renderItem, toolbar, details, empty, listTitle = 'List', }) {
32
+ const { columns, rows } = useWindowSize();
33
+ const wide = columns >= WIDE_BREAKPOINT;
34
+ // 顶栏(1) + 输入栏(3) + 内边距与标题(3) + 底栏(2) = 9 行。
35
+ const capacity = Math.max(3, rows - 9);
36
+ const offset = Math.min(Math.max(0, index - capacity + 1), Math.max(0, items.length - capacity));
37
+ const visibleItems = items.slice(offset, offset + capacity);
38
+ const hasAbove = offset > 0;
39
+ const hasBelow = offset + capacity < items.length;
40
+ return (_jsxs(Box, { flexDirection: "column", flexGrow: 1, children: [toolbar, _jsxs(Box, { flexDirection: wide ? 'row' : 'column', flexGrow: 1, overflow: "hidden", children: [(wide || !showDetails) && (_jsxs(Box, { flexDirection: "column", width: wide ? '40%' : '100%', flexGrow: wide ? 0 : 1, paddingX: 2, paddingY: 1, overflow: "hidden", children: [_jsxs(Box, { justifyContent: "space-between", marginBottom: 1, flexShrink: 0, children: [_jsxs(Text, { bold: focus === 2, dimColor: focus !== 2, children: [listTitle, " \u00B7 ", panelCount(index, items.length)] }), (hasAbove || hasBelow) && (_jsxs(Text, { dimColor: true, children: [hasAbove ? '↑' : ' ', hasBelow ? '↓' : ' '] }))] }), !items.length ? (_jsx(Text, { dimColor: true, children: empty })) : (visibleItems.map((item, visible) => {
41
+ const selected = visible + offset === index;
42
+ if (renderItem) {
43
+ return (_jsx(Box, { flexShrink: 0, children: renderItem(item, selected) }, item.id));
44
+ }
45
+ return (_jsxs(Text, { bold: selected, color: selected ? theme.accent : undefined, wrap: "truncate-end", children: [selected ? '❯ ' : ' ', label ? label(item) : item.id] }, item.id));
46
+ }))] })), (wide || showDetails) && (_jsxs(Box, { flexDirection: "column", flexGrow: 1, paddingX: 2, paddingY: 1, overflow: "hidden", borderStyle: wide ? 'single' : undefined, borderTop: false, borderBottom: false, borderRight: false, borderLeft: wide, borderColor: focus === 3 ? theme.accent : theme.border, borderDimColor: focus !== 3, children: [_jsxs(Box, { justifyContent: "space-between", marginBottom: 1, flexShrink: 0, children: [_jsx(Text, { bold: focus === 3, dimColor: focus !== 3, children: "Details" }), !wide && showDetails && _jsx(Text, { dimColor: true, children: "Esc \u8FD4\u56DE" })] }), details] }))] })] }));
47
+ }
@@ -0,0 +1,28 @@
1
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
+ import { Box, Text, useInput } from 'ink';
3
+ import { theme } from '../theme.js';
4
+ /**
5
+ * 二次确认弹层:
6
+ * - 高危/删除操作(tone=danger):遵循 [y/N] 安全默认,仅按 Y 确认,Enter/N/Esc 均取消;
7
+ * - 普通操作(tone=warning/accent):遵循 [Y/n] 流畅默认,Y 或 Enter 确认,N/Esc 取消。
8
+ */
9
+ export function Confirm({ title, tone = 'warning', children, onAccept, onCancel, }) {
10
+ const safeDefaultCancel = tone === 'danger';
11
+ useInput((input, key) => {
12
+ if (key.escape || input.toLowerCase() === 'n') {
13
+ onCancel();
14
+ return;
15
+ }
16
+ if (key.return) {
17
+ if (safeDefaultCancel)
18
+ onCancel();
19
+ else
20
+ onAccept();
21
+ return;
22
+ }
23
+ if (!key.ctrl && !key.meta && input.toLowerCase() === 'y')
24
+ onAccept();
25
+ });
26
+ const borderColor = tone === 'danger' ? theme.danger : tone === 'accent' ? theme.borderActive : theme.warning;
27
+ return (_jsxs(Box, { flexDirection: "column", flexShrink: 0, borderStyle: "round", borderColor: borderColor, paddingX: 2, paddingY: 1, children: [_jsx(Text, { bold: true, color: borderColor, children: title }), children && (_jsx(Box, { flexDirection: "column", marginTop: 1, flexShrink: 0, children: children })), _jsx(Box, { marginTop: 1, flexShrink: 0, children: _jsx(Text, { dimColor: true, children: safeDefaultCancel ? 'Y 确认 · N / Enter / Esc 取消' : 'Y / Enter 确认 · N / Esc 取消' }) })] }));
28
+ }
@@ -0,0 +1,113 @@
1
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
+ import { PasswordInput, Spinner, TextInput } from '@inkjs/ui';
3
+ import { Box, Text, useInput, useWindowSize } from 'ink';
4
+ import { useEffect, useRef, useState } from 'react';
5
+ import { messageOf } from '../../shared/errors.js';
6
+ import { theme } from '../theme.js';
7
+ /** 通用多字段终端表单,支持 ↑/↓/Tab 切换字段与 Ctrl+S 随时快捷保存。 */
8
+ export function Form({ title, fields, lead, assist, onCancel, onSave, }) {
9
+ const [selected, select] = useState(0);
10
+ const [values, setValues] = useState(() => Object.fromEntries(fields.map((field) => [field.key, field.initial ?? ''])));
11
+ const [busy, setBusy] = useState(false);
12
+ const [inputRevision, refreshInputs] = useState(0);
13
+ const assistance = useRef(undefined);
14
+ useEffect(() => () => assistance.current?.abort(), []);
15
+ const [error, setError] = useState();
16
+ const valuesRef = useRef(values);
17
+ valuesRef.current = values;
18
+ const pending = useRef(false);
19
+ const { rows } = useWindowSize();
20
+ const height = Math.max(1, Math.min(8, rows - (lead ? 15 : 10)));
21
+ const first = Math.min(Math.max(0, selected - height + 1), Math.max(0, fields.length - height));
22
+ /** 执行提交并统一捕获业务与校验错误。 */
23
+ async function save(payload) {
24
+ if (pending.current)
25
+ return;
26
+ pending.current = true;
27
+ setBusy(true);
28
+ setError(undefined);
29
+ try {
30
+ await onSave(payload);
31
+ }
32
+ catch (caught) {
33
+ setError(messageOf(caught));
34
+ }
35
+ finally {
36
+ pending.current = false;
37
+ setBusy(false);
38
+ }
39
+ }
40
+ async function applyAssistance() {
41
+ if (!assist)
42
+ return;
43
+ const controller = new AbortController();
44
+ assistance.current = controller;
45
+ pending.current = true;
46
+ setBusy(true);
47
+ setError(undefined);
48
+ try {
49
+ const patch = await assist(valuesRef.current, controller.signal);
50
+ if (!controller.signal.aborted) {
51
+ setValues((previous) => ({ ...previous, ...patch }));
52
+ refreshInputs((value) => value + 1);
53
+ }
54
+ }
55
+ catch (error) {
56
+ if (!controller.signal.aborted)
57
+ setError(messageOf(error));
58
+ }
59
+ finally {
60
+ assistance.current = undefined;
61
+ pending.current = false;
62
+ setBusy(false);
63
+ }
64
+ }
65
+ useInput((input, key) => {
66
+ if (pending.current) {
67
+ if (key.escape)
68
+ assistance.current?.abort();
69
+ return;
70
+ }
71
+ if (assist && key.ctrl && input.toLowerCase() === 'g') {
72
+ void applyAssistance();
73
+ return;
74
+ }
75
+ if (key.escape)
76
+ onCancel();
77
+ else if (key.ctrl && input.toLowerCase() === 's') {
78
+ void save(valuesRef.current);
79
+ }
80
+ else if (key.tab) {
81
+ select((current) => (current + (key.shift ? fields.length - 1 : 1)) % fields.length);
82
+ }
83
+ else if (key.upArrow && fields.length > 1) {
84
+ select((current) => (current + fields.length - 1) % fields.length);
85
+ }
86
+ else if (key.downArrow && fields.length > 1) {
87
+ select((current) => (current + 1) % fields.length);
88
+ }
89
+ });
90
+ function update(key, value) {
91
+ setValues((previous) => {
92
+ if (previous[key] === value)
93
+ return previous;
94
+ const next = { ...previous, [key]: value };
95
+ valuesRef.current = next;
96
+ return next;
97
+ });
98
+ }
99
+ async function submit(field, value) {
100
+ if (pending.current)
101
+ return;
102
+ update(field.key, value);
103
+ if (selected < fields.length - 1) {
104
+ select(selected + 1);
105
+ return;
106
+ }
107
+ await save({ ...valuesRef.current, [field.key]: value });
108
+ }
109
+ return (_jsxs(Box, { flexDirection: "column", flexShrink: 0, borderStyle: "round", borderColor: theme.borderActive, paddingX: 2, paddingY: 1, children: [_jsxs(Box, { justifyContent: "space-between", marginBottom: 1, flexShrink: 0, children: [_jsx(Text, { bold: true, color: theme.accent, children: title }), _jsxs(Text, { dimColor: true, children: [selected + 1, "/", fields.length] })] }), lead && (_jsx(Box, { marginBottom: 1, flexShrink: 0, children: lead })), fields.slice(first, first + height).map((field, offset) => {
110
+ const active = first + offset === selected;
111
+ return (_jsxs(Box, { gap: 1, flexShrink: 0, children: [_jsxs(Text, { bold: active, color: active ? theme.accent : undefined, children: [active ? '❯' : ' ', " ", field.label, ":"] }), active && !busy ? (field.secret ? (_jsx(PasswordInput, { placeholder: field.placeholder, onChange: (value) => update(field.key, value), onSubmit: (value) => void submit(field, value || valuesRef.current[field.key] || '') }, field.key)) : (_jsx(TextInput, { defaultValue: values[field.key], placeholder: field.placeholder, onChange: (value) => update(field.key, value), onSubmit: (value) => void submit(field, value) }, field.key + inputRevision))) : (_jsx(Text, { dimColor: true, wrap: "truncate-end", children: field.secret && values[field.key] ? '••••' : values[field.key] || '—' }))] }, field.key));
112
+ }), error && (_jsx(Box, { marginTop: 1, flexShrink: 0, children: _jsxs(Text, { color: theme.danger, children: ["\u2716 ", error] }) })), _jsx(Box, { marginTop: 1, flexShrink: 0, children: busy ? (_jsx(Spinner, { label: "\u5904\u7406\u4E2D\u2026" })) : (_jsxs(Text, { dimColor: true, wrap: "truncate-end", children: [fields.length > 1 ? '↑↓/Tab 切换 · Ctrl+S 保存 · ' : '', assist ? 'Ctrl+G AI 辅助 · ' : '', "Enter", ' ', selected === fields.length - 1 ? '提交' : '下一项', " \u00B7 Esc \u53D6\u6D88"] })) })] }));
113
+ }
@@ -0,0 +1,44 @@
1
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
+ import { Box, Text, useInput, useWindowSize } from 'ink';
3
+ import { theme, WIDE_BREAKPOINT } from '../theme.js';
4
+ const GLOBAL_KEYS = [
5
+ { keys: '1 / 2 / Tab', desc: '切换 Commands / Decisions' },
6
+ { keys: 'S', desc: '手动同步私有 GitHub 命令库和决策库' },
7
+ { keys: 'Ctrl+K / P', desc: '跨模块全局实时搜索' },
8
+ { keys: 'Ctrl+E', desc: '配置 AI 助手' },
9
+ { keys: '↑ ↓ / j k', desc: '上下选择(g / G 跳首末项)' },
10
+ { keys: '→ / ←', desc: '窄屏进入详情 / 返回列表' },
11
+ { keys: 'Esc', desc: '返回 / 清空筛选(不退出程序)' },
12
+ { keys: '? / q', desc: '快捷键帮助 / 退出 Praxo' },
13
+ ];
14
+ const COMMAND_KEYS = [
15
+ { keys: 'Enter / y', desc: '渲染变量并复制到剪贴板' },
16
+ { keys: 'r / Ctrl+R', desc: '打开确认并在子进程执行' },
17
+ { keys: '/ · f', desc: '展开实时搜索 / 条件筛选' },
18
+ { keys: 'a / n', desc: '新增命令' },
19
+ { keys: 'A / I', desc: '生成命令草稿 / 解释详情中的命令' },
20
+ { keys: 'e / d', desc: '编辑命令 / 删除命令(亦支持 Del)' },
21
+ { keys: 't / l', desc: '管理标签 / 关联决策' },
22
+ ];
23
+ const DECISION_KEYS = [
24
+ { keys: 'Enter', desc: '查看决策详情' },
25
+ { keys: 'r / h', desc: '对比复盘(当时 vs 现在)/ 历史' },
26
+ { keys: 's', desc: '打开决策与使用统计看板' },
27
+ { keys: 'I / Ctrl+G', desc: 'AI 质疑或总结 / 在复盘表单生成建议' },
28
+ { keys: '/ · f', desc: '展开实时搜索 / 条件筛选' },
29
+ { keys: 'a / n / e / d', desc: '新增 / 编辑 / 删除决策' },
30
+ { keys: 't / l', desc: '管理标签 / 关联命令' },
31
+ ];
32
+ /** 渲染紧凑且不压缩重叠的快捷键分组。 */
33
+ function SectionBlock({ title, items }) {
34
+ return (_jsxs(Box, { flexDirection: "column", flexShrink: 0, children: [_jsx(Text, { bold: true, color: theme.accent, children: title }), _jsx(Box, { flexDirection: "column", marginTop: 1, flexShrink: 0, children: items.map((item) => (_jsxs(Box, { gap: 2, flexShrink: 0, children: [_jsx(Box, { width: 14, flexShrink: 0, children: _jsx(Text, { bold: true, children: item.keys }) }), _jsx(Text, { wrap: "truncate-end", children: item.desc })] }, item.keys))) })] }));
35
+ }
36
+ /** 全局快捷键帮助浮层:宽屏双栏并排,对齐 lazygit / k9s / vim 国际键位规范。 */
37
+ export function HelpModal({ section, onClose }) {
38
+ const wide = useWindowSize().columns >= WIDE_BREAKPOINT;
39
+ useInput((input, key) => {
40
+ if (key.escape || input === '?' || input.toLowerCase() === 'q')
41
+ onClose();
42
+ });
43
+ return (_jsxs(Box, { flexDirection: "column", flexShrink: 0, borderStyle: "round", borderColor: theme.borderActive, paddingX: 2, paddingY: 1, children: [_jsxs(Box, { justifyContent: "space-between", flexShrink: 0, marginBottom: 1, children: [_jsx(Text, { bold: true, color: theme.brand, children: "Praxo \u5FEB\u6377\u952E\u6307\u5357" }), _jsx(Text, { dimColor: true, children: "\u6309 ? \u6216 Esc \u5173\u95ED" })] }), _jsxs(Box, { flexDirection: wide ? 'row' : 'column', gap: wide ? 4 : 1, flexShrink: 0, children: [_jsx(Box, { width: wide ? '48%' : '100%', flexShrink: 0, children: _jsx(SectionBlock, { title: "\u5168\u5C40\u5BFC\u822A", items: GLOBAL_KEYS }) }), _jsx(Box, { width: wide ? '50%' : '100%', flexShrink: 0, children: _jsx(SectionBlock, { title: section === 'commands' ? 'Command Vault' : 'Decision Log', items: section === 'commands' ? COMMAND_KEYS : DECISION_KEYS }) })] }), _jsx(Box, { marginTop: 1, flexShrink: 0, children: _jsx(Text, { dimColor: true, children: "\u8868\u5355\u5185\u652F\u6301 \u2191/\u2193/Tab \u5207\u6362\u5B57\u6BB5 \u00B7 Ctrl+S \u76F4\u63A5\u4FDD\u5B58 \u00B7 Ctrl+C \u968F\u65F6\u9000\u51FA" }) })] }));
44
+ }
@@ -0,0 +1,28 @@
1
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
+ import { Box, Text, useInput, useWindowSize } from 'ink';
3
+ import { useState } from 'react';
4
+ import { theme } from '../theme.js';
5
+ /** 可滚动只读查看面板,用于命令输出、复盘历史与统计信息展示。 */
6
+ export function Inspection({ title, lines, onClose, action, }) {
7
+ const { rows } = useWindowSize();
8
+ const [offset, setOffset] = useState(0);
9
+ const count = Math.max(3, rows - 9);
10
+ const maxOffset = Math.max(0, lines.length - count);
11
+ useInput((input, key) => {
12
+ if (action && input === action.key && !key.ctrl && !key.meta)
13
+ action.run();
14
+ if (key.escape || key.leftArrow || input.toLowerCase() === 'q')
15
+ onClose();
16
+ if (key.upArrow || input === 'k')
17
+ setOffset((current) => Math.max(0, current - 1));
18
+ if (key.downArrow || input === 'j')
19
+ setOffset((current) => Math.min(maxOffset, current + 1));
20
+ if (key.pageUp)
21
+ setOffset((current) => Math.max(0, current - count));
22
+ if (key.pageDown)
23
+ setOffset((current) => Math.min(maxOffset, current + count));
24
+ });
25
+ const end = Math.min(lines.length, offset + count);
26
+ const rangeText = lines.length ? `${offset + 1}-${end} / ${lines.length}` : '0';
27
+ return (_jsxs(Box, { flexDirection: "column", borderStyle: "round", borderColor: theme.borderActive, paddingX: 2, paddingY: 1, children: [_jsxs(Box, { justifyContent: "space-between", marginBottom: 1, children: [_jsx(Text, { bold: true, color: theme.accent, children: title }), _jsx(Text, { dimColor: true, children: rangeText })] }), lines.slice(offset, offset + count).map((line, index) => (_jsx(Text, { wrap: "truncate-end", children: line || ' ' }, offset + index))), _jsx(Box, { marginTop: 1, children: _jsxs(Text, { dimColor: true, children: [action ? action.key + ' ' + action.label + ' · ' : '', "\u2191 \u2193 / j k / PgUp PgDn \u6EDA\u52A8 \u00B7 Esc / Q \u8FD4\u56DE"] }) })] }));
28
+ }
@@ -0,0 +1,7 @@
1
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
+ import { Box, Text } from 'ink';
3
+ import { theme } from '../theme.js';
4
+ /** 极简克制的底部状态栏:flexShrink=0 锁定 2 行高度,防止与内容重叠。 */
5
+ export function KeyHints({ items, status, }) {
6
+ return (_jsxs(Box, { flexShrink: 0, paddingX: 2, justifyContent: "space-between", gap: 2, borderStyle: "single", borderTop: true, borderBottom: false, borderLeft: false, borderRight: false, borderColor: theme.border, borderDimColor: true, children: [_jsx(Box, { gap: 2, flexWrap: "nowrap", overflow: "hidden", children: items.map((item) => (_jsxs(Box, { gap: 1, flexShrink: 0, children: [_jsx(Text, { dimColor: true, bold: true, children: item.key }), _jsx(Text, { dimColor: true, children: item.label })] }, item.key + item.label))) }), status && (_jsxs(Text, { color: status.error ? theme.danger : theme.success, wrap: "truncate-end", children: [status.error ? '✖ ' : '✔ ', status.text] }))] }));
7
+ }
@@ -0,0 +1,31 @@
1
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
+ import { TextInput } from '@inkjs/ui';
3
+ import { Box, Text, useInput } from 'ink';
4
+ import { theme } from '../theme.js';
5
+ /**
6
+ * 国际标准模式化搜索栏:
7
+ * - 搜索态(active=true):展开 `❯` 实时输入行,边输入边过滤下方列表;
8
+ * - 浏览态(active=false):仅当存在已生效的搜索词或筛选条件时显示紧凑状态条,否则仅渲染一条极简细分隔线,不伪装成输入框。
9
+ */
10
+ export function SearchInput({ value, session, active, activePlaceholder = '输入关键词实时筛选…', filters, count, onChange, onSubmit, onCancel, onMove, }) {
11
+ useInput((_input, key) => {
12
+ if (key.escape) {
13
+ onCancel();
14
+ return;
15
+ }
16
+ if (key.upArrow)
17
+ onMove?.(-1);
18
+ if (key.downArrow)
19
+ onMove?.(1);
20
+ }, { isActive: active });
21
+ // 搜索态:展开完整的实时输入行
22
+ if (active) {
23
+ return (_jsxs(Box, { flexShrink: 0, paddingX: 2, justifyContent: "space-between", gap: 2, borderStyle: "single", borderTop: true, borderBottom: true, borderLeft: false, borderRight: false, borderColor: theme.accent, children: [_jsxs(Box, { gap: 1, flexGrow: 1, flexShrink: 1, children: [_jsx(Text, { bold: true, color: theme.accent, children: "\u276F" }), _jsx(TextInput, { defaultValue: value, placeholder: activePlaceholder, onChange: onChange, onSubmit: onSubmit }, session)] }), _jsxs(Box, { gap: 2, flexShrink: 0, children: [filters && _jsx(Text, { color: theme.info, children: filters }), count !== undefined && _jsxs(Text, { dimColor: true, children: [count, " \u9879"] })] })] }));
24
+ }
25
+ // 浏览态且存在激活条件:紧凑展示当前过滤摘要
26
+ if (value || filters) {
27
+ return (_jsxs(Box, { flexShrink: 0, paddingX: 2, justifyContent: "space-between", gap: 2, borderStyle: "single", borderTop: true, borderBottom: true, borderLeft: false, borderRight: false, borderColor: theme.border, borderDimColor: true, children: [_jsxs(Box, { gap: 2, flexShrink: 1, children: [value && (_jsxs(Text, { color: theme.accent, wrap: "truncate-end", children: ["/ ", value] })), filters && (_jsx(Text, { color: theme.info, wrap: "truncate-end", children: filters }))] }), _jsx(Text, { dimColor: true, children: "Esc \u6E05\u7A7A" })] }));
28
+ }
29
+ // 浏览态无条件:仅保留一条克制的顶栏细分隔线,避免“看着像输入框却不能直接打字”的错觉
30
+ return (_jsx(Box, { flexShrink: 0, borderStyle: "single", borderTop: true, borderBottom: false, borderLeft: false, borderRight: false, borderColor: theme.border, borderDimColor: true }));
31
+ }
@@ -0,0 +1,93 @@
1
+ import { jsxs as _jsxs, jsx as _jsx } from "react/jsx-runtime";
2
+ import { Box, Text, useInput } from 'ink';
3
+ import { useEffect, useRef, useState } from 'react';
4
+ import { messageOf } from '../../shared/errors.js';
5
+ import { Confirm } from './Confirm.js';
6
+ export function useSyncPanel(sync, onChange) {
7
+ const [panel, setPanel] = useState();
8
+ const [status, setStatus] = useState();
9
+ const running = useRef(false);
10
+ const reply = useRef(undefined);
11
+ useEffect(() => () => reply.current?.(false), []);
12
+ async function start() {
13
+ if (running.current)
14
+ return;
15
+ try {
16
+ const state = sync.status();
17
+ if (state.status === 'Unconfigured')
18
+ return;
19
+ if (state.status === 'Conflict') {
20
+ setPanel({ type: 'conflict', conflicts: sync.conflicts() });
21
+ return;
22
+ }
23
+ running.current = true;
24
+ setStatus('Syncing');
25
+ const result = await sync.run({
26
+ approve: (findings) => new Promise((resolve) => {
27
+ reply.current = resolve;
28
+ setPanel({ type: 'confirm', findings, reply: resolve });
29
+ }),
30
+ });
31
+ setPanel(result.status === 'Conflict'
32
+ ? { type: 'conflict', conflicts: result.conflicts }
33
+ : undefined);
34
+ setStatus(result.status === 'Blocked' ? 'Blocked · pxo sync --dry-run' : undefined);
35
+ onChange();
36
+ }
37
+ catch (error) {
38
+ setStatus('Error · ' + messageOf(error));
39
+ }
40
+ finally {
41
+ running.current = false;
42
+ reply.current = undefined;
43
+ }
44
+ }
45
+ return {
46
+ panel,
47
+ status,
48
+ start,
49
+ isRunning: () => running.current,
50
+ close() {
51
+ if (panel?.type === 'confirm')
52
+ panel.reply(false);
53
+ setPanel(undefined);
54
+ },
55
+ choose(id, side) {
56
+ sync.resolve(id, side);
57
+ const conflicts = sync.conflicts();
58
+ if (conflicts.every(({ choice }) => choice)) {
59
+ setPanel(undefined);
60
+ setStatus('Pending · S 重试');
61
+ }
62
+ else
63
+ setPanel({ type: 'conflict', conflicts });
64
+ },
65
+ };
66
+ }
67
+ export function SyncPanel({ controller }) {
68
+ const [error, setError] = useState();
69
+ const { panel } = controller;
70
+ const current = panel?.type === 'conflict' ? panel.conflicts.find(({ choice }) => !choice) : undefined;
71
+ useInput((input, key) => {
72
+ if (key.escape)
73
+ controller.close();
74
+ if (!current || key.ctrl || key.meta)
75
+ return;
76
+ const normalized = input.toLowerCase();
77
+ const side = normalized === 'l' ? 'local' : normalized === 'r' ? 'remote' : undefined;
78
+ if (!side)
79
+ return;
80
+ try {
81
+ controller.choose(current.id, side);
82
+ setError(undefined);
83
+ }
84
+ catch (caught) {
85
+ setError(messageOf(caught));
86
+ }
87
+ }, { isActive: panel?.type === 'conflict' });
88
+ if (!panel)
89
+ return null;
90
+ if (panel.type === 'confirm')
91
+ return (_jsx(Confirm, { title: "\u540C\u6B65\u524D\u786E\u8BA4\u7591\u4F3C\u654F\u611F\u5185\u5BB9", tone: "danger", onAccept: () => panel.reply(true), onCancel: controller.close, children: panel.findings.slice(0, 6).map(({ record, field }) => (_jsxs(Text, { children: [record, " \u00B7 ", field] }, record + field))) }));
92
+ return (_jsxs(Box, { flexDirection: "column", paddingX: 2, paddingY: 1, children: [_jsxs(Text, { bold: true, children: ["\u540C\u6B65\u51B2\u7A81 \u00B7 ", panel.conflicts.filter(({ choice }) => !choice).length, " \u5F85\u5904\u7406"] }), current && (_jsxs(Text, { children: [current.record, " \u00B7 ", current.kind] })), current && _jsxs(Text, { wrap: "truncate-end", children: ["\u672C\u673A \u00B7 ", current.local] }), current && _jsxs(Text, { wrap: "truncate-end", children: ["\u8FDC\u7AEF \u00B7 ", current.remote] }), error && _jsx(Text, { color: "red", children: error }), _jsx(Text, { dimColor: true, children: "L \u4FDD\u7559\u672C\u673A \u00B7 R \u4FDD\u7559\u8FDC\u7AEF \u00B7 Esc \u5173\u95ED" })] }));
93
+ }
@@ -0,0 +1,18 @@
1
+ import { jsx as _jsx } from "react/jsx-runtime";
2
+ import { render } from 'ink';
3
+ import { Workspace } from './Workspace.js';
4
+ /** 启动全屏交互式 TUI,开启增量渲染与备用屏避免闪烁和污染终端历史。 */
5
+ export async function launchTui(app, initial) {
6
+ const handle = render(_jsx(Workspace, { app: app, initial: initial }), {
7
+ exitOnCtrlC: false,
8
+ interactive: true,
9
+ incrementalRendering: true,
10
+ alternateScreen: true,
11
+ });
12
+ try {
13
+ await handle.waitUntilExit();
14
+ }
15
+ finally {
16
+ handle.unmount();
17
+ }
18
+ }