agent-loft 0.2.76 → 0.2.77
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 +2 -2
- package/package.json +1 -1
- package/src/agents/claude/session.ts +27 -13
- package/src/agents/codex/driver.ts +1 -1
- package/src/agents/codex/session.ts +26 -11
- package/src/channels/feishu/bot.ts +2 -0
- package/src/channels/web/api.ts +8 -0
- package/src/channels/web/server.ts +1 -0
- package/src/channels/web/tasks-api.ts +18 -2
- package/src/core/command-catalog.ts +2 -1
- package/src/core/commands.ts +15 -0
- package/src/core/hub.ts +130 -17
- package/src/core/permission.ts +42 -0
- package/src/core/store.ts +12 -1
- package/src/core/task-runner.ts +17 -8
- package/src/core/tasks-bridge.ts +28 -2
- package/src/core/tasks.ts +20 -0
- package/src/core/types.ts +7 -4
- package/web/css/composer.css +46 -0
- package/web/css/tasks.css +4 -0
- package/web/css/topbar.css +4 -3
- package/web/lib/dom.js +1 -0
- package/web/lib/permission.js +30 -0
- package/web/settings/commands.js +1 -1
- package/web/views/composer.js +8 -3
- package/web/views/conv-actions.js +33 -0
- package/web/views/tasks.js +47 -5
- package/web/views/topbar.js +29 -2
package/README.md
CHANGED
|
@@ -73,7 +73,7 @@ Logo 就是这个意思:一大两小几颗星(多个 agent)站在同一张
|
|
|
73
73
|
- **网页多服务器切换**:在 设置 → 服务器 添加其他 agent-loft,再点「授权」到对方页面确认,侧栏左上角就能切换;各台分别登录,切走后保持连接,列表显示待处理数和运行状态,刷新后保留选择。几台需使用同一主域名下的 HTTPS 地址(例如 `mac.example.com`、`nas.example.com`)。在外层页面开启系统通知后,各台的提醒都能推到同一个主屏幕 App,点通知自动切到对应服务器和对话。见[使用指南](docs/产品介绍.md#在网页和手机上切换多台服务器)。
|
|
74
74
|
- **系统通知**:Web 会话回复完成、出错、需要授权或提问时推送到手机 / 电脑(设置 → 通知 → 「在此设备开启通知」,可以发测试通知)。飞书会话由飞书提醒,正在前台看着的会话不推。需要 HTTPS 访问,iPhone 需 iOS 16.4+ 且从主屏幕图标打开。
|
|
75
75
|
- **跨渠道同步**:飞书里的会话在 Web 上也能打开接着聊。同一个授权请求同时出现在飞书卡片和网页上,哪边先点算哪边,另一边自动变成「已处理」。
|
|
76
|
-
- **授权**:允许一次 / 本会话全部允许 / 总是允许(按钮上写明放行范围)/
|
|
76
|
+
- **授权**:允许一次 / 本会话全部允许 / 总是允许(按钮上写明放行范围)/ 拒绝。权限级别(输入框左下角或 `/permission`):逐次询问 / 自动改文件 / 完全允许,定时任务也可以单独设,完全允许只给管理员。`/autoedit on` 让 Claude Code 在这条会话里改工作目录内的文件不再询问(Bash 仍询问)。超时一律按拒绝处理。
|
|
77
77
|
- **设置都在网页上**,按用途分组:**我的**(账号和密码、飞书绑定、登录设备、通知、记忆、技能、用量,每个人都有);**Agent**(运行环境、各 agent 的默认模型和思考程度、可选模型、Codex 沙箱、额度查询;工作目录、会话闲置过期、授权卡超时和 Claude 的「总是允许」名单;「/」命令);**连接**(飞书机器人、配对批准、指令面板同步;远程控制;服务器);**管理**(用户、所有人的登录设备;服务端版本和升级、重启、局域网访问和端口)。设置、新建 / 编辑专家、重命名等编辑弹窗不会因点击外部或按 Esc 关闭;通过关闭、取消或保存 / 完成按钮退出。改了没保存就切页或关掉设置会先提醒。
|
|
78
78
|
- **多用户**(信任型):管理员在 设置 → 用户 里给别人建账号。每个人只看得到自己的对话、授权和通知,设置只有管理员能改,见下面「安全」。
|
|
79
79
|
- **专家**:设置 → 专家。专家是一份配置,新建对话、定时任务时选一个,对话从头到尾都是它(中途不能换;飞书里 `/expert 名字`、`/claude`、`/codex` 换专家会开新会话)。**内置专家**:Claude Code、Codex,保留原装提示词和所有工具,默认技能与 MCP 在「设置 → Agent」中按账号、按引擎分别选择。**自定义专家**由创建者管理,可以勾选「共享给所有账号」。共享后,其他人能在网页、绑定账号后的飞书私聊和定时任务中选择它;只有创建者能修改设定。每个人在该专家的「我的工具」里选择自己的技能和 MCP,使用各自的变量、凭据、记忆和聊天记录;创建者沿用原有工具选择,其他人未配置时不加载技能或 MCP。取消共享后,其他人的历史对话保留,后续消息不能继续调用该专家,相关定时任务在下次运行时暂停。可以配:
|
|
@@ -167,7 +167,7 @@ agent-loft service install
|
|
|
167
167
|
|
|
168
168
|
`aloft` 是 `agent-loft` 的简写。
|
|
169
169
|
|
|
170
|
-
聊天里的命令(飞书和 Web 通用;Web 打开页面时会预加载当前专家和目录的命令,输入框打 `/` 会弹出命令补全,飞书里打 `/` 会弹出机器人的指令面板(agent-loft 自动注册,约 5~8 分钟生效;只发一个 `/` 也会回一张可点击的命令卡片),顺序和显示项在 设置 → 命令 里调整):`/new` `/fork` `/sessions [all]` `/resume <id>` `/model [名称]` `/effort <程度>` `/stop` `/cd <目录>` `/pwd` `/status` `/autoedit [on|off]` `/approve <id> allow-once|allow-always|allow-session|deny` `/help`;只在飞书里有的:`/expert [名称]`(或者直接发 `/claude`、`/codex`,换专家会开新会话)`/web` `/detach` `/bind <绑定码>`
|
|
170
|
+
聊天里的命令(飞书和 Web 通用;Web 打开页面时会预加载当前专家和目录的命令,输入框打 `/` 会弹出命令补全,飞书里打 `/` 会弹出机器人的指令面板(agent-loft 自动注册,约 5~8 分钟生效;只发一个 `/` 也会回一张可点击的命令卡片),顺序和显示项在 设置 → 命令 里调整):`/new` `/fork` `/sessions [all]` `/resume <id>` `/model [名称]` `/effort <程度>` `/stop` `/cd <目录>` `/pwd` `/status` `/permission [ask|edit|full|default]`、`/autoedit [on|off]` `/approve <id> allow-once|allow-always|allow-session|deny` `/help`;只在飞书里有的:`/expert [名称]`(或者直接发 `/claude`、`/codex`,换专家会开新会话)`/web` `/detach` `/bind <绑定码>`
|
|
171
171
|
|
|
172
172
|
自定义命令:设置 → 命令 → 「添加命令」,填命令名、说明和一段提示词,之后发 `/命令名 参数` 就会把这段提示词发给 agent(提示词里的 `$ARGUMENTS` 换成参数,没写就把参数接在后面)。按 agent 分开存,可以编辑、删除,也会同步到飞书指令面板。
|
|
173
173
|
|
package/package.json
CHANGED
|
@@ -22,6 +22,7 @@ import { expertAppend, expertSystemPrompt, RICH_REPLY_LINES, searchLabel } from
|
|
|
22
22
|
import { ACCESS_LEVELS, type ExpertAccess } from "../../core/experts.js";
|
|
23
23
|
import { MEMORY_MCP_NAME, memoryMcpSpawn } from "../../core/memory-mcp.js";
|
|
24
24
|
import { SKILLS_MCP_NAME, skillsMcpSpawn, TASKS_MCP_NAME, tasksMcpSpawn } from "../../core/tasks-mcp.js";
|
|
25
|
+
import type { PermissionLevel } from "../../core/permission.js";
|
|
25
26
|
import { PLUGIN_NAME, projectCommandNames } from "../../core/skill-runtime.js";
|
|
26
27
|
import { describeAttachments, inlineTextBlocks, readTextAttachments } from "../../core/uploads.js";
|
|
27
28
|
import type {
|
|
@@ -305,8 +306,8 @@ export class ClaudeSession implements AgentSession {
|
|
|
305
306
|
private turnBusy = false;
|
|
306
307
|
private pending: UserInput[] = [];
|
|
307
308
|
/**
|
|
308
|
-
*
|
|
309
|
-
*
|
|
309
|
+
* 全部放行:对话选了「完全允许」(构造时就是 true),或者用户点过「本会话全部允许」。
|
|
310
|
+
* 点出来的只在内存里:这个对象一换(/new、切目录、切 agent、恢复历史、进程重启),就重新逐条询问。
|
|
310
311
|
*/
|
|
311
312
|
private allowAll = false;
|
|
312
313
|
/**
|
|
@@ -324,6 +325,7 @@ export class ClaudeSession implements AgentSession {
|
|
|
324
325
|
private readonly events: AgentEvents,
|
|
325
326
|
private readonly host: InteractionHost,
|
|
326
327
|
) {
|
|
328
|
+
this.allowAll = opts.permission === "full";
|
|
327
329
|
this.costSoFar = opts.resumeId ? undefined : 0;
|
|
328
330
|
const previousUsage = usageOf(opts.resumeId);
|
|
329
331
|
this.tokensSoFar = previousUsage
|
|
@@ -361,9 +363,9 @@ export class ClaudeSession implements AgentSession {
|
|
|
361
363
|
...(this.access === "web" ? {} : { CLAUDE_CODE_ENABLE_TODO_TOOLS: "1" }),
|
|
362
364
|
...(this.access === "exec" ? (this.opts.skills?.env ?? {}) : {}),
|
|
363
365
|
},
|
|
364
|
-
// 只能是 default 或 acceptEdits:bypassPermissions 会让 canUseTool
|
|
366
|
+
// 只能是 default 或 acceptEdits:bypassPermissions 会让 canUseTool 变成死代码(「完全允许」也在 canUseTool 里放行)。
|
|
365
367
|
// acceptEdits 只放行工作目录(含附件目录)内的改文件,其它照样走 canUseTool
|
|
366
|
-
permissionMode: this.opts.
|
|
368
|
+
permissionMode: this.opts.permission === "edit" ? "acceptEdits" : "default",
|
|
367
369
|
// 逐字输出给 Web 用;飞书渠道直接忽略这些片段
|
|
368
370
|
includePartialMessages: true,
|
|
369
371
|
...(this.opts.model ? { model: this.opts.model } : {}),
|
|
@@ -545,21 +547,24 @@ export class ClaudeSession implements AgentSession {
|
|
|
545
547
|
if (answered) return answered;
|
|
546
548
|
}
|
|
547
549
|
|
|
548
|
-
//
|
|
549
|
-
|
|
550
|
+
// 提问、批准计划这类不是「安全确认」,而是要用户真的做决定,全部允许也照样问。
|
|
551
|
+
// 标了「调用前询问」的 MCP 是用户特意要每次把关的:全部允许、总是允许都不算数(和 Codex 一致)
|
|
552
|
+
const asksFirst = this.mcpAsksFirst(toolName);
|
|
553
|
+
const sessionable = isRememberable(toolName) && !asksFirst;
|
|
550
554
|
if (sessionable && this.allowAll) return { behavior: "allow", updatedInput: input };
|
|
551
555
|
|
|
552
556
|
const signature = signatureOf(toolName, input);
|
|
553
|
-
|
|
557
|
+
const rememberable = !asksFirst && isRememberableSignature(toolName, signature);
|
|
558
|
+
if (!asksFirst && isPreApproved(toolName, signature)) return { behavior: "allow", updatedInput: input };
|
|
554
559
|
|
|
555
560
|
const outcome = await this.host({
|
|
556
561
|
kind: "approval",
|
|
557
562
|
title: `需要授权:${toolName}`,
|
|
558
563
|
detail: describeToolCall(toolName, input),
|
|
559
|
-
...(
|
|
560
|
-
...(sessionable ? { allowSession: true } : {}),
|
|
564
|
+
...(rememberable ? { alwaysLabel: alwaysLabelOf(toolName, signature), alwaysGlobal: true } : {}),
|
|
565
|
+
...(sessionable && !this.opts.noSessionGrant ? { allowSession: true } : {}),
|
|
561
566
|
});
|
|
562
|
-
if (outcome.settlement === "allow-always" &&
|
|
567
|
+
if (outcome.settlement === "allow-always" && rememberable) rememberAlways(signature);
|
|
563
568
|
if (outcome.settlement === "allow-session") {
|
|
564
569
|
if (!this.allowAll) this.events.onStep("warning", "🔓 本会话内后续操作不再询问(/new 或切换会话后恢复逐条确认)");
|
|
565
570
|
this.allowAll = true;
|
|
@@ -585,6 +590,13 @@ export class ClaudeSession implements AgentSession {
|
|
|
585
590
|
return !!config && !!m && m[1]! in config.mcp && !config.askMcp.includes(m[1]!);
|
|
586
591
|
}
|
|
587
592
|
|
|
593
|
+
/** 配置里标了「调用前询问」的 MCP 工具 */
|
|
594
|
+
private mcpAsksFirst(toolName: string): boolean {
|
|
595
|
+
const config = this.opts.expert ?? this.opts.builtinMcp;
|
|
596
|
+
const m = /^mcp__(.+?)__/.exec(toolName);
|
|
597
|
+
return !!config && !!m && m[1]! in config.mcp && config.askMcp.includes(m[1]!);
|
|
598
|
+
}
|
|
599
|
+
|
|
588
600
|
/** 内置专家算能跑命令 */
|
|
589
601
|
private get access(): ExpertAccess {
|
|
590
602
|
return this.opts.expert?.access ?? "exec";
|
|
@@ -667,10 +679,12 @@ export class ClaudeSession implements AgentSession {
|
|
|
667
679
|
return toModelInfo(await this.q!.supportedModels());
|
|
668
680
|
}
|
|
669
681
|
|
|
670
|
-
|
|
671
|
-
|
|
682
|
+
/** 显式换级别时,之前点的「本会话全部允许」也作废:以这次选的为准 */
|
|
683
|
+
async setPermission(level: PermissionLevel | undefined): Promise<void> {
|
|
684
|
+
this.opts.permission = level;
|
|
685
|
+
this.allowAll = level === "full";
|
|
672
686
|
// 还没起 CLI 就不用管:下次拉起时按 opts 来
|
|
673
|
-
if (this.q) await this.q.setPermissionMode(
|
|
687
|
+
if (this.q) await this.q.setPermissionMode(level === "edit" ? "acceptEdits" : "default");
|
|
674
688
|
}
|
|
675
689
|
|
|
676
690
|
async setModel(model?: string, effort?: string): Promise<void> {
|
|
@@ -265,7 +265,7 @@ export class CodexDriver implements AgentDriver {
|
|
|
265
265
|
|
|
266
266
|
async statusLines(): Promise<string[]> {
|
|
267
267
|
const quota = config().web.quotaEnabled ? describeRateLimits(await readRateLimits()) : [];
|
|
268
|
-
return [
|
|
268
|
+
return [`默认沙箱:${config().agents.codex.sandbox}`, ...(quota.length > 0 ? ["", ...quota] : [])];
|
|
269
269
|
}
|
|
270
270
|
|
|
271
271
|
async quota(): Promise<QuotaInfo | null> {
|
|
@@ -9,6 +9,7 @@ import { contextBlock } from "../../core/expert-prompt.js";
|
|
|
9
9
|
import { ACCESS_LEVELS, type ExpertAccess, type ExpertRuntime } from "../../core/experts.js";
|
|
10
10
|
import { MEMORY_MCP_NAME, memoryMcpSpawn } from "../../core/memory-mcp.js";
|
|
11
11
|
import { SKILLS_MCP_NAME, skillsMcpSpawn, TASK_TOOL_TIMEOUT_SEC, TASKS_MCP_NAME, tasksMcpSpawn } from "../../core/tasks-mcp.js";
|
|
12
|
+
import type { PermissionLevel } from "../../core/permission.js";
|
|
12
13
|
import { codexSkillLines } from "../../core/skill-runtime.js";
|
|
13
14
|
import { describeAttachments, inlineTextBlocks, readTextAttachments } from "../../core/uploads.js";
|
|
14
15
|
import type {
|
|
@@ -155,6 +156,7 @@ export function codexMcp(mcp: ExpertRuntime["mcp"], ask: readonly string[] = [])
|
|
|
155
156
|
}
|
|
156
157
|
|
|
157
158
|
const SANDBOX_RANK = ["read-only", "workspace-write", "danger-full-access"];
|
|
159
|
+
const PERMISSION_SANDBOX: Record<PermissionLevel, string> = { ask: "read-only", edit: "workspace-write", full: "danger-full-access" };
|
|
158
160
|
|
|
159
161
|
/** 用户自己配的 MCP 服务(config.toml 里的 mcp_servers)。名字因人而异,只能读出来再逐个关 */
|
|
160
162
|
let userMcpCache: { names: string[]; at: number } | null = null;
|
|
@@ -313,7 +315,7 @@ export class CodexSession implements AgentSession {
|
|
|
313
315
|
private opening: Promise<string> | null = null;
|
|
314
316
|
private detached = false;
|
|
315
317
|
private runtime: RuntimeInfo = {};
|
|
316
|
-
/**
|
|
318
|
+
/** 全部放行:对话选了「完全允许」,或者用户点过「本会话全部允许」(点出来的只在内存里,会话对象一换就重新逐条询问)。 */
|
|
317
319
|
private allowAll = false;
|
|
318
320
|
private replyText = "";
|
|
319
321
|
/** 本轮所有模型请求的用量,和会话汇总使用相同的输入 / 缓存 / 输出口径。 */
|
|
@@ -334,7 +336,9 @@ export class CodexSession implements AgentSession {
|
|
|
334
336
|
private readonly opts: SessionOptions,
|
|
335
337
|
private readonly events: AgentEvents,
|
|
336
338
|
private readonly host: InteractionHost,
|
|
337
|
-
) {
|
|
339
|
+
) {
|
|
340
|
+
this.allowAll = opts.permission === "full";
|
|
341
|
+
}
|
|
338
342
|
|
|
339
343
|
get sessionId(): string | undefined {
|
|
340
344
|
return this.threadId;
|
|
@@ -424,13 +428,23 @@ export class CodexSession implements AgentSession {
|
|
|
424
428
|
}
|
|
425
429
|
|
|
426
430
|
/**
|
|
427
|
-
*
|
|
428
|
-
*
|
|
431
|
+
* 沙箱:这条对话选了权限级别就按级别,没选就按设置里的(选了级别的上限 hub 已经按主人核过,见 permissionMax)。
|
|
432
|
+
* 再按专家封顶:只能联网、能读文件的专家一律只读(只能联网的本来就没有执行命令的工具,这是第二道保险);
|
|
433
|
+
* 能改文件的最多到 workspace-write;能跑命令的和内置专家不封顶。
|
|
429
434
|
*/
|
|
430
435
|
private get sandboxMode(): string {
|
|
431
|
-
const
|
|
432
|
-
const cap = this.access === "exec" ?
|
|
433
|
-
return SANDBOX_RANK.indexOf(cap) < SANDBOX_RANK.indexOf(
|
|
436
|
+
const wanted = this.opts.permission ? PERMISSION_SANDBOX[this.opts.permission] : config().agents.codex.sandbox;
|
|
437
|
+
const cap = this.access === "exec" ? "danger-full-access" : this.access === "edit" ? "workspace-write" : "read-only";
|
|
438
|
+
return SANDBOX_RANK.indexOf(cap) < SANDBOX_RANK.indexOf(wanted) ? cap : wanted;
|
|
439
|
+
}
|
|
440
|
+
|
|
441
|
+
/**
|
|
442
|
+
* 下一轮生效:turn/start 每轮都显式带沙箱(实测同一条 thread 可以来回切)。
|
|
443
|
+
* 显式换级别时,之前点的「本会话全部允许」也作废。
|
|
444
|
+
*/
|
|
445
|
+
async setPermission(level: PermissionLevel | undefined): Promise<void> {
|
|
446
|
+
this.opts.permission = level;
|
|
447
|
+
this.allowAll = level === "full";
|
|
434
448
|
}
|
|
435
449
|
|
|
436
450
|
/**
|
|
@@ -731,7 +745,7 @@ export class CodexSession implements AgentSession {
|
|
|
731
745
|
|
|
732
746
|
/** 审批都走这里:带上「本会话全部允许」按钮,点了就记住。 */
|
|
733
747
|
private async ask(spec: Extract<InteractionSpec, { kind: "approval" }>): Promise<InteractionOutcome> {
|
|
734
|
-
const outcome = await this.host({ ...spec, allowSession: true });
|
|
748
|
+
const outcome = await this.host({ ...spec, ...(this.opts.noSessionGrant ? {} : { allowSession: true }) });
|
|
735
749
|
if (outcome.settlement === "allow-session") {
|
|
736
750
|
if (!this.allowAll) this.events.onStep("warning", "🔓 本会话内后续操作不再询问(/new 或切换会话后恢复逐条确认)");
|
|
737
751
|
this.allowAll = true;
|
|
@@ -770,7 +784,8 @@ export class CodexSession implements AgentSession {
|
|
|
770
784
|
|
|
771
785
|
case "item/commandExecution/requestApproval": {
|
|
772
786
|
const req = params as CommandExecutionApprovalParams;
|
|
773
|
-
|
|
787
|
+
// 全部放行只批这一次:acceptForSession 记在 thread 上(实测 resume 后还在),调低权限后收不回来
|
|
788
|
+
if (this.allowAll) return { decision: "accept" };
|
|
774
789
|
const amendment = req.proposedExecpolicyAmendment ?? null;
|
|
775
790
|
const outcome = await this.ask({
|
|
776
791
|
kind: "approval",
|
|
@@ -796,7 +811,7 @@ export class CodexSession implements AgentSession {
|
|
|
796
811
|
|
|
797
812
|
case "item/fileChange/requestApproval": {
|
|
798
813
|
const req = params as FileChangeApprovalParams;
|
|
799
|
-
if (this.allowAll) return { decision: "
|
|
814
|
+
if (this.allowAll) return { decision: "accept" };
|
|
800
815
|
const outcome = await this.ask({
|
|
801
816
|
kind: "approval",
|
|
802
817
|
title: "需要授权:改动文件",
|
|
@@ -812,7 +827,7 @@ export class CodexSession implements AgentSession {
|
|
|
812
827
|
|
|
813
828
|
case "item/permissions/requestApproval": {
|
|
814
829
|
const req = params as PermissionsApprovalParams;
|
|
815
|
-
if (this.allowAll) return { permissions: req.permissions ?? {}, scope: "
|
|
830
|
+
if (this.allowAll) return { permissions: req.permissions ?? {}, scope: "turn" };
|
|
816
831
|
const outcome = await this.ask({
|
|
817
832
|
kind: "approval",
|
|
818
833
|
title: "需要授权:额外权限",
|
|
@@ -708,6 +708,8 @@ export class FeishuBot {
|
|
|
708
708
|
channel: "feishu",
|
|
709
709
|
// 别人的 agent 会话、挂着的请求,这个聊天里都碰不到
|
|
710
710
|
...this.commandScope(ownKey),
|
|
711
|
+
// 群里谁都能发命令:完全允许只认私聊里绑定了管理员账号的本人
|
|
712
|
+
allowFullAccess: p2p && linkedUser(this.cfg.id, operator)?.role === "admin",
|
|
711
713
|
});
|
|
712
714
|
await this.renderReply(key, chatId, reply);
|
|
713
715
|
} catch (err) {
|
package/src/channels/web/api.ts
CHANGED
|
@@ -46,6 +46,7 @@ import { purgeUserData } from "../../core/personal.js";
|
|
|
46
46
|
import { countRecords, purgeHistory, readMeta, searchHistory, writeMeta } from "../../core/chat-history.js";
|
|
47
47
|
import { curateNow, pendingCount } from "../../core/memory-curator.js";
|
|
48
48
|
import { listAllowlist, setAllowlist } from "../../agents/claude/permissions.js";
|
|
49
|
+
import { isPermissionLevel, type PermissionLevel } from "../../core/permission.js";
|
|
49
50
|
import { agentAvailability, agentHealth, invalidateHealth } from "../../agents/health.js";
|
|
50
51
|
import { installCodex, upgrade, useInstalledCodex, versionInfo } from "../../core/upgrade.js";
|
|
51
52
|
import { feishuBots } from "../feishu/index.js";
|
|
@@ -1128,6 +1129,11 @@ export async function handleApi(req: IncomingMessage, res: ServerResponse, url:
|
|
|
1128
1129
|
case "effort":
|
|
1129
1130
|
text = await hub.setEffort(key, value);
|
|
1130
1131
|
break;
|
|
1132
|
+
case "permission": {
|
|
1133
|
+
if (value && !isPermissionLevel(value)) throw new HttpError(400, "权限级别不对");
|
|
1134
|
+
text = await hub.setPermission(key, value ? (value as PermissionLevel) : undefined, admin);
|
|
1135
|
+
break;
|
|
1136
|
+
}
|
|
1131
1137
|
// 换专家(开新会话):只有飞书的对话能换,网页上的 hub 会拒绝
|
|
1132
1138
|
case "agent":
|
|
1133
1139
|
text = await hub.setExpert(key, value, allowedAgentsFor(key));
|
|
@@ -1461,6 +1467,8 @@ export async function handleApi(req: IncomingMessage, res: ServerResponse, url:
|
|
|
1461
1467
|
);
|
|
1462
1468
|
// 管理员在用户列表里重置了自己的密码:当前这台换个新登录态,别把自己踢出去
|
|
1463
1469
|
if (id === user.id && typeof body.password === "string") newSession(req, res, user.id);
|
|
1470
|
+
// 降级、停用:他活着的会话不能带着旧权限继续,空闲下来按新身份重新拉起
|
|
1471
|
+
if (body.role !== undefined || body.disabled !== undefined) hub.memoryChanged(id);
|
|
1464
1472
|
sendJson(res, 200, updated);
|
|
1465
1473
|
return;
|
|
1466
1474
|
}
|
|
@@ -423,6 +423,7 @@ function handleClientMessage(client: Client, raw: string): void {
|
|
|
423
423
|
})(),
|
|
424
424
|
convVisible: (k) => canSeeKey(user, k),
|
|
425
425
|
allowGlobalAlways: isAdmin(user),
|
|
426
|
+
allowFullAccess: isAdmin(user),
|
|
426
427
|
})
|
|
427
428
|
.then((reply) => ack(true, { reply, info: hub.info(key) }))
|
|
428
429
|
.catch((err) => ack(false, { error: err instanceof Error ? err.message : String(err) }));
|
|
@@ -3,9 +3,10 @@ import type { IncomingMessage, ServerResponse } from "node:http";
|
|
|
3
3
|
import { config, resolveWorkspacePath } from "../../core/config.js";
|
|
4
4
|
import { canUseExpert, getExpert, isBuiltin } from "../../core/experts.js";
|
|
5
5
|
import { hub } from "../../core/hub.js";
|
|
6
|
+
import { exceedsPermission, isPermissionLevel, PERMISSION_LABEL, permissionCapOfAccess } from "../../core/permission.js";
|
|
6
7
|
import { memoryOwnerOf } from "../../core/personal.js";
|
|
7
8
|
import { getConversation } from "../../core/store.js";
|
|
8
|
-
import { forgetTask, isTaskRunning, runTaskNow } from "../../core/task-runner.js";
|
|
9
|
+
import { forgetTask, isTaskRunning, releaseTaskConv, runTaskNow } from "../../core/task-runner.js";
|
|
9
10
|
import { serverTimeZone } from "../../core/task-schedule.js";
|
|
10
11
|
import { createTask, deleteTask, getTask, listTasks, updateTask, viewOf, type Task, type TaskInput } from "../../core/tasks.js";
|
|
11
12
|
import type { User } from "../../core/users.js";
|
|
@@ -18,7 +19,7 @@ function view(task: Task) {
|
|
|
18
19
|
...viewOf(task),
|
|
19
20
|
running: isTaskRunning(task.id),
|
|
20
21
|
// 结果在哪条对话里看(专用对话第一次运行前还没有)
|
|
21
|
-
...(conv && !conv.hidden ? { convKey: conv.key, convTitle: conv.title ?? "" } : {}),
|
|
22
|
+
...(conv && !conv.hidden ? { convKey: conv.key, convTitle: conv.title ?? "", convPermission: hub.permissionOf(conv) } : {}),
|
|
22
23
|
};
|
|
23
24
|
}
|
|
24
25
|
|
|
@@ -37,6 +38,15 @@ function checkInput(user: User, body: TaskInput): TaskInput {
|
|
|
37
38
|
if (!cwd) throw new HttpError(400, `目录必须存在,且在 ${config().workspaceRoot} 之内`);
|
|
38
39
|
out.cwd = cwd === config().workspaceRoot ? "" : cwd;
|
|
39
40
|
}
|
|
41
|
+
// 完全允许和对话里的规则一样只给管理员。到点时还会按当时的主人和专家再封顶一次(见 task-runner.ts)
|
|
42
|
+
if (isPermissionLevel(body.permission)) {
|
|
43
|
+
if (body.permission === "full" && user.role !== "admin") throw new HttpError(403, "只有管理员能选「完全允许」");
|
|
44
|
+
const id = pick === undefined ? undefined : String(pick);
|
|
45
|
+
const access = id && !isBuiltin(id) ? getExpert(id)?.access : undefined;
|
|
46
|
+
if (access && exceedsPermission(body.permission, permissionCapOfAccess(access))) {
|
|
47
|
+
throw new HttpError(400, `这个专家的权限最高只能到「${PERMISSION_LABEL[permissionCapOfAccess(access)]}」`);
|
|
48
|
+
}
|
|
49
|
+
}
|
|
40
50
|
const target = body.target as { kind?: string; key?: string } | undefined;
|
|
41
51
|
if (target?.kind === "conv") {
|
|
42
52
|
const conv = target.key ? getConversation(target.key) : undefined;
|
|
@@ -80,11 +90,17 @@ export async function handleTasksApi(req: IncomingMessage, res: ServerResponse,
|
|
|
80
90
|
if (!m[2] && method === "PATCH") {
|
|
81
91
|
const body = await readJsonBody<TaskInput>(req);
|
|
82
92
|
let updated: Task;
|
|
93
|
+
// updateTask 是就地改的:先记下原来的专用对话
|
|
94
|
+
const before = task.target.kind === "dedicated" ? task.target.key : undefined;
|
|
83
95
|
try {
|
|
84
96
|
updated = updateTask(user.id, task.id, checkInput(user, body));
|
|
85
97
|
} catch (err) {
|
|
86
98
|
throw bad(err);
|
|
87
99
|
}
|
|
100
|
+
// 换了对话:旧的那条收回权限。还是这条:马上按新级别来,调低不能等到下次运行
|
|
101
|
+
const now = updated.target.kind === "dedicated" ? updated.target.key : undefined;
|
|
102
|
+
if (before && before !== now) releaseTaskConv(updated.id, before);
|
|
103
|
+
if (now) hub.applyTaskPermission(now, updated.permission);
|
|
88
104
|
sendJson(res, 200, view(updated));
|
|
89
105
|
return true;
|
|
90
106
|
}
|
|
@@ -28,7 +28,8 @@ export const BUILTIN_COMMANDS: BuiltinSpec[] = [
|
|
|
28
28
|
{ name: "cd", args: "<相对目录>", description: "切换工作目录(限 workspace 内)" },
|
|
29
29
|
{ name: "pwd", description: "显示当前工作目录" },
|
|
30
30
|
{ name: "fork", description: "从当前会话分叉,原会话保留" },
|
|
31
|
-
{ name: "
|
|
31
|
+
{ name: "permission", args: "[ask|edit|full|default]", description: "查看 / 切换本对话的权限级别(逐次询问、自动改文件、完全允许)" },
|
|
32
|
+
{ name: "autoedit", args: "[on|off]", description: "本对话自动允许改工作目录内的文件(等于 /permission edit)" },
|
|
32
33
|
// 网页上的对话中途不能换专家(新建对话时选),这几个只在飞书里有
|
|
33
34
|
{ name: "expert", args: "[名称]", description: "查看 / 换专家(换了会开新会话)", feishuOnly: true },
|
|
34
35
|
{ name: "claude", description: "换成 Claude Code 专家(开新会话)", multiAgentOnly: true, feishuOnly: true },
|
package/src/core/commands.ts
CHANGED
|
@@ -3,6 +3,7 @@
|
|
|
3
3
|
// 只有「整条消息就是一个命令」时才当命令处理,参数对不上就退化成普通聊天 ——
|
|
4
4
|
// 避免把正常对话误当指令执行。
|
|
5
5
|
import { BUILTIN_COMMANDS, usageOf } from "./command-catalog.js";
|
|
6
|
+
import type { PermissionLevel } from "./permission.js";
|
|
6
7
|
import type { ApprovalDecision } from "./types.js";
|
|
7
8
|
|
|
8
9
|
export type ParsedCommand =
|
|
@@ -18,12 +19,21 @@ export type ParsedCommand =
|
|
|
18
19
|
| { kind: "status" }
|
|
19
20
|
| { kind: "pwd" }
|
|
20
21
|
| { kind: "autoedit"; on?: boolean }
|
|
22
|
+
/** default:恢复默认;不给就是看当前级别 */
|
|
23
|
+
| { kind: "permission"; level?: PermissionLevel | "default" }
|
|
21
24
|
| { kind: "help" }
|
|
22
25
|
/** 只发了一个「/」:列出可用命令 */
|
|
23
26
|
| { kind: "commands" }
|
|
24
27
|
| { kind: "approve"; requestId: string; decision: ApprovalDecision }
|
|
25
28
|
| { kind: "chat"; text: string };
|
|
26
29
|
|
|
30
|
+
const PERMISSION_ARGS: Record<string, PermissionLevel | "default"> = {
|
|
31
|
+
ask: "ask", 询问: "ask", 逐次询问: "ask",
|
|
32
|
+
edit: "edit", 自动改文件: "edit",
|
|
33
|
+
full: "full", 完全允许: "full",
|
|
34
|
+
default: "default", 默认: "default",
|
|
35
|
+
};
|
|
36
|
+
|
|
27
37
|
const DECISIONS: ApprovalDecision[] = ["allow-once", "allow-always", "allow-session", "deny"];
|
|
28
38
|
|
|
29
39
|
export function parseCommand(raw: string): ParsedCommand {
|
|
@@ -71,6 +81,11 @@ export function parseCommand(raw: string): ParsedCommand {
|
|
|
71
81
|
if (["off", "关", "0", "false"].includes(v)) return { kind: "autoedit", on: false };
|
|
72
82
|
return { kind: "chat", text };
|
|
73
83
|
}
|
|
84
|
+
case "permission": {
|
|
85
|
+
if (!arg) return { kind: "permission" };
|
|
86
|
+
const level = Object.hasOwn(PERMISSION_ARGS, arg.toLowerCase()) ? PERMISSION_ARGS[arg.toLowerCase()] : undefined;
|
|
87
|
+
return level ? { kind: "permission", level } : { kind: "chat", text };
|
|
88
|
+
}
|
|
74
89
|
case "help":
|
|
75
90
|
return { kind: "help" };
|
|
76
91
|
case "approve": {
|