pi-web-ui 0.68.0 → 0.68.2

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 (35) hide show
  1. package/bin/pi-web-ui.mjs +1876 -1876
  2. package/dist/server/agent-service.js +450 -68
  3. package/dist/server/attachments.js +3 -3
  4. package/dist/server/client-state.js +4 -2
  5. package/dist/server/dsh/dsh-agent-service.js +15 -1
  6. package/dist/server/dsh/runtime/cordis.yml +1 -1
  7. package/dist/server/dsh/runtime/goal-rpc.mjs +645 -645
  8. package/dist/server/dsh/runtime/launcher.mjs +164 -164
  9. package/dist/server/dsh/runtime/override.patch.yml +71 -71
  10. package/dist/server/dsh/runtime/runtime-root.mjs +92 -86
  11. package/dist/server/index.js +68 -2
  12. package/dist/server/locales.js +156 -0
  13. package/dist/server/plugins.js +63 -0
  14. package/dist/server/prompt-composer.js +34 -0
  15. package/dist/server/serialize.js +24 -0
  16. package/dist/server/settings-service.js +9 -0
  17. package/dist/server/update-check.js +49 -50
  18. package/dist/server/vision-bridge.js +9 -9
  19. package/extensions/webui.ts +190 -190
  20. package/package.json +6 -2
  21. package/plugins/catalog.json +9 -0
  22. package/web/dist/assets/TerminalPanel-BQ5NTB9Y.js +6 -0
  23. package/web/dist/assets/TerminalPanel-DOrYoP_4.css +32 -0
  24. package/web/dist/assets/index-C_I-6Zul.css +10 -0
  25. package/web/dist/assets/index-Ck5pa3XK.js +333 -0
  26. package/web/dist/assets/markdown-DOsihKaR.js +51 -0
  27. package/web/dist/assets/{react-C9ovnpIm.js → react-DIP6JKYk.js} +2 -2
  28. package/web/dist/assets/xterm-B96xOxS9.js +38 -0
  29. package/web/dist/index.html +4 -4
  30. package/web/dist/assets/TerminalPanel-6GBZ9nXN.css +0 -32
  31. package/web/dist/assets/TerminalPanel-CTY_LN4U.js +0 -6
  32. package/web/dist/assets/index-Dc6t3GTo.css +0 -10
  33. package/web/dist/assets/index-fwF-jmiV.js +0 -332
  34. package/web/dist/assets/markdown-DRBrS2Nf.js +0 -51
  35. package/web/dist/assets/xterm-D1D2FVe3.js +0 -38
