@vybestack/llxprt-code-policy 0.10.0-nightly.260613.1adad3b34
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/.last_build +0 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +2 -0
- package/dist/index.js.map +1 -0
- package/dist/src/config.d.ts +25 -0
- package/dist/src/config.js +119 -0
- package/dist/src/config.js.map +1 -0
- package/dist/src/confirmation-bus/index.d.ts +2 -0
- package/dist/src/confirmation-bus/index.js +3 -0
- package/dist/src/confirmation-bus/index.js.map +1 -0
- package/dist/src/confirmation-bus/message-bus.d.ts +29 -0
- package/dist/src/confirmation-bus/message-bus.js +143 -0
- package/dist/src/confirmation-bus/message-bus.js.map +1 -0
- package/dist/src/confirmation-bus/types.d.ts +180 -0
- package/dist/src/confirmation-bus/types.js +37 -0
- package/dist/src/confirmation-bus/types.js.map +1 -0
- package/dist/src/index.d.ts +11 -0
- package/dist/src/index.js +8 -0
- package/dist/src/index.js.map +1 -0
- package/dist/src/policies/discovered.toml +9 -0
- package/dist/src/policies/read-only.toml +96 -0
- package/dist/src/policies/write.toml +101 -0
- package/dist/src/policies/yolo.toml +10 -0
- package/dist/src/policy-engine.d.ts +72 -0
- package/dist/src/policy-engine.js +236 -0
- package/dist/src/policy-engine.js.map +1 -0
- package/dist/src/stable-stringify.d.ts +29 -0
- package/dist/src/stable-stringify.js +137 -0
- package/dist/src/stable-stringify.js.map +1 -0
- package/dist/src/toml-loader.d.ts +48 -0
- package/dist/src/toml-loader.js +453 -0
- package/dist/src/toml-loader.js.map +1 -0
- package/dist/src/types.d.ts +80 -0
- package/dist/src/types.js +18 -0
- package/dist/src/types.js.map +1 -0
- package/dist/src/utils/shell-utils.d.ts +30 -0
- package/dist/src/utils/shell-utils.js +118 -0
- package/dist/src/utils/shell-utils.js.map +1 -0
- package/dist/src/utils.d.ts +26 -0
- package/dist/src/utils.js +68 -0
- package/dist/src/utils.js.map +1 -0
- package/package.json +52 -0
package/dist/.last_build
ADDED
|
File without changes
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './src/index.js';
|
package/dist/index.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../index.ts"],"names":[],"mappings":"AAAA,cAAc,gBAAgB,CAAC"}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* Copyright 2025 Vybestack LLC
|
|
4
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
5
|
+
*/
|
|
6
|
+
import { type ApprovalMode, type PolicyRule } from './types.js';
|
|
7
|
+
import type { PolicyFileError } from './toml-loader.js';
|
|
8
|
+
export declare const DEFAULT_CORE_POLICIES_DIR: string;
|
|
9
|
+
export declare const DEFAULT_POLICY_TIER = 1;
|
|
10
|
+
export declare const USER_POLICY_TIER = 2;
|
|
11
|
+
export declare const ADMIN_POLICY_TIER = 3;
|
|
12
|
+
export interface PolicyPathResolver {
|
|
13
|
+
getUserPoliciesDir: () => string;
|
|
14
|
+
getSystemPoliciesDir: () => string;
|
|
15
|
+
}
|
|
16
|
+
export interface PolicyConfigSource {
|
|
17
|
+
getApprovalMode: () => ApprovalMode;
|
|
18
|
+
getAllowedTools: () => string[] | undefined;
|
|
19
|
+
getNonInteractive: () => boolean;
|
|
20
|
+
getUserPolicyPath?: () => string | undefined;
|
|
21
|
+
}
|
|
22
|
+
export declare function getPolicyDirectories(defaultPoliciesDir?: string, pathResolver?: PolicyPathResolver): string[];
|
|
23
|
+
export declare function getPolicyTier(dir: string, defaultPoliciesDir?: string, pathResolver?: PolicyPathResolver): number;
|
|
24
|
+
export declare function formatPolicyError(error: PolicyFileError): string;
|
|
25
|
+
export declare function migrateLegacyApprovalMode(config: PolicyConfigSource): PolicyRule[];
|
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* Copyright 2025 Vybestack LLC
|
|
4
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
5
|
+
*/
|
|
6
|
+
import * as path from 'node:path';
|
|
7
|
+
import { fileURLToPath } from 'node:url';
|
|
8
|
+
import { PolicyDecision } from './types.js';
|
|
9
|
+
const __filename = fileURLToPath(import.meta.url);
|
|
10
|
+
const __dirname = path.dirname(__filename);
|
|
11
|
+
export const DEFAULT_CORE_POLICIES_DIR = path.join(__dirname, 'policies');
|
|
12
|
+
export const DEFAULT_POLICY_TIER = 1;
|
|
13
|
+
export const USER_POLICY_TIER = 2;
|
|
14
|
+
export const ADMIN_POLICY_TIER = 3;
|
|
15
|
+
const DEFAULT_POLICY_PATH_RESOLVER = {
|
|
16
|
+
getUserPoliciesDir: () => '',
|
|
17
|
+
getSystemPoliciesDir: () => '',
|
|
18
|
+
};
|
|
19
|
+
export function getPolicyDirectories(defaultPoliciesDir, pathResolver = DEFAULT_POLICY_PATH_RESOLVER) {
|
|
20
|
+
const dirs = [];
|
|
21
|
+
if (defaultPoliciesDir) {
|
|
22
|
+
dirs.push(defaultPoliciesDir);
|
|
23
|
+
}
|
|
24
|
+
else {
|
|
25
|
+
dirs.push(DEFAULT_CORE_POLICIES_DIR);
|
|
26
|
+
}
|
|
27
|
+
const userPoliciesDir = pathResolver.getUserPoliciesDir();
|
|
28
|
+
if (userPoliciesDir) {
|
|
29
|
+
dirs.push(userPoliciesDir);
|
|
30
|
+
}
|
|
31
|
+
const systemPoliciesDir = pathResolver.getSystemPoliciesDir();
|
|
32
|
+
if (systemPoliciesDir) {
|
|
33
|
+
dirs.push(systemPoliciesDir);
|
|
34
|
+
}
|
|
35
|
+
return dirs.reverse();
|
|
36
|
+
}
|
|
37
|
+
export function getPolicyTier(dir, defaultPoliciesDir, pathResolver = DEFAULT_POLICY_PATH_RESOLVER) {
|
|
38
|
+
const normalizedDir = path.resolve(dir);
|
|
39
|
+
const userPoliciesDir = pathResolver.getUserPoliciesDir();
|
|
40
|
+
const systemPoliciesDir = pathResolver.getSystemPoliciesDir();
|
|
41
|
+
if (defaultPoliciesDir &&
|
|
42
|
+
normalizedDir === path.resolve(defaultPoliciesDir)) {
|
|
43
|
+
return DEFAULT_POLICY_TIER;
|
|
44
|
+
}
|
|
45
|
+
if (normalizedDir === path.resolve(DEFAULT_CORE_POLICIES_DIR)) {
|
|
46
|
+
return DEFAULT_POLICY_TIER;
|
|
47
|
+
}
|
|
48
|
+
if (userPoliciesDir && normalizedDir === path.resolve(userPoliciesDir)) {
|
|
49
|
+
return USER_POLICY_TIER;
|
|
50
|
+
}
|
|
51
|
+
if (systemPoliciesDir && normalizedDir === path.resolve(systemPoliciesDir)) {
|
|
52
|
+
return ADMIN_POLICY_TIER;
|
|
53
|
+
}
|
|
54
|
+
return DEFAULT_POLICY_TIER;
|
|
55
|
+
}
|
|
56
|
+
export function formatPolicyError(error) {
|
|
57
|
+
const tierLabel = error.tier.toUpperCase();
|
|
58
|
+
let message = `[${tierLabel}] Policy file error in ${error.fileName}:
|
|
59
|
+
`;
|
|
60
|
+
message += ` ${error.message}`;
|
|
61
|
+
if (error.details) {
|
|
62
|
+
message += `
|
|
63
|
+
${error.details}`;
|
|
64
|
+
}
|
|
65
|
+
if (error.suggestion) {
|
|
66
|
+
message += `
|
|
67
|
+
Suggestion: ${error.suggestion}`;
|
|
68
|
+
}
|
|
69
|
+
return message;
|
|
70
|
+
}
|
|
71
|
+
function normalizeToolName(toolName) {
|
|
72
|
+
if (toolName === 'ShellTool' ||
|
|
73
|
+
toolName.startsWith('ShellTool(') ||
|
|
74
|
+
toolName.startsWith('run_shell_command(')) {
|
|
75
|
+
return 'run_shell_command';
|
|
76
|
+
}
|
|
77
|
+
return toolName;
|
|
78
|
+
}
|
|
79
|
+
const AUTO_EDIT_TOOLS = [
|
|
80
|
+
'replace',
|
|
81
|
+
'write_file',
|
|
82
|
+
'insert_at_line',
|
|
83
|
+
'delete_line_range',
|
|
84
|
+
'apply_patch',
|
|
85
|
+
];
|
|
86
|
+
export function migrateLegacyApprovalMode(config) {
|
|
87
|
+
const rules = [];
|
|
88
|
+
const approvalMode = config.getApprovalMode();
|
|
89
|
+
if (approvalMode === 'yolo') {
|
|
90
|
+
rules.push({
|
|
91
|
+
decision: PolicyDecision.ALLOW,
|
|
92
|
+
priority: 1.999,
|
|
93
|
+
source: 'Legacy (YOLO)',
|
|
94
|
+
});
|
|
95
|
+
}
|
|
96
|
+
if (approvalMode === 'autoEdit') {
|
|
97
|
+
for (const tool of AUTO_EDIT_TOOLS) {
|
|
98
|
+
rules.push({
|
|
99
|
+
toolName: tool,
|
|
100
|
+
decision: PolicyDecision.ALLOW,
|
|
101
|
+
priority: 1.015,
|
|
102
|
+
source: 'Legacy (AUTO_EDIT)',
|
|
103
|
+
});
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
const allowedTools = config.getAllowedTools();
|
|
107
|
+
if (allowedTools && allowedTools.length > 0) {
|
|
108
|
+
for (const tool of allowedTools) {
|
|
109
|
+
rules.push({
|
|
110
|
+
toolName: normalizeToolName(tool),
|
|
111
|
+
decision: PolicyDecision.ALLOW,
|
|
112
|
+
priority: 2.3,
|
|
113
|
+
source: 'Legacy (--allowed-tools)',
|
|
114
|
+
});
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
return rules;
|
|
118
|
+
}
|
|
119
|
+
//# sourceMappingURL=config.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"config.js","sourceRoot":"","sources":["../../src/config.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,KAAK,IAAI,MAAM,WAAW,CAAC;AAClC,OAAO,EAAE,aAAa,EAAE,MAAM,UAAU,CAAC;AACzC,OAAO,EAAsC,cAAc,EAAE,MAAM,YAAY,CAAC;AAGhF,MAAM,UAAU,GAAG,aAAa,CAAC,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;AAClD,MAAM,SAAS,GAAG,IAAI,CAAC,OAAO,CA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type PolicyLogger } from './message-bus.js';
|
|
2
|
+
export { MessageBusType, ConfirmationOutcome, type ConfirmationPayload, type PolicyFunctionCall, type PolicyToolCallState, type SerializableConfirmationDetails, type ToolCallsUpdateMessage, type ToolConfirmationRequest, type ToolConfirmationResponse, type ToolPolicyRejection, type ToolExecutionSuccess, type ToolExecutionFailure, type UpdatePolicy, type BucketAuthConfirmationRequest, type BucketAuthConfirmationResponse, type HookExecutionRequest, type HookExecutionResponse, type MessageBusMessage, ToolConfirmationOutcome, type ToolConfirmationPayload, } from './types.js';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/confirmation-bus/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAqB,MAAM,kBAAkB,CAAC;AACjE,OAAO,EACL,cAAc,EACd,mBAAmB,EAiBnB,uBAAuB,GAExB,MAAM,YAAY,CAAC"}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { PolicyEngine } from '../policy-engine.js';
|
|
2
|
+
import { ConfirmationOutcome, MessageBusType, type ConfirmationPayload, type MessageBusMessage, type PolicyFunctionCall } from './types.js';
|
|
3
|
+
type MessageHandler<T extends MessageBusMessage = MessageBusMessage> = (message: T) => void;
|
|
4
|
+
export interface PolicyLogger {
|
|
5
|
+
log: (message: string, ...args: unknown[]) => void;
|
|
6
|
+
warn?: (message: string, ...args: unknown[]) => void;
|
|
7
|
+
error?: (message: string, ...args: unknown[]) => void;
|
|
8
|
+
}
|
|
9
|
+
/**
|
|
10
|
+
* MessageBus provides event-driven communication for tool confirmations and policy decisions.
|
|
11
|
+
* Uses EventEmitter for pub/sub pattern and integrates with PolicyEngine for authorization.
|
|
12
|
+
*/
|
|
13
|
+
export declare class MessageBus {
|
|
14
|
+
private readonly emitter;
|
|
15
|
+
private readonly policyEngine;
|
|
16
|
+
private readonly debugMode;
|
|
17
|
+
private readonly logger?;
|
|
18
|
+
constructor(policyEngine?: PolicyEngine, debugMode?: boolean, logger?: PolicyLogger);
|
|
19
|
+
publish(message: MessageBusMessage): void;
|
|
20
|
+
subscribe<T extends MessageBusMessage>(type: MessageBusType, handler: MessageHandler<T>): () => void;
|
|
21
|
+
unsubscribe<T extends MessageBusMessage>(type: MessageBusType, handler: MessageHandler<T>): void;
|
|
22
|
+
requestConfirmation(toolCall: PolicyFunctionCall, args: Record<string, unknown>, serverName?: string): Promise<boolean>;
|
|
23
|
+
respondToConfirmation(correlationId: string, outcome: ConfirmationOutcome, payload?: ConfirmationPayload, requiresUserConfirmation?: boolean): void;
|
|
24
|
+
requestBucketAuthConfirmation(provider: string, bucket: string, bucketIndex: number, totalBuckets: number): Promise<boolean>;
|
|
25
|
+
respondToBucketAuthConfirmation(correlationId: string, confirmed: boolean): void;
|
|
26
|
+
removeAllListeners(): void;
|
|
27
|
+
listenerCount(type: MessageBusType): number;
|
|
28
|
+
}
|
|
29
|
+
export {};
|
|
@@ -0,0 +1,143 @@
|
|
|
1
|
+
import { EventEmitter } from 'node:events';
|
|
2
|
+
import { randomUUID } from 'node:crypto';
|
|
3
|
+
import { PolicyEngine } from '../policy-engine.js';
|
|
4
|
+
import { PolicyDecision } from '../types.js';
|
|
5
|
+
import { ConfirmationOutcome, MessageBusType, } from './types.js';
|
|
6
|
+
/**
|
|
7
|
+
* MessageBus provides event-driven communication for tool confirmations and policy decisions.
|
|
8
|
+
* Uses EventEmitter for pub/sub pattern and integrates with PolicyEngine for authorization.
|
|
9
|
+
*/
|
|
10
|
+
export class MessageBus {
|
|
11
|
+
emitter;
|
|
12
|
+
policyEngine;
|
|
13
|
+
debugMode;
|
|
14
|
+
logger;
|
|
15
|
+
constructor(policyEngine, debugMode = false, logger) {
|
|
16
|
+
this.emitter = new EventEmitter();
|
|
17
|
+
this.policyEngine = policyEngine ?? new PolicyEngine();
|
|
18
|
+
this.debugMode = debugMode;
|
|
19
|
+
this.logger = logger;
|
|
20
|
+
this.emitter.setMaxListeners(50);
|
|
21
|
+
}
|
|
22
|
+
publish(message) {
|
|
23
|
+
if (this.debugMode) {
|
|
24
|
+
this.logger?.log(`[MessageBus] Publishing: ${message.type}`, message);
|
|
25
|
+
}
|
|
26
|
+
this.emitter.emit(message.type, message);
|
|
27
|
+
}
|
|
28
|
+
subscribe(type, handler) {
|
|
29
|
+
this.emitter.on(type, handler);
|
|
30
|
+
return () => {
|
|
31
|
+
this.emitter.off(type, handler);
|
|
32
|
+
};
|
|
33
|
+
}
|
|
34
|
+
unsubscribe(type, handler) {
|
|
35
|
+
this.emitter.off(type, handler);
|
|
36
|
+
}
|
|
37
|
+
async requestConfirmation(toolCall, args, serverName) {
|
|
38
|
+
const correlationId = randomUUID();
|
|
39
|
+
if (!toolCall.name) {
|
|
40
|
+
throw new Error('Tool call must have a name');
|
|
41
|
+
}
|
|
42
|
+
const decision = this.policyEngine.evaluate(toolCall.name, args, serverName);
|
|
43
|
+
if (this.debugMode) {
|
|
44
|
+
this.logger?.log(`[MessageBus] Policy decision for ${toolCall.name}: ${decision}`);
|
|
45
|
+
}
|
|
46
|
+
if (decision === PolicyDecision.ALLOW) {
|
|
47
|
+
return true;
|
|
48
|
+
}
|
|
49
|
+
if (decision === PolicyDecision.DENY) {
|
|
50
|
+
this.publish({
|
|
51
|
+
type: MessageBusType.TOOL_POLICY_REJECTION,
|
|
52
|
+
toolCall,
|
|
53
|
+
correlationId,
|
|
54
|
+
reason: 'Policy denied execution',
|
|
55
|
+
serverName,
|
|
56
|
+
});
|
|
57
|
+
return false;
|
|
58
|
+
}
|
|
59
|
+
return new Promise((resolve) => {
|
|
60
|
+
const timeout = setTimeout(() => {
|
|
61
|
+
unsubscribe();
|
|
62
|
+
resolve(false);
|
|
63
|
+
}, 300000);
|
|
64
|
+
const unsubscribe = this.subscribe(MessageBusType.TOOL_CONFIRMATION_RESPONSE, (response) => {
|
|
65
|
+
if (response.correlationId === correlationId) {
|
|
66
|
+
clearTimeout(timeout);
|
|
67
|
+
unsubscribe();
|
|
68
|
+
let resolvedConfirmation;
|
|
69
|
+
if (response.outcome !== undefined) {
|
|
70
|
+
const isCancel = response.outcome === ConfirmationOutcome.Cancel;
|
|
71
|
+
const isModify = response.outcome === ConfirmationOutcome.ModifyWithEditor;
|
|
72
|
+
const isSuggest = response.outcome === ConfirmationOutcome.SuggestEdit;
|
|
73
|
+
resolvedConfirmation = !isCancel && !isModify && !isSuggest;
|
|
74
|
+
}
|
|
75
|
+
else if (response.confirmed !== undefined) {
|
|
76
|
+
resolvedConfirmation = response.confirmed;
|
|
77
|
+
}
|
|
78
|
+
else {
|
|
79
|
+
resolvedConfirmation = false;
|
|
80
|
+
}
|
|
81
|
+
resolve(resolvedConfirmation);
|
|
82
|
+
}
|
|
83
|
+
});
|
|
84
|
+
this.publish({
|
|
85
|
+
type: MessageBusType.TOOL_CONFIRMATION_REQUEST,
|
|
86
|
+
toolCall,
|
|
87
|
+
correlationId,
|
|
88
|
+
serverName,
|
|
89
|
+
});
|
|
90
|
+
});
|
|
91
|
+
}
|
|
92
|
+
respondToConfirmation(correlationId, outcome, payload, requiresUserConfirmation) {
|
|
93
|
+
const confirmed = outcome !== ConfirmationOutcome.Cancel &&
|
|
94
|
+
outcome !== ConfirmationOutcome.ModifyWithEditor &&
|
|
95
|
+
outcome !== ConfirmationOutcome.SuggestEdit;
|
|
96
|
+
this.publish({
|
|
97
|
+
type: MessageBusType.TOOL_CONFIRMATION_RESPONSE,
|
|
98
|
+
correlationId,
|
|
99
|
+
outcome,
|
|
100
|
+
payload,
|
|
101
|
+
confirmed,
|
|
102
|
+
requiresUserConfirmation,
|
|
103
|
+
});
|
|
104
|
+
}
|
|
105
|
+
async requestBucketAuthConfirmation(provider, bucket, bucketIndex, totalBuckets) {
|
|
106
|
+
const correlationId = randomUUID();
|
|
107
|
+
return new Promise((resolve) => {
|
|
108
|
+
const timeout = setTimeout(() => {
|
|
109
|
+
unsubscribe();
|
|
110
|
+
resolve(false);
|
|
111
|
+
}, 300000);
|
|
112
|
+
const unsubscribe = this.subscribe(MessageBusType.BUCKET_AUTH_CONFIRMATION_RESPONSE, (response) => {
|
|
113
|
+
if (response.correlationId === correlationId) {
|
|
114
|
+
clearTimeout(timeout);
|
|
115
|
+
unsubscribe();
|
|
116
|
+
resolve(response.confirmed);
|
|
117
|
+
}
|
|
118
|
+
});
|
|
119
|
+
this.publish({
|
|
120
|
+
type: MessageBusType.BUCKET_AUTH_CONFIRMATION_REQUEST,
|
|
121
|
+
correlationId,
|
|
122
|
+
provider,
|
|
123
|
+
bucket,
|
|
124
|
+
bucketIndex,
|
|
125
|
+
totalBuckets,
|
|
126
|
+
});
|
|
127
|
+
});
|
|
128
|
+
}
|
|
129
|
+
respondToBucketAuthConfirmation(correlationId, confirmed) {
|
|
130
|
+
this.publish({
|
|
131
|
+
type: MessageBusType.BUCKET_AUTH_CONFIRMATION_RESPONSE,
|
|
132
|
+
correlationId,
|
|
133
|
+
confirmed,
|
|
134
|
+
});
|
|
135
|
+
}
|
|
136
|
+
removeAllListeners() {
|
|
137
|
+
this.emitter.removeAllListeners();
|
|
138
|
+
}
|
|
139
|
+
listenerCount(type) {
|
|
140
|
+
return this.emitter.listenerCount(type);
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
//# sourceMappingURL=message-bus.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"message-bus.js","sourceRoot":"","sources":["../../../src/confirmation-bus/message-bus.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAC3C,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AACzC,OAAO,EAAE,YAAY,EAAE,MAAM,qBAAqB,CAAC;AACnD,OAAO,EAAE,cAAc,EAAE,MAAM,aAAa,CAAC;AAC7C,OAAO,EACL,mBAAmB,EACnB,cAAc,GAMf,MAAM,YAAY,CAAC;AAYpB;;;GAGG;AACH,MAAM,OAAO,UAAU;IACJ,OAAO,CAAe;IACtB,YAAY,CAAe;IAC3B,SAA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AAK,CAAC,CAAC;YACjB,CAAC,EAAE,MAAM,CAAC,CAAC;YAEX,MAAM,WAAW,GAAG,IAAI,CAAC,SAAS,CAChC,cAAc,CAAC,iCAAiC,EAChD,CAAC,QAAQ,EAAE,EAAE;gBACX,IAAI,QAAQ,CAAC,aAAa,KAAK,aAAa,EAAE,CAAC;oBAC7C,YAAY,CAAC,OAAO,CAAC,CAAC;oBACtB,WAAW,EAAE,CAAC;oBACd,OAAO,CAAC,QAAQ,CAAC,SAAS,CAAC,CAAC;gBAC9B,CAAC;YACH,CAAC,CACF,CAAC;YAEF,IAAI,CAAC,OAAO,CAAC;gBACX,IAAI,EAAE,cAAc,CAAC,gCAAgC;gBACrD,aAAa;gBACb,QAAQ;gBACR,MAAM;gBACN,WAAW;gBACX,YAAY;aACb,CAAC,CAAC;QACL,CAAC,CAAC,CAAC;IACL,CAAC;IAED,+BAA+B,CAC7B,aAAqB,EACrB,SAAkB;QAElB,IAAI,CAAC,OAAO,CAAC;YACX,IAAI,EAAE,cAAc,CAAC,iCAAiC;YACtD,aAAa;YACb,SAAS;SACV,CAAC,CAAC;IACL,CAAC;IAED,kBAAkB;QAChB,IAAI,CAAC,OAAO,CAAC,kBAAkB,EAAE,CAAC;IACpC,CAAC;IAED,aAAa,CAAC,IAAoB;QAChC,OAAO,IAAI,CAAC,OAAO,CAAC,aAAa,CAAC,IAAI,CAAC,CAAC;IAC1C,CAAC;CACF"}
|
|
@@ -0,0 +1,180 @@
|
|
|
1
|
+
export declare enum MessageBusType {
|
|
2
|
+
TOOL_CONFIRMATION_REQUEST = "tool-confirmation-request",
|
|
3
|
+
TOOL_CONFIRMATION_RESPONSE = "tool-confirmation-response",
|
|
4
|
+
TOOL_POLICY_REJECTION = "tool-policy-rejection",
|
|
5
|
+
TOOL_EXECUTION_SUCCESS = "tool-execution-success",
|
|
6
|
+
TOOL_EXECUTION_FAILURE = "tool-execution-failure",
|
|
7
|
+
UPDATE_POLICY = "update-policy",
|
|
8
|
+
BUCKET_AUTH_CONFIRMATION_REQUEST = "bucket-auth-confirmation-request",
|
|
9
|
+
BUCKET_AUTH_CONFIRMATION_RESPONSE = "bucket-auth-confirmation-response",
|
|
10
|
+
HOOK_EXECUTION_REQUEST = "HOOK_EXECUTION_REQUEST",
|
|
11
|
+
HOOK_EXECUTION_RESPONSE = "HOOK_EXECUTION_RESPONSE",
|
|
12
|
+
TOOL_CALLS_UPDATE = "tool-calls-update"
|
|
13
|
+
}
|
|
14
|
+
export interface PolicyFunctionCall {
|
|
15
|
+
id?: string;
|
|
16
|
+
name?: string;
|
|
17
|
+
args?: Record<string, unknown>;
|
|
18
|
+
}
|
|
19
|
+
export interface PolicyToolCallState {
|
|
20
|
+
id?: string;
|
|
21
|
+
name?: string;
|
|
22
|
+
status?: string;
|
|
23
|
+
[key: string]: unknown;
|
|
24
|
+
}
|
|
25
|
+
export interface ToolCallsUpdateMessage<T = unknown> {
|
|
26
|
+
type: MessageBusType.TOOL_CALLS_UPDATE;
|
|
27
|
+
readonly toolCalls: readonly T[];
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* Confirmation outcome enum. Declared as `ToolConfirmationOutcome` so its
|
|
31
|
+
* declaration name matches the structurally-identical enum declared in the
|
|
32
|
+
* telemetry package. TypeScript keys cross-module enum assignability off the
|
|
33
|
+
* declaration name, so sharing the name keeps telemetry event construction
|
|
34
|
+
* (e.g. `new ToolCallEvent(completedToolCall)`) compatible across packages.
|
|
35
|
+
*
|
|
36
|
+
* `ConfirmationOutcome` is exported as a value+type alias for the policy
|
|
37
|
+
* package's public API and internal references.
|
|
38
|
+
*/
|
|
39
|
+
export declare enum ToolConfirmationOutcome {
|
|
40
|
+
ProceedOnce = "proceed_once",
|
|
41
|
+
ProceedAlways = "proceed_always",
|
|
42
|
+
ProceedAlwaysAndSave = "proceed_always_and_save",
|
|
43
|
+
ProceedAlwaysServer = "proceed_always_server",
|
|
44
|
+
ProceedAlwaysTool = "proceed_always_tool",
|
|
45
|
+
ModifyWithEditor = "modify_with_editor",
|
|
46
|
+
SuggestEdit = "suggest_edit",
|
|
47
|
+
Cancel = "cancel"
|
|
48
|
+
}
|
|
49
|
+
export declare const ConfirmationOutcome: typeof ToolConfirmationOutcome;
|
|
50
|
+
export type ConfirmationOutcome = ToolConfirmationOutcome;
|
|
51
|
+
export interface ConfirmationPayload {
|
|
52
|
+
/**
|
|
53
|
+
* Used to override modified proposed content for modifiable tools in the
|
|
54
|
+
* inline modify flow.
|
|
55
|
+
*/
|
|
56
|
+
newContent?: string;
|
|
57
|
+
/**
|
|
58
|
+
* Used to override command text for shell-like tool confirmations.
|
|
59
|
+
*/
|
|
60
|
+
editedCommand?: string;
|
|
61
|
+
}
|
|
62
|
+
/**
|
|
63
|
+
* Data-only versions of ToolCallConfirmationDetails for bus transmission.
|
|
64
|
+
*/
|
|
65
|
+
export type SerializableConfirmationDetails = {
|
|
66
|
+
type: 'info';
|
|
67
|
+
title: string;
|
|
68
|
+
prompt: string;
|
|
69
|
+
urls?: string[];
|
|
70
|
+
} | {
|
|
71
|
+
type: 'edit';
|
|
72
|
+
title: string;
|
|
73
|
+
fileName: string;
|
|
74
|
+
filePath: string;
|
|
75
|
+
fileDiff: string;
|
|
76
|
+
originalContent: string | null;
|
|
77
|
+
newContent: string;
|
|
78
|
+
} | {
|
|
79
|
+
type: 'exec';
|
|
80
|
+
title: string;
|
|
81
|
+
command: string;
|
|
82
|
+
rootCommand: string;
|
|
83
|
+
rootCommands: string[];
|
|
84
|
+
} | {
|
|
85
|
+
type: 'mcp';
|
|
86
|
+
title: string;
|
|
87
|
+
serverName: string;
|
|
88
|
+
toolName: string;
|
|
89
|
+
toolDisplayName: string;
|
|
90
|
+
};
|
|
91
|
+
export interface ToolConfirmationRequest {
|
|
92
|
+
type: MessageBusType.TOOL_CONFIRMATION_REQUEST;
|
|
93
|
+
toolCall: PolicyFunctionCall;
|
|
94
|
+
correlationId: string;
|
|
95
|
+
serverName?: string;
|
|
96
|
+
/**
|
|
97
|
+
* Optional rich details for the confirmation UI (diffs, counts, etc.)
|
|
98
|
+
*/
|
|
99
|
+
details?: SerializableConfirmationDetails;
|
|
100
|
+
}
|
|
101
|
+
export interface ToolConfirmationResponse {
|
|
102
|
+
type: MessageBusType.TOOL_CONFIRMATION_RESPONSE;
|
|
103
|
+
correlationId: string;
|
|
104
|
+
/**
|
|
105
|
+
* Complete enum outcome preferred for consumers. When omitted, fall back to
|
|
106
|
+
* the legacy `confirmed` boolean semantics.
|
|
107
|
+
*/
|
|
108
|
+
outcome?: ConfirmationOutcome;
|
|
109
|
+
/**
|
|
110
|
+
* Optional payload used by inline modify flows.
|
|
111
|
+
*/
|
|
112
|
+
payload?: ConfirmationPayload;
|
|
113
|
+
/**
|
|
114
|
+
* Legacy flag maintained for compatibility. New publishers should send a
|
|
115
|
+
* concrete outcome instead.
|
|
116
|
+
*/
|
|
117
|
+
confirmed?: boolean;
|
|
118
|
+
requiresUserConfirmation?: boolean;
|
|
119
|
+
}
|
|
120
|
+
export interface ToolPolicyRejection {
|
|
121
|
+
type: MessageBusType.TOOL_POLICY_REJECTION;
|
|
122
|
+
toolCall: PolicyFunctionCall;
|
|
123
|
+
correlationId: string;
|
|
124
|
+
reason: string;
|
|
125
|
+
serverName?: string;
|
|
126
|
+
}
|
|
127
|
+
export interface ToolExecutionSuccess {
|
|
128
|
+
type: MessageBusType.TOOL_EXECUTION_SUCCESS;
|
|
129
|
+
toolCall: PolicyFunctionCall;
|
|
130
|
+
correlationId: string;
|
|
131
|
+
result: unknown;
|
|
132
|
+
}
|
|
133
|
+
export interface ToolExecutionFailure {
|
|
134
|
+
type: MessageBusType.TOOL_EXECUTION_FAILURE;
|
|
135
|
+
toolCall: PolicyFunctionCall;
|
|
136
|
+
correlationId: string;
|
|
137
|
+
error: Error;
|
|
138
|
+
}
|
|
139
|
+
export interface UpdatePolicy {
|
|
140
|
+
type: MessageBusType.UPDATE_POLICY;
|
|
141
|
+
toolName: string;
|
|
142
|
+
persist?: boolean;
|
|
143
|
+
argsPattern?: string;
|
|
144
|
+
commandPrefix?: string | string[];
|
|
145
|
+
mcpName?: string;
|
|
146
|
+
}
|
|
147
|
+
/**
|
|
148
|
+
* Request to confirm OAuth bucket authentication
|
|
149
|
+
*/
|
|
150
|
+
export interface BucketAuthConfirmationRequest {
|
|
151
|
+
type: MessageBusType.BUCKET_AUTH_CONFIRMATION_REQUEST;
|
|
152
|
+
correlationId: string;
|
|
153
|
+
provider: string;
|
|
154
|
+
bucket: string;
|
|
155
|
+
bucketIndex: number;
|
|
156
|
+
totalBuckets: number;
|
|
157
|
+
}
|
|
158
|
+
/**
|
|
159
|
+
* Response to bucket auth confirmation request
|
|
160
|
+
*/
|
|
161
|
+
export interface BucketAuthConfirmationResponse {
|
|
162
|
+
type: MessageBusType.BUCKET_AUTH_CONFIRMATION_RESPONSE;
|
|
163
|
+
correlationId: string;
|
|
164
|
+
confirmed: boolean;
|
|
165
|
+
}
|
|
166
|
+
export interface HookExecutionRequest {
|
|
167
|
+
type: MessageBusType.HOOK_EXECUTION_REQUEST;
|
|
168
|
+
payload: {
|
|
169
|
+
eventName: string;
|
|
170
|
+
correlationId: string;
|
|
171
|
+
};
|
|
172
|
+
}
|
|
173
|
+
export interface HookExecutionResponse {
|
|
174
|
+
type: MessageBusType.HOOK_EXECUTION_RESPONSE;
|
|
175
|
+
payload: {
|
|
176
|
+
correlationId: string;
|
|
177
|
+
};
|
|
178
|
+
}
|
|
179
|
+
export type MessageBusMessage<TToolCall = unknown> = ToolConfirmationRequest | ToolConfirmationResponse | ToolPolicyRejection | ToolExecutionSuccess | ToolExecutionFailure | UpdatePolicy | BucketAuthConfirmationRequest | BucketAuthConfirmationResponse | HookExecutionRequest | HookExecutionResponse | ToolCallsUpdateMessage<TToolCall>;
|
|
180
|
+
export type ToolConfirmationPayload = ConfirmationPayload;
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
export var MessageBusType;
|
|
2
|
+
(function (MessageBusType) {
|
|
3
|
+
MessageBusType["TOOL_CONFIRMATION_REQUEST"] = "tool-confirmation-request";
|
|
4
|
+
MessageBusType["TOOL_CONFIRMATION_RESPONSE"] = "tool-confirmation-response";
|
|
5
|
+
MessageBusType["TOOL_POLICY_REJECTION"] = "tool-policy-rejection";
|
|
6
|
+
MessageBusType["TOOL_EXECUTION_SUCCESS"] = "tool-execution-success";
|
|
7
|
+
MessageBusType["TOOL_EXECUTION_FAILURE"] = "tool-execution-failure";
|
|
8
|
+
MessageBusType["UPDATE_POLICY"] = "update-policy";
|
|
9
|
+
MessageBusType["BUCKET_AUTH_CONFIRMATION_REQUEST"] = "bucket-auth-confirmation-request";
|
|
10
|
+
MessageBusType["BUCKET_AUTH_CONFIRMATION_RESPONSE"] = "bucket-auth-confirmation-response";
|
|
11
|
+
MessageBusType["HOOK_EXECUTION_REQUEST"] = "HOOK_EXECUTION_REQUEST";
|
|
12
|
+
MessageBusType["HOOK_EXECUTION_RESPONSE"] = "HOOK_EXECUTION_RESPONSE";
|
|
13
|
+
MessageBusType["TOOL_CALLS_UPDATE"] = "tool-calls-update";
|
|
14
|
+
})(MessageBusType || (MessageBusType = {}));
|
|
15
|
+
/**
|
|
16
|
+
* Confirmation outcome enum. Declared as `ToolConfirmationOutcome` so its
|
|
17
|
+
* declaration name matches the structurally-identical enum declared in the
|
|
18
|
+
* telemetry package. TypeScript keys cross-module enum assignability off the
|
|
19
|
+
* declaration name, so sharing the name keeps telemetry event construction
|
|
20
|
+
* (e.g. `new ToolCallEvent(completedToolCall)`) compatible across packages.
|
|
21
|
+
*
|
|
22
|
+
* `ConfirmationOutcome` is exported as a value+type alias for the policy
|
|
23
|
+
* package's public API and internal references.
|
|
24
|
+
*/
|
|
25
|
+
export var ToolConfirmationOutcome;
|
|
26
|
+
(function (ToolConfirmationOutcome) {
|
|
27
|
+
ToolConfirmationOutcome["ProceedOnce"] = "proceed_once";
|
|
28
|
+
ToolConfirmationOutcome["ProceedAlways"] = "proceed_always";
|
|
29
|
+
ToolConfirmationOutcome["ProceedAlwaysAndSave"] = "proceed_always_and_save";
|
|
30
|
+
ToolConfirmationOutcome["ProceedAlwaysServer"] = "proceed_always_server";
|
|
31
|
+
ToolConfirmationOutcome["ProceedAlwaysTool"] = "proceed_always_tool";
|
|
32
|
+
ToolConfirmationOutcome["ModifyWithEditor"] = "modify_with_editor";
|
|
33
|
+
ToolConfirmationOutcome["SuggestEdit"] = "suggest_edit";
|
|
34
|
+
ToolConfirmationOutcome["Cancel"] = "cancel";
|
|
35
|
+
})(ToolConfirmationOutcome || (ToolConfirmationOutcome = {}));
|
|
36
|
+
export const ConfirmationOutcome = ToolConfirmationOutcome;
|
|
37
|
+
//# sourceMappingURL=types.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../../src/confirmation-bus/types.ts"],"names":[],"mappings":"AAAA,MAAM,CAAN,IAAY,cAYX;AAZD,WAAY,cAAc;IACxB,yEAAuD,CAAA;IACvD,2EAAyD,CAAA;IACzD,iEAA+C,CAAA;IAC/C,mEAAiD,CAAA;IACjD,mEAAiD,CAAA;IACjD,iDAA+B,CAAA;IAC/B,uFAAqE,CAAA;IACrE,yFAAuE,CAAA;IACvE,mEAAiD,CAAA;IACjD,qEAAmD,CAAA;IACnD,yDAAuC,CAAA;AACzC,CAAC,EAZW,cAAc,KAAd,cAAc,QAYzB;AAoBD;;;;;;;;;GASG;AACH,MAAM,CAAN,IAAY,uBASX;AATD,WAAY,uBAAuB;IACjC,uDAA4B,CAAA;IAC5B,2DAAgC,CAAA;IAChC,2EAAgD,CAAA;IAChD,wEAA6C,CAAA;IAC7C,oEAAyC,CAAA;IACzC,kEAAuC,CAAA;IACvC,uDAA4B,CAAA;IAC5B,4CAAiB,CAAA;AACnB,CAAC,EATW,uBAAuB,KAAvB,uBAAuB,QASlC;AAED,MAAM,CAAC,MAAM,mBAAmB,GAAG,uBAAuB,CAAC"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
export { PolicyDecision, ApprovalMode } from './types.js';
|
|
2
|
+
export type { PolicyEngineConfig, PolicyRule, PolicySettings, } from './types.js';
|
|
3
|
+
export { PolicyEngine } from './policy-engine.js';
|
|
4
|
+
export { stableStringify, stableParse } from './stable-stringify.js';
|
|
5
|
+
export { loadPoliciesFromToml, loadPolicyFromToml, loadDefaultPolicies, } from './toml-loader.js';
|
|
6
|
+
export type { PolicyFileError, PolicyFileErrorType, PolicyLoadResult, } from './toml-loader.js';
|
|
7
|
+
export { buildArgsPatterns, escapeRegex } from './utils.js';
|
|
8
|
+
export { DEFAULT_CORE_POLICIES_DIR, DEFAULT_POLICY_TIER, USER_POLICY_TIER, ADMIN_POLICY_TIER, getPolicyDirectories, getPolicyTier, formatPolicyError, migrateLegacyApprovalMode, } from './config.js';
|
|
9
|
+
export type { PolicyConfigSource, PolicyPathResolver } from './config.js';
|
|
10
|
+
export { MessageBus, MessageBusType, ConfirmationOutcome, ToolConfirmationOutcome, } from './confirmation-bus/index.js';
|
|
11
|
+
export type { PolicyLogger, ConfirmationPayload, PolicyFunctionCall, PolicyToolCallState, SerializableConfirmationDetails, ToolCallsUpdateMessage, ToolConfirmationRequest, ToolConfirmationResponse, ToolPolicyRejection, ToolExecutionSuccess, ToolExecutionFailure, UpdatePolicy, BucketAuthConfirmationRequest, BucketAuthConfirmationResponse, HookExecutionRequest, HookExecutionResponse, MessageBusMessage, ToolConfirmationPayload, } from './confirmation-bus/index.js';
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
export { PolicyDecision, ApprovalMode } from './types.js';
|
|
2
|
+
export { PolicyEngine } from './policy-engine.js';
|
|
3
|
+
export { stableStringify, stableParse } from './stable-stringify.js';
|
|
4
|
+
export { loadPoliciesFromToml, loadPolicyFromToml, loadDefaultPolicies, } from './toml-loader.js';
|
|
5
|
+
export { buildArgsPatterns, escapeRegex } from './utils.js';
|
|
6
|
+
export { DEFAULT_CORE_POLICIES_DIR, DEFAULT_POLICY_TIER, USER_POLICY_TIER, ADMIN_POLICY_TIER, getPolicyDirectories, getPolicyTier, formatPolicyError, migrateLegacyApprovalMode, } from './config.js';
|
|
7
|
+
export { MessageBus, MessageBusType, ConfirmationOutcome, ToolConfirmationOutcome, } from './confirmation-bus/index.js';
|
|
8
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,YAAY,EAAE,MAAM,YAAY,CAAC;AAM1D,OAAO,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAClD,OAAO,EAAE,eAAe,EAAE,WAAW,EAAE,MAAM,uBAAuB,CAAC;AACrE,OAAO,EACL,oBAAoB,EACpB,kBAAkB,EAClB,mBAAmB,GACpB,MAAM,kBAAkB,CAAC;AAM1B,OAAO,EAAE,iBAAiB,EAAE,WAAW,EAAE,MAAM,YAAY,CAAC;AAC5D,OAAO,EACL,yBAAyB,EACzB,mBAAmB,EACnB,gBAAgB,EAChB,iBAAiB,EACjB,oBAAoB,EACpB,aAAa,EACb,iBAAiB,EACjB,yBAAyB,GAC1B,MAAM,aAAa,CAAC;AAErB,OAAO,EACL,UAAU,EACV,cAAc,EACd,mBAAmB,EACnB,uBAAuB,GACxB,MAAM,6BAA6B,CAAC"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
# Default policy for discovered tools (MCP, extensions, etc.)
|
|
2
|
+
# Priority band: 10 (Tier 1 - Default: 1.010 after transformation)
|
|
3
|
+
# Discovered tools require user confirmation unless explicitly trusted
|
|
4
|
+
|
|
5
|
+
[[rule]]
|
|
6
|
+
# Match all discovered tools (tools with discovered_tool_ prefix will be added by ToolRegistry)
|
|
7
|
+
toolName = "discovered_tool_*"
|
|
8
|
+
decision = "ask_user"
|
|
9
|
+
priority = 10
|