pi-web-ui 0.88.0 → 0.89.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 +42 -1
- package/dist/server/agent-service.js +358 -45
- package/dist/server/attachments.js +39 -0
- package/dist/server/client-state.js +22 -0
- package/dist/server/conversation-read-tool.js +325 -0
- package/dist/server/dsh/dsh-agent-service.js +32 -3
- package/dist/server/files-service.js +103 -0
- package/dist/server/index.js +258 -2
- package/dist/server/model-admin.js +285 -36
- package/dist/server/plugins.js +140 -1
- package/dist/server/scheduler-tasks.js +405 -0
- package/dist/server/settings-service.js +8 -1
- package/dist/server/terminals.js +14 -1
- package/dist/server/tool-manager.js +6 -1
- package/dist/server/update-check.js +249 -19
- package/extensions/webui.ts +9 -2
- package/package.json +3 -2
- package/plugin-sdk/index.d.ts +4 -0
- package/plugin-sdk/index.mjs +9 -0
- package/plugins/catalog.json +11 -2
- package/web/dist/assets/{TerminalPanel-CDH27dNP.js → TerminalPanel-BOUmN3uu.js} +1 -1
- package/web/dist/assets/index-3XU67qMh.js +376 -0
- package/web/dist/assets/{index-DTEcxHWs.css → index-B-gdvWtW.css} +1 -1
- package/web/dist/index.html +2 -2
- package/web/dist/assets/index-CQg5A74_.js +0 -375
|
@@ -34,7 +34,7 @@ import { MarkerService } from "./marker-service.js";
|
|
|
34
34
|
import { SlashCommandsService, parseSlash } from "./slash-commands.js";
|
|
35
35
|
import { ModelAdminService } from "./model-admin.js";
|
|
36
36
|
import { FilesService, MACHINE_ROOT, desktopDirWire, workspacePath } from "./files-service.js";
|
|
37
|
-
import { isExtensionDisabled, isExtensionEnabled, normalizeRetryMaxAttempts, normalizeSkillList, ClientStateStore, } from "./client-state.js";
|
|
37
|
+
import { isExtensionDisabled, isExtensionEnabled, normalizeDisabledPluginTools, normalizeRetryMaxAttempts, normalizeSkillList, ClientStateStore, } from "./client-state.js";
|
|
38
38
|
import { bilingual, pick, resolveServerLang } from "./i18n.js";
|
|
39
39
|
import { SubagentTemplatesStore, pickTemplatePrompt } from "./subagent-templates.js";
|
|
40
40
|
import { ComposerDraftsStore } from "./composer-drafts.js";
|
|
@@ -45,6 +45,7 @@ import { decodeText } from "./text-sniff.js";
|
|
|
45
45
|
import { makeEditSoftTool } from "./edit-soft-tool.js";
|
|
46
46
|
import { collectSubagentDescendantIds, makeSubagentTools, subagentTitle, withSubagentOwner, } from "./subagents.js";
|
|
47
47
|
import { makeDelegateTaskTool } from "./delegate-task.js";
|
|
48
|
+
import { makeConversationReadTool, parseTranscriptLines, toTranscriptInput, } from "./conversation-read-tool.js";
|
|
48
49
|
import { buildAttachmentMessages, parseModelSpec } from "./attachments.js";
|
|
49
50
|
import { buildVisionBridgePrompt, findVisionModels, transcribeImages } from "./vision-bridge.js";
|
|
50
51
|
import { BUILTIN_SOUL, DEFAULT_PROMPT_TEMPLATE, buildToolsSchemaText, renderPromptTemplate, resolveSectionTexts, } from "./prompt-composer.js";
|
|
@@ -1331,6 +1332,86 @@ export class ClientSession {
|
|
|
1331
1332
|
return !!t && t.enabled;
|
|
1332
1333
|
},
|
|
1333
1334
|
};
|
|
1335
|
+
/** conversation_read 工具的数据宿主:读本客户端的 conversation 体系 +
|
|
1336
|
+
* 落盘会话目录。运行中对话按 id(实时消息,含未落盘的);历史按 path,
|
|
1337
|
+
* 且必须是会话列表里的路径(任意文件不给读)。跨标签页的实时运行不在
|
|
1338
|
+
* this.convs 里——以落盘历史为准(工具 description 会告诉模型)。 */
|
|
1339
|
+
conversationReadHost() {
|
|
1340
|
+
return {
|
|
1341
|
+
listRunningConversations: () => {
|
|
1342
|
+
const out = [];
|
|
1343
|
+
for (const c of this.convs.values()) {
|
|
1344
|
+
let messageCount = 0;
|
|
1345
|
+
let isStreaming = false;
|
|
1346
|
+
try {
|
|
1347
|
+
messageCount = c.session.getSessionStats().totalMessages;
|
|
1348
|
+
isStreaming = c.session.isStreaming;
|
|
1349
|
+
}
|
|
1350
|
+
catch {
|
|
1351
|
+
// 会话替换中——报默认值
|
|
1352
|
+
}
|
|
1353
|
+
out.push({
|
|
1354
|
+
id: c.id,
|
|
1355
|
+
title: c.title,
|
|
1356
|
+
cwd: c.cwd,
|
|
1357
|
+
messageCount,
|
|
1358
|
+
isStreaming,
|
|
1359
|
+
isSubagent: !!c.isSubagent,
|
|
1360
|
+
...(c.parentId ? { parentId: c.parentId } : {}),
|
|
1361
|
+
});
|
|
1362
|
+
}
|
|
1363
|
+
return out;
|
|
1364
|
+
},
|
|
1365
|
+
readRunningConversation: (id) => {
|
|
1366
|
+
const c = this.convs.get(id);
|
|
1367
|
+
if (!c)
|
|
1368
|
+
return undefined;
|
|
1369
|
+
let raw = [];
|
|
1370
|
+
try {
|
|
1371
|
+
raw = (c.session.messages ??
|
|
1372
|
+
c.session.agent.state.messages ??
|
|
1373
|
+
[]);
|
|
1374
|
+
}
|
|
1375
|
+
catch {
|
|
1376
|
+
raw = [];
|
|
1377
|
+
}
|
|
1378
|
+
return { title: c.title, cwd: c.cwd, isSubagent: !!c.isSubagent, messages: raw.map(toTranscriptInput) };
|
|
1379
|
+
},
|
|
1380
|
+
listHistorySessions: async (scope, cwd) => {
|
|
1381
|
+
const infos = scope === "all"
|
|
1382
|
+
? await SessionManager.listAll(piSessionsRoot())
|
|
1383
|
+
: await SessionManager.list(cwd || this.cwd, piSessionsRoot());
|
|
1384
|
+
return infos.map((s) => ({
|
|
1385
|
+
path: s.path,
|
|
1386
|
+
name: s.name,
|
|
1387
|
+
firstMessage: s.firstMessage,
|
|
1388
|
+
messageCount: s.messageCount,
|
|
1389
|
+
modified: s.modified.getTime(),
|
|
1390
|
+
cwd: s.cwd,
|
|
1391
|
+
}));
|
|
1392
|
+
},
|
|
1393
|
+
readHistorySession: async (path) => {
|
|
1394
|
+
const all = await SessionManager.listAll(piSessionsRoot());
|
|
1395
|
+
const hit = all.find((s) => resolve(s.path) === resolve(path));
|
|
1396
|
+
if (!hit)
|
|
1397
|
+
return undefined;
|
|
1398
|
+
try {
|
|
1399
|
+
if (statSync(hit.path).size > 16 * 1024 * 1024)
|
|
1400
|
+
return undefined;
|
|
1401
|
+
const text = readFileSync(hit.path, "utf8");
|
|
1402
|
+
return {
|
|
1403
|
+
title: hit.name || hit.firstMessage,
|
|
1404
|
+
cwd: hit.cwd,
|
|
1405
|
+
sessionPath: hit.path,
|
|
1406
|
+
messages: parseTranscriptLines(text),
|
|
1407
|
+
};
|
|
1408
|
+
}
|
|
1409
|
+
catch {
|
|
1410
|
+
return undefined;
|
|
1411
|
+
}
|
|
1412
|
+
},
|
|
1413
|
+
};
|
|
1414
|
+
}
|
|
1334
1415
|
widgetsTimer = null;
|
|
1335
1416
|
/** Model-stall watchdog interval (see startStallTimer). */
|
|
1336
1417
|
stallTimer = null;
|
|
@@ -1711,9 +1792,9 @@ export class ClientSession {
|
|
|
1711
1792
|
...makePersistentTerminalTools(terminals, effectiveCwd, () => this.getLang()),
|
|
1712
1793
|
// 不覆盖内置 edit 的独立宽松编辑工具(缩进不敏感匹配;开关看设置)。
|
|
1713
1794
|
makeEditSoftTool(effectiveCwd, () => this.getLang()),
|
|
1714
|
-
// 插件注册的 AI
|
|
1715
|
-
// refreshPluginTools 动态补入已有会话)。
|
|
1716
|
-
...
|
|
1795
|
+
// 插件注册的 AI 工具(创建时刻的实时快照,已按 disabledPluginTools 过滤;
|
|
1796
|
+
// 后续注册经 refreshPluginTools 动态补入已有会话)。
|
|
1797
|
+
...this.enabledPluginToolDefs(),
|
|
1717
1798
|
// 第一方子代理工具(spawn/get_result/steer/list/stop)。子代理会话
|
|
1718
1799
|
// 也注册了它们,因此可自然嵌套派发。host 按 ownerId 包装:子代理的
|
|
1719
1800
|
// 父对话 = 真正调用 spawn 的那个会话(本 runtime 所属会话),而不是
|
|
@@ -1740,6 +1821,11 @@ export class ClientSession {
|
|
|
1740
1821
|
// 操作用户授权的页面 → page_response 回来。ownerId 语义同上(本 runtime
|
|
1741
1822
|
// 所属会话,不是派发瞬间的 active)。
|
|
1742
1823
|
makeBrowserPageTool(this, ownerId),
|
|
1824
|
+
// 别的对话读取(运行中含子代理 + 历史转录,只读):用户引用了别的
|
|
1825
|
+
// 对话(引用 chip / 粘过来的 id / “看看之前那个对话”)时用。子代理
|
|
1826
|
+
// 会话同样注册了它,可自然嵌套读取。不需要 ownerId——读的是本
|
|
1827
|
+
// 客户端的 conversation 体系与落盘历史,与派发者无关。
|
|
1828
|
+
makeConversationReadTool(this.conversationReadHost(), () => this.getLang()),
|
|
1743
1829
|
],
|
|
1744
1830
|
});
|
|
1745
1831
|
// 终端工具开关从创建起就生效(工具始终注册进注册表,只调活跃集)。
|
|
@@ -3305,7 +3391,9 @@ export class ClientSession {
|
|
|
3305
3391
|
return;
|
|
3306
3392
|
}
|
|
3307
3393
|
try {
|
|
3308
|
-
const targets = collectTargets(this.agentDir, ClientSession.currentAppVersion()
|
|
3394
|
+
const targets = collectTargets(this.agentDir, ClientSession.currentAppVersion(), undefined, {
|
|
3395
|
+
projectCwd: this.conv?.cwd ?? this.cwd,
|
|
3396
|
+
});
|
|
3309
3397
|
const items = sortUpdateItems(await checkAllUpdates(targets, undefined, () => this.getLang(), resolveNpmRegistry(this.agentDir)));
|
|
3310
3398
|
this.updatesAllCache = { at: Date.now(), items };
|
|
3311
3399
|
this.emit({ type: "update_status_all", items });
|
|
@@ -3500,6 +3588,15 @@ export class ClientSession {
|
|
|
3500
3588
|
refreshProviderModels(providerId, reqId) {
|
|
3501
3589
|
return this.modelAdmin.refreshProviderModels(providerId, reqId, () => this.getLang());
|
|
3502
3590
|
}
|
|
3591
|
+
/** Force-refresh built-in providers' official pi.dev catalogs (bypass the
|
|
3592
|
+
* SDK's 4h freshness window) — refresh_builtin_result. */
|
|
3593
|
+
refreshBuiltinModels(reqId) {
|
|
3594
|
+
return this.modelAdmin.refreshBuiltinModels(reqId);
|
|
3595
|
+
}
|
|
3596
|
+
/** Append one model to a built-in provider's models.json overlay entry. */
|
|
3597
|
+
appendBuiltinModel(providerId, model, reqId) {
|
|
3598
|
+
return this.modelAdmin.appendBuiltinModel(providerId, model, reqId);
|
|
3599
|
+
}
|
|
3503
3600
|
/** Copy a built-in provider into an editable custom-provider draft
|
|
3504
3601
|
* (clone_provider_result) — lets the user run a second API key without
|
|
3505
3602
|
* overwriting the built-in one. */
|
|
@@ -3681,6 +3778,10 @@ export class ClientSession {
|
|
|
3681
3778
|
markerChanged = true;
|
|
3682
3779
|
}
|
|
3683
3780
|
await this.settingsSvc.set(rest);
|
|
3781
|
+
if (rest.disabledPluginTools !== undefined) {
|
|
3782
|
+
this.refreshPluginTools();
|
|
3783
|
+
this.flushSnapshot();
|
|
3784
|
+
}
|
|
3684
3785
|
if (markerChanged) {
|
|
3685
3786
|
// 标记开关影响 system prompt 引导,需重载生效(流式中则延迟)
|
|
3686
3787
|
this.pushSettings();
|
|
@@ -3728,6 +3829,7 @@ export class ClientSession {
|
|
|
3728
3829
|
* 所以这两条路径之后都要重放本方法(见 reloadSession/创建处)。 */
|
|
3729
3830
|
applyToolGating(session) {
|
|
3730
3831
|
applyAgentToolsGating(session, effectiveDisabledAgentTools(this.settingsSvc.current));
|
|
3832
|
+
this.syncPluginTools(session);
|
|
3731
3833
|
// SDK 的 setActiveToolsByName 只改 agent.state.tools,不派发任何事件——门控后
|
|
3732
3834
|
// 主动推一次快照,否则快照里的 tools 要等下一个 SDK 事件才对齐(会话空闲时永远
|
|
3733
3835
|
// 等不到;回归:tests/terminal-smoke-test.mjs「agent exposes persistent terminal tools」)。
|
|
@@ -3736,11 +3838,17 @@ export class ClientSession {
|
|
|
3736
3838
|
if (active && active.session === session)
|
|
3737
3839
|
this.flushSnapshot();
|
|
3738
3840
|
}
|
|
3739
|
-
/**
|
|
3841
|
+
/** 当前启用的插件 AI 工具定义(provider 快照按 disabledPluginTools 过滤;
|
|
3842
|
+
* 未知/已卸载插件的禁用条目保留但不影响现有工具)。 */
|
|
3843
|
+
enabledPluginToolDefs() {
|
|
3844
|
+
const off = new Set(normalizeDisabledPluginTools(this.settingsSvc.current.disabledPluginTools));
|
|
3845
|
+
return (this.pluginToolsProvider?.() ?? []).filter((t) => !off.has(t.name)).map(pluginToolToDefinition);
|
|
3846
|
+
}
|
|
3847
|
+
/** 把插件 AI 工具同步进一个已存在的会话(新增/更新/移除;禁用工具同步移除)。
|
|
3740
3848
|
* 实际 diff 逻辑在 plugins.ts 的 syncPluginToolsIntoSession(可单测)。 */
|
|
3741
3849
|
syncPluginTools(session) {
|
|
3742
3850
|
try {
|
|
3743
|
-
const defs =
|
|
3851
|
+
const defs = this.enabledPluginToolDefs();
|
|
3744
3852
|
const next = syncPluginToolsIntoSession(session, defs, this.appliedPluginToolNames);
|
|
3745
3853
|
if (next)
|
|
3746
3854
|
this.appliedPluginToolNames = new Set(next);
|
|
@@ -4736,8 +4844,25 @@ export class ClientSession {
|
|
|
4736
4844
|
if (cwdChanged) {
|
|
4737
4845
|
this.cwd = newCwd;
|
|
4738
4846
|
this.roots = this.stateStore.getWorkspaceRoots(this.clientId, newCwd);
|
|
4739
|
-
|
|
4740
|
-
|
|
4847
|
+
// 模型/key 恢复不挡快照:后台做,带代际 guard(用户又切走就跳过),
|
|
4848
|
+
// 做完补一次 flush 刷新模型栏。
|
|
4849
|
+
{
|
|
4850
|
+
const convId = id;
|
|
4851
|
+
void (async () => {
|
|
4852
|
+
try {
|
|
4853
|
+
await this.restoreProjectProviderKeysForCwd(newCwd);
|
|
4854
|
+
if (this.disposed || this.activeId !== convId || this.cwd !== newCwd)
|
|
4855
|
+
return;
|
|
4856
|
+
await this.restoreProjectModelForCwd(newCwd);
|
|
4857
|
+
if (this.disposed || this.activeId !== convId || this.cwd !== newCwd)
|
|
4858
|
+
return;
|
|
4859
|
+
this.flushSnapshot();
|
|
4860
|
+
}
|
|
4861
|
+
catch {
|
|
4862
|
+
/* 静默:恢复失败保持会话默认 */
|
|
4863
|
+
}
|
|
4864
|
+
})();
|
|
4865
|
+
}
|
|
4741
4866
|
// Mirror set_cwd's project-switch side-effects so the whole UI follows
|
|
4742
4867
|
// the new workspace, not just the chat pane.
|
|
4743
4868
|
try {
|
|
@@ -4748,7 +4873,7 @@ export class ClientSession {
|
|
|
4748
4873
|
}
|
|
4749
4874
|
this.stateStore.remember(this.clientId, newCwd);
|
|
4750
4875
|
void this.pushProjects();
|
|
4751
|
-
|
|
4876
|
+
this.refreshSessionsOnSwitch();
|
|
4752
4877
|
void this.listFiles(undefined);
|
|
4753
4878
|
void this.listCommands();
|
|
4754
4879
|
}
|
|
@@ -4817,6 +4942,16 @@ export class ClientSession {
|
|
|
4817
4942
|
messageCount,
|
|
4818
4943
|
isStreaming,
|
|
4819
4944
|
isSubagent: !!conv.isSubagent,
|
|
4945
|
+
// 落盘会话才有文件(inMemory 子代理缺省):右键复制路径 / AI 按 path 读历史时用。
|
|
4946
|
+
...(() => {
|
|
4947
|
+
try {
|
|
4948
|
+
const f = conv.session.sessionFile;
|
|
4949
|
+
return f ? { sessionFile: f } : {};
|
|
4950
|
+
}
|
|
4951
|
+
catch {
|
|
4952
|
+
return {};
|
|
4953
|
+
}
|
|
4954
|
+
})(),
|
|
4820
4955
|
// 子代理带 error 标记:左栏红点提示(普通对话不参与)。
|
|
4821
4956
|
...(conv.isSubagent ? this.subagentRunOutcome(conv) : {}),
|
|
4822
4957
|
parentId: conv.parentId,
|
|
@@ -4863,6 +4998,12 @@ export class ClientSession {
|
|
|
4863
4998
|
*/
|
|
4864
4999
|
sessionInfosCache = null;
|
|
4865
5000
|
static SESSION_INFO_CACHE_TTL = 3000;
|
|
5001
|
+
/** 最近项目列表缓存:pushProjects 的全量扫盘(SessionManager.listAll +
|
|
5002
|
+
* existsSync 逐个校验)昂贵,切项目/新对话/跨客户端通知时频繁触发 ——
|
|
5003
|
+
* TTL 内直接复用并把当前 cwd 合并进去,不反复扫盘。 */
|
|
5004
|
+
projectsCache = null;
|
|
5005
|
+
static PROJECTS_CACHE_TTL = 15_000;
|
|
5006
|
+
projectsInFlight = null;
|
|
4866
5007
|
async loadSessionInfos() {
|
|
4867
5008
|
const now = Date.now();
|
|
4868
5009
|
const c = this.sessionInfosCache;
|
|
@@ -4885,6 +5026,13 @@ export class ClientSession {
|
|
|
4885
5026
|
this.sessionsRequested = true;
|
|
4886
5027
|
await this.pushSessions();
|
|
4887
5028
|
}
|
|
5029
|
+
/** 切项目时的会话列表刷新:历史面板没打开过就不扫盘(只清缓存),打开过
|
|
5030
|
+
* 才重推 —— 首访切项目的转录解析不在关键路径上。 */
|
|
5031
|
+
refreshSessionsOnSwitch() {
|
|
5032
|
+
this.invalidateSessionInfos();
|
|
5033
|
+
if (this.sessionsRequested)
|
|
5034
|
+
void this.refreshSessions();
|
|
5035
|
+
}
|
|
4888
5036
|
async pushSessions() {
|
|
4889
5037
|
if (!this.sessionsRequested)
|
|
4890
5038
|
return;
|
|
@@ -4916,6 +5064,7 @@ export class ClientSession {
|
|
|
4916
5064
|
/** Remove an entry from the client's recent-project list (UI state only). */
|
|
4917
5065
|
async removeProject(path) {
|
|
4918
5066
|
this.stateStore.removeProject(this.clientId, path);
|
|
5067
|
+
this.invalidateProjectsCache();
|
|
4919
5068
|
await this.pushProjects();
|
|
4920
5069
|
}
|
|
4921
5070
|
/** Permanently delete a persisted session transcript file (history list ✕).
|
|
@@ -5105,7 +5254,8 @@ export class ClientSession {
|
|
|
5105
5254
|
this.emitConversations();
|
|
5106
5255
|
}
|
|
5107
5256
|
/** Dismiss 口径的「已结束子代理」:非 streaming 且无保留态(存活终端/
|
|
5108
|
-
* 审查/后台唤醒等),与 dismissFinishedSubagents 的候选口径一致。
|
|
5257
|
+
* 审查/后台唤醒等),与 dismissFinishedSubagents 的候选口径一致。
|
|
5258
|
+
* issue #181:终端只看用户终端,残留 AI bash 不算(随移出一起释放)。 */
|
|
5109
5259
|
isDismissableFinishedSubagent(conv) {
|
|
5110
5260
|
let streaming = true;
|
|
5111
5261
|
try {
|
|
@@ -5120,8 +5270,8 @@ export class ClientSession {
|
|
|
5120
5270
|
reviewing: conv.goal.reviewing,
|
|
5121
5271
|
wizardRunning: conv.wizardRunning,
|
|
5122
5272
|
streaming: false,
|
|
5123
|
-
//
|
|
5124
|
-
openTerminals: conv.terminals.
|
|
5273
|
+
// Dismiss 口径:只看“用过”的用户终端(AI bash 不钉住,见上)。
|
|
5274
|
+
openTerminals: conv.terminals.countUserBlockingLive(),
|
|
5125
5275
|
listed: false,
|
|
5126
5276
|
promptedSinceActive: false,
|
|
5127
5277
|
hasActiveSubagentRun: () => hasActiveSubagentRun({ sessionId: conv.session.sessionFile }),
|
|
@@ -5192,7 +5342,10 @@ export class ClientSession {
|
|
|
5192
5342
|
});
|
|
5193
5343
|
return;
|
|
5194
5344
|
}
|
|
5195
|
-
|
|
5345
|
+
// issue #181:只看用户终端——AI bash(agentBash)是 agent 的内部执行记录,
|
|
5346
|
+
// 随对话一起释放(removeConversation 里 killAll),不得阻断移出;否则残留的
|
|
5347
|
+
// ai-bash-98/99 会把会话永久钉在列表里。用户亲手开且用过的终端仍拦截。
|
|
5348
|
+
if (conv.terminals.countUserBlockingLive() > 0) {
|
|
5196
5349
|
this.emit({
|
|
5197
5350
|
type: "notice",
|
|
5198
5351
|
level: "warning",
|
|
@@ -5201,7 +5354,7 @@ export class ClientSession {
|
|
|
5201
5354
|
});
|
|
5202
5355
|
return;
|
|
5203
5356
|
}
|
|
5204
|
-
// 没动过的空 shell(点开终端 tab
|
|
5357
|
+
// 没动过的空 shell(点开终端 tab 自动建的那个)与 AI bash 不拦截:随对话一起释放
|
|
5205
5358
|
// (removeConversation 里 killAll)。
|
|
5206
5359
|
if (shouldRetainActive({
|
|
5207
5360
|
reviewing: conv.goal.reviewing,
|
|
@@ -5455,8 +5608,8 @@ export class ClientSession {
|
|
|
5455
5608
|
reviewing: conv.goal.reviewing,
|
|
5456
5609
|
wizardRunning: conv.wizardRunning,
|
|
5457
5610
|
streaming: false,
|
|
5458
|
-
//
|
|
5459
|
-
openTerminals: conv.terminals.
|
|
5611
|
+
// Dismiss 口径:只看“用过”的用户终端(issue #181,AI bash 不钉住)。
|
|
5612
|
+
openTerminals: conv.terminals.countUserBlockingLive(),
|
|
5460
5613
|
listed: false,
|
|
5461
5614
|
promptedSinceActive: false,
|
|
5462
5615
|
hasActiveSubagentRun: () => hasActiveSubagentRun({ sessionId: conv.session.sessionFile }),
|
|
@@ -5747,34 +5900,77 @@ export class ClientSession {
|
|
|
5747
5900
|
* opened before the recent-list feature existed still show up).
|
|
5748
5901
|
*/
|
|
5749
5902
|
async pushProjects() {
|
|
5750
|
-
|
|
5751
|
-
|
|
5752
|
-
|
|
5753
|
-
|
|
5754
|
-
|
|
5755
|
-
|
|
5756
|
-
|
|
5757
|
-
|
|
5758
|
-
|
|
5759
|
-
|
|
5760
|
-
|
|
5761
|
-
|
|
5762
|
-
|
|
5763
|
-
|
|
5903
|
+
const now = Date.now();
|
|
5904
|
+
const cached = this.projectsCache;
|
|
5905
|
+
// TTL 命中:直接复用(把当前 cwd 合并进去,刚 remember 的新项目也可见)。
|
|
5906
|
+
if (cached && now - cached.at < ClientSession.PROJECTS_CACHE_TTL) {
|
|
5907
|
+
this.emit({ type: "projects", projects: this.withCurrentCwd(cached.projects, now) });
|
|
5908
|
+
return;
|
|
5909
|
+
}
|
|
5910
|
+
// 已有扫描在跑:搭车等它,不要并发扫两遍盘。
|
|
5911
|
+
if (this.projectsInFlight) {
|
|
5912
|
+
try {
|
|
5913
|
+
const projects = await this.projectsInFlight;
|
|
5914
|
+
if (projects)
|
|
5915
|
+
this.emit({ type: "projects", projects: this.withCurrentCwd(projects, Date.now()) });
|
|
5916
|
+
}
|
|
5917
|
+
catch {
|
|
5918
|
+
/* 首发扫描已自行 emit 错误结果,这里不再补 */
|
|
5764
5919
|
}
|
|
5765
|
-
|
|
5766
|
-
// is useless in the picker. Tombstoned entries (explicitly removed by
|
|
5767
|
-
// the user) stay hidden even though session files still mention them.
|
|
5768
|
-
const projects = [...map.entries()]
|
|
5769
|
-
.filter(([path]) => !removedProjects.has(path) && existsSync(path))
|
|
5770
|
-
.map(([path, lastUsed]) => ({ path, lastUsed }))
|
|
5771
|
-
.sort((a, b) => b.lastUsed - a.lastUsed)
|
|
5772
|
-
.slice(0, 20);
|
|
5773
|
-
this.emit({ type: "projects", projects });
|
|
5920
|
+
return;
|
|
5774
5921
|
}
|
|
5775
|
-
|
|
5776
|
-
|
|
5922
|
+
const run = (async () => {
|
|
5923
|
+
try {
|
|
5924
|
+
const saved = this.stateStore.get(this.clientId);
|
|
5925
|
+
const removedProjects = new Set(this.stateStore.getRemovedProjects(this.clientId));
|
|
5926
|
+
const map = new Map();
|
|
5927
|
+
for (const p of saved.projects)
|
|
5928
|
+
map.set(p.path, p.lastUsed);
|
|
5929
|
+
const all = await SessionManager.listAll(piSessionsRoot());
|
|
5930
|
+
for (const s of all) {
|
|
5931
|
+
if (s.cwd) {
|
|
5932
|
+
const t = s.modified.getTime();
|
|
5933
|
+
const prev = map.get(s.cwd);
|
|
5934
|
+
if (prev === undefined || t > prev)
|
|
5935
|
+
map.set(s.cwd, t);
|
|
5936
|
+
}
|
|
5937
|
+
}
|
|
5938
|
+
// Only keep directories that still exist — a deleted/unmounted workspace
|
|
5939
|
+
// is useless in the picker. Tombstoned entries (explicitly removed by
|
|
5940
|
+
// the user) stay hidden even though session files still mention them.
|
|
5941
|
+
const projects = [...map.entries()]
|
|
5942
|
+
.filter(([path]) => !removedProjects.has(path) && existsSync(path))
|
|
5943
|
+
.map(([path, lastUsed]) => ({ path, lastUsed }))
|
|
5944
|
+
.sort((a, b) => b.lastUsed - a.lastUsed)
|
|
5945
|
+
.slice(0, 20);
|
|
5946
|
+
this.projectsCache = { at: Date.now(), projects };
|
|
5947
|
+
this.emit({ type: "projects", projects });
|
|
5948
|
+
return projects;
|
|
5949
|
+
}
|
|
5950
|
+
catch {
|
|
5951
|
+
this.emit({ type: "projects", projects: [] });
|
|
5952
|
+
return null;
|
|
5953
|
+
}
|
|
5954
|
+
finally {
|
|
5955
|
+
this.projectsInFlight = null;
|
|
5956
|
+
}
|
|
5957
|
+
})();
|
|
5958
|
+
this.projectsInFlight = run;
|
|
5959
|
+
await run;
|
|
5960
|
+
}
|
|
5961
|
+
/** 缓存命中时把当前 cwd 并进去:命中则刷新 lastUsed 重排,未命中则补到首位
|
|
5962
|
+
* (remember 刚写入的新项目在 TTL 窗口内也可见,不必等下一次扫盘)。 */
|
|
5963
|
+
withCurrentCwd(projects, now) {
|
|
5964
|
+
if (projects.some((p) => p.path === this.cwd)) {
|
|
5965
|
+
return projects
|
|
5966
|
+
.map((p) => (p.path === this.cwd && p.lastUsed < now ? { ...p, lastUsed: now } : p))
|
|
5967
|
+
.sort((a, b) => b.lastUsed - a.lastUsed);
|
|
5777
5968
|
}
|
|
5969
|
+
return [{ path: this.cwd, lastUsed: now }, ...projects].slice(0, 20);
|
|
5970
|
+
}
|
|
5971
|
+
/** 最近项目缓存失效(用户显式移除项目后,下一次推送必须重扫)。 */
|
|
5972
|
+
invalidateProjectsCache() {
|
|
5973
|
+
this.projectsCache = null;
|
|
5778
5974
|
}
|
|
5779
5975
|
/** List a workspace directory (relative to the configured cwd). */
|
|
5780
5976
|
async listFiles(relPath) {
|
|
@@ -5849,6 +6045,14 @@ export class ClientSession {
|
|
|
5849
6045
|
async copyEntry(src, destDir, move) {
|
|
5850
6046
|
return this.files.copyEntry(src, destDir, move);
|
|
5851
6047
|
}
|
|
6048
|
+
/** 文件树右键菜单:在系统资源管理器中定位(issue #187)。 */
|
|
6049
|
+
async revealEntry(path) {
|
|
6050
|
+
return this.files.revealEntry(path);
|
|
6051
|
+
}
|
|
6052
|
+
/** 文件树右键菜单:用系统默认应用打开文件(issue #187)。 */
|
|
6053
|
+
async openDefaultEntry(path) {
|
|
6054
|
+
return this.files.openDefaultEntry(path);
|
|
6055
|
+
}
|
|
5852
6056
|
async makeDir(relPath) {
|
|
5853
6057
|
return this.files.makeDir(relPath);
|
|
5854
6058
|
}
|
|
@@ -5965,6 +6169,15 @@ export class ClientSession {
|
|
|
5965
6169
|
this.removeConversation(displaced.id);
|
|
5966
6170
|
}
|
|
5967
6171
|
else {
|
|
6172
|
+
// 冷切换的 runtime 创建要 1~2s(扫技能/扩展)—— 先回一条 ack +
|
|
6173
|
+
// 快照,点击看起来不再 frozen;落地后再推第二次全量。
|
|
6174
|
+
this.emit({
|
|
6175
|
+
type: "notice",
|
|
6176
|
+
level: "info",
|
|
6177
|
+
text: `正在切换到工作目录:${abs}`,
|
|
6178
|
+
textEn: `Switching to directory: ${abs}`,
|
|
6179
|
+
});
|
|
6180
|
+
this.flushSnapshot();
|
|
5968
6181
|
// First visit to this project: resume its most recent session —
|
|
5969
6182
|
// unless that transcript is streaming on another client (#145):
|
|
5970
6183
|
// default-opening it would strand the tab on a conversation it
|
|
@@ -6019,8 +6232,25 @@ export class ClientSession {
|
|
|
6019
6232
|
this.conv.lastActiveAt = Date.now();
|
|
6020
6233
|
this.cwd = abs;
|
|
6021
6234
|
this.roots = this.stateStore.getWorkspaceRoots(this.clientId, abs);
|
|
6022
|
-
|
|
6023
|
-
|
|
6235
|
+
// 模型/key 恢复不挡快照:后台做,带切换代际 guard(用户又切走就跳过,
|
|
6236
|
+
// 否则会把旧项目的 key 套到新对话上),做完补一次 flush 刷新模型栏。
|
|
6237
|
+
{
|
|
6238
|
+
const convId = this.activeId;
|
|
6239
|
+
void (async () => {
|
|
6240
|
+
try {
|
|
6241
|
+
await this.restoreProjectProviderKeysForCwd(abs);
|
|
6242
|
+
if (this.disposed || this.activeId !== convId || this.cwd !== abs)
|
|
6243
|
+
return;
|
|
6244
|
+
await this.restoreProjectModelForCwd(abs);
|
|
6245
|
+
if (this.disposed || this.activeId !== convId || this.cwd !== abs)
|
|
6246
|
+
return;
|
|
6247
|
+
this.flushSnapshot();
|
|
6248
|
+
}
|
|
6249
|
+
catch {
|
|
6250
|
+
/* 静默:恢复失败保持会话默认 */
|
|
6251
|
+
}
|
|
6252
|
+
})();
|
|
6253
|
+
}
|
|
6024
6254
|
// 工作区跟随型插件(编辑器文件树等)同步切根。
|
|
6025
6255
|
try {
|
|
6026
6256
|
this.onCwdChanged?.(abs, this.roots);
|
|
@@ -6042,7 +6272,7 @@ export class ClientSession {
|
|
|
6042
6272
|
text: `已切换到工作目录:${abs}`,
|
|
6043
6273
|
textEn: `Switched to directory: ${abs}`,
|
|
6044
6274
|
});
|
|
6045
|
-
|
|
6275
|
+
this.refreshSessionsOnSwitch();
|
|
6046
6276
|
void this.listFiles(undefined);
|
|
6047
6277
|
// Commands are per-project (.pi/commands.json in the current cwd).
|
|
6048
6278
|
void this.listCommands();
|
|
@@ -6452,6 +6682,89 @@ export class AgentService {
|
|
|
6452
6682
|
void cs.prompt(text);
|
|
6453
6683
|
return { conversationId: before, clientId };
|
|
6454
6684
|
}
|
|
6685
|
+
/** 内置定时任务的无头执行(issue #184,server/scheduler-tasks.ts 的 executor)。
|
|
6686
|
+
* 每个任务独立伪客户端 `scheduler:<taskId>`(专属会话连续、无浏览器也能跑);
|
|
6687
|
+
* cwd 按任务配置 pin 住(不存在即失败,不默默跑错目录);可选模型/思考强度
|
|
6688
|
+
* 在投递前应用(失败即返回错误,不回落,避免账单/效果与预期不符)。
|
|
6689
|
+
* fire-and-forget 投递后等待运行结束(最长 10 分钟轮询),回填真实 outcome
|
|
6690
|
+
* (成功/失败/耗时/会话 id)供历史记录与通知使用;超时按失败记录(运行本身
|
|
6691
|
+
* 不中止,继续在后台跑完)。 */
|
|
6692
|
+
async chatFromScheduler(task) {
|
|
6693
|
+
const safe = String(task.id ?? "task").replace(/[^A-Za-z0-9_-]/g, "") || "task";
|
|
6694
|
+
const clientId = `scheduler:${safe}`;
|
|
6695
|
+
const text = String(task.prompt ?? "");
|
|
6696
|
+
if (!text.trim())
|
|
6697
|
+
return { ok: false, error: "触发指令为空" };
|
|
6698
|
+
if (this.quiesced)
|
|
6699
|
+
return { ok: false, error: "服务器正忙(quiesced),请稍后重试" };
|
|
6700
|
+
const cwd = String(task.cwd ?? "").trim();
|
|
6701
|
+
try {
|
|
6702
|
+
if (!cwd || !statSync(cwd).isDirectory())
|
|
6703
|
+
throw new Error("not-a-dir");
|
|
6704
|
+
}
|
|
6705
|
+
catch {
|
|
6706
|
+
return { ok: false, error: `目标项目不存在或不是目录:${cwd || "(空)"}` };
|
|
6707
|
+
}
|
|
6708
|
+
try {
|
|
6709
|
+
const cs = await this.attach(clientId, () => { });
|
|
6710
|
+
if (cs.cwd !== cwd)
|
|
6711
|
+
await cs.setCwd(cwd);
|
|
6712
|
+
const model = String(task.model ?? "").trim();
|
|
6713
|
+
if (model) {
|
|
6714
|
+
try {
|
|
6715
|
+
await cs.setModel(model);
|
|
6716
|
+
}
|
|
6717
|
+
catch (err) {
|
|
6718
|
+
return { ok: false, error: `切换模型失败(${model}):${err.message}` };
|
|
6719
|
+
}
|
|
6720
|
+
}
|
|
6721
|
+
const thinking = String(task.thinkingLevel ?? "").trim();
|
|
6722
|
+
if (thinking) {
|
|
6723
|
+
try {
|
|
6724
|
+
cs.setThinking(thinking);
|
|
6725
|
+
}
|
|
6726
|
+
catch (err) {
|
|
6727
|
+
return { ok: false, error: `切换思考强度失败(${thinking}):${err.message}` };
|
|
6728
|
+
}
|
|
6729
|
+
}
|
|
6730
|
+
const conversationId = cs.readConversationForPlugins()?.conversationId ?? "";
|
|
6731
|
+
void cs.prompt(`[定时任务] ${text}`);
|
|
6732
|
+
// 等待运行结束:每 2s 轮询,最长 10 分钟。超时按失败记录(运行继续)。
|
|
6733
|
+
const deadline = Date.now() + 10 * 60 * 1000;
|
|
6734
|
+
for (;;) {
|
|
6735
|
+
await new Promise((r) => setTimeout(r, 2000));
|
|
6736
|
+
let streaming = false;
|
|
6737
|
+
let lastError;
|
|
6738
|
+
try {
|
|
6739
|
+
const snap = cs.readConversationForPlugins();
|
|
6740
|
+
streaming = snap?.isStreaming === true;
|
|
6741
|
+
const msgs = snap?.messages ?? [];
|
|
6742
|
+
for (let i = msgs.length - 1; i >= 0; i--) {
|
|
6743
|
+
const m = msgs[i];
|
|
6744
|
+
if (m.role === "assistant" && m.errorMessage) {
|
|
6745
|
+
lastError = m.errorMessage;
|
|
6746
|
+
break;
|
|
6747
|
+
}
|
|
6748
|
+
if (m.role === "assistant")
|
|
6749
|
+
break;
|
|
6750
|
+
}
|
|
6751
|
+
}
|
|
6752
|
+
catch {
|
|
6753
|
+
streaming = false;
|
|
6754
|
+
}
|
|
6755
|
+
if (!streaming) {
|
|
6756
|
+
if (lastError)
|
|
6757
|
+
return { ok: false, conversationId: conversationId || undefined, error: lastError };
|
|
6758
|
+
return { ok: true, conversationId: conversationId || undefined };
|
|
6759
|
+
}
|
|
6760
|
+
if (Date.now() >= deadline)
|
|
6761
|
+
return { ok: false, conversationId: conversationId || undefined, error: "运行超时(10 分钟),仍在后台继续" };
|
|
6762
|
+
}
|
|
6763
|
+
}
|
|
6764
|
+
catch (err) {
|
|
6765
|
+
return { ok: false, error: err.message };
|
|
6766
|
+
}
|
|
6767
|
+
}
|
|
6455
6768
|
/** 插件直调模型(host.llm.complete 的落地):孤立无工具的一次性补全。
|
|
6456
6769
|
* 不建对话、不进历史、不碰任何会话状态;花费走用户自己的模型额度。
|
|
6457
6770
|
* quiesced 时拒绝;无客户端时用进程 cwd + 默认模型照常跑。 */
|
|
@@ -247,6 +247,45 @@ export async function buildAttachmentMessages(ctx, attachments) {
|
|
|
247
247
|
/** Cap for reading a file in "lines" mode (selected slice is inlined). */
|
|
248
248
|
const MAX_LINES_READ_BYTES = 2 * 1024 * 1024;
|
|
249
249
|
for (const [idx, att] of attachments.entries()) {
|
|
250
|
+
// Quoted conversation (left-panel right-click / global-search quote):
|
|
251
|
+
// `path` is unused — the reference travels in conversationId (running
|
|
252
|
+
// conversation, incl. subagents) or sessionPath (history transcript).
|
|
253
|
+
// The transcript is NOT inlined here (it can be huge and goes stale);
|
|
254
|
+
// the model fetches it on demand with the conversation_read tool.
|
|
255
|
+
if (att.mode === "conversation") {
|
|
256
|
+
const convId = att.conversationId;
|
|
257
|
+
const sessPath = att.sessionPath;
|
|
258
|
+
const id = typeof convId === "string" && convId.trim() ? convId.trim() : undefined;
|
|
259
|
+
const sp = typeof sessPath === "string" && sessPath.trim() ? sessPath.trim() : undefined;
|
|
260
|
+
const title = att.name ?? id ?? sp ?? "conversation";
|
|
261
|
+
if (!id && !sp) {
|
|
262
|
+
ctx.emit({
|
|
263
|
+
type: "notice",
|
|
264
|
+
level: "warning",
|
|
265
|
+
text: `对话引用缺少 id/path,已跳过`,
|
|
266
|
+
textEn: `Conversation reference without id/path, skipped`,
|
|
267
|
+
});
|
|
268
|
+
continue;
|
|
269
|
+
}
|
|
270
|
+
const ref = id ? `id="${attr(id)}"` : `path="${attr(sp)}"`;
|
|
271
|
+
const how = id
|
|
272
|
+
? `Use the conversation_read tool with id="${attr(id)}" to read its messages.`
|
|
273
|
+
: `Use the conversation_read tool with path="${attr(sp)}" to read its transcript.`;
|
|
274
|
+
out.push({
|
|
275
|
+
message: {
|
|
276
|
+
customType: "file",
|
|
277
|
+
content: [
|
|
278
|
+
{
|
|
279
|
+
type: "text",
|
|
280
|
+
text: `\n<conversation-ref ${ref} title="${attr(title)}">\nThe user quoted another conversation "${attr(title)}". ${how} Do not guess its contents.\n用户引用了另一个对话,别猜它的内容,用 conversation_read 去读。\n</conversation-ref>`,
|
|
281
|
+
},
|
|
282
|
+
],
|
|
283
|
+
display: true,
|
|
284
|
+
details: { name: title, path: id ?? sp, mode: "conversation", conversationId: id, sessionPath: sp },
|
|
285
|
+
},
|
|
286
|
+
});
|
|
287
|
+
continue;
|
|
288
|
+
}
|
|
250
289
|
// Granted web page (page-picker extension): `path` is the page origin,
|
|
251
290
|
// NOT a workspace path — never stat/read it. The model gets the exact
|
|
252
291
|
// browser_page target plus the fact that this page is already granted,
|