@evandu/super-pi 0.1.320 → 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 +47 -10
- package/dist/.super-pi-check-inputs.json +4 -0
- package/dist/client/.super-pi-client-sources.json +18 -18
- package/dist/client/assets/{CodeMirrorEditor-CAE3YBWg.js → CodeMirrorEditor-BsMtOxUG.js} +1 -1
- package/dist/client/assets/{GitDiffEditor-CSOZ4_Y8.js → GitDiffEditor-L_OuYDQ2.js} +2 -2
- package/dist/client/assets/index-Cvx8i65V.css +1 -0
- package/dist/client/assets/index-DeMK1efe.js +358 -0
- 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 +14 -5
- package/dist/server/file-review-threads.js +53 -26
- package/dist/server/http-server.js +65 -45
- package/dist/server/runtime.js +3 -2
- package/dist/shared/file-review.d.ts +9 -3
- package/dist/shared/file-review.js +11 -8
- package/package.json +1 -1
- package/dist/client/assets/index-B4HerJl4.css +0 -1
- package/dist/client/assets/index-DMTJGkKw.js +0 -363
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_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",
|
|
@@ -1,21 +1,30 @@
|
|
|
1
|
-
import type
|
|
1
|
+
import { type ReviewThread } from "../shared/file-review.js";
|
|
2
2
|
type ScopedThread = ReviewThread & {
|
|
3
3
|
workspaceId: string;
|
|
4
4
|
cwd: string;
|
|
5
5
|
};
|
|
6
6
|
type Scope = Pick<ScopedThread, "workspaceId" | "cwd">;
|
|
7
|
-
/**
|
|
7
|
+
/** Review threads belong to one workspace checkout. Cwd records the origin of a relative anchor. */
|
|
8
8
|
export declare class FileReviewThreads {
|
|
9
9
|
private readonly path;
|
|
10
10
|
private entries;
|
|
11
11
|
private loaded;
|
|
12
12
|
constructor(path: string);
|
|
13
13
|
list(scope: Scope): ScopedThread[];
|
|
14
|
-
create(scope: Scope,
|
|
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
|
-
|
|
18
|
-
|
|
24
|
+
agentReply(scopes: Scope[], author: {
|
|
25
|
+
conversationId: string;
|
|
26
|
+
agentName?: string;
|
|
27
|
+
}, id: string, detail: unknown, replyId: string, location?: unknown): ScopedThread;
|
|
19
28
|
private append;
|
|
20
29
|
private replace;
|
|
21
30
|
private get;
|
|
@@ -1,5 +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 { 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";
|
|
3
7
|
function record(value) {
|
|
4
8
|
if (!value || typeof value !== "object" || Array.isArray(value))
|
|
5
9
|
throw new Error("批注参数无效。");
|
|
@@ -36,9 +40,9 @@ function anchorFrom(value, allowAdditional = true) {
|
|
|
36
40
|
};
|
|
37
41
|
}
|
|
38
42
|
function sameScope(thread, scope) {
|
|
39
|
-
return thread.workspaceId === scope.workspaceId
|
|
43
|
+
return thread.workspaceId === scope.workspaceId;
|
|
40
44
|
}
|
|
41
|
-
/**
|
|
45
|
+
/** Review threads belong to one workspace checkout. Cwd records the origin of a relative anchor. */
|
|
42
46
|
export class FileReviewThreads {
|
|
43
47
|
path;
|
|
44
48
|
entries = new Map();
|
|
@@ -50,10 +54,10 @@ export class FileReviewThreads {
|
|
|
50
54
|
this.load();
|
|
51
55
|
return [...this.entries.values()].filter(thread => sameScope(thread, scope)).reverse();
|
|
52
56
|
}
|
|
53
|
-
create(scope,
|
|
57
|
+
create(scope, comments, agentName) {
|
|
54
58
|
this.load();
|
|
55
59
|
if (!Array.isArray(comments) || !comments.length || comments.length > 25)
|
|
56
|
-
throw new Error("
|
|
60
|
+
throw new Error("请选择要保存的批注。");
|
|
57
61
|
const next = new Map(this.entries);
|
|
58
62
|
const created = [];
|
|
59
63
|
for (const value of comments) {
|
|
@@ -63,14 +67,14 @@ export class FileReviewThreads {
|
|
|
63
67
|
throw new Error("批注标识无效。");
|
|
64
68
|
const existing = next.get(id);
|
|
65
69
|
if (existing) {
|
|
66
|
-
if (!sameScope(existing, scope)
|
|
67
|
-
throw new Error("
|
|
70
|
+
if (!sameScope(existing, scope))
|
|
71
|
+
throw new Error("此批注属于另一工作区。");
|
|
68
72
|
created.push(existing);
|
|
69
73
|
continue;
|
|
70
74
|
}
|
|
71
75
|
const entry = {
|
|
72
|
-
...scope, ...anchorFrom(item), id,
|
|
73
|
-
text: text(item.text, 2_000), replies: [], createdAt: new Date().toISOString(),
|
|
76
|
+
...scope, ...anchorFrom(item), id,
|
|
77
|
+
text: text(item.text, 2_000), replies: [], createdAt: new Date().toISOString(), agentName,
|
|
74
78
|
};
|
|
75
79
|
next.set(id, entry);
|
|
76
80
|
created.push(entry);
|
|
@@ -78,6 +82,31 @@ export class FileReviewThreads {
|
|
|
78
82
|
this.save(next);
|
|
79
83
|
return created;
|
|
80
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
|
+
}
|
|
81
110
|
update(scope, id, action, detail, replyId) {
|
|
82
111
|
const thread = this.getForScope(scope, id);
|
|
83
112
|
if (action === "delete") {
|
|
@@ -88,6 +117,8 @@ export class FileReviewThreads {
|
|
|
88
117
|
}
|
|
89
118
|
if (action === "reply")
|
|
90
119
|
return this.append(thread, "user", detail, replyId);
|
|
120
|
+
if (action === "edit")
|
|
121
|
+
return this.replace({ ...thread, text: text(detail, 2_000) });
|
|
91
122
|
if (action !== "resolve" && action !== "reopen")
|
|
92
123
|
throw new Error("未知批注操作。");
|
|
93
124
|
if (action === "resolve" && thread.resolvedAt || action === "reopen" && !thread.resolvedAt)
|
|
@@ -97,39 +128,35 @@ export class FileReviewThreads {
|
|
|
97
128
|
getForScope(scope, id) {
|
|
98
129
|
const thread = this.get(id);
|
|
99
130
|
if (!sameScope(thread, scope))
|
|
100
|
-
throw new Error("
|
|
131
|
+
throw new Error("找不到此工作区中的批注。");
|
|
101
132
|
return thread;
|
|
102
133
|
}
|
|
103
|
-
|
|
104
|
-
const thread = this.getForScope(scope, id);
|
|
105
|
-
if (!thread.replies.some(reply => reply.author === "user" && reply.id === replyId && !reply.sentAt))
|
|
106
|
-
return thread;
|
|
107
|
-
const sentAt = new Date().toISOString();
|
|
108
|
-
return this.replace({ ...thread, replies: thread.replies.map(reply => reply.author === "user" && reply.id === replyId ? { ...reply, sentAt } : reply) });
|
|
109
|
-
}
|
|
110
|
-
agentReply(scope, conversationId, id, detail, replyId, location) {
|
|
134
|
+
agentReply(scopes, author, id, detail, replyId, location) {
|
|
111
135
|
const thread = this.get(id);
|
|
112
|
-
if (
|
|
113
|
-
throw new Error("
|
|
136
|
+
if (!scopes.some(scope => sameScope(thread, scope)))
|
|
137
|
+
throw new Error("此批注不属于当前工作区。");
|
|
114
138
|
let code;
|
|
115
139
|
if (location !== undefined) {
|
|
116
140
|
const input = record(location);
|
|
117
141
|
const { line } = input;
|
|
118
142
|
if (line !== undefined && (typeof line !== "number" || !Number.isSafeInteger(line) || line < 1))
|
|
119
143
|
throw new Error("修改位置行号无效。");
|
|
120
|
-
|
|
144
|
+
const path = workspaceReviewPath(text(input.path, 4096));
|
|
145
|
+
if (/^(?:\/|[a-z]:)|(?:^|\/)\.\.(?:\/|$)/i.test(path))
|
|
146
|
+
throw new Error("修改位置须是工作区相对路径。");
|
|
147
|
+
code = { path, line: line };
|
|
121
148
|
}
|
|
122
|
-
return this.append(thread, "agent", detail, replyId, code);
|
|
149
|
+
return this.append(thread, "agent", detail, replyId, { ...author, location: code, cwd: "" });
|
|
123
150
|
}
|
|
124
|
-
append(thread, author, detail, replyId,
|
|
151
|
+
append(thread, author, detail, replyId, provenance) {
|
|
125
152
|
const id = replyId ? text(replyId, 200) : randomUUID();
|
|
126
|
-
if (thread.replies.some(reply => reply.author === author && reply.id === id))
|
|
153
|
+
if (thread.replies.some(reply => reply.author === author && reply.id === id && reply.conversationId === provenance?.conversationId))
|
|
127
154
|
return thread;
|
|
128
155
|
if (thread.resolvedAt)
|
|
129
156
|
throw new Error("此批注已标为完成。");
|
|
130
157
|
if (thread.replies.length >= 100)
|
|
131
158
|
throw new Error("此批注的回复已达上限。");
|
|
132
|
-
const reply = { id, author, text: text(detail, author === "agent" ? 12_000 : 2_000), createdAt: new Date().toISOString()
|
|
159
|
+
const reply = { ...provenance, id, author, text: text(detail, author === "agent" ? 12_000 : 2_000), createdAt: new Date().toISOString() };
|
|
133
160
|
return this.replace({ ...thread, replies: [...thread.replies, reply] });
|
|
134
161
|
}
|
|
135
162
|
replace(thread) {
|
|
@@ -152,7 +179,7 @@ export class FileReviewThreads {
|
|
|
152
179
|
const saved = JSON.parse(readFileSync(this.path, "utf8"));
|
|
153
180
|
if (saved.version !== 1 || !Array.isArray(saved.entries))
|
|
154
181
|
throw new Error("批注记录格式不正确。");
|
|
155
|
-
this.entries = new Map(saved.entries.map((entry) => [entry.id, entry]));
|
|
182
|
+
this.entries = new Map(saved.entries.map(({ conversationId: _legacyOwner, ...entry }) => [entry.id, entry]));
|
|
156
183
|
}
|
|
157
184
|
this.loaded = true;
|
|
158
185
|
}
|
|
@@ -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 {
|
|
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";
|
|
@@ -478,34 +478,71 @@ export function createHttpServer(options) {
|
|
|
478
478
|
const conversation = store.conversation(conversationId);
|
|
479
479
|
const allowed = verifyCapability(conversationId, request.headers["x-review-capability"], { running: runService.isRunning(conversationId) });
|
|
480
480
|
if (!allowed.ok || !conversation || conversation.archivedAt) {
|
|
481
|
-
json(403, { error: "
|
|
481
|
+
json(403, { error: "当前执行没有批注访问权限。" });
|
|
482
482
|
return;
|
|
483
483
|
}
|
|
484
484
|
try {
|
|
485
|
-
const agent = await context.runtime.agentFor?.(conversation);
|
|
486
|
-
const selection = toolSelection(agent?.tools, { extraAllowedTools: ["review_reply"] });
|
|
487
|
-
if (conversation.agentId && context.runtime.agentFor && !agent || selection.excludeTools?.includes("review_reply") || selection.tools && !selection.tools.includes("review_reply")) {
|
|
488
|
-
json(403, { error: "当前 Agent 没有批注回复权限。" });
|
|
489
|
-
return;
|
|
490
|
-
}
|
|
491
485
|
const payload = await readRequestText(request, 96_000);
|
|
492
486
|
if (payload.tooLarge) {
|
|
493
|
-
json(413, { error: "
|
|
487
|
+
json(413, { error: "批注请求过大。" });
|
|
494
488
|
return;
|
|
495
489
|
}
|
|
496
490
|
const body = JSON.parse(payload.text);
|
|
497
|
-
if (
|
|
498
|
-
throw new Error("
|
|
491
|
+
if (body.action !== undefined && body.action !== "list" && body.action !== "reply" && body.action !== "create")
|
|
492
|
+
throw new Error("未知批注工具操作。");
|
|
493
|
+
const tool = body.action === "create" ? "review_create" : body.action === "list" ? "review_list" : "review_reply";
|
|
494
|
+
const agent = await context.runtime.agentFor?.(conversation);
|
|
495
|
+
const selection = toolSelection(agent?.tools, { extraAllowedTools: FILE_REVIEW_DISCUSSION_TOOLS });
|
|
496
|
+
if (conversation.agentId && context.runtime.agentFor && !agent || selection.excludeTools?.includes(tool) || selection.tools && !selection.tools.includes(tool)) {
|
|
497
|
+
json(403, { error: "当前 Agent 没有此批注工具的权限。" });
|
|
498
|
+
return;
|
|
499
|
+
}
|
|
499
500
|
if (!runService.isRunning(conversationId)) {
|
|
500
501
|
json(403, { error: "当前执行已经结束。" });
|
|
501
502
|
return;
|
|
502
503
|
}
|
|
503
|
-
|
|
504
|
-
|
|
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
|
+
}
|
|
512
|
+
const workspaces = new Set([conversation.workspaceId, conversation.groupExecution?.workspaceId]);
|
|
513
|
+
const scopes = [...workspaces].flatMap(workspaceId => {
|
|
514
|
+
const workspace = workspaceId ? store.workspace(workspaceId) : undefined;
|
|
515
|
+
return workspace && !workspace.closedAt ? [{ workspaceId: workspace.id, cwd: "" }] : [];
|
|
516
|
+
});
|
|
517
|
+
if (tool === "review_list") {
|
|
518
|
+
const entries = scopes.flatMap(scope => fileReviewThreads.list(scope));
|
|
519
|
+
const offset = Number.isSafeInteger(body.offset) && body.offset > 0 ? body.offset : 0;
|
|
520
|
+
if (typeof body.id === "string") {
|
|
521
|
+
const thread = entries.find(item => item.id === body.id);
|
|
522
|
+
if (!thread)
|
|
523
|
+
throw new Error("找不到当前工作区中的批注。");
|
|
524
|
+
const end = Math.max(0, thread.replies.length - offset);
|
|
525
|
+
const from = Math.max(0, end - 12);
|
|
526
|
+
json(200, { thread: { ...thread, replies: thread.replies.slice(from, end), replyCount: thread.replies.length },
|
|
527
|
+
nextOffset: from ? offset + end - from : undefined });
|
|
528
|
+
return;
|
|
529
|
+
}
|
|
530
|
+
const path = typeof body.path === "string" ? workspaceReviewPath(body.path) : undefined;
|
|
531
|
+
const matches = entries.filter(thread => (body.includeResolved === true || !thread.resolvedAt)
|
|
532
|
+
&& (!path || [thread.path, thread.currentPath, ...thread.additional?.map(item => item.path) ?? []]
|
|
533
|
+
.some(item => item && workspaceReviewPath(item, thread.cwd) === path)));
|
|
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 }));
|
|
536
|
+
json(200, { threads: page, nextOffset: matches.length > offset + page.length ? offset + page.length : undefined });
|
|
537
|
+
return;
|
|
538
|
+
}
|
|
539
|
+
if (typeof body.id !== "string" || typeof body.replyId !== "string" || !body.replyId)
|
|
540
|
+
throw new Error("批注回复缺少标识。");
|
|
541
|
+
const thread = fileReviewThreads.agentReply(scopes, { conversationId, agentName: agent?.name }, body.id, body.text, body.replyId, body.location);
|
|
505
542
|
json(200, { id: thread.id, replied: true });
|
|
506
543
|
}
|
|
507
544
|
catch (error) {
|
|
508
|
-
json(400, { error: error instanceof Error ? error.message : "
|
|
545
|
+
json(400, { error: error instanceof Error ? error.message : "无法处理批注工具请求。" });
|
|
509
546
|
}
|
|
510
547
|
return;
|
|
511
548
|
}
|
|
@@ -519,18 +556,11 @@ export function createHttpServer(options) {
|
|
|
519
556
|
}
|
|
520
557
|
const worktreeId = url.searchParams.get("worktreeId");
|
|
521
558
|
const checkout = worktreeId ? await resolveGitWorktree(workspace.path, worktreeId) : undefined;
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
json(200, { threads: [] });
|
|
526
|
-
return;
|
|
527
|
-
}
|
|
528
|
-
throw new Error("请先在此工作树打开一个会话。");
|
|
529
|
-
}
|
|
530
|
-
const root = await resolveFileCwd(owner.path, checkout ? "" : url.searchParams.get("cwd"));
|
|
531
|
-
const scope = { workspaceId: owner.id, cwd: relative(resolve(owner.path), root).replaceAll("\\", "/") };
|
|
559
|
+
let owner = checkout ? store.workspaces().find(item => !item.closedAt && !relative(resolve(item.path), resolve(checkout.path))) : workspace;
|
|
560
|
+
const root = await resolveFileCwd(checkout?.path ?? workspace.path, checkout ? "" : url.searchParams.get("cwd"));
|
|
561
|
+
const cwd = relative(resolve(checkout?.path ?? workspace.path), root).replaceAll("\\", "/");
|
|
532
562
|
if (request.method === "GET") {
|
|
533
|
-
json(200, { threads: fileReviewThreads.list(
|
|
563
|
+
json(200, { threads: owner ? fileReviewThreads.list({ workspaceId: owner.id, cwd }) : [] });
|
|
534
564
|
return;
|
|
535
565
|
}
|
|
536
566
|
if (request.method !== "POST") {
|
|
@@ -548,32 +578,22 @@ export function createHttpServer(options) {
|
|
|
548
578
|
return;
|
|
549
579
|
}
|
|
550
580
|
const body = JSON.parse(payload.text);
|
|
581
|
+
if (!owner && checkout && body.action === "create") {
|
|
582
|
+
const project = workspace.worktreeOf ? store.workspace(workspace.worktreeOf) ?? workspace : workspace;
|
|
583
|
+
owner = await store.createWorkspace((checkout.entry.branch ?? `工作树 ${checkout.entry.head.slice(0, 8)}`).slice(0, 80), checkout.path, checkout.entry.primary ? undefined : project);
|
|
584
|
+
context.broadcaster.broadcastState();
|
|
585
|
+
}
|
|
586
|
+
if (!owner)
|
|
587
|
+
throw new Error("找不到此工作树的批注。");
|
|
588
|
+
const scope = { workspaceId: owner.id, cwd };
|
|
551
589
|
if (body.action === "create") {
|
|
552
|
-
|
|
553
|
-
if (!conversation || conversation.archivedAt || conversation.groupExecution || conversation.workspaceId !== scope.workspaceId || (conversation.cwd ?? "") !== scope.cwd) {
|
|
554
|
-
throw new Error("接收会话不在此工作目录,或已归档。");
|
|
555
|
-
}
|
|
556
|
-
json(200, { threads: fileReviewThreads.create(scope, conversation.id, body.comments) });
|
|
590
|
+
json(200, { threads: fileReviewThreads.create(scope, body.comments) });
|
|
557
591
|
}
|
|
558
592
|
else if (body.action === "reply") {
|
|
559
593
|
if (typeof body.id !== "string" || typeof body.requestKey !== "string" || !/^[0-9a-f-]{36}$/.test(body.requestKey)) {
|
|
560
594
|
throw new Error("批注回复缺少有效标识。");
|
|
561
595
|
}
|
|
562
|
-
|
|
563
|
-
const conversation = store.conversation(original.conversationId);
|
|
564
|
-
if (!conversation || conversation.archivedAt || conversation.workspaceId !== scope.workspaceId || (conversation.cwd ?? "") !== scope.cwd) {
|
|
565
|
-
throw new Error("原会话已不可用。");
|
|
566
|
-
}
|
|
567
|
-
if (context.conversationService.childLockState(conversation.id) === "locked")
|
|
568
|
-
throw new Error(CHILD_SESSION_LOCK_REASON);
|
|
569
|
-
if (context.conversationService.isReverting(conversation.id))
|
|
570
|
-
throw new Error("请等会话撤回结束后再回复批注。");
|
|
571
|
-
const thread = fileReviewThreads.update(scope, body.id, "reply", body.text, body.requestKey);
|
|
572
|
-
const reply = thread.replies.find(item => item.author === "user" && item.id === body.requestKey);
|
|
573
|
-
await new Promise((accept, reject) => {
|
|
574
|
-
void runService.enqueueAndRun(conversation.id, reviewFollowUpPrompt(thread, reply.text), undefined, undefined, `message_${body.requestKey}`, "queue", accept).catch(reject);
|
|
575
|
-
});
|
|
576
|
-
json(200, { thread: fileReviewThreads.markReplySent(scope, thread.id, reply.id) });
|
|
596
|
+
json(200, { thread: fileReviewThreads.update(scope, body.id, "reply", body.text, body.requestKey) });
|
|
577
597
|
}
|
|
578
598
|
else {
|
|
579
599
|
if (typeof body.id !== "string" || typeof body.action !== "string")
|
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;
|
|
@@ -25,15 +27,19 @@ export type ReviewReply = {
|
|
|
25
27
|
author: "user" | "agent";
|
|
26
28
|
text: string;
|
|
27
29
|
createdAt: string;
|
|
28
|
-
sentAt?: string;
|
|
29
30
|
location?: ReviewCodeLocation;
|
|
31
|
+
conversationId?: string;
|
|
32
|
+
agentName?: string;
|
|
33
|
+
cwd?: string;
|
|
30
34
|
};
|
|
31
35
|
export type ReviewThread = ReviewAnchor & {
|
|
32
36
|
id: string;
|
|
33
37
|
text: string;
|
|
34
|
-
|
|
38
|
+
cwd: string;
|
|
35
39
|
createdAt: string;
|
|
36
40
|
resolvedAt?: string;
|
|
41
|
+
agentName?: string;
|
|
37
42
|
replies: ReviewReply[];
|
|
38
43
|
};
|
|
39
|
-
export declare function
|
|
44
|
+
export declare function reviewExcerpt(lines: readonly string[]): string;
|
|
45
|
+
export declare function workspaceReviewPath(path: string, cwd?: string): string;
|
|
@@ -1,9 +1,12 @@
|
|
|
1
|
-
export
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
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
|
+
}
|
|
7
|
+
export function workspaceReviewPath(path, cwd = "") {
|
|
8
|
+
const normalized = path.replaceAll("\\", "/").replace(/^\.\//, "");
|
|
9
|
+
if (!cwd || /^(?:\/|[a-z]:)/i.test(normalized))
|
|
10
|
+
return normalized;
|
|
11
|
+
return `${cwd}/${normalized}`;
|
|
9
12
|
}
|