pi-web-ui 0.68.1 → 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.
- package/dist/server/agent-service.js +150 -53
- package/dist/server/client-state.js +4 -2
- package/dist/server/dsh/dsh-agent-service.js +15 -1
- package/dist/server/dsh/runtime/runtime-root.mjs +17 -11
- package/dist/server/index.js +61 -1
- package/dist/server/locales.js +156 -0
- package/dist/server/prompt-composer.js +34 -0
- package/dist/server/settings-service.js +9 -0
- package/dist/server/update-check.js +49 -50
- package/package.json +3 -1
- package/web/dist/assets/TerminalPanel-BQ5NTB9Y.js +6 -0
- package/web/dist/assets/TerminalPanel-DOrYoP_4.css +32 -0
- package/web/dist/assets/index-C_I-6Zul.css +10 -0
- package/web/dist/assets/index-Ck5pa3XK.js +333 -0
- package/web/dist/assets/markdown-DOsihKaR.js +51 -0
- package/web/dist/assets/{react-C9ovnpIm.js → react-DIP6JKYk.js} +2 -2
- package/web/dist/assets/xterm-B96xOxS9.js +38 -0
- package/web/dist/index.html +4 -4
- package/web/dist/assets/TerminalPanel-6GBZ9nXN.css +0 -32
- package/web/dist/assets/TerminalPanel-IJF_fssI.js +0 -6
- package/web/dist/assets/index-BmiyyjKp.css +0 -10
- package/web/dist/assets/index-qoTr5KXy.js +0 -332
- package/web/dist/assets/markdown-DRBrS2Nf.js +0 -51
- package/web/dist/assets/xterm-D1D2FVe3.js +0 -38
|
@@ -0,0 +1,156 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* locales — downloadable language packs.
|
|
3
|
+
*
|
|
4
|
+
* Core ships zh/en only (see web/src/i18n.tsx). Every other language lives in
|
|
5
|
+
* `locales/<code>.json` in the git repo (NOT in the npm `files` whitelist, so
|
|
6
|
+
* packs never ship with the package) with shape:
|
|
7
|
+
* { code, nativeName, version, strings: Record<string,string> }
|
|
8
|
+
*
|
|
9
|
+
* On demand the server downloads a pack from PI_WEB_LOCALE_BASE_URL
|
|
10
|
+
* (default: GitHub raw — version tag first, `main` as fallback) into
|
|
11
|
+
* <dataDir>/locales/<code>.json and serves it to the browser. Missing keys
|
|
12
|
+
* fall back to English client-side, so version skew between app and pack is
|
|
13
|
+
* tolerable. Manually dropped <dataDir>/locales/*.json files work too
|
|
14
|
+
* (offline installs) — the list is read from disk.
|
|
15
|
+
*/
|
|
16
|
+
import { existsSync, mkdirSync, readFileSync, renameSync, rmSync, writeFileSync } from "node:fs";
|
|
17
|
+
import { join } from "node:path";
|
|
18
|
+
/** Packs available for download (alphabetical by code). */
|
|
19
|
+
export const LOCALE_PACKS = [
|
|
20
|
+
{ code: "de", nativeName: "Deutsch" },
|
|
21
|
+
{ code: "es", nativeName: "Español" },
|
|
22
|
+
{ code: "fr", nativeName: "Français" },
|
|
23
|
+
{ code: "it", nativeName: "Italiano" },
|
|
24
|
+
{ code: "ja", nativeName: "日本語" },
|
|
25
|
+
{ code: "ko", nativeName: "한국어" },
|
|
26
|
+
{ code: "pt", nativeName: "Português" },
|
|
27
|
+
{ code: "ru", nativeName: "Русский" },
|
|
28
|
+
];
|
|
29
|
+
export function isKnownPack(code) {
|
|
30
|
+
return LOCALE_PACKS.some((p) => p.code === code);
|
|
31
|
+
}
|
|
32
|
+
export function packMeta(code) {
|
|
33
|
+
return LOCALE_PACKS.find((p) => p.code === code) ?? null;
|
|
34
|
+
}
|
|
35
|
+
export function packPath(dataDir, code) {
|
|
36
|
+
return join(dataDir, "locales", `${code}.json`);
|
|
37
|
+
}
|
|
38
|
+
/** Downloaded packs must look like this (extra fields ignored). */
|
|
39
|
+
export function validatePack(data, code) {
|
|
40
|
+
if (!data || typeof data !== "object")
|
|
41
|
+
return { ok: false, error: "not an object" };
|
|
42
|
+
const d = data;
|
|
43
|
+
if (d["code"] !== code)
|
|
44
|
+
return { ok: false, error: `code mismatch (want ${code})` };
|
|
45
|
+
if (typeof d["nativeName"] !== "string" || !d["nativeName"].trim()) {
|
|
46
|
+
return { ok: false, error: "missing nativeName" };
|
|
47
|
+
}
|
|
48
|
+
if (!d["strings"] || typeof d["strings"] !== "object")
|
|
49
|
+
return { ok: false, error: "missing strings" };
|
|
50
|
+
const strings = {};
|
|
51
|
+
for (const [k, v] of Object.entries(d["strings"])) {
|
|
52
|
+
if (typeof v !== "string")
|
|
53
|
+
return { ok: false, error: `non-string value for ${k}` };
|
|
54
|
+
strings[k] = v;
|
|
55
|
+
}
|
|
56
|
+
if (Object.keys(strings).length === 0)
|
|
57
|
+
return { ok: false, error: "empty strings" };
|
|
58
|
+
return {
|
|
59
|
+
ok: true,
|
|
60
|
+
pack: {
|
|
61
|
+
code,
|
|
62
|
+
nativeName: d["nativeName"].trim(),
|
|
63
|
+
version: typeof d["version"] === "string" ? d["version"] : "unknown",
|
|
64
|
+
strings,
|
|
65
|
+
},
|
|
66
|
+
};
|
|
67
|
+
}
|
|
68
|
+
/** Read an installed pack (null when missing / corrupt — corrupt files are ignored, not deleted). */
|
|
69
|
+
export function readPackFile(dataDir, code) {
|
|
70
|
+
if (!isKnownPack(code))
|
|
71
|
+
return null;
|
|
72
|
+
const file = packPath(dataDir, code);
|
|
73
|
+
if (!existsSync(file))
|
|
74
|
+
return null;
|
|
75
|
+
try {
|
|
76
|
+
const data = JSON.parse(readFileSync(file, "utf8"));
|
|
77
|
+
const v = validatePack(data, code);
|
|
78
|
+
return v.ok ? v.pack : null;
|
|
79
|
+
}
|
|
80
|
+
catch {
|
|
81
|
+
return null;
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
export function listPacks(dataDir) {
|
|
85
|
+
return LOCALE_PACKS.map((meta) => {
|
|
86
|
+
const installed = readPackFile(dataDir, meta.code);
|
|
87
|
+
return { ...meta, installed: installed !== null, version: installed?.version ?? null };
|
|
88
|
+
});
|
|
89
|
+
}
|
|
90
|
+
export function removePack(dataDir, code) {
|
|
91
|
+
if (!isKnownPack(code))
|
|
92
|
+
return false;
|
|
93
|
+
const file = packPath(dataDir, code);
|
|
94
|
+
if (!existsSync(file))
|
|
95
|
+
return false;
|
|
96
|
+
rmSync(file);
|
|
97
|
+
return true;
|
|
98
|
+
}
|
|
99
|
+
const MAX_PACK_BYTES = 4 * 1024 * 1024;
|
|
100
|
+
/**
|
|
101
|
+
* Download a pack and persist it under <dataDir>/locales/<code>.json
|
|
102
|
+
* (atomic write via tmp + rename). Throws on network / validation errors.
|
|
103
|
+
*/
|
|
104
|
+
export async function installPack(dataDir, code, opts = {}) {
|
|
105
|
+
const meta = packMeta(code);
|
|
106
|
+
if (!meta)
|
|
107
|
+
throw new Error(`unknown locale: ${code}`);
|
|
108
|
+
const base = (opts.baseUrl ?? "https://raw.githubusercontent.com/xing-shuyin/pi-web-ui").replace(/\/+$/, "");
|
|
109
|
+
const urls = opts.version
|
|
110
|
+
? [`${base}/v${opts.version}/locales/${code}.json`, `${base}/main/locales/${code}.json`]
|
|
111
|
+
: [`${base}/main/locales/${code}.json`];
|
|
112
|
+
const fetchFn = opts.fetchFn ?? fetch;
|
|
113
|
+
const timeoutMs = opts.timeoutMs ?? 30000;
|
|
114
|
+
let lastError = "";
|
|
115
|
+
for (const url of urls) {
|
|
116
|
+
const ctrl = new AbortController();
|
|
117
|
+
const timer = setTimeout(() => ctrl.abort(), timeoutMs);
|
|
118
|
+
try {
|
|
119
|
+
const res = await fetchFn(url, { signal: ctrl.signal });
|
|
120
|
+
if (!res.ok) {
|
|
121
|
+
lastError = `HTTP ${res.status} for ${url}`;
|
|
122
|
+
continue;
|
|
123
|
+
}
|
|
124
|
+
const text = await res.text();
|
|
125
|
+
if (text.length > MAX_PACK_BYTES)
|
|
126
|
+
throw new Error(`pack too large (${text.length} bytes)`);
|
|
127
|
+
let data;
|
|
128
|
+
try {
|
|
129
|
+
data = JSON.parse(text);
|
|
130
|
+
}
|
|
131
|
+
catch {
|
|
132
|
+
throw new Error(`invalid JSON from ${url}`);
|
|
133
|
+
}
|
|
134
|
+
const v = validatePack(data, code);
|
|
135
|
+
if (!v.ok)
|
|
136
|
+
throw new Error(`invalid pack ${code}: ${v.error}`);
|
|
137
|
+
mkdirSync(join(dataDir, "locales"), { recursive: true });
|
|
138
|
+
const file = packPath(dataDir, code);
|
|
139
|
+
const tmp = `${file}.${process.pid}.tmp`;
|
|
140
|
+
writeFileSync(tmp, JSON.stringify(v.pack));
|
|
141
|
+
renameSync(tmp, file);
|
|
142
|
+
return { code, nativeName: v.pack.nativeName, version: v.pack.version };
|
|
143
|
+
}
|
|
144
|
+
catch (e) {
|
|
145
|
+
lastError = e instanceof Error ? e.message : String(e);
|
|
146
|
+
// A validation error means the URL answered with wrong content —
|
|
147
|
+
// don't silently retry the fallback for it, surface it directly.
|
|
148
|
+
if (lastError.startsWith("invalid "))
|
|
149
|
+
throw e;
|
|
150
|
+
}
|
|
151
|
+
finally {
|
|
152
|
+
clearTimeout(timer);
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
throw new Error(lastError || `download failed for ${code}`);
|
|
156
|
+
}
|
|
@@ -31,6 +31,25 @@ export const PROMPT_TOKENS = [
|
|
|
31
31
|
"skills", // 技能段 <available_skills>
|
|
32
32
|
"cwd", // Current working directory 行
|
|
33
33
|
];
|
|
34
|
+
/** 只读来源(设置面板只读展示、不提供覆盖输入):这些 token 的内容由系统/环境
|
|
35
|
+
* 在每次 run 时动态生成(工具集、项目文件、技能、工作目录、开关状态),用户无法
|
|
36
|
+
* 在设置里预设其内容。反之 soul / guidelines / append 是用户内容层,可编辑。
|
|
37
|
+
* 注意:只读是「设置面板 UI」层面;服务端 override 机制(renderPromptTemplate)
|
|
38
|
+
* 仍保留,以兼容旧配置与编程调用。 */
|
|
39
|
+
export const READONLY_PROMPT_SOURCES = [
|
|
40
|
+
"tools", // 工具列表(运行时时按已注册工具动态生成)
|
|
41
|
+
"pi_docs", // Pi 文档指引(指向已安装 pi 包路径,由安装位置决定)
|
|
42
|
+
"persona", // Windows persona(仅 win32,平台固定)
|
|
43
|
+
"terminal", // 终端工具使用引导(随「终端工具」开关)
|
|
44
|
+
"markers", // 内置标记工具引导(随 markers 开关)
|
|
45
|
+
"context", // 项目上下文(AGENTS.md / CLAUDE.md 收集结果)
|
|
46
|
+
"skills", // 技能段(来自环境/技能文件)
|
|
47
|
+
"cwd", // 当前工作目录
|
|
48
|
+
];
|
|
49
|
+
/** 仅当 token 是只读来源时返回 true(设置面板用于判断是否展示覆盖输入框)。 */
|
|
50
|
+
export function isReadonlyPromptSource(token) {
|
|
51
|
+
return READONLY_PROMPT_SOURCES.includes(token);
|
|
52
|
+
}
|
|
34
53
|
/** 默认模板:全部 token 按自然顺序以空行连接 —— 无覆盖、不改动时渲染结果 ≈
|
|
35
54
|
* SDK 默认拼装的完整提示词。 */
|
|
36
55
|
export const DEFAULT_PROMPT_TEMPLATE = PROMPT_TOKENS.map((t) => `{{${t}}}`).join("\n\n");
|
|
@@ -147,6 +166,21 @@ function buildToolsText(inputs) {
|
|
|
147
166
|
"In addition to the tools above, you may have access to other custom tools depending on the project.",
|
|
148
167
|
].join("\n\n");
|
|
149
168
|
}
|
|
169
|
+
/** 工具 schema 只读文本(设置面板「查看当前完整提示词」里展示发给模型的完整
|
|
170
|
+
* 工具定义:name + description + parameters JSON Schema)。 */
|
|
171
|
+
export function buildToolsSchemaText(tools) {
|
|
172
|
+
if (tools.length === 0)
|
|
173
|
+
return "";
|
|
174
|
+
return tools
|
|
175
|
+
.map((t) => {
|
|
176
|
+
const lines = [`## ${t.name}`];
|
|
177
|
+
if (t.description && t.description.trim())
|
|
178
|
+
lines.push(t.description.trim());
|
|
179
|
+
lines.push("", "Parameters (JSON Schema):", JSON.stringify(t.parameters ?? {}, null, 2));
|
|
180
|
+
return lines.join("\n");
|
|
181
|
+
})
|
|
182
|
+
.join("\n\n");
|
|
183
|
+
}
|
|
150
184
|
/** 计算每个 token 的自动内容(无覆盖时的展开值)。 */
|
|
151
185
|
export function resolveSectionTexts(inputs) {
|
|
152
186
|
const cwd = inputs.cwd.replace(/\\/g, "/");
|
|
@@ -193,6 +193,7 @@ export class SettingsService {
|
|
|
193
193
|
terminalBash: this.settings.terminalBash,
|
|
194
194
|
terminalBashIdleMs: this.settings.terminalBashIdleMs,
|
|
195
195
|
editSoftEnabled: this.settings.editSoftEnabled,
|
|
196
|
+
questionnaireEnabled: this.settings.questionnaireEnabled,
|
|
196
197
|
thinkingWrap: this.settings.thinkingWrap,
|
|
197
198
|
toolsWrap: this.settings.toolsWrap,
|
|
198
199
|
visionBridgeEnabled: this.settings.visionBridgeEnabled,
|
|
@@ -206,6 +207,8 @@ export class SettingsService {
|
|
|
206
207
|
effectiveSystemPrompt: promptSnap.full,
|
|
207
208
|
// 每个来源未覆盖时的默认(自动)内容(「各来源」行预览用)。
|
|
208
209
|
promptSourceDefaults: promptSnap.texts,
|
|
210
|
+
// 发给模型的工具 schema(name/description/parameters)—— 只读预览。
|
|
211
|
+
toolsSchema: promptSnap.toolsSchema,
|
|
209
212
|
visionBridgeDefaultPrompt: SYSTEM_PROMPT,
|
|
210
213
|
visionModels: this.collectVisionModels(),
|
|
211
214
|
disabledSkills: [...this.settings.disabledSkills],
|
|
@@ -320,6 +323,10 @@ export class SettingsService {
|
|
|
320
323
|
if (partial.editSoftEnabled !== undefined) {
|
|
321
324
|
this.settings.editSoftEnabled = partial.editSoftEnabled;
|
|
322
325
|
}
|
|
326
|
+
// 问卷开关:运行时无需重载(bridge 处实时读取)。
|
|
327
|
+
if (partial.questionnaireEnabled !== undefined) {
|
|
328
|
+
this.settings.questionnaireEnabled = partial.questionnaireEnabled;
|
|
329
|
+
}
|
|
323
330
|
if (partial.thinkingWrap !== undefined) {
|
|
324
331
|
this.settings.thinkingWrap = partial.thinkingWrap;
|
|
325
332
|
}
|
|
@@ -425,6 +432,8 @@ export class SettingsService {
|
|
|
425
432
|
terminalBash: p.terminalBash ?? this.settings.terminalBash,
|
|
426
433
|
terminalBashIdleMs: p.terminalBashIdleMs ?? this.settings.terminalBashIdleMs,
|
|
427
434
|
editSoftEnabled: p.editSoftEnabled ?? this.settings.editSoftEnabled,
|
|
435
|
+
// 问卷开关不进预设——保留当前值。
|
|
436
|
+
questionnaireEnabled: this.settings.questionnaireEnabled,
|
|
428
437
|
reviewPrompt: p.reviewPrompt ?? this.settings.reviewPrompt,
|
|
429
438
|
reviewDisabledSkills: [...(p.reviewDisabledSkills ?? this.settings.reviewDisabledSkills)],
|
|
430
439
|
// 纯 UI 偏好不进预设——保留当前值。
|
|
@@ -7,9 +7,8 @@
|
|
|
7
7
|
* (and an injected pi-core probe); ClientSession only wires it to the wire
|
|
8
8
|
* protocol.
|
|
9
9
|
*/
|
|
10
|
-
import {
|
|
11
|
-
import {
|
|
12
|
-
import { join } from "node:path";
|
|
10
|
+
import { readdirSync, readFileSync, realpathSync, existsSync } from "node:fs";
|
|
11
|
+
import { delimiter, dirname, join } from "node:path";
|
|
13
12
|
const PI_CORE_PACKAGE = "@earendil-works/pi-coding-agent";
|
|
14
13
|
const REGISTRY = "https://registry.npmjs.org";
|
|
15
14
|
const FETCH_TIMEOUT_MS = 8_000;
|
|
@@ -157,67 +156,67 @@ function readLocalPackage(dir) {
|
|
|
157
156
|
/** How long a pi probe result stays hot (mirrors ClientSession.piCliProbe). */
|
|
158
157
|
const PI_PROBE_TTL_MS = 10_000;
|
|
159
158
|
let piCoreProbe = null;
|
|
160
|
-
|
|
161
|
-
function
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
159
|
+
/** Locate the pi CLI on PATH without spawning anything. */
|
|
160
|
+
function piCliOnPath() {
|
|
161
|
+
const dirs = (process.env.PATH ?? "").split(delimiter);
|
|
162
|
+
for (const dir of dirs) {
|
|
163
|
+
if (!dir)
|
|
164
|
+
continue;
|
|
165
|
+
const candidate = join(dir, "pi");
|
|
166
|
+
if (existsSync(candidate))
|
|
167
|
+
return candidate;
|
|
168
|
+
}
|
|
169
|
+
return null;
|
|
170
|
+
}
|
|
171
|
+
/**
|
|
172
|
+
* Read the pi core version from disk: resolve the `pi` bin (typically a
|
|
173
|
+
* symlink into <global>/node_modules/<pkg>/dist/bundle/cli.js) and walk up to
|
|
174
|
+
* its package.json. FORK-FREE by design — see the note on defaultProbePiCore.
|
|
175
|
+
*/
|
|
176
|
+
function readPiCoreVersionFromDisk() {
|
|
177
|
+
const bin = piCliOnPath();
|
|
178
|
+
if (!bin)
|
|
179
|
+
return null;
|
|
166
180
|
try {
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
181
|
+
let dir = dirname(realpathSync(bin));
|
|
182
|
+
for (let i = 0; i < 8; i++) {
|
|
183
|
+
const pkgPath = join(dir, "package.json");
|
|
184
|
+
if (existsSync(pkgPath)) {
|
|
185
|
+
try {
|
|
186
|
+
const pkg = JSON.parse(readFileSync(pkgPath, "utf8"));
|
|
187
|
+
if (pkg.name === PI_CORE_PACKAGE && pkg.version)
|
|
188
|
+
return pkg.version;
|
|
189
|
+
}
|
|
190
|
+
catch {
|
|
191
|
+
/* unreadable package.json — keep walking */
|
|
192
|
+
}
|
|
193
|
+
}
|
|
194
|
+
const parent = dirname(dir);
|
|
195
|
+
if (parent === dir)
|
|
196
|
+
break;
|
|
197
|
+
dir = parent;
|
|
198
|
+
}
|
|
173
199
|
}
|
|
174
200
|
catch {
|
|
175
|
-
|
|
176
|
-
piCoreProbePending = false;
|
|
177
|
-
return;
|
|
201
|
+
/* ignore */
|
|
178
202
|
}
|
|
179
|
-
|
|
180
|
-
const finish = (version) => {
|
|
181
|
-
piCoreProbe = { at: Date.now(), version };
|
|
182
|
-
piCoreProbePending = false;
|
|
183
|
-
};
|
|
184
|
-
const timer = setTimeout(() => {
|
|
185
|
-
try {
|
|
186
|
-
proc.kill();
|
|
187
|
-
}
|
|
188
|
-
catch {
|
|
189
|
-
/* already exited */
|
|
190
|
-
}
|
|
191
|
-
finish(null);
|
|
192
|
-
}, 5000);
|
|
193
|
-
proc.stdout?.on("data", (d) => (out += d.toString()));
|
|
194
|
-
proc.on("error", () => {
|
|
195
|
-
clearTimeout(timer);
|
|
196
|
-
finish(null);
|
|
197
|
-
});
|
|
198
|
-
proc.on("close", (code) => {
|
|
199
|
-
clearTimeout(timer);
|
|
200
|
-
finish(code === 0 ? parsePiVersionOutput(out) : null);
|
|
201
|
-
});
|
|
203
|
+
return null;
|
|
202
204
|
}
|
|
203
205
|
/**
|
|
204
206
|
* Default pi core probe: run the globally installed `pi --version`, memoized
|
|
205
207
|
* machine-wide for PI_PROBE_TTL_MS so repeated collectTargets calls never
|
|
206
|
-
* re-probe.
|
|
207
|
-
*
|
|
208
|
-
*
|
|
209
|
-
* multi-threaded process occasionally leaves the forked child stuck between
|
|
210
|
-
* fork and exec while the main thread sits in spawnSync's pipe_read. Mirrors
|
|
211
|
-
* ClientSession.isPiCliInstalled(); Windows resolves `pi` to a pi.cmd shim
|
|
212
|
-
* that only execs through a shell.)
|
|
208
|
+
* re-probe. Reads the version from disk (pi bin → realpath → package.json)
|
|
209
|
+
* instead of spawning `pi --version`. FORK-FREE by design — see the note on
|
|
210
|
+
* defaultProbePiCore.
|
|
213
211
|
*/
|
|
214
212
|
export function defaultProbePiCore() {
|
|
215
213
|
const now = Date.now();
|
|
216
214
|
const cached = piCoreProbe;
|
|
217
215
|
if (cached && now - cached.at < PI_PROBE_TTL_MS)
|
|
218
216
|
return cached.version;
|
|
219
|
-
|
|
220
|
-
|
|
217
|
+
const version = readPiCoreVersionFromDisk();
|
|
218
|
+
piCoreProbe = { at: now, version };
|
|
219
|
+
return version;
|
|
221
220
|
}
|
|
222
221
|
/**
|
|
223
222
|
* Fallback when the CLI probe yields nothing: the version of the vendored pi
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "pi-web-ui",
|
|
3
|
-
"version": "0.68.
|
|
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": {
|
|
@@ -84,6 +84,7 @@
|
|
|
84
84
|
"react-icons": "^5.7.0",
|
|
85
85
|
"react-markdown": "^9.0.1",
|
|
86
86
|
"rehype-highlight": "^7.0.1",
|
|
87
|
+
"rehype-raw": "^7.0.0",
|
|
87
88
|
"remark-gfm": "^4.0.0",
|
|
88
89
|
"typebox": "^1.3.14",
|
|
89
90
|
"ws": "^8.18.0"
|
|
@@ -99,6 +100,7 @@
|
|
|
99
100
|
"concurrently": "^9.1.0",
|
|
100
101
|
"cross-env": "^10.1.0",
|
|
101
102
|
"esbuild": "^0.25.12",
|
|
103
|
+
"jsdom": "^26.1.0",
|
|
102
104
|
"mermaid": "^11.17.2",
|
|
103
105
|
"oxlint": "^1.81.0",
|
|
104
106
|
"playwright-core": "^1.62.1",
|
|
@@ -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}
|