mirror of
https://bitbucket.org/siakitem/my-pi.git
synced 2026-10-26 10:45:22 +00:00
refactor(permission-system): simplify policy and autoreview flow
This commit is contained in:
@@ -8,7 +8,7 @@ import { mkdirSync, mkdtempSync, rmSync, writeFileSync } from "node:fs";
|
||||
import { tmpdir } from "node:os";
|
||||
import { join } from "node:path";
|
||||
|
||||
import { getGlobalConfigPath, getProjectConfigPath } from "#src/config-paths";
|
||||
import { getGlobalConfigPath } from "#src/config-paths";
|
||||
import { PermissionManager, type PolicyLoader } from "#src/permission-manager";
|
||||
import type { ResolvedPolicyPaths } from "#src/policy-loader";
|
||||
import type { Rule } from "#src/rule";
|
||||
@@ -21,7 +21,6 @@ import type { PermissionState, ScopeConfig } from "#src/types";
|
||||
export function createInMemoryPolicyLoader(
|
||||
scopes: {
|
||||
global?: ScopeConfig;
|
||||
project?: ScopeConfig;
|
||||
agent?: Record<string, ScopeConfig>;
|
||||
projectAgent?: Record<string, ScopeConfig>;
|
||||
} = {},
|
||||
@@ -30,7 +29,6 @@ export function createInMemoryPolicyLoader(
|
||||
const issues: string[] = [];
|
||||
return {
|
||||
loadGlobalConfig: () => scopes.global ?? ({} as const),
|
||||
loadProjectConfig: () => scopes.project ?? ({} as const),
|
||||
// eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing -- || is intentional: handles both falsy name and missing key
|
||||
loadAgentConfig: (name?: string) => (name && scopes.agent?.[name]) || {},
|
||||
loadProjectAgentConfig: (name?: string) =>
|
||||
@@ -42,8 +40,6 @@ export function createInMemoryPolicyLoader(
|
||||
getResolvedPolicyPaths: (): ResolvedPolicyPaths => ({
|
||||
globalConfigPath: "/in-memory/config.json",
|
||||
globalConfigExists: true,
|
||||
projectConfigPath: null,
|
||||
projectConfigExists: false,
|
||||
agentsDir: "/in-memory/agents",
|
||||
agentsDirExists: false,
|
||||
projectAgentsDir: null,
|
||||
@@ -185,7 +181,6 @@ export function createManagerWithProject(
|
||||
const manager = new PermissionManager({
|
||||
globalConfigPath,
|
||||
agentsDir,
|
||||
projectGlobalConfigPath,
|
||||
projectAgentsDir,
|
||||
mcpServerNames: options.mcpServerNames,
|
||||
});
|
||||
@@ -245,7 +240,13 @@ export function createAgentDirHarness(opts: {
|
||||
JSON.stringify({ permission: opts.globalPermission }, null, 2),
|
||||
);
|
||||
|
||||
const projectConfigPath = getProjectConfigPath(cwd);
|
||||
const projectConfigPath = join(
|
||||
cwd,
|
||||
".pi",
|
||||
"extensions",
|
||||
"pi-permission-system",
|
||||
"policy.jsonc",
|
||||
);
|
||||
mkdirSync(join(cwd, ".pi", "extensions", "pi-permission-system"), {
|
||||
recursive: true,
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user