pub struct OpenCodeConfig {
pub config_path: PathBuf,
pub project_root: PathBuf,
}Expand description
OpenCode 配置管理器
Fields§
§config_path: PathBuf全局 opencode.json 路径(~/.config/opencode/opencode.json)
project_root: PathBuf项目根目录(仅用于清理 v39 之前的旧版项目级插件产物)
Implementations§
Source§impl OpenCodeConfig
impl OpenCodeConfig
Sourcepub fn new(root: &ProjectRoot) -> Result<Self>
pub fn new(root: &ProjectRoot) -> Result<Self>
创建管理器,配置路径固定为用户级全局 opencode.json
v39 起(官方文档+源码查证):opencode 用户级配置根为
~/.config/opencode(全平台一致,含 Windows——xdg-basedir 无平台
分支);插件自动加载目录为配置根下 plugins/。因此插件文件与
配置清理全部落在用户级(一次 install 全仓库 opencode 会话可用),
不再读写项目根 .opencode.json——那是用户自建文件,不属于本工具。
Sourcepub fn install_plugin(&mut self) -> Result<()>
pub fn install_plugin(&mut self) -> Result<()>
安装 code-repo-wiki 插件
插件目录自动加载,无需配置条目;本方法仅幂等清理配置中
历史遗留的无效 plugins 键(opencode 1.18.10 解析会报
Unrecognized key 错误)。配置不存在时静默创建空对象。
Sourcepub fn uninstall_plugin(&mut self) -> Result<()>
pub fn uninstall_plugin(&mut self) -> Result<()>
从 opencode.json 卸载 code-repo-wiki 插件(清理无效 plugins 键)
opencode 对插件是目录自动加载,卸载插件的实际动作是删除
.opencode/plugins/code-repo-wiki.ts 文件(由用户决定,不在此处执行);
本方法仅保证配置不含历史遗留的无效键。
Sourcepub fn is_installed(&self) -> Result<bool>
pub fn is_installed(&self) -> Result<bool>
检查插件是否已安装(插件文件 .opencode/plugins/code-repo-wiki.ts 是否存在)
以文件存在性为准:opencode 目录自动加载,配置文件不再承载注册信息。
N10:官方加载器 glob 为 {plugin,plugins}/*.{ts,js}——单复数目录
都要查(此前只查 plugins/,用户手工放在 plugin/ 时误报未安装)。
v39:插件已移至用户级配置根(~/.config/opencode/plugins/),
安装状态以用户级文件存在性为准(项目级旧产物由迁移逻辑清理,
不再视为已安装)。
Sourcepub fn install_plugin_file(&mut self) -> Result<bool>
pub fn install_plugin_file(&mut self) -> Result<bool>
将插件模板写入 {config_root}/plugins/code-repo-wiki.ts(用户级)
v39:插件是「用户级内容」——装进 Agent 配置根目录
~/.config/opencode/plugins/(官方文档:该目录下 {plugin,plugins}/*.{ts,js}
启动时自动加载),一次 install 全仓库 opencode 会话可用,不再写入
项目 .opencode/plugins/。写入前清理 v39 之前的旧版项目级产物。
升级语义(用户拍板「带标记则升级」):插件文件是 code-repo-wiki 专属产物(文件名即标记),内容与最新模板(注入当前 exe 绝对路径) 不同即覆盖升级(旧版本模板/二进制路径变化);相同则跳过。 返回是否实际写入。模板经 include_str 内嵌编译(见下方实现注释: v33 修复自举缺陷——模板源不再依赖仓库内安装产物文件)。
Sourcepub fn uninstall_plugin_file(&mut self) -> Result<()>
pub fn uninstall_plugin_file(&mut self) -> Result<()>
删除用户级插件文件(plugins/ 与 plugin/ 双目录,与官方自动加载
glob {plugin,plugins}/*.{ts,js} 及 Self::is_installed 对称),
并清理 v39 之前的旧版项目级产物。
文件不存在时静默成功(幂等,与 uninstall_plugin 语义一致)。
Sourcepub fn config_dir() -> Result<PathBuf>
pub fn config_dir() -> Result<PathBuf>
获取 OpenCode 配置的根目录 (~/.config/opencode/)
v33:USERPROFILE 与 HOME 都缺失时显式报错(与
crate::config::global_config_dir 的「写错位置比报错更隐蔽」
语义统一),不再回退 . 静默写当前目录。
Auto Trait Implementations§
impl Freeze for OpenCodeConfig
impl RefUnwindSafe for OpenCodeConfig
impl Send for OpenCodeConfig
impl Sync for OpenCodeConfig
impl Unpin for OpenCodeConfig
impl UnsafeUnpin for OpenCodeConfig
impl UnwindSafe for OpenCodeConfig
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
Source§fn in_current_span(self) -> Instrumented<Self> ⓘ
fn in_current_span(self) -> Instrumented<Self> ⓘ
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more