@youweichen/pi-web-ui 0.45.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/LICENSE +21 -0
- package/README.md +45 -0
- package/bin/pi-web-ui.mjs +1818 -0
- package/deploy/com.xingshuyin.pi-web-ui.plist +48 -0
- package/deploy/nginx-subpath.conf +88 -0
- package/deploy/pi-web-ui-task.xml +71 -0
- package/deploy/pi-web-ui.service +31 -0
- package/dist/server/agent-service.js +2975 -0
- package/dist/server/attachments.js +672 -0
- package/dist/server/bg-servers.js +150 -0
- package/dist/server/client-state.js +234 -0
- package/dist/server/control-socket.js +177 -0
- package/dist/server/ensure-bash.js +80 -0
- package/dist/server/files-service.js +709 -0
- package/dist/server/goal-service.js +869 -0
- package/dist/server/index.js +879 -0
- package/dist/server/mcp-bridge.js +268 -0
- package/dist/server/model-admin.js +821 -0
- package/dist/server/patch-node-pty.js +80 -0
- package/dist/server/plugin-facilities.js +299 -0
- package/dist/server/plugin-updater.js +226 -0
- package/dist/server/plugins.js +893 -0
- package/dist/server/process-utils.js +112 -0
- package/dist/server/protocol-version.js +11 -0
- package/dist/server/protocol.js +6 -0
- package/dist/server/scm.js +298 -0
- package/dist/server/serialize.js +172 -0
- package/dist/server/settings-service.js +395 -0
- package/dist/server/slash-commands.js +263 -0
- package/dist/server/terminals.js +1372 -0
- package/dist/server/text-sniff.js +268 -0
- package/dist/server/uploads.js +107 -0
- package/dist/server/vision-bridge.js +131 -0
- package/dist/server/webui-context.js +222 -0
- package/extensions/webui.ts +192 -0
- package/package.json +99 -0
- package/web/dist/assets/TerminalPanel-6GBZ9nXN.css +32 -0
- package/web/dist/assets/TerminalPanel-D4AktsEn.js +2 -0
- package/web/dist/assets/abnfDiagram-VCTEODGH-Ct5StJwt.js +1 -0
- package/web/dist/assets/arc-pkuxEN8A.js +1 -0
- package/web/dist/assets/architectureDiagram-5GKGNRK7-C6P6yn4y.js +36 -0
- package/web/dist/assets/blockDiagram-I7D4REHJ-BmgfH1jt.js +129 -0
- package/web/dist/assets/c4Diagram-7LVT6UL2-CgmwTFsK.js +38 -0
- package/web/dist/assets/channel-0Y__6sq2.js +1 -0
- package/web/dist/assets/chunk-2Q5K7J3B-DX_NqAiH.js +1 -0
- package/web/dist/assets/chunk-5VM5RSS4-gLeuQuYv.js +15 -0
- package/web/dist/assets/chunk-F27PBJKO-D4WX4mhI.js +1 -0
- package/web/dist/assets/chunk-IMKFNOWR-DBpDxGQD.js +231 -0
- package/web/dist/assets/chunk-JWPE2WC7-DIQ8iZN5.js +1 -0
- package/web/dist/assets/chunk-POPQ4Y6H-F_YTNoGz.js +1 -0
- package/web/dist/assets/chunk-SVP7TREG-CmDIvX-r.js +88 -0
- package/web/dist/assets/chunk-TICWLB2K-BQUzHQyS.js +206 -0
- package/web/dist/assets/chunk-XXDRQBXY-DqR9iffH.js +1 -0
- package/web/dist/assets/classDiagram-ZZMXUADV-BEfGIpzu.js +1 -0
- package/web/dist/assets/classDiagram-v2-VYDZK3BY-BEfGIpzu.js +1 -0
- package/web/dist/assets/cose-bilkent-JH36ORCC-Dl67W4Dx.js +1 -0
- package/web/dist/assets/cynefin-OW5HDTMX-fWdqaCpX.js +178 -0
- package/web/dist/assets/cynefinDiagram-5FMLGOSQ-CSUAXbaP.js +62 -0
- package/web/dist/assets/cytoscape.esm-Bch-eiPH.js +331 -0
- package/web/dist/assets/dagre-GXQ25YYZ-CqUVwu1X.js +4 -0
- package/web/dist/assets/defaultLocale-DX6XiGOO.js +1 -0
- package/web/dist/assets/diagram-S7CK7UJ4-bRce-WYV.js +30 -0
- package/web/dist/assets/diagram-UQ7AKVKN-CiqPtPBE.js +41 -0
- package/web/dist/assets/diagram-VSXAHHWV-CbEA05LX.js +3 -0
- package/web/dist/assets/diagram-VX7I27RA-CRcY9MD-.js +24 -0
- package/web/dist/assets/diagram-Z3DM3KII-DmTwvZdS.js +24 -0
- package/web/dist/assets/ebnfDiagram-PWID7BFC-DbwmiGVj.js +1 -0
- package/web/dist/assets/erDiagram-RLTQ6QDP-Cxiaf87y.js +99 -0
- package/web/dist/assets/flowDiagram-HODETNUW-BQiecP1I.js +168 -0
- package/web/dist/assets/ganttDiagram-EL5Y4UJY-CSr8RRNw.js +292 -0
- package/web/dist/assets/gitGraphDiagram-WWUBYQGX-C4Tdis3g.js +106 -0
- package/web/dist/assets/index-CniHcFxT.js +22 -0
- package/web/dist/assets/index-DYz2iP_B.css +10 -0
- package/web/dist/assets/infoDiagram-27XIBGKW-ij_5A0pY.js +2 -0
- package/web/dist/assets/init-Gi6I4Gst.js +1 -0
- package/web/dist/assets/ishikawaDiagram-5VMMS53U-C8-tm2LV.js +70 -0
- package/web/dist/assets/journeyDiagram-3NMN7TZE-ZJedkNel.js +139 -0
- package/web/dist/assets/kanban-definition-UXKFOSKX-BEuoM53n.js +89 -0
- package/web/dist/assets/katex-C5jXJg4s.js +257 -0
- package/web/dist/assets/layout-zq_9DigZ.js +1 -0
- package/web/dist/assets/linear-D-QXJ5Wc.js +1 -0
- package/web/dist/assets/markdown-CUPbftfV.js +51 -0
- package/web/dist/assets/mermaid.core-CCiG-bOm.js +312 -0
- package/web/dist/assets/mindmap-definition-YA3MSWOX-VaAisUIe.js +96 -0
- package/web/dist/assets/ordinal-Cboi1Yqb.js +1 -0
- package/web/dist/assets/pegDiagram-XKGWAZYB-D5vmRtkn.js +1 -0
- package/web/dist/assets/pieDiagram-E7YTZNPT-loD6V8fn.js +39 -0
- package/web/dist/assets/quadrantDiagram-AXDQQJYC-B7E4mH1-.js +7 -0
- package/web/dist/assets/railroadDiagram-O6MQD6OU-DTALHvDa.js +1 -0
- package/web/dist/assets/react-ZkKJMDQQ.js +24 -0
- package/web/dist/assets/requirementDiagram-BXWQKSXE-ZjJKuEcR.js +84 -0
- package/web/dist/assets/sankeyDiagram-P5KCCOFB-DufTudDP.js +40 -0
- package/web/dist/assets/sequenceDiagram-WJ2MYXX4-B-Zk4alI.js +162 -0
- package/web/dist/assets/sizeCapture-INFHLROL-B1pjlxXN.js +1 -0
- package/web/dist/assets/stateDiagram-D77RDMKH-BeWg6PIR.js +1 -0
- package/web/dist/assets/stateDiagram-v2-MP3YSRHH-DagWhIFJ.js +1 -0
- package/web/dist/assets/swimlanes-42K2YHIH-4J4jmMmO.js +1 -0
- package/web/dist/assets/swimlanesDiagram-VR7AAH4N-Dsi9x540.js +8 -0
- package/web/dist/assets/timeline-definition-24CTP7MA-ByqLfxqe.js +120 -0
- package/web/dist/assets/vennDiagram-4TSXK5OY-B_EqVW4R.js +34 -0
- package/web/dist/assets/wardleyDiagram-VM6X3IG4-Bu7sA6F8.js +78 -0
- package/web/dist/assets/xterm-D1D2FVe3.js +38 -0
- package/web/dist/assets/xychartDiagram-S5SC5T6Z-w1KPVGKk.js +7 -0
- package/web/dist/favicon.svg +8 -0
- package/web/dist/fonts/ibm-plex-mono/ibm-plex-mono-latin-400-normal.woff2 +0 -0
- package/web/dist/fonts/ibm-plex-mono/ibm-plex-mono-latin-500-normal.woff2 +0 -0
- package/web/dist/fonts/ibm-plex-mono/ibm-plex-mono-latin-600-normal.woff2 +0 -0
- package/web/dist/fonts/ibm-plex-mono/ibm-plex-mono-latin-ext-400-normal.woff2 +0 -0
- package/web/dist/fonts/ibm-plex-mono/ibm-plex-mono-latin-ext-500-normal.woff2 +0 -0
- package/web/dist/fonts/ibm-plex-mono/ibm-plex-mono-latin-ext-600-normal.woff2 +0 -0
- package/web/dist/fonts/inter/inter-latin-400-normal.woff2 +0 -0
- package/web/dist/fonts/inter/inter-latin-500-normal.woff2 +0 -0
- package/web/dist/fonts/inter/inter-latin-600-normal.woff2 +0 -0
- package/web/dist/fonts/inter/inter-latin-700-normal.woff2 +0 -0
- package/web/dist/fonts/inter/inter-latin-800-normal.woff2 +0 -0
- package/web/dist/fonts/inter/inter-latin-ext-400-normal.woff2 +0 -0
- package/web/dist/fonts/inter/inter-latin-ext-500-normal.woff2 +0 -0
- package/web/dist/fonts/inter/inter-latin-ext-600-normal.woff2 +0 -0
- package/web/dist/fonts/inter/inter-latin-ext-700-normal.woff2 +0 -0
- package/web/dist/fonts/inter/inter-latin-ext-800-normal.woff2 +0 -0
- package/web/dist/icon.ico +0 -0
- package/web/dist/index.html +17 -0
- package/web/public/favicon.svg +8 -0
- package/web/public/fonts/ibm-plex-mono/ibm-plex-mono-latin-400-normal.woff2 +0 -0
- package/web/public/fonts/ibm-plex-mono/ibm-plex-mono-latin-500-normal.woff2 +0 -0
- package/web/public/fonts/ibm-plex-mono/ibm-plex-mono-latin-600-normal.woff2 +0 -0
- package/web/public/fonts/ibm-plex-mono/ibm-plex-mono-latin-ext-400-normal.woff2 +0 -0
- package/web/public/fonts/ibm-plex-mono/ibm-plex-mono-latin-ext-500-normal.woff2 +0 -0
- package/web/public/fonts/ibm-plex-mono/ibm-plex-mono-latin-ext-600-normal.woff2 +0 -0
- package/web/public/fonts/inter/inter-latin-400-normal.woff2 +0 -0
- package/web/public/fonts/inter/inter-latin-500-normal.woff2 +0 -0
- package/web/public/fonts/inter/inter-latin-600-normal.woff2 +0 -0
- package/web/public/fonts/inter/inter-latin-700-normal.woff2 +0 -0
- package/web/public/fonts/inter/inter-latin-800-normal.woff2 +0 -0
- package/web/public/fonts/inter/inter-latin-ext-400-normal.woff2 +0 -0
- package/web/public/fonts/inter/inter-latin-ext-500-normal.woff2 +0 -0
- package/web/public/fonts/inter/inter-latin-ext-600-normal.woff2 +0 -0
- package/web/public/fonts/inter/inter-latin-ext-700-normal.woff2 +0 -0
- package/web/public/fonts/inter/inter-latin-ext-800-normal.woff2 +0 -0
- package/web/public/icon.ico +0 -0
|
@@ -0,0 +1,222 @@
|
|
|
1
|
+
const WIDGET_WIDTH = 80;
|
|
2
|
+
/** ANSI 转义序列(CSI + OSC 两类):扩展 widget/status 文本里常混有 TUI 颜色码
|
|
3
|
+
* (如 pi-powerline-footer),浏览器会把它渲染成字面 `[38;5;244m` 乱码(issue #16)。 */
|
|
4
|
+
const ANSI_RE = /\[[0-9:;<=>?]*[ -/]*[@-~]|\][^\u0007\u001b]*(?:\u0007|\u001b\\)/g;
|
|
5
|
+
/** Strip all ANSI escape sequences (CSI/OSC) from a string. */
|
|
6
|
+
export function stripAnsi(s) {
|
|
7
|
+
return s.replace(ANSI_RE, "");
|
|
8
|
+
}
|
|
9
|
+
/** Mock theme: TUI color functions degrade to identity so widget text survives. */
|
|
10
|
+
const mockTheme = new Proxy({
|
|
11
|
+
fg: (_color, text) => text,
|
|
12
|
+
bold: (text) => text,
|
|
13
|
+
strikethrough: (text) => text,
|
|
14
|
+
dim: (text) => text,
|
|
15
|
+
}, {
|
|
16
|
+
get(target, prop) {
|
|
17
|
+
if (prop in target)
|
|
18
|
+
return target[prop];
|
|
19
|
+
// Unknown theme methods → no-op passthrough.
|
|
20
|
+
return (_arg, text) => text !== undefined ? text : "";
|
|
21
|
+
},
|
|
22
|
+
});
|
|
23
|
+
/** Mock TUI: any method call is a safe no-op. */
|
|
24
|
+
const mockTui = new Proxy({
|
|
25
|
+
requestRender: () => { },
|
|
26
|
+
render: () => { },
|
|
27
|
+
}, {
|
|
28
|
+
get(target, prop) {
|
|
29
|
+
if (prop in target)
|
|
30
|
+
return target[prop];
|
|
31
|
+
return () => { };
|
|
32
|
+
},
|
|
33
|
+
});
|
|
34
|
+
/**
|
|
35
|
+
* Implements the subset of ExtensionUIContext that makes sense for a web UI.
|
|
36
|
+
* TUI-only affordances (select/confirm/input dialogs, terminal input, custom
|
|
37
|
+
* footer) are inert: dialogs resolve to cancellation instead of blocking.
|
|
38
|
+
*/
|
|
39
|
+
export class WebUIContext {
|
|
40
|
+
theme = mockTheme;
|
|
41
|
+
widgets = new Map();
|
|
42
|
+
lastLines = new Map();
|
|
43
|
+
emit;
|
|
44
|
+
constructor(emit) {
|
|
45
|
+
this.emit = emit;
|
|
46
|
+
}
|
|
47
|
+
// -- widgets -------------------------------------------------------------
|
|
48
|
+
/** Matches ExtensionUIContext's overloaded setWidget exactly. */
|
|
49
|
+
setWidget = (key, content, options) => {
|
|
50
|
+
void options;
|
|
51
|
+
if (content === undefined) {
|
|
52
|
+
this.widgets.delete(key);
|
|
53
|
+
this.lastLines.delete(key);
|
|
54
|
+
this.push();
|
|
55
|
+
return;
|
|
56
|
+
}
|
|
57
|
+
if (typeof content === "function") {
|
|
58
|
+
let comp;
|
|
59
|
+
try {
|
|
60
|
+
// Mock TUI/theme: extensions only read a handful of theme helpers;
|
|
61
|
+
// everything else is a no-op, so the widget renders to plain text.
|
|
62
|
+
comp = content(mockTui, mockTheme);
|
|
63
|
+
}
|
|
64
|
+
catch {
|
|
65
|
+
comp = undefined;
|
|
66
|
+
}
|
|
67
|
+
this.widgets.set(key, {
|
|
68
|
+
render: (w) => comp?.render?.(w),
|
|
69
|
+
dispose: comp?.dispose,
|
|
70
|
+
});
|
|
71
|
+
}
|
|
72
|
+
else {
|
|
73
|
+
this.widgets.set(key, { render: () => content });
|
|
74
|
+
}
|
|
75
|
+
this.push();
|
|
76
|
+
};
|
|
77
|
+
/** Re-render all widgets and push when content changed (polled + on demand). */
|
|
78
|
+
refresh() {
|
|
79
|
+
let changed = false;
|
|
80
|
+
for (const [key, w] of this.widgets) {
|
|
81
|
+
let lines;
|
|
82
|
+
try {
|
|
83
|
+
lines = w.render(WIDGET_WIDTH);
|
|
84
|
+
}
|
|
85
|
+
catch {
|
|
86
|
+
lines = undefined;
|
|
87
|
+
}
|
|
88
|
+
const prev = this.lastLines.get(key);
|
|
89
|
+
if (JSON.stringify(lines ?? null) !== JSON.stringify(prev ?? null)) {
|
|
90
|
+
this.lastLines.set(key, lines ?? []);
|
|
91
|
+
changed = true;
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
if (changed)
|
|
95
|
+
this.push();
|
|
96
|
+
}
|
|
97
|
+
push() {
|
|
98
|
+
const widgets = this.snapshot();
|
|
99
|
+
this.emit({ type: "widgets", widgets });
|
|
100
|
+
}
|
|
101
|
+
/** Render all widgets to their current text lines (without emitting). */
|
|
102
|
+
snapshot() {
|
|
103
|
+
return [...this.widgets.entries()].map(([key, w]) => {
|
|
104
|
+
let lines;
|
|
105
|
+
try {
|
|
106
|
+
lines = w.render(WIDGET_WIDTH);
|
|
107
|
+
}
|
|
108
|
+
catch {
|
|
109
|
+
lines = undefined;
|
|
110
|
+
}
|
|
111
|
+
// 浏览器不是终端:ANSI 颜色码剥掉再下发/比对(issue #16)。
|
|
112
|
+
const clean = lines?.map(stripAnsi) ?? undefined;
|
|
113
|
+
this.lastLines.set(key, clean ?? []);
|
|
114
|
+
return { key, lines: clean ?? [] };
|
|
115
|
+
});
|
|
116
|
+
}
|
|
117
|
+
// -- notifications --------------------------------------------------------
|
|
118
|
+
notify(message, type) {
|
|
119
|
+
this.emit({ type: "notice", level: type ?? "info", text: message });
|
|
120
|
+
}
|
|
121
|
+
// -- footer status (pi-lens "LSP Inactive", pi-cache-optimizer cache stats) --
|
|
122
|
+
statuses = new Map();
|
|
123
|
+
setStatus(key, text) {
|
|
124
|
+
if (text === undefined || text === "") {
|
|
125
|
+
this.statuses.delete(key);
|
|
126
|
+
}
|
|
127
|
+
else {
|
|
128
|
+
// 入口处剥 ANSI:pushStatuses / statusSnapshot 两条路径都拿到干净文本。
|
|
129
|
+
const clean = stripAnsi(text);
|
|
130
|
+
if (clean === "")
|
|
131
|
+
this.statuses.delete(key);
|
|
132
|
+
else
|
|
133
|
+
this.statuses.set(key, clean);
|
|
134
|
+
}
|
|
135
|
+
this.pushStatuses();
|
|
136
|
+
}
|
|
137
|
+
pushStatuses() {
|
|
138
|
+
this.emit({
|
|
139
|
+
type: "statuses",
|
|
140
|
+
statuses: [...this.statuses.entries()].map(([k, v]) => ({
|
|
141
|
+
key: k,
|
|
142
|
+
text: v,
|
|
143
|
+
})),
|
|
144
|
+
});
|
|
145
|
+
}
|
|
146
|
+
/** Current footer status entries (for replay on socket attach). */
|
|
147
|
+
statusSnapshot() {
|
|
148
|
+
return [...this.statuses.entries()].map(([k, v]) => ({ key: k, text: v }));
|
|
149
|
+
}
|
|
150
|
+
// -- dialogs (select/confirm/input bridged to the browser) ---------------
|
|
151
|
+
dialogSeq = 0;
|
|
152
|
+
pendingDialogs = new Map();
|
|
153
|
+
select = (title, options) => this.openDialog("select", title, [options]);
|
|
154
|
+
confirm = (title, message) => this.openDialog("confirm", title, [message]);
|
|
155
|
+
input = (title, placeholder) => this.openDialog("input", title, [placeholder ?? ""]);
|
|
156
|
+
openDialog(kind, title, args) {
|
|
157
|
+
return new Promise((resolve) => {
|
|
158
|
+
const id = ++this.dialogSeq;
|
|
159
|
+
this.pendingDialogs.set(id, resolve);
|
|
160
|
+
this.emit({ type: "dialog", id, kind, title, args });
|
|
161
|
+
});
|
|
162
|
+
}
|
|
163
|
+
/** Resolve a pending dialog with the user's choice (called from the client). */
|
|
164
|
+
resolveDialog(id, value) {
|
|
165
|
+
const resolve = this.pendingDialogs.get(id);
|
|
166
|
+
if (resolve) {
|
|
167
|
+
this.pendingDialogs.delete(id);
|
|
168
|
+
resolve(value);
|
|
169
|
+
this.emit({ type: "dialog_closed", id });
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
/** Close every pending dialog as cancelled (used when a goal wizard aborts —
|
|
173
|
+
* its unanswered browser dialogs must vanish, not linger). */
|
|
174
|
+
cancelPendingDialogs() {
|
|
175
|
+
for (const [id, resolve] of this.pendingDialogs) {
|
|
176
|
+
this.pendingDialogs.delete(id);
|
|
177
|
+
resolve(null);
|
|
178
|
+
this.emit({ type: "dialog_closed", id });
|
|
179
|
+
}
|
|
180
|
+
}
|
|
181
|
+
// -- inert TUI-only affordances ------------------------------------------
|
|
182
|
+
onTerminalInput = () => () => { };
|
|
183
|
+
setWorkingMessage = () => { };
|
|
184
|
+
setWorkingVisible = () => { };
|
|
185
|
+
setWorkingIndicator = () => { };
|
|
186
|
+
setHiddenThinkingLabel = () => { };
|
|
187
|
+
setFooter = () => { };
|
|
188
|
+
setHeader = () => { };
|
|
189
|
+
setTitle = () => { };
|
|
190
|
+
custom = (_factory, _done) => new Promise(() => { });
|
|
191
|
+
pasteToEditor = () => { };
|
|
192
|
+
setEditorText = () => { };
|
|
193
|
+
getEditorText = () => "";
|
|
194
|
+
editor = async () => undefined;
|
|
195
|
+
addAutocompleteProvider = () => { };
|
|
196
|
+
setEditorComponent = () => { };
|
|
197
|
+
getEditorComponent = () => undefined;
|
|
198
|
+
getAllThemes = () => [];
|
|
199
|
+
getTheme = () => undefined;
|
|
200
|
+
setTheme = () => ({ success: false });
|
|
201
|
+
getToolsExpanded = () => false;
|
|
202
|
+
setToolsExpanded = () => { };
|
|
203
|
+
/** Dispose all widgets (extension reload / session teardown). */
|
|
204
|
+
dispose() {
|
|
205
|
+
for (const w of this.widgets.values()) {
|
|
206
|
+
try {
|
|
207
|
+
w.dispose?.();
|
|
208
|
+
}
|
|
209
|
+
catch {
|
|
210
|
+
// best effort
|
|
211
|
+
}
|
|
212
|
+
}
|
|
213
|
+
this.widgets.clear();
|
|
214
|
+
this.lastLines.clear();
|
|
215
|
+
// Cancel any pending dialogs.
|
|
216
|
+
for (const [id, resolve] of this.pendingDialogs) {
|
|
217
|
+
resolve(null);
|
|
218
|
+
this.emit({ type: "dialog_closed", id });
|
|
219
|
+
}
|
|
220
|
+
this.pendingDialogs.clear();
|
|
221
|
+
}
|
|
222
|
+
}
|
|
@@ -0,0 +1,192 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* pi-web-ui 的 pi 扩展 —— 提供命令行集成。
|
|
3
|
+
*
|
|
4
|
+
* 能力:
|
|
5
|
+
* /webui 启动本机 pi-web-ui 服务器,打开浏览器访问
|
|
6
|
+
* /webui --port 9000 指定端口启动
|
|
7
|
+
* /webui --no-browser 启动但不开浏览器
|
|
8
|
+
* /webui stop 停止已启动的服务器
|
|
9
|
+
* /webui status 查看运行状态 / URL
|
|
10
|
+
*
|
|
11
|
+
* 实现说明:
|
|
12
|
+
* - 不依赖全局 bin(pi install 后 pi-web-ui 命令不一定在 PATH),直接用
|
|
13
|
+
* node 调包内 dist/server/index.js,通过环境变量 PORT / PI_WEB_CWD /
|
|
14
|
+
* PI_WEB_DATA_DIR 控制。
|
|
15
|
+
* - 工作目录默认用当前 pi 会话的 ctx.cwd;可用 --cwd / path 覆盖。
|
|
16
|
+
* - 服务器作为子进程后台运行,/webui 不阻塞 pi。
|
|
17
|
+
* - 每个 pi 会话管理一个子进程;session_shutdown 时清理,避免孤儿进程。
|
|
18
|
+
*/
|
|
19
|
+
|
|
20
|
+
import { spawn } from "node:child_process";
|
|
21
|
+
import { existsSync } from "node:fs";
|
|
22
|
+
import { dirname, join, resolve } from "node:path";
|
|
23
|
+
import { fileURLToPath } from "node:url";
|
|
24
|
+
import net from "node:net";
|
|
25
|
+
import type { ExtensionAPI, ExtensionCommandContext } from "@earendil-works/pi-coding-agent";
|
|
26
|
+
|
|
27
|
+
// 本文件位于 <pkg>/extensions/webui.ts → 包根在上一级
|
|
28
|
+
const PKG_ROOT = resolve(dirname(fileURLToPath(import.meta.url)), "..");
|
|
29
|
+
const SERVER_ENTRY = join(PKG_ROOT, "dist", "server", "index.js");
|
|
30
|
+
const NODE = process.execPath;
|
|
31
|
+
|
|
32
|
+
/** 每个会话的服务器子进程 + 元数据 */
|
|
33
|
+
interface RunningServer {
|
|
34
|
+
proc: ReturnType<typeof spawn>;
|
|
35
|
+
port: number;
|
|
36
|
+
cwd: string;
|
|
37
|
+
url: string;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
// 会话 → 运行实例(模块级 Map;每会话一个会话对象,无需清理全局)
|
|
41
|
+
const running = new Map<string, RunningServer>();
|
|
42
|
+
|
|
43
|
+
/** 找一个空闲端口 */
|
|
44
|
+
function findFreePort(from = 8787): Promise<number> {
|
|
45
|
+
return new Promise((resolve_, reject) => {
|
|
46
|
+
const srv = net.createServer();
|
|
47
|
+
srv.listen(from, () => {
|
|
48
|
+
const port = (srv.address() as net.AddressInfo).port;
|
|
49
|
+
srv.close(() => resolve_(port));
|
|
50
|
+
});
|
|
51
|
+
srv.on("error", () => {
|
|
52
|
+
// 端口被占则顺延
|
|
53
|
+
findFreePort(from + 1).then(resolve_, reject);
|
|
54
|
+
});
|
|
55
|
+
});
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
/** 解析 --key value / --flag 参数 */
|
|
59
|
+
function parseArgs(args: string): { port?: number; cwd?: string; noBrowser: boolean } {
|
|
60
|
+
const out: { port?: number; cwd?: string; noBrowser: boolean } = { noBrowser: false };
|
|
61
|
+
const toks = args.split(/\s+/).filter(Boolean);
|
|
62
|
+
for (let i = 0; i < toks.length; i++) {
|
|
63
|
+
const t = toks[i];
|
|
64
|
+
if ((t === "--port" || t === "-p") && toks[i + 1]) {
|
|
65
|
+
const n = Number(toks[++i]);
|
|
66
|
+
if (Number.isInteger(n) && n > 0 && n < 65536) out.port = n;
|
|
67
|
+
} else if ((t === "--cwd") && toks[i + 1]) {
|
|
68
|
+
out.cwd = resolve(toks[++i]);
|
|
69
|
+
} else if (t === "--no-browser") {
|
|
70
|
+
out.noBrowser = true;
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
return out;
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
/** 打开浏览器 */
|
|
77
|
+
async function openBrowser(url: string): Promise<void> {
|
|
78
|
+
const { platform } = process;
|
|
79
|
+
const [cmd, ...rest] =
|
|
80
|
+
platform === "darwin"
|
|
81
|
+
? ["open", url]
|
|
82
|
+
: platform === "win32"
|
|
83
|
+
? ["cmd", "/c", "start", "", url]
|
|
84
|
+
: ["xdg-open", url];
|
|
85
|
+
// 无界面环境缺少 xdg-open 等打开器时,ENOENT 以异步 'error' 事件触发,
|
|
86
|
+
// try/catch 拦不住会崩掉整个进程 —— 必须挂 error 监听。
|
|
87
|
+
spawn(cmd, rest, { stdio: "ignore", detached: true })
|
|
88
|
+
.on("error", (err) => {
|
|
89
|
+
if ((err as NodeJS.ErrnoException)?.code === "ENOENT") {
|
|
90
|
+
console.warn(
|
|
91
|
+
`[webui] 未找到浏览器打开器 (${(err as NodeJS.ErrnoException).path || "command not found"}),请用 --no-browser 关闭自动打开`
|
|
92
|
+
);
|
|
93
|
+
} else {
|
|
94
|
+
console.warn("[webui] 打开浏览器失败:", err.message);
|
|
95
|
+
}
|
|
96
|
+
})
|
|
97
|
+
.unref();
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
export default function (pi: ExtensionAPI): void {
|
|
101
|
+
pi.registerCommand("webui", {
|
|
102
|
+
description: "启动本机 pi-web-ui Web 界面(/webui [--port N] [--cwd PATH] [--no-browser] | stop | status)",
|
|
103
|
+
handler: async (args: string, ctx: ExtensionCommandContext) => {
|
|
104
|
+
const sid = ctx.sessionManager.getSessionId();
|
|
105
|
+
const opts = parseArgs(args);
|
|
106
|
+
const action = (args.split(/\s+/)[0] || "start").toLowerCase();
|
|
107
|
+
|
|
108
|
+
// 停止
|
|
109
|
+
if (action === "stop" || action === "kill") {
|
|
110
|
+
const inst = running.get(sid);
|
|
111
|
+
if (!inst) {
|
|
112
|
+
ctx.ui.notify("没有正在运行的本机 pi-web-ui 服务器", "info");
|
|
113
|
+
return;
|
|
114
|
+
}
|
|
115
|
+
inst.proc.kill("SIGTERM");
|
|
116
|
+
running.delete(sid);
|
|
117
|
+
ctx.ui.notify(`已停止 pi-web-ui (${inst.url})`, "info");
|
|
118
|
+
return;
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
// 状态
|
|
122
|
+
if (action === "status") {
|
|
123
|
+
const inst = running.get(sid);
|
|
124
|
+
if (!inst) {
|
|
125
|
+
ctx.ui.notify("本机 pi-web-ui 未运行", "info");
|
|
126
|
+
return;
|
|
127
|
+
}
|
|
128
|
+
const alive = inst.proc.exitCode === null;
|
|
129
|
+
ctx.ui.notify(
|
|
130
|
+
alive ? `pi-web-ui 运行中 → ${inst.url}\n端口 ${inst.port} · cwd ${inst.cwd}` : `已退出(exit=${inst.proc.exitCode})`,
|
|
131
|
+
alive ? "info" : "warning",
|
|
132
|
+
);
|
|
133
|
+
return;
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
// 默认 start
|
|
137
|
+
if (action !== "start" && action !== "run") {
|
|
138
|
+
ctx.ui.notify(`未知动作 ${action}(可用 start|stop|status)`, "warning");
|
|
139
|
+
return;
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
// 已运行则提示
|
|
143
|
+
const existing = running.get(sid);
|
|
144
|
+
if (existing && existing.proc.exitCode === null) {
|
|
145
|
+
ctx.ui.notify(`pi-web-ui 已在运行 → ${existing.url}`, "info");
|
|
146
|
+
return;
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
// 检查是否已构建
|
|
150
|
+
if (!existsSync(SERVER_ENTRY)) {
|
|
151
|
+
ctx.ui.notify(
|
|
152
|
+
"缺少 dist/ 产物(当前安装未包含已构建前端)。请运行 `npm run build` 后重试,或用 pi-web-ui 官方 npm 包。",
|
|
153
|
+
"warning",
|
|
154
|
+
);
|
|
155
|
+
return;
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
const port = opts.port ?? (await findFreePort());
|
|
159
|
+
const cwd = opts.cwd ?? ctx.cwd;
|
|
160
|
+
const url = `http://localhost:${port}`;
|
|
161
|
+
|
|
162
|
+
const env = {
|
|
163
|
+
...process.env,
|
|
164
|
+
PORT: String(port),
|
|
165
|
+
PI_WEB_CWD: cwd,
|
|
166
|
+
...(process.env.PI_WEB_DATA_DIR ? {} : { PI_WEB_DATA_DIR: join(cwd, ".pi-web") }),
|
|
167
|
+
};
|
|
168
|
+
const proc = spawn(NODE, [SERVER_ENTRY], { cwd, env, stdio: "ignore", detached: true });
|
|
169
|
+
proc.unref();
|
|
170
|
+
running.set(sid, { proc, port, cwd, url });
|
|
171
|
+
|
|
172
|
+
ctx.ui.notify(`pi-web-ui 启动中 → ${url}\n端口 ${port} · cwd ${cwd}\n(几秒后可用,/webui status 查看)`);
|
|
173
|
+
|
|
174
|
+
if (!opts.noBrowser) await openBrowser(url);
|
|
175
|
+
|
|
176
|
+
// 进程退出时清理
|
|
177
|
+
proc.on("exit", () => {
|
|
178
|
+
if (running.get(sid)?.proc === proc) running.delete(sid);
|
|
179
|
+
});
|
|
180
|
+
},
|
|
181
|
+
});
|
|
182
|
+
|
|
183
|
+
// 会话结束清理子进程,避免孤儿
|
|
184
|
+
pi.on("session_shutdown", async (_event, ctx) => {
|
|
185
|
+
const sid = ctx.sessionManager.getSessionId();
|
|
186
|
+
const inst = running.get(sid);
|
|
187
|
+
if (inst && inst.proc.exitCode === null) {
|
|
188
|
+
inst.proc.kill("SIGTERM");
|
|
189
|
+
running.delete(sid);
|
|
190
|
+
}
|
|
191
|
+
});
|
|
192
|
+
}
|
package/package.json
ADDED
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@youweichen/pi-web-ui",
|
|
3
|
+
"version": "0.45.0",
|
|
4
|
+
"description": "Web chat interface for the pi coding agent, powered by the pi SDK (@earendil-works/pi-coding-agent) — one-command run, Docker/systemd/launchd deployable",
|
|
5
|
+
"license": "MIT",
|
|
6
|
+
"author": {
|
|
7
|
+
"name": "youweichen",
|
|
8
|
+
"email": "youweichen0208@users.noreply.github.com"
|
|
9
|
+
},
|
|
10
|
+
"type": "module",
|
|
11
|
+
"bin": {
|
|
12
|
+
"pi-web-ui": "bin/pi-web-ui.mjs"
|
|
13
|
+
},
|
|
14
|
+
"files": [
|
|
15
|
+
"bin/",
|
|
16
|
+
"dist/",
|
|
17
|
+
"web/dist/",
|
|
18
|
+
"web/public/",
|
|
19
|
+
"deploy/",
|
|
20
|
+
"extensions/",
|
|
21
|
+
"README.md",
|
|
22
|
+
"LICENSE"
|
|
23
|
+
],
|
|
24
|
+
"keywords": [
|
|
25
|
+
"pi",
|
|
26
|
+
"pi-package",
|
|
27
|
+
"coding-agent",
|
|
28
|
+
"ai",
|
|
29
|
+
"chat",
|
|
30
|
+
"web-ui",
|
|
31
|
+
"terminal",
|
|
32
|
+
"llm"
|
|
33
|
+
],
|
|
34
|
+
"repository": {
|
|
35
|
+
"type": "git",
|
|
36
|
+
"url": "git+https://github.com/youweichen0208/pi-web-ui.git"
|
|
37
|
+
},
|
|
38
|
+
"pi": {
|
|
39
|
+
"extensions": [
|
|
40
|
+
"./extensions"
|
|
41
|
+
]
|
|
42
|
+
},
|
|
43
|
+
"engines": {
|
|
44
|
+
"node": ">=22.19.0"
|
|
45
|
+
},
|
|
46
|
+
"scripts": {
|
|
47
|
+
"prepublishOnly": "npm run build",
|
|
48
|
+
"dev": "concurrently -k -n server,web -c blue,green \"npm:dev:server\" \"npm:dev:web\"",
|
|
49
|
+
"dev:server": "cross-env PORT=8788 PI_WEB_ALLOW_ORIGINS=http://localhost:5173,http://127.0.0.1:5173 node --watch --import tsx server/index.ts",
|
|
50
|
+
"dev:web": "vite --config web/vite.config.ts",
|
|
51
|
+
"build": "npm run build:web && npm run build:server",
|
|
52
|
+
"build:web": "vite build --config web/vite.config.ts",
|
|
53
|
+
"build:server": "tsc -p tsconfig.server.json",
|
|
54
|
+
"typecheck": "tsc -p tsconfig.server.json --noEmit && tsc -p web/tsconfig.json --noEmit && tsc -p tsconfig.tests.json --noEmit",
|
|
55
|
+
"test": "vitest run",
|
|
56
|
+
"test:unit": "vitest run",
|
|
57
|
+
"test:smoke": "node tests/run-smoke.mjs",
|
|
58
|
+
"check:protocol": "node scripts/check-protocol-sync.mjs",
|
|
59
|
+
"test:freeze": "node tests/freeze-test.mjs",
|
|
60
|
+
"start": "node dist/server/index.js"
|
|
61
|
+
},
|
|
62
|
+
"dependencies": {
|
|
63
|
+
"@earendil-works/pi-coding-agent": "^0.84.2",
|
|
64
|
+
"@xterm/addon-fit": "^0.11.0",
|
|
65
|
+
"@xterm/xterm": "^6.0.0",
|
|
66
|
+
"compression": "^1.8.1",
|
|
67
|
+
"express": "^4.21.2",
|
|
68
|
+
"highlight.js": "^11.10.0",
|
|
69
|
+
"mermaid": "^11.17.2",
|
|
70
|
+
"node-pty": "^1.1.0",
|
|
71
|
+
"react": "^18.3.1",
|
|
72
|
+
"react-dom": "^18.3.1",
|
|
73
|
+
"react-icons": "^5.7.0",
|
|
74
|
+
"react-markdown": "^9.0.1",
|
|
75
|
+
"rehype-highlight": "^7.0.1",
|
|
76
|
+
"remark-gfm": "^4.0.0",
|
|
77
|
+
"typebox": "^1.3.14",
|
|
78
|
+
"ws": "^8.18.0"
|
|
79
|
+
},
|
|
80
|
+
"devDependencies": {
|
|
81
|
+
"@types/compression": "^1.8.1",
|
|
82
|
+
"@types/express": "^4.17.21",
|
|
83
|
+
"@types/node": "^22.10.0",
|
|
84
|
+
"@types/react": "^18.3.12",
|
|
85
|
+
"@types/react-dom": "^18.3.1",
|
|
86
|
+
"@types/ws": "^8.5.13",
|
|
87
|
+
"@vitejs/plugin-react": "^4.3.4",
|
|
88
|
+
"concurrently": "^9.1.0",
|
|
89
|
+
"cross-env": "^10.1.0",
|
|
90
|
+
"playwright-core": "^1.62.1",
|
|
91
|
+
"tsx": "^4.19.2",
|
|
92
|
+
"typescript": "^5.7.2",
|
|
93
|
+
"vite": "^6.0.3",
|
|
94
|
+
"vitest": "^4.1.11"
|
|
95
|
+
},
|
|
96
|
+
"allowScripts": {
|
|
97
|
+
"node-pty@1.1.0": true
|
|
98
|
+
}
|
|
99
|
+
}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) 2014 The xterm.js authors. All rights reserved.
|
|
3
|
+
* Copyright (c) 2012-2013, Christopher Jeffrey (MIT License)
|
|
4
|
+
* https://github.com/chjj/term.js
|
|
5
|
+
* @license MIT
|
|
6
|
+
*
|
|
7
|
+
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
8
|
+
* of this software and associated documentation files (the "Software"), to deal
|
|
9
|
+
* in the Software without restriction, including without limitation the rights
|
|
10
|
+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
11
|
+
* copies of the Software, and to permit persons to whom the Software is
|
|
12
|
+
* furnished to do so, subject to the following conditions:
|
|
13
|
+
*
|
|
14
|
+
* The above copyright notice and this permission notice shall be included in
|
|
15
|
+
* all copies or substantial portions of the Software.
|
|
16
|
+
*
|
|
17
|
+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
18
|
+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
19
|
+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
20
|
+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
21
|
+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
22
|
+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
23
|
+
* THE SOFTWARE.
|
|
24
|
+
*
|
|
25
|
+
* Originally forked from (with the author's permission):
|
|
26
|
+
* Fabrice Bellard's javascript vt100 for jslinux:
|
|
27
|
+
* http://bellard.org/jslinux/
|
|
28
|
+
* Copyright (c) 2011 Fabrice Bellard
|
|
29
|
+
* The original design remains. The terminal itself
|
|
30
|
+
* has been extended to include xterm CSI codes, among
|
|
31
|
+
* other features.
|
|
32
|
+
*/.xterm{cursor:text;position:relative;user-select:none;-ms-user-select:none;-webkit-user-select:none}.xterm.focus,.xterm:focus{outline:none}.xterm .xterm-helpers{position:absolute;top:0;z-index:5}.xterm .xterm-helper-textarea{padding:0;border:0;margin:0;position:absolute;opacity:0;left:-9999em;top:0;width:0;height:0;z-index:-5;white-space:nowrap;overflow:hidden;resize:none}.xterm .composition-view{background:#000;color:#fff;display:none;position:absolute;white-space:nowrap;z-index:1}.xterm .composition-view.active{display:block}.xterm .xterm-viewport{background-color:#000;overflow-y:scroll;cursor:default;position:absolute;right:0;left:0;top:0;bottom:0}.xterm .xterm-screen{position:relative}.xterm .xterm-screen canvas{position:absolute;left:0;top:0}.xterm-char-measure-element{display:inline-block;visibility:hidden;position:absolute;top:0;left:-9999em;line-height:normal}.xterm.enable-mouse-events{cursor:default}.xterm.xterm-cursor-pointer,.xterm .xterm-cursor-pointer{cursor:pointer}.xterm.column-select.focus{cursor:crosshair}.xterm .xterm-accessibility:not(.debug),.xterm .xterm-message{position:absolute;left:0;top:0;bottom:0;right:0;z-index:10;color:transparent;pointer-events:none}.xterm .xterm-accessibility-tree:not(.debug) *::selection{color:transparent}.xterm .xterm-accessibility-tree{font-family:monospace;-webkit-user-select:text;user-select:text;white-space:pre}.xterm .xterm-accessibility-tree>div{transform-origin:left;width:fit-content}.xterm .live-region{position:absolute;left:-9999px;width:1px;height:1px;overflow:hidden}.xterm-dim{opacity:1!important}.xterm-underline-1{text-decoration:underline}.xterm-underline-2{text-decoration:double underline}.xterm-underline-3{text-decoration:wavy underline}.xterm-underline-4{text-decoration:dotted underline}.xterm-underline-5{text-decoration:dashed underline}.xterm-overline{text-decoration:overline}.xterm-overline.xterm-underline-1{text-decoration:overline underline}.xterm-overline.xterm-underline-2{text-decoration:overline double underline}.xterm-overline.xterm-underline-3{text-decoration:overline wavy underline}.xterm-overline.xterm-underline-4{text-decoration:overline dotted underline}.xterm-overline.xterm-underline-5{text-decoration:overline dashed underline}.xterm-strikethrough{text-decoration:line-through}.xterm-screen .xterm-decoration-container .xterm-decoration{z-index:6;position:absolute}.xterm-screen .xterm-decoration-container .xterm-decoration.xterm-decoration-top-layer{z-index:7}.xterm-decoration-overview-ruler{z-index:8;position:absolute;top:0;right:0;pointer-events:none}.xterm-decoration-top{z-index:2;position:relative}.xterm .xterm-scrollable-element>.scrollbar{cursor:default}.xterm .xterm-scrollable-element>.scrollbar>.scra{cursor:pointer;font-size:11px!important}.xterm .xterm-scrollable-element>.visible{opacity:1;background:#0000;transition:opacity .1s linear;z-index:11}.xterm .xterm-scrollable-element>.invisible{opacity:0;pointer-events:none}.xterm .xterm-scrollable-element>.invisible.fade{transition:opacity .8s linear}.xterm .xterm-scrollable-element>.shadow{position:absolute;display:none}.xterm .xterm-scrollable-element>.shadow.top{display:block;top:0;left:3px;height:3px;width:100%;box-shadow:var(--vscode-scrollbar-shadow, #000) 0 6px 6px -6px inset}.xterm .xterm-scrollable-element>.shadow.left{display:block;top:3px;left:0;height:100%;width:3px;box-shadow:var(--vscode-scrollbar-shadow, #000) 6px 0 6px -6px inset}.xterm .xterm-scrollable-element>.shadow.top-left-corner{display:block;top:0;left:0;height:3px;width:3px}.xterm .xterm-scrollable-element>.shadow.top.left{box-shadow:var(--vscode-scrollbar-shadow, #000) 6px 0 6px -6px inset}
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
import{a as d,j as t}from"./markdown-CUPbftfV.js";import{u as H,F as O,a as R,b as P,c as q,d as L,e as G,f as J,g as V,r as W}from"./index-CniHcFxT.js";import{D as X,o as Y}from"./xterm-D1D2FVe3.js";import"./react-ZkKJMDQQ.js";const $="pi-web-ui:theme-change";function A(){const s=getComputedStyle(document.documentElement),n=(f,r)=>s.getPropertyValue(f).trim()||r;return{background:n("--term-bg","#1b1f24"),foreground:n("--term-fg","#e6e8ef"),cursor:n("--term-cursor","#3b49df"),cursorAccent:n("--term-cursor-accent","#1b1f24"),selectionBackground:n("--term-selection","rgba(59, 73, 223, 0.35)"),black:n("--term-black","#2a2f37"),red:n("--term-red","#f87171"),green:n("--term-green","#34d399"),yellow:n("--term-yellow","#fbbf24"),blue:n("--term-blue","#60a5fa"),magenta:n("--term-magenta","#c084fc"),cyan:n("--term-cyan","#22d3ee"),white:n("--term-white","#e6e8ef"),brightBlack:n("--term-bright-black","#6b7284"),brightRed:n("--term-bright-red","#f87171"),brightGreen:n("--term-bright-green","#34d399"),brightYellow:n("--term-bright-yellow","#fbbf24"),brightBlue:n("--term-bright-blue","#60a5fa"),brightMagenta:n("--term-bright-magenta","#c084fc"),brightCyan:n("--term-bright-cyan","#22d3ee"),brightWhite:n("--term-bright-white","#ffffff")}}function Q({conversationId:s,terminalId:n,command:f,cwd:r,active:p,send:o,register:j}){const g=d.useRef(null),y=d.useRef(null),N=f?JSON.stringify(f):"";return d.useEffect(()=>{const h=g.current;if(!h)return;const a=new X({theme:A(),fontFamily:'"SF Mono", "JetBrains Mono", ui-monospace, Menlo, Consolas, monospace',fontSize:13,cursorBlink:!0,scrollback:8e3}),l=new Y;a.loadAddon(l),a.open(h),y.current={term:a,fit:l},p&&a.focus();const x=()=>{a.options.theme=A()};window.addEventListener($,x),a.attachCustomKeyEventHandler(m=>{var F;if(m.type!=="keydown")return!0;const E=(F=m.key)==null?void 0:F.toLowerCase();if((m.ctrlKey||m.metaKey)&&E==="v")return!1;if(m.ctrlKey&&!m.shiftKey&&!m.altKey&&E==="c"&&a.hasSelection()){const k=a.textarea;return k&&(k.value=a.getSelection(),k.select()),!1}return!0});const v=j(s,n,{write:m=>a.write(m),dispose:()=>a.dispose()}),C=()=>{try{l.fit(),o({type:"terminal_resize",terminalId:n,conversationId:s,cols:a.cols,rows:a.rows})}catch{}},b=requestAnimationFrame(()=>{try{l.fit()}catch{}o(f?{type:"run_command",terminalId:n,conversationId:s,command:f,cols:a.cols,rows:a.rows}:{type:"terminal_create",terminalId:n,conversationId:s,cwd:r,cols:a.cols,rows:a.rows})}),T=a.onData(m=>{o({type:"terminal_input",terminalId:n,conversationId:s,data:m})});let w=null;return typeof ResizeObserver<"u"&&(w=new ResizeObserver(()=>{h.offsetWidth>0&&h.offsetHeight>0&&C()}),w.observe(h)),()=>{cancelAnimationFrame(b),T.dispose(),window.removeEventListener($,x),w==null||w.disconnect(),v(),a.dispose(),y.current=null}},[s,n,N,o,j]),d.useEffect(()=>{if(!p)return;const h=requestAnimationFrame(()=>{const a=y.current;if(a){try{a.fit.fit(),o({type:"terminal_resize",terminalId:n,conversationId:s,cols:a.term.cols,rows:a.term.rows})}catch{}a.term.focus()}});return()=>cancelAnimationFrame(h)},[p]),t.jsx("div",{ref:g,className:`term-xterm ${p?"":"hidden"}`})}const K={name:"",command:"",cwd:"${pwd}"};function ne({chat:s,send:n,terminal:f}){const r=H(),[p,o]=d.useState(null),[j,g]=d.useState(!1),[y,N]=d.useState(!1),[h,a]=d.useState(null),[l,x]=d.useState(K),[v,C]=d.useState(null),b=d.useRef(null);d.useEffect(()=>{s.terminals.length===0?o(null):s.terminals.some(e=>e.id===p)||o(s.terminals[s.terminals.length-1].id)},[s.terminals,p]),d.useEffect(()=>()=>{b.current&&clearTimeout(b.current)},[]);const T=e=>{var u;if(!s.ready)return;const i=W(),c=s.activeConversationId||((u=s.state)==null?void 0:u.conversationId)||"";f.create({...e,id:i,conversationId:c,cols:e.cols??80,rows:e.rows??24,running:!0,exitCode:null}),o(i),g(!1)},w=()=>{var e;return T({title:r("terminalTitle",{n:s.terminals.length+1}),cwd:((e=s.state)==null?void 0:e.cwd)??""})},m=e=>{var u;const i=e.name||e.command,c=s.terminals.find(_=>_.title===i);if(c){f.restart(c.id),o(c.id),n({type:"run_command",terminalId:c.id,conversationId:c.conversationId,command:e,cols:80,rows:24});return}T({title:i,cwd:((u=s.state)==null?void 0:u.cwd)??"",command:e})},E=e=>{const i=s.terminals.find(c=>c.id===e);if(i&&n({type:"terminal_kill",terminalId:e,conversationId:i.conversationId}),f.close(e),p===e){const c=s.terminals.filter(u=>u.id!==e);o(c.length>0?c[c.length-1].id:null)}},F=()=>{N(!0),a(null),x(K)},k=e=>{const i=s.commands[e];i&&(N(!1),a(e),x({name:i.name,command:i.command,cwd:i.cwd??""}))},D=()=>{N(!1),a(null)},S=()=>{const e=l.name.trim(),i=l.command.trim();if(!e||!i)return;const c=l.cwd.trim(),u={name:e,command:i,cwd:c||void 0},_=y?[...s.commands,u]:h!==null?s.commands.map((z,B)=>B===h?u:z):s.commands;n({type:"save_commands",commands:_}),D()},M=e=>{if(v===e){const i=s.commands.filter((c,u)=>u!==e);n({type:"save_commands",commands:i}),C(null),b.current&&clearTimeout(b.current)}else C(e),b.current&&clearTimeout(b.current),b.current=setTimeout(()=>C(null),2500)},I=y||h!==null;return t.jsxs("div",{className:"terminal-view",children:[t.jsxs("aside",{className:`term-side term-commands ${j?"open":""}`,children:[t.jsxs("div",{className:"panel-header",children:[t.jsx("span",{className:"panel-title",children:r("commands")}),t.jsxs("div",{className:"panel-header-actions",children:[t.jsx("button",{type:"button",className:"panel-refresh",title:r("rerun"),onClick:()=>n({type:"list_commands"}),children:t.jsx(O,{})}),t.jsx("button",{type:"button",className:"panel-new",title:r("newCommand"),onClick:F,children:t.jsx(R,{})})]})]}),t.jsx("div",{className:"panel-body",children:I?t.jsxs("div",{className:"cmd-form",children:[t.jsx("label",{htmlFor:"cmd-name",children:r("name")}),t.jsx("input",{id:"cmd-name",className:"cmd-input",value:l.name,placeholder:r("exampleName"),autoFocus:!0,onChange:e=>x({...l,name:e.target.value})}),t.jsx("label",{htmlFor:"cmd-command",children:r("command")}),t.jsx("input",{id:"cmd-command",className:"cmd-input",value:l.command,placeholder:r("exampleCommand"),onChange:e=>x({...l,command:e.target.value}),onKeyDown:e=>{e.key==="Enter"&&!e.nativeEvent.isComposing&&S()}}),t.jsxs("label",{htmlFor:"cmd-cwd",children:[r("directory")," ",t.jsx("span",{className:"cmd-hint",children:r("cwdHint")})]}),t.jsx("input",{id:"cmd-cwd",className:"cmd-input",value:l.cwd,placeholder:"${pwd}",onChange:e=>x({...l,cwd:e.target.value}),onKeyDown:e=>{e.key==="Enter"&&!e.nativeEvent.isComposing&&S()}}),t.jsxs("div",{className:"cmd-form-actions",children:[t.jsx("button",{type:"button",className:"btn",onClick:D,children:r("cancel")}),t.jsx("button",{type:"button",className:"btn primary",disabled:!l.name.trim()||!l.command.trim(),onClick:S,children:r("save")})]})]}):t.jsxs(t.Fragment,{children:[s.commands.length===0&&t.jsx("div",{className:"panel-empty",children:r("noCommands")}),s.commands.map((e,i)=>t.jsxs("div",{className:"cmd-item",children:[t.jsx("button",{type:"button",className:"cmd-run",title:r("clickToRun"),onClick:()=>m(e),children:t.jsx(P,{})}),t.jsxs("button",{type:"button",className:"cmd-main",title:r("clickToRun"),onClick:()=>m(e),children:[t.jsx("span",{className:"cmd-name",children:e.name}),t.jsx("span",{className:"cmd-command",children:e.command}),e.cwd&&t.jsx("span",{className:"cmd-cwd",children:e.cwd})]}),t.jsx("button",{type:"button",className:"cmd-act",title:r("edit"),onClick:()=>k(i),children:t.jsx(q,{})}),t.jsx("button",{type:"button",className:`cmd-act del ${v===i?"confirm":""}`,title:r("delete"),onClick:()=>M(i),children:v===i?r("confirmQ"):t.jsx(L,{})})]},i))]})}),t.jsxs("div",{className:"term-tabs-block",children:[t.jsxs("div",{className:"panel-header",children:[t.jsx("span",{className:"panel-title",children:r("terminal")}),t.jsx("button",{type:"button",className:"panel-new",title:r("newTerminal"),onClick:w,children:t.jsx(R,{})})]}),t.jsxs("div",{className:"panel-body",children:[s.terminals.length===0&&t.jsx("div",{className:"panel-empty",children:r("noTerminal")}),s.terminals.map(e=>t.jsxs("div",{className:`term-tab ${e.id===p?"active":""}`,children:[t.jsxs("button",{type:"button",className:"term-tab-main",title:`${e.cwd}${e.command?`
|
|
2
|
+
> ${e.command.command}`:""}`,onClick:()=>{o(e.id),g(!1)},children:[t.jsx("span",{className:`term-tab-dot ${e.running?"run":"exit"}`}),t.jsxs("span",{className:"term-tab-title",children:[e.title,!e.running&&t.jsx("span",{className:"term-tab-exit",children:r("exited",{code:e.exitCode===null?"":` ${e.exitCode}`})})]})]}),t.jsx("button",{type:"button",className:"term-tab-close",title:r("closeTerminal"),onClick:()=>E(e.id),children:t.jsx(G,{})})]},e.id))]})]})]}),t.jsxs("div",{className:"term-main",children:[j&&t.jsx("div",{className:"drawer-backdrop",onClick:()=>g(!1)}),t.jsx("button",{type:"button",className:"term-side-toggle",title:r("commands"),onClick:()=>g(e=>!e),children:t.jsx(J,{})}),s.terminals.length===0?t.jsxs("div",{className:"term-empty",children:[t.jsx(V,{className:"term-empty-icon"}),t.jsx("div",{className:"term-empty-title",children:r("builtinTerminal")}),t.jsx("div",{className:"term-empty-sub",children:r("termEmptySub")})]}):s.terminals.map(e=>t.jsx(Q,{conversationId:e.conversationId,terminalId:e.id,command:e.command,cwd:e.cwd,active:e.id===p,send:n,register:f.register},`${e.conversationId}:${e.id}`))]})]})}export{ne as TerminalPanel};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{g as p,r as u,d as a}from"./chunk-SVP7TREG-CmDIvX-r.js";import{p as f}from"./chunk-JWPE2WC7-DIQ8iZN5.js";import{_ as n,l as o}from"./mermaid.core-CCiG-bOm.js";import{M as c,b as d}from"./cynefin-OW5HDTMX-fWdqaCpX.js";import"./index-CniHcFxT.js";import"./markdown-CUPbftfV.js";import"./react-ZkKJMDQQ.js";var v=d().RailroadAbnf.parser.LangiumParser,i=n(e=>{const r=e.alternatives.map(g);return r.length===1?r[0]:{type:"choice",alternatives:r}},"transformAlternation"),g=n(e=>{const r=e.elements.map(y);return r.length===1?r[0]:{type:"sequence",elements:r}},"transformConcatenation"),b=n(e=>{if(e.includes("*")){const[t,s]=e.split("*"),l=t?parseInt(t,10):0,m=s?parseInt(s,10):1/0;return{min:l,max:m}}const r=parseInt(e,10);return{min:r,max:r}},"parseRepeat"),y=n(e=>{const r=A(e.primary);if(!e.repeat)return r;const{min:t,max:s}=b(e.repeat);return t===0&&s===1?{type:"optional",element:r}:{type:"repetition",element:r,min:t,max:s}},"transformElement"),A=n(e=>{switch(e.$type){case"AbnfStringLiteral":return{type:"terminal",value:e.value};case"AbnfNumVal":return{type:"terminal",value:e.value};case"AbnfRuleName":return{type:"nonterminal",name:e.name};case"AbnfGroup":return i(e.element);case"AbnfOptionalGroup":return{type:"optional",element:i(e.element)};default:throw new Error(`Unsupported ABNF primary node: ${e.$type}`)}},"transformPrimary"),P=n(e=>({name:e.name,definition:i(e.definition)}),"transformRule"),h=n(e=>{f(e,a),e.title&&a.setTitle(e.title),e.rules.map(r=>a.addRule(P(r)))},"populateDb"),R={parse:n(e=>{a.clear(),o.debug("[ABNF Parser] Starting Langium parse");const r=v.parse(e);if(r.lexerErrors.length>0||r.parserErrors.length>0)throw new c(r);const t=r.value;o.debug("[ABNF Parser] Parsed rules:",t.rules.length),h(t),o.debug("[ABNF Parser] Parse complete")},"parse"),parser:{yy:a}},I={parser:R,db:a,renderer:u,styles:p};export{I as diagram};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{a0 as ln,a1 as an,a2 as y,a3 as tn,a4 as H,a5 as q,a6 as _,a7 as un,a8 as rn,a9 as L,aa as o,ab as B,ac as sn,ad as on,ae as fn}from"./mermaid.core-CCiG-bOm.js";function cn(l){return l.innerRadius}function yn(l){return l.outerRadius}function gn(l){return l.startAngle}function dn(l){return l.endAngle}function mn(l){return l&&l.padAngle}function pn(l,h,I,D,v,A,C,a){var O=I-l,i=D-h,n=C-v,d=a-A,u=d*O-n*i;if(!(u*u<y))return u=(n*(h-A)-d*(l-v))/u,[l+u*O,h+u*i]}function W(l,h,I,D,v,A,C){var a=l-I,O=h-D,i=(C?A:-A)/L(a*a+O*O),n=i*O,d=-i*a,u=l+n,s=h+d,f=I+n,c=D+d,F=(u+f)/2,t=(s+c)/2,m=f-u,g=c-s,R=m*m+g*g,T=v-A,P=u*c-f*s,S=(g<0?-1:1)*L(fn(0,T*T*R-P*P)),j=(P*g-m*S)/R,z=(-P*m-g*S)/R,w=(P*g+m*S)/R,p=(-P*m+g*S)/R,x=j-F,e=z-t,r=w-F,G=p-t;return x*x+e*e>r*r+G*G&&(j=w,z=p),{cx:j,cy:z,x01:-n,y01:-d,x11:j*(v/T-1),y11:z*(v/T-1)}}function hn(){var l=cn,h=yn,I=B(0),D=null,v=gn,A=dn,C=mn,a=null,O=ln(i);function i(){var n,d,u=+l.apply(this,arguments),s=+h.apply(this,arguments),f=v.apply(this,arguments)-an,c=A.apply(this,arguments)-an,F=un(c-f),t=c>f;if(a||(a=n=O()),s<u&&(d=s,s=u,u=d),!(s>y))a.moveTo(0,0);else if(F>tn-y)a.moveTo(s*H(f),s*q(f)),a.arc(0,0,s,f,c,!t),u>y&&(a.moveTo(u*H(c),u*q(c)),a.arc(0,0,u,c,f,t));else{var m=f,g=c,R=f,T=c,P=F,S=F,j=C.apply(this,arguments)/2,z=j>y&&(D?+D.apply(this,arguments):L(u*u+s*s)),w=_(un(s-u)/2,+I.apply(this,arguments)),p=w,x=w,e,r;if(z>y){var G=sn(z/u*q(j)),M=sn(z/s*q(j));(P-=G*2)>y?(G*=t?1:-1,R+=G,T-=G):(P=0,R=T=(f+c)/2),(S-=M*2)>y?(M*=t?1:-1,m+=M,g-=M):(S=0,m=g=(f+c)/2)}var J=s*H(m),K=s*q(m),N=u*H(T),Q=u*q(T);if(w>y){var U=s*H(g),V=s*q(g),X=u*H(R),Y=u*q(R),E;if(F<rn)if(E=pn(J,K,X,Y,U,V,N,Q)){var Z=J-E[0],$=K-E[1],b=U-E[0],k=V-E[1],nn=1/q(on((Z*b+$*k)/(L(Z*Z+$*$)*L(b*b+k*k)))/2),en=L(E[0]*E[0]+E[1]*E[1]);p=_(w,(u-en)/(nn-1)),x=_(w,(s-en)/(nn+1))}else p=x=0}S>y?x>y?(e=W(X,Y,J,K,s,x,t),r=W(U,V,N,Q,s,x,t),a.moveTo(e.cx+e.x01,e.cy+e.y01),x<w?a.arc(e.cx,e.cy,x,o(e.y01,e.x01),o(r.y01,r.x01),!t):(a.arc(e.cx,e.cy,x,o(e.y01,e.x01),o(e.y11,e.x11),!t),a.arc(0,0,s,o(e.cy+e.y11,e.cx+e.x11),o(r.cy+r.y11,r.cx+r.x11),!t),a.arc(r.cx,r.cy,x,o(r.y11,r.x11),o(r.y01,r.x01),!t))):(a.moveTo(J,K),a.arc(0,0,s,m,g,!t)):a.moveTo(J,K),!(u>y)||!(P>y)?a.lineTo(N,Q):p>y?(e=W(N,Q,U,V,u,-p,t),r=W(J,K,X,Y,u,-p,t),a.lineTo(e.cx+e.x01,e.cy+e.y01),p<w?a.arc(e.cx,e.cy,p,o(e.y01,e.x01),o(r.y01,r.x01),!t):(a.arc(e.cx,e.cy,p,o(e.y01,e.x01),o(e.y11,e.x11),!t),a.arc(0,0,u,o(e.cy+e.y11,e.cx+e.x11),o(r.cy+r.y11,r.cx+r.x11),t),a.arc(r.cx,r.cy,p,o(r.y11,r.x11),o(r.y01,r.x01),!t))):a.arc(0,0,u,T,R,t)}if(a.closePath(),n)return a=null,n+""||null}return i.centroid=function(){var n=(+l.apply(this,arguments)+ +h.apply(this,arguments))/2,d=(+v.apply(this,arguments)+ +A.apply(this,arguments))/2-rn/2;return[H(d)*n,q(d)*n]},i.innerRadius=function(n){return arguments.length?(l=typeof n=="function"?n:B(+n),i):l},i.outerRadius=function(n){return arguments.length?(h=typeof n=="function"?n:B(+n),i):h},i.cornerRadius=function(n){return arguments.length?(I=typeof n=="function"?n:B(+n),i):I},i.padRadius=function(n){return arguments.length?(D=n==null?null:typeof n=="function"?n:B(+n),i):D},i.startAngle=function(n){return arguments.length?(v=typeof n=="function"?n:B(+n),i):v},i.endAngle=function(n){return arguments.length?(A=typeof n=="function"?n:B(+n),i):A},i.padAngle=function(n){return arguments.length?(C=typeof n=="function"?n:B(+n),i):C},i.context=function(n){return arguments.length?(a=n??null,i):a},i}export{hn as d};
|