@evandu/super-pi 0.1.254 → 0.1.255

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 (40) hide show
  1. package/agents/super-pi-task/core.ts +1 -1
  2. package/agents/super-pi-task/index.ts +24 -0
  3. package/dist/client/.super-pi-client-sources.json +8 -8
  4. package/dist/client/assets/{CodeMirrorEditor-DdxPcLjw.js → CodeMirrorEditor-CQQoIuoy.js} +2 -2
  5. package/dist/client/assets/GitDiffEditor-BnROmsWz.js +29 -0
  6. package/dist/client/assets/{dist-D1NpQAva.js → dist-AW5lyI3I.js} +1 -1
  7. package/dist/client/assets/{dist-DkPVc7Rf.js → dist-BGxkyh6e.js} +1 -1
  8. package/dist/client/assets/dist-BJxfd7yb.js +11 -0
  9. package/dist/client/assets/{dist-AczI3ocs.js → dist-BRVQKlcp.js} +1 -1
  10. package/dist/client/assets/dist-BV64A9Ji.js +1 -0
  11. package/dist/client/assets/dist-CKF2Jksy.js +1 -0
  12. package/dist/client/assets/dist-CX_Hm4GS.js +1 -0
  13. package/dist/client/assets/{dist-DRk4qy9i.js → dist-Cx00EZKR.js} +2 -2
  14. package/dist/client/assets/{dist-D09S6VMH.js → dist-D71y2EI1.js} +1 -1
  15. package/dist/client/assets/{dist-CISO_jYt.js → dist-Dc1MBGAG.js} +1 -1
  16. package/dist/client/assets/dist-Dds-qLxY.js +9 -0
  17. package/dist/client/assets/{dist-BbuAnJ4T.js → dist-DeD9copn.js} +1 -1
  18. package/dist/client/assets/{dist-BUl4ovQu.js → dist-DuvGReu-.js} +2 -2
  19. package/dist/client/assets/{dist-C8yZkfJN.js → dist-Dvb0SqcK.js} +2 -2
  20. package/dist/client/assets/{dist-BsG-6pTu.js → dist-J6XWqRpB.js} +1 -1
  21. package/dist/client/assets/{dist-BSugRTzs.js → dist-QzbOCAU6.js} +1 -1
  22. package/dist/client/assets/{dist-uuaqc1SU.js → dist-moiMRpw_.js} +1 -1
  23. package/dist/client/assets/{index-WcUajwk6.js → index-BUlfbbqO.js} +14 -14
  24. package/dist/client/assets/index-Bfm53ZYL.css +1 -0
  25. package/dist/client/index.html +2 -2
  26. package/dist/server/agents.d.ts +1 -1
  27. package/dist/server/agents.js +1 -1
  28. package/dist/server/http-server.js +91 -1
  29. package/dist/server/runtime.js +1 -1
  30. package/dist/server/tool-registry.d.ts +12 -0
  31. package/dist/server/tool-registry.js +24 -1
  32. package/package.json +1 -1
  33. package/skills/super-pi-tool-development/SKILL.md +12 -0
  34. package/dist/client/assets/GitDiffEditor-CNCMPKVv.js +0 -27
  35. package/dist/client/assets/dist-0FXz0KLB.js +0 -9
  36. package/dist/client/assets/dist-D5-SYidb.js +0 -1
  37. package/dist/client/assets/dist-QyJg7PsR.js +0 -11
  38. package/dist/client/assets/dist-gBVaCjue.js +0 -1
  39. package/dist/client/assets/dist-vK4fMIi8.js +0 -1
  40. package/dist/client/assets/index-BvAvBj_1.css +0 -1
@@ -8,9 +8,9 @@
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-WcUajwk6.js"></script>
11
+ <script type="module" crossorigin src="/assets/index-BUlfbbqO.js"></script>
12
12
  <link rel="modulepreload" crossorigin href="/assets/rolldown-runtime-XKyaHtl9.js">
