@evandu/super-pi 0.1.202 → 0.1.204

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.
Files changed (43) hide show
  1. package/agents/coder.md +2 -0
  2. package/agents/project-leader.md +2 -0
  3. package/agents/reviewer.md +2 -0
  4. package/agents/super-pi-task/core.ts +15 -0
  5. package/agents/super-pi-task/index.ts +28 -3
  6. package/dist/client/.super-pi-client-sources.json +4 -4
  7. package/dist/client/assets/{CodeMirrorEditor-vxQIyy7b.js → CodeMirrorEditor-KQDBvdAI.js} +2 -2
  8. package/dist/client/assets/{dist-4SH20Tbv.js → dist-1vBvKRAO.js} +1 -1
  9. package/dist/client/assets/{dist-B_slddW0.js → dist-3UazBQPy.js} +1 -1
  10. package/dist/client/assets/{dist-DEKddEF2.js → dist-3nL837Fs.js} +1 -1
  11. package/dist/client/assets/{dist-IjAxSRZT.js → dist-50OrOetK.js} +1 -1
  12. package/dist/client/assets/{dist-D9xg8iqu.js → dist-B-wznWiJ.js} +1 -1
  13. package/dist/client/assets/{dist-DcgxyyHo.js → dist-B015qWBZ.js} +1 -1
  14. package/dist/client/assets/{dist-BOiDpbIK.js → dist-B2DwIkxS.js} +1 -1
  15. package/dist/client/assets/{dist-Dbqc2GHg.js → dist-BN2UnOQ2.js} +1 -1
  16. package/dist/client/assets/{dist-B9Xymme_.js → dist-Bim285Uv.js} +1 -1
  17. package/dist/client/assets/{dist-CPrZlJdM.js → dist-Bz8mBVYg.js} +1 -1
  18. package/dist/client/assets/{dist-C6vEFxfz.js → dist-CA6dRqYD.js} +1 -1
  19. package/dist/client/assets/{dist-C6WoehaJ.js → dist-CWwcn5gh.js} +1 -1
  20. package/dist/client/assets/{dist-DRZYzTGl.js → dist-Ce0_mKRX.js} +1 -1
  21. package/dist/client/assets/{dist-p340hSe4.js → dist-DNFTA8eK.js} +1 -1
  22. package/dist/client/assets/{dist-DqP_0JTb.js → dist-DNjtMha0.js} +1 -1
  23. package/dist/client/assets/{dist-B-IVJoQx.js → dist-DWD02ase.js} +1 -1
  24. package/dist/client/assets/{dist-B131Snro.js → dist-DYys59TX.js} +1 -1
  25. package/dist/client/assets/{dist-BA_txYZC.js → dist-DpFdyk4c.js} +1 -1
  26. package/dist/client/assets/{dist-DEROl11F.js → dist-EZxvaEWE.js} +1 -1
  27. package/dist/client/assets/{dist-DAYkQ0P3.js → dist-J3S-elPb.js} +1 -1
  28. package/dist/client/assets/{dist-DDjw1OJ2.js → dist-KL5ywpxl.js} +1 -1
  29. package/dist/client/assets/{dist-BBL_GRBs.js → dist-xcgc6bsN.js} +1 -1
  30. package/dist/client/assets/{index-fsBZreVZ.js → index-Bmx2_cFl.js} +11 -11
  31. package/dist/client/assets/{index-Df8Zo6Xu.css → index-DcuTYCZ-.css} +1 -1
  32. package/dist/client/index.html +2 -2
  33. package/dist/server/application/project-service.d.ts +19 -1
  34. package/dist/server/application/project-service.js +196 -7
  35. package/dist/server/application/session-orchestrator-service.d.ts +2 -0
  36. package/dist/server/application/session-orchestrator-service.js +16 -4
  37. package/dist/server/http-server.js +1 -0
  38. package/dist/server/team-context.d.ts +12 -0
  39. package/dist/server/team-context.js +179 -0
  40. package/dist/server/types.d.ts +6 -0
  41. package/dist/shared/team-context.d.ts +52 -0
  42. package/dist/shared/team-context.js +3 -0
  43. package/package.json +3 -1
