@evandu/super-pi 0.1.218 → 0.1.219
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/project-leader.md +1 -1
- package/agents/super-pi-task/core.ts +1 -1
- package/agents/super-pi-task/index.ts +4 -2
- package/dist/client/.super-pi-client-sources.json +6 -6
- package/dist/client/assets/{CodeMirrorEditor-CyESWKhO.js → CodeMirrorEditor-BoRBaVec.js} +2 -2
- package/dist/client/assets/{dist-DHh4-Br1.js → dist-BOC9yjsN.js} +1 -1
- package/dist/client/assets/{dist-DH6F4kKv.js → dist-BOF4T7jI.js} +1 -1
- package/dist/client/assets/{dist-1djw1Aua.js → dist-BVVJTFYw.js} +1 -1
- package/dist/client/assets/{dist-BwQiVXeZ.js → dist-BXOV_xtI.js} +1 -1
- package/dist/client/assets/{dist-BXMYNRiG.js → dist-Bh20DSAa.js} +1 -1
- package/dist/client/assets/{dist-DZGY_CNU.js → dist-CIv6vCdn.js} +1 -1
- package/dist/client/assets/{dist-GMozZ-IZ.js → dist-CMdO3YzL.js} +1 -1
- package/dist/client/assets/{dist-C9qNY2Kp.js → dist-CPjKkcyd.js} +1 -1
- package/dist/client/assets/{dist-BQ5yUYGI.js → dist-CYpk6fXT.js} +1 -1
- package/dist/client/assets/{dist-xAE0Sxu_.js → dist-CiRgPe6t.js} +1 -1
- package/dist/client/assets/{dist-C7y8W3IU.js → dist-CjhpwEGf.js} +1 -1
- package/dist/client/assets/{dist-CWLwzCNI.js → dist-Cp3XgqJR.js} +1 -1
- package/dist/client/assets/{dist-B33BwR-8.js → dist-D1hdxSH6.js} +1 -1
- package/dist/client/assets/{dist-BXq9HMCd.js → dist-DLYLxwOe.js} +1 -1
- package/dist/client/assets/{dist-Cgclz1Km.js → dist-DQ_C0DEU.js} +1 -1
- package/dist/client/assets/{dist-CkjmcyTq.js → dist-DUbHNa35.js} +1 -1
- package/dist/client/assets/{dist-BfAB10-T.js → dist-Digy2Mj0.js} +1 -1
- package/dist/client/assets/{dist-XNj0UVAT.js → dist-DvWgfLRt.js} +1 -1
- package/dist/client/assets/{dist-C6tiomV0.js → dist-Dwsqs8C-.js} +1 -1
- package/dist/client/assets/{dist-DtyV497P.js → dist-gRtmlyhZ.js} +1 -1
- package/dist/client/assets/{dist-Zl8KoipB.js → dist-mAA5Fw0-.js} +1 -1
- package/dist/client/assets/{dist-BlALlifb.js → dist-xb23AFcT.js} +1 -1
- package/dist/client/assets/{index-2k9h0zMt.js → index-DmxXnVfN.js} +11 -11
- package/dist/client/assets/index-Nu--gcBs.css +1 -0
- package/dist/client/index.html +2 -2
- package/dist/server/application/conversation-service.d.ts +7 -2
- package/dist/server/application/conversation-service.js +45 -5
- package/dist/server/application/project-service.d.ts +8 -4
- package/dist/server/application/project-service.js +76 -34
- package/dist/server/application/run-service.js +2 -0
- package/dist/server/application/session-orchestrator-service.d.ts +3 -0
- package/dist/server/application/session-orchestrator-service.js +53 -21
- package/dist/server/command-handler.d.ts +3 -1
- package/dist/server/command-handler.js +21 -1
- package/dist/server/index.js +2 -2
- package/dist/server/store.d.ts +7 -1
- package/dist/server/store.js +47 -8
- package/dist/server/types.d.ts +17 -1
- package/dist/server/upload.d.ts +2 -0
- package/dist/server/upload.js +19 -2
- package/dist/shared/project-overview.d.ts +9 -0
- package/dist/shared/project-overview.js +21 -7
- package/dist/shared/project-presentation.d.ts +3 -0
- package/dist/shared/project-presentation.js +13 -5
- package/dist/shared/team-context.d.ts +1 -1
- package/package.json +1 -1
- package/dist/client/assets/index-CwfAN5Vw.css +0 -1
|
@@ -127,7 +127,15 @@ export class SessionOrchestratorService {
|
|
|
127
127
|
if (!workspace)
|
|
128
128
|
throw new Error("找不到这个工作区。");
|
|
129
129
|
const parent = options.parentConversationId ? this.store.conversation(options.parentConversationId) : undefined;
|
|
130
|
-
const
|
|
130
|
+
const source = options.forkFromConversationId ? this.store.conversation(options.forkFromConversationId) : undefined;
|
|
131
|
+
if (options.forkFromConversationId && (!source || !parent || source.workspaceId !== workspaceId
|
|
132
|
+
|| parent.workspaceId !== workspaceId || (!source.warmSession && source.parentConversationId !== parent.id) || parent.archivedAt)) {
|
|
133
|
+
throw new Error("只能分叉同工作区及同一直属上级的会话");
|
|
134
|
+
}
|
|
135
|
+
if (source && options.cwd !== undefined && options.cwd !== (source.cwd ?? ".")) {
|
|
136
|
+
throw new Error("分叉任务须使用来源会话的工作目录");
|
|
137
|
+
}
|
|
138
|
+
const cwd = source ? source.cwd : options.cwd !== undefined ? options.cwd : parent?.workspaceId === workspaceId ? parent.cwd : undefined;
|
|
131
139
|
await assertSessionCwdInsideWorkspace(workspace.path, cwd);
|
|
132
140
|
if (options.handoffNote !== undefined && (typeof options.handoffNote !== "string" || options.handoffNote.length > 8000))
|
|
133
141
|
throw new Error("handoffNote 须为最多 8000 字符的交接说明");
|
|
@@ -135,28 +143,42 @@ export class SessionOrchestratorService {
|
|
|
135
143
|
// in-memory ledger below. The ledger is task/status/progress metadata and dies with the process;
|
|
136
144
|
// the conversation's parentConversationId/origin is what the sidebar's session tree redraws
|
|
137
145
|
// from after a restart, so it has to be the persistent record.
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
if (options.title) {
|
|
145
|
-
await this.conversationService.renameConversation(conversationId, options.title);
|
|
146
|
+
let conversationId;
|
|
147
|
+
if (source) {
|
|
148
|
+
const result = await this.conversationService.forkConversation(source.id, { parentConversationId: parent?.id });
|
|
149
|
+
if (!result.ok)
|
|
150
|
+
throw new Error(result.message);
|
|
151
|
+
conversationId = result.forkedId;
|
|
146
152
|
}
|
|
147
|
-
else
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
await this.conversationService.setAgent(conversationId, options.agentId);
|
|
153
|
+
else {
|
|
154
|
+
conversationId = await this.conversationService.createConversation(workspaceId, {
|
|
155
|
+
parentConversationId: options.parentConversationId,
|
|
156
|
+
origin: options.parentConversationId ? "orchestrator" : "user",
|
|
157
|
+
...(options.separateMemoryTree ? { separateMemoryTree: true } : {}),
|
|
158
|
+
}, cwd);
|
|
154
159
|
}
|
|
155
|
-
|
|
156
|
-
|
|
160
|
+
try {
|
|
161
|
+
if (options.title) {
|
|
162
|
+
await this.conversationService.renameConversation(conversationId, options.title);
|
|
163
|
+
}
|
|
164
|
+
else if (options.task) {
|
|
165
|
+
const titleSnippet = options.task.trim().replace(/\s+/g, " ").slice(0, 30);
|
|
166
|
+
await this.conversationService.renameConversation(conversationId, `任务:${titleSnippet}`);
|
|
167
|
+
}
|
|
168
|
+
if (options.agentId) {
|
|
169
|
+
await this.conversationService.setAgent(conversationId, options.agentId);
|
|
170
|
+
}
|
|
171
|
+
if (options.model) {
|
|
172
|
+
await this.conversationService.setModel(conversationId, options.model.provider, options.model.modelId);
|
|
173
|
+
}
|
|
174
|
+
if (options.thinkingLevel) {
|
|
175
|
+
await this.conversationService.setThinking(conversationId, options.thinkingLevel);
|
|
176
|
+
}
|
|
157
177
|
}
|
|
158
|
-
|
|
159
|
-
|
|
178
|
+
catch (error) {
|
|
179
|
+
if (source)
|
|
180
|
+
await this.remove(conversationId);
|
|
181
|
+
throw error;
|
|
160
182
|
}
|
|
161
183
|
// Register in relationship ledger
|
|
162
184
|
this.ledger.register({
|
|
@@ -205,6 +227,8 @@ export class SessionOrchestratorService {
|
|
|
205
227
|
if (!conversation) {
|
|
206
228
|
throw new Error(`找不到会话:${conversationId}`);
|
|
207
229
|
}
|
|
230
|
+
if (conversation.warmSession)
|
|
231
|
+
throw new Error("预热快照只能通过项目派发使用");
|
|
208
232
|
this.ledger.update(conversationId, {
|
|
209
233
|
status: "running",
|
|
210
234
|
});
|
|
@@ -871,6 +895,14 @@ export class SessionOrchestratorService {
|
|
|
871
895
|
descendantCount: descendants.length,
|
|
872
896
|
};
|
|
873
897
|
}
|
|
898
|
+
async removeWarmSession(conversationId) {
|
|
899
|
+
const conversation = this.store.conversation(conversationId);
|
|
900
|
+
if (!conversation)
|
|
901
|
+
return;
|
|
902
|
+
if (!conversation.warmSession)
|
|
903
|
+
throw new Error("只能通过此操作移除预热快照");
|
|
904
|
+
await this.remove(conversationId);
|
|
905
|
+
}
|
|
874
906
|
/**
|
|
875
907
|
* Permanently destroys a direct child session and its entire descendant subtree (stopping any
|
|
876
908
|
* running/queued turns first) and removes all transcripts, outputs, runs, and auxiliary state.
|
|
@@ -891,7 +923,7 @@ export class SessionOrchestratorService {
|
|
|
891
923
|
...(reason ? { reason } : {}),
|
|
892
924
|
};
|
|
893
925
|
}
|
|
894
|
-
if (!conversation.parentConversationId) {
|
|
926
|
+
if (!conversation.parentConversationId && !conversation.warmSession) {
|
|
895
927
|
throw new Error("顶层会话不能销毁,只能由用户归档。");
|
|
896
928
|
}
|
|
897
929
|
const descendants = this.descendantsOf(conversationId);
|
|
@@ -6,6 +6,7 @@ import type { ExtensionUiService } from "./application/extension-ui-service.js";
|
|
|
6
6
|
import type { CatalogService } from "./application/catalog-service.js";
|
|
7
7
|
import type { ProviderService } from "./application/provider-service.js";
|
|
8
8
|
import type { ScheduledTaskService } from "./application/scheduled-task-service.js";
|
|
9
|
+
import type { SessionOrchestratorService } from "./application/session-orchestrator-service.js";
|
|
9
10
|
import type { TerminalService } from "./terminal.js";
|
|
10
11
|
export type SocketSender = (event: ServerEvent) => void;
|
|
11
12
|
/**
|
|
@@ -34,6 +35,7 @@ export declare class CommandHandler {
|
|
|
34
35
|
* follows.
|
|
35
36
|
*/
|
|
36
37
|
private readonly scheduledTaskService?;
|
|
38
|
+
private readonly sessionOrchestratorService?;
|
|
37
39
|
/**
|
|
38
40
|
* The built-in terminal service.
|
|
39
41
|
*
|
|
@@ -57,7 +59,7 @@ export declare class CommandHandler {
|
|
|
57
59
|
* service has to say so rather than take the whole handler down - the same rule `providerService`
|
|
58
60
|
* follows.
|
|
59
61
|
*/
|
|
60
|
-
scheduledTaskService?: ScheduledTaskService | undefined);
|
|
62
|
+
scheduledTaskService?: ScheduledTaskService | undefined, sessionOrchestratorService?: SessionOrchestratorService | undefined);
|
|
61
63
|
/**
|
|
62
64
|
* Processes a client command.
|
|
63
65
|
*
|
|
@@ -15,6 +15,7 @@ export class CommandHandler {
|
|
|
15
15
|
rootDir;
|
|
16
16
|
providerService;
|
|
17
17
|
scheduledTaskService;
|
|
18
|
+
sessionOrchestratorService;
|
|
18
19
|
/**
|
|
19
20
|
* The built-in terminal service.
|
|
20
21
|
*
|
|
@@ -38,7 +39,7 @@ export class CommandHandler {
|
|
|
38
39
|
* service has to say so rather than take the whole handler down - the same rule `providerService`
|
|
39
40
|
* follows.
|
|
40
41
|
*/
|
|
41
|
-
scheduledTaskService) {
|
|
42
|
+
scheduledTaskService, sessionOrchestratorService) {
|
|
42
43
|
this.workspaceService = workspaceService;
|
|
43
44
|
this.conversationService = conversationService;
|
|
44
45
|
this.runService = runService;
|
|
@@ -47,6 +48,7 @@ export class CommandHandler {
|
|
|
47
48
|
this.rootDir = rootDir;
|
|
48
49
|
this.providerService = providerService;
|
|
49
50
|
this.scheduledTaskService = scheduledTaskService;
|
|
51
|
+
this.sessionOrchestratorService = sessionOrchestratorService;
|
|
50
52
|
this.terminalService = terminalService;
|
|
51
53
|
}
|
|
52
54
|
/**
|
|
@@ -76,6 +78,10 @@ export class CommandHandler {
|
|
|
76
78
|
this.conversationService.releaseRevert(conversationId);
|
|
77
79
|
}
|
|
78
80
|
async handleCommand(command, sendToSocket, remoteAddress) {
|
|
81
|
+
if ("conversationId" in command && typeof command.conversationId === "string"
|
|
82
|
+
&& command.type !== "conversation.warm.delete" && this.conversationService.isWarmSession?.(command.conversationId)) {
|
|
83
|
+
throw new Error("预热快照只能通过项目派发使用");
|
|
84
|
+
}
|
|
79
85
|
if (command.type === "terminal.shell.set") {
|
|
80
86
|
if (!this.terminalService || !(await this.terminalService.setShell(command.command, remoteAddress)))
|
|
81
87
|
return;
|
|
@@ -235,6 +241,20 @@ export class CommandHandler {
|
|
|
235
241
|
}
|
|
236
242
|
return;
|
|
237
243
|
}
|
|
244
|
+
if (command.type === "conversation.warm.save") {
|
|
245
|
+
if (typeof command.title !== "string")
|
|
246
|
+
throw new Error("请输入预热会话名称");
|
|
247
|
+
const result = await this.conversationService.forkConversation(command.conversationId, { warmTitle: command.title });
|
|
248
|
+
if (!result.ok)
|
|
249
|
+
throw new Error(result.message);
|
|
250
|
+
return;
|
|
251
|
+
}
|
|
252
|
+
if (command.type === "conversation.warm.delete") {
|
|
253
|
+
if (!this.sessionOrchestratorService)
|
|
254
|
+
throw new Error("会话编排服务未就绪");
|
|
255
|
+
await this.sessionOrchestratorService.removeWarmSession(command.conversationId);
|
|
256
|
+
return;
|
|
257
|
+
}
|
|
238
258
|
if (command.type === "conversation.model") {
|
|
239
259
|
await this.conversationService.setModel(command.conversationId, command.provider, command.modelId);
|
|
240
260
|
return;
|
package/dist/server/index.js
CHANGED
|
@@ -277,7 +277,7 @@ runService.setFileIndexes(fileIndexes);
|
|
|
277
277
|
*/
|
|
278
278
|
const nameIndexes = new Map();
|
|
279
279
|
runService.setNameIndexes(nameIndexes);
|
|
280
|
-
const conversationService = new ConversationService(store, runtime, subagents, broadcaster, catalogService, runService, extensionUiService, initialAgentDirs);
|
|
280
|
+
const conversationService = new ConversationService(store, runtime, subagents, broadcaster, catalogService, runService, extensionUiService, initialAgentDirs, uploadsDir);
|
|
281
281
|
conversationService.setMemory(memory);
|
|
282
282
|
const workspaceService = new WorkspaceService(store, runtime, broadcaster, catalogService, runService, extensionUiService, initialAgentDirs);
|
|
283
283
|
/**
|
|
@@ -360,7 +360,7 @@ const serverContext = {
|
|
|
360
360
|
terminalEnabled: () => terminalService.enabled,
|
|
361
361
|
terminalDisabledReason: () => terminalDisabledReason(),
|
|
362
362
|
};
|
|
363
|
-
const commandHandler = new CommandHandler(workspaceService, conversationService, runService, extensionUiService, catalogService, terminalService, rootDir, providerService, scheduledTaskService);
|
|
363
|
+
const commandHandler = new CommandHandler(workspaceService, conversationService, runService, extensionUiService, catalogService, terminalService, rootDir, providerService, scheduledTaskService, sessionOrchestratorService);
|
|
364
364
|
// ------------------------------------------------------------- Lifecycle & shutdown
|
|
365
365
|
let shutdownPromise;
|
|
366
366
|
async function closeHttpServer() {
|
package/dist/server/store.d.ts
CHANGED
|
@@ -304,6 +304,8 @@ export declare class Store {
|
|
|
304
304
|
* for a message that was never allowed to be sent.
|
|
305
305
|
*/
|
|
306
306
|
childLockUnlocked(conversationId: string): boolean;
|
|
307
|
+
listWarmSessions(workspaceId: string): NonNullable<AppState["warmSessions"]>;
|
|
308
|
+
isWarmSession(conversationId: string): boolean;
|
|
307
309
|
/**
|
|
308
310
|
* Opens (or re-closes) one child session's composer, and persists it.
|
|
309
311
|
*
|
|
@@ -371,7 +373,11 @@ export declare class Store {
|
|
|
371
373
|
* (`byRecency`) puts a fork at the TOP of its workspace group, because `updatedAt` is now - which is the
|
|
372
374
|
* same position a newly created conversation takes, and the same reason.
|
|
373
375
|
*/
|
|
374
|
-
forkConversation(sourceConversationId: string, forkedConversationId: string
|
|
376
|
+
forkConversation(sourceConversationId: string, forkedConversationId: string, options?: {
|
|
377
|
+
parentConversationId?: string;
|
|
378
|
+
warmTitle?: string;
|
|
379
|
+
piSessionFile?: string;
|
|
380
|
+
}): Promise<Conversation>;
|
|
375
381
|
/**
|
|
376
382
|
* Archive is a marker, not a move: the conversation keeps its id, workspace, messages and position.
|
|
377
383
|
* `updatedAt` is deliberately NOT touched, because it drives the sidebar's live timestamp and recency -
|
package/dist/server/store.js
CHANGED
|
@@ -690,6 +690,17 @@ export class Store {
|
|
|
690
690
|
delete state.scheduledTasks;
|
|
691
691
|
if (state.projects !== undefined && !Array.isArray(state.projects))
|
|
692
692
|
delete state.projects;
|
|
693
|
+
let migratedProjects = false;
|
|
694
|
+
for (const project of state.projects ?? []) {
|
|
695
|
+
if (String(project.status) !== "completed")
|
|
696
|
+
continue;
|
|
697
|
+
project.status = project.ownerConversationId ? "active" : "awaiting_start";
|
|
698
|
+
const delivery = [...(project.reports ?? [])].reverse().find((report) => report.kind === "delivery" && !report.taskId);
|
|
699
|
+
if (delivery && !delivery.createdAt)
|
|
700
|
+
delivery.createdAt = project.closedAt ?? project.updatedAt;
|
|
701
|
+
delete project.closedAt;
|
|
702
|
+
migratedProjects = true;
|
|
703
|
+
}
|
|
693
704
|
// Every sweep runs before the store is constructed, so a single persist below publishes them together.
|
|
694
705
|
// Reconciling them in separate writes would put a file on disk in which one kind of orphan was fixed
|
|
695
706
|
// and the other was not - a half-repaired state that still needs a second restart to finish.
|
|
@@ -707,7 +718,7 @@ export class Store {
|
|
|
707
718
|
// Persisted here, in `open`, rather than left for the first unrelated write: a reconciled record that
|
|
708
719
|
// is only rewritten by a later mutation would still read `running` to anything that opened the file
|
|
709
720
|
// in the meantime, and would be reconciled a SECOND time on the next restart.
|
|
710
|
-
if (defaulted || orphaned.length || orphanedWorkflows.length || orphanedTasks.changed || interrupted.length || requeued.recovered.length || requeued.changed || todos.changed || foldedUsage) {
|
|
721
|
+
if (defaulted || migratedProjects || orphaned.length || orphanedWorkflows.length || orphanedTasks.changed || interrupted.length || requeued.recovered.length || requeued.changed || todos.changed || foldedUsage) {
|
|
711
722
|
for (const run of orphaned)
|
|
712
723
|
console.warn(`Super Pi: sub-agent run ${run.id} was still marked running when the last server stopped - it is now failed, because no child process survived it.`);
|
|
713
724
|
for (const plan of orphanedWorkflows)
|
|
@@ -923,7 +934,7 @@ export class Store {
|
|
|
923
934
|
conversationsForWorkspace(workspaceId) {
|
|
924
935
|
const openEscalations = this.openEscalationConversationIds();
|
|
925
936
|
const pendingResults = this.pendingResultConversationIds();
|
|
926
|
-
return structuredClone(this.state.conversations.filter((item) => item.workspaceId === workspaceId)).map((c) => {
|
|
937
|
+
return structuredClone(this.state.conversations.filter((item) => item.workspaceId === workspaceId && !item.warmSession)).map((c) => {
|
|
927
938
|
const hasOpenEscalation = openEscalations.has(c.id);
|
|
928
939
|
const hasPendingResult = pendingResults.has(c.id);
|
|
929
940
|
if (!hasOpenEscalation && !hasPendingResult)
|
|
@@ -1199,7 +1210,9 @@ export class Store {
|
|
|
1199
1210
|
const { projects: _projects, ...publicState } = this.state;
|
|
1200
1211
|
const closed = new Set(this.state.workspaces.filter((item) => item.closedAt).map((item) => item.id));
|
|
1201
1212
|
const workspaces = this.state.workspaces.filter((item) => !closed.has(item.id));
|
|
1202
|
-
const visible = this.state.conversations.filter((item) => !closed.has(item.workspaceId));
|
|
1213
|
+
const visible = this.state.conversations.filter((item) => !closed.has(item.workspaceId) && !item.warmSession);
|
|
1214
|
+
const warmSessions = workspaces.flatMap((workspace) => this.listWarmSessions(workspace.id));
|
|
1215
|
+
const presets = warmSessions.length ? { warmSessions } : {};
|
|
1203
1216
|
const openEscalations = this.openEscalationConversationIds();
|
|
1204
1217
|
const pendingResults = this.pendingResultConversationIds();
|
|
1205
1218
|
// Legacy sockets still receive complete visible transcripts. Project before cloning so a closed
|
|
@@ -1207,6 +1220,7 @@ export class Store {
|
|
|
1207
1220
|
if (scope === undefined) {
|
|
1208
1221
|
return structuredClone({
|
|
1209
1222
|
...publicState,
|
|
1223
|
+
...presets,
|
|
1210
1224
|
workspaces,
|
|
1211
1225
|
conversations: visible.map((c) => {
|
|
1212
1226
|
const hasOpenEscalation = openEscalations.has(c.id);
|
|
@@ -1235,6 +1249,7 @@ export class Store {
|
|
|
1235
1249
|
}));
|
|
1236
1250
|
return structuredClone({
|
|
1237
1251
|
...publicState,
|
|
1252
|
+
...presets,
|
|
1238
1253
|
workspaces,
|
|
1239
1254
|
conversations,
|
|
1240
1255
|
// THE CLOCK THE SERVER SCHEDULES BY, NAMED. The scheduled-task panel renders 「每天 09:00」 and
|
|
@@ -1356,6 +1371,13 @@ export class Store {
|
|
|
1356
1371
|
childLockUnlocked(conversationId) {
|
|
1357
1372
|
return Boolean(this.state.unlockedChildConversationIds?.includes(conversationId));
|
|
1358
1373
|
}
|
|
1374
|
+
listWarmSessions(workspaceId) {
|
|
1375
|
+
return this.state.conversations.filter((item) => item.warmSession && item.workspaceId === workspaceId)
|
|
1376
|
+
.map(({ id, title, workspaceId, cwd, archivedAt, updatedAt }) => ({ id, title, workspaceId, cwd, savedAt: archivedAt ?? updatedAt }));
|
|
1377
|
+
}
|
|
1378
|
+
isWarmSession(conversationId) {
|
|
1379
|
+
return this.state.conversations.some((item) => item.id === conversationId && item.warmSession);
|
|
1380
|
+
}
|
|
1359
1381
|
/**
|
|
1360
1382
|
* Opens (or re-closes) one child session's composer, and persists it.
|
|
1361
1383
|
*
|
|
@@ -1445,14 +1467,21 @@ export class Store {
|
|
|
1445
1467
|
* (`byRecency`) puts a fork at the TOP of its workspace group, because `updatedAt` is now - which is the
|
|
1446
1468
|
* same position a newly created conversation takes, and the same reason.
|
|
1447
1469
|
*/
|
|
1448
|
-
async forkConversation(sourceConversationId, forkedConversationId) {
|
|
1470
|
+
async forkConversation(sourceConversationId, forkedConversationId, options = {}) {
|
|
1449
1471
|
const source = this.requireConversation(sourceConversationId);
|
|
1450
1472
|
if (source.id === forkedConversationId)
|
|
1451
1473
|
throw new Error("Cannot fork a conversation into itself");
|
|
1474
|
+
const parent = options.parentConversationId ? this.requireConversation(options.parentConversationId) : undefined;
|
|
1475
|
+
if (parent && (parent.workspaceId !== source.workspaceId || parent.archivedAt || (!source.warmSession && source.parentConversationId !== parent.id))) {
|
|
1476
|
+
throw new Error("分叉会话必须与来源保留同一个直属上级和工作区");
|
|
1477
|
+
}
|
|
1452
1478
|
const conversation = {
|
|
1453
1479
|
id: forkedConversationId,
|
|
1454
|
-
treeId: forkedConversationId,
|
|
1455
|
-
|
|
1480
|
+
treeId: parent ? memoryTreeId(source.warmSession ? parent : source, this.state.conversations) : forkedConversationId,
|
|
1481
|
+
...(parent ? { parentConversationId: parent.id, origin: "orchestrator" } : {}),
|
|
1482
|
+
...(options.warmTitle ? { warmSession: true, archivedAt: now() } : {}),
|
|
1483
|
+
...(options.piSessionFile ? { piSessionFile: options.piSessionFile } : {}),
|
|
1484
|
+
title: options.warmTitle ?? source.title,
|
|
1456
1485
|
workspaceId: source.workspaceId,
|
|
1457
1486
|
updatedAt: now(),
|
|
1458
1487
|
status: "idle",
|
|
@@ -1475,7 +1504,13 @@ export class Store {
|
|
|
1475
1504
|
if (source.cwd)
|
|
1476
1505
|
conversation.cwd = source.cwd;
|
|
1477
1506
|
this.state.conversations.unshift(conversation);
|
|
1478
|
-
|
|
1507
|
+
try {
|
|
1508
|
+
await this.persist();
|
|
1509
|
+
}
|
|
1510
|
+
catch (error) {
|
|
1511
|
+
this.state.conversations = this.state.conversations.filter((item) => item.id !== conversation.id);
|
|
1512
|
+
throw error;
|
|
1513
|
+
}
|
|
1479
1514
|
return structuredClone(conversation);
|
|
1480
1515
|
}
|
|
1481
1516
|
/**
|
|
@@ -1501,6 +1536,8 @@ export class Store {
|
|
|
1501
1536
|
* byte-identically to one that was never archived. `delete` is legal here because the field is optional. */
|
|
1502
1537
|
async unarchiveConversation(conversationId) {
|
|
1503
1538
|
const conversation = this.requireConversation(conversationId);
|
|
1539
|
+
if (conversation.warmSession)
|
|
1540
|
+
throw new Error("预热快照只能通过项目派发使用");
|
|
1504
1541
|
if (!conversation.archivedAt)
|
|
1505
1542
|
return;
|
|
1506
1543
|
delete conversation.archivedAt;
|
|
@@ -1530,6 +1567,8 @@ export class Store {
|
|
|
1530
1567
|
/** Restores one archived tree in one write; active descendants are already restored by definition. */
|
|
1531
1568
|
async unarchiveConversationTree(conversationId) {
|
|
1532
1569
|
const root = this.requireConversation(conversationId);
|
|
1570
|
+
if (root.warmSession)
|
|
1571
|
+
throw new Error("预热快照只能通过项目派发使用");
|
|
1533
1572
|
const parent = root.parentConversationId
|
|
1534
1573
|
? this.state.conversations.find(item => item.id === root.parentConversationId)
|
|
1535
1574
|
: undefined;
|
|
@@ -1562,7 +1601,7 @@ export class Store {
|
|
|
1562
1601
|
const root = this.state.conversations.find((item) => item.id === conversationId);
|
|
1563
1602
|
if (!root)
|
|
1564
1603
|
return { destroyed: [] };
|
|
1565
|
-
if (!root.parentConversationId) {
|
|
1604
|
+
if (!root.parentConversationId && !root.warmSession) {
|
|
1566
1605
|
throw new Error("顶层会话不能销毁,只能由用户归档。");
|
|
1567
1606
|
}
|
|
1568
1607
|
const subtree = this.conversationSubtree(root);
|
package/dist/server/types.d.ts
CHANGED
|
@@ -491,6 +491,7 @@ export type Conversation = {
|
|
|
491
491
|
status: RunStatus;
|
|
492
492
|
messages: Message[];
|
|
493
493
|
archivedAt?: string;
|
|
494
|
+
warmSession?: true;
|
|
494
495
|
/**
|
|
495
496
|
* Cumulative usage observed for this conversation: its OWN assistant messages AND the one-shot
|
|
496
497
|
* (sub-agent) calls it dispatched.
|
|
@@ -980,7 +981,7 @@ export type TerminalShell = {
|
|
|
980
981
|
file: string;
|
|
981
982
|
args: string[];
|
|
982
983
|
};
|
|
983
|
-
export type ProjectStatus = "planning" | "awaiting_start" | "active" | "blocked" | "awaiting_approval" | "awaiting_review" | "
|
|
984
|
+
export type ProjectStatus = "planning" | "awaiting_start" | "active" | "blocked" | "awaiting_approval" | "awaiting_review" | "failed" | "cancelled";
|
|
984
985
|
/**
|
|
985
986
|
* THE STATES A TASK CAN BE IN.
|
|
986
987
|
*
|
|
@@ -1074,6 +1075,7 @@ export type ProjectReport = {
|
|
|
1074
1075
|
id: string;
|
|
1075
1076
|
projectId: string;
|
|
1076
1077
|
taskId?: string;
|
|
1078
|
+
acceptedTaskIds?: string[];
|
|
1077
1079
|
authorConversationId?: string;
|
|
1078
1080
|
kind: "progress" | "blocked" | "delivery" | "decision_request" | "review";
|
|
1079
1081
|
progress: string;
|
|
@@ -1248,6 +1250,13 @@ export type AppState = {
|
|
|
1248
1250
|
* decision nobody has made yet.
|
|
1249
1251
|
*/
|
|
1250
1252
|
unlockedChildConversationIds?: string[];
|
|
1253
|
+
warmSessions?: Array<{
|
|
1254
|
+
id: string;
|
|
1255
|
+
title: string;
|
|
1256
|
+
workspaceId: string;
|
|
1257
|
+
cwd?: string;
|
|
1258
|
+
savedAt: string;
|
|
1259
|
+
}>;
|
|
1251
1260
|
/**
|
|
1252
1261
|
* THE CLOCK THIS SERVER SCHEDULES BY. A scheduled task's 「每天 09:00」 is the SERVER's wall clock,
|
|
1253
1262
|
* and the panel has to say so, because browser rendering 「下次」 may be on a different clock
|
|
@@ -1559,6 +1568,13 @@ export type ClientCommandBody =
|
|
|
1559
1568
|
} | {
|
|
1560
1569
|
type: "conversation.archive";
|
|
1561
1570
|
conversationId: string;
|
|
1571
|
+
} | {
|
|
1572
|
+
type: "conversation.warm.save";
|
|
1573
|
+
conversationId: string;
|
|
1574
|
+
title: string;
|
|
1575
|
+
} | {
|
|
1576
|
+
type: "conversation.warm.delete";
|
|
1577
|
+
conversationId: string;
|
|
1562
1578
|
} | {
|
|
1563
1579
|
type: "conversation.unarchive";
|
|
1564
1580
|
conversationId: string;
|
package/dist/server/upload.d.ts
CHANGED
|
@@ -30,4 +30,6 @@ export declare function findUploadFile(uploadsDir: string, conversationId: strin
|
|
|
30
30
|
size: number;
|
|
31
31
|
} | null>;
|
|
32
32
|
export declare function deleteConversationUploads(uploadsDir: string, conversationId: string): Promise<void>;
|
|
33
|
+
/** Gives each fork its own copy of the local images referenced by its history. */
|
|
34
|
+
export declare function copyForkUploads(uploadsDir: string, conversationId: string, forkedId: string, images: MessageImage[]): Promise<void>;
|
|
33
35
|
export declare function loadConversationImages(uploadsDir: string, conversationId: string, images: MessageImage[]): Promise<PiImageContent[]>;
|
package/dist/server/upload.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { existsSync } from "node:fs";
|
|
2
|
-
import { mkdir, readdir, readFile, rm, stat, writeFile } from "node:fs/promises";
|
|
3
|
-
import { extname, join } from "node:path";
|
|
2
|
+
import { copyFile, mkdir, readdir, readFile, realpath, rm, stat, writeFile } from "node:fs/promises";
|
|
3
|
+
import { basename, extname, isAbsolute, join, relative, sep } from "node:path";
|
|
4
4
|
/** 5MB maximum decoded image payload, matching the source-file size ceiling in files.ts. */
|
|
5
5
|
export const MAX_UPLOAD_BYTES = 5 * 1024 * 1024;
|
|
6
6
|
/** 10MB maximum HTTP request body to safely handle base64 overhead before JSON parsing. */
|
|
@@ -141,6 +141,23 @@ export async function deleteConversationUploads(uploadsDir, conversationId) {
|
|
|
141
141
|
const dir = join(uploadsDir, conversationId);
|
|
142
142
|
await rm(dir, { recursive: true, force: true }).catch(() => { });
|
|
143
143
|
}
|
|
144
|
+
/** Gives each fork its own copy of the local images referenced by its history. */
|
|
145
|
+
export async function copyForkUploads(uploadsDir, conversationId, forkedId, images) {
|
|
146
|
+
const root = await realpath(uploadsDir);
|
|
147
|
+
const target = join(root, forkedId);
|
|
148
|
+
await mkdir(target);
|
|
149
|
+
for (const id of new Set(images.map((image) => image.id))) {
|
|
150
|
+
const file = await findUploadFile(root, conversationId, id);
|
|
151
|
+
if (!file)
|
|
152
|
+
throw new Error("无法找到历史消息的附件,分叉未保存");
|
|
153
|
+
const source = await realpath(file.filePath);
|
|
154
|
+
const scoped = relative(join(root, conversationId), source);
|
|
155
|
+
if (!scoped || scoped === ".." || scoped.startsWith(`..${sep}`) || isAbsolute(scoped)) {
|
|
156
|
+
throw new Error("历史附件越出了上传目录,分叉未保存");
|
|
157
|
+
}
|
|
158
|
+
await copyFile(source, join(target, basename(file.filePath)));
|
|
159
|
+
}
|
|
160
|
+
}
|
|
144
161
|
export async function loadConversationImages(uploadsDir, conversationId, images) {
|
|
145
162
|
const result = [];
|
|
146
163
|
for (const img of images) {
|
|
@@ -6,6 +6,7 @@ export type OverviewReport = {
|
|
|
6
6
|
progress?: string;
|
|
7
7
|
summary?: string;
|
|
8
8
|
evidenceRefs?: string[];
|
|
9
|
+
acceptedTaskIds?: string[];
|
|
9
10
|
createdAt?: string;
|
|
10
11
|
};
|
|
11
12
|
export type OverviewDecision = {
|
|
@@ -39,6 +40,14 @@ export type OverviewProject = {
|
|
|
39
40
|
/** Internal coordination is not a request for the user's attention. */
|
|
40
41
|
export declare function userProjectDecisions(project: OverviewProject): OverviewDecision[];
|
|
41
42
|
export declare function ownerProjectReports(project: OverviewProject): OverviewReport[];
|
|
43
|
+
export declare function latestProjectDelivery<T extends OverviewReport>(project: {
|
|
44
|
+
ownerConversationId?: string;
|
|
45
|
+
reports?: T[];
|
|
46
|
+
}): T | undefined;
|
|
47
|
+
export declare function deliveryCoversTasks(delivery: OverviewReport | undefined, tasks: {
|
|
48
|
+
id: string;
|
|
49
|
+
updatedAt?: string;
|
|
50
|
+
}[]): boolean;
|
|
42
51
|
export declare function projectUserOverview(project: OverviewProject): {
|
|
43
52
|
label: string;
|
|
44
53
|
summary: string;
|
|
@@ -5,20 +5,34 @@ export function userProjectDecisions(project) {
|
|
|
5
5
|
export function ownerProjectReports(project) {
|
|
6
6
|
return (project.reports ?? []).filter(report => !report.taskId && ["progress", "delivery"].includes(report.kind ?? "")
|
|
7
7
|
&& (report.authorConversationId === project.ownerConversationId && Boolean(project.ownerConversationId)
|
|
8
|
-
||
|
|
8
|
+
|| report.kind === "delivery" && !report.authorConversationId));
|
|
9
|
+
}
|
|
10
|
+
export function latestProjectDelivery(project) {
|
|
11
|
+
return [...(project.reports ?? [])].reverse().find(report => report.kind === "delivery" && !report.taskId
|
|
12
|
+
&& (!report.authorConversationId || report.authorConversationId === project.ownerConversationId));
|
|
13
|
+
}
|
|
14
|
+
export function deliveryCoversTasks(delivery, tasks) {
|
|
15
|
+
if (!delivery)
|
|
16
|
+
return false;
|
|
17
|
+
if (delivery.acceptedTaskIds) {
|
|
18
|
+
const accepted = new Set(delivery.acceptedTaskIds);
|
|
19
|
+
return tasks.every(task => accepted.has(task.id));
|
|
20
|
+
}
|
|
21
|
+
const deliveredAt = delivery.createdAt ? Date.parse(delivery.createdAt) : NaN;
|
|
22
|
+
return Number.isFinite(deliveredAt) && tasks.every(task => !task.updatedAt || Date.parse(task.updatedAt) <= deliveredAt);
|
|
9
23
|
}
|
|
10
24
|
export function projectUserOverview(project) {
|
|
11
25
|
const decisions = userProjectDecisions(project);
|
|
12
26
|
const reports = ownerProjectReports(project);
|
|
13
27
|
const progress = [...reports].reverse().find(report => report.kind === "progress");
|
|
14
|
-
const delivery =
|
|
15
|
-
const ended = ["
|
|
28
|
+
const delivery = latestProjectDelivery(project);
|
|
29
|
+
const ended = ["cancelled", "failed"].includes(project.status);
|
|
16
30
|
const owner = project.resources?.sessions?.find(session => session.id === project.ownerConversationId);
|
|
17
31
|
const busy = (project.resources?.activeWorkers ?? 0) > 0 || ["running", "waiting", "awaiting_background"].includes(owner?.status ?? "");
|
|
18
|
-
const label = project.status === "
|
|
19
|
-
: decisions.length ? "需要你决定" : busy ? "正在推进" : !project.ownerConversationId ? "待启动" : ["failed", "stopped"].includes(owner?.status ?? "") ? "执行暂停" : "未交付";
|
|
20
|
-
const summary =
|
|
21
|
-
:
|
|
32
|
+
const label = project.status === "cancelled" ? "已取消" : project.status === "failed" ? "执行暂停"
|
|
33
|
+
: decisions.length ? "需要你决定" : busy ? "正在推进" : !project.ownerConversationId ? "待启动" : ["failed", "stopped"].includes(owner?.status ?? "") ? "执行暂停" : delivery ? "待继续" : "未交付";
|
|
34
|
+
const summary = progress?.progress?.trim() || progress?.summary?.trim() || (ended ? "项目已结束,已有记录会保留。"
|
|
35
|
+
: delivery ? "可继续安排新任务或追加验证。" : "已交由负责人推进,进展和成果会在这里汇总。");
|
|
22
36
|
return { label, summary, progress, delivery, decisions, ended,
|
|
23
37
|
deliveryLabel: project.mode === "lightweight" ? "自评交付" : "交付成果" };
|
|
24
38
|
}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { type OverviewReport } from "./project-overview.js";
|
|
1
2
|
/** Business phases are persisted; activity is a read-only projection of current execution. */
|
|
2
3
|
export type ProjectActivity = {
|
|
3
4
|
kind: string;
|
|
@@ -19,6 +20,7 @@ export type ActivityTask = {
|
|
|
19
20
|
ownerConversationId?: string;
|
|
20
21
|
reviewerConversationId?: string;
|
|
21
22
|
dependencies?: string[];
|
|
23
|
+
updatedAt?: string;
|
|
22
24
|
review?: {
|
|
23
25
|
verdict?: string;
|
|
24
26
|
lightweight?: boolean;
|
|
@@ -29,6 +31,7 @@ export type ActivityProject = {
|
|
|
29
31
|
mode?: string;
|
|
30
32
|
ownerConversationId?: string;
|
|
31
33
|
tasks?: ActivityTask[];
|
|
34
|
+
reports?: OverviewReport[];
|
|
32
35
|
resources?: {
|
|
33
36
|
activeWorkers?: number;
|
|
34
37
|
sessions?: ActivitySession[];
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { deliveryCoversTasks, latestProjectDelivery } from "./project-overview.js";
|
|
1
2
|
export const PROJECT_PHASE_WORDS = {
|
|
2
3
|
draft: "待澄清", planning: "待规划", planned: "已规划", awaiting_start: "待启动", active: "进行中",
|
|
3
4
|
pending: "等待依赖", ready: "待派发", assigned: "已委派", in_progress: "执行阶段", interrupted: "已中断",
|
|
@@ -21,6 +22,8 @@ export function deriveTaskActivity(task, sessions = [], mode = "standard", tasks
|
|
|
21
22
|
case "failed": return activity("failed", "失败", "由直属负责人核对失败原因");
|
|
22
23
|
case "cancelled": return activity("cancelled", "已取消", "保留已有记录");
|
|
23
24
|
case "completed":
|
|
25
|
+
if (projectSessionBusy(session?.status) || projectSessionBusy(reviewer?.status))
|
|
26
|
+
return activity("iterating", "正在继续迭代", "继续原会话,已有验收记录保留");
|
|
24
27
|
if (task.review?.lightweight || mode === "lightweight" && task.review?.verdict === "accepted")
|
|
25
28
|
return activity("self_delivered", "自评交付", "按轻量项目口径汇总");
|
|
26
29
|
if (mode !== "lightweight" && task.review?.verdict === "accepted")
|
|
@@ -57,7 +60,7 @@ export function deriveTaskActivity(task, sessions = [], mode = "standard", tasks
|
|
|
57
60
|
}
|
|
58
61
|
}
|
|
59
62
|
export function deriveProjectActivity(project) {
|
|
60
|
-
if (["
|
|
63
|
+
if (["cancelled", "failed"].includes(project.status))
|
|
61
64
|
return activity(project.status, projectPhaseWord(project.status), "查看交付与项目记录");
|
|
62
65
|
if (["blocked", "awaiting_approval"].includes(project.status))
|
|
63
66
|
return activity(project.status, projectPhaseWord(project.status), "由项目负责人处理阻塞与升级");
|
|
@@ -66,15 +69,20 @@ export function deriveProjectActivity(project) {
|
|
|
66
69
|
const leader = sessions.find(session => session.id === project.ownerConversationId);
|
|
67
70
|
if (!project.ownerConversationId)
|
|
68
71
|
return activity(tasks.length ? "awaiting_start" : "planning", tasks.length ? "待启动" : "待规划", "由负责人启动项目并安排任务");
|
|
69
|
-
if (tasks.length && tasks.every(task => task.required === false || task.status === "completed")) {
|
|
70
|
-
return activity(projectSessionBusy(leader?.status) ? "summarizing" : "ready_to_close", projectSessionBusy(leader?.status) ? "汇总交付中" : "待汇总交付", "由项目负责人提交最终交付并关闭项目");
|
|
71
|
-
}
|
|
72
72
|
const activities = tasks.map(task => deriveTaskActivity(task, sessions, project.mode, tasks));
|
|
73
|
-
const live = activities.find(item => ["executing", "reviewing", "queued", "review_queued", "background", "review_background"].includes(item.kind));
|
|
73
|
+
const live = activities.find(item => ["executing", "reviewing", "queued", "review_queued", "background", "review_background", "iterating"].includes(item.kind));
|
|
74
74
|
if (live)
|
|
75
75
|
return live;
|
|
76
76
|
if ((project.resources?.activeWorkers ?? 0) > 0 && !sessions.some(session => projectSessionBusy(session.status)))
|
|
77
77
|
return activity("background", "等待后台结果", "等待项目内的一次性调用返回结果");
|
|
78
|
+
const required = tasks.filter(task => task.required !== false);
|
|
79
|
+
if (required.length && required.every(task => task.status === "completed")) {
|
|
80
|
+
if (!deliveryCoversTasks(latestProjectDelivery(project), required)) {
|
|
81
|
+
return activity(projectSessionBusy(leader?.status) ? "summarizing" : "ready_to_deliver", projectSessionBusy(leader?.status) ? "汇总交付中" : "待汇总交付", "由项目负责人记录本阶段交付");
|
|
82
|
+
}
|
|
83
|
+
if (!projectSessionBusy(leader?.status))
|
|
84
|
+
return activity("ready_for_iteration", "待继续", "可继续安排任务或补充验证");
|
|
85
|
+
}
|
|
78
86
|
if (projectSessionBusy(leader?.status))
|
|
79
87
|
return activity("coordinating", "协调中", "项目负责人正在安排后续工作");
|
|
80
88
|
const awaiting = activities.find(item => ["awaiting_delivery", "awaiting_review_result", "review_interrupted", "awaiting_review_assignment", "interrupted", "awaiting_subordinates", "blocked", "ready", "waiting_dependency"].includes(item.kind));
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
export type TeamContextKind = "finding" | "decision" | "pitfall" | "hypothesis";
|
|
2
2
|
export type CoordinationHint = {
|
|
3
|
-
action: "dispatch" | "message" | "request_review" | "resolve_escalation" | "
|
|
3
|
+
action: "dispatch" | "message" | "request_review" | "resolve_escalation" | "deliver";
|
|
4
4
|
taskId?: string;
|
|
5
5
|
escalationId?: string;
|
|
6
6
|
targetConversationId?: string;
|