@compilr-dev/sdk 0.2.0 → 0.2.2

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/agent.js CHANGED
@@ -29,17 +29,27 @@ function toRunResult(raw) {
29
29
  };
30
30
  }
31
31
  /**
32
- * Build permission manager options from config
32
+ * Build permission manager options from config.
33
+ *
34
+ * When a PermissionCallback is provided:
35
+ * - defaultLevel is 'always' (tools auto-allowed unless rules say otherwise)
36
+ * - includeDefaults is true (agents library's built-in rules for dangerous tools)
37
+ * - Custom rules can be passed via permissionRules
38
+ *
39
+ * This matches the CLI pattern: everything allowed by default, only dangerous
40
+ * tools (bash, write_file, edit, etc.) require user approval.
33
41
  */
34
- function buildPermissions(permissions, presetDefault) {
42
+ function buildPermissions(permissions, presetDefault, permissionRules, includeDefaultRules) {
35
43
  const mode = permissions ?? presetDefault ?? 'auto';
36
44
  if (mode === 'read-only') {
37
45
  return { defaultLevel: 'deny' };
38
46
  }
39
47
  if (typeof mode === 'function') {
40
48
  return {
41
- defaultLevel: 'once',
49
+ defaultLevel: 'always',
42
50
  onPermissionRequest: mode,
51
+ rules: permissionRules,
52
+ includeDefaults: includeDefaultRules ?? true,
43
53
  };
44
54
  }
45
55
  // 'auto' — allow all tools
@@ -102,7 +112,7 @@ class CompilrAgentImpl {
102
112
  });
103
113
  }
104
114
  // Build agent config
105
- const permissionsConfig = buildPermissions(config?.permissions, preset.defaultPermissions);
115
+ const permissionsConfig = buildPermissions(config?.permissions, preset.defaultPermissions, config?.permissionRules, config?.includeDefaultRules);
106
116
  const guardrailsConfig = buildGuardrails(config?.guardrails);
