@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
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { CODING_STANDARD_REQUEST } from "../active-memory.js";
|
|
1
2
|
import { SteerUnavailableError } from "../runtime.js";
|
|
2
3
|
import { checkSubagentDepth, parentDeniedTools, subagentRoster } from "../task-tool.js";
|
|
3
4
|
import { newSubagentRunId } from "../subagents.js";
|
|
@@ -148,6 +149,9 @@ export class RunService {
|
|
|
148
149
|
cancelledQuestionConversations = new Set();
|
|
149
150
|
memory;
|
|
150
151
|
setMemory(memory) { this.memory = memory; }
|
|
152
|
+
async recordCodingStandards(conversationId, messageId) {
|
|
153
|
+
return this.memory?.rememberCodingStandards(conversationId, messageId).catch(() => "平台未能保存代码规范,请检查主动记忆设置。");
|
|
154
|
+
}
|
|
151
155
|
/**
|
|
152
156
|
* WHAT THE AGENT CHANGED, and what each file looked like before.
|
|
153
157
|
*
|
|
@@ -1038,6 +1042,7 @@ export class RunService {
|
|
|
1038
1042
|
this.extensionUiService.cancelPendingUi(conversation.id, "expired", {});
|
|
1039
1043
|
const uiHost = this.extensionUiService.createHost(conversation.id);
|
|
1040
1044
|
let assistant = assistantMessage;
|
|
1045
|
+
let currentUserMessageId = userMessageId;
|
|
1041
1046
|
let closedOwnScope = false;
|
|
1042
1047
|
let toolCalls = [];
|
|
1043
1048
|
let pendingTools = Promise.resolve();
|
|
@@ -1515,6 +1520,14 @@ export class RunService {
|
|
|
1515
1520
|
return toolCalls;
|
|
1516
1521
|
if (!ownsScope())
|
|
1517
1522
|
return toolCalls;
|
|
1523
|
+
if (this.memory) {
|
|
1524
|
+
const checkpointed = this.store.conversation(conversation.id);
|
|
1525
|
+
if (checkpointed)
|
|
1526
|
+
this.memory.learnFromTurn(checkpointed, currentUserMessageId, previous.id);
|
|
1527
|
+
}
|
|
1528
|
+
currentUserMessageId = delivered.user.id;
|
|
1529
|
+
if (CODING_STANDARD_REQUEST.test(delivered.user.content))
|
|
1530
|
+
await this.recordCodingStandards(conversation.id, delivered.user.id);
|
|
1518
1531
|
const next = delivered.assistant;
|
|
1519
1532
|
this.broadcaster.broadcastState();
|
|
1520
1533
|
assistant = next;
|
|
@@ -1533,6 +1546,11 @@ export class RunService {
|
|
|
1533
1546
|
};
|
|
1534
1547
|
try {
|
|
1535
1548
|
runCwd = await resolveSessionCwd(workspace.path, conversation.cwd);
|
|
1549
|
+
if (this.memory && CODING_STANDARD_REQUEST.test(prompt) && !controller.signal.aborted) {
|
|
1550
|
+
const result = await this.recordCodingStandards(conversation.id, userMessageId);
|
|
1551
|
+
if (result)
|
|
1552
|
+
prompt += `\n\n[平台记忆操作结果] ${result}`;
|
|
1553
|
+
}
|
|
1536
1554
|
for await (const delta of this.runtime.answer({
|
|
1537
1555
|
conversation,
|
|
1538
1556
|
prompt,
|
|
@@ -1697,7 +1715,8 @@ export class RunService {
|
|
|
1697
1715
|
if (closedOwnScope && this.activeRuns.get(conversation.id) === controller && !controller.signal.aborted) {
|
|
1698
1716
|
const completed = this.store.snapshot().conversations.find(c => c.id === conversation.id);
|
|
1699
1717
|
if (completed)
|
|
1700
|
-
await this.memory?.completed(completed
|
|
1718
|
+
await this.memory?.completed(completed, { userMessageId: currentUserMessageId, assistantMessageId: assistant.id })
|
|
1719
|
+
.catch(error => console.warn("Super Pi memory scheduling failed:", error));
|
|
1701
1720
|
}
|
|
1702
1721
|
}
|
|
1703
1722
|
/**
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import type { Message } from "./types.js";
|
|
2
|
+
export declare const ENGINEERING_ROLE_IDS: Set<string>;
|
|
3
|
+
export declare const isEngineeringRole: (id: string | undefined) => boolean;
|
|
4
|
+
export declare const STANDARD_PREFIX = "\u4EE3\u7801\u89C4\u8303\uFF1A";
|
|
5
|
+
export declare const LESSON_PREFIX = "\u5DE5\u7A0B\u9A8C\u8BC1\u7ECF\u9A8C\uFF1A";
|
|
6
|
+
export declare const sensitiveMemoryText: (text: string) => boolean;
|
|
7
|
+
export declare function userProse(text: string): string;
|
|
8
|
+
export declare function isLearningCandidate(userText: string, engineeringRole: boolean): boolean;
|
|
9
|
+
type Check = {
|
|
10
|
+
id: string;
|
|
11
|
+
command: string;
|
|
12
|
+
output: string;
|
|
13
|
+
status: "ok" | "error";
|
|
14
|
+
};
|
|
15
|
+
export type RecoveryEvidence = {
|
|
16
|
+
failed: Check;
|
|
17
|
+
passed: Check;
|
|
18
|
+
};
|
|
19
|
+
export declare function recoveries(messages: Message[], finalAssistantId: string): RecoveryEvidence[];
|
|
20
|
+
export declare function learningResult(text: string, userText: string | undefined, evidence: RecoveryEvidence[]): {
|
|
21
|
+
standards: {
|
|
22
|
+
applicability?: string;
|
|
23
|
+
rule: string;
|
|
24
|
+
}[];
|
|
25
|
+
lesson: {
|
|
26
|
+
rule: string;
|
|
27
|
+
applicability: string;
|
|
28
|
+
} | undefined;
|
|
29
|
+
};
|
|
30
|
+
export {};
|
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
export const ENGINEERING_ROLE_IDS = new Set(["solution-designer", "code-designer", "code-auditor", "document-organizer"]);
|
|
2
|
+
const codingRoles = new Set([...ENGINEERING_ROLE_IDS, "coder", "planner", "reviewer", "project-leader", "verifier"]);
|
|
3
|
+
export const isEngineeringRole = (id) => id !== undefined && codingRoles.has(id);
|
|
4
|
+
export const STANDARD_PREFIX = "代码规范:";
|
|
5
|
+
export const LESSON_PREFIX = "工程验证经验:";
|
|
6
|
+
export const sensitiveMemoryText = (text) => /-----BEGIN [A-Z ]*PRIVATE KEY-----|authorization\s*:\s*bearer\s+\S+|(?:api[_-]?key|password|[a-z_]*token)\s*=\s*["']?[^\s"']{8,}/iu.test(text);
|
|
7
|
+
const privateExperienceText = (text) => sensitiveMemoryText(text)
|
|
8
|
+
|| /(?:\b[a-z]:[\\/]|\\\\[^\\\s]+\\|\/(?:home|Users|local-data|var|root|mnt|opt)\/|\b(?:https?|ssh):\/\/\S+|\b(?:sk-[A-Za-z0-9_-]{24,}|gh[pousr]_[A-Za-z0-9]{20,}))/iu.test(text);
|
|
9
|
+
const stableWording = /(?:以后|今后|下次|始终|一律|规范|约定|每次|别再|总是|不能再|长期|默认|always|never|from now on|going forward|convention)/iu;
|
|
10
|
+
const engineeringTopic = /(?:health|健康|代码|源码|接口|风格|验证|日志|测试|发布|工作区|文件|分支|目录|仓库|部署|刷新|行尾|crlf|bug|lint|test|build|repo|release|commit|style|naming)/iu;
|
|
11
|
+
const correctionWording = /(?:不要|不能|不应该|你这里|应该用|统一用|这里用|must|should use|do not|instead)/iu;
|
|
12
|
+
const temporaryWording = /(?:这一次|这次先|这次不用|本次先|临时|仅本次|暂时|现在先|先不用|for this (?:task|change|run)|for now|temporarily)/iu;
|
|
13
|
+
const globalWording = /(?:全局|所有(?:工作区|仓库|项目)|任何(?:工作区|仓库|项目)|跨(?:工作区|仓库|项目)|globally|across all (?:workspaces|repos|projects))/iu;
|
|
14
|
+
export function userProse(text) {
|
|
15
|
+
let fence;
|
|
16
|
+
return text.split(/\r?\n/u).filter(line => {
|
|
17
|
+
const marker = /^\s*(`{3,}|~{3,})(.*)$/u.exec(line);
|
|
18
|
+
if (marker) {
|
|
19
|
+
if (!fence)
|
|
20
|
+
fence = marker[1];
|
|
21
|
+
else if (marker[1].startsWith(fence) && !marker[2].trim())
|
|
22
|
+
fence = undefined;
|
|
23
|
+
return false;
|
|
24
|
+
}
|
|
25
|
+
return !fence && !/^\s*>/u.test(line);
|
|
26
|
+
}).join("\n");
|
|
27
|
+
}
|
|
28
|
+
export function isLearningCandidate(userText, engineeringRole) {
|
|
29
|
+
return Boolean(userText.trim()) && !sensitiveMemoryText(userText)
|
|
30
|
+
&& (engineeringRole || (engineeringTopic.test(userText) && (stableWording.test(userText) || correctionWording.test(userText))));
|
|
31
|
+
}
|
|
32
|
+
function checkEvidence(messageId, tool, index) {
|
|
33
|
+
const command = tool.detail?.trim() ?? "";
|
|
34
|
+
const output = tool.result?.text.trim() ?? "";
|
|
35
|
+
if (!/^(bash|powershell|shell|command)$/iu.test(tool.label) || !tool.status || !command || !output
|
|
36
|
+
|| sensitiveMemoryText(command) || sensitiveMemoryText(output))
|
|
37
|
+
return;
|
|
38
|
+
if (!/api\/health|healthcheck|server-ready|install-smoke|(?:\b(?:node --test|npm (?:run )?test|pytest|tsc|lint|typecheck|build)\b)/iu.test(command))
|
|
39
|
+
return;
|
|
40
|
+
if (tool.status === "ok") {
|
|
41
|
+
const healthResponse = /\b(?:curl|invoke-restmethod|invoke-webrequest|fetch|iwr)\b/iu.test(command)
|
|
42
|
+
&& /["']status["']\s*:\s*["']ok["']/iu.test(output) && /["']service["']\s*:\s*["']super-pi["']/iu.test(output);
|
|
43
|
+
const verifiedCompletion = /(?:node --test|npm (?:run )?test|pytest|tsc|lint|typecheck|build|install-smoke)/iu.test(command)
|
|
44
|
+
&& /(?:#\s*fail\s+0\b|(?:^|\s)\d+\s+passed\b|BUILD SUCCESS|INSTALL SMOKE PASSED)/imu.test(output);
|
|
45
|
+
if (!healthResponse && !verifiedCompletion)
|
|
46
|
+
return;
|
|
47
|
+
}
|
|
48
|
+
return { id: messageId + ":" + index, command: command.slice(0, 400), output: output.slice(-650), status: tool.status };
|
|
49
|
+
}
|
|
50
|
+
function verificationFamily(command) {
|
|
51
|
+
if (/install-smoke|server-ready/iu.test(command))
|
|
52
|
+
return command.replace(/\s+/gu, " ");
|
|
53
|
+
if (/api\/health/iu.test(command) && /\b(?:curl|invoke-restmethod|invoke-webrequest|fetch|iwr)\b/iu.test(command))
|
|
54
|
+
return "http-health";
|
|
55
|
+
return command.replace(/\s+/gu, " ");
|
|
56
|
+
}
|
|
57
|
+
export function recoveries(messages, finalAssistantId) {
|
|
58
|
+
const finalIndex = messages.findIndex(message => message.id === finalAssistantId && message.role === "assistant");
|
|
59
|
+
if (finalIndex < 0)
|
|
60
|
+
return [];
|
|
61
|
+
const stages = messages.slice(0, finalIndex + 1).filter(message => message.role === "assistant").slice(-3);
|
|
62
|
+
const recentFailures = new Map();
|
|
63
|
+
const confirmed = [];
|
|
64
|
+
for (const message of stages)
|
|
65
|
+
for (const [index, tool] of (message.toolCalls ?? []).entries()) {
|
|
66
|
+
const check = checkEvidence(message.id, tool, index);
|
|
67
|
+
if (!check)
|
|
68
|
+
continue;
|
|
69
|
+
const family = verificationFamily(check.command);
|
|
70
|
+
if (check.status === "error")
|
|
71
|
+
recentFailures.set(family, check);
|
|
72
|
+
else {
|
|
73
|
+
const failed = recentFailures.get(family);
|
|
74
|
+
if (failed && message.id === finalAssistantId)
|
|
75
|
+
confirmed.push({ failed, passed: check });
|
|
76
|
+
recentFailures.delete(family);
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
return confirmed.slice(-3);
|
|
80
|
+
}
|
|
81
|
+
export function learningResult(text, userText, evidence) {
|
|
82
|
+
const result = JSON.parse(text.trim().replace(/^```(?:json)?\s*|\s*```$/giu, ""));
|
|
83
|
+
const standards = [];
|
|
84
|
+
if (userText && Array.isArray(result?.standards))
|
|
85
|
+
for (const item of result.standards.slice(0, 4)) {
|
|
86
|
+
const quote = typeof item?.quote === "string" ? item.quote.trim() : "";
|
|
87
|
+
if (!quote || quote.length > 600 || !userText.includes(quote) || privateExperienceText(quote) || temporaryWording.test(quote))
|
|
88
|
+
continue;
|
|
89
|
+
const originalLine = userText.split(/\r?\n/u).find(line => line.includes(quote));
|
|
90
|
+
if (originalLine && temporaryWording.test(originalLine))
|
|
91
|
+
continue;
|
|
92
|
+
const condition = typeof item.conditionQuote === "string" ? item.conditionQuote.trim() : "";
|
|
93
|
+
const validCondition = condition && condition.length <= 240 && userText.includes(condition)
|
|
94
|
+
&& !privateExperienceText(condition) && !temporaryWording.test(condition);
|
|
95
|
+
const applicability = validCondition ? condition : globalWording.test(originalLine ?? quote) ? "用户明确要求跨项目遵守" : undefined;
|
|
96
|
+
standards.push({ applicability, rule: STANDARD_PREFIX + quote });
|
|
97
|
+
}
|
|
98
|
+
const suggestion = result?.lesson;
|
|
99
|
+
const pair = evidence.find(item => item.failed.id === suggestion?.failedId && item.passed.id === suggestion?.passedId);
|
|
100
|
+
const lesson = typeof suggestion?.text === "string" ? suggestion.text.trim() : "";
|
|
101
|
+
const condition = typeof suggestion?.applicability === "string" ? suggestion.applicability.trim() : "";
|
|
102
|
+
return { standards, lesson: pair && lesson && lesson.length <= 650 && !privateExperienceText(lesson) ? {
|
|
103
|
+
rule: LESSON_PREFIX + lesson + "\n实测来源:" + pair.failed.id + " → " + pair.passed.id,
|
|
104
|
+
applicability: condition && condition.length <= 240 && !privateExperienceText(condition) ? condition : "已有相同故障现象和验收条件的任务",
|
|
105
|
+
} : undefined };
|
|
106
|
+
}
|
|
@@ -12,7 +12,7 @@ import { basename, dirname, extname, join, relative, resolve } from "node:path";
|
|
|
12
12
|
import { describe as describeFilesError, FilesError, fileMeta, listDirectory, MAX_FILE_BYTES, readWorkspaceFile, resolveInsideRoot, toRelative, writeWorkspaceFile, } from "./files.js";
|
|
13
13
|
import { findUploadFile, MAX_UPLOAD_BODY_BYTES, saveUpload } from "./upload.js";
|
|
14
14
|
import { describeThrown } from "./failure-text.js";
|
|
15
|
-
import { checkDiskVersion } from "./version.js";
|
|
15
|
+
import { checkDiskVersion, readPackageVersion } from "./version.js";
|
|
16
16
|
import { gitBlame, gitBranches, gitCommit, gitCommitDiff, gitDiff, gitGraph, gitLog, gitMutate, gitStagedDraftInput, gitStashes, gitStatus, gitWorktrees, resolveGitWorktree, inspectGitWorktree, gitWorktreeCommittedDiff } from "./git.js";
|
|
17
17
|
import { computeFileDiff } from "./file-diff.js";
|
|
18
18
|
import { verifyCapability } from "./capability.js";
|
|
@@ -25,7 +25,9 @@ import { createWorktreeService } from "./application/worktree-service.js";
|
|
|
25
25
|
import { MAX_FEISHU_REQUEST_BYTES } from "./application/feishu-service.js";
|
|
26
26
|
import { MAX_WEB_REQUEST_BYTES } from "./web.js";
|
|
27
27
|
import { MAX_TOOL_BODY_BYTES } from "./tool-registry.js";
|
|
28
|
-
import { claimUpdateSlot,
|
|
28
|
+
import { claimUpdateSlot, packageUpdateArgs, releaseUpdateSlot, shellArgs } from "./update.js";
|
|
29
|
+
import { UpdateTracker } from "./update-status.js";
|
|
30
|
+
import { updateIsActive } from "../shared/update-status.js";
|
|
29
31
|
import { FileIndex, refreshWorkspaceIndex } from "./file-index.js";
|
|
30
32
|
import { ensureNameIndex, QUICK_OPEN_PAGE_SIZE, recordWorkspacePath } from "./file-name-index.js";
|
|
31
33
|
import { resolveFileCwd, sessionScopeKey, workspacePathFromSession } from "./session-cwd.js";
|
|
@@ -358,6 +360,15 @@ export function createHttpServer(options) {
|
|
|
358
360
|
const gitDrafts = new Set();
|
|
359
361
|
const manageWorktree = createWorktreeService(context);
|
|
360
362
|
const explicitFileOpen = createExplicitFileOpen();
|
|
363
|
+
let tracker;
|
|
364
|
+
const getUpdateTracker = () => tracker ??= new UpdateTracker(join(paths.dataDir ?? rootDir, "update-status.json"), rootDir);
|
|
365
|
+
const updateStatus = () => {
|
|
366
|
+
const status = getUpdateTracker().snapshot();
|
|
367
|
+
const operation = status.operation;
|
|
368
|
+
const lastUpdate = operation?.phase === "completed" || operation?.phase === "failed"
|
|
369
|
+
? { ok: operation.phase === "completed", code: operation.failure?.code, at: operation.changedAt } : null;
|
|
370
|
+
return { ...status, updating: updateIsActive(operation), lastUpdate };
|
|
371
|
+
};
|
|
361
372
|
return createServer(async (request, response) => {
|
|
362
373
|
// Every HTTP request gets one stable id. It is returned to the browser and
|
|
363
374
|
// included in the server log, so a report containing a status code or a
|
|
@@ -399,6 +410,56 @@ export function createHttpServer(options) {
|
|
|
399
410
|
const url = new URL(request.url ?? "/", `http://${request.headers.host ?? "localhost"}`);
|
|
400
411
|
const remote = request.socket.remoteAddress ?? "";
|
|
401
412
|
const json = (status, body) => { response.writeHead(status, { "content-type": "application/json; charset=utf-8", "cache-control": "no-store" }); response.end(JSON.stringify(body)); };
|
|
413
|
+
if (url.pathname === "/api/group-chats" && context.groupChatService) {
|
|
414
|
+
const groups = context.groupChatService;
|
|
415
|
+
const workspaceId = url.searchParams.get("workspaceId") ?? "";
|
|
416
|
+
const roomId = url.searchParams.get("id");
|
|
417
|
+
try {
|
|
418
|
+
if (request.method === "GET") {
|
|
419
|
+
if (!roomId) {
|
|
420
|
+
json(200, groups.list(workspaceId));
|
|
421
|
+
return;
|
|
422
|
+
}
|
|
423
|
+
const room = groups.get(workspaceId, roomId);
|
|
424
|
+
if (room.revision === url.searchParams.get("revision"))
|
|
425
|
+
response.writeHead(204, { "cache-control": "no-store" }).end();
|
|
426
|
+
else
|
|
427
|
+
json(200, room);
|
|
428
|
+
return;
|
|
429
|
+
}
|
|
430
|
+
if (request.method === "POST") {
|
|
431
|
+
const input = await readRequestText(request, 128_000);
|
|
432
|
+
if (input.tooLarge) {
|
|
433
|
+
json(413, { error: "群聊请求内容过大。" });
|
|
434
|
+
return;
|
|
435
|
+
}
|
|
436
|
+
const body = JSON.parse(input.text);
|
|
437
|
+
if (!roomId) {
|
|
438
|
+
json(201, await groups.create(workspaceId, body));
|
|
439
|
+
return;
|
|
440
|
+
}
|
|
441
|
+
if (body?.action === "send") {
|
|
442
|
+
json(202, await groups.send(workspaceId, roomId, body));
|
|
443
|
+
return;
|
|
444
|
+
}
|
|
445
|
+
if (body?.action === "configure") {
|
|
446
|
+
json(200, await groups.configure(workspaceId, roomId, body));
|
|
447
|
+
return;
|
|
448
|
+
}
|
|
449
|
+
if (body?.action === "stop" && typeof body.postId === "string") {
|
|
450
|
+
json(200, await groups.stop(workspaceId, roomId, body.postId));
|
|
451
|
+
return;
|
|
452
|
+
}
|
|
453
|
+
json(400, { error: "群聊操作无效。" });
|
|
454
|
+
return;
|
|
455
|
+
}
|
|
456
|
+
response.writeHead(405, { allow: "GET, POST" }).end();
|
|
457
|
+
}
|
|
458
|
+
catch (error) {
|
|
459
|
+
json(400, { error: describeThrown(error) || "群聊操作失败。" });
|
|
460
|
+
}
|
|
461
|
+
return;
|
|
462
|
+
}
|
|
402
463
|
if (url.pathname === "/api/tools/export") {
|
|
403
464
|
// NOT EXEMPT FROM THE TOKEN CHECK ABOVE, and that is deliberate: an export hands out a tool's
|
|
404
465
|
// whole source, so it is a management read exactly like GET and DELETE, not a capability call.
|
|
@@ -1112,127 +1173,146 @@ export function createHttpServer(options) {
|
|
|
1112
1173
|
}
|
|
1113
1174
|
if (url.pathname === "/api/update" && request.method === "POST") {
|
|
1114
1175
|
if (!isLocalOrPrivateAddress(remote)) {
|
|
1115
|
-
|
|
1176
|
+
json(403, { error: "只允许从本机或局域网更新服务。" });
|
|
1116
1177
|
return;
|
|
1117
1178
|
}
|
|
1118
|
-
// THE BODY IS OPTIONAL. An old client sends nothing; that still has to work.
|
|
1119
1179
|
let body = {};
|
|
1120
1180
|
try {
|
|
1121
|
-
const
|
|
1122
|
-
|
|
1123
|
-
|
|
1124
|
-
|
|
1125
|
-
raw = reader.push(piece);
|
|
1126
|
-
if (raw.length > 4096)
|
|
1127
|
-
break;
|
|
1181
|
+
const input = await readRequestText(request, 4096);
|
|
1182
|
+
if (input.tooLarge) {
|
|
1183
|
+
json(413, { error: "更新请求过大。" });
|
|
1184
|
+
return;
|
|
1128
1185
|
}
|
|
1129
|
-
|
|
1130
|
-
body = raw.trim() ? JSON.parse(raw) : {};
|
|
1186
|
+
body = input.text.trim() ? JSON.parse(input.text) : {};
|
|
1131
1187
|
}
|
|
1132
1188
|
catch {
|
|
1133
|
-
|
|
1189
|
+
json(400, { error: "更新请求格式无效。" });
|
|
1190
|
+
return;
|
|
1134
1191
|
}
|
|
1135
1192
|
const wantedVersion = typeof body?.version === "string" && body.version ? body.version : undefined;
|
|
1136
1193
|
const restartOnly = body?.restartOnly === true;
|
|
1137
|
-
|
|
1138
|
-
|
|
1139
|
-
|
|
1140
|
-
|
|
1194
|
+
if (wantedVersion && (wantedVersion.length > 128 || !/^\d+\.\d+\.\d+(?:-[a-z0-9.-]+)?(?:\+[a-z0-9.-]+)?$/iu.test(wantedVersion))) {
|
|
1195
|
+
json(400, { error: "目标版本格式无效。" });
|
|
1196
|
+
return;
|
|
1197
|
+
}
|
|
1141
1198
|
if (!claimUpdateSlot()) {
|
|
1142
|
-
|
|
1143
|
-
|
|
1144
|
-
|
|
1145
|
-
|
|
1146
|
-
|
|
1147
|
-
|
|
1148
|
-
|
|
1149
|
-
|
|
1150
|
-
|
|
1151
|
-
|
|
1152
|
-
|
|
1153
|
-
|
|
1154
|
-
|
|
1155
|
-
|
|
1156
|
-
|
|
1199
|
+
const current = updateStatus();
|
|
1200
|
+
const error = current.operation?.phase === "restarting" ? "服务正在重启,请等它结束。" : "更新已经在进行中,请等它结束。";
|
|
1201
|
+
json(409, { ...current, error });
|
|
1202
|
+
return;
|
|
1203
|
+
}
|
|
1204
|
+
const updateTracker = getUpdateTracker();
|
|
1205
|
+
let id;
|
|
1206
|
+
try {
|
|
1207
|
+
id = updateTracker.begin(restartOnly ? "restart" : "update", restartOnly ? checkDiskVersion(rootDir).diskVersion : wantedVersion);
|
|
1208
|
+
}
|
|
1209
|
+
catch (error) {
|
|
1210
|
+
releaseUpdateSlot();
|
|
1211
|
+
console.error("Super Pi: could not start update:", error);
|
|
1212
|
+
json(500, { error: "无法保存更新记录,请检查服务数据目录。" });
|
|
1213
|
+
return;
|
|
1214
|
+
}
|
|
1215
|
+
json(202, { ...updateStatus(), status: "updating" });
|
|
1216
|
+
let failed = false;
|
|
1217
|
+
const fail = (step, message, code) => {
|
|
1218
|
+
if (failed)
|
|
1219
|
+
return;
|
|
1220
|
+
failed = true;
|
|
1221
|
+
updateTracker.fail(id, step, message, code);
|
|
1222
|
+
releaseUpdateSlot();
|
|
1223
|
+
console.error(`Super Pi: ${message}`);
|
|
1224
|
+
};
|
|
1157
1225
|
const listenPort = port ?? request.socket.localPort;
|
|
1158
|
-
const restartEnv = { ...process.env, SUPER_PI_PORT: String(listenPort) };
|
|
1226
|
+
const restartEnv = { ...process.env, SUPER_PI_DATA_DIR: paths.dataDir, SUPER_PI_PORT: String(listenPort) };
|
|
1159
1227
|
if (host)
|
|
1160
1228
|
restartEnv.SUPER_PI_HOST = host;
|
|
1161
1229
|
const restartNow = () => {
|
|
1162
|
-
|
|
1163
|
-
|
|
1164
|
-
|
|
1165
|
-
|
|
1166
|
-
|
|
1167
|
-
|
|
1168
|
-
|
|
1169
|
-
|
|
1230
|
+
const deadline = setTimeout(() => fail("restarting", "等待新服务上线超时,请查看服务日志后重试。"), 150_000);
|
|
1231
|
+
deadline.unref();
|
|
1232
|
+
try {
|
|
1233
|
+
const restart = spawn(process.execPath, [join(rootDir, "scripts", "restart-server.mjs")], { cwd: rootDir, detached: true, stdio: "inherit", env: restartEnv });
|
|
1234
|
+
restart.once("error", () => { clearTimeout(deadline); fail("restarting", "无法启动重启程序,请查看服务日志后重试。"); });
|
|
1235
|
+
restart.once("exit", (code) => {
|
|
1236
|
+
if (code !== 0) {
|
|
1237
|
+
clearTimeout(deadline);
|
|
1238
|
+
fail("restarting", "重启程序未能让服务重新上线,请查看服务日志。", code ?? undefined);
|
|
1239
|
+
}
|
|
1240
|
+
});
|
|
1241
|
+
restart.unref();
|
|
1242
|
+
}
|
|
1243
|
+
catch {
|
|
1244
|
+
clearTimeout(deadline);
|
|
1245
|
+
fail("restarting", "无法启动重启程序,请查看服务日志后重试。");
|
|
1246
|
+
}
|
|
1170
1247
|
};
|
|
1171
|
-
// RESTART ONLY: the code on disk is already new, the running server is not. Re-downloading
|
|
1172
|
-
// 32.8 MB to restart a process is waste; the second button asks for exactly this.
|
|
1173
|
-
// The outcome is recorded here as well: from the client's point of view a restart is the
|
|
1174
|
-
// end of the update it started, and it needs to be able to say so.
|
|
1175
1248
|
if (restartOnly) {
|
|
1176
|
-
recordUpdateOutcome(true);
|
|
1177
|
-
release();
|
|
1178
1249
|
restartNow();
|
|
1179
1250
|
return;
|
|
1180
1251
|
}
|
|
1181
|
-
// Use npm directly instead of `pi update` to avoid Windows detached+shell exit timing issues.
|
|
1182
|
-
// npm's exit code correctly reflects whether the update succeeded.
|
|
1183
1252
|
const npmCmd = process.platform === "win32" ? "npm.cmd" : "npm";
|
|
1184
1253
|
const update = packageUpdateArgs(rootDir, wantedVersion);
|
|
1185
|
-
|
|
1186
|
-
|
|
1187
|
-
|
|
1188
|
-
|
|
1189
|
-
|
|
1190
|
-
|
|
1191
|
-
|
|
1192
|
-
|
|
1193
|
-
|
|
1194
|
-
|
|
1195
|
-
|
|
1196
|
-
|
|
1197
|
-
|
|
1254
|
+
try {
|
|
1255
|
+
const child = spawn(npmCmd, shellArgs(update.args), { stdio: ["ignore", "ignore", "pipe"], shell: process.platform === "win32", env: process.env });
|
|
1256
|
+
let stderr = "";
|
|
1257
|
+
child.stderr?.on("data", (chunk) => { stderr = (stderr + chunk.toString()).slice(-4096); });
|
|
1258
|
+
child.once("error", () => fail("installing", "无法启动 npm 安装程序,请检查服务日志。"));
|
|
1259
|
+
child.once("close", (code) => {
|
|
1260
|
+
if (failed)
|
|
1261
|
+
return;
|
|
1262
|
+
if (code !== 0) {
|
|
1263
|
+
const npmCode = /\bnpm\s+(?:ERR!|error)\s+code\s+([A-Z][A-Z0-9_]{1,30})\b/u.exec(stderr)?.[1];
|
|
1264
|
+
const detail = [npmCode, code === null ? "进程已中断" : `退出码 ${code}`].filter(Boolean).join(",");
|
|
1265
|
+
fail("installing", `安装更新失败(${detail})。`, code ?? undefined);
|
|
1266
|
+
return;
|
|
1267
|
+
}
|
|
1268
|
+
const installed = readPackageVersion(rootDir);
|
|
1269
|
+
if (!installed || (wantedVersion && installed !== wantedVersion)) {
|
|
1270
|
+
fail("installing", "npm 已退出,但当前服务的安装目录缺少目标版本。请核对安装位置。");
|
|
1271
|
+
return;
|
|
1272
|
+
}
|
|
1273
|
+
try {
|
|
1274
|
+
updateTracker.restarting(id, installed);
|
|
1275
|
+
}
|
|
1276
|
+
catch {
|
|
1277
|
+
fail("installing", "版本已安装,但无法保存重启状态。请手动重启服务。");
|
|
1278
|
+
return;
|
|
1279
|
+
}
|
|
1198
1280
|
restartNow();
|
|
1199
|
-
}
|
|
1200
|
-
|
|
1201
|
-
|
|
1202
|
-
|
|
1203
|
-
|
|
1204
|
-
}
|
|
1205
|
-
});
|
|
1206
|
-
child.on("error", (error) => { spawnFailed = true; recordUpdateOutcome(false); release(); console.warn(`Super Pi: update spawn failed: ${error instanceof Error ? error.message : "unknown error"}`); });
|
|
1207
|
-
child.unref();
|
|
1281
|
+
});
|
|
1282
|
+
}
|
|
1283
|
+
catch {
|
|
1284
|
+
fail("installing", "无法启动 npm 安装程序,请检查服务日志。");
|
|
1285
|
+
}
|
|
1208
1286
|
return;
|
|
1209
1287
|
}
|
|
1210
|
-
if (url.pathname === "/api/update-check" && request.method === "GET") {
|
|
1288
|
+
if ((url.pathname === "/api/update-status" || url.pathname === "/api/update-check") && request.method === "GET") {
|
|
1211
1289
|
if (!isLocalOrPrivateAddress(remote)) {
|
|
1212
|
-
|
|
1290
|
+
json(403, { error: "只允许从本机或局域网查看更新。" });
|
|
1291
|
+
return;
|
|
1292
|
+
}
|
|
1293
|
+
const current = updateStatus();
|
|
1294
|
+
if (url.pathname === "/api/update-status") {
|
|
1295
|
+
json(200, current);
|
|
1296
|
+
return;
|
|
1297
|
+
}
|
|
1298
|
+
if (current.updating) {
|
|
1299
|
+
json(200, { ...current, updateAvailable: false });
|
|
1213
1300
|
return;
|
|
1214
1301
|
}
|
|
1215
1302
|
try {
|
|
1216
|
-
const
|
|
1217
|
-
|
|
1218
|
-
|
|
1219
|
-
|
|
1220
|
-
// minute. While the slot is held the answer is already known, so it is answered here.
|
|
1221
|
-
if (isUpdateInFlight()) {
|
|
1222
|
-
response.writeHead(200, { "content-type": "application/json; charset=utf-8" }).end(JSON.stringify({ ...current, updating: true, lastUpdate: getLastUpdateOutcome() ?? null, updateAvailable: false }));
|
|
1223
|
-
return;
|
|
1224
|
-
}
|
|
1225
|
-
// Query the npm registry for the latest @evandu/super-pi version.
|
|
1226
|
-
const remoteVersion = await fetch("https://registry.npmjs.org/@evandu/super-pi/latest").then(async (result) => {
|
|
1227
|
-
if (!result.ok)
|
|
1228
|
-
throw new Error(`npm registry HTTP ${result.status}`);
|
|
1229
|
-
return result.json();
|
|
1230
|
-
});
|
|
1303
|
+
const response = await fetch("https://registry.npmjs.org/@evandu/super-pi/latest", { signal: AbortSignal.timeout(10_000) });
|
|
1304
|
+
if (!response.ok)
|
|
1305
|
+
throw new Error(`npm registry HTTP ${response.status}`);
|
|
1306
|
+
const remoteVersion = await response.json();
|
|
1231
1307
|
const latestVersion = typeof remoteVersion.version === "string" ? remoteVersion.version : undefined;
|
|
1232
|
-
|
|
1308
|
+
if (!latestVersion)
|
|
1309
|
+
throw new Error("npm registry did not report a version");
|
|
1310
|
+
const status = updateStatus();
|
|
1311
|
+
json(200, { ...status, latestVersion, updateAvailable: !status.updating && latestVersion !== status.diskVersion });
|
|
1233
1312
|
}
|
|
1234
1313
|
catch (error) {
|
|
1235
|
-
|
|
1314
|
+
console.warn("Super Pi: update check failed:", error instanceof Error ? error.message : error);
|
|
1315
|
+
json(502, { error: "暂时无法获取最新版本,请检查服务器网络后重试。" });
|
|
1236
1316
|
}
|
|
1237
1317
|
return;
|
|
1238
1318
|
}
|
package/dist/server/index.js
CHANGED
|
@@ -22,6 +22,7 @@ import { CatalogService } from "./application/catalog-service.js";
|
|
|
22
22
|
import { ProviderService } from "./application/provider-service.js";
|
|
23
23
|
import { ProviderRegistry } from "./providers.js";
|
|
24
24
|
import { RunService } from "./application/run-service.js";
|
|
25
|
+
import { GroupChatService } from "./application/group-chat-service.js";
|
|
25
26
|
import { FileChangeTracker } from "./file-changes.js";
|
|
26
27
|
import { ConversationService } from "./application/conversation-service.js";
|
|
27
28
|
import { ScheduledTaskService } from "./application/scheduled-task-service.js";
|
|
@@ -344,6 +345,7 @@ const projectService = new ProjectService(store, sessionOrchestratorService, {
|
|
|
344
345
|
void sessionOrchestratorService.restoreWatchdogs().catch((error) => {
|
|
345
346
|
console.warn("Super Pi: restoring watchdogs failed:", error instanceof Error ? error.message : String(error));
|
|
346
347
|
});
|
|
348
|
+
const groupChatService = await GroupChatService.open(join(dataDir, "group-chats.json"), store, runtime, memory);
|
|
347
349
|
const serverContext = {
|
|
348
350
|
memory,
|
|
349
351
|
knowledge,
|
|
@@ -367,6 +369,7 @@ const serverContext = {
|
|
|
367
369
|
sessionReminderService,
|
|
368
370
|
sessionOrchestratorService,
|
|
369
371
|
projectService,
|
|
372
|
+
groupChatService,
|
|
370
373
|
execService,
|
|
371
374
|
toolRegistry,
|
|
372
375
|
toolRunner,
|
|
@@ -395,6 +398,7 @@ async function shutdown(reason) {
|
|
|
395
398
|
// Kill every shell BEFORE the sockets close, so a PTY is never outlived by the server that owns it.
|
|
396
399
|
terminalService.closeAll();
|
|
397
400
|
const execClosed = execService.closeAll();
|
|
401
|
+
const groupsClosed = groupChatService.close();
|
|
398
402
|
runService.abortAll();
|
|
399
403
|
workflows.abortAll();
|
|
400
404
|
// The scheduler stops BEFORE the runs are waited for, so no new task starts while the server is
|
|
@@ -406,7 +410,7 @@ async function shutdown(reason) {
|
|
|
406
410
|
}
|
|
407
411
|
await sessionOrchestratorService.watchdog.dispose();
|
|
408
412
|
await execClosed;
|
|
409
|
-
await Promise.all([runService.waitForIdle(), workflows.waitForIdle()]);
|
|
413
|
+
await Promise.all([runService.waitForIdle(), workflows.waitForIdle(), groupsClosed]);
|
|
410
414
|
// THE LIVE SESSIONS GO NEXT, AND THEY HAVE TO GO EXPLICITLY. `runService.abortAll()` stops the
|
|
411
415
|
// TURNS, and a stopped turn is not a stopped session: a session with nothing running on it is idle,
|
|
412
416
|
// it holds a model client and a session file, and nothing in the abort path would reach it. So
|
|
@@ -3,8 +3,23 @@ import { type MemoryEntry, type MemoryTarget } from "./memory.js";
|
|
|
3
3
|
export declare const memoryTokenCost: (value: string) => number;
|
|
4
4
|
export declare const DEFAULT_MEMORY_BUDGET = 6000;
|
|
5
5
|
export declare const memoryTerms: (value: string) => string[];
|
|
6
|
-
export declare function
|
|
6
|
+
export declare function experienceMode(value: string): "quick-fix" | "rigorous" | undefined;
|
|
7
|
+
export declare function recallMemory(groups: Partial<Record<MemoryTarget, MemoryEntry[]>>, query: string, budget: number, context?: {
|
|
8
|
+
workspaceId?: string;
|
|
9
|
+
mode?: ReturnType<typeof experienceMode>;
|
|
10
|
+
browse?: boolean;
|
|
11
|
+
}): {
|
|
7
12
|
notes: string;
|
|
8
13
|
selected: number;
|
|
14
|
+
entries: {
|
|
15
|
+
target: string;
|
|
16
|
+
id: string;
|
|
17
|
+
content: string;
|
|
18
|
+
revision: number;
|
|
19
|
+
sourceConversationId: string;
|
|
20
|
+
sourceMessageId?: string;
|
|
21
|
+
experience?: MemoryEntry["experience"];
|
|
22
|
+
pinned: boolean;
|
|
23
|
+
}[];
|
|
9
24
|
omitted: number;
|
|
10
25
|
};
|