@evandu/super-pi 0.1.181 → 0.1.182

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 (37) hide show
  1. package/dist/client/.super-pi-client-sources.json +5 -5
  2. package/dist/client/assets/{CodeMirrorEditor-Ds5FtOmr.js → CodeMirrorEditor-DUyqaSOB.js} +2 -2
  3. package/dist/client/assets/{dist-DK6YFp_a.js → dist-AQ8CYp6b.js} +1 -1
  4. package/dist/client/assets/{dist-CGEv6ocT.js → dist-Bj218gfa.js} +1 -1
  5. package/dist/client/assets/{dist-BsB82GlW.js → dist-C7PhA7pe.js} +1 -1
  6. package/dist/client/assets/{dist-LWgwgXSp.js → dist-CB124C6Z.js} +1 -1
  7. package/dist/client/assets/{dist-BOsVN1AS.js → dist-CNem2r_T.js} +1 -1
  8. package/dist/client/assets/{dist-BSwraz5b.js → dist-CPmDYAQT.js} +1 -1
  9. package/dist/client/assets/{dist-RADY23tg.js → dist-CU8JEI5K.js} +1 -1
  10. package/dist/client/assets/{dist-28uVn4av.js → dist-CeU4Svbh.js} +1 -1
  11. package/dist/client/assets/{dist-B_251caF.js → dist-CkTZUfAR.js} +1 -1
  12. package/dist/client/assets/{dist-CT0VqErg.js → dist-CvLzvDh7.js} +1 -1
  13. package/dist/client/assets/{dist-DCYMeHTp.js → dist-D3HMZhM-.js} +1 -1
  14. package/dist/client/assets/{dist-65_o5Row.js → dist-D4lWO1EF.js} +1 -1
  15. package/dist/client/assets/{dist-Dssf0A4Z.js → dist-DLOUy-hB.js} +1 -1
  16. package/dist/client/assets/{dist-CacIUE03.js → dist-DTd2PCza.js} +1 -1
  17. package/dist/client/assets/{dist-BKMTNdOk.js → dist-Dkm31GRe.js} +1 -1
  18. package/dist/client/assets/{dist-DETrPt4i.js → dist-Dlg4MpdE.js} +1 -1
  19. package/dist/client/assets/{dist-Cc0bJ30I.js → dist-Dnx8LlEL.js} +1 -1
  20. package/dist/client/assets/{dist-yEp6eUql.js → dist-NLNoAzKl.js} +1 -1
  21. package/dist/client/assets/{dist-CDXayauu.js → dist-TX6Uhfee.js} +1 -1
  22. package/dist/client/assets/{dist-EI3JPt0D.js → dist-dnyR0Vf6.js} +1 -1
  23. package/dist/client/assets/{dist-CfLIzkuU.js → dist-ka17rnWs.js} +1 -1
  24. package/dist/client/assets/{dist-BmGTVkN5.js → dist-nbHIDjzw.js} +1 -1
  25. package/dist/client/assets/{index-DsrCbcwc.js → index-BplDWdZp.js} +15 -15
  26. package/dist/client/assets/{index-DAKtgLA9.css → index-Ui6aXMVV.css} +1 -1
  27. package/dist/client/index.html +2 -2
  28. package/dist/server/application/run-service.js +37 -14
  29. package/dist/server/http-server.js +26 -5
  30. package/dist/server/store.d.ts +2 -0
  31. package/dist/server/store.js +9 -0
  32. package/dist/server/types.d.ts +10 -0
  33. package/dist/server/update.d.ts +17 -0
  34. package/dist/server/update.js +26 -0
  35. package/dist/shared/session-reporting.d.ts +15 -0
  36. package/dist/shared/session-reporting.js +39 -0
  37. package/package.json +4 -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-DsrCbcwc.js"></script>
12
- <link rel="stylesheet" crossorigin href="/assets/index-DAKtgLA9.css">
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>
@@ -381,6 +381,7 @@ export class RunService {
381
381
  return undefined;
382
382
  const row = await this.store.addToolMessage(parentId, message, { delivery: "waiting" });
383
383
  await this.moveAheadOfUnclaimed(parentId, row.id);
384
+ await this.store.markConversationReported(input.conversationId);
384
385
  this.broadcaster.broadcastState();
385
386
  return row;
386
387
  });
