mirror of
https://bitbucket.org/siakitem/my-pi.git
synced 2026-10-26 10:45:22 +00:00
feat: 组合包配置以包内 config/ 为唯一来源,并新增受保护写入人工审批
配置统一:权限策略、硬防御、Tool Search、提示词封面以及新迁入的 RTK、pi-compaction、pi-worktree、pi-hermes-memory 配置全部由扩展 直接读取已安装组合包内的 config/,pi install / pi update 即完成部署; 删除 rebuild-bundle-config.mjs 与 bundle-manifest.json,my-pi/ 只保留 日志与缓存。update.sh 成功升级后将默认 git 来源的已安装副本 reset 回发布版本。AGENTS.md 新增「组合包配置原则」。 脚本整合:search_config.sh / ssh_config.sh 合并为 configure.sh search|ssh;install.sh / update.sh 共享函数抽到 scripts/lib.sh,远程 安装器改为先下载到临时文件再执行,下载失败可被检测。 权限:hard-guards 新增 protectedWrites,写入 Pi 凭据/设置、已安装 组合包与扩展目录、pi-ssh 凭据库时一律人工确认(跳过 AutoReview、 yolo 与 Session grant,无 UI 时拒绝);放行 ls、LSP 查询、ctx 只读、 web_search、Chrome 只读与 git 只读命令,skill_manage 改为 ask。 Generated with [Devin](https://devin.ai) Co-Authored-By: Devin <158243242+devin-ai-integration[bot]@users.noreply.github.com>
This commit is contained in:
co-authored by
Devin <158243242+devin-ai-integration[bot]@users.noreply.github.com>
parent
a0ee9389c7
commit
2aa1be0b54
@@ -64,9 +64,9 @@ Pi 不支持修改进程 cwd。`/wt new` / `merge` / `switch` 通过 `SessionMan
|
||||
|
||||
## 状态与配置
|
||||
|
||||
- 登记文件:`<agentDir>/pi-worktree/state.json`(`getAgentDir()`,遵循 `PI_CODING_AGENT_DIR`),目录权限 `700`、文件权限 `600`,原子写入;文件损坏或版本未知时命令报错中止,不会被静默覆盖。**不**放在 `<agentDir>/my-pi/` 下,因为该目录每次升级会被整体替换。
|
||||
- `settings.json` 的 `piWorktree` 键:
|
||||
- `root`:worktree 根目录,默认 `~/.pi/worktrees`(只展开开头的 `~`,展开后必须是绝对路径)。worktree 路径为 `<root>/<主 worktree 目录名>/<slug>`。
|
||||
- 登记文件:`<agentDir>/pi-worktree/state.json`(`getAgentDir()`,遵循 `PI_CODING_AGENT_DIR`),目录权限 `700`、文件权限 `600`,原子写入;文件损坏或版本未知时命令报错中止,不会被静默覆盖。**不**放在 `<agentDir>/my-pi/` 下,因为该目录只承载可随时丢弃的运行时状态。
|
||||
- 配置文件:已安装组合包内的 `config/pi-worktree.json`(仓库 `config/` 是唯一来源,`pi update` 随组合包刷新;不读取 `settings.json`)。键:
|
||||
- `root`:worktree 根目录,默认 `~/.pi/worktrees`(只展开开头的 `~`,展开后必须是绝对路径)。该默认值依赖本机路径,因此组合包附带的 JSON 不写 `root`,由代码运行时计算。worktree 路径为 `<root>/<主 worktree 目录名>/<slug>`。
|
||||
- `branchPrefix`:新分支前缀,默认 `wt/`。
|
||||
- slug 规则:`A-Za-z0-9._-` 与 `/` 分层,最长 64 字符,不能以 `-` 开头、不能含 `..`、不能以 `.lock` 结尾,保留名 `main` / `HEAD` 不可用。
|
||||
|
||||
|
||||
@@ -971,7 +971,7 @@ export function registerWorktreeCommands(pi: ExtensionAPI): void {
|
||||
const git = createGit();
|
||||
let settings: WorktreeSettings;
|
||||
try {
|
||||
settings = readWorktreeSettings(() => pi.getSettings());
|
||||
settings = readWorktreeSettings();
|
||||
} catch (error) {
|
||||
notifyError(ctx.ui, error);
|
||||
return;
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
import { readFileSync } from "node:fs";
|
||||
import { homedir } from "node:os";
|
||||
import { isAbsolute, join } from "node:path";
|
||||
import { fileURLToPath } from "node:url";
|
||||
|
||||
export interface WorktreeSettings {
|
||||
/** Absolute directory under which worktrees are created: <root>/<repoName>/<pathSlug>. */
|
||||
@@ -10,20 +12,44 @@ export interface WorktreeSettings {
|
||||
const DEFAULT_ROOT = "~/.pi/worktrees";
|
||||
const DEFAULT_BRANCH_PREFIX = "wt/";
|
||||
|
||||
// Bundle-level `config/` is the single source of truth: the extension reads
|
||||
// `config/pi-worktree.json` from inside the installed bundle (resolved
|
||||
// relative to this source file), never `settings.json`. A `~`-prefixed `root`
|
||||
// is expanded against the current home directory at runtime.
|
||||
export const WORKTREE_CONFIG_PATH = fileURLToPath(
|
||||
new URL("../../config/pi-worktree.json", import.meta.url),
|
||||
);
|
||||
|
||||
function expandRoot(value: string): string {
|
||||
if (value === "~") return homedir();
|
||||
if (value.startsWith("~/")) return join(homedir(), value.slice(2));
|
||||
return value;
|
||||
}
|
||||
|
||||
export function readWorktreeSettings(getSettings: () => unknown): WorktreeSettings {
|
||||
const raw = (getSettings() as { piWorktree?: { root?: unknown; branchPrefix?: unknown } } | undefined)?.piWorktree;
|
||||
const rootRaw = typeof raw?.root === "string" && raw.root.trim() ? raw.root.trim() : DEFAULT_ROOT;
|
||||
function readConfigFile(configPath: string): Record<string, unknown> {
|
||||
try {
|
||||
const parsed = JSON.parse(readFileSync(configPath, "utf8")) as unknown;
|
||||
return parsed !== null && typeof parsed === "object" && !Array.isArray(parsed)
|
||||
? (parsed as Record<string, unknown>)
|
||||
: {};
|
||||
} catch {
|
||||
return {};
|
||||
}
|
||||
}
|
||||
|
||||
export function readWorktreeSettings(
|
||||
configPath: string = WORKTREE_CONFIG_PATH,
|
||||
): WorktreeSettings {
|
||||
const raw = readConfigFile(configPath);
|
||||
const rootRaw =
|
||||
typeof raw.root === "string" && raw.root.trim() ? raw.root.trim() : DEFAULT_ROOT;
|
||||
const root = expandRoot(rootRaw);
|
||||
if (!isAbsolute(root)) {
|
||||
throw new Error(`piWorktree.root 必须是绝对路径或以 ~ 开头:${rootRaw}`);
|
||||
throw new Error(`pi-worktree config root 必须是绝对路径或以 ~ 开头:${rootRaw}`);
|
||||
}
|
||||
const branchPrefix =
|
||||
typeof raw?.branchPrefix === "string" && raw.branchPrefix ? raw.branchPrefix : DEFAULT_BRANCH_PREFIX;
|
||||
typeof raw.branchPrefix === "string" && raw.branchPrefix
|
||||
? raw.branchPrefix
|
||||
: DEFAULT_BRANCH_PREFIX;
|
||||
return { root, branchPrefix };
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user