Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -167,11 +167,11 @@ macOS 的审批模式、模型和思考强度在等待、推理、输出、工

参考 [CC GUI 的输入栏选择器](https://github.com/zhukunpenglinyutong/jetbrains-cc-gui/blob/7bcd6c3803ec44944cef90f5bff0aa666cab99a2/webview/src/components/ChatInputBox/ButtonArea.tsx)在生成期间继续提供模式和模型回调,以及 [发送入口](https://github.com/zhukunpenglinyutong/jetbrains-cc-gui/blob/7bcd6c3803ec44944cef90f5bff0aa666cab99a2/webview/src/hooks/useMessageSender.ts)读取用户选择。Lithe 保留已有共享 Host 的忙碌边界:响应期间不发送 `setConfigOption`,只由当前会话的功能模型保存每个选项最后一次预选;重新选择已确认值取消该项预选。视图不另存配置队列,也不改本机 CLI 配置。

正常结束、取消确认或本轮请求失败后,功能模型先提交模型,再按最新上游选项顺序提交剩余配置,每个请求确认后才提交下一个。换模型可能改变思考强度和速度目录,因此每一步都重新校验;拒绝、发送失败、能力消失或返回值未确认时,清除剩余预选,恢复已经确认的值并显示配置错误。等待全部确认期间继续阻止发送,不自动提交用户草稿。停止请求本身不能解除等待,也不能让新配置进入尚未结束的一轮。
正常结束、取消确认或本轮请求失败后,产品把该会话全部预选连同最新已确认目录一次交给 Host(`applyNextTurnConfiguration`)。排序、校验和确认规则只在 Host 的 `rust/lithe-agent-host/src/next_turn_config.rs` 写一份,两端共用 `shared/fixtures/agent/next-turn-configuration-v1.json`:先提交模型,再按 Agent 目录顺序提交剩余配置(不按用户点击顺序),每个请求确认后才提交下一个。换模型可能改变思考强度和速度目录,因此每一步都用 Agent 最新返回的目录重新校验,已是当前值的跳过;能力消失(`unsupported`)、返回值未确认(`notConfirmed`)或请求失败(`requestFailed`,附上游原文)时停止,结果以一个 `nextTurnConfigured` 事件返回,已确认的配置保留生效。产品本地化失败码、清除剩余预选并显示配置错误。等待结果期间继续阻止发送,不自动提交用户草稿。停止请求本身不能解除等待,也不能让新配置进入尚未结束的一轮。本轮失败时,暂存的续写输入按该轮错误标记为失败、不自动作为新一轮发送,但预选配置仍然提交。2026-11(#1662 AGT-09)前两端各写一份:Windows 按点击顺序提交、不核对确认值、本轮失败时丢弃预选;macOS 本轮失败后会把续写输入自动发成新一轮。

正确做法:当前轮使用模型 A,用户选择 B 和 High;本轮结束后确认 B,再用 B 的最新目录确认 High,下一条消息才使用新值。不要这样做:仅移除控件的禁用条件并立即请求 `session/set_config_option`,或把本地预选直接覆盖到已确认配置中;前者可能影响当前工具授权且会被 Host 拒绝,后者会把失败当成成功。

预选按项目、Agent 和会话隔离;切换标签不丢失,后台完成只提交该后台会话的配置。新的上游配置或模式通知只更新已确认状态,不覆盖用户的有效预选。断连清除未确认预选和请求关联,迟到确认不能恢复它们。代价是本轮结束与下一轮发送之间可能多出数次配置确认,且不兼容的新模型选项需要用户重新选择。该能力目前只接入 macOS;Windows 不据此标记完成。状态仅保存在会话内存中,不新增下载、缓存或工作树可复用资源,不写发行包,不影响代码签名和 Sparkle delta。
预选按项目、Agent 和会话隔离;切换标签不丢失,后台完成只提交该后台会话的配置。新的上游配置或模式通知只更新已确认状态,不覆盖用户的有效预选。断连清除未确认预选和请求关联,迟到确认不能恢复它们。代价是本轮结束与下一轮发送之间可能多出数次配置确认,且不兼容的新模型选项需要用户重新选择。Windows 使用同一 Host 命令与事件。状态仅保存在会话内存中,不新增下载、缓存或工作树可复用资源,不写发行包,不影响代码签名和 Sparkle delta。

### 思考、计划、斜杠命令与模式通知

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,11 +52,14 @@ HTTP 请求不带 ACP 会话 ID。请求开始时,如果恰好只有一个未

代理在响应流结束时才上报调用,可能晚于 prompt 响应。Host 用 `CallsInFlight` 记录已归属但未上报的调用,在发出 `turnFinished` 前最多等 2 秒,保证每轮统计能收到本轮调用;超过这个上限仍未结束的流只计入会话统计,不会拖住回合结束:代理在请求开始时记下会话和 Host 的回合序号(generation),该回合发出 `turnFinished` 后才上报的调用带 `afterTurnFinished: true`,macOS 只把它记入会话,不会记到用户随后开始的下一轮。

### 5. macOS 只聚合、不保存明细
### 5. 统计口径只在 Host 写一份,产品只做加法

`AgentModelCallTotals` 对会话和每轮做有界聚合(次数、失败数、非流式数、带用量的次数、时长、首 token、生成时间、用量、最近一次主请求构成),会话再长内存也不增长。
每个 `modelCall` 事件都带 Host 计算的 `statistics`(`rust/lithe-agent-host/src/model_call_statistics.rs`,共享 fixture `shared/fixtures/agent/model-call-statistics-v1.json`):这次请求算几步、是否失败、是否算非流式回答、计入多少时长与首 token、生成速度的时间和 token,以及它是否代表当前上下文。两端只按事件顺序把这些贡献相加(计数相加、上报过的 reasoning 相加、出现的上下文覆盖旧值),不得再从 `call` 推导口径。2026-11(#1662 AGT-07)前两端各写一份:Windows 把 HTTP 500 的非流式请求也计入“非流式”,并把最后一次请求(包括辅助请求)的构成当作当前上下文。

- 主请求的识别:Agent 一旦发送过工具定义,就只有带工具的请求更新上下文构成,不带工具的(例如生成标题)视为辅助请求;从不发送工具的 Agent 每次请求都更新,避免构成停在第一次请求。
macOS 的 `AgentModelCallTotals` 与 Windows 的会话统计对会话和每轮做有界聚合(次数、失败数、非流式数、带用量的次数、时长、首 token、生成时间、用量、最近一次主请求构成),会话再长内存也不增长。

- 失败请求(状态码 ≥ 400,含传输失败的 502)计为失败的步,不计为非流式回答。
- 主请求的识别(由 Host 按会话记忆):Agent 一旦发送过工具定义,就只有带工具的请求更新上下文构成,不带工具的(例如生成标题)视为辅助请求;从不发送工具的 Agent 每次请求都更新,避免构成停在第一次请求。
- 有调用缺少用量(流中断、服务商没给最终 usage)时,Token 合计只是下限,界面显示“≥”并说明缺了几次。

正确:会话卡片的“步”= 观测到的模型调用数;TPS = 流式调用的输出 token ÷(调用时长 − 首 token 时间)。
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ Windows Agent 面板的一次启动只对应一个 ACP 进程,进程身份由
- 切走前用 `captureSnapshot()` 保存当前可见状态,切回时 `restoreSnapshot()` 放回。恢复会清掉全部进程相关标记,`prepareConversation()` 因此走 `loadSession` 重新附着,用户看到的仍是原会话;工作区切换清空全部保留状态,避免跨项目串台。
- 发送条件包含 `pendingConfigToken == null`:会话设置还在确认时不接受新消息,界面沿用「准备中」提示。
- `draft` 与 `files` 由 `agent-surface.store` 按 Agent 与会话保存,`AgentComposer` 为受控组件;工具窗口与编辑区标签读取同一份草稿。新会话确认后迁移其草稿,历史加载失败不挪用其他会话的输入。
- 响应中的模型、权限和 Effort 选择作为下一轮草稿配置;轮次完成后顺序提交并等待各自确认,全部成功才发送下一条消息。不能把菜单显示值提前当成上游已确认值。
- 响应中的模型、权限和 Effort 选择作为下一轮草稿配置;轮次结束(含失败)后一次交给 Host 的 `applyNextTurnConfiguration`,由 Host 按共享规则排序、校验并逐项确认,收到成功的 `nextTurnConfigured` 才发送下一条消息。不能把菜单显示值提前当成上游已确认值。
- 附件校验在事件处理阶段先算出结果,成功后再写入状态;上限错误只显示提示,不改动原有草稿与附件。
- 文件菜单跨 Agent 添加附件时,先提交目标配置,再用提交返回的配置内容核对当前设置。连接服务返回本次启动实际生效的设置,包含自己保存的本机 CLI 地址与模型刷新;被取代、启动失败或刷新保存失败时返回空结果。菜单必须核对该结果与当前设置,允许本次刷新,但拒绝外部配置变更。保存会重新规范化并发布对象,不能拿保存前的对象引用当作修订身份;保存失败或工作区切换时,附件草稿保持不变。
- 子 Agent 的活动记录必须保留到终止,才能继续路由其输出和授权;只有已结束的展示记录限制为最近 64 条。正确做法是清理旧的终态记录后继续接收第 65 个子 Agent;不能因展示名额耗尽而忽略 Host 已挂起的授权。
Expand Down
13 changes: 12 additions & 1 deletion .agents/notes/implemented/feature/2026-10-24-agent-hooks.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,20 @@ Lithe 管理资源库并显式写入原生配置;何时运行、Shell、标准
创建与编辑分别显示「新 Hook」和「编辑 Hook」,主按钮也区分添加与保存。

Agent 使用带原有品牌标志的选择按钮及「全部」动作,只展示已支持的两个
Agent;全不选时仍由已有校验禁止保存。macOS 复用 MCP 资源库原有的选择
Agent;全不选时由 Core 草稿校验禁止保存。macOS 复用 MCP 资源库原有的选择
按钮外观,抽为 `AgentSelectionChip`,不再分别维护两套样式。说明继续遵守
macOS 设置的 ⓘ 规则,不复制参考页的控件下方说明段落。描述字段通过共享
文本编辑器显式选择正文字体,其他调用者继续使用原有等宽字体与控件样式。

编辑器的字段校验只有一份规则:Agent Host 的 `hooks::validate_draft`,经
Core `agent.hooks.validateDraft` 返回逐字段的 `{field, code}`,与 `save` 的最终
校验共用同一组规则(#1662 AGT-18)。以前 Swift `canSave` 漏掉重复 Agent 和
非工具事件的工具筛选、Windows `validHook` 另写了一份正则且重名单独判断,
草稿能通过编辑器却在保存时被 Host 拒绝。超时字段把原始文本交给 Core,
只接受 ASCII 数字,保存时写入 Core 解析出的秒数;两端把
`agent.hooks.draft.<field>.<code>` 本地化后显示在编辑器内,空名称和空命令
只禁用保存、不显示提示,避免新建时立即报错。

搜索按名称、描述和命令筛选。页面必须根据筛选后的列表显示空状态:有
搜索词而无结果时提示「没有匹配的 Hook」,无搜索词且资源库为空时提示
「还没有 Hook」。不能只检查资源库总数,否则已有内容的无匹配搜索会留下
Expand Down Expand Up @@ -107,6 +116,8 @@ Swift 功能模型负责草稿与 UI 状态,Rust Core 负责严格命令分派
自有条目、trust 索引不变、只读/符号链接、冲突、部分失败、取消与日志恢复。
- Core `hook_contract_dispatch_is_strict_before_accessing_native_files` 校验
严格请求;Swift 与 TypeScript 读取同一个跨平台 fixture。
- `shared/fixtures/agent/hook-draft-validation-v1.json` 由 Host、Core 分发、
Swift 桥接与 TypeScript 请求测试共同读取,固定每个字段码。
- `./.agents/skills/write-stable-tests/scripts/verify-test-stability.sh`。
- `./.agents/skills/write-stable-tests/scripts/test-stability-macos.sh -- --filter 'AgentHooks|SettingsSidebarLayoutTests|SettingsSearchVocabularyTests|ContextMenuCoverageTests'`。
- `./scripts/macos/verify/verify-runtime-bundle-immutability.sh`、`./scripts/architecture/verify-service-boundaries.sh`、
Expand Down
23 changes: 23 additions & 0 deletions macos/Resources/en.lproj/Localizable.strings
Original file line number Diff line number Diff line change
Expand Up @@ -5088,6 +5088,29 @@
"agent.history.provider" = "Conversation provider";
"agent.history.providerHint" = "Try another search or provider filter.";
"agent.history.unknownProvider" = "Unknown provider";
"agent.hooks.draft.agents.duplicate" = "Each Agent can be selected only once.";
"agent.hooks.draft.agents.required" = "Select at least one Agent.";
"agent.hooks.draft.agents.unsupported" = "Only Codex and Claude Code support Hooks.";
"agent.hooks.draft.command.containsNul" = "The command cannot contain a NUL character.";
"agent.hooks.draft.command.contains_nul" = "The command cannot contain a NUL character.";
"agent.hooks.draft.command.required" = "Enter a command.";
"agent.hooks.draft.command.tooLong" = "The command can have at most 32768 bytes.";
"agent.hooks.draft.command.too_long" = "The command can have at most 32768 bytes.";
"agent.hooks.draft.description.tooLong" = "The description can have at most 200 characters.";
"agent.hooks.draft.description.too_long" = "The description can have at most 200 characters.";
"agent.hooks.draft.id.invalid" = "This Hook draft has an invalid identifier. Close the editor and try again.";
"agent.hooks.draft.matcher.incompatibleEvent" = "Tool filters apply only to tool events.";
"agent.hooks.draft.matcher.incompatible_event" = "Tool filters apply only to tool events.";
"agent.hooks.draft.name.duplicate" = "A Hook with this name already exists.";
"agent.hooks.draft.name.invalidCharacters" = "Use only letters, digits, hyphens or underscores in the Hook name.";
"agent.hooks.draft.name.invalid_characters" = "Use only letters, digits, hyphens or underscores in the Hook name.";
"agent.hooks.draft.name.required" = "Enter a Hook name.";
"agent.hooks.draft.name.tooLong" = "Hook names can have at most 80 characters.";
"agent.hooks.draft.name.too_long" = "Hook names can have at most 80 characters.";
"agent.hooks.draft.timeout.notInteger" = "Enter the timeout as a whole number of seconds, or leave it empty.";
"agent.hooks.draft.timeout.not_integer" = "Enter the timeout as a whole number of seconds, or leave it empty.";
"agent.hooks.draft.timeout.outOfRange" = "The timeout must be from 1 to 86400 seconds.";
"agent.hooks.draft.timeout.out_of_range" = "The timeout must be from 1 to 86400 seconds.";
"agent.settings.enableSubscription" = "Enable";
"agent.stop" = "Stop";
"ai.add" = "Add";
Expand Down
23 changes: 23 additions & 0 deletions macos/Resources/zh-Hans.lproj/Localizable.strings
Original file line number Diff line number Diff line change
Expand Up @@ -5088,6 +5088,29 @@
"agent.history.provider" = "对话供应商";
"agent.history.providerHint" = "试试其他搜索条件或供应商筛选。";
"agent.history.unknownProvider" = "未知供应商";
"agent.hooks.draft.agents.duplicate" = "每个 Agent 只能选择一次。";
"agent.hooks.draft.agents.required" = "请至少选择一个 Agent。";
"agent.hooks.draft.agents.unsupported" = "只有 Codex 和 Claude Code 支持 Hook。";
"agent.hooks.draft.command.containsNul" = "命令不能包含 NUL 字符。";
"agent.hooks.draft.command.contains_nul" = "命令不能包含 NUL 字符。";
"agent.hooks.draft.command.required" = "请输入命令。";
"agent.hooks.draft.command.tooLong" = "命令最多 32768 字节。";
"agent.hooks.draft.command.too_long" = "命令最多 32768 字节。";
"agent.hooks.draft.description.tooLong" = "描述最多 200 个字符。";
"agent.hooks.draft.description.too_long" = "描述最多 200 个字符。";
"agent.hooks.draft.id.invalid" = "此 Hook 草稿的标识无效,请关闭编辑器后重试。";
"agent.hooks.draft.matcher.incompatibleEvent" = "工具筛选只适用于工具相关的事件。";
"agent.hooks.draft.matcher.incompatible_event" = "工具筛选只适用于工具相关的事件。";
"agent.hooks.draft.name.duplicate" = "已存在同名的 Hook。";
"agent.hooks.draft.name.invalidCharacters" = "Hook 名称只能包含字母、数字、连字符或下划线。";
"agent.hooks.draft.name.invalid_characters" = "Hook 名称只能包含字母、数字、连字符或下划线。";
"agent.hooks.draft.name.required" = "请输入 Hook 名称。";
"agent.hooks.draft.name.tooLong" = "Hook 名称最多 80 个字符。";
"agent.hooks.draft.name.too_long" = "Hook 名称最多 80 个字符。";
"agent.hooks.draft.timeout.notInteger" = "超时请填写整数秒,或留空。";
"agent.hooks.draft.timeout.not_integer" = "超时请填写整数秒,或留空。";
"agent.hooks.draft.timeout.outOfRange" = "超时必须在 1 到 86400 秒之间。";
"agent.hooks.draft.timeout.out_of_range" = "超时必须在 1 到 86400 秒之间。";
"agent.settings.enableSubscription" = "启用";
"agent.stop" = "停止";
"ai.add" = "添加";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,12 @@ import LitheCoreContracts
final class AgentHooksFeatureModel: ObservableObject {
enum Phase: Equatable { case idle, loading, ready, saving, failed(String) }
@Published private(set) var phase: Phase = .idle
@Published private(set) var library: AgentHookLibrary?
@Published var draft: AgentHook?
@Published private(set) var library: AgentHookLibrary? { didSet { revalidate() } }
@Published var draft: AgentHook? { didSet { revalidate() } }
/// Raw timeout text; Core parses it so the integer and range rules have one owner.
@Published var timeoutText = "" { didSet { revalidate() } }
/// Core's field-level verdict for the current draft; `nil` without a draft or library.
@Published private(set) var draftValidation: AgentHookDraftValidation?
@Published var query = ""
private let service: any AgentHooksService

Expand All @@ -18,14 +22,21 @@ final class AgentHooksFeatureModel: ObservableObject {
query.isEmpty || [entry.hook.name, entry.hook.description, entry.hook.command].contains { $0.localizedCaseInsensitiveContains(query) }
}
}
var canSave: Bool {
guard let draft, library != nil, !isBusy else { return false }
return !draft.name.isEmpty && draft.name.utf8.count <= 80
&& draft.name.utf8.allSatisfy { (48...57).contains($0) || (65...90).contains($0) || (97...122).contains($0) || $0 == 45 || $0 == 95 }
&& draft.description.unicodeScalars.count <= 200 && !draft.command.trimmingCharacters(in: .whitespacesAndNewlines).isEmpty
&& draft.command.utf8.count <= 32768 && !draft.command.contains("\0") && !draft.agents.isEmpty
&& (draft.timeoutSeconds == nil || (1...86400).contains(draft.timeoutSeconds!))
&& !(library?.hooks.contains { $0.id != draft.id && $0.hook.name.caseInsensitiveCompare(draft.name) == .orderedSame } ?? false)
var canSave: Bool { draft != nil && library != nil && !isBusy && draftValidation?.valid == true }

/// Starts editing `hook`, seeding the timeout field from its stored value.
func beginEditing(_ hook: AgentHook) {
timeoutText = hook.timeoutSeconds.map(String.init) ?? ""
draft = hook
}

private func revalidate() {
guard let draft, let library else { draftValidation = nil; return }
do { draftValidation = try service.validateDraft(draft, timeoutText: timeoutText, library: library) }
catch {
// log-exempt: 同一次失败已经记录过:Core 请求轨迹已记录 agent.hooks.validateDraft 的失败,保存按钮保持禁用
draftValidation = nil
}
}

func load() async {
Expand All @@ -36,7 +47,8 @@ final class AgentHooksFeatureModel: ObservableObject {
catch { phase = .failed(error.localizedDescription) }
}
func save() async {
guard canSave, let draft, let library else { return }
guard canSave, var draft, let library, let validation = draftValidation else { return }
draft.timeoutSeconds = validation.timeoutSeconds
phase = .saving
do {
self.library = try await service.save(draft, library: library)
Expand Down
Loading
Loading