@evandu/super-pi 0.1.321 → 0.1.322
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/code-auditor.md +1 -0
- package/agents/super-pi-task/index.ts +16 -0
- package/dist/.super-pi-check-inputs.json +2 -2
- package/dist/client/.super-pi-client-sources.json +13 -13
- package/dist/client/assets/{CodeMirrorEditor-DoS1qVaB.js → CodeMirrorEditor-BsMtOxUG.js} +1 -1
- package/dist/client/assets/{GitDiffEditor-prLA4Cd8.js → GitDiffEditor-L_OuYDQ2.js} +1 -1
- package/dist/client/assets/index-Cvx8i65V.css +1 -0
- package/dist/client/assets/{index-D6OVl078.js → index-DeMK1efe.js} +60 -60
- package/dist/client/index.html +2 -2
- package/dist/server/agents.d.ts +1 -1
- package/dist/server/agents.js +2 -1
- package/dist/server/file-review-threads.d.ts +8 -1
- package/dist/server/file-review-threads.js +32 -4
- package/dist/server/http-server.js +15 -7
- package/dist/server/runtime.js +3 -2
- package/dist/shared/file-review.d.ts +4 -0
- package/dist/shared/file-review.js +6 -0
- package/package.json +1 -1
- package/dist/client/assets/index-Dj33YA2I.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-DeMK1efe.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-Cvx8i65V.css">
|
|
14
14
|
</head>
|
|
15
15
|
<body>
|
|
16
16
|
<div id="root"></div>
|
|
17
17
|
|
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", "tool_shortcut", "tool_remove", "memory", "skill_manage", "session_search", "agent_handbook", "user_tool", "user_tool_manage", "review_list", "review_reply", "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", "presentation_create", "presentation_read", "presentation_edit", "presentation_render", "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", "agent_handbook", "user_tool", "user_tool_manage", "review_list", "review_reply", "review_create", "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", "presentation_create", "presentation_read", "presentation_edit", "presentation_render", "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
|
@@ -2,6 +2,7 @@ import { mkdir, readdir, readFile, writeFile } from "node:fs/promises";
|
|
|
2
2
|
import { homedir } from "node:os";
|
|
3
3
|
import { join, resolve } from "node:path";
|
|
4
4
|
import { orderAgentsForDisplay } from "../shared/agent-order.js";
|
|
5
|
+
import { FILE_REVIEW_TOOLS } from "../shared/file-review.js";
|
|
5
6
|
/**
|
|
6
7
|
* A guard rather than a cast: it is the only thing that lets `tools:` be checked once and then used as
|
|
7
8
|
* a map everywhere without the compiler complaining. It narrows to the index-signature shape that
|
|
@@ -40,7 +41,7 @@ export const PI_TOOL_NAMES = [
|
|
|
40
41
|
/** Tools shipped by this package. Authors must be able to explicitly deny host extras. */
|
|
41
42
|
export const SUPER_PI_TOOL_NAMES = [
|
|
42
43
|
"task", "todowrite", "workflow", "run_async", "worktree", "scheduled_task", "project", "question", "tool_register", "tool_shortcut", "tool_remove",
|
|
43
|
-
"memory", "skill_manage", "session_search", "agent_handbook", "user_tool", "user_tool_manage",
|
|
44
|
+
"memory", "skill_manage", "session_search", "agent_handbook", "user_tool", "user_tool_manage", ...FILE_REVIEW_TOOLS,
|
|
44
45
|
"session_spawn", "session_status", "session_dispatch", "session_stop", "session_report", "session_stop_subtree", "session_remove", "session_reminder",
|
|
45
46
|
"knowledge_search", "knowledge_import",
|
|
46
47
|
"document_read", "document_write", "presentation_create", "presentation_read", "presentation_edit", "presentation_render", "web_search", "web_fetch", "feishu_doc_read", "feishu_doc_write",
|
|
@@ -11,7 +11,14 @@ export declare class FileReviewThreads {
|
|
|
11
11
|
private loaded;
|
|
12
12
|
constructor(path: string);
|
|
13
13
|
list(scope: Scope): ScopedThread[];
|
|
14
|
-
create(scope: Scope, comments: unknown): ScopedThread[];
|
|
14
|
+
create(scope: Scope, comments: unknown, agentName?: string): ScopedThread[];
|
|
15
|
+
agentCreate(workspace: {
|
|
16
|
+
id: string;
|
|
17
|
+
path: string;
|
|
18
|
+
}, author: {
|
|
19
|
+
conversationId: string;
|
|
20
|
+
agentName?: string;
|
|
21
|
+
}, input: unknown, canWrite: () => boolean): Promise<ScopedThread>;
|
|
15
22
|
update(scope: Scope, id: string, action: string, detail?: unknown, replyId?: string): ScopedThread | undefined;
|
|
16
23
|
getForScope(scope: Scope, id: string): ScopedThread;
|
|
17
24
|
agentReply(scopes: Scope[], author: {
|
|
@@ -1,6 +1,9 @@
|
|
|
1
|
-
import { randomUUID } from "node:crypto";
|
|
1
|
+
import { createHash, randomUUID } from "node:crypto";
|
|
2
2
|
import { existsSync, readFileSync, renameSync, writeFileSync } from "node:fs";
|
|
3
|
-
import {
|
|
3
|
+
import { stat } from "node:fs/promises";
|
|
4
|
+
import { posix } from "node:path";
|
|
5
|
+
import { reviewExcerpt, workspaceReviewPath } from "../shared/file-review.js";
|
|
6
|
+
import { readWorkspaceFile, resolveInsideRoot } from "./files.js";
|
|
4
7
|
function record(value) {
|
|
5
8
|
if (!value || typeof value !== "object" || Array.isArray(value))
|
|
6
9
|
throw new Error("批注参数无效。");
|
|
@@ -51,7 +54,7 @@ export class FileReviewThreads {
|
|
|
51
54
|
this.load();
|
|
52
55
|
return [...this.entries.values()].filter(thread => sameScope(thread, scope)).reverse();
|
|
53
56
|
}
|
|
54
|
-
create(scope, comments) {
|
|
57
|
+
create(scope, comments, agentName) {
|
|
55
58
|
this.load();
|
|
56
59
|
if (!Array.isArray(comments) || !comments.length || comments.length > 25)
|
|
57
60
|
throw new Error("请选择要保存的批注。");
|
|
@@ -71,7 +74,7 @@ export class FileReviewThreads {
|
|
|
71
74
|
}
|
|
72
75
|
const entry = {
|
|
73
76
|
...scope, ...anchorFrom(item), id,
|
|
74
|
-
text: text(item.text, 2_000), replies: [], createdAt: new Date().toISOString(),
|
|
77
|
+
text: text(item.text, 2_000), replies: [], createdAt: new Date().toISOString(), agentName,
|
|
75
78
|
};
|
|
76
79
|
next.set(id, entry);
|
|
77
80
|
created.push(entry);
|
|
@@ -79,6 +82,31 @@ export class FileReviewThreads {
|
|
|
79
82
|
this.save(next);
|
|
80
83
|
return created;
|
|
81
84
|
}
|
|
85
|
+
async agentCreate(workspace, author, input, canWrite) {
|
|
86
|
+
const item = record(input);
|
|
87
|
+
const id = "review-" + createHash("sha256").update(JSON.stringify([author.conversationId, text(item.requestId, 200)])).digest("hex");
|
|
88
|
+
const scope = { workspaceId: workspace.id, cwd: "" };
|
|
89
|
+
this.load();
|
|
90
|
+
if (this.entries.has(id))
|
|
91
|
+
return this.getForScope(scope, id);
|
|
92
|
+
const requested = workspaceReviewPath(text(item.path, 4096));
|
|
93
|
+
if (/(?:^|\/)\.\.(?:\/|$)/.test(requested))
|
|
94
|
+
throw new Error("批注路径须在当前工作区内。");
|
|
95
|
+
const path = posix.normalize(requested);
|
|
96
|
+
const target = await resolveInsideRoot(workspace.path, requested);
|
|
97
|
+
if (!(await stat(target)).isFile())
|
|
98
|
+
throw new Error("只能为文件创建批注。");
|
|
99
|
+
const anchor = anchorFrom({ side: "file", path, source: `file:${path}`, start: item.start, end: item.end ?? item.start });
|
|
100
|
+
if (anchor.start !== undefined && anchor.end !== undefined) {
|
|
101
|
+
const lines = (await readWorkspaceFile(workspace.path, requested)).content.split(/\r?\n/);
|
|
102
|
+
if (anchor.end > lines.length)
|
|
103
|
+
throw new Error("批注行号超出文件范围。");
|
|
104
|
+
anchor.excerpt = reviewExcerpt(lines.slice(anchor.start - 1, anchor.end));
|
|
105
|
+
}
|
|
106
|
+
if (!canWrite())
|
|
107
|
+
throw new Error("当前执行已经结束。");
|
|
108
|
+
return this.create(scope, [{ ...anchor, id, text: item.text }], author.agentName || "Agent")[0];
|
|
109
|
+
}
|
|
82
110
|
update(scope, id, action, detail, replyId) {
|
|
83
111
|
const thread = this.getForScope(scope, id);
|
|
84
112
|
if (action === "delete") {
|
|
@@ -25,7 +25,7 @@ import { computeFileDiff } from "./file-diff.js";
|
|
|
25
25
|
import { verifyCapability } from "./capability.js";
|
|
26
26
|
import { FileReviewThreads } from "./file-review-threads.js";
|
|
27
27
|
import { toolSelection } from "./agents.js";
|
|
28
|
-
import { workspaceReviewPath } from "../shared/file-review.js";
|
|
28
|
+
import { FILE_REVIEW_DISCUSSION_TOOLS, workspaceReviewPath } from "../shared/file-review.js";
|
|
29
29
|
import { conversationWorkspace } from "./model-filter.js";
|
|
30
30
|
import { describeSchedule } from "./scheduled-tasks.js";
|
|
31
31
|
import { MAX_KNOWLEDGE_REQUEST_BYTES } from "./knowledge.js";
|
|
@@ -488,11 +488,11 @@ export function createHttpServer(options) {
|
|
|
488
488
|
return;
|
|
489
489
|
}
|
|
490
490
|
const body = JSON.parse(payload.text);
|
|
491
|
-
if (body.action !== undefined && body.action !== "list" && body.action !== "reply")
|
|
491
|
+
if (body.action !== undefined && body.action !== "list" && body.action !== "reply" && body.action !== "create")
|
|
492
492
|
throw new Error("未知批注工具操作。");
|
|
493
|
-
const tool = body.action === "list" ? "review_list" : "review_reply";
|
|
493
|
+
const tool = body.action === "create" ? "review_create" : body.action === "list" ? "review_list" : "review_reply";
|
|
494
494
|
const agent = await context.runtime.agentFor?.(conversation);
|
|
495
|
-
const selection = toolSelection(agent?.tools, { extraAllowedTools:
|
|
495
|
+
const selection = toolSelection(agent?.tools, { extraAllowedTools: FILE_REVIEW_DISCUSSION_TOOLS });
|
|
496
496
|
if (conversation.agentId && context.runtime.agentFor && !agent || selection.excludeTools?.includes(tool) || selection.tools && !selection.tools.includes(tool)) {
|
|
497
497
|
json(403, { error: "当前 Agent 没有此批注工具的权限。" });
|
|
498
498
|
return;
|
|
@@ -501,6 +501,14 @@ export function createHttpServer(options) {
|
|
|
501
501
|
json(403, { error: "当前执行已经结束。" });
|
|
502
502
|
return;
|
|
503
503
|
}
|
|
504
|
+
if (tool === "review_create") {
|
|
505
|
+
const workspace = conversation.workspaceId ? store.workspace(conversation.workspaceId) : undefined;
|
|
506
|
+
if (!workspace || workspace.closedAt)
|
|
507
|
+
throw new Error("当前执行没有有效工作区。");
|
|
508
|
+
const thread = await fileReviewThreads.agentCreate(workspace, { conversationId, agentName: agent?.name }, body, () => runService.isRunning(conversationId) && !store.conversation(conversationId)?.archivedAt && !!store.workspace(workspace.id) && !store.workspace(workspace.id)?.closedAt);
|
|
509
|
+
json(200, { id: thread.id, path: thread.path, start: thread.start, end: thread.end, created: true });
|
|
510
|
+
return;
|
|
511
|
+
}
|
|
504
512
|
const workspaces = new Set([conversation.workspaceId, conversation.groupExecution?.workspaceId]);
|
|
505
513
|
const scopes = [...workspaces].flatMap(workspaceId => {
|
|
506
514
|
const workspace = workspaceId ? store.workspace(workspaceId) : undefined;
|
|
@@ -523,8 +531,8 @@ export function createHttpServer(options) {
|
|
|
523
531
|
const matches = entries.filter(thread => (body.includeResolved === true || !thread.resolvedAt)
|
|
524
532
|
&& (!path || [thread.path, thread.currentPath, ...thread.additional?.map(item => item.path) ?? []]
|
|
525
533
|
.some(item => item && workspaceReviewPath(item, thread.cwd) === path)));
|
|
526
|
-
const page = matches.slice(offset, offset + 20).map(({ id, path, currentPath, cwd, side, start, end, text, resolvedAt, replies, workspaceId }) => ({ id, workspaceId, path: workspaceReviewPath(path, cwd), currentPath: currentPath && workspaceReviewPath(currentPath, cwd),
|
|
527
|
-
side, start, end, text, resolvedAt, replyCount: replies.length }));
|
|
534
|
+
const page = matches.slice(offset, offset + 20).map(({ id, path, currentPath, cwd, side, start, end, text, resolvedAt, replies, workspaceId, agentName }) => ({ id, workspaceId, path: workspaceReviewPath(path, cwd), currentPath: currentPath && workspaceReviewPath(currentPath, cwd),
|
|
535
|
+
side, start, end, text, resolvedAt, agentName, replyCount: replies.length }));
|
|
528
536
|
json(200, { threads: page, nextOffset: matches.length > offset + page.length ? offset + page.length : undefined });
|
|
529
537
|
return;
|
|
530
538
|
}
|
|
@@ -534,7 +542,7 @@ export function createHttpServer(options) {
|
|
|
534
542
|
json(200, { id: thread.id, replied: true });
|
|
535
543
|
}
|
|
536
544
|
catch (error) {
|
|
537
|
-
json(400, { error: error instanceof Error ? error.message : "
|
|
545
|
+
json(400, { error: error instanceof Error ? error.message : "无法处理批注工具请求。" });
|
|
538
546
|
}
|
|
539
547
|
return;
|
|
540
548
|
}
|
package/dist/server/runtime.js
CHANGED
|
@@ -2,6 +2,7 @@ import { spawn } from "node:child_process";
|
|
|
2
2
|
import { RpcChannel } from "./rpc-channel.js";
|
|
3
3
|
export { RpcChannel } from "./rpc-channel.js";
|
|
4
4
|
import { randomUUID } from "node:crypto";
|
|
5
|
+
import { FILE_REVIEW_DISCUSSION_TOOLS } from "../shared/file-review.js";
|
|
5
6
|
import { KNOWLEDGE_IMPORT_TOOL_NAME, KNOWLEDGE_TOOL_NAME } from "./knowledge.js";
|
|
6
7
|
import { DOCUMENT_READ_TOOL_NAME, DOCUMENT_WRITE_TOOL_NAME } from "./documents.js";
|
|
7
8
|
import { PRESENTATION_TOOL_NAMES } from "./presentations/service.js";
|
|
@@ -1543,7 +1544,7 @@ export class PiRpcRuntime {
|
|
|
1543
1544
|
extensionToolNames() {
|
|
1544
1545
|
const names = [TASK_TOOL_NAME, TODO_TOOL_NAME, WORKFLOW_TOOL_NAME, RUN_ASYNC_TOOL_NAME, SCHEDULED_TASK_TOOL_NAME, "question", "tool_register"];
|
|
1545
1546
|
if (process.env.SUPER_PI_REVIEW_ENDPOINT)
|
|
1546
|
-
names.push(
|
|
1547
|
+
names.push(...FILE_REVIEW_DISCUSSION_TOOLS);
|
|
1547
1548
|
if (this.memory)
|
|
1548
1549
|
names.push("memory", "skill_manage", "session_search", "agent_handbook");
|
|
1549
1550
|
if (this.knowledge)
|
|
@@ -1787,7 +1788,7 @@ export class PiRpcRuntime {
|
|
|
1787
1788
|
// allowlist and naming a tool Pi has not registered would change the spawn line for every other
|
|
1788
1789
|
// mode. The prompt asks for a bare JSON array and nothing else; if the model spends a turn on a
|
|
1789
1790
|
// tool call anyway the reranker times out and falls back to the lexical order.
|
|
1790
|
-
const reviewTools = extensionArgs.length && process.env.SUPER_PI_REVIEW_ENDPOINT ?
|
|
1791
|
+
const reviewTools = extensionArgs.length && process.env.SUPER_PI_REVIEW_ENDPOINT ? FILE_REVIEW_DISCUSSION_TOOLS : [];
|
|
1791
1792
|
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: agent?.id === "rsi-discussion" ? [] : [...reviewTools, ...(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", "agent_handbook"] : []), ...(knowledgeEnabled ? [KNOWLEDGE_TOOL_NAME, KNOWLEDGE_IMPORT_TOOL_NAME] : []), ...(documentsEnabled ? [DOCUMENT_READ_TOOL_NAME, DOCUMENT_WRITE_TOOL_NAME, ...PRESENTATION_TOOL_NAMES] : []), ...(webEnabled ? [WEB_SEARCH_TOOL_NAME, WEB_FETCH_TOOL_NAME] : []), ...(feishuEnabled ? [FEISHU_READ_TOOL_NAME, FEISHU_WRITE_TOOL_NAME] : [])] });
|
|
1792
1793
|
// Refused here, with the reason, rather than handed to the spawn: an ENOENT from `spawn` reads as
|
|
1793
1794
|
// "the app is broken" and hides the one fact that matters, which is where it looked for Pi.
|
|
@@ -1,4 +1,6 @@
|
|
|
1
1
|
export type ReviewSide = "file" | "before" | "after";
|
|
2
|
+
export declare const FILE_REVIEW_DISCUSSION_TOOLS: readonly ["review_list", "review_reply"];
|
|
3
|
+
export declare const FILE_REVIEW_TOOLS: readonly ["review_list", "review_reply", "review_create"];
|
|
2
4
|
export type ReviewLine = {
|
|
3
5
|
side: ReviewSide;
|
|
4
6
|
number: number;
|
|
@@ -36,6 +38,8 @@ export type ReviewThread = ReviewAnchor & {
|
|
|
36
38
|
cwd: string;
|
|
37
39
|
createdAt: string;
|
|
38
40
|
resolvedAt?: string;
|
|
41
|
+
agentName?: string;
|
|
39
42
|
replies: ReviewReply[];
|
|
40
43
|
};
|
|
44
|
+
export declare function reviewExcerpt(lines: readonly string[]): string;
|
|
41
45
|
export declare function workspaceReviewPath(path: string, cwd?: string): string;
|
|
@@ -1,3 +1,9 @@
|
|
|
1
|
+
export const FILE_REVIEW_DISCUSSION_TOOLS = ["review_list", "review_reply"];
|
|
2
|
+
export const FILE_REVIEW_TOOLS = [...FILE_REVIEW_DISCUSSION_TOOLS, "review_create"];
|
|
3
|
+
export function reviewExcerpt(lines) {
|
|
4
|
+
const text = lines.join("\n");
|
|
5
|
+
return text.length > 3000 ? text.slice(0, 3000) + "\n[…摘录截断]" : text;
|
|
6
|
+
}
|
|
1
7
|
export function workspaceReviewPath(path, cwd = "") {
|
|
2
8
|
const normalized = path.replaceAll("\\", "/").replace(/^\.\//, "");
|
|
3
9
|
if (!cwd || /^(?:\/|[a-z]:)/i.test(normalized))
|