@evandu/super-pi 0.1.187 → 0.1.189
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 +129 -0
- package/agents/super-pi-task/index.ts +58 -3
- package/dist/client/.super-pi-client-sources.json +1 -1
- package/dist/server/agents.d.ts +1 -1
- package/dist/server/agents.js +1 -1
- package/dist/server/application/project-service.d.ts +25 -0
- package/dist/server/application/project-service.js +75 -0
- package/dist/server/application/session-orchestrator-service.js +8 -0
- package/dist/server/application/session-reminder-service.d.ts +55 -0
- package/dist/server/application/session-reminder-service.js +121 -0
- package/dist/server/conversation-usage.js +2 -2
- package/dist/server/http-server.js +111 -4
- package/dist/server/index.js +3 -0
- package/dist/server/json-comments.d.ts +14 -0
- package/dist/server/json-comments.js +71 -0
- package/dist/server/model-context-window.d.ts +34 -0
- package/dist/server/model-context-window.js +76 -0
- package/dist/server/models-store.d.ts +36 -0
- package/dist/server/models-store.js +132 -0
- package/dist/server/pi-session.js +3 -2
- package/dist/server/providers.js +10 -2
- package/dist/server/runtime.js +6 -2
- package/dist/server/server-context.d.ts +1 -0
- package/dist/server/task-tool.d.ts +3 -0
- package/dist/server/task-tool.js +12 -0
- package/package.json +1 -1
|
@@ -1165,6 +1165,7 @@ export const SESSION_STOP_TOOL_NAME = "session_stop";
|
|
|
1165
1165
|
export const SESSION_REPORT_TOOL_NAME = "session_report";
|
|
1166
1166
|
export const SESSION_STOP_SUBTREE_TOOL_NAME = "session_stop_subtree";
|
|
1167
1167
|
export const SESSION_REMOVE_TOOL_NAME = "session_remove";
|
|
1168
|
+
export const SESSION_REMINDER_TOOL_NAME = "session_reminder";
|
|
1168
1169
|
|
|
1169
1170
|
/** Model-facing description for session_spawn. */
|
|
1170
1171
|
export const SESSION_SPAWN_DESCRIPTION = `Create a child conversation in the current workspace and immediately dispatch its initial task. You can specify a primary agent as the child's role.
|
|
@@ -1298,6 +1299,134 @@ Usage notes:
|
|
|
1298
1299
|
4. Only your DIRECT child can be targeted (top-level user sessions and non-direct-child sessions are refused). Deleting a direct child that has subordinates destroys that whole branch together.
|
|
1299
1300
|
5. Destroying a session that is already gone is idempotent and succeeds without error.`;
|
|
1300
1301
|
|
|
1302
|
+
/**
|
|
1303
|
+
* Model-facing description for session_reminder.
|
|
1304
|
+
*
|
|
1305
|
+
* THE COPY IN `src/server/task-tool.ts` MUST BE THE SAME STRING. The two files are loaded by two
|
|
1306
|
+
* different module systems, so the text is written out twice and `scripts/session-reminder-pmo-rights.test.mjs`
|
|
1307
|
+
* asserts the two copies agree - exactly the wire rule every other tool on this extension follows.
|
|
1308
|
+
*/
|
|
1309
|
+
export const SESSION_REMINDER_DESCRIPTION = `Set an in-session timer that delivers a reminder note back to THIS conversation after a given number of seconds. Multiple reminders can run in parallel, and pending reminders can be cancelled or listed.
|
|
1310
|
+
|
|
1311
|
+
WHEN TO USE THIS:
|
|
1312
|
+
- Self-reminders and time-based checkpoints (e.g. "Check child session progress in 60 seconds", "Review test run in 120 seconds").
|
|
1313
|
+
- Unlike scheduled_task which runs in a separate independent conversation, session_reminder sends the note back to THIS EXACT conversation as a new turn so you can follow up directly.
|
|
1314
|
+
|
|
1315
|
+
Actions:
|
|
1316
|
+
- "create" (default): Schedule a reminder. Requires delaySeconds (or seconds) and note. Returns reminderId.
|
|
1317
|
+
- "cancel": Cancel a pending reminder. Requires reminderId.
|
|
1318
|
+
- "list": List all active pending reminders for this conversation.`;
|
|
1319
|
+
|
|
1320
|
+
/** The parameters `session_reminder` accepts. The action is optional and defaults to "create". */
|
|
1321
|
+
export type SessionReminderParams = {
|
|
1322
|
+
action?: "create" | "cancel" | "list";
|
|
1323
|
+
delaySeconds?: number;
|
|
1324
|
+
seconds?: number;
|
|
1325
|
+
note?: string;
|
|
1326
|
+
reminderId?: string;
|
|
1327
|
+
};
|
|
1328
|
+
|
|
1329
|
+
/**
|
|
1330
|
+
* Execute session_reminder: set, cancel or list this conversation's own reminders.
|
|
1331
|
+
*
|
|
1332
|
+
* THE REMINDER COMES BACK HERE, NOT SOMEWHERE ELSE. The note is delivered to the CALLING
|
|
1333
|
+
* conversation - the one whose capability this call carries - because a reminder that landed in
|
|
1334
|
+
* another session would be a message nobody is waiting for.
|
|
1335
|
+
*/
|
|
1336
|
+
export async function executeSessionReminder(
|
|
1337
|
+
params: SessionReminderParams,
|
|
1338
|
+
config: OrchestratorToolConfig,
|
|
1339
|
+
deps: { signal?: AbortSignal; fetch?: TaskFetch } = {},
|
|
1340
|
+
): Promise<TaskToolResult> {
|
|
1341
|
+
const text = (body: string, isError?: boolean): TaskToolResult => ({
|
|
1342
|
+
content: [{ type: "text", text: body }],
|
|
1343
|
+
details: undefined,
|
|
1344
|
+
...(isError ? { isError: true } : {}),
|
|
1345
|
+
});
|
|
1346
|
+
|
|
1347
|
+
if (!config.endpoint) {
|
|
1348
|
+
return text("The session_reminder tool is not available in this session: SUPER_PI_ORCHESTRATOR_ENDPOINT is not set.", true);
|
|
1349
|
+
}
|
|
1350
|
+
|
|
1351
|
+
const action = (params.action ?? "create").trim();
|
|
1352
|
+
if (action !== "create" && action !== "cancel" && action !== "list") {
|
|
1353
|
+
return text(`Unknown session_reminder action "${action}". Use "create", "cancel" or "list".`, true);
|
|
1354
|
+
}
|
|
1355
|
+
|
|
1356
|
+
const body: Record<string, unknown> = {
|
|
1357
|
+
action: "reminder",
|
|
1358
|
+
subaction: action,
|
|
1359
|
+
callerConversationId: config.conversationId || undefined,
|
|
1360
|
+
capability: config.capability,
|
|
1361
|
+
};
|
|
1362
|
+
|
|
1363
|
+
if (action === "create") {
|
|
1364
|
+
const delaySeconds = Number(params.delaySeconds ?? params.seconds);
|
|
1365
|
+
if (!Number.isFinite(delaySeconds) || delaySeconds <= 0) {
|
|
1366
|
+
return text("A reminder needs a positive delay: pass delaySeconds (or seconds).", true);
|
|
1367
|
+
}
|
|
1368
|
+
const note = typeof params.note === "string" ? params.note.trim() : "";
|
|
1369
|
+
if (!note) {
|
|
1370
|
+
return text("A reminder needs a note: say what should be delivered back into this conversation.", true);
|
|
1371
|
+
}
|
|
1372
|
+
body.delaySeconds = delaySeconds;
|
|
1373
|
+
body.note = note;
|
|
1374
|
+
} else if (action === "cancel") {
|
|
1375
|
+
const reminderId = typeof params.reminderId === "string" ? params.reminderId.trim() : "";
|
|
1376
|
+
if (!reminderId) {
|
|
1377
|
+
return text("Cancelling a reminder needs its reminderId. Call session_reminder(action=list) to see the pending ones.", true);
|
|
1378
|
+
}
|
|
1379
|
+
body.reminderId = reminderId;
|
|
1380
|
+
}
|
|
1381
|
+
|
|
1382
|
+
const send = deps.fetch ?? (globalFetch as unknown as TaskFetch);
|
|
1383
|
+
try {
|
|
1384
|
+
const response = await send(config.endpoint, {
|
|
1385
|
+
method: "POST",
|
|
1386
|
+
headers: {
|
|
1387
|
+
"content-type": "application/json",
|
|
1388
|
+
...(config.token ? { authorization: `Bearer ${config.token}` } : {}),
|
|
1389
|
+
},
|
|
1390
|
+
body: JSON.stringify(body),
|
|
1391
|
+
...(deps.signal ? { signal: deps.signal } : {}),
|
|
1392
|
+
});
|
|
1393
|
+
|
|
1394
|
+
const bodyText = await response.text();
|
|
1395
|
+
let payload: {
|
|
1396
|
+
ok?: boolean;
|
|
1397
|
+
error?: string;
|
|
1398
|
+
reminderId?: string;
|
|
1399
|
+
delaySeconds?: number;
|
|
1400
|
+
note?: string;
|
|
1401
|
+
reminders?: { reminderId: string; note: string; delaySeconds: number }[];
|
|
1402
|
+
};
|
|
1403
|
+
try {
|
|
1404
|
+
payload = JSON.parse(bodyText);
|
|
1405
|
+
} catch {
|
|
1406
|
+
return text(`The orchestrator endpoint returned HTTP ${response.status}: ${bodyText}`, true);
|
|
1407
|
+
}
|
|
1408
|
+
|
|
1409
|
+
if (!response.ok || !payload.ok) {
|
|
1410
|
+
return text(`The reminder could not be handled: ${payload.error ?? `HTTP ${response.status}`}`, true);
|
|
1411
|
+
}
|
|
1412
|
+
|
|
1413
|
+
if (action === "create") {
|
|
1414
|
+
return text(`Reminder ${payload.reminderId} is set for ${payload.delaySeconds}s from now; it will be delivered back into THIS conversation.`);
|
|
1415
|
+
}
|
|
1416
|
+
if (action === "cancel") {
|
|
1417
|
+
return text(`Reminder ${String(params.reminderId).trim()} was cancelled; it will not fire.`);
|
|
1418
|
+
}
|
|
1419
|
+
const reminders = payload.reminders ?? [];
|
|
1420
|
+
if (!reminders.length) return text("This conversation has no pending reminders.");
|
|
1421
|
+
return text([
|
|
1422
|
+
`${reminders.length} pending reminder(s) in this conversation:`,
|
|
1423
|
+
...reminders.map((reminder) => `- ${reminder.reminderId} in ${reminder.delaySeconds}s: ${reminder.note}`),
|
|
1424
|
+
].join("\n"));
|
|
1425
|
+
} catch (error) {
|
|
1426
|
+
return text(`session_reminder network error: ${error instanceof Error ? error.message : String(error)}`, true);
|
|
1427
|
+
}
|
|
1428
|
+
}
|
|
1429
|
+
|
|
1301
1430
|
/** Compact summary returned for an orchestrated session. */
|
|
1302
1431
|
export type OrchestratorSessionSummary = {
|
|
1303
1432
|
conversationId: string;
|
|
@@ -45,6 +45,7 @@ import {
|
|
|
45
45
|
SESSION_REPORT_TOOL_NAME,
|
|
46
46
|
SESSION_STOP_SUBTREE_TOOL_NAME,
|
|
47
47
|
SESSION_REMOVE_TOOL_NAME,
|
|
48
|
+
SESSION_REMINDER_TOOL_NAME,
|
|
48
49
|
SESSION_SPAWN_DESCRIPTION,
|
|
49
50
|
SESSION_STATUS_DESCRIPTION,
|
|
50
51
|
SESSION_DISPATCH_DESCRIPTION,
|
|
@@ -52,6 +53,7 @@ import {
|
|
|
52
53
|
SESSION_REPORT_DESCRIPTION,
|
|
53
54
|
SESSION_STOP_SUBTREE_DESCRIPTION,
|
|
54
55
|
SESSION_REMOVE_DESCRIPTION,
|
|
56
|
+
SESSION_REMINDER_DESCRIPTION,
|
|
55
57
|
executeSessionSpawn,
|
|
56
58
|
executeSessionStatus,
|
|
57
59
|
executeSessionDispatch,
|
|
@@ -59,6 +61,7 @@ import {
|
|
|
59
61
|
executeSessionReport,
|
|
60
62
|
executeSessionStopSubtree,
|
|
61
63
|
executeSessionRemove,
|
|
64
|
+
executeSessionReminder,
|
|
62
65
|
readOrchestratorConfig,
|
|
63
66
|
type SessionSpawnParams,
|
|
64
67
|
type SessionStatusParams,
|
|
@@ -67,6 +70,7 @@ import {
|
|
|
67
70
|
type SessionReportParams,
|
|
68
71
|
type SessionStopSubtreeParams,
|
|
69
72
|
type SessionRemoveParams,
|
|
73
|
+
type SessionReminderParams,
|
|
70
74
|
} from "./core.ts";
|
|
71
75
|
|
|
72
76
|
/**
|
|
@@ -309,11 +313,11 @@ const extension = (pi: ExtensionApi): void => {
|
|
|
309
313
|
pi.registerTool({
|
|
310
314
|
name: PROJECT_TOOL_NAME, label: "Project", description: PROJECT_DESCRIPTION,
|
|
311
315
|
parameters: Type.Object({
|
|
312
|
-
action: Type.Union(["create", "start", "get", "list", "add_task", "dispatch", "submit", "request_review", "review", "update_task", "report", "escalate", "resolve_escalation", "complete", "cancel", "export"].map((value) => Type.Literal(value))),
|
|
316
|
+
action: Type.Union(["create", "start", "get", "list", "add_task", "dispatch", "submit", "request_review", "review", "update_task", "report", "escalate", "resolve_escalation", "correct", "complete", "cancel", "export"].map((value) => Type.Literal(value))),
|
|
313
317
|
projectId: Type.Optional(Type.String()), taskId: Type.Optional(Type.String()),
|
|
314
318
|
parentTaskId: Type.Optional(Type.String()), role: Type.Optional(Type.Union([Type.Literal("leader"), Type.Literal("executor")])),
|
|
315
|
-
title: Type.Optional(Type.String({ description: "Required for action=\"create\" (and add_task): short project or task title." })),
|
|
316
|
-
objective: Type.Optional(Type.String({ description: "Required for action=\"create\" (and add_task): what the project or task should achieve." })),
|
|
319
|
+
title: Type.Optional(Type.String({ description: "Required for action=\"create\" (and add_task): short project or task title. For action=\"create\" this and objective are the ONLY two fields you must send; every other field may be omitted." })),
|
|
320
|
+
objective: Type.Optional(Type.String({ description: "Required for action=\"create\" (and add_task): what the project or task should achieve. For action=\"create\" this and title are the ONLY two fields you must send." })),
|
|
317
321
|
deliverables: Type.Optional(Type.Array(Type.String(), { description: "Optional deliverables list. Omit if not needed; does not block starting." })),
|
|
318
322
|
acceptanceCriteria: Type.Optional(Type.Array(Type.String(), { description: "Optional acceptance criteria list. Omit if not needed; does not block starting." })),
|
|
319
323
|
constraints: Type.Optional(Type.Array(Type.String(), { description: "Optional constraints list. Omit if not needed; does not block starting." })),
|
|
@@ -331,6 +335,8 @@ const extension = (pi: ExtensionApi): void => {
|
|
|
331
335
|
risks: Type.Optional(Type.Array(Type.String())), decisionNeeded: Type.Optional(Type.String()), reason: Type.Optional(Type.String()), severity: Type.Optional(Type.String()),
|
|
332
336
|
escalationId: Type.Optional(Type.String({ description: "The id of the escalation to answer - take it from the escalations array that project(action=get) returns. Required for resolve_escalation" })),
|
|
333
337
|
decision: Type.Optional(Type.String({ description: "Your handling note on that escalation: what you decided and why. Required for resolve_escalation" })),
|
|
338
|
+
targetConversationId: Type.Optional(Type.String({ description: "For action=\"correct\": the project member session that receives the message. It must be inside this project's tree - a session outside it is refused." })),
|
|
339
|
+
content: Type.Optional(Type.String({ description: "For action=\"correct\": the one message sent to that member session, in its own words. Required for correct." })),
|
|
334
340
|
defaultLeaderProfile: Type.Optional(Type.Object({
|
|
335
341
|
agentId: Type.Optional(Type.String()), cwd: Type.Optional(Type.String()),
|
|
336
342
|
model: Type.Optional(Type.Object({ provider: Type.String(), modelId: Type.String() })),
|
|
@@ -647,6 +653,37 @@ const extension = (pi: ExtensionApi): void => {
|
|
|
647
653
|
})),
|
|
648
654
|
});
|
|
649
655
|
|
|
656
|
+
/**
|
|
657
|
+
* The `session_reminder` parameter schema.
|
|
658
|
+
*
|
|
659
|
+
* `action` is optional and defaults to "create", because setting a reminder is what the tool is
|
|
660
|
+
* for and a model that only means "remind me later" should not have to spell the action out.
|
|
661
|
+
* `delaySeconds` and `seconds` are the same field under two spellings, and BOTH are accepted:
|
|
662
|
+
* a model that reaches for `seconds` is not wrong, and refusing it would only teach it to
|
|
663
|
+
* retry with a different word.
|
|
664
|
+
*/
|
|
665
|
+
const SessionReminderParameters = Type.Object({
|
|
666
|
+
action: Type.Optional(Type.Union([
|
|
667
|
+
Type.Literal("create", { description: "Set a new reminder for this conversation (default)" }),
|
|
668
|
+
Type.Literal("cancel", { description: "Cancel a pending reminder - needs its reminderId" }),
|
|
669
|
+
Type.Literal("list", { description: "List this conversation's pending reminders" }),
|
|
670
|
+
], {
|
|
671
|
+
description: "What to do: 'create' (default), 'cancel' or 'list'.",
|
|
672
|
+
})),
|
|
673
|
+
delaySeconds: Type.Optional(Type.Number({
|
|
674
|
+
description: "How many seconds from now the reminder fires. Must be positive.",
|
|
675
|
+
})),
|
|
676
|
+
seconds: Type.Optional(Type.Number({
|
|
677
|
+
description: "The same as delaySeconds - accepted because models spell it both ways.",
|
|
678
|
+
})),
|
|
679
|
+
note: Type.Optional(Type.String({
|
|
680
|
+
description: "The reminder text, delivered back into THIS conversation when it fires. Required for create.",
|
|
681
|
+
})),
|
|
682
|
+
reminderId: Type.Optional(Type.String({
|
|
683
|
+
description: "The reminder's id, as returned by create or listed by list. Required for cancel.",
|
|
684
|
+
})),
|
|
685
|
+
});
|
|
686
|
+
|
|
650
687
|
if (orchestratorConfig.endpoint) {
|
|
651
688
|
pi.registerTool({
|
|
652
689
|
name: SESSION_SPAWN_TOOL_NAME,
|
|
@@ -733,6 +770,24 @@ const extension = (pi: ExtensionApi): void => {
|
|
|
733
770
|
execute: async (_toolCallId, params, signal) =>
|
|
734
771
|
await executeSessionRemove(params as SessionRemoveParams, orchestratorConfig, { signal: signal ?? undefined }),
|
|
735
772
|
});
|
|
773
|
+
|
|
774
|
+
/**
|
|
775
|
+
* `session_reminder`, registered AFTER the tools that act on OTHER SESSIONS.
|
|
776
|
+
*
|
|
777
|
+
* The order is the reading order, and this one is the odd one out: every tool above it reaches
|
|
778
|
+
* OUT to somebody else's session, while this one turns the clock on THIS conversation. A model
|
|
779
|
+
* reading the list top to bottom meets the manager's instruments first and its own timer last,
|
|
780
|
+
* which is the order the relationship actually has.
|
|
781
|
+
*/
|
|
782
|
+
pi.registerTool({
|
|
783
|
+
name: SESSION_REMINDER_TOOL_NAME,
|
|
784
|
+
label: "Session Reminder",
|
|
785
|
+
description: SESSION_REMINDER_DESCRIPTION,
|
|
786
|
+
promptSnippet: "set a timer that delivers a note back into THIS conversation when it fires",
|
|
787
|
+
parameters: SessionReminderParameters,
|
|
788
|
+
execute: async (_toolCallId, params, signal) =>
|
|
789
|
+
await executeSessionReminder(params as SessionReminderParams, orchestratorConfig, { signal: signal ?? undefined }),
|
|
790
|
+
});
|
|
736
791
|
}
|
|
737
792
|
};
|
|
738
793
|
|
|
@@ -40,5 +40,5 @@
|
|
|
40
40
|
"src/client/types.ts": "ef0586e206d0f229ed0e81e72397e1ddfd82c00ae7133d06d20892605e6f1ff4",
|
|
41
41
|
"src/client/vite-env.d.ts": "65996936fbb042915f7b74a200fcdde7e410f32a669b1ab9597cfaa4b0faddb5"
|
|
42
42
|
},
|
|
43
|
-
"recordedAt": "2026-11-
|
|
43
|
+
"recordedAt": "2026-11-11T17:07:45.892Z"
|
|
44
44
|
}
|
package/dist/server/agents.d.ts
CHANGED
|
@@ -38,7 +38,7 @@ type Frontmatter = Record<string, unknown>;
|
|
|
38
38
|
*/
|
|
39
39
|
export declare const PI_TOOL_NAMES: readonly ["read", "bash", "powershell", "edit", "write", "grep", "find", "ls", "codemode", "tool_search", "list_mcp_resources", "list_mcp_resource_templates", "read_mcp_resource"];
|
|
40
40
|
/** Tools shipped by this package. Authors must be able to explicitly deny host extras. */
|
|
41
|
-
export declare const SUPER_PI_TOOL_NAMES: readonly ["task", "todowrite", "workflow", "run_async", "scheduled_task", "project", "question", "tool_register", "memory", "skill_manage", "session_search", "session_spawn", "session_status", "session_dispatch", "session_stop", "session_report", "session_stop_subtree", "session_remove", "knowledge_search", "knowledge_import", "document_read", "document_write", "web_search", "web_fetch", "feishu_doc_read", "feishu_doc_write"];
|
|
41
|
+
export declare const SUPER_PI_TOOL_NAMES: readonly ["task", "todowrite", "workflow", "run_async", "scheduled_task", "project", "question", "tool_register", "memory", "skill_manage", "session_search", "session_spawn", "session_status", "session_dispatch", "session_stop", "session_report", "session_stop_subtree", "session_remove", "session_reminder", "knowledge_search", "knowledge_import", "document_read", "document_write", "web_search", "web_fetch", "feishu_doc_read", "feishu_doc_write"];
|
|
42
42
|
/**
|
|
43
43
|
* Whether a name can be a real Pi tool. A name is real if it is one of `PI_TOOL_NAMES`, an MCP
|
|
44
44
|
* server tool, or a PATTERN.
|
package/dist/server/agents.js
CHANGED
|
@@ -41,7 +41,7 @@ export const PI_TOOL_NAMES = [
|
|
|
41
41
|
export const SUPER_PI_TOOL_NAMES = [
|
|
42
42
|
"task", "todowrite", "workflow", "run_async", "scheduled_task", "project", "question", "tool_register",
|
|
43
43
|
"memory", "skill_manage", "session_search",
|
|
44
|
-
"session_spawn", "session_status", "session_dispatch", "session_stop", "session_report", "session_stop_subtree", "session_remove",
|
|
44
|
+
"session_spawn", "session_status", "session_dispatch", "session_stop", "session_report", "session_stop_subtree", "session_remove", "session_reminder",
|
|
45
45
|
"knowledge_search", "knowledge_import",
|
|
46
46
|
"document_read", "document_write", "web_search", "web_fetch", "feishu_doc_read", "feishu_doc_write",
|
|
47
47
|
];
|
|
@@ -360,5 +360,30 @@ export declare class ProjectService {
|
|
|
360
360
|
*/
|
|
361
361
|
private planTopLevelTasks;
|
|
362
362
|
private registerTopLevelTasks;
|
|
363
|
+
/**
|
|
364
|
+
* THE INITIATOR'S LIMITED CORRECTION RIGHT.
|
|
365
|
+
*
|
|
366
|
+
* The person who opened the project gets exactly two things the Leader's chain does not give
|
|
367
|
+
* them: READ-ONLY SUPERVISION of the whole project (the project's own read surface already
|
|
368
|
+
* shows every member's status to every member), and ONE message to any session inside the
|
|
369
|
+
* project tree - a single correction, delivered to that session directly, without having to go
|
|
370
|
+
* through the Leader and wait for it to be relayed.
|
|
371
|
+
*
|
|
372
|
+
* WHY IT IS BOUNDED BY THREE RULES, AND NOT BY "THE INITIATOR CAN DO WHATEVER":
|
|
373
|
+
*
|
|
374
|
+
* 1. ONLY THE INITIATOR. Every other session in the project keeps the reporting line: a member
|
|
375
|
+
* still reaches its direct supervisor, and the Leader still answers to the initiator. If every
|
|
376
|
+
* member could correct every other member, the tree would stop being a tree.
|
|
377
|
+
* 2. ONLY INSIDE THE PROJECT TREE. The target must be one of this project's sessions - the
|
|
378
|
+
* Leader, a branch Leader, a worker, a reviewer. A session that is not in this project is
|
|
379
|
+
* somebody else's department, and this right says nothing about it.
|
|
380
|
+
* 3. ONE MESSAGE, NOT A CHANNEL. This sends a message; it does not open a line. The reporting
|
|
381
|
+
* line, the escalation path and the parent's dispatch rules are untouched by it.
|
|
382
|
+
*/
|
|
383
|
+
correctMember(id: string, targetConversationId: string, content: string, workspaceId: string, actor?: string): Promise<{
|
|
384
|
+
ok: true;
|
|
385
|
+
conversationId: string;
|
|
386
|
+
delivered: true;
|
|
387
|
+
}>;
|
|
363
388
|
tool(body: Record<string, any>, workspaceId: string, actor: string): Promise<unknown>;
|
|
364
389
|
}
|
|
@@ -1245,6 +1245,14 @@ export class ProjectService {
|
|
|
1245
1245
|
...(effective?.thinkingLevel ? { thinkingLevel: effective.thinkingLevel } : {}),
|
|
1246
1246
|
...(effective?.watchdogTimeoutSeconds ? { watchdogTimeoutSeconds: effective.watchdogTimeoutSeconds } : {}),
|
|
1247
1247
|
})).conversationId;
|
|
1248
|
+
// A LEADER WITHOUT A PROFILE LANDS ON THE WORKSPACE DEFAULT, AND THAT IS NOT A DECISION.
|
|
1249
|
+
// The default agent is whatever the workspace happens to run - it may well be another PMO,
|
|
1250
|
+
// which is how a project's leader became "one more pmo" once. The silent part was the
|
|
1251
|
+
// problem: the project looked started and the timeline never said what the leader is.
|
|
1252
|
+
// So the fallback is written down, where the people reading the project can see it.
|
|
1253
|
+
if (!effective?.agentId) {
|
|
1254
|
+
this.event(p, "leader-profile-missing", "未指定 Leader 的 agentId,负责人会话落在工作区默认 agent 上;请用 defaultLeaderProfile 明确指定", undefined, actor);
|
|
1255
|
+
}
|
|
1248
1256
|
}
|
|
1249
1257
|
for (const task of p.tasks) {
|
|
1250
1258
|
if (!task.parentTaskId && (!task.accountableConversationId || task.accountableConversationId === p.initiatorConversationId)) {
|
|
@@ -1386,6 +1394,14 @@ export class ProjectService {
|
|
|
1386
1394
|
/* THE MOMENT THE TASK WENT OUT IS WRITTEN DOWN. It is what tells a session that died BEFORE
|
|
1387
1395
|
this dispatch from one that died AFTER it: only the second one interrupted the task, and
|
|
1388
1396
|
only the second one may turn it into 「已中断」. */
|
|
1397
|
+
/* THE STATUS IS CHECKED AGAIN AT THE MOMENT OF THE WRITE, and it is checked against the
|
|
1398
|
+
STORE, not against the snapshot this operation started with. The spawn above is an await:
|
|
1399
|
+
while it was in flight the project could have been closed - every task delivered, the
|
|
1400
|
+
reconcile marked it done - and a dispatch that writes into a closed project is a duplicate
|
|
1401
|
+
delivery, not a delivery. The door check is not enough, because the door and the write are
|
|
1402
|
+
separated by exactly the length of a spawn, and the object in hand is the state from the
|
|
1403
|
+
door. So the fresh copy is read here, and the refusal happens before anything is written. */
|
|
1404
|
+
this.live(this.raw(id, workspaceId));
|
|
1389
1405
|
t.status = "in_progress";
|
|
1390
1406
|
t.updatedAt = stamp();
|
|
1391
1407
|
t.dispatchedAt = t.updatedAt;
|
|
@@ -2005,6 +2021,51 @@ export class ProjectService {
|
|
|
2005
2021
|
ids.set(item.title, task.id);
|
|
2006
2022
|
}
|
|
2007
2023
|
}
|
|
2024
|
+
/**
|
|
2025
|
+
* THE INITIATOR'S LIMITED CORRECTION RIGHT.
|
|
2026
|
+
*
|
|
2027
|
+
* The person who opened the project gets exactly two things the Leader's chain does not give
|
|
2028
|
+
* them: READ-ONLY SUPERVISION of the whole project (the project's own read surface already
|
|
2029
|
+
* shows every member's status to every member), and ONE message to any session inside the
|
|
2030
|
+
* project tree - a single correction, delivered to that session directly, without having to go
|
|
2031
|
+
* through the Leader and wait for it to be relayed.
|
|
2032
|
+
*
|
|
2033
|
+
* WHY IT IS BOUNDED BY THREE RULES, AND NOT BY "THE INITIATOR CAN DO WHATEVER":
|
|
2034
|
+
*
|
|
2035
|
+
* 1. ONLY THE INITIATOR. Every other session in the project keeps the reporting line: a member
|
|
2036
|
+
* still reaches its direct supervisor, and the Leader still answers to the initiator. If every
|
|
2037
|
+
* member could correct every other member, the tree would stop being a tree.
|
|
2038
|
+
* 2. ONLY INSIDE THE PROJECT TREE. The target must be one of this project's sessions - the
|
|
2039
|
+
* Leader, a branch Leader, a worker, a reviewer. A session that is not in this project is
|
|
2040
|
+
* somebody else's department, and this right says nothing about it.
|
|
2041
|
+
* 3. ONE MESSAGE, NOT A CHANNEL. This sends a message; it does not open a line. The reporting
|
|
2042
|
+
* line, the escalation path and the parent's dispatch rules are untouched by it.
|
|
2043
|
+
*/
|
|
2044
|
+
async correctMember(id, targetConversationId, content, workspaceId, actor) {
|
|
2045
|
+
const p = this.raw(id, workspaceId);
|
|
2046
|
+
if (!actor)
|
|
2047
|
+
throw new Error("纠偏需要发起会话的身份。");
|
|
2048
|
+
// THE INITIATOR, AND ONLY THE INITIATOR.
|
|
2049
|
+
if (actor !== p.initiatorConversationId) {
|
|
2050
|
+
throw new Error("只有项目发起会话可以直接纠偏:其它会话请通过直接上级转述,汇报线不变。");
|
|
2051
|
+
}
|
|
2052
|
+
const target = text(targetConversationId, "targetConversationId");
|
|
2053
|
+
if (target === actor)
|
|
2054
|
+
throw new Error("不能给自己的会话发纠偏消息。");
|
|
2055
|
+
const message = text(content, "content");
|
|
2056
|
+
// INSIDE THIS PROJECT'S TREE, AND ONLY INSIDE IT.
|
|
2057
|
+
const members = new Set([
|
|
2058
|
+
p.ownerConversationId,
|
|
2059
|
+
...p.tasks.flatMap((t) => [t.ownerConversationId, t.reviewerConversationId]),
|
|
2060
|
+
].filter(Boolean));
|
|
2061
|
+
if (!members.has(target)) {
|
|
2062
|
+
throw new Error(`会话 ${target} 不在这个项目的会话树里,纠偏只能发给项目树内的会话。`);
|
|
2063
|
+
}
|
|
2064
|
+
if (!this.orchestrator)
|
|
2065
|
+
throw new Error("会话编排服务未就绪");
|
|
2066
|
+
await this.orchestrator.dispatch(target, message, { wait: false });
|
|
2067
|
+
return { ok: true, conversationId: target, delivered: true };
|
|
2068
|
+
}
|
|
2008
2069
|
async tool(body, workspaceId, actor) {
|
|
2009
2070
|
if (body.action === "create") {
|
|
2010
2071
|
// ONLY A ROOT CONVERSATION MAY OPEN A PROJECT. Every dispatched session - the leader, its
|
|
@@ -2027,6 +2088,19 @@ export class ProjectService {
|
|
|
2027
2088
|
const running = this.store.projects().filter((p) => p.initiatorConversationId === actor && !closed(p));
|
|
2028
2089
|
if (running.length >= 3)
|
|
2029
2090
|
throw new Error("你同时进行的项目超过上限(3 个),先完成或停止一个再新建。");
|
|
2091
|
+
// ONLY TWO FIELDS ARE ASKED FOR, AND SAYING SO IS PART OF THE CONTRACT. The schema marks
|
|
2092
|
+
// `title` and `objective` optional - they are optional for the other actions of this tool -
|
|
2093
|
+
// so a model that reads the schema alone can send a project with neither, and then it meets
|
|
2094
|
+
// a bare "项目标题 不能为空". That message names a field the model never sent. So the
|
|
2095
|
+
// refusal names what IS needed, in one sentence, the first time.
|
|
2096
|
+
const missing = [];
|
|
2097
|
+
if (typeof body.title !== "string" || !body.title.trim())
|
|
2098
|
+
missing.push("title(项目标题)");
|
|
2099
|
+
if (typeof body.objective !== "string" || !body.objective.trim())
|
|
2100
|
+
missing.push("objective(项目目标)");
|
|
2101
|
+
if (missing.length) {
|
|
2102
|
+
throw new Error(`起项目只需要 title 和 objective,缺 ${missing.join(" 和 ")}。其余参数(risk、mode、deliverables 等)都可以不填。`);
|
|
2103
|
+
}
|
|
2030
2104
|
const { tasks: batch, ...input } = body;
|
|
2031
2105
|
const plan = this.planTopLevelTasks(batch);
|
|
2032
2106
|
const project = await this.create({ ...input, workspaceId }, actor);
|
|
@@ -2059,6 +2133,7 @@ export class ProjectService {
|
|
|
2059
2133
|
case "resolve_escalation":
|
|
2060
2134
|
case "resolveEscalation":
|
|
2061
2135
|
return this.resolveEscalation(id, text(body.escalationId, "escalationId"), text(body.decision, "decision"), body.status ?? "resolved", workspaceId, actor);
|
|
2136
|
+
case "correct": return this.correctMember(id, text(body.targetConversationId, "targetConversationId"), text(body.content, "content"), workspaceId, actor);
|
|
2062
2137
|
case "complete": return this.complete(id, body.summary, body.evidenceRefs, workspaceId, actor);
|
|
2063
2138
|
case "cancel": return this.cancel(id, body, workspaceId, actor);
|
|
2064
2139
|
default: throw new Error("未知的项目工具操作");
|
|
@@ -196,6 +196,14 @@ export class SessionOrchestratorService {
|
|
|
196
196
|
this.ledger.update(conversationId, {
|
|
197
197
|
status: "running",
|
|
198
198
|
});
|
|
199
|
+
// THE CONVERSATION'S OWN RECORD SAYS THE SAME THING. The ledger is metadata the orchestrator
|
|
200
|
+
// keeps for itself; the CONVERSATION's status is what the sidebar, the project panel and the
|
|
201
|
+
// status tool read, and it is the record a person believes. A session that has just been
|
|
202
|
+
// handed its work must not still read `idle` there: `idle` is a claim that nobody is working on
|
|
203
|
+
// it, and work has just been handed over. A Leader that was spawned with its opening prompt
|
|
204
|
+
// and then reads `idle` is a project that says it is running while its own session says it is
|
|
205
|
+
// not.
|
|
206
|
+
await this.store.setStatus(conversationId, "running");
|
|
199
207
|
// THE ORDER IS THE SYSTEM'S, NOT THE READER'S. It used to go through `enqueueAndRun`, which
|
|
200
208
|
// writes the words under the reader's own name - so the child's transcript showed an
|
|
201
209
|
// instruction the reader never typed, wearing the reader's avatar, and a reader who looked at
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import type { Store } from "../store.js";
|
|
2
|
+
import type { RunService } from "./run-service.js";
|
|
3
|
+
export interface SessionReminderItem {
|
|
4
|
+
reminderId: string;
|
|
5
|
+
conversationId: string;
|
|
6
|
+
note: string;
|
|
7
|
+
delaySeconds: number;
|
|
8
|
+
fireAt: number;
|
|
9
|
+
createdAt: number;
|
|
10
|
+
}
|
|
11
|
+
export declare class SessionReminderService {
|
|
12
|
+
private readonly runService;
|
|
13
|
+
private readonly store;
|
|
14
|
+
private reminders;
|
|
15
|
+
constructor(runService: RunService, store: Store);
|
|
16
|
+
/**
|
|
17
|
+
* Schedules a reminder note to be sent back to the same conversation after delaySeconds.
|
|
18
|
+
*/
|
|
19
|
+
createReminder(params: {
|
|
20
|
+
conversationId: string;
|
|
21
|
+
delaySeconds: number;
|
|
22
|
+
note: string;
|
|
23
|
+
}): {
|
|
24
|
+
ok: true;
|
|
25
|
+
reminderId: string;
|
|
26
|
+
delaySeconds: number;
|
|
27
|
+
note: string;
|
|
28
|
+
fireAt: string;
|
|
29
|
+
};
|
|
30
|
+
/**
|
|
31
|
+
* Cancels a pending reminder by ID.
|
|
32
|
+
*
|
|
33
|
+
* A REMINDER BELONGS TO THE CONVERSATION THAT SET IT. `conversationId` is optional only so the
|
|
34
|
+
* service can be called without one; when it IS given, a reminder owned by another conversation
|
|
35
|
+
* is refused, because one session taking another session's timer away is exactly the kind of
|
|
36
|
+
* cross-session reach the tree rules exist to prevent.
|
|
37
|
+
*/
|
|
38
|
+
cancelReminder(reminderId: string, conversationId?: string): {
|
|
39
|
+
ok: boolean;
|
|
40
|
+
cancelled?: boolean;
|
|
41
|
+
error?: string;
|
|
42
|
+
};
|
|
43
|
+
/**
|
|
44
|
+
* Lists active reminders for a conversation.
|
|
45
|
+
*/
|
|
46
|
+
listReminders(conversationId: string): SessionReminderItem[];
|
|
47
|
+
/**
|
|
48
|
+
* Cancels all pending reminders for a given conversation.
|
|
49
|
+
*/
|
|
50
|
+
cancelAllForConversation(conversationId: string): void;
|
|
51
|
+
/**
|
|
52
|
+
* Timer callback: delivers the note to the originating conversation.
|
|
53
|
+
*/
|
|
54
|
+
private triggerReminder;
|
|
55
|
+
}
|
|
@@ -0,0 +1,121 @@
|
|
|
1
|
+
import { randomUUID } from "node:crypto";
|
|
2
|
+
export class SessionReminderService {
|
|
3
|
+
runService;
|
|
4
|
+
store;
|
|
5
|
+
reminders = new Map();
|
|
6
|
+
constructor(runService, store) {
|
|
7
|
+
this.runService = runService;
|
|
8
|
+
this.store = store;
|
|
9
|
+
}
|
|
10
|
+
/**
|
|
11
|
+
* Schedules a reminder note to be sent back to the same conversation after delaySeconds.
|
|
12
|
+
*/
|
|
13
|
+
createReminder(params) {
|
|
14
|
+
const { conversationId, note } = params;
|
|
15
|
+
const delaySeconds = Math.max(1, Math.round(params.delaySeconds));
|
|
16
|
+
// A REMINDER THAT FIRES IMMEDIATELY IS NOT A REMINDER. `Math.max(1, ...)` would quietly turn a
|
|
17
|
+
// zero or negative delay into "one second from now", so the bad number is refused in words
|
|
18
|
+
// instead of becoming a timer the caller never asked for.
|
|
19
|
+
if (!Number.isFinite(params.delaySeconds) || params.delaySeconds <= 0) {
|
|
20
|
+
throw new Error("提醒需要正的秒数:请传 delaySeconds(或 seconds)。");
|
|
21
|
+
}
|
|
22
|
+
if (!note || !note.trim()) {
|
|
23
|
+
throw new Error("提醒内容 (note) 不能为空");
|
|
24
|
+
}
|
|
25
|
+
const conversation = this.store.conversation(conversationId);
|
|
26
|
+
if (!conversation) {
|
|
27
|
+
throw new Error(`找不到会话:${conversationId}`);
|
|
28
|
+
}
|
|
29
|
+
const reminderId = `rem_${randomUUID()}`;
|
|
30
|
+
const now = Date.now();
|
|
31
|
+
const fireAt = now + delaySeconds * 1000;
|
|
32
|
+
const item = {
|
|
33
|
+
reminderId,
|
|
34
|
+
conversationId,
|
|
35
|
+
note: note.trim(),
|
|
36
|
+
delaySeconds,
|
|
37
|
+
fireAt,
|
|
38
|
+
createdAt: now,
|
|
39
|
+
};
|
|
40
|
+
const timer = setTimeout(() => {
|
|
41
|
+
void this.triggerReminder(reminderId);
|
|
42
|
+
}, delaySeconds * 1000);
|
|
43
|
+
// Node process unref to avoid blocking process exit if idle
|
|
44
|
+
if (typeof timer.unref === "function") {
|
|
45
|
+
timer.unref();
|
|
46
|
+
}
|
|
47
|
+
this.reminders.set(reminderId, { item, timer });
|
|
48
|
+
return {
|
|
49
|
+
ok: true,
|
|
50
|
+
reminderId,
|
|
51
|
+
delaySeconds,
|
|
52
|
+
note: item.note,
|
|
53
|
+
fireAt: new Date(fireAt).toISOString(),
|
|
54
|
+
};
|
|
55
|
+
}
|
|
56
|
+
/**
|
|
57
|
+
* Cancels a pending reminder by ID.
|
|
58
|
+
*
|
|
59
|
+
* A REMINDER BELONGS TO THE CONVERSATION THAT SET IT. `conversationId` is optional only so the
|
|
60
|
+
* service can be called without one; when it IS given, a reminder owned by another conversation
|
|
61
|
+
* is refused, because one session taking another session's timer away is exactly the kind of
|
|
62
|
+
* cross-session reach the tree rules exist to prevent.
|
|
63
|
+
*/
|
|
64
|
+
cancelReminder(reminderId, conversationId) {
|
|
65
|
+
const existing = this.reminders.get(reminderId);
|
|
66
|
+
if (!existing) {
|
|
67
|
+
return { ok: false, error: `找不到提醒 ${reminderId} 或该提醒已触发` };
|
|
68
|
+
}
|
|
69
|
+
if (conversationId && existing.item.conversationId !== conversationId) {
|
|
70
|
+
return { ok: false, error: `提醒 ${reminderId} 不属于本会话,不能取消。` };
|
|
71
|
+
}
|
|
72
|
+
clearTimeout(existing.timer);
|
|
73
|
+
this.reminders.delete(reminderId);
|
|
74
|
+
return { ok: true, cancelled: true };
|
|
75
|
+
}
|
|
76
|
+
/**
|
|
77
|
+
* Lists active reminders for a conversation.
|
|
78
|
+
*/
|
|
79
|
+
listReminders(conversationId) {
|
|
80
|
+
const results = [];
|
|
81
|
+
const now = Date.now();
|
|
82
|
+
for (const { item } of this.reminders.values()) {
|
|
83
|
+
if (item.conversationId === conversationId) {
|
|
84
|
+
results.push({ ...item });
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
return results.sort((a, b) => a.fireAt - b.fireAt);
|
|
88
|
+
}
|
|
89
|
+
/**
|
|
90
|
+
* Cancels all pending reminders for a given conversation.
|
|
91
|
+
*/
|
|
92
|
+
cancelAllForConversation(conversationId) {
|
|
93
|
+
for (const [id, entry] of this.reminders.entries()) {
|
|
94
|
+
if (entry.item.conversationId === conversationId) {
|
|
95
|
+
clearTimeout(entry.timer);
|
|
96
|
+
this.reminders.delete(id);
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
/**
|
|
101
|
+
* Timer callback: delivers the note to the originating conversation.
|
|
102
|
+
*/
|
|
103
|
+
async triggerReminder(reminderId) {
|
|
104
|
+
const entry = this.reminders.get(reminderId);
|
|
105
|
+
if (!entry)
|
|
106
|
+
return;
|
|
107
|
+
this.reminders.delete(reminderId);
|
|
108
|
+
const { conversationId, note } = entry.item;
|
|
109
|
+
const conversation = this.store.conversation(conversationId);
|
|
110
|
+
if (!conversation || conversation.archivedAt) {
|
|
111
|
+
return;
|
|
112
|
+
}
|
|
113
|
+
const message = `[定时提醒] ${note}`;
|
|
114
|
+
try {
|
|
115
|
+
await this.runService.enqueueAndRun(conversationId, message);
|
|
116
|
+
}
|
|
117
|
+
catch (error) {
|
|
118
|
+
console.warn(`Super Pi: delivering session reminder to ${conversationId} failed:`, error instanceof Error ? error.message : String(error));
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { arbitrateContextWindow, readDeclaredWindows, readStoreWindows } from "./model-context-window.js";
|
|
2
2
|
const nonnegative = (value) => typeof value === "number" && Number.isFinite(value) && value >= 0;
|
|
3
3
|
/** Collect only completed assistant messages, never the repeated usage on streaming deltas. */
|
|
4
4
|
export class ConversationUsageCollector {
|
|
@@ -27,7 +27,7 @@ export class ConversationUsageCollector {
|
|
|
27
27
|
let contextUsage;
|
|
28
28
|
if (context) {
|
|
29
29
|
const contextWindow = model?.provider && model.id
|
|
30
|
-
?
|
|
30
|
+
? arbitrateContextWindow(readDeclaredWindows(agentDir), readStoreWindows(agentDir), model.provider, model.id, context.contextWindow) ?? context.contextWindow
|
|
31
31
|
: context.contextWindow;
|
|
32
32
|
if (nonnegative(contextWindow) && contextWindow > 0) {
|
|
33
33
|
// Pi returns null after compaction until another assistant supplies a trustworthy token count.
|