107
117
  this.agent = new Agent({
108
118
  provider,
@@ -114,6 +124,8 @@ class CompilrAgentImpl {
114
124
  permissions: {
115
125
  defaultLevel: permissionsConfig.defaultLevel,
116
126
  onPermissionRequest: permissionsConfig.onPermissionRequest,
127
+ rules: permissionsConfig.rules,
128
+ includeDefaults: permissionsConfig.includeDefaults,
117
129
  },
118
130
  guardrails: {
119
131
  enabled: guardrailsConfig.enabled,
package/dist/config.d.ts CHANGED
@@ -1,7 +1,7 @@
1
1
  /**
2
2
  * SDK configuration types
3
3
  */
4
- import type { LLMProvider, Message, Tool, HooksConfig, AnchorInput, AgentEvent, ToolExecutionResult } from '@compilr-dev/agents';
4
+ import type { LLMProvider, Message, Tool, ToolPermission, HooksConfig, AnchorInput, AgentEvent, ToolExecutionResult } from '@compilr-dev/agents';
5
5
  import type { Preset } from './presets/types.js';
6
6
  /**
7
7
  * Supported provider types for auto-detection
@@ -128,6 +128,17 @@ export interface CompilrAgentConfig {
128
128
  tools?: ToolConfig;
129
129
  /** Permission mode. Default: 'auto' */
130
130
  permissions?: 'auto' | 'read-only' | PermissionCallback;
131
+ /**
132
+ * Tool-specific permission rules (e.g., bash='once', read_file='always').
133
+ * When omitted with a PermissionCallback, the agents library's built-in
134
+ * defaults are used (includeDefaults: true).
135
+ */
136
+ permissionRules?: ToolPermission[];
137
+ /**
138
+ * Whether to include the agents library's built-in default permission rules.
139
+ * Default: true when a PermissionCallback is provided, false otherwise.
140
+ */
141
+ includeDefaultRules?: boolean;
131
142
  /** Guardrail configuration. Default: true */
132
143
  guardrails?: boolean | GuardrailConfig;
133
144
  /** Lifecycle hooks */
package/dist/index.d.ts CHANGED
@@ -59,5 +59,7 @@ export { STEP_ORDER, GUIDED_STEP_CRITERIA, getNextStep, isValidTransition, getSt
59
59
  export { platformSkills, designSkill, sketchSkill, prdSkill, refineSkill, refineItemSkill, architectureSkill, sessionNotesSkill, buildSkill, scaffoldSkill, } from './skills/index.js';
60
60
  export { defineTool, createSuccessResult, createErrorResult, mergeHooks, createLoggingHooks, createClaudeProvider, createOpenAIProvider, createGeminiNativeProvider, createOllamaProvider, createTogetherProvider, createGroqProvider, createFireworksProvider, createPerplexityProvider, createOpenRouterProvider, createMockProvider, MockProvider, Agent, ContextManager, DEFAULT_CONTEXT_CONFIG, createTaskTool, createSuggestTool, defaultAgentTypes, TOOL_SETS, BUILTIN_GUARDRAILS, TOOL_NAMES, getDefaultShellManager, builtinSkills, AnchorManager, MCPManager, AgentError, ProviderError, ToolError, ToolTimeoutError, MaxIterationsError, AbortError, } from '@compilr-dev/agents';
61
61
  export type { Tool, HooksConfig, AgentEvent, Message, LLMProvider, AnchorInput, ToolExecutionResult, AgentRunResult, PermissionHandler, ToolPermission, AgentTypeConfig, GuardrailTriggeredHandler, BeforeLLMHookResult, BeforeToolHook, BeforeToolHookResult, AfterToolHook, AgentState, AgentConfig, SessionInfo, Anchor, AnchorScope, AnchorClearOptions, AnchorPriority, AnchorQueryOptions, FileAccessType, FileAccess, GuardrailResult, GuardrailContext, MCPClient, MCPToolDefinition, } from '@compilr-dev/agents';
62
+ export { DEFAULT_PERMISSION_RULES, findMatchingRule, permissionModeLabel, permissionLevelLabel, } from './permissions.js';
63
+ export type { PermissionRule, PermissionMode, PermissionLevel } from './permissions.js';
62
64
  export { readFileTool, writeFileTool, createBashTool, bashTool, bashOutputTool, killShellTool, grepTool, globTool, editTool, todoWriteTool, todoReadTool, createTodoTools, TodoStore, webFetchTool, suggestTool, } from '@compilr-dev/agents';
63
65
  export { gitStatusTool, gitDiffTool, gitLogTool, gitCommitTool, gitBranchTool, gitStashTool, gitBlameTool, gitFileHistoryTool, detectProjectTool, findProjectRootTool, runTestsTool, runLintTool, runBuildTool, runFormatTool, findDefinitionTool, findReferencesTool, findTodosTool, checkOutdatedTool, findVulnerabilitiesTool, analyzeTestCoverageTool, getFileStructureTool, getComplexityTool, allCodingTools, unifiedTools, } from '@compilr-dev/agents-coding';
package/dist/index.js CHANGED
@@ -153,6 +153,10 @@ MCPManager,
153
153
  // Error types
154
154
  AgentError, ProviderError, ToolError, ToolTimeoutError, MaxIterationsError, AbortError, } from '@compilr-dev/agents';
155
155
  // =============================================================================
156
+ // Shared Permission Defaults & Utilities
157
+ // =============================================================================
158
+ export { DEFAULT_PERMISSION_RULES, findMatchingRule, permissionModeLabel, permissionLevelLabel, } from './permissions.js';
159
+ // =============================================================================
156
160
  // Individual Tool Re-exports (for consumers that build custom tool registries)
157
161
  // =============================================================================
158
162
  // Base tools from @compilr-dev/agents
@@ -0,0 +1,51 @@
1
+ /**
2
+ * Shared permission types and defaults for CLI and Desktop.
3
+ *
4
+ * Both consumers define the same default rules and modes. This module
5
+ * provides a single source of truth so they stay in sync.
6
+ */
7
+ import type { ToolPermission } from '@compilr-dev/agents';
8
+ /**
9
+ * Permission level for a tool.
10
+ * Re-exported from agents for convenience.
11
+ */
12
+ export type PermissionLevel = 'always' | 'session' | 'once' | 'deny';
13
+ /**
14
+ * Extended permission rule with UI metadata.
15
+ * Extends ToolPermission with an isDefault flag so UIs can distinguish
16
+ * built-in rules from user-customized ones (default rules cannot be deleted).
17
+ */
18
+ export interface PermissionRule extends ToolPermission {
19
+ /** True for built-in rules (cannot be deleted, only level can be changed) */
20
+ isDefault?: boolean;
21
+ }
22
+ /**
23
+ * Global permission mode controlling how the permission system behaves.
24
+ * - 'normal': Use rule-based checking (check each tool's configured level)
25
+ * - 'plan': Always prompt before any tool execution (ignores rules)
26
+ * - 'auto-accept': Allow everything without prompting
27
+ */
28
+ export type PermissionMode = 'normal' | 'plan' | 'auto-accept';
29
+ /**
30
+ * Default permission rules shared between CLI and Desktop.
31
+ *
32
+ * The model is "allow by default, restrict dangerous tools":
33
+ * - Read-only tools (read_file, glob, grep) → always allowed
34
+ * - Write/execute tools (bash, write_file, edit) → ask once per invocation
35
+ * - Git mutating tools (git_commit, git_branch) → ask once
36
+ * - Runner tools (run_tests, run_lint) → ask once
37
+ */
38
+ export declare const DEFAULT_PERMISSION_RULES: PermissionRule[];
39
+ /**
40
+ * Find the matching permission rule for a tool name.
41
+ * Checks exact match first, then wildcard patterns (e.g., git_* matches git_commit).
42
+ */
43
+ export declare function findMatchingRule(rules: PermissionRule[], toolName: string): PermissionRule | null;
44
+ /**
45
+ * Display label for a permission mode.
46
+ */
47
+ export declare function permissionModeLabel(mode: PermissionMode): string;
48
+ /**
49
+ * Display label for a permission level.
50
+ */
51
+ export declare function permissionLevelLabel(level: PermissionLevel): string;
@@ -0,0 +1,85 @@
1
+ /**
2
+ * Shared permission types and defaults for CLI and Desktop.
3
+ *
4
+ * Both consumers define the same default rules and modes. This module
5
+ * provides a single source of truth so they stay in sync.
6
+ */
7
+ // =============================================================================
8
+ // Default Rules
9
+ // =============================================================================
10
+ /**
11
+ * Default permission rules shared between CLI and Desktop.
12
+ *
13
+ * The model is "allow by default, restrict dangerous tools":
14
+ * - Read-only tools (read_file, glob, grep) → always allowed
15
+ * - Write/execute tools (bash, write_file, edit) → ask once per invocation
16
+ * - Git mutating tools (git_commit, git_branch) → ask once
17
+ * - Runner tools (run_tests, run_lint) → ask once
18
+ */
19
+ export const DEFAULT_PERMISSION_RULES = [
20
+ { toolName: 'bash', level: 'once', description: 'Execute shell commands', isDefault: true },
21
+ { toolName: 'write_file', level: 'once', description: 'Write/create files', isDefault: true },
22
+ { toolName: 'edit', level: 'once', description: 'Edit file contents', isDefault: true },
23
+ { toolName: 'git_commit', level: 'once', description: 'Create git commits', isDefault: true },
24
+ { toolName: 'git_branch', level: 'once', description: 'Create/delete branches', isDefault: true },
25
+ { toolName: 'run_tests', level: 'once', description: 'Run test suite', isDefault: true },
26
+ {
27
+ toolName: 'run_lint',
28
+ level: 'once',
29
+ description: 'Run linter (may auto-fix)',
30
+ isDefault: true,
31
+ },
32
+ { toolName: 'read_file', level: 'always', description: 'Read files', isDefault: true },
33
+ { toolName: 'glob', level: 'always', description: 'Find files by pattern', isDefault: true },
34
+ { toolName: 'grep', level: 'always', description: 'Search file contents', isDefault: true },
35
+ ];
36
+ // =============================================================================
37
+ // Utilities
38
+ // =============================================================================
39
+ /**
40
+ * Find the matching permission rule for a tool name.
41
+ * Checks exact match first, then wildcard patterns (e.g., git_* matches git_commit).
42
+ */
43
+ export function findMatchingRule(rules, toolName) {
44
+ // Exact match first
45
+ const exact = rules.find((r) => r.toolName === toolName);
46
+ if (exact)
47
+ return exact;
48
+ // Wildcard match (e.g., git_* → /^git_.*$/)
49
+ for (const rule of rules) {
50
+ if (rule.toolName.includes('*')) {
51
+ const pattern = new RegExp('^' + rule.toolName.replace(/\*/g, '.*') + '$');
52
+ if (pattern.test(toolName))
53
+ return rule;
54
+ }
55
+ }
56
+ return null;
57
+ }
58
+ /**
59
+ * Display label for a permission mode.
60
+ */
61
+ export function permissionModeLabel(mode) {
62
+ switch (mode) {
63
+ case 'normal':
64
+ return 'Normal';
65
+ case 'plan':
66
+ return 'Plan (ask for everything)';
67
+ case 'auto-accept':
68
+ return 'Auto-accept (no prompts)';
69
+ }
70
+ }
71
+ /**
72
+ * Display label for a permission level.
73
+ */
74
+ export function permissionLevelLabel(level) {
75
+ switch (level) {
76
+ case 'always':
77
+ return 'Always allow';
78
+ case 'session':
79
+ return 'Ask once per session';
80
+ case 'once':
81
+ return 'Ask every time';
82
+ case 'deny':
83
+ return 'Always deny';
84
+ }
85
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@compilr-dev/sdk",
3
- "version": "0.2.0",
3
+ "version": "0.2.2",
4
4
  "description": "Universal agent runtime for building AI-powered applications",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",