@evandu/super-pi 0.1.211 → 0.1.213
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/agents/super-pi-task/index.ts +2 -2
- package/dist/client/.super-pi-client-sources.json +13 -11
- package/dist/client/assets/{CodeMirrorEditor-MdWueY4Q.js → CodeMirrorEditor-CWQ63ic7.js} +2 -2
- package/dist/client/assets/{dist-CqySFKLY.js → dist-1JCM42S_.js} +1 -1
- package/dist/client/assets/{dist-C0YOtlvB.js → dist-B4JgRHcx.js} +1 -1
- package/dist/client/assets/{dist-B-1cvb_W.js → dist-BflbRJh7.js} +1 -1
- package/dist/client/assets/{dist-BuAO0LWb.js → dist-BovQNGqG.js} +1 -1
- package/dist/client/assets/{dist-C3mMFcwt.js → dist-C1bYhGj9.js} +1 -1
- package/dist/client/assets/{dist-CAzQDVvy.js → dist-C89gZQyY.js} +1 -1
- package/dist/client/assets/{dist-cCJE_Zja.js → dist-CBwA1Hj6.js} +1 -1
- package/dist/client/assets/{dist-Bkzn7IaC.js → dist-CSJ40osf.js} +1 -1
- package/dist/client/assets/{dist-B8WfwLcX.js → dist-CTyatJ4C.js} +1 -1
- package/dist/client/assets/{dist-w8qcu8q7.js → dist-Cfsepw_s.js} +1 -1
- package/dist/client/assets/{dist-CLWiSrA-.js → dist-CgaceQnz.js} +1 -1
- package/dist/client/assets/{dist-C_Wz6ihj.js → dist-D6hqngEN.js} +1 -1
- package/dist/client/assets/{dist-DVAByMNF.js → dist-DBYIaqLh.js} +1 -1
- package/dist/client/assets/{dist-1xDQIWzD.js → dist-DI4tD3TE.js} +1 -1
- package/dist/client/assets/{dist-D8fuymoV.js → dist-DPvPBdAr.js} +1 -1
- package/dist/client/assets/{dist-B6ISmJaJ.js → dist-DcP6TqSv.js} +1 -1
- package/dist/client/assets/{dist-CfHytN2f.js → dist-DmQVKHaq.js} +1 -1
- package/dist/client/assets/{dist-CNd5Ci5w.js → dist-DrCHmlZi.js} +1 -1
- package/dist/client/assets/{dist-BPuO75ds.js → dist-Dwo0gVvc.js} +1 -1
- package/dist/client/assets/{dist-CHCNt4B9.js → dist-jVJqGU4O.js} +1 -1
- package/dist/client/assets/{dist-D6IPUy64.js → dist-n_tNFYcU.js} +1 -1
- package/dist/client/assets/{dist-BYGObtWt.js → dist-xglN4F4D.js} +1 -1
- package/dist/client/assets/{index-DvsjPwq0.css → index-Bsz1JjtL.css} +1 -1
- package/dist/client/assets/{index-KGJni2S2.js → index-DaGnNSnb.js} +51 -51
- package/dist/client/index.html +2 -2
- package/dist/server/git.d.ts +1 -1
- package/dist/server/git.js +61 -19
- package/dist/server/http-server.js +2 -2
- package/dist/server/tool-registry.d.ts +2 -0
- package/dist/server/tool-registry.js +4 -1
- package/dist/shared/tool-glyph.d.ts +7 -0
- package/dist/shared/tool-glyph.js +19 -0
- package/package.json +4 -1
package/dist/client/index.html
CHANGED
|
@@ -8,8 +8,8 @@
|
|
|
8
8
|
<link rel="alternate icon" href="/favicon.ico" />
|
|
9
9
|
<link rel="apple-touch-icon" href="/favicon.svg" />
|
|
10
10
|
<title>Super Pi</title>
|
|
11
|
-
<script type="module" crossorigin src="/assets/index-
|
|
12
|
-
<link rel="stylesheet" crossorigin href="/assets/index-
|
|
11
|
+
<script type="module" crossorigin src="/assets/index-DaGnNSnb.js"></script>
|
|
12
|
+
<link rel="stylesheet" crossorigin href="/assets/index-Bsz1JjtL.css">
|
|
13
13
|
</head>
|
|
14
14
|
<body>
|
|
15
15
|
<div id="root"></div>
|
package/dist/server/git.d.ts
CHANGED
|
@@ -33,7 +33,7 @@ export declare function gitDiff(root: string, path: string, staged: boolean): Pr
|
|
|
33
33
|
path: string;
|
|
34
34
|
staged: boolean;
|
|
35
35
|
diff: string;
|
|
36
|
-
kind: "text";
|
|
36
|
+
kind: "binary" | "text";
|
|
37
37
|
}>;
|
|
38
38
|
/**
|
|
39
39
|
* The content of a file AS IT WAS COMMITTED, or `null` when there is no such version.
|
package/dist/server/git.js
CHANGED
|
@@ -4,20 +4,31 @@ import { basename, relative, resolve, sep } from "node:path";
|
|
|
4
4
|
import { existsSync } from "node:fs";
|
|
5
5
|
import { readFile, stat } from "node:fs/promises";
|
|
6
6
|
const exec = promisify(execFile);
|
|
7
|
-
async function git(cwd, args, options) { return exec("git", ["-c", "core.quotepath=false", ...args], { cwd, windowsHide: true, maxBuffer: options?.maxBuffer ?? 8 * 1024 * 1024 }); }
|
|
8
|
-
function files(raw, cwd = "") {
|
|
9
|
-
const
|
|
10
|
-
const
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
if (
|
|
18
|
-
|
|
7
|
+
async function git(cwd, args, options) { return exec("git", ["--literal-pathspecs", "-c", "core.quotepath=false", ...args], { cwd, windowsHide: true, maxBuffer: options?.maxBuffer ?? 8 * 1024 * 1024 }); }
|
|
8
|
+
function files(raw, cwd = "") {
|
|
9
|
+
const staged = [], unstaged = [], untracked = [];
|
|
10
|
+
const records = raw.split("\0");
|
|
11
|
+
for (let index = 0; index < records.length; index++) {
|
|
12
|
+
const line = records[index];
|
|
13
|
+
if (!line || line.length < 4)
|
|
14
|
+
continue;
|
|
15
|
+
const xy = line.slice(0, 2), repoPath = line.slice(3).replaceAll("\\", "/");
|
|
16
|
+
// Porcelain -z emits a second path for renames/copies; it is not a status record.
|
|
17
|
+
if (/[RC]/.test(xy))
|
|
18
|
+
index++;
|
|
19
|
+
const path = cwd && repoPath.startsWith(cwd + "/") ? repoPath.slice(cwd.length + 1) : repoPath;
|
|
20
|
+
const item = { path, name: basename(path), xy };
|
|
21
|
+
if (xy === "??")
|
|
22
|
+
untracked.push(item);
|
|
23
|
+
else {
|
|
24
|
+
if (xy[0] !== " ")
|
|
25
|
+
staged.push(item);
|
|
26
|
+
if (xy[1] !== " ")
|
|
27
|
+
unstaged.push(item);
|
|
28
|
+
}
|
|
19
29
|
}
|
|
20
|
-
|
|
30
|
+
return { staged, unstaged, untracked };
|
|
31
|
+
}
|
|
21
32
|
export async function gitStatus(root, cwd = "") { try {
|
|
22
33
|
await git(root, ["rev-parse", "--git-dir"]);
|
|
23
34
|
}
|
|
@@ -27,9 +38,19 @@ catch {
|
|
|
27
38
|
export async function gitLog(root, limit, cwd = "") { const hasHead = await git(root, ["rev-parse", "--verify", "HEAD"]).then(() => true).catch(() => false); if (!hasHead)
|
|
28
39
|
return { commits: [], truncated: false }; const out = await git(root, ["log", `-${Math.min(Math.max(limit, 1), 50)}`, "--format=%H%x00%h%x00%s%x00%an%x00%aI%x00", ...(cwd ? ["--", cwd] : [])]); const parts = out.stdout.split("\0").filter(Boolean); const commits = []; for (let i = 0; i + 4 < parts.length; i += 5)
|
|
29
40
|
commits.push({ hash: parts[i], short: parts[i + 1], subject: parts[i + 2], author: parts[i + 3], date: new Date(parts[i + 4]).toISOString() }); return { commits, truncated: commits.length >= limit }; }
|
|
30
|
-
export async function gitDiff(root, path, staged) {
|
|
31
|
-
|
|
32
|
-
|
|
41
|
+
export async function gitDiff(root, path, staged) {
|
|
42
|
+
const safe = resolve(root, path);
|
|
43
|
+
if (!safe.startsWith(resolve(root) + sep) || path.includes("\0"))
|
|
44
|
+
throw Object.assign(new Error("文件路径无效"), { code: "path" });
|
|
45
|
+
const tracked = await git(root, ["ls-files", "--error-unmatch", "--", path]).then(() => true).catch(() => false)
|
|
46
|
+
|| staged && await git(root, ["cat-file", "-e", `HEAD:${relative(root, safe).split(sep).join("/")}`]).then(() => true).catch(() => false);
|
|
47
|
+
if (!tracked && !existsSync(safe))
|
|
48
|
+
throw Object.assign(new Error("文件路径无效"), { code: "path" });
|
|
49
|
+
if (!tracked)
|
|
50
|
+
return { path, staged, diff: null, kind: "untracked" };
|
|
51
|
+
const out = await git(root, ["diff", ...(staged ? ["--cached"] : []), "--", path]);
|
|
52
|
+
return { path, staged, diff: out.stdout, kind: /^Binary files .* differ$/m.test(out.stdout) ? "binary" : "text" };
|
|
53
|
+
}
|
|
33
54
|
/**
|
|
34
55
|
* The content of a file AS IT WAS COMMITTED, or `null` when there is no such version.
|
|
35
56
|
*
|
|
@@ -343,21 +364,42 @@ function safePath(root, path) {
|
|
|
343
364
|
return path;
|
|
344
365
|
}
|
|
345
366
|
export async function gitMutate(root, op, path, message, cwd = "") {
|
|
367
|
+
safePath(root, cwd);
|
|
368
|
+
if (op === "stage-all" || op === "unstage-all") {
|
|
369
|
+
if (op === "stage-all")
|
|
370
|
+
await git(root, ["add", "--", cwd || "."]);
|
|
371
|
+
else {
|
|
372
|
+
const hasHead = await git(root, ["rev-parse", "--verify", "HEAD"]).then(() => true).catch(() => false);
|
|
373
|
+
await git(root, hasHead ? ["restore", "--staged", "--", cwd || "."] : ["rm", "--cached", "-r", "-f", "--", cwd || "."]);
|
|
374
|
+
}
|
|
375
|
+
return gitStatus(root, cwd);
|
|
376
|
+
}
|
|
346
377
|
if (op === "stage" || op === "unstage" || op === "discard") {
|
|
347
378
|
if (!path)
|
|
348
379
|
throw Object.assign(new Error("缺少文件路径"), { code: "path" });
|
|
349
380
|
safePath(root, path);
|
|
350
381
|
if (op === "stage")
|
|
351
382
|
await git(root, ["add", "--", path]);
|
|
352
|
-
else if (op === "unstage")
|
|
353
|
-
await git(root, ["
|
|
383
|
+
else if (op === "unstage") {
|
|
384
|
+
const hasHead = await git(root, ["rev-parse", "--verify", "HEAD"]).then(() => true).catch(() => false);
|
|
385
|
+
await git(root, hasHead ? ["restore", "--staged", "--", path] : ["rm", "--cached", "-f", "--", path]);
|
|
386
|
+
}
|
|
354
387
|
else
|
|
355
388
|
await git(root, ["restore", "--", path]);
|
|
356
389
|
}
|
|
357
390
|
else if (op === "commit") {
|
|
358
391
|
if (!message?.trim())
|
|
359
392
|
throw Object.assign(new Error("提交消息不能为空"), { code: "bad_message" });
|
|
360
|
-
await git(root, ["
|
|
393
|
+
const repoRoot = (await git(root, ["rev-parse", "--show-toplevel"])).stdout.trim();
|
|
394
|
+
const indexed = (await git(root, ["diff", "--cached", "--name-only", "--no-renames", "--no-relative", "-z"])).stdout.split("\0").filter(Boolean);
|
|
395
|
+
if (!indexed.length)
|
|
396
|
+
throw Object.assign(new Error("没有已暂存的更改,请先暂存需要提交的文件"), { code: "empty_index" });
|
|
397
|
+
const normalize = (value) => process.platform === "win32" ? resolve(value).toLowerCase() : resolve(value);
|
|
398
|
+
const scope = normalize(resolve(root, cwd));
|
|
399
|
+
if (indexed.some(file => !normalize(resolve(repoRoot, file)).startsWith(scope + sep)))
|
|
400
|
+
throw Object.assign(new Error("暂存区还有当前目录之外的更改,请在共同的仓库目录中提交"), { code: "outside_scope" });
|
|
401
|
+
// A pathspec commit reads working-tree content; an index-only commit preserves partial staging.
|
|
402
|
+
await git(root, ["commit", "-m", message.trim()]);
|
|
361
403
|
}
|
|
362
404
|
else if (op === "pull")
|
|
363
405
|
await git(root, ["pull", "--ff-only"]);
|
|
@@ -457,7 +457,7 @@ export function createHttpServer(options) {
|
|
|
457
457
|
if (local)
|
|
458
458
|
environment = { ...environment, fingerprint: { python: local.python, platform: local.platform, packages: environment.requires } };
|
|
459
459
|
}
|
|
460
|
-
const tool = await toolRegistry.register({ slug: body.slug, name: body.name, description: body.description, entrypoint: body.entrypoint, script: body.script, environment, permissions: body.permissions, files: body.files });
|
|
460
|
+
const tool = await toolRegistry.register({ slug: body.slug, name: body.name, glyph: body.glyph, description: body.description, entrypoint: body.entrypoint, script: body.script, environment, permissions: body.permissions, files: body.files });
|
|
461
461
|
broadcaster.broadcast({ type: "tools.updated", tools: await toolRegistry.list() });
|
|
462
462
|
json(201, tool);
|
|
463
463
|
return;
|
|
@@ -2396,7 +2396,7 @@ export function createHttpServer(options) {
|
|
|
2396
2396
|
contentUrl.searchParams.delete("frame");
|
|
2397
2397
|
contentUrl.searchParams.delete("download");
|
|
2398
2398
|
const escapeAttribute = (value) => value.replace(/&/g, "&").replace(/"/g, """).replace(/</g, "<").replace(/>/g, ">");
|
|
2399
|
-
const body = `<!doctype html><html><head><meta charset="utf-8"><title
|
|
2399
|
+
const body = `<!doctype html><html><head><meta charset="utf-8"><title>${escapeAttribute(artifact.path.split("/").pop() ?? "HTML")} · Super Pi</title><style>html,body,iframe{margin:0;width:100%;height:100%;border:0;display:block}</style></head><body><iframe title="Interactive content" sandbox="allow-scripts" referrerpolicy="no-referrer" csp="${escapeAttribute(MESSAGE_HTML_CSP)}" src="${escapeAttribute(contentUrl.pathname + contentUrl.search)}"></iframe></body></html>`;
|
|
2400
2400
|
response.writeHead(200, { "content-type": "text/html; charset=utf-8", "content-security-policy": `${MESSAGE_FRAME_CSP}; sandbox allow-scripts` }).end(request.method === "HEAD" ? undefined : body);
|
|
2401
2401
|
return;
|
|
2402
2402
|
}
|
|
@@ -37,6 +37,7 @@ export type MountedTool = {
|
|
|
37
37
|
id: string;
|
|
38
38
|
slug: string;
|
|
39
39
|
name: string;
|
|
40
|
+
glyph?: string;
|
|
40
41
|
description?: string;
|
|
41
42
|
entrypoint: string;
|
|
42
43
|
script?: ToolScript;
|
|
@@ -74,6 +75,7 @@ export declare class ToolRegistry {
|
|
|
74
75
|
register(input: {
|
|
75
76
|
slug: string;
|
|
76
77
|
name: string;
|
|
78
|
+
glyph?: string;
|
|
77
79
|
description?: string;
|
|
78
80
|
entrypoint?: string;
|
|
79
81
|
script?: ToolScript;
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { mkdir, readdir, readFile, rename, rm, stat, writeFile } from "node:fs/promises";
|
|
2
2
|
import { dirname, join, relative, resolve, sep } from "node:path";
|
|
3
|
+
import { validateToolGlyph } from "../shared/tool-glyph.js";
|
|
3
4
|
export const MAX_ASSETS = 32;
|
|
4
5
|
export const MAX_ASSET_BYTES = 512_000;
|
|
5
6
|
/**
|
|
@@ -56,6 +57,7 @@ export class ToolRegistry {
|
|
|
56
57
|
const script = input.script ? normalizeScript(input.script, files) : undefined;
|
|
57
58
|
const environment = input.environment ? normalizeEnvironment(input.environment) : undefined;
|
|
58
59
|
const permissions = normalizePermissions(input.permissions);
|
|
60
|
+
const glyph = validateToolGlyph(input.glyph);
|
|
59
61
|
const finalDir = join(this.toolsDir, slug), stagingDir = `${finalDir}.${crypto.randomUUID()}.staging`;
|
|
60
62
|
if (await stat(finalDir).catch(() => undefined))
|
|
61
63
|
throw new Error("工具目录已经存在");
|
|
@@ -67,7 +69,7 @@ export class ToolRegistry {
|
|
|
67
69
|
await rm(stagingDir, { recursive: true, force: true });
|
|
68
70
|
throw error;
|
|
69
71
|
}
|
|
70
|
-
const now = new Date().toISOString(), tool = { id: `tool_${crypto.randomUUID()}`, slug, name: input.name.trim(), description: input.description?.trim().slice(0, 500), entrypoint, script, environment, permissions, source: "user", enabled: true, createdAt: now, updatedAt: now };
|
|
72
|
+
const now = new Date().toISOString(), tool = { id: `tool_${crypto.randomUUID()}`, slug, name: input.name.trim(), ...(glyph ? { glyph } : {}), description: input.description?.trim().slice(0, 500), entrypoint, script, environment, permissions, source: "user", enabled: true, createdAt: now, updatedAt: now };
|
|
71
73
|
this.items.push(tool);
|
|
72
74
|
try {
|
|
73
75
|
await this.save();
|
|
@@ -114,6 +116,7 @@ export class ToolRegistry {
|
|
|
114
116
|
exportedAt: new Date().toISOString(),
|
|
115
117
|
slug: tool.slug,
|
|
116
118
|
name: tool.name,
|
|
119
|
+
...(tool.glyph ? { glyph: tool.glyph } : {}),
|
|
117
120
|
...(tool.description ? { description: tool.description } : {}),
|
|
118
121
|
entrypoint: tool.entrypoint,
|
|
119
122
|
files,
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
/** Plain text only: the same identity survives registration, sharing and browser rendering. */
|
|
2
|
+
export declare function validateToolGlyph(value: unknown): string | undefined;
|
|
3
|
+
export declare function mountedToolGlyph(tool: {
|
|
4
|
+
name: string;
|
|
5
|
+
slug?: string;
|
|
6
|
+
glyph?: string;
|
|
7
|
+
}): string;
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
/** Plain text only: the same identity survives registration, sharing and browser rendering. */
|
|
2
|
+
export function validateToolGlyph(value) {
|
|
3
|
+
if (value === undefined)
|
|
4
|
+
return undefined;
|
|
5
|
+
if (typeof value !== "string" || !value.trim() || Array.from(value.trim()).length > 4 || /[<>\u0000-\u001f\u007f]/.test(value))
|
|
6
|
+
throw new Error("工具图标须为 1 至 4 个字符的文字或符号");
|
|
7
|
+
return value.trim();
|
|
8
|
+
}
|
|
9
|
+
export function mountedToolGlyph(tool) {
|
|
10
|
+
try {
|
|
11
|
+
const glyph = validateToolGlyph(tool.glyph);
|
|
12
|
+
if (glyph)
|
|
13
|
+
return glyph;
|
|
14
|
+
}
|
|
15
|
+
catch { /* Old records still receive a readable fallback. */ }
|
|
16
|
+
const name = `${tool.name} ${tool.slug ?? ""}`.toLowerCase();
|
|
17
|
+
const symbols = [[/json/, "{}"], [/正则|regex/, ".*"], [/计算|calc/, "∑"], [/时间|timestamp|date/, "◷"], [/差异|diff/, "±"], [/markdown/, "M↓"], [/图像|图片|image/, "▧"], [/表格|csv|excel/, "▦"], [/颜色|color/, "◐"], [/base64/, "64"], [/hash|哈希/, "#"], [/git/, "⑂"]];
|
|
18
|
+
return symbols.find(([pattern]) => pattern.test(name))?.[1] ?? (Array.from(tool.name.trim()).slice(0, 2).join("") || "◇");
|
|
19
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@evandu/super-pi",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.213",
|
|
4
4
|
"description": "Web control plane and companion for Pi",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"type": "module",
|
|
@@ -43,6 +43,7 @@
|
|
|
43
43
|
"test": "node scripts/test.mjs"
|
|
44
44
|
},
|
|
45
45
|
"check:logic": [
|
|
46
|
+
"scripts/sidebar-refresh.test.mjs",
|
|
46
47
|
"scripts/provider-network.test.mjs",
|
|
47
48
|
"scripts/project-overview.test.mjs",
|
|
48
49
|
"scripts/team-handoff-view.test.mjs",
|
|
@@ -282,6 +283,8 @@
|
|
|
282
283
|
"scripts/session-reminder-pmo-rights.test.mjs"
|
|
283
284
|
],
|
|
284
285
|
"check:browser": [
|
|
286
|
+
"scripts/message-actions-browser.test.mjs",
|
|
287
|
+
"scripts/sidebar-refresh-browser.test.mjs",
|
|
285
288
|
"scripts/provider-network-browser.test.mjs",
|
|
286
289
|
"scripts/project-presentation-browser.test.mjs",
|
|
287
290
|
"scripts/team-context-browser.test.mjs",
|