Skip to main content

OpenCodeConfig

Struct OpenCodeConfig 

Source
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

Source

pub fn new(root: &ProjectRoot) -> Result<Self>

创建管理器,配置路径固定为用户级全局 opencode.json

v39 起(官方文档+源码查证):opencode 用户级配置根为 ~/.config/opencode(全平台一致,含 Windows——xdg-basedir 无平台 分支);插件自动加载目录为配置根下 plugins/。因此插件文件与 配置清理全部落在用户级(一次 install 全仓库 opencode 会话可用), 不再读写项目根 .opencode.json——那是用户自建文件,不属于本工具。

Source

pub fn install_plugin(&mut self) -> Result<()>

安装 code-repo-wiki 插件

插件目录自动加载,无需配置条目;本方法仅幂等清理配置中 历史遗留的无效 plugins 键(opencode 1.18.10 解析会报 Unrecognized key 错误)。配置不存在时静默创建空对象。

Source

pub fn uninstall_plugin(&mut self) -> Result<()>

从 opencode.json 卸载 code-repo-wiki 插件(清理无效 plugins 键)

opencode 对插件是目录自动加载,卸载插件的实际动作是删除 .opencode/plugins/code-repo-wiki.ts 文件(由用户决定,不在此处执行); 本方法仅保证配置不含历史遗留的无效键。

Source

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/), 安装状态以用户级文件存在性为准(项目级旧产物由迁移逻辑清理, 不再视为已安装)。

Source

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 修复自举缺陷——模板源不再依赖仓库内安装产物文件)。

Source

pub fn uninstall_plugin_file(&mut self) -> Result<()>

删除用户级插件文件(plugins/plugin/ 双目录,与官方自动加载 glob {plugin,plugins}/*.{ts,js}Self::is_installed 对称), 并清理 v39 之前的旧版项目级产物。

文件不存在时静默成功(幂等,与 uninstall_plugin 语义一致)。

Source

pub fn config_dir() -> Result<PathBuf>

获取 OpenCode 配置的根目录 (~/.config/opencode/)

v33:USERPROFILE 与 HOME 都缺失时显式报错(与 crate::config::global_config_dir 的「写错位置比报错更隐蔽」 语义统一),不再回退 . 静默写当前目录。

Source

pub fn config_dir_from( userprofile: Option<&str>, home: Option<&str>, ) -> Result<PathBuf>

纯函数版配置根目录解析(N11/v33 语义)——Windows 下 USERPROFILE 优先于 HOME(两者都存在时 HOME 可能是 Cygwin/残留值)。拆成纯函数以便测试不依赖进程级环境变量 (并行测试对全局 env 的读写是竞态)。

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts 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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts 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
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> PolicyExt for T
where T: ?Sized,

Source§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow only if self and other return Action::Follow. Read more
Source§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow if either self or other returns Action::Follow. Read more
Source§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more