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
@@ -9,9 +9,11 @@ import {
|
||||
classifyTokenAsRuleCandidate,
|
||||
} from "#src/access-intent/bash/token-classification";
|
||||
import {
|
||||
collectCommandTokens,
|
||||
collectPathCandidateTokens,
|
||||
collectRedirectTokens,
|
||||
type BashPathTokenRole,
|
||||
type CollectedPathToken,
|
||||
collectCommandTokensDetailed,
|
||||
collectPathCandidateTokensDetailed,
|
||||
collectRedirectTokensDetailed,
|
||||
extractCommandName,
|
||||
} from "#src/access-intent/bash/token-collection";
|
||||
import { normalizePathPolicyLiteral } from "#src/access-intent/path-normalization";
|
||||
@@ -40,6 +42,9 @@ type EffectiveBase =
|
||||
interface PathCandidate {
|
||||
readonly token: string;
|
||||
readonly base: EffectiveBase;
|
||||
readonly role: BashPathTokenRole;
|
||||
readonly program: string | null;
|
||||
readonly wrapped: boolean;
|
||||
}
|
||||
|
||||
// ── Public output types ──────────────────────────────────────────────────────
|
||||
@@ -49,13 +54,41 @@ export interface BashPathRuleCandidate {
|
||||
readonly token: string;
|
||||
/** The path's lexical and canonical forms for permission policy matching. */
|
||||
readonly path: AccessPath;
|
||||
/**
|
||||
* How the command uses the token — `redirect-out`/`redirect-in` for
|
||||
* redirect destinations, `argument` otherwise. Only the protected-write
|
||||
* gate reads this; the ordinary path gate is role-agnostic.
|
||||
*/
|
||||
readonly role: BashPathTokenRole;
|
||||
/** The enclosing command's program name, or `null` outside a command. */
|
||||
readonly program: string | null;
|
||||
/**
|
||||
* True inside a wrapper payload (`bash -c`, `eval`, `sudo`, `xargs`, …) or a
|
||||
* command/process substitution — the enclosing program cannot vouch for the
|
||||
* token's use.
|
||||
*/
|
||||
readonly wrapped: boolean;
|
||||
}
|
||||
|
||||
/** Cd-aware path-rule candidates extracted from a bash program. */
|
||||
export interface ResolvedBashPaths {
|
||||
readonly ruleCandidates: readonly BashPathRuleCandidate[];
|
||||
/**
|
||||
* The protected-write slice: every `ruleCandidates` entry plus every
|
||||
* `redirect-out` destination, which is admitted unconditionally — a redirect
|
||||
* target need not exist nor look like a path to still be written (`cd dir
|
||||
* && echo 1 > new.json`). Role metadata is what the gate classifies on.
|
||||
*/
|
||||
readonly writeCandidates: readonly BashPathRuleCandidate[];
|
||||
}
|
||||
|
||||
/**
|
||||
* Redirect targets that are really file-descriptor plumbing, not files:
|
||||
* `>&1`, `2>&-` and friends write to a descriptor, so they never enter the
|
||||
* write slice.
|
||||
*/
|
||||
const FD_DUPLICATE_TARGET = /^&?[\d-]+$/;
|
||||
|
||||
// ── Walk-time constants ──────────────────────────────────────────────────────
|
||||
|
||||
/** The working directory in force at the start of a program (`cwd`). */
|
||||
@@ -101,9 +134,7 @@ export class BashPathResolver {
|
||||
? CWD_BASE
|
||||
: this.deriveBaseFromCdTarget(CWD_BASE, this.workdir);
|
||||
const candidates = this.collectPathCandidates(rootNode, initialBase);
|
||||
return {
|
||||
ruleCandidates: this.projectRuleCandidates(candidates),
|
||||
};
|
||||
return this.projectCandidates(candidates);
|
||||
}
|
||||
|
||||
// ── AST walk — collect PathCandidates ──────────────────────────────────
|
||||
@@ -145,7 +176,7 @@ export class BashPathResolver {
|
||||
case "redirected_statement":
|
||||
return this.walkCurrentShellSequence(node, base, out);
|
||||
case "command":
|
||||
tagTokens(collectCommandTokens(node), base, out);
|
||||
tagTokens(collectCommandTokensDetailed(node), base, out);
|
||||
return this.foldCd(node, base);
|
||||
case "pipeline":
|
||||
// tree-sitter-bash mis-groups a redirect-bearing `&&`/`;` list as the
|
||||
@@ -170,7 +201,7 @@ export class BashPathResolver {
|
||||
// substitution interiors: collect every candidate in the subtree tagged
|
||||
// with the enclosing base and do not fold their internal `cd`s. (Folding
|
||||
// inside substitutions is deferred — conservative, never under-flags.)
|
||||
tagTokens(collectPathCandidateTokens(node), base, out);
|
||||
tagTokens(collectPathCandidateTokensDetailed(node), base, out);
|
||||
return base;
|
||||
}
|
||||
}
|
||||
@@ -230,7 +261,7 @@ export class BashPathResolver {
|
||||
}
|
||||
// Downstream stage (after a `|`): subshell — collect against the folded
|
||||
// base, do not fold.
|
||||
tagTokens(collectPathCandidateTokens(child), current, out);
|
||||
tagTokens(collectPathCandidateTokensDetailed(child), current, out);
|
||||
}
|
||||
return current;
|
||||
}
|
||||
@@ -260,7 +291,7 @@ export class BashPathResolver {
|
||||
if (child.type === "file_redirect") {
|
||||
// Redirect destinations are part of the piped stage; collect them
|
||||
// against the folded base without folding.
|
||||
tagTokens(collectRedirectTokens(child), current, out);
|
||||
tagTokens(collectRedirectTokensDetailed(child), current, out);
|
||||
continue;
|
||||
}
|
||||
// The inner statement is the `list`/`command` being redirected; fold its
|
||||
@@ -270,7 +301,7 @@ export class BashPathResolver {
|
||||
return current;
|
||||
}
|
||||
// Bare `command` or any other shape: a true subshell first stage.
|
||||
tagTokens(collectPathCandidateTokens(node), base, out);
|
||||
tagTokens(collectPathCandidateTokensDetailed(node), base, out);
|
||||
return base;
|
||||
}
|
||||
|
||||
@@ -298,7 +329,7 @@ export class BashPathResolver {
|
||||
current = this.walkForCandidates(child, current, out);
|
||||
} else {
|
||||
// Terminal child = the real pipe stage; collect without folding.
|
||||
tagTokens(collectPathCandidateTokens(child), current, out);
|
||||
tagTokens(collectPathCandidateTokensDetailed(child), current, out);
|
||||
}
|
||||
}
|
||||
return current;
|
||||
@@ -363,34 +394,67 @@ export class BashPathResolver {
|
||||
/**
|
||||
* Project candidates into policy lookup values while preserving literal
|
||||
* values after a non-literal `cd`, where no reliable absolute base exists.
|
||||
*
|
||||
* `ruleCandidates` keeps the long-standing admission rule — path-shaped
|
||||
* tokens plus bare tokens an existence probe confirms. `writeCandidates`
|
||||
* additionally admits every `redirect-out` destination: a redirect writes
|
||||
* its target whether or not the file exists yet, so existence and shape
|
||||
* cannot gate it. The write slice is deduplicated per role so the same
|
||||
* path appearing as both a read argument and a write destination keeps
|
||||
* both classifications.
|
||||
*/
|
||||
private projectRuleCandidates(
|
||||
private projectCandidates(
|
||||
candidates: readonly PathCandidate[],
|
||||
): BashPathRuleCandidate[] {
|
||||
const seen = new Set<string>();
|
||||
const result: BashPathRuleCandidate[] = [];
|
||||
): ResolvedBashPaths {
|
||||
const seenRules = new Set<string>();
|
||||
const seenWrites = new Set<string>();
|
||||
const ruleCandidates: BashPathRuleCandidate[] = [];
|
||||
const writeCandidates: BashPathRuleCandidate[] = [];
|
||||
|
||||
for (const { token, base } of candidates) {
|
||||
const pushWrite = (
|
||||
candidate: BashPathRuleCandidate,
|
||||
matchValues: readonly string[],
|
||||
): void => {
|
||||
const key = `${candidate.role} | ||||