@evandu/super-pi 0.1.181 → 0.1.183
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/dist/client/.super-pi-client-sources.json +5 -5
- package/dist/client/assets/{CodeMirrorEditor-Ds5FtOmr.js → CodeMirrorEditor-DUyqaSOB.js} +2 -2
- package/dist/client/assets/{dist-DK6YFp_a.js → dist-AQ8CYp6b.js} +1 -1
- package/dist/client/assets/{dist-CGEv6ocT.js → dist-Bj218gfa.js} +1 -1
- package/dist/client/assets/{dist-BsB82GlW.js → dist-C7PhA7pe.js} +1 -1
- package/dist/client/assets/{dist-LWgwgXSp.js → dist-CB124C6Z.js} +1 -1
- package/dist/client/assets/{dist-BOsVN1AS.js → dist-CNem2r_T.js} +1 -1
- package/dist/client/assets/{dist-BSwraz5b.js → dist-CPmDYAQT.js} +1 -1
- package/dist/client/assets/{dist-RADY23tg.js → dist-CU8JEI5K.js} +1 -1
- package/dist/client/assets/{dist-28uVn4av.js → dist-CeU4Svbh.js} +1 -1
- package/dist/client/assets/{dist-B_251caF.js → dist-CkTZUfAR.js} +1 -1
- package/dist/client/assets/{dist-CT0VqErg.js → dist-CvLzvDh7.js} +1 -1
- package/dist/client/assets/{dist-DCYMeHTp.js → dist-D3HMZhM-.js} +1 -1
- package/dist/client/assets/{dist-65_o5Row.js → dist-D4lWO1EF.js} +1 -1
- package/dist/client/assets/{dist-Dssf0A4Z.js → dist-DLOUy-hB.js} +1 -1
- package/dist/client/assets/{dist-CacIUE03.js → dist-DTd2PCza.js} +1 -1
- package/dist/client/assets/{dist-BKMTNdOk.js → dist-Dkm31GRe.js} +1 -1
- package/dist/client/assets/{dist-DETrPt4i.js → dist-Dlg4MpdE.js} +1 -1
- package/dist/client/assets/{dist-Cc0bJ30I.js → dist-Dnx8LlEL.js} +1 -1
- package/dist/client/assets/{dist-yEp6eUql.js → dist-NLNoAzKl.js} +1 -1
- package/dist/client/assets/{dist-CDXayauu.js → dist-TX6Uhfee.js} +1 -1
- package/dist/client/assets/{dist-EI3JPt0D.js → dist-dnyR0Vf6.js} +1 -1
- package/dist/client/assets/{dist-CfLIzkuU.js → dist-ka17rnWs.js} +1 -1
- package/dist/client/assets/{dist-BmGTVkN5.js → dist-nbHIDjzw.js} +1 -1
- package/dist/client/assets/{index-DsrCbcwc.js → index-BplDWdZp.js} +15 -15
- package/dist/client/assets/{index-DAKtgLA9.css → index-Ui6aXMVV.css} +1 -1
- package/dist/client/index.html +2 -2
- package/dist/server/application/run-service.d.ts +7 -0
- package/dist/server/application/run-service.js +60 -15
- package/dist/server/http-server.js +30 -6
- package/dist/server/store.d.ts +2 -0
- package/dist/server/store.js +9 -0
- package/dist/server/types.d.ts +10 -0
- package/dist/server/update.d.ts +17 -0
- package/dist/server/update.js +26 -0
- package/dist/shared/child-session-lock.d.ts +8 -0
- package/dist/shared/child-session-lock.js +8 -0
- package/dist/shared/session-reporting.d.ts +15 -0
- package/dist/shared/session-reporting.js +39 -0
- package/package.json +5 -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-BplDWdZp.js"></script>
|
|
12
|
+
<link rel="stylesheet" crossorigin href="/assets/index-Ui6aXMVV.css">
|
|
13
13
|
</head>
|
|
14
14
|
<body>
|
|
15
15
|
<div id="root"></div>
|
|
@@ -92,6 +92,13 @@ export declare class RunService {
|
|
|
92
92
|
holdHistoryCut(conversationId: string): void;
|
|
93
93
|
releaseHistoryCut(conversationId: string): void;
|
|
94
94
|
private assertHistoryAvailable;
|
|
95
|
+
/**
|
|
96
|
+
* Whether a conversation is a child session with an active (unarchived) parent.
|
|
97
|
+
*
|
|
98
|
+
* Reuses the canonical judgement in `src/shared/child-session-lock.ts`: child sessions
|
|
99
|
+
* must report upwards via `session_report` rather than asking the user directly.
|
|
100
|
+
*/
|
|
101
|
+
private isChildConversation;
|
|
95
102
|
/**
|
|
96
103
|
* The completion of the run currently holding a conversation's slot.
|
|
97
104
|
*
|
|
@@ -11,6 +11,7 @@ import { describeThrownWithStack } from "../failure-text.js";
|
|
|
11
11
|
import { toWorkspaceRelative } from "../files.js";
|
|
12
12
|
import { refreshWorkspaceIndex } from "../file-index.js";
|
|
13
13
|
import { resolveSessionCwd } from "../session-cwd.js";
|
|
14
|
+
import { CHILD_QUESTION_LOCK_REASON, isChildSession } from "../../shared/child-session-lock.js";
|
|
14
15
|
import { execFile } from "node:child_process";
|
|
15
16
|
import { promisify } from "node:util";
|
|
16
17
|
import { randomUUID } from "node:crypto";
|
|
@@ -166,6 +167,16 @@ export class RunService {
|
|
|
166
167
|
if (this.historyCutClaims.has(conversationId))
|
|
167
168
|
throw new Error("正在撤回上一条消息,Pi 的历史还没截断完成,请等撤回结束后再发送。");
|
|
168
169
|
}
|
|
170
|
+
/**
|
|
171
|
+
* Whether a conversation is a child session with an active (unarchived) parent.
|
|
172
|
+
*
|
|
173
|
+
* Reuses the canonical judgement in `src/shared/child-session-lock.ts`: child sessions
|
|
174
|
+
* must report upwards via `session_report` rather than asking the user directly.
|
|
175
|
+
*/
|
|
176
|
+
isChildConversation(conversationId) {
|
|
177
|
+
const facts = this.store.childSessionFacts(conversationId);
|
|
178
|
+
return isChildSession(facts.parentConversationId, facts.parent);
|
|
179
|
+
}
|
|
169
180
|
/**
|
|
170
181
|
* The completion of the run currently holding a conversation's slot.
|
|
171
182
|
*
|
|
@@ -381,6 +392,7 @@ export class RunService {
|
|
|
381
392
|
return undefined;
|
|
382
393
|
const row = await this.store.addToolMessage(parentId, message, { delivery: "waiting" });
|
|
383
394
|
await this.moveAheadOfUnclaimed(parentId, row.id);
|
|
395
|
+
await this.store.markConversationReported(input.conversationId);
|
|
384
396
|
this.broadcaster.broadcastState();
|
|
385
397
|
return row;
|
|
386
398
|
});
|
|
@@ -620,6 +632,17 @@ export class RunService {
|
|
|
620
632
|
* backfilled with `options[0]`.
|
|
621
633
|
*/
|
|
622
634
|
async askQuestion(conversationId) {
|
|
635
|
+
if (this.isChildConversation(conversationId)) {
|
|
636
|
+
const pending = this.store.pendingQuestion(conversationId);
|
|
637
|
+
if (pending) {
|
|
638
|
+
void this.store.updateToolCall(conversationId, pending.messageId, pending.index, {
|
|
639
|
+
question: { items: pending.question.items, status: "cancelled" },
|
|
640
|
+
}).then(() => {
|
|
641
|
+
this.broadcaster.broadcastState();
|
|
642
|
+
}).catch(() => { });
|
|
643
|
+
}
|
|
644
|
+
throw new Error(CHILD_QUESTION_LOCK_REASON);
|
|
645
|
+
}
|
|
623
646
|
// The HTTP callback belongs to the run that admitted it. A stop followed by a new turn clears
|
|
624
647
|
// the conversation's cancellation marker, but must never let an old polling ask bind its row.
|
|
625
648
|
const owner = this.activeRuns.get(conversationId);
|
|
@@ -1283,12 +1306,15 @@ export class RunService {
|
|
|
1283
1306
|
// spends writing its replacement text - and by the time the file path was on screen, the block looked
|
|
1284
1307
|
// broken rather than early. The placeholder word is now only the FALLBACK for the first fragment, when
|
|
1285
1308
|
// Pi has not yet said what the call is or what it opens.
|
|
1309
|
+
// 归属在宣布时刻一次性判死:当时 thinking 活着且 answer 还没来,它就永远是 thinking 里的调用
|
|
1310
|
+
const callThinkingBlock = (thinkingActive && !answerAfterThinking) ? thinkingBlock : null;
|
|
1286
1311
|
enqueueTools("a tool call being prepared", () => this.store.appendToolCall(conversation.id, assistant.id, {
|
|
1287
1312
|
label: call.name || "工具",
|
|
1288
1313
|
...(call.detail ? { detail: call.detail } : { detail: "正在生成参数…" }),
|
|
1289
1314
|
preparing: true,
|
|
1290
1315
|
at,
|
|
1291
1316
|
thinkingAt,
|
|
1317
|
+
thinkingBlock: callThinkingBlock,
|
|
1292
1318
|
}));
|
|
1293
1319
|
// `thinkingAt` GOES WITH THE PLACEHOLDER. It is how much reasoning had been written when the
|
|
1294
1320
|
// model announced this call, and the real call needs it to work out whether the reasoning kept
|
|
@@ -1300,7 +1326,14 @@ export class RunService {
|
|
|
1300
1326
|
// opened, and the index of the block the call belongs to is no longer the current one.
|
|
1301
1327
|
// THE FOLD THIS CALL BELONGS TO, DECIDED AT THE MOMENT THE MODEL ANNOUNCED IT. A call announced
|
|
1302
1328
|
// after the answer started belongs to no fold, even when the reasoning is still running.
|
|
1303
|
-
preparingRows.set(call.contentIndex, {
|
|
1329
|
+
preparingRows.set(call.contentIndex, {
|
|
1330
|
+
row,
|
|
1331
|
+
name: call.name,
|
|
1332
|
+
thinkingAt,
|
|
1333
|
+
thinkingActive,
|
|
1334
|
+
thinkingBlock: callThinkingBlock,
|
|
1335
|
+
at,
|
|
1336
|
+
});
|
|
1304
1337
|
};
|
|
1305
1338
|
/**
|
|
1306
1339
|
* THE AGENT IS ABOUT TO WRITE A FILE.
|
|
@@ -1389,19 +1422,31 @@ export class RunService {
|
|
|
1389
1422
|
rowByToolCallId.set(call.id, row);
|
|
1390
1423
|
this.noteToolCallSite(conversation.id, call.id, assistant.id, row);
|
|
1391
1424
|
}
|
|
1392
|
-
// THE FOLD WAS
|
|
1393
|
-
//
|
|
1394
|
-
//
|
|
1395
|
-
//
|
|
1396
|
-
//
|
|
1397
|
-
//
|
|
1398
|
-
//
|
|
1399
|
-
//
|
|
1400
|
-
|
|
1401
|
-
//
|
|
1402
|
-
//
|
|
1403
|
-
//
|
|
1404
|
-
|
|
1425
|
+
// THE FOLD WAS DECIDED WHEN THE CALL WAS ANNOUNCED, and it stays decided.
|
|
1426
|
+
//
|
|
1427
|
+
// This line used to re-judge the ownership at execution time ("the reasoning had already
|
|
1428
|
+
// stopped AND the answer has started since" - the two-fact rule added in 0.1.181). Two
|
|
1429
|
+
// judgements of one fact is one fact too many: the placeholder row was filed in the fold
|
|
1430
|
+
// when the model announced the call, and this line filed it back outside a moment later.
|
|
1431
|
+
// The reader watched the block JUMP out of the fold and into the answer flow - a wrong
|
|
1432
|
+
// intermediate state, even though the final state was right.
|
|
1433
|
+
//
|
|
1434
|
+
// The rule is the reader's, from 11-09: a call announced before the body text stays in the
|
|
1435
|
+
// block it was announced in. The announcement is the only moment that knows which block that
|
|
1436
|
+
// was, so it is the only moment allowed to decide.
|
|
1437
|
+
const callThinkingBlock = prepared[1].thinkingBlock;
|
|
1438
|
+
// at 也保持宣布时刻的 spoken 偏移,不按执行时刻重算;只有无占位符的调用才用执行时刻的 spoken
|
|
1439
|
+
const callAt = prepared[1].at;
|
|
1440
|
+
enqueueTools("a tool call", () => this.store.updateToolCall(conversation.id, assistant.id, row, {
|
|
1441
|
+
label: call.name,
|
|
1442
|
+
detail: call.detail,
|
|
1443
|
+
args: call.args,
|
|
1444
|
+
live: "",
|
|
1445
|
+
preparing: false,
|
|
1446
|
+
at: callAt,
|
|
1447
|
+
thinkingBlock: callThinkingBlock,
|
|
1448
|
+
...(call.question && !this.isChildConversation(conversation.id) ? { question: call.question } : {}),
|
|
1449
|
+
}));
|
|
1405
1450
|
return;
|
|
1406
1451
|
}
|
|
1407
1452
|
const row = rows++;
|
|
@@ -1423,7 +1468,7 @@ export class RunService {
|
|
|
1423
1468
|
// must NOT be called once the answer has started - that would file an after-answer call between
|
|
1424
1469
|
// two stretches of reasoning that were never separated by one.
|
|
1425
1470
|
const callThinkingBlock = answerAfterThinking ? null : currentThinkingBlock();
|
|
1426
|
-
enqueueTools("a tool call", () => this.store.appendToolCall(conversation.id, assistant.id, { label: call.name, detail: call.detail, args: call.args, at, thinkingAt, thinkingBlock: callThinkingBlock, ...(call.question ? { question: call.question } : {}) }));
|
|
1471
|
+
enqueueTools("a tool call", () => this.store.appendToolCall(conversation.id, assistant.id, { label: call.name, detail: call.detail, args: call.args, at, thinkingAt, thinkingBlock: callThinkingBlock, ...(call.question && !this.isChildConversation(conversation.id) ? { question: call.question } : {}) }));
|
|
1427
1472
|
};
|
|
1428
1473
|
const onToolUpdate = (call) => {
|
|
1429
1474
|
if (!acceptsEvent("tool.update"))
|
|
@@ -21,11 +21,12 @@ import { MAX_DOCUMENT_REQUEST_BYTES } from "./application/document-service.js";
|
|
|
21
21
|
import { MAX_FEISHU_REQUEST_BYTES } from "./application/feishu-service.js";
|
|
22
22
|
import { MAX_WEB_REQUEST_BYTES } from "./web.js";
|
|
23
23
|
import { MAX_TOOL_BODY_BYTES } from "./tool-registry.js";
|
|
24
|
-
import { claimUpdateSlot, packageUpdateArgs, releaseUpdateSlot, shellArgs } from "./update.js";
|
|
24
|
+
import { claimUpdateSlot, getLastUpdateOutcome, isUpdateInFlight, packageUpdateArgs, recordUpdateOutcome, releaseUpdateSlot, shellArgs } from "./update.js";
|
|
25
25
|
import { FileIndex } from "./file-index.js";
|
|
26
26
|
import { ensureNameIndex, recordWorkspacePath } from "./file-name-index.js";
|
|
27
27
|
import { resolveSessionCwd, sessionScopeKey, workspacePathFromSession } from "./session-cwd.js";
|
|
28
28
|
import { verifyDirectChildScope, verifyListParentScope, verifyReportTargetScope, verifySpawnParentScope } from "./session-tree-scope.js";
|
|
29
|
+
import { CHILD_SESSION_LOCK_REASON } from "../shared/child-session-lock.js";
|
|
29
30
|
import { MAX_CONTENT_DEPTH, MAX_CONTENT_FILE_BYTES, MAX_CONTENT_RESULTS, searchByContent } from "./content-search.js";
|
|
30
31
|
import { getAvailableSkills, readSkill } from "./skills.js";
|
|
31
32
|
/**
|
|
@@ -1044,7 +1045,10 @@ export function createHttpServer(options) {
|
|
|
1044
1045
|
};
|
|
1045
1046
|
// RESTART ONLY: the code on disk is already new, the running server is not. Re-downloading
|
|
1046
1047
|
// 32.8 MB to restart a process is waste; the second button asks for exactly this.
|
|
1048
|
+
// The outcome is recorded here as well: from the client's point of view a restart is the
|
|
1049
|
+
// end of the update it started, and it needs to be able to say so.
|
|
1047
1050
|
if (restartOnly) {
|
|
1051
|
+
recordUpdateOutcome(true);
|
|
1048
1052
|
release();
|
|
1049
1053
|
restartNow();
|
|
1050
1054
|
return;
|
|
@@ -1054,17 +1058,27 @@ export function createHttpServer(options) {
|
|
|
1054
1058
|
const npmCmd = process.platform === "win32" ? "npm.cmd" : "npm";
|
|
1055
1059
|
const update = packageUpdateArgs(rootDir, wantedVersion);
|
|
1056
1060
|
const child = spawn(npmCmd, shellArgs(update.args), { stdio: "ignore", shell: process.platform === "win32", env: process.env });
|
|
1061
|
+
// A SPAWN THAT NEVER STARTED. Node emits "error" and THEN "close" with a null code, so
|
|
1062
|
+
// without this flag the close handler would read that null as a finished install and tell
|
|
1063
|
+
// the user the update worked when npm never ran at all.
|
|
1064
|
+
let spawnFailed = false;
|
|
1057
1065
|
child.on("close", (code) => {
|
|
1058
|
-
|
|
1059
|
-
|
|
1066
|
+
// THE OUTCOME IS RECORDED BEFORE THE SLOT IS RELEASED. If the slot were released first,
|
|
1067
|
+
// a client polling at that exact moment would see "not updating" with no outcome
|
|
1068
|
+
// recorded and could not tell whether the install had worked.
|
|
1069
|
+
if (code === 0 || (code === null && !spawnFailed)) {
|
|
1070
|
+
recordUpdateOutcome(true);
|
|
1071
|
+
release();
|
|
1060
1072
|
console.log("Super Pi: npm install completed, triggering restart.");
|
|
1061
1073
|
restartNow();
|
|
1062
1074
|
}
|
|
1063
1075
|
else {
|
|
1076
|
+
recordUpdateOutcome(false, typeof code === "number" ? code : undefined);
|
|
1077
|
+
release();
|
|
1064
1078
|
console.error(`Super Pi: npm install failed with code ${code}`);
|
|
1065
1079
|
}
|
|
1066
1080
|
});
|
|
1067
|
-
child.on("error", (error) => { release(); console.warn(`Super Pi: update spawn failed: ${error instanceof Error ? error.message : "unknown error"}`); });
|
|
1081
|
+
child.on("error", (error) => { spawnFailed = true; recordUpdateOutcome(false); release(); console.warn(`Super Pi: update spawn failed: ${error instanceof Error ? error.message : "unknown error"}`); });
|
|
1068
1082
|
child.unref();
|
|
1069
1083
|
return;
|
|
1070
1084
|
}
|
|
@@ -1075,6 +1089,14 @@ export function createHttpServer(options) {
|
|
|
1075
1089
|
}
|
|
1076
1090
|
try {
|
|
1077
1091
|
const current = checkDiskVersion(rootDir);
|
|
1092
|
+
// AN UPDATE IS RUNNING, so the registry question is not worth asking. The client polls
|
|
1093
|
+
// this endpoint every two seconds while it waits for the install to finish, and npm's
|
|
1094
|
+
// registry does not need one machine to ask it for the latest version a hundred times a
|
|
1095
|
+
// minute. While the slot is held the answer is already known, so it is answered here.
|
|
1096
|
+
if (isUpdateInFlight()) {
|
|
1097
|
+
response.writeHead(200, { "content-type": "application/json; charset=utf-8" }).end(JSON.stringify({ ...current, updating: true, lastUpdate: getLastUpdateOutcome() ?? null, updateAvailable: false }));
|
|
1098
|
+
return;
|
|
1099
|
+
}
|
|
1078
1100
|
// Query the npm registry for the latest @evandu/super-pi version.
|
|
1079
1101
|
const remoteVersion = await fetch("https://registry.npmjs.org/@evandu/super-pi/latest").then(async (result) => {
|
|
1080
1102
|
if (!result.ok)
|
|
@@ -1082,7 +1104,7 @@ export function createHttpServer(options) {
|
|
|
1082
1104
|
return result.json();
|
|
1083
1105
|
});
|
|
1084
1106
|
const latestVersion = typeof remoteVersion.version === "string" ? remoteVersion.version : undefined;
|
|
1085
|
-
response.writeHead(200, { "content-type": "application/json; charset=utf-8" }).end(JSON.stringify({ ...current, latestVersion, updateAvailable: Boolean(latestVersion && latestVersion !== current.diskVersion) }));
|
|
1107
|
+
response.writeHead(200, { "content-type": "application/json; charset=utf-8" }).end(JSON.stringify({ ...current, latestVersion, updateAvailable: Boolean(latestVersion && latestVersion !== current.diskVersion), updating: isUpdateInFlight(), lastUpdate: getLastUpdateOutcome() ?? null }));
|
|
1086
1108
|
}
|
|
1087
1109
|
catch (error) {
|
|
1088
1110
|
response.writeHead(502, { "content-type": "application/json; charset=utf-8" }).end(JSON.stringify({ error: error instanceof Error ? error.message : String(error) }));
|
|
@@ -2180,7 +2202,9 @@ export function createHttpServer(options) {
|
|
|
2180
2202
|
response.writeHead(200, { "content-type": "application/json" }).end(JSON.stringify(result));
|
|
2181
2203
|
}
|
|
2182
2204
|
catch (error) {
|
|
2183
|
-
|
|
2205
|
+
const errorText = describeThrown(error) || "问答失败,没有拿到失败原因。";
|
|
2206
|
+
const status = errorText.includes(CHILD_SESSION_LOCK_REASON) ? 403 : 400;
|
|
2207
|
+
response.writeHead(status, { "content-type": "application/json" }).end(JSON.stringify({ error: errorText }));
|
|
2184
2208
|
}
|
|
2185
2209
|
return;
|
|
2186
2210
|
}
|
package/dist/server/store.d.ts
CHANGED
|
@@ -679,6 +679,8 @@ export declare class Store {
|
|
|
679
679
|
setMessagePiEntryId(conversationId: string, messageId: string, piEntryId: string): Promise<void>;
|
|
680
680
|
/** Cache a locator Pi itself resolved while serving this conversation; never trust it as authorization. */
|
|
681
681
|
setConversationPiSessionFile(conversationId: string, path: string): Promise<void>;
|
|
682
|
+
/** Records that a child conversation has reported its result/progress to its parent. */
|
|
683
|
+
markConversationReported(conversationId: string, timestamp?: string): Promise<Conversation | undefined>;
|
|
682
684
|
/**
|
|
683
685
|
* Reverts the conversation to the state right after `messageId`, in `state.json` only.
|
|
684
686
|
*
|
package/dist/server/store.js
CHANGED
|
@@ -2148,6 +2148,15 @@ export class Store {
|
|
|
2148
2148
|
conversation.piSessionFile = path;
|
|
2149
2149
|
await this.persistMetadata(conversationId);
|
|
2150
2150
|
}
|
|
2151
|
+
/** Records that a child conversation has reported its result/progress to its parent. */
|
|
2152
|
+
async markConversationReported(conversationId, timestamp) {
|
|
2153
|
+
const target = this.state.conversations.find((c) => c.id === conversationId);
|
|
2154
|
+
if (!target)
|
|
2155
|
+
return undefined;
|
|
2156
|
+
target.reportedToParentAt = timestamp || now();
|
|
2157
|
+
await this.persistMetadata(conversationId);
|
|
2158
|
+
return target;
|
|
2159
|
+
}
|
|
2151
2160
|
/**
|
|
2152
2161
|
* Reverts the conversation to the state right after `messageId`, in `state.json` only.
|
|
2153
2162
|
*
|
package/dist/server/types.d.ts
CHANGED
|
@@ -559,6 +559,16 @@ export type Conversation = {
|
|
|
559
559
|
* recorded simply means "top level", which is what those conversations genuinely are.
|
|
560
560
|
*/
|
|
561
561
|
parentConversationId?: string;
|
|
562
|
+
/**
|
|
563
|
+
* 上次向父会话汇报的时间戳(ISO 字符串)。仅子会话有意义。
|
|
564
|
+
* 初始为空;父会话通过工具/转述/完成读取该子会话后写入。
|
|
565
|
+
* 只要本字段存在,子会话就在汇报轴上算「已汇报」。
|
|
566
|
+
*/
|
|
567
|
+
reportedToParentAt?: string;
|
|
568
|
+
/**
|
|
569
|
+
* 用户上次点击阅读该会话的时间戳(ISO 字符串)。
|
|
570
|
+
* 顶层会话退回到根据这个判断未读;子会话不看这个。
|
|
571
|
+
*/
|
|
562
572
|
/** Stable memory-sharing identity, inherited at birth; forks start a new tree. */
|
|
563
573
|
treeId?: string;
|
|
564
574
|
/**
|
package/dist/server/update.d.ts
CHANGED
|
@@ -41,3 +41,20 @@ export declare function packageUpdateArgs(rootDir: string, version?: string): {
|
|
|
41
41
|
export declare function claimUpdateSlot(): boolean;
|
|
42
42
|
/** Releases the update slot, so the next update can start. */
|
|
43
43
|
export declare function releaseUpdateSlot(): void;
|
|
44
|
+
/**
|
|
45
|
+
* Whether an update is running RIGHT NOW.
|
|
46
|
+
*
|
|
47
|
+
* The client used to keep its buttons disabled only for as long as its own request was in
|
|
48
|
+
* flight, which ended the moment the server answered 202 - while npm was still installing.
|
|
49
|
+
* The server knew the whole time (it holds the slot above), so it says so out loud and the
|
|
50
|
+
* client asks.
|
|
51
|
+
*/
|
|
52
|
+
export declare function isUpdateInFlight(): boolean;
|
|
53
|
+
/** Records the outcome of an update attempt. */
|
|
54
|
+
export declare function recordUpdateOutcome(ok: boolean, code?: number): void;
|
|
55
|
+
/** The most recent update outcome, or undefined when no update has run in this process. */
|
|
56
|
+
export declare function getLastUpdateOutcome(): {
|
|
57
|
+
ok: boolean;
|
|
58
|
+
code?: number;
|
|
59
|
+
at: string;
|
|
60
|
+
} | undefined;
|
package/dist/server/update.js
CHANGED
|
@@ -72,3 +72,29 @@ export function claimUpdateSlot() {
|
|
|
72
72
|
export function releaseUpdateSlot() {
|
|
73
73
|
updateInFlight = false;
|
|
74
74
|
}
|
|
75
|
+
/**
|
|
76
|
+
* Whether an update is running RIGHT NOW.
|
|
77
|
+
*
|
|
78
|
+
* The client used to keep its buttons disabled only for as long as its own request was in
|
|
79
|
+
* flight, which ended the moment the server answered 202 - while npm was still installing.
|
|
80
|
+
* The server knew the whole time (it holds the slot above), so it says so out loud and the
|
|
81
|
+
* client asks.
|
|
82
|
+
*/
|
|
83
|
+
export function isUpdateInFlight() {
|
|
84
|
+
return updateInFlight;
|
|
85
|
+
}
|
|
86
|
+
/**
|
|
87
|
+
* WHAT THE LAST UPDATE ACTUALLY DID.
|
|
88
|
+
*
|
|
89
|
+
* The outcome of the most recent update, so the client can tell the user what actually
|
|
90
|
+
* happened instead of showing a spinner forever.
|
|
91
|
+
*/
|
|
92
|
+
let lastUpdate;
|
|
93
|
+
/** Records the outcome of an update attempt. */
|
|
94
|
+
export function recordUpdateOutcome(ok, code) {
|
|
95
|
+
lastUpdate = { ok, code, at: new Date().toISOString() };
|
|
96
|
+
}
|
|
97
|
+
/** The most recent update outcome, or undefined when no update has run in this process. */
|
|
98
|
+
export function getLastUpdateOutcome() {
|
|
99
|
+
return lastUpdate;
|
|
100
|
+
}
|
|
@@ -7,6 +7,14 @@
|
|
|
7
7
|
* server must not disagree about what the rule is.
|
|
8
8
|
*/
|
|
9
9
|
export declare const CHILD_SESSION_LOCK_REASON = "\u6C47\u62A5\u7EBF\u53EA\u5141\u8BB8\u9010\u7EA7\u4E0A\u5347\uFF0C\u5B50\u4F1A\u8BDD\u9ED8\u8BA4\u4E0D\u80FD\u76F4\u63A5\u5BF9\u8BDD\uFF1B\u786E\u6709\u7279\u6B8A\u60C5\u51B5\u53EF\u89E3\u9501\u3002";
|
|
10
|
+
/**
|
|
11
|
+
* THE QUESTION LOCK SENTENCE.
|
|
12
|
+
*
|
|
13
|
+
* Child sessions must not use the `question` tool to ask the reader directly.
|
|
14
|
+
* When they need a human decision, they must report to their direct supervisor
|
|
15
|
+
* using `session_report`, which escalates through the reporting line.
|
|
16
|
+
*/
|
|
17
|
+
export declare const CHILD_QUESTION_LOCK_REASON = "\u6C47\u62A5\u7EBF\u53EA\u5141\u8BB8\u9010\u7EA7\u4E0A\u5347\uFF0C\u5B50\u4F1A\u8BDD\u9ED8\u8BA4\u4E0D\u80FD\u76F4\u63A5\u5BF9\u8BDD\uFF1B\u786E\u6709\u7279\u6B8A\u60C5\u51B5\u53EF\u89E3\u9501\u3002\u5B50\u4F1A\u8BDD\u8981\u7528 session_report \u5411\u76F4\u63A5\u4E0A\u7EA7\uFF08\u7236\u4F1A\u8BDD\uFF09\u6C47\u62A5\uFF0C\u7531\u7236\u4F1A\u8BDD\u9010\u7EA7\u8F6C\u8FF0\u3002";
|
|
10
18
|
/** The minimum a parent row has to expose for the judgement to be made. */
|
|
11
19
|
export type ChildSessionRow = {
|
|
12
20
|
id: string;
|
|
@@ -30,6 +30,14 @@
|
|
|
30
30
|
* server must not disagree about what the rule is.
|
|
31
31
|
*/
|
|
32
32
|
export const CHILD_SESSION_LOCK_REASON = "汇报线只允许逐级上升,子会话默认不能直接对话;确有特殊情况可解锁。";
|
|
33
|
+
/**
|
|
34
|
+
* THE QUESTION LOCK SENTENCE.
|
|
35
|
+
*
|
|
36
|
+
* Child sessions must not use the `question` tool to ask the reader directly.
|
|
37
|
+
* When they need a human decision, they must report to their direct supervisor
|
|
38
|
+
* using `session_report`, which escalates through the reporting line.
|
|
39
|
+
*/
|
|
40
|
+
export const CHILD_QUESTION_LOCK_REASON = `${CHILD_SESSION_LOCK_REASON}子会话要用 session_report 向直接上级(父会话)汇报,由父会话逐级转述。`;
|
|
33
41
|
/**
|
|
34
42
|
* Whether a conversation is a CHILD SESSION: it hangs under a parent that is still ALIVE.
|
|
35
43
|
*
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { ChildSessionRow } from "./child-session-lock.js";
|
|
2
|
+
export type SessionReportingSnapshot = {
|
|
3
|
+
id: string;
|
|
4
|
+
parentConversationId?: string;
|
|
5
|
+
status?: string;
|
|
6
|
+
reportedToParentAt?: string;
|
|
7
|
+
archivedAt?: string;
|
|
8
|
+
};
|
|
9
|
+
export type ReportingAxisState = "pending_report" | "awaiting_subordinates" | "unread";
|
|
10
|
+
export declare function deriveReportingState(params: {
|
|
11
|
+
conversation: SessionReportingSnapshot;
|
|
12
|
+
parent?: ChildSessionRow;
|
|
13
|
+
directChildren: SessionReportingSnapshot[];
|
|
14
|
+
isTopLevelUnread: boolean;
|
|
15
|
+
}): ReportingAxisState | null;
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
// 会话状态模型:汇报线上的位置 —— 两边共用的推导逻辑与类型。
|
|
2
|
+
//
|
|
3
|
+
// 状态在回答什么问题:
|
|
4
|
+
// - 子会话:有没有向上汇报?没有就是待汇报(pending_report),报过了就消停了(null)。
|
|
5
|
+
// - 父会话:下级是不是都在消停状态?不是就是等待下级(awaiting_subordinates)。
|
|
6
|
+
// - 顶层会话:自己有没有未读?有就是未读(unread)。
|
|
7
|
+
//
|
|
8
|
+
// 规则在 `docs/DESIGN-PRINCIPLES.md` 第二节「汇报线逐级转述:Boss 只有一个联络线」。
|
|
9
|
+
import { isChildSession } from "./child-session-lock.js";
|
|
10
|
+
export function deriveReportingState(params) {
|
|
11
|
+
const { conversation, parent, directChildren, isTopLevelUnread } = params;
|
|
12
|
+
// 1. 如果自己是子会话(按 isChildSession 判据,父会话存在且未归档)
|
|
13
|
+
if (isChildSession(conversation.parentConversationId, parent)) {
|
|
14
|
+
// 还没汇报过 -> 待汇报
|
|
15
|
+
if (!conversation.reportedToParentAt) {
|
|
16
|
+
return "pending_report";
|
|
17
|
+
}
|
|
18
|
+
// 已经汇报过 -> 在汇报轴上完成,不显示任何汇报标记
|
|
19
|
+
return null;
|
|
20
|
+
}
|
|
21
|
+
// 2. 如果自己有未结束或未汇报的直接子会话
|
|
22
|
+
const hasPendingChild = directChildren.some((child) => {
|
|
23
|
+
if (child.archivedAt)
|
|
24
|
+
return false;
|
|
25
|
+
const isRunning = child.status === "running" ||
|
|
26
|
+
child.status === "waiting" ||
|
|
27
|
+
child.status === "awaiting_background";
|
|
28
|
+
const hasNotReported = !child.reportedToParentAt;
|
|
29
|
+
return isRunning || hasNotReported;
|
|
30
|
+
});
|
|
31
|
+
if (hasPendingChild) {
|
|
32
|
+
return "awaiting_subordinates";
|
|
33
|
+
}
|
|
34
|
+
// 3. 顶层会话退回到原有的「未读」逻辑
|
|
35
|
+
if (isTopLevelUnread) {
|
|
36
|
+
return "unread";
|
|
37
|
+
}
|
|
38
|
+
return null;
|
|
39
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@evandu/super-pi",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.183",
|
|
4
4
|
"description": "Web control plane and companion for Pi",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"type": "module",
|
|
@@ -127,6 +127,8 @@
|
|
|
127
127
|
"scripts/turn-failure-marks-failed.test.mjs",
|
|
128
128
|
"scripts/model-context-window.test.mjs",
|
|
129
129
|
"scripts/update-ui-contract.test.mjs",
|
|
130
|
+
"scripts/stopping-marker.test.mjs",
|
|
131
|
+
"scripts/update-button-state.test.mjs",
|
|
130
132
|
"scripts/temp-sweep.test.mjs",
|
|
131
133
|
"scripts/workspace-identity.test.mjs",
|
|
132
134
|
"scripts/followup.test.mjs",
|
|
@@ -256,6 +258,8 @@
|
|
|
256
258
|
"scripts/primary-employee-guard.test.mjs",
|
|
257
259
|
"scripts/interrupted-task-recovery.test.mjs",
|
|
258
260
|
"scripts/child-session-lock.test.mjs",
|
|
261
|
+
"scripts/child-question-lock.test.mjs",
|
|
262
|
+
"scripts/session-reporting.test.mjs",
|
|
259
263
|
"scripts/mutation-lock-coverage.test.mjs"
|
|
260
264
|
],
|
|
261
265
|
"check:browser": [
|