@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
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* Copyright 2025 Vybestack LLC
|
|
4
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
5
|
+
*/
|
|
6
|
+
export declare enum PolicyDecision {
|
|
7
|
+
ALLOW = "allow",
|
|
8
|
+
DENY = "deny",
|
|
9
|
+
ASK_USER = "ask_user"
|
|
10
|
+
}
|
|
11
|
+
export declare enum ApprovalMode {
|
|
12
|
+
DEFAULT = "default",
|
|
13
|
+
AUTO_EDIT = "autoEdit",
|
|
14
|
+
YOLO = "yolo"
|
|
15
|
+
}
|
|
16
|
+
export interface PolicyRule {
|
|
17
|
+
/**
|
|
18
|
+
* A unique name for the policy rule, useful for identification and debugging.
|
|
19
|
+
*/
|
|
20
|
+
name?: string;
|
|
21
|
+
/**
|
|
22
|
+
* The name of the tool this rule applies to.
|
|
23
|
+
* If undefined, the rule applies to all tools.
|
|
24
|
+
*/
|
|
25
|
+
toolName?: string;
|
|
26
|
+
/**
|
|
27
|
+
* Pattern to match against tool arguments.
|
|
28
|
+
* Can be used for more fine-grained control.
|
|
29
|
+
*/
|
|
30
|
+
argsPattern?: RegExp;
|
|
31
|
+
/**
|
|
32
|
+
* The decision to make when this rule matches.
|
|
33
|
+
*/
|
|
34
|
+
decision: PolicyDecision;
|
|
35
|
+
/**
|
|
36
|
+
* Priority of this rule. Higher numbers take precedence.
|
|
37
|
+
* Default is 0.
|
|
38
|
+
*/
|
|
39
|
+
priority?: number;
|
|
40
|
+
/**
|
|
41
|
+
* Allow shell redirections (>, |, etc.) in this rule.
|
|
42
|
+
* Only applies to shell tools.
|
|
43
|
+
* Default is false.
|
|
44
|
+
*/
|
|
45
|
+
allowRedirection?: boolean;
|
|
46
|
+
/**
|
|
47
|
+
* Origin of the rule, e.g. "Default: defaults.toml", "Settings (MCP Trusted)",
|
|
48
|
+
* "Dynamic (Confirmed)".
|
|
49
|
+
*/
|
|
50
|
+
source?: string;
|
|
51
|
+
}
|
|
52
|
+
export interface PolicyEngineConfig {
|
|
53
|
+
/**
|
|
54
|
+
* List of policy rules to apply.
|
|
55
|
+
*/
|
|
56
|
+
rules?: PolicyRule[];
|
|
57
|
+
/**
|
|
58
|
+
* Default decision when no rules match.
|
|
59
|
+
* Defaults to ASK_USER.
|
|
60
|
+
*/
|
|
61
|
+
defaultDecision?: PolicyDecision;
|
|
62
|
+
/**
|
|
63
|
+
* Whether to allow tools in non-interactive mode.
|
|
64
|
+
* When true, ASK_USER decisions become DENY.
|
|
65
|
+
*/
|
|
66
|
+
nonInteractive?: boolean;
|
|
67
|
+
}
|
|
68
|
+
export interface PolicySettings {
|
|
69
|
+
mcp?: {
|
|
70
|
+
excluded?: string[];
|
|
71
|
+
allowed?: string[];
|
|
72
|
+
};
|
|
73
|
+
tools?: {
|
|
74
|
+
exclude?: string[];
|
|
75
|
+
allowed?: string[];
|
|
76
|
+
};
|
|
77
|
+
mcpServers?: Record<string, {
|
|
78
|
+
trust?: boolean;
|
|
79
|
+
}>;
|
|
80
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* Copyright 2025 Vybestack LLC
|
|
4
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
5
|
+
*/
|
|
6
|
+
export var PolicyDecision;
|
|
7
|
+
(function (PolicyDecision) {
|
|
8
|
+
PolicyDecision["ALLOW"] = "allow";
|
|
9
|
+
PolicyDecision["DENY"] = "deny";
|
|
10
|
+
PolicyDecision["ASK_USER"] = "ask_user";
|
|
11
|
+
})(PolicyDecision || (PolicyDecision = {}));
|
|
12
|
+
export var ApprovalMode;
|
|
13
|
+
(function (ApprovalMode) {
|
|
14
|
+
ApprovalMode["DEFAULT"] = "default";
|
|
15
|
+
ApprovalMode["AUTO_EDIT"] = "autoEdit";
|
|
16
|
+
ApprovalMode["YOLO"] = "yolo";
|
|
17
|
+
})(ApprovalMode || (ApprovalMode = {}));
|
|
18
|
+
//# sourceMappingURL=types.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/types.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,MAAM,CAAN,IAAY,cAIX;AAJD,WAAY,cAAc;IACxB,iCAAe,CAAA;IACf,+BAAa,CAAA;IACb,uCAAqB,CAAA;AACvB,CAAC,EAJW,cAAc,KAAd,cAAc,QAIzB;AAED,MAAM,CAAN,IAAY,YAIX;AAJD,WAAY,YAAY;IACtB,mCAAmB,CAAA;IACnB,sCAAsB,CAAA;IACtB,6BAAa,CAAA;AACf,CAAC,EAJW,YAAY,KAAZ,YAAY,QAIvB"}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* Copyright 2025 Vybestack LLC
|
|
4
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
5
|
+
*/
|
|
6
|
+
export declare const SHELL_TOOL_NAMES: string[];
|
|
7
|
+
export interface SplitCommandsOptions {
|
|
8
|
+
/**
|
|
9
|
+
* Whether to split on pipe operators (|).
|
|
10
|
+
* Default: true (split pipes for security checks).
|
|
11
|
+
*
|
|
12
|
+
* Originally added for now-removed command instrumentation (PR #1546);
|
|
13
|
+
* retained because it is zero-cost, tested, and useful for future
|
|
14
|
+
* pipeline-aware display. Security validation always uses the default
|
|
15
|
+
* (true) so every pipeline stage is validated individually.
|
|
16
|
+
*/
|
|
17
|
+
splitOnPipes?: boolean;
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* Split a command string into individual commands respecting common shell
|
|
21
|
+
* separators. This intentionally contains the lightweight fallback behavior
|
|
22
|
+
* used by the policy engine and does not depend on core shell tooling.
|
|
23
|
+
*/
|
|
24
|
+
export declare function splitCommands(command: string, options?: SplitCommandsOptions): string[];
|
|
25
|
+
/**
|
|
26
|
+
* Detects whether a shell command contains shell redirection operators
|
|
27
|
+
* (>, >>, <, <<, <<<, fd forms such as 2>, &>, >&), respecting shell quoting rules.
|
|
28
|
+
* Pipe operators (|) are NOT treated as redirection.
|
|
29
|
+
*/
|
|
30
|
+
export declare function hasRedirection(command: string): boolean;
|
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* Copyright 2025 Vybestack LLC
|
|
4
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
5
|
+
*/
|
|
6
|
+
export const SHELL_TOOL_NAMES = ['run_shell_command', 'ShellTool'];
|
|
7
|
+
function handleDoubleOperator(char, nextChar, state) {
|
|
8
|
+
if ((char === '&' && nextChar === '&') ||
|
|
9
|
+
(char === '|' && nextChar === '|')) {
|
|
10
|
+
state.commands.push(state.currentCommand.trim());
|
|
11
|
+
state.currentCommand = '';
|
|
12
|
+
return true;
|
|
13
|
+
}
|
|
14
|
+
return false;
|
|
15
|
+
}
|
|
16
|
+
function handleSingleOperator(char, nextChar, state, splitOnPipes) {
|
|
17
|
+
if (char === ';') {
|
|
18
|
+
state.commands.push(state.currentCommand.trim());
|
|
19
|
+
state.currentCommand = '';
|
|
20
|
+
}
|
|
21
|
+
else if (char === '&') {
|
|
22
|
+
const prevChar = state.currentCommand[state.currentCommand.length - 1];
|
|
23
|
+
if (prevChar === '>' || nextChar === '>') {
|
|
24
|
+
state.currentCommand += char;
|
|
25
|
+
}
|
|
26
|
+
else {
|
|
27
|
+
state.commands.push(state.currentCommand.trim());
|
|
28
|
+
state.currentCommand = '';
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
else if (char === '|') {
|
|
32
|
+
if (splitOnPipes) {
|
|
33
|
+
state.commands.push(state.currentCommand.trim());
|
|
34
|
+
state.currentCommand = '';
|
|
35
|
+
}
|
|
36
|
+
else {
|
|
37
|
+
state.currentCommand += char;
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
else {
|
|
41
|
+
state.currentCommand += char;
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* Split a command string into individual commands respecting common shell
|
|
46
|
+
* separators. This intentionally contains the lightweight fallback behavior
|
|
47
|
+
* used by the policy engine and does not depend on core shell tooling.
|
|
48
|
+
*/
|
|
49
|
+
export function splitCommands(command, options) {
|
|
50
|
+
const splitOnPipes = options?.splitOnPipes ?? true;
|
|
51
|
+
const state = {
|
|
52
|
+
commands: [],
|
|
53
|
+
currentCommand: '',
|
|
54
|
+
inSingleQuotes: false,
|
|
55
|
+
inDoubleQuotes: false,
|
|
56
|
+
};
|
|
57
|
+
let i = 0;
|
|
58
|
+
while (i < command.length) {
|
|
59
|
+
const char = command[i];
|
|
60
|
+
const nextChar = command[i + 1];
|
|
61
|
+
if (char === '\\' && i < command.length - 1) {
|
|
62
|
+
state.currentCommand += char + command[i + 1];
|
|
63
|
+
i += 2;
|
|
64
|
+
continue;
|
|
65
|
+
}
|
|
66
|
+
if (char === "'" && !state.inDoubleQuotes) {
|
|
67
|
+
state.inSingleQuotes = !state.inSingleQuotes;
|
|
68
|
+
}
|
|
69
|
+
else if (char === '"' && !state.inSingleQuotes) {
|
|
70
|
+
state.inDoubleQuotes = !state.inDoubleQuotes;
|
|
71
|
+
}
|
|
72
|
+
if (!state.inSingleQuotes && !state.inDoubleQuotes) {
|
|
73
|
+
if (handleDoubleOperator(char, nextChar, state)) {
|
|
74
|
+
i++;
|
|
75
|
+
}
|
|
76
|
+
else {
|
|
77
|
+
handleSingleOperator(char, nextChar, state, splitOnPipes);
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
else {
|
|
81
|
+
state.currentCommand += char;
|
|
82
|
+
}
|
|
83
|
+
i++;
|
|
84
|
+
}
|
|
85
|
+
if (state.currentCommand.trim()) {
|
|
86
|
+
state.commands.push(state.currentCommand.trim());
|
|
87
|
+
}
|
|
88
|
+
return state.commands.filter(Boolean);
|
|
89
|
+
}
|
|
90
|
+
/**
|
|
91
|
+
* Detects whether a shell command contains shell redirection operators
|
|
92
|
+
* (>, >>, <, <<, <<<, fd forms such as 2>, &>, >&), respecting shell quoting rules.
|
|
93
|
+
* Pipe operators (|) are NOT treated as redirection.
|
|
94
|
+
*/
|
|
95
|
+
export function hasRedirection(command) {
|
|
96
|
+
let inSingleQuotes = false;
|
|
97
|
+
let inDoubleQuotes = false;
|
|
98
|
+
let i = 0;
|
|
99
|
+
while (i < command.length) {
|
|
100
|
+
const char = command[i];
|
|
101
|
+
if (char === '\\' && !inSingleQuotes && i < command.length - 1) {
|
|
102
|
+
i += 2;
|
|
103
|
+
continue;
|
|
104
|
+
}
|
|
105
|
+
if (char === "'" && !inDoubleQuotes) {
|
|
106
|
+
inSingleQuotes = !inSingleQuotes;
|
|
107
|
+
}
|
|
108
|
+
else if (char === '"' && !inSingleQuotes) {
|
|
109
|
+
inDoubleQuotes = !inDoubleQuotes;
|
|
110
|
+
}
|
|
111
|
+
if (!inSingleQuotes && !inDoubleQuotes && (char === '>' || char === '<')) {
|
|
112
|
+
return true;
|
|
113
|
+
}
|
|
114
|
+
i++;
|
|
115
|
+
}
|
|
116
|
+
return false;
|
|
117
|
+
}
|
|
118
|
+
//# sourceMappingURL=shell-utils.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"shell-utils.js","sourceRoot":"","sources":["../../../src/utils/shell-utils.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,MAAM,CAAC,MAAM,gBAAgB,GAAG,CAAC,mBAAmB,EAAE,WAAW,CAAC,CAAC;AAsBnE,SAAS,oBAAoB,CAC3B,IAAY,EACZ,QAAgB,EAChB,KAAiB;IAEjB,IACE,CAAC,IAAI,KAAK,GAAG,IAAI,QAAQ,KAAK,GAAG,CAAC;QAClC,CAAC,IAAI,KAAK,GAAG,IAAI,QAAQ,KAAK,GAAG,CAAC,EAClC,CAAC;QACD,KAAK,CAAC,QAAQ,CAAC,IAAI,CAAC,KAAK,CAAC,cAAc,CAAC,IAAI,EAAE,CAAC,CAAC;QACjD,KAAK,CAAC,cAAc,GA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**
|
|
2
|
+
* @license
|
|
3
|
+
* Copyright 2025 Vybestack LLC
|
|
4
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
5
|
+
*/
|
|
6
|
+
/**
|
|
7
|
+
* Escapes special regex characters in a string.
|
|
8
|
+
*/
|
|
9
|
+
export declare function escapeRegex(text: string): string;
|
|
10
|
+
/**
|
|
11
|
+
* Validates that a policy-supplied regex pattern is within safe bounds.
|
|
12
|
+
* Policy regex comes from admin-controlled TOML files, but we still enforce
|
|
13
|
+
* a source length limit as defence-in-depth against ReDoS.
|
|
14
|
+
*
|
|
15
|
+
* Note: the nested-quantifier heuristic only detects directly adjacent
|
|
16
|
+
* quantifiers (e.g. `a*+`, `b+{2,}`). It does NOT catch grouped nested
|
|
17
|
+
* quantifiers such as `(a*)*` or `(a+)+`, where the quantifiers are separated
|
|
18
|
+
* by grouping constructs. Policy authors should avoid nested quantifiers when
|
|
19
|
+
* authoring policy regexes.
|
|
20
|
+
*/
|
|
21
|
+
export declare function validatePolicyRegex(source: string): void;
|
|
22
|
+
/**
|
|
23
|
+
* Builds regex patterns for policy matching from command prefixes or regex.
|
|
24
|
+
* Handles both string and array inputs for commandPrefix.
|
|
25
|
+
*/
|
|
26
|
+
export declare function buildArgsPatterns(argsPattern?: RegExp, commandPrefix?: string | string[], commandRegex?: string): RegExp[];
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* Copyright 2025 Vybestack LLC
|
|
4
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
5
|
+
*/
|
|
6
|
+
/**
|
|
7
|
+
* Escapes special regex characters in a string.
|
|
8
|
+
*/
|
|
9
|
+
export function escapeRegex(text) {
|
|
10
|
+
// eslint-disable-next-line sonarjs/regular-expr -- Static regex reviewed for lint hardening; behavior preserved.
|
|
11
|
+
return text.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
|
|
12
|
+
}
|
|
13
|
+
/** Maximum source length for admin-supplied policy regex patterns. */
|
|
14
|
+
const MAX_POLICY_REGEX_SOURCE_LENGTH = 1024;
|
|
15
|
+
/**
|
|
16
|
+
* Validates that a policy-supplied regex pattern is within safe bounds.
|
|
17
|
+
* Policy regex comes from admin-controlled TOML files, but we still enforce
|
|
18
|
+
* a source length limit as defence-in-depth against ReDoS.
|
|
19
|
+
*
|
|
20
|
+
* Note: the nested-quantifier heuristic only detects directly adjacent
|
|
21
|
+
* quantifiers (e.g. `a*+`, `b+{2,}`). It does NOT catch grouped nested
|
|
22
|
+
* quantifiers such as `(a*)*` or `(a+)+`, where the quantifiers are separated
|
|
23
|
+
* by grouping constructs. Policy authors should avoid nested quantifiers when
|
|
24
|
+
* authoring policy regexes.
|
|
25
|
+
*/
|
|
26
|
+
export function validatePolicyRegex(source) {
|
|
27
|
+
if (source.length > MAX_POLICY_REGEX_SOURCE_LENGTH) {
|
|
28
|
+
throw new Error(`Policy regex pattern exceeds maximum allowed length of ${MAX_POLICY_REGEX_SOURCE_LENGTH}`);
|
|
29
|
+
}
|
|
30
|
+
// Reject patterns with nested quantifiers that can cause catastrophic backtracking (ReDoS)
|
|
31
|
+
// eslint-disable-next-line sonarjs/regular-expr -- Static regex reviewed for lint hardening; behavior preserved.
|
|
32
|
+
if (/([+*]|\{\d+,\d*\})\??([+*]|\{\d+,\d*\})/.test(source)) {
|
|
33
|
+
throw new Error('Policy regex contains nested quantifiers (potential ReDoS)');
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* Builds regex patterns for policy matching from command prefixes or regex.
|
|
38
|
+
* Handles both string and array inputs for commandPrefix.
|
|
39
|
+
*/
|
|
40
|
+
export function buildArgsPatterns(argsPattern, commandPrefix, commandRegex) {
|
|
41
|
+
const patterns = [];
|
|
42
|
+
if (commandPrefix != null && commandPrefix !== '') {
|
|
43
|
+
const prefixes = Array.isArray(commandPrefix)
|
|
44
|
+
? commandPrefix
|
|
45
|
+
: [commandPrefix];
|
|
46
|
+
for (const prefix of prefixes) {
|
|
47
|
+
// Escape backslashes first, then quotes, for JSON matching
|
|
48
|
+
const escaped = prefix.replace(/\\/g, '\\\\').replace(/"/g, '\\"');
|
|
49
|
+
const escapedRegex = escapeRegex(escaped);
|
|
50
|
+
// Use word boundary to prevent partial matches
|
|
51
|
+
patterns.push(new RegExp(`"command":"${escapedRegex}(?:[\\s"]|$)`));
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
if (commandRegex !== undefined && commandRegex !== '') {
|
|
55
|
+
validatePolicyRegex(commandRegex);
|
|
56
|
+
// Use non-backtracking prefix with bounded match length
|
|
57
|
+
patterns.push(new RegExp(`"command":"(?:${commandRegex})`));
|
|
58
|
+
}
|
|
59
|
+
if (argsPattern instanceof RegExp) {
|
|
60
|
+
validatePolicyRegex(argsPattern.source);
|
|
61
|
+
// Rebuild regex with .* replaced by [^"]* to prevent polynomial
|
|
62
|
+
// backtracking when matching JSON-serialized tool arguments.
|
|
63
|
+
const safeSource = argsPattern.source.replace(/\.\*/g, '[^"]*');
|
|
64
|
+
patterns.push(new RegExp(safeSource, argsPattern.flags));
|
|
65
|
+
}
|
|
66
|
+
return patterns;
|
|
67
|
+
}
|
|
68
|
+
//# sourceMappingURL=utils.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"utils.js","sourceRoot":"","sources":["../../src/utils.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH;;GAEG;AACH,MAAM,UAAU,WAAW,CAAC,IAAY;IACtC,iHAAiH;IACjH,OAAO,IAAI,CAAC,OAAO,CAAC,qBAAqB,EAAE,MAAM,CAAC,CAAC;AACrD,CAAC;AAED,sEAAsE;AACtE,MAAM,8BAA8B,GAAG,IAAI,CAAC;AAE5C;;;;;;;;;;GAUG;AACH,MAAM,UAAU,mBAAmB,CAAC,MAAc;IAChD,IAAI,MAAM,CAAC,MAAM,GAAG,8BAA8B,EAAE,CAAC;QACnD,MAAM,IAAI,KAAK,CACb,0DAA0D,8BAA8B,E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GAAG,WAAW,CAAC,MAAM,CAAC,OAAO,CAAC,OAAO,EAAE,OAAO,CAAC,CAAC;QAChE,QAAQ,CAAC,IAAI,CAAC,IAAI,MAAM,CAAC,UAAU,EAAE,WAAW,CAAC,KAAK,CAAC,CAAC,CAAC;IAC3D,CAAC;IAED,OAAO,QAAQ,CAAC;AAClB,CAAC"}
|
package/package.json
ADDED
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@vybestack/llxprt-code-policy",
|
|
3
|
+
"version": "0.10.0-nightly.260613.1adad3b34",
|
|
4
|
+
"description": "LLxprt Code Policy — policy engine and confirmation bus",
|
|
5
|
+
"license": "Apache-2.0",
|
|
6
|
+
"repository": {
|
|
7
|
+
"type": "git",
|
|
8
|
+
"url": "git+https://github.com/vybestack/llxprt-code.git"
|
|
9
|
+
},
|
|
10
|
+
"type": "module",
|
|
11
|
+
"main": "dist/index.js",
|
|
12
|
+
"types": "dist/index.d.ts",
|
|
13
|
+
"exports": {
|
|
14
|
+
".": {
|
|
15
|
+
"types": "./dist/index.d.ts",
|
|
16
|
+
"import": "./dist/index.js"
|
|
17
|
+
},
|
|
18
|
+
"./types.js": "./dist/src/types.js",
|
|
19
|
+
"./policy-engine.js": "./dist/src/policy-engine.js",
|
|
20
|
+
"./stable-stringify.js": "./dist/src/stable-stringify.js",
|
|
21
|
+
"./config.js": "./dist/src/config.js",
|
|
22
|
+
"./toml-loader.js": "./dist/src/toml-loader.js",
|
|
23
|
+
"./utils.js": "./dist/src/utils.js",
|
|
24
|
+
"./confirmation-bus/index.js": "./dist/src/confirmation-bus/index.js",
|
|
25
|
+
"./confirmation-bus/types.js": "./dist/src/confirmation-bus/types.js",
|
|
26
|
+
"./confirmation-bus/message-bus.js": "./dist/src/confirmation-bus/message-bus.js"
|
|
27
|
+
},
|
|
28
|
+
"scripts": {
|
|
29
|
+
"build": "node ../../scripts/build_package.js",
|
|
30
|
+
"lint": "eslint . --ext .ts,.tsx",
|
|
31
|
+
"format": "prettier --write .",
|
|
32
|
+
"test": "vitest run",
|
|
33
|
+
"test:ci": "vitest run",
|
|
34
|
+
"typecheck": "tsc --noEmit"
|
|
35
|
+
},
|
|
36
|
+
"files": [
|
|
37
|
+
"dist"
|
|
38
|
+
],
|
|
39
|
+
"dependencies": {
|
|
40
|
+
"@iarna/toml": "^2.2.5",
|
|
41
|
+
"zod": "^3.25.76"
|
|
42
|
+
},
|
|
43
|
+
"devDependencies": {
|
|
44
|
+
"@types/node": "^24.2.1",
|
|
45
|
+
"fast-check": "^4.2.0",
|
|
46
|
+
"typescript": "^5.3.3",
|
|
47
|
+
"vitest": "^3.1.1"
|
|
48
|
+
},
|
|
49
|
+
"engines": {
|
|
50
|
+
"node": ">=20"
|
|
51
|
+
}
|
|
52
|
+
}
|