agent-loft 0.2.48 → 0.2.50
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/README.md +32 -15
- package/package.json +1 -1
- package/src/agents/claude/driver.ts +1 -1
- package/src/agents/claude/session.ts +140 -47
- package/src/agents/codex/driver.ts +1 -1
- package/src/agents/codex/session.ts +90 -58
- package/src/channels/feishu/bot.ts +1 -3
- package/src/channels/feishu/cards.ts +2 -2
- package/src/channels/web/api.ts +49 -19
- package/src/channels/web/conv-pages.ts +37 -0
- package/src/channels/web/experts-api.ts +203 -0
- package/src/channels/web/skills-api.ts +1 -7
- package/src/channels/web/tasks-api.ts +9 -5
- package/src/core/command-catalog.ts +4 -6
- package/src/core/commands.ts +6 -11
- package/src/core/expert-prompt.ts +119 -0
- package/src/core/experts.ts +438 -0
- package/src/core/hub.ts +137 -102
- package/src/core/mcp.ts +253 -0
- package/src/core/memory-curator.ts +14 -19
- package/src/core/memory.ts +11 -4
- package/src/core/personal.ts +5 -1
- package/src/core/skill-runtime.ts +11 -114
- package/src/core/store.ts +30 -11
- package/src/core/task-prompt.ts +1 -1
- package/src/core/task-runner.ts +24 -11
- package/src/core/tasks-bridge.ts +7 -7
- package/src/core/tasks.ts +49 -14
- package/src/core/types.ts +4 -7
- package/src/core/uploads.ts +7 -7
- package/src/mcp/tasks-server.ts +1 -2
- package/web/css/experts.css +225 -0
- package/web/css/messages.css +43 -0
- package/web/css/overlay.css +12 -0
- package/web/css/search.css +214 -0
- package/web/css/sidebar.css +79 -56
- package/web/css/skills.css +0 -11
- package/web/css/topbar.css +135 -5
- package/web/index.html +2 -0
- package/web/lib/dom.js +6 -14
- package/web/settings/experts.js +622 -0
- package/web/settings/index.js +3 -0
- package/web/settings/memory.js +23 -7
- package/web/settings/skills.js +3 -3
- package/web/state.js +7 -2
- package/web/views/composer.js +31 -29
- package/web/views/conv-actions.js +8 -9
- package/web/views/conv-search.js +206 -0
- package/web/views/experts.js +74 -0
- package/web/views/layout.js +9 -4
- package/web/views/messages.js +44 -11
- package/web/views/quota.js +13 -10
- package/web/views/sidebar.js +71 -19
- package/web/views/tasks.js +21 -36
- package/web/views/topbar.js +148 -74
- package/src/core/chat-mode.ts +0 -62
- package/web/views/mention.js +0 -202
package/src/core/mcp.ts
ADDED
|
@@ -0,0 +1,253 @@
|
|
|
1
|
+
// MCP 服务:由 agent-loft 按人管理,专家(core/experts.ts)勾选了哪些,开会话时就挂哪些。
|
|
2
|
+
//
|
|
3
|
+
// 两种:
|
|
4
|
+
// - stdio:本机起一个进程(command + args + 环境变量);
|
|
5
|
+
// - http:连一个地址(url + 请求头)。
|
|
6
|
+
// 环境变量和请求头可以标成密钥:网页上不回显,只说填没填。值只交给 MCP 进程 / 请求头,不进 agent 的提示词。
|
|
7
|
+
// 和技能一样是「信任型」的:能执行命令的专家读得到 data/ 下的文件,包括这里的值。
|
|
8
|
+
//
|
|
9
|
+
// 机器上原有的 MCP(Claude 的 ~/.claude.json、Codex 的 config.toml)只给管理员选,id 写成 machine:<名字>。
|
|
10
|
+
// 内置的 Claude Code / Codex 专家不经过这里:它们照旧加载机器上的配置。
|
|
11
|
+
//
|
|
12
|
+
// 存储:data/mcp.json,所有人的放在一起,只有主进程读写。
|
|
13
|
+
import crypto from "node:crypto";
|
|
14
|
+
import os from "node:os";
|
|
15
|
+
import path from "node:path";
|
|
16
|
+
import { EventEmitter } from "node:events";
|
|
17
|
+
import { dataDir, readJson, writeJsonAtomic } from "../home.js";
|
|
18
|
+
import { MEMORY_MCP_NAME } from "./memory-mcp.js";
|
|
19
|
+
import { SKILLS_MCP_NAME, TASKS_MCP_NAME } from "./tasks-mcp.js";
|
|
20
|
+
|
|
21
|
+
export type McpPair = { name: string; value: string; secret: boolean };
|
|
22
|
+
|
|
23
|
+
export type McpServer = {
|
|
24
|
+
id: string;
|
|
25
|
+
owner: string;
|
|
26
|
+
/** 服务名:工具在 agent 里叫 mcp__<name>__<工具>,同一个人的不能重名 */
|
|
27
|
+
name: string;
|
|
28
|
+
description: string;
|
|
29
|
+
type: "stdio" | "http";
|
|
30
|
+
command?: string;
|
|
31
|
+
args?: string[];
|
|
32
|
+
url?: string;
|
|
33
|
+
/** stdio 的环境变量 */
|
|
34
|
+
env: McpPair[];
|
|
35
|
+
/** http 的请求头 */
|
|
36
|
+
headers: McpPair[];
|
|
37
|
+
/** 调用这个服务的工具前先弹授权卡(默认不问:是用户自己给专家挂的) */
|
|
38
|
+
ask: boolean;
|
|
39
|
+
createdAt: number;
|
|
40
|
+
updatedAt: number;
|
|
41
|
+
};
|
|
42
|
+
|
|
43
|
+
/** 开会话时交给 agent 的样子(Claude 的 McpServerConfig 同形) */
|
|
44
|
+
export type McpSpec =
|
|
45
|
+
| { type: "stdio"; command: string; args: string[]; env: Record<string, string> }
|
|
46
|
+
| { type: "http"; url: string; headers: Record<string, string> };
|
|
47
|
+
|
|
48
|
+
export const MCP_NAME = /^[a-z0-9][a-z0-9_-]{0,31}$/;
|
|
49
|
+
const PAIR_NAME = /^[A-Za-z_][A-Za-z0-9_-]{0,63}$/;
|
|
50
|
+
const RESERVED = new Set([MEMORY_MCP_NAME, TASKS_MCP_NAME, SKILLS_MCP_NAME]);
|
|
51
|
+
export const MACHINE_PREFIX = "machine:";
|
|
52
|
+
|
|
53
|
+
export const MCP_LIMITS = { perUser: 50, description: 500, command: 1000, args: 50, arg: 2000, pairs: 30, value: 4000, url: 2000 };
|
|
54
|
+
|
|
55
|
+
const storePath = path.join(dataDir, "mcp.json");
|
|
56
|
+
|
|
57
|
+
/** 有变化。owner:谁的;他用着这个服务的会话空闲下来要换上新的 */
|
|
58
|
+
export const mcpEvents = new EventEmitter<{ changed: [owner: string, id: string] }>();
|
|
59
|
+
|
|
60
|
+
let cache: McpServer[] | null = null;
|
|
61
|
+
|
|
62
|
+
function load(): McpServer[] {
|
|
63
|
+
cache ??= readJson<McpServer[]>(storePath, []).filter((s) => s && typeof s.id === "string" && typeof s.owner === "string" && MCP_NAME.test(s.name));
|
|
64
|
+
return cache;
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
function save(): void {
|
|
68
|
+
writeJsonAtomic(storePath, load());
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
export function resetMcpCache(): void {
|
|
72
|
+
cache = null;
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
export function listMcp(owner: string): McpServer[] {
|
|
76
|
+
return load()
|
|
77
|
+
.filter((s) => s.owner === owner)
|
|
78
|
+
.sort((a, b) => a.name.localeCompare(b.name));
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
export function getMcp(id: string): McpServer | undefined {
|
|
82
|
+
return load().find((s) => s.id === id);
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
export type McpInput = {
|
|
86
|
+
name?: unknown;
|
|
87
|
+
description?: unknown;
|
|
88
|
+
type?: unknown;
|
|
89
|
+
command?: unknown;
|
|
90
|
+
args?: unknown;
|
|
91
|
+
url?: unknown;
|
|
92
|
+
env?: unknown;
|
|
93
|
+
headers?: unknown;
|
|
94
|
+
ask?: unknown;
|
|
95
|
+
};
|
|
96
|
+
|
|
97
|
+
const str = (v: unknown, max: number, what: string): string => {
|
|
98
|
+
const s = typeof v === "string" ? v.trim() : "";
|
|
99
|
+
if (s.length > max) throw new Error(`${what}太长(最多 ${max} 个字)`);
|
|
100
|
+
return s;
|
|
101
|
+
};
|
|
102
|
+
|
|
103
|
+
/**
|
|
104
|
+
* 键值对:密钥留空表示「不改」(网页上看不到原值,没重新填就沿用 prev 里的)。
|
|
105
|
+
* 不是密钥的留空就是空字符串。
|
|
106
|
+
*/
|
|
107
|
+
function cleanPairs(raw: unknown, prev: McpPair[], what: string): McpPair[] {
|
|
108
|
+
if (raw === undefined) return prev;
|
|
109
|
+
if (!Array.isArray(raw)) throw new Error(`${what}格式不对`);
|
|
110
|
+
if (raw.length > MCP_LIMITS.pairs) throw new Error(`${what}太多(最多 ${MCP_LIMITS.pairs} 个)`);
|
|
111
|
+
const out: McpPair[] = [];
|
|
112
|
+
const seen = new Set<string>();
|
|
113
|
+
for (const item of raw as Record<string, unknown>[]) {
|
|
114
|
+
const name = str(item?.name, 64, `${what}名`);
|
|
115
|
+
if (!name) continue;
|
|
116
|
+
if (!PAIR_NAME.test(name)) throw new Error(`${what}名「${name}」不合法:字母、数字、下划线和 -`);
|
|
117
|
+
if (seen.has(name)) throw new Error(`${what}「${name}」重复了`);
|
|
118
|
+
seen.add(name);
|
|
119
|
+
const secret = item?.secret === true;
|
|
120
|
+
let value = typeof item?.value === "string" ? item.value : "";
|
|
121
|
+
if (value.length > MCP_LIMITS.value) throw new Error(`${what}「${name}」的值太长`);
|
|
122
|
+
if (secret && value === "") value = prev.find((p) => p.name === name)?.value ?? "";
|
|
123
|
+
out.push({ name, value, secret });
|
|
124
|
+
}
|
|
125
|
+
return out;
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
function validate(owner: string, input: McpInput, prev?: McpServer): Omit<McpServer, "id" | "owner" | "createdAt" | "updatedAt"> {
|
|
129
|
+
const name = prev ? prev.name : str(input.name, 32, "名字").toLowerCase();
|
|
130
|
+
if (!MCP_NAME.test(name)) throw new Error("名字只能用小写字母、数字、- 和 _,以字母或数字开头,最长 32 个字");
|
|
131
|
+
if (RESERVED.has(name)) throw new Error(`「${name}」是 agent-loft 自己用的名字`);
|
|
132
|
+
if (!prev && listMcp(owner).some((s) => s.name === name)) throw new Error(`已经有一个叫「${name}」的 MCP 了`);
|
|
133
|
+
const type = input.type === undefined && prev ? prev.type : input.type === "http" ? "http" : input.type === "stdio" ? "stdio" : null;
|
|
134
|
+
if (!type) throw new Error("类型只能是 stdio 或 http");
|
|
135
|
+
const description = input.description === undefined && prev ? prev.description : str(input.description, MCP_LIMITS.description, "说明");
|
|
136
|
+
const ask = input.ask === undefined && prev ? prev.ask : input.ask === true;
|
|
137
|
+
if (type === "stdio") {
|
|
138
|
+
const command = input.command === undefined && prev?.command ? prev.command : str(input.command, MCP_LIMITS.command, "命令");
|
|
139
|
+
if (!command) throw new Error("stdio 要填启动命令");
|
|
140
|
+
let args = prev?.args ?? [];
|
|
141
|
+
if (input.args !== undefined) {
|
|
142
|
+
if (!Array.isArray(input.args)) throw new Error("参数格式不对");
|
|
143
|
+
if (input.args.length > MCP_LIMITS.args) throw new Error(`参数太多(最多 ${MCP_LIMITS.args} 个)`);
|
|
144
|
+
args = input.args.map((a) => String(a ?? ""));
|
|
145
|
+
if (args.some((a) => a.length > MCP_LIMITS.arg)) throw new Error("有个参数太长");
|
|
146
|
+
}
|
|
147
|
+
return { name, description, type, command, args, env: cleanPairs(input.env, prev?.env ?? [], "环境变量"), headers: [], ask };
|
|
148
|
+
}
|
|
149
|
+
const url = input.url === undefined && prev?.url ? prev.url : str(input.url, MCP_LIMITS.url, "地址");
|
|
150
|
+
let parsed: URL;
|
|
151
|
+
try {
|
|
152
|
+
parsed = new URL(url);
|
|
153
|
+
} catch {
|
|
154
|
+
throw new Error("地址不对:要写完整的 http:// 或 https:// 地址");
|
|
155
|
+
}
|
|
156
|
+
if (parsed.protocol !== "http:" && parsed.protocol !== "https:") throw new Error("地址只能是 http:// 或 https://");
|
|
157
|
+
return { name, description, type, url, env: [], headers: cleanPairs(input.headers, prev?.headers ?? [], "请求头"), ask };
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
export function createMcp(owner: string, input: McpInput): McpServer {
|
|
161
|
+
if (listMcp(owner).length >= MCP_LIMITS.perUser) throw new Error(`每人最多 ${MCP_LIMITS.perUser} 个 MCP`);
|
|
162
|
+
const now = Date.now();
|
|
163
|
+
const server: McpServer = { id: `m_${crypto.randomBytes(6).toString("hex")}`, owner, ...validate(owner, input), createdAt: now, updatedAt: now };
|
|
164
|
+
load().push(server);
|
|
165
|
+
save();
|
|
166
|
+
mcpEvents.emit("changed", owner, server.id);
|
|
167
|
+
return server;
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
export function updateMcp(owner: string, id: string, input: McpInput): McpServer {
|
|
171
|
+
const list = load();
|
|
172
|
+
const idx = list.findIndex((s) => s.id === id && s.owner === owner);
|
|
173
|
+
if (idx < 0) throw new Error("这个 MCP 不存在");
|
|
174
|
+
const prev = list[idx]!;
|
|
175
|
+
const next: McpServer = { ...prev, ...validate(owner, input, prev), updatedAt: Date.now() };
|
|
176
|
+
list[idx] = next;
|
|
177
|
+
save();
|
|
178
|
+
mcpEvents.emit("changed", owner, id);
|
|
179
|
+
return next;
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
export function deleteMcp(owner: string, id: string): void {
|
|
183
|
+
const list = load();
|
|
184
|
+
const idx = list.findIndex((s) => s.id === id && s.owner === owner);
|
|
185
|
+
if (idx < 0) throw new Error("这个 MCP 不存在");
|
|
186
|
+
list.splice(idx, 1);
|
|
187
|
+
save();
|
|
188
|
+
mcpEvents.emit("changed", owner, id);
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
export function purgeUserMcp(owner: string): void {
|
|
192
|
+
const list = load();
|
|
193
|
+
const kept = list.filter((s) => s.owner !== owner);
|
|
194
|
+
if (kept.length === list.length) return;
|
|
195
|
+
cache = kept;
|
|
196
|
+
save();
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
/** 网页上看的样子:密钥不回显 */
|
|
200
|
+
export function mcpView(s: McpServer) {
|
|
201
|
+
const pairs = (list: McpPair[]) => list.map((p) => (p.secret ? { name: p.name, secret: true, set: p.value !== "" } : { name: p.name, value: p.value, secret: false }));
|
|
202
|
+
return {
|
|
203
|
+
id: s.id,
|
|
204
|
+
name: s.name,
|
|
205
|
+
description: s.description,
|
|
206
|
+
type: s.type,
|
|
207
|
+
...(s.type === "stdio" ? { command: s.command ?? "", args: s.args ?? [], env: pairs(s.env) } : { url: s.url ?? "", headers: pairs(s.headers) }),
|
|
208
|
+
ask: s.ask,
|
|
209
|
+
createdAt: s.createdAt,
|
|
210
|
+
updatedAt: s.updatedAt,
|
|
211
|
+
};
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
export function specOf(s: McpServer): McpSpec {
|
|
215
|
+
return s.type === "stdio"
|
|
216
|
+
? { type: "stdio", command: s.command ?? "", args: s.args ?? [], env: Object.fromEntries(s.env.map((p) => [p.name, p.value])) }
|
|
217
|
+
: { type: "http", url: s.url ?? "", headers: Object.fromEntries(s.headers.filter((p) => p.value !== "").map((p) => [p.name, p.value])) };
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
// ---------- 机器上原有的 ----------
|
|
221
|
+
|
|
222
|
+
/**
|
|
223
|
+
* Claude 机器级(用户范围)的 MCP:~/.claude.json 顶层的 mcpServers(设了 CLAUDE_CONFIG_DIR 就在那下面)。
|
|
224
|
+
* 项目范围、插件带的不列。只认 stdio / http / sse 三种。
|
|
225
|
+
*/
|
|
226
|
+
export function claudeMachineMcp(): Record<string, McpSpec | { type: "sse"; url: string; headers: Record<string, string> }> {
|
|
227
|
+
const dir = process.env.CLAUDE_CONFIG_DIR || os.homedir();
|
|
228
|
+
const raw = readJson<{ mcpServers?: Record<string, Record<string, unknown>> }>(path.join(dir, ".claude.json"), {});
|
|
229
|
+
const out: Record<string, McpSpec | { type: "sse"; url: string; headers: Record<string, string> }> = {};
|
|
230
|
+
for (const [name, cfg] of Object.entries(raw.mcpServers ?? {})) {
|
|
231
|
+
if (!cfg || typeof cfg !== "object" || RESERVED.has(name)) continue;
|
|
232
|
+
const headers = (cfg.headers && typeof cfg.headers === "object" ? cfg.headers : {}) as Record<string, string>;
|
|
233
|
+
if ((cfg.type === "http" || cfg.type === "sse") && typeof cfg.url === "string") {
|
|
234
|
+
out[name] = { type: cfg.type, url: cfg.url, headers };
|
|
235
|
+
} else if (typeof cfg.command === "string") {
|
|
236
|
+
out[name] = {
|
|
237
|
+
type: "stdio",
|
|
238
|
+
command: cfg.command,
|
|
239
|
+
args: Array.isArray(cfg.args) ? cfg.args.map(String) : [],
|
|
240
|
+
env: (cfg.env && typeof cfg.env === "object" ? cfg.env : {}) as Record<string, string>,
|
|
241
|
+
};
|
|
242
|
+
}
|
|
243
|
+
}
|
|
244
|
+
return out;
|
|
245
|
+
}
|
|
246
|
+
|
|
247
|
+
export function isMachineId(id: string): boolean {
|
|
248
|
+
return id.startsWith(MACHINE_PREFIX);
|
|
249
|
+
}
|
|
250
|
+
|
|
251
|
+
export function machineName(id: string): string {
|
|
252
|
+
return id.slice(MACHINE_PREFIX.length);
|
|
253
|
+
}
|
|
@@ -2,7 +2,8 @@
|
|
|
2
2
|
//
|
|
3
3
|
// 三件事:
|
|
4
4
|
// 1. 录入(startHistoryCapture):hub 的事件流里,有主人的对话的每句话(用户说的、agent 的最终回复)
|
|
5
|
-
// 记进主人的聊天记录索引(chat-history.ts
|
|
5
|
+
// 记进主人的聊天记录索引(chat-history.ts)。不管开没开记忆都记:侧栏的「搜索」要搜聊天内容。
|
|
6
|
+
// 没开记忆(或者关了整理)时记进来的话随即标成整理过了,之后再打开记忆也不会一下子整理一大堆旧的。
|
|
6
7
|
// 2. 回填(backfill):第一次用时,把已有对话从 agent 的记录里读一遍进索引,每人只做一次。
|
|
7
8
|
// 回填进来的只供搜索,不拿去整理 —— 一次整理几百段旧对话太费额度。
|
|
8
9
|
// 3. 整理:把上次整理之后新说的话交给模型(用户在记忆设置里选 agent 和模型,默认最省的),
|
|
@@ -28,12 +29,11 @@ import {
|
|
|
28
29
|
readMemory,
|
|
29
30
|
removeMemoryItem,
|
|
30
31
|
updateMemoryItem,
|
|
31
|
-
type CurateScope,
|
|
32
32
|
type CurateSettings,
|
|
33
33
|
type UserMemory,
|
|
34
34
|
} from "./memory.js";
|
|
35
35
|
import { memoryOwnerOf } from "./personal.js";
|
|
36
|
-
import { listConversations } from "./store.js";
|
|
36
|
+
import { expertIdOf, listConversations, type Conversation } from "./store.js";
|
|
37
37
|
import { activeUsers } from "./users.js";
|
|
38
38
|
import type { AgentDriver } from "./types.js";
|
|
39
39
|
import { agentAvailability } from "../agents/health.js";
|
|
@@ -52,11 +52,6 @@ const MAX_CHANGES = 5;
|
|
|
52
52
|
|
|
53
53
|
let capturing = false;
|
|
54
54
|
|
|
55
|
-
/** 记不记这个用户的聊天:开着记忆,并且整理和「参考以前的聊天」至少开了一个 */
|
|
56
|
-
function wants(memory: UserMemory): boolean {
|
|
57
|
-
return memory.enabled && (memory.curate.when !== "off" || memory.chatHistory);
|
|
58
|
-
}
|
|
59
|
-
|
|
60
55
|
export function startHistoryCapture(): void {
|
|
61
56
|
if (capturing) return;
|
|
62
57
|
capturing = true;
|
|
@@ -67,7 +62,7 @@ export function startHistoryCapture(): void {
|
|
|
67
62
|
const conv = hub.conversation(env.key);
|
|
68
63
|
if (!conv || conv.hidden) return;
|
|
69
64
|
const owner = memoryOwnerOf(conv);
|
|
70
|
-
if (!owner
|
|
65
|
+
if (!owner) return;
|
|
71
66
|
const text =
|
|
72
67
|
ev.type === "user"
|
|
73
68
|
? [ev.text, ev.attachments.length ? `(附件:${ev.attachments.join("、")})` : ""].filter(Boolean).join("\n")
|
|
@@ -363,18 +358,18 @@ export async function curateBatch(
|
|
|
363
358
|
return log;
|
|
364
359
|
}
|
|
365
360
|
|
|
366
|
-
/**
|
|
367
|
-
function inScope(conv:
|
|
368
|
-
return scope === "all" || (
|
|
361
|
+
/** 这段对话在不在用户选的整理范围里(按对话的专家算) */
|
|
362
|
+
function inScope(conv: Pick<Conversation, "agent" | "expert">, curate: Pick<CurateSettings, "scope" | "experts">): boolean {
|
|
363
|
+
return curate.scope === "all" || curate.experts.includes(expertIdOf(conv));
|
|
369
364
|
}
|
|
370
365
|
|
|
371
366
|
/** 某个用户等着整理的对话。删掉的、不在整理范围里的直接记成整理过(之后改范围也不补整理);正在回复的这次先不碰 */
|
|
372
367
|
function collect(userId: string, settleMs: number, now?: number): Pending[] {
|
|
373
|
-
const
|
|
368
|
+
const curate = readMemory(userId).curate;
|
|
374
369
|
const out: Pending[] = [];
|
|
375
370
|
for (const p of pendingConversations(userId, settleMs, now)) {
|
|
376
371
|
const conv = hub.conversation(p.key);
|
|
377
|
-
if (!conv || conv.hidden || !inScope(conv,
|
|
372
|
+
if (!conv || conv.hidden || !inScope(conv, curate)) {
|
|
378
373
|
markExtracted(userId, p.key, p.last);
|
|
379
374
|
continue;
|
|
380
375
|
}
|
|
@@ -397,11 +392,11 @@ export function sweepOnce(opts: { now?: number } = {}): Promise<void> {
|
|
|
397
392
|
const now = opts.now ?? Date.now();
|
|
398
393
|
for (const user of activeUsers()) {
|
|
399
394
|
try {
|
|
395
|
+
// 回填不看记忆开关:侧栏搜索也要搜以前的聊天
|
|
396
|
+
if (!readMeta(user.id).backfilled) await backfill(user.id);
|
|
400
397
|
const memory = readMemory(user.id);
|
|
401
|
-
if (!memory.enabled) continue;
|
|
402
|
-
if (memory.chatHistory && !readMeta(user.id).backfilled) await backfill(user.id);
|
|
403
398
|
const c = memory.curate;
|
|
404
|
-
if (c.when === "off") {
|
|
399
|
+
if (!memory.enabled || c.when === "off") {
|
|
405
400
|
// 不整理:聊过的不攒着,之后再打开也不会一下子整理一大堆旧的
|
|
406
401
|
for (const p of pendingConversations(user.id, 0, now)) markExtracted(user.id, p.key, p.last);
|
|
407
402
|
} else if (c.when === "idle") {
|
|
@@ -434,10 +429,10 @@ export function curateNow(userId: string, opts: { now?: number } = {}): Promise<
|
|
|
434
429
|
|
|
435
430
|
/** 还没整理的对话有几段(设置页显示「有 N 段对话等着整理」) */
|
|
436
431
|
export function pendingCount(userId: string): number {
|
|
437
|
-
const
|
|
432
|
+
const curate = readMemory(userId).curate;
|
|
438
433
|
return pendingConversations(userId, 0).filter((p) => {
|
|
439
434
|
const conv = hub.conversation(p.key);
|
|
440
|
-
return conv && !conv.hidden && inScope(conv,
|
|
435
|
+
return conv && !conv.hidden && inScope(conv, curate);
|
|
441
436
|
}).length;
|
|
442
437
|
}
|
|
443
438
|
|
package/src/core/memory.ts
CHANGED
|
@@ -44,12 +44,13 @@ export type UserMemory = {
|
|
|
44
44
|
*/
|
|
45
45
|
export type CurateWhen = "idle" | "daily" | "manual" | "off";
|
|
46
46
|
|
|
47
|
-
/** 整理哪些对话:全部 /
|
|
48
|
-
export type CurateScope = "all" | "
|
|
47
|
+
/** 整理哪些对话:全部 / 只整理选中专家的(experts 里的专家 id,内置的就是 claude、codex) */
|
|
48
|
+
export type CurateScope = "all" | "experts";
|
|
49
49
|
|
|
50
50
|
export type CurateSettings = {
|
|
51
51
|
when: CurateWhen;
|
|
52
52
|
scope: CurateScope;
|
|
53
|
+
experts: string[];
|
|
53
54
|
idleMinutes: number;
|
|
54
55
|
dailyHour: number;
|
|
55
56
|
/** auto:Claude 能用就用 Claude,否则 Codex */
|
|
@@ -58,12 +59,17 @@ export type CurateSettings = {
|
|
|
58
59
|
model: string;
|
|
59
60
|
};
|
|
60
61
|
|
|
61
|
-
export const DEFAULT_CURATE: CurateSettings = { when: "daily", scope: "all", idleMinutes: 30, dailyHour: 2, agent: "auto", model: "" };
|
|
62
|
+
export const DEFAULT_CURATE: CurateSettings = { when: "daily", scope: "all", experts: [], idleMinutes: 30, dailyHour: 2, agent: "auto", model: "" };
|
|
62
63
|
|
|
63
64
|
function cleanCurate(raw: Partial<CurateSettings> | undefined, base: CurateSettings): CurateSettings {
|
|
64
65
|
const r = raw ?? {};
|
|
65
66
|
const when = (["idle", "daily", "manual", "off"] as const).find((w) => w === r.when) ?? base.when;
|
|
66
|
-
|
|
67
|
+
// 以前的「只整理聊天 / 工作模式的」没有了(聊天模式换成了专家),一律回到全部
|
|
68
|
+
const legacy = (r.scope as string) === "chat" || (r.scope as string) === "work";
|
|
69
|
+
const scope = legacy ? "all" : ((["all", "experts"] as const).find((s) => s === r.scope) ?? base.scope);
|
|
70
|
+
const experts = Array.isArray(r.experts)
|
|
71
|
+
? [...new Set(r.experts.filter((x): x is string => typeof x === "string" && /^[\w-]{1,64}$/.test(x)))].slice(0, 100)
|
|
72
|
+
: base.experts;
|
|
67
73
|
const idle = Math.round(Number(r.idleMinutes ?? base.idleMinutes));
|
|
68
74
|
const hour = Math.round(Number(r.dailyHour ?? base.dailyHour));
|
|
69
75
|
const agent = (["auto", "claude", "codex"] as const).find((a) => a === r.agent) ?? base.agent;
|
|
@@ -71,6 +77,7 @@ function cleanCurate(raw: Partial<CurateSettings> | undefined, base: CurateSetti
|
|
|
71
77
|
return {
|
|
72
78
|
when,
|
|
73
79
|
scope,
|
|
80
|
+
experts,
|
|
74
81
|
idleMinutes: Number.isFinite(idle) ? Math.max(5, Math.min(24 * 60, idle)) : base.idleMinutes,
|
|
75
82
|
dailyHour: Number.isFinite(hour) ? Math.max(0, Math.min(23, hour)) : base.dailyHour,
|
|
76
83
|
agent,
|
package/src/core/personal.ts
CHANGED
|
@@ -4,6 +4,8 @@ import { purgeHistory } from "./chat-history.js";
|
|
|
4
4
|
import { unlinkUser } from "./feishu-links.js";
|
|
5
5
|
import { deleteUserTasks } from "./tasks.js";
|
|
6
6
|
import { purgeUserSkills } from "./skills.js";
|
|
7
|
+
import { purgeUserExperts } from "./experts.js";
|
|
8
|
+
import { purgeUserMcp } from "./mcp.js";
|
|
7
9
|
import type { Conversation } from "./store.js";
|
|
8
10
|
import { getUser, legacyOwnerId } from "./users.js";
|
|
9
11
|
import { deleteUiPrefs } from "./ui-prefs.js";
|
|
@@ -39,12 +41,14 @@ export function sessionMemory(
|
|
|
39
41
|
};
|
|
40
42
|
}
|
|
41
43
|
|
|
42
|
-
/**
|
|
44
|
+
/** 删用户时一起删掉的个人数据:记忆、聊天记录索引、飞书绑定、定时任务、技能(他建的技能,装了的人也就没了)、专家和 MCP */
|
|
43
45
|
export function purgeUserData(userId: string): void {
|
|
44
46
|
deleteMemory(userId);
|
|
45
47
|
purgeHistory(userId);
|
|
46
48
|
unlinkUser(userId);
|
|
47
49
|
deleteUserTasks(userId);
|
|
48
50
|
purgeUserSkills(userId);
|
|
51
|
+
purgeUserExperts(userId);
|
|
52
|
+
purgeUserMcp(userId);
|
|
49
53
|
deleteUiPrefs(userId);
|
|
50
54
|
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
// 技能怎么交到 agent
|
|
2
|
-
// 机器上原有的技能(~/.claude/skills、~/.agents/skills
|
|
1
|
+
// 技能怎么交到 agent 手上:开会话时挂哪些、注入哪些变量;自定义专家只给它选中的;
|
|
2
|
+
// 机器上原有的技能(~/.claude/skills、~/.agents/skills 这些)只给管理员(内置专家才加载)。
|
|
3
3
|
//
|
|
4
4
|
// 两个 agent 的做法不一样(都实测过):
|
|
5
5
|
// - Claude:每个用户一个插件目录(data/skills/plugins/<用户>),里面链接着他启用的技能,开会话时用
|
|
@@ -186,19 +186,24 @@ function varsPrompt(skills: Skill[], env: Record<string, string>, userId: string
|
|
|
186
186
|
/**
|
|
187
187
|
* 开会话时给 agent 的技能(SessionOptions.skills)。owner 是这条对话的主人(personal.ts 的 memoryOwnerOf);
|
|
188
188
|
* 没有主人的对话(飞书群聊等,只有管理员能配)照旧:机器上的技能都在,没有 agent-loft 的技能。
|
|
189
|
+
* only:自定义专家选中的技能 id,只给这些(变量的说明也只说这些的)。插件目录照样是这个人启用的全部 ——
|
|
190
|
+
* 正在用这个目录的其他会话不受影响,Claude 那边再用白名单只放选中的。
|
|
189
191
|
*/
|
|
190
|
-
export function sessionSkills(owner: string | undefined): SessionSkills | undefined {
|
|
192
|
+
export function sessionSkills(owner: string | undefined, only?: string[]): SessionSkills | undefined {
|
|
191
193
|
if (!owner) return undefined;
|
|
192
194
|
const user = getUser(owner);
|
|
193
195
|
if (!user) return undefined;
|
|
194
196
|
const admin = user.role === "admin";
|
|
195
|
-
const
|
|
197
|
+
const all = activeSkills(owner);
|
|
198
|
+
const keep = only ? new Set(only) : undefined;
|
|
199
|
+
const skills = keep ? all.filter((s) => keep.has(s.id)) : all;
|
|
196
200
|
const env = skillEnv(owner, skills);
|
|
197
201
|
const prompt = varsPrompt(skills, env, owner);
|
|
198
202
|
let pluginDir: string | undefined;
|
|
199
|
-
|
|
203
|
+
// 子智能体可能选了主专家没有的技能,插件资源要准备完整;各自的白名单由 driver 限定。
|
|
204
|
+
if (all.length) {
|
|
200
205
|
try {
|
|
201
|
-
pluginDir = syncPluginDir(owner,
|
|
206
|
+
pluginDir = syncPluginDir(owner, all);
|
|
202
207
|
} catch (err) {
|
|
203
208
|
console.error("[技能] 整理插件目录失败:", err instanceof Error ? err.message : err);
|
|
204
209
|
}
|
|
@@ -229,97 +234,6 @@ export function codexSkillLines(skills: SessionSkills | undefined): string[] {
|
|
|
229
234
|
return lines;
|
|
230
235
|
}
|
|
231
236
|
|
|
232
|
-
// ---------- @ 技能 ----------
|
|
233
|
-
|
|
234
|
-
export type MentionTarget = { name: string; description: string; kind: "loft" | "machine"; skillMd: string; agents?: ("claude" | "codex")[] };
|
|
235
|
-
|
|
236
|
-
/** 这个人能 @ 的技能:启用着的 agent-loft 技能;管理员再加上机器上原有的(同名时 agent-loft 的优先) */
|
|
237
|
-
export function mentionTargets(owner: string | undefined): MentionTarget[] {
|
|
238
|
-
if (!owner) return [];
|
|
239
|
-
const user = getUser(owner);
|
|
240
|
-
if (!user) return [];
|
|
241
|
-
const out: MentionTarget[] = activeSkills(owner).map((s) => ({
|
|
242
|
-
name: s.name,
|
|
243
|
-
description: s.description,
|
|
244
|
-
kind: "loft",
|
|
245
|
-
skillMd: path.join(skillDir(s.id), "SKILL.md"),
|
|
246
|
-
}));
|
|
247
|
-
if (user.role === "admin") {
|
|
248
|
-
const taken = new Set(out.map((t) => t.name));
|
|
249
|
-
for (const m of machineSkills()) {
|
|
250
|
-
if (taken.has(m.name)) continue;
|
|
251
|
-
taken.add(m.name);
|
|
252
|
-
out.push({ name: m.name, description: m.description, kind: "machine", skillMd: path.join(m.dir, "SKILL.md"), agents: m.agents });
|
|
253
|
-
}
|
|
254
|
-
}
|
|
255
|
-
return out;
|
|
256
|
-
}
|
|
257
|
-
|
|
258
|
-
/** 消息里 @ 到的技能名(前面是开头、空白或标点,不是邮箱里的 @),按出现顺序去重 */
|
|
259
|
-
export function parseMentions(text: string): string[] {
|
|
260
|
-
const out: string[] = [];
|
|
261
|
-
for (const m of text.matchAll(/(?:^|[^\w.@/-])@([a-z0-9][a-z0-9_-]*)/gi)) {
|
|
262
|
-
const name = m[1]!.toLowerCase();
|
|
263
|
-
if (!out.includes(name)) out.push(name);
|
|
264
|
-
}
|
|
265
|
-
return out;
|
|
266
|
-
}
|
|
267
|
-
|
|
268
|
-
const INLINE_MAX = 30_000;
|
|
269
|
-
|
|
270
|
-
/**
|
|
271
|
-
* 消息里 @ 了技能:附给 agent 的说明(包进 wrapContext 之前的那几行)。没 @ 到能用的就是 null。
|
|
272
|
-
* 聊天模式没有工具,直接把 SKILL.md 的内容放进来。
|
|
273
|
-
*/
|
|
274
|
-
export function mentionContext(
|
|
275
|
-
text: string,
|
|
276
|
-
opts: { owner: string | undefined; agent: string; mode: "chat" | "work" },
|
|
277
|
-
): string[] | null {
|
|
278
|
-
const names = parseMentions(text);
|
|
279
|
-
if (!names.length) return null;
|
|
280
|
-
const targets = mentionTargets(opts.owner);
|
|
281
|
-
const hits = names.map((n) => targets.find((t) => t.name === n)).filter((t): t is MentionTarget => !!t);
|
|
282
|
-
if (!hits.length) return null;
|
|
283
|
-
if (opts.mode === "chat") {
|
|
284
|
-
const lines = [
|
|
285
|
-
`用户在这条消息里点名要用技能:${hits.map((t) => t.name).join("、")}。下面是技能的说明。现在是聊天模式,不能执行命令、读写文件:说明里能直接做的照着做,需要执行命令、读文件的步骤告诉用户发 /work 切到工作模式再来。`,
|
|
286
|
-
];
|
|
287
|
-
let budget = INLINE_MAX;
|
|
288
|
-
for (const t of hits) {
|
|
289
|
-
let md = "";
|
|
290
|
-
try {
|
|
291
|
-
md = fs.readFileSync(t.skillMd, "utf8");
|
|
292
|
-
} catch {
|
|
293
|
-
md = "(读不到这个技能的 SKILL.md)";
|
|
294
|
-
}
|
|
295
|
-
if (md.length > budget) md = `${md.slice(0, Math.max(0, budget))}\n…(太长,后面省略)`;
|
|
296
|
-
budget -= md.length;
|
|
297
|
-
lines.push("", `### 技能 ${t.name}`, "", md.trim());
|
|
298
|
-
}
|
|
299
|
-
// 受保护的密钥走 skill_request(MCP 工具聊天模式下也有),调接口的技能在聊天模式也能用
|
|
300
|
-
const mentioned = activeSkills(opts.owner!).filter((sk) => hits.some((t) => t.kind === "loft" && t.name === sk.name));
|
|
301
|
-
const guarded = protectedLines(mentioned, opts.owner!);
|
|
302
|
-
if (guarded.length) lines.push("", ...guarded);
|
|
303
|
-
return lines;
|
|
304
|
-
}
|
|
305
|
-
if (opts.agent === "claude") {
|
|
306
|
-
// Claude 认得的:agent-loft 的(插件里)和它自己目录里的;只在 Codex 目录里的它不认得,让它去读文件
|
|
307
|
-
const known = hits.filter((t) => t.kind === "loft" || t.agents?.includes("claude"));
|
|
308
|
-
const other = hits.filter((t) => !known.includes(t));
|
|
309
|
-
const lines = [`用户在这条消息里点名要用技能:${hits.map((t) => t.name).join("、")}。`];
|
|
310
|
-
if (known.length) {
|
|
311
|
-
const refs = known.map((t) => (t.kind === "loft" ? `${PLUGIN_NAME}:${t.name}` : t.name));
|
|
312
|
-
lines.push(`先用 Skill 工具调用 ${refs.join("、")},再按技能的说明完成用户的要求。`);
|
|
313
|
-
}
|
|
314
|
-
if (other.length) lines.push("这些先完整读一遍 SKILL.md 再照着做(相对路径以 SKILL.md 所在目录为准):", ...other.map((t) => `- ${t.name}:${t.skillMd}`));
|
|
315
|
-
return lines;
|
|
316
|
-
}
|
|
317
|
-
return [
|
|
318
|
-
`用户在这条消息里点名要用技能:${hits.map((t) => t.name).join("、")}。先完整读一遍对应的 SKILL.md,再照着做(相对路径以 SKILL.md 所在目录为准):`,
|
|
319
|
-
...hits.map((t) => `- ${t.name}:${t.skillMd}`),
|
|
320
|
-
];
|
|
321
|
-
}
|
|
322
|
-
|
|
323
237
|
/**
|
|
324
238
|
* 成员在 Claude 会话里直接发「/机器上的技能」:CLI 会绕过白名单直接展开,这里先拦下。
|
|
325
239
|
* native 是 Claude 报上来的命令表;读不到(超时、出错)时还按扫出来的机器技能名拦,不能因此放行。
|
|
@@ -335,23 +249,6 @@ export function isMachineCommand(name: string, native: { name: string; builtin?:
|
|
|
335
249
|
return machineSkills().some((m) => m.name.toLowerCase() === bare);
|
|
336
250
|
}
|
|
337
251
|
|
|
338
|
-
/** /skills 的回复:这条对话里能 @ 的技能 */
|
|
339
|
-
export function skillsText(owner: string | undefined): string {
|
|
340
|
-
if (!owner) return "这条对话没有绑定 agent-loft 用户,用不了 agent-loft 的技能。飞书私聊里发 /bind 绑定账号后就能用。";
|
|
341
|
-
const targets = mentionTargets(owner);
|
|
342
|
-
const loft = targets.filter((t) => t.kind === "loft");
|
|
343
|
-
const machine = targets.filter((t) => t.kind === "machine");
|
|
344
|
-
const lines: string[] = [];
|
|
345
|
-
if (loft.length) {
|
|
346
|
-
lines.push(`**能用的技能(${loft.length} 个)**`, "", ...loft.map((t) => `- \`@${t.name}\` ${t.description}`));
|
|
347
|
-
} else {
|
|
348
|
-
lines.push("还没有启用任何技能。可以在网页「设置 → 技能」里新建、上传;也可以直接让 agent「把刚才的做法存成技能」。");
|
|
349
|
-
}
|
|
350
|
-
if (machine.length) lines.push("", `**本机技能(只有管理员能用,${machine.length} 个)**:${machine.map((t) => `\`@${t.name}\``).join(" ")}`);
|
|
351
|
-
lines.push("", "在消息里写 @名字 点名使用;工作模式下 agent 也会自己挑合适的用。");
|
|
352
|
-
return lines.join("\n");
|
|
353
|
-
}
|
|
354
|
-
|
|
355
252
|
/** 测试用 */
|
|
356
253
|
export function resetMachineCache(): void {
|
|
357
254
|
machineCache = null;
|
package/src/core/store.ts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
// 会话(conversation)的持久化。
|
|
2
2
|
//
|
|
3
3
|
// 一个 conversation 是「一个聊天上下文」:飞书的一个私聊 / 群 / 话题,或者 Web 上
|
|
4
|
-
//
|
|
5
|
-
//
|
|
4
|
+
// 的一条对话。它记着用哪个专家(core/experts.ts)和它的引擎(agent)、在哪个目录,以及 agent 的会话 id
|
|
5
|
+
// 和模型。专家定了就不换:飞书里换专家等于开新会话(见 hub.setExpert)。
|
|
6
6
|
import path from "node:path";
|
|
7
7
|
import { dataDir, readJson, writeJsonAtomic } from "../home.js";
|
|
8
8
|
import { config } from "./config.js";
|
|
@@ -19,11 +19,6 @@ export type AgentBinding = {
|
|
|
19
19
|
* 拿到不同于它的新会话 id 后清掉。
|
|
20
20
|
*/
|
|
21
21
|
forkFrom?: string;
|
|
22
|
-
/**
|
|
23
|
-
* 上次告诉这个 agent 会话的是哪种模式(没有 = 工作模式,agent 原装的样子)。和对话现在的模式不一样,
|
|
24
|
-
* 就要在下一条消息里说一声(Codex 换不了系统提示,见 core/chat-mode.ts)。
|
|
25
|
-
*/
|
|
26
|
-
announcedMode?: "chat" | "work";
|
|
27
22
|
};
|
|
28
23
|
|
|
29
24
|
export type Conversation = {
|
|
@@ -38,7 +33,10 @@ export type Conversation = {
|
|
|
38
33
|
* 用户手动改过名就清掉,之后不再动它。
|
|
39
34
|
*/
|
|
40
35
|
titleAuto?: boolean;
|
|
36
|
+
/** 引擎:claude / codex。按它找 driver、存会话 id */
|
|
41
37
|
agent: string;
|
|
38
|
+
/** 自定义专家的 id。没有就是内置专家,也就是 agent 本身 */
|
|
39
|
+
expert?: string;
|
|
42
40
|
cwd: string;
|
|
43
41
|
/** cwd 是否用户显式指定。没指定过的跟随 workspaceRoot 变化 */
|
|
44
42
|
cwdExplicit?: boolean;
|
|
@@ -57,8 +55,6 @@ export type Conversation = {
|
|
|
57
55
|
* 账号时记下(见 core/feishu-links.ts)。飞书群聊、没绑定的私聊和升级前就有的 Web 会话没有,归管理员。
|
|
58
56
|
*/
|
|
59
57
|
owner?: string;
|
|
60
|
-
/** chat:聊天模式(/chat)。没有就是工作模式。属于对话,跨 /new 和切 agent 保留 */
|
|
61
|
-
mode?: "chat";
|
|
62
58
|
/** 定时任务的专用对话:是哪个任务的(见 core/tasks.ts)。任务删了就清掉 */
|
|
63
59
|
taskId?: string;
|
|
64
60
|
};
|
|
@@ -70,10 +66,29 @@ let cache: StoreShape | null = null;
|
|
|
70
66
|
let persistTimer: NodeJS.Timeout | null = null;
|
|
71
67
|
|
|
72
68
|
function load(): StoreShape {
|
|
73
|
-
cache
|
|
69
|
+
if (cache) return cache;
|
|
70
|
+
cache = readJson<StoreShape>(storePath, {});
|
|
71
|
+
// 聊天模式取消了(换成了专家):以前聊天模式的对话直接丢掉,不迁移
|
|
72
|
+
let dropped = 0;
|
|
73
|
+
for (const [key, conv] of Object.entries(cache)) {
|
|
74
|
+
if ((conv as { mode?: string }).mode === "chat") {
|
|
75
|
+
delete cache[key];
|
|
76
|
+
dropped++;
|
|
77
|
+
}
|
|
78
|
+
for (const b of Object.values(conv.perAgent ?? {})) delete (b as { announcedMode?: string }).announcedMode;
|
|
79
|
+
}
|
|
80
|
+
if (dropped) {
|
|
81
|
+
console.log(`[store] 聊天模式已取消,丢掉了 ${dropped} 条聊天模式的对话`);
|
|
82
|
+
writeJsonAtomic(storePath, cache);
|
|
83
|
+
}
|
|
74
84
|
return cache;
|
|
75
85
|
}
|
|
76
86
|
|
|
87
|
+
/** 这条对话的专家 id:自定义专家的 id,或者内置专家(就是 agent 本身) */
|
|
88
|
+
export function expertIdOf(conv: Pick<Conversation, "agent" | "expert">): string {
|
|
89
|
+
return conv.expert ?? conv.agent;
|
|
90
|
+
}
|
|
91
|
+
|
|
77
92
|
/** 合并写盘:一轮对话里会频繁 touch,没必要每次都落盘。 */
|
|
78
93
|
function persist(immediate = false): void {
|
|
79
94
|
if (immediate) {
|
|
@@ -125,8 +140,10 @@ export function ensureConversation(params: {
|
|
|
125
140
|
channel: string;
|
|
126
141
|
channelId: string;
|
|
127
142
|
agent: string;
|
|
143
|
+
expert?: string;
|
|
128
144
|
title?: string;
|
|
129
145
|
owner?: string;
|
|
146
|
+
cwd?: string;
|
|
130
147
|
}): Conversation {
|
|
131
148
|
const existing = getConversation(params.key);
|
|
132
149
|
if (existing) return existing;
|
|
@@ -136,7 +153,9 @@ export function ensureConversation(params: {
|
|
|
136
153
|
channel: params.channel,
|
|
137
154
|
channelId: params.channelId,
|
|
138
155
|
agent: params.agent,
|
|
139
|
-
|
|
156
|
+
...(params.expert ? { expert: params.expert } : {}),
|
|
157
|
+
cwd: params.cwd ?? config().workspaceRoot,
|
|
158
|
+
...(params.cwd && params.cwd !== config().workspaceRoot ? { cwdExplicit: true } : {}),
|
|
140
159
|
perAgent: {},
|
|
141
160
|
activeAt: now,
|
|
142
161
|
createdAt: now,
|