13
- <link rel="stylesheet" crossorigin href="/assets/index-BvAvBj_1.css">
13
+ <link rel="stylesheet" crossorigin href="/assets/index-Bfm53ZYL.css">
14
14
  </head>
15
15
  <body>
16
16
  <div id="root"></div>
@@ -38,7 +38,7 @@ type Frontmatter = Record<string, unknown>;
38
38
  */
39
39
  export declare const PI_TOOL_NAMES: readonly ["read", "bash", "powershell", "edit", "write", "grep", "find", "ls", "codemode", "tool_search", "list_mcp_resources", "list_mcp_resource_templates", "read_mcp_resource"];
40
40
  /** Tools shipped by this package. Authors must be able to explicitly deny host extras. */
41
- export declare const SUPER_PI_TOOL_NAMES: readonly ["task", "todowrite", "workflow", "run_async", "worktree", "scheduled_task", "project", "question", "tool_register", "memory", "skill_manage", "session_search", "session_spawn", "session_status", "session_dispatch", "session_stop", "session_report", "session_stop_subtree", "session_remove", "session_reminder", "knowledge_search", "knowledge_import", "document_read", "document_write", "web_search", "web_fetch", "feishu_doc_read", "feishu_doc_write"];
41
+ export declare const SUPER_PI_TOOL_NAMES: readonly ["task", "todowrite", "workflow", "run_async", "worktree", "scheduled_task", "project", "question", "tool_register", "tool_shortcut", "tool_remove", "memory", "skill_manage", "session_search", "session_spawn", "session_status", "session_dispatch", "session_stop", "session_report", "session_stop_subtree", "session_remove", "session_reminder", "knowledge_search", "knowledge_import", "document_read", "document_write", "web_search", "web_fetch", "feishu_doc_read", "feishu_doc_write"];
42
42
  /**
43
43
  * Whether a name can be a real Pi tool. A name is real if it is one of `PI_TOOL_NAMES`, an MCP
44
44
  * server tool, or a PATTERN.
@@ -39,7 +39,7 @@ export const PI_TOOL_NAMES = [
39
39
  ];
40
40
  /** Tools shipped by this package. Authors must be able to explicitly deny host extras. */