@@ -1,190 +1,190 @@
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" ? ["open", url] : platform === "win32" ? ["cmd", "/c", "start", "", url] : ["xdg-open", url];
81
- // 无界面环境缺少 xdg-open 等打开器时,ENOENT 以异步 'error' 事件触发,
82
- // try/catch 拦不住会崩掉整个进程 —— 必须挂 error 监听。
83
- spawn(cmd, rest, { stdio: "ignore", detached: true })
84
- .on("error", (err) => {
85
- if ((err as NodeJS.ErrnoException)?.code === "ENOENT") {
86
- console.warn(
87
- `[webui] 未找到浏览器打开器 (${(err as NodeJS.ErrnoException).path || "command not found"}),请用 --no-browser 关闭自动打开`,
88
- );
89
- } else {
90
- console.warn("[webui] 打开浏览器失败:", err.message);
91
- }
92
- })
93
- .unref();
94
- }
95
-
96
- export default function (pi: ExtensionAPI): void {
97
- pi.registerCommand("webui", {
98
- description: "启动本机 pi-web-ui Web 界面(/webui [--port N] [--cwd PATH] [--no-browser] | stop | status)",
99
- handler: async (args: string, ctx: ExtensionCommandContext) => {
100
- const sid = ctx.sessionManager.getSessionId();
101
- const opts = parseArgs(args);
102
- const action = (args.split(/\s+/)[0] || "start").toLowerCase();
103
-
104
- // 停止
105
- if (action === "stop" || action === "kill") {
106
- const inst = running.get(sid);
107
- if (!inst) {
108
- ctx.ui.notify("没有正在运行的本机 pi-web-ui 服务器", "info");
109
- return;
110
- }
111
- inst.proc.kill("SIGTERM");
112
- running.delete(sid);
113
- ctx.ui.notify(`已停止 pi-web-ui (${inst.url})`, "info");
114
- return;
115
- }
116
-
117
- // 状态
118
- if (action === "status") {
119
- const inst = running.get(sid);
120
- if (!inst) {
121
- ctx.ui.notify("本机 pi-web-ui 未运行", "info");
122
- return;
123
- }
124
- const alive = inst.proc.exitCode === null;
125
- ctx.ui.notify(
126
- alive
127
- ? `pi-web-ui 运行中 → ${inst.url}\n端口 ${inst.port} · cwd ${inst.cwd}`
128
- : `已退出(exit=${inst.proc.exitCode})`,
129
- alive ? "info" : "warning",
130
- );
131
- return;
132
- }
133
-
134
- // 默认 start
135
- if (action !== "start" && action !== "run") {
136
- ctx.ui.notify(`未知动作 ${action}(可用 start|stop|status)`, "warning");
137
- return;
138
- }
139
-
140
- // 已运行则提示
141
- const existing = running.get(sid);
142
- if (existing && existing.proc.exitCode === null) {
143
- ctx.ui.notify(`pi-web-ui 已在运行 → ${existing.url}`, "info");
144
- return;
145
- }
146
-
147
- // 检查是否已构建
148
- if (!existsSync(SERVER_ENTRY)) {
149
- ctx.ui.notify(
150
- "缺少 dist/ 产物(当前安装未包含已构建前端)。请运行 `npm run build` 后重试,或用 pi-web-ui 官方 npm 包。",
151
- "warning",
152
- );
153
- return;
154
- }
155
-
156
- const port = opts.port ?? (await findFreePort());
157
- const cwd = opts.cwd ?? ctx.cwd;
158
- const url = `http://localhost:${port}`;
159
-
160
- const env = {
161
- ...process.env,
162
- PORT: String(port),
163
- PI_WEB_CWD: cwd,
164
- ...(process.env.PI_WEB_DATA_DIR ? {} : { PI_WEB_DATA_DIR: join(cwd, ".pi-web") }),
165
- };
166
- const proc = spawn(NODE, [SERVER_ENTRY], { cwd, env, stdio: "ignore", detached: true });
167
- proc.unref();
168
- running.set(sid, { proc, port, cwd, url });
169
-
170
- ctx.ui.notify(`pi-web-ui 启动中 → ${url}\n端口 ${port} · cwd ${cwd}\n(几秒后可用,/webui status 查看)`);
171
-
172
- if (!opts.noBrowser) await openBrowser(url);
173
-
174
- // 进程退出时清理
175
- proc.on("exit", () => {
176
- if (running.get(sid)?.proc === proc) running.delete(sid);
177
- });
178
- },
179
- });
180
-
181
- // 会话结束清理子进程,避免孤儿
182
- pi.on("session_shutdown", async (_event, ctx) => {
183
- const sid = ctx.sessionManager.getSessionId();
184
- const inst = running.get(sid);
185
- if (inst && inst.proc.exitCode === null) {
186
- inst.proc.kill("SIGTERM");
187
- running.delete(sid);
188
- }
189
- });
190
- }
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" ? ["open", url] : platform === "win32" ? ["cmd", "/c", "start", "", url] : ["xdg-open", url];
81
+ // 无界面环境缺少 xdg-open 等打开器时,ENOENT 以异步 'error' 事件触发,
82
+ // try/catch 拦不住会崩掉整个进程 —— 必须挂 error 监听。
83
+ spawn(cmd, rest, { stdio: "ignore", detached: true })
84
+ .on("error", (err) => {
85
+ if ((err as NodeJS.ErrnoException)?.code === "ENOENT") {
86
+ console.warn(
87
+ `[webui] 未找到浏览器打开器 (${(err as NodeJS.ErrnoException).path || "command not found"}),请用 --no-browser 关闭自动打开`,
88
+ );
89
+ } else {
90
+ console.warn("[webui] 打开浏览器失败:", err.message);
91
+ }
92
+ })
93
+ .unref();
94
+ }
95
+
96
+ export default function (pi: ExtensionAPI): void {
97
+ pi.registerCommand("webui", {
98
+ description: "启动本机 pi-web-ui Web 界面(/webui [--port N] [--cwd PATH] [--no-browser] | stop | status)",
99
+ handler: async (args: string, ctx: ExtensionCommandContext) => {
100
+ const sid = ctx.sessionManager.getSessionId();
101
+ const opts = parseArgs(args);
102
+ const action = (args.split(/\s+/)[0] || "start").toLowerCase();
103
+
104
+ // 停止
105
+ if (action === "stop" || action === "kill") {
106
+ const inst = running.get(sid);
107
+ if (!inst) {
108
+ ctx.ui.notify("没有正在运行的本机 pi-web-ui 服务器", "info");
109
+ return;
110
+ }
111
+ inst.proc.kill("SIGTERM");
112
+ running.delete(sid);
113
+ ctx.ui.notify(`已停止 pi-web-ui (${inst.url})`, "info");
114
+ return;
115
+ }
116
+
117
+ // 状态
118
+ if (action === "status") {
119
+ const inst = running.get(sid);
120
+ if (!inst) {
121
+ ctx.ui.notify("本机 pi-web-ui 未运行", "info");
122
+ return;
123
+ }
124
+ const alive = inst.proc.exitCode === null;
125
+ ctx.ui.notify(
126
+ alive
127
+ ? `pi-web-ui 运行中 → ${inst.url}\n端口 ${inst.port} · cwd ${inst.cwd}`
128
+ : `已退出(exit=${inst.proc.exitCode})`,
129
+ alive ? "info" : "warning",
130
+ );
131
+ return;
132
+ }
133
+
134
+ // 默认 start
135
+ if (action !== "start" && action !== "run") {
136
+ ctx.ui.notify(`未知动作 ${action}(可用 start|stop|status)`, "warning");
137
+ return;
138
+ }
139
+
140
+ // 已运行则提示
141
+ const existing = running.get(sid);
142
+ if (existing && existing.proc.exitCode === null) {
143
+ ctx.ui.notify(`pi-web-ui 已在运行 → ${existing.url}`, "info");
144
+ return;
145
+ }
146
+
147
+ // 检查是否已构建
148
+ if (!existsSync(SERVER_ENTRY)) {
149
+ ctx.ui.notify(
150
+ "缺少 dist/ 产物(当前安装未包含已构建前端)。请运行 `npm run build` 后重试,或用 pi-web-ui 官方 npm 包。",
151
+ "warning",
152
+ );
153
+ return;
154
+ }
155
+
156
+ const port = opts.port ?? (await findFreePort());
157
+ const cwd = opts.cwd ?? ctx.cwd;
158
+ const url = `http://localhost:${port}`;
159
+
160
+ const env = {
161
+ ...process.env,
162
+ PORT: String(port),
163
+ PI_WEB_CWD: cwd,
164
+ ...(process.env.PI_WEB_DATA_DIR ? {} : { PI_WEB_DATA_DIR: join(cwd, ".pi-web") }),
165
+ };
166
+ const proc = spawn(NODE, [SERVER_ENTRY], { cwd, env, stdio: "ignore", detached: true });
167
+ proc.unref();
168
+ running.set(sid, { proc, port, cwd, url });
169
+
170
+ ctx.ui.notify(`pi-web-ui 启动中 → ${url}\n端口 ${port} · cwd ${cwd}\n(几秒后可用,/webui status 查看)`);
171
+
172
+ if (!opts.noBrowser) await openBrowser(url);
173
+
174
+ // 进程退出时清理
175
+ proc.on("exit", () => {
176
+ if (running.get(sid)?.proc === proc) running.delete(sid);
177
+ });
178
+ },
179
+ });
180
+
181
+ // 会话结束清理子进程,避免孤儿
182
+ pi.on("session_shutdown", async (_event, ctx) => {
183
+ const sid = ctx.sessionManager.getSessionId();
184
+ const inst = running.get(sid);
185
+ if (inst && inst.proc.exitCode === null) {
186
+ inst.proc.kill("SIGTERM");
187
+ running.delete(sid);
188
+ }
189
+ });
190
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "pi-web-ui",
3
- "version": "0.68.0",
3
+ "version": "0.68.2",
4
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
5
  "license": "MIT",
6
6
  "author": {
@@ -51,11 +51,12 @@
51
51
  "dev": "concurrently -k -n server,web -c blue,green \"npm:dev:server\" \"npm:dev:web\"",
52
52
  "dev:server": "cross-env PI_WEB_PORT=8788 PI_WEB_ALLOW_ORIGINS=http://localhost:5173,http://127.0.0.1:5173 node --watch --import tsx server/index.ts",
53
53
  "dev:web": "vite --config web/vite.config.ts",
54
- "build": "npm run build:web && npm run build:server && npm run build:dsh-runtime && npm run build:mermaid-vendor",
54
+ "build": "npm run build:web && npm run build:server && npm run build:dsh-runtime && npm run build:mermaid-vendor && npm run build:runtrace-vendor",
55
55
  "build:web": "vite build --config web/vite.config.ts",
56
56
  "build:server": "tsc -p tsconfig.server.json",
57
57
  "build:dsh-runtime": "node scripts/copy-dsh-runtime.mjs",
58
58
  "build:mermaid-vendor": "node scripts/build-mermaid-vendor.mjs",
59
+ "build:runtrace-vendor": "node scripts/build-runtrace-vendor.mjs",
59
60
  "typecheck": "tsc -p tsconfig.server.json --noEmit && tsc -p web/tsconfig.json --noEmit && tsc -p tsconfig.tests.json --noEmit",
60
61
  "test": "vitest run",
61
62
  "test:unit": "vitest run",
@@ -83,6 +84,7 @@
83
84
  "react-icons": "^5.7.0",
84
85
  "react-markdown": "^9.0.1",
85
86
  "rehype-highlight": "^7.0.1",
87
+ "rehype-raw": "^7.0.0",
86
88
  "remark-gfm": "^4.0.0",
87
89
  "typebox": "^1.3.14",
88
90
  "ws": "^8.18.0"
@@ -98,12 +100,14 @@
98
100
  "concurrently": "^9.1.0",
99
101
  "cross-env": "^10.1.0",
100
102
  "esbuild": "^0.25.12",
103
+ "jsdom": "^26.1.0",
101
104
  "mermaid": "^11.17.2",
102
105
  "oxlint": "^1.81.0",
103
106
  "playwright-core": "^1.62.1",
104
107
  "prettier": "^3.9.6",
105
108
  "tsx": "^4.19.2",
106
109
  "typescript": "^5.7.2",
110
+ "vis-timeline": "^8.5.4",
107
111
  "vite": "^6.0.3",
108
112
  "vitest": "^4.1.11"
109
113
  },
@@ -34,5 +34,14 @@
34
34
  "descriptionEn": "Renders ```mermaid fences in messages to SVG diagrams (fenced-code renderer plugin, offline-first local engine).",
35
35
  "source": "xing-shuyin/pi-web-ui/plugins/mermaid",
36
36
  "homepage": "https://github.com/xing-shuyin/pi-web-ui/tree/main/plugins/mermaid"
37
+ },
38
+ {
39
+ "id": "run-trace",
40
+ "name": "run-trace",
41
+ "icon": "🧭",
42
+ "description": "运行轨迹:任务 → 思考 → 工具 → 文件改动 → 结果的时间线聚合视图,支持回放与节点详情。",
43
+ "descriptionEn": "Run trajectory: task → thinking → tools → file changes → result timeline with replay and node details.",
44
+ "source": "xing-shuyin/pi-web-ui/plugins/run-trace",
45
+ "homepage": "https://github.com/xing-shuyin/pi-web-ui/tree/main/plugins/run-trace"
37
46
  }
