@gotgenes/pi-permission-system 10.2.0 → 10.3.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +14 -0
- package/package.json +1 -1
- package/src/config-modal.ts +7 -10
- package/src/config-store.ts +227 -0
- package/src/index.ts +65 -38
- package/src/permission-prompter.ts +3 -3
- package/src/permission-session.ts +10 -14
- package/src/permissions-service.ts +3 -5
- package/src/session-logger.ts +46 -9
- package/test/composition-root.test.ts +85 -1
- package/test/config-modal.test.ts +15 -10
- package/test/config-store.test.ts +428 -0
- package/test/permission-prompter.test.ts +12 -5
- package/test/permission-session.test.ts +57 -26
- package/test/session-logger.test.ts +151 -64
- package/src/runtime.ts +0 -280
- package/test/runtime.test.ts +0 -487
package/CHANGELOG.md
CHANGED
|
@@ -5,6 +5,20 @@ All notable changes to this project will be documented in this file.
|
|
|
5
5
|
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/),
|
|
6
6
|
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
|
7
7
|
|
|
8
|
+
## [10.3.1](https://github.com/gotgenes/pi-packages/compare/pi-permission-system-v10.3.0...pi-permission-system-v10.3.1) (2026-06-06)
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
### Bug Fixes
|
|
12
|
+
|
|
13
|
+
* share one PermissionManager and SessionRules across gate and RPC paths ([#337](https://github.com/gotgenes/pi-packages/issues/337)) ([7dd1e65](https://github.com/gotgenes/pi-packages/commit/7dd1e65493fa0061a3b84eb329457f939b953e0a))
|
|
14
|
+
|
|
15
|
+
## [10.3.0](https://github.com/gotgenes/pi-packages/compare/pi-permission-system-v10.2.0...pi-permission-system-v10.3.0) (2026-06-05)
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
### Features
|
|
19
|
+
|
|
20
|
+
* add ConfigStore owning extension config state ([5941733](https://github.com/gotgenes/pi-packages/commit/5941733a67c0ad9aef3d3b2e5908a82e76ac8603))
|
|
21
|
+
|
|
8
22
|
## [10.2.0](https://github.com/gotgenes/pi-packages/compare/pi-permission-system-v10.1.0...pi-permission-system-v10.2.0) (2026-06-04)
|
|
9
23
|
|
|
10
24
|
|
package/package.json
CHANGED
package/src/config-modal.ts
CHANGED
|
@@ -5,6 +5,7 @@ import {
|
|
|
5
5
|
} from "@earendil-works/pi-coding-agent";
|
|
6
6
|
import { type SettingItem, SettingsList } from "@earendil-works/pi-tui";
|
|
7
7
|
|
|
8
|
+
import type { CommandConfigStore } from "./config-store";
|
|
8
9
|
import {
|
|
9
10
|
DEFAULT_EXTENSION_CONFIG,
|
|
10
11
|
type PermissionSystemExtensionConfig,
|
|
@@ -12,11 +13,7 @@ import {
|
|
|
12
13
|
import type { Ruleset } from "./rule";
|
|
13
14
|
|
|
14
15
|
interface PermissionSystemConfigController {
|
|
15
|
-
|
|
16
|
-
setConfig(
|
|
17
|
-
next: PermissionSystemExtensionConfig,
|
|
18
|
-
ctx: ExtensionCommandContext,
|
|
19
|
-
): void;
|
|
16
|
+
config: CommandConfigStore;
|
|
20
17
|
getConfigPath(): string;
|
|
21
18
|
/** Optional: returns the composed config-layer ruleset for origin display. */
|
|
22
19
|
getComposedRules?(): Ruleset;
|
|
@@ -175,15 +172,15 @@ async function openSettingsModal(
|
|
|
175
172
|
// eslint-disable-next-line @typescript-eslint/no-invalid-void-type -- ctx.ui.custom<void> is valid; rule does not allow void in generic fn call type args
|
|
176
173
|
await ctx.ui.custom<void>(
|
|
177
174
|
(_tui, _theme, _keybindings, done) => {
|
|
178
|
-
let current = controller.
|
|
175
|
+
let current = controller.config.current();
|
|
179
176
|
const settingsList = new SettingsList(
|
|
180
177
|
buildSettingItems(current),
|
|
181
178
|
10,
|
|
182
179
|
getSettingsListTheme(),
|
|
183
180
|
(id, newValue) => {
|
|
184
181
|
current = applySetting(current, id, newValue);
|
|
185
|
-
controller.
|
|
186
|
-
current = controller.
|
|
182
|
+
controller.config.save(current, ctx);
|
|
183
|
+
current = controller.config.current();
|
|
187
184
|
syncSettingValues(settingsList, current);
|
|
188
185
|
},
|
|
189
186
|
() => done(),
|
|
@@ -208,7 +205,7 @@ function handleArgs(
|
|
|
208
205
|
if (normalized === "show") {
|
|
209
206
|
const rules = controller.getComposedRules?.();
|
|
210
207
|
ctx.ui.notify(
|
|
211
|
-
`permission-system: ${summarizeConfig(controller.
|
|
208
|
+
`permission-system: ${summarizeConfig(controller.config.current(), rules)}`,
|
|
212
209
|
"info",
|
|
213
210
|
);
|
|
214
211
|
return true;
|
|
@@ -223,7 +220,7 @@ function handleArgs(
|
|
|
223
220
|
}
|
|
224
221
|
|
|
225
222
|
if (normalized === "reset") {
|
|
226
|
-
controller.
|
|
223
|
+
controller.config.save(cloneDefaultConfig(), ctx);
|
|
227
224
|
ctx.ui.notify("Permission system settings reset to defaults.", "info");
|
|
228
225
|
return true;
|
|
229
226
|
}
|
|
@@ -0,0 +1,227 @@
|
|
|
1
|
+
import {
|
|
2
|
+
existsSync,
|
|
3
|
+
mkdirSync,
|
|
4
|
+
renameSync,
|
|
5
|
+
unlinkSync,
|
|
6
|
+
writeFileSync,
|
|
7
|
+
} from "node:fs";
|
|
8
|
+
import { dirname, normalize } from "node:path";
|
|
9
|
+
import type {
|
|
10
|
+
ExtensionCommandContext,
|
|
11
|
+
ExtensionContext,
|
|
12
|
+
} from "@earendil-works/pi-coding-agent";
|
|
13
|
+
|
|
14
|
+
import { loadAndMergeConfigs, loadUnifiedConfig } from "./config-loader";
|
|
15
|
+
import {
|
|
16
|
+
getGlobalConfigPath,
|
|
17
|
+
getLegacyExtensionConfigPath,
|
|
18
|
+
getLegacyGlobalPolicyPath,
|
|
19
|
+
getLegacyProjectPolicyPath,
|
|
20
|
+
} from "./config-paths";
|
|
21
|
+
import { buildResolvedConfigLogEntry } from "./config-reporter";
|
|
22
|
+
import {
|
|
23
|
+
DEFAULT_EXTENSION_CONFIG,
|
|
24
|
+
EXTENSION_ROOT,
|
|
25
|
+
normalizePermissionSystemConfig,
|
|
26
|
+
type PermissionSystemExtensionConfig,
|
|
27
|
+
} from "./extension-config";
|
|
28
|
+
import type { ResolvedPolicyPaths } from "./policy-loader";
|
|
29
|
+
import { syncPermissionSystemStatus } from "./status";
|
|
30
|
+
|
|
31
|
+
/** Read-only view of the current config — for consumers that only read. */
|
|
32
|
+
export interface ConfigReader {
|
|
33
|
+
current(): PermissionSystemExtensionConfig;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
/**
|
|
37
|
+
* Narrow subset of `ConfigStore` that `PermissionSession` depends on.
|
|
38
|
+
*
|
|
39
|
+
* Using an interface rather than the concrete class avoids private-member
|
|
40
|
+
* coupling between the class and test doubles.
|
|
41
|
+
*/
|
|
42
|
+
export interface SessionConfigStore extends ConfigReader {
|
|
43
|
+
refresh(ctx?: ExtensionContext): void;
|
|
44
|
+
logResolvedPaths(cwd?: string): void;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
/**
|
|
48
|
+
* Narrow subset of `ConfigStore` for the `/permission-system` command.
|
|
49
|
+
*
|
|
50
|
+
* Using an interface rather than the concrete class avoids private-member
|
|
51
|
+
* coupling between the class and test doubles.
|
|
52
|
+
*/
|
|
53
|
+
export interface CommandConfigStore extends ConfigReader {
|
|
54
|
+
save(
|
|
55
|
+
next: PermissionSystemExtensionConfig,
|
|
56
|
+
ctx: ExtensionCommandContext,
|
|
57
|
+
): void;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
/** Narrow logging sink — replaced by an injected logger in Step 3 (#336). */
|
|
61
|
+
export interface ConfigStoreLogger {
|
|
62
|
+
writeDebugLog(event: string, details?: Record<string, unknown>): void;
|
|
63
|
+
writeReviewLog(event: string, details?: Record<string, unknown>): void;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
/** Narrow view of the manager's resolved policy paths (for `logResolvedPaths`). */
|
|
67
|
+
export interface ResolvedPolicyPathProvider {
|
|
68
|
+
getResolvedPolicyPaths(): ResolvedPolicyPaths;
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
export interface ConfigStoreDeps {
|
|
72
|
+
agentDir: string;
|
|
73
|
+
policyPaths: ResolvedPolicyPathProvider;
|
|
74
|
+
logger: ConfigStoreLogger;
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
/**
|
|
78
|
+
* Owns the mutable extension config and the operations that read/write it.
|
|
79
|
+
*
|
|
80
|
+
* Replaces the three `(runtime, …)` config free functions
|
|
81
|
+
* (`refreshExtensionConfig`, `saveExtensionConfig`, `logResolvedConfigPaths`)
|
|
82
|
+
* with methods that privately own `config` and `lastConfigWarning`.
|
|
83
|
+
*
|
|
84
|
+
* Implements {@link ConfigReader} so consumers that only read the current config
|
|
85
|
+
* can depend on the narrow interface rather than the full class.
|
|
86
|
+
*/
|
|
87
|
+
export class ConfigStore implements SessionConfigStore, CommandConfigStore {
|
|
88
|
+
private config: PermissionSystemExtensionConfig;
|
|
89
|
+
private lastConfigWarning: string | null = null;
|
|
90
|
+
|
|
91
|
+
constructor(private readonly deps: ConfigStoreDeps) {
|
|
92
|
+
this.config = { ...DEFAULT_EXTENSION_CONFIG };
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
/** Return the current extension config. */
|
|
96
|
+
current(): PermissionSystemExtensionConfig {
|
|
97
|
+
return this.config;
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
/**
|
|
101
|
+
* Reload merged config from disk.
|
|
102
|
+
*
|
|
103
|
+
* If `ctx` is provided, uses it to derive the cwd and sync UI status.
|
|
104
|
+
* Equivalent to `refreshExtensionConfig(runtime, ctx?)`.
|
|
105
|
+
*/
|
|
106
|
+
refresh(ctx?: ExtensionContext): void {
|
|
107
|
+
const cwd = ctx?.cwd ?? null;
|
|
108
|
+
const mergeResult = loadAndMergeConfigs(
|
|
109
|
+
this.deps.agentDir,
|
|
110
|
+
cwd ?? "",
|
|
111
|
+
EXTENSION_ROOT,
|
|
112
|
+
);
|
|
113
|
+
const runtimeConfig = normalizePermissionSystemConfig(mergeResult.merged);
|
|
114
|
+
this.config = runtimeConfig;
|
|
115
|
+
|
|
116
|
+
if (ctx?.hasUI) {
|
|
117
|
+
syncPermissionSystemStatus(ctx, runtimeConfig);
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
const warning =
|
|
121
|
+
mergeResult.issues.length > 0 ? mergeResult.issues.join("\n") : undefined;
|
|
122
|
+
|
|
123
|
+
if (warning && warning !== this.lastConfigWarning) {
|
|
124
|
+
this.lastConfigWarning = warning;
|
|
125
|
+
ctx?.ui.notify(warning, "warning");
|
|
126
|
+
} else if (!warning) {
|
|
127
|
+
this.lastConfigWarning = null;
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
this.deps.logger.writeDebugLog("config.loaded", {
|
|
131
|
+
warning: warning ?? null,
|
|
132
|
+
debugLog: runtimeConfig.debugLog,
|
|
133
|
+
permissionReviewLog: runtimeConfig.permissionReviewLog,
|
|
134
|
+
yoloMode: runtimeConfig.yoloMode,
|
|
135
|
+
});
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
/**
|
|
139
|
+
* Save updated runtime knobs to the global config file, then update
|
|
140
|
+
* the current config and sync UI status.
|
|
141
|
+
*
|
|
142
|
+
* Equivalent to `saveExtensionConfig(runtime, next, ctx)`.
|
|
143
|
+
*/
|
|
144
|
+
// Called via the CommandConfigStore interface from config-modal.ts — fallow cannot trace through interfaces.
|
|
145
|
+
// fallow-ignore-next-line unused-class-member
|
|
146
|
+
save(
|
|
147
|
+
next: PermissionSystemExtensionConfig,
|
|
148
|
+
ctx: ExtensionCommandContext,
|
|
149
|
+
): void {
|
|
150
|
+
const normalized = normalizePermissionSystemConfig(next);
|
|
151
|
+
const globalPath = getGlobalConfigPath(this.deps.agentDir);
|
|
152
|
+
|
|
153
|
+
const existing = loadUnifiedConfig(globalPath);
|
|
154
|
+
const merged = {
|
|
155
|
+
...existing.config,
|
|
156
|
+
debugLog: normalized.debugLog,
|
|
157
|
+
permissionReviewLog: normalized.permissionReviewLog,
|
|
158
|
+
yoloMode: normalized.yoloMode,
|
|
159
|
+
};
|
|
160
|
+
|
|
161
|
+
const tmpPath = `${globalPath}.tmp`;
|
|
162
|
+
try {
|
|
163
|
+
mkdirSync(dirname(globalPath), { recursive: true });
|
|
164
|
+
writeFileSync(tmpPath, `${JSON.stringify(merged, null, 2)}\n`, "utf-8");
|
|
165
|
+
renameSync(tmpPath, globalPath);
|
|
166
|
+
} catch (error) {
|
|
167
|
+
try {
|
|
168
|
+
if (existsSync(tmpPath)) {
|
|
169
|
+
unlinkSync(tmpPath);
|
|
170
|
+
}
|
|
171
|
+
} catch {
|
|
172
|
+
// Ignore cleanup failures.
|
|
173
|
+
}
|
|
174
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
175
|
+
ctx.ui.notify(
|
|
176
|
+
`Failed to save permission-system config at '${globalPath}': ${message}`,
|
|
177
|
+
"error",
|
|
178
|
+
);
|
|
179
|
+
return;
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
this.config = normalized;
|
|
183
|
+
syncPermissionSystemStatus(ctx, normalized);
|
|
184
|
+
this.lastConfigWarning = null;
|
|
185
|
+
|
|
186
|
+
this.deps.logger.writeDebugLog("config.saved", {
|
|
187
|
+
debugLog: normalized.debugLog,
|
|
188
|
+
permissionReviewLog: normalized.permissionReviewLog,
|
|
189
|
+
yoloMode: normalized.yoloMode,
|
|
190
|
+
});
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
/**
|
|
194
|
+
* Write the resolved config path set to the review and debug logs.
|
|
195
|
+
*
|
|
196
|
+
* Equivalent to `logResolvedConfigPaths(runtime)`.
|
|
197
|
+
*/
|
|
198
|
+
logResolvedPaths(cwd?: string): void {
|
|
199
|
+
const policyPaths = this.deps.policyPaths.getResolvedPolicyPaths();
|
|
200
|
+
const { agentDir } = this.deps;
|
|
201
|
+
const legacyGlobalPolicyDetected = existsSync(
|
|
202
|
+
getLegacyGlobalPolicyPath(agentDir),
|
|
203
|
+
);
|
|
204
|
+
const legacyProjectPolicyDetected = cwd
|
|
205
|
+
? existsSync(getLegacyProjectPolicyPath(cwd))
|
|
206
|
+
: false;
|
|
207
|
+
const legacyExtConfigPath = getLegacyExtensionConfigPath(EXTENSION_ROOT);
|
|
208
|
+
const newGlobalPath = getGlobalConfigPath(agentDir);
|
|
209
|
+
const legacyExtensionConfigDetected =
|
|
210
|
+
normalize(legacyExtConfigPath) !== normalize(newGlobalPath) &&
|
|
211
|
+
existsSync(legacyExtConfigPath);
|
|
212
|
+
const entry = buildResolvedConfigLogEntry({
|
|
213
|
+
policyPaths,
|
|
214
|
+
legacyGlobalPolicyDetected,
|
|
215
|
+
legacyProjectPolicyDetected,
|
|
216
|
+
legacyExtensionConfigDetected,
|
|
217
|
+
});
|
|
218
|
+
this.deps.logger.writeReviewLog(
|
|
219
|
+
"config.resolved",
|
|
220
|
+
entry as unknown as Record<string, unknown>,
|
|
221
|
+
);
|
|
222
|
+
this.deps.logger.writeDebugLog(
|
|
223
|
+
"config.resolved",
|
|
224
|
+
entry as unknown as Record<string, unknown>,
|
|
225
|
+
);
|
|
226
|
+
}
|
|
227
|
+
}
|
package/src/index.ts
CHANGED
|
@@ -1,8 +1,11 @@
|
|
|
1
1
|
import type { ExtensionAPI } from "@earendil-works/pi-coding-agent";
|
|
2
|
+
import { getAgentDir } from "@earendil-works/pi-coding-agent";
|
|
2
3
|
import { registerBuiltinToolInputFormatters } from "./builtin-tool-input-formatters";
|
|
3
4
|
import { registerPermissionSystemCommand } from "./config-modal";
|
|
4
5
|
import { getGlobalConfigPath } from "./config-paths";
|
|
6
|
+
import { ConfigStore } from "./config-store";
|
|
5
7
|
import { GateDecisionReporter } from "./decision-reporter";
|
|
8
|
+
import { computeExtensionPaths } from "./extension-paths";
|
|
6
9
|
import {
|
|
7
10
|
PermissionForwarder,
|
|
8
11
|
type PermissionForwarderDeps,
|
|
@@ -22,14 +25,9 @@ import { PermissionManager } from "./permission-manager";
|
|
|
22
25
|
import { PermissionPrompter } from "./permission-prompter";
|
|
23
26
|
import { PermissionSession } from "./permission-session";
|
|
24
27
|
import { LocalPermissionsService } from "./permissions-service";
|
|
25
|
-
import {
|
|
26
|
-
createExtensionRuntime,
|
|
27
|
-
logResolvedConfigPaths,
|
|
28
|
-
refreshExtensionConfig,
|
|
29
|
-
saveExtensionConfig,
|
|
30
|
-
} from "./runtime";
|
|
31
28
|
import { PermissionServiceLifecycle } from "./service-lifecycle";
|
|
32
29
|
import { createSessionLogger } from "./session-logger";
|
|
30
|
+
import { SessionRules } from "./session-rules";
|
|
33
31
|
import { isSubagentExecutionContext } from "./subagent-context";
|
|
34
32
|
import { subscribeSubagentLifecycle } from "./subagent-lifecycle-events";
|
|
35
33
|
import { getSubagentSessionRegistry } from "./subagent-registry";
|
|
@@ -40,58 +38,85 @@ import {
|
|
|
40
38
|
} from "./yolo-mode";
|
|
41
39
|
|
|
42
40
|
export default function piPermissionSystemExtension(pi: ExtensionAPI): void {
|
|
43
|
-
const
|
|
41
|
+
const agentDir = getAgentDir();
|
|
42
|
+
const paths = computeExtensionPaths(agentDir);
|
|
43
|
+
const permissionManager = new PermissionManager({ agentDir });
|
|
44
|
+
const sessionRules = new SessionRules();
|
|
44
45
|
const subagentRegistry = getSubagentSessionRegistry();
|
|
45
46
|
const formatterRegistry = new ToolInputFormatterRegistry();
|
|
46
47
|
registerBuiltinToolInputFormatters(formatterRegistry);
|
|
47
48
|
|
|
49
|
+
// Forward reference: configStore is declared before the logger so the
|
|
50
|
+
// logger's getConfig thunk can close over the variable; assigned immediately
|
|
51
|
+
// after. Typed via cast so the closure compiles without assertions.
|
|
52
|
+
// The same null-at-init pattern used in the former createExtensionRuntime.
|
|
53
|
+
let configStore = null as unknown as ConfigStore;
|
|
54
|
+
|
|
55
|
+
// sessionNotify is a mutable holder so the logger's notify closure can
|
|
56
|
+
// reach the UI once PermissionSession is constructed. Starts as null;
|
|
57
|
+
// notify is a best-effort sink (no-op at factory-init when there is no UI).
|
|
58
|
+
let sessionNotify: PermissionSession | null = null;
|
|
59
|
+
|
|
60
|
+
const logger = createSessionLogger({
|
|
61
|
+
globalLogsDir: paths.globalLogsDir,
|
|
62
|
+
getConfig: () => configStore.current(),
|
|
63
|
+
notify: (message) =>
|
|
64
|
+
sessionNotify?.getRuntimeContext()?.ui.notify(message, "warning"),
|
|
65
|
+
});
|
|
66
|
+
|
|
67
|
+
configStore = new ConfigStore({
|
|
68
|
+
agentDir,
|
|
69
|
+
policyPaths: permissionManager,
|
|
70
|
+
logger: {
|
|
71
|
+
writeDebugLog: (e, d) => logger.debug(e, d),
|
|
72
|
+
writeReviewLog: (e, d) => logger.review(e, d),
|
|
73
|
+
},
|
|
74
|
+
});
|
|
75
|
+
|
|
48
76
|
const forwardingDeps: PermissionForwarderDeps = {
|
|
49
|
-
forwardingDir:
|
|
50
|
-
subagentSessionsDir:
|
|
77
|
+
forwardingDir: paths.forwardingDir,
|
|
78
|
+
subagentSessionsDir: paths.subagentSessionsDir,
|
|
51
79
|
registry: subagentRegistry,
|
|
52
80
|
events: pi.events,
|
|
53
81
|
logger: {
|
|
54
|
-
writeReviewLog:
|
|
55
|
-
writeDebugLog:
|
|
82
|
+
writeReviewLog: (event, details) => logger.review(event, details),
|
|
83
|
+
writeDebugLog: (event, details) => logger.debug(event, details),
|
|
56
84
|
},
|
|
57
|
-
writeReviewLog:
|
|
85
|
+
writeReviewLog: (event, details) => logger.review(event, details),
|
|
58
86
|
requestPermissionDecisionFromUi,
|
|
59
87
|
shouldAutoApprove: () =>
|
|
60
|
-
shouldAutoApprovePermissionState("ask",
|
|
88
|
+
shouldAutoApprovePermissionState("ask", configStore.current()),
|
|
61
89
|
};
|
|
62
90
|
const forwarder = new PermissionForwarder(forwardingDeps);
|
|
63
91
|
|
|
64
92
|
const prompter = new PermissionPrompter({
|
|
65
|
-
|
|
66
|
-
writeReviewLog:
|
|
93
|
+
config: configStore,
|
|
94
|
+
writeReviewLog: (event, details) => logger.review(event, details),
|
|
67
95
|
events: pi.events,
|
|
68
96
|
forwarder,
|
|
69
97
|
});
|
|
70
98
|
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
const sessionManager = new PermissionManager({ agentDir: runtime.agentDir });
|
|
99
|
+
configStore.refresh();
|
|
74
100
|
|
|
75
101
|
const session = new PermissionSession(
|
|
76
|
-
|
|
77
|
-
|
|
102
|
+
paths,
|
|
103
|
+
logger,
|
|
78
104
|
new ForwardingManager(
|
|
79
|
-
|
|
105
|
+
paths.subagentSessionsDir,
|
|
80
106
|
forwarder,
|
|
81
107
|
subagentRegistry,
|
|
82
108
|
),
|
|
83
|
-
|
|
109
|
+
permissionManager,
|
|
110
|
+
sessionRules,
|
|
111
|
+
configStore,
|
|
84
112
|
{
|
|
85
|
-
refreshExtensionConfig: (ctx) => refreshExtensionConfig(runtime, ctx),
|
|
86
|
-
logResolvedConfigPaths: () => logResolvedConfigPaths(runtime),
|
|
87
|
-
getConfig: () => runtime.config,
|
|
88
113
|
canRequestPermissionConfirmation: (ctx) =>
|
|
89
114
|
canResolveAskPermissionRequest({
|
|
90
|
-
config:
|
|
115
|
+
config: configStore.current(),
|
|
91
116
|
hasUI: ctx.hasUI,
|
|
92
117
|
isSubagent: isSubagentExecutionContext(
|
|
93
118
|
ctx,
|
|
94
|
-
|
|
119
|
+
paths.subagentSessionsDir,
|
|
95
120
|
subagentRegistry,
|
|
96
121
|
),
|
|
97
122
|
}),
|
|
@@ -99,27 +124,29 @@ export default function piPermissionSystemExtension(pi: ExtensionAPI): void {
|
|
|
99
124
|
},
|
|
100
125
|
);
|
|
101
126
|
|
|
127
|
+
// Connect the notify sink now that session is available.
|
|
128
|
+
sessionNotify = session;
|
|
129
|
+
|
|
102
130
|
registerPermissionSystemCommand(pi, {
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
getConfigPath: () => getGlobalConfigPath(runtime.agentDir),
|
|
131
|
+
config: configStore,
|
|
132
|
+
getConfigPath: () => getGlobalConfigPath(agentDir),
|
|
106
133
|
getComposedRules: () =>
|
|
107
|
-
|
|
108
|
-
|
|
134
|
+
permissionManager.getComposedConfigRules(
|
|
135
|
+
session.lastKnownActiveAgentName ?? undefined,
|
|
109
136
|
),
|
|
110
137
|
});
|
|
111
138
|
|
|
112
139
|
const rpcHandles = registerPermissionRpcHandlers(pi.events, {
|
|
113
|
-
getPermissionManager: () =>
|
|
114
|
-
getSessionRules: () =>
|
|
115
|
-
getRuntimeContext: () =>
|
|
140
|
+
getPermissionManager: () => permissionManager,
|
|
141
|
+
getSessionRules: () => sessionRules.getRuleset(),
|
|
142
|
+
getRuntimeContext: () => session.getRuntimeContext(),
|
|
116
143
|
requestPermissionDecisionFromUi,
|
|
117
|
-
writeReviewLog:
|
|
144
|
+
writeReviewLog: (event, details) => logger.review(event, details),
|
|
118
145
|
});
|
|
119
146
|
|
|
120
147
|
const permissionsService = new LocalPermissionsService(
|
|
121
|
-
|
|
122
|
-
|
|
148
|
+
permissionManager,
|
|
149
|
+
sessionRules,
|
|
123
150
|
formatterRegistry,
|
|
124
151
|
);
|
|
125
152
|
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { ExtensionContext } from "@earendil-works/pi-coding-agent";
|
|
2
|
-
import type {
|
|
2
|
+
import type { ConfigReader } from "./config-store";
|
|
3
3
|
import type { ApprovalRequester } from "./forwarded-permissions/permission-forwarder";
|
|
4
4
|
import type { PermissionPromptDecision } from "./permission-dialog";
|
|
5
5
|
import {
|
|
@@ -45,7 +45,7 @@ export interface PermissionPrompterApi {
|
|
|
45
45
|
*/
|
|
46
46
|
export interface PermissionPrompterDeps {
|
|
47
47
|
/** Read current config for yolo-mode check (called at prompt time). */
|
|
48
|
-
|
|
48
|
+
config: ConfigReader;
|
|
49
49
|
/** Write structured entries to the permission review log. */
|
|
50
50
|
writeReviewLog(event: string, details: Record<string, unknown>): void;
|
|
51
51
|
/** Event bus used for UI prompt broadcasts. */
|
|
@@ -72,7 +72,7 @@ export class PermissionPrompter implements PermissionPrompterApi {
|
|
|
72
72
|
ctx: ExtensionContext,
|
|
73
73
|
details: PromptPermissionDetails,
|
|
74
74
|
): Promise<PermissionPromptDecision> {
|
|
75
|
-
if (shouldAutoApprovePermissionState("ask", this.deps.
|
|
75
|
+
if (shouldAutoApprovePermissionState("ask", this.deps.config.current())) {
|
|
76
76
|
this.writeReviewEntry("permission_request.auto_approved", details);
|
|
77
77
|
return { approved: true, state: "approved", autoApproved: true };
|
|
78
78
|
}
|
|
@@ -5,6 +5,7 @@ import {
|
|
|
5
5
|
getActiveAgentNameFromSystemPrompt,
|
|
6
6
|
} from "./active-agent";
|
|
7
7
|
import type { AgentPrepSession } from "./agent-prep-session";
|
|
8
|
+
import type { SessionConfigStore } from "./config-store";
|
|
8
9
|
import type { PermissionSystemExtensionConfig } from "./extension-config";
|
|
9
10
|
import type { ExtensionPaths } from "./extension-paths";
|
|
10
11
|
import type { ForwardingController } from "./forwarding-manager";
|
|
@@ -19,7 +20,7 @@ import type { SessionApproval } from "./session-approval";
|
|
|
19
20
|
import type { SessionApprovalRecorder } from "./session-approval-recorder";
|
|
20
21
|
import type { SessionLifecycleSession } from "./session-lifecycle-session";
|
|
21
22
|
import type { SessionLogger } from "./session-logger";
|
|
22
|
-
import { SessionRules } from "./session-rules";
|
|
23
|
+
import type { SessionRules } from "./session-rules";
|
|
23
24
|
import type { SkillPromptEntry } from "./skill-prompt-sanitizer";
|
|
24
25
|
import {
|
|
25
26
|
resolveToolPreviewLimits,
|
|
@@ -30,16 +31,9 @@ import type { PermissionCheckResult, PermissionState } from "./types";
|
|
|
30
31
|
/**
|
|
31
32
|
* Runtime operations that `PermissionSession` delegates to but does not own.
|
|
32
33
|
*
|
|
33
|
-
* Injected at construction time from the composition root (`index.ts`)
|
|
34
|
-
* where the `ExtensionRuntime` is available.
|
|
34
|
+
* Injected at construction time from the composition root (`index.ts`).
|
|
35
35
|
*/
|
|
36
36
|
export interface PermissionSessionRuntimeDeps {
|
|
37
|
-
/** Reload merged config from disk; optionally update the stored runtime context. */
|
|
38
|
-
refreshExtensionConfig(ctx?: ExtensionContext): void;
|
|
39
|
-
/** Write the resolved config path set to the review and debug logs. */
|
|
40
|
-
logResolvedConfigPaths(): void;
|
|
41
|
-
/** Read current extension config (called at query time). */
|
|
42
|
-
getConfig(): PermissionSystemExtensionConfig;
|
|
43
37
|
/** Whether the current context can show an interactive permission prompt. */
|
|
44
38
|
canRequestPermissionConfirmation(ctx: ExtensionContext): boolean;
|
|
45
39
|
/** Prompt the user for a permission decision, log the outcome, and return it. */
|
|
@@ -61,7 +55,8 @@ export interface PermissionSessionRuntimeDeps {
|
|
|
61
55
|
* - `ExtensionPaths` — immutable path constants
|
|
62
56
|
* - `SessionLogger` — debug + review + warn
|
|
63
57
|
* - `ForwardingController` — polling lifecycle
|
|
64
|
-
* - `
|
|
58
|
+
* - `SessionConfigStore` — owns extension config; provides refresh, log, read
|
|
59
|
+
* - `PermissionSessionRuntimeDeps` — prompting + permission-confirmation bridge
|
|
65
60
|
*/
|
|
66
61
|
export class PermissionSession
|
|
67
62
|
implements
|
|
@@ -73,7 +68,6 @@ export class PermissionSession
|
|
|
73
68
|
SessionLifecycleSession
|
|
74
69
|
{
|
|
75
70
|
private context: ExtensionContext | null = null;
|
|
76
|
-
private readonly sessionRules = new SessionRules();
|
|
77
71
|
private skillEntries: SkillPromptEntry[] = [];
|
|
78
72
|
private knownAgentName: string | null = null;
|
|
79
73
|
private toolsCacheKey: string | null = null;
|
|
@@ -84,6 +78,8 @@ export class PermissionSession
|
|
|
84
78
|
readonly logger: SessionLogger,
|
|
85
79
|
private readonly forwarding: ForwardingController,
|
|
86
80
|
private readonly permissionManager: ScopedPermissionManager,
|
|
81
|
+
private readonly sessionRules: SessionRules,
|
|
82
|
+
private readonly configStore: SessionConfigStore,
|
|
87
83
|
private readonly runtimeDeps: PermissionSessionRuntimeDeps,
|
|
88
84
|
) {}
|
|
89
85
|
|
|
@@ -260,17 +256,17 @@ export class PermissionSession
|
|
|
260
256
|
|
|
261
257
|
/** Reload merged config from disk; optionally update the stored runtime context. */
|
|
262
258
|
refreshConfig(ctx?: ExtensionContext): void {
|
|
263
|
-
this.
|
|
259
|
+
this.configStore.refresh(ctx);
|
|
264
260
|
}
|
|
265
261
|
|
|
266
262
|
/** Write the resolved config path set to the review and debug logs. */
|
|
267
263
|
logResolvedConfigPaths(): void {
|
|
268
|
-
this.
|
|
264
|
+
this.configStore.logResolvedPaths(this.context?.cwd);
|
|
269
265
|
}
|
|
270
266
|
|
|
271
267
|
/** Read current extension config. */
|
|
272
268
|
get config(): PermissionSystemExtensionConfig {
|
|
273
|
-
return this.
|
|
269
|
+
return this.configStore.current();
|
|
274
270
|
}
|
|
275
271
|
|
|
276
272
|
// ── Infrastructure paths ───────────────────────────────────────────────
|
|
@@ -10,11 +10,9 @@ import type {
|
|
|
10
10
|
/**
|
|
11
11
|
* In-process implementation of the cross-extension {@link PermissionsService}.
|
|
12
12
|
*
|
|
13
|
-
* Constructed once in the composition root and backed by the
|
|
14
|
-
*
|
|
15
|
-
*
|
|
16
|
-
* reassigned on the runtime object (only `PermissionSession` reassigns its
|
|
17
|
-
* own internal copy), and `runtime.sessionRules` is `readonly`.
|
|
13
|
+
* Constructed once in the composition root and backed by the single shared
|
|
14
|
+
* `PermissionManager` and `SessionRules` instances that `PermissionSession`
|
|
15
|
+
* also uses — so service queries and gate-path approvals see the same state.
|
|
18
16
|
*/
|
|
19
17
|
export class LocalPermissionsService implements PermissionsService {
|
|
20
18
|
constructor(
|