@evandu/super-pi 0.1.314 → 0.1.317
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/agents/super-pi-task/index.ts +23 -0
- package/desktop/preload.cjs +4 -2
- package/dist/client/.super-pi-client-sources.json +30 -26
- package/dist/client/assets/{CodeMirrorEditor-DodqscaS.js → CodeMirrorEditor-BNCzYdKo.js} +1 -1
- package/dist/client/assets/{GitDiffEditor-BA3eG1na.js → GitDiffEditor-BMDOqTzy.js} +1 -1
- package/dist/client/assets/index-D9YZBpfH.css +1 -0
- package/dist/client/assets/index-MUKi24sj.js +363 -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/application/rsi-repairs.d.ts +1 -1
- package/dist/server/application/rsi-repairs.js +14 -3
- package/dist/server/file-review-threads.d.ts +25 -0
- package/dist/server/file-review-threads.js +165 -0
- package/dist/server/http-server.js +123 -1
- package/dist/server/index.js +4 -3
- package/dist/server/runtime.js +4 -1
- package/dist/server/types.d.ts +1 -0
- package/dist/server/ws-server.js +1 -0
- package/dist/shared/file-review.d.ts +39 -0
- package/dist/shared/file-review.js +9 -0
- package/dist/shared/rsi.d.ts +2 -0
- package/package.json +3 -1
- package/dist/client/assets/index-B9lWq5MJ.js +0 -363
- package/dist/client/assets/index-CtsA5apS.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-MUKi24sj.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-D9YZBpfH.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", "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_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"];
|
|
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
|
@@ -40,7 +40,7 @@ export const PI_TOOL_NAMES = [
|
|
|
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
42
|
"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",
|
|
43
|
+
"memory", "skill_manage", "session_search", "agent_handbook", "user_tool", "user_tool_manage", "review_reply",
|
|
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",
|
|
46
46
|
"document_read", "document_write", "presentation_create", "presentation_read", "presentation_edit", "presentation_render", "web_search", "web_fetch", "feishu_doc_read", "feishu_doc_write",
|
|
@@ -3,7 +3,7 @@ import type { GroupRsiReport } from "../../shared/group-chat.js";
|
|
|
3
3
|
import { type RsiRepairView, type RsiSource } from "../../shared/rsi.js";
|
|
4
4
|
export type RsiRepairHooks = {
|
|
5
5
|
discuss(source: RsiSource, title: string, prompt: string): Promise<string>;
|
|
6
|
-
send(conversationId: string, prompt: string): Promise<void>;
|
|
6
|
+
send(conversationId: string, prompt: string, requestId?: string): Promise<void>;
|
|
7
7
|
execute(conversationId: string, prompt: string): Promise<void>;
|
|
8
8
|
endExecution(conversationId: string): Promise<void>;
|
|
9
9
|
stop(conversationId: string): Promise<unknown>;
|
|
@@ -85,10 +85,13 @@ export class RsiRepairs {
|
|
|
85
85
|
return this.serial(async () => {
|
|
86
86
|
if (this.closed || !this.hooks)
|
|
87
87
|
throw new Error("当前服务不支持 RSI 讨论与修复。");
|
|
88
|
+
const requestId = typeof body.requestId === "string" && /^rsi_[0-9a-f-]{36}$/i.test(body.requestId) ? body.requestId : undefined;
|
|
88
89
|
const workspace = this.store.workspace(source.workspaceId);
|
|
89
90
|
if (!workspace || workspace.closedAt && body.action !== "rsi.repair.cancel")
|
|
90
91
|
throw new Error("请选择已打开的有效工作区。");
|
|
91
92
|
if (body.action === "rsi.repair.discuss") {
|
|
93
|
+
if (requestId && this.jobs.some(job => job.initialRequestId === requestId && rsiKey(job.source) === rsiKey(source)))
|
|
94
|
+
return;
|
|
92
95
|
const initialPrompt = typeof body.initialPrompt === "string" ? body.initialPrompt.trim() : "";
|
|
93
96
|
if (initialPrompt.length > 12000)
|
|
94
97
|
throw new Error("讨论开场内容不能超过 12000 字。");
|
|
@@ -106,7 +109,8 @@ export class RsiRepairs {
|
|
|
106
109
|
delete existing.error;
|
|
107
110
|
existing.updatedAt = new Date().toISOString();
|
|
108
111
|
await this.save();
|
|
109
|
-
await this.hooks.send(existing.conversationId, initialPrompt);
|
|
112
|
+
await this.hooks.send(existing.conversationId, initialPrompt, requestId);
|
|
113
|
+
existing.initialRequestId = requestId;
|
|
110
114
|
if (report) {
|
|
111
115
|
existing.observationSourceKey = report.sourceKey;
|
|
112
116
|
existing.reportId = report.id;
|
|
@@ -135,7 +139,7 @@ export class RsiRepairs {
|
|
|
135
139
|
const id = await this.hooks.discuss(source, title, prompt);
|
|
136
140
|
const now = new Date().toISOString();
|
|
137
141
|
this.jobs.push({ id: randomUUID(), source: { ...source }, reportId: report?.id, observationSourceKey: report?.sourceKey, title, conversationId: id, status: "discussing", createdAt: now, updatedAt: now,
|
|
138
|
-
initialMessageId: this.store.conversation(id)?.messages.find(message => message.role === "user")?.id, ...(initialPrompt ? { initialPrompt } : {}) });
|
|
142
|
+
initialMessageId: this.store.conversation(id)?.messages.find(message => message.role === "user")?.id, initialRequestId: requestId, ...(initialPrompt ? { initialPrompt } : {}) });
|
|
139
143
|
await this.save();
|
|
140
144
|
return;
|
|
141
145
|
}
|
|
@@ -145,6 +149,10 @@ export class RsiRepairs {
|
|
|
145
149
|
const conversation = this.store.conversation(job.conversationId);
|
|
146
150
|
if (!conversation || conversation.workspaceId !== source.workspaceId || conversation.archivedAt && body.action !== "rsi.repair.cancel")
|
|
147
151
|
throw new Error("修复会话不存在或已归档。");
|
|
152
|
+
if (requestId && body.action === "rsi.repair.approve" && job.approvedRequestId === requestId)
|
|
153
|
+
return;
|
|
154
|
+
if (requestId && body.action === "rsi.repair.send" && this.store.hasAcceptedSend(job.conversationId, `message_${requestId.slice(4)}`))
|
|
155
|
+
return;
|
|
148
156
|
if (body.action === "rsi.repair.cancel") {
|
|
149
157
|
if (["completed", "cancelled"].includes(job.status))
|
|
150
158
|
return;
|
|
@@ -163,6 +171,8 @@ export class RsiRepairs {
|
|
|
163
171
|
return;
|
|
164
172
|
}
|
|
165
173
|
if (body.action === "rsi.repair.accept") {
|
|
174
|
+
if (job.status === "completed")
|
|
175
|
+
return;
|
|
166
176
|
if (job.status !== "review")
|
|
167
177
|
throw new Error("修复尚未进入待验收状态。");
|
|
168
178
|
job.status = "completed";
|
|
@@ -182,7 +192,7 @@ export class RsiRepairs {
|
|
|
182
192
|
delete job.error;
|
|
183
193
|
job.updatedAt = new Date().toISOString();
|
|
184
194
|
await this.save();
|
|
185
|
-
await this.hooks.send(job.conversationId, message);
|
|
195
|
+
await this.hooks.send(job.conversationId, message, requestId);
|
|
186
196
|
return;
|
|
187
197
|
}
|
|
188
198
|
if (body.action !== "rsi.repair.approve")
|
|
@@ -208,6 +218,7 @@ export class RsiRepairs {
|
|
|
208
218
|
job.approvedPlan = plan;
|
|
209
219
|
job.updatedAt = job.approvedAt;
|
|
210
220
|
delete job.error;
|
|
221
|
+
job.approvedRequestId = requestId;
|
|
211
222
|
job.approvals = [...(job.approvals ?? []), { at: job.approvedAt, revision: view.revision, plan }];
|
|
212
223
|
try {
|
|
213
224
|
await this.save();
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import type { ReviewThread } from "../shared/file-review.js";
|
|
2
|
+
type ScopedThread = ReviewThread & {
|
|
3
|
+
workspaceId: string;
|
|
4
|
+
cwd: string;
|
|
5
|
+
};
|
|
6
|
+
type Scope = Pick<ScopedThread, "workspaceId" | "cwd">;
|
|
7
|
+
/** The execution service owns sent annotations. Drafts can remain in the reader's local storage. */
|
|
8
|
+
export declare class FileReviewThreads {
|
|
9
|
+
private readonly path;
|
|
10
|
+
private entries;
|
|
11
|
+
private loaded;
|
|
12
|
+
constructor(path: string);
|
|
13
|
+
list(scope: Scope): ScopedThread[];
|
|
14
|
+
create(scope: Scope, conversationId: string, comments: unknown): ScopedThread[];
|
|
15
|
+
update(scope: Scope, id: string, action: string, detail?: unknown, replyId?: string): ScopedThread | undefined;
|
|
16
|
+
getForScope(scope: Scope, id: string): ScopedThread;
|
|
17
|
+
markReplySent(scope: Scope, id: string, replyId: string): ScopedThread;
|
|
18
|
+
agentReply(scope: Scope, conversationId: string, id: string, detail: unknown, replyId: string, location?: unknown): ScopedThread;
|
|
19
|
+
private append;
|
|
20
|
+
private replace;
|
|
21
|
+
private get;
|
|
22
|
+
private load;
|
|
23
|
+
private save;
|
|
24
|
+
}
|
|
25
|
+
export {};
|
|
@@ -0,0 +1,165 @@
|
|
|
1
|
+
import { randomUUID } from "node:crypto";
|
|
2
|
+
import { existsSync, readFileSync, renameSync, writeFileSync } from "node:fs";
|
|
3
|
+
function record(value) {
|
|
4
|
+
if (!value || typeof value !== "object" || Array.isArray(value))
|
|
5
|
+
throw new Error("批注参数无效。");
|
|
6
|
+
return value;
|
|
7
|
+
}
|
|
8
|
+
function text(value, limit, optional = false) {
|
|
9
|
+
if (value === undefined && optional)
|
|
10
|
+
return;
|
|
11
|
+
if (typeof value !== "string" || value.length > limit || value.includes("\0") || !optional && !value.trim())
|
|
12
|
+
throw new Error("批注内容或定位无效。");
|
|
13
|
+
return value;
|
|
14
|
+
}
|
|
15
|
+
function anchorFrom(value, allowAdditional = true) {
|
|
16
|
+
const source = record(value);
|
|
17
|
+
const { side, start, end } = source;
|
|
18
|
+
if (side !== "file" && side !== "before" && side !== "after")
|
|
19
|
+
throw new Error("批注版本无效。");
|
|
20
|
+
if (start !== undefined || end !== undefined) {
|
|
21
|
+
if (typeof start !== "number" || typeof end !== "number" || !Number.isSafeInteger(start) || !Number.isSafeInteger(end)
|
|
22
|
+
|| start < 1 || end < start || end - start >= 30)
|
|
23
|
+
throw new Error("批注行范围无效。");
|
|
24
|
+
}
|
|
25
|
+
let additional;
|
|
26
|
+
if (source.additional !== undefined) {
|
|
27
|
+
if (!allowAdditional || !Array.isArray(source.additional) || source.additional.length > 29)
|
|
28
|
+
throw new Error("批注行范围无效。");
|
|
29
|
+
additional = source.additional.map(item => anchorFrom(item, false));
|
|
30
|
+
}
|
|
31
|
+
return {
|
|
32
|
+
side, start: start, end: end,
|
|
33
|
+
path: text(source.path, 4096), source: text(source.source, 8192),
|
|
34
|
+
comparison: text(source.comparison, 600, true), commit: text(source.commit, 128, true),
|
|
35
|
+
excerpt: text(source.excerpt, 3200, true), position: text(source.position, 120, true), currentPath: text(source.currentPath, 4096, true), additional,
|
|
36
|
+
};
|
|
37
|
+
}
|
|
38
|
+
function sameScope(thread, scope) {
|
|
39
|
+
return thread.workspaceId === scope.workspaceId && thread.cwd === scope.cwd;
|
|
40
|
+
}
|
|
41
|
+
/** The execution service owns sent annotations. Drafts can remain in the reader's local storage. */
|
|
42
|
+
export class FileReviewThreads {
|
|
43
|
+
path;
|
|
44
|
+
entries = new Map();
|
|
45
|
+
loaded = false;
|
|
46
|
+
constructor(path) {
|
|
47
|
+
this.path = path;
|
|
48
|
+
}
|
|
49
|
+
list(scope) {
|
|
50
|
+
this.load();
|
|
51
|
+
return [...this.entries.values()].filter(thread => sameScope(thread, scope)).reverse();
|
|
52
|
+
}
|
|
53
|
+
create(scope, conversationId, comments) {
|
|
54
|
+
this.load();
|
|
55
|
+
if (!Array.isArray(comments) || !comments.length || comments.length > 25)
|
|
56
|
+
throw new Error("请选择要带到会话的批注。");
|
|
57
|
+
const next = new Map(this.entries);
|
|
58
|
+
const created = [];
|
|
59
|
+
for (const value of comments) {
|
|
60
|
+
const item = record(value);
|
|
61
|
+
const id = text(item.id, 128);
|
|
62
|
+
if (!/^[A-Za-z0-9_-]+$/.test(id))
|
|
63
|
+
throw new Error("批注标识无效。");
|
|
64
|
+
const existing = next.get(id);
|
|
65
|
+
if (existing) {
|
|
66
|
+
if (!sameScope(existing, scope) || existing.conversationId !== conversationId)
|
|
67
|
+
throw new Error("此批注已经关联到另一会话。");
|
|
68
|
+
created.push(existing);
|
|
69
|
+
continue;
|
|
70
|
+
}
|
|
71
|
+
const entry = {
|
|
72
|
+
...scope, ...anchorFrom(item), id, conversationId,
|
|
73
|
+
text: text(item.text, 2_000), replies: [], createdAt: new Date().toISOString(),
|
|
74
|
+
};
|
|
75
|
+
next.set(id, entry);
|
|
76
|
+
created.push(entry);
|
|
77
|
+
}
|
|
78
|
+
this.save(next);
|
|
79
|
+
return created;
|
|
80
|
+
}
|
|
81
|
+
update(scope, id, action, detail, replyId) {
|
|
82
|
+
const thread = this.getForScope(scope, id);
|
|
83
|
+
if (action === "delete") {
|
|
84
|
+
const next = new Map(this.entries);
|
|
85
|
+
next.delete(id);
|
|
86
|
+
this.save(next);
|
|
87
|
+
return;
|
|
88
|
+
}
|
|
89
|
+
if (action === "reply")
|
|
90
|
+
return this.append(thread, "user", detail, replyId);
|
|
91
|
+
if (action !== "resolve" && action !== "reopen")
|
|
92
|
+
throw new Error("未知批注操作。");
|
|
93
|
+
if (action === "resolve" && thread.resolvedAt || action === "reopen" && !thread.resolvedAt)
|
|
94
|
+
return thread;
|
|
95
|
+
return this.replace({ ...thread, resolvedAt: action === "resolve" ? new Date().toISOString() : undefined });
|
|
96
|
+
}
|
|
97
|
+
getForScope(scope, id) {
|
|
98
|
+
const thread = this.get(id);
|
|
99
|
+
if (!sameScope(thread, scope))
|
|
100
|
+
throw new Error("找不到此工作目录中的批注。");
|
|
101
|
+
return thread;
|
|
102
|
+
}
|
|
103
|
+
markReplySent(scope, id, replyId) {
|
|
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) {
|
|
111
|
+
const thread = this.get(id);
|
|
112
|
+
if (thread.conversationId !== conversationId || !sameScope(thread, scope))
|
|
113
|
+
throw new Error("此批注不属于当前会话。");
|
|
114
|
+
let code;
|
|
115
|
+
if (location !== undefined) {
|
|
116
|
+
const input = record(location);
|
|
117
|
+
const { line } = input;
|
|
118
|
+
if (line !== undefined && (typeof line !== "number" || !Number.isSafeInteger(line) || line < 1))
|
|
119
|
+
throw new Error("修改位置行号无效。");
|
|
120
|
+
code = { path: text(input.path, 4096), line: line };
|
|
121
|
+
}
|
|
122
|
+
return this.append(thread, "agent", detail, replyId, code);
|
|
123
|
+
}
|
|
124
|
+
append(thread, author, detail, replyId, location) {
|
|
125
|
+
const id = replyId ? text(replyId, 200) : randomUUID();
|
|
126
|
+
if (thread.replies.some(reply => reply.author === author && reply.id === id))
|
|
127
|
+
return thread;
|
|
128
|
+
if (thread.resolvedAt)
|
|
129
|
+
throw new Error("此批注已标为完成。");
|
|
130
|
+
if (thread.replies.length >= 100)
|
|
131
|
+
throw new Error("此批注的回复已达上限。");
|
|
132
|
+
const reply = { id, author, text: text(detail, author === "agent" ? 12_000 : 2_000), createdAt: new Date().toISOString(), location };
|
|
133
|
+
return this.replace({ ...thread, replies: [...thread.replies, reply] });
|
|
134
|
+
}
|
|
135
|
+
replace(thread) {
|
|
136
|
+
const next = new Map(this.entries);
|
|
137
|
+
next.set(thread.id, thread);
|
|
138
|
+
this.save(next);
|
|
139
|
+
return thread;
|
|
140
|
+
}
|
|
141
|
+
get(id) {
|
|
142
|
+
this.load();
|
|
143
|
+
const entry = this.entries.get(id);
|
|
144
|
+
if (!entry)
|
|
145
|
+
throw new Error("找不到该批注。");
|
|
146
|
+
return entry;
|
|
147
|
+
}
|
|
148
|
+
load() {
|
|
149
|
+
if (this.loaded)
|
|
150
|
+
return;
|
|
151
|
+
if (existsSync(this.path)) {
|
|
152
|
+
const saved = JSON.parse(readFileSync(this.path, "utf8"));
|
|
153
|
+
if (saved.version !== 1 || !Array.isArray(saved.entries))
|
|
154
|
+
throw new Error("批注记录格式不正确。");
|
|
155
|
+
this.entries = new Map(saved.entries.map((entry) => [entry.id, entry]));
|
|
156
|
+
}
|
|
157
|
+
this.loaded = true;
|
|
158
|
+
}
|
|
159
|
+
save(next) {
|
|
160
|
+
const temporary = this.path + ".tmp";
|
|
161
|
+
writeFileSync(temporary, JSON.stringify({ version: 1, entries: [...next.values()] }), { mode: 0o600 });
|
|
162
|
+
renameSync(temporary, this.path);
|
|
163
|
+
this.entries = next;
|
|
164
|
+
}
|
|
165
|
+
}
|
|
@@ -23,6 +23,9 @@ import { checkDiskVersion, readPackageVersion } from "./version.js";
|
|
|
23
23
|
import { gitBlame, gitBranches, gitCommit, gitCommitDiff, gitDiff, gitIndexFileContent, gitGraph, gitLog, gitMutate, gitStagedDraftInput, gitStashes, gitStatus, gitWorktrees, resolveGitWorktree, inspectGitWorktree, gitWorktreeCommittedDiff } from "./git.js";
|
|
24
24
|
import { computeFileDiff } from "./file-diff.js";
|
|
25
25
|
import { verifyCapability } from "./capability.js";
|
|
26
|
+
import { FileReviewThreads } from "./file-review-threads.js";
|
|
27
|
+
import { toolSelection } from "./agents.js";
|
|
28
|
+
import { reviewFollowUpPrompt } from "../shared/file-review.js";
|
|
26
29
|
import { conversationWorkspace } from "./model-filter.js";
|
|
27
30
|
import { describeSchedule } from "./scheduled-tasks.js";
|
|
28
31
|
import { MAX_KNOWLEDGE_REQUEST_BYTES } from "./knowledge.js";
|
|
@@ -369,6 +372,7 @@ export function createHttpServer(options) {
|
|
|
369
372
|
const { uploadsDir, clientDir, rootDir } = paths;
|
|
370
373
|
const gitDrafts = new Set();
|
|
371
374
|
const manageWorktree = createWorktreeService(context);
|
|
375
|
+
const fileReviewThreads = new FileReviewThreads(join(paths.dataDir, "file-review-threads.json"));
|
|
372
376
|
const explicitFileOpen = createExplicitFileOpen();
|
|
373
377
|
const browserAccess = context.browserAccess ??= new BrowserAccess(join(paths.dataDir, "browser-access.json"));
|
|
374
378
|
const nativeTools = new NativeToolsService(paths.dataDir, () => context.runtime?.reloadNativeTools?.());
|
|
@@ -454,7 +458,7 @@ export function createHttpServer(options) {
|
|
|
454
458
|
// the endpoint that can spend it is exactly the one an agent's own turn can reach, and the
|
|
455
459
|
// management half (`/api/feishu/config`) stays behind the ordinary token AND the local-address
|
|
456
460
|
// predicate.
|
|
457
|
-
if (requestPath !== "/api/user-tools/tool" && 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)) {
|
|
461
|
+
if (requestPath !== "/api/file-review/tool" && requestPath !== "/api/user-tools/tool" && 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)) {
|
|
458
462
|
response.writeHead(401, { "www-authenticate": "Bearer" }).end("Authentication required");
|
|
459
463
|
return;
|
|
460
464
|
}
|
|
@@ -465,6 +469,124 @@ export function createHttpServer(options) {
|
|
|
465
469
|
return;
|
|
466
470
|
if (await handleRsiHttp(context, request, response, url))
|
|
467
471
|
return;
|
|
472
|
+
if (url.pathname === "/api/file-review/tool") {
|
|
473
|
+
if (request.method !== "POST") {
|
|
474
|
+
json(405, { error: "批注工具需要 POST 请求。" });
|
|
475
|
+
return;
|
|
476
|
+
}
|
|
477
|
+
const conversationId = String(request.headers["x-review-conversation"] ?? "");
|
|
478
|
+
const conversation = store.conversation(conversationId);
|
|
479
|
+
const allowed = verifyCapability(conversationId, request.headers["x-review-capability"], { running: runService.isRunning(conversationId) });
|
|
480
|
+
if (!allowed.ok || !conversation || conversation.archivedAt) {
|
|
481
|
+
json(403, { error: "当前执行没有批注回复权限。" });
|
|
482
|
+
return;
|
|
483
|
+
}
|
|
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
|
+
const payload = await readRequestText(request, 96_000);
|
|
492
|
+
if (payload.tooLarge) {
|
|
493
|
+
json(413, { error: "批注回复过大。" });
|
|
494
|
+
return;
|
|
495
|
+
}
|
|
496
|
+
const body = JSON.parse(payload.text);
|
|
497
|
+
if (typeof body.id !== "string" || typeof body.replyId !== "string" || !body.replyId)
|
|
498
|
+
throw new Error("批注回复缺少标识。");
|
|
499
|
+
if (!runService.isRunning(conversationId)) {
|
|
500
|
+
json(403, { error: "当前执行已经结束。" });
|
|
501
|
+
return;
|
|
502
|
+
}
|
|
503
|
+
const scope = { workspaceId: conversation.workspaceId, cwd: conversation.cwd ?? "" };
|
|
504
|
+
const thread = fileReviewThreads.agentReply(scope, conversationId, body.id, body.text, body.replyId, body.location);
|
|
505
|
+
json(200, { id: thread.id, replied: true });
|
|
506
|
+
}
|
|
507
|
+
catch (error) {
|
|
508
|
+
json(400, { error: error instanceof Error ? error.message : "无法回复批注。" });
|
|
509
|
+
}
|
|
510
|
+
return;
|
|
511
|
+
}
|
|
512
|
+
if (url.pathname === "/api/file-review") {
|
|
513
|
+
try {
|
|
514
|
+
const workspaceId = url.searchParams.get("workspaceId") ?? "";
|
|
515
|
+
const workspace = store.workspace(workspaceId);
|
|
516
|
+
if (!workspace || workspace.closedAt) {
|
|
517
|
+
json(404, { error: "请先选择有效工作区。" });
|
|
518
|
+
return;
|
|
519
|
+
}
|
|
520
|
+
const worktreeId = url.searchParams.get("worktreeId");
|
|
521
|
+
const checkout = worktreeId ? await resolveGitWorktree(workspace.path, worktreeId) : undefined;
|
|
522
|
+
const owner = checkout ? store.workspaces().find(item => !item.closedAt && !relative(resolve(item.path), resolve(checkout.path))) : workspace;
|
|
523
|
+
if (!owner) {
|
|
524
|
+
if (request.method === "GET") {
|
|
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("\\", "/") };
|
|
532
|
+
if (request.method === "GET") {
|
|
533
|
+
json(200, { threads: fileReviewThreads.list(scope) });
|
|
534
|
+
return;
|
|
535
|
+
}
|
|
536
|
+
if (request.method !== "POST") {
|
|
537
|
+
json(405, { error: "批注仅支持 GET / POST。" });
|
|
538
|
+
return;
|
|
539
|
+
}
|
|
540
|
+
const origin = request.headers.origin;
|
|
541
|
+
if (!isBrowserAuthorized(request) && (!isLocalOrPrivateAddress(remote) || origin && origin !== url.origin)) {
|
|
542
|
+
json(403, { error: "批注操作需要同源访问。" });
|
|
543
|
+
return;
|
|
544
|
+
}
|
|
545
|
+
const payload = await readRequestText(request, 2_500_000);
|
|
546
|
+
if (payload.tooLarge) {
|
|
547
|
+
json(413, { error: "批注请求过大。" });
|
|
548
|
+
return;
|
|
549
|
+
}
|
|
550
|
+
const body = JSON.parse(payload.text);
|
|
551
|
+
if (body.action === "create") {
|
|
552
|
+
const conversation = typeof body.conversationId === "string" ? store.conversation(body.conversationId) : undefined;
|
|
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) });
|
|
557
|
+
}
|
|
558
|
+
else if (body.action === "reply") {
|
|
559
|
+
if (typeof body.id !== "string" || typeof body.requestKey !== "string" || !/^[0-9a-f-]{36}$/.test(body.requestKey)) {
|
|
560
|
+
throw new Error("批注回复缺少有效标识。");
|
|
561
|
+
}
|
|
562
|
+
const original = fileReviewThreads.getForScope(scope, body.id);
|
|
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) });
|
|
577
|
+
}
|
|
578
|
+
else {
|
|
579
|
+
if (typeof body.id !== "string" || typeof body.action !== "string")
|
|
580
|
+
throw new Error("批注操作缺少标识。");
|
|
581
|
+
const thread = fileReviewThreads.update(scope, body.id, body.action, body.text, typeof body.requestKey === "string" ? body.requestKey : undefined);
|
|
582
|
+
json(200, { thread });
|
|
583
|
+
}
|
|
584
|
+
}
|
|
585
|
+
catch (error) {
|
|
586
|
+
json(400, { error: error instanceof Error ? error.message : "无法处理批注。" });
|
|
587
|
+
}
|
|
588
|
+
return;
|
|
589
|
+
}
|
|
468
590
|
if (url.pathname === "/api/read-receipts") {
|
|
469
591
|
if (request.method === "GET") {
|
|
470
592
|
json(200, { receipts: readReceipts.list() });
|
package/dist/server/index.js
CHANGED
|
@@ -196,6 +196,7 @@ if (runtime instanceof PiRpcRuntime)
|
|
|
196
196
|
// capability on its own.
|
|
197
197
|
const documentService = new DocumentService(store);
|
|
198
198
|
process.env.SUPER_PI_DOCUMENTS_ENDPOINT = documentsEndpoint;
|
|
199
|
+
process.env.SUPER_PI_REVIEW_ENDPOINT = `http://${internalHost}:${port}/api/file-review/tool`;
|
|
199
200
|
// The Feishu tools. The credential belongs to the OFFICIAL CLI, which keeps it in the OS keychain,
|
|
200
201
|
// so this service holds nothing but the CLI's address. The endpoint is published here the same way
|
|
201
202
|
// the document one is: the Pi process of a turn reads it out of its environment, and the endpoint
|
|
@@ -366,12 +367,12 @@ const groupChatService = await GroupChatService.open(join(dataDir, "group-chats.
|
|
|
366
367
|
const { groupPrimaryExecutor, groupPrimaryLifecycle } = await import("./group-primary-executor.js");
|
|
367
368
|
runtime.setGroupMemberExecutor?.(groupPrimaryExecutor(store, runService, uploadsDir), groupPrimaryLifecycle(store, runService, id => runtime.disposeSessions?.(id) ?? Promise.resolve(), join(dataDir, "pi-sessions"), () => broadcaster.broadcastState()));
|
|
368
369
|
const userTools = await UserTools.open(join(dataDir, "user-capabilities"));
|
|
369
|
-
async function queueRsiConversation(id, prompt, authorized = false) {
|
|
370
|
+
async function queueRsiConversation(id, prompt, authorized = false, requestId) {
|
|
370
371
|
await new Promise((resolve, reject) => {
|
|
371
372
|
let accepted = false;
|
|
372
373
|
const acknowledge = () => { accepted = true; resolve(); };
|
|
373
374
|
const work = authorized ? runService.enqueueAuthorizedRsiRepair(id, prompt, acknowledge)
|
|
374
|
-
: runService.enqueueAndRun(id, prompt, undefined, undefined, crypto.randomUUID(), "queue", acknowledge);
|
|
375
|
+
: runService.enqueueAndRun(id, prompt, undefined, undefined, requestId ?? crypto.randomUUID(), "queue", acknowledge);
|
|
375
376
|
void work.catch(async (error) => {
|
|
376
377
|
if (!accepted)
|
|
377
378
|
reject(error);
|
|
@@ -407,7 +408,7 @@ const rsiService = await RsiService.open(join(dataDir, "rsi"), store, runtime, u
|
|
|
407
408
|
broadcaster.broadcastState();
|
|
408
409
|
return id;
|
|
409
410
|
},
|
|
410
|
-
async send(id, prompt) { await store.setConversationAgent(id, "rsi-discussion"); await queueRsiConversation(id, prompt); },
|
|
411
|
+
async send(id, prompt, requestId) { await store.setConversationAgent(id, "rsi-discussion"); await queueRsiConversation(id, prompt, false, requestId && `message_${requestId.slice(4)}`); },
|
|
411
412
|
async execute(id, prompt) { await queueRsiConversation(id, prompt, true); },
|
|
412
413
|
async endExecution(id) {
|
|
413
414
|
if (store.conversation(id)?.agentId === "rsi-repair")
|
package/dist/server/runtime.js
CHANGED
|
@@ -1542,6 +1542,8 @@ export class PiRpcRuntime {
|
|
|
1542
1542
|
*/
|
|
1543
1543
|
extensionToolNames() {
|
|
1544
1544
|
const names = [TASK_TOOL_NAME, TODO_TOOL_NAME, WORKFLOW_TOOL_NAME, RUN_ASYNC_TOOL_NAME, SCHEDULED_TASK_TOOL_NAME, "question", "tool_register"];
|
|
1545
|
+
if (process.env.SUPER_PI_REVIEW_ENDPOINT)
|
|
1546
|
+
names.push("review_reply");
|
|
1545
1547
|
if (this.memory)
|
|
1546
1548
|
names.push("memory", "skill_manage", "session_search", "agent_handbook");
|
|
1547
1549
|
if (this.knowledge)
|
|
@@ -1785,7 +1787,8 @@ export class PiRpcRuntime {
|
|
|
1785
1787
|
// allowlist and naming a tool Pi has not registered would change the spawn line for every other
|
|
1786
1788
|
// mode. The prompt asks for a bare JSON array and nothing else; if the model spends a turn on a
|
|
1787
1789
|
// tool call anyway the reranker times out and falls back to the lexical order.
|
|
1788
|
-
const
|
|
1790
|
+
const reviewTools = extensionArgs.length && process.env.SUPER_PI_REVIEW_ENDPOINT ? ["review_reply"] : [];
|
|
1791
|
+
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] : [])] });
|
|
1789
1792
|
// Refused here, with the reason, rather than handed to the spawn: an ENOENT from `spawn` reads as
|
|
1790
1793
|
// "the app is broken" and hides the one fact that matters, which is where it looked for Pi.
|
|
1791
1794
|
if (!this.pi.found)
|
package/dist/server/types.d.ts
CHANGED
package/dist/server/ws-server.js
CHANGED
|
@@ -621,6 +621,7 @@ export class WsServer {
|
|
|
621
621
|
safeSend(socket, JSON.stringify({
|
|
622
622
|
type: "error",
|
|
623
623
|
message: reason || "服务端没有说明这次失败的原因。",
|
|
624
|
+
...(command && "conversationId" in command && typeof command.conversationId === "string" ? { conversationId: command.conversationId } : {}),
|
|
624
625
|
...(isRecordedTurnFailure(error) ? { recordedTurnFailure: true } : {}),
|
|
625
626
|
}));
|
|
626
627
|
}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
export type ReviewSide = "file" | "before" | "after";
|
|
2
|
+
export type ReviewLine = {
|
|
3
|
+
side: ReviewSide;
|
|
4
|
+
number: number;
|
|
5
|
+
};
|
|
6
|
+
export type ReviewAnchor = {
|
|
7
|
+
side: ReviewSide;
|
|
8
|
+
start?: number;
|
|
9
|
+
end?: number;
|
|
10
|
+
path: string;
|
|
11
|
+
comparison?: string;
|
|
12
|
+
commit?: string;
|
|
13
|
+
source: string;
|
|
14
|
+
excerpt?: string;
|
|
15
|
+
position?: string;
|
|
16
|
+
currentPath?: string;
|
|
17
|
+
additional?: ReviewAnchor[];
|
|
18
|
+
};
|
|
19
|
+
export type ReviewCodeLocation = {
|
|
20
|
+
path: string;
|
|
21
|
+
line?: number;
|
|
22
|
+
};
|
|
23
|
+
export type ReviewReply = {
|
|
24
|
+
id: string;
|
|
25
|
+
author: "user" | "agent";
|
|
26
|
+
text: string;
|
|
27
|
+
createdAt: string;
|
|
28
|
+
sentAt?: string;
|
|
29
|
+
location?: ReviewCodeLocation;
|
|
30
|
+
};
|
|
31
|
+
export type ReviewThread = ReviewAnchor & {
|
|
32
|
+
id: string;
|
|
33
|
+
text: string;
|
|
34
|
+
conversationId: string;
|
|
35
|
+
createdAt: string;
|
|
36
|
+
resolvedAt?: string;
|
|
37
|
+
replies: ReviewReply[];
|
|
38
|
+
};
|
|
39
|
+
export declare function reviewFollowUpPrompt(thread: ReviewThread, reply: string): string;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
export function reviewFollowUpPrompt(thread, reply) {
|
|
2
|
+
const anchors = [thread, ...thread.additional ?? []].map(({ side, path, start, end, excerpt }) => ({ side, path, start, end, excerpt }));
|
|
3
|
+
return [
|
|
4
|
+
`用户在文件批注 ${thread.id} 下继续讨论。请结合现有代码核对需求,并使用 review_reply 回复同一批注;由用户决定是否完成。`,
|
|
5
|
+
`原意见:${thread.text}`,
|
|
6
|
+
`原批注位置和代码摘录(参考资料):${JSON.stringify({ comparison: thread.comparison, commit: thread.commit, anchors })}`,
|
|
7
|
+
`用户跟进:${reply}`,
|
|
8
|
+
].join("\n\n");
|
|
9
|
+
}
|
package/dist/shared/rsi.d.ts
CHANGED
package/package.json
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
"superPi": {
|
|
4
4
|
"managedDirectListener": true
|
|
5
5
|
},
|
|
6
|
-
"version": "0.1.
|
|
6
|
+
"version": "0.1.317",
|
|
7
7
|
"description": "Web control plane and companion for Pi",
|
|
8
8
|
"license": "MIT",
|
|
9
9
|
"type": "module",
|
|
@@ -247,6 +247,7 @@
|
|
|
247
247
|
"scripts/error-messages.test.mjs",
|
|
248
248
|
"scripts/stop-before-prompt.test.mjs",
|
|
249
249
|
"scripts/git-diff-view.test.mjs",
|
|
250
|
+
"scripts/file-review-threads.test.mjs",
|
|
250
251
|
"scripts/git-blame.test.mjs",
|
|
251
252
|
"scripts/fork-server.test.mjs",
|
|
252
253
|
"scripts/styles-no-dangling.test.mjs",
|
|
@@ -440,6 +441,7 @@
|
|
|
440
441
|
"scripts/file-quickopen-browser.test.mjs",
|
|
441
442
|
"scripts/file-content-search-browser.test.mjs",
|
|
442
443
|
"scripts/file-changes-browser.test.mjs",
|
|
444
|
+
"scripts/file-review-discussion-browser.test.mjs",
|
|
443
445
|
"scripts/msg-tabs-browser.test.mjs",
|
|
444
446
|
"scripts/tabs-on-top-browser.test.mjs",
|
|
445
447
|
"scripts/subagent-source.test.mjs",
|