@evandu/super-pi 0.1.160 → 0.1.161
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/agents/super-pi-task/core.ts +1 -1
- package/agents/super-pi-task/index.ts +2 -1
- package/dist/client/.super-pi-client-sources.json +5 -5
- package/dist/client/assets/{CodeMirrorEditor-DeH4azrn.js → CodeMirrorEditor-CDaL0eZg.js} +2 -2
- package/dist/client/assets/{dist-QI-T3k9i.js → dist-BA58NP6M.js} +1 -1
- package/dist/client/assets/{dist-DefZp4Fa.js → dist-BDNs_xhA.js} +1 -1
- package/dist/client/assets/{dist-CsDwtK1F.js → dist-BHWAql8E.js} +1 -1
- package/dist/client/assets/{dist-u0a7h80y.js → dist-BJG0l-sn.js} +1 -1
- package/dist/client/assets/{dist-C1iGzBNB.js → dist-BZgXABCU.js} +1 -1
- package/dist/client/assets/{dist-7jfYXjWH.js → dist-CSdmsB0d.js} +1 -1
- package/dist/client/assets/{dist-CA4ywFCU.js → dist-CTelFWCj.js} +1 -1
- package/dist/client/assets/{dist-ClXbSHKM.js → dist-CWgIVqDh.js} +1 -1
- package/dist/client/assets/{dist-BotfOUXo.js → dist-CZlI9li3.js} +1 -1
- package/dist/client/assets/{dist-CNdHgilU.js → dist-CiyMaqx4.js} +1 -1
- package/dist/client/assets/{dist-CdG0dOlF.js → dist-Cm3rvfSQ.js} +1 -1
- package/dist/client/assets/{dist-CrwnaHWk.js → dist-D1cVuzfF.js} +1 -1
- package/dist/client/assets/{dist-CBAhomD3.js → dist-DL66Z_jn.js} +1 -1
- package/dist/client/assets/{dist-DWHnCS4H.js → dist-DO3oDtGc.js} +1 -1
- package/dist/client/assets/{dist-Br9aGZZB.js → dist-DOdfw0L-.js} +1 -1
- package/dist/client/assets/{dist-BeLF-5JB.js → dist-DPwOtaMP.js} +1 -1
- package/dist/client/assets/{dist-C1FnggSV.js → dist-DVCVhi5y.js} +1 -1
- package/dist/client/assets/{dist-DjepRcJQ.js → dist-DhPkHpbv.js} +1 -1
- package/dist/client/assets/{dist-Fa50HH8A.js → dist-DnaLB6eU.js} +1 -1
- package/dist/client/assets/{dist-CrIX2hon.js → dist-S5Gkqadu.js} +1 -1
- package/dist/client/assets/{dist-Bl20l56d.js → dist-gCJkYldU.js} +1 -1
- package/dist/client/assets/{dist-CgShg9H1.js → dist-jwSzBAO8.js} +1 -1
- package/dist/client/assets/{index-D3XEFVty.js → index-B9tN8KD3.js} +10 -10
- package/dist/client/assets/{index-CYvr3uNw.css → index-BK3ZIqJj.css} +1 -1
- package/dist/client/index.html +2 -2
- package/dist/server/application/conversation-service.d.ts +6 -0
- package/dist/server/application/conversation-service.js +6 -1
- package/dist/server/application/project-service.d.ts +72 -1
- package/dist/server/application/project-service.js +256 -19
- package/dist/server/application/session-orchestrator-service.d.ts +9 -0
- package/dist/server/application/session-orchestrator-service.js +1 -0
- package/dist/server/http-server.js +8 -0
- package/dist/server/store.d.ts +1 -0
- package/dist/server/store.js +8 -1
- package/dist/server/types.d.ts +36 -0
- package/package.json +1 -1
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-B9tN8KD3.js"></script>
|
|
12
|
+
<link rel="stylesheet" crossorigin href="/assets/index-BK3ZIqJj.css">
|
|
13
13
|
</head>
|
|
14
14
|
<body>
|
|
15
15
|
<div id="root"></div>
|
|
@@ -44,10 +44,16 @@ export declare class ConversationService {
|
|
|
44
44
|
* tree's edge (`parentConversationId`) and its origin. Only the orchestrator passes it - the "+"
|
|
45
45
|
* button and every other caller create a top-level conversation by omission, which is the same
|
|
46
46
|
* "absence means top level" rule the pre-tree state.json files read under.
|
|
47
|
+
*
|
|
48
|
+
* `separateMemoryTree` says that this conversation is its own working context: it must not
|
|
49
|
+
* inherit the memory tree of the conversation it hangs under. A project leader is the case that
|
|
50
|
+
* needs it - it sits in the user's chat in the sidebar, and it shares nothing of that chat's
|
|
51
|
+
* tree-scoped memories with it.
|
|
47
52
|
*/
|
|
48
53
|
createConversation(workspaceId: string, parentage?: {
|
|
49
54
|
parentConversationId?: string;
|
|
50
55
|
origin?: "user" | "orchestrator";
|
|
56
|
+
separateMemoryTree?: boolean;
|
|
51
57
|
}, cwd?: string): Promise<string>;
|
|
52
58
|
/**
|
|
53
59
|
* Name a conversation from what was said in it. Returns the title; the CALLER applies it, because the
|
|
@@ -50,6 +50,11 @@ export class ConversationService {
|
|
|
50
50
|
* tree's edge (`parentConversationId`) and its origin. Only the orchestrator passes it - the "+"
|
|
51
51
|
* button and every other caller create a top-level conversation by omission, which is the same
|
|
52
52
|
* "absence means top level" rule the pre-tree state.json files read under.
|
|
53
|
+
*
|
|
54
|
+
* `separateMemoryTree` says that this conversation is its own working context: it must not
|
|
55
|
+
* inherit the memory tree of the conversation it hangs under. A project leader is the case that
|
|
56
|
+
* needs it - it sits in the user's chat in the sidebar, and it shares nothing of that chat's
|
|
57
|
+
* tree-scoped memories with it.
|
|
53
58
|
*/
|
|
54
59
|
async createConversation(workspaceId, parentage, cwd) {
|
|
55
60
|
const workspace = this.store.workspace(workspaceId);
|
|
@@ -128,7 +133,7 @@ export class ConversationService {
|
|
|
128
133
|
// `null` is intentional here: Store uses it to remove a workspace value that it
|
|
129
134
|
// would otherwise have copied before applying the resolved configuration.
|
|
130
135
|
const sessionCwd = await normalizeSessionCwd(workspace.path, cwd);
|
|
131
|
-
const defaults = { ...resolved, agentId: resolved.agentId ?? null, model: resolved.model ?? null, thinkingLevel: resolved.thinkingLevel ?? null, ...(sessionCwd ? { cwd: sessionCwd } : {}), ...(modelNotice ? { modelNotice } : {}), ...(agentNotice ? { agentNotice } : {}), ...(parentage ? { parentConversationId: parentage.parentConversationId, origin: parentage.origin } : {}) };
|
|
136
|
+
const defaults = { ...resolved, agentId: resolved.agentId ?? null, model: resolved.model ?? null, thinkingLevel: resolved.thinkingLevel ?? null, ...(sessionCwd ? { cwd: sessionCwd } : {}), ...(modelNotice ? { modelNotice } : {}), ...(agentNotice ? { agentNotice } : {}), ...(parentage ? { parentConversationId: parentage.parentConversationId, origin: parentage.origin } : {}), ...(parentage?.separateMemoryTree ? { separateMemoryTree: true } : {}) };
|
|
132
137
|
const created = await this.store.createConversation(workspaceId, defaults);
|
|
133
138
|
this.broadcaster.broadcastState();
|
|
134
139
|
return created.id;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { Store } from "../store.js";
|
|
2
|
-
import type { Project, ProjectEscalation, ProjectReport, ProjectRisk, ProjectTask, SessionProfile } from "../types.js";
|
|
2
|
+
import type { Project, ProjectEscalation, ProjectMode, ProjectReport, ProjectRisk, ProjectTask, SessionProfile } from "../types.js";
|
|
3
3
|
import type { SessionOrchestratorService } from "./session-orchestrator-service.js";
|
|
4
4
|
export declare const profile: (value: unknown, label: string) => SessionProfile | undefined;
|
|
5
5
|
export declare const mergeProfile: (taskProfile?: SessionProfile, projectDefault?: SessionProfile) => SessionProfile | undefined;
|
|
@@ -20,6 +20,9 @@ export type CreateProjectInput = {
|
|
|
20
20
|
defaultExecutorProfile?: unknown;
|
|
21
21
|
defaultReviewerProfile?: unknown;
|
|
22
22
|
initiatorConversationId?: string;
|
|
23
|
+
/** "standard" (the default) or "lightweight" - the small project's shape, where the project
|
|
24
|
+
* leader session does the work itself and no independent reviewer session exists. */
|
|
25
|
+
mode?: ProjectMode;
|
|
23
26
|
};
|
|
24
27
|
export type AddTaskInput = Partial<ProjectTask> & {
|
|
25
28
|
title: string;
|
|
@@ -36,6 +39,16 @@ export type TopLevelTaskPlan = {
|
|
|
36
39
|
priority?: ProjectTask["priority"];
|
|
37
40
|
dependencies: string[];
|
|
38
41
|
};
|
|
42
|
+
/** What one click on 「提到 N Token 并继续」 produced. */
|
|
43
|
+
export type BudgetRaiseResult = {
|
|
44
|
+
project: Project;
|
|
45
|
+
/** The cap before the raise, so the panel can say what changed. */
|
|
46
|
+
previousMaxTokens: number;
|
|
47
|
+
/** The cap the server raised it to - the number the one-click button promised. */
|
|
48
|
+
suggestedMaxTokens: number;
|
|
49
|
+
/** How many budget exceptions were closed by the raise. */
|
|
50
|
+
resolvedEscalations: number;
|
|
51
|
+
};
|
|
39
52
|
/** Persist explicit domain fields only; transport credentials never enter project records. */
|
|
40
53
|
export declare class ProjectService {
|
|
41
54
|
private readonly store;
|
|
@@ -44,6 +57,16 @@ export declare class ProjectService {
|
|
|
44
57
|
constructor(store: Store, orchestrator?: (Pick<SessionOrchestratorService, "spawn" | "dispatch"> & Partial<Pick<SessionOrchestratorService, "stopSubtree">>) | undefined);
|
|
45
58
|
static taskView(task: ProjectTask, project: Pick<Project, "defaultExecutorProfile" | "defaultReviewerProfile">): ProjectTask;
|
|
46
59
|
private projectView;
|
|
60
|
+
/**
|
|
61
|
+
* THE NUMBER THE ONE-CLICK PATH OFFERS.
|
|
62
|
+
*
|
|
63
|
+
* The Boss does not type a budget when the budget runs out: a number typed in a hurry is a
|
|
64
|
+
* number nobody predicted, and a budget that is guessed wrong is the failure this whole path
|
|
65
|
+
* exists to remove. So the server suggests one instead - double what has already been spent,
|
|
66
|
+
* because an agent run that needed twice its first budget will need twice its second one, and
|
|
67
|
+
* never less than one token more than the current cap, so the offer always really raises it.
|
|
68
|
+
*/
|
|
69
|
+
private suggestedMaxTokens;
|
|
47
70
|
private raw;
|
|
48
71
|
private workspace;
|
|
49
72
|
private event;
|
|
@@ -52,6 +75,20 @@ export declare class ProjectService {
|
|
|
52
75
|
private leader;
|
|
53
76
|
private topLevelAuthor;
|
|
54
77
|
private manager;
|
|
78
|
+
/**
|
|
79
|
+
* DOES THIS TASK COUNT AS ACCEPTED?
|
|
80
|
+
*
|
|
81
|
+
* In a STANDARD project, acceptance means another session reviewed this delivery: the reviewer
|
|
82
|
+
* of the review must be the session that was spawned to review, and it must NOT be the session
|
|
83
|
+
* that did the work. Those conditions are the whole point of an independent review, so they
|
|
84
|
+
* stand exactly as they were.
|
|
85
|
+
*
|
|
86
|
+
* In a LIGHTWEIGHT project there is no reviewer session at all - the leader session does the
|
|
87
|
+
* work itself - so a delivery is accepted on the executor's own evidence. The flag that says so
|
|
88
|
+
* is written by `submit` and nowhere else, and it names the session that made the call, so a
|
|
89
|
+
* task with no accepted review at all still counts for nothing.
|
|
90
|
+
*/
|
|
91
|
+
private taskAccepted;
|
|
55
92
|
private requiredComplete;
|
|
56
93
|
private task;
|
|
57
94
|
private member;
|
|
@@ -80,10 +117,44 @@ export declare class ProjectService {
|
|
|
80
117
|
workspaceId?: string;
|
|
81
118
|
}, actor?: string): Promise<ProjectTask>;
|
|
82
119
|
updateStatus(id: string, status: Project["status"], workspaceId?: string): Promise<Project>;
|
|
120
|
+
/**
|
|
121
|
+
* THE SESSION THAT OPENED THE PROJECT MAY CANCEL IT.
|
|
122
|
+
*
|
|
123
|
+
* There is no delete here, and that is deliberate. The project record, its tasks, its events and
|
|
124
|
+
* its evidence references are the trail of what was tried; a project that went nowhere is
|
|
125
|
+
* evidence too. Cancelling stops the work and marks the project cancelled - the record stays,
|
|
126
|
+
* readable, with the reason attached.
|
|
127
|
+
*
|
|
128
|
+
* Only the session that opened the project may do this. A worker or a reviewer that could
|
|
129
|
+
* cancel the project it belongs to would have a way to make its own budget and concurrency
|
|
130
|
+
* guards disappear, and those guards are the only thing between a runaway agent and an
|
|
131
|
+
* unbounded bill. The human path - the panel's stop button - is unchanged and stays the Boss's.
|
|
132
|
+
*
|
|
133
|
+
* A reason is required: "we changed our minds" and "the customer shipped it last night" are
|
|
134
|
+
* different decisions, and the timeline is where that difference has to show up.
|
|
135
|
+
*/
|
|
136
|
+
cancel(id: string, body: Record<string, any>, workspaceId: string, actor: string): Promise<Project>;
|
|
83
137
|
updateBudget(id: string, input: {
|
|
84
138
|
maxTokens?: number;
|
|
85
139
|
maxConcurrent?: number;
|
|
86
140
|
}, workspaceId: string): Promise<Project>;
|
|
141
|
+
/**
|
|
142
|
+
* ONE CLICK: RAISE THE BUDGET AND LET THE WORK CONTINUE.
|
|
143
|
+
*
|
|
144
|
+
* Three things happen here, and they happen together: the cap goes up to a number the SERVER
|
|
145
|
+
* computed, the budget exception that is waiting for a decision is closed, and the work that
|
|
146
|
+
* was blocked is woken up again. Doing them apart is what made the old path painful - a Boss
|
|
147
|
+
* had to open a form, type a number, press save, and then wake the leader by hand, and every
|
|
148
|
+
* one of those steps was a chance to stop halfway.
|
|
149
|
+
*
|
|
150
|
+
* IT IS A BOSS OPERATION. A session may not raise the budget of its own project: the budget is
|
|
151
|
+
* the Boss's stop, and an agent that could lift its own limit would not have one. The HTTP
|
|
152
|
+
* layer refuses a request that carries a capability for the same reason.
|
|
153
|
+
*
|
|
154
|
+
* The manual `updateBudget` stays a SEPARATE intent: adjusting a number is not the same as
|
|
155
|
+
* asking for the work to continue, so the manual path does not continue anything.
|
|
156
|
+
*/
|
|
157
|
+
raiseBudgetAndContinue(id: string, workspaceId: string, callerConversationId?: string): Promise<BudgetRaiseResult>;
|
|
87
158
|
addReport(id: string, input: Omit<ProjectReport, "id" | "projectId" | "createdAt">, workspaceId?: string, actor?: string): Promise<ProjectReport>;
|
|
88
159
|
addEscalation(id: string, input: Pick<ProjectEscalation, "reason" | "severity" | "taskId">, workspaceId?: string, actor?: string): Promise<ProjectEscalation>;
|
|
89
160
|
resolveEscalation(id: string, escalationId: string, decision: string, status: "resolved" | "dismissed", workspaceId?: string): Promise<ProjectEscalation>;
|
|
@@ -1,5 +1,16 @@
|
|
|
1
1
|
import { randomUUID } from "node:crypto";
|
|
2
2
|
const stamp = () => new Date().toISOString();
|
|
3
|
+
/**
|
|
4
|
+
* WHAT THE PROJECT LEADER IS TOLD WHEN IT STARTS.
|
|
5
|
+
*
|
|
6
|
+
* The two prompts are kept apart on purpose. The standard one is the shape the project flow has
|
|
7
|
+
* always had - decompose, delegate, review - and it is not touched. The lightweight one is a
|
|
8
|
+
* different set of instructions about a different shape: one session, no decomposition, no
|
|
9
|
+
* reviewer. Writing one prompt with holes in it would mean every sentence had to carry a
|
|
10
|
+
* condition, and the model would have to work out which shape it was in.
|
|
11
|
+
*/
|
|
12
|
+
const STANDARD_LEADER_PROMPT = "你是直接向 Boss 负责的项目 Leader,兼任秘书。先调用 project(action=get, projectId) 了解最新状态。小项目只拆最少必要任务,大项目按交付边界分工。用 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,不得自行解决升级事项。所有任务验收后,用 complete 提交带证据的最终交付总结。上下文有限,明确假设,主动寻找反证。只在本次触发范围内工作。";
|
|
13
|
+
const LIGHTWEIGHT_LEADER_PROMPT = "你是直接向 Boss 负责的项目 Leader,这是一个轻量项目:这个项目由你亲自完成,不要拆子任务、不要派发给别人、也没有独立复核。先调用 project(action=get, projectId) 了解最新状态。用 add_task 登记任务(明确目标、交付物、验收标准、依赖),任务一律登记为执行任务:role=leader 或带 parentTaskId 都会被拒绝。dispatch 会把任务交回给你自己,你亲自做完;做完后调用 project(action=submit, projectId, taskId, output, evidenceRefs) 提交交付,提交即完成,不会有人回来复核,证据必须附上。不要用 session_spawn/session_dispatch 或 task/workflow 绕过项目资源限制。不要轮询等待,不要反复无进展重试。用 report 登记关键进展,用 escalate 将重大偏差、权限或预算问题交给 Boss,不得自行解决升级事项。所有任务交付后,用 complete 提交带证据的最终交付总结。上下文有限,明确假设,主动寻找反证。只在本次触发范围内工作。";
|
|
3
14
|
const text = (value, label) => {
|
|
4
15
|
if (typeof value !== "string" || !value.trim())
|
|
5
16
|
throw new Error(`${label} 不能为空`);
|
|
@@ -100,7 +111,31 @@ export const mergeProfile = (taskProfile, projectDefault) => {
|
|
|
100
111
|
const closed = (p) => ["completed", "cancelled", "failed"].includes(p.status);
|
|
101
112
|
const busy = (status) => ["running", "waiting", "awaiting_background"].includes(status ?? "");
|
|
102
113
|
const dependenciesComplete = (p, t) => t.dependencies.every((id) => p.tasks.find((candidate) => candidate.id === id)?.status === "completed");
|
|
103
|
-
|
|
114
|
+
// THE BUDGET IS COUNTED IN BILLING-EQUIVALENT TOKENS, NOT RAW TOKENS. A cache read costs a
|
|
115
|
+
// fraction of a fresh input token (0.1x on every provider we know), and a cache write costs a
|
|
116
|
+
// little more than one (1.25x). Counting them at 1:1 inflates an agent run by an order of
|
|
117
|
+
// magnitude, so a budget written by intuition always blows up. The formula is:
|
|
118
|
+
// input + output + cacheWrite * 1.25 + cacheRead * 0.1
|
|
119
|
+
// and it is shown to the reader, because a budget nobody can predict is a budget nobody trusts.
|
|
120
|
+
const CACHE_READ_WEIGHT = 0.1;
|
|
121
|
+
const CACHE_WRITE_WEIGHT = 1.25;
|
|
122
|
+
const tokens = (usage) => usage ? Math.round(usage.input + usage.output + usage.cacheWrite * CACHE_WRITE_WEIGHT + usage.cacheRead * CACHE_READ_WEIGHT) : 0;
|
|
123
|
+
/** The budget a project starts with, and the floor the one-click raise falls back to. */
|
|
124
|
+
const DEFAULT_MAX_TOKENS = 100_000;
|
|
125
|
+
/**
|
|
126
|
+
* THE TWO SHAPES A PROJECT CAN HAVE.
|
|
127
|
+
*
|
|
128
|
+
* A standard project spends three sessions on every piece of work - the leader, the worker, and
|
|
129
|
+
* the reviewer - and pays two handovers for it. That is the right shape when the work needs an
|
|
130
|
+
* independent check, and it is too expensive for a project with one small task in it: the cost of
|
|
131
|
+
* the project flow then exceeds the cost of the work.
|
|
132
|
+
*
|
|
133
|
+
* A lightweight project collapses the flow to the leader session: it IS the worker, and a
|
|
134
|
+
* delivery is accepted on the executor's own evidence. Every guardrail is unchanged - the budget,
|
|
135
|
+
* the concurrency cap, the mandatory evidence, the escalation path, the event timeline - because
|
|
136
|
+
* what makes a project a project is the guardrails, not the number of sessions.
|
|
137
|
+
*/
|
|
138
|
+
const lightweight = (p) => p.mode === "lightweight";
|
|
104
139
|
/** Persist explicit domain fields only; transport credentials never enter project records. */
|
|
105
140
|
export class ProjectService {
|
|
106
141
|
store;
|
|
@@ -125,12 +160,27 @@ export class ProjectService {
|
|
|
125
160
|
return t;
|
|
126
161
|
}
|
|
127
162
|
projectView(p) {
|
|
163
|
+
const resources = this.resources(p);
|
|
128
164
|
return {
|
|
129
165
|
...p,
|
|
130
|
-
resources
|
|
166
|
+
resources,
|
|
167
|
+
suggestedMaxTokens: this.suggestedMaxTokens(p, resources.tokens),
|
|
131
168
|
tasks: p.tasks.map((t) => ProjectService.taskView(t, p)),
|
|
132
169
|
};
|
|
133
170
|
}
|
|
171
|
+
/**
|
|
172
|
+
* THE NUMBER THE ONE-CLICK PATH OFFERS.
|
|
173
|
+
*
|
|
174
|
+
* The Boss does not type a budget when the budget runs out: a number typed in a hurry is a
|
|
175
|
+
* number nobody predicted, and a budget that is guessed wrong is the failure this whole path
|
|
176
|
+
* exists to remove. So the server suggests one instead - double what has already been spent,
|
|
177
|
+
* because an agent run that needed twice its first budget will need twice its second one, and
|
|
178
|
+
* never less than one token more than the current cap, so the offer always really raises it.
|
|
179
|
+
*/
|
|
180
|
+
suggestedMaxTokens(p, usedTokens) {
|
|
181
|
+
const current = p.budget?.maxTokens ?? DEFAULT_MAX_TOKENS;
|
|
182
|
+
return Math.max(current + 1, usedTokens * 2);
|
|
183
|
+
}
|
|
134
184
|
raw(id, workspaceId) {
|
|
135
185
|
const scope = this.workspace(workspaceId);
|
|
136
186
|
const p = this.store.project(id);
|
|
@@ -192,9 +242,30 @@ export class ProjectService {
|
|
|
192
242
|
throw new Error("仅直属 Leader 可以管理此任务");
|
|
193
243
|
return manager;
|
|
194
244
|
}
|
|
245
|
+
/**
|
|
246
|
+
* DOES THIS TASK COUNT AS ACCEPTED?
|
|
247
|
+
*
|
|
248
|
+
* In a STANDARD project, acceptance means another session reviewed this delivery: the reviewer
|
|
249
|
+
* of the review must be the session that was spawned to review, and it must NOT be the session
|
|
250
|
+
* that did the work. Those conditions are the whole point of an independent review, so they
|
|
251
|
+
* stand exactly as they were.
|
|
252
|
+
*
|
|
253
|
+
* In a LIGHTWEIGHT project there is no reviewer session at all - the leader session does the
|
|
254
|
+
* work itself - so a delivery is accepted on the executor's own evidence. The flag that says so
|
|
255
|
+
* is written by `submit` and nowhere else, and it names the session that made the call, so a
|
|
256
|
+
* task with no accepted review at all still counts for nothing.
|
|
257
|
+
*/
|
|
258
|
+
taskAccepted(t) {
|
|
259
|
+
if (t.status !== "completed")
|
|
260
|
+
return false;
|
|
261
|
+
if (t.review?.lightweight === true)
|
|
262
|
+
return Boolean(t.review.reviewerConversationId);
|
|
263
|
+
return t.review?.verdict === "accepted" && t.review.reviewerConversationId === t.reviewerConversationId
|
|
264
|
+
&& Boolean(t.reviewerConversationId) && t.reviewerConversationId !== t.ownerConversationId;
|
|
265
|
+
}
|
|
195
266
|
requiredComplete(p, parentTaskId) {
|
|
196
267
|
const required = p.tasks.filter((t) => t.parentTaskId === parentTaskId && (t.status !== "cancelled" || !t.blockedReason));
|
|
197
|
-
return required.length > 0 && required.every((t) =>
|
|
268
|
+
return required.length > 0 && required.every((t) => this.taskAccepted(t));
|
|
198
269
|
}
|
|
199
270
|
task(p, taskId) {
|
|
200
271
|
const t = p.tasks.find((item) => item.id === taskId);
|
|
@@ -233,12 +304,22 @@ export class ProjectService {
|
|
|
233
304
|
const coordinatorIds = new Set([p.ownerConversationId, ...p.tasks.filter((t) => t.role === "leader").map((t) => t.ownerConversationId)].filter(Boolean));
|
|
234
305
|
const sessions = state.conversations.filter((c) => c.workspaceId === p.workspaceId && members.has(c.id)).map((c) => ({
|
|
235
306
|
id: c.id, title: c.title, status: c.status, tokens: tokens(c.usage), contextPercent: c.contextUsage?.percent,
|
|
307
|
+
// THE TREE SKELETON. The client draws the agents of a project as a tree, and the only
|
|
308
|
+
// thing that knows who spawned whom is the conversation's own parent link. It is sent
|
|
309
|
+
// verbatim (including the undefined case, which means "this session has no parent in
|
|
310
|
+
// this collection" - i.e. it is a root of the tree).
|
|
311
|
+
parentConversationId: c.parentConversationId,
|
|
236
312
|
role: c.id === p.ownerConversationId ? "项目负责人" : coordinatorIds.has(c.id) ? "分支 Leader" : p.tasks.some((t) => t.reviewerConversationId === c.id) ? "独立复核" : "执行者",
|
|
237
313
|
}));
|
|
238
314
|
const runs = state.subagentRuns.filter((r) => members.has(r.conversationId));
|
|
315
|
+
/* A COORDINATOR IS NOT A WORKER - EXCEPT IN A LIGHTWEIGHT PROJECT, WHERE THE LEADER IS THE
|
|
316
|
+
WORKER. There the leader session does the work itself, so a project that is running must not
|
|
317
|
+
report zero running agents. The concurrency guard is not touched by this: the in-flight task
|
|
318
|
+
it counts (`reserved`) already covers the busy leader, so the cap behaves exactly as before. */
|
|
319
|
+
const leaderIsWorker = lightweight(p) && p.ownerConversationId !== undefined;
|
|
239
320
|
return { tokens: sessions.reduce((sum, s) => sum + s.tokens, 0) + runs.reduce((sum, r) => sum + tokens(r.usage), 0),
|
|
240
321
|
usageKnown: sessions.length > 0 && sessions.every((s) => Boolean(this.store.conversation(s.id)?.usage)) && runs.every((r) => Boolean(r.usage)),
|
|
241
|
-
activeWorkers: sessions.filter((s) => !coordinatorIds.has(s.id) && busy(s.status)).length + runs.filter((r) => r.status === "running").length, sessions };
|
|
322
|
+
activeWorkers: sessions.filter((s) => (!coordinatorIds.has(s.id) || (leaderIsWorker && s.id === p.ownerConversationId)) && busy(s.status)).length + runs.filter((r) => r.status === "running").length, sessions };
|
|
242
323
|
}
|
|
243
324
|
list(workspaceId) {
|
|
244
325
|
const scope = this.workspace(workspaceId);
|
|
@@ -265,6 +346,10 @@ export class ProjectService {
|
|
|
265
346
|
throw new Error("项目负责人由启动操作创建独立会话");
|
|
266
347
|
if (input.risk !== undefined && !["low", "medium", "high"].includes(input.risk))
|
|
267
348
|
throw new Error("项目风险等级不合法");
|
|
349
|
+
// THE MODE IS CHOSEN ONCE, AT BIRTH, AND IT IS A CLOSED SET. A typo must not silently buy a
|
|
350
|
+
// project the standard shape, because the standard shape is the one with the reviewer.
|
|
351
|
+
if (input.mode !== undefined && input.mode !== "standard" && input.mode !== "lightweight")
|
|
352
|
+
throw new Error("项目模式不合法:只能是 standard 或 lightweight");
|
|
268
353
|
if (input.budget !== undefined && (!input.budget || typeof input.budget !== "object" || Array.isArray(input.budget)))
|
|
269
354
|
throw new Error("资源预算不合法");
|
|
270
355
|
for (const [key, value] of Object.entries(input.budget ?? {})) {
|
|
@@ -280,7 +365,10 @@ export class ProjectService {
|
|
|
280
365
|
const now = stamp();
|
|
281
366
|
const p = { id: `project_${randomUUID()}`, workspaceId, title: text(input.title, "项目标题"), objective: text(input.objective, "项目目标"),
|
|
282
367
|
deliverables: strings(input.deliverables, "交付物"), acceptanceCriteria: strings(input.acceptanceCriteria, "验收标准"), constraints: strings(input.constraints, "约束"),
|
|
283
|
-
risk: input.risk ?? "low", status: "planning", budget: { maxTokens: input.budget?.maxTokens ??
|
|
368
|
+
risk: input.risk ?? "low", status: "planning", budget: { maxTokens: input.budget?.maxTokens ?? DEFAULT_MAX_TOKENS, maxConcurrent: input.budget?.maxConcurrent ?? 2 },
|
|
369
|
+
// A project without a mode is a standard project: the mode is written down only when it was
|
|
370
|
+
// asked for, so every project that existed before the mode existed reads as standard.
|
|
371
|
+
...(input.mode ? { mode: input.mode } : {}),
|
|
284
372
|
...(defaultLeaderProfile ? { defaultLeaderProfile } : {}),
|
|
285
373
|
...(defaultExecutorProfile ? { defaultExecutorProfile } : {}),
|
|
286
374
|
...(defaultReviewerProfile ? { defaultReviewerProfile } : {}),
|
|
@@ -338,6 +426,12 @@ export class ProjectService {
|
|
|
338
426
|
// project, so it is where the project belongs in the tree. A project the Boss started from
|
|
339
427
|
// the panel has no initiator, and stays a root session exactly as before.
|
|
340
428
|
...(p.initiatorConversationId ? { parentConversationId: p.initiatorConversationId } : {}),
|
|
429
|
+
// A PROJECT IS ITS OWN WORKING CONTEXT. The leader hangs under the conversation that
|
|
430
|
+
// asked for the project, but it must NOT share that conversation's memory tree: a tree
|
|
431
|
+
// is what makes the memories of a chat visible to the sessions below it, and the
|
|
432
|
+
// project's workers are not part of the user's chat. The tree edge is for the SIDEBAR
|
|
433
|
+
// and the memory tree is for the WORK - they are two different things.
|
|
434
|
+
separateMemoryTree: true,
|
|
341
435
|
title: `项目负责人 · ${p.title}`,
|
|
342
436
|
task: p.objective,
|
|
343
437
|
initialPrompt: "",
|
|
@@ -351,7 +445,7 @@ export class ProjectService {
|
|
|
351
445
|
this.event(p, "started", "项目负责人开始组织执行", undefined, actor);
|
|
352
446
|
p.status = "active";
|
|
353
447
|
await this.store.setProject(p);
|
|
354
|
-
await this.orchestrator.dispatch(p.ownerConversationId, `${this.context(p)}\n
|
|
448
|
+
await this.orchestrator.dispatch(p.ownerConversationId, `${this.context(p)}\n${lightweight(p) ? LIGHTWEIGHT_LEADER_PROMPT : STANDARD_LEADER_PROMPT}`, { wait: false });
|
|
355
449
|
return p;
|
|
356
450
|
});
|
|
357
451
|
}
|
|
@@ -359,6 +453,15 @@ export class ProjectService {
|
|
|
359
453
|
return this.change(id, workspaceId, (p) => {
|
|
360
454
|
this.live(p);
|
|
361
455
|
const parentTaskId = optional(input.parentTaskId, "父任务 id");
|
|
456
|
+
// A LIGHTWEIGHT PROJECT HAS ONE SESSION, SO IT HAS NO TREE OF TASKS. Decomposing the work
|
|
457
|
+
// would mean spawning the worker sessions the mode exists to avoid, and a branch leader
|
|
458
|
+
// would mean a second one. Both are refused here, in words the caller can act on.
|
|
459
|
+
if (lightweight(p)) {
|
|
460
|
+
if (parentTaskId)
|
|
461
|
+
throw new Error("轻量项目不再拆子任务:整个项目由负责人会话自己完成");
|
|
462
|
+
if (input.role === "leader")
|
|
463
|
+
throw new Error("轻量项目没有分支 Leader:请登记为执行任务,由负责人亲自完成");
|
|
464
|
+
}
|
|
362
465
|
// A top-level task is accountable to whoever owns the project: the leader once it runs, and
|
|
363
466
|
// before that the initiator who registered it - a task nobody answers for cannot be closed.
|
|
364
467
|
let manager = p.ownerConversationId ?? p.initiatorConversationId;
|
|
@@ -429,16 +532,31 @@ export class ProjectService {
|
|
|
429
532
|
throw new Error("父任务未处于执行中");
|
|
430
533
|
const effective = mergeProfile(t.executorProfile, p.defaultExecutorProfile);
|
|
431
534
|
if (!t.ownerConversationId) {
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
}
|
|
535
|
+
if (lightweight(p)) {
|
|
536
|
+
// THE LEADER IS THE WORKER. A lightweight project spawns no worker session, so the task's
|
|
537
|
+
// executor IS the project leader session - the very session that is asking for this
|
|
538
|
+
// dispatch. There is nothing to hand the work to otherwise.
|
|
539
|
+
if (!p.ownerConversationId)
|
|
540
|
+
throw new Error("轻量项目还没有负责人会话:请先启动项目负责人");
|
|
541
|
+
t.ownerConversationId = p.ownerConversationId;
|
|
542
|
+
}
|
|
543
|
+
else {
|
|
544
|
+
t.ownerConversationId = (await this.orchestrator.spawn({
|
|
545
|
+
workspaceId, parentConversationId: manager, title: `${t.role === "leader" ? "Leader" : "执行"} · ${t.title}`, task: t.objective, initialPrompt: "",
|
|
546
|
+
...(effective?.agentId ? { agentId: effective.agentId } : {}),
|
|
547
|
+
...(effective?.cwd !== undefined ? { cwd: effective.cwd } : {}),
|
|
548
|
+
...(effective?.model ? { model: effective.model } : {}),
|
|
549
|
+
...(effective?.thinkingLevel ? { thinkingLevel: effective.thinkingLevel } : {}),
|
|
550
|
+
...(effective?.watchdogTimeoutSeconds ? { watchdogTimeoutSeconds: effective.watchdogTimeoutSeconds } : {}),
|
|
551
|
+
})).conversationId;
|
|
552
|
+
}
|
|
440
553
|
}
|
|
441
|
-
|
|
554
|
+
// THE BUSY CHECK IS ABOUT A SECOND WORKER SESSION, AND THERE IS NONE HERE. It stops a
|
|
555
|
+
// worker from being handed a second task while it is still running the first one. In a
|
|
556
|
+
// lightweight project the executor is the leader, which is busy by definition - it is the
|
|
557
|
+
// session that asked for this dispatch - and the leader's own queue serializes the tasks
|
|
558
|
+
// it has taken on.
|
|
559
|
+
if (!lightweight(p) && busy(this.store.conversation(t.ownerConversationId)?.status))
|
|
442
560
|
throw new Error("执行会话尚未结束,请等待完成回报后派发");
|
|
443
561
|
t.status = "in_progress";
|
|
444
562
|
t.updatedAt = stamp();
|
|
@@ -447,7 +565,11 @@ export class ProjectService {
|
|
|
447
565
|
this.reconcile(p);
|
|
448
566
|
await this.store.setProject(p);
|
|
449
567
|
const delegation = t.role === "leader" ? `你是分支 Leader,负责这项任务的拆解、委派、集成交付。用 project add_task 时必须带 parentTaskId="${t.id}";可按必要性指定 role="leader" 或 "executor";add_task / update_task 时可以带 executorProfile 与 reviewerProfile(支持指定 agentId、cwd、model、thinkingLevel、watchdogTimeoutSeconds),按任务性质将执行与复核委派给最合适的员工,不指定则继承项目默认。用 project dispatch / request_review 管理直属子任务,子会话结束自动回报给你,不要轮询;并发满时结束本轮等待回报。所有必需子任务独立验收后才能 submit 聚合交付,上级还会独立复核你的集成结果。最多 3 层 Leader、8 个分支 Leader;小任务不要继续拆层。` : "你是执行者,不得自行拆解子任务。";
|
|
450
|
-
|
|
568
|
+
/* THE LIGHTWEIGHT TASK SAYS WHAT IS DIFFERENT, because the difference is the point: there is
|
|
569
|
+
no reviewer coming back, so the evidence that the reviewer would have demanded is the only
|
|
570
|
+
thing that stands behind the delivery. */
|
|
571
|
+
const modeNote = lightweight(p) ? "本项目是轻量项目:你就是唯一的执行会话,不会有独立复核人回来,完成后调用 project(action=submit, …) 提交即完成,交付证据必须附上。" : "";
|
|
572
|
+
await this.orchestrator.dispatch(t.ownerConversationId, `${this.context(p)}\n${delegation}\n你负责执行任务 ${t.id}:${t.title}\n目标:${t.objective}\n交付物:${t.deliverables.join(";")}\n验收:${t.acceptanceCriteria.join(";")}\n上次复核意见与验证证据:${JSON.stringify(t.review ?? null)}\n已验收前置产物:${JSON.stringify(p.tasks.filter((d) => t.dependencies.includes(d.id)).map((d) => ({ title: d.title, output: d.output, evidenceRefs: d.evidenceRefs })))}\n你不是唯一执行者,遵守分工边界。${modeNote}完成后必须调用 project(action=submit, projectId="${p.id}", taskId="${t.id}", output="交付总结", evidenceRefs=["产物路径或验证记录"]),不能自行标记已完成。复核退回时修复后重新 submit。遇到阻塞用 report 或 escalate,保留证据、假设和未解决问题。不要自行创建其他执行会话或 task/workflow。`, { wait: false });
|
|
451
573
|
return ProjectService.taskView(t, p);
|
|
452
574
|
});
|
|
453
575
|
}
|
|
@@ -462,9 +584,26 @@ export class ProjectService {
|
|
|
462
584
|
if (t.role === "leader" && !this.requiredComplete(p, t.id))
|
|
463
585
|
throw new Error("Leader 的必需子任务尚未全部独立验收");
|
|
464
586
|
t.output = text(input.output, "交付结果");
|
|
465
|
-
|
|
587
|
+
const evidenceRefs = strings(input.evidenceRefs, "交付证据");
|
|
588
|
+
t.evidenceRefs = evidenceRefs;
|
|
589
|
+
// THE EVIDENCE IS REQUIRED IN BOTH SHAPES. The reviewer is gone in a lightweight project,
|
|
590
|
+
// and the evidence is exactly what the reviewer would have checked - so it is the one thing
|
|
591
|
+
// that does not get lighter.
|
|
466
592
|
if (!t.evidenceRefs.length)
|
|
467
593
|
throw new Error("交付必须附上产物或验证证据");
|
|
594
|
+
if (lightweight(p)) {
|
|
595
|
+
/* THE DELIVERY IS ACCEPTED ON THE EXECUTOR'S OWN EVIDENCE. There is no reviewer session to
|
|
596
|
+
send it to, so the acceptance is written down here - with the flag that says there was
|
|
597
|
+
no independent review, and with the session that made the call, so the record is not a
|
|
598
|
+
claim that somebody else checked it. */
|
|
599
|
+
t.status = "completed";
|
|
600
|
+
t.updatedAt = stamp();
|
|
601
|
+
t.review = { verdict: "accepted", summary: "轻量项目:执行者自评交付,未做独立复核", evidenceRefs,
|
|
602
|
+
reviewerConversationId: t.ownerConversationId, createdAt: stamp(), lightweight: true };
|
|
603
|
+
this.event(p, "submitted", `轻量交付完成:${t.title}`, t.id, actor);
|
|
604
|
+
this.reconcile(p);
|
|
605
|
+
return ProjectService.taskView(t, p);
|
|
606
|
+
}
|
|
468
607
|
t.status = "awaiting_review";
|
|
469
608
|
t.updatedAt = stamp();
|
|
470
609
|
delete t.review;
|
|
@@ -475,6 +614,10 @@ export class ProjectService {
|
|
|
475
614
|
}
|
|
476
615
|
async requestReview(id, taskId, workspaceId, actor) {
|
|
477
616
|
return this.change(id, workspaceId, async (p) => {
|
|
617
|
+
/* THERE IS NO REVIEWER TO ASK FOR. A lightweight project's delivery is accepted when it is
|
|
618
|
+
submitted, so asking for a review is asking for a session that will never exist. */
|
|
619
|
+
if (lightweight(p))
|
|
620
|
+
throw new Error("轻量项目不做独立复核:提交即完成");
|
|
478
621
|
this.admission(p);
|
|
479
622
|
const t = this.task(p, taskId);
|
|
480
623
|
const manager = this.manager(p, t, actor);
|
|
@@ -639,6 +782,48 @@ export class ProjectService {
|
|
|
639
782
|
await this.orchestrator?.stopSubtree?.(result.ownerConversationId);
|
|
640
783
|
return result;
|
|
641
784
|
}
|
|
785
|
+
/**
|
|
786
|
+
* THE SESSION THAT OPENED THE PROJECT MAY CANCEL IT.
|
|
787
|
+
*
|
|
788
|
+
* There is no delete here, and that is deliberate. The project record, its tasks, its events and
|
|
789
|
+
* its evidence references are the trail of what was tried; a project that went nowhere is
|
|
790
|
+
* evidence too. Cancelling stops the work and marks the project cancelled - the record stays,
|
|
791
|
+
* readable, with the reason attached.
|
|
792
|
+
*
|
|
793
|
+
* Only the session that opened the project may do this. A worker or a reviewer that could
|
|
794
|
+
* cancel the project it belongs to would have a way to make its own budget and concurrency
|
|
795
|
+
* guards disappear, and those guards are the only thing between a runaway agent and an
|
|
796
|
+
* unbounded bill. The human path - the panel's stop button - is unchanged and stays the Boss's.
|
|
797
|
+
*
|
|
798
|
+
* A reason is required: "we changed our minds" and "the customer shipped it last night" are
|
|
799
|
+
* different decisions, and the timeline is where that difference has to show up.
|
|
800
|
+
*/
|
|
801
|
+
async cancel(id, body, workspaceId, actor) {
|
|
802
|
+
const reason = typeof body.reason === "string" ? body.reason.trim() : "";
|
|
803
|
+
if (!reason)
|
|
804
|
+
throw new Error("取消项目必须说明理由:理由会进入项目的事件时间线。");
|
|
805
|
+
const found = this.get(id, workspaceId);
|
|
806
|
+
if (!found.initiatorConversationId || found.initiatorConversationId !== actor)
|
|
807
|
+
throw new Error("只有项目的发起人可以取消它。");
|
|
808
|
+
const result = await this.change(id, workspaceId, (p) => {
|
|
809
|
+
this.live(p);
|
|
810
|
+
p.status = "cancelled";
|
|
811
|
+
if (closed(p))
|
|
812
|
+
p.closedAt = stamp();
|
|
813
|
+
for (const t of p.tasks) {
|
|
814
|
+
if (["completed", "cancelled", "failed"].includes(t.status))
|
|
815
|
+
continue;
|
|
816
|
+
t.status = "cancelled";
|
|
817
|
+
t.updatedAt = stamp();
|
|
818
|
+
}
|
|
819
|
+
this.event(p, "status", `项目发起人取消项目:${reason}`, undefined, actor);
|
|
820
|
+
return p;
|
|
821
|
+
});
|
|
822
|
+
// Stop after releasing the write lock: an interrupted tool may itself be waiting for it.
|
|
823
|
+
if (result.ownerConversationId)
|
|
824
|
+
await this.orchestrator?.stopSubtree?.(result.ownerConversationId);
|
|
825
|
+
return result;
|
|
826
|
+
}
|
|
642
827
|
async updateBudget(id, input, workspaceId) {
|
|
643
828
|
return this.change(id, workspaceId, (p) => {
|
|
644
829
|
this.live(p);
|
|
@@ -652,6 +837,56 @@ export class ProjectService {
|
|
|
652
837
|
return p;
|
|
653
838
|
});
|
|
654
839
|
}
|
|
840
|
+
/**
|
|
841
|
+
* ONE CLICK: RAISE THE BUDGET AND LET THE WORK CONTINUE.
|
|
842
|
+
*
|
|
843
|
+
* Three things happen here, and they happen together: the cap goes up to a number the SERVER
|
|
844
|
+
* computed, the budget exception that is waiting for a decision is closed, and the work that
|
|
845
|
+
* was blocked is woken up again. Doing them apart is what made the old path painful - a Boss
|
|
846
|
+
* had to open a form, type a number, press save, and then wake the leader by hand, and every
|
|
847
|
+
* one of those steps was a chance to stop halfway.
|
|
848
|
+
*
|
|
849
|
+
* IT IS A BOSS OPERATION. A session may not raise the budget of its own project: the budget is
|
|
850
|
+
* the Boss's stop, and an agent that could lift its own limit would not have one. The HTTP
|
|
851
|
+
* layer refuses a request that carries a capability for the same reason.
|
|
852
|
+
*
|
|
853
|
+
* The manual `updateBudget` stays a SEPARATE intent: adjusting a number is not the same as
|
|
854
|
+
* asking for the work to continue, so the manual path does not continue anything.
|
|
855
|
+
*/
|
|
856
|
+
async raiseBudgetAndContinue(id, workspaceId, callerConversationId) {
|
|
857
|
+
if (callerConversationId)
|
|
858
|
+
throw new Error("管理操作仅由 Boss 发起:Agent 不能提高预算,也不能替 Boss 让项目继续");
|
|
859
|
+
const raised = await this.change(id, workspaceId, (p) => {
|
|
860
|
+
this.live(p);
|
|
861
|
+
const previousMaxTokens = p.budget?.maxTokens ?? DEFAULT_MAX_TOKENS;
|
|
862
|
+
const usedTokens = this.resources(p).tokens;
|
|
863
|
+
const suggestedMaxTokens = Math.max(previousMaxTokens + 1, usedTokens * 2);
|
|
864
|
+
(p.budget ??= {}).maxTokens = suggestedMaxTokens;
|
|
865
|
+
const decision = `Boss 提高预算到 ${suggestedMaxTokens} Token 并继续`;
|
|
866
|
+
let resolvedEscalations = 0;
|
|
867
|
+
for (const e of p.escalations) {
|
|
868
|
+
if (e.status !== "open")
|
|
869
|
+
continue;
|
|
870
|
+
// ONLY THE BUDGET ONES. An exception about scope or permissions is not the Boss's to
|
|
871
|
+
// close with a budget decision, and closing it here would hide a question nobody answered.
|
|
872
|
+
if (!e.reason.includes("预算"))
|
|
873
|
+
continue;
|
|
874
|
+
e.status = "resolved";
|
|
875
|
+
e.decision = decision;
|
|
876
|
+
e.resolvedAt = stamp();
|
|
877
|
+
resolvedEscalations += 1;
|
|
878
|
+
}
|
|
879
|
+
this.event(p, "budget", `Boss 提高派发预算:${previousMaxTokens} → ${suggestedMaxTokens} Token,并继续执行(已处理 ${resolvedEscalations} 条预算例外)`);
|
|
880
|
+
this.reconcile(p);
|
|
881
|
+
return { previousMaxTokens, suggestedMaxTokens, resolvedEscalations };
|
|
882
|
+
});
|
|
883
|
+
// AND NOW LET IT MOVE. `start` is the existing way to wake the leader: it dispatches the
|
|
884
|
+
// leader session when the project has one, and creates one when it has not. Its refusal -
|
|
885
|
+
// "项目负责人正在执行,请勿重复启动" - is passed through unchanged: a busy leader is a fact
|
|
886
|
+
// the Boss has to see, not an error to swallow.
|
|
887
|
+
const project = await this.start(id, workspaceId);
|
|
888
|
+
return { ...raised, project };
|
|
889
|
+
}
|
|
655
890
|
async addReport(id, input, workspaceId, actor) {
|
|
656
891
|
return this.change(id, workspaceId, (p) => {
|
|
657
892
|
this.live(p);
|
|
@@ -735,8 +970,9 @@ export class ProjectService {
|
|
|
735
970
|
this.live(p);
|
|
736
971
|
this.leader(p, actor);
|
|
737
972
|
const required = p.tasks.filter((t) => t.status !== "cancelled" || !t.blockedReason);
|
|
738
|
-
if (!required.length || required.some((t) =>
|
|
739
|
-
throw new Error("所有任务必须经独立复核验收后才能完成项目");
|
|
973
|
+
if (!required.length || required.some((t) => !this.taskAccepted(t))) {
|
|
974
|
+
throw new Error(lightweight(p) ? "所有任务必须完成交付后才能完成项目" : "所有任务必须经独立复核验收后才能完成项目");
|
|
975
|
+
}
|
|
740
976
|
if (p.escalations.some((e) => e.status === "open"))
|
|
741
977
|
throw new Error("尚有未处理例外");
|
|
742
978
|
const evidence = strings(evidenceRefs, "最终交付证据");
|
|
@@ -866,6 +1102,7 @@ export class ProjectService {
|
|
|
866
1102
|
case "report": return this.addReport(id, body, workspaceId, actor);
|
|
867
1103
|
case "escalate": return this.addEscalation(id, body, workspaceId, actor);
|
|
868
1104
|
case "complete": return this.complete(id, body.summary, body.evidenceRefs, workspaceId, actor);
|
|
1105
|
+
case "cancel": return this.cancel(id, body, workspaceId, actor);
|
|
869
1106
|
default: throw new Error("未知的项目工具操作");
|
|
870
1107
|
}
|
|
871
1108
|
}
|
|
@@ -45,6 +45,15 @@ export interface SpawnSessionOptions {
|
|
|
45
45
|
wait?: boolean;
|
|
46
46
|
/** Optional silence watchdog timeout in seconds. If set, parent is reminded if child goes quiet for this duration. */
|
|
47
47
|
watchdogTimeoutSeconds?: number;
|
|
48
|
+
/**
|
|
49
|
+
* Whether the new session opens its OWN memory tree instead of inheriting the parent's.
|
|
50
|
+
*
|
|
51
|
+
* A memory tree is what makes one conversation's tree-scoped memories visible to the sessions
|
|
52
|
+
* under it. A project wants the opposite: the project hangs under the conversation that asked
|
|
53
|
+
* for it in the SIDEBAR, and it shares nothing of that conversation's memories. The session tree
|
|
54
|
+
* edge and the memory tree are two different things, and this flag touches only the second.
|
|
55
|
+
*/
|
|
56
|
+
separateMemoryTree?: boolean;
|
|
48
57
|
}
|
|
49
58
|
export interface ReportSessionOptions {
|
|
50
59
|
/** The report content (milestone, findings, roadblock, or final output). */
|
|
@@ -130,6 +130,7 @@ export class SessionOrchestratorService {
|
|
|
130
130
|
const conversationId = await this.conversationService.createConversation(workspaceId, {
|
|
131
131
|
parentConversationId: options.parentConversationId,
|
|
132
132
|
origin: options.parentConversationId ? "orchestrator" : "user",
|
|
133
|
+
...(options.separateMemoryTree ? { separateMemoryTree: true } : {}),
|
|
133
134
|
}, cwd);
|
|
134
135
|
// Set title if requested or derive from task
|
|
135
136
|
if (options.title) {
|
|
@@ -1585,6 +1585,14 @@ export function createHttpServer(options) {
|
|
|
1585
1585
|
json(200, { project });
|
|
1586
1586
|
return;
|
|
1587
1587
|
}
|
|
1588
|
+
// ONE CLICK: RAISE THE BUDGET AND CONTINUE. The server computes the new cap, closes the
|
|
1589
|
+
// budget exception and wakes the leader - the client sends no number of its own.
|
|
1590
|
+
if (request.method === "POST" && subresource === "budget" && parts[2] === "continue") {
|
|
1591
|
+
const result = await service.raiseBudgetAndContinue(projectId, workspaceId, callerConversationId);
|
|
1592
|
+
broadcaster.broadcastState();
|
|
1593
|
+
json(200, result);
|
|
1594
|
+
return;
|
|
1595
|
+
}
|
|
1588
1596
|
if (request.method === "POST" && subresource === "tasks" && parts[2] && parts[3] === "dispatch") {
|
|
1589
1597
|
const task = await service.dispatchTask(projectId, parts[2], workspaceId);
|
|
1590
1598
|
broadcaster.broadcastState();
|