38
47
  ]
@@ -0,0 +1,6 @@
1
+ import{a as l,j as n}from"./markdown-DOsihKaR.js";import{u as P,b as O,T as M,a as W,F as Y,c as z,d as Z,e as H,f as ee,g as ne,h as te,i as se,r as ae}from"./index-Ck5pa3XK.js";import{D as re,o as ie}from"./xterm-B96xOxS9.js";import"./react-DIP6JKYk.js";function le(t){let c=null;return{clean:t.replace(/\r?\n?\[pi-term-exit:(-?\d+)\]\r?\n?/g,(a,x)=>(c=Number(x),`\r
2
+ `)).replace(/\r?\n?\x1b\[90m\[(?:进程已退出,退出码 |Process exited with code )-?\d+\]\x1b\[0m\r?\n?/g,`\r
3
+ `),exitCode:c}}function ce({conversationId:t,terminalId:c,command:p,cwd:a,title:x,active:u,running:v,exitCode:j,send:h,register:C}){const T=l.useRef(null),y=l.useRef(null),{locale:o}=P(),N=l.useRef(o);N.current=o;const E=p?JSON.stringify(p):"";l.useEffect(()=>{const m=T.current;if(!m)return;const r=new re({theme:O(),fontFamily:'"SF Mono", "JetBrains Mono", ui-monospace, Menlo, Consolas, monospace',fontSize:13,cursorBlink:!0,scrollback:8e3}),b=new ie;r.loadAddon(b),r.open(m),y.current={term:r,fit:b},u&&r.focus();const g=()=>{r.options.theme=O()};window.addEventListener(M,g),r.attachCustomKeyEventHandler(d=>{if(d.type!=="keydown")return!0;const S=d.key?.toLowerCase();if((d.ctrlKey||d.metaKey)&&S==="v")return!1;if(d.ctrlKey&&!d.shiftKey&&!d.altKey&&S==="c"&&r.hasSelection()){const D=r.textarea;return D&&(D.value=r.getSelection(),D.select()),!1}return!0});const _=C(t,c,{write:d=>r.write(le(d).clean),dispose:()=>r.dispose()}),$=()=>{try{b.fit(),h({type:"terminal_resize",terminalId:c,conversationId:t,cols:r.cols,rows:r.rows})}catch{}},B=requestAnimationFrame(()=>{try{b.fit()}catch{}h(p?{type:"run_command",terminalId:c,conversationId:t,command:p,cols:r.cols,rows:r.rows}:{type:"terminal_create",terminalId:c,title:x,locale:N.current,conversationId:t,cwd:a,cols:r.cols,rows:r.rows})}),R=r.onData(d=>{h({type:"terminal_input",terminalId:c,conversationId:t,data:d})});let k=null;return typeof ResizeObserver<"u"&&(k=new ResizeObserver(()=>{m.offsetWidth>0&&m.offsetHeight>0&&$()}),k.observe(m)),()=>{cancelAnimationFrame(B),R.dispose(),window.removeEventListener(M,g),k?.disconnect(),_(),r.dispose(),y.current=null}},[t,c,E,h,C]),l.useEffect(()=>{if(!u)return;const m=requestAnimationFrame(()=>{const r=y.current;if(r){try{r.fit.fit(),h({type:"terminal_resize",terminalId:c,conversationId:t,cols:r.term.cols,rows:r.term.rows})}catch{}r.term.focus()}});return()=>cancelAnimationFrame(m)},[u]);const{t:F}=P(),f=l.useRef(void 0);return l.useEffect(()=>{if(v===f.current||(f.current=v,v!==!1))return;const m=y.current;m&&m.term.write(`\r
4
+ \x1B[90m${F("exitBanner",{code:j??""})}\x1B[0m\r
5
+ `)},[v,c,j]),n.jsx("div",{ref:T,className:`term-xterm ${u?"":"hidden"}`})}const q={name:"",command:"",cwd:"${pwd}"};function pe({chat:t,send:c,terminal:p}){const a=W(),[x,u]=l.useState(null),[v,j]=l.useState(!1),[h,C]=l.useState(!1),[T,y]=l.useState(null),[o,N]=l.useState(q),[E,F]=l.useState(null),f=l.useRef(null),[m,r]=l.useState(!0),[b,g]=l.useState(null),[_,$]=l.useState("");l.useEffect(()=>{t.terminals.length===0?u(null):t.terminals.some(e=>e.id===x)||u(t.terminals[t.terminals.length-1].id)},[t.terminals,x]),l.useEffect(()=>{t.terminalActiveId&&(u(t.terminalActiveId),j(!1))},[t.terminalActiveId]),l.useEffect(()=>()=>{f.current&&clearTimeout(f.current)},[]);const B=t.terminals.filter(e=>!e.agentBash),R=t.terminals.filter(e=>e.agentBash),k=e=>{if(!t.ready)return;const s=ae(),i=t.activeConversationId||t.state?.conversationId||"";p.create({...e,id:s,conversationId:i,cols:e.cols??80,rows:e.rows??24,running:!0,exitCode:null}),u(s),j(!1)},d=()=>k({title:a("terminalTitle",{n:B.length+1}),cwd:t.state?.cwd??""}),S=e=>{const s=e.name||e.command,i=t.terminals.find(w=>w.title===s);if(i){p.restart(i.id),u(i.id),c({type:"run_command",terminalId:i.id,conversationId:i.conversationId,command:e,cols:80,rows:24});return}k({title:s,cwd:t.state?.cwd??"",command:e})},D=e=>{const s=t.terminals.find(i=>i.id===e);if(s&&c({type:"terminal_kill",terminalId:e,conversationId:s.conversationId}),p.close(e),x===e){const i=t.terminals.filter(w=>w.id!==e);u(i.length>0?i[i.length-1].id:null)}},I=e=>n.jsxs("div",{className:`term-tab ${e.id===x?"active":""}`,children:[n.jsxs("button",{type:"button",className:"term-tab-main",title:`${e.cwd}${e.command?`
6
+ > ${e.command.command}`:""}`,onClick:()=>{b||(u(e.id),j(!1))},children:[n.jsx("span",{className:`term-tab-dot ${e.running?"run":"exit"}`}),n.jsxs("span",{className:"term-tab-title",children:[b===e.id?n.jsx("input",{autoFocus:!0,className:"term-tab-rename-input",value:_,placeholder:e.title,onClick:s=>s.stopPropagation(),onChange:s=>$(s.target.value),onKeyDown:s=>{if(s.stopPropagation(),s.key==="Enter"&&!s.nativeEvent.isComposing){const i=_.trim();i&&c({type:"rename_terminal",terminalId:e.id,conversationId:e.conversationId,title:i}),g(null)}else s.key==="Escape"&&g(null)},onBlur:()=>g(null)}):e.title,!e.running&&n.jsx("span",{className:"term-tab-exit",children:a("exited",{code:e.exitCode===null?"":` ${e.exitCode}`})})]})]}),n.jsx("button",{type:"button",className:"term-tab-close term-tab-rename",title:a("renameTerminal"),onClick:s=>{s.stopPropagation(),$(e.title),g(e.id)},children:n.jsx(H,{})}),n.jsx("button",{type:"button",className:"term-tab-close",title:a("closeTerminal"),onClick:()=>D(e.id),children:n.jsx(se,{})})]},e.id),G=()=>{C(!0),y(null),N(q)},L=e=>{const s=t.commands[e];s&&(C(!1),y(e),N({name:s.name,command:s.command,cwd:s.cwd??""}))},K=()=>{C(!1),y(null)},A=()=>{const e=o.name.trim(),s=o.command.trim();if(!e||!s)return;const i=o.cwd.trim(),w={name:e,command:s,cwd:i||void 0},Q=h?[...t.commands,w]:T!==null?t.commands.map((U,V)=>V===T?w:U):t.commands;c({type:"save_commands",commands:Q}),K()},J=e=>{if(E===e){const s=t.commands.filter((i,w)=>w!==e);c({type:"save_commands",commands:s}),F(null),f.current&&clearTimeout(f.current)}else F(e),f.current&&clearTimeout(f.current),f.current=setTimeout(()=>F(null),2500)},X=h||T!==null;return n.jsxs("div",{className:"terminal-view",children:[n.jsxs("aside",{className:`term-side term-commands ${v?"open":""}`,children:[n.jsxs("div",{className:"panel-header",children:[n.jsx("span",{className:"panel-title",children:a("commands")}),n.jsxs("div",{className:"panel-header-actions",children:[n.jsx("button",{type:"button",className:"panel-refresh",title:a("rerun"),onClick:()=>c({type:"list_commands"}),children:n.jsx(Y,{})}),n.jsx("button",{type:"button",className:"panel-new",title:a("newCommand"),onClick:G,children:n.jsx(z,{})})]})]}),n.jsx("div",{className:"panel-body",children:X?n.jsxs("div",{className:"cmd-form",children:[n.jsx("label",{htmlFor:"cmd-name",children:a("name")}),n.jsx("input",{id:"cmd-name",className:"cmd-input",value:o.name,placeholder:a("exampleName"),autoFocus:!0,onChange:e=>N({...o,name:e.target.value})}),n.jsx("label",{htmlFor:"cmd-command",children:a("command")}),n.jsx("input",{id:"cmd-command",className:"cmd-input",value:o.command,placeholder:a("exampleCommand"),onChange:e=>N({...o,command:e.target.value}),onKeyDown:e=>{e.key==="Enter"&&!e.nativeEvent.isComposing&&A()}}),n.jsxs("label",{htmlFor:"cmd-cwd",children:[a("directory")," ",n.jsx("span",{className:"cmd-hint",children:a("cwdHint")})]}),n.jsx("input",{id:"cmd-cwd",className:"cmd-input",value:o.cwd,placeholder:"${pwd}",onChange:e=>N({...o,cwd:e.target.value}),onKeyDown:e=>{e.key==="Enter"&&!e.nativeEvent.isComposing&&A()}}),n.jsxs("div",{className:"cmd-form-actions",children:[n.jsx("button",{type:"button",className:"btn",onClick:K,children:a("cancel")}),n.jsx("button",{type:"button",className:"btn primary",disabled:!o.name.trim()||!o.command.trim(),onClick:A,children:a("save")})]})]}):n.jsxs(n.Fragment,{children:[t.commands.length===0&&n.jsx("div",{className:"panel-empty",children:a("noCommands")}),t.commands.map((e,s)=>n.jsxs("div",{className:"cmd-item",children:[n.jsx("button",{type:"button",className:"cmd-run",title:a("clickToRun"),onClick:()=>S(e),children:n.jsx(Z,{})}),n.jsxs("button",{type:"button",className:"cmd-main",title:a("clickToRun"),onClick:()=>S(e),children:[n.jsx("span",{className:"cmd-name",children:e.name}),n.jsx("span",{className:"cmd-command",children:e.command}),e.cwd&&n.jsx("span",{className:"cmd-cwd",children:e.cwd})]}),n.jsx("button",{type:"button",className:"cmd-act",title:a("edit"),onClick:()=>L(s),children:n.jsx(H,{})}),n.jsx("button",{type:"button",className:`cmd-act del ${E===s?"confirm":""}`,title:a("delete"),onClick:()=>J(s),children:E===s?a("confirmQ"):n.jsx(ee,{})})]},s))]})}),n.jsxs("div",{className:"term-tabs-block",children:[n.jsxs("div",{className:"panel-header",children:[n.jsx("span",{className:"panel-title",children:a("terminal")}),n.jsx("button",{type:"button",className:"panel-new",title:a("newTerminal"),onClick:d,children:n.jsx(z,{})})]}),n.jsxs("div",{className:"panel-body",children:[t.terminals.length===0&&n.jsx("div",{className:"panel-empty",children:a("noTerminal")}),B.map(I),R.length>0&&n.jsxs("div",{className:"term-folder",children:[n.jsxs("button",{type:"button",className:`term-folder-header ${m?"open":""}`,title:a("aiBashGroup"),onClick:()=>r(e=>!e),children:[n.jsx("span",{className:"term-folder-caret",children:m?"▾":"▸"}),n.jsx("span",{className:"term-folder-title",children:a("aiBashGroup")}),n.jsx("span",{className:"term-folder-count",children:R.length})]}),m&&n.jsx("div",{className:"term-folder-body",children:R.map(I)})]})]})]})]}),n.jsxs("div",{className:"term-main",children:[v&&n.jsx("div",{className:"drawer-backdrop",onClick:()=>j(!1)}),n.jsx("button",{type:"button",className:"term-side-toggle",title:a("commands"),onClick:()=>j(e=>!e),children:n.jsx(ne,{})}),t.terminals.length===0?n.jsxs("div",{className:"term-empty",children:[n.jsx(te,{className:"term-empty-icon"}),n.jsx("div",{className:"term-empty-title",children:a("builtinTerminal")}),n.jsx("div",{className:"term-empty-sub",children:a("termEmptySub")})]}):t.terminals.map(e=>n.jsx(ce,{conversationId:e.conversationId,terminalId:e.id,command:e.command,cwd:e.cwd,title:e.title,active:e.id===x,running:e.running,exitCode:e.exitCode,send:c,register:p.register},`${e.conversationId}:${e.id}`))]})]})}export{pe as TerminalPanel};
@@ -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;inset: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;inset: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;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}