@compilr-dev/agents 0.5.6 → 0.5.7
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/dist/index.d.ts +1 -1
- package/dist/permissions/index.d.ts +1 -1
- package/dist/permissions/manager.js +15 -10
- package/dist/permissions/types.d.ts +31 -4
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -52,7 +52,7 @@ export type { Guardrail, GuardrailInput, GuardrailAction, GuardrailResult, Guard
|
|
|
52
52
|
export { MCPClient, MCPManager, mcpToolToTool, mcpToolsToTools, convertMCPResult, contentBlocksToString, generateToolName, normalizeServerConfig, MCPError, MCPErrorCode, isMCPError, createSDKNotInstalledError, } from './mcp/index.js';
|
|
53
53
|
export type { MCPTransport, MCPConnectionStatus, MCPStdioOptions, MCPHttpOptions, MCPClientConfig, MCPServerConfig, MCPToolDefinition, MCPContentBlock, MCPToolResult, MCPClientEventType, MCPClientEvent, MCPClientEventHandler, MCPManagerOptions, MCPToolConversionOptions, } from './mcp/index.js';
|
|
54
54
|
export { PermissionManager } from './permissions/index.js';
|
|
55
|
-
export type { PermissionLevel, ToolPermission, PermissionRequest, PermissionCheckResult, PermissionHandler, PreviewGenerator, PermissionManagerOptions, PermissionEventType, PermissionEvent, PermissionEventHandler, } from './permissions/index.js';
|
|
55
|
+
export type { PermissionLevel, ToolPermission, PermissionRequest, PermissionCheckResult, PermissionHandler, PermissionHandlerResponse, PreviewGenerator, PermissionManagerOptions, PermissionEventType, PermissionEvent, PermissionEventHandler, } from './permissions/index.js';
|
|
56
56
|
export { ProjectMemoryLoader, createProjectMemoryLoader, loadProjectMemory, hasProjectMemory, getProviderPatterns, getSupportedProviders, getGenericPatterns, PROVIDER_PATTERNS, GENERIC_PATTERNS, } from './memory/index.js';
|
|
57
57
|
export type { LLMProviderName, MemoryFile, ProjectMemory, FilePattern, CombineStrategy, ProjectMemoryOptions, ProjectMemoryEventType, ProjectMemoryEvent, ProjectMemoryEventHandler, MemoryDiscoveryResult, ProviderPatterns, } from './memory/index.js';
|
|
58
58
|
export { UsageTracker, createUsageTracker } from './costs/index.js';
|
|
@@ -2,4 +2,4 @@
|
|
|
2
2
|
* Permissions module - Tool-level permission management
|
|
3
3
|
*/
|
|
4
4
|
export { PermissionManager } from './manager.js';
|
|
5
|
-
export type { PermissionLevel, ToolPermission, PermissionRequest, PermissionCheckResult, PermissionHandler, PreviewGenerator, PermissionManagerOptions, PermissionEventType, PermissionEvent, PermissionEventHandler, } from './types.js';
|
|
5
|
+
export type { PermissionLevel, ToolPermission, PermissionRequest, PermissionCheckResult, PermissionHandler, PermissionHandlerResponse, PreviewGenerator, PermissionManagerOptions, PermissionEventType, PermissionEvent, PermissionEventHandler, } from './types.js';
|
|
@@ -226,8 +226,8 @@ export class PermissionManager {
|
|
|
226
226
|
return { allowed: true, level, askedUser: false, rule };
|
|
227
227
|
}
|
|
228
228
|
// Ask for permission
|
|
229
|
-
const
|
|
230
|
-
if (allowed) {
|
|
229
|
+
const askResult = await this.askPermission(toolName, input, level, rule);
|
|
230
|
+
if (askResult.allowed) {
|
|
231
231
|
this.sessionGrants.add(toolName);
|
|
232
232
|
this.emit({ type: 'permission:session_granted', toolName, level, input, rule });
|
|
233
233
|
}
|
|
@@ -235,11 +235,11 @@ export class PermissionManager {
|
|
|
235
235
|
this.emit({ type: 'permission:denied', toolName, level, input, rule });
|
|
236
236
|
}
|
|
237
237
|
return {
|
|
238
|
-
allowed,
|
|
238
|
+
allowed: askResult.allowed,
|
|
239
239
|
level,
|
|
240
240
|
askedUser: true,
|
|
241
241
|
rule,
|
|
242
|
-
reason: allowed ? undefined : 'User denied permission',
|
|
242
|
+
reason: askResult.allowed ? undefined : (askResult.reason ?? 'User denied permission'),
|
|
243
243
|
};
|
|
244
244
|
}
|
|
245
245
|
case 'once': {
|
|
@@ -249,19 +249,19 @@ export class PermissionManager {
|
|
|
249
249
|
return { allowed: true, level, askedUser: false, rule };
|
|
250
250
|
}
|
|
251
251
|
// Ask for permission each time (unless session-granted above)
|
|
252
|
-
const
|
|
253
|
-
if (allowed) {
|
|
252
|
+
const askResult = await this.askPermission(toolName, input, level, rule);
|
|
253
|
+
if (askResult.allowed) {
|
|
254
254
|
this.emit({ type: 'permission:granted', toolName, level, input, rule });
|
|
255
255
|
}
|
|
256
256
|
else {
|
|
257
257
|
this.emit({ type: 'permission:denied', toolName, level, input, rule });
|
|
258
258
|
}
|
|
259
259
|
return {
|
|
260
|
-
allowed,
|
|
260
|
+
allowed: askResult.allowed,
|
|
261
261
|
level,
|
|
262
262
|
askedUser: true,
|
|
263
263
|
rule,
|
|
264
|
-
reason: allowed ? undefined : 'User denied permission',
|
|
264
|
+
reason: askResult.allowed ? undefined : (askResult.reason ?? 'User denied permission'),
|
|
265
265
|
};
|
|
266
266
|
}
|
|
267
267
|
}
|
|
@@ -281,7 +281,7 @@ export class PermissionManager {
|
|
|
281
281
|
async askPermission(toolName, input, level, rule) {
|
|
282
282
|
// If no handler, default to allow
|
|
283
283
|
if (!this.handler) {
|
|
284
|
-
return true;
|
|
284
|
+
return { allowed: true };
|
|
285
285
|
}
|
|
286
286
|
const preview = this.previewGenerator(toolName, input);
|
|
287
287
|
const request = {
|
|
@@ -292,7 +292,12 @@ export class PermissionManager {
|
|
|
292
292
|
preview,
|
|
293
293
|
};
|
|
294
294
|
this.emit({ type: 'permission:asked', toolName, level, input, rule });
|
|
295
|
-
|
|
295
|
+
const response = await this.handler(request);
|
|
296
|
+
// Normalize legacy boolean responses (backward compat)
|
|
297
|
+
if (typeof response === 'boolean') {
|
|
298
|
+
return { allowed: response };
|
|
299
|
+
}
|
|
300
|
+
return response;
|
|
296
301
|
}
|
|
297
302
|
/**
|
|
298
303
|
* Grant session-level permission for a tool
|
|
@@ -84,25 +84,52 @@ export interface PermissionCheckResult {
|
|
|
84
84
|
*/
|
|
85
85
|
reason?: string;
|
|
86
86
|
}
|
|
87
|
+
/**
|
|
88
|
+
* Response shape from a permission handler.
|
|
89
|
+
*
|
|
90
|
+
* Either a plain boolean (legacy — backward compatible) OR a structured
|
|
91
|
+
* object that can carry an optional reason. The reason is delivered to
|
|
92
|
+
* the agent inline with the tool's permission-denied error so the agent
|
|
93
|
+
* sees the user's context immediately, in the same turn.
|
|
94
|
+
*
|
|
95
|
+
* @example
|
|
96
|
+
* ```typescript
|
|
97
|
+
* // Legacy (still supported):
|
|
98
|
+
* return true;
|
|
99
|
+
* return false;
|
|
100
|
+
*
|
|
101
|
+
* // With reason:
|
|
102
|
+
* return { allowed: false, reason: 'Use project_document_add instead' };
|
|
103
|
+
* return { allowed: true };
|
|
104
|
+
* ```
|
|
105
|
+
*/
|
|
106
|
+
export type PermissionHandlerResponse = boolean | {
|
|
107
|
+
allowed: boolean;
|
|
108
|
+
reason?: string;
|
|
109
|
+
};
|
|
87
110
|
/**
|
|
88
111
|
* Handler called when permission is needed
|
|
89
112
|
*
|
|
90
113
|
* @param request - Information about the permission request
|
|
91
|
-
* @returns true to allow
|
|
114
|
+
* @returns true to allow / false to deny — or { allowed, reason? } to
|
|
115
|
+
* carry context (especially useful when denying with a message)
|
|
92
116
|
*
|
|
93
117
|
* @example
|
|
94
118
|
* ```typescript
|
|
95
119
|
* const handler: PermissionHandler = async (request) => {
|
|
96
120
|
* // Show UI prompt to user
|
|
97
|
-
* const
|
|
121
|
+
* const result = await showConfirmDialog(
|
|
98
122
|
* `Allow ${request.toolName}?`,
|
|
99
123
|
* request.description
|
|
100
124
|
* );
|
|
101
|
-
*
|
|
125
|
+
* if (!result.allowed && result.message) {
|
|
126
|
+
* return { allowed: false, reason: result.message };
|
|
127
|
+
* }
|
|
128
|
+
* return result.allowed;
|
|
102
129
|
* };
|
|
103
130
|
* ```
|
|
104
131
|
*/
|
|
105
|
-
export type PermissionHandler = (request: PermissionRequest) =>
|
|
132
|
+
export type PermissionHandler = (request: PermissionRequest) => PermissionHandlerResponse | Promise<PermissionHandlerResponse>;
|
|
106
133
|
/**
|
|
107
134
|
* Preview generator for permission requests
|
|
108
135
|
*
|