refactor(permission-system): simplify policy and autoreview flow

This commit is contained in:
云服务部-叶林立
2026-09-03 02:01:06 +08:00
parent 180da95ab7
commit 6e7effa792
112 changed files with 911 additions and 10346 deletions
+1 -38
View File
@@ -67,8 +67,6 @@ function getConfiguredMcpServerNamesFromPaths(
export interface ResolvedPolicyPaths {
globalConfigPath: string;
globalConfigExists: boolean;
projectConfigPath: string | null;
projectConfigExists: boolean;
agentsDir: string;
agentsDirExists: boolean;
projectAgentsDir: string | null;
@@ -87,7 +85,6 @@ export interface ResolvedPolicyPaths {
*/
export interface PolicyLoader {
loadGlobalConfig(): ScopeConfig;
loadProjectConfig(): ScopeConfig;
loadAgentConfig(agentName?: string): ScopeConfig;
loadProjectAgentConfig(agentName?: string): ScopeConfig;
getConfiguredMcpServerNames(): readonly string[];
@@ -130,7 +127,6 @@ type FileCacheEntry<TValue> = {
export interface PolicyLoaderOptions {
globalConfigPath?: string;
agentsDir?: string;
projectGlobalConfigPath?: string;
projectAgentsDir?: string;
globalMcpConfigPath?: string;
mcpServerNames?: readonly string[];
@@ -147,13 +143,11 @@ export interface PolicyLoaderOptions {
export class FilePolicyLoader implements PolicyLoader {
private readonly globalConfigPath: string;
private readonly agentsDir: string;
private readonly projectGlobalConfigPath: string | null;
private readonly projectAgentsDir: string | null;
private readonly globalMcpConfigPath: string;
private readonly configuredMcpServerNamesOverride: readonly string[] | null;
private globalConfigCache: FileCacheEntry<ScopeConfig> | null = null;
private projectGlobalConfigCache: FileCacheEntry<ScopeConfig> | null = null;
private readonly agentConfigCache = new Map<
string,
FileCacheEntry<ScopeConfig>
@@ -171,7 +165,6 @@ export class FilePolicyLoader implements PolicyLoader {
this.globalConfigPath =
options.globalConfigPath ?? defaultGlobalConfigPath();
this.agentsDir = options.agentsDir ?? defaultAgentsDir();
this.projectGlobalConfigPath = options.projectGlobalConfigPath ?? null;
this.projectAgentsDir = options.projectAgentsDir ?? null;
this.globalMcpConfigPath =
options.globalMcpConfigPath ?? defaultGlobalMcpConfigPath();
@@ -219,29 +212,6 @@ export class FilePolicyLoader implements PolicyLoader {
return value;
}
loadProjectConfig(): ScopeConfig {
if (!this.projectGlobalConfigPath) {
return {};
}
const stamp = getFileStamp(this.projectGlobalConfigPath);
if (this.projectGlobalConfigCache?.stamp === stamp) {
return this.projectGlobalConfigCache.value;
}
const { config, issues } = loadUnifiedConfig(this.projectGlobalConfigPath);
this.accumulateConfigIssues(issues);
// A present-but-rejected file yields issues (parse error or schema
// rejection); an absent file yields none. Fail closed on the former.
const value: ScopeConfig = {
permission: config.permission,
...(issues.length > 0 ? { invalid: true } : {}),
};
this.projectGlobalConfigCache = { stamp, value };
return value;
}
private loadScopeConfigFrom(
dir: string | null,
@@ -335,15 +305,12 @@ export class FilePolicyLoader implements PolicyLoader {
const agentStamp = agentName
? getFileStamp(join(this.agentsDir, `${agentName}.md`))
: "missing";
const projectStamp = this.projectGlobalConfigPath
? getFileStamp(this.projectGlobalConfigPath)
: "none";
const projectAgentStamp =
this.projectAgentsDir && agentName
? getFileStamp(join(this.projectAgentsDir, `${agentName}.md`))
: "none";
return `${getFileStamp(this.globalConfigPath)}|${projectStamp}|${agentStamp}|${projectAgentStamp}`;
return `${getFileStamp(this.globalConfigPath)}|${agentStamp}|${projectAgentStamp}`;
}
// ── Resolved paths ────────────────────────────────────────────────────
@@ -352,10 +319,6 @@ export class FilePolicyLoader implements PolicyLoader {
return {
globalConfigPath: this.globalConfigPath,
globalConfigExists: existsSync(this.globalConfigPath),
projectConfigPath: this.projectGlobalConfigPath,
projectConfigExists: this.projectGlobalConfigPath
? existsSync(this.projectGlobalConfigPath)
: false,
agentsDir: this.agentsDir,
agentsDirExists: existsSync(this.agentsDir),
projectAgentsDir: this.projectAgentsDir,