41
41
  export const SUPER_PI_TOOL_NAMES = [
42
- "task", "todowrite", "workflow", "run_async", "worktree", "scheduled_task", "project", "question", "tool_register",
42
+ "task", "todowrite", "workflow", "run_async", "worktree", "scheduled_task", "project", "question", "tool_register", "tool_shortcut", "tool_remove",
43
43
  "memory", "skill_manage", "session_search",
44
44
  "session_spawn", "session_status", "session_dispatch", "session_stop", "session_report", "session_stop_subtree", "session_remove", "session_reminder",
45
45
  "knowledge_search", "knowledge_import",
@@ -406,7 +406,7 @@ export function createHttpServer(options) {
406
406
  // the endpoint that can spend it is exactly the one an agent's own turn can reach, and the
407
407
  // management half (`/api/feishu/config`) stays behind the ordinary token AND the local-address
408
408
  // predicate.
409
- if (requestPath !== "/api/conversations" && requestPath !== "/api/conversation/usage" && requestPath !== "/api/memory/tool" && requestPath !== "/api/knowledge/tool" && requestPath !== "/api/documents/tool" && requestPath !== "/api/web/tool" && requestPath !== "/api/feishu/tool" && requestPath !== "/api/todos" && requestPath !== "/api/scheduled-tasks" && requestPath !== "/api/projects/tool" && requestPath !== "/api/question" && (requestPath !== "/api/tools" || request.method !== "POST") && !requestPath.startsWith("/tools/") && !isAuthorized(request, accessToken)) {
409
+ if (requestPath !== "/api/conversations" && requestPath !== "/api/conversation/usage" && requestPath !== "/api/memory/tool" && requestPath !== "/api/knowledge/tool" && requestPath !== "/api/documents/tool" && requestPath !== "/api/web/tool" && requestPath !== "/api/feishu/tool" && requestPath !== "/api/todos" && requestPath !== "/api/scheduled-tasks" && requestPath !== "/api/projects/tool" && requestPath !== "/api/question" && requestPath !== "/api/tools/agent" && (requestPath !== "/api/tools" || request.method !== "POST") && !requestPath.startsWith("/tools/") && !isAuthorized(request, accessToken)) {
410
410
  response.writeHead(401, { "www-authenticate": "Bearer" }).end("Authentication required");
411
411
  return;
412
412
  }
@@ -573,6 +573,96 @@ export function createHttpServer(options) {
573
573
  return;
574
574
  }
575
575
  }
576
+ if (url.pathname === "/api/tools/shortcut") {
577
+ try {
578
+ if (request.method !== "POST") {
579
+ json(405, { error: "这个接口只接受 POST 请求。" });
580
+ return;
581
+ }
582
+ const input = await readRequestText(request, 8_000);
583
+ if (input.tooLarge) {
584
+ json(413, { error: "快捷键请求内容过大。" });
585
+ return;
586
+ }
587
+ const body = JSON.parse(input.text);
588
+ if (!body.slug) {
589
+ json(400, { error: "缺少工具 slug。" });
590
+ return;
591
+ }
592
+ const result = await toolRegistry.setShortcut(body.slug, body.shortcut ?? undefined);
593
+ if (result.conflict) {
594
+ json(409, { error: `快捷键已被「${result.conflict}」占用。` });
595
+ return;
596
+ }
597
+ broadcaster.broadcast({ type: "tools.updated", tools: await toolRegistry.list() });
598
+ json(200, { ok: true });
599
+ return;
600
+ }
601
+ catch (error) {
602
+ json(400, { error: describeThrown(error) || "快捷键设置失败。" });
603
+ return;
604
+ }
605
+ }
606
+ if (url.pathname === "/api/tools/agent") {
607
+ try {
608
+ if (request.method !== "POST") {
609
+ json(405, { error: "这个接口只接受 POST 请求。" });
610
+ return;
611
+ }
612
+ const input = await readRequestText(request, 8_000);
613
+ if (input.tooLarge) {
614
+ json(413, { error: "工具操作请求内容过大。" });
615
+ return;
616
+ }
617
+ const body = JSON.parse(input.text);
618
+ if (!body.conversationId || !runService.verifyPrimaryCapability(body.conversationId, body.capability ?? request.headers["x-super-pi-capability"]).ok) {
619
+ json(403, { error: "只有当前主会话可以管理全局工具。" });
620
+ return;
621
+ }
622
+ if (!body.slug) {
623
+ json(400, { error: "缺少工具 slug。" });
624
+ return;
625
+ }
626
+ if (body.action === "get-shortcut") {
627
+ const tool = (await toolRegistry.list()).find(item => item.slug === body.slug);
628
+ if (!tool) {
629
+ json(404, { error: "找不到这个工具,可能已经下架。" });
630
+ return;
631
+ }
632
+ json(200, { shortcut: tool.shortcut ?? null });
633
+ return;
634
+ }
635
+ if (body.action === "set-shortcut") {
636
+ const result = await toolRegistry.setShortcut(body.slug, body.shortcut ?? undefined);
637
+ if (result.conflict) {
638
+ json(409, { error: `快捷键已被「${result.conflict}」占用。` });
639
+ return;
640
+ }
641
+ broadcaster.broadcast({ type: "tools.updated", tools: await toolRegistry.list() });
642
+ json(200, { shortcut: result.tool?.shortcut ?? null });
643
+ return;
644
+ }
645
+ if (body.action === "remove") {
646
+ const tool = (await toolRegistry.list()).find(item => item.slug === body.slug);
647
+ if (!tool) {
648
+ json(404, { error: "找不到这个工具,可能已经下架。" });
649
+ return;
650
+ }
651
+ const removed = await toolRegistry.remove(tool.id);
652
+ if (removed)
653
+ await rm(toolRunner.envDir(tool.id), { recursive: true, force: true });
654
+ broadcaster.broadcast({ type: "tools.updated", tools: await toolRegistry.list() });
655
+ json(200, { removed });
656
+ return;
657
+ }
658
+ json(400, { error: "不支持的工具操作。" });
659
+ return;
660
+ }
661
+ catch (error) {
662
+ json(400, { error: describeThrown(error) || "工具操作失败。" });
663
+ return;
664
+ }
665
+ }
576
666
  if (url.pathname.startsWith("/tools/")) {
577
667
  let id;
578
668
  let resource;
@@ -1614,7 +1614,7 @@ export class PiRpcRuntime {
1614
1614
  // allowlist and naming a tool Pi has not registered would change the spawn line for every other
1615
1615
  // mode. The prompt asks for a bare JSON array and nothing else; if the model spends a turn on a
1616
1616
  // tool call anyway the reranker times out and falls back to the lexical order.
1617
- const agentArgs = memoryReview ? ["--no-extensions", "--no-skills", "--no-mcp", "--no-context-files", "--no-prompt-templates", "--tools", "memory,skill_manage,session_search"] : knowledgeRerank ? ["--no-extensions", "--no-skills", "--no-mcp", "--no-context-files", "--no-prompt-templates"] : await agentSpawnArgs(this.agents.promptDir, agent, { extraAllowedTools: [...(extensionArgs.length ? [TASK_TOOL_NAME, TODO_TOOL_NAME, PROJECT_TOOL_NAME, WORKFLOW_TOOL_NAME, RUN_ASYNC_TOOL_NAME, SCHEDULED_TASK_TOOL_NAME, "question", "tool_register", ...(this.options.orchestratorEndpoint ? [WORKTREE_TOOL_NAME, SESSION_SPAWN_TOOL_NAME, SESSION_STATUS_TOOL_NAME, SESSION_DISPATCH_TOOL_NAME, SESSION_STOP_TOOL_NAME, SESSION_REPORT_TOOL_NAME, SESSION_STOP_SUBTREE_TOOL_NAME, SESSION_REMOVE_TOOL_NAME, SESSION_REMINDER_TOOL_NAME] : [])] : []), ...(memoryEnabled ? ["memory", "skill_manage", "session_search"] : []), ...(knowledgeEnabled ? [KNOWLEDGE_TOOL_NAME, KNOWLEDGE_IMPORT_TOOL_NAME] : []), ...(documentsEnabled ? [DOCUMENT_READ_TOOL_NAME, DOCUMENT_WRITE_TOOL_NAME] : []), ...(webEnabled ? [WEB_SEARCH_TOOL_NAME, WEB_FETCH_TOOL_NAME] : []), ...(feishuEnabled ? [FEISHU_READ_TOOL_NAME, FEISHU_WRITE_TOOL_NAME] : [])] });
1617
+ const agentArgs = memoryReview ? ["--no-extensions", "--no-skills", "--no-mcp", "--no-context-files", "--no-prompt-templates", "--tools", "memory,skill_manage,session_search"] : knowledgeRerank ? ["--no-extensions", "--no-skills", "--no-mcp", "--no-context-files", "--no-prompt-templates"] : await agentSpawnArgs(this.agents.promptDir, agent, { extraAllowedTools: [...(extensionArgs.length ? [TASK_TOOL_NAME, TODO_TOOL_NAME, PROJECT_TOOL_NAME, WORKFLOW_TOOL_NAME, RUN_ASYNC_TOOL_NAME, SCHEDULED_TASK_TOOL_NAME, "question", "tool_register", "tool_shortcut", "tool_remove", ...(this.options.orchestratorEndpoint ? [WORKTREE_TOOL_NAME, SESSION_SPAWN_TOOL_NAME, SESSION_STATUS_TOOL_NAME, SESSION_DISPATCH_TOOL_NAME, SESSION_STOP_TOOL_NAME, SESSION_REPORT_TOOL_NAME, SESSION_STOP_SUBTREE_TOOL_NAME, SESSION_REMOVE_TOOL_NAME, SESSION_REMINDER_TOOL_NAME] : [])] : []), ...(memoryEnabled ? ["memory", "skill_manage", "session_search"] : []), ...(knowledgeEnabled ? [KNOWLEDGE_TOOL_NAME, KNOWLEDGE_IMPORT_TOOL_NAME] : []), ...(documentsEnabled ? [DOCUMENT_READ_TOOL_NAME, DOCUMENT_WRITE_TOOL_NAME] : []), ...(webEnabled ? [WEB_SEARCH_TOOL_NAME, WEB_FETCH_TOOL_NAME] : []), ...(feishuEnabled ? [FEISHU_READ_TOOL_NAME, FEISHU_WRITE_TOOL_NAME] : [])] });
1618
1618
  // Refused here, with the reason, rather than handed to the spawn: an ENOENT from `spawn` reads as
1619
1619
  // "the app is broken" and hides the one fact that matters, which is where it looked for Pi.
1620
1620
  if (!this.pi.found)
@@ -33,6 +33,13 @@ export type ToolFingerprint = {
33
33
  export type ToolPermissions = {
34
34
  llm?: boolean;
35
35
  };
36
+ export type ToolShortcut = {
37
+ key: string;
38
+ ctrl?: boolean;
39
+ alt?: boolean;
40
+ shift?: boolean;
41
+ meta?: boolean;
42
+ };
36
43
  export type MountedTool = {
37
44
  id: string;
38
45
  slug: string;
@@ -43,6 +50,7 @@ export type MountedTool = {
43
50
  width: number;
44
51
  height: number;
45
52
  };
53
+ shortcut?: ToolShortcut;
46
54
  entrypoint: string;
47
55
  script?: ToolScript;
48
56
  environment?: ToolEnvironment;
@@ -76,6 +84,10 @@ export declare class ToolRegistry {
76
84
  private load;
77
85
  private save;
78
86
  list(): Promise<MountedTool[]>;
87
+ setShortcut(slug: string, shortcut?: ToolShortcut): Promise<{
88
+ tool?: MountedTool;
89
+ conflict?: string;
90
+ }>;
79
91
  register(input: {
80
92
  slug: string;
81
93
  name: string;
@@ -35,6 +35,28 @@ export class ToolRegistry {
35
35
  } }
36
36
  async save() { await mkdir(dirname(this.file), { recursive: true }); const tmp = `${this.file}.${process.pid}.tmp`; await writeFile(tmp, JSON.stringify(this.items, null, 2), "utf8"); await rename(tmp, this.file); }
37
37
  async list() { await this.load(); return this.items.map(copy); }
38
+ async setShortcut(slug, shortcut) {
39
+ await this.load();
40
+ const tool = this.items.find(item => item.slug === slug);
41
+ if (!tool)
42
+ throw new Error("找不到这个工具,可能已经下架。");
43
+ if (shortcut && (typeof shortcut.key !== "string" || !shortcut.key.trim() || shortcut.key.length > 32 || [shortcut.ctrl, shortcut.alt, shortcut.shift, shortcut.meta].some(value => value !== undefined && typeof value !== "boolean")))
44
+ throw new Error("快捷键格式无效。");
45
+ if (shortcut) {
46
+ const normalized = { ...shortcut, key: shortcut.key.toLowerCase() };
47
+ if (normalized.key === "escape" || (!normalized.ctrl && !normalized.alt && !normalized.shift && !normalized.meta && ["enter", "space", "tab"].includes(normalized.key)))
48
+ throw new Error("这个按键被弹窗或焦点控件保留,不能绑定为工具快捷键。");
49
+ const conflict = this.items.find(item => item.id !== tool.id && item.shortcut && item.shortcut.key.toLowerCase() === normalized.key && !!item.shortcut.ctrl === !!normalized.ctrl && !!item.shortcut.alt === !!normalized.alt && !!item.shortcut.shift === !!normalized.shift && !!item.shortcut.meta === !!normalized.meta);
50
+ if (conflict)
51
+ return { conflict: conflict.name };
52
+ tool.shortcut = normalized;
53
+ }
54
+ else
55
+ delete tool.shortcut;
56
+ tool.updatedAt = new Date().toISOString();
57
+ await this.save();
58
+ return { tool: copy(tool) };
59
+ }
38
60
  async register(input) {
39
61
  await this.load();
40
62
  const slug = input.slug.trim().toLowerCase();
@@ -222,5 +244,6 @@ function isParam(value) { const x = value; return !!x && typeof x === "object" &
222
244
  function isTool(value) { const x = value; if (!x || typeof x !== "object" || typeof x.id !== "string" || typeof x.slug !== "string" || typeof x.name !== "string" || typeof x.entrypoint !== "string" || (x.source !== "user" && x.source !== "builtin"))
223
245
  return false; if (x.dialogSize !== undefined && (!x.dialogSize || !Number.isFinite(x.dialogSize.width) || !Number.isFinite(x.dialogSize.height)))
224
246
  return false; if (x.environment !== undefined && (typeof x.environment !== "object" || x.environment === null))
247
+ return false; if (x.shortcut !== undefined && (!x.shortcut || typeof x.shortcut.key !== "string" || [x.shortcut.ctrl, x.shortcut.alt, x.shortcut.shift, x.shortcut.meta].some(item => item !== undefined && typeof item !== "boolean")))
225
248
  return false; return x.permissions === undefined || (typeof x.permissions === "object" && x.permissions !== null); }
226
- function copy(value) { return { ...value, script: value.script ? { ...value.script, parameters: value.script.parameters ? { ...value.script.parameters } : undefined } : undefined, environment: value.environment ? { ...value.environment, requires: value.environment.requires ? [...value.environment.requires] : undefined } : undefined, permissions: value.permissions ? { ...value.permissions } : undefined }; }
249
+ function copy(value) { return { ...value, shortcut: value.shortcut ? { ...value.shortcut } : undefined, script: value.script ? { ...value.script, parameters: value.script.parameters ? { ...value.script.parameters } : undefined } : undefined, environment: value.environment ? { ...value.environment, requires: value.environment.requires ? [...value.environment.requires] : undefined } : undefined, permissions: value.permissions ? { ...value.permissions } : undefined }; }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@evandu/super-pi",
3
- "version": "0.1.254",
3
+ "version": "0.1.255",
4
4
  "description": "Web control plane and companion for Pi",
5
5
  "license": "MIT",
6
6
  "type": "module",
@@ -22,6 +22,18 @@ If the tool needs more reading space, include `dialogSize: { width, height }` in
22
22
 
23
23
  Keep the iframe content usable when the popup is narrow: use flexible layouts, allow long tables or code to scroll inside the panel, and do not assume the requested size will fit every viewport.
24
24
 
25
+ ## Updating an existing tool
26
+
27
+ When replacing or rebuilding an existing tool, preserve its shortcut explicitly:
28
+
29
+ 1. Call `tool_shortcut` with `action: "get"` and the existing `slug` before removing the tool.
30
+ 2. Remove it with `tool_remove`. Removal clears its shortcut immediately, making the key available to other tools.
31
+ 3. Register the replacement with `tool_register`.
32
+ 4. If a shortcut was returned in step 1, call `tool_shortcut` with `action: "set"` and that shortcut.
33
+ 5. If setting it reports a conflict, keep the replacement registered and tell the user which tool owns the key. Do not silently change or clear the other tool's shortcut.
34
+
35
+ Never assume a shortcut survives removal or re-registration. New tools do not claim a shortcut unless the user asks for one.
36
+
25
37
  ## Finish
26
38
 
27
39
  Register only after the HTML and any script files are complete. Return the tool name, registration result, and the main interaction or calculation verified. If registration is unavailable in the current environment, report that constraint and provide the retained copy-prompt fallback only then.