@evandu/super-pi 0.1.220 → 0.1.222
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 +3 -2
- package/agents/super-pi-task/core.ts +16 -16
- package/agents/super-pi-task/index.ts +5 -2
- package/dist/client/.super-pi-client-sources.json +8 -8
- package/dist/client/assets/{CodeMirrorEditor-DLESYIdU.js → CodeMirrorEditor-IWcAz6oz.js} +2 -2
- package/dist/client/assets/{dist-h8QFV1py.js → dist-0tDquiIc.js} +1 -1
- package/dist/client/assets/{dist-CbixgvA8.js → dist-B2WzMUqb.js} +1 -1
- package/dist/client/assets/{dist-DhCNXN4F.js → dist-B41_P-GB.js} +1 -1
- package/dist/client/assets/{dist-Bz37bm03.js → dist-B4YZqIKX.js} +1 -1
- package/dist/client/assets/{dist-BG1xVEUu.js → dist-BPhtg6ss.js} +1 -1
- package/dist/client/assets/{dist-YSB8UKj7.js → dist-Brmqe6G6.js} +1 -1
- package/dist/client/assets/{dist-D0Mff5_O.js → dist-Bx-zvsek.js} +1 -1
- package/dist/client/assets/{dist-CYEoLBJJ.js → dist-ByhQMTZz.js} +1 -1
- package/dist/client/assets/{dist-hyn4QSU9.js → dist-C-CsTWFq.js} +1 -1
- package/dist/client/assets/{dist-B6UYFWUo.js → dist-CLfjxR6r.js} +1 -1
- package/dist/client/assets/{dist-DvJTvgiN.js → dist-CRfBzL2s.js} +1 -1
- package/dist/client/assets/{dist-DKRxalqK.js → dist-Cd2jBngi.js} +1 -1
- package/dist/client/assets/{dist-CQAWuaHA.js → dist-ChJliyoT.js} +1 -1
- package/dist/client/assets/{dist-BTUuXAFG.js → dist-D73UQVEK.js} +1 -1
- package/dist/client/assets/{dist-DPvgTEV_.js → dist-DR-NR2sl.js} +1 -1
- package/dist/client/assets/{dist-aDKso4tk.js → dist-DZFnjuKR.js} +1 -1
- package/dist/client/assets/{dist-B-ydE4PJ.js → dist-DftBUe3J.js} +1 -1
- package/dist/client/assets/{dist-2Gv721yB.js → dist-DgRXONWV.js} +1 -1
- package/dist/client/assets/{dist-CoC8iHD1.js → dist-DglikBo1.js} +1 -1
- package/dist/client/assets/{dist-DmraLEb2.js → dist-JFHBsRN8.js} +1 -1
- package/dist/client/assets/{dist-B-63MNT9.js → dist-KddcFuL2.js} +1 -1
- package/dist/client/assets/{dist-CrtcsyOg.js → dist-fzY9qpWd.js} +1 -1
- package/dist/client/assets/index-DbtNmSyS.js +103 -0
- package/dist/client/assets/index-OmaD3l6r.css +1 -0
- package/dist/client/index.html +2 -2
- package/dist/server/application/extension-ui-service.d.ts +2 -1
- package/dist/server/application/extension-ui-service.js +25 -17
- package/dist/server/application/project-service.d.ts +3 -2
- package/dist/server/application/project-service.js +34 -38
- package/dist/server/application/session-reminder-service.d.ts +7 -3
- package/dist/server/application/session-reminder-service.js +40 -19
- package/dist/server/http-server.js +6 -6
- package/dist/server/index.js +5 -1
- package/dist/server/store.d.ts +1 -1
- package/dist/server/store.js +42 -1
- package/dist/server/task-tool.d.ts +1 -1
- package/dist/server/task-tool.js +7 -7
- package/dist/shared/session-reporting.d.ts +2 -20
- package/dist/shared/session-reporting.js +9 -27
- package/package.json +1 -1
- package/dist/client/assets/index-B-h_KnC5.css +0 -1
- package/dist/client/assets/index-BMuvJCSx.js +0 -103
package/dist/client/index.html
CHANGED
|
@@ -8,8 +8,8 @@
|
|
|
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-
|
|
12
|
-
<link rel="stylesheet" crossorigin href="/assets/index-
|
|
11
|
+
<script type="module" crossorigin src="/assets/index-DbtNmSyS.js"></script>
|
|
12
|
+
<link rel="stylesheet" crossorigin href="/assets/index-OmaD3l6r.css">
|
|
13
13
|
</head>
|
|
14
14
|
<body>
|
|
15
15
|
<div id="root"></div>
|
|
@@ -14,8 +14,9 @@ import type { EventBroadcaster } from "../server-context.js";
|
|
|
14
14
|
*/
|
|
15
15
|
export declare class ExtensionUiService {
|
|
16
16
|
private readonly broadcaster;
|
|
17
|
+
private readonly canAddressUser;
|
|
17
18
|
private readonly pendingUi;
|
|
18
|
-
constructor(broadcaster: EventBroadcaster);
|
|
19
|
+
constructor(broadcaster: EventBroadcaster, canAddressUser?: (conversationId: string) => boolean);
|
|
19
20
|
private uiKey;
|
|
20
21
|
/**
|
|
21
22
|
* Settles a pending UI request by answering, timing out, or aborting.
|
|
@@ -11,9 +11,11 @@
|
|
|
11
11
|
*/
|
|
12
12
|
export class ExtensionUiService {
|
|
13
13
|
broadcaster;
|
|
14
|
+
canAddressUser;
|
|
14
15
|
pendingUi = new Map();
|
|
15
|
-
constructor(broadcaster) {
|
|
16
|
+
constructor(broadcaster, canAddressUser = () => true) {
|
|
16
17
|
this.broadcaster = broadcaster;
|
|
18
|
+
this.canAddressUser = canAddressUser;
|
|
17
19
|
}
|
|
18
20
|
uiKey(conversationId, requestId) {
|
|
19
21
|
return `${conversationId}\u0000${requestId}`;
|
|
@@ -62,24 +64,30 @@ export class ExtensionUiService {
|
|
|
62
64
|
const scoped = (request) => runId ? { ...request, requestId: `${runId}:${request.requestId}` } : request;
|
|
63
65
|
return {
|
|
64
66
|
notify: (request) => {
|
|
67
|
+
if (!this.canAddressUser(conversationId))
|
|
68
|
+
return;
|
|
65
69
|
this.broadcaster.broadcast({ type: "extension.ui", conversationId, request: scoped(request) });
|
|
66
70
|
},
|
|
67
|
-
ask: (request) =>
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
71
|
+
ask: async (request) => {
|
|
72
|
+
if (!this.canAddressUser(conversationId))
|
|
73
|
+
return { cancelled: true };
|
|
74
|
+
return new Promise((resolve) => {
|
|
75
|
+
const shown = scoped(request);
|
|
76
|
+
const key = this.uiKey(conversationId, shown.requestId);
|
|
77
|
+
// Only the Pi-declared `timeoutMs` is honoured. There is no safety net when Pi did not set
|
|
78
|
+
// one: a question Pi chose to leave open is a question the model is waiting on, and a
|
|
79
|
+
// fabricated cancel would be the model continuing on a false premise. The run-level
|
|
80
|
+
// teardown (stop / abort / shutdown) is the path that closes an unanswered ask.
|
|
81
|
+
const pending = { conversationId, request: shown, resolve };
|
|
82
|
+
if (shown.timeoutMs !== undefined) {
|
|
83
|
+
pending.timer = setTimeout(() => {
|
|
84
|
+
this.settleUi(key, { cancelled: true }, "timeout");
|
|
85
|
+
}, shown.timeoutMs);
|
|
86
|
+
}
|
|
87
|
+
this.pendingUi.set(key, pending);
|
|
88
|
+
this.broadcaster.broadcast({ type: "extension.ui", conversationId, request: shown });
|
|
89
|
+
});
|
|
90
|
+
},
|
|
83
91
|
};
|
|
84
92
|
}
|
|
85
93
|
}
|
|
@@ -19,8 +19,8 @@ import type { SessionOrchestratorService } from "./session-orchestrator-service.
|
|
|
19
19
|
* leader has no subordinates at all, so it is told the second half only - it must not decide
|
|
20
20
|
* alone either - and is never told about subordinates it does not have.
|
|
21
21
|
*/
|
|
22
|
-
export declare const STANDARD_LEADER_PROMPT = "\u4F60\u662F\
|
|
23
|
-
export declare const LIGHTWEIGHT_LEADER_PROMPT = "\u4F60\u662F\
|
|
22
|
+
export declare const STANDARD_LEADER_PROMPT = "\u4F60\u662F\u8D1F\u8D23\u9879\u76EE\u534F\u8C03\u7684 Leader\uFF0C\u8D1F\u8D23\u654F\u6377\u5F00\u53D1\u4E0E\u5C0F\u6B65\u4EA4\u4ED8\u3002\u7528\u6237\u662F\u9876\u5C42\u51B3\u7B56\u8005\uFF0C\u4F60\u81EA\u884C\u5904\u7406\u5185\u90E8\u534F\u8C03\uFF0C\u6CBF\u6C47\u62A5\u7EBF\u6C47\u603B\u8FDB\u5C55\u3001\u6210\u679C\u4E0E\u5FC5\u8981\u51B3\u7B56\u3002\u5F00\u7BC7\u4E0A\u4E0B\u6587\u5DF2\u7ED9\u51FA\u9879\u76EE\u76EE\u6807\u3001\u6A21\u5F0F\u3001\u5206\u5DE5\u4E0E\u5F53\u524D\u4EFB\u52A1\u6E05\u5355\uFF0C\u4E0D\u5FC5\u5148\u8C03\u7528 project(action=get) \u5C31\u80FD\u76F4\u63A5\u62C6\u89E3\u3001\u6D3E\u6D3B\u6216\u63A8\u8FDB\u3002\u5C0F\u9879\u76EE\u53EA\u62C6\u6700\u5C11\u5FC5\u8981\u4EFB\u52A1\uFF0C\u5927\u9879\u76EE\u6309\u4EA4\u4ED8\u8FB9\u754C\u5206\u5DE5\u3002\u7528 add_task \u767B\u8BB0\u4EFB\u52A1\uFF08\u660E\u786E\u76EE\u6807\u3001\u4EA4\u4ED8\u7269\u3001\u9A8C\u6536\u6807\u51C6\u3001\u4F9D\u8D56\uFF09\uFF1Badd_task / update_task \u65F6\u53EF\u4EE5\u5E26 executorProfile \u4E0E reviewerProfile\uFF08\u652F\u6301\u6307\u5B9A agentId\u3001cwd\u3001model\u3001thinkingLevel\u3001watchdogTimeoutSeconds\uFF09\uFF0C\u6309\u4EFB\u52A1\u6027\u8D28\u5C06\u6267\u884C\u4E0E\u590D\u6838\u59D4\u6D3E\u7ED9\u6700\u5408\u9002\u7684\u5458\u5DE5\uFF0C\u4E0D\u6307\u5B9A\u5219\u7EE7\u627F\u9879\u76EE\u9ED8\u8BA4\uFF1B\u9700\u8981\u7EE7\u7EED\u62C6\u89E3\u7684\u5DE5\u4F5C\u8BBE role=leader\uFF0C\u53F6\u5B50\u6267\u884C\u4EFB\u52A1\u8BBE role=executor\uFF0C\u5B50 Leader \u7528 parentTaskId \u767B\u8BB0\u81EA\u5DF1\u7684\u5B50\u4EFB\u52A1\uFF0Cdispatch \u7ACB\u5373\u542F\u52A8\u6267\u884C\u5B50\u4F1A\u8BDD\uFF1B\u4E0D\u8981\u7528 session_spawn/session_dispatch \u6216 task/workflow \u7ED5\u5F00\u9879\u76EE\u5206\u5DE5\u4E0E\u6C47\u62A5\u7EBF\u3002\u6536\u5230\u4EA4\u4ED8\u540E\u7528 request_review \u542F\u52A8\u72EC\u7ACB\u590D\u6838\u3002\u6D3E\u53D1\u540E\u5B50\u4F1A\u8BDD\u4F1A\u7ACB\u5373\u5F00\u59CB\u6267\u884C\u5E76\u5728\u5B8C\u6210\u540E\u81EA\u52A8\u56DE\u62A5\u7ED9\u4F60\uFF0C\u5C4A\u65F6\u7EE7\u7EED\u6D3E\u53D1 ready \u4EFB\u52A1\u3001\u590D\u6838\u5F85\u9A8C\u6536\u4EFB\u52A1\u6216\u6309 review.summary \u8FD4\u5DE5\uFF1B\u4E0D\u8981\u8F6E\u8BE2\u7B49\u5F85\uFF0C\u4E0D\u8981\u53CD\u590D\u65E0\u8FDB\u5C55\u91CD\u8BD5\uFF0C\u7B49\u5F85\u56DE\u62A5\u65F6\u76F4\u63A5\u7ED3\u675F\u5F53\u524D\u56DE\u590D\u3002\u7528 report \u767B\u8BB0\u5173\u952E\u8FDB\u5C55\u3002\u4F60\u7684\u4E0B\u5C5E\u7684\u5347\u7EA7\u5148\u5230\u4F60\u8FD9\u91CC\uFF1A\u4F60\u5728\u81EA\u5DF1\u8FD9\u4E00\u5C42\u5904\u7406\uFF0C\u80FD\u81EA\u5DF1\u89E3\u51B3\u7684\u81EA\u5DF1\u89E3\u51B3\uFF1B\u672C\u5C42\u89E3\u51B3\u4E0D\u4E86\u7684\u95EE\u9898\u624D\u7528 escalate\uFF1A\u6709\u7236\u4F1A\u8BDD\u5C31\u4EA4\u7ED9\u76F4\u5C5E\u7236\u4F1A\u8BDD\uFF0C\u7531\u5B83\u5224\u65AD\u548C\u8F6C\u8FF0\uFF1B\u53EA\u6709\u9876\u5C42\u4F1A\u8BDD\u624D\u628A\u786E\u9700\u7528\u6237\u51B3\u5B9A\u7684\u95EE\u9898\u4EA4\u7ED9\u7528\u6237\u3002\u4F60\u4E0D\u80FD\u66FF Boss \u505A\u51B3\u5B9A\uFF0C\u4E5F\u4E0D\u8981\u628A\u6CA1\u5904\u7406\u7684\u5347\u7EA7\u538B\u4E0B\u53BB\u4E0D\u7406\u3002\u6240\u6709\u4EFB\u52A1\u9A8C\u6536\u540E\uFF0C\u7528 deliver \u8BB0\u5F55\u5E26\u8BC1\u636E\u7684\u9636\u6BB5\u4EA4\u4ED8\uFF0C\u540E\u7EED\u53EF\u7EE7\u7EED\u6D3E\u53D1\u3002\u4E0A\u4E0B\u6587\u6709\u9650\uFF0C\u660E\u786E\u5047\u8BBE\uFF0C\u4E3B\u52A8\u5BFB\u627E\u53CD\u8BC1\u3002\u53EA\u5728\u672C\u6B21\u89E6\u53D1\u8303\u56F4\u5185\u5DE5\u4F5C\u3002";
|
|
23
|
+
export declare const LIGHTWEIGHT_LEADER_PROMPT = "\u4F60\u662F\u8D1F\u8D23\u9879\u76EE\u534F\u8C03\u7684 Leader\uFF0C\u8FD9\u662F\u4E00\u4E2A\u8F7B\u91CF\u9879\u76EE\uFF1A\u8FD9\u4E2A\u9879\u76EE\u7531\u4F60\u4EB2\u81EA\u5B8C\u6210\uFF0C\u4E0D\u8981\u62C6\u5B50\u4EFB\u52A1\u3001\u4E0D\u8981\u6D3E\u53D1\u7ED9\u522B\u4EBA\u3001\u4E5F\u6CA1\u6709\u72EC\u7ACB\u590D\u6838\u3002\u5F00\u7BC7\u4E0A\u4E0B\u6587\u5DF2\u7ED9\u51FA\u9879\u76EE\u76EE\u6807\u3001\u6A21\u5F0F\u4E0E\u5F53\u524D\u4EFB\u52A1\u6E05\u5355\uFF0C\u4E0D\u5FC5\u5148\u8C03\u7528 project(action=get) \u5C31\u80FD\u76F4\u63A5\u52A8\u624B\u3002\u7528 add_task \u767B\u8BB0\u4EFB\u52A1\uFF08\u660E\u786E\u76EE\u6807\u3001\u4EA4\u4ED8\u7269\u3001\u9A8C\u6536\u6807\u51C6\u3001\u4F9D\u8D56\uFF09\uFF0C\u4EFB\u52A1\u4E00\u5F8B\u767B\u8BB0\u4E3A\u6267\u884C\u4EFB\u52A1\uFF1Arole=leader \u6216\u5E26 parentTaskId \u90FD\u4F1A\u88AB\u62D2\u7EDD\u3002dispatch \u4F1A\u628A\u4EFB\u52A1\u4EA4\u56DE\u7ED9\u4F60\u81EA\u5DF1\uFF0C\u4F60\u4EB2\u81EA\u505A\u5B8C\uFF1B\u505A\u5B8C\u540E\u8C03\u7528 project(action=submit, projectId, taskId, output, evidenceRefs) \u63D0\u4EA4\u4EA4\u4ED8\uFF0C\u63D0\u4EA4\u5373\u5B8C\u6210\uFF0C\u4E0D\u4F1A\u6709\u4EBA\u56DE\u6765\u590D\u6838\uFF0C\u8BC1\u636E\u5FC5\u987B\u9644\u4E0A\u3002\u4E0D\u8981\u7528 session_spawn/session_dispatch \u6216 task/workflow \u7ED5\u5F00\u9879\u76EE\u804C\u8D23\u4E0E\u6C47\u62A5\u7EBF\u3002\u4E0D\u8981\u8F6E\u8BE2\u7B49\u5F85\uFF0C\u4E0D\u8981\u53CD\u590D\u65E0\u8FDB\u5C55\u91CD\u8BD5\u3002\u7528 report \u6C47\u603B\u5173\u952E\u8FDB\u5C55\u3002\u666E\u901A\u6280\u672F\u51B3\u7B56\u3001\u963B\u585E\u4E0E\u8FD4\u5DE5\u7531\u4F60\u81EA\u884C\u5904\u7406\uFF1B\u672C\u5C42\u89E3\u51B3\u4E0D\u4E86\u7684\u4E8B\u624D\u7528 escalate\uFF1A\u6709\u7236\u4F1A\u8BDD\u5C31\u4EA4\u7ED9\u76F4\u5C5E\u7236\u4F1A\u8BDD\uFF0C\u7531\u5B83\u5224\u65AD\u548C\u8F6C\u8FF0\uFF1B\u53EA\u6709\u9876\u5C42\u4F1A\u8BDD\u624D\u628A\u786E\u9700\u7528\u6237\u51B3\u5B9A\u7684\u95EE\u9898\u4EA4\u7ED9\u7528\u6237\uFF0C\u4E0D\u5F97\u66FF Boss \u51B3\u5B9A\u8FD9\u4E9B\u4E8B\u9879\u3002\u6240\u6709\u4EFB\u52A1\u4EA4\u4ED8\u540E\uFF0C\u7528 deliver \u8BB0\u5F55\u5E26\u8BC1\u636E\u7684\u9636\u6BB5\u4EA4\u4ED8\uFF0C\u540E\u7EED\u53EF\u7EE7\u7EED\u6D3E\u53D1\u3002\u4E0A\u4E0B\u6587\u6709\u9650\uFF0C\u660E\u786E\u5047\u8BBE\uFF0C\u4E3B\u52A8\u5BFB\u627E\u53CD\u8BC1\u3002\u53EA\u5728\u672C\u6B21\u89E6\u53D1\u8303\u56F4\u5185\u5DE5\u4F5C\u3002";
|
|
24
24
|
export declare const profile: (value: unknown, label: string) => SessionProfile | undefined;
|
|
25
25
|
export declare const mergeProfile: (taskProfile?: SessionProfile, projectDefault?: SessionProfile) => SessionProfile | undefined;
|
|
26
26
|
/**
|
|
@@ -272,6 +272,7 @@ export declare class ProjectService {
|
|
|
272
272
|
private requiredComplete;
|
|
273
273
|
private task;
|
|
274
274
|
private member;
|
|
275
|
+
private canAddressUser;
|
|
275
276
|
isMember(p: Project, actor?: string): boolean;
|
|
276
277
|
directSupervisor(p: Project, actor?: string, taskId?: string): string | undefined;
|
|
277
278
|
/**
|
|
@@ -22,8 +22,8 @@ const stamp = () => new Date().toISOString();
|
|
|
22
22
|
* leader has no subordinates at all, so it is told the second half only - it must not decide
|
|
23
23
|
* alone either - and is never told about subordinates it does not have.
|
|
24
24
|
*/
|
|
25
|
-
export const STANDARD_LEADER_PROMPT = "
|
|
26
|
-
export const LIGHTWEIGHT_LEADER_PROMPT = "
|
|
25
|
+
export const STANDARD_LEADER_PROMPT = "你是负责项目协调的 Leader,负责敏捷开发与小步交付。用户是顶层决策者,你自行处理内部协调,沿汇报线汇总进展、成果与必要决策。开篇上下文已给出项目目标、模式、分工与当前任务清单,不必先调用 project(action=get) 就能直接拆解、派活或推进。小项目只拆最少必要任务,大项目按交付边界分工。用 add_task 登记任务(明确目标、交付物、验收标准、依赖);add_task / update_task 时可以带 executorProfile 与 reviewerProfile(支持指定 agentId、cwd、model、thinkingLevel、watchdogTimeoutSeconds),按任务性质将执行与复核委派给最合适的员工,不指定则继承项目默认;需要继续拆解的工作设 role=leader,叶子执行任务设 role=executor,子 Leader 用 parentTaskId 登记自己的子任务,dispatch 立即启动执行子会话;不要用 session_spawn/session_dispatch 或 task/workflow 绕开项目分工与汇报线。收到交付后用 request_review 启动独立复核。派发后子会话会立即开始执行并在完成后自动回报给你,届时继续派发 ready 任务、复核待验收任务或按 review.summary 返工;不要轮询等待,不要反复无进展重试,等待回报时直接结束当前回复。用 report 登记关键进展。你的下属的升级先到你这里:你在自己这一层处理,能自己解决的自己解决;本层解决不了的问题才用 escalate:有父会话就交给直属父会话,由它判断和转述;只有顶层会话才把确需用户决定的问题交给用户。你不能替 Boss 做决定,也不要把没处理的升级压下去不理。所有任务验收后,用 deliver 记录带证据的阶段交付,后续可继续派发。上下文有限,明确假设,主动寻找反证。只在本次触发范围内工作。";
|
|
26
|
+
export const LIGHTWEIGHT_LEADER_PROMPT = "你是负责项目协调的 Leader,这是一个轻量项目:这个项目由你亲自完成,不要拆子任务、不要派发给别人、也没有独立复核。开篇上下文已给出项目目标、模式与当前任务清单,不必先调用 project(action=get) 就能直接动手。用 add_task 登记任务(明确目标、交付物、验收标准、依赖),任务一律登记为执行任务:role=leader 或带 parentTaskId 都会被拒绝。dispatch 会把任务交回给你自己,你亲自做完;做完后调用 project(action=submit, projectId, taskId, output, evidenceRefs) 提交交付,提交即完成,不会有人回来复核,证据必须附上。不要用 session_spawn/session_dispatch 或 task/workflow 绕开项目职责与汇报线。不要轮询等待,不要反复无进展重试。用 report 汇总关键进展。普通技术决策、阻塞与返工由你自行处理;本层解决不了的事才用 escalate:有父会话就交给直属父会话,由它判断和转述;只有顶层会话才把确需用户决定的问题交给用户,不得替 Boss 决定这些事项。所有任务交付后,用 deliver 记录带证据的阶段交付,后续可继续派发。上下文有限,明确假设,主动寻找反证。只在本次触发范围内工作。";
|
|
27
27
|
const text = (value, label) => {
|
|
28
28
|
if (typeof value !== "string" || !value.trim())
|
|
29
29
|
throw new Error(`${label} 不能为空`);
|
|
@@ -428,19 +428,21 @@ export class ProjectService {
|
|
|
428
428
|
* else has not answered this case, and settling it would repeat the mistake this project
|
|
429
429
|
* already made once: one answer closing every case of that member at once.
|
|
430
430
|
*/
|
|
431
|
-
settleEscalationsByMessage(p, actor, target, content) {
|
|
431
|
+
settleEscalationsByMessage(p, actor, target, content, existingIds) {
|
|
432
432
|
if (!actor)
|
|
433
433
|
return;
|
|
434
434
|
const answer = truncate(oneLine(content), 200);
|
|
435
435
|
let settled = 0;
|
|
436
436
|
for (const e of p.escalations ?? []) {
|
|
437
|
+
if (existingIds && !existingIds.has(e.id))
|
|
438
|
+
continue;
|
|
437
439
|
if (e.status !== "open")
|
|
438
440
|
continue;
|
|
439
441
|
if ((e.audience ?? "boss") !== "supervisor")
|
|
440
442
|
continue;
|
|
441
443
|
if (e.targetConversationId !== actor)
|
|
442
444
|
continue;
|
|
443
|
-
if (e.requestedByConversationId
|
|
445
|
+
if (e.requestedByConversationId !== target)
|
|
444
446
|
continue;
|
|
445
447
|
e.status = "resolved";
|
|
446
448
|
e.decision = answer;
|
|
@@ -631,6 +633,8 @@ export class ProjectService {
|
|
|
631
633
|
and the exported report all read the same corrected project, and none of them has to know
|
|
632
634
|
that the correction happened at all. */
|
|
633
635
|
this.reconcileInterrupted(p);
|
|
636
|
+
if (p.status === "awaiting_approval" && !p.escalations.some(item => item.status === "open" && item.severity === "high" && item.audience !== "supervisor"))
|
|
637
|
+
this.reconcile(p);
|
|
634
638
|
const resources = this.resources(p);
|
|
635
639
|
return {
|
|
636
640
|
...p,
|
|
@@ -885,6 +889,10 @@ export class ProjectService {
|
|
|
885
889
|
if (actor && actor !== p.ownerConversationId && actor !== p.initiatorConversationId && !p.tasks.some((t) => t.ownerConversationId === actor || t.reviewerConversationId === actor))
|
|
886
890
|
throw new Error("调用会话不属于项目执行团队");
|
|
887
891
|
}
|
|
892
|
+
canAddressUser(p, actor) {
|
|
893
|
+
return !actor || ((actor === p.ownerConversationId || actor === p.initiatorConversationId)
|
|
894
|
+
&& !this.store.conversation(actor)?.parentConversationId);
|
|
895
|
+
}
|
|
888
896
|
isMember(p, actor) {
|
|
889
897
|
if (!actor)
|
|
890
898
|
return false;
|
|
@@ -899,15 +907,16 @@ export class ProjectService {
|
|
|
899
907
|
return false;
|
|
900
908
|
}
|
|
901
909
|
directSupervisor(p, actor, taskId) {
|
|
902
|
-
if (!actor
|
|
910
|
+
if (!actor)
|
|
903
911
|
return undefined;
|
|
904
912
|
const session = this.store.conversation(actor);
|
|
905
|
-
const
|
|
906
|
-
if (
|
|
907
|
-
return
|
|
908
|
-
|
|
909
|
-
|
|
910
|
-
|
|
913
|
+
const parent = session?.parentConversationId ? this.store.conversation(session.parentConversationId) : undefined;
|
|
914
|
+
if (parent && !parent.archivedAt && parent.workspaceId === p.workspaceId && this.isMember(p, parent.id))
|
|
915
|
+
return parent.id;
|
|
916
|
+
if (actor === p.ownerConversationId || actor === p.initiatorConversationId)
|
|
917
|
+
return undefined;
|
|
918
|
+
const assigned = p.tasks.filter(item => item.ownerConversationId === actor || item.reviewerConversationId === actor);
|
|
919
|
+
const t = assigned.find(item => item.id === taskId) ?? assigned[0];
|
|
911
920
|
const manager = t ? this.manager(p, t) : undefined;
|
|
912
921
|
if (manager && this.isMember(p, manager))
|
|
913
922
|
return manager;
|
|
@@ -949,9 +958,8 @@ export class ProjectService {
|
|
|
949
958
|
const project = this.liveProjectForSession(conversationId);
|
|
950
959
|
if (!project)
|
|
951
960
|
return { ok: true };
|
|
952
|
-
if (
|
|
961
|
+
if (this.canAddressUser(project, conversationId))
|
|
953
962
|
return { ok: true };
|
|
954
|
-
}
|
|
955
963
|
return {
|
|
956
964
|
ok: false,
|
|
957
965
|
reason: "项目成员不能直接向 Boss 提问:请通过直接上级上报,由负责人代为转述",
|
|
@@ -966,10 +974,9 @@ export class ProjectService {
|
|
|
966
974
|
t.updatedAt = stamp();
|
|
967
975
|
this.event(p, "ready", `前置交付已验收:${t.title}`, t.id);
|
|
968
976
|
}
|
|
969
|
-
const isLeader = (convId) => !convId || convId === p.ownerConversationId || convId === p.initiatorConversationId;
|
|
970
977
|
const openBoss = p.escalations.filter((e) => e.status === "open" && (e.audience === "boss" || !e.audience));
|
|
971
|
-
const hasLeaderBlockedTask = p.tasks.some((t) => t.status === "blocked" &&
|
|
972
|
-
const lastLeaderProjectReport = [...p.reports].reverse().find((r) => !r.taskId &&
|
|
978
|
+
const hasLeaderBlockedTask = p.tasks.some((t) => t.status === "blocked" && this.canAddressUser(p, t.blockedReportedByConversationId));
|
|
979
|
+
const lastLeaderProjectReport = [...p.reports].reverse().find((r) => !r.taskId && this.canAddressUser(p, r.authorConversationId));
|
|
973
980
|
const leaderProjectBlocked = lastLeaderProjectReport?.kind === "blocked";
|
|
974
981
|
/* AN INTERRUPTED TASK BLOCKS THE PROJECT. Its execution session is gone, so nobody is working
|
|
975
982
|
on it and nobody will report back on it: the project is not "running", it is waiting for a
|
|
@@ -2038,7 +2045,8 @@ export class ProjectService {
|
|
|
2038
2045
|
const t = input.taskId ? this.task(p, text(input.taskId, "任务 id")) : undefined;
|
|
2039
2046
|
if (t && ["completed", "cancelled"].includes(t.status) && input.kind === "blocked")
|
|
2040
2047
|
throw new Error("已结束的任务不能标记阻塞");
|
|
2041
|
-
|
|
2048
|
+
const projectContact = actor === p.ownerConversationId || (!t && actor === p.initiatorConversationId);
|
|
2049
|
+
if (actor && !projectContact && (!t || ![t.ownerConversationId, t.reviewerConversationId, this.manager(p, t)].includes(actor)))
|
|
2042
2050
|
throw new Error("仅可汇报本人负责的任务");
|
|
2043
2051
|
const report = { id: randomUUID(), projectId: id, taskId: t?.id, authorConversationId: actor, kind: input.kind,
|
|
2044
2052
|
progress: text(input.progress, "汇报进展"), summary: typeof input.summary === "string" && input.summary.trim() ? text(input.summary, "汇报标题") : undefined, variance: optional(input.variance, "偏差"), nextStep: optional(input.nextStep, "下一步"), risks: strings(input.risks, "风险"),
|
|
@@ -2052,7 +2060,7 @@ export class ProjectService {
|
|
|
2052
2060
|
t.blockedReportedByConversationId = actor;
|
|
2053
2061
|
t.updatedAt = stamp();
|
|
2054
2062
|
}
|
|
2055
|
-
if (actor &&
|
|
2063
|
+
if (actor && !this.canAddressUser(p, actor)) {
|
|
2056
2064
|
memberBlockedReport = true;
|
|
2057
2065
|
supervisorToWake = this.directSupervisor(p, actor, t?.id);
|
|
2058
2066
|
taskForWake = t;
|
|
@@ -2064,7 +2072,7 @@ export class ProjectService {
|
|
|
2064
2072
|
}, actor);
|
|
2065
2073
|
if (supervisorToWake) {
|
|
2066
2074
|
const taskInfo = taskForWake ? `任务 ${taskForWake.id}(${taskForWake.title})` : "所属任务";
|
|
2067
|
-
await this.wake(supervisorToWake, `下级成员(会话:${actor})汇报阻塞:${taskInfo}\n原因:${report.progress}\n
|
|
2075
|
+
await this.wake(supervisorToWake, `下级成员(会话:${actor})汇报阻塞:${taskInfo}\n原因:${report.progress}\n请先在本层处理;仍需上级协助时,收敛后沿汇报线转述。`, "阻塞上报", id, workspaceId, actor);
|
|
2068
2076
|
}
|
|
2069
2077
|
else if (memberBlockedReport) {
|
|
2070
2078
|
/* A MEMBER REPORTED A BLOCK AND NO SUPERVISOR COULD BE FOUND. The report is saved either
|
|
@@ -2086,7 +2094,7 @@ export class ProjectService {
|
|
|
2086
2094
|
const t = input.taskId
|
|
2087
2095
|
? this.task(p, text(input.taskId, "任务 id"))
|
|
2088
2096
|
: p.tasks.find((task) => task.ownerConversationId === actor || task.reviewerConversationId === actor);
|
|
2089
|
-
const isBossAudience =
|
|
2097
|
+
const isBossAudience = this.canAddressUser(p, actor);
|
|
2090
2098
|
const audience = isBossAudience ? "boss" : "supervisor";
|
|
2091
2099
|
let targetConversationId;
|
|
2092
2100
|
if (!isBossAudience) {
|
|
@@ -2124,7 +2132,7 @@ export class ProjectService {
|
|
|
2124
2132
|
return e;
|
|
2125
2133
|
}, actor);
|
|
2126
2134
|
if (supervisorToWake) {
|
|
2127
|
-
await this.wake(supervisorToWake, `下级成员(会话:${actor},身份:${wakeMemberRole ?? "执行者"})发起例外升级(ID:${result.id}):\n${result.title ? `待决问题:${result.title}\n` : ""}原因:${result.reason}\n严重级别:${result.severity}\n
|
|
2135
|
+
await this.wake(supervisorToWake, `下级成员(会话:${actor},身份:${wakeMemberRole ?? "执行者"})发起例外升级(ID:${result.id}):\n${result.title ? `待决问题:${result.title}\n` : ""}原因:${result.reason}\n严重级别:${result.severity}\n请先在本层处理。若仍需上级或用户作决定,由你收敛问题并发起新的升级。`, `例外升级(ID:${result.id})`, id, workspaceId, actor);
|
|
2128
2136
|
}
|
|
2129
2137
|
return result;
|
|
2130
2138
|
}
|
|
@@ -2221,23 +2229,7 @@ export class ProjectService {
|
|
|
2221
2229
|
}
|
|
2222
2230
|
}
|
|
2223
2231
|
else {
|
|
2224
|
-
const
|
|
2225
|
-
? p.tasks.find((t) => t.id === result.taskId)
|
|
2226
|
-
: p.tasks.find((t) => t.ownerConversationId === result.requestedByConversationId || t.reviewerConversationId === result.requestedByConversationId);
|
|
2227
|
-
let directLeaderId;
|
|
2228
|
-
if (targetTask) {
|
|
2229
|
-
if (targetTask.role === "leader" && targetTask.ownerConversationId) {
|
|
2230
|
-
directLeaderId = targetTask.ownerConversationId;
|
|
2231
|
-
}
|
|
2232
|
-
else if (targetTask.parentTaskId) {
|
|
2233
|
-
const parent = p.tasks.find((t) => t.id === targetTask.parentTaskId);
|
|
2234
|
-
directLeaderId = parent?.ownerConversationId ?? targetTask.accountableConversationId;
|
|
2235
|
-
}
|
|
2236
|
-
else {
|
|
2237
|
-
directLeaderId = targetTask.accountableConversationId ?? p.ownerConversationId;
|
|
2238
|
-
}
|
|
2239
|
-
}
|
|
2240
|
-
const recipientId = directLeaderId || p.ownerConversationId;
|
|
2232
|
+
const recipientId = result.requestedByConversationId ?? p.initiatorConversationId ?? p.ownerConversationId;
|
|
2241
2233
|
if (recipientId) {
|
|
2242
2234
|
await this.wake(recipientId, `Boss 已处理项目 ${p.id} 的例外:${result.reason}\n决策:${result.decision}\n先读取 project 最新状态,按决策继续范围内的工作。`, `例外处理结果(ID:${result.id})`, id, workspaceId, actor);
|
|
2243
2235
|
}
|
|
@@ -2385,7 +2377,11 @@ export class ProjectService {
|
|
|
2385
2377
|
}
|
|
2386
2378
|
if (!this.orchestrator)
|
|
2387
2379
|
throw new Error("会话编排服务未就绪");
|
|
2380
|
+
const existingIds = new Set(p.escalations.filter(item => item.status === "open" && item.audience === "supervisor"
|
|
2381
|
+
&& item.targetConversationId === actor && item.requestedByConversationId === target).map(item => item.id));
|
|
2388
2382
|
await this.dispatchContext(target, message, { wait: false });
|
|
2383
|
+
if (existingIds.size)
|
|
2384
|
+
await this.change(id, workspaceId, current => this.settleEscalationsByMessage(current, actor, target, message, existingIds));
|
|
2389
2385
|
return { ok: true, conversationId: target, delivered: true };
|
|
2390
2386
|
}
|
|
2391
2387
|
async tool(body, workspaceId, actor) {
|
|
@@ -4,6 +4,7 @@ export interface SessionReminderItem {
|
|
|
4
4
|
reminderId: string;
|
|
5
5
|
conversationId: string;
|
|
6
6
|
note: string;
|
|
7
|
+
repeat: boolean;
|
|
7
8
|
delaySeconds: number;
|
|
8
9
|
fireAt: number;
|
|
9
10
|
createdAt: number;
|
|
@@ -14,19 +15,22 @@ export declare class SessionReminderService {
|
|
|
14
15
|
private reminders;
|
|
15
16
|
constructor(runService: RunService, store: Store);
|
|
16
17
|
/**
|
|
17
|
-
* Schedules a
|
|
18
|
+
* Schedules a wake-up for the same conversation after delaySeconds.
|
|
18
19
|
*/
|
|
19
20
|
createReminder(params: {
|
|
20
21
|
conversationId: string;
|
|
21
22
|
delaySeconds: number;
|
|
22
|
-
note
|
|
23
|
+
note?: string;
|
|
24
|
+
repeat?: boolean;
|
|
23
25
|
}): {
|
|
24
26
|
ok: true;
|
|
25
27
|
reminderId: string;
|
|
26
28
|
delaySeconds: number;
|
|
27
29
|
note: string;
|
|
30
|
+
repeat: boolean;
|
|
28
31
|
fireAt: string;
|
|
29
32
|
};
|
|
33
|
+
private arm;
|
|
30
34
|
/**
|
|
31
35
|
* Cancels a pending reminder by ID.
|
|
32
36
|
*
|
|
@@ -49,7 +53,7 @@ export declare class SessionReminderService {
|
|
|
49
53
|
*/
|
|
50
54
|
cancelAllForConversation(conversationId: string): void;
|
|
51
55
|
/**
|
|
52
|
-
* Timer callback:
|
|
56
|
+
* Timer callback: wakes the originating conversation.
|
|
53
57
|
*/
|
|
54
58
|
private triggerReminder;
|
|
55
59
|
}
|
|
@@ -8,10 +8,10 @@ export class SessionReminderService {
|
|
|
8
8
|
this.store = store;
|
|
9
9
|
}
|
|
10
10
|
/**
|
|
11
|
-
* Schedules a
|
|
11
|
+
* Schedules a wake-up for the same conversation after delaySeconds.
|
|
12
12
|
*/
|
|
13
13
|
createReminder(params) {
|
|
14
|
-
const { conversationId,
|
|
14
|
+
const { conversationId, repeat = false } = params;
|
|
15
15
|
const delaySeconds = Math.max(1, Math.round(params.delaySeconds));
|
|
16
16
|
// A REMINDER THAT FIRES IMMEDIATELY IS NOT A REMINDER. `Math.max(1, ...)` would quietly turn a
|
|
17
17
|
// zero or negative delay into "one second from now", so the bad number is refused in words
|
|
@@ -19,9 +19,6 @@ export class SessionReminderService {
|
|
|
19
19
|
if (!Number.isFinite(params.delaySeconds) || params.delaySeconds <= 0) {
|
|
20
20
|
throw new Error("提醒需要正的秒数:请传 delaySeconds(或 seconds)。");
|
|
21
21
|
}
|
|
22
|
-
if (!note || !note.trim()) {
|
|
23
|
-
throw new Error("提醒内容 (note) 不能为空");
|
|
24
|
-
}
|
|
25
22
|
const conversation = this.store.conversation(conversationId);
|
|
26
23
|
if (!conversation) {
|
|
27
24
|
throw new Error(`找不到会话:${conversationId}`);
|
|
@@ -29,30 +26,34 @@ export class SessionReminderService {
|
|
|
29
26
|
const reminderId = `rem_${randomUUID()}`;
|
|
30
27
|
const now = Date.now();
|
|
31
28
|
const fireAt = now + delaySeconds * 1000;
|
|
29
|
+
if (fireAt > 8.64e15)
|
|
30
|
+
throw new Error("提醒间隔超出日期范围。");
|
|
32
31
|
const item = {
|
|
33
32
|
reminderId,
|
|
34
33
|
conversationId,
|
|
35
|
-
note: note
|
|
34
|
+
note: repeat ? "" : (params.note?.trim() ?? ""),
|
|
35
|
+
repeat,
|
|
36
36
|
delaySeconds,
|
|
37
37
|
fireAt,
|
|
38
38
|
createdAt: now,
|
|
39
39
|
};
|
|
40
|
-
|
|
41
|
-
void this.triggerReminder(reminderId);
|
|
42
|
-
}, delaySeconds * 1000);
|
|
43
|
-
// Node process unref to avoid blocking process exit if idle
|
|
44
|
-
if (typeof timer.unref === "function") {
|
|
45
|
-
timer.unref();
|
|
46
|
-
}
|
|
47
|
-
this.reminders.set(reminderId, { item, timer });
|
|
40
|
+
this.reminders.set(reminderId, { item, timer: this.arm(item), lastFiredAt: now, delivering: false });
|
|
48
41
|
return {
|
|
49
42
|
ok: true,
|
|
50
43
|
reminderId,
|
|
51
44
|
delaySeconds,
|
|
52
45
|
note: item.note,
|
|
46
|
+
repeat,
|
|
53
47
|
fireAt: new Date(fireAt).toISOString(),
|
|
54
48
|
};
|
|
55
49
|
}
|
|
50
|
+
arm(item) {
|
|
51
|
+
// Node treats delays beyond the signed 32-bit limit as 1 ms. Re-arm long waits in chunks.
|
|
52
|
+
const delay = Math.min(item.fireAt - Date.now(), 2 ** 31 - 1);
|
|
53
|
+
const timer = setTimeout(() => void this.triggerReminder(item.reminderId), delay);
|
|
54
|
+
timer.unref();
|
|
55
|
+
return timer;
|
|
56
|
+
}
|
|
56
57
|
/**
|
|
57
58
|
* Cancels a pending reminder by ID.
|
|
58
59
|
*
|
|
@@ -78,7 +79,6 @@ export class SessionReminderService {
|
|
|
78
79
|
*/
|
|
79
80
|
listReminders(conversationId) {
|
|
80
81
|
const results = [];
|
|
81
|
-
const now = Date.now();
|
|
82
82
|
for (const { item } of this.reminders.values()) {
|
|
83
83
|
if (item.conversationId === conversationId) {
|
|
84
84
|
results.push({ ...item });
|
|
@@ -98,23 +98,44 @@ export class SessionReminderService {
|
|
|
98
98
|
}
|
|
99
99
|
}
|
|
100
100
|
/**
|
|
101
|
-
* Timer callback:
|
|
101
|
+
* Timer callback: wakes the originating conversation.
|
|
102
102
|
*/
|
|
103
103
|
async triggerReminder(reminderId) {
|
|
104
104
|
const entry = this.reminders.get(reminderId);
|
|
105
105
|
if (!entry)
|
|
106
106
|
return;
|
|
107
|
-
|
|
108
|
-
|
|
107
|
+
const now = Date.now();
|
|
108
|
+
if (now < entry.item.fireAt) {
|
|
109
|
+
entry.timer = this.arm(entry.item);
|
|
110
|
+
return;
|
|
111
|
+
}
|
|
112
|
+
const { conversationId, note, repeat, delaySeconds } = entry.item;
|
|
109
113
|
const conversation = this.store.conversation(conversationId);
|
|
110
114
|
if (!conversation || conversation.archivedAt) {
|
|
115
|
+
this.reminders.delete(reminderId);
|
|
111
116
|
return;
|
|
112
117
|
}
|
|
118
|
+
if (repeat) {
|
|
119
|
+
entry.item.fireAt = now + delaySeconds * 1000;
|
|
120
|
+
entry.timer = this.arm(entry.item);
|
|
121
|
+
// One wake-up is enough while a previous reminder is running or still in the queue.
|
|
122
|
+
if (entry.delivering || this.store.listWaitingMessages(conversationId).some(message => message.source === "session-reminder"))
|
|
123
|
+
return;
|
|
124
|
+
}
|
|
125
|
+
else {
|
|
126
|
+
this.reminders.delete(reminderId);
|
|
127
|
+
}
|
|
128
|
+
const elapsed = Math.round((now - entry.lastFiredAt) / 1000);
|
|
129
|
+
entry.delivering = true;
|
|
113
130
|
try {
|
|
114
|
-
await this.runService.enqueueReminder(conversationId, note);
|
|
131
|
+
await this.runService.enqueueReminder(conversationId, note || `距上次计时已过 ${elapsed} 秒。`);
|
|
132
|
+
entry.lastFiredAt = now;
|
|
115
133
|
}
|
|
116
134
|
catch (error) {
|
|
117
135
|
console.warn(`Super Pi: delivering session reminder to ${conversationId} failed:`, error instanceof Error ? error.message : String(error));
|
|
118
136
|
}
|
|
137
|
+
finally {
|
|
138
|
+
entry.delivering = false;
|
|
139
|
+
}
|
|
119
140
|
}
|
|
120
141
|
}
|
|
@@ -2102,13 +2102,13 @@ export function createHttpServer(options) {
|
|
|
2102
2102
|
json(400, { error: "提醒需要正的秒数:请传 delaySeconds(或 seconds)。" });
|
|
2103
2103
|
return;
|
|
2104
2104
|
}
|
|
2105
|
-
const note = typeof body.note === "string" ? body.note.trim() : "";
|
|
2106
|
-
if (!note) {
|
|
2107
|
-
json(400, { error: "提醒内容不能为空:note 要写清楚提醒什么。" });
|
|
2108
|
-
return;
|
|
2109
|
-
}
|
|
2110
2105
|
try {
|
|
2111
|
-
const created = reminders.createReminder({
|
|
2106
|
+
const created = reminders.createReminder({
|
|
2107
|
+
conversationId: callerConversationId,
|
|
2108
|
+
delaySeconds,
|
|
2109
|
+
note: typeof body.note === "string" ? body.note : undefined,
|
|
2110
|
+
repeat: body.repeat === true,
|
|
2111
|
+
});
|
|
2112
2112
|
json(200, { ...created, ok: true });
|
|
2113
2113
|
}
|
|
2114
2114
|
catch (error) {
|
package/dist/server/index.js
CHANGED
|
@@ -7,6 +7,7 @@ import { mkdir } from "node:fs/promises";
|
|
|
7
7
|
import { homedir } from "node:os";
|
|
8
8
|
import { join, resolve } from "node:path";
|
|
9
9
|
import { pathToFileURL } from "node:url";
|
|
10
|
+
import { isChildSession } from "../shared/child-session-lock.js";
|
|
10
11
|
import { openStateStore } from "./persistence/open-state-store.js";
|
|
11
12
|
import { PiRpcRuntime, WelcomeRuntime } from "./runtime.js";
|
|
12
13
|
import { agentModeOf, resolveAgentDirectories } from "./agents.js";
|
|
@@ -187,7 +188,10 @@ const feishu = new FeishuService();
|
|
|
187
188
|
process.env.SUPER_PI_FEISHU_ENDPOINT = `http://${internalHost}:${port}/api/feishu/tool`;
|
|
188
189
|
const web = new WebService();
|
|
189
190
|
process.env.SUPER_PI_WEB_ENDPOINT = `http://${internalHost}:${port}/api/web/tool`;
|
|
190
|
-
const extensionUiService = new ExtensionUiService(broadcaster
|
|
191
|
+
const extensionUiService = new ExtensionUiService(broadcaster, id => {
|
|
192
|
+
const { parentConversationId, parent } = store.childSessionFacts(id);
|
|
193
|
+
return !isChildSession(parentConversationId, parent);
|
|
194
|
+
});
|
|
191
195
|
const supervisor = new SubagentSupervisor(join(dataDir, "pi-sessions"), undefined, {
|
|
192
196
|
dir: initialAgentDirs,
|
|
193
197
|
promptDir: agentPromptDir,
|
package/dist/server/store.d.ts
CHANGED
|
@@ -154,7 +154,7 @@ export declare class Store {
|
|
|
154
154
|
*
|
|
155
155
|
* `supervisor` = 团队内部的事(会话在等自己的直属上级),`boss` = 到了顶层。
|
|
156
156
|
* 一个会话同时开着内部和顶层两条时,顶层那条赢:那是唯一需要用户听见的一条。
|
|
157
|
-
*
|
|
157
|
+
* 旧的子会话记录在加载时归回父会话,此处仅聚合规范化后的受众。
|
|
158
158
|
*/
|
|
159
159
|
openEscalationAudiences(): Map<string, "supervisor" | "boss">;
|
|
160
160
|
/** Child conversation IDs whose enqueued session result is still waiting or sending on a non-archived parent. */
|
package/dist/server/store.js
CHANGED
|
@@ -652,6 +652,43 @@ function reconcileBackgroundTasks(state) {
|
|
|
652
652
|
}
|
|
653
653
|
return { orphaned, changed: orphaned.length > 0, unlinked };
|
|
654
654
|
}
|
|
655
|
+
function normalizeProjectEscalations(project, conversation) {
|
|
656
|
+
let changed = false;
|
|
657
|
+
for (const item of project.escalations ?? []) {
|
|
658
|
+
if (String(item.status) === "pending") {
|
|
659
|
+
item.status = "open";
|
|
660
|
+
changed = true;
|
|
661
|
+
}
|
|
662
|
+
if (item.status !== "open" || item.audience === "supervisor" || !item.requestedByConversationId)
|
|
663
|
+
continue;
|
|
664
|
+
const requester = conversation(item.requestedByConversationId);
|
|
665
|
+
const assigned = item.requestedByConversationId !== project.ownerConversationId
|
|
666
|
+
&& item.requestedByConversationId !== project.initiatorConversationId
|
|
667
|
+
? project.tasks?.find(task => task.ownerConversationId === item.requestedByConversationId
|
|
668
|
+
|| task.reviewerConversationId === item.requestedByConversationId) : undefined;
|
|
669
|
+
const taskManager = assigned?.parentTaskId
|
|
670
|
+
? project.tasks.find(task => task.id === assigned.parentTaskId)?.ownerConversationId : project.ownerConversationId;
|
|
671
|
+
const fallback = !requester && item.requestedByConversationId === project.ownerConversationId ? project.initiatorConversationId : undefined;
|
|
672
|
+
if (!requester?.parentConversationId && !assigned && !fallback)
|
|
673
|
+
continue;
|
|
674
|
+
// Old versions let project leaders address the user while they still had a parent.
|
|
675
|
+
const parent = [requester?.parentConversationId, assigned ? taskManager : undefined, fallback]
|
|
676
|
+
.filter((id) => Boolean(id && id !== item.requestedByConversationId))
|
|
677
|
+
.map(conversation)
|
|
678
|
+
.find(candidate => candidate?.workspaceId === project.workspaceId && !candidate.archivedAt
|
|
679
|
+
&& (candidate.id === project.ownerConversationId || candidate.id === project.initiatorConversationId
|
|
680
|
+
|| project.tasks?.some(task => task.ownerConversationId === candidate.id || task.reviewerConversationId === candidate.id)));
|
|
681
|
+
item.audience = "supervisor";
|
|
682
|
+
item.targetConversationId = parent?.id;
|
|
683
|
+
if (!parent) {
|
|
684
|
+
item.status = "dismissed";
|
|
685
|
+
item.decision = "旧例外找不到可处理的直属上级,原始记录已保留。";
|
|
686
|
+
item.resolvedAt = now();
|
|
687
|
+
}
|
|
688
|
+
changed = true;
|
|
689
|
+
}
|
|
690
|
+
return changed;
|
|
691
|
+
}
|
|
655
692
|
export class Store {
|
|
656
693
|
repository;
|
|
657
694
|
state;
|
|
@@ -691,7 +728,10 @@ export class Store {
|
|
|
691
728
|
if (state.projects !== undefined && !Array.isArray(state.projects))
|
|
692
729
|
delete state.projects;
|
|
693
730
|
let migratedProjects = false;
|
|
731
|
+
const conversationsById = new Map((state.conversations ?? []).filter(Boolean).map(item => [item.id, item]));
|
|
694
732
|
for (const project of state.projects ?? []) {
|
|
733
|
+
if (normalizeProjectEscalations(project, id => conversationsById.get(id)))
|
|
734
|
+
migratedProjects = true;
|
|
695
735
|
if (String(project.status) !== "completed")
|
|
696
736
|
continue;
|
|
697
737
|
project.status = project.ownerConversationId ? "active" : "awaiting_start";
|
|
@@ -878,7 +918,7 @@ export class Store {
|
|
|
878
918
|
*
|
|
879
919
|
* `supervisor` = 团队内部的事(会话在等自己的直属上级),`boss` = 到了顶层。
|
|
880
920
|
* 一个会话同时开着内部和顶层两条时,顶层那条赢:那是唯一需要用户听见的一条。
|
|
881
|
-
*
|
|
921
|
+
* 旧的子会话记录在加载时归回父会话,此处仅聚合规范化后的受众。
|
|
882
922
|
*/
|
|
883
923
|
openEscalationAudiences() {
|
|
884
924
|
const audiences = new Map();
|
|
@@ -921,6 +961,7 @@ export class Store {
|
|
|
921
961
|
if (!this.state.projects)
|
|
922
962
|
this.state.projects = [];
|
|
923
963
|
const stored = structuredClone(project);
|
|
964
|
+
normalizeProjectEscalations(stored, id => this.state.conversations.find(item => item.id === id));
|
|
924
965
|
const index = this.state.projects.findIndex((item) => item.id === stored.id);
|
|
925
966
|
if (index < 0)
|
|
926
967
|
this.state.projects.unshift(stored);
|