@evandu/super-pi 0.1.179 → 0.1.181
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 +3 -3
- package/dist/client/assets/{CodeMirrorEditor-BdY_vez9.js → CodeMirrorEditor-Ds5FtOmr.js} +2 -2
- package/dist/client/assets/{dist-C_5fMTu2.js → dist-28uVn4av.js} +1 -1
- package/dist/client/assets/{dist-BzicsMSL.js → dist-65_o5Row.js} +1 -1
- package/dist/client/assets/{dist-CxZY8nws.js → dist-BKMTNdOk.js} +1 -1
- package/dist/client/assets/{dist-B_v-qVKZ.js → dist-BOsVN1AS.js} +1 -1
- package/dist/client/assets/{dist-DjsQFuR8.js → dist-BSwraz5b.js} +1 -1
- package/dist/client/assets/{dist-DfY4zXbE.js → dist-B_251caF.js} +1 -1
- package/dist/client/assets/{dist-D7S0Q68i.js → dist-BmGTVkN5.js} +1 -1
- package/dist/client/assets/{dist-tD_cG-sA.js → dist-BsB82GlW.js} +1 -1
- package/dist/client/assets/{dist-Bxp6Lr31.js → dist-CDXayauu.js} +1 -1
- package/dist/client/assets/{dist-CE4F-GnZ.js → dist-CGEv6ocT.js} +1 -1
- package/dist/client/assets/{dist-CcVJlndc.js → dist-CT0VqErg.js} +1 -1
- package/dist/client/assets/{dist-BPaSHEMs.js → dist-CacIUE03.js} +1 -1
- package/dist/client/assets/{dist-BXJ0FVm3.js → dist-Cc0bJ30I.js} +1 -1
- package/dist/client/assets/{dist-XnsZBWBb.js → dist-CfLIzkuU.js} +1 -1
- package/dist/client/assets/{dist-1AZAH0Vw.js → dist-DCYMeHTp.js} +1 -1
- package/dist/client/assets/{dist-DVYPDnbh.js → dist-DETrPt4i.js} +1 -1
- package/dist/client/assets/{dist-BXrWZekq.js → dist-DK6YFp_a.js} +1 -1
- package/dist/client/assets/{dist-RxPniecV.js → dist-Dssf0A4Z.js} +1 -1
- package/dist/client/assets/{dist-BiQDCO0Z.js → dist-EI3JPt0D.js} +1 -1
- package/dist/client/assets/{dist-Dl22kIFG.js → dist-LWgwgXSp.js} +1 -1
- package/dist/client/assets/{dist-zNY48I29.js → dist-RADY23tg.js} +1 -1
- package/dist/client/assets/{dist-D-AKDchV.js → dist-yEp6eUql.js} +1 -1
- package/dist/client/assets/{index-Cy4Cb9zB.js → index-DsrCbcwc.js} +4 -4
- package/dist/client/index.html +1 -1
- package/dist/server/application/run-service.d.ts +1 -0
- package/dist/server/application/run-service.js +56 -23
- package/dist/server/application/session-orchestrator-service.js +4 -2
- package/dist/server/command-handler.js +2 -2
- package/dist/server/http-server.js +7 -3
- package/dist/server/length-continuation.d.ts +33 -0
- package/dist/server/length-continuation.js +63 -0
- package/dist/server/update.d.ts +16 -0
- package/dist/server/update.js +20 -0
- package/package.json +3 -1
- package/scripts/restart-server.mjs +15 -2
package/dist/client/index.html
CHANGED
|
@@ -8,7 +8,7 @@
|
|
|
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-
|
|
11
|
+
<script type="module" crossorigin src="/assets/index-DsrCbcwc.js"></script>
|
|
12
12
|
<link rel="stylesheet" crossorigin href="/assets/index-DAKtgLA9.css">
|
|
13
13
|
</head>
|
|
14
14
|
<body>
|
|
@@ -86,6 +86,7 @@ export declare class RunService {
|
|
|
86
86
|
setNameIndexes(indexes: Map<string, import("../file-name-index.js").FileNameIndex>): void;
|
|
87
87
|
reviewMemoryBoundary(conversationId: string): void;
|
|
88
88
|
private readonly activeRuns;
|
|
89
|
+
private readonly lengthContinuations;
|
|
89
90
|
private readonly turnEventScopes;
|
|
90
91
|
private readonly historyCutClaims;
|
|
91
92
|
holdHistoryCut(conversationId: string): void;
|
|
@@ -6,7 +6,7 @@ import { verifyCapability } from "../capability.js";
|
|
|
6
6
|
import { capText, validateWorkflowPlan, workflowSummary } from "../workflow.js";
|
|
7
7
|
import { ensureNameIndex, recordWorkspacePath } from "../file-name-index.js";
|
|
8
8
|
import { formatTurnFailure, isLengthExceededError } from "../turn-failure.js";
|
|
9
|
-
import { isLengthContinuation, lengthContinuationText } from "../length-continuation.js";
|
|
9
|
+
import { isLengthContinuation, lengthContinuationText, MAX_LENGTH_CONTINUATIONS, buildLengthContinuationPrompt } from "../length-continuation.js";
|
|
10
10
|
import { describeThrownWithStack } from "../failure-text.js";
|
|
11
11
|
import { toWorkspaceRelative } from "../files.js";
|
|
12
12
|
import { refreshWorkspaceIndex } from "../file-index.js";
|
|
@@ -149,6 +149,7 @@ export class RunService {
|
|
|
149
149
|
this.memory?.review(conversation);
|
|
150
150
|
}
|
|
151
151
|
activeRuns = new Map();
|
|
152
|
+
lengthContinuations = new Map();
|
|
152
153
|
turnEventScopes = new Map();
|
|
153
154
|
historyCutClaims = new Map();
|
|
154
155
|
holdHistoryCut(conversationId) {
|
|
@@ -1297,7 +1298,9 @@ export class RunService {
|
|
|
1297
1298
|
// model announced the call - because that is the only moment the block it belongs to is the
|
|
1298
1299
|
// OPEN one. By the time the call runs, the reasoning may have ended and a LATER block may have
|
|
1299
1300
|
// opened, and the index of the block the call belongs to is no longer the current one.
|
|
1300
|
-
|
|
1301
|
+
// THE FOLD THIS CALL BELONGS TO, DECIDED AT THE MOMENT THE MODEL ANNOUNCED IT. A call announced
|
|
1302
|
+
// 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 });
|
|
1301
1304
|
};
|
|
1302
1305
|
/**
|
|
1303
1306
|
* THE AGENT IS ABOUT TO WRITE A FILE.
|
|
@@ -1386,12 +1389,18 @@ export class RunService {
|
|
|
1386
1389
|
rowByToolCallId.set(call.id, row);
|
|
1387
1390
|
this.noteToolCallSite(conversation.id, call.id, assistant.id, row);
|
|
1388
1391
|
}
|
|
1389
|
-
//
|
|
1390
|
-
//
|
|
1391
|
-
//
|
|
1392
|
-
|
|
1393
|
-
//
|
|
1394
|
-
//
|
|
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.
|
|
1395
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 } : {}) }));
|
|
1396
1405
|
return;
|
|
1397
1406
|
}
|
|
@@ -1409,7 +1418,11 @@ export class RunService {
|
|
|
1409
1418
|
// the reasoning still growing after the call was announced? Here the answer is read from
|
|
1410
1419
|
// `thinkingActive`, because a call with no placeholder carries no earlier offset to compare.
|
|
1411
1420
|
const thinkingAt = thought;
|
|
1412
|
-
|
|
1421
|
+
// A CALL ANNOUNCED AFTER THE ANSWER BELONGS TO NO FOLD, even when the reasoning is still running.
|
|
1422
|
+
// `currentThinkingBlock()` also marks the thinking as interrupted when it is not active, so it
|
|
1423
|
+
// must NOT be called once the answer has started - that would file an after-answer call between
|
|
1424
|
+
// two stretches of reasoning that were never separated by one.
|
|
1425
|
+
const callThinkingBlock = answerAfterThinking ? null : currentThinkingBlock();
|
|
1413
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 } : {}) }));
|
|
1414
1427
|
};
|
|
1415
1428
|
const onToolUpdate = (call) => {
|
|
@@ -1618,21 +1631,18 @@ export class RunService {
|
|
|
1618
1631
|
await pendingTools;
|
|
1619
1632
|
if (!acceptsEvent("text.delta"))
|
|
1620
1633
|
continue;
|
|
1621
|
-
// `waiting` → `running` ON THE FIRST DELTA, before the live write. The conversation was
|
|
1622
|
-
// opened in `waiting` (see `openTurn` / `openTurnOnSpecificMessage` / `openTurnOnMessage`),
|
|
1623
|
-
// and the first response token is the observable fact that says the LLM is actually
|
|
1624
|
-
// answering rather than hanging on auth / quota / network. `promoteToRunning` is a no-op
|
|
1625
|
-
// after the first signal so this stays a one-shot status write, not a per-token one.
|
|
1626
|
-
await promoteToRunning();
|
|
1627
1634
|
if (!acceptsEvent("text.delta"))
|
|
1628
1635
|
continue;
|
|
1629
|
-
|
|
1636
|
+
// THE ANSWER ENDS THE PREVIOUS THINKING STAGE, WHATEVER THE REASONING IS DOING. It used to wait
|
|
1637
|
+
// for `!thinkingActive`, which meant a model that writes text while it is still reasoning never ended
|
|
1638
|
+
// its thinking stage at all - and every call after that text was filed inside the thinking fold.
|
|
1639
|
+
if (thinkingBlock >= 0)
|
|
1630
1640
|
answerAfterThinking = true;
|
|
1631
1641
|
this.store.appendAssistantDeltaLive(conversation.id, assistant.id, delta);
|
|
1632
1642
|
spoken += delta.length;
|
|
1633
|
-
//
|
|
1634
|
-
//
|
|
1635
|
-
|
|
1643
|
+
// Promote to running AFTER the store has received the first delta, so any state
|
|
1644
|
+
// snapshot emitted carries the live delta and does not wipe out client stream bounds.
|
|
1645
|
+
await promoteToRunning();
|
|
1636
1646
|
this.broadcaster.broadcast({ type: "message.delta", conversationId: conversation.id, messageId: assistant.id, delta });
|
|
1637
1647
|
scheduleCheckpoint();
|
|
1638
1648
|
}
|
|
@@ -1836,15 +1846,16 @@ export class RunService {
|
|
|
1836
1846
|
}
|
|
1837
1847
|
await this.assertModelSupportsImages(conversation, false, message.id);
|
|
1838
1848
|
await this.runUntilDrained(conversation, workspace, composePrompt(message), controller, message.id);
|
|
1849
|
+
// Turn completed cleanly without truncation; clear any stale warning and continuation tracking
|
|
1850
|
+
this.lengthContinuations.delete(conversationId);
|
|
1851
|
+
await this.store.setWarningReason(conversationId, undefined).catch(() => undefined);
|
|
1839
1852
|
}
|
|
1840
1853
|
catch (error) {
|
|
1841
1854
|
// A TRUNCATED ANSWER IS NOT A DEAD CHILD. The model filled its single-response output budget
|
|
1842
1855
|
// and stopped mid-sentence; the work it was doing is not over. The conversation goes back to
|
|
1843
|
-
// `idle` - usable, not failed - and the
|
|
1844
|
-
// above can see that the child needs to be told to carry on rather than reported as broken.
|
|
1856
|
+
// `idle` - usable, not failed - and the error is raised so orchestrators can auto-continue.
|
|
1845
1857
|
if (isLengthExceededError(error)) {
|
|
1846
1858
|
await this.store.setStatus(conversation.id, "idle");
|
|
1847
|
-
await this.store.setWarningReason(conversationId, formatTurnFailure(error));
|
|
1848
1859
|
console.warn("Super Pi agent-dispatched turn was truncated by the output limit:", describeThrownWithStack(error));
|
|
1849
1860
|
throw error;
|
|
1850
1861
|
}
|
|
@@ -1879,6 +1890,10 @@ export class RunService {
|
|
|
1879
1890
|
if (clientId && this.store.hasMessage(conversationId, clientId))
|
|
1880
1891
|
return;
|
|
1881
1892
|
this.memory?.cancel(conversationId);
|
|
1893
|
+
if (!isLengthContinuation(content)) {
|
|
1894
|
+
this.lengthContinuations.delete(conversationId);
|
|
1895
|
+
await this.store.setWarningReason(conversationId, undefined).catch(() => undefined);
|
|
1896
|
+
}
|
|
1882
1897
|
const trimmed = content.trim();
|
|
1883
1898
|
const validImages = Array.isArray(images) && images.length > 0 ? images : undefined;
|
|
1884
1899
|
if (!trimmed && !validImages?.length)
|
|
@@ -1989,6 +2004,9 @@ export class RunService {
|
|
|
1989
2004
|
throw error;
|
|
1990
2005
|
}
|
|
1991
2006
|
await this.runUntilDrained(conversation, workspace, expanded, controller, message.id, validImages);
|
|
2007
|
+
// Turn completed cleanly without truncation; clear any stale warning and continuation tracking
|
|
2008
|
+
this.lengthContinuations.delete(conversationId);
|
|
2009
|
+
await this.store.setWarningReason(conversationId, undefined).catch(() => undefined);
|
|
1992
2010
|
}
|
|
1993
2011
|
catch (error) {
|
|
1994
2012
|
// A failing turn needs to be READ AS A FAILING TURN, not just stamped "failed" in a corner no one
|
|
@@ -2033,9 +2051,24 @@ export class RunService {
|
|
|
2033
2051
|
// send is to offer a retry, which is the wrong move: retrying asks for the same answer again
|
|
2034
2052
|
// instead of asking for the rest of this one.
|
|
2035
2053
|
if (isLengthExceededError(error)) {
|
|
2054
|
+
const used = this.lengthContinuations.get(conversation.id) ?? 0;
|
|
2055
|
+
if (used < MAX_LENGTH_CONTINUATIONS && !controller.signal.aborted) {
|
|
2056
|
+
this.lengthContinuations.set(conversation.id, used + 1);
|
|
2057
|
+
console.warn(`Super Pi turn was truncated by output limit (${used + 1}/${MAX_LENGTH_CONTINUATIONS}); auto-continuing silently.`);
|
|
2058
|
+
const lastAssistant = conversation.messages.filter((m) => m.role === "assistant").pop();
|
|
2059
|
+
const continuationPrompt = buildLengthContinuationPrompt(lastAssistant);
|
|
2060
|
+
// Auto continue without exposing warning banner to user
|
|
2061
|
+
queueMicrotask(() => {
|
|
2062
|
+
void this.enqueueAndRunAsAgent(conversation.id, continuationPrompt).catch((contErr) => {
|
|
2063
|
+
console.warn("Super Pi auto-continuation dispatch error:", describeThrownWithStack(contErr));
|
|
2064
|
+
});
|
|
2065
|
+
});
|
|
2066
|
+
return;
|
|
2067
|
+
}
|
|
2068
|
+
this.lengthContinuations.delete(conversation.id);
|
|
2036
2069
|
await this.store.setStatus(conversation.id, "idle");
|
|
2037
2070
|
await this.store.setWarningReason(conversation.id, formatTurnFailure(error));
|
|
2038
|
-
console.warn("Super Pi turn
|
|
2071
|
+
console.warn("Super Pi turn reached maximum continuations after truncation:", describeThrownWithStack(error));
|
|
2039
2072
|
return;
|
|
2040
2073
|
}
|
|
2041
2074
|
await this.store.setStatus(conversation.id, controller.signal.aborted ? "stopped" : "failed");
|
|
@@ -4,7 +4,7 @@ import { capText } from "../workflow.js";
|
|
|
4
4
|
import { assertSessionCwdInsideWorkspace } from "../session-cwd.js";
|
|
5
5
|
import { SessionWatchdog } from "./session-watchdog.js";
|
|
6
6
|
import { isLengthExceededError } from "../turn-failure.js";
|
|
7
|
-
import {
|
|
7
|
+
import { buildLengthContinuationPrompt } from "../length-continuation.js";
|
|
8
8
|
export const SESSION_OUTPUT_CHAR_LIMIT = 64 * 1024;
|
|
9
9
|
export const sessionResultRelativePath = (conversationId) => `.super-pi/session-results/${conversationId}.md`;
|
|
10
10
|
/**
|
|
@@ -347,7 +347,9 @@ export class SessionOrchestratorService {
|
|
|
347
347
|
// THE ORDER GOES IN AS A SYSTEM MESSAGE, AND THE RUN IS WAITED FOR. The child must be given
|
|
348
348
|
// the chance to finish before anything is reported to the parent - otherwise the parent would
|
|
349
349
|
// receive a result that is missing the tail the child was about to write.
|
|
350
|
-
|
|
350
|
+
const lastAssistant = this.store.conversation(conversationId)?.messages.filter((m) => m.role === "assistant").pop();
|
|
351
|
+
const prompt = buildLengthContinuationPrompt(lastAssistant);
|
|
352
|
+
await this.runService.enqueueAndRunAsAgent(conversationId, prompt);
|
|
351
353
|
await this.runService.waitForConversationIdle(conversationId);
|
|
352
354
|
}
|
|
353
355
|
catch (error) {
|
|
@@ -2,7 +2,7 @@ import { spawn } from "node:child_process";
|
|
|
2
2
|
import { join } from "node:path";
|
|
3
3
|
import { KNOWN_APIS } from "./providers.js";
|
|
4
4
|
import { CHILD_SESSION_LOCK_REASON } from "../shared/child-session-lock.js";
|
|
5
|
-
import { claimUpdateSlot, packageUpdateArgs, releaseUpdateSlot } from "./update.js";
|
|
5
|
+
import { claimUpdateSlot, packageUpdateArgs, releaseUpdateSlot, shellArgs } from "./update.js";
|
|
6
6
|
/**
|
|
7
7
|
* Routes client commands to appropriate application services and converts results or errors.
|
|
8
8
|
*/
|
|
@@ -455,7 +455,7 @@ export class CommandHandler {
|
|
|
455
455
|
throw new Error("更新已经在进行中,请等它结束");
|
|
456
456
|
const npmCmd = process.platform === "win32" ? "npm.cmd" : "npm";
|
|
457
457
|
const update = packageUpdateArgs(this.rootDir ?? import.meta.dirname);
|
|
458
|
-
const updater = spawn(npmCmd, update.args, { stdio: "inherit", shell: process.platform === "win32", env: process.env });
|
|
458
|
+
const updater = spawn(npmCmd, shellArgs(update.args), { stdio: "inherit", shell: process.platform === "win32", env: process.env });
|
|
459
459
|
// EXACTLY ONE RELEASE PER CHILD, for the same reason the HTTP endpoint does it: a spawn that
|
|
460
460
|
// fails emits "error" and then "close", and releasing twice would free the slot out from
|
|
461
461
|
// under an update that had already claimed it.
|
|
@@ -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 } from "./update.js";
|
|
24
|
+
import { claimUpdateSlot, packageUpdateArgs, 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";
|
|
@@ -1034,7 +1034,11 @@ export function createHttpServer(options) {
|
|
|
1034
1034
|
restartEnv.SUPER_PI_HOST = host;
|
|
1035
1035
|
const restartNow = () => {
|
|
1036
1036
|
console.log("Super Pi: restart triggered.");
|
|
1037
|
-
|
|
1037
|
+
// INHERIT, NOT IGNORE. The restart script says what it did - which port it found, whether
|
|
1038
|
+
// it refused to kill a process, how long the new server took to come up. With stdio
|
|
1039
|
+
// "ignore" all of that went nowhere, so a failed restart left no trace anywhere and the
|
|
1040
|
+
// only symptom was a console that had quietly died.
|
|
1041
|
+
const restart = spawn(process.execPath, [join(rootDir, "scripts", "restart-server.mjs")], { cwd: rootDir, detached: true, stdio: "inherit", env: restartEnv });
|
|
1038
1042
|
restart.on("error", (restartError) => console.error(`Super Pi: restart after update failed: ${restartError instanceof Error ? restartError.message : String(restartError)}`));
|
|
1039
1043
|
restart.unref();
|
|
1040
1044
|
};
|
|
@@ -1049,7 +1053,7 @@ export function createHttpServer(options) {
|
|
|
1049
1053
|
// npm's exit code correctly reflects whether the update succeeded.
|
|
1050
1054
|
const npmCmd = process.platform === "win32" ? "npm.cmd" : "npm";
|
|
1051
1055
|
const update = packageUpdateArgs(rootDir, wantedVersion);
|
|
1052
|
-
const child = spawn(npmCmd, update.args, { stdio: "ignore", shell: process.platform === "win32", env: process.env });
|
|
1056
|
+
const child = spawn(npmCmd, shellArgs(update.args), { stdio: "ignore", shell: process.platform === "win32", env: process.env });
|
|
1053
1057
|
child.on("close", (code) => {
|
|
1054
1058
|
release();
|
|
1055
1059
|
if (code === 0 || code === null) {
|
|
@@ -24,6 +24,10 @@
|
|
|
24
24
|
* calling it a 「智能体下发」 order would say the system sent a task, which is not what happened.
|
|
25
25
|
*/
|
|
26
26
|
export declare const LENGTH_CONTINUATION_ENVELOPE = "continue_output";
|
|
27
|
+
/**
|
|
28
|
+
* Maximum number of automatic continuations allowed per task/turn before requiring manual intervention.
|
|
29
|
+
*/
|
|
30
|
+
export declare const MAX_LENGTH_CONTINUATIONS = 3;
|
|
27
31
|
/**
|
|
28
32
|
* THE TEXT THE MODEL IS GIVEN.
|
|
29
33
|
*
|
|
@@ -40,6 +44,35 @@ export declare const LENGTH_CONTINUATION_TEXT = "\u4E0A\u4E00\u6761\u56DE\u7B54\
|
|
|
40
44
|
* the instruction rather than the markup.
|
|
41
45
|
*/
|
|
42
46
|
export declare const LENGTH_CONTINUATION_PROMPT = "<continue_output>\u4E0A\u4E00\u6761\u56DE\u7B54\u56E0\u4E3A\u8FBE\u5230\u5355\u6B21\u8F93\u51FA\u7684\u957F\u5EA6\u4E0A\u9650\u88AB\u622A\u65AD\u4E86\u3002\u8BF7\u76F4\u63A5\u4ECE\u88AB\u622A\u65AD\u7684\u5730\u65B9\u63A5\u7740\u5199\u5B8C\uFF0C\u4E0D\u8981\u91CD\u590D\u5DF2\u7ECF\u5199\u8FC7\u7684\u5185\u5BB9\u3002</continue_output>";
|
|
47
|
+
/**
|
|
48
|
+
* Extracts the tail anchor text from truncated assistant content.
|
|
49
|
+
*/
|
|
50
|
+
export declare function extractContinuationAnchor(text: string, maxLen?: number): string;
|
|
51
|
+
/**
|
|
52
|
+
* Checks whether text ends inside an unclosed code block (odd number of ```).
|
|
53
|
+
*/
|
|
54
|
+
export declare function hasUnclosedCodeBlock(text: string): boolean;
|
|
55
|
+
/**
|
|
56
|
+
* Checks whether text ends inside an unclosed thinking block (<think> without </think>).
|
|
57
|
+
*/
|
|
58
|
+
export declare function hasUnclosedThinking(text: string): boolean;
|
|
59
|
+
/**
|
|
60
|
+
* Constructs an intelligent continuation order tailored to the truncation context.
|
|
61
|
+
*
|
|
62
|
+
* When an anchor is available, pointing at the exact cut-off text gives the model an attention
|
|
63
|
+
* anchor and prevents it from freezing or emitting a single polite word.
|
|
64
|
+
*/
|
|
65
|
+
export declare function buildLengthContinuationText(assistant?: {
|
|
66
|
+
content?: unknown;
|
|
67
|
+
toolCalls?: unknown[];
|
|
68
|
+
}): string;
|
|
69
|
+
/**
|
|
70
|
+
* Builds the full enclosed continuation prompt with envelope.
|
|
71
|
+
*/
|
|
72
|
+
export declare function buildLengthContinuationPrompt(assistant?: {
|
|
73
|
+
content?: unknown;
|
|
74
|
+
toolCalls?: unknown[];
|
|
75
|
+
}): string;
|
|
43
76
|
/**
|
|
44
77
|
* Whether this content is a continuation order.
|
|
45
78
|
*/
|
|
@@ -24,6 +24,10 @@
|
|
|
24
24
|
* calling it a 「智能体下发」 order would say the system sent a task, which is not what happened.
|
|
25
25
|
*/
|
|
26
26
|
export const LENGTH_CONTINUATION_ENVELOPE = "continue_output";
|
|
27
|
+
/**
|
|
28
|
+
* Maximum number of automatic continuations allowed per task/turn before requiring manual intervention.
|
|
29
|
+
*/
|
|
30
|
+
export const MAX_LENGTH_CONTINUATIONS = 3;
|
|
27
31
|
/**
|
|
28
32
|
* THE TEXT THE MODEL IS GIVEN.
|
|
29
33
|
*
|
|
@@ -40,6 +44,65 @@ export const LENGTH_CONTINUATION_TEXT = "上一条回答因为达到单次输出
|
|
|
40
44
|
* the instruction rather than the markup.
|
|
41
45
|
*/
|
|
42
46
|
export const LENGTH_CONTINUATION_PROMPT = `<${LENGTH_CONTINUATION_ENVELOPE}>${LENGTH_CONTINUATION_TEXT}</${LENGTH_CONTINUATION_ENVELOPE}>`;
|
|
47
|
+
/**
|
|
48
|
+
* Extracts the tail anchor text from truncated assistant content.
|
|
49
|
+
*/
|
|
50
|
+
export function extractContinuationAnchor(text, maxLen = 60) {
|
|
51
|
+
const clean = text.trimEnd();
|
|
52
|
+
if (!clean)
|
|
53
|
+
return "";
|
|
54
|
+
if (clean.length <= maxLen)
|
|
55
|
+
return clean;
|
|
56
|
+
return clean.slice(-maxLen).trimStart();
|
|
57
|
+
}
|
|
58
|
+
/**
|
|
59
|
+
* Checks whether text ends inside an unclosed code block (odd number of ```).
|
|
60
|
+
*/
|
|
61
|
+
export function hasUnclosedCodeBlock(text) {
|
|
62
|
+
const matches = text.match(/```/g);
|
|
63
|
+
return Boolean(matches && matches.length % 2 === 1);
|
|
64
|
+
}
|
|
65
|
+
/**
|
|
66
|
+
* Checks whether text ends inside an unclosed thinking block (<think> without </think>).
|
|
67
|
+
*/
|
|
68
|
+
export function hasUnclosedThinking(text) {
|
|
69
|
+
const opens = (text.match(/<think>/g) || []).length;
|
|
70
|
+
const closes = (text.match(/<\/think>/g) || []).length;
|
|
71
|
+
return opens > closes;
|
|
72
|
+
}
|
|
73
|
+
/**
|
|
74
|
+
* Constructs an intelligent continuation order tailored to the truncation context.
|
|
75
|
+
*
|
|
76
|
+
* When an anchor is available, pointing at the exact cut-off text gives the model an attention
|
|
77
|
+
* anchor and prevents it from freezing or emitting a single polite word.
|
|
78
|
+
*/
|
|
79
|
+
export function buildLengthContinuationText(assistant) {
|
|
80
|
+
if (!assistant)
|
|
81
|
+
return LENGTH_CONTINUATION_TEXT;
|
|
82
|
+
// Case 1: truncation happened inside tool call arguments
|
|
83
|
+
if (Array.isArray(assistant.toolCalls) && assistant.toolCalls.length > 0) {
|
|
84
|
+
const rawContent = typeof assistant.content === "string" ? assistant.content.trim() : "";
|
|
85
|
+
if (!rawContent || rawContent.length < 20) {
|
|
86
|
+
return "上一次工具调用因参数超出单次长度上限未完整执行。请将写入或修改操作拆分为更小的批次(如使用分块写入或局部编辑模式)重新发起调用。";
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
// Case 2: textual output
|
|
90
|
+
const content = typeof assistant.content === "string" ? assistant.content : "";
|
|
91
|
+
const anchor = extractContinuationAnchor(content);
|
|
92
|
+
if (!anchor)
|
|
93
|
+
return LENGTH_CONTINUATION_TEXT;
|
|
94
|
+
if (hasUnclosedCodeBlock(content)) {
|
|
95
|
+
return `上一条代码因为达到单次输出上限在以下断点处被截断:\n\`\`\`\n${anchor}\n\`\`\`\n请直接紧接上述断点继续写完后续代码并闭合代码块,严禁寒暄,不要重复断点之前已经写过的代码。`;
|
|
96
|
+
}
|
|
97
|
+
return `上一条回答因为达到单次输出上限在以下内容处被截断:\n"${anchor}"\n请直接紧接上述断点继续写完,严禁客套寒暄,不要重复断点之前的内容。`;
|
|
98
|
+
}
|
|
99
|
+
/**
|
|
100
|
+
* Builds the full enclosed continuation prompt with envelope.
|
|
101
|
+
*/
|
|
102
|
+
export function buildLengthContinuationPrompt(assistant) {
|
|
103
|
+
const text = buildLengthContinuationText(assistant);
|
|
104
|
+
return `<${LENGTH_CONTINUATION_ENVELOPE}>${text}</${LENGTH_CONTINUATION_ENVELOPE}>`;
|
|
105
|
+
}
|
|
43
106
|
/**
|
|
44
107
|
* Whether this content is a continuation order.
|
|
45
108
|
*/
|
package/dist/server/update.d.ts
CHANGED
|
@@ -1,3 +1,19 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Quote an argument for a shell on Windows.
|
|
3
|
+
*
|
|
4
|
+
* WHY THIS EXISTS. Node runs `spawn("npm.cmd", args, { shell: true })` by CONCATENATING the
|
|
5
|
+
* arguments into one command line - it does not escape them (Node's own DEP0190 warning says
|
|
6
|
+
* exactly that). So an argument with a space in it arrives at npm in pieces: measured, a
|
|
7
|
+
* `--prefix "C:\\Users\\Some Name\\npm"` reached npm as `C:\\Users\\Some Name` and npm
|
|
8
|
+
* answered `ENOENT ... lstat ... path C:\\Users\\Some`.
|
|
9
|
+
*
|
|
10
|
+
* The npm prefix is wherever the user's npm lives, so on a machine whose home directory has a
|
|
11
|
+
* space in it the update - and the CLI's update - would fail with a path that looks truncated.
|
|
12
|
+
* Quoting here is what makes the argument survive.
|
|
13
|
+
*/
|
|
14
|
+
export declare function quoteForShell(value: string): string;
|
|
15
|
+
/** The arguments to hand to npm, quoted for the shell when the shell is what runs them. */
|
|
16
|
+
export declare function shellArgs(args: string[]): string[];
|
|
1
17
|
/**
|
|
2
18
|
* Return npm's install arguments for the package that is actually running.
|
|
3
19
|
*
|
package/dist/server/update.js
CHANGED
|
@@ -1,4 +1,24 @@
|
|
|
1
1
|
import { sep } from "node:path";
|
|
2
|
+
/**
|
|
3
|
+
* Quote an argument for a shell on Windows.
|
|
4
|
+
*
|
|
5
|
+
* WHY THIS EXISTS. Node runs `spawn("npm.cmd", args, { shell: true })` by CONCATENATING the
|
|
6
|
+
* arguments into one command line - it does not escape them (Node's own DEP0190 warning says
|
|
7
|
+
* exactly that). So an argument with a space in it arrives at npm in pieces: measured, a
|
|
8
|
+
* `--prefix "C:\\Users\\Some Name\\npm"` reached npm as `C:\\Users\\Some Name` and npm
|
|
9
|
+
* answered `ENOENT ... lstat ... path C:\\Users\\Some`.
|
|
10
|
+
*
|
|
11
|
+
* The npm prefix is wherever the user's npm lives, so on a machine whose home directory has a
|
|
12
|
+
* space in it the update - and the CLI's update - would fail with a path that looks truncated.
|
|
13
|
+
* Quoting here is what makes the argument survive.
|
|
14
|
+
*/
|
|
15
|
+
export function quoteForShell(value) {
|
|
16
|
+
return `"${String(value).replace(/"/g, '""')}"`;
|
|
17
|
+
}
|
|
18
|
+
/** The arguments to hand to npm, quoted for the shell when the shell is what runs them. */
|
|
19
|
+
export function shellArgs(args) {
|
|
20
|
+
return process.platform === "win32" ? args.map(quoteForShell) : args;
|
|
21
|
+
}
|
|
2
22
|
/**
|
|
3
23
|
* Return npm's install arguments for the package that is actually running.
|
|
4
24
|
*
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@evandu/super-pi",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.181",
|
|
4
4
|
"description": "Web control plane and companion for Pi",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"type": "module",
|
|
@@ -45,6 +45,8 @@
|
|
|
45
45
|
"check:logic": [
|
|
46
46
|
"scripts/update-args.test.mjs",
|
|
47
47
|
"scripts/update-restart.test.mjs",
|
|
48
|
+
"scripts/update-restart-budget.test.mjs",
|
|
49
|
+
"scripts/update-shell-quoting.test.mjs",
|
|
48
50
|
"scripts/update-version-pinning.test.mjs",
|
|
49
51
|
"scripts/test-runner.test.mjs",
|
|
50
52
|
"scripts/stream-checkpoint.test.mjs",
|
|
@@ -79,5 +79,18 @@ const logPath = process.env.SUPER_PI_LOG ?? "restart-server.log";
|
|
|
79
79
|
const logFd = openSync(logPath, "a");
|
|
80
80
|
const child = spawn(process.execPath, [entry], { stdio: ["ignore", logFd, logFd], detached: true, env: process.env });
|
|
81
81
|
child.unref();
|
|
82
|
-
|
|
83
|
-
|
|
82
|
+
// HOW LONG THE NEW SERVER MAY TAKE TO BECOME REACHABLE.
|
|
83
|
+
//
|
|
84
|
+
// MEASURED 2026-11-10: right after `npm install` replaced the package, a COLD start took
|
|
85
|
+
// 17.1 seconds (the same server starts in ~1.2 seconds when the files are already in the page
|
|
86
|
+
// cache). The old budget was 10 seconds, so the script killed the new server WHILE IT WAS STILL
|
|
87
|
+
// STARTING - and the result was a console that was not merely stale but DEAD: the old process had
|
|
88
|
+
// already been shut down and the new one was killed before it ever listened.
|
|
89
|
+
//
|
|
90
|
+
// A slow start must never become a dead console. The budget is generous, and when it runs out
|
|
91
|
+
// the new server is LEFT RUNNING: a start that is merely slow will still come up, and a process
|
|
92
|
+
// that is stuck is worth more than no process at all.
|
|
93
|
+
const READINESS_BUDGET_MS = 120000;
|
|
94
|
+
for (let elapsed = 0; elapsed < READINESS_BUDGET_MS; elapsed += 200) { try { const response = await fetch(`http://127.0.0.1:${port}/api/health`); const body = await response.json(); if (response.ok && body.status === "ok" && body.service === "super-pi") { console.log("Server ready: /api/health passed."); process.exit(0); } } catch {} await waitMs(200); }
|
|
95
|
+
console.error(`Server did not become reachable within ${READINESS_BUDGET_MS}ms. It is STILL RUNNING - do not kill it, a slow start still ends up serving. See ${logPath}:`); try { console.error(readFileSync(logPath, "utf8").slice(-8000)); } catch {}
|
|
96
|
+
process.exit(1);
|