@@ -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-fsBZreVZ.js"></script>
12
- <link rel="stylesheet" crossorigin href="/assets/index-Df8Zo6Xu.css">
11
+ <script type="module" crossorigin src="/assets/index-Bmx2_cFl.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">, workspaceId?: string, actor?: string): Promise<ProjectReport>;
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,147 @@ 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, receipt) {
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 (receipt)
440
+ content += `\n${receipt.notes}`;
441
+ else if (project) {
442
+ const snapshot = this.getContext(project.id, project.workspaceId, conversationId, taskId);
443
+ if (snapshot.notes)
444
+ content += `\n${snapshot.notes}`;
445
+ }
446
+ return this.orchestrator.dispatch(conversationId, content, options);
447
+ }
448
+ syncDeliveryContext(p, task, actor) {
449
+ if (!task.output || !task.evidenceRefs?.length)
450
+ return;
451
+ const current = p.sharedContext?.find(entry => entry.deliveryTaskId === task.id);
452
+ const accepted = this.taskAccepted(task);
453
+ try {
454
+ publishTeamContext(p, [{
455
+ ...(current ? { id: current.id, expectedRevision: current.revision } : {}),
456
+ title: `${accepted ? "已验收交付" : "待验证交付"}:${task.title}`.slice(0, 160),
457
+ content: task.output.slice(0, 8000), kind: accepted ? "finding" : "hypothesis", status: "active",
458
+ taskIds: [task.id], paths: task.ownedPaths ?? [], evidenceRefs: task.evidenceRefs,
459
+ }], actor ?? task.ownerConversationId ?? "user", () => true);
460
+ }
461
+ catch (error) {
462
+ if (error instanceof Error && error.message.includes("超过 1 MB")) {
463
+ this.event(p, "context_capacity", "交付已保留,自动共享摘要未写入:请将旧记录整理为文件摘要", task.id, actor);
464
+ return;
465
+ }
466
+ throw error;
467
+ }
468
+ const entry = current ? p.sharedContext?.find(entry => entry.id === current.id) : p.sharedContext?.at(-1);
469
+ if (entry) {
470
+ const owner = this.store.conversation(task.ownerConversationId ?? "");
471
+ entry.deliveryTaskId = task.id;
472
+ entry.sourceCwd = owner?.cwd;
473
+ entry.sourceMessageId ??= owner?.messages?.at(-1)?.id;
474
+ entry.updatedFromMessageId = actor ? this.store.conversation(actor)?.messages?.at(-1)?.id : undefined;
475
+ }
476
+ }
477
+ dispatchReceipt(task) {
478
+ if (!task.handoff)
479
+ return task;
480
+ const { notes: _notes, discoveryFiles: _files, ...handoff } = task.handoff;
481
+ return { ...task, handoff };
482
+ }
341
483
  /**
342
484
  * A PROJECT EMPLOYEE MUST BE A PRIMARY AGENT.
343
485
  *
@@ -470,7 +612,7 @@ export class ProjectService {
470
612
  if (!this.orchestrator)
471
613
  return;
472
614
  try {
473
- await this.orchestrator.dispatch(target, prompt, { wait: false });
615
+ await this.dispatchContext(target, prompt, { wait: false });
474
616
  }
475
617
  catch (error) {
476
618
  const message = error instanceof Error ? error.message : String(error);
@@ -1196,6 +1338,7 @@ export class ProjectService {
1196
1338
  else {
1197
1339
  this.event(p, "created", "Boss 触发项目");
1198
1340
  }
1341
+ this.publishContext(p, input.sharedContext, initiator);
1199
1342
  const saved = await this.store.setProject(p);
1200
1343
  return this.projectView(saved);
1201
1344
  }
@@ -1275,7 +1418,7 @@ export class ProjectService {
1275
1418
  this.event(p, "started", "项目负责人开始组织执行", undefined, actor);
1276
1419
  p.status = "active";
1277
1420
  await this.store.setProject(p);
1278
- await this.orchestrator.dispatch(p.ownerConversationId, `${this.context(p)}\n${lightweight(p) ? LIGHTWEIGHT_LEADER_PROMPT : STANDARD_LEADER_PROMPT}`, { wait: false });
1421
+ await this.dispatchContext(p.ownerConversationId, `${this.context(p)}\n${lightweight(p) ? LIGHTWEIGHT_LEADER_PROMPT : STANDARD_LEADER_PROMPT}`, { wait: false });
1279
1422
  return p;
1280
1423
  });
1281
1424
  }
@@ -1344,7 +1487,9 @@ export class ProjectService {
1344
1487
  ...(executorProfile ? { executorProfile } : {}),
1345
1488
  ...(reviewerProfile ? { reviewerProfile } : {}),
1346
1489
  dueAt: optional(input.dueAt, "截止时间"), createdAt: now, updatedAt: now };
1490
+ Object.assign(t, this.taskCoordination(input));
1347
1491
  p.tasks.push(t);
1492
+ this.publishContext(p, input.sharedContext, actor);
1348
1493
  this.reconcile(p);
1349
1494
  this.event(p, "task_created", `登记任务:${t.title}`, t.id, actor);
1350
1495
  return ProjectService.taskView(t, p);
@@ -1354,6 +1499,7 @@ export class ProjectService {
1354
1499
  return this.change(id, workspaceId, async (p) => {
1355
1500
  const t = this.task(p, taskId);
1356
1501
  const manager = this.manager(p, t, actor);
1502
+ this.assertWriteScope(p, t);
1357
1503
  /* WAS THIS TASK INTERRUPTED? It is remembered before the status moves on, because both the
1358
1504
  worker and the reader need to know that this is a task coming back from a dead session,
1359
1505
  not a task that is being started for the first time. */
