@evandu/super-pi 0.1.322 → 0.1.324
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/agents/super-pi-managed-model/index.ts +8 -1
- package/dist/.super-pi-check-inputs.json +2 -2
- package/dist/client/.super-pi-client-sources.json +24 -19
- package/dist/client/assets/CodeMirrorEditor-eVHUQY8Y.js +2 -0
- package/dist/client/assets/GitDiffEditor-Cebgkg-9.js +31 -0
- package/dist/client/assets/index-A2acEU1u.css +1 -0
- package/dist/client/assets/index-D9r6d2wH.js +363 -0
- package/dist/client/index.html +2 -2
- package/dist/server/application/group-chat-service.js +54 -4
- package/dist/server/application/provider-service.d.ts +2 -0
- package/dist/server/application/provider-service.js +28 -0
- package/dist/server/application/run-service.d.ts +2 -0
- package/dist/server/application/run-service.js +14 -2
- package/dist/server/file-review-threads.d.ts +5 -2
- package/dist/server/file-review-threads.js +83 -5
- package/dist/server/git.d.ts +7 -7
- package/dist/server/git.js +25 -8
- package/dist/server/group-primary-executor.js +9 -1
- package/dist/server/http-server.js +22 -10
- package/dist/server/managed-http.js +87 -18
- package/dist/server/managed-model-adapter.d.ts +8 -0
- package/dist/server/managed-model-adapter.js +46 -2
- package/dist/server/managed-model-gateway.d.ts +38 -0
- package/dist/server/managed-model-gateway.js +24 -3
- package/dist/server/managed-servers.d.ts +1 -0
- package/dist/server/managed-servers.js +15 -8
- package/dist/server/runtime.d.ts +1 -0
- package/dist/server/shared-model-catalog.d.ts +8 -0
- package/dist/server/shared-model-catalog.js +45 -0
- package/dist/server/store.d.ts +11 -1
- package/dist/server/store.js +85 -1
- package/dist/server/types.d.ts +9 -0
- package/dist/server/ws-server.d.ts +2 -2
- package/dist/server/ws-server.js +19 -5
- package/dist/shared/file-review.d.ts +39 -0
- package/dist/shared/file-review.js +14 -0
- package/dist/shared/group-chat.d.ts +2 -0
- package/dist/shared/managed-servers.d.ts +1 -0
- package/dist/shared/model-configuration.d.ts +12 -0
- package/dist/shared/model-configuration.js +3 -0
- package/dist/shared/request-timing.d.ts +8 -0
- package/dist/shared/request-timing.js +1 -0
- package/package.json +2 -1
- package/dist/client/assets/CodeMirrorEditor-BsMtOxUG.js +0 -2
- package/dist/client/assets/GitDiffEditor-L_OuYDQ2.js +0 -29
- package/dist/client/assets/index-Cvx8i65V.css +0 -1
- package/dist/client/assets/index-DeMK1efe.js +0 -358
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-D9r6d2wH.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-A2acEU1u.css">
|
|
14
14
|
</head>
|
|
15
15
|
<body>
|
|
16
16
|
<div id="root"></div>
|
|
17
17
|
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { randomUUID } from "node:crypto";
|
|
1
|
+
import { createHash, randomUUID } from "node:crypto";
|
|
2
2
|
import { open, readFile, realpath, writeFile } from "node:fs/promises";
|
|
3
3
|
import { dirname, isAbsolute, join, relative, resolve, sep } from "node:path";
|
|
4
4
|
import { createGitWorktree } from "../git.js";
|
|
@@ -45,6 +45,8 @@ function resolveQuestion(room, reply, answer, answerMessageId) {
|
|
|
45
45
|
const topic = room.messages.find(post => post.role === "user" && post.id === reply.topicId);
|
|
46
46
|
if (topic?.status === "interrupted" || topic?.status === "failed" || (answerMessageId && topic?.status === "completed")) {
|
|
47
47
|
topic.status = "queued";
|
|
48
|
+
if (topic.role === "user" && topic.requestTiming)
|
|
49
|
+
topic.requestTiming = { startedAt: topic.requestTiming.startedAt };
|
|
48
50
|
delete topic.error;
|
|
49
51
|
}
|
|
50
52
|
}
|
|
@@ -277,6 +279,8 @@ export class GroupChatService {
|
|
|
277
279
|
for (const post of room.messages)
|
|
278
280
|
if (post.status === "running" || (post.role === "assistant" && post.status === "queued")) {
|
|
279
281
|
post.status = "interrupted";
|
|
282
|
+
if (post.role === "user" && post.requestTiming)
|
|
283
|
+
post.requestTiming.outcome = "interrupted";
|
|
280
284
|
post.error = "服务重启,本次发言已中断。";
|
|
281
285
|
const trace = room.executions?.[post.id];
|
|
282
286
|
if (trace && room.executions)
|
|
@@ -363,7 +367,34 @@ export class GroupChatService {
|
|
|
363
367
|
}
|
|
364
368
|
const rsi = room.rsi ?? defaultGroupRsi();
|
|
365
369
|
const executionBusy = this.runtime.groupMembersBusy?.(workspaceId, id) ?? false;
|
|
366
|
-
|
|
370
|
+
const executionsByTopic = new Map();
|
|
371
|
+
for (const post of room.messages)
|
|
372
|
+
if (post.role === "assistant" && post.status === "completed" && post.executionConversationId && post.executionRequestId) {
|
|
373
|
+
const timing = this.store.requestTiming?.(post.executionConversationId, post.executionRequestId);
|
|
374
|
+
if (!timing)
|
|
375
|
+
continue;
|
|
376
|
+
const executions = executionsByTopic.get(post.topicId) ?? [];
|
|
377
|
+
executions.push(timing);
|
|
378
|
+
executionsByTopic.set(post.topicId, executions);
|
|
379
|
+
}
|
|
380
|
+
const timingChanges = [];
|
|
381
|
+
for (const post of room.messages) {
|
|
382
|
+
if (post.role !== "user" || post.requestTiming?.outcome !== "completed")
|
|
383
|
+
continue;
|
|
384
|
+
const executions = executionsByTopic.get(post.id);
|
|
385
|
+
if (!executions?.length)
|
|
386
|
+
continue;
|
|
387
|
+
const timing = post.requestTiming;
|
|
388
|
+
const latest = executions.reduce((value, item) => item.endedAt && item.endedAt > value ? item.endedAt : value, timing.endedAt ?? "");
|
|
389
|
+
const ended = executions.every(item => item.outcome);
|
|
390
|
+
const interrupted = executions.some(item => item.outcome === "interrupted");
|
|
391
|
+
const failed = executions.some(item => item.outcome !== "completed");
|
|
392
|
+
timing.endedAt = ended && !interrupted ? latest : undefined;
|
|
393
|
+
timing.outcome = !ended ? undefined : interrupted ? "interrupted" : failed ? "incomplete" : "completed";
|
|
394
|
+
timingChanges.push([post.id, timing.endedAt, timing.outcome]);
|
|
395
|
+
}
|
|
396
|
+
const timingRevision = timingChanges.length ? createHash("sha256").update(JSON.stringify(timingChanges)).digest("hex").slice(0, 16) : "";
|
|
397
|
+
return { ...room, rsi: { ...rsi, pending: rsi.enabled && room.messages.length > 0 && rsi.sourceKey !== rsiSourceKey(room) }, activity: groupActivity(room, executionBusy), revision: `${room.revision}:${this.streamRevisions.get(id) ?? 0}:${executionBusy}${timingRevision ? `:${timingRevision}` : ""}` };
|
|
367
398
|
}
|
|
368
399
|
execution(workspaceId, id, postId) {
|
|
369
400
|
const room = this.find(this.rooms, workspaceId, id);
|
|
@@ -632,7 +663,7 @@ export class GroupChatService {
|
|
|
632
663
|
}
|
|
633
664
|
if (!memberIds.length && parent?.role === "assistant" && room.members.some(member => member.id === parent.memberId))
|
|
634
665
|
memberIds.push(parent.memberId);
|
|
635
|
-
room.messages.push({ id: randomUUID(), role: "user", clientId, content, files, images, memberIds, replyTo: parent?.id, createdAt: timestamp(), status: "queued" });
|
|
666
|
+
room.messages.push({ id: randomUUID(), role: "user", clientId, content, files, images, memberIds, replyTo: parent?.id, createdAt: timestamp(), status: "queued", requestTiming: {} });
|
|
636
667
|
room.updatedAt = timestamp();
|
|
637
668
|
room.revision += 1;
|
|
638
669
|
});
|
|
@@ -668,6 +699,8 @@ export class GroupChatService {
|
|
|
668
699
|
for (const post of posts) {
|
|
669
700
|
post.content = this.live.get(post.id) ?? post.content;
|
|
670
701
|
post.status = "cancelled";
|
|
702
|
+
if (post.role === "user" && post.requestTiming)
|
|
703
|
+
Object.assign(post.requestTiming, { endedAt: timestamp(), outcome: "stopped" });
|
|
671
704
|
if (post.role === "assistant") {
|
|
672
705
|
this.saveExecution(room, post.id, true);
|
|
673
706
|
if (post.humanQuestion && !post.humanQuestion.answer)
|
|
@@ -707,6 +740,8 @@ export class GroupChatService {
|
|
|
707
740
|
if (next?.status !== "queued")
|
|
708
741
|
return;
|
|
709
742
|
next.status = "running";
|
|
743
|
+
if (next.requestTiming)
|
|
744
|
+
next.requestTiming.startedAt ??= timestamp();
|
|
710
745
|
current.revision += 1;
|
|
711
746
|
return next;
|
|
712
747
|
});
|
|
@@ -1441,8 +1476,11 @@ export class GroupChatService {
|
|
|
1441
1476
|
current.messages.push(this.moderatorPost(message, notice, hostName));
|
|
1442
1477
|
}
|
|
1443
1478
|
const handled = decision.action === "clarify" || !decision.hasNewRequest;
|
|
1444
|
-
if (handled)
|
|
1479
|
+
if (handled) {
|
|
1445
1480
|
message.status = "completed";
|
|
1481
|
+
if (message.requestTiming)
|
|
1482
|
+
Object.assign(message.requestTiming, { endedAt: timestamp(), outcome: "completed" });
|
|
1483
|
+
}
|
|
1446
1484
|
current.revision += 1;
|
|
1447
1485
|
current.updatedAt = timestamp();
|
|
1448
1486
|
return { ids, handled };
|
|
@@ -1693,6 +1731,14 @@ export class GroupChatService {
|
|
|
1693
1731
|
this.find(rooms, started.workspaceId, roomId).revision++;
|
|
1694
1732
|
} }),
|
|
1695
1733
|
userToolContext: reply.requirementsOnly ? undefined : { id: reply.id, workspaceId: started.workspaceId },
|
|
1734
|
+
onRequest: reply.requirementsOnly ? undefined : id => this.edit(rooms => {
|
|
1735
|
+
const room = this.find(rooms, started.workspaceId, roomId);
|
|
1736
|
+
const post = room.messages.find(item => item.id === reply.id);
|
|
1737
|
+
if (post?.role === "assistant") {
|
|
1738
|
+
post.executionRequestId = id;
|
|
1739
|
+
room.revision++;
|
|
1740
|
+
}
|
|
1741
|
+
}),
|
|
1696
1742
|
memberSession: reply.requirementsOnly ? undefined : { workspaceId: started.workspaceId, roomId, memberId: reply.memberId, context: this.context(started, topic) },
|
|
1697
1743
|
prompt: `会议身份:${member?.name ?? agent.name}。${member?.worktreePath ? "你在独立工作树工作;报告分支和产物供后续审查整合。" : ""}\n${prompt}`, cwd: member?.worktreePath,
|
|
1698
1744
|
agent: executionAgent, model: member?.model ?? (agent.model && { ...agent.model, label: agent.model.modelId }), signal: memberSignal, timeoutMs: 15 * 60_000,
|
|
@@ -1740,6 +1786,10 @@ export class GroupChatService {
|
|
|
1740
1786
|
if (post?.status !== "running")
|
|
1741
1787
|
return;
|
|
1742
1788
|
post.status = signal.aborted ? this.closing ? "interrupted" : "cancelled" : error ? "failed" : "completed";
|
|
1789
|
+
if (post.role === "user" && post.requestTiming) {
|
|
1790
|
+
const at = timestamp();
|
|
1791
|
+
Object.assign(post.requestTiming, { responseEndedAt: at, endedAt: at, outcome: post.status === "cancelled" ? "stopped" : post.status });
|
|
1792
|
+
}
|
|
1743
1793
|
if (content !== undefined)
|
|
1744
1794
|
post.content = content.slice(0, MAX_CONTENT);
|
|
1745
1795
|
post.error = signal.aborted ? (this.closing ? "服务停止,本次发言已中断。" : undefined) : error?.slice(0, 1600);
|
|
@@ -51,6 +51,8 @@ export declare class ProviderService {
|
|
|
51
51
|
set(input: unknown): Promise<PublicProvider[]>;
|
|
52
52
|
remove(providerId: string): Promise<PublicProvider[]>;
|
|
53
53
|
removeModel(providerId: string, modelId: string): Promise<PublicProvider[]>;
|
|
54
|
+
refreshConfiguration(): Promise<void>;
|
|
55
|
+
setSharedCatalogKey(providerId: string, key: string): Promise<void>;
|
|
54
56
|
private readonly oauthJobs;
|
|
55
57
|
constructor(registry: ProviderRegistry, runtime: AgentRuntime, broadcaster: EventBroadcaster, catalogService: CatalogService, store: Store, discoverModels?: typeof discoverPiProviderModels);
|
|
56
58
|
/**
|
|
@@ -6,6 +6,9 @@ import { thinkingLevelsEndpoint } from "../../shared/thinking-levels.js";
|
|
|
6
6
|
import { randomUUID } from "node:crypto";
|
|
7
7
|
import { ModelDiscovery } from "../model-discovery.js";
|
|
8
8
|
import { discoverPiProviderModels } from "../pi-session.js";
|
|
9
|
+
import { activeSharedCatalog } from "../managed-model-adapter.js";
|
|
10
|
+
import { sharedProviderModels } from "../shared-model-catalog.js";
|
|
11
|
+
import { piAuthPath } from "../providers.js";
|
|
9
12
|
/**
|
|
10
13
|
* THE PROVIDERS A PERSON ADDED, as a service.
|
|
11
14
|
*
|
|
@@ -88,6 +91,22 @@ export class ProviderService {
|
|
|
88
91
|
async set(input) { return this.mutate(() => this.setNow(input)); }
|
|
89
92
|
async remove(providerId) { return this.mutate(() => this.removeNow(providerId)); }
|
|
90
93
|
async removeModel(providerId, modelId) { return this.mutate(() => this.removeModelNow(providerId, modelId)); }
|
|
94
|
+
async refreshConfiguration() { return this.mutate(() => this.afterChange([], false)); }
|
|
95
|
+
async setSharedCatalogKey(providerId, key) {
|
|
96
|
+
return this.mutate(async () => {
|
|
97
|
+
const url = new URL("./core/auth-storage.js", import.meta.resolve("@earendil-works/pi-coding-agent")).href;
|
|
98
|
+
const { AuthStorage } = await import(url);
|
|
99
|
+
const storage = AuthStorage.create(piAuthPath(this.registry.agentDir));
|
|
100
|
+
await storage.modify(providerId, async (previous) => {
|
|
101
|
+
if (previous?.type === "oauth")
|
|
102
|
+
throw new Error("请在内置供应商登录中管理此授权。");
|
|
103
|
+
if (!key)
|
|
104
|
+
return undefined;
|
|
105
|
+
return { type: "api_key", key, ...(previous?.env ? { env: previous.env } : {}) };
|
|
106
|
+
});
|
|
107
|
+
await this.afterChange([], false);
|
|
108
|
+
});
|
|
109
|
+
}
|
|
91
110
|
oauthJobs = new Map();
|
|
92
111
|
constructor(registry, runtime, broadcaster, catalogService, store, discoverModels = discoverPiProviderModels) {
|
|
93
112
|
this.registry = registry;
|
|
@@ -175,6 +194,15 @@ export class ProviderService {
|
|
|
175
194
|
provider.builtin = true;
|
|
176
195
|
byId.set(info.id, provider);
|
|
177
196
|
}
|
|
197
|
+
for (const [id, models] of sharedProviderModels(await activeSharedCatalog())) {
|
|
198
|
+
const previous = byId.get(id);
|
|
199
|
+
byId.set(id, {
|
|
200
|
+
...previous, id, name: previous?.name ?? id, hasKey: previous?.hasKey ?? false,
|
|
201
|
+
baseUrl: models[0].baseUrl, api: models[0].api,
|
|
202
|
+
models: models.map(model => ({ id: model.id, name: model.name, reasoning: model.reasoning,
|
|
203
|
+
imageInput: model.input.includes("image"), contextWindow: model.contextWindow, maxTokens: model.maxTokens })),
|
|
204
|
+
});
|
|
205
|
+
}
|
|
178
206
|
return [...byId.values()];
|
|
179
207
|
}
|
|
180
208
|
oauthSnapshot() {
|
|
@@ -421,6 +421,8 @@ export declare class RunService {
|
|
|
421
421
|
mode?: MessageDeliveryMode;
|
|
422
422
|
onAccepted?: (messageId: string) => void;
|
|
423
423
|
images?: MessageImage[];
|
|
424
|
+
trackRequestTiming?: boolean;
|
|
425
|
+
timingRequestIds?: string[];
|
|
424
426
|
}): Promise<void>;
|
|
425
427
|
acknowledgeAcceptedSend(conversationId: string, clientId: string | undefined): Promise<boolean>;
|
|
426
428
|
enqueueAndRun(conversationId: string, content: string, images?: MessageImage[], attachments?: Message["attachments"], clientId?: string, mode?: MessageDeliveryMode, onAccepted?: () => void): Promise<void>;
|
|
@@ -1181,6 +1181,7 @@ export class RunService {
|
|
|
1181
1181
|
let assistant = assistantMessage;
|
|
1182
1182
|
let currentUserMessageId = userMessageId;
|
|
1183
1183
|
let closedOwnScope = false;
|
|
1184
|
+
let outcome = "completed";
|
|
1184
1185
|
let toolCalls = [];
|
|
1185
1186
|
let pendingTools = Promise.resolve();
|
|
1186
1187
|
// A TURN MOVES FROM `waiting` TO `running` ONCE THE MODEL HAS PRODUCED ANY SIGNAL: a text delta
|
|
@@ -1660,6 +1661,7 @@ export class RunService {
|
|
|
1660
1661
|
return toolCalls;
|
|
1661
1662
|
if (!ownsScope())
|
|
1662
1663
|
return toolCalls;
|
|
1664
|
+
await this.store.finishRequestReply(conversation.id, previous.id, currentUserMessageId, "completed");
|
|
1663
1665
|
if (this.memory) {
|
|
1664
1666
|
const checkpointed = this.store.conversation(conversation.id);
|
|
1665
1667
|
if (checkpointed)
|
|
@@ -1829,6 +1831,10 @@ export class RunService {
|
|
|
1829
1831
|
scheduleCheckpoint();
|
|
1830
1832
|
}
|
|
1831
1833
|
}
|
|
1834
|
+
catch (error) {
|
|
1835
|
+
outcome = isLengthExceededError(error) ? "incomplete" : "failed";
|
|
1836
|
+
throw error;
|
|
1837
|
+
}
|
|
1832
1838
|
finally {
|
|
1833
1839
|
scope.accepting = false;
|
|
1834
1840
|
traceScope("draining");
|
|
@@ -1851,6 +1857,9 @@ export class RunService {
|
|
|
1851
1857
|
enqueueTools("unfinished tool calls", () => this.store.clearPreparingToolCalls(conversation.id, assistant.id, stranded));
|
|
1852
1858
|
}
|
|
1853
1859
|
await pendingTools;
|
|
1860
|
+
if (ownsScope()) {
|
|
1861
|
+
await this.store.finishRequestReply(conversation.id, assistant.id, currentUserMessageId, controller.signal.aborted ? "stopped" : outcome);
|
|
1862
|
+
}
|
|
1854
1863
|
// The positions are facts ABOUT THIS TURN and stop being true when it ends, so they go with it.
|
|
1855
1864
|
// A dispatch whose POST arrives after this line gets no anchor and renders where it always did -
|
|
1856
1865
|
// which is the honest outcome, because by then the call that asked for it may no longer be on screen.
|
|
@@ -2004,7 +2013,10 @@ export class RunService {
|
|
|
2004
2013
|
}
|
|
2005
2014
|
let message;
|
|
2006
2015
|
try {
|
|
2007
|
-
message = await this.store.addAgentMessage(conversationId, trimmed, {
|
|
2016
|
+
message = await this.store.addAgentMessage(conversationId, trimmed, {
|
|
2017
|
+
images: options?.images, ...(queueOnly ? { delivery: "waiting" } : {}),
|
|
2018
|
+
requestTiming: options?.trackRequestTiming ? {} : undefined, timingRequestIds: options?.timingRequestIds,
|
|
2019
|
+
});
|
|
2008
2020
|
}
|
|
2009
2021
|
catch (error) {
|
|
2010
2022
|
if (reservedController)
|
|
@@ -2328,7 +2340,7 @@ export class RunService {
|
|
|
2328
2340
|
}
|
|
2329
2341
|
this.lengthContinuations.set(conversationId, used + 1);
|
|
2330
2342
|
try {
|
|
2331
|
-
await this.enqueueAndRunAsAgent(conversationId, buildLengthContinuationPrompt(assistant));
|
|
2343
|
+
await this.enqueueAndRunAsAgent(conversationId, buildLengthContinuationPrompt(assistant), { timingRequestIds: assistant?.timingRequestIds });
|
|
2332
2344
|
return;
|
|
2333
2345
|
}
|
|
2334
2346
|
catch (error) {
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { type ReviewThread } from "../shared/file-review.js";
|
|
1
|
+
import { type ReviewDiffReplay, type ReviewThread } from "../shared/file-review.js";
|
|
2
2
|
type ScopedThread = ReviewThread & {
|
|
3
3
|
workspaceId: string;
|
|
4
4
|
cwd: string;
|
|
@@ -11,7 +11,8 @@ export declare class FileReviewThreads {
|
|
|
11
11
|
private loaded;
|
|
12
12
|
constructor(path: string);
|
|
13
13
|
list(scope: Scope): ScopedThread[];
|
|
14
|
-
create(scope: Scope, comments: unknown, agentName?: string): ScopedThread[];
|
|
14
|
+
create(scope: Scope, comments: unknown, agentName?: string, diff?: unknown): ScopedThread[];
|
|
15
|
+
snapshot(scope: Scope, threadId: string): ReviewDiffReplay | undefined;
|
|
15
16
|
agentCreate(workspace: {
|
|
16
17
|
id: string;
|
|
17
18
|
path: string;
|
|
@@ -30,5 +31,7 @@ export declare class FileReviewThreads {
|
|
|
30
31
|
private get;
|
|
31
32
|
private load;
|
|
32
33
|
private save;
|
|
34
|
+
private snapshotPath;
|
|
35
|
+
private saveSnapshot;
|
|
33
36
|
}
|
|
34
37
|
export {};
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { createHash, randomUUID } from "node:crypto";
|
|
2
|
-
import { existsSync, readFileSync, renameSync, writeFileSync } from "node:fs";
|
|
2
|
+
import { existsSync, mkdirSync, readFileSync, renameSync, rmSync, writeFileSync } from "node:fs";
|
|
3
3
|
import { stat } from "node:fs/promises";
|
|
4
|
-
import { posix } from "node:path";
|
|
5
|
-
import { reviewExcerpt, workspaceReviewPath } from "../shared/file-review.js";
|
|
4
|
+
import { join, posix } from "node:path";
|
|
5
|
+
import { reviewExcerpt, reviewTextVersions, workspaceReviewPath } from "../shared/file-review.js";
|
|
6
6
|
import { readWorkspaceFile, resolveInsideRoot } from "./files.js";
|
|
7
7
|
function record(value) {
|
|
8
8
|
if (!value || typeof value !== "object" || Array.isArray(value))
|
|
@@ -42,6 +42,44 @@ function anchorFrom(value, allowAdditional = true) {
|
|
|
42
42
|
function sameScope(thread, scope) {
|
|
43
43
|
return thread.workspaceId === scope.workspaceId;
|
|
44
44
|
}
|
|
45
|
+
function diffVersion(value) {
|
|
46
|
+
const { kind, hash } = record(value);
|
|
47
|
+
if (kind === "missing" || kind === "unknown")
|
|
48
|
+
return { kind };
|
|
49
|
+
if ((kind === "commit" || kind === "blob") && typeof hash === "string" && /^(?:[a-f0-9]{40}|[a-f0-9]{64})$/i.test(hash)) {
|
|
50
|
+
return { kind, hash: hash.toLowerCase() };
|
|
51
|
+
}
|
|
52
|
+
throw new Error("差异版本标识无效。");
|
|
53
|
+
}
|
|
54
|
+
function diffSnapshot(value) {
|
|
55
|
+
const input = record(value);
|
|
56
|
+
const path = text(input.path, 4096);
|
|
57
|
+
const previousPath = text(input.previousPath, 4096, true);
|
|
58
|
+
const payloadText = (item) => item === null ? null : text(item, 8 * 1024 * 1024, true);
|
|
59
|
+
let content;
|
|
60
|
+
let versions;
|
|
61
|
+
if (input.mode === "patch" && (input.kind === "text" || input.kind === "binary" || input.kind === "untracked")) {
|
|
62
|
+
const patch = payloadText(input.diff);
|
|
63
|
+
if (patch === undefined)
|
|
64
|
+
throw new Error("缺少原差异内容。");
|
|
65
|
+
const sides = record(input.versions);
|
|
66
|
+
versions = { before: diffVersion(sides.before), after: diffVersion(sides.after) };
|
|
67
|
+
content = { mode: "patch", kind: input.kind, diff: patch, limited: input.limited === true, versions };
|
|
68
|
+
}
|
|
69
|
+
else if (input.mode === "text") {
|
|
70
|
+
const before = payloadText(input.before);
|
|
71
|
+
const after = payloadText(input.after);
|
|
72
|
+
if (before === undefined || after === undefined)
|
|
73
|
+
throw new Error("缺少原差异内容。");
|
|
74
|
+
const beforeUnknown = before === null && input.beforeUnknown === true;
|
|
75
|
+
versions = reviewTextVersions(before, after, beforeUnknown);
|
|
76
|
+
content = { mode: "text", before, after, ...(beforeUnknown ? { beforeUnknown } : {}) };
|
|
77
|
+
}
|
|
78
|
+
else
|
|
79
|
+
throw new Error("差异快照格式无效。");
|
|
80
|
+
const id = createHash("sha256").update(JSON.stringify([path, previousPath, content])).digest("hex");
|
|
81
|
+
return { ref: { id, path, ...(previousPath === undefined ? {} : { previousPath }), ...versions }, content };
|
|
82
|
+
}
|
|
45
83
|
/** Review threads belong to one workspace checkout. Cwd records the origin of a relative anchor. */
|
|
46
84
|
export class FileReviewThreads {
|
|
47
85
|
path;
|
|
@@ -54,12 +92,14 @@ export class FileReviewThreads {
|
|
|
54
92
|
this.load();
|
|
55
93
|
return [...this.entries.values()].filter(thread => sameScope(thread, scope)).reverse();
|
|
56
94
|
}
|
|
57
|
-
create(scope, comments, agentName) {
|
|
95
|
+
create(scope, comments, agentName, diff) {
|
|
58
96
|
this.load();
|
|
59
97
|
if (!Array.isArray(comments) || !comments.length || comments.length > 25)
|
|
60
98
|
throw new Error("请选择要保存的批注。");
|
|
61
99
|
const next = new Map(this.entries);
|
|
62
100
|
const created = [];
|
|
101
|
+
const snapshot = diff === undefined ? undefined : diffSnapshot(diff);
|
|
102
|
+
let added = false;
|
|
63
103
|
for (const value of comments) {
|
|
64
104
|
const item = record(value);
|
|
65
105
|
const id = text(item.id, 128);
|
|
@@ -74,14 +114,29 @@ export class FileReviewThreads {
|
|
|
74
114
|
}
|
|
75
115
|
const entry = {
|
|
76
116
|
...scope, ...anchorFrom(item), id,
|
|
77
|
-
text: text(item.text, 2_000), replies: [], createdAt: new Date().toISOString(), agentName,
|
|
117
|
+
text: text(item.text, 2_000), replies: [], createdAt: new Date().toISOString(), agentName, diffSnapshot: snapshot?.ref,
|
|
78
118
|
};
|
|
119
|
+
if (snapshot && [entry, ...entry.additional ?? []].some(anchor => anchor.side === "file" || anchor.path !== (anchor.side === "before" ? snapshot.ref.previousPath ?? snapshot.ref.path : snapshot.ref.path))) {
|
|
120
|
+
throw new Error("批注位置与差异快照不匹配。");
|
|
121
|
+
}
|
|
79
122
|
next.set(id, entry);
|
|
80
123
|
created.push(entry);
|
|
124
|
+
added = true;
|
|
81
125
|
}
|
|
126
|
+
if (snapshot && added)
|
|
127
|
+
this.saveSnapshot(snapshot);
|
|
82
128
|
this.save(next);
|
|
83
129
|
return created;
|
|
84
130
|
}
|
|
131
|
+
snapshot(scope, threadId) {
|
|
132
|
+
const ref = this.getForScope(scope, threadId).diffSnapshot;
|
|
133
|
+
if (!ref)
|
|
134
|
+
return;
|
|
135
|
+
const path = this.snapshotPath(ref.id);
|
|
136
|
+
if (!existsSync(path))
|
|
137
|
+
return;
|
|
138
|
+
return { ref, content: JSON.parse(readFileSync(path, "utf8")) };
|
|
139
|
+
}
|
|
85
140
|
async agentCreate(workspace, author, input, canWrite) {
|
|
86
141
|
const item = record(input);
|
|
87
142
|
const id = "review-" + createHash("sha256").update(JSON.stringify([author.conversationId, text(item.requestId, 200)])).digest("hex");
|
|
@@ -113,6 +168,15 @@ export class FileReviewThreads {
|
|
|
113
168
|
const next = new Map(this.entries);
|
|
114
169
|
next.delete(id);
|
|
115
170
|
this.save(next);
|
|
171
|
+
const snapshotId = thread.diffSnapshot?.id;
|
|
172
|
+
if (snapshotId && ![...next.values()].some(entry => entry.diffSnapshot?.id === snapshotId)) {
|
|
173
|
+
try {
|
|
174
|
+
rmSync(this.snapshotPath(snapshotId), { force: true });
|
|
175
|
+
}
|
|
176
|
+
catch (error) {
|
|
177
|
+
console.warn("Could not remove unused review snapshot.", error);
|
|
178
|
+
}
|
|
179
|
+
}
|
|
116
180
|
return;
|
|
117
181
|
}
|
|
118
182
|
if (action === "reply")
|
|
@@ -189,4 +253,18 @@ export class FileReviewThreads {
|
|
|
189
253
|
renameSync(temporary, this.path);
|
|
190
254
|
this.entries = next;
|
|
191
255
|
}
|
|
256
|
+
snapshotPath(id) {
|
|
257
|
+
if (!/^[a-f0-9]{64}$/.test(id))
|
|
258
|
+
throw new Error("差异快照标识无效。");
|
|
259
|
+
return join(this.path + ".snapshots", id + ".json");
|
|
260
|
+
}
|
|
261
|
+
saveSnapshot(snapshot) {
|
|
262
|
+
const target = this.snapshotPath(snapshot.ref.id);
|
|
263
|
+
if (existsSync(target))
|
|
264
|
+
return;
|
|
265
|
+
mkdirSync(this.path + ".snapshots", { recursive: true, mode: 0o700 });
|
|
266
|
+
const temporary = target + ".tmp";
|
|
267
|
+
writeFileSync(temporary, JSON.stringify(snapshot.content), { mode: 0o600 });
|
|
268
|
+
renameSync(temporary, target);
|
|
269
|
+
}
|
|
192
270
|
}
|
package/dist/server/git.d.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import type { GitCommitDetail } from "../shared/git-commit.js";
|
|
2
2
|
import type { GitGraphResponse } from "../shared/git-graph.js";
|
|
3
|
+
import type { ReviewVersions } from "../shared/file-review.js";
|
|
3
4
|
export type GitWorkspace = {
|
|
4
5
|
branch: string | null;
|
|
5
6
|
detached: boolean;
|
|
@@ -33,6 +34,7 @@ export declare function gitCommitDiff(root: string, cwd: string, hash: string, p
|
|
|
33
34
|
staged: boolean;
|
|
34
35
|
kind: "binary" | "text";
|
|
35
36
|
diff: string | null;
|
|
37
|
+
versions: ReviewVersions;
|
|
36
38
|
}>;
|
|
37
39
|
export type GitWorktree = {
|
|
38
40
|
id: string;
|
|
@@ -89,13 +91,9 @@ export declare function inspectGitWorktree(path: string, base: GitWorktree | und
|
|
|
89
91
|
export declare function gitWorktreeCommittedDiff(root: string, base: GitWorktree | undefined, path: string, fullContext?: boolean): Promise<{
|
|
90
92
|
path: string;
|
|
91
93
|
staged: boolean;
|
|
92
|
-
kind: "text";
|
|
93
|
-
diff: string;
|
|
94
|
-
|
|
95
|
-
path: string;
|
|
96
|
-
staged: boolean;
|
|
97
|
-
kind: "binary";
|
|
98
|
-
diff: null;
|
|
94
|
+
kind: "binary" | "text";
|
|
95
|
+
diff: string | null;
|
|
96
|
+
versions: ReviewVersions;
|
|
99
97
|
}>;
|
|
100
98
|
export declare function gitBranches(root: string, cwd: string, query: string, offset: number, localOnly?: boolean): Promise<{
|
|
101
99
|
branches: {
|
|
@@ -128,12 +126,14 @@ export declare function gitDiff(root: string, path: string, staged: boolean, ful
|
|
|
128
126
|
diff: null;
|
|
129
127
|
kind: "untracked";
|
|
130
128
|
currentExists: boolean;
|
|
129
|
+
versions: ReviewVersions;
|
|
131
130
|
} | {
|
|
132
131
|
path: string;
|
|
133
132
|
staged: boolean;
|
|
134
133
|
diff: string;
|
|
135
134
|
kind: "binary" | "text";
|
|
136
135
|
currentExists: boolean;
|
|
136
|
+
versions: ReviewVersions;
|
|
137
137
|
}>;
|
|
138
138
|
/** Read the index version for the editable working-tree comparison. The path is resolved beneath the
|
|
139
139
|
* workspace before it becomes a Git object expression, and the blob stays within the file editor's
|
package/dist/server/git.js
CHANGED
|
@@ -162,6 +162,15 @@ const PATCH_OPTIONS = ["--no-color", "--no-ext-diff", "--no-textconv", "--submod
|
|
|
162
162
|
const HISTORY_DIFF_OPTIONS = [...PATCH_OPTIONS, "--find-renames"];
|
|
163
163
|
const FULL_DIFF_MAX_BYTES = 2 * 1024 * 1024;
|
|
164
164
|
const FULL_DIFF_MAX_LINES = 12_000;
|
|
165
|
+
function comparedCommits(before, after) {
|
|
166
|
+
return { before: before ? { kind: "commit", hash: before } : { kind: "missing" }, after: { kind: "commit", hash: after } };
|
|
167
|
+
}
|
|
168
|
+
function comparedBlobs(patch) {
|
|
169
|
+
const index = /^index ([0-9a-f]{40}(?:[0-9a-f]{24})?)\.\.([0-9a-f]{40}(?:[0-9a-f]{24})?)(?: |$)/m.exec(patch);
|
|
170
|
+
const side = (hash) => !hash ? { kind: "unknown" }
|
|
171
|
+
: /^0+$/.test(hash) ? { kind: "missing" } : { kind: "blob", hash };
|
|
172
|
+
return { before: side(index?.[1]), after: side(index?.[2]) };
|
|
173
|
+
}
|
|
165
174
|
function patchContext(fullContext) {
|
|
166
175
|
// Any file that fits the full view limits fits within this unified context.
|
|
167
176
|
return fullContext ? "--unified=1000000" : "--unified=3";
|
|
@@ -254,7 +263,8 @@ export async function gitCommitDiff(root, cwd, hash, path, fullContext = false)
|
|
|
254
263
|
.map(name => scope ? `${scope}/${name}` : name);
|
|
255
264
|
const patch = await diff(["--patch", patchContext(fullContext)], paths, true, fullContext);
|
|
256
265
|
const binary = /^Binary files .* differ$/m.test(patch);
|
|
257
|
-
return { path, staged: false, kind: binary ? "binary" : "text", diff: binary ? null : patch
|
|
266
|
+
return { path, staged: false, kind: binary ? "binary" : "text", diff: binary ? null : patch,
|
|
267
|
+
versions: comparedCommits(detail.parents[0], detail.hash) };
|
|
258
268
|
}
|
|
259
269
|
const normalizedPath = (path) => process.platform === "win32" ? resolve(path).toLowerCase() : resolve(path);
|
|
260
270
|
async function worktreeRoot(root) {
|
|
@@ -421,11 +431,11 @@ export async function gitWorktreeCommittedDiff(root, base, path, fullContext = f
|
|
|
421
431
|
safePath(root, path);
|
|
422
432
|
const reference = await worktreeComparisonBase(root, base);
|
|
423
433
|
if (!reference)
|
|
424
|
-
return { path, staged: false, kind: "text", diff: "" };
|
|
434
|
+
return { path, staged: false, kind: "text", diff: "", versions: comparedBlobs("") };
|
|
425
435
|
const stdout = await readGitDiff(root, ["diff", ...PATCH_OPTIONS, patchContext(fullContext), reference.mergeBase, reference.target, "--", path], fullContext);
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
436
|
+
const binary = /^Binary files .* differ$/m.test(stdout);
|
|
437
|
+
return { path, staged: false, kind: binary ? "binary" : "text", diff: binary ? null : stdout,
|
|
438
|
+
versions: comparedCommits(reference.mergeBase, reference.target) };
|
|
429
439
|
}
|
|
430
440
|
export async function gitBranches(root, cwd, query, offset, localOnly = false) {
|
|
431
441
|
const canWrite = await canChangeWorktree(root, cwd);
|
|
@@ -511,9 +521,16 @@ export async function gitDiff(root, path, staged, fullContext = false) {
|
|
|
511
521
|
if (!tracked && !currentExists)
|
|
512
522
|
throw Object.assign(new Error("文件路径无效"), { code: "path" });
|
|
513
523
|
if (!tracked)
|
|
514
|
-
return { path, staged, diff: null, kind: "untracked", currentExists };
|
|
515
|
-
|
|
516
|
-
|
|
524
|
+
return { path, staged, diff: null, kind: "untracked", currentExists, versions: comparedBlobs("") };
|
|
525
|
+
// Pin HEAD before reading a staged patch so the stored base identifies what Git actually compared.
|
|
526
|
+
const head = staged ? await git(root, ["rev-parse", "--verify", "HEAD"]).then(result => result.stdout.trim()).catch(() => "") : "";
|
|
527
|
+
const patch = await readGitDiff(root, ["diff", ...PATCH_OPTIONS, patchContext(fullContext),
|
|
528
|
+
...(staged ? ["--cached", ...(head ? [head] : [])] : []), "--", path], fullContext);
|
|
529
|
+
const versions = comparedBlobs(patch);
|
|
530
|
+
if (COMMIT_HASH.test(head))
|
|
531
|
+
versions.before = { kind: "commit", hash: head };
|
|
532
|
+
return { path, staged, diff: patch, kind: /^Binary files .* differ$/m.test(patch) ? "binary" : "text",
|
|
533
|
+
currentExists, versions };
|
|
517
534
|
}
|
|
518
535
|
/** Read the index version for the editable working-tree comparison. The path is resolved beneath the
|
|
519
536
|
* workspace before it becomes a Git object expression, and the blob stays within the file editor's
|
|
@@ -69,7 +69,15 @@ export function groupPrimaryExecutor(store, runs, uploadsDir) {
|
|
|
69
69
|
const stored = await saveUpload(uploadsDir, id, "会议图片", image.mimeType, image.data);
|
|
70
70
|
return { id: stored.id, name: stored.name, mimeType: stored.mimeType, bytes: stored.bytes };
|
|
71
71
|
}));
|
|
72
|
-
|
|
72
|
+
let recorded;
|
|
73
|
+
await runs.enqueueAndRunAsAgent(id, fresh ? `${input.prompt}\n会议完整公开上下文:\n${JSON.stringify(scope.context)}` : input.prompt, {
|
|
74
|
+
images, trackRequestTiming: Boolean(input.onRequest),
|
|
75
|
+
onAccepted(messageId) {
|
|
76
|
+
recorded = Promise.resolve(input.onRequest?.(messageId));
|
|
77
|
+
void recorded.catch(() => undefined);
|
|
78
|
+
},
|
|
79
|
+
});
|
|
80
|
+
await recorded;
|
|
73
81
|
observe();
|
|
74
82
|
input.signal?.throwIfAborted();
|
|
75
83
|
const current = store.conversation(id);
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { handleManagedHttp } from "./managed-http.js";
|
|
2
2
|
import { handleRsiHttp } from "./rsi-http.js";
|
|
3
3
|
import { remoteModelRelay } from "./managed-model-relay.js";
|
|
4
|
-
import { readManagedModelConfig } from "./managed-model-adapter.js";
|
|
4
|
+
import { modelConfigurationMode, readManagedModelConfig } from "./managed-model-adapter.js";
|
|
5
5
|
import { ReadReceipts } from "./read-receipts.js";
|
|
6
6
|
import { createReadStream, existsSync } from "node:fs";
|
|
7
7
|
import { matchPathMentions } from "../shared/file-mentions.js";
|
|
@@ -531,8 +531,8 @@ export function createHttpServer(options) {
|
|
|
531
531
|
const matches = entries.filter(thread => (body.includeResolved === true || !thread.resolvedAt)
|
|
532
532
|
&& (!path || [thread.path, thread.currentPath, ...thread.additional?.map(item => item.path) ?? []]
|
|
533
533
|
.some(item => item && workspaceReviewPath(item, thread.cwd) === path)));
|
|
534
|
-
const page = matches.slice(offset, offset + 20).map(({ id, path, currentPath, cwd, side, start, end, text, resolvedAt, replies, workspaceId, agentName }) => ({ id, workspaceId, path: workspaceReviewPath(path, cwd), currentPath: currentPath && workspaceReviewPath(currentPath, cwd),
|
|
535
|
-
side, start, end, text, resolvedAt, agentName, replyCount: replies.length }));
|
|
534
|
+
const page = matches.slice(offset, offset + 20).map(({ id, path, currentPath, cwd, side, start, end, text, resolvedAt, replies, workspaceId, agentName, diffSnapshot }) => ({ id, workspaceId, path: workspaceReviewPath(path, cwd), currentPath: currentPath && workspaceReviewPath(currentPath, cwd),
|
|
535
|
+
side, start, end, text, resolvedAt, agentName, diffSnapshot, replyCount: replies.length }));
|
|
536
536
|
json(200, { threads: page, nextOffset: matches.length > offset + page.length ? offset + page.length : undefined });
|
|
537
537
|
return;
|
|
538
538
|
}
|
|
@@ -557,10 +557,19 @@ export function createHttpServer(options) {
|
|
|
557
557
|
const worktreeId = url.searchParams.get("worktreeId");
|
|
558
558
|
const checkout = worktreeId ? await resolveGitWorktree(workspace.path, worktreeId) : undefined;
|
|
559
559
|
let owner = checkout ? store.workspaces().find(item => !item.closedAt && !relative(resolve(item.path), resolve(checkout.path))) : workspace;
|
|
560
|
-
const root = await resolveFileCwd(checkout?.path ?? workspace.path, checkout ? "" : url.searchParams.get("cwd"));
|
|
561
|
-
const cwd = relative(resolve(checkout?.path ?? workspace.path), root).replaceAll("\\", "/");
|
|
562
560
|
if (request.method === "GET") {
|
|
563
|
-
|
|
561
|
+
const scope = owner && { workspaceId: owner.id, cwd: "" };
|
|
562
|
+
const original = url.searchParams.get("snapshot");
|
|
563
|
+
if (original !== null) {
|
|
564
|
+
const saved = scope && fileReviewThreads.snapshot(scope, original);
|
|
565
|
+
if (!saved) {
|
|
566
|
+
json(404, { error: "原差异快照已不可用。批注中仍保留原代码摘录。" });
|
|
567
|
+
return;
|
|
568
|
+
}
|
|
569
|
+
json(200, saved);
|
|
570
|
+
}
|
|
571
|
+
else
|
|
572
|
+
json(200, { threads: scope ? fileReviewThreads.list(scope) : [] });
|
|
564
573
|
return;
|
|
565
574
|
}
|
|
566
575
|
if (request.method !== "POST") {
|
|
@@ -572,7 +581,7 @@ export function createHttpServer(options) {
|
|
|
572
581
|
json(403, { error: "批注操作需要同源访问。" });
|
|
573
582
|
return;
|
|
574
583
|
}
|
|
575
|
-
const payload = await readRequestText(request,
|
|
584
|
+
const payload = await readRequestText(request, 24_000_000);
|
|
576
585
|
if (payload.tooLarge) {
|
|
577
586
|
json(413, { error: "批注请求过大。" });
|
|
578
587
|
return;
|
|
@@ -585,9 +594,12 @@ export function createHttpServer(options) {
|
|
|
585
594
|
}
|
|
586
595
|
if (!owner)
|
|
587
596
|
throw new Error("找不到此工作树的批注。");
|
|
588
|
-
const scope = { workspaceId: owner.id, cwd };
|
|
597
|
+
const scope = { workspaceId: owner.id, cwd: "" };
|
|
589
598
|
if (body.action === "create") {
|
|
590
|
-
|
|
599
|
+
const base = checkout?.path ?? workspace.path;
|
|
600
|
+
const root = await resolveFileCwd(base, checkout ? "" : url.searchParams.get("cwd"));
|
|
601
|
+
scope.cwd = relative(resolve(base), root).replaceAll("\\", "/");
|
|
602
|
+
json(200, { threads: fileReviewThreads.create(scope, body.comments, undefined, body.diffSnapshot) });
|
|
591
603
|
}
|
|
592
604
|
else if (body.action === "reply") {
|
|
593
605
|
if (typeof body.id !== "string" || typeof body.requestKey !== "string" || !/^[0-9a-f-]{36}$/.test(body.requestKey)) {
|
|
@@ -1992,7 +2004,7 @@ export function createHttpServer(options) {
|
|
|
1992
2004
|
if (url.pathname === "/api/health") {
|
|
1993
2005
|
const version = checkDiskVersion(rootDir);
|
|
1994
2006
|
response.writeHead(200, { "content-type": "application/json; charset=utf-8" })
|
|
1995
|
-
.end(JSON.stringify({ status: "ok", service: "super-pi", manager: Boolean(context.managedServers), managed: Boolean(process.env.SUPER_PI_MANAGED_CONFIG), modelRelay: Boolean(process.env.SUPER_PI_MANAGED_CONFIG), ...version }));
|
|
2007
|
+
.end(JSON.stringify({ status: "ok", service: "super-pi", manager: Boolean(context.managedServers), managed: Boolean(process.env.SUPER_PI_MANAGED_CONFIG), modelRelay: Boolean(process.env.SUPER_PI_MANAGED_CONFIG), modelMode: await modelConfigurationMode(), ...version }));
|
|
1996
2008
|
return;
|
|
1997
2009
|
}
|
|
1998
2010
|
/**
|