@evandu/super-pi 0.1.201 → 0.1.203
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/coder.md +2 -0
- package/agents/project-leader.md +2 -0
- package/agents/reviewer.md +2 -0
- package/agents/super-pi-task/core.ts +23 -8
- package/agents/super-pi-task/index.ts +28 -3
- package/dist/client/.super-pi-client-sources.json +4 -4
- package/dist/client/assets/{CodeMirrorEditor-vxQIyy7b.js → CodeMirrorEditor-BiglkRzj.js} +2 -2
- package/dist/client/assets/{dist-BOiDpbIK.js → dist-49ljEEGU.js} +1 -1
- package/dist/client/assets/{dist-4SH20Tbv.js → dist-61Dk73D4.js} +1 -1
- package/dist/client/assets/{dist-Dbqc2GHg.js → dist-B-aA7mO-.js} +1 -1
- package/dist/client/assets/{dist-B_slddW0.js → dist-BL0stJam.js} +1 -1
- package/dist/client/assets/{dist-C6vEFxfz.js → dist-Bpi6hyA8.js} +1 -1
- package/dist/client/assets/{dist-BBL_GRBs.js → dist-BxB43BSv.js} +1 -1
- package/dist/client/assets/{dist-DAYkQ0P3.js → dist-C1htLmr_.js} +1 -1
- package/dist/client/assets/{dist-B131Snro.js → dist-C8Tuwf5W.js} +1 -1
- package/dist/client/assets/{dist-DEROl11F.js → dist-CXNAGqHc.js} +1 -1
- package/dist/client/assets/{dist-p340hSe4.js → dist-Cgr1Rtd1.js} +1 -1
- package/dist/client/assets/{dist-DcgxyyHo.js → dist-CkqzW1o9.js} +1 -1
- package/dist/client/assets/{dist-DDjw1OJ2.js → dist-CxeW1xem.js} +1 -1
- package/dist/client/assets/{dist-CPrZlJdM.js → dist-D1TsEFY2.js} +1 -1
- package/dist/client/assets/{dist-B-IVJoQx.js → dist-DAN5qo0Q.js} +1 -1
- package/dist/client/assets/{dist-DEKddEF2.js → dist-DPtg9nbO.js} +1 -1
- package/dist/client/assets/{dist-BA_txYZC.js → dist-DSZRirQJ.js} +1 -1
- package/dist/client/assets/{dist-DqP_0JTb.js → dist-DcV-t-Fp.js} +1 -1
- package/dist/client/assets/{dist-DRZYzTGl.js → dist-DlkKRiSu.js} +1 -1
- package/dist/client/assets/{dist-D9xg8iqu.js → dist-Dy10rlCf.js} +1 -1
- package/dist/client/assets/{dist-B9Xymme_.js → dist-Nqd9ROg_.js} +1 -1
- package/dist/client/assets/{dist-IjAxSRZT.js → dist-UZ3I2i5X.js} +1 -1
- package/dist/client/assets/{dist-C6WoehaJ.js → dist-_85Di7Zz.js} +1 -1
- package/dist/client/assets/{index-fsBZreVZ.js → index-DBLhe-n8.js} +11 -11
- package/dist/client/assets/{index-Df8Zo6Xu.css → index-DcuTYCZ-.css} +1 -1
- package/dist/client/index.html +2 -2
- package/dist/server/application/project-service.d.ts +19 -1
- package/dist/server/application/project-service.js +194 -7
- package/dist/server/application/session-orchestrator-service.d.ts +2 -0
- package/dist/server/application/session-orchestrator-service.js +16 -4
- package/dist/server/http-server.js +1 -0
- package/dist/server/team-context.d.ts +12 -0
- package/dist/server/team-context.js +173 -0
- package/dist/server/types.d.ts +6 -0
- package/dist/shared/team-context.d.ts +52 -0
- package/dist/shared/team-context.js +3 -0
- package/package.json +3 -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-DBLhe-n8.js"></script>
|
|
12
|
+
<link rel="stylesheet" crossorigin href="/assets/index-DcuTYCZ-.css">
|
|
13
13
|
</head>
|
|
14
14
|
<body>
|
|
15
15
|
<div id="root"></div>
|
|
@@ -35,6 +35,7 @@ export type ProjectListPage = {
|
|
|
35
35
|
returned: number;
|
|
36
36
|
};
|
|
37
37
|
export type CreateProjectInput = {
|
|
38
|
+
sharedContext?: unknown;
|
|
38
39
|
workspaceId: string;
|
|
39
40
|
title: string;
|
|
40
41
|
objective: string;
|
|
@@ -52,6 +53,7 @@ export type CreateProjectInput = {
|
|
|
52
53
|
mode?: ProjectMode;
|
|
53
54
|
};
|
|
54
55
|
export type AddTaskInput = Partial<ProjectTask> & {
|
|
56
|
+
sharedContext?: unknown;
|
|
55
57
|
title: string;
|
|
56
58
|
objective: string;
|
|
57
59
|
executorProfile?: unknown;
|
|
@@ -65,6 +67,9 @@ export type TopLevelTaskPlan = {
|
|
|
65
67
|
acceptanceCriteria?: string[];
|
|
66
68
|
priority?: ProjectTask["priority"];
|
|
67
69
|
dependencies: string[];
|
|
70
|
+
ownedPaths?: string[];
|
|
71
|
+
readOnly?: boolean;
|
|
72
|
+
handoffNote?: string;
|
|
68
73
|
};
|
|
69
74
|
/**
|
|
70
75
|
* HOW THE SERVICE ASKS WHAT AN AGENT ID IS.
|
|
@@ -99,6 +104,16 @@ export declare class ProjectService {
|
|
|
99
104
|
* server always passes one.
|
|
100
105
|
*/
|
|
101
106
|
agents?: AgentModeLookup | undefined);
|
|
107
|
+
private publishContext;
|
|
108
|
+
shareContext(id: string, value: unknown, workspaceId: string, actor?: string): Promise<unknown>;
|
|
109
|
+
messageTask(id: string, taskId: string, content: string, workspaceId: string, actor?: string, targetConversationId?: string, deliveryMode?: string): Promise<unknown>;
|
|
110
|
+
getContext(id: string | undefined, workspaceId: string, actor?: string, taskId?: string, contextIds?: unknown): unknown;
|
|
111
|
+
private assertWriteScope;
|
|
112
|
+
private taskCoordination;
|
|
113
|
+
private captureHandoff;
|
|
114
|
+
private dispatchContext;
|
|
115
|
+
private syncDeliveryContext;
|
|
116
|
+
private dispatchReceipt;
|
|
102
117
|
/**
|
|
103
118
|
* A PROJECT EMPLOYEE MUST BE A PRIMARY AGENT.
|
|
104
119
|
*
|
|
@@ -299,6 +314,7 @@ export declare class ProjectService {
|
|
|
299
314
|
submit(id: string, taskId: string, input: {
|
|
300
315
|
output?: string;
|
|
301
316
|
evidenceRefs?: string[];
|
|
317
|
+
sharedContext?: unknown;
|
|
302
318
|
}, workspaceId: string, actor?: string): Promise<ProjectTask>;
|
|
303
319
|
requestReview(id: string, taskId: string, workspaceId: string, actor?: string): Promise<ProjectTask>;
|
|
304
320
|
review(id: string, taskId: string, input: {
|
|
@@ -327,7 +343,9 @@ export declare class ProjectService {
|
|
|
327
343
|
* different decisions, and the timeline is where that difference has to show up.
|
|
328
344
|
*/
|
|
329
345
|
cancel(id: string, body: Record<string, any>, workspaceId: string, actor: string): Promise<Project>;
|
|
330
|
-
addReport(id: string, input: Omit<ProjectReport, "id" | "projectId" | "createdAt"
|
|
346
|
+
addReport(id: string, input: Omit<ProjectReport, "id" | "projectId" | "createdAt"> & {
|
|
347
|
+
sharedContext?: unknown;
|
|
348
|
+
}, workspaceId?: string, actor?: string): Promise<ProjectReport>;
|
|
331
349
|
addEscalation(id: string, input: Pick<ProjectEscalation, "reason" | "severity" | "taskId" | "title">, workspaceId?: string, actor?: string): Promise<ProjectEscalation>;
|
|
332
350
|
/**
|
|
333
351
|
* A DECISION ON A CLOSED PROJECT IS STILL A RECORD - AND A CLOSED PROJECT HAS NOBODY TO WAKE.
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { randomUUID } from "node:crypto";
|
|
2
|
+
import { buildTeamHandoff, discoverTeamFiles, parseTeamContext, pathsOverlap, publishTeamContext, teamPaths } from "../team-context.js";
|
|
2
3
|
import { deriveReportingState, deriveSessionState, sessionStateWord, } from "../../shared/session-reporting.js";
|
|
3
4
|
const stamp = () => new Date().toISOString();
|
|
4
5
|
/**
|
|
@@ -338,6 +339,145 @@ export class ProjectService {
|
|
|
338
339
|
this.orchestrator = orchestrator;
|
|
339
340
|
this.agents = agents;
|
|
340
341
|
}
|
|
342
|
+
publishContext(p, value, actor) {
|
|
343
|
+
const inputs = parseTeamContext(value);
|
|
344
|
+
if (!inputs.length)
|
|
345
|
+
return;
|
|
346
|
+
this.member(p, actor);
|
|
347
|
+
const canEdit = (entry) => !actor || actor === entry.authorConversationId || actor === p.ownerConversationId || actor === p.initiatorConversationId
|
|
348
|
+
|| p.tasks.some(task => [task.ownerConversationId, task.reviewerConversationId].includes(entry.authorConversationId)
|
|
349
|
+
&& (task.parentTaskId ? p.tasks.find(parent => parent.id === task.parentTaskId)?.ownerConversationId : p.ownerConversationId) === actor);
|
|
350
|
+
const before = p.contextRevision ?? 0;
|
|
351
|
+
const revisions = new Map((p.sharedContext ?? []).map(entry => [entry.id, entry.revision]));
|
|
352
|
+
const previousRefs = new Map((p.sharedContext ?? []).map(entry => [entry.id, { refs: JSON.stringify(entry.evidenceRefs), cwd: entry.sourceCwd }]));
|
|
353
|
+
publishTeamContext(p, inputs, actor ?? "user", canEdit);
|
|
354
|
+
for (const entry of p.sharedContext ?? [])
|
|
355
|
+
if (entry.revision !== revisions.get(entry.id)) {
|
|
356
|
+
const author = actor ? this.store.conversation(actor) : undefined;
|
|
357
|
+
const previous = previousRefs.get(entry.id);
|
|
358
|
+
entry.sourceCwd = previous?.refs === JSON.stringify(entry.evidenceRefs) ? previous.cwd : author?.cwd;
|
|
359
|
+
if (!revisions.has(entry.id))
|
|
360
|
+
entry.sourceMessageId = author?.messages?.at(-1)?.id;
|
|
361
|
+
entry.updatedFromMessageId = author?.messages?.at(-1)?.id;
|
|
362
|
+
}
|
|
363
|
+
if (before !== (p.contextRevision ?? 0))
|
|
364
|
+
this.event(p, "context_published", `共享上下文更新到第 ${p.contextRevision} 版`, undefined, actor);
|
|
365
|
+
}
|
|
366
|
+
async shareContext(id, value, workspaceId, actor) {
|
|
367
|
+
return this.change(id, workspaceId, p => { this.live(p); this.publishContext(p, value, actor); return { revision: p.contextRevision ?? 0, entries: p.sharedContext ?? [] }; });
|
|
368
|
+
}
|
|
369
|
+
async messageTask(id, taskId, content, workspaceId, actor, targetConversationId, deliveryMode = "queue") {
|
|
370
|
+
const p = this.raw(id, workspaceId);
|
|
371
|
+
this.live(p);
|
|
372
|
+
const task = this.task(p, taskId);
|
|
373
|
+
this.manager(p, task, actor);
|
|
374
|
+
if (!["in_progress", "awaiting_review", "blocked"].includes(task.status))
|
|
375
|
+
throw new Error("补充指令只用于执行、复核或阻塞中的任务;新工作请登记任务,返工请重新派发原任务");
|
|
376
|
+
if (!["queue", "steer"].includes(deliveryMode))
|
|
377
|
+
throw new Error("deliveryMode 只能是 queue 或 steer");
|
|
378
|
+
const target = targetConversationId ?? task.ownerConversationId;
|
|
379
|
+
if (!target || ![task.ownerConversationId, task.reviewerConversationId].includes(target))
|
|
380
|
+
throw new Error("补充指令只能发送给本任务已有的执行或复核会话");
|
|
381
|
+
const result = await this.dispatchContext(target, text(content, "补充指令"), { wait: false, mode: deliveryMode }, task.id);
|
|
382
|
+
await this.change(id, workspaceId, project => {
|
|
383
|
+
this.event(project, "task_message", `向「${task.title}」发送补充指令(${deliveryMode === "steer" ? "下一工具边界" : "排队"}),附带当前共享上下文`, task.id, actor);
|
|
384
|
+
});
|
|
385
|
+
return result;
|
|
386
|
+
}
|
|
387
|
+
getContext(id, workspaceId, actor, taskId, contextIds) {
|
|
388
|
+
const p = id ? this.raw(id, workspaceId) : actor ? this.projectForSession(actor) : undefined;
|
|
389
|
+
if (!p)
|
|
390
|
+
return { notes: "", entries: [], revision: 0 };
|
|
391
|
+
if (p.workspaceId !== workspaceId)
|
|
392
|
+
throw new Error("项目不属于当前工作区");
|
|
393
|
+
this.member(p, actor);
|
|
394
|
+
const assigned = taskId ? this.task(p, taskId) : actor === p.ownerConversationId ? undefined : p.tasks.filter(item => item.ownerConversationId === actor || item.reviewerConversationId === actor)
|
|
395
|
+
.sort((a, b) => Number(b.status === "in_progress" || b.status === "awaiting_review") - Number(a.status === "in_progress" || a.status === "awaiting_review") || (b.dispatchedAt ?? b.updatedAt).localeCompare(a.dispatchedAt ?? a.updatedAt))[0];
|
|
396
|
+
const task = assigned && actor && assigned.reviewerConversationId === actor ? { ...assigned, readOnly: true, ownedPaths: [] } : assigned;
|
|
397
|
+
if (contextIds !== undefined) {
|
|
398
|
+
if (!Array.isArray(contextIds) || contextIds.length > 32 || contextIds.some(item => typeof item !== "string"))
|
|
399
|
+
throw new Error("contextIds 须为最多 32 项的条目 id 数组");
|
|
400
|
+
return { projectId: p.id, revision: p.contextRevision ?? 0, entries: (p.sharedContext ?? []).filter(entry => contextIds.includes(entry.id)), notes: "" };
|
|
401
|
+
}
|
|
402
|
+
const workspace = this.store.workspace(workspaceId);
|
|
403
|
+
const source = assigned && actor && assigned.reviewerConversationId === actor ? assigned.ownerConversationId
|
|
404
|
+
: task?.parentTaskId ? p.tasks.find(parent => parent.id === task.parentTaskId)?.ownerConversationId : p.ownerConversationId;
|
|
405
|
+
const files = workspace && source ? discoverTeamFiles(this.store.conversation(source), workspace.path) : [];
|
|
406
|
+
const handoff = buildTeamHandoff(p, task, source, files, actor ? this.store.conversation(actor)?.cwd : undefined);
|
|
407
|
+
return { projectId: p.id, revision: p.contextRevision ?? 0, ...handoff, navigationFiles: files };
|
|
408
|
+
}
|
|
409
|
+
assertWriteScope(p, task) {
|
|
410
|
+
if (task.readOnly || !task.ownedPaths?.length)
|
|
411
|
+
return;
|
|
412
|
+
const conflicts = p.tasks.filter(other => other.id !== task.id && !other.readOnly && other.status === "in_progress"
|
|
413
|
+
&& other.ownerConversationId && busy(this.store.conversation(other.ownerConversationId)?.status)
|
|
414
|
+
&& other.ownedPaths?.some(path => task.ownedPaths.some(own => pathsOverlap(path, own))));
|
|
415
|
+
if (conflicts.length)
|
|
416
|
+
throw new Error(`并行写入范围冲突:${conflicts.map(other => `${other.title}(${other.ownedPaths?.join("、")})`).join(";")}。请调整分工范围或等待这些任务完成;只读任务可并行。`);
|
|
417
|
+
}
|
|
418
|
+
taskCoordination(input) {
|
|
419
|
+
if (input.readOnly !== undefined && typeof input.readOnly !== "boolean")
|
|
420
|
+
throw new Error("readOnly 必须为布尔值");
|
|
421
|
+
if (input.handoffNote !== undefined && (typeof input.handoffNote !== "string" || input.handoffNote.length > 8000))
|
|
422
|
+
throw new Error("handoffNote 须为最多 8000 字符的交接说明");
|
|
423
|
+
return {
|
|
424
|
+
...(input.ownedPaths === undefined ? {} : { ownedPaths: teamPaths(input.ownedPaths) }),
|
|
425
|
+
...(input.readOnly === undefined ? {} : { readOnly: input.readOnly }),
|
|
426
|
+
...(input.handoffNote === undefined ? {} : { handoffNote: input.handoffNote.trim() }),
|
|
427
|
+
};
|
|
428
|
+
}
|
|
429
|
+
captureHandoff(p, task, source) {
|
|
430
|
+
const workspace = this.store.workspace(p.workspaceId);
|
|
431
|
+
const files = workspace && source ? discoverTeamFiles(this.store.conversation(source), workspace.path) : [];
|
|
432
|
+
task.handoff = buildTeamHandoff(p, task, source, files, this.store.conversation(task.ownerConversationId ?? "")?.cwd);
|
|
433
|
+
}
|
|
434
|
+
async dispatchContext(conversationId, content, options = {}, taskId) {
|
|
435
|
+
if (!this.orchestrator)
|
|
436
|
+
throw new Error("会话编排服务未就绪");
|
|
437
|
+
const project = this.store.projects().find(p => p.ownerConversationId === conversationId
|
|
438
|
+
|| p.tasks.some(task => task.ownerConversationId === conversationId || task.reviewerConversationId === conversationId));
|
|
439
|
+
if (project) {
|
|
440
|
+
const snapshot = this.getContext(project.id, project.workspaceId, conversationId, taskId);
|
|
441
|
+
if (snapshot.notes)
|
|
442
|
+
content += `\n${snapshot.notes}`;
|
|
443
|
+
}
|
|
444
|
+
return this.orchestrator.dispatch(conversationId, content, options);
|
|
445
|
+
}
|
|
446
|
+
syncDeliveryContext(p, task, actor) {
|
|
447
|
+
if (!task.output || !task.evidenceRefs?.length)
|
|
448
|
+
return;
|
|
449
|
+
const current = p.sharedContext?.find(entry => entry.deliveryTaskId === task.id);
|
|
450
|
+
const accepted = this.taskAccepted(task);
|
|
451
|
+
try {
|
|
452
|
+
publishTeamContext(p, [{
|
|
453
|
+
...(current ? { id: current.id, expectedRevision: current.revision } : {}),
|
|
454
|
+
title: `${accepted ? "已验收交付" : "待验证交付"}:${task.title}`.slice(0, 160),
|
|
455
|
+
content: task.output.slice(0, 8000), kind: accepted ? "finding" : "hypothesis", status: "active",
|
|
456
|
+
taskIds: [task.id], paths: task.ownedPaths ?? [], evidenceRefs: task.evidenceRefs,
|
|
457
|
+
}], actor ?? task.ownerConversationId ?? "user", () => true);
|
|
458
|
+
}
|
|
459
|
+
catch (error) {
|
|
460
|
+
if (error instanceof Error && error.message.includes("超过 1 MB")) {
|
|
461
|
+
this.event(p, "context_capacity", "交付已保留,自动共享摘要未写入:请将旧记录整理为文件摘要", task.id, actor);
|
|
462
|
+
return;
|
|
463
|
+
}
|
|
464
|
+
throw error;
|
|
465
|
+
}
|
|
466
|
+
const entry = current ? p.sharedContext?.find(entry => entry.id === current.id) : p.sharedContext?.at(-1);
|
|
467
|
+
if (entry) {
|
|
468
|
+
const owner = this.store.conversation(task.ownerConversationId ?? "");
|
|
469
|
+
entry.deliveryTaskId = task.id;
|
|
470
|
+
entry.sourceCwd = owner?.cwd;
|
|
471
|
+
entry.sourceMessageId ??= owner?.messages?.at(-1)?.id;
|
|
472
|
+
entry.updatedFromMessageId = actor ? this.store.conversation(actor)?.messages?.at(-1)?.id : undefined;
|
|
473
|
+
}
|
|
474
|
+
}
|
|
475
|
+
dispatchReceipt(task) {
|
|
476
|
+
if (!task.handoff)
|
|
477
|
+
return task;
|
|
478
|
+
const { notes: _notes, discoveryFiles: _files, ...handoff } = task.handoff;
|
|
479
|
+
return { ...task, handoff };
|
|
480
|
+
}
|
|
341
481
|
/**
|
|
342
482
|
* A PROJECT EMPLOYEE MUST BE A PRIMARY AGENT.
|
|
343
483
|
*
|
|
@@ -470,7 +610,7 @@ export class ProjectService {
|
|
|
470
610
|
if (!this.orchestrator)
|
|
471
611
|
return;
|
|
472
612
|
try {
|
|
473
|
-
await this.
|
|
613
|
+
await this.dispatchContext(target, prompt, { wait: false });
|
|
474
614
|
}
|
|
475
615
|
catch (error) {
|
|
476
616
|
const message = error instanceof Error ? error.message : String(error);
|
|
@@ -1196,6 +1336,7 @@ export class ProjectService {
|
|
|
1196
1336
|
else {
|
|
1197
1337
|
this.event(p, "created", "Boss 触发项目");
|
|
1198
1338
|
}
|
|
1339
|
+
this.publishContext(p, input.sharedContext, initiator);
|
|
1199
1340
|
const saved = await this.store.setProject(p);
|
|
1200
1341
|
return this.projectView(saved);
|
|
1201
1342
|
}
|
|
@@ -1275,7 +1416,7 @@ export class ProjectService {
|
|
|
1275
1416
|
this.event(p, "started", "项目负责人开始组织执行", undefined, actor);
|
|
1276
1417
|
p.status = "active";
|
|
1277
1418
|
await this.store.setProject(p);
|
|
1278
|
-
await this.
|
|
1419
|
+
await this.dispatchContext(p.ownerConversationId, `${this.context(p)}\n${lightweight(p) ? LIGHTWEIGHT_LEADER_PROMPT : STANDARD_LEADER_PROMPT}`, { wait: false });
|
|
1279
1420
|
return p;
|
|
1280
1421
|
});
|
|
1281
1422
|
}
|
|
@@ -1344,7 +1485,9 @@ export class ProjectService {
|
|
|
1344
1485
|
...(executorProfile ? { executorProfile } : {}),
|
|
1345
1486
|
...(reviewerProfile ? { reviewerProfile } : {}),
|
|
1346
1487
|
dueAt: optional(input.dueAt, "截止时间"), createdAt: now, updatedAt: now };
|
|
1488
|
+
Object.assign(t, this.taskCoordination(input));
|
|
1347
1489
|
p.tasks.push(t);
|
|
1490
|
+
this.publishContext(p, input.sharedContext, actor);
|
|
1348
1491
|
this.reconcile(p);
|
|
1349
1492
|
this.event(p, "task_created", `登记任务:${t.title}`, t.id, actor);
|
|
1350
1493
|
return ProjectService.taskView(t, p);
|
|
@@ -1354,6 +1497,7 @@ export class ProjectService {
|
|
|
1354
1497
|
return this.change(id, workspaceId, async (p) => {
|
|
1355
1498
|
const t = this.task(p, taskId);
|
|
1356
1499
|
const manager = this.manager(p, t, actor);
|
|
1500
|
+
this.assertWriteScope(p, t);
|
|
1357
1501
|
/* WAS THIS TASK INTERRUPTED? It is remembered before the status moves on, because both the
|
|
1358
1502
|
worker and the reader need to know that this is a task coming back from a dead session,
|
|
1359
1503
|
not a task that is being started for the first time. */
|
|
@@ -1421,7 +1565,8 @@ export class ProjectService {
|
|
|
1421
1565
|
delete t.blockedReason;
|
|
1422
1566
|
delete t.blockedReportedByConversationId;
|
|
1423
1567
|
delete t.interruptedReason;
|
|
1424
|
-
this.
|
|
1568
|
+
this.captureHandoff(p, t, manager);
|
|
1569
|
+
this.event(p, "dispatched", `派发执行:${t.title};交接 ${t.handoff?.entries.length ?? 0} 条共享记录`, t.id, actor);
|
|
1425
1570
|
this.reconcile(p);
|
|
1426
1571
|
await this.store.setProject(p);
|
|
1427
1572
|
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;小任务不要继续拆层。你的下属的升级先到你这里;你决定是自己解决还是再向上级转述。` : `你是执行者,直接上级会话是 ${manager},不得自行拆解子任务。`;
|
|
@@ -1436,7 +1581,7 @@ export class ProjectService {
|
|
|
1436
1581
|
? `\n注意:这个任务上一次执行被中断了(${oneLine(interruptedNote ?? "执行会话不在了")})。请先确认当前状态,再继续完成交付;不要假设上一次的工作已经完成。`
|
|
1437
1582
|
: "";
|
|
1438
1583
|
try {
|
|
1439
|
-
await this.
|
|
1584
|
+
await this.dispatchContext(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}${recoveryNote}完成后必须调用 project(action=submit, projectId="${p.id}", taskId="${t.id}", output="交付总结", evidenceRefs=["产物路径或验证记录"]),不能自行标记已完成。复核退回时修复后重新 submit。遇到阻塞用 report(阻塞) 或 escalate 上报给你的直接上级,不要直接找 Boss,保留证据、假设和未解决问题。不要自行创建其他执行会话或 task/workflow。`, { wait: false }, t.id);
|
|
1440
1585
|
}
|
|
1441
1586
|
catch (error) {
|
|
1442
1587
|
/* A DISPATCH THAT DID NOT HAPPEN MUST NOT LEAVE THE TASK SAYING 「执行中」. The status was
|
|
@@ -1474,6 +1619,7 @@ export class ProjectService {
|
|
|
1474
1619
|
// that does not get lighter.
|
|
1475
1620
|
if (!t.evidenceRefs.length)
|
|
1476
1621
|
throw new Error("交付必须附上产物或验证证据");
|
|
1622
|
+
this.publishContext(p, input.sharedContext, actor);
|
|
1477
1623
|
if (lightweight(p)) {
|
|
1478
1624
|
/* THE DELIVERY IS ACCEPTED ON THE EXECUTOR'S OWN EVIDENCE. There is no reviewer session to
|
|
1479
1625
|
send it to, so the acceptance is written down here - with the flag that says there was
|
|
@@ -1483,6 +1629,7 @@ export class ProjectService {
|
|
|
1483
1629
|
t.updatedAt = stamp();
|
|
1484
1630
|
t.review = { verdict: "accepted", summary: "轻量项目:执行者自评交付,未做独立复核", evidenceRefs,
|
|
1485
1631
|
reviewerConversationId: t.ownerConversationId, createdAt: stamp(), lightweight: true };
|
|
1632
|
+
this.syncDeliveryContext(p, t, actor);
|
|
1486
1633
|
this.event(p, "submitted", `轻量交付完成:${t.title}`, t.id, actor);
|
|
1487
1634
|
this.reconcile(p);
|
|
1488
1635
|
return ProjectService.taskView(t, p);
|
|
@@ -1490,6 +1637,7 @@ export class ProjectService {
|
|
|
1490
1637
|
t.status = "awaiting_review";
|
|
1491
1638
|
t.updatedAt = stamp();
|
|
1492
1639
|
delete t.review;
|
|
1640
|
+
this.syncDeliveryContext(p, t, actor);
|
|
1493
1641
|
this.event(p, "submitted", `交付待独立复核:${t.title}`, t.id, actor);
|
|
1494
1642
|
this.reconcile(p);
|
|
1495
1643
|
return ProjectService.taskView(t, p);
|
|
@@ -1523,7 +1671,7 @@ export class ProjectService {
|
|
|
1523
1671
|
throw new Error("复核会话正在执行");
|
|
1524
1672
|
this.event(p, "review_requested", `启动独立复核:${t.title}`, t.id, actor);
|
|
1525
1673
|
await this.store.setProject(p);
|
|
1526
|
-
await this.
|
|
1674
|
+
await this.dispatchContext(t.reviewerConversationId, `${this.context(p)}\n你是独立复核人,只读检查,不修改执行者产物。任务 ${t.id}:${t.title}\n目标:${t.objective}\n验收标准:${t.acceptanceCriteria.join(";")}\n交付:${t.output}\n证据:${JSON.stringify(t.evidenceRefs)}\n主动寻找反例,核对真实产物、测试与证据,不能只复述作者结论。调用 project(action=review, projectId="${p.id}", taskId="${t.id}", verdict="accepted" 或 "changes_requested", summary="验收理由或具体返工项", evidenceRefs=["独立验证记录"])。完成后结束本轮,由上级安排后续。不创建额外会话。`, { wait: false }, t.id);
|
|
1527
1675
|
return ProjectService.taskView(t, p);
|
|
1528
1676
|
});
|
|
1529
1677
|
}
|
|
@@ -1543,6 +1691,7 @@ export class ProjectService {
|
|
|
1543
1691
|
t.review = { verdict: input.verdict, summary: text(input.summary, "复核意见"), evidenceRefs, reviewerConversationId: actor, createdAt: stamp() };
|
|
1544
1692
|
t.status = input.verdict === "accepted" ? "completed" : "ready";
|
|
1545
1693
|
t.updatedAt = stamp();
|
|
1694
|
+
this.syncDeliveryContext(p, t, actor);
|
|
1546
1695
|
this.event(p, "reviewed", `${input.verdict === "accepted" ? "验收通过" : "退回返工"}:${t.title};${t.review.summary}`, t.id, actor);
|
|
1547
1696
|
this.reconcile(p);
|
|
1548
1697
|
return ProjectService.taskView(t, p);
|
|
@@ -1556,6 +1705,11 @@ export class ProjectService {
|
|
|
1556
1705
|
const manager = this.manager(p, t);
|
|
1557
1706
|
if (actor && actor !== manager && actor !== t.ownerConversationId)
|
|
1558
1707
|
throw new Error("无权更新此任务");
|
|
1708
|
+
if (patch.ownedPaths !== undefined || patch.readOnly !== undefined || patch.handoffNote !== undefined) {
|
|
1709
|
+
if (t.status === "in_progress" || t.status === "awaiting_review")
|
|
1710
|
+
throw new Error("执行或复核期间不能修改分工范围,请通过共享条目补充发现");
|
|
1711
|
+
Object.assign(t, this.taskCoordination({ ownedPaths: patch.ownedPaths, readOnly: patch.readOnly, handoffNote: patch.handoffNote }));
|
|
1712
|
+
}
|
|
1559
1713
|
if (patch.status !== undefined) {
|
|
1560
1714
|
if (patch.status === "in_progress" && !dependenciesComplete(p, t))
|
|
1561
1715
|
throw new Error("任务的前置依赖尚未全部完成,不能开始执行");
|
|
@@ -1740,6 +1894,7 @@ export class ProjectService {
|
|
|
1740
1894
|
const report = { id: randomUUID(), projectId: id, taskId: t?.id, authorConversationId: actor, kind: input.kind,
|
|
1741
1895
|
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, "风险"),
|
|
1742
1896
|
decisionNeeded: optional(input.decisionNeeded, "所需决策"), evidenceRefs: strings(input.evidenceRefs, "证据"), createdAt: stamp() };
|
|
1897
|
+
this.publishContext(p, input.sharedContext, actor);
|
|
1743
1898
|
p.reports.push(report);
|
|
1744
1899
|
if (report.kind === "blocked") {
|
|
1745
1900
|
if (t) {
|
|
@@ -1988,6 +2143,7 @@ export class ProjectService {
|
|
|
1988
2143
|
acceptanceCriteria: record.acceptanceCriteria === undefined ? undefined : strings(record.acceptanceCriteria, "任务验收标准"),
|
|
1989
2144
|
priority: priority,
|
|
1990
2145
|
dependencies: record.dependencies === undefined ? [] : strings(record.dependencies, "任务依赖"),
|
|
2146
|
+
...this.taskCoordination(record),
|
|
1991
2147
|
};
|
|
1992
2148
|
});
|
|
1993
2149
|
const index = new Map();
|
|
@@ -2026,6 +2182,7 @@ export class ProjectService {
|
|
|
2026
2182
|
const dependencies = item.dependencies.map((dependency) => ids.get(dependency));
|
|
2027
2183
|
const task = await this.addTask(projectId, {
|
|
2028
2184
|
title: item.title, objective: item.objective,
|
|
2185
|
+
...this.taskCoordination(item),
|
|
2029
2186
|
...(item.deliverables ? { deliverables: item.deliverables } : {}),
|
|
2030
2187
|
...(item.acceptanceCriteria ? { acceptanceCriteria: item.acceptanceCriteria } : {}),
|
|
2031
2188
|
...(item.priority !== undefined ? { priority: item.priority } : {}),
|
|
@@ -2076,7 +2233,7 @@ export class ProjectService {
|
|
|
2076
2233
|
}
|
|
2077
2234
|
if (!this.orchestrator)
|
|
2078
2235
|
throw new Error("会话编排服务未就绪");
|
|
2079
|
-
await this.
|
|
2236
|
+
await this.dispatchContext(target, message, { wait: false });
|
|
2080
2237
|
return { ok: true, conversationId: target, delivered: true };
|
|
2081
2238
|
}
|
|
2082
2239
|
async tool(body, workspaceId, actor) {
|
|
@@ -2128,6 +2285,8 @@ export class ProjectService {
|
|
|
2128
2285
|
// and "the workspace has fifty and I was shown twenty".
|
|
2129
2286
|
return this.listForActor(workspaceId, actor);
|
|
2130
2287
|
}
|
|
2288
|
+
if (body.action === "get_context")
|
|
2289
|
+
return this.getContext(typeof body.projectId === "string" ? body.projectId : undefined, workspaceId, actor, typeof body.taskId === "string" ? body.taskId : undefined, body.contextIds);
|
|
2131
2290
|
const id = text(body.projectId, "projectId");
|
|
2132
2291
|
const rawProject = this.raw(id, workspaceId);
|
|
2133
2292
|
this.member(rawProject, actor);
|
|
@@ -2136,7 +2295,35 @@ export class ProjectService {
|
|
|
2136
2295
|
case "export": return this.exportReport(id, workspaceId);
|
|
2137
2296
|
case "start": return this.start(id, workspaceId, actor);
|
|
2138
2297
|
case "add_task": return this.addTask(id, body, workspaceId, actor);
|
|
2139
|
-
case "
|
|
2298
|
+
case "share_context": return this.shareContext(id, body.sharedContext, workspaceId, actor);
|
|
2299
|
+
case "message": {
|
|
2300
|
+
this.manager(rawProject, this.task(rawProject, text(body.taskId, "taskId")), actor);
|
|
2301
|
+
if (body.sharedContext !== undefined)
|
|
2302
|
+
await this.shareContext(id, body.sharedContext, workspaceId, actor);
|
|
2303
|
+
return this.messageTask(id, text(body.taskId, "taskId"), text(body.content, "content"), workspaceId, actor, typeof body.targetConversationId === "string" ? body.targetConversationId : undefined, body.deliveryMode);
|
|
2304
|
+
}
|
|
2305
|
+
case "dispatch": {
|
|
2306
|
+
if (body.sharedContext !== undefined)
|
|
2307
|
+
await this.shareContext(id, body.sharedContext, workspaceId, actor);
|
|
2308
|
+
if (body.taskIds === undefined) {
|
|
2309
|
+
const taskId = text(body.taskId, "taskId");
|
|
2310
|
+
if (body.handoffNote !== undefined)
|
|
2311
|
+
await this.updateTask(id, taskId, { workspaceId, handoffNote: body.handoffNote }, actor);
|
|
2312
|
+
return this.dispatchReceipt(await this.dispatchTask(id, taskId, workspaceId, actor));
|
|
2313
|
+
}
|
|
2314
|
+
if (!Array.isArray(body.taskIds) || !body.taskIds.length || body.taskIds.length > 32 || body.taskIds.some(taskId => typeof taskId !== "string"))
|
|
2315
|
+
throw new Error("taskIds 须为 1–32 项任务 id 数组");
|
|
2316
|
+
const started = [], failed = [];
|
|
2317
|
+
for (const taskId of [...new Set(body.taskIds)]) {
|
|
2318
|
+
try {
|
|
2319
|
+
started.push(await this.dispatchTask(id, taskId, workspaceId, actor));
|
|
2320
|
+
}
|
|
2321
|
+
catch (error) {
|
|
2322
|
+
failed.push({ taskId, error: error instanceof Error ? error.message : String(error) });
|
|
2323
|
+
}
|
|
2324
|
+
}
|
|
2325
|
+
return { ok: failed.length === 0, partial: failed.length > 0 && started.length > 0, started: started.map(task => this.dispatchReceipt(task)), failed };
|
|
2326
|
+
}
|
|
2140
2327
|
case "submit": return this.submit(id, text(body.taskId, "taskId"), body, workspaceId, actor);
|
|
2141
2328
|
case "request_review": return this.requestReview(id, text(body.taskId, "taskId"), workspaceId, actor);
|
|
2142
2329
|
case "review": return this.review(id, text(body.taskId, "taskId"), body, workspaceId, actor);
|
|
@@ -17,6 +17,8 @@ export declare const sessionResultRelativePath: (conversationId: string) => stri
|
|
|
17
17
|
*/
|
|
18
18
|
export declare const MAX_LENGTH_CONTINUATIONS = 3;
|
|
19
19
|
export interface SpawnSessionOptions {
|
|
20
|
+
/** Explicit, task-specific findings to hand over without copying private transcripts. */
|
|
21
|
+
handoffNote?: string;
|
|
20
22
|
/** The high-level task to be performed by the sibling session. */
|
|
21
23
|
task: string;
|
|
22
24
|
/** Parent conversation initiating the orchestration, if any. */
|
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
import { mkdir, readFile, rm, writeFile } from "node:fs/promises";
|
|
2
|
-
import { join } from "node:path";
|
|
2
|
+
import { join, posix } from "node:path";
|
|
3
3
|
import { parseMessageDeliveryMode } from "./run-service.js";
|
|
4
4
|
import { deleteConversationUploads } from "../upload.js";
|
|
5
5
|
import { capText } from "../workflow.js";
|
|
6
6
|
import { assertSessionCwdInsideWorkspace } from "../session-cwd.js";
|
|
7
7
|
import { SessionWatchdog } from "./session-watchdog.js";
|
|
8
8
|
import { isLengthExceededError } from "../turn-failure.js";
|
|
9
|
+
import { discoverTeamFiles } from "../team-context.js";
|
|
9
10
|
import { buildLengthContinuationPrompt } from "../length-continuation.js";
|
|
10
11
|
export const SESSION_OUTPUT_CHAR_LIMIT = 64 * 1024;
|
|
11
12
|
export const sessionResultRelativePath = (conversationId) => `.super-pi/session-results/${conversationId}.md`;
|
|
@@ -125,8 +126,11 @@ export class SessionOrchestratorService {
|
|
|
125
126
|
const workspace = this.store.workspace(workspaceId);
|
|
126
127
|
if (!workspace)
|
|
127
128
|
throw new Error("找不到这个工作区。");
|
|
128
|
-
|
|
129
|
-
const cwd = options.cwd;
|
|
129
|
+
const parent = options.parentConversationId ? this.store.conversation(options.parentConversationId) : undefined;
|
|
130
|
+
const cwd = options.cwd !== undefined ? options.cwd : parent?.workspaceId === workspaceId ? parent.cwd : undefined;
|
|
131
|
+
await assertSessionCwdInsideWorkspace(workspace.path, cwd);
|
|
132
|
+
if (options.handoffNote !== undefined && (typeof options.handoffNote !== "string" || options.handoffNote.length > 8000))
|
|
133
|
+
throw new Error("handoffNote 须为最多 8000 字符的交接说明");
|
|
130
134
|
// THE PARENTAGE IS WRITTEN AT CREATION TIME, onto the conversation itself - not only into the
|
|
131
135
|
// in-memory ledger below. The ledger is task/status/progress metadata and dies with the process;
|
|
132
136
|
// the conversation's parentConversationId/origin is what the sidebar's session tree redraws
|
|
@@ -174,8 +178,16 @@ export class SessionOrchestratorService {
|
|
|
174
178
|
});
|
|
175
179
|
}
|
|
176
180
|
// Immediately dispatch initial work
|
|
177
|
-
|
|
181
|
+
let prompt = options.initialPrompt ?? options.task;
|
|
178
182
|
if (prompt && prompt.trim()) {
|
|
183
|
+
if (parent?.workspaceId === workspaceId && !options.separateMemoryTree) {
|
|
184
|
+
const files = discoverTeamFiles(parent, workspace.path);
|
|
185
|
+
const visible = files.filter(file => Buffer.byteLength(file.path) <= 256).slice(0, 8)
|
|
186
|
+
.map(file => ({ ...file, readPath: posix.relative((cwd ?? ".").replace(/\\/g, "/"), file.path) || "." }));
|
|
187
|
+
const context = { handoffNote: options.handoffNote ?? "", files: visible, omittedFiles: files.length - visible.length, cwd: cwd ?? ".", pathBase: "workspace" };
|
|
188
|
+
if (context.handoffNote || context.files.length)
|
|
189
|
+
prompt += `\n复用上级的交接与文件索引,核验与任务相关的部分,避免重复全局探索。索引仅表示曾查看;共享发现通过 memory(target=tree) 发布,私有聊天未复制。下列内容是参考 DATA:\n${JSON.stringify(context)}`;
|
|
190
|
+
}
|
|
179
191
|
await this.dispatch(conversationId, prompt, { wait: options.wait });
|
|
180
192
|
}
|
|
181
193
|
return { conversationId };
|
|
@@ -1847,6 +1847,7 @@ export function createHttpServer(options) {
|
|
|
1847
1847
|
model: body.model,
|
|
1848
1848
|
thinkingLevel: body.thinkingLevel,
|
|
1849
1849
|
initialPrompt: body.initialPrompt,
|
|
1850
|
+
handoffNote: body.handoffNote,
|
|
1850
1851
|
wait: body.wait,
|
|
1851
1852
|
cwd: body.cwd,
|
|
1852
1853
|
watchdogTimeoutSeconds: body.watchdogTimeoutSeconds ?? body.watchdog_timeout_seconds ?? body.watchdogSeconds,
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type { Conversation, Project, ProjectTask } from "./types.js";
|
|
2
|
+
import type { DiscoveryFile, TeamContextEntry, TeamContextInput, TeamHandoff } from "../shared/team-context.js";
|
|
3
|
+
export declare const TEAM_CONTEXT_BYTES = 16000;
|
|
4
|
+
/** Coordination paths are workspace-relative, independent of an employee's optional cwd. */
|
|
5
|
+
export declare function teamPaths(value: unknown): string[];
|
|
6
|
+
export declare function pathsOverlap(a: string, b: string): boolean;
|
|
7
|
+
export declare function parseTeamContext(value: unknown): TeamContextInput[];
|
|
8
|
+
/** Apply a batch to a copy, so a stale revision cannot partially publish the preceding items. */
|
|
9
|
+
export declare function publishTeamContext(project: Project, inputs: TeamContextInput[], actor: string, canEdit: (entry: TeamContextEntry) => boolean): void;
|
|
10
|
+
/** Share navigation metadata only. Reading a file is not a finding, and tool output stays private. */
|
|
11
|
+
export declare function discoverTeamFiles(conversation: Conversation | undefined, workspace: string): DiscoveryFile[];
|
|
12
|
+
export declare function buildTeamHandoff(project: Project, task?: ProjectTask, sourceConversationId?: string, discoveryFiles?: DiscoveryFile[], sessionCwd?: string): TeamHandoff;
|