@@ -1421,7 +1567,8 @@ export class ProjectService {
1421
1567
  delete t.blockedReason;
1422
1568
  delete t.blockedReportedByConversationId;
1423
1569
  delete t.interruptedReason;
1424
- this.event(p, "dispatched", `派发执行:${t.title}`, t.id, actor);
1570
+ this.captureHandoff(p, t, manager);
1571
+ this.event(p, "dispatched", `派发执行:${t.title};交接 ${t.handoff?.entries.length ?? 0} 条共享记录`, t.id, actor);
1425
1572
  this.reconcile(p);
1426
1573
  await this.store.setProject(p);
1427
1574
  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 +1583,7 @@ export class ProjectService {
1436
1583
  ? `\n注意:这个任务上一次执行被中断了(${oneLine(interruptedNote ?? "执行会话不在了")})。请先确认当前状态,再继续完成交付;不要假设上一次的工作已经完成。`
1437
1584
  : "";
1438
1585
  try {
1439
- 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}${recoveryNote}完成后必须调用 project(action=submit, projectId="${p.id}", taskId="${t.id}", output="交付总结", evidenceRefs=["产物路径或验证记录"]),不能自行标记已完成。复核退回时修复后重新 submit。遇到阻塞用 report(阻塞) 或 escalate 上报给你的直接上级,不要直接找 Boss,保留证据、假设和未解决问题。不要自行创建其他执行会话或 task/workflow。`, { wait: false });
1586
+ 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, t.handoff);
1440
1587
  }
1441
1588
  catch (error) {
1442
1589
  /* A DISPATCH THAT DID NOT HAPPEN MUST NOT LEAVE THE TASK SAYING 「执行中」. The status was
@@ -1474,6 +1621,7 @@ export class ProjectService {
1474
1621
  // that does not get lighter.
1475
1622
  if (!t.evidenceRefs.length)
1476
1623
  throw new Error("交付必须附上产物或验证证据");
1624
+ this.publishContext(p, input.sharedContext, actor);
1477
1625
  if (lightweight(p)) {
1478
1626
  /* THE DELIVERY IS ACCEPTED ON THE EXECUTOR'S OWN EVIDENCE. There is no reviewer session to
1479
1627
  send it to, so the acceptance is written down here - with the flag that says there was
@@ -1483,6 +1631,7 @@ export class ProjectService {
1483
1631
  t.updatedAt = stamp();
1484
1632
  t.review = { verdict: "accepted", summary: "轻量项目:执行者自评交付,未做独立复核", evidenceRefs,
1485
1633
  reviewerConversationId: t.ownerConversationId, createdAt: stamp(), lightweight: true };
1634
+ this.syncDeliveryContext(p, t, actor);
1486
1635
  this.event(p, "submitted", `轻量交付完成:${t.title}`, t.id, actor);
1487
1636
  this.reconcile(p);
1488
1637
  return ProjectService.taskView(t, p);
@@ -1490,6 +1639,7 @@ export class ProjectService {
1490
1639
  t.status = "awaiting_review";
1491
1640
  t.updatedAt = stamp();
1492
1641
  delete t.review;
1642
+ this.syncDeliveryContext(p, t, actor);
1493
1643
  this.event(p, "submitted", `交付待独立复核:${t.title}`, t.id, actor);
1494
1644
  this.reconcile(p);
1495
1645
  return ProjectService.taskView(t, p);
@@ -1523,7 +1673,7 @@ export class ProjectService {
1523
1673
  throw new Error("复核会话正在执行");
1524
1674
  this.event(p, "review_requested", `启动独立复核:${t.title}`, t.id, actor);
1525
1675
  await this.store.setProject(p);
1526
- await this.orchestrator.dispatch(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 });
1676
+ 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
1677
  return ProjectService.taskView(t, p);
1528
1678
  });
1529
1679
  }
@@ -1543,6 +1693,7 @@ export class ProjectService {
1543
1693
  t.review = { verdict: input.verdict, summary: text(input.summary, "复核意见"), evidenceRefs, reviewerConversationId: actor, createdAt: stamp() };
1544
1694
  t.status = input.verdict === "accepted" ? "completed" : "ready";
1545
1695
  t.updatedAt = stamp();
1696
+ this.syncDeliveryContext(p, t, actor);
1546
1697
  this.event(p, "reviewed", `${input.verdict === "accepted" ? "验收通过" : "退回返工"}:${t.title};${t.review.summary}`, t.id, actor);
1547
1698
  this.reconcile(p);
1548
1699
  return ProjectService.taskView(t, p);
@@ -1556,6 +1707,11 @@ export class ProjectService {
1556
1707
  const manager = this.manager(p, t);
1557
1708
  if (actor && actor !== manager && actor !== t.ownerConversationId)
1558
1709
  throw new Error("无权更新此任务");
1710
+ if (patch.ownedPaths !== undefined || patch.readOnly !== undefined || patch.handoffNote !== undefined) {
1711
+ if (t.status === "in_progress" || t.status === "awaiting_review")
1712
+ throw new Error("执行或复核期间不能修改分工范围,请通过共享条目补充发现");
1713
+ Object.assign(t, this.taskCoordination({ ownedPaths: patch.ownedPaths, readOnly: patch.readOnly, handoffNote: patch.handoffNote }));
1714
+ }
1559
1715
  if (patch.status !== undefined) {
1560
1716
  if (patch.status === "in_progress" && !dependenciesComplete(p, t))
1561
1717
  throw new Error("任务的前置依赖尚未全部完成,不能开始执行");
@@ -1740,6 +1896,7 @@ export class ProjectService {
1740
1896
  const report = { id: randomUUID(), projectId: id, taskId: t?.id, authorConversationId: actor, kind: input.kind,
1741
1897
  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
1898
  decisionNeeded: optional(input.decisionNeeded, "所需决策"), evidenceRefs: strings(input.evidenceRefs, "证据"), createdAt: stamp() };
1899
+ this.publishContext(p, input.sharedContext, actor);
1743
1900
  p.reports.push(report);
1744
1901
  if (report.kind === "blocked") {
1745
1902
  if (t) {
@@ -1988,6 +2145,7 @@ export class ProjectService {
1988
2145
  acceptanceCriteria: record.acceptanceCriteria === undefined ? undefined : strings(record.acceptanceCriteria, "任务验收标准"),
1989
2146
  priority: priority,
1990
2147
  dependencies: record.dependencies === undefined ? [] : strings(record.dependencies, "任务依赖"),
2148
+ ...this.taskCoordination(record),
1991
2149
  };
1992
2150
  });
1993
2151
  const index = new Map();
@@ -2026,6 +2184,7 @@ export class ProjectService {
2026
2184
  const dependencies = item.dependencies.map((dependency) => ids.get(dependency));
2027
2185
  const task = await this.addTask(projectId, {
2028
2186
  title: item.title, objective: item.objective,
2187
+ ...this.taskCoordination(item),
2029
2188
  ...(item.deliverables ? { deliverables: item.deliverables } : {}),
2030
2189
  ...(item.acceptanceCriteria ? { acceptanceCriteria: item.acceptanceCriteria } : {}),
2031
2190
  ...(item.priority !== undefined ? { priority: item.priority } : {}),
@@ -2076,7 +2235,7 @@ export class ProjectService {
2076
2235
  }
2077
2236
  if (!this.orchestrator)
2078
2237
  throw new Error("会话编排服务未就绪");
2079
- await this.orchestrator.dispatch(target, message, { wait: false });
2238
+ await this.dispatchContext(target, message, { wait: false });
2080
2239
  return { ok: true, conversationId: target, delivered: true };
2081
2240
  }
2082
2241
  async tool(body, workspaceId, actor) {
@@ -2128,6 +2287,8 @@ export class ProjectService {
2128
2287
  // and "the workspace has fifty and I was shown twenty".
2129
2288
  return this.listForActor(workspaceId, actor);
2130
2289
  }
2290
+ if (body.action === "get_context")
2291
+ return this.getContext(typeof body.projectId === "string" ? body.projectId : undefined, workspaceId, actor, typeof body.taskId === "string" ? body.taskId : undefined, body.contextIds);
2131
2292
  const id = text(body.projectId, "projectId");
2132
2293
  const rawProject = this.raw(id, workspaceId);
2133
2294
  this.member(rawProject, actor);
@@ -2136,7 +2297,35 @@ export class ProjectService {
2136
2297
  case "export": return this.exportReport(id, workspaceId);
2137
2298
  case "start": return this.start(id, workspaceId, actor);
2138
2299
  case "add_task": return this.addTask(id, body, workspaceId, actor);
2139
- case "dispatch": return this.dispatchTask(id, text(body.taskId, "taskId"), workspaceId, actor);
2300
+ case "share_context": return this.shareContext(id, body.sharedContext, workspaceId, actor);
2301
+ case "message": {
2302
+ this.manager(rawProject, this.task(rawProject, text(body.taskId, "taskId")), actor);
2303
+ if (body.sharedContext !== undefined)
2304
+ await this.shareContext(id, body.sharedContext, workspaceId, actor);
2305
+ return this.messageTask(id, text(body.taskId, "taskId"), text(body.content, "content"), workspaceId, actor, typeof body.targetConversationId === "string" ? body.targetConversationId : undefined, body.deliveryMode);
2306
+ }
2307
+ case "dispatch": {
2308
+ if (body.sharedContext !== undefined)
2309
+ await this.shareContext(id, body.sharedContext, workspaceId, actor);
2310
+ if (body.taskIds === undefined) {
2311
+ const taskId = text(body.taskId, "taskId");
2312
+ if (body.handoffNote !== undefined)
2313
+ await this.updateTask(id, taskId, { workspaceId, handoffNote: body.handoffNote }, actor);
2314
+ return this.dispatchReceipt(await this.dispatchTask(id, taskId, workspaceId, actor));
2315
+ }
2316
+ if (!Array.isArray(body.taskIds) || !body.taskIds.length || body.taskIds.length > 32 || body.taskIds.some(taskId => typeof taskId !== "string"))
2317
+ throw new Error("taskIds 须为 1–32 项任务 id 数组");
2318
+ const started = [], failed = [];
2319
+ for (const taskId of [...new Set(body.taskIds)]) {
2320
+ try {
2321
+ started.push(await this.dispatchTask(id, taskId, workspaceId, actor));
2322
+ }
2323
+ catch (error) {
2324
+ failed.push({ taskId, error: error instanceof Error ? error.message : String(error) });
2325
+ }
2326
+ }
2327
+ return { ok: failed.length === 0, partial: failed.length > 0 && started.length > 0, started: started.map(task => this.dispatchReceipt(task)), failed };
2328
+ }
2140
2329
  case "submit": return this.submit(id, text(body.taskId, "taskId"), body, workspaceId, actor);
2141
2330
  case "request_review": return this.requestReview(id, text(body.taskId, "taskId"), workspaceId, actor);
2142
2331
  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
- await assertSessionCwdInsideWorkspace(workspace.path, options.cwd);
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
- const prompt = options.initialPrompt ?? options.task;
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;