agent-loft 0.2.98 → 0.2.100
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 +5 -4
- package/package.json +2 -1
- package/src/agents/claude/session.ts +58 -6
- package/src/agents/codex/app-server.ts +2 -1
- package/src/agents/codex/protocol.ts +2 -1
- package/src/agents/codex/session.ts +65 -1
- package/src/agents/health.ts +73 -2
- package/src/agents/workbuddy/account.ts +98 -0
- package/src/agents/workbuddy/driver.ts +157 -0
- package/src/agents/workbuddy/errors.ts +34 -0
- package/src/agents/workbuddy/history.ts +237 -0
- package/src/agents/workbuddy/sdk.ts +156 -0
- package/src/agents/workbuddy/session.ts +484 -0
- package/src/channels/feishu/bot.ts +1 -1
- package/src/channels/feishu/cards.ts +9 -4
- package/src/channels/web/api.ts +40 -0
- package/src/channels/web/experts-api.ts +3 -1
- package/src/channels/weixin/bot.ts +2 -1
- package/src/channels/weixin/format.ts +5 -5
- package/src/core/builtin-agents.ts +48 -7
- package/src/core/command-catalog.ts +4 -2
- package/src/core/commands.ts +13 -1
- package/src/core/config.ts +20 -3
- package/src/core/experts.ts +5 -3
- package/src/core/hub.ts +62 -12
- package/src/core/interactions.ts +1 -1
- package/src/core/memory-curator.ts +2 -2
- package/src/core/memory.ts +2 -2
- package/src/core/permission.ts +20 -2
- package/src/core/store.ts +5 -0
- package/src/core/types.ts +14 -0
- package/src/core/users.ts +1 -1
- package/src/main.ts +6 -2
- package/web/css/composer.css +15 -0
- package/web/lib/dom.js +2 -0
- package/web/lib/permission.js +23 -4
- package/web/settings/agents.js +107 -13
- package/web/settings/commands.js +1 -1
- package/web/settings/experts.js +1 -1
- package/web/settings/memory.js +2 -1
- package/web/state.js +4 -0
- package/web/views/composer.js +5 -4
- package/web/views/conv-actions.js +24 -4
- package/web/views/interaction.js +9 -5
- package/web/views/sidebar.js +2 -1
- package/web/views/tasks.js +2 -2
- package/web/views/topbar.js +16 -11
|
@@ -8,6 +8,7 @@ import { activeSkills } from "./skills.js";
|
|
|
8
8
|
import { sessionSkills } from "./skill-runtime.js";
|
|
9
9
|
import { getUser } from "./users.js";
|
|
10
10
|
import type { SessionOptions } from "./types.js";
|
|
11
|
+
import { DEFAULT_PERMISSION_LEVELS, engineSupports, type PermissionLevel } from "./permission.js";
|
|
11
12
|
|
|
12
13
|
export type BuiltinAgentDefaults = {
|
|
13
14
|
/** null = 全部已启用的个人技能;[] = 不加载个人技能 */
|
|
@@ -15,20 +16,44 @@ export type BuiltinAgentDefaults = {
|
|
|
15
16
|
machineSkills: boolean;
|
|
16
17
|
/** null = 沿用机器配置;[] = 不加载 MCP(系统工具除外) */
|
|
17
18
|
mcp: string[] | null;
|
|
19
|
+
/**
|
|
20
|
+
* 这个人用这个引擎的对话默认按哪一级权限(没单独选过级别的对话都按它,专家照样按自己的权限封顶)。
|
|
21
|
+
* null = 跟随引擎(Claude 逐次询问,Codex 按设置里的沙箱)。和技能、MCP 不同,自定义专家的对话也按它
|
|
22
|
+
*/
|
|
23
|
+
permission: PermissionLevel | null;
|
|
18
24
|
};
|
|
19
25
|
type Defaults = Record<Engine, BuiltinAgentDefaults>;
|
|
20
26
|
const file = path.join(dataDir, "builtin-agents.json");
|
|
21
27
|
export const builtinAgentEvents = new EventEmitter<{ changed: [owner: string] }>();
|
|
22
28
|
|
|
29
|
+
// 对话列表里每条都要算默认权限,不能每次都读盘。只有本文件写它
|
|
30
|
+
let cache: Record<string, Partial<Defaults>> | null = null;
|
|
31
|
+
function readAll(): Record<string, Partial<Defaults>> {
|
|
32
|
+
return (cache ??= readJson<Record<string, Partial<Defaults>>>(file, {}));
|
|
33
|
+
}
|
|
34
|
+
function writeAll(all: Record<string, Partial<Defaults>>): void {
|
|
35
|
+
writeJsonAtomic(file, all);
|
|
36
|
+
cache = all;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
function storedPermission(value: unknown, engine: Engine, admin: boolean): PermissionLevel | null {
|
|
40
|
+
if (!(DEFAULT_PERMISSION_LEVELS as readonly unknown[]).includes(value)) return null;
|
|
41
|
+
const level = value as PermissionLevel;
|
|
42
|
+
// 成员最高到自动改文件(见 hub.permissionMax);管理员降级成成员后,以前存的高一级不再算数
|
|
43
|
+
if (!engineSupports(engine, level) || (level === "auto" && !admin)) return null;
|
|
44
|
+
return level;
|
|
45
|
+
}
|
|
46
|
+
|
|
23
47
|
export function builtinAgentDefaults(owner: string): Defaults {
|
|
24
48
|
const admin = getUser(owner)?.role === "admin";
|
|
25
|
-
const stored =
|
|
49
|
+
const stored = readAll()[owner];
|
|
26
50
|
const defaults = (engine: Engine): BuiltinAgentDefaults => ({
|
|
27
51
|
skills: stored?.[engine]?.skills ?? null,
|
|
28
52
|
machineSkills: admin && stored?.[engine]?.machineSkills !== false,
|
|
29
53
|
mcp: stored?.[engine]?.mcp ?? (admin ? null : []),
|
|
54
|
+
permission: storedPermission(stored?.[engine]?.permission, engine, admin),
|
|
30
55
|
});
|
|
31
|
-
return { claude: defaults("claude"), codex: defaults("codex") };
|
|
56
|
+
return { claude: defaults("claude"), codex: defaults("codex"), workbuddy: defaults("workbuddy") };
|
|
32
57
|
}
|
|
33
58
|
|
|
34
59
|
function selection(value: unknown, what: string): string[] | null {
|
|
@@ -70,10 +95,16 @@ export function setBuiltinAgentDefaults(owner: string, patch: unknown): Defaults
|
|
|
70
95
|
}
|
|
71
96
|
current.mcp = ids;
|
|
72
97
|
}
|
|
98
|
+
if (p.permission !== undefined) {
|
|
99
|
+
if (p.permission !== null && !(DEFAULT_PERMISSION_LEVELS as readonly unknown[]).includes(p.permission)) throw new Error("默认权限只能是逐次询问、自动改文件或自动判断");
|
|
100
|
+
const level = p.permission as PermissionLevel | null;
|
|
101
|
+
if (level && !engineSupports(engine, level)) throw new Error("「自动判断」只有 Claude Code 能用");
|
|
102
|
+
if (level === "auto" && user.role !== "admin") throw new Error("只有管理员能把「自动判断」设成默认");
|
|
103
|
+
current.permission = level;
|
|
104
|
+
}
|
|
73
105
|
}
|
|
74
|
-
const all =
|
|
75
|
-
all
|
|
76
|
-
writeJsonAtomic(file, all);
|
|
106
|
+
const all = { ...readAll(), [owner]: next };
|
|
107
|
+
writeAll(all);
|
|
77
108
|
builtinAgentEvents.emit("changed", owner);
|
|
78
109
|
return next;
|
|
79
110
|
}
|
|
@@ -88,9 +119,19 @@ export function builtinAgentSession(owner: string | undefined, engine: Engine):
|
|
|
88
119
|
};
|
|
89
120
|
}
|
|
90
121
|
|
|
122
|
+
/** 对话没单独选过级别时按哪一级(没主人的对话没有默认) */
|
|
123
|
+
export function defaultPermissionOf(owner: string | undefined, engine: string): PermissionLevel | undefined {
|
|
124
|
+
if (!owner || !getUser(owner) || !(ENGINES as readonly string[]).includes(engine)) return undefined;
|
|
125
|
+
return builtinAgentDefaults(owner)[engine as Engine].permission ?? undefined;
|
|
126
|
+
}
|
|
127
|
+
|
|
91
128
|
export function deleteBuiltinAgentDefaults(owner: string): void {
|
|
92
|
-
const all =
|
|
129
|
+
const all = { ...readAll() };
|
|
93
130
|
if (!(owner in all)) return;
|
|
94
131
|
delete all[owner];
|
|
95
|
-
|
|
132
|
+
writeAll(all);
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
export function resetBuiltinAgentCacheForTest(): void {
|
|
136
|
+
cache = null;
|
|
96
137
|
}
|
|
@@ -30,12 +30,14 @@ export const BUILTIN_COMMANDS: BuiltinSpec[] = [
|
|
|
30
30
|
{ name: "cd", args: "<相对目录>", description: "切换工作目录(限 workspace 内)" },
|
|
31
31
|
{ name: "pwd", description: "显示当前工作目录" },
|
|
32
32
|
{ name: "fork", description: "从当前会话分叉,原会话保留" },
|
|
33
|
-
{ name: "permission", args: "[ask|edit|full|default]", description: "查看 /
|
|
33
|
+
{ name: "permission", args: "[ask|edit|auto|full|default]", description: "查看 / 切换本对话的权限级别(逐次询问、自动改文件、自动判断、完全允许)" },
|
|
34
|
+
{ name: "planmode", args: "[on|off]", description: "开关计划模式:先出方案,批准了再动手" },
|
|
34
35
|
{ name: "autoedit", args: "[on|off]", description: "本对话自动允许改工作目录内的文件(等于 /permission edit)" },
|
|
35
36
|
// 网页上的对话中途不能换专家(新建对话时选),这几个只在飞书、微信里有
|
|
36
37
|
{ name: "expert", args: "[名称]", description: "查看 / 换专家(换了会开新会话)", chatOnly: true },
|
|
37
38
|
{ name: "claude", description: "换成 Claude Code 专家(开新会话)", multiAgentOnly: true, chatOnly: true },
|
|
38
39
|
{ name: "codex", description: "换成 Codex 专家(开新会话)", multiAgentOnly: true, chatOnly: true },
|
|
40
|
+
{ name: "workbuddy", description: "换成 WorkBuddy 专家(开新会话)", multiAgentOnly: true, chatOnly: true },
|
|
39
41
|
{ name: "web", description: "接上一条 Web 会话,在飞书里查看和回复", feishuOnly: true },
|
|
40
42
|
{ name: "detach", description: "不再接着 Web 会话,回到这个聊天自己的会话", feishuOnly: true },
|
|
41
43
|
{ name: "bind", args: "<绑定码>", description: "把这个飞书账号绑定到你的 agent-loft 用户(绑定码在 Web 的「设置 → 账号」里生成)", feishuOnly: true },
|
|
@@ -163,7 +165,7 @@ export function buildCatalog(params: {
|
|
|
163
165
|
(!c.feishuOnly || params.channel === undefined || params.channel === "feishu") &&
|
|
164
166
|
(!c.chatOnly || params.channel !== "web") &&
|
|
165
167
|
// /claude /codex 只在这个渠道能用对应 agent 时才有意义
|
|
166
|
-
(!["claude", "codex"].includes(c.name) || params.allowedAgents.includes(c.name)),
|
|
168
|
+
(!["claude", "codex", "workbuddy"].includes(c.name) || params.allowedAgents.includes(c.name)),
|
|
167
169
|
).map((c) => ({
|
|
168
170
|
name: c.name,
|
|
169
171
|
...(c.args ? { args: c.args } : {}),
|
package/src/core/commands.ts
CHANGED
|
@@ -19,6 +19,8 @@ export type ParsedCommand =
|
|
|
19
19
|
| { kind: "status" }
|
|
20
20
|
| { kind: "pwd" }
|
|
21
21
|
| { kind: "autoedit"; on?: boolean }
|
|
22
|
+
/** 计划模式;on 不给就是切换 */
|
|
23
|
+
| { kind: "plan"; on?: boolean }
|
|
22
24
|
/** default:恢复默认;不给就是看当前级别 */
|
|
23
25
|
| { kind: "permission"; level?: PermissionLevel | "default" }
|
|
24
26
|
| { kind: "help" }
|
|
@@ -30,6 +32,7 @@ export type ParsedCommand =
|
|
|
30
32
|
const PERMISSION_ARGS: Record<string, PermissionLevel | "default"> = {
|
|
31
33
|
ask: "ask", 询问: "ask", 逐次询问: "ask",
|
|
32
34
|
edit: "edit", 自动改文件: "edit",
|
|
35
|
+
auto: "auto", 自动判断: "auto",
|
|
33
36
|
full: "full", 完全允许: "full",
|
|
34
37
|
default: "default", 默认: "default",
|
|
35
38
|
};
|
|
@@ -65,6 +68,7 @@ export function parseCommand(raw: string): ParsedCommand {
|
|
|
65
68
|
// 快捷切换到内置专家
|
|
66
69
|
case "claude":
|
|
67
70
|
case "codex":
|
|
71
|
+
case "workbuddy":
|
|
68
72
|
return arg ? { kind: "chat", text } : { kind: "agent", agent: head.toLowerCase() };
|
|
69
73
|
case "stop":
|
|
70
74
|
return { kind: "stop" };
|
|
@@ -81,6 +85,14 @@ export function parseCommand(raw: string): ParsedCommand {
|
|
|
81
85
|
if (["off", "关", "0", "false"].includes(v)) return { kind: "autoedit", on: false };
|
|
82
86
|
return { kind: "chat", text };
|
|
83
87
|
}
|
|
88
|
+
// 不叫 /plan:那是很常见的自定义命令名,内置了会把用户已有的挤掉
|
|
89
|
+
case "planmode": {
|
|
90
|
+
const v = arg.toLowerCase();
|
|
91
|
+
if (!v) return { kind: "plan" };
|
|
92
|
+
if (["on", "开", "1", "true"].includes(v)) return { kind: "plan", on: true };
|
|
93
|
+
if (["off", "关", "0", "false"].includes(v)) return { kind: "plan", on: false };
|
|
94
|
+
return { kind: "chat", text };
|
|
95
|
+
}
|
|
84
96
|
case "permission": {
|
|
85
97
|
if (!arg) return { kind: "permission" };
|
|
86
98
|
const level = Object.hasOwn(PERMISSION_ARGS, arg.toLowerCase()) ? PERMISSION_ARGS[arg.toLowerCase()] : undefined;
|
|
@@ -115,7 +127,7 @@ export function helpText(agents: string[], channel?: string): string {
|
|
|
115
127
|
...BUILTIN_COMMANDS.filter((c) => !c.multiAgentOnly || multi)
|
|
116
128
|
.filter((c) => !c.feishuOnly || channel === "feishu")
|
|
117
129
|
.filter((c) => !c.chatOnly || channel === "feishu" || channel === "weixin")
|
|
118
|
-
.filter((c) => !["claude", "codex"].includes(c.name))
|
|
130
|
+
.filter((c) => !["claude", "codex", "workbuddy"].includes(c.name))
|
|
119
131
|
.map((c) =>
|
|
120
132
|
c.name === "expert"
|
|
121
133
|
? `\`${usageOf(c)}\` ${c.description}${multi ? `,也可以直接发 ${agents.map((a) => `\`/${a}\``).join(" ")}` : ""}`
|
package/src/core/config.ts
CHANGED
|
@@ -61,6 +61,21 @@ export type AppConfig = {
|
|
|
61
61
|
/** 生成会话名称用的模型,空 = Codex 默认模型 */
|
|
62
62
|
titleModel: string;
|
|
63
63
|
};
|
|
64
|
+
/** 腾讯 WorkBuddy(CodeBuddy Code):SDK 自带 CLI,登录在 设置 → Agent 里用浏览器完成 */
|
|
65
|
+
workbuddy: {
|
|
66
|
+
enabled: boolean;
|
|
67
|
+
/**
|
|
68
|
+
* 账号所在站点:workbuddy 用本机 WorkBuddy 桌面版的 CLI(www.workbuddy.cn);
|
|
69
|
+
* internal / external / ioa 用 SDK 自带的 CLI 连 CodeBuddy 国内版、国际版、腾讯内网
|
|
70
|
+
*/
|
|
71
|
+
environment: "workbuddy" | "internal" | "external" | "ioa";
|
|
72
|
+
/** WorkBuddy 桌面版里 CLI 的路径,空 = 在常见位置自动找 */
|
|
73
|
+
cliPath: string;
|
|
74
|
+
defaultModel: string;
|
|
75
|
+
/** WorkBuddy 没有思考程度,留着和别的 agent 同形 */
|
|
76
|
+
defaultEffort: string;
|
|
77
|
+
models: string[];
|
|
78
|
+
};
|
|
64
79
|
};
|
|
65
80
|
web: {
|
|
66
81
|
enabled: boolean;
|
|
@@ -80,7 +95,7 @@ export type AppConfig = {
|
|
|
80
95
|
quotaEnabled: boolean;
|
|
81
96
|
};
|
|
82
97
|
/** 输入「/」时命令列表的顺序和隐藏项,按 agent 分开(设置 → 命令) */
|
|
83
|
-
commands: { claude: CommandPrefs; codex: CommandPrefs };
|
|
98
|
+
commands: { claude: CommandPrefs; codex: CommandPrefs; workbuddy: CommandPrefs };
|
|
84
99
|
/** 远程控制:网页终端和远程桌面。管理员能用;成员要在 设置 → 用户 里单独开(users.json 的 remote) */
|
|
85
100
|
remote: {
|
|
86
101
|
terminal: boolean;
|
|
@@ -117,7 +132,7 @@ export type AppConfig = {
|
|
|
117
132
|
};
|
|
118
133
|
};
|
|
119
134
|
|
|
120
|
-
export const AGENT_IDS = ["claude", "codex"] as const;
|
|
135
|
+
export const AGENT_IDS = ["claude", "codex", "workbuddy"] as const;
|
|
121
136
|
|
|
122
137
|
export function defaultConfig(): AppConfig {
|
|
123
138
|
return {
|
|
@@ -137,9 +152,11 @@ export function defaultConfig(): AppConfig {
|
|
|
137
152
|
autoTitle: false,
|
|
138
153
|
titleModel: "",
|
|
139
154
|
},
|
|
155
|
+
// 默认不开:要先在设置里登录
|
|
156
|
+
workbuddy: { enabled: false, environment: "workbuddy", cliPath: "", defaultModel: "", defaultEffort: "", models: [] },
|
|
140
157
|
},
|
|
141
158
|
web: { enabled: true, host: "0.0.0.0", port: 8800, passwordHash: "", trustedProxies: ["127.0.0.1", "::1"], quotaRefreshMin: 10, quotaEnabled: true },
|
|
142
|
-
commands: { claude: { order: [], hidden: [], custom: [] }, codex: { order: [], hidden: [], custom: [] } },
|
|
159
|
+
commands: { claude: { order: [], hidden: [], custom: [] }, codex: { order: [], hidden: [], custom: [] }, workbuddy: { order: [], hidden: [], custom: [] } },
|
|
143
160
|
remote: {
|
|
144
161
|
terminal: true,
|
|
145
162
|
desktop: true,
|
package/src/core/experts.ts
CHANGED
|
@@ -16,8 +16,10 @@ import { canUseMcp, claudeMachineMcp, getMcp, isMachineId, machineName, specOf,
|
|
|
16
16
|
import { activeSkills, canSee, getSkill } from "./skills.js";
|
|
17
17
|
import { canUseResource, getUser } from "./users.js";
|
|
18
18
|
|
|
19
|
-
export type Engine = "claude" | "codex";
|
|
20
|
-
export const ENGINES: readonly Engine[] = ["claude", "codex"];
|
|
19
|
+
export type Engine = "claude" | "codex" | "workbuddy";
|
|
20
|
+
export const ENGINES: readonly Engine[] = ["claude", "codex", "workbuddy"];
|
|
21
|
+
/** 能建自定义专家的引擎。WorkBuddy 目前只有内置专家(工具名、子智能体还没对齐) */
|
|
22
|
+
export const EXPERT_ENGINES: readonly Engine[] = ["claude", "codex"];
|
|
21
23
|
|
|
22
24
|
/** 一级包含一级:能跑命令就等于能改任何文件 */
|
|
23
25
|
export type ExpertAccess = "web" | "read" | "edit" | "exec";
|
|
@@ -283,7 +285,7 @@ function validate(owner: string, input: ExpertInput, prev?: Expert, selfId?: str
|
|
|
283
285
|
const name = text(pick("name"), EXPERT_LIMITS.name, "名字");
|
|
284
286
|
if (!name) throw new Error("给专家起个名字");
|
|
285
287
|
const engine = pick("engine");
|
|
286
|
-
if (engine !== "claude" && engine !== "codex") throw new Error("引擎只能是 Claude 或 Codex");
|
|
288
|
+
if (engine !== "claude" && engine !== "codex") throw new Error(engine === "workbuddy" ? "WorkBuddy 暂不支持自定义专家,用内置的 WorkBuddy 就好" : "引擎只能是 Claude 或 Codex");
|
|
287
289
|
if (prev && prev.engine !== engine) throw new Error("建好之后不能换引擎(用这个专家的对话都是这个引擎的会话)");
|
|
288
290
|
const access = pick("access");
|
|
289
291
|
if (!ACCESS_LEVELS.includes(access as ExpertAccess)) throw new Error("权限不对");
|
package/src/core/hub.ts
CHANGED
|
@@ -37,7 +37,7 @@ import {
|
|
|
37
37
|
import { formatDateTime } from "./task-schedule.js";
|
|
38
38
|
import { attachmentInfo, ensureUploadsDir, KIND_LABEL } from "./uploads.js";
|
|
39
39
|
import { memoryOwnerOf, sessionMemory } from "./personal.js";
|
|
40
|
-
import { exceedsPermission, minPermission, PERMISSION_LABEL, permissionCapOfAccess, permissionOfSandbox, type PermissionLevel } from "./permission.js";
|
|
40
|
+
import { engineSupports, exceedsPermission, forEngine, minPermission, PERMISSION_LABEL, permissionCapOfAccess, permissionOfSandbox, type PermissionLevel } from "./permission.js";
|
|
41
41
|
import { readMemory } from "./memory.js";
|
|
42
42
|
import { canUseFiles, getUser, userEvents } from "./users.js";
|
|
43
43
|
import type {
|
|
@@ -61,7 +61,7 @@ import { helpText, type ParsedCommand } from "./commands.js";
|
|
|
61
61
|
import { listScheduled } from "./scheduled.js";
|
|
62
62
|
import { expertSystemPrompt, searchLabel, stripContext, wrapContext } from "./expert-prompt.js";
|
|
63
63
|
import { availableExperts, avatarUrl, canUseExpert, expertEvents, expertToolEvents, expertRuntime, getExpert, isBuiltin, type ExpertRuntime } from "./experts.js";
|
|
64
|
-
import { builtinAgentDefaults, builtinAgentEvents, builtinAgentSession } from "./builtin-agents.js";
|
|
64
|
+
import { builtinAgentDefaults, builtinAgentEvents, builtinAgentSession, defaultPermissionOf } from "./builtin-agents.js";
|
|
65
65
|
import { mcpEvents } from "./mcp.js";
|
|
66
66
|
import { isMachineCommand, sessionSkills } from "./skill-runtime.js";
|
|
67
67
|
import { skillEvents } from "./skills.js";
|
|
@@ -204,6 +204,8 @@ export type ConversationInfo = {
|
|
|
204
204
|
permission: PermissionLevel;
|
|
205
205
|
/** 这条对话最高能选到哪一级 */
|
|
206
206
|
permissionMax: PermissionLevel;
|
|
207
|
+
/** 计划模式开着:先出方案,批准了再动手 */
|
|
208
|
+
plan?: boolean;
|
|
207
209
|
/** 这条对话的专家 */
|
|
208
210
|
expert: ExpertBadge;
|
|
209
211
|
/** 这条对话有主人、会用上主人的记忆(主人自己关了记忆的话实际不会注入,见 personal.ts) */
|
|
@@ -683,6 +685,7 @@ class Hub extends EventEmitter<{ event: [EventEnvelope]; task: [TaskTurnEnd]; "p
|
|
|
683
685
|
...(binding.sessionId || binding.forkFrom || binding.parked || binding.pastSessions?.length ? { canHandoff: true } : {}),
|
|
684
686
|
permission: this.permissionOf(conv),
|
|
685
687
|
permissionMax: this.permissionMax(conv),
|
|
688
|
+
...(conv.plan ? { plan: true } : {}),
|
|
686
689
|
expert: this.expertBadge(conv),
|
|
687
690
|
...(memoryOwnerOf(conv) ? { personal: true } : {}),
|
|
688
691
|
...(conv.taskId ? { taskId: conv.taskId } : {}),
|
|
@@ -788,6 +791,7 @@ class Hub extends EventEmitter<{ event: [EventEnvelope]; task: [TaskTurnEnd]; "p
|
|
|
788
791
|
...(resumeId ? { resumeId } : {}),
|
|
789
792
|
...(fork ? { fork: true } : {}),
|
|
790
793
|
...(permission ? { permission } : {}),
|
|
794
|
+
...(conv.plan ? { plan: true } : {}),
|
|
791
795
|
...(taskOwner && getUser(taskOwner)?.role !== "admin" ? { noSessionGrant: true } : {}),
|
|
792
796
|
...(expert ? { expert } : {}),
|
|
793
797
|
...(memory ? { memory } : {}),
|
|
@@ -809,6 +813,11 @@ class Hub extends EventEmitter<{ event: [EventEnvelope]; task: [TaskTurnEnd]; "p
|
|
|
809
813
|
onTodos: (todos) => alive() && this.emitEvent(key, { type: "todos", todos }),
|
|
810
814
|
onTextDelta: (text) => alive() && this.emitEvent(key, { type: "delta", text }),
|
|
811
815
|
onText: (text) => alive() && this.emitEvent(key, { type: "text", text }),
|
|
816
|
+
onPlanMode: (on) => {
|
|
817
|
+
if (!alive() || !!getConversation(key)?.plan === on) return;
|
|
818
|
+
updateConversation(key, { plan: on || undefined });
|
|
819
|
+
this.emitEvent(key, { type: "meta" });
|
|
820
|
+
},
|
|
812
821
|
onFollowUp: (text) => {
|
|
813
822
|
if (!alive()) return;
|
|
814
823
|
try {
|
|
@@ -1499,7 +1508,7 @@ class Hub extends EventEmitter<{ event: [EventEnvelope]; task: [TaskTurnEnd]; "p
|
|
|
1499
1508
|
channel: "weixin", channelId: conv.channelId,
|
|
1500
1509
|
agent: conv.agent, expert: conv.expert, owner: conv.owner,
|
|
1501
1510
|
cwd: conv.cwd, cwdExplicit: conv.cwdExplicit,
|
|
1502
|
-
...(
|
|
1511
|
+
...carriedPermission(conv),
|
|
1503
1512
|
perAgent: {}, createdAt: now, activeAt: now,
|
|
1504
1513
|
...patch,
|
|
1505
1514
|
};
|
|
@@ -1635,10 +1644,14 @@ class Hub extends EventEmitter<{ event: [EventEnvelope]; task: [TaskTurnEnd]; "p
|
|
|
1635
1644
|
return !admin && conv.agent === "codex" ? minPermission(max, permissionOfSandbox(config().agents.codex.sandbox)) : max;
|
|
1636
1645
|
}
|
|
1637
1646
|
|
|
1638
|
-
/**
|
|
1647
|
+
/**
|
|
1648
|
+
* 交给 session 的级别:选过的按上限封顶,引擎不认的降一级(Codex 没有自动判断);
|
|
1649
|
+
* 没选过就按主人在设置里定的默认,也没有就是 undefined,走引擎默认。
|
|
1650
|
+
* 定时任务的专用对话不用默认:级别只跟着任务走
|
|
1651
|
+
*/
|
|
1639
1652
|
private effectivePermission(conv: Conversation): PermissionLevel | undefined {
|
|
1640
|
-
const wanted = requestedPermission(conv);
|
|
1641
|
-
return wanted ? minPermission(wanted, this.permissionMax(conv)) : undefined;
|
|
1653
|
+
const wanted = requestedPermission(conv) ?? (conv.taskId ? undefined : defaultPermissionOf(memoryOwnerOf(conv), conv.agent));
|
|
1654
|
+
return wanted ? forEngine(conv.agent, minPermission(wanted, this.permissionMax(conv))) : undefined;
|
|
1642
1655
|
}
|
|
1643
1656
|
|
|
1644
1657
|
/** 给人看的级别:没选过就换算引擎默认(Claude 逐次询问,Codex 看设置里的沙箱,不超过专家) */
|
|
@@ -1687,12 +1700,14 @@ class Hub extends EventEmitter<{ event: [EventEnvelope]; task: [TaskTurnEnd]; "p
|
|
|
1687
1700
|
private describePermission(key: string): string {
|
|
1688
1701
|
const conv = getConversation(key)!;
|
|
1689
1702
|
return [
|
|
1690
|
-
`当前权限:${PERMISSION_LABEL[this.permissionOf(conv)]}。`,
|
|
1703
|
+
`当前权限:${PERMISSION_LABEL[this.permissionOf(conv)]}${conv.plan ? ",计划模式开着" : ""}。`,
|
|
1691
1704
|
"",
|
|
1692
1705
|
"- `/permission ask`:逐次询问",
|
|
1693
1706
|
"- `/permission edit`:自动改文件",
|
|
1707
|
+
...(engineSupports(conv.agent, "auto") ? ["- `/permission auto`:自动判断(Claude 逐个判断安不安全,拿不准再问你)"] : []),
|
|
1694
1708
|
"- `/permission full`:完全允许",
|
|
1695
|
-
"- `/permission default
|
|
1709
|
+
"- `/permission default`:恢复默认(设置 → Agent 里定的默认权限)",
|
|
1710
|
+
"- `/planmode on` / `/planmode off`:开关计划模式(先出方案,你批准了再动手)",
|
|
1696
1711
|
"",
|
|
1697
1712
|
`这条对话最高能到「${PERMISSION_LABEL[this.permissionMax(conv)]}」。`,
|
|
1698
1713
|
].join("\n");
|
|
@@ -1705,6 +1720,7 @@ class Hub extends EventEmitter<{ event: [EventEnvelope]; task: [TaskTurnEnd]; "p
|
|
|
1705
1720
|
return `⚠️ 已切换为「完全允许」:agent 的操作不再询问,可以跑任意命令、改任意文件。提问和标了「调用前询问」的 MCP 照常询问;开新会话后恢复默认。${nextTurn}`;
|
|
1706
1721
|
}
|
|
1707
1722
|
if (level === "ask") return `已切换为「逐次询问」:改文件、跑命令都要先问你。${nextTurn}`;
|
|
1723
|
+
if (level === "auto") return "已切换为「自动判断」:Claude 逐个判断操作安不安全,安全的直接做,拿不准的再问你。";
|
|
1708
1724
|
return conv.agent === "codex"
|
|
1709
1725
|
? `已切换为「自动改文件」:工作目录(${conv.cwd})内可以直接改文件、跑命令,超出沙箱的要先问你。${nextTurn}`
|
|
1710
1726
|
: `已切换为「自动改文件」:修改工作目录(${conv.cwd})内的文件不再询问;目录外的文件、Bash 命令照常询问。`;
|
|
@@ -1714,6 +1730,7 @@ class Hub extends EventEmitter<{ event: [EventEnvelope]; task: [TaskTurnEnd]; "p
|
|
|
1714
1730
|
const conv = getConversation(key)!;
|
|
1715
1731
|
if (conv.taskId) return "这是定时任务的专用对话,权限跟着任务走。到定时任务页面编辑这个任务来改。";
|
|
1716
1732
|
if (level === "full" && !allowFull) return "只有管理员本人能选「完全允许」。飞书上要在私聊里、并且绑定了管理员账号。";
|
|
1733
|
+
if (level && !engineSupports(conv.agent, level)) return `「${PERMISSION_LABEL[level]}」只有 Claude Code 能用。`;
|
|
1717
1734
|
const max = this.permissionMax(conv);
|
|
1718
1735
|
if (level && exceedsPermission(level, max)) return `这条对话最高只能到「${PERMISSION_LABEL[max]}」(看对话的主人和专家的权限)。`;
|
|
1719
1736
|
this.applyPermission(key, level);
|
|
@@ -1725,6 +1742,31 @@ class Hub extends EventEmitter<{ event: [EventEnvelope]; task: [TaskTurnEnd]; "p
|
|
|
1725
1742
|
return this.serial(key, async () => this.setPermissionNow(key, level, allowFull));
|
|
1726
1743
|
}
|
|
1727
1744
|
|
|
1745
|
+
/** 计划模式。on 不给就是切换。不动权限级别:批准方案后按原来的级别干活 */
|
|
1746
|
+
private setPlanNow(key: string, on: boolean | undefined): string {
|
|
1747
|
+
const conv = getConversation(key)!;
|
|
1748
|
+
if (conv.taskId) return "定时任务的专用对话到点就要直接干活,不能开计划模式。";
|
|
1749
|
+
const next = on ?? !conv.plan;
|
|
1750
|
+
if (next === !!conv.plan) return next ? "计划模式本来就开着。" : "计划模式本来就关着。";
|
|
1751
|
+
updateConversation(key, { plan: next || undefined });
|
|
1752
|
+
const live = this.live.get(key);
|
|
1753
|
+
live?.session.setPlan?.(next)?.catch((err) => {
|
|
1754
|
+
// 没切过去:不能让它照旧动手(或一直只出方案),空闲下来按新开关重新拉起
|
|
1755
|
+
console.warn(`[${conv.agent}] ${key} 切换计划模式失败:`, err instanceof Error ? err.message : err);
|
|
1756
|
+
this.staleLive.add(live.id);
|
|
1757
|
+
this.dropIfStale(key);
|
|
1758
|
+
});
|
|
1759
|
+
this.emitEvent(key, { type: "meta" });
|
|
1760
|
+
const nextTurn = conv.agent === "codex" ? "下一轮起生效。" : "";
|
|
1761
|
+
return next
|
|
1762
|
+
? `已打开计划模式:先只读、出方案,你批准了再按「${PERMISSION_LABEL[this.permissionOf(conv)]}」动手。${nextTurn}`
|
|
1763
|
+
: `已关闭计划模式。${nextTurn}`;
|
|
1764
|
+
}
|
|
1765
|
+
|
|
1766
|
+
setPlan(key: string, on?: boolean): Promise<string> {
|
|
1767
|
+
return this.serial(key, async () => this.setPlanNow(key, on));
|
|
1768
|
+
}
|
|
1769
|
+
|
|
1728
1770
|
/** /autoedit:on 不给就是切换。「自动改文件」的旧叫法,关掉就是恢复默认 */
|
|
1729
1771
|
private setAutoEditNow(key: string, on: boolean | undefined): string {
|
|
1730
1772
|
const conv = getConversation(key)!;
|
|
@@ -2017,7 +2059,7 @@ class Hub extends EventEmitter<{ event: [EventEnvelope]; task: [TaskTurnEnd]; "p
|
|
|
2017
2059
|
`目录:${conv.cwd}`,
|
|
2018
2060
|
`模型:${runtime.model ?? "默认"}`,
|
|
2019
2061
|
...(runtime.effort ? [`思考程度:${runtime.effort}`] : []),
|
|
2020
|
-
`权限:${PERMISSION_LABEL[this.permissionOf(conv)]}(/permission 切换)`,
|
|
2062
|
+
`权限:${PERMISSION_LABEL[this.permissionOf(conv)]}${conv.plan ? ",计划模式" : ""}(/permission、/planmode 切换)`,
|
|
2021
2063
|
...(extra.length > 0 ? ["", ...extra] : []),
|
|
2022
2064
|
].join("\n");
|
|
2023
2065
|
}
|
|
@@ -2081,7 +2123,7 @@ class Hub extends EventEmitter<{ event: [EventEnvelope]; task: [TaskTurnEnd]; "p
|
|
|
2081
2123
|
cwd: conv.cwd,
|
|
2082
2124
|
...(conv.cwdExplicit ? { cwdExplicit: true } : {}),
|
|
2083
2125
|
// 「完全允许」不跟着分叉过去
|
|
2084
|
-
...(
|
|
2126
|
+
...carriedPermission(conv),
|
|
2085
2127
|
...(conv.expert ? { expert: conv.expert } : {}),
|
|
2086
2128
|
forkOf: key,
|
|
2087
2129
|
perAgent: {
|
|
@@ -2161,7 +2203,7 @@ class Hub extends EventEmitter<{ event: [EventEnvelope]; task: [TaskTurnEnd]; "p
|
|
|
2161
2203
|
cwd: conv.cwd,
|
|
2162
2204
|
...(conv.cwdExplicit ? { cwdExplicit: true } : {}),
|
|
2163
2205
|
// 和分叉一样,「完全允许」不跟过去
|
|
2164
|
-
...(
|
|
2206
|
+
...carriedPermission(conv),
|
|
2165
2207
|
forkOf: key,
|
|
2166
2208
|
handoff: true,
|
|
2167
2209
|
});
|
|
@@ -2244,12 +2286,14 @@ class Hub extends EventEmitter<{ event: [EventEnvelope]; task: [TaskTurnEnd]; "p
|
|
|
2244
2286
|
...(channel ? { channel } : {}),
|
|
2245
2287
|
...(owner && getUser(owner)?.role !== "admin" ? { member: true } : {}),
|
|
2246
2288
|
});
|
|
2247
|
-
return { type: "commands", agent: conv.agent, commands: all.filter((c) => !c.hidden && (!["claude", "codex"].includes(c.name) || ctx.allowedExperts === undefined || ctx.allowedExperts.includes(c.name))) };
|
|
2289
|
+
return { type: "commands", agent: conv.agent, commands: all.filter((c) => !c.hidden && (!["claude", "codex", "workbuddy"].includes(c.name) || ctx.allowedExperts === undefined || ctx.allowedExperts.includes(c.name))) };
|
|
2248
2290
|
}
|
|
2249
2291
|
case "pwd":
|
|
2250
2292
|
return text(getConversation(key)!.cwd);
|
|
2251
2293
|
case "autoedit":
|
|
2252
2294
|
return text(await this.setAutoEdit(key, cmd.on));
|
|
2295
|
+
case "plan":
|
|
2296
|
+
return text(await this.setPlan(key, cmd.on));
|
|
2253
2297
|
case "permission":
|
|
2254
2298
|
return text(cmd.level ? await this.setPermission(key, cmd.level === "default" ? undefined : cmd.level, ctx.allowFullAccess === true) : this.describePermission(key));
|
|
2255
2299
|
case "status":
|
|
@@ -2337,3 +2381,9 @@ class Hub extends EventEmitter<{ event: [EventEnvelope]; task: [TaskTurnEnd]; "p
|
|
|
2337
2381
|
}
|
|
2338
2382
|
|
|
2339
2383
|
export const hub = new Hub();
|
|
2384
|
+
|
|
2385
|
+
/** 分叉、交接、微信开新对话时带过去的级别:「完全允许」不跟过去,放手只是对原来那件事说的 */
|
|
2386
|
+
function carriedPermission(conv: Conversation): { permission?: PermissionLevel } {
|
|
2387
|
+
const level = requestedPermission(conv);
|
|
2388
|
+
return level && level !== "full" ? { permission: level } : {};
|
|
2389
|
+
}
|
package/src/core/interactions.ts
CHANGED
|
@@ -232,7 +232,7 @@ function publicView(entry: Entry | Interaction): Interaction {
|
|
|
232
232
|
}
|
|
233
233
|
|
|
234
234
|
export function isDetached(interaction: Interaction): boolean {
|
|
235
|
-
return
|
|
235
|
+
return !!interaction.spec.detached;
|
|
236
236
|
}
|
|
237
237
|
|
|
238
238
|
export function unansweredCount(entry: Interaction): number {
|
|
@@ -480,7 +480,7 @@ export function describeResult(r: CurateResult): string | undefined {
|
|
|
480
480
|
|
|
481
481
|
/** 按用户的设置挑 agent。指定的那个用不了就是 undefined(不悄悄换成另一个,免得用到他没想用的额度) */
|
|
482
482
|
export function pickDriver(settings: Pick<CurateSettings, "agent">): AgentDriver | undefined {
|
|
483
|
-
const usable = hub.enabledAgents().filter((d) => d.complete && agentAvailability(d.id as "claude" | "codex")?.available !== false);
|
|
483
|
+
const usable = hub.enabledAgents().filter((d) => d.complete && agentAvailability(d.id as "claude" | "codex" | "workbuddy")?.available !== false);
|
|
484
484
|
if (settings.agent !== "auto") return usable.find((d) => d.id === settings.agent);
|
|
485
485
|
return usable.find((d) => d.id === "claude") ?? usable[0];
|
|
486
486
|
}
|
|
@@ -525,7 +525,7 @@ export async function curateBatch(
|
|
|
525
525
|
const driver = opts.driver ?? pickDriver(memory.curate);
|
|
526
526
|
if (!driver) {
|
|
527
527
|
// 没有能用的 agent:留着,等它能用了再整理
|
|
528
|
-
log.error = memory.curate.agent === "auto" ? "没有能用的 agent" : `${
|
|
528
|
+
log.error = memory.curate.agent === "auto" ? "没有能用的 agent" : `${({ claude: "Claude", codex: "Codex", workbuddy: "WorkBuddy" } as Record<string, string>)[memory.curate.agent] ?? memory.curate.agent} 现在用不了(没启用、没装或没登录)`;
|
|
529
529
|
patchMeta(userId, { lastCuration: log });
|
|
530
530
|
return log;
|
|
531
531
|
}
|
package/src/core/memory.ts
CHANGED
|
@@ -102,7 +102,7 @@ export type CurateSettings = {
|
|
|
102
102
|
idleMinutes: number;
|
|
103
103
|
dailyHour: number;
|
|
104
104
|
/** auto:Claude 能用就用 Claude,否则 Codex */
|
|
105
|
-
agent: "auto" | "claude" | "codex";
|
|
105
|
+
agent: "auto" | "claude" | "codex" | "workbuddy";
|
|
106
106
|
/** 空 = 这个 agent 最省的默认(Claude 用 Haiku,Codex 用默认模型、思考程度 low) */
|
|
107
107
|
model: string;
|
|
108
108
|
};
|
|
@@ -120,7 +120,7 @@ function cleanCurate(raw: Partial<CurateSettings> | undefined, base: CurateSetti
|
|
|
120
120
|
: base.experts;
|
|
121
121
|
const idle = Math.round(Number(r.idleMinutes ?? base.idleMinutes));
|
|
122
122
|
const hour = Math.round(Number(r.dailyHour ?? base.dailyHour));
|
|
123
|
-
const agent = (["auto", "claude", "codex"] as const).find((a) => a === r.agent) ?? base.agent;
|
|
123
|
+
const agent = (["auto", "claude", "codex", "workbuddy"] as const).find((a) => a === r.agent) ?? base.agent;
|
|
124
124
|
const model = typeof r.model === "string" ? r.model.trim().slice(0, 100) : base.model;
|
|
125
125
|
return {
|
|
126
126
|
when,
|
package/src/core/permission.ts
CHANGED
|
@@ -2,27 +2,45 @@
|
|
|
2
2
|
//
|
|
3
3
|
// ask 逐次询问 Claude:default; Codex:只读沙箱(写文件要批准)
|
|
4
4
|
// edit 自动改文件 Claude:acceptEdits; Codex:工作区可写沙箱
|
|
5
|
+
// auto 自动判断 Claude:auto(分类器逐个判断,拿不准再问);Codex 没有,按自动改文件算
|
|
5
6
|
// full 完全允许 Claude:default + 全放行;Codex:无沙箱 + 全放行
|
|
6
7
|
//
|
|
7
|
-
// 不选级别(undefined)=
|
|
8
|
+
// 不选级别(undefined)= 按主人在设置里定的默认(见 builtin-agents.ts),没定就是老行为:
|
|
9
|
+
// Claude 逐次询问,Codex 按设置里的沙箱。老对话、老任务都不受影响。
|
|
8
10
|
//
|
|
9
11
|
// 完全允许不用 Claude 的 bypassPermissions:那会让 canUseTool 变成死代码,提问卡和「调用前询问」的 MCP 都走不到。
|
|
10
12
|
// Codex 也不用 approvalPolicy: never:实测 on-request 配无沙箱一样不弹审批,还留着 MCP 审批这条路。
|
|
13
|
+
//
|
|
14
|
+
// 计划模式(先出方案、批准了再动手)不是一个级别,是和级别叠加的开关,见 store.ts 的 Conversation.plan。
|
|
11
15
|
import type { ExpertAccess } from "./experts.js";
|
|
12
16
|
|
|
13
|
-
export const PERMISSION_LEVELS = ["ask", "edit", "full"] as const;
|
|
17
|
+
export const PERMISSION_LEVELS = ["ask", "edit", "auto", "full"] as const;
|
|
14
18
|
export type PermissionLevel = (typeof PERMISSION_LEVELS)[number];
|
|
15
19
|
|
|
16
20
|
export const PERMISSION_LABEL: Record<PermissionLevel, string> = {
|
|
17
21
|
ask: "逐次询问",
|
|
18
22
|
edit: "自动改文件",
|
|
23
|
+
auto: "自动判断",
|
|
19
24
|
full: "完全允许",
|
|
20
25
|
};
|
|
21
26
|
|
|
27
|
+
/** 能当默认权限的级别:完全允许是对一次任务说的,不能默认放开 */
|
|
28
|
+
export const DEFAULT_PERMISSION_LEVELS = ["ask", "edit", "auto"] as const;
|
|
29
|
+
|
|
22
30
|
export function isPermissionLevel(v: unknown): v is PermissionLevel {
|
|
23
31
|
return typeof v === "string" && (PERMISSION_LEVELS as readonly string[]).includes(v);
|
|
24
32
|
}
|
|
25
33
|
|
|
34
|
+
/** 这个引擎认不认这一级:自动判断只有 Claude 有(WorkBuddy 也按自动改文件算) */
|
|
35
|
+
export function engineSupports(agent: string, level: PermissionLevel): boolean {
|
|
36
|
+
return level !== "auto" || agent === "claude";
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
/** 引擎不认的级别降到它认的最近一级(Codex 的自动判断按自动改文件算) */
|
|
40
|
+
export function forEngine(agent: string, level: PermissionLevel): PermissionLevel {
|
|
41
|
+
return engineSupports(agent, level) ? level : "edit";
|
|
42
|
+
}
|
|
43
|
+
|
|
26
44
|
export function minPermission(a: PermissionLevel, b: PermissionLevel): PermissionLevel {
|
|
27
45
|
return PERMISSION_LEVELS.indexOf(a) <= PERMISSION_LEVELS.indexOf(b) ? a : b;
|
|
28
46
|
}
|
package/src/core/store.ts
CHANGED
|
@@ -64,6 +64,11 @@ export type Conversation = {
|
|
|
64
64
|
* 「自动改文件」跨 /new 保留,「完全允许」开新会话时清掉。实际生效的还要封顶,见 hub.permissionMax。
|
|
65
65
|
*/
|
|
66
66
|
permission?: PermissionLevel;
|
|
67
|
+
/**
|
|
68
|
+
* 计划模式:agent 先出方案,用户批准了才按 permission 动手。和权限级别叠加,属于对话;
|
|
69
|
+
* 方案批准后自动关掉(见 hub 的 onPlanMode)
|
|
70
|
+
*/
|
|
71
|
+
plan?: boolean;
|
|
67
72
|
/** 以前 /autoedit 记的,只读不写(Claude 下等于 permission: "edit");选过级别就清掉 */
|
|
68
73
|
autoEdit?: boolean;
|
|
69
74
|
/** 从哪条对话分叉出来的(对话 key),列表里据此显示关联 */
|
package/src/core/types.ts
CHANGED
|
@@ -60,6 +60,14 @@ export type InteractionSpec =
|
|
|
60
60
|
alwaysGlobal?: boolean;
|
|
61
61
|
/** 给了就显示「本会话全部允许」按钮。只有 agent 能真正兑现时才给 */
|
|
62
62
|
allowSession?: boolean;
|
|
63
|
+
/** 「允许一次」「拒绝」按钮换个说法(批准计划:开始执行 / 继续改方案) */
|
|
64
|
+
allowLabel?: string;
|
|
65
|
+
denyLabel?: string;
|
|
66
|
+
/**
|
|
67
|
+
* 发起方不等这张卡(Codex 出完方案那一轮已经结束了):用户另外发了消息就撤掉,
|
|
68
|
+
* 和不阻塞的提问一样(见 interactions.dismissDetached)
|
|
69
|
+
*/
|
|
70
|
+
detached?: boolean;
|
|
63
71
|
}
|
|
64
72
|
| {
|
|
65
73
|
kind: "question";
|
|
@@ -108,6 +116,8 @@ export type AgentEvents = {
|
|
|
108
116
|
onTextDelta: (delta: string) => void;
|
|
109
117
|
/** 一段完整的回复正文 */
|
|
110
118
|
onText: (text: string) => void;
|
|
119
|
+
/** agent 自己进出了计划模式(用户批准了方案、Claude 自己进了计划模式):核心据此更新对话上的开关 */
|
|
120
|
+
onPlanMode?: (on: boolean) => void;
|
|
111
121
|
/** 用户回答了不阻塞的提问(detached):把答案当下一条用户消息发出 */
|
|
112
122
|
onFollowUp?: (text: string) => void;
|
|
113
123
|
onResult: (result: TurnResult) => void;
|
|
@@ -223,6 +233,8 @@ export type SessionOptions = {
|
|
|
223
233
|
uploadsDir: string;
|
|
224
234
|
/** 权限级别(见 core/permission.ts),已按主人和专家封顶。不给 = 老行为:Claude 逐次询问,Codex 按设置里的沙箱 */
|
|
225
235
|
permission?: PermissionLevel | undefined;
|
|
236
|
+
/** 计划模式:先出方案,用户批准了再按 permission 动手(见 store.ts 的 Conversation.plan) */
|
|
237
|
+
plan?: boolean;
|
|
226
238
|
/** 不给「本会话全部允许」按钮:有主人的对话,主人不是管理员 */
|
|
227
239
|
noSessionGrant?: boolean;
|
|
228
240
|
/**
|
|
@@ -285,6 +297,8 @@ export interface AgentSession {
|
|
|
285
297
|
dispose(): Promise<void>;
|
|
286
298
|
/** 运行中切换权限级别。不追溯已经弹出的授权 */
|
|
287
299
|
setPermission?(level: PermissionLevel | undefined): Promise<void>;
|
|
300
|
+
/** 开关计划模式。Claude 立即生效,Codex 下一轮生效 */
|
|
301
|
+
setPlan?(on: boolean): Promise<void>;
|
|
288
302
|
}
|
|
289
303
|
|
|
290
304
|
export type Diagnosis = {
|
package/src/core/users.ts
CHANGED
|
@@ -204,7 +204,7 @@ function cleanPermissions(value: unknown, current: ResourcePermissions = {}): Re
|
|
|
204
204
|
for (const [kind, ids] of Object.entries(value)) {
|
|
205
205
|
if (!["experts", "agents", "servers"].includes(kind)) throw new Error("未知的使用权限");
|
|
206
206
|
if (ids !== null && (!Array.isArray(ids) || ids.length > 200 || ids.some((id) => typeof id !== "string" || !/^[\w-]{1,100}$/.test(id)))) throw new Error("使用权限必须是 ID 列表或 null");
|
|
207
|
-
if (kind === "agents" && ids?.some((id: string) => !["claude", "codex"].includes(id))) throw new Error("未知的内置 Agent");
|
|
207
|
+
if (kind === "agents" && ids?.some((id: string) => !["claude", "codex", "workbuddy"].includes(id))) throw new Error("未知的内置 Agent");
|
|
208
208
|
next[kind as ResourceKind] = ids === null ? null : [...new Set(ids as string[])];
|
|
209
209
|
}
|
|
210
210
|
return next;
|
package/src/main.ts
CHANGED
|
@@ -5,6 +5,7 @@ import { flushStore, getConversation } from "./core/store.js";
|
|
|
5
5
|
import { backfillLibrary, startLibraryCapture, tidyLibrary } from "./core/library.js";
|
|
6
6
|
import { ClaudeDriver } from "./agents/claude/driver.js";
|
|
7
7
|
import { CodexDriver } from "./agents/codex/driver.js";
|
|
8
|
+
import { WorkBuddyDriver } from "./agents/workbuddy/driver.js";
|
|
8
9
|
import { agentHealth } from "./agents/health.js";
|
|
9
10
|
import { startFeishu, stopFeishu } from "./channels/feishu/index.js";
|
|
10
11
|
import { startWeixin, stopWeixin } from "./channels/weixin/index.js";
|
|
@@ -20,7 +21,7 @@ import { startScheduler, stopScheduler } from "./core/scheduled.js";
|
|
|
20
21
|
import { startTaskRunner, stopTaskRunner } from "./core/task-runner.js";
|
|
21
22
|
import { startTasksBridge, stopTasksBridge } from "./core/tasks-bridge.js";
|
|
22
23
|
|
|
23
|
-
async function startDriver(id: "claude" | "codex"): Promise<void> {
|
|
24
|
+
async function startDriver(id: "claude" | "codex" | "workbuddy"): Promise<void> {
|
|
24
25
|
const driver = hub.driver(id);
|
|
25
26
|
if (!driver) return;
|
|
26
27
|
try {
|
|
@@ -37,11 +38,14 @@ async function main(): Promise<void> {
|
|
|
37
38
|
|
|
38
39
|
hub.registerDriver(new ClaudeDriver());
|
|
39
40
|
hub.registerDriver(new CodexDriver());
|
|
41
|
+
hub.registerDriver(new WorkBuddyDriver());
|
|
40
42
|
if (config().agents.claude.enabled) await startDriver("claude");
|
|
41
43
|
if (config().agents.codex.enabled) await startDriver("codex");
|
|
42
|
-
|
|
44
|
+
if (config().agents.workbuddy.enabled) void startDriver("workbuddy");
|
|
45
|
+
// Web 上新启用了 Codex:现拉 app-server;WorkBuddy 预先加载 SDK
|
|
43
46
|
onConfigChange((next, prev) => {
|
|
44
47
|
if (next.agents.codex.enabled && !prev.agents.codex.enabled) void startDriver("codex");
|
|
48
|
+
if (next.agents.workbuddy.enabled && !prev.agents.workbuddy.enabled) void startDriver("workbuddy");
|
|
45
49
|
});
|
|
46
50
|
|
|
47
51
|
// 资料库:升级时把已有的附件收进来(只一次),再清掉对话没了的、上传了一直没发的
|