Repository navigation
feat(agents): Agent 插件上报并修改模型与供应商,资源库读取支持筛选与排序 - #248
Conversation
| Self::AddProvider { provider } | Self::UpdateProvider { provider } => snapshot | ||
| .find(&provider.id) | ||
| .is_some_and(|found| provider.is_in(found)), | ||
| Self::RemoveProvider { id } => snapshot.find(id).is_none(), |
There was a problem hiding this comment.
🔴 Unchecked deletion of unrelated providers
When a plugin’s removal edit drops other providers too, shows_in still passes. edit_staged then replaces the real configuration and reports success.
Learn more
Core reads the agent’s provider configuration before calling its plugin, then asks the plugin to read the staged file after editing it. The removal check confirms the requested provider existed before the edit. The staged verification only confirms that it no longer appears. edit_staged installs the staged bytes once that check passes and the original file still matches.
Example: Configure alpha and gamma, then remove alpha. The synthetic backend’s wrong-edit mode replaces the staged configuration with an unrelated JSON object. Its reader still returns a valid snapshot containing the built-in provider and a default model. The removal check passes even though gamma is gone too.
Recommended fix: Verify the removal against the pre-edit snapshot as well as the staged snapshot. Require unrelated provider records to survive, allowing only explicitly supported changes to derived fields. Add a removal test using the wrong-edit mode and verify that the original file remains byte-for-byte unchanged.
Was this helpful? React with 👍 or 👎 to provide feedback.
| let snapshot = read_providers(link, agent, configuration, declared, &paths.files)?; | ||
| change.check_against(&snapshot)?; |
There was a problem hiding this comment.
🔴 Provider addition overwrites concurrent additions
If another writer adds the same provider before staging, check_against still approves the addition using the earlier snapshot. edit_staged copies the newer file, so its final byte check does not catch the stale approval.
Learn more
The provider command checks that an add uses a new ID before preparing the staged file. That check uses the plugin’s first read, which is not tied to any file revision. edit_staged captures its baseline later and detects only changes made after that capture. The synthetic provider editor assigns the requested provider by ID, relying on Core’s duplicate check to distinguish adds from updates.
Example: Start adding gateway. The initial read sees no such provider. The CLI saves its own gateway before Core copies the file. The edit replaces that entry in the copy, and the final byte check passes because the real file still contains the CLI’s version that Core copied.
Recommended fix: Check the operation against a read of the unmodified staged copy before invoking the editor, and verify it still resolves to the chosen target. Keep the existing comparison against the exact bytes staged so writes after that point still cause a refusal.
Was this helpful? React with 👍 or 👎 to provide feedback.
| let authority = rest.split('/').next().unwrap_or_default(); | ||
| let host = authority.strip_prefix('[').map_or_else( | ||
| || authority.split(':').next().unwrap_or_default(), | ||
| |v6| v6.split(']').next().unwrap_or_default(), | ||
| ); | ||
| !authority.contains('@') && !host.is_empty() |
There was a problem hiding this comment.
🟡 Malformed provider URLs pass validation
When a user mistypes a port as 8O80, is_endpoint accepts it. Both the edit and its read-back use that check, so the unusable endpoint can be saved.
Learn more
The endpoint check is shared by provider input and snapshot validation. It finds the start of a host without parsing the URL, so a nonnumeric port or unmatched IPv6 bracket passes both paths.
Example: Add a provider at https://api.example.com:8O80/v1. A plugin that stores and reports the supplied endpoint lets the edit pass, instead of Core returning agentProviders.invalidEndpoint.
Recommended fix: Use the crate’s existing url dependency to validate the full host and port. Retain checks for whitespace, controls and disallowed URL components, including empty userinfo, and test malformed ports and IPv6 addresses for both input and read-back.
Was this helpful? React with 👍 or 👎 to provide feedback.
| query.as_deref().is_none_or(|query| { | ||
| candidate | ||
| .texts | ||
| .iter() | ||
| .any(|text| text.to_lowercase().contains(query)) | ||
| }) |
There was a problem hiding this comment.
🟡 Library search misses final sigma
Searching for Σ misses ΦΩΣ because matching lowercases the query to σ but the item ends in ς.
Learn more
The library query contract specifies case-insensitive substring matching. Rust lowercases Greek capital sigma differently when it ends a word than when it appears alone, so lowercasing the entire strings independently can turn an exact substring into a mismatch.
Example: Save an MCP server named ΦΩΣ and search for Σ. The server name becomes φως, while the query becomes σ. The server is absent from the results.
Recommended fix: Use the same Unicode case-folding function for the query and candidate text, and cover final sigma with a library read test. Reuse the folding for the name tie-break comparator to keep case handling consistent.
Was this helpful? React with 👍 or 👎 to provide feedback.
关联
改动
一、API-45:Agent 插件上报并修改模型与供应商(
agents能力 0 内的补充,不升版本)agents[].configuration.providers:read、可选的edit与operations(addProvider、updateProvider、removeProvider、setProviderEnabled、setModel、setProvider、setProfile)。必须同时声明files;edit和operations同有同无;权限沿用agents.configuration。agentProviders.read({agent?}):每个 Agent 一项,含 CLI 版本、当前模型及来源层(用户配置 / 配置档 / 默认值 / 环境变量名)、当前供应商、配置里的供应商(ID、显示名、接口地址、协议、密钥环境变量名、请求头名、是否启用、是否内置)、配置档、账号标签、来源文件路径。未授权的 Agent 只列出,不调用插件。agentProviders.apply({agent, change},只接受用户发起):在暂存副本上调用插件的edit,回读确认修改生效,检查文件没被别人改过后替换。baseUrl只能是 http/https、必须有 host,不能带用户名、密码、查询参数、片段;条目数与长度都有上限。契约写明插件不得读凭据文件和钥匙串。baseUrl,走同一条地址校验;块里其他变量只给名字(environmentNames)。Core 不含任何具体变量名或 Agent 名。agentProviders.*共 16 个,一码一义(见契约 README)。agent.providers.read_finished/read_failed/change_applied/change_failed,只记操作、数量、耗时和错误码。二、
agentLibrary.read支持筛选与排序query、agent+presence(present/missing)、sort(name/agentCount)。matches: {mcpServers, hooks, skills},只给键;library、skills、states、agents仍然完整(save是整体覆盖)。不带参数时回答与之前完全一致。agentLibrary.invalidFilter。三、顺带修复
duration_ms(live.rs、records.rs、library.rs)。文档与契约
reference/domains/agents.md、capabilities-and-versions.md、api-catalog.md的 API-45 行、协议更新记录、四语 SDK README。agentProviders.*是宿主到 Core 的命令,providers.read/edit是插件函数,都不是插件调用的宿主方法,所以方法表和“宿主方法(按 API 编号)”索引没有加行,与 feat(agents): 统计支持拆分维度、筛选,并给出每组速度中位数与首字平均耗时 #245 的处理一致。兼容
providers会把它当未知字段拒绝整个清单;遇到新的筛选参数以agents.invalidPayload拒绝。providers的插件不受影响。验证(macOS,本机)
cargo fmt --checkcargo test -p lithe-agent-runtime -p lithe-plugin-agentscargo test -p lithe-core -p lithe-diagnosticscargo clippy --workspace --all-targets --all-features -- -D warningsscripts/rust-core/verify-rust-core-comments.shnode shared/plugins/scripts/verify-docs.mjsnode shared/plugins/scripts/sdk-e2e.mjs未执行:整个 workspace 的测试只跑了上面四个 crate;Windows 目标的 clippy 本机编不了
zstd-sys,看 CI。