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
52 changes: 31 additions & 21 deletions crates/tw-adopt/src/clients.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,10 @@ impl TakesEffect {
/// 接管提示和诊断结论里的那一句。
pub fn note(&self) -> &'static str {
match self {
TakesEffect::Immediately => "下一个请求即使用新配置。",
TakesEffect::OnRestart => "重新打开终端后生效,在此之前网关不会收到该客户端的请求。",
TakesEffect::Immediately => "The next request uses the new configuration.",
TakesEffect::OnRestart => {
"It takes effect once the terminal is reopened; until then the gateway sees nothing from this client."
}
}
}
/// 该不该设「还没收到请求」的超时提示。
Expand Down Expand Up @@ -81,8 +83,10 @@ impl Verified {
/// 命令行里的说法。
pub fn note(&self) -> &'static str {
match self {
Verified::Measured => "已在本机实际运行验证",
Verified::FieldsOnly => "字段名已查证,尚未在本机实际运行验证",
Verified::Measured => "checked by actually running it on this machine",
Verified::FieldsOnly => {
"the field names are verified; it has not been run on this machine"
}
}
}
}
Expand Down Expand Up @@ -189,9 +193,9 @@ pub fn adoptable() -> Vec<Client> {
// **`settings.local.json` 优先级更高。**cc-switch #6828 栽在这里
shadowed_by: &[".claude/settings.local.json"],
costs: &[
"接口地址不是官方域名时,Remote Control 和语音输入不可用。",
"MCP tool search 将默认关闭。",
"Claude Code 可能会显示一次欢迎页,关闭即可。",
"Remote Control and voice input do not work when the endpoint is not an official domain.",
"MCP tool search is off by default.",
"Claude Code may show its welcome screen once; closing it is enough.",
],
verified: Verified::FieldsOnly,
marker: &[".claude"],
Expand All @@ -216,8 +220,8 @@ pub fn adoptable() -> Vec<Client> {
// 所以它不构成遮蔽 —— 但它确实存在,值得在诊断里提一句
shadowed_by: &[],
costs: &[
"Codex CLI 不从网关获取模型列表,自定义模型名无效,模型列表以本地的模型目录文件为准。",
"修改后需要重新打开终端。",
"Codex CLI does not read the model list from the gateway, so a custom model name has no effect; its local model catalogue decides.",
"The terminal has to be reopened afterwards.",
],
verified: Verified::Measured,
marker: &[".codex"],
Expand All @@ -232,7 +236,7 @@ pub fn adoptable() -> Vec<Client> {
format: Format::Json,
takes_effect: TakesEffect::OnRestart,
shadowed_by: &[],
costs: &["修改后需要重新启动 opencode。"],
costs: &["opencode has to be restarted afterwards."],
verified: Verified::FieldsOnly,
marker: &[".config/opencode", ".local/share/opencode"],
process: &["opencode"],
Expand All @@ -248,7 +252,9 @@ pub fn adoptable() -> Vec<Client> {
shadowed_by: &[],
// **只算部分接管**:Zed 的密钥走它自己的凭据存储,不在
// settings.json 里,我们写不进去。
costs: &["Zed 的密钥不保存在配置文件中,需要在 Zed 的设置界面中手动填写一次。"],
costs: &[
"Zed keeps its key outside the configuration file, so it has to be filled in once in Zed's settings.",
],
verified: Verified::FieldsOnly,
marker: &[".config/zed"],
process: &["Zed"],
Expand All @@ -265,8 +271,8 @@ pub fn adoptable() -> Vec<Client> {
// 我们只写 home 那一份,所以项目里的会盖住它
shadowed_by: &[],
costs: &[
"Aider 依次读取主目录、Git 项目根目录和当前目录中的配置,后读取的会覆盖先读取的,接管只修改主目录中的配置。",
"修改后需要重新启动 Aider。",
"Aider reads the home directory, then the Git project root, then the current directory, and each one overrides the last; only the home directory is changed here.",
"Aider has to be restarted afterwards.",
],
verified: Verified::FieldsOnly,
// 没接管过的用户本来就没有这个文件,所以它自己就是那个痕迹
Expand Down Expand Up @@ -304,25 +310,25 @@ pub fn manual_only() -> Vec<ManualOnly> {
vec![
ManualOnly {
name: "Cursor",
steps: "在 Cursor 的「Settings → Models」中开启 Override OpenAI Base URL,填写 {v1}。",
caveat: "Tab 补全与 inline edit 仍由 Cursor 自身的服务处理,不经过网关,因此只能部分接管。",
steps: "In Cursor, under Settings → Models, turn on Override OpenAI Base URL and enter {v1}.",
caveat: "Tab completion and inline edit still go to Cursor's own service rather than the gateway, so only part of Cursor is covered.",
},
ManualOnly {
name: "Continue",
steps: "在 ~/.continue/config.yaml 的 models 列表中添加一项,将 apiBase 设为 {v1}。",
steps: "Add an entry to the models list in ~/.continue/config.yaml with apiBase set to {v1}.",
// **接管它要往一个 YAML 列表里插一个新条目**,那是结构性
// 改写,不是替换一个标量。我们的 YAML 补丁只做后者
// (见 crate::yaml 开头那段)。宁可少接管一个客户端,也不
// 要写一段我们自己没把握的结构。
caveat: "接入需要在 models 列表中新增条目,不提供自动接管,请按上述步骤手动配置。",
caveat: "This needs a new entry in the models list, which is not written automatically; follow the steps above.",
},
ManualOnly {
name: "Gemini CLI",
steps: "在 shell 配置文件中添加 export GOOGLE_GEMINI_BASE_URL={base},然后重新打开终端。",
steps: "Add export GOOGLE_GEMINI_BASE_URL={base} to the shell configuration, then reopen the terminal.",
// 它只认环境变量,没有可写的配置字段。改 .zshrc 超出了
// 「只改 endpoint 和 key 字段」的边界 ——
// **报告是我们的职责,修改是他的权利。**
caveat: "Gemini CLI 只从环境变量读取接口地址。ThinkWatch 不修改 shell 配置文件,请手动添加。",
caveat: "Gemini CLI reads the endpoint only from the environment. ThinkWatch does not edit shell configuration files, so add it by hand.",
},
]
}
Expand Down Expand Up @@ -503,7 +509,7 @@ mod tests {
c.id
);
assert!(
c.takes_effect.note().contains("重新打开终端"),
c.takes_effect.note().contains("terminal is reopened"),
"{} 没在接管那一刻说清要重开",
c.id
);
Expand Down Expand Up @@ -559,7 +565,11 @@ mod tests {
// 我们这儿,而 Tab 补全根本不经过。
let m = manual_only();
let cursor = m.iter().find(|c| c.name == "Cursor").unwrap();
assert!(cursor.caveat.contains("Tab 补全"), "{}", cursor.caveat);
assert!(
cursor.caveat.contains("Tab completion"),
"{}",
cursor.caveat
);
// 步骤里要有真实的地址,而不是一个让用户自己去找的说法
let gw = Gateway {
base: "http://127.0.0.1:8788".into(),
Expand Down
86 changes: 48 additions & 38 deletions crates/tw-adopt/src/detect.rs
Original file line number Diff line number Diff line change
Expand Up @@ -237,34 +237,34 @@ pub fn diagnose(c: &Client, home: &Path, project: Option<&Path>) -> Vec<Finding>
if started.is_empty() {
out.push(Finding {
level: Level::Clear,
title: format!("{} 当前未运行", c.name),
detail: "下次启动时将读取新配置。".into(),
title: format!("{} is not running", c.name),
detail: "It reads the new configuration the next time it starts.".into(),
fix: None,
});
} else if !stale.is_empty() {
out.push(Finding {
level: Level::Blocking,
title: format!("{} 的进程启动于接管之前", c.name),
title: format!("{} was started before the change", c.name),
detail: format!(
"有 {} 个进程在接管之前启动,仍在使用旧配置。{}",
"{} processes were started before the change and are still on the old configuration. {}",
stale.len(),
c.takes_effect.note()
),
fix: Some(format!("退出 {} 后重新打开", c.name)),
fix: Some(format!("Quit {} and open it again", c.name)),
});
} else {
out.push(Finding {
level: Level::Clear,
title: format!("{} 在接管之后启动", c.name),
detail: "已读取新配置。".into(),
title: format!("{} was started after the change", c.name),
detail: "It has read the new configuration.".into(),
fix: None,
});
}
}
None => out.push(Finding {
level: Level::Suspect,
title: "尚未接管该客户端".into(),
detail: format!("{} 中没有接管记录。", d.real.display()),
title: "This client has not been pointed at the gateway".into(),
detail: format!("{} carries no record.", d.real.display()),
fix: None,
}),
}
Expand All @@ -273,11 +273,11 @@ pub fn diagnose(c: &Client, home: &Path, project: Option<&Path>) -> Vec<Finding>
if d.shadows.is_empty() {
out.push(Finding {
level: Level::Clear,
title: "没有优先级更高的配置文件".into(),
title: "Nothing takes precedence over this file".into(),
detail: if c.shadowed_by.is_empty() {
"该客户端没有优先级更高的配置文件。".into()
"This client has no configuration file that takes precedence.".into()
} else {
format!("{} 不存在。", c.shadowed_by.join("、"))
format!("{} does not exist.", c.shadowed_by.join(", "))
},
fix: None,
});
Expand All @@ -291,19 +291,22 @@ pub fn diagnose(c: &Client, home: &Path, project: Option<&Path>) -> Vec<Finding>
} else {
Level::Blocking
},
title: format!("{} 的优先级高于接管写入的配置", s.display()),
title: format!(
"{} takes precedence over what was written here",
s.display()
),
detail: if hits.is_empty() {
"该文件存在,但不包含相关字段。".into()
"The file exists, but carries none of the fields in question.".into()
} else {
format!(
"该文件中包含 {},会覆盖接管写入的设置。",
"The file carries {}, which overrides what was written here.",
hits.iter()
.map(|s| s.to_string())
.collect::<Vec<_>>()
.join("、")
.join(", ")
)
},
fix: Some(format!("检查 {} 中的相关字段", s.display())),
fix: Some(format!("Look at those fields in {}", s.display())),
});
}
}
Expand All @@ -314,9 +317,12 @@ pub fn diagnose(c: &Client, home: &Path, project: Option<&Path>) -> Vec<Finding>
if local.exists() {
out.push(Finding {
level: Level::Suspect,
title: "当前项目中有同名配置文件".into(),
detail: format!("{} 会覆盖用户级配置。", local.display()),
fix: Some(format!("检查 {}", local.display())),
title: "This project has a configuration file of the same name".into(),
detail: format!(
"{} overrides the user-level configuration.",
local.display()
),
fix: Some(format!("Look at {}", local.display())),
});
}
}
Expand All @@ -332,15 +338,16 @@ pub fn diagnose(c: &Client, home: &Path, project: Option<&Path>) -> Vec<Finding>
} else {
Level::Blocking
},
title: "本机存在管理策略文件".into(),
detail: format!("{MANAGED} 的优先级高于其他所有配置,包括用户配置。"),
title: "This machine has a managed-policy file".into(),
detail: format!("{MANAGED} takes precedence over everything else, including the user's own configuration."),
fix: None,
});
} else {
out.push(Finding {
level: Level::Clear,
title: "本机没有管理策略文件".into(),
detail: "不存在优先级高于其他所有配置的管理策略文件。".into(),
title: "This machine has no managed-policy file".into(),
detail: "There is no managed-policy file taking precedence over everything else."
.into(),
fix: None,
});
}
Expand All @@ -351,8 +358,8 @@ pub fn diagnose(c: &Client, home: &Path, project: Option<&Path>) -> Vec<Finding>
if exports.is_empty() {
out.push(Finding {
level: Level::Clear,
title: "shell 配置中没有同名环境变量".into(),
detail: "已检查 .zshrc、.zprofile、.bashrc 等文件。".into(),
title: "No shell file exports a variable of the same name".into(),
detail: "Checked .zshrc, .zprofile, .bashrc and the rest.".into(),
fix: None,
});
} else {
Expand All @@ -363,19 +370,22 @@ pub fn diagnose(c: &Client, home: &Path, project: Option<&Path>) -> Vec<Finding>
(
Level::Suspect,
format!(
"不影响 {}(其配置文件优先级更高),但会影响读取环境变量的其他客户端。",
"It does not affect {}, whose configuration file takes precedence, but it does affect every client that reads the environment.",
c.name
),
)
} else {
(
Level::Blocking,
format!("{} 读取环境变量,该行会覆盖接管写入的配置。", c.name),
format!(
"{} reads the environment, so this line overrides what was written here.",
c.name
),
)
};
out.push(Finding {
level,
title: format!("{} 第 {line} 行导出了 {name}", f.display()),
title: format!("{} exports {name} on line {line}", f.display()),
detail,
// 命令给出来,执行与否是他的事
fix: Some(format!("sed -i '' '{line}d' {}", f.display())),
Expand All @@ -387,17 +397,17 @@ pub fn diagnose(c: &Client, home: &Path, project: Option<&Path>) -> Vec<Finding>
match (&d.adopted_at_ms, &d.endpoint) {
(Some(_), None) => out.push(Finding {
level: Level::Blocking,
title: "接管写入的字段已不在配置中".into(),
title: "The fields written here are no longer in the configuration".into(),
detail: format!(
"{} 中未找到接管写入的接口地址,可能已被其他工具修改。",
"{} no longer carries the endpoint that was written here; something else may have changed it.",
d.real.display()
),
fix: Some("重新接管该客户端".into()),
fix: Some("Point this client at the gateway again".into()),
}),
(Some(_), Some(ep)) => out.push(Finding {
level: Level::Clear,
title: "配置中的接口地址与接管时一致".into(),
detail: format!("当前指向 {ep}。"),
title: "The endpoint in the configuration is the one written here".into(),
detail: format!("It points at {ep}."),
fix: None,
}),
_ => {}
Expand All @@ -407,8 +417,8 @@ pub fn diagnose(c: &Client, home: &Path, project: Option<&Path>) -> Vec<Finding>
// 绿色的「查过了没问题」会让人以为已经确认过。
out.push(Finding {
level: Level::Suspect,
title: "以上均为静态检查".into(),
detail: "静态检查无法确认配置已实际生效。收到该客户端的真实请求后,才能确认接管已生效。"
title: "Everything above is a static check".into(),
detail: "A static check cannot tell whether the configuration is actually in use. Only a real request from this client settles that."
.into(),
fix: None,
});
Expand Down Expand Up @@ -480,7 +490,7 @@ mod tests {
.find(|f| f.title.contains("ANTHROPIC_BASE_URL"))
.unwrap();
assert_eq!(f.level, Level::Suspect, "{:?}", f);
assert!(f.detail.contains("优先级更高"), "{}", f.detail);
assert!(f.detail.contains("takes precedence"), "{}", f.detail);

let cx = diagnose(&c("codex"), home, None);
let f = cx
Expand All @@ -505,7 +515,7 @@ mod tests {
let d = tempfile::tempdir().unwrap();
let out = diagnose(&c("claude-code"), d.path(), None);
assert!(
out.iter().any(|f| f.detail.contains("真实请求")),
out.iter().any(|f| f.detail.contains("real request")),
"结论里没留下这句话:{out:?}"
);
}
Expand Down
Loading
Loading