@@ -1283,12 +1284,15 @@ export class RunService {
1283
1284
  // spends writing its replacement text - and by the time the file path was on screen, the block looked
1284
1285
  // broken rather than early. The placeholder word is now only the FALLBACK for the first fragment, when
1285
1286
  // Pi has not yet said what the call is or what it opens.
1287
+ // 归属在宣布时刻一次性判死:当时 thinking 活着且 answer 还没来,它就永远是 thinking 里的调用
1288
+ const callThinkingBlock = (thinkingActive && !answerAfterThinking) ? thinkingBlock : null;
1286
1289
  enqueueTools("a tool call being prepared", () => this.store.appendToolCall(conversation.id, assistant.id, {
1287
1290
  label: call.name || "工具",
1288
1291
  ...(call.detail ? { detail: call.detail } : { detail: "正在生成参数…" }),
1289
1292
  preparing: true,
1290
1293
  at,
1291
1294
  thinkingAt,
1295
+ thinkingBlock: callThinkingBlock,
1292
1296
  }));
1293
1297
  // `thinkingAt` GOES WITH THE PLACEHOLDER. It is how much reasoning had been written when the
1294
1298
  // model announced this call, and the real call needs it to work out whether the reasoning kept
@@ -1300,7 +1304,14 @@ export class RunService {
1300
1304
  // opened, and the index of the block the call belongs to is no longer the current one.
1301
1305
  // THE FOLD THIS CALL BELONGS TO, DECIDED AT THE MOMENT THE MODEL ANNOUNCED IT. A call announced
1302
1306
  // after the answer started belongs to no fold, even when the reasoning is still running.
1303
- preparingRows.set(call.contentIndex, { row, name: call.name, thinkingAt, thinkingActive, thinkingBlock: thinkingActive && !answerAfterThinking ? thinkingBlock : null });
1307
+ preparingRows.set(call.contentIndex, {
1308
+ row,
1309
+ name: call.name,
1310
+ thinkingAt,
1311
+ thinkingActive,
1312
+ thinkingBlock: callThinkingBlock,
1313
+ at,
1314
+ });
1304
1315
  };
1305
1316
  /**
1306
1317
  * THE AGENT IS ABOUT TO WRITE A FILE.
@@ -1389,19 +1400,31 @@ export class RunService {
1389
1400
  rowByToolCallId.set(call.id, row);
1390
1401
  this.noteToolCallSite(conversation.id, call.id, assistant.id, row);
1391
1402
  }
1392
- // THE FOLD WAS CAPTURED WHEN THE CALL WAS ANNOUNCED, and two facts can still dissolve it by the
1393
- // time the tool finishes. One: the reasoning had already stopped at the announcement AND the
1394
- // answer has started since - a call that only runs after the answer belongs to the answer, not
1395
- // to the fold above it. The other fact is what keeps an announced-during-the-reasoning call
1396
- // INSIDE the fold even when its tool finishes after the answer began: the reasoning KEPT
1397
- // GROWING after the announcement, which says the call is part of that reasoning. Judging by
1398
- // only one of the two moments is what made the same call land in different folds depending on
1399
- // when its tool happened to finish.
1400
- const callThinkingBlock = (prepared[1].thinkingAt < thought || !answerAfterThinking) ? prepared[1].thinkingBlock : null;
1401
- // `at` stays at the EXECUTION position: a call that belongs to no fold is drawn in the answer
1402
- // flow where its tool actually settled. `thinkingAt` stays at initiation so calls inside one
1403
- // reasoning block do not all collapse onto the final reasoning offset.
1404
- enqueueTools("a tool call", () => this.store.updateToolCall(conversation.id, assistant.id, row, { label: call.name, detail: call.detail, args: call.args, live: "", preparing: false, at, thinkingBlock: callThinkingBlock, ...(call.question ? { question: call.question } : {}) }));
1403
+ // THE FOLD WAS DECIDED WHEN THE CALL WAS ANNOUNCED, and it stays decided.
1404
+ //
1405
+ // This line used to re-judge the ownership at execution time ("the reasoning had already
1406
+ // stopped AND the answer has started since" - the two-fact rule added in 0.1.181). Two
1407
+ // judgements of one fact is one fact too many: the placeholder row was filed in the fold
1408
+ // when the model announced the call, and this line filed it back outside a moment later.
1409
+ // The reader watched the block JUMP out of the fold and into the answer flow - a wrong
1410
+ // intermediate state, even though the final state was right.
1411
+ //
1412
+ // The rule is the reader's, from 11-09: a call announced before the body text stays in the
1413
+ // block it was announced in. The announcement is the only moment that knows which block that
1414
+ // was, so it is the only moment allowed to decide.
1415
+ const callThinkingBlock = prepared[1].thinkingBlock;
1416
+ // at 也保持宣布时刻的 spoken 偏移,不按执行时刻重算;只有无占位符的调用才用执行时刻的 spoken
1417
+ const callAt = prepared[1].at;
1418
+ enqueueTools("a tool call", () => this.store.updateToolCall(conversation.id, assistant.id, row, {
1419
+ label: call.name,
1420
+ detail: call.detail,
1421
+ args: call.args,
1422
+ live: "",
1423
+ preparing: false,
1424
+ at: callAt,
1425
+ thinkingBlock: callThinkingBlock,
1426
+ ...(call.question ? { question: call.question } : {}),
1427
+ }));
1405
1428
  return;
1406
1429
  }
1407
1430
  const row = rows++;
@@ -21,7 +21,7 @@ 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";
@@ -1044,7 +1044,10 @@ export function createHttpServer(options) {
1044
1044
  };
1045
1045
  // RESTART ONLY: the code on disk is already new, the running server is not. Re-downloading
1046
1046
  // 32.8 MB to restart a process is waste; the second button asks for exactly this.
1047
+ // The outcome is recorded here as well: from the client's point of view a restart is the
1048
+ // end of the update it started, and it needs to be able to say so.
1047
1049
  if (restartOnly) {
1050
+ recordUpdateOutcome(true);
1048
1051
  release();
1049
1052
  restartNow();
1050
1053
  return;
@@ -1054,17 +1057,27 @@ export function createHttpServer(options) {
1054
1057
  const npmCmd = process.platform === "win32" ? "npm.cmd" : "npm";
1055
1058
  const update = packageUpdateArgs(rootDir, wantedVersion);
1056
1059
  const child = spawn(npmCmd, shellArgs(update.args), { stdio: "ignore", shell: process.platform === "win32", env: process.env });
1060
+ // A SPAWN THAT NEVER STARTED. Node emits "error" and THEN "close" with a null code, so
1061
+ // without this flag the close handler would read that null as a finished install and tell
1062
+ // the user the update worked when npm never ran at all.
1063
+ let spawnFailed = false;
1057
1064
  child.on("close", (code) => {
1058
- release();
1059
- if (code === 0 || code === null) {
1065
+ // THE OUTCOME IS RECORDED BEFORE THE SLOT IS RELEASED. If the slot were released first,
1066
+ // a client polling at that exact moment would see "not updating" with no outcome
1067
+ // recorded and could not tell whether the install had worked.
1068
+ if (code === 0 || (code === null && !spawnFailed)) {
1069
+ recordUpdateOutcome(true);
1070
+ release();
1060
1071
  console.log("Super Pi: npm install completed, triggering restart.");
1061
1072
  restartNow();
1062
1073
  }
1063
1074
  else {
1075
+ recordUpdateOutcome(false, typeof code === "number" ? code : undefined);
1076
+ release();
1064
1077
  console.error(`Super Pi: npm install failed with code ${code}`);
1065
1078
  }
1066
1079
  });
1067
- child.on("error", (error) => { release(); console.warn(`Super Pi: update spawn failed: ${error instanceof Error ? error.message : "unknown error"}`); });
1080
+ child.on("error", (error) => { spawnFailed = true; recordUpdateOutcome(false); release(); console.warn(`Super Pi: update spawn failed: ${error instanceof Error ? error.message : "unknown error"}`); });
1068
1081
  child.unref();
1069
1082
  return;
1070
1083
  }
@@ -1075,6 +1088,14 @@ export function createHttpServer(options) {
1075
1088
  }
1076
1089
  try {
1077
1090
  const current = checkDiskVersion(rootDir);
1091
+ // AN UPDATE IS RUNNING, so the registry question is not worth asking. The client polls
1092
+ // this endpoint every two seconds while it waits for the install to finish, and npm's
1093
+ // registry does not need one machine to ask it for the latest version a hundred times a
1094
+ // minute. While the slot is held the answer is already known, so it is answered here.
1095
+ if (isUpdateInFlight()) {
1096
+ response.writeHead(200, { "content-type": "application/json; charset=utf-8" }).end(JSON.stringify({ ...current, updating: true, lastUpdate: getLastUpdateOutcome() ?? null, updateAvailable: false }));
1097
+ return;
1098
+ }
1078
1099
  // Query the npm registry for the latest @evandu/super-pi version.
1079
1100
  const remoteVersion = await fetch("https://registry.npmjs.org/@evandu/super-pi/latest").then(async (result) => {
1080
1101
  if (!result.ok)
@@ -1082,7 +1103,7 @@ export function createHttpServer(options) {
1082
1103
  return result.json();
1083
1104
  });
1084
1105
  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) }));
1106
+ 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
1107
  }
1087
1108
  catch (error) {
1088
1109
  response.writeHead(502, { "content-type": "application/json; charset=utf-8" }).end(JSON.stringify({ error: error instanceof Error ? error.message : String(error) }));
@@ -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
  *
@@ -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
  *
@@ -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
  /**
@@ -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;
@@ -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
+ }
@@ -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.181",
3
+ "version": "0.1.182",
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,7 @@
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/session-reporting.test.mjs",
259
262
  "scripts/mutation-lock-coverage.test.mjs"
260
263
  ],
261
264
  "check:browser": [