@evandu/super-pi 0.1.253 → 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.
- package/agents/super-pi-task/core.ts +1 -1
- package/agents/super-pi-task/index.ts +24 -0
- package/dist/client/.super-pi-client-sources.json +8 -8
- package/dist/client/assets/{CodeMirrorEditor-DnjDYGwz.js → CodeMirrorEditor-CQQoIuoy.js} +2 -2
- package/dist/client/assets/GitDiffEditor-BnROmsWz.js +29 -0
- package/dist/client/assets/{dist-D1NpQAva.js → dist-AW5lyI3I.js} +1 -1
- package/dist/client/assets/{dist-DkPVc7Rf.js → dist-BGxkyh6e.js} +1 -1
- package/dist/client/assets/dist-BJxfd7yb.js +11 -0
- package/dist/client/assets/{dist-AczI3ocs.js → dist-BRVQKlcp.js} +1 -1
- package/dist/client/assets/dist-BV64A9Ji.js +1 -0
- package/dist/client/assets/dist-CKF2Jksy.js +1 -0
- package/dist/client/assets/dist-CX_Hm4GS.js +1 -0
- package/dist/client/assets/{dist-DRk4qy9i.js → dist-Cx00EZKR.js} +2 -2
- package/dist/client/assets/{dist-D09S6VMH.js → dist-D71y2EI1.js} +1 -1
- package/dist/client/assets/{dist-CISO_jYt.js → dist-Dc1MBGAG.js} +1 -1
- package/dist/client/assets/dist-Dds-qLxY.js +9 -0
- package/dist/client/assets/{dist-BbuAnJ4T.js → dist-DeD9copn.js} +1 -1
- package/dist/client/assets/{dist-BUl4ovQu.js → dist-DuvGReu-.js} +2 -2
- package/dist/client/assets/{dist-C8yZkfJN.js → dist-Dvb0SqcK.js} +2 -2
- package/dist/client/assets/{dist-BsG-6pTu.js → dist-J6XWqRpB.js} +1 -1
- package/dist/client/assets/{dist-BSugRTzs.js → dist-QzbOCAU6.js} +1 -1
- package/dist/client/assets/{dist-uuaqc1SU.js → dist-moiMRpw_.js} +1 -1
- package/dist/client/assets/{index-Cxt9aePy.js → index-BUlfbbqO.js} +14 -14
- package/dist/client/assets/index-Bfm53ZYL.css +1 -0
- package/dist/client/index.html +2 -2
- package/dist/server/agents.d.ts +1 -1
- package/dist/server/agents.js +1 -1
- package/dist/server/http-server.js +127 -6
- package/dist/server/runtime.js +1 -1
- package/dist/server/tool-registry.d.ts +12 -0
- package/dist/server/tool-registry.js +24 -1
- package/package.json +1 -1
- package/skills/super-pi-tool-development/SKILL.md +12 -0
- package/dist/client/assets/GitDiffEditor-O0JZcWkA.js +0 -27
- package/dist/client/assets/dist-0FXz0KLB.js +0 -9
- package/dist/client/assets/dist-D5-SYidb.js +0 -1
- package/dist/client/assets/dist-QyJg7PsR.js +0 -11
- package/dist/client/assets/dist-gBVaCjue.js +0 -1
- package/dist/client/assets/dist-vK4fMIi8.js +0 -1
- package/dist/client/assets/index-BvAvBj_1.css +0 -1
package/dist/client/index.html
CHANGED
|
@@ -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-
|
|
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-
|
|
13
|
+
<link rel="stylesheet" crossorigin href="/assets/index-Bfm53ZYL.css">
|
|
14
14
|
</head>
|
|
15
15
|
<body>
|
|
16
16
|
<div id="root"></div>
|
package/dist/server/agents.d.ts
CHANGED
|
@@ -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.
|
package/dist/server/agents.js
CHANGED
|
@@ -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;
|
|
@@ -1602,11 +1692,34 @@ export function createHttpServer(options) {
|
|
|
1602
1692
|
json(403, { error: "Git 写操作只允许来自本机或局域网的请求。" });
|
|
1603
1693
|
return;
|
|
1604
1694
|
}
|
|
1605
|
-
const asked = await readRequestText(request, 512000);
|
|
1695
|
+
const asked = await readRequestText(request, op === "diff-edit-save" ? MAX_FILE_BYTES * 2 : 512000);
|
|
1606
1696
|
if (asked.tooLarge) {
|
|
1607
1697
|
json(413, { error: "请求过大" });
|
|
1608
1698
|
return;
|
|
1609
1699
|
}
|
|
1700
|
+
if (op === "diff-edit-save") {
|
|
1701
|
+
const body = asked.text ? JSON.parse(asked.text) : {};
|
|
1702
|
+
if (!body || typeof body !== "object" || Array.isArray(body)
|
|
1703
|
+
|| typeof body.path !== "string" || typeof body.content !== "string"
|
|
1704
|
+
|| typeof body.baseEtag !== "string") {
|
|
1705
|
+
json(400, { error: "差异保存需要 path、content 和 baseEtag", code: "bad_request" });
|
|
1706
|
+
return;
|
|
1707
|
+
}
|
|
1708
|
+
const worktreeId = url.searchParams.get("worktreeId");
|
|
1709
|
+
if (worktreeId !== null && !/^[a-f0-9]{64}$/.test(worktreeId)) {
|
|
1710
|
+
json(400, { error: "请先选择有效工作树", code: "bad_worktree" });
|
|
1711
|
+
return;
|
|
1712
|
+
}
|
|
1713
|
+
const checkout = worktreeId ? await resolveGitWorktree(workspace.path, worktreeId) : undefined;
|
|
1714
|
+
const editRoot = checkout?.path ?? workspace.path;
|
|
1715
|
+
const editSession = checkout?.path ?? sessionRoot;
|
|
1716
|
+
await explorerPath(editRoot, editSession, body.path, true);
|
|
1717
|
+
const path = await workspacePathFromSession(editRoot, editSession, body.path);
|
|
1718
|
+
const saved = await serializeWorkspaceWrite(workspace.path, () => writeWorkspaceFile(editRoot, path, body.content, body.baseEtag));
|
|
1719
|
+
broadcaster.broadcast({ type: "files.invalidated", workspaceId: workspace.id, paths: checkout ? [] : [path] });
|
|
1720
|
+
json(200, saved);
|
|
1721
|
+
return;
|
|
1722
|
+
}
|
|
1610
1723
|
if (op === "draft") {
|
|
1611
1724
|
if (!context.runtime?.askOnce) {
|
|
1612
1725
|
json(503, { error: "未配置可生成提交说明的模型" });
|
|
@@ -1690,11 +1803,19 @@ export function createHttpServer(options) {
|
|
|
1690
1803
|
json(400, { error: "差异编辑需要 path", code: "bad_path" });
|
|
1691
1804
|
return;
|
|
1692
1805
|
}
|
|
1693
|
-
|
|
1694
|
-
|
|
1806
|
+
const worktreeId = url.searchParams.get("worktreeId");
|
|
1807
|
+
if (worktreeId !== null && !/^[a-f0-9]{64}$/.test(worktreeId)) {
|
|
1808
|
+
json(400, { error: "请先选择有效工作树", code: "bad_worktree" });
|
|
1809
|
+
return;
|
|
1810
|
+
}
|
|
1811
|
+
const checkout = worktreeId ? await resolveGitWorktree(workspace.path, worktreeId) : undefined;
|
|
1812
|
+
const editRoot = checkout?.path ?? workspace.path;
|
|
1813
|
+
const editSession = checkout?.path ?? sessionRoot;
|
|
1814
|
+
await explorerPath(editRoot, editSession, requested, true);
|
|
1815
|
+
const path = await workspacePathFromSession(editRoot, editSession, requested);
|
|
1695
1816
|
const [original, file] = await Promise.all([
|
|
1696
|
-
gitIndexFileContent(
|
|
1697
|
-
readWorkspaceFile(
|
|
1817
|
+
gitIndexFileContent(editRoot, path),
|
|
1818
|
+
readWorkspaceFile(editRoot, path),
|
|
1698
1819
|
]);
|
|
1699
1820
|
json(200, { path: file.path, original, content: file.content, eol: file.eol, bom: file.bom, meta: file.meta });
|
|
1700
1821
|
}
|
package/dist/server/runtime.js
CHANGED
|
@@ -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
|
@@ -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.
|