@evandu/super-pi 0.1.218 → 0.1.220
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-DLESYIdU.js} +2 -2
- package/dist/client/assets/{dist-xAE0Sxu_.js → dist-2Gv721yB.js} +1 -1
- package/dist/client/assets/{dist-CWLwzCNI.js → dist-B-63MNT9.js} +1 -1
- package/dist/client/assets/{dist-BQ5yUYGI.js → dist-B-ydE4PJ.js} +1 -1
- package/dist/client/assets/{dist-BfAB10-T.js → dist-B6UYFWUo.js} +1 -1
- package/dist/client/assets/{dist-GMozZ-IZ.js → dist-BG1xVEUu.js} +1 -1
- package/dist/client/assets/{dist-C6tiomV0.js → dist-BTUuXAFG.js} +1 -1
- package/dist/client/assets/{dist-Zl8KoipB.js → dist-Bz37bm03.js} +1 -1
- package/dist/client/assets/{dist-BwQiVXeZ.js → dist-CQAWuaHA.js} +1 -1
- package/dist/client/assets/{dist-XNj0UVAT.js → dist-CYEoLBJJ.js} +1 -1
- package/dist/client/assets/{dist-CkjmcyTq.js → dist-CbixgvA8.js} +1 -1
- package/dist/client/assets/{dist-DHh4-Br1.js → dist-CoC8iHD1.js} +1 -1
- package/dist/client/assets/{dist-DtyV497P.js → dist-CrtcsyOg.js} +1 -1
- package/dist/client/assets/{dist-BlALlifb.js → dist-D0Mff5_O.js} +1 -1
- package/dist/client/assets/{dist-BXMYNRiG.js → dist-DKRxalqK.js} +1 -1
- package/dist/client/assets/{dist-Cgclz1Km.js → dist-DPvgTEV_.js} +1 -1
- package/dist/client/assets/{dist-C9qNY2Kp.js → dist-DhCNXN4F.js} +1 -1
- package/dist/client/assets/{dist-BXq9HMCd.js → dist-DmraLEb2.js} +1 -1
- package/dist/client/assets/{dist-B33BwR-8.js → dist-DvJTvgiN.js} +1 -1
- package/dist/client/assets/{dist-C7y8W3IU.js → dist-YSB8UKj7.js} +1 -1
- package/dist/client/assets/{dist-1djw1Aua.js → dist-aDKso4tk.js} +1 -1
- package/dist/client/assets/{dist-DH6F4kKv.js → dist-h8QFV1py.js} +1 -1
- package/dist/client/assets/{dist-DZGY_CNU.js → dist-hyn4QSU9.js} +1 -1
- package/dist/client/assets/index-B-h_KnC5.css +1 -0
- package/dist/client/assets/{index-2k9h0zMt.js → index-BMuvJCSx.js} +11 -11
- 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 +53 -5
- package/dist/server/application/project-service.js +167 -36
- package/dist/server/application/run-service.d.ts +3 -1
- package/dist/server/application/run-service.js +22 -5
- package/dist/server/application/session-orchestrator-service.d.ts +65 -0
- package/dist/server/application/session-orchestrator-service.js +175 -22
- package/dist/server/application/session-reminder-service.js +1 -2
- 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/runtime.js +2 -2
- package/dist/server/store.d.ts +17 -4
- package/dist/server/store.js +93 -28
- package/dist/server/types.d.ts +24 -1
- package/dist/server/upload.d.ts +2 -0
- package/dist/server/upload.js +19 -2
- package/dist/shared/project-overview.d.ts +21 -0
- package/dist/shared/project-overview.js +36 -7
- package/dist/shared/project-presentation.d.ts +3 -0
- package/dist/shared/project-presentation.js +13 -5
- package/dist/shared/session-reporting.d.ts +32 -0
- package/dist/shared/session-reporting.js +29 -0
- package/dist/shared/team-context.d.ts +1 -1
- package/package.json +5 -1
- package/dist/client/assets/index-CwfAN5Vw.css +0 -1
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)
|
|
@@ -815,8 +826,10 @@ export class Store {
|
|
|
815
826
|
if (!conversation)
|
|
816
827
|
return undefined;
|
|
817
828
|
const clone = structuredClone(conversation);
|
|
818
|
-
|
|
829
|
+
const escalationAudience = this.openEscalationAudiences().get(conversation.id);
|
|
830
|
+
if (escalationAudience) {
|
|
819
831
|
clone.hasOpenEscalation = true;
|
|
832
|
+
clone.escalationAudience = escalationAudience;
|
|
820
833
|
}
|
|
821
834
|
if (this.pendingResultConversationIds().has(conversation.id)) {
|
|
822
835
|
clone.hasPendingResult = true;
|
|
@@ -858,15 +871,28 @@ export class Store {
|
|
|
858
871
|
project(projectId) { const project = this.state.projects?.find((item) => item.id === projectId); return project ? structuredClone(project) : undefined; }
|
|
859
872
|
/** Conversation IDs that currently have an unresolved escalation requested. */
|
|
860
873
|
openEscalationConversationIds() {
|
|
861
|
-
|
|
874
|
+
return new Set(this.openEscalationAudiences().keys());
|
|
875
|
+
}
|
|
876
|
+
/**
|
|
877
|
+
* 每条未决例外该谁拍板,按发起会话归拢。
|
|
878
|
+
*
|
|
879
|
+
* `supervisor` = 团队内部的事(会话在等自己的直属上级),`boss` = 到了顶层。
|
|
880
|
+
* 一个会话同时开着内部和顶层两条时,顶层那条赢:那是唯一需要用户听见的一条。
|
|
881
|
+
* 老记录没有 `audience`,按 `boss` 读 —— 宁可多让用户看见一次,也不要把该用户决定的事藏起来。
|
|
882
|
+
*/
|
|
883
|
+
openEscalationAudiences() {
|
|
884
|
+
const audiences = new Map();
|
|
862
885
|
for (const project of this.state.projects ?? []) {
|
|
863
886
|
for (const e of project.escalations ?? []) {
|
|
864
887
|
if ((e.status === "open" || e.status === "pending") && e.requestedByConversationId) {
|
|
865
|
-
|
|
888
|
+
const audience = e.audience ?? "boss";
|
|
889
|
+
if (audiences.get(e.requestedByConversationId) !== "boss") {
|
|
890
|
+
audiences.set(e.requestedByConversationId, audience);
|
|
891
|
+
}
|
|
866
892
|
}
|
|
867
893
|
}
|
|
868
894
|
}
|
|
869
|
-
return
|
|
895
|
+
return audiences;
|
|
870
896
|
}
|
|
871
897
|
/** Child conversation IDs whose enqueued session result is still waiting or sending on a non-archived parent. */
|
|
872
898
|
pendingResultConversationIds() {
|
|
@@ -875,7 +901,7 @@ export class Store {
|
|
|
875
901
|
if (parent.archivedAt)
|
|
876
902
|
continue;
|
|
877
903
|
for (const message of parent.messages) {
|
|
878
|
-
if (message.role !== "tool" || !message.delivery)
|
|
904
|
+
if (message.role !== "tool" || !message.delivery || message.source === "session-reminder")
|
|
879
905
|
continue;
|
|
880
906
|
const tagMatch = /^<task\b([^>]*)>/.exec(message.content);
|
|
881
907
|
if (!tagMatch)
|
|
@@ -921,16 +947,16 @@ export class Store {
|
|
|
921
947
|
}
|
|
922
948
|
/** Clone only one workspace's transcripts, never unrelated workspaces or app state. */
|
|
923
949
|
conversationsForWorkspace(workspaceId) {
|
|
924
|
-
const openEscalations = this.
|
|
950
|
+
const openEscalations = this.openEscalationAudiences();
|
|
925
951
|
const pendingResults = this.pendingResultConversationIds();
|
|
926
|
-
return structuredClone(this.state.conversations.filter((item) => item.workspaceId === workspaceId)).map((c) => {
|
|
927
|
-
const
|
|
952
|
+
return structuredClone(this.state.conversations.filter((item) => item.workspaceId === workspaceId && !item.warmSession)).map((c) => {
|
|
953
|
+
const escalationAudience = openEscalations.get(c.id);
|
|
928
954
|
const hasPendingResult = pendingResults.has(c.id);
|
|
929
|
-
if (!
|
|
955
|
+
if (!escalationAudience && !hasPendingResult)
|
|
930
956
|
return c;
|
|
931
957
|
return {
|
|
932
958
|
...c,
|
|
933
|
-
...(
|
|
959
|
+
...(escalationAudience ? { hasOpenEscalation: true, escalationAudience } : {}),
|
|
934
960
|
...(hasPendingResult ? { hasPendingResult: true } : {}),
|
|
935
961
|
};
|
|
936
962
|
});
|
|
@@ -1199,23 +1225,26 @@ export class Store {
|
|
|
1199
1225
|
const { projects: _projects, ...publicState } = this.state;
|
|
1200
1226
|
const closed = new Set(this.state.workspaces.filter((item) => item.closedAt).map((item) => item.id));
|
|
1201
1227
|
const workspaces = this.state.workspaces.filter((item) => !closed.has(item.id));
|
|
1202
|
-
const visible = this.state.conversations.filter((item) => !closed.has(item.workspaceId));
|
|
1203
|
-
const
|
|
1228
|
+
const visible = this.state.conversations.filter((item) => !closed.has(item.workspaceId) && !item.warmSession);
|
|
1229
|
+
const warmSessions = workspaces.flatMap((workspace) => this.listWarmSessions(workspace.id));
|
|
1230
|
+
const presets = warmSessions.length ? { warmSessions } : {};
|
|
1231
|
+
const openEscalations = this.openEscalationAudiences();
|
|
1204
1232
|
const pendingResults = this.pendingResultConversationIds();
|
|
1205
1233
|
// Legacy sockets still receive complete visible transcripts. Project before cloning so a closed
|
|
1206
1234
|
// workspace's retained history is never copied just to discard it afterwards.
|
|
1207
1235
|
if (scope === undefined) {
|
|
1208
1236
|
return structuredClone({
|
|
1209
1237
|
...publicState,
|
|
1238
|
+
...presets,
|
|
1210
1239
|
workspaces,
|
|
1211
1240
|
conversations: visible.map((c) => {
|
|
1212
|
-
const
|
|
1241
|
+
const escalationAudience = openEscalations.get(c.id);
|
|
1213
1242
|
const hasPendingResult = pendingResults.has(c.id);
|
|
1214
|
-
if (!
|
|
1243
|
+
if (!escalationAudience && !hasPendingResult)
|
|
1215
1244
|
return c;
|
|
1216
1245
|
return {
|
|
1217
1246
|
...c,
|
|
1218
|
-
...(
|
|
1247
|
+
...(escalationAudience ? { hasOpenEscalation: true, escalationAudience } : {}),
|
|
1219
1248
|
...(hasPendingResult ? { hasPendingResult: true } : {}),
|
|
1220
1249
|
};
|
|
1221
1250
|
}),
|
|
@@ -1227,7 +1256,9 @@ export class Store {
|
|
|
1227
1256
|
const selectedId = visible.find((item) => item.id === scope.conversationId)?.id;
|
|
1228
1257
|
const conversations = visible.map(({ messages, ...metadata }) => ({
|
|
1229
1258
|
...metadata,
|
|
1230
|
-
...(openEscalations.has(metadata.id)
|
|
1259
|
+
...(openEscalations.has(metadata.id)
|
|
1260
|
+
? { hasOpenEscalation: true, escalationAudience: openEscalations.get(metadata.id) }
|
|
1261
|
+
: {}),
|
|
1231
1262
|
...(pendingResults.has(metadata.id) ? { hasPendingResult: true } : {}),
|
|
1232
1263
|
messages: metadata.id === selectedId ? messages : [],
|
|
1233
1264
|
messagesLoaded: metadata.id === selectedId,
|
|
@@ -1235,6 +1266,7 @@ export class Store {
|
|
|
1235
1266
|
}));
|
|
1236
1267
|
return structuredClone({
|
|
1237
1268
|
...publicState,
|
|
1269
|
+
...presets,
|
|
1238
1270
|
workspaces,
|
|
1239
1271
|
conversations,
|
|
1240
1272
|
// THE CLOCK THE SERVER SCHEDULES BY, NAMED. The scheduled-task panel renders 「每天 09:00」 and
|
|
@@ -1356,6 +1388,13 @@ export class Store {
|
|
|
1356
1388
|
childLockUnlocked(conversationId) {
|
|
1357
1389
|
return Boolean(this.state.unlockedChildConversationIds?.includes(conversationId));
|
|
1358
1390
|
}
|
|
1391
|
+
listWarmSessions(workspaceId) {
|
|
1392
|
+
return this.state.conversations.filter((item) => item.warmSession && item.workspaceId === workspaceId)
|
|
1393
|
+
.map(({ id, title, workspaceId, cwd, archivedAt, updatedAt }) => ({ id, title, workspaceId, cwd, savedAt: archivedAt ?? updatedAt }));
|
|
1394
|
+
}
|
|
1395
|
+
isWarmSession(conversationId) {
|
|
1396
|
+
return this.state.conversations.some((item) => item.id === conversationId && item.warmSession);
|
|
1397
|
+
}
|
|
1359
1398
|
/**
|
|
1360
1399
|
* Opens (or re-closes) one child session's composer, and persists it.
|
|
1361
1400
|
*
|
|
@@ -1445,14 +1484,21 @@ export class Store {
|
|
|
1445
1484
|
* (`byRecency`) puts a fork at the TOP of its workspace group, because `updatedAt` is now - which is the
|
|
1446
1485
|
* same position a newly created conversation takes, and the same reason.
|
|
1447
1486
|
*/
|
|
1448
|
-
async forkConversation(sourceConversationId, forkedConversationId) {
|
|
1487
|
+
async forkConversation(sourceConversationId, forkedConversationId, options = {}) {
|
|
1449
1488
|
const source = this.requireConversation(sourceConversationId);
|
|
1450
1489
|
if (source.id === forkedConversationId)
|
|
1451
1490
|
throw new Error("Cannot fork a conversation into itself");
|
|
1491
|
+
const parent = options.parentConversationId ? this.requireConversation(options.parentConversationId) : undefined;
|
|
1492
|
+
if (parent && (parent.workspaceId !== source.workspaceId || parent.archivedAt || (!source.warmSession && source.parentConversationId !== parent.id))) {
|
|
1493
|
+
throw new Error("分叉会话必须与来源保留同一个直属上级和工作区");
|
|
1494
|
+
}
|
|
1452
1495
|
const conversation = {
|
|
1453
1496
|
id: forkedConversationId,
|
|
1454
|
-
treeId: forkedConversationId,
|
|
1455
|
-
|
|
1497
|
+
treeId: parent ? memoryTreeId(source.warmSession ? parent : source, this.state.conversations) : forkedConversationId,
|
|
1498
|
+
...(parent ? { parentConversationId: parent.id, origin: "orchestrator" } : {}),
|
|
1499
|
+
...(options.warmTitle ? { warmSession: true, archivedAt: now() } : {}),
|
|
1500
|
+
...(options.piSessionFile ? { piSessionFile: options.piSessionFile } : {}),
|
|
1501
|
+
title: options.warmTitle ?? source.title,
|
|
1456
1502
|
workspaceId: source.workspaceId,
|
|
1457
1503
|
updatedAt: now(),
|
|
1458
1504
|
status: "idle",
|
|
@@ -1475,7 +1521,13 @@ export class Store {
|
|
|
1475
1521
|
if (source.cwd)
|
|
1476
1522
|
conversation.cwd = source.cwd;
|
|
1477
1523
|
this.state.conversations.unshift(conversation);
|
|
1478
|
-
|
|
1524
|
+
try {
|
|
1525
|
+
await this.persist();
|
|
1526
|
+
}
|
|
1527
|
+
catch (error) {
|
|
1528
|
+
this.state.conversations = this.state.conversations.filter((item) => item.id !== conversation.id);
|
|
1529
|
+
throw error;
|
|
1530
|
+
}
|
|
1479
1531
|
return structuredClone(conversation);
|
|
1480
1532
|
}
|
|
1481
1533
|
/**
|
|
@@ -1501,6 +1553,8 @@ export class Store {
|
|
|
1501
1553
|
* byte-identically to one that was never archived. `delete` is legal here because the field is optional. */
|
|
1502
1554
|
async unarchiveConversation(conversationId) {
|
|
1503
1555
|
const conversation = this.requireConversation(conversationId);
|
|
1556
|
+
if (conversation.warmSession)
|
|
1557
|
+
throw new Error("预热快照只能通过项目派发使用");
|
|
1504
1558
|
if (!conversation.archivedAt)
|
|
1505
1559
|
return;
|
|
1506
1560
|
delete conversation.archivedAt;
|
|
@@ -1530,6 +1584,8 @@ export class Store {
|
|
|
1530
1584
|
/** Restores one archived tree in one write; active descendants are already restored by definition. */
|
|
1531
1585
|
async unarchiveConversationTree(conversationId) {
|
|
1532
1586
|
const root = this.requireConversation(conversationId);
|
|
1587
|
+
if (root.warmSession)
|
|
1588
|
+
throw new Error("预热快照只能通过项目派发使用");
|
|
1533
1589
|
const parent = root.parentConversationId
|
|
1534
1590
|
? this.state.conversations.find(item => item.id === root.parentConversationId)
|
|
1535
1591
|
: undefined;
|
|
@@ -1562,7 +1618,7 @@ export class Store {
|
|
|
1562
1618
|
const root = this.state.conversations.find((item) => item.id === conversationId);
|
|
1563
1619
|
if (!root)
|
|
1564
1620
|
return { destroyed: [] };
|
|
1565
|
-
if (!root.parentConversationId) {
|
|
1621
|
+
if (!root.parentConversationId && !root.warmSession) {
|
|
1566
1622
|
throw new Error("顶层会话不能销毁,只能由用户归档。");
|
|
1567
1623
|
}
|
|
1568
1624
|
const subtree = this.conversationSubtree(root);
|
|
@@ -1771,10 +1827,15 @@ export class Store {
|
|
|
1771
1827
|
if (conversation.archivedAt)
|
|
1772
1828
|
throw new Error("无法向已归档的会话下发指令,请先恢复该会话");
|
|
1773
1829
|
const message = { id: id("message"), role: "tool", content, createdAt: now() };
|
|
1830
|
+
if (options?.source)
|
|
1831
|
+
message.source = options.source;
|
|
1774
1832
|
if (options?.delivery)
|
|
1775
1833
|
message.delivery = options.delivery;
|
|
1776
1834
|
conversation.messages.push(message);
|
|
1777
|
-
|
|
1835
|
+
if (message.source === "session-reminder" && !message.delivery)
|
|
1836
|
+
await this.persistIncomingTurn(conversation, message);
|
|
1837
|
+
else
|
|
1838
|
+
await this.persistMessages(conversation);
|
|
1778
1839
|
return structuredClone(message);
|
|
1779
1840
|
}
|
|
1780
1841
|
async addUserMessage(conversationId, content, images, attachments, options) {
|
|
@@ -1794,10 +1855,13 @@ export class Store {
|
|
|
1794
1855
|
conversation.messages.push(message);
|
|
1795
1856
|
// Persisted as a transcript change and nothing more: this is the honest record of "the user said this
|
|
1796
1857
|
// and nothing has picked it up yet", and a refresh has to show it in the same place it was sent from.
|
|
1797
|
-
if (message.delivery)
|
|
1858
|
+
if (message.delivery)
|
|
1798
1859
|
await this.persistMessages(conversation);
|
|
1799
|
-
|
|
1800
|
-
|
|
1860
|
+
else
|
|
1861
|
+
await this.persistIncomingTurn(conversation, message);
|
|
1862
|
+
return structuredClone(message);
|
|
1863
|
+
}
|
|
1864
|
+
async persistIncomingTurn(conversation, message) {
|
|
1801
1865
|
const firstUser = conversation.messages.find((item) => item.role === "user");
|
|
1802
1866
|
const autoTitle = firstUser?.content.trim()
|
|
1803
1867
|
? firstUser.content.slice(0, 42)
|
|
@@ -1832,8 +1896,7 @@ export class Store {
|
|
|
1832
1896
|
// changed, and the repository has an incremental path for each. The base snapshot every other
|
|
1833
1897
|
// conversation lives in is untouched by this call, so rewriting it buys nothing.
|
|
1834
1898
|
await this.persistMessages(conversation);
|
|
1835
|
-
await this.persistMetadata(
|
|
1836
|
-
return structuredClone(message);
|
|
1899
|
+
await this.persistMetadata(conversation.id);
|
|
1837
1900
|
}
|
|
1838
1901
|
/**
|
|
1839
1902
|
* Takes the browser's id for its own optimistic message, when it is safe to.
|
|
@@ -2578,6 +2641,8 @@ export class Store {
|
|
|
2578
2641
|
if (!trimmed)
|
|
2579
2642
|
throw new Error("消息不能为空");
|
|
2580
2643
|
const { conversation, message } = this.requireWaitingMessage(conversationId, messageId);
|
|
2644
|
+
if (message.source === "session-reminder")
|
|
2645
|
+
throw new Error("Agent 的定时提醒不能改字");
|
|
2581
2646
|
if (message.role === "tool")
|
|
2582
2647
|
throw new Error("后台任务结果不能改字");
|
|
2583
2648
|
if (message.delivery !== "waiting")
|
package/dist/server/types.d.ts
CHANGED
|
@@ -112,6 +112,7 @@ export type ToolCallQuestion = {
|
|
|
112
112
|
export type Message = {
|
|
113
113
|
id: string;
|
|
114
114
|
role: MessageRole;
|
|
115
|
+
source?: "session-reminder";
|
|
115
116
|
content: string;
|
|
116
117
|
createdAt: string;
|
|
117
118
|
piEntryId?: string;
|
|
@@ -491,6 +492,7 @@ export type Conversation = {
|
|
|
491
492
|
status: RunStatus;
|
|
492
493
|
messages: Message[];
|
|
493
494
|
archivedAt?: string;
|
|
495
|
+
warmSession?: true;
|
|
494
496
|
/**
|
|
495
497
|
* Cumulative usage observed for this conversation: its OWN assistant messages AND the one-shot
|
|
496
498
|
* (sub-agent) calls it dispatched.
|
|
@@ -594,6 +596,12 @@ export type Conversation = {
|
|
|
594
596
|
reportedToParentAt?: string;
|
|
595
597
|
/** 该会话是否存在未决的例外升级(等待上级处理)。 */
|
|
596
598
|
hasOpenEscalation?: boolean;
|
|
599
|
+
/**
|
|
600
|
+
* 这条未决例外该谁拍板:`supervisor` = 团队内部(直属上级),`boss` = 到了顶层。
|
|
601
|
+
* 与 `hasOpenEscalation` 一样是只读投影,不落盘;客户端靠它区分「内部升级」和
|
|
602
|
+
* 「真的需要用户决定的事」——只有后者才配出现在用户面前。
|
|
603
|
+
*/
|
|
604
|
+
escalationAudience?: "supervisor" | "boss";
|
|
597
605
|
/** Read-only projection: whether this child session still has an undelivered result in its parent's waiting queue. */
|
|
598
606
|
hasPendingResult?: boolean;
|
|
599
607
|
/**
|
|
@@ -980,7 +988,7 @@ export type TerminalShell = {
|
|
|
980
988
|
file: string;
|
|
981
989
|
args: string[];
|
|
982
990
|
};
|
|
983
|
-
export type ProjectStatus = "planning" | "awaiting_start" | "active" | "blocked" | "awaiting_approval" | "awaiting_review" | "
|
|
991
|
+
export type ProjectStatus = "planning" | "awaiting_start" | "active" | "blocked" | "awaiting_approval" | "awaiting_review" | "failed" | "cancelled";
|
|
984
992
|
/**
|
|
985
993
|
* THE STATES A TASK CAN BE IN.
|
|
986
994
|
*
|
|
@@ -1074,6 +1082,7 @@ export type ProjectReport = {
|
|
|
1074
1082
|
id: string;
|
|
1075
1083
|
projectId: string;
|
|
1076
1084
|
taskId?: string;
|
|
1085
|
+
acceptedTaskIds?: string[];
|
|
1077
1086
|
authorConversationId?: string;
|
|
1078
1087
|
kind: "progress" | "blocked" | "delivery" | "decision_request" | "review";
|
|
1079
1088
|
progress: string;
|
|
@@ -1248,6 +1257,13 @@ export type AppState = {
|
|
|
1248
1257
|
* decision nobody has made yet.
|
|
1249
1258
|
*/
|
|
1250
1259
|
unlockedChildConversationIds?: string[];
|
|
1260
|
+
warmSessions?: Array<{
|
|
1261
|
+
id: string;
|
|
1262
|
+
title: string;
|
|
1263
|
+
workspaceId: string;
|
|
1264
|
+
cwd?: string;
|
|
1265
|
+
savedAt: string;
|
|
1266
|
+
}>;
|
|
1251
1267
|
/**
|
|
1252
1268
|
* THE CLOCK THIS SERVER SCHEDULES BY. A scheduled task's 「每天 09:00」 is the SERVER's wall clock,
|
|
1253
1269
|
* and the panel has to say so, because browser rendering 「下次」 may be on a different clock
|
|
@@ -1559,6 +1575,13 @@ export type ClientCommandBody =
|
|
|
1559
1575
|
} | {
|
|
1560
1576
|
type: "conversation.archive";
|
|
1561
1577
|
conversationId: string;
|
|
1578
|
+
} | {
|
|
1579
|
+
type: "conversation.warm.save";
|
|
1580
|
+
conversationId: string;
|
|
1581
|
+
title: string;
|
|
1582
|
+
} | {
|
|
1583
|
+
type: "conversation.warm.delete";
|
|
1584
|
+
conversationId: string;
|
|
1562
1585
|
} | {
|
|
1563
1586
|
type: "conversation.unarchive";
|
|
1564
1587
|
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 = {
|
|
@@ -38,7 +39,27 @@ export type OverviewProject = {
|
|
|
38
39
|
};
|
|
39
40
|
/** Internal coordination is not a request for the user's attention. */
|
|
40
41
|
export declare function userProjectDecisions(project: OverviewProject): OverviewDecision[];
|
|
42
|
+
/**
|
|
43
|
+
* HOW MANY PROJECTS NEED THE USER - counted by project, not by case.
|
|
44
|
+
*
|
|
45
|
+
* The notice above the project tab says "N projects need you to decide". One project with two
|
|
46
|
+
* open boss-level cases is still ONE project to decide about, and a notice that says "2 projects"
|
|
47
|
+
* above a list that shows one is simply wrong. The count therefore goes over the PROJECTS that
|
|
48
|
+
* have at least one such case, and the cases themselves are counted separately.
|
|
49
|
+
*/
|
|
50
|
+
export declare function projectsNeedingUserDecision(projects: OverviewProject[]): {
|
|
51
|
+
projects: number;
|
|
52
|
+
cases: number;
|
|
53
|
+
};
|
|
41
54
|
export declare function ownerProjectReports(project: OverviewProject): OverviewReport[];
|
|
55
|
+
export declare function latestProjectDelivery<T extends OverviewReport>(project: {
|
|
56
|
+
ownerConversationId?: string;
|
|
57
|
+
reports?: T[];
|
|
58
|
+
}): T | undefined;
|
|
59
|
+
export declare function deliveryCoversTasks(delivery: OverviewReport | undefined, tasks: {
|
|
60
|
+
id: string;
|
|
61
|
+
updatedAt?: string;
|
|
62
|
+
}[]): boolean;
|
|
42
63
|
export declare function projectUserOverview(project: OverviewProject): {
|
|
43
64
|
label: string;
|
|
44
65
|
summary: string;
|
|
@@ -2,23 +2,52 @@
|
|
|
2
2
|
export function userProjectDecisions(project) {
|
|
3
3
|
return (project.escalations ?? []).filter(item => item.status === "open" && (item.audience === "boss" || item.audience === undefined));
|
|
4
4
|
}
|
|
5
|
+
/**
|
|
6
|
+
* HOW MANY PROJECTS NEED THE USER - counted by project, not by case.
|
|
7
|
+
*
|
|
8
|
+
* The notice above the project tab says "N projects need you to decide". One project with two
|
|
9
|
+
* open boss-level cases is still ONE project to decide about, and a notice that says "2 projects"
|
|
10
|
+
* above a list that shows one is simply wrong. The count therefore goes over the PROJECTS that
|
|
11
|
+
* have at least one such case, and the cases themselves are counted separately.
|
|
12
|
+
*/
|
|
13
|
+
export function projectsNeedingUserDecision(projects) {
|
|
14
|
+
const withCases = projects.filter(project => userProjectDecisions(project).length > 0);
|
|
15
|
+
return {
|
|
16
|
+
projects: withCases.length,
|
|
17
|
+
cases: withCases.reduce((sum, project) => sum + userProjectDecisions(project).length, 0),
|
|
18
|
+
};
|
|
19
|
+
}
|
|
5
20
|
export function ownerProjectReports(project) {
|
|
6
21
|
return (project.reports ?? []).filter(report => !report.taskId && ["progress", "delivery"].includes(report.kind ?? "")
|
|
7
22
|
&& (report.authorConversationId === project.ownerConversationId && Boolean(project.ownerConversationId)
|
|
8
|
-
||
|
|
23
|
+
|| report.kind === "delivery" && !report.authorConversationId));
|
|
24
|
+
}
|
|
25
|
+
export function latestProjectDelivery(project) {
|
|
26
|
+
return [...(project.reports ?? [])].reverse().find(report => report.kind === "delivery" && !report.taskId
|
|
27
|
+
&& (!report.authorConversationId || report.authorConversationId === project.ownerConversationId));
|
|
28
|
+
}
|
|
29
|
+
export function deliveryCoversTasks(delivery, tasks) {
|
|
30
|
+
if (!delivery)
|
|
31
|
+
return false;
|
|
32
|
+
if (delivery.acceptedTaskIds) {
|
|
33
|
+
const accepted = new Set(delivery.acceptedTaskIds);
|
|
34
|
+
return tasks.every(task => accepted.has(task.id));
|
|
35
|
+
}
|
|
36
|
+
const deliveredAt = delivery.createdAt ? Date.parse(delivery.createdAt) : NaN;
|
|
37
|
+
return Number.isFinite(deliveredAt) && tasks.every(task => !task.updatedAt || Date.parse(task.updatedAt) <= deliveredAt);
|
|
9
38
|
}
|
|
10
39
|
export function projectUserOverview(project) {
|
|
11
40
|
const decisions = userProjectDecisions(project);
|
|
12
41
|
const reports = ownerProjectReports(project);
|
|
13
42
|
const progress = [...reports].reverse().find(report => report.kind === "progress");
|
|
14
|
-
const delivery =
|
|
15
|
-
const ended = ["
|
|
43
|
+
const delivery = latestProjectDelivery(project);
|
|
44
|
+
const ended = ["cancelled", "failed"].includes(project.status);
|
|
16
45
|
const owner = project.resources?.sessions?.find(session => session.id === project.ownerConversationId);
|
|
17
46
|
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
|
-
:
|
|
47
|
+
const label = project.status === "cancelled" ? "已取消" : project.status === "failed" ? "执行暂停"
|
|
48
|
+
: decisions.length ? "需要你决定" : busy ? "正在推进" : !project.ownerConversationId ? "待启动" : ["failed", "stopped"].includes(owner?.status ?? "") ? "执行暂停" : delivery ? "待继续" : "未交付";
|
|
49
|
+
const summary = progress?.progress?.trim() || progress?.summary?.trim() || (ended ? "项目已结束,已有记录会保留。"
|
|
50
|
+
: delivery ? "可继续安排新任务或追加验证。" : "已交由负责人推进,进展和成果会在这里汇总。");
|
|
22
51
|
return { label, summary, progress, delivery, decisions, ended,
|
|
23
52
|
deliveryLabel: project.mode === "lightweight" ? "自评交付" : "交付成果" };
|
|
24
53
|
}
|
|
@@ -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));
|
|
@@ -7,7 +7,21 @@ export type SessionReportingSnapshot = {
|
|
|
7
7
|
archivedAt?: string;
|
|
8
8
|
hasOpenEscalation?: boolean;
|
|
9
9
|
hasPendingResult?: boolean;
|
|
10
|
+
/**
|
|
11
|
+
* 谁来拍板这条未决例外:`supervisor` = 团队内部(直属上级),`boss` = 到了顶层。
|
|
12
|
+
* 缺席 = 老记录,按 `boss` 读(保守读法:可能需要用户的事,先给用户看)。
|
|
13
|
+
*/
|
|
14
|
+
escalationAudience?: EscalationAudience;
|
|
10
15
|
};
|
|
16
|
+
/** 这条未决例外该谁拍板。 */
|
|
17
|
+
export type EscalationAudience = "supervisor" | "boss";
|
|
18
|
+
/**
|
|
19
|
+
* 从会话载荷上读出例外的 audience。
|
|
20
|
+
*
|
|
21
|
+
* 客户端的会话类型是自己的一份镜像(`src/client/types.ts`),不在本次改动的文件清单里,
|
|
22
|
+
* 所以这个字段不通过类型系统读,而是只从这里这一个门口读一次。
|
|
23
|
+
*/
|
|
24
|
+
export declare function escalationAudienceOf(conversation: unknown): EscalationAudience | undefined;
|
|
11
25
|
export type ReportingAxisState = "pending_report" | "awaiting_subordinates" | "awaiting_decision" | "unread";
|
|
12
26
|
export declare function deriveReportingState(params: {
|
|
13
27
|
conversation: SessionReportingSnapshot;
|
|
@@ -15,6 +29,24 @@ export declare function deriveReportingState(params: {
|
|
|
15
29
|
directChildren: SessionReportingSnapshot[];
|
|
16
30
|
isTopLevelUnread?: boolean;
|
|
17
31
|
}): ReportingAxisState | null;
|
|
32
|
+
/**
|
|
33
|
+
* 给用户看的那一套推导:内部升级不算「等上面拍板」。
|
|
34
|
+
*
|
|
35
|
+
* `deriveReportingState` 说的是这个会话在汇报线上的位置,那条内部规则(自己有待拍板的例外)
|
|
36
|
+
* 对团队内部是对的 —— 但它被原样搬到用户面前时读作「用户被叫来开会了」,而用户根本不在那场
|
|
37
|
+
* 会里。所以用户这一侧单独走这一个出口:`audience` 是 `supervisor` 的未决例外不参与
|
|
38
|
+
* `awaiting_decision` 的判定,于是这个会话显示它真正在做的事(运行中就显示运行中),
|
|
39
|
+
* 而不是被一条内部升级盖住。
|
|
40
|
+
*
|
|
41
|
+
* 判据本体在 `deriveReportingState` 里没有动:服务端的推导(项目面板的会话行)走的是那一条,
|
|
42
|
+
* 客户端走的是这一条,两边各有一套派生,谁也不用为了另一边的语义让步。
|
|
43
|
+
*/
|
|
44
|
+
export declare function deriveUserReportingState(params: {
|
|
45
|
+
conversation: SessionReportingSnapshot;
|
|
46
|
+
parent?: ChildSessionRow;
|
|
47
|
+
directChildren: SessionReportingSnapshot[];
|
|
48
|
+
isTopLevelUnread?: boolean;
|
|
49
|
+
}): ReportingAxisState | null;
|
|
18
50
|
export type SessionDisplayState = "waiting" | "running" | "failed" | "question" | "completed" | "unread" | "idle" | "awaiting_background" | "pending_report" | "awaiting_subordinates" | "awaiting_decision";
|
|
19
51
|
export declare const SESSION_STATE_WORD: Record<string, string>;
|
|
20
52
|
export declare function sessionStateWord(state: string | undefined): string;
|