pi-web-ui 0.116.0 → 0.117.0
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/CHANGELOG.md +38 -4
- package/bin/device-hub-cli.mjs +26 -3
- package/bin/pi-web-ui.mjs +138 -70
- package/dist/server/agent-service-daemon.js +52 -6
- package/dist/server/agent-service.js +495 -141
- package/dist/server/canvas/canvas-workspace.js +18 -86
- package/dist/server/client-state.js +35 -6
- package/dist/server/compaction-markers.js +43 -24
- package/dist/server/dangling-tools.js +172 -16
- package/dist/server/device-center/bot-execution.js +48 -1
- package/dist/server/device-center/collab-service.js +26 -8
- package/dist/server/device-center/collab-tool.js +394 -18
- package/dist/server/device-center/connector.js +107 -37
- package/dist/server/device-center/delivery-authority.js +98 -0
- package/dist/server/device-center/delivery-subject.js +30 -0
- package/dist/server/device-center/device-integration.js +453 -183
- package/dist/server/device-center/execution-guides.js +15 -5
- package/dist/server/device-center/executor.js +47 -5
- package/dist/server/device-center/hub-conversations.js +14 -4
- package/dist/server/device-center/hub-deliveries.js +120 -15
- package/dist/server/device-center/hub-integration.js +655 -334
- package/dist/server/device-center/hub-page.js +5 -4
- package/dist/server/device-center/hub-setup.js +23 -1
- package/dist/server/device-center/hub-transaction-log.js +197 -0
- package/dist/server/device-center/hub.js +772 -354
- package/dist/server/device-center/integration-verification.js +113 -0
- package/dist/server/device-center/local-hub.js +6 -2
- package/dist/server/device-center/local-publication.js +423 -0
- package/dist/server/device-center/local-verification-job.js +97 -0
- package/dist/server/device-center/local-verification.js +274 -0
- package/dist/server/device-center/local.js +107 -12
- package/dist/server/device-center/main.js +4 -1
- package/dist/server/device-center/partition-log.js +62 -25
- package/dist/server/device-center/publication-journal.js +312 -0
- package/dist/server/device-center/publish-intent.js +379 -0
- package/dist/server/device-center/relay.js +134 -24
- package/dist/server/device-center/runtime.js +426 -42
- package/dist/server/device-center/store.js +225 -47
- package/dist/server/device-center/task-outcome.js +81 -0
- package/dist/server/device-center/task-recovery.js +603 -178
- package/dist/server/device-center/task-settlement.js +353 -0
- package/dist/server/device-center/task-workspace.js +443 -0
- package/dist/server/device-center/verification-limits.js +10 -0
- package/dist/server/device-center/work-contract.js +995 -0
- package/dist/server/dispatch-domain-handlers.js +15 -0
- package/dist/server/dsh/dsh-agent-service.js +9 -2
- package/dist/server/index.js +26 -1
- package/dist/server/patch-node-pty.js +3 -2
- package/dist/server/patch-remote-catalog.js +3 -2
- package/dist/server/preset-fields.js +17 -1
- package/dist/server/preset-share.js +1 -0
- package/dist/server/protocol-version.js +1 -1
- package/dist/server/quick-ask-settings.js +28 -0
- package/dist/server/quick-ask.js +164 -0
- package/dist/server/resolve-global-sdk.js +61 -11
- package/dist/server/scheduler-tasks.js +35 -8
- package/dist/server/session-list-scan.js +223 -0
- package/dist/server/session-open.js +93 -0
- package/dist/server/session-parser.js +4 -0
- package/dist/server/session-scan.js +90 -38
- package/dist/server/settings-service.js +9 -1
- package/dist/server/soft-cap.js +5 -0
- package/dist/server/transcript-prepare.js +73 -0
- package/dist/server/universal/drivers/claude-code.js +98 -34
- package/dist/server/universal/universal-session.js +4 -0
- package/dist/server/workspace-handle.js +428 -0
- package/docs/architecture-plugins.md +18 -5
- package/docs/device-center.md +30 -22
- package/package.json +3 -4
- package/plugin-sdk/README.md +16 -8
- package/plugin-sdk/client.d.ts +27 -0
- package/plugin-sdk/client.mjs +82 -0
- package/plugin-sdk/index.d.ts +10 -0
- package/plugin-sdk/index.mjs +4 -683
- package/plugin-sdk/package.json +15 -4
- package/plugin-sdk/testing.d.ts +10 -0
- package/plugin-sdk/testing.mjs +566 -0
- package/themes/flow-cristallo.css +168 -0
- package/themes/flow-ink.css +169 -0
- package/themes/flow-obsidian.css +169 -0
- package/themes/flow-zurich.css +169 -0
- package/web/dist/.build-assets.json +1 -1
- package/web/dist/assets/{BgTasksModal-BDoOpj-F.js → BgTasksModal-BjNRIUIc.js} +1 -1
- package/web/dist/assets/{BgTasksModal-C0i3O1FT.js → BgTasksModal-C0zuU8FE.js} +1 -1
- package/web/dist/assets/{CanvasStudio-B8thymBN.js → CanvasStudio-BWvdmJ0M.js} +3 -3
- package/web/dist/assets/{CanvasStudio-zSxyIx1R.js → CanvasStudio-VQFjmTGq.js} +3 -3
- package/web/dist/assets/DeviceCenter-DI9_0aBB.js +3 -0
- package/web/dist/assets/DeviceCenter-DsNtXqzY.js +3 -0
- package/web/dist/assets/{DeviceExecutionSettings-q5Ik8oXg.js → DeviceExecutionSettings-BLP1Su5G.js} +1 -1
- package/web/dist/assets/DeviceGroups-2Pvk0Cds.js +1 -0
- package/web/dist/assets/DeviceGroups-CP7CcyPD.js +1 -0
- package/web/dist/assets/{Dropdown-C4LIhshN.js → Dropdown-CQtstPGv.js} +1 -1
- package/web/dist/assets/FilePreview-BMB2tNyT.js +2 -0
- package/web/dist/assets/FilePreview-RGFQUbJo.js +2 -0
- package/web/dist/assets/{GlobalSearchModal-BWgU8yPd.js → GlobalSearchModal-BM5wxiqU.js} +1 -1
- package/web/dist/assets/{GlobalSearchModal-F7fNimKk.js → GlobalSearchModal-DGv_WINq.js} +1 -1
- package/web/dist/assets/GroupConversation-B7SnuXj1.js +61 -0
- package/web/dist/assets/GroupConversation-Dda69q-2.js +61 -0
- package/web/dist/assets/{HintTip-c6d0TJoh.js → HintTip-ChTW8o1m.js} +1 -1
- package/web/dist/assets/ModelConfigModal-C-0Z4hUZ.js +2 -0
- package/web/dist/assets/ModelConfigModal-yqeadyab.js +2 -0
- package/web/dist/assets/{PiSetupModal-BmMrrgB9.js → PiSetupModal-BX5rUuoI.js} +1 -1
- package/web/dist/assets/{ProviderOAuthControls-BGSBIKD7.js → ProviderOAuthControls-DY4SCfXg.js} +1 -1
- package/web/dist/assets/SCMPanel-C4KbQvvK.js +2 -0
- package/web/dist/assets/SCMPanel-DPAyY2sW.js +2 -0
- package/web/dist/assets/SettingsModal-DxZp6D_g.js +32 -0
- package/web/dist/assets/SettingsModal-WhQzaOPt.js +32 -0
- package/web/dist/assets/{TerminalPanel-DDavKvFr.js → TerminalPanel-D4By_RVc.js} +2 -2
- package/web/dist/assets/{TerminalPanel-0CYvD72B.js → TerminalPanel-lZw8-i3j.js} +2 -2
- package/web/dist/assets/{TuiOverlayModal-BsA-QTvN.js → TuiOverlayModal-C3pAVuC8.js} +1 -1
- package/web/dist/assets/{TuiOverlayModal-DzoVQBuG.js → TuiOverlayModal-D7_rEXcJ.js} +1 -1
- package/web/dist/assets/app-globals-KqOVtmp1.js +123 -0
- package/web/dist/assets/{canvas-client-CUnXlQYX.js → canvas-client-BY6ojmle.js} +1 -1
- package/web/dist/assets/{desktop-aAKpvKJV.js → desktop-CV6KKp9R.js} +1 -1
- package/web/dist/assets/index-BawF7ZP5.js +397 -0
- package/web/dist/assets/index-BoGCoq5X.js +397 -0
- package/web/dist/assets/index-CVW9FoY2.css +1 -0
- package/web/dist/assets/{plugin-host-BRWib9DF.js → plugin-host-Dn8Dd6SC.js} +1 -1
- package/web/dist/assets/{remote-ssh-client-CfYSMEZg.js → remote-ssh-client-Dzi-eEyE.js} +1 -1
- package/web/dist/assets/{theme-D2l_mLNo.js → theme-D_bihpdN.js} +1 -1
- package/web/dist/index.html +11 -11
- package/web/dist/sw.js +1 -1
- package/dist/gh-comment-781.md +0 -5
- package/dist/server/device-center/local-page.js +0 -17
- package/dist/server/device-center/smoke-preview.js +0 -3
- package/dist/server/durable/durable-capabilities.js +0 -11
- package/dist/server/markers/builtins/services.js +0 -123
- package/dist/server/markers/builtins/todo.js +0 -189
- package/dist/server/markers-list-tool.js +0 -34
- package/dist/server/orchestrator.js +0 -109
- package/dist/server/patch-turn-end-boundary.js +0 -77
- package/dist/server/system-prompt-soul.js +0 -41
- package/dist/server/univer-service.js +0 -448
- package/dist/server/universal/drivers/dsh-driver.js +0 -379
- package/dist/test-artifact.md +0 -9
- package/dist/test-preview-modal.md +0 -11
- package/dist/test-report.html +0 -20
- package/web/dist/assets/DeviceCenter-DfAHKcid.js +0 -3
- package/web/dist/assets/DeviceCenter-ydvOTlzE.js +0 -3
- package/web/dist/assets/DeviceGroups-CI14_SRb.js +0 -1
- package/web/dist/assets/DeviceGroups-DvsB5IEU.js +0 -1
- package/web/dist/assets/FilePreview-BgGongmv.js +0 -2
- package/web/dist/assets/FilePreview-D4NrhF-U.js +0 -2
- package/web/dist/assets/GroupConversation-Dh71Pdb-.js +0 -17
- package/web/dist/assets/GroupConversation-ZK3nRmNm.js +0 -17
- package/web/dist/assets/ModelConfigModal-YVEgyy34.js +0 -2
- package/web/dist/assets/ModelConfigModal-vWtg3srp.js +0 -2
- package/web/dist/assets/SCMPanel-B8_EDxNr.js +0 -2
- package/web/dist/assets/SCMPanel-BU58qk3T.js +0 -2
- package/web/dist/assets/SettingsModal-CMUybq3J.js +0 -32
- package/web/dist/assets/SettingsModal-OBmGTh-5.js +0 -32
- package/web/dist/assets/app-globals-CZxzGvIo.js +0 -123
- package/web/dist/assets/index-C6DwztqE.css +0 -1
- package/web/dist/assets/index-CuN802Sj.js +0 -93
- package/web/dist/assets/index-EH5Fw9fa.js +0 -93
|
@@ -523,18 +523,28 @@ export class SchedulerStore {
|
|
|
523
523
|
this.changed();
|
|
524
524
|
return true;
|
|
525
525
|
}
|
|
526
|
-
async tick() {
|
|
527
|
-
const now = Date.now();
|
|
526
|
+
async tick(now = Date.now()) {
|
|
528
527
|
for (const task of this.tasks.values()) {
|
|
529
|
-
if (!task.enabled
|
|
528
|
+
if (!task.enabled)
|
|
530
529
|
continue;
|
|
531
530
|
let next = this.nextFire.get(task.id);
|
|
532
531
|
if (next === undefined) {
|
|
533
532
|
next = computeNextFire(task, Math.max(now, task.updatedAt)) ?? now + TICK_MS;
|
|
534
533
|
this.nextFire.set(task.id, next);
|
|
535
534
|
}
|
|
536
|
-
if (
|
|
537
|
-
|
|
535
|
+
if (this.running.has(task.id)) {
|
|
536
|
+
if (next <= now) {
|
|
537
|
+
// 任务已在执行中(单次执行耗时超过周期):顺延本次计划触发至下个周期,防同一任务并发重叠(issue #836)
|
|
538
|
+
const nextSlot = computeNextFire(task, now) ?? now + TICK_MS;
|
|
539
|
+
this.nextFire.set(task.id, nextSlot);
|
|
540
|
+
this.changed();
|
|
541
|
+
this.notify("info", `定时任务「${task.name}」上一轮仍在执行中,本次定时触发已顺延至下个周期(${new Date(nextSlot).toLocaleTimeString()})。`, `Scheduled task "${task.name}" is still running from previous turn; postponed to next interval (${new Date(nextSlot).toLocaleTimeString()}).`);
|
|
542
|
+
}
|
|
543
|
+
continue;
|
|
544
|
+
}
|
|
545
|
+
if (next <= now) {
|
|
546
|
+
void this.fire(task.id, false, now).catch((err) => this.reportFailure(err));
|
|
547
|
+
}
|
|
538
548
|
}
|
|
539
549
|
}
|
|
540
550
|
/** 手动立即执行一次(面板 Run Now;调试用,不扰动下次触发)。 */
|
|
@@ -546,7 +556,7 @@ export class SchedulerStore {
|
|
|
546
556
|
return { ok: false, error: "任务正在执行中" };
|
|
547
557
|
return this.fire(id, true);
|
|
548
558
|
}
|
|
549
|
-
async fire(id, manual) {
|
|
559
|
+
async fire(id, manual, triggerAt) {
|
|
550
560
|
const task = this.tasks.get(id);
|
|
551
561
|
if (!task)
|
|
552
562
|
return { ok: false, error: "任务不存在" };
|
|
@@ -562,8 +572,15 @@ export class SchedulerStore {
|
|
|
562
572
|
}
|
|
563
573
|
}
|
|
564
574
|
this.running.add(id);
|
|
565
|
-
this.changed();
|
|
566
575
|
const startedAt = Date.now();
|
|
576
|
+
const scheduleBase = triggerAt !== undefined ? Math.max(triggerAt, startedAt) : startedAt;
|
|
577
|
+
// issue #836:定时触发瞬间即刻推进 nextFire 到下一周期:
|
|
578
|
+
// 1. 面板在长任务执行期间不会停留在已过期的历史时间戳;
|
|
579
|
+
// 2. 执行时长 ≥ 任务间隔时,调度器不会停摆或遗漏后续排期。
|
|
580
|
+
if (!task.oneShot && !manual) {
|
|
581
|
+
this.nextFire.set(id, computeNextFire(task, scheduleBase) ?? scheduleBase + TICK_MS);
|
|
582
|
+
}
|
|
583
|
+
this.changed();
|
|
567
584
|
let result;
|
|
568
585
|
try {
|
|
569
586
|
result = executor
|
|
@@ -607,7 +624,17 @@ export class SchedulerStore {
|
|
|
607
624
|
this.nextFire.delete(id);
|
|
608
625
|
}
|
|
609
626
|
else if (cur && cur.enabled && !manual) {
|
|
610
|
-
|
|
627
|
+
if (cur.kind === "interval") {
|
|
628
|
+
// 间隔任务完成时按下一次周期排期(自执行结束起算,与既有单测契约对齐)
|
|
629
|
+
this.nextFire.set(id, computeNextFire(cur, Date.now()) ?? Date.now() + TICK_MS);
|
|
630
|
+
}
|
|
631
|
+
else {
|
|
632
|
+
// cron 任务若执行耗时超过原定时刻,顺延至下一个有效 cron 时间点(issue #836)
|
|
633
|
+
const currentNext = this.nextFire.get(id);
|
|
634
|
+
if (currentNext === undefined || currentNext <= Date.now()) {
|
|
635
|
+
this.nextFire.set(id, computeNextFire(cur, Date.now()) ?? Date.now() + TICK_MS);
|
|
636
|
+
}
|
|
637
|
+
}
|
|
611
638
|
}
|
|
612
639
|
this.running.delete(id);
|
|
613
640
|
this.changed();
|
|
@@ -0,0 +1,223 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 会话列表元信息扫描(左栏历史列表用):字节级、可增量。
|
|
3
|
+
*
|
|
4
|
+
* 与 parseSessionInfoFast(列表模式)提取相同字段、同一套规则:
|
|
5
|
+
* - session 头:id / cwd / timestamp / parentSession;session_info:最后一个非空 name;
|
|
6
|
+
* - message:计数、最大 message.timestamp、第一条用户消息文本;
|
|
7
|
+
* - 已拿到 id 与首条用户消息后,超过 512 字节、且不含 "session_info" 的长行不做 JSON.parse,
|
|
8
|
+
* 只看行首判断是否 message 并取第一个数值型 "timestamp"。
|
|
9
|
+
*
|
|
10
|
+
* 相对原实现的改进:
|
|
11
|
+
* 1. 按字节读取、按换行字节切行(UTF-8 中 0x0A 不会出现在多字节序列里),长行走快路径时
|
|
12
|
+
* 完全不解码成字符串、也不经过逐字符的 base64 过滤器;
|
|
13
|
+
* 2. 增量:记录最后一个完整行之后的字节偏移与两处指纹(文件头 + 偏移前一小段)。会话文件是
|
|
14
|
+
* 追加写入的,再次扫描时若两处指纹未变,只解析新增的字节;文件被改写(链修复、截断等)
|
|
15
|
+
* 指纹不符则整份重扫。末尾未写完的半行计入本次结果但不推进偏移,下次随完整行重读。
|
|
16
|
+
*/
|
|
17
|
+
import { promises as fsPromises } from "node:fs";
|
|
18
|
+
import { setImmediate } from "node:timers/promises";
|
|
19
|
+
const CHUNK_BYTES = 64 * 1024;
|
|
20
|
+
const FAST_PATH_MIN_BYTES = 512;
|
|
21
|
+
const HEAD_SIG_BYTES = 128;
|
|
22
|
+
const TAIL_SIG_BYTES = 64;
|
|
23
|
+
/** 需要完整解析的超长行先剔除内嵌 base64("data":"…"),避免把图片载荷解析成对象。 */
|
|
24
|
+
const STRIP_DATA_MIN_CHARS = 64 * 1024;
|
|
25
|
+
const DATA_VALUE_RE = /"data"\s*:\s*"(?:[^"\\]|\\.)*"/g;
|
|
26
|
+
const COLON = 0x3a;
|
|
27
|
+
const TIMESTAMP_KEY = Buffer.from('"timestamp"');
|
|
28
|
+
const SESSION_INFO_KEY = Buffer.from('"session_info"');
|
|
29
|
+
const MESSAGE_TYPE_RE = /"type"\s*:\s*"message"/;
|
|
30
|
+
function isWs(b) {
|
|
31
|
+
return b === 0x20 || b === 0x09 || b === 0x0d || b === 0x0a;
|
|
32
|
+
}
|
|
33
|
+
/** 等价于 /"timestamp"\s*:\s*(\d{10,16})/.exec(line) 的第一个匹配,直接在字节上找。 */
|
|
34
|
+
function firstNumericTimestamp(line) {
|
|
35
|
+
let from = 0;
|
|
36
|
+
for (;;) {
|
|
37
|
+
const k = line.indexOf(TIMESTAMP_KEY, from);
|
|
38
|
+
if (k < 0)
|
|
39
|
+
return null;
|
|
40
|
+
let i = k + TIMESTAMP_KEY.length;
|
|
41
|
+
while (i < line.length && isWs(line[i]))
|
|
42
|
+
i++;
|
|
43
|
+
if (line[i] === COLON) {
|
|
44
|
+
i++;
|
|
45
|
+
while (i < line.length && isWs(line[i]))
|
|
46
|
+
i++;
|
|
47
|
+
let j = i;
|
|
48
|
+
while (j < line.length && j - i < 16 && line[j] >= 0x30 && line[j] <= 0x39)
|
|
49
|
+
j++;
|
|
50
|
+
if (j - i >= 10)
|
|
51
|
+
return Number(line.toString("latin1", i, j));
|
|
52
|
+
}
|
|
53
|
+
from = k + 1;
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
function messageText(msg) {
|
|
57
|
+
if (typeof msg.content === "string")
|
|
58
|
+
return msg.content;
|
|
59
|
+
let text = "";
|
|
60
|
+
if (Array.isArray(msg.content)) {
|
|
61
|
+
for (const part of msg.content) {
|
|
62
|
+
if (part && typeof part.text === "string")
|
|
63
|
+
text += (text ? " " : "") + part.text;
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
return text;
|
|
67
|
+
}
|
|
68
|
+
function isBlank(line) {
|
|
69
|
+
for (let i = 0; i < line.length; i++)
|
|
70
|
+
if (!isWs(line[i]))
|
|
71
|
+
return false;
|
|
72
|
+
return true;
|
|
73
|
+
}
|
|
74
|
+
function applyLine(line, st) {
|
|
75
|
+
if (line.length === 0 || isBlank(line))
|
|
76
|
+
return;
|
|
77
|
+
if (st.id && st.firstMessage && line.length > FAST_PATH_MIN_BYTES && line.indexOf(SESSION_INFO_KEY) < 0) {
|
|
78
|
+
const head = line.toString("utf8", 0, 140);
|
|
79
|
+
if (MESSAGE_TYPE_RE.test(head)) {
|
|
80
|
+
st.messageCount++;
|
|
81
|
+
const ts = firstNumericTimestamp(line);
|
|
82
|
+
if (ts !== null && ts > st.lastActivityTime)
|
|
83
|
+
st.lastActivityTime = ts;
|
|
84
|
+
}
|
|
85
|
+
return;
|
|
86
|
+
}
|
|
87
|
+
let text = line.toString("utf8");
|
|
88
|
+
if (text.length > STRIP_DATA_MIN_CHARS)
|
|
89
|
+
text = text.replace(DATA_VALUE_RE, '"data":""');
|
|
90
|
+
let rec;
|
|
91
|
+
try {
|
|
92
|
+
rec = JSON.parse(text);
|
|
93
|
+
}
|
|
94
|
+
catch {
|
|
95
|
+
return;
|
|
96
|
+
}
|
|
97
|
+
if (!rec || typeof rec !== "object")
|
|
98
|
+
return;
|
|
99
|
+
if (rec.type === "session") {
|
|
100
|
+
st.id = typeof rec.id === "string" ? rec.id : "";
|
|
101
|
+
st.cwd = typeof rec.cwd === "string" ? rec.cwd : "";
|
|
102
|
+
if (typeof rec.timestamp === "string")
|
|
103
|
+
st.headerTime = new Date(rec.timestamp).getTime();
|
|
104
|
+
if (typeof rec.parentSession === "string")
|
|
105
|
+
st.parentSessionPath = rec.parentSession;
|
|
106
|
+
}
|
|
107
|
+
else if (rec.type === "session_info") {
|
|
108
|
+
if (typeof rec.name === "string" && rec.name.trim())
|
|
109
|
+
st.name = rec.name.trim();
|
|
110
|
+
}
|
|
111
|
+
else if (rec.type === "message") {
|
|
112
|
+
st.messageCount++;
|
|
113
|
+
const msg = rec.message;
|
|
114
|
+
if (msg && typeof msg === "object") {
|
|
115
|
+
if (typeof msg.timestamp === "number")
|
|
116
|
+
st.lastActivityTime = Math.max(st.lastActivityTime, msg.timestamp);
|
|
117
|
+
if (!st.firstMessage && msg.role === "user") {
|
|
118
|
+
const t = messageText(msg);
|
|
119
|
+
if (t)
|
|
120
|
+
st.firstMessage = t;
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
function emptyFields() {
|
|
126
|
+
return { id: "", cwd: "", headerTime: 0, firstMessage: "", messageCount: 0, lastActivityTime: 0 };
|
|
127
|
+
}
|
|
128
|
+
async function readSig(fh, position, length) {
|
|
129
|
+
if (length <= 0 || position < 0)
|
|
130
|
+
return "";
|
|
131
|
+
const buf = Buffer.allocUnsafe(length);
|
|
132
|
+
const { bytesRead } = await fh.read(buf, 0, length, position);
|
|
133
|
+
return buf.toString("base64", 0, bytesRead);
|
|
134
|
+
}
|
|
135
|
+
function toInfo(filePath, fileMtime, f) {
|
|
136
|
+
if (!f.id)
|
|
137
|
+
return null;
|
|
138
|
+
const modified = f.lastActivityTime > 0 ? f.lastActivityTime : f.headerTime > 0 ? f.headerTime : fileMtime;
|
|
139
|
+
return {
|
|
140
|
+
path: filePath,
|
|
141
|
+
id: f.id,
|
|
142
|
+
cwd: f.cwd,
|
|
143
|
+
name: f.name,
|
|
144
|
+
parentSessionPath: f.parentSessionPath,
|
|
145
|
+
created: new Date(f.headerTime || fileMtime),
|
|
146
|
+
modified: new Date(modified),
|
|
147
|
+
messageCount: f.messageCount,
|
|
148
|
+
firstMessage: f.firstMessage || "(no messages)",
|
|
149
|
+
allMessagesText: "",
|
|
150
|
+
};
|
|
151
|
+
}
|
|
152
|
+
/**
|
|
153
|
+
* 扫描会话文件的列表元信息。`prev` 为上次扫描的状态:文件只是被追加时,从上次偏移继续;
|
|
154
|
+
* 否则整份重扫。返回 null 仅在文件不可读时。
|
|
155
|
+
*/
|
|
156
|
+
export async function scanSessionListInfo(filePath, fileMtime, prev) {
|
|
157
|
+
let fh;
|
|
158
|
+
try {
|
|
159
|
+
fh = await fsPromises.open(filePath, "r");
|
|
160
|
+
}
|
|
161
|
+
catch {
|
|
162
|
+
return null;
|
|
163
|
+
}
|
|
164
|
+
try {
|
|
165
|
+
const size = (await fh.stat()).size;
|
|
166
|
+
const headSig = await readSig(fh, 0, Math.min(HEAD_SIG_BYTES, size));
|
|
167
|
+
let start = 0;
|
|
168
|
+
let fields = emptyFields();
|
|
169
|
+
if (prev && prev.offset > 0 && prev.offset <= size && prev.headSig === headSig) {
|
|
170
|
+
const tailLen = Math.min(TAIL_SIG_BYTES, prev.offset);
|
|
171
|
+
const tailSig = await readSig(fh, prev.offset - tailLen, tailLen);
|
|
172
|
+
if (tailSig === prev.tailSig) {
|
|
173
|
+
start = prev.offset;
|
|
174
|
+
const { offset: _o, headSig: _h, tailSig: _t, ...rest } = prev;
|
|
175
|
+
fields = { ...rest };
|
|
176
|
+
}
|
|
177
|
+
}
|
|
178
|
+
let pos = start;
|
|
179
|
+
let committed = start;
|
|
180
|
+
let pending = [];
|
|
181
|
+
for (;;) {
|
|
182
|
+
const buf = Buffer.allocUnsafe(CHUNK_BYTES);
|
|
183
|
+
const { bytesRead } = await fh.read(buf, 0, CHUNK_BYTES, pos);
|
|
184
|
+
if (bytesRead === 0)
|
|
185
|
+
break;
|
|
186
|
+
const view = buf.subarray(0, bytesRead);
|
|
187
|
+
let s = 0;
|
|
188
|
+
let nl;
|
|
189
|
+
while ((nl = view.indexOf(0x0a, s)) !== -1) {
|
|
190
|
+
const piece = view.subarray(s, nl);
|
|
191
|
+
const line = pending.length > 0 ? Buffer.concat([...pending, piece]) : piece;
|
|
192
|
+
pending = [];
|
|
193
|
+
applyLine(line, fields);
|
|
194
|
+
committed = pos + nl + 1;
|
|
195
|
+
s = nl + 1;
|
|
196
|
+
}
|
|
197
|
+
if (s < bytesRead)
|
|
198
|
+
pending.push(view.subarray(s));
|
|
199
|
+
pos += bytesRead;
|
|
200
|
+
await setImmediate();
|
|
201
|
+
}
|
|
202
|
+
const tailLen = Math.min(TAIL_SIG_BYTES, committed);
|
|
203
|
+
const state = {
|
|
204
|
+
...fields,
|
|
205
|
+
offset: committed,
|
|
206
|
+
headSig,
|
|
207
|
+
tailSig: await readSig(fh, committed - tailLen, tailLen),
|
|
208
|
+
};
|
|
209
|
+
// 末尾未写完的半行:计入本次结果,但不进入可续扫状态(下次随完整行重读)
|
|
210
|
+
let resultFields = fields;
|
|
211
|
+
if (pending.length > 0) {
|
|
212
|
+
resultFields = { ...fields };
|
|
213
|
+
applyLine(Buffer.concat(pending), resultFields);
|
|
214
|
+
}
|
|
215
|
+
return { info: toInfo(filePath, fileMtime, resultFields), state, resumedFrom: start };
|
|
216
|
+
}
|
|
217
|
+
catch {
|
|
218
|
+
return null;
|
|
219
|
+
}
|
|
220
|
+
finally {
|
|
221
|
+
await fh.close().catch(() => { });
|
|
222
|
+
}
|
|
223
|
+
}
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 打开历史会话的 SessionManager:异步读盘 + 分时片解析(C2)。
|
|
3
|
+
*
|
|
4
|
+
* SDK 的 `SessionManager.open` 用同步 readSync 读完整个转录并逐行 JSON.parse,大转录(数十 MB)
|
|
5
|
+
* 会把事件循环卡住数百毫秒——期间所有客户端的 WebSocket(流式输出、心跳、其他人的操作)一起停摆。
|
|
6
|
+
* 这里改为 fs.promises 异步读取,逐行解析时每 ~8ms 让出一次事件循环,再把解析好的条目交给 SDK
|
|
7
|
+
* (与 `SessionManager.open` 在超大头部时走的 preloadedFileEntries 是同一条构造路径)。
|
|
8
|
+
*
|
|
9
|
+
* 总 CPU 不变,变化的是「不再独占主线程」。
|
|
10
|
+
*
|
|
11
|
+
* SDK 的构造函数在类型上是 private:这里按其运行时签名
|
|
12
|
+
* `(cwd, sessionDir, sessionFile, persist, newSessionOptions, preloadedFileEntries)` 调用,
|
|
13
|
+
* 并在构造后核验结果(会话文件、会话 id、条目数);任何一步不符或抛错都回退到
|
|
14
|
+
* `SessionManager.open`,因此 SDK 将来改了签名也只会退回原行为,不会打开错的会话。
|
|
15
|
+
* `PI_WEB_ASYNC_SESSION_OPEN=0` 可强制使用原路径。
|
|
16
|
+
*
|
|
17
|
+
* 与 SDK `loadEntriesFromFile` 的语义对齐:空行 / 坏行跳过;首条必须是带字符串 id 的 session
|
|
18
|
+
* 头(否则交给 SDK 原路径处理报错 / 空文件语义);文件末尾缺换行时补一个 "\n"。
|
|
19
|
+
*/
|
|
20
|
+
import { promises as fsPromises } from "node:fs";
|
|
21
|
+
import { dirname, resolve } from "node:path";
|
|
22
|
+
import { setImmediate } from "node:timers/promises";
|
|
23
|
+
import { SessionManager } from "@earendil-works/pi-coding-agent";
|
|
24
|
+
const SLICE_MS = 8;
|
|
25
|
+
/** 逐行解析 JSONL,每 sliceMs 让出一次事件循环。规则同 SDK parseSessionEntryLine。 */
|
|
26
|
+
export async function parseJsonlSliced(raw, sliceMs = SLICE_MS) {
|
|
27
|
+
const entries = [];
|
|
28
|
+
let start = 0;
|
|
29
|
+
let sliceStart = performance.now();
|
|
30
|
+
const take = (line) => {
|
|
31
|
+
if (!line.trim())
|
|
32
|
+
return;
|
|
33
|
+
try {
|
|
34
|
+
const v = JSON.parse(line);
|
|
35
|
+
if (v)
|
|
36
|
+
entries.push(v); // SDK:`if (entry) entries.push(entry)`
|
|
37
|
+
}
|
|
38
|
+
catch {
|
|
39
|
+
// Skip malformed lines(与 SDK 一致)
|
|
40
|
+
}
|
|
41
|
+
};
|
|
42
|
+
for (;;) {
|
|
43
|
+
const nl = raw.indexOf("\n", start);
|
|
44
|
+
if (nl === -1)
|
|
45
|
+
break;
|
|
46
|
+
take(raw.slice(start, nl));
|
|
47
|
+
start = nl + 1;
|
|
48
|
+
if (performance.now() - sliceStart >= sliceMs) {
|
|
49
|
+
await setImmediate();
|
|
50
|
+
sliceStart = performance.now();
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
const tail = raw.slice(start);
|
|
54
|
+
take(tail);
|
|
55
|
+
return { entries, tail };
|
|
56
|
+
}
|
|
57
|
+
export async function openSessionManagerAsync(path) {
|
|
58
|
+
const resolvedPath = resolve(path);
|
|
59
|
+
if (process.env.PI_WEB_ASYNC_SESSION_OPEN === "0")
|
|
60
|
+
return SessionManager.open(resolvedPath);
|
|
61
|
+
let raw;
|
|
62
|
+
try {
|
|
63
|
+
raw = await fsPromises.readFile(resolvedPath, "utf8");
|
|
64
|
+
}
|
|
65
|
+
catch {
|
|
66
|
+
return SessionManager.open(resolvedPath);
|
|
67
|
+
}
|
|
68
|
+
const { entries, tail } = await parseJsonlSliced(raw);
|
|
69
|
+
const header = entries[0];
|
|
70
|
+
if (!header || header.type !== "session" || typeof header.id !== "string") {
|
|
71
|
+
// 空文件 / 非 pi 会话:交给 SDK 原路径(初始化空文件或抛出明确错误)
|
|
72
|
+
return SessionManager.open(resolvedPath);
|
|
73
|
+
}
|
|
74
|
+
try {
|
|
75
|
+
// SDK loadEntriesFromFile:头部合法且文件末尾缺换行时先补一个(在构造前,构造可能因版本迁移重写文件)
|
|
76
|
+
if (tail)
|
|
77
|
+
await fsPromises.appendFile(resolvedPath, "\n");
|
|
78
|
+
const cwd = typeof header.cwd === "string" ? header.cwd : process.cwd();
|
|
79
|
+
const Ctor = SessionManager;
|
|
80
|
+
const manager = new Ctor(cwd, dirname(resolvedPath), resolvedPath, true, undefined, entries);
|
|
81
|
+
const file = manager.getSessionFile();
|
|
82
|
+
const ok = typeof file === "string" &&
|
|
83
|
+
resolve(file) === resolvedPath &&
|
|
84
|
+
manager.getSessionId() === header.id &&
|
|
85
|
+
manager.getEntries().length === entries.length - 1;
|
|
86
|
+
if (!ok)
|
|
87
|
+
return SessionManager.open(resolvedPath);
|
|
88
|
+
return manager;
|
|
89
|
+
}
|
|
90
|
+
catch {
|
|
91
|
+
return SessionManager.open(resolvedPath);
|
|
92
|
+
}
|
|
93
|
+
}
|
|
@@ -9,6 +9,7 @@
|
|
|
9
9
|
*/
|
|
10
10
|
import { existsSync } from "node:fs";
|
|
11
11
|
import { sessionLines } from "./session-scan.js";
|
|
12
|
+
import { scanSessionListInfo } from "./session-list-scan.js";
|
|
12
13
|
import * as fsPromises from "node:fs/promises";
|
|
13
14
|
import { basename, join, resolve } from "node:path";
|
|
14
15
|
import { SessionManager } from "@earendil-works/pi-coding-agent";
|
|
@@ -155,6 +156,9 @@ export async function discoverRecentProjectsFromDisk(sessionRoots, limit = 30) {
|
|
|
155
156
|
* 逐行异步读取,内存仅保留当前 JSONL 记录及列表字段。
|
|
156
157
|
*/
|
|
157
158
|
export async function parseSessionInfoFast(filePath, fileMtime, withAllMessagesText = false) {
|
|
159
|
+
// 列表模式:字节级扫描(长行不解码、不过 base64 过滤器),规则与下方原实现一致。
|
|
160
|
+
if (!withAllMessagesText)
|
|
161
|
+
return (await scanSessionListInfo(filePath, fileMtime))?.info ?? null;
|
|
158
162
|
try {
|
|
159
163
|
let id = "";
|
|
160
164
|
let cwd = "";
|
|
@@ -2,72 +2,124 @@
|
|
|
2
2
|
* not the file or embedded binary `data` strings. */
|
|
3
3
|
import { createReadStream } from "node:fs";
|
|
4
4
|
import { setImmediate } from "node:timers/promises";
|
|
5
|
+
/** 字符串内的特殊字符(引号 / 转义 / 换行)与字符串外的「非空白或换行」:sticky 扫描用。 */
|
|
6
|
+
const STRING_SPECIAL = /["\\\n]/g;
|
|
7
|
+
const NON_WS_OR_NL = /[^\s]|\n/g;
|
|
8
|
+
function tokenIsData(token) {
|
|
9
|
+
if (token === "data")
|
|
10
|
+
return true;
|
|
11
|
+
if (token.length < 4 || !token.includes("\\"))
|
|
12
|
+
return false;
|
|
13
|
+
try {
|
|
14
|
+
return JSON.parse('"' + token + '"') === "data";
|
|
15
|
+
}
|
|
16
|
+
catch {
|
|
17
|
+
return false;
|
|
18
|
+
}
|
|
19
|
+
}
|
|
5
20
|
/** Discard JSON string values of `data` properties (embedded image/base64 payloads)
|
|
6
21
|
* before assembling lines. Preserve the empty string so JSON syntax stays valid.
|
|
7
|
-
* Text/content strings remain intact, including escaped quotes and newlines.
|
|
8
|
-
|
|
22
|
+
* Text/content strings remain intact, including escaped quotes and newlines.
|
|
23
|
+
*
|
|
24
|
+
* 状态机与原逐字符实现完全一致(差分测试见 tests/unit/session-scan-filter.test.ts),
|
|
25
|
+
* 但不再逐字符 push + 正则:字符串内用正则跳到下一个引号/转义/换行,字符串外跳到下一个
|
|
26
|
+
* 非空白字符,普通字符整段切片输出。大转录的流式扫描吞吐因此提升一个数量级。 */
|
|
27
|
+
export class BinaryStringFilter {
|
|
9
28
|
inString = false;
|
|
10
29
|
escaped = false;
|
|
11
30
|
token = "";
|
|
12
31
|
dataKey = false;
|
|
13
32
|
awaitingValue = false;
|
|
14
33
|
discard = false;
|
|
34
|
+
addToken(seg) {
|
|
35
|
+
if (this.token.length < 16)
|
|
36
|
+
this.token += seg.slice(0, 16 - this.token.length);
|
|
37
|
+
}
|
|
15
38
|
push(chunk) {
|
|
16
|
-
const
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
this.escaped = false;
|
|
21
|
-
this.discard = false;
|
|
22
|
-
}
|
|
39
|
+
const out = [];
|
|
40
|
+
const n = chunk.length;
|
|
41
|
+
let i = 0;
|
|
42
|
+
while (i < n) {
|
|
23
43
|
if (this.inString) {
|
|
24
|
-
if (!this.discard)
|
|
25
|
-
output.push(char);
|
|
26
44
|
if (this.escaped) {
|
|
45
|
+
const ch = chunk[i];
|
|
46
|
+
if (ch === "\n") {
|
|
47
|
+
// 换行重置行内状态,换行符本身按字符串外处理
|
|
48
|
+
this.inString = false;
|
|
49
|
+
this.escaped = false;
|
|
50
|
+
this.discard = false;
|
|
51
|
+
continue;
|
|
52
|
+
}
|
|
53
|
+
if (!this.discard)
|
|
54
|
+
out.push(ch);
|
|
27
55
|
this.escaped = false;
|
|
28
|
-
|
|
29
|
-
|
|
56
|
+
this.addToken(ch);
|
|
57
|
+
i++;
|
|
58
|
+
continue;
|
|
30
59
|
}
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
60
|
+
STRING_SPECIAL.lastIndex = i;
|
|
61
|
+
const m = STRING_SPECIAL.exec(chunk);
|
|
62
|
+
const j = m ? m.index : n;
|
|
63
|
+
if (j > i) {
|
|
64
|
+
const seg = chunk.slice(i, j);
|
|
65
|
+
if (!this.discard)
|
|
66
|
+
out.push(seg);
|
|
67
|
+
this.addToken(seg);
|
|
35
68
|
}
|
|
36
|
-
|
|
69
|
+
if (!m)
|
|
70
|
+
break;
|
|
71
|
+
const ch = chunk[j];
|
|
72
|
+
if (ch === "\n") {
|
|
37
73
|
this.inString = false;
|
|
38
|
-
|
|
39
|
-
output.push(char);
|
|
40
|
-
try {
|
|
41
|
-
this.dataKey = JSON.parse('"' + this.token + '"') === "data";
|
|
42
|
-
}
|
|
43
|
-
catch {
|
|
44
|
-
this.dataKey = false;
|
|
45
|
-
}
|
|
74
|
+
this.escaped = false;
|
|
46
75
|
this.discard = false;
|
|
76
|
+
i = j;
|
|
77
|
+
continue;
|
|
78
|
+
}
|
|
79
|
+
if (ch === "\\") {
|
|
80
|
+
if (!this.discard)
|
|
81
|
+
out.push(ch);
|
|
82
|
+
this.escaped = true;
|
|
83
|
+
this.addToken(ch);
|
|
84
|
+
i = j + 1;
|
|
85
|
+
continue;
|
|
47
86
|
}
|
|
48
|
-
|
|
49
|
-
|
|
87
|
+
// 收尾引号:无论是否丢弃都输出(保持 JSON 语法完整)
|
|
88
|
+
out.push('"');
|
|
89
|
+
this.inString = false;
|
|
90
|
+
this.dataKey = tokenIsData(this.token);
|
|
91
|
+
this.discard = false;
|
|
92
|
+
i = j + 1;
|
|
50
93
|
continue;
|
|
51
94
|
}
|
|
52
|
-
|
|
53
|
-
|
|
95
|
+
NON_WS_OR_NL.lastIndex = i;
|
|
96
|
+
const m = NON_WS_OR_NL.exec(chunk);
|
|
97
|
+
const j = m ? m.index : n;
|
|
98
|
+
if (j > i)
|
|
99
|
+
out.push(chunk.slice(i, j)); // 纯空白:不改变状态
|
|
100
|
+
if (!m)
|
|
101
|
+
break;
|
|
102
|
+
const ch = chunk[j];
|
|
103
|
+
out.push(ch);
|
|
104
|
+
if (ch === "\n") {
|
|
105
|
+
// JSONL records are independent, including after malformed lines.
|
|
106
|
+
this.dataKey = false;
|
|
107
|
+
this.awaitingValue = false;
|
|
108
|
+
}
|
|
109
|
+
else if (ch === '"') {
|
|
54
110
|
this.inString = true;
|
|
55
111
|
this.token = "";
|
|
56
112
|
this.discard = this.awaitingValue;
|
|
57
113
|
this.awaitingValue = false;
|
|
58
114
|
this.dataKey = false;
|
|
59
115
|
}
|
|
60
|
-
else
|
|
61
|
-
this.awaitingValue =
|
|
116
|
+
else {
|
|
117
|
+
this.awaitingValue = ch === ":" && this.dataKey;
|
|
62
118
|
this.dataKey = false;
|
|
63
119
|
}
|
|
64
|
-
|
|
65
|
-
if (char === "\n") {
|
|
66
|
-
this.dataKey = false;
|
|
67
|
-
this.awaitingValue = false;
|
|
68
|
-
}
|
|
120
|
+
i = j + 1;
|
|
69
121
|
}
|
|
70
|
-
return
|
|
122
|
+
return out.join("");
|
|
71
123
|
}
|
|
72
124
|
}
|
|
73
125
|
/** Early return and errors close the file. Non-binary text records are not capped:
|
|
@@ -9,8 +9,9 @@
|
|
|
9
9
|
import { existsSync, readFileSync } from "node:fs";
|
|
10
10
|
import { basename, dirname, join } from "node:path";
|
|
11
11
|
import { fileURLToPath } from "node:url";
|
|
12
|
+
import { mergeQuickAskSettings, normalizeQuickAskSettings } from "./quick-ask-settings.js";
|
|
12
13
|
import { extensionKey, isInternalExtension, normalizeBgCleanupMinutes, normalizeDisabledPluginTools, normalizeRetryMaxAttempts, normalizeKeepRecentMessages, normalizeSkillList, normalizeSkillsCatalogBudget, normalizeSkillsCatalogMaxDesc, normalizeSkillsFullTextMaxBytes, normalizeSkillsMaxFileBytes, normalizeToolWatchdogTimeoutMs, normalizeUiLayout, defaultSubagentAutoWakeMaxTurns, normalizeSubagentAutoWakeMaxTurns, settingsPresetToUi, } from "./client-state.js";
|
|
13
|
-
import { normalizeSoftCapByModel, normalizeSoftCapTokens } from "./soft-cap.js";
|
|
14
|
+
import { normalizeAutoCompactionInstructions, normalizeSoftCapByModel, normalizeSoftCapTokens } from "./soft-cap.js";
|
|
14
15
|
import { findVisionModels, SYSTEM_PROMPT } from "./vision-bridge.js";
|
|
15
16
|
import { COMMITMSG_SYSTEM_PROMPT } from "./scm-commitmsg.js";
|
|
16
17
|
import { PLAN_MODE_SYSTEM_PROMPT } from "./plan-mode.js";
|
|
@@ -471,6 +472,7 @@ export class SettingsService {
|
|
|
471
472
|
visionBridgePrompt: this.settings.visionBridgePrompt,
|
|
472
473
|
scmCommitMsgPromptMode: this.settings.scmCommitMsgPromptMode,
|
|
473
474
|
scmCommitMsgPrompt: this.settings.scmCommitMsgPrompt,
|
|
475
|
+
...normalizeQuickAskSettings(this.settings),
|
|
474
476
|
planModePromptMode: this.settings.planModePromptMode,
|
|
475
477
|
planModePrompt: this.settings.planModePrompt,
|
|
476
478
|
reviewPrompt: this.settings.reviewPrompt,
|
|
@@ -519,6 +521,7 @@ export class SettingsService {
|
|
|
519
521
|
retryMaxAttempts: this.settings.retryMaxAttempts,
|
|
520
522
|
softCapTokens: this.settings.softCapTokens,
|
|
521
523
|
softCapByModel: { ...this.settings.softCapByModel },
|
|
524
|
+
autoCompactionInstructions: this.settings.autoCompactionInstructions ?? "",
|
|
522
525
|
subagentModels: this.collectSubagentModels(),
|
|
523
526
|
quickPhrases: [...this.settings.quickPhrases],
|
|
524
527
|
quickPhrasesEnabled: this.settings.quickPhrasesEnabled,
|
|
@@ -786,6 +789,7 @@ export class SettingsService {
|
|
|
786
789
|
if (partial.scmCommitMsgPrompt !== undefined) {
|
|
787
790
|
next.scmCommitMsgPrompt = partial.scmCommitMsgPrompt;
|
|
788
791
|
}
|
|
792
|
+
Object.assign(next, mergeQuickAskSettings(this.settings, partial));
|
|
789
793
|
if (partial.planModePromptMode !== undefined) {
|
|
790
794
|
next.planModePromptMode = partial.planModePromptMode;
|
|
791
795
|
}
|
|
@@ -839,6 +843,10 @@ export class SettingsService {
|
|
|
839
843
|
// getRetrySettings,无需 reload runtime;见宿主 applyRetryOverrides)。
|
|
840
844
|
next.retryMaxAttempts = normalizeRetryMaxAttempts(partial.retryMaxAttempts);
|
|
841
845
|
}
|
|
846
|
+
if (partial.autoCompactionInstructions !== undefined) {
|
|
847
|
+
// 自动压缩附加指令:只影响软上限自动压缩(下一轮触发的 session.compact 即读到)。
|
|
848
|
+
next.autoCompactionInstructions = normalizeAutoCompactionInstructions(partial.autoCompactionInstructions);
|
|
849
|
+
}
|
|
842
850
|
if (partial.softCapTokens !== undefined || partial.softCapByModel !== undefined) {
|
|
843
851
|
// 压缩软上限:持久化 + 即时重算各会话的 compaction reserveTokens
|
|
844
852
|
// 覆盖(SDK 每次自动压缩检查前都重读 getCompactionSettings,无需
|
package/dist/server/soft-cap.js
CHANGED
|
@@ -88,6 +88,11 @@ export function normalizeSoftCapByModel(v) {
|
|
|
88
88
|
}
|
|
89
89
|
return out;
|
|
90
90
|
}
|
|
91
|
+
/** 自动压缩附加指令:字符串、≤2000 字(空串 = 不传,保持 SDK 默认摘要)。
|
|
92
|
+
* 只用于软上限触发的自动压缩;手动 `/compact` 与 AI 的 `compact_context` 不受影响。 */
|
|
93
|
+
export function normalizeAutoCompactionInstructions(v) {
|
|
94
|
+
return typeof v === "string" ? v.slice(0, 2000) : "";
|
|
95
|
+
}
|
|
91
96
|
/** 当前模型的生效软上限(0 = 关闭):按模型覆盖优先于全局。 */
|
|
92
97
|
export function effectiveSoftCap(globalCap, byModel, modelId) {
|
|
93
98
|
if (modelId) {
|