@evandu/super-pi 0.1.241 → 0.1.243
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 +58 -0
- package/agents/code-designer.md +58 -0
- package/agents/document-organizer.md +42 -0
- package/agents/solution-designer.md +56 -0
- package/agents/super-pi-memory/index.ts +3 -2
- package/dist/client/.super-pi-client-sources.json +11 -6
- package/dist/client/assets/{CodeMirrorEditor-CiOKD-_q.js → CodeMirrorEditor-B7eDr7dY.js} +1 -1
- package/dist/client/assets/{GitDiffEditor-D5VMi7K-.js → GitDiffEditor-pYaHOM0Q.js} +1 -1
- package/dist/client/assets/index-CfAcuYba.css +1 -0
- package/dist/client/assets/{index-oUDSLOqG.js → index-D0Po7xmY.js} +54 -54
- package/dist/client/index.html +2 -2
- package/dist/server/active-memory.d.ts +37 -5
- package/dist/server/active-memory.js +191 -10
- package/dist/server/agents.d.ts +1 -1
- package/dist/server/agents.js +1 -1
- package/dist/server/application/group-chat-service.d.ts +55 -0
- package/dist/server/application/group-chat-service.js +624 -0
- package/dist/server/application/run-service.d.ts +1 -0
- package/dist/server/application/run-service.js +20 -1
- package/dist/server/engineering-learning.d.ts +30 -0
- package/dist/server/engineering-learning.js +106 -0
- package/dist/server/http-server.js +171 -91
- package/dist/server/index.js +5 -1
- package/dist/server/memory-recall.d.ts +16 -1
- package/dist/server/memory-recall.js +22 -8
- package/dist/server/memory.d.ts +10 -1
- package/dist/server/memory.js +11 -6
- package/dist/server/runtime.d.ts +12 -12
- package/dist/server/runtime.js +68 -11
- package/dist/server/server-context.d.ts +1 -0
- package/dist/server/update-status.d.ts +14 -0
- package/dist/server/update-status.js +69 -0
- package/dist/server/update.d.ts +0 -17
- package/dist/server/update.js +0 -26
- package/dist/shared/group-chat.d.ts +67 -0
- package/dist/shared/group-chat.js +1 -0
- package/dist/shared/update-status.d.ts +28 -0
- package/dist/shared/update-status.js +1 -0
- package/package.json +4 -1
- package/scripts/restart-server.mjs +9 -1
- package/dist/client/assets/index-CwH7sttH.css +0 -1
|
@@ -8,24 +8,38 @@ export const memoryTerms = (value) => {
|
|
|
8
8
|
const cjk = value.match(/[\p{Script=Han}]{2,}/gu) ?? [];
|
|
9
9
|
return [...new Set([...words, ...cjk.flatMap(word => Array.from({ length: word.length - 1 }, (_, i) => word.slice(i, i + 2)))])];
|
|
10
10
|
};
|
|
11
|
-
export function
|
|
11
|
+
export function experienceMode(value) {
|
|
12
|
+
const fast = /\b(?:quick[ -]fix|hotfix|lightweight)\b|快速(?:修复|迭代)|轻量|快修|最小改动/iu.test(value);
|
|
13
|
+
const rigorous = /\b(?:long[ -](?:lived|term)|rigorous|large[ -]project)\b|长期维护|大型?项目|严谨|规范设计|单测维护/iu.test(value);
|
|
14
|
+
return fast === rigorous ? undefined : fast ? "quick-fix" : "rigorous";
|
|
15
|
+
}
|
|
16
|
+
export function recallMemory(groups, query, budget, context) {
|
|
12
17
|
const words = memoryTerms(query).slice(0, 128);
|
|
18
|
+
const mode = experienceMode(query) ?? context?.mode;
|
|
13
19
|
const ranked = Object.entries(groups).flatMap(([target, entries]) => (entries ?? []).filter(entry => !entry.archivedAt).map(entry => {
|
|
14
|
-
const
|
|
20
|
+
const source = entry.experience;
|
|
21
|
+
const text = [entry.content, source?.applicability, source?.projectName, source?.workspaceName].filter(Boolean).join(" ").normalize("NFKC").toLocaleLowerCase();
|
|
15
22
|
const relevance = words.reduce((sum, word) => sum + (text.includes(word) ? 1 : 0), 0);
|
|
16
23
|
const priority = target === "user" ? 5 : target === "tree" ? 4 : target === "session" ? 3 : target === "role" ? 2 : 1;
|
|
17
|
-
|
|
18
|
-
|
|
24
|
+
const sourceMode = source && (experienceMode(source.applicability) ?? experienceMode(entry.content));
|
|
25
|
+
const fit = relevance && mode && sourceMode ? (mode === sourceMode ? 160 : -160) : 0;
|
|
26
|
+
const local = Boolean(source && context?.workspaceId === source.workspaceId);
|
|
27
|
+
const pinned = Boolean(entry.pinned && (!source || ((relevance > 0 || local || source.applicability === "用户明确要求跨项目遵守") && fit >= 0)));
|
|
28
|
+
return { target, entry, score: relevance * 100 + priority + fit + (local ? 10 : 0), relevance, pinned, local };
|
|
29
|
+
})).sort((a, b) => Number(b.pinned) - Number(a.pinned)
|
|
30
|
+
|| b.score - a.score || (b.entry.updatedAt ?? b.entry.createdAt).localeCompare(a.entry.updatedAt ?? a.entry.createdAt));
|
|
19
31
|
const selected = [];
|
|
20
32
|
const render = () => `${MEMORY_GUIDANCE}\n<persistent-memory-data>\n${JSON.stringify(selected)}\n</persistent-memory-data>`;
|
|
21
|
-
for (const { target, entry, relevance } of ranked) {
|
|
33
|
+
for (const { target, entry, relevance, pinned, local } of ranked) {
|
|
34
|
+
if (target === "experience" && !context?.browse && !local && !pinned && !relevance)
|
|
35
|
+
continue;
|
|
22
36
|
// Keep a small recent/core fallback; relevance determines access to the rest of the archive.
|
|
23
|
-
if (words.length && !relevance && !
|
|
37
|
+
if (words.length && !relevance && !pinned && (context?.browse || selected.length >= 4))
|
|
24
38
|
continue;
|
|
25
|
-
const item = { target, id: entry.id, content: target === "skills" ? entry.content.split("\n")[0] : entry.content, revision: entry.revision ?? 1, sourceConversationId: entry.conversationId, sourceMessageId: entry.sourceMessageId, pinned: !!entry.pinned };
|
|
39
|
+
const item = { target, id: entry.id, content: target === "skills" ? entry.content.split("\n")[0] : entry.content, revision: entry.revision ?? 1, sourceConversationId: entry.conversationId, sourceMessageId: entry.sourceMessageId, experience: entry.experience, pinned: !!entry.pinned };
|
|
26
40
|
selected.push(item);
|
|
27
41
|
if (memoryTokenCost(render()) > budget)
|
|
28
42
|
selected.pop();
|
|
29
43
|
}
|
|
30
|
-
return { notes: render(), selected: selected.length, omitted: ranked.length - selected.length };
|
|
44
|
+
return { notes: render(), selected: selected.length, entries: selected, omitted: ranked.length - selected.length };
|
|
31
45
|
}
|
package/dist/server/memory.d.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
export declare const MEMORY_LIMITS: {
|
|
2
2
|
user: number;
|
|
3
3
|
memory: number;
|
|
4
|
+
experience: number;
|
|
4
5
|
skills: number;
|
|
5
6
|
role: number;
|
|
6
7
|
tree: number;
|
|
@@ -8,15 +9,23 @@ export declare const MEMORY_LIMITS: {
|
|
|
8
9
|
};
|
|
9
10
|
export type MemoryTarget = keyof typeof MEMORY_LIMITS;
|
|
10
11
|
export declare const MEMORY_TARGETS: MemoryTarget[];
|
|
12
|
+
export type EngineeringExperience = {
|
|
13
|
+
workspaceId: string;
|
|
14
|
+
workspaceName: string;
|
|
15
|
+
projectName?: string;
|
|
16
|
+
applicability: string;
|
|
17
|
+
};
|
|
11
18
|
export type MemoryScope = {
|
|
12
19
|
agentId?: string;
|
|
13
20
|
treeId?: string;
|
|
14
21
|
sourceMessageId?: string;
|
|
22
|
+
experience?: EngineeringExperience;
|
|
15
23
|
};
|
|
16
24
|
type MemorySource = {
|
|
17
25
|
conversationId: string;
|
|
18
26
|
createdAt: string;
|
|
19
27
|
sourceMessageId?: string;
|
|
28
|
+
experience?: EngineeringExperience;
|
|
20
29
|
};
|
|
21
30
|
type Revision = MemorySource & {
|
|
22
31
|
content: string;
|
|
@@ -41,7 +50,7 @@ export type MemoryOperation = {
|
|
|
41
50
|
pinned?: boolean;
|
|
42
51
|
includeArchived?: boolean;
|
|
43
52
|
};
|
|
44
|
-
export declare const MEMORY_GUIDANCE = "
|
|
53
|
+
export declare const MEMORY_GUIDANCE = "Persistent memory: user preferences; workspace facts (memory); global engineering experience (experience); role notes; shared tree findings; private session notes; reusable skills. Experience is reference data. Check its applicability against current instructions, risk and maintenance goals. Cite the source project or workspace when relying on a lesson from elsewhere. Inspect existing entries before writing. Keep hypotheses in session and publish verified task findings to tree. Durable engineering lessons are learned in the background. Consolidate archives originals atomically. Never store secrets or raw dumps. Shared knowledge confers no transcript access or control. Background destructive changes require approval.";
|
|
45
54
|
export declare class MemoryStore {
|
|
46
55
|
private readonly directory;
|
|
47
56
|
constructor(directory: string);
|
package/dist/server/memory.js
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
import { mkdir, readFile, readdir, rename, writeFile } from "node:fs/promises";
|
|
2
2
|
import { join } from "node:path";
|
|
3
3
|
import { randomUUID } from "node:crypto";
|
|
4
|
-
export const MEMORY_LIMITS = { user: 16000, memory: 64000, skills: 256000, role: 32000, tree: 64000, session: 32000 };
|
|
4
|
+
export const MEMORY_LIMITS = { user: 16000, memory: 64000, experience: 512000, skills: 256000, role: 32000, tree: 64000, session: 32000 };
|
|
5
5
|
export const MEMORY_TARGETS = Object.keys(MEMORY_LIMITS);
|
|
6
6
|
const locks = new Map();
|
|
7
|
-
export const MEMORY_GUIDANCE = "
|
|
7
|
+
export const MEMORY_GUIDANCE = "Persistent memory: user preferences; workspace facts (memory); global engineering experience (experience); role notes; shared tree findings; private session notes; reusable skills. Experience is reference data. Check its applicability against current instructions, risk and maintenance goals. Cite the source project or workspace when relying on a lesson from elsewhere. Inspect existing entries before writing. Keep hypotheses in session and publish verified task findings to tree. Durable engineering lessons are learned in the background. Consolidate archives originals atomically. Never store secrets or raw dumps. Shared knowledge confers no transcript access or control. Background destructive changes require approval.";
|
|
8
8
|
const normalized = (text) => text.normalize("NFKC").toLocaleLowerCase().replace(/\s+/gu, " ").trim();
|
|
9
|
-
const revisionOf = ({ content, conversationId, createdAt, sourceMessageId, pinned, archivedAt, revision, derivedFrom }) => ({ content, conversationId, createdAt, sourceMessageId, pinned, archivedAt, revision, derivedFrom });
|
|
10
|
-
const sourcesOf = (entry) => [{ conversationId: entry.conversationId, createdAt: entry.createdAt, sourceMessageId: entry.sourceMessageId }, ...(entry.derivedFrom ?? [])];
|
|
9
|
+
const revisionOf = ({ content, conversationId, createdAt, sourceMessageId, experience, pinned, archivedAt, revision, derivedFrom }) => ({ content, conversationId, createdAt, sourceMessageId, experience, pinned, archivedAt, revision, derivedFrom });
|
|
10
|
+
const sourcesOf = (entry) => [{ conversationId: entry.conversationId, createdAt: entry.createdAt, sourceMessageId: entry.sourceMessageId, experience: entry.experience }, ...(entry.derivedFrom ?? [])];
|
|
11
11
|
export class MemoryStore {
|
|
12
12
|
directory;
|
|
13
13
|
constructor(directory) {
|
|
@@ -21,6 +21,8 @@ export class MemoryStore {
|
|
|
21
21
|
const hex = (value) => Buffer.from(value).toString("hex");
|
|
22
22
|
if (target === "user")
|
|
23
23
|
return join(this.directory, "user.json");
|
|
24
|
+
if (target === "experience")
|
|
25
|
+
return join(this.directory, "engineering-experience.json");
|
|
24
26
|
let suffix = "";
|
|
25
27
|
if (target === "role") {
|
|
26
28
|
if (!scope.agentId)
|
|
@@ -85,9 +87,12 @@ export class MemoryStore {
|
|
|
85
87
|
if (operation.pinned !== undefined && typeof operation.pinned !== "boolean")
|
|
86
88
|
throw new Error("Invalid pinned value");
|
|
87
89
|
const stamp = new Date().toISOString();
|
|
88
|
-
const
|
|
90
|
+
const experience = operation.target === "experience" ? scope.experience : undefined;
|
|
91
|
+
const fresh = () => ({ id: randomUUID(), content: content, conversationId, createdAt: stamp, sourceMessageId: scope.sourceMessageId, experience, revision: 1, ...(operation.pinned ? { pinned: true } : {}) });
|
|
89
92
|
if (operation.action === "add") {
|
|
90
|
-
if (entries.some(entry => !entry.archivedAt && normalized(entry.content) === normalized(content)
|
|
93
|
+
if (entries.some(entry => !entry.archivedAt && normalized(entry.content) === normalized(content)
|
|
94
|
+
&& entry.experience?.workspaceId === experience?.workspaceId && entry.experience?.projectName === experience?.projectName
|
|
95
|
+
&& normalized(entry.experience?.applicability ?? "") === normalized(experience?.applicability ?? "")))
|
|
91
96
|
return visible();
|
|
92
97
|
entries.push(fresh());
|
|
93
98
|
}
|
package/dist/server/runtime.d.ts
CHANGED
|
@@ -249,6 +249,16 @@ export type ForkOutcome = {
|
|
|
249
249
|
/** Entry lines copied, header excluded. */
|
|
250
250
|
entriesCopied: number;
|
|
251
251
|
};
|
|
252
|
+
export type IsolatedCompletionInput = {
|
|
253
|
+
prompt: string;
|
|
254
|
+
timeoutMs: number;
|
|
255
|
+
cwd: string;
|
|
256
|
+
signal?: AbortSignal;
|
|
257
|
+
model?: ModelSelection;
|
|
258
|
+
agent?: AgentDefinition;
|
|
259
|
+
onText?: (text: string) => void;
|
|
260
|
+
onToolStart?: () => void;
|
|
261
|
+
};
|
|
252
262
|
export interface AgentRuntime {
|
|
253
263
|
answer(input: AnswerInput): AsyncIterable<string>;
|
|
254
264
|
stop?(conversationId: string): Promise<void>;
|
|
@@ -332,12 +342,7 @@ export interface AgentRuntime {
|
|
|
332
342
|
* Absent on a runtime with no Pi behind it, which the caller reports as a refusal rather than
|
|
333
343
|
* pretending a model answered.
|
|
334
344
|
*/
|
|
335
|
-
askOnce?(input:
|
|
336
|
-
prompt: string;
|
|
337
|
-
timeoutMs: number;
|
|
338
|
-
cwd: string;
|
|
339
|
-
signal?: AbortSignal;
|
|
340
|
-
}): Promise<string>;
|
|
345
|
+
askOnce?(input: IsolatedCompletionInput): Promise<string>;
|
|
341
346
|
/**
|
|
342
347
|
* The agent a conversation runs as, read fresh from the agent directory. Absent on a runtime with
|
|
343
348
|
* no agents (the welcome runtime), where every conversation runs as Pi itself. Callers that need an
|
|
@@ -1187,12 +1192,7 @@ export declare class PiRpcRuntime implements AgentRuntime {
|
|
|
1187
1192
|
* A single completion for a mounted tool. See `AgentRuntime.askOnce` for why it is its own child,
|
|
1188
1193
|
* why nothing is attached but Pi, and why it picks no model.
|
|
1189
1194
|
*/
|
|
1190
|
-
askOnce(input:
|
|
1191
|
-
prompt: string;
|
|
1192
|
-
timeoutMs: number;
|
|
1193
|
-
cwd: string;
|
|
1194
|
-
signal?: AbortSignal;
|
|
1195
|
-
}): Promise<string>;
|
|
1195
|
+
askOnce(input: IsolatedCompletionInput): Promise<string>;
|
|
1196
1196
|
/**
|
|
1197
1197
|
* The live session for a conversation, if there is one.
|
|
1198
1198
|
*
|
package/dist/server/runtime.js
CHANGED
|
@@ -2501,31 +2501,73 @@ export class PiRpcRuntime {
|
|
|
2501
2501
|
async askOnce(input) {
|
|
2502
2502
|
if (!this.pi.found)
|
|
2503
2503
|
throw new Error(this.pi.reason);
|
|
2504
|
-
|
|
2505
|
-
|
|
2504
|
+
const args = ["--mode", "rpc", "--no-session", "--no-extensions", "--no-skills", "--no-prompt-templates"];
|
|
2505
|
+
if (input.agent && input.onToolStart) {
|
|
2506
|
+
const nativeTools = ["read", "bash", "powershell", "edit", "write", "grep", "find", "ls"];
|
|
2507
|
+
const selection = toolSelection(input.agent.tools);
|
|
2508
|
+
const allowed = nativeTools.filter(name => (selection.tools ?? nativeTools).includes(name) && !selection.excludeTools?.includes(name));
|
|
2509
|
+
args.push(...(allowed.length ? ["--tools", allowed.join(",")] : ["--no-tools"]));
|
|
2510
|
+
}
|
|
2511
|
+
else
|
|
2512
|
+
args.push("--no-tools", "--no-context-files");
|
|
2513
|
+
if (input.agent)
|
|
2514
|
+
args.push(input.agent.promptMode === "replace" ? "--system-prompt" : "--append-system-prompt", await writeAgentPrompt(this.agents.promptDir, input.agent));
|
|
2515
|
+
const proxyEnv = await readProviderProxyEnv(defaultAgentDir(), input.model?.provider);
|
|
2516
|
+
input.signal?.throwIfAborted();
|
|
2517
|
+
const child = spawn(shellQuote(this.pi.command), args.map(arg => shellQuote(arg)), {
|
|
2506
2518
|
cwd: resolve(input.cwd),
|
|
2507
|
-
env: { ...process.env, ...
|
|
2519
|
+
env: { ...process.env, ...proxyEnv },
|
|
2508
2520
|
stdio: ["pipe", "pipe", "pipe"],
|
|
2509
2521
|
shell: process.platform === "win32",
|
|
2522
|
+
detached: process.platform !== "win32",
|
|
2510
2523
|
});
|
|
2511
2524
|
const channel = new RpcChannel(child);
|
|
2512
2525
|
const deadline = Date.now() + input.timeoutMs;
|
|
2513
2526
|
try {
|
|
2527
|
+
if (input.model) {
|
|
2528
|
+
const response = await channel.request({ id: "isolated_model", type: "set_model", provider: input.model.provider, modelId: input.model.modelId }, Math.min(input.timeoutMs, 8_000));
|
|
2529
|
+
if (response.success !== true)
|
|
2530
|
+
throw new Error(response.error || "Pi 无法选择指定模型");
|
|
2531
|
+
}
|
|
2532
|
+
input.signal?.throwIfAborted();
|
|
2514
2533
|
channel.write({ id: "tool_llm", type: "prompt", message: input.prompt });
|
|
2515
2534
|
let settled = false, text = "";
|
|
2535
|
+
let failure;
|
|
2536
|
+
const splitter = new InlineThinkingSplitter();
|
|
2537
|
+
const append = (parts) => {
|
|
2538
|
+
const delta = parts.filter(part => part.kind === "text").map(part => part.text).join("");
|
|
2539
|
+
if (!delta)
|
|
2540
|
+
return;
|
|
2541
|
+
text += delta;
|
|
2542
|
+
input.onText?.(delta);
|
|
2543
|
+
};
|
|
2544
|
+
const noteOutcome = (message, reason) => {
|
|
2545
|
+
const stop = message?.stopReason ?? reason;
|
|
2546
|
+
if (stop)
|
|
2547
|
+
failure = ["error", "aborted", "length"].includes(stop) ? message?.errorMessage || `模型未完成回答(${stop})` : undefined;
|
|
2548
|
+
};
|
|
2516
2549
|
while (!settled && Date.now() < deadline) {
|
|
2517
2550
|
if (input.signal?.aborted)
|
|
2518
2551
|
throw new Error("已取消");
|
|
2519
2552
|
const record = await channel.next(100);
|
|
2520
2553
|
if (!record)
|
|
2521
2554
|
continue;
|
|
2522
|
-
if (record.type === "
|
|
2523
|
-
|
|
2555
|
+
if (record.type === "tool_execution_start")
|
|
2556
|
+
input.onToolStart?.();
|
|
2557
|
+
if (record.type === "message_update") {
|
|
2558
|
+
const event = record.assistantMessageEvent;
|
|
2559
|
+
if (event?.type === "text_delta")
|
|
2560
|
+
append(splitter.push(event.delta ?? ""));
|
|
2561
|
+
if (event?.type === "done" || event?.type === "error")
|
|
2562
|
+
noteOutcome(event.message, event.type === "error" ? "error" : event.reason);
|
|
2563
|
+
}
|
|
2564
|
+
if (record.type === "agent_end" && !record.willRetry && record.messages)
|
|
2565
|
+
noteOutcome([...record.messages].reverse().find(message => message.role === "assistant"));
|
|
2524
2566
|
if (record.type === "agent_settled")
|
|
2525
2567
|
settled = true;
|
|
2526
2568
|
if (record.type === "response" && record.id === "tool_llm" && record.success === false)
|
|
2527
2569
|
throw new Error(record.error ?? "Pi 拒绝了这次请求");
|
|
2528
|
-
if (child.exitCode !== null)
|
|
2570
|
+
if (!settled && child.exitCode !== null)
|
|
2529
2571
|
throw new Error("模型进程意外退出");
|
|
2530
2572
|
}
|
|
2531
2573
|
if (!settled)
|
|
@@ -2533,14 +2575,29 @@ export class PiRpcRuntime {
|
|
|
2533
2575
|
// THE MODEL'S OWN REASONING IS NOT THE TOOL'S OUTPUT. A model that thinks inside its answer
|
|
2534
2576
|
// would otherwise hand the caller a `<think>`-prefixed string, and the caller - a tool, a
|
|
2535
2577
|
// title, a card - would store the reasoning trace as its result.
|
|
2536
|
-
|
|
2537
|
-
if (
|
|
2578
|
+
append(splitter.flush());
|
|
2579
|
+
if (failure)
|
|
2580
|
+
throw new Error(failure);
|
|
2581
|
+
if (!text.trim())
|
|
2538
2582
|
throw new Error("模型没有返回任何内容");
|
|
2539
|
-
return
|
|
2583
|
+
return text;
|
|
2540
2584
|
}
|
|
2541
2585
|
finally {
|
|
2542
|
-
if (child.
|
|
2543
|
-
|
|
2586
|
+
if (child.pid !== undefined) {
|
|
2587
|
+
if (process.platform === "win32") {
|
|
2588
|
+
if (child.exitCode === null)
|
|
2589
|
+
await killTree(child.pid);
|
|
2590
|
+
}
|
|
2591
|
+
else {
|
|
2592
|
+
try {
|
|
2593
|
+
process.kill(-child.pid, "SIGKILL");
|
|
2594
|
+
}
|
|
2595
|
+
catch (error) {
|
|
2596
|
+
if (error.code !== "ESRCH")
|
|
2597
|
+
throw error;
|
|
2598
|
+
}
|
|
2599
|
+
}
|
|
2600
|
+
}
|
|
2544
2601
|
}
|
|
2545
2602
|
}
|
|
2546
2603
|
/**
|
|
@@ -75,6 +75,7 @@ export interface ServerContext {
|
|
|
75
75
|
sessionOrchestratorService?: import("./application/session-orchestrator-service.js").SessionOrchestratorService;
|
|
76
76
|
sessionReminderService?: import("./application/session-reminder-service.js").SessionReminderService;
|
|
77
77
|
projectService?: import("./application/project-service.js").ProjectService;
|
|
78
|
+
groupChatService?: import("./application/group-chat-service.js").GroupChatService;
|
|
78
79
|
execService: ExecService;
|
|
79
80
|
toolRegistry: ToolRegistry;
|
|
80
81
|
toolRunner: ToolRunner;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { type UpdateOperation, type UpdateStatus } from "../shared/update-status.js";
|
|
2
|
+
/** Keeps the last operation available to the service that comes up after a restart. */
|
|
3
|
+
export declare class UpdateTracker {
|
|
4
|
+
private readonly file;
|
|
5
|
+
private readonly root;
|
|
6
|
+
private operation;
|
|
7
|
+
constructor(file: string, root: string);
|
|
8
|
+
private save;
|
|
9
|
+
snapshot(): UpdateStatus;
|
|
10
|
+
begin(action: UpdateOperation["action"], targetVersion?: string): string;
|
|
11
|
+
private change;
|
|
12
|
+
restarting(id: string, targetVersion: string): void;
|
|
13
|
+
fail(id: string, step: "installing" | "restarting", message: string, code?: number): void;
|
|
14
|
+
}
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
import { randomUUID } from "node:crypto";
|
|
2
|
+
import { readFileSync, renameSync, writeFileSync } from "node:fs";
|
|
3
|
+
import { updateIsActive } from "../shared/update-status.js";
|
|
4
|
+
import { checkDiskVersion } from "./version.js";
|
|
5
|
+
/** Keeps the last operation available to the service that comes up after a restart. */
|
|
6
|
+
export class UpdateTracker {
|
|
7
|
+
file;
|
|
8
|
+
root;
|
|
9
|
+
operation = null;
|
|
10
|
+
constructor(file, root) {
|
|
11
|
+
this.file = file;
|
|
12
|
+
this.root = root;
|
|
13
|
+
try {
|
|
14
|
+
const value = JSON.parse(readFileSync(file, "utf8"));
|
|
15
|
+
if (value?.id && ["installing", "restarting", "completed", "failed"].includes(value.phase))
|
|
16
|
+
this.operation = value;
|
|
17
|
+
}
|
|
18
|
+
catch { /* A new service has no update history. */ }
|
|
19
|
+
const previous = this.operation;
|
|
20
|
+
if (!previous || !updateIsActive(previous))
|
|
21
|
+
return;
|
|
22
|
+
const versions = checkDiskVersion(this.root);
|
|
23
|
+
if (previous.phase === "restarting" && previous.targetVersion === versions.runningVersion && !versions.needsRestart) {
|
|
24
|
+
this.change(previous.id, { phase: "completed" });
|
|
25
|
+
}
|
|
26
|
+
else if (previous.phase === "restarting") {
|
|
27
|
+
this.fail(previous.id, "restarting", `服务已重新启动,当前运行 v${versions.runningVersion}。请核对已安装版本。`);
|
|
28
|
+
}
|
|
29
|
+
else
|
|
30
|
+
this.fail(previous.id, "installing", "上一次安装期间服务退出。请检查已安装版本后重试。");
|
|
31
|
+
}
|
|
32
|
+
save(operation) {
|
|
33
|
+
const temporary = `${this.file}.${process.pid}.tmp`;
|
|
34
|
+
writeFileSync(temporary, JSON.stringify(operation), { encoding: "utf8", mode: 0o600 });
|
|
35
|
+
renameSync(temporary, this.file);
|
|
36
|
+
}
|
|
37
|
+
snapshot() { return { ...checkDiskVersion(this.root), operation: this.operation }; }
|
|
38
|
+
begin(action, targetVersion) {
|
|
39
|
+
const { runningVersion } = checkDiskVersion(this.root);
|
|
40
|
+
const startedAt = new Date().toISOString();
|
|
41
|
+
const operation = { id: randomUUID(), action, phase: action === "update" ? "installing" : "restarting",
|
|
42
|
+
fromVersion: runningVersion, targetVersion, startedAt, changedAt: startedAt };
|
|
43
|
+
this.save(operation);
|
|
44
|
+
this.operation = operation;
|
|
45
|
+
return operation.id;
|
|
46
|
+
}
|
|
47
|
+
change(id, change) {
|
|
48
|
+
if (this.operation?.id !== id || !updateIsActive(this.operation))
|
|
49
|
+
return;
|
|
50
|
+
const operation = { ...this.operation, ...change, changedAt: new Date().toISOString() };
|
|
51
|
+
this.operation = operation;
|
|
52
|
+
try {
|
|
53
|
+
this.save(operation);
|
|
54
|
+
}
|
|
55
|
+
catch (error) {
|
|
56
|
+
console.warn("Super Pi: could not save update status:", error);
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
restarting(id, targetVersion) {
|
|
60
|
+
if (this.operation?.id !== id || this.operation.phase !== "installing")
|
|
61
|
+
return;
|
|
62
|
+
const operation = { ...this.operation, phase: "restarting", targetVersion, changedAt: new Date().toISOString() };
|
|
63
|
+
this.save(operation);
|
|
64
|
+
this.operation = operation;
|
|
65
|
+
}
|
|
66
|
+
fail(id, step, message, code) {
|
|
67
|
+
this.change(id, { phase: "failed", failure: { step, message, code } });
|
|
68
|
+
}
|
|
69
|
+
}
|
package/dist/server/update.d.ts
CHANGED
|
@@ -41,20 +41,3 @@ export declare function packageUpdateArgs(rootDir: string, version?: string, pla
|
|
|
41
41
|
export declare function claimUpdateSlot(): boolean;
|
|
42
42
|
/** Releases the update slot, so the next update can start. */
|
|
43
43
|
export declare function releaseUpdateSlot(): void;
|
|
44
|
-
/**
|
|
45
|
-
* Whether an update is running RIGHT NOW.
|
|
46
|
-
*
|
|
47
|
-
* The client used to keep its buttons disabled only for as long as its own request was in
|
|
48
|
-
* flight, which ended the moment the server answered 202 - while npm was still installing.
|
|
49
|
-
* The server knew the whole time (it holds the slot above), so it says so out loud and the
|
|
50
|
-
* client asks.
|
|
51
|
-
*/
|
|
52
|
-
export declare function isUpdateInFlight(): boolean;
|
|
53
|
-
/** Records the outcome of an update attempt. */
|
|
54
|
-
export declare function recordUpdateOutcome(ok: boolean, code?: number): void;
|
|
55
|
-
/** The most recent update outcome, or undefined when no update has run in this process. */
|
|
56
|
-
export declare function getLastUpdateOutcome(): {
|
|
57
|
-
ok: boolean;
|
|
58
|
-
code?: number;
|
|
59
|
-
at: string;
|
|
60
|
-
} | undefined;
|
package/dist/server/update.js
CHANGED
|
@@ -69,29 +69,3 @@ export function claimUpdateSlot() {
|
|
|
69
69
|
export function releaseUpdateSlot() {
|
|
70
70
|
updateInFlight = false;
|
|
71
71
|
}
|
|
72
|
-
/**
|
|
73
|
-
* Whether an update is running RIGHT NOW.
|
|
74
|
-
*
|
|
75
|
-
* The client used to keep its buttons disabled only for as long as its own request was in
|
|
76
|
-
* flight, which ended the moment the server answered 202 - while npm was still installing.
|
|
77
|
-
* The server knew the whole time (it holds the slot above), so it says so out loud and the
|
|
78
|
-
* client asks.
|
|
79
|
-
*/
|
|
80
|
-
export function isUpdateInFlight() {
|
|
81
|
-
return updateInFlight;
|
|
82
|
-
}
|
|
83
|
-
/**
|
|
84
|
-
* WHAT THE LAST UPDATE ACTUALLY DID.
|
|
85
|
-
*
|
|
86
|
-
* The outcome of the most recent update, so the client can tell the user what actually
|
|
87
|
-
* happened instead of showing a spinner forever.
|
|
88
|
-
*/
|
|
89
|
-
let lastUpdate;
|
|
90
|
-
/** Records the outcome of an update attempt. */
|
|
91
|
-
export function recordUpdateOutcome(ok, code) {
|
|
92
|
-
lastUpdate = { ok, code, at: new Date().toISOString() };
|
|
93
|
-
}
|
|
94
|
-
/** The most recent update outcome, or undefined when no update has run in this process. */
|
|
95
|
-
export function getLastUpdateOutcome() {
|
|
96
|
-
return lastUpdate;
|
|
97
|
-
}
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
export type GroupModel = {
|
|
2
|
+
provider: string;
|
|
3
|
+
modelId: string;
|
|
4
|
+
label: string;
|
|
5
|
+
};
|
|
6
|
+
export type GroupModerator = {
|
|
7
|
+
model?: GroupModel;
|
|
8
|
+
prompt: string;
|
|
9
|
+
};
|
|
10
|
+
export declare const DEFAULT_GROUP_MEMBER_IDS: readonly ["solution-designer", "code-designer", "code-auditor", "document-organizer"];
|
|
11
|
+
export type GroupMember = {
|
|
12
|
+
id: string;
|
|
13
|
+
name: string;
|
|
14
|
+
description: string;
|
|
15
|
+
};
|
|
16
|
+
export type GroupStatus = "queued" | "running" | "completed" | "failed" | "cancelled" | "interrupted";
|
|
17
|
+
type GroupPost = {
|
|
18
|
+
id: string;
|
|
19
|
+
content: string;
|
|
20
|
+
createdAt: string;
|
|
21
|
+
status: GroupStatus;
|
|
22
|
+
error?: string;
|
|
23
|
+
};
|
|
24
|
+
export type GroupFileReference = {
|
|
25
|
+
path: string;
|
|
26
|
+
excerpt: string;
|
|
27
|
+
};
|
|
28
|
+
export type GroupUserPost = GroupPost & {
|
|
29
|
+
role: "user";
|
|
30
|
+
memberIds: string[];
|
|
31
|
+
replyTo?: string;
|
|
32
|
+
clientId: string;
|
|
33
|
+
files?: GroupFileReference[];
|
|
34
|
+
memoryNotice?: string;
|
|
35
|
+
};
|
|
36
|
+
export type GroupReply = GroupPost & {
|
|
37
|
+
role: "assistant";
|
|
38
|
+
memberId: string;
|
|
39
|
+
memberName?: string;
|
|
40
|
+
topicId: string;
|
|
41
|
+
replyTo: string;
|
|
42
|
+
assignment?: string;
|
|
43
|
+
routeReason?: string;
|
|
44
|
+
background?: boolean;
|
|
45
|
+
settledAt?: string;
|
|
46
|
+
handoff?: {
|
|
47
|
+
memberId: string;
|
|
48
|
+
assignment: string;
|
|
49
|
+
};
|
|
50
|
+
};
|
|
51
|
+
export type GroupMessage = GroupUserPost | GroupReply;
|
|
52
|
+
export type GroupSummary = {
|
|
53
|
+
id: string;
|
|
54
|
+
workspaceId: string;
|
|
55
|
+
title: string;
|
|
56
|
+
updatedAt: string;
|
|
57
|
+
};
|
|
58
|
+
export type GroupRoom = GroupSummary & {
|
|
59
|
+
members: GroupMember[];
|
|
60
|
+
moderator: GroupModerator;
|
|
61
|
+
revision: number;
|
|
62
|
+
messages: GroupMessage[];
|
|
63
|
+
};
|
|
64
|
+
export type GroupSnapshot = Omit<GroupRoom, "revision"> & {
|
|
65
|
+
revision: string;
|
|
66
|
+
};
|
|
67
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export const DEFAULT_GROUP_MEMBER_IDS = ["solution-designer", "code-designer", "code-auditor", "document-organizer"];
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
export type UpdateVersions = {
|
|
2
|
+
runningVersion: string;
|
|
3
|
+
diskVersion: string;
|
|
4
|
+
needsRestart: boolean;
|
|
5
|
+
};
|
|
6
|
+
export type UpdatePhase = "installing" | "restarting" | "completed" | "failed";
|
|
7
|
+
export type UpdateOperation = {
|
|
8
|
+
id: string;
|
|
9
|
+
action: "update" | "restart";
|
|
10
|
+
phase: UpdatePhase;
|
|
11
|
+
fromVersion: string;
|
|
12
|
+
targetVersion?: string;
|
|
13
|
+
startedAt: string;
|
|
14
|
+
changedAt: string;
|
|
15
|
+
failure?: {
|
|
16
|
+
step: "installing" | "restarting";
|
|
17
|
+
message: string;
|
|
18
|
+
code?: number;
|
|
19
|
+
};
|
|
20
|
+
};
|
|
21
|
+
export type UpdateStatus = UpdateVersions & {
|
|
22
|
+
operation: UpdateOperation | null;
|
|
23
|
+
};
|
|
24
|
+
export type UpdateCheck = UpdateStatus & {
|
|
25
|
+
latestVersion?: string;
|
|
26
|
+
updateAvailable: boolean;
|
|
27
|
+
};
|
|
28
|
+
export declare const updateIsActive: (operation?: UpdateOperation | null) => boolean;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export const updateIsActive = (operation) => operation?.phase === "installing" || operation?.phase === "restarting";
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@evandu/super-pi",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.243",
|
|
4
4
|
"description": "Web control plane and companion for Pi",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"type": "module",
|
|
@@ -64,6 +64,7 @@
|
|
|
64
64
|
"scripts/stream-transport.test.mjs",
|
|
65
65
|
"scripts/remote-transport.test.mjs",
|
|
66
66
|
"scripts/browser-safe-port.test.mjs",
|
|
67
|
+
"scripts/server-ready.test.mjs",
|
|
67
68
|
"scripts/agent-order.test.mjs",
|
|
68
69
|
"scripts/agent-picker-order.test.mjs",
|
|
69
70
|
"scripts/inline-thinking.test.mjs",
|
|
@@ -175,6 +176,7 @@
|
|
|
175
176
|
"scripts/revert-session-file.test.mjs",
|
|
176
177
|
"scripts/revert-real-pi.test.mjs",
|
|
177
178
|
"scripts/bg-task.test.mjs",
|
|
179
|
+
"scripts/group-chat.test.mjs",
|
|
178
180
|
"scripts/todo-tool.test.mjs",
|
|
179
181
|
"scripts/tool-calls.test.mjs",
|
|
180
182
|
"scripts/files-api.test.mjs",
|
|
@@ -326,6 +328,7 @@
|
|
|
326
328
|
"scripts/md-render-browser.test.mjs",
|
|
327
329
|
"scripts/right-sidebar-browser.test.mjs",
|
|
328
330
|
"scripts/background-task-output-browser.test.mjs",
|
|
331
|
+
"scripts/group-chat-browser.test.mjs",
|
|
329
332
|
"scripts/rail-workspace-follows-session-browser.test.mjs",
|
|
330
333
|
"scripts/git-tab-browser.test.mjs",
|
|
331
334
|
"scripts/workspace-reopen-browser.test.mjs",
|
|
@@ -91,6 +91,14 @@ child.unref();
|
|
|
91
91
|
// the new server is LEFT RUNNING: a start that is merely slow will still come up, and a process
|
|
92
92
|
// that is stuck is worth more than no process at all.
|
|
93
93
|
const READINESS_BUDGET_MS = 120000;
|
|
94
|
-
|
|
94
|
+
const deadline = Date.now() + READINESS_BUDGET_MS;
|
|
95
|
+
while (Date.now() < deadline) {
|
|
96
|
+
try {
|
|
97
|
+
const response = await fetch(`http://127.0.0.1:${port}/api/health`, { signal: AbortSignal.timeout(2_000) });
|
|
98
|
+
const body = await response.json();
|
|
99
|
+
if (response.ok && body.status === "ok" && body.service === "super-pi") { console.log("Server ready: /api/health passed."); process.exit(0); }
|
|
100
|
+
} catch { /* The replacement is still starting. */ }
|
|
101
|
+
await waitMs(200);
|
|
102
|
+
}
|
|
95
103
|
console.error(`Server did not become reachable within ${READINESS_BUDGET_MS}ms. It is STILL RUNNING - do not kill it, a slow start still ends up serving. See ${logPath}:`); try { console.error(readFileSync(logPath, "utf8").slice(-8000)); } catch {}
|
|
96
104
|
process.exit(1);
|