@evandu/super-pi 0.1.310 → 0.1.312
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/rsi-discussion.md +2 -3
- package/agents/rsi-repair.md +1 -1
- package/dist/client/.super-pi-client-sources.json +29 -26
- package/dist/client/assets/{CodeMirrorEditor-BOnbuu1R.js → CodeMirrorEditor-CHzeo3AO.js} +1 -1
- package/dist/client/assets/{GitDiffEditor-CghIhA6m.js → GitDiffEditor-UbWgTpJv.js} +1 -1
- package/dist/client/assets/index-12mdWLr3.js +356 -0
- package/dist/client/assets/index-BcWXglOe.css +1 -0
- package/dist/client/index.html +2 -2
- package/dist/server/application/rsi-repairs.d.ts +1 -0
- package/dist/server/application/rsi-repairs.js +46 -15
- package/dist/server/application/rsi-service.d.ts +1 -1
- package/dist/server/application/rsi-service.js +8 -3
- package/dist/server/application/run-service.d.ts +4 -0
- package/dist/server/application/run-service.js +26 -1
- package/dist/server/index.js +10 -3
- package/dist/server/pi-session-events.d.ts +1 -0
- package/dist/server/pi-session-events.js +4 -1
- package/dist/server/rsi-evidence.d.ts +3 -0
- package/dist/server/rsi-evidence.js +11 -0
- package/dist/server/runtime.js +3 -2
- package/dist/server/store.js +2 -1
- package/dist/shared/rsi.d.ts +12 -1
- package/dist/shared/rsi.js +1 -0
- package/package.json +1 -1
- package/dist/client/assets/index-COa-CUVo.css +0 -1
- package/dist/client/assets/index-kGuSFdh8.js +0 -356
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-12mdWLr3.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-BcWXglOe.css">
|
|
14
14
|
</head>
|
|
15
15
|
<body>
|
|
16
16
|
<div id="root"></div>
|
|
17
17
|
|
|
@@ -5,6 +5,7 @@ export type RsiRepairHooks = {
|
|
|
5
5
|
discuss(source: RsiSource, title: string, prompt: string): Promise<string>;
|
|
6
6
|
send(conversationId: string, prompt: string): Promise<void>;
|
|
7
7
|
execute(conversationId: string, prompt: string): Promise<void>;
|
|
8
|
+
endExecution(conversationId: string): Promise<void>;
|
|
8
9
|
stop(conversationId: string): Promise<unknown>;
|
|
9
10
|
};
|
|
10
11
|
/** Discussion is read-only; only explicit UI approval can transition a plan to execution. */
|
|
@@ -2,7 +2,7 @@ import { randomUUID } from "node:crypto";
|
|
|
2
2
|
import { mkdir, readFile, rename, writeFile } from "node:fs/promises";
|
|
3
3
|
import { join } from "node:path";
|
|
4
4
|
import { rsiKey } from "../../shared/rsi.js";
|
|
5
|
-
import { rsiEvidence } from "../rsi-evidence.js";
|
|
5
|
+
import { rsiEvidence, rsiExecutionSteps } from "../rsi-evidence.js";
|
|
6
6
|
import { rsiFailure } from "./group-rsi.js";
|
|
7
7
|
const busy = (status) => ["queued", "running", "waiting", "awaiting_background"].includes(status ?? "");
|
|
8
8
|
/** Discussion is read-only; only explicit UI approval can transition a plan to execution. */
|
|
@@ -34,6 +34,7 @@ export class RsiRepairs {
|
|
|
34
34
|
if (store.conversation(job.conversationId)) {
|
|
35
35
|
try {
|
|
36
36
|
await hooks?.stop(job.conversationId);
|
|
37
|
+
await hooks?.endExecution(job.conversationId);
|
|
37
38
|
}
|
|
38
39
|
catch (error) {
|
|
39
40
|
job.error += ` 停止历史会话时遇到问题:${rsiFailure(error)}`;
|
|
@@ -71,13 +72,13 @@ export class RsiRepairs {
|
|
|
71
72
|
return this.jobs.filter(job => rsiKey(job.source) === rsiKey(source)).map(job => {
|
|
72
73
|
const conversation = this.store.conversation(job.conversationId);
|
|
73
74
|
// Legacy refresh payloads predate explicit internal-message tracking.
|
|
74
|
-
const messages = (conversation?.messages ?? []).filter(message => (message.role === "user" || message.role === "assistant") && message.id !== job.initialMessageId && !job.observationMessageIds?.includes(message.id)
|
|
75
|
+
const messages = (conversation?.messages ?? []).filter(message => (message.role === "user" || message.role === "assistant") && (message.id !== job.initialMessageId || !!job.initialPrompt) && !job.observationMessageIds?.includes(message.id)
|
|
75
76
|
&& !(message.role === "user" && message.content.startsWith("继续同一来源的综合 RSI 讨论。")));
|
|
76
77
|
const last = messages.at(-1);
|
|
77
78
|
return { ...structuredClone(job), model: conversation?.model, busy: busy(conversation?.status),
|
|
78
79
|
revision: last?.role === "assistant" && last.content.trim() ? last.id : undefined,
|
|
79
80
|
proposedPlan: last?.role === "assistant" ? last.content.slice(0, 16000) : undefined,
|
|
80
|
-
messages: messages.slice(-40).map(message => ({ id: message.id, actualModel: message.actualModel, role: message.role, content: message.id === job.executionMessageId ? `已授权实施:\n${job.approvedPlan}` : message.content.slice(0, 16000) })) };
|
|
81
|
+
messages: messages.slice(-40).map(message => ({ id: message.id, actualModel: message.actualModel, role: message.role, content: message.id === job.executionMessageId ? `已授权实施:\n${job.approvedPlan}` : message.id === job.initialMessageId && job.initialPrompt ? job.initialPrompt : message.content.slice(0, 16000), steps: rsiExecutionSteps(message.toolCalls) })) };
|
|
81
82
|
});
|
|
82
83
|
}
|
|
83
84
|
async action(source, body, report, context) {
|
|
@@ -88,16 +89,32 @@ export class RsiRepairs {
|
|
|
88
89
|
if (!workspace || workspace.closedAt && body.action !== "rsi.repair.cancel")
|
|
89
90
|
throw new Error("请选择已打开的有效工作区。");
|
|
90
91
|
if (body.action === "rsi.repair.discuss") {
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
92
|
+
const initialPrompt = typeof body.initialPrompt === "string" ? body.initialPrompt.trim() : "";
|
|
93
|
+
if (initialPrompt.length > 12000)
|
|
94
|
+
throw new Error("讨论开场内容不能超过 12000 字。");
|
|
95
|
+
if (!report && !initialPrompt)
|
|
96
|
+
throw new Error("请输入你希望 RSI 讨论和改进的问题。");
|
|
97
|
+
const finding = body.findingId === undefined ? undefined : report?.findings.find(item => item.id === body.findingId);
|
|
94
98
|
if (body.findingId !== undefined && !finding)
|
|
95
99
|
throw new Error("RSI 建议不存在。");
|
|
96
|
-
const existing = [...this.jobs].reverse().find(job => rsiKey(job.source) === rsiKey(source) && !this.store.conversation(job.conversationId)?.archivedAt && this.store.conversation(job.conversationId));
|
|
100
|
+
const existing = [...this.jobs].reverse().find(job => job.status !== "cancelled" && rsiKey(job.source) === rsiKey(source) && !this.store.conversation(job.conversationId)?.archivedAt && this.store.conversation(job.conversationId));
|
|
97
101
|
if (existing) {
|
|
98
|
-
if (busy(this.store.conversation(existing.conversationId)?.status) ||
|
|
99
|
-
|
|
100
|
-
if (existing.
|
|
102
|
+
if (busy(this.store.conversation(existing.conversationId)?.status) || existing.status === "implementing")
|
|
103
|
+
throw new Error("RSI 讨论仍在处理中,请等它回复后再继续。");
|
|
104
|
+
if (initialPrompt && existing.status !== "cancelled") {
|
|
105
|
+
existing.status = "discussing";
|
|
106
|
+
delete existing.error;
|
|
107
|
+
existing.updatedAt = new Date().toISOString();
|
|
108
|
+
await this.save();
|
|
109
|
+
await this.hooks.send(existing.conversationId, initialPrompt);
|
|
110
|
+
if (report) {
|
|
111
|
+
existing.observationSourceKey = report.sourceKey;
|
|
112
|
+
existing.reportId = report.id;
|
|
113
|
+
delete existing.findingId;
|
|
114
|
+
}
|
|
115
|
+
await this.save();
|
|
116
|
+
}
|
|
117
|
+
else if (report && (existing.observationSourceKey !== report.sourceKey || ["completed", "cancelled"].includes(existing.status))) {
|
|
101
118
|
existing.status = "discussing";
|
|
102
119
|
await this.save();
|
|
103
120
|
await this.hooks.send(existing.conversationId, `继续同一来源的综合 RSI 讨论。继承用户此前的意见和适用边界。本次没有实施授权,不扩展任何旧授权范围。以下是最新整体观察数据,请合并更新判断,避免逐点重复报告:\n${rsiEvidence(JSON.stringify({ report, context })).slice(0, 28000)}`);
|
|
@@ -112,10 +129,13 @@ export class RsiRepairs {
|
|
|
112
129
|
return;
|
|
113
130
|
}
|
|
114
131
|
const title = "RSI · 整体改进讨论";
|
|
115
|
-
const prompt =
|
|
132
|
+
const prompt = initialPrompt
|
|
133
|
+
? `${initialPrompt}${report ? `\n\n---\nRSI 当前观察摘要(仅作补充上下文,不覆盖用户问题):\n${rsiEvidence(JSON.stringify({ report, context })).slice(0, 24000)}` : ""}`
|
|
134
|
+
: `继续同一来源的综合 RSI 讨论。继承用户此前的意见和适用边界。本次没有实施授权,不扩展任何旧授权范围。以下是最新整体观察数据,请合并更新判断,避免逐点重复报告:\n${rsiEvidence(JSON.stringify({ report, context })).slice(0, 28000)}`;
|
|
116
135
|
const id = await this.hooks.discuss(source, title, prompt);
|
|
117
136
|
const now = new Date().toISOString();
|
|
118
|
-
this.jobs.push({ id: randomUUID(), source: { ...source }, reportId: report
|
|
137
|
+
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 } : {}) });
|
|
119
139
|
await this.save();
|
|
120
140
|
return;
|
|
121
141
|
}
|
|
@@ -139,6 +159,7 @@ export class RsiRepairs {
|
|
|
139
159
|
job.status = "cancelled";
|
|
140
160
|
job.updatedAt = new Date().toISOString();
|
|
141
161
|
await this.save();
|
|
162
|
+
await this.hooks.endExecution(job.conversationId);
|
|
142
163
|
return;
|
|
143
164
|
}
|
|
144
165
|
if (body.action === "rsi.repair.accept") {
|
|
@@ -196,7 +217,7 @@ export class RsiRepairs {
|
|
|
196
217
|
throw error;
|
|
197
218
|
}
|
|
198
219
|
try {
|
|
199
|
-
await this.hooks.execute(job.conversationId, `用户已通过 RSI
|
|
220
|
+
await this.hooks.execute(job.conversationId, `用户已通过 RSI 界面明确授权以下方案。现在开始实施:使用本轮提供的写入与命令工具修改并验证。历史中关于等待授权的回复只描述当时的状态。保留讨论中的约束,无需再次确认已批准的范围。范围有变时才停下。不得自行提交、推送、发布或修改 Super Pi npm 安装目录。完成后报告实际修改、验证结果和未完成部分。\n${plan}`);
|
|
200
221
|
job.executionMessageId = this.store.conversation(job.conversationId)?.messages.filter(message => message.role === "user").at(-1)?.id;
|
|
201
222
|
await this.save();
|
|
202
223
|
}
|
|
@@ -204,6 +225,7 @@ export class RsiRepairs {
|
|
|
204
225
|
job.status = "failed";
|
|
205
226
|
job.error = rsiFailure(error);
|
|
206
227
|
await this.save();
|
|
228
|
+
await this.hooks.endExecution(job.conversationId);
|
|
207
229
|
}
|
|
208
230
|
});
|
|
209
231
|
}
|
|
@@ -215,14 +237,23 @@ export class RsiRepairs {
|
|
|
215
237
|
const conversation = this.store.conversation(id);
|
|
216
238
|
if (!conversation || busy(conversation.status))
|
|
217
239
|
return;
|
|
240
|
+
const implementing = job.status === "implementing";
|
|
218
241
|
if (conversation.status === "failed" || conversation.status === "stopped") {
|
|
219
242
|
job.status = conversation.status === "failed" ? "failed" : "interrupted";
|
|
220
243
|
job.error = conversation.error || "执行已停止;请核对已完成的工作后继续讨论。";
|
|
221
244
|
}
|
|
222
|
-
else if (
|
|
223
|
-
|
|
245
|
+
else if (implementing) {
|
|
246
|
+
const start = conversation.messages.findIndex(message => message.id === job.executionMessageId);
|
|
247
|
+
const nextUser = conversation.messages.findIndex((message, index) => index > start && message.role === "user");
|
|
248
|
+
const acted = start >= 0 && conversation.messages.slice(start + 1, nextUser < 0 ? undefined : nextUser).some(message => message.role === "assistant" && message.toolCalls?.some(tool => tool.status === "ok" && !["read", "grep", "find", "ls", "tool_search"].includes(tool.label)));
|
|
249
|
+
job.status = acted ? "review" : "failed";
|
|
250
|
+
if (!acted)
|
|
251
|
+
job.error = "本轮未完成实施或验证。请查看 RSI 的回复,继续讨论后可以重新授权。";
|
|
252
|
+
}
|
|
224
253
|
job.updatedAt = new Date().toISOString();
|
|
225
254
|
await this.save();
|
|
255
|
+
if (implementing)
|
|
256
|
+
await this.hooks?.endExecution(id);
|
|
226
257
|
});
|
|
227
258
|
}
|
|
228
259
|
async close() { this.closed = true; await this.lane; }
|
|
@@ -9,7 +9,7 @@ type Hooks = {
|
|
|
9
9
|
stop(conversationId: string): Promise<unknown>;
|
|
10
10
|
repairs?: RsiRepairHooks;
|
|
11
11
|
};
|
|
12
|
-
/** Observations
|
|
12
|
+
/** Observations run independently; the sidebar owns the implementation view. */
|
|
13
13
|
export declare class RsiService {
|
|
14
14
|
private directory;
|
|
15
15
|
private store;
|
|
@@ -3,11 +3,11 @@ import { mkdir, readFile, writeFile, rename } from "node:fs/promises";
|
|
|
3
3
|
import { join } from "node:path";
|
|
4
4
|
import { rsiKey } from "../../shared/rsi.js";
|
|
5
5
|
import { defaultGroupRsi, updateUnifiedObservation, parseRsiReport, rsiInput, rsiSourceKey, RSI_INSTRUCTIONS, rsiFailure } from "./group-rsi.js";
|
|
6
|
-
import { rsiEvidence } from "../rsi-evidence.js";
|
|
6
|
+
import { rsiEvidence, rsiExecutionSteps } from "../rsi-evidence.js";
|
|
7
7
|
import { applicableRules, assertModelAllowed, resolveRsiModel } from "../model-filter.js";
|
|
8
8
|
import { resolveFileCwd } from "../session-cwd.js";
|
|
9
9
|
import { RsiRepairs } from "./rsi-repairs.js";
|
|
10
|
-
/** Observations
|
|
10
|
+
/** Observations run independently; the sidebar owns the implementation view. */
|
|
11
11
|
export class RsiService {
|
|
12
12
|
directory;
|
|
13
13
|
store;
|
|
@@ -118,7 +118,12 @@ export class RsiService {
|
|
|
118
118
|
const slugs = new Set(improvements.map(job => job.slug));
|
|
119
119
|
return { state: groupState ?? this.state(source), improvements: improvements.map(job => {
|
|
120
120
|
const conversation = job.conversationId ? this.store.conversation(job.conversationId) : undefined;
|
|
121
|
-
|
|
121
|
+
const messages = conversation?.messages.filter(message => message.role === "assistant") ?? [];
|
|
122
|
+
const last = messages.at(-1);
|
|
123
|
+
return { ...structuredClone(job), model: conversation?.model,
|
|
124
|
+
actualModel: messages.slice().reverse().find(message => message.actualModel)?.actualModel,
|
|
125
|
+
steps: rsiExecutionSteps(messages.slice(-8).flatMap(message => message.toolCalls ?? [])),
|
|
126
|
+
result: last?.content && rsiEvidence(last.content).slice(0, 6000) };
|
|
122
127
|
}), repairs: this.repairs.list(source),
|
|
123
128
|
capabilities: this.tools.list().filter(tool => slugs.has(tool.slug)).map(({ slug, name, kind, version, applicability }) => ({ slug, name, kind, version, applicability })),
|
|
124
129
|
usage: this.tools.receipts().filter(item => slugs.has(item.slug)).map(({ slug, version, status, durationMs, at }) => ({ slug, version, status, durationMs, at })) };
|
|
@@ -68,6 +68,10 @@ export declare class RunService {
|
|
|
68
68
|
private readonly extensionUiService;
|
|
69
69
|
private agentsDir;
|
|
70
70
|
private readonly workflows;
|
|
71
|
+
private readonly authorizedRsiMessages;
|
|
72
|
+
/** Bind temporary implementation tools to the server-created message that carries the approved plan. */
|
|
73
|
+
enqueueAuthorizedRsiRepair(conversationId: string, prompt: string, onAccepted: () => void): Promise<void>;
|
|
74
|
+
private rsiTurnAgent;
|
|
71
75
|
private readonly modelObservers;
|
|
72
76
|
observeModel(conversationId: string, observer: (model: ModelSelection) => void | Promise<void>): () => void;
|
|
73
77
|
private readonly executionObservers;
|
|
@@ -147,6 +147,26 @@ export class RunService {
|
|
|
147
147
|
extensionUiService;
|
|
148
148
|
agentsDir;
|
|
149
149
|
workflows;
|
|
150
|
+
authorizedRsiMessages = new Map();
|
|
151
|
+
/** Bind temporary implementation tools to the server-created message that carries the approved plan. */
|
|
152
|
+
async enqueueAuthorizedRsiRepair(conversationId, prompt, onAccepted) {
|
|
153
|
+
if (this.authorizedRsiMessages.has(conversationId) || this.activeRuns.has(conversationId)) {
|
|
154
|
+
throw new Error("RSI 正在处理上一条消息,请稍后重试。");
|
|
155
|
+
}
|
|
156
|
+
const messageId = `message_${randomUUID()}`;
|
|
157
|
+
this.authorizedRsiMessages.set(conversationId, messageId);
|
|
158
|
+
try {
|
|
159
|
+
await this.enqueueAndRun(conversationId, prompt, undefined, undefined, messageId, "queue", onAccepted);
|
|
160
|
+
}
|
|
161
|
+
finally {
|
|
162
|
+
this.authorizedRsiMessages.delete(conversationId);
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
rsiTurnAgent(conversation, messageId) {
|
|
166
|
+
return this.authorizedRsiMessages.get(conversation.id) === messageId
|
|
167
|
+
? { ...conversation, agentId: "rsi-repair" }
|
|
168
|
+
: conversation;
|
|
169
|
+
}
|
|
150
170
|
modelObservers = new Map();
|
|
151
171
|
observeModel(conversationId, observer) {
|
|
152
172
|
const observers = this.modelObservers.get(conversationId) ?? new Set();
|
|
@@ -1114,7 +1134,7 @@ export class RunService {
|
|
|
1114
1134
|
const conversation = this.store.snapshot().conversations.find(item => item.id === conversationId);
|
|
1115
1135
|
if (!conversation)
|
|
1116
1136
|
throw new Error("找不到这个会话。");
|
|
1117
|
-
const agent = await this.runtime.agentFor?.(conversation);
|
|
1137
|
+
const agent = await this.runtime.agentFor?.(this.rsiTurnAgent(conversation, messageId));
|
|
1118
1138
|
const identity = agent ? { id: agent.id, name: agent.name } : { name: "Pi" };
|
|
1119
1139
|
const opened = await this.store.openTurnOnMessage(conversationId, messageId, identity);
|
|
1120
1140
|
this.broadcaster.broadcastState();
|
|
@@ -1134,6 +1154,7 @@ export class RunService {
|
|
|
1134
1154
|
* nothing above it - the user could not find what they had typed, while the agent quoted it back.
|
|
1135
1155
|
*/
|
|
1136
1156
|
async streamTurn(conversation, workspace, prompt, assistantMessage, controller, userMessageId, images, agentIdentity) {
|
|
1157
|
+
conversation = this.rsiTurnAgent(conversation, userMessageId);
|
|
1137
1158
|
const scope = { id: randomUUID(), controller, accepting: true };
|
|
1138
1159
|
this.turnEventScopes.set(conversation.id, scope);
|
|
1139
1160
|
const ownsScope = () => this.turnEventScopes.get(conversation.id) === scope
|
|
@@ -2478,6 +2499,8 @@ export class RunService {
|
|
|
2478
2499
|
// Already-sent Pi steers are FIFO. Put this row directly behind them, ahead of unclaimed rows.
|
|
2479
2500
|
await this.moveAheadOfUnclaimed(conversationId, messageId);
|
|
2480
2501
|
this.broadcaster.broadcastState();
|
|
2502
|
+
if (this.authorizedRsiMessages.has(conversationId))
|
|
2503
|
+
return;
|
|
2481
2504
|
if (!this.runtime.steer)
|
|
2482
2505
|
return;
|
|
2483
2506
|
// A running conversation may be in the tiny hand-off window after Pi ended but before this service
|
|
@@ -2509,6 +2532,8 @@ export class RunService {
|
|
|
2509
2532
|
*/
|
|
2510
2533
|
async steerWaitingMessageOnBusyRun(conversationId, messageId) {
|
|
2511
2534
|
const startWaiting = await this.serializeConversation(conversationId, async () => {
|
|
2535
|
+
if (this.authorizedRsiMessages.has(conversationId))
|
|
2536
|
+
return false;
|
|
2512
2537
|
if (this.shuttingDown || this.interruptTargets.has(conversationId)) {
|
|
2513
2538
|
if (!this.shuttingDown) {
|
|
2514
2539
|
await this.moveAheadOfUnclaimed(conversationId, messageId);
|
package/dist/server/index.js
CHANGED
|
@@ -366,10 +366,13 @@ const groupChatService = await GroupChatService.open(join(dataDir, "group-chats.
|
|
|
366
366
|
const { groupPrimaryExecutor, groupPrimaryLifecycle } = await import("./group-primary-executor.js");
|
|
367
367
|
runtime.setGroupMemberExecutor?.(groupPrimaryExecutor(store, runService, uploadsDir), groupPrimaryLifecycle(store, runService, id => runtime.disposeSessions?.(id) ?? Promise.resolve(), join(dataDir, "pi-sessions"), () => broadcaster.broadcastState()));
|
|
368
368
|
const userTools = await UserTools.open(join(dataDir, "user-capabilities"));
|
|
369
|
-
async function queueRsiConversation(id, prompt) {
|
|
369
|
+
async function queueRsiConversation(id, prompt, authorized = false) {
|
|
370
370
|
await new Promise((resolve, reject) => {
|
|
371
371
|
let accepted = false;
|
|
372
|
-
|
|
372
|
+
const acknowledge = () => { accepted = true; resolve(); };
|
|
373
|
+
const work = authorized ? runService.enqueueAuthorizedRsiRepair(id, prompt, acknowledge)
|
|
374
|
+
: runService.enqueueAndRun(id, prompt, undefined, undefined, crypto.randomUUID(), "queue", acknowledge);
|
|
375
|
+
void work.catch(async (error) => {
|
|
373
376
|
if (!accepted)
|
|
374
377
|
reject(error);
|
|
375
378
|
else {
|
|
@@ -405,7 +408,11 @@ const rsiService = await RsiService.open(join(dataDir, "rsi"), store, runtime, u
|
|
|
405
408
|
return id;
|
|
406
409
|
},
|
|
407
410
|
async send(id, prompt) { await store.setConversationAgent(id, "rsi-discussion"); await queueRsiConversation(id, prompt); },
|
|
408
|
-
async execute(id, prompt) { await
|
|
411
|
+
async execute(id, prompt) { await queueRsiConversation(id, prompt, true); },
|
|
412
|
+
async endExecution(id) {
|
|
413
|
+
if (store.conversation(id)?.agentId === "rsi-repair")
|
|
414
|
+
await store.setConversationAgent(id, "rsi-discussion");
|
|
415
|
+
},
|
|
409
416
|
stop: id => runService.stopRun(id),
|
|
410
417
|
},
|
|
411
418
|
async start(source, title, prompt, signal) {
|
|
@@ -65,6 +65,7 @@ export type TurnItem =
|
|
|
65
65
|
};
|
|
66
66
|
/** The callbacks a turn supplies. The names match the RPC runtime's, so the two paths behave alike. */
|
|
67
67
|
export interface TurnEventHandlers {
|
|
68
|
+
includeRsiToolOutput?: boolean;
|
|
68
69
|
onCompaction?(event: ContextCompactionEvent): void;
|
|
69
70
|
onToolCall?(call: ToolCallNotice): void;
|
|
70
71
|
/**
|
|
@@ -16,10 +16,11 @@
|
|
|
16
16
|
* be announced as unhandled is still announced as unhandled - this bridge changes WHERE the events come
|
|
17
17
|
* from, not what they mean.
|
|
18
18
|
*/
|
|
19
|
-
import { describeToolCall, describeToolCallArgs, extractPartialResultText, readQuestionCall } from "./tool-calls.js";
|
|
19
|
+
import { describeToolCall, describeToolCallArgs, extractPartialResultText, extractToolResultText, readQuestionCall } from "./tool-calls.js";
|
|
20
20
|
import { toolTargetPath } from "./file-changes.js";
|
|
21
21
|
import { LengthExceededError, isProviderQuotaError } from "./turn-failure.js";
|
|
22
22
|
import { readCompactionEvent } from "../shared/context-compaction.js";
|
|
23
|
+
import { rsiEvidence } from "./rsi-evidence.js";
|
|
23
24
|
/** Keeps only real strings, so a malformed queue snapshot cannot put objects into a broadcast. */
|
|
24
25
|
const textList = (value) => Array.isArray(value) ? value.filter((item) => typeof item === "string") : undefined;
|
|
25
26
|
/**
|
|
@@ -312,11 +313,13 @@ export function handleSessionEvent(event, queue, handlers, report, failure) {
|
|
|
312
313
|
if (!id)
|
|
313
314
|
return true;
|
|
314
315
|
const name = record.toolName ?? "unknown";
|
|
316
|
+
const result = handlers.includeRsiToolOutput ? extractToolResultText(record.result) : undefined;
|
|
315
317
|
try {
|
|
316
318
|
handlers.onToolEnd?.({
|
|
317
319
|
id,
|
|
318
320
|
name,
|
|
319
321
|
status: record.isError === true ? "error" : "ok",
|
|
322
|
+
...(result ? { result: { text: rsiEvidence(result.text).slice(0, 1500) } } : {}),
|
|
320
323
|
...(typeof record.durationMs === "number" && Number.isFinite(record.durationMs) ? { durationMs: Math.max(0, Math.round(record.durationMs)) } : {}),
|
|
321
324
|
});
|
|
322
325
|
}
|
|
@@ -1,2 +1,5 @@
|
|
|
1
|
+
import type { ToolCallBlock } from "./types.js";
|
|
2
|
+
import type { RsiExecutionStep } from "../shared/rsi.js";
|
|
3
|
+
export declare function rsiExecutionSteps(calls: ToolCallBlock[] | undefined): RsiExecutionStep[] | undefined;
|
|
1
4
|
/** Redact common credentials before copying task evidence into observer records or prompts. */
|
|
2
5
|
export declare function rsiEvidence(text: string): string;
|
|
@@ -1,3 +1,14 @@
|
|
|
1
|
+
export function rsiExecutionSteps(calls) {
|
|
2
|
+
return calls?.slice(-20).map(call => {
|
|
3
|
+
const output = call.result?.text ?? call.live;
|
|
4
|
+
return {
|
|
5
|
+
label: call.label,
|
|
6
|
+
detail: call.detail && rsiEvidence(call.detail).slice(0, 500),
|
|
7
|
+
output: output && rsiEvidence(output).slice(0, 1500),
|
|
8
|
+
status: call.status,
|
|
9
|
+
};
|
|
10
|
+
});
|
|
11
|
+
}
|
|
1
12
|
/** Redact common credentials before copying task evidence into observer records or prompts. */
|
|
2
13
|
export function rsiEvidence(text) {
|
|
3
14
|
return text.replace(/-----BEGIN [^-]*PRIVATE KEY-----[\s\S]*?-----END [^-]*PRIVATE KEY-----/g, "[private key omitted]")
|
package/dist/server/runtime.js
CHANGED
|
@@ -1044,7 +1044,7 @@ export class PiRpcRuntime {
|
|
|
1044
1044
|
// `tools: {"*": false, "read": true}` gets exactly the same tools here as it used to get on the
|
|
1045
1045
|
// command line - including the empty allowlist that means "this agent talks and does not act".
|
|
1046
1046
|
const selection = nativeToolPolicy(agent
|
|
1047
|
-
? toolSelection(agent.tools, { extraAllowedTools: this.extensionToolNames() })
|
|
1047
|
+
? toolSelection(agent.tools, { extraAllowedTools: agent.id === "rsi-discussion" ? [] : this.extensionToolNames() })
|
|
1048
1048
|
: {}, readNativeToolSettings(nativeToolSettingsPath(this.sessionDir)));
|
|
1049
1049
|
const systemPromptFile = agent ? await writeAgentPrompt(this.agents.promptDir, agent) : undefined;
|
|
1050
1050
|
return {
|
|
@@ -1130,6 +1130,7 @@ export class PiRpcRuntime {
|
|
|
1130
1130
|
let compactionActive = false;
|
|
1131
1131
|
let compactionReason = "threshold";
|
|
1132
1132
|
const handlers = {
|
|
1133
|
+
includeRsiToolOutput: conversation.agentId === "rsi-repair" || conversation.agentId === "rsi-builder",
|
|
1133
1134
|
onCompaction: deferred(async (event) => {
|
|
1134
1135
|
compactionActive = event.phase === "start";
|
|
1135
1136
|
compactionReason = event.reason;
|
|
@@ -1784,7 +1785,7 @@ export class PiRpcRuntime {
|
|
|
1784
1785
|
// allowlist and naming a tool Pi has not registered would change the spawn line for every other
|
|
1785
1786
|
// mode. The prompt asks for a bare JSON array and nothing else; if the model spends a turn on a
|
|
1786
1787
|
// tool call anyway the reranker times out and falls back to the lexical order.
|
|
1787
|
-
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", "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] : [])] });
|
|
1788
|
+
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" ? [] : [...(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] : [])] });
|
|
1788
1789
|
// Refused here, with the reason, rather than handed to the spawn: an ENOENT from `spawn` reads as
|
|
1789
1790
|
// "the app is broken" and hides the one fact that matters, which is where it looked for Pi.
|
|
1790
1791
|
if (!this.pi.found)
|
package/dist/server/store.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { SESSION_SEARCH_LIMIT } from "../shared/session-search.js";
|
|
2
|
+
import { isRsiInternalAgent } from "../shared/rsi.js";
|
|
2
3
|
import { rename } from "node:fs/promises";
|
|
3
4
|
import { JsonStateRepository, defaultJsonStatePath } from "./persistence/json-state-repository.js";
|
|
4
5
|
import { normalizeTodos } from "./task-tool.js";
|
|
@@ -1089,7 +1090,7 @@ export class Store {
|
|
|
1089
1090
|
searchConversationMessages(workspaceId, query) {
|
|
1090
1091
|
const literal = new RegExp(query.replace(/[.*+?^${}()|[\]\\]/g, "\\$&"), "iu");
|
|
1091
1092
|
const sessions = this.state.conversations
|
|
1092
|
-
.filter(item => item.workspaceId === workspaceId && !item.archivedAt && !item.warmSession)
|
|
1093
|
+
.filter(item => item.workspaceId === workspaceId && !item.archivedAt && !item.warmSession && !isRsiInternalAgent(item.agentId))
|
|
1093
1094
|
.sort((a, b) => b.updatedAt.localeCompare(a.updatedAt));
|
|
1094
1095
|
const hits = [];
|
|
1095
1096
|
for (const session of sessions) {
|
package/dist/shared/rsi.d.ts
CHANGED
|
@@ -4,10 +4,17 @@ export type RsiSource = {
|
|
|
4
4
|
id: string;
|
|
5
5
|
workspaceId: string;
|
|
6
6
|
};
|
|
7
|
+
export declare const isRsiInternalAgent: (agentId?: string) => agentId is "rsi-builder" | "rsi-discussion" | "rsi-repair";
|
|
8
|
+
export type RsiExecutionStep = {
|
|
9
|
+
label: string;
|
|
10
|
+
detail?: string;
|
|
11
|
+
output?: string;
|
|
12
|
+
status?: "ok" | "error";
|
|
13
|
+
};
|
|
7
14
|
export type RsiRepair = {
|
|
8
15
|
id: string;
|
|
9
16
|
source: RsiSource;
|
|
10
|
-
reportId
|
|
17
|
+
reportId?: string;
|
|
11
18
|
findingId?: string;
|
|
12
19
|
title: string;
|
|
13
20
|
conversationId: string;
|
|
@@ -21,6 +28,7 @@ export type RsiRepair = {
|
|
|
21
28
|
error?: string;
|
|
22
29
|
initialMessageId?: string;
|
|
23
30
|
executionMessageId?: string;
|
|
31
|
+
initialPrompt?: string;
|
|
24
32
|
observationMessageIds?: string[];
|
|
25
33
|
approvals?: {
|
|
26
34
|
at: string;
|
|
@@ -38,6 +46,7 @@ export type RsiRepairView = RsiRepair & {
|
|
|
38
46
|
role: "user" | "assistant";
|
|
39
47
|
content: string;
|
|
40
48
|
actualModel?: GroupModel;
|
|
49
|
+
steps?: RsiExecutionStep[];
|
|
41
50
|
}[];
|
|
42
51
|
};
|
|
43
52
|
export type RsiImprovement = {
|
|
@@ -65,6 +74,8 @@ export type RsiSnapshot = {
|
|
|
65
74
|
improvements: (RsiImprovement & {
|
|
66
75
|
model?: GroupModel;
|
|
67
76
|
actualModel?: GroupModel;
|
|
77
|
+
steps?: RsiExecutionStep[];
|
|
78
|
+
result?: string;
|
|
68
79
|
})[];
|
|
69
80
|
capabilities: {
|
|
70
81
|
slug: string;
|
package/dist/shared/rsi.js
CHANGED