@compilr-dev/sdk 0.2.1 → 0.2.3
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 +4 -0
- package/dist/index.js +8 -0
- package/dist/mcp-config.d.ts +74 -0
- package/dist/mcp-config.js +124 -0
- package/dist/permissions.d.ts +51 -0
- package/dist/permissions.js +85 -0
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -59,5 +59,9 @@ 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';
|
|
64
|
+
export { readMCPConfigFile, writeMCPConfigFile, resolveServerEntry, loadMCPServers, saveMCPServerEntry, deleteMCPServerEntry, getServerNames, } from './mcp-config.js';
|
|
65
|
+
export type { MCPServerEntry, MCPConfigFile, ResolvedMCPServer } from './mcp-config.js';
|
|
62
66
|
export { readFileTool, writeFileTool, createBashTool, bashTool, bashOutputTool, killShellTool, grepTool, globTool, editTool, todoWriteTool, todoReadTool, createTodoTools, TodoStore, webFetchTool, suggestTool, } from '@compilr-dev/agents';
|
|
63
67
|
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,14 @@ 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
|
+
// =============================================================================
|
|
160
|
+
// Shared MCP Configuration
|
|
161
|
+
// =============================================================================
|
|
162
|
+
export { readMCPConfigFile, writeMCPConfigFile, resolveServerEntry, loadMCPServers, saveMCPServerEntry, deleteMCPServerEntry, getServerNames, } from './mcp-config.js';
|
|
163
|
+
// =============================================================================
|
|
156
164
|
// Individual Tool Re-exports (for consumers that build custom tool registries)
|
|
157
165
|
// =============================================================================
|
|
158
166
|
// Base tools from @compilr-dev/agents
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* MCP Configuration — shared types and file I/O for mcp.json
|
|
3
|
+
*
|
|
4
|
+
* Used by both @compilr-dev/cli and compilr-dev-desktop.
|
|
5
|
+
* Config format is compatible with Claude Desktop / Gemini CLI.
|
|
6
|
+
*
|
|
7
|
+
* File structure:
|
|
8
|
+
* { "mcpServers": { "name": { command?, url?, ... } } }
|
|
9
|
+
*/
|
|
10
|
+
/**
|
|
11
|
+
* Single MCP server entry in the config file.
|
|
12
|
+
* If `command` is present → stdio transport.
|
|
13
|
+
* If `url` is present → HTTP transport.
|
|
14
|
+
*/
|
|
15
|
+
export interface MCPServerEntry {
|
|
16
|
+
command?: string;
|
|
17
|
+
args?: string[];
|
|
18
|
+
env?: Record<string, string>;
|
|
19
|
+
cwd?: string;
|
|
20
|
+
url?: string;
|
|
21
|
+
headers?: Record<string, string>;
|
|
22
|
+
disabled?: boolean;
|
|
23
|
+
timeout?: number;
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* Shape of the mcp.json config file.
|
|
27
|
+
*/
|
|
28
|
+
export interface MCPConfigFile {
|
|
29
|
+
mcpServers: Record<string, MCPServerEntry>;
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* Resolved MCP server config ready for MCPManager.
|
|
33
|
+
*/
|
|
34
|
+
export interface ResolvedMCPServer {
|
|
35
|
+
name: string;
|
|
36
|
+
transport: 'stdio' | 'http';
|
|
37
|
+
command?: string;
|
|
38
|
+
args?: string[];
|
|
39
|
+
env?: Record<string, string>;
|
|
40
|
+
cwd?: string;
|
|
41
|
+
url?: string;
|
|
42
|
+
headers?: Record<string, string>;
|
|
43
|
+
timeout?: number;
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* Read and parse an mcp.json file. Returns empty record on any error.
|
|
47
|
+
*/
|
|
48
|
+
export declare function readMCPConfigFile(filePath: string): Record<string, MCPServerEntry>;
|
|
49
|
+
/**
|
|
50
|
+
* Write servers to an mcp.json file (creates directory if needed).
|
|
51
|
+
*/
|
|
52
|
+
export declare function writeMCPConfigFile(filePath: string, servers: Record<string, MCPServerEntry>): void;
|
|
53
|
+
/**
|
|
54
|
+
* Convert an MCPServerEntry to a ResolvedMCPServer.
|
|
55
|
+
* Returns null if the entry is invalid (neither command nor url) or disabled.
|
|
56
|
+
*/
|
|
57
|
+
export declare function resolveServerEntry(name: string, entry: MCPServerEntry): ResolvedMCPServer | null;
|
|
58
|
+
/**
|
|
59
|
+
* Load and resolve MCP servers from one or more config file paths.
|
|
60
|
+
* Later paths override earlier ones (by server name).
|
|
61
|
+
*/
|
|
62
|
+
export declare function loadMCPServers(...configPaths: string[]): ResolvedMCPServer[];
|
|
63
|
+
/**
|
|
64
|
+
* Save a single MCP server entry to a config file (add or overwrite by name).
|
|
65
|
+
*/
|
|
66
|
+
export declare function saveMCPServerEntry(filePath: string, name: string, entry: MCPServerEntry): void;
|
|
67
|
+
/**
|
|
68
|
+
* Delete a single MCP server entry from a config file.
|
|
69
|
+
*/
|
|
70
|
+
export declare function deleteMCPServerEntry(filePath: string, name: string): void;
|
|
71
|
+
/**
|
|
72
|
+
* Get all server names from one or more config files.
|
|
73
|
+
*/
|
|
74
|
+
export declare function getServerNames(...configPaths: string[]): Set<string>;
|
|
@@ -0,0 +1,124 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* MCP Configuration — shared types and file I/O for mcp.json
|
|
3
|
+
*
|
|
4
|
+
* Used by both @compilr-dev/cli and compilr-dev-desktop.
|
|
5
|
+
* Config format is compatible with Claude Desktop / Gemini CLI.
|
|
6
|
+
*
|
|
7
|
+
* File structure:
|
|
8
|
+
* { "mcpServers": { "name": { command?, url?, ... } } }
|
|
9
|
+
*/
|
|
10
|
+
import { existsSync, readFileSync, writeFileSync, mkdirSync } from 'fs';
|
|
11
|
+
import { dirname } from 'path';
|
|
12
|
+
// =============================================================================
|
|
13
|
+
// File I/O
|
|
14
|
+
// =============================================================================
|
|
15
|
+
/**
|
|
16
|
+
* Read and parse an mcp.json file. Returns empty record on any error.
|
|
17
|
+
*/
|
|
18
|
+
export function readMCPConfigFile(filePath) {
|
|
19
|
+
try {
|
|
20
|
+
if (!existsSync(filePath))
|
|
21
|
+
return {};
|
|
22
|
+
const data = readFileSync(filePath, 'utf-8');
|
|
23
|
+
const parsed = JSON.parse(data);
|
|
24
|
+
if (parsed.mcpServers && typeof parsed.mcpServers === 'object') {
|
|
25
|
+
return parsed.mcpServers;
|
|
26
|
+
}
|
|
27
|
+
return {};
|
|
28
|
+
}
|
|
29
|
+
catch {
|
|
30
|
+
return {};
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* Write servers to an mcp.json file (creates directory if needed).
|
|
35
|
+
*/
|
|
36
|
+
export function writeMCPConfigFile(filePath, servers) {
|
|
37
|
+
const dir = dirname(filePath);
|
|
38
|
+
if (!existsSync(dir)) {
|
|
39
|
+
mkdirSync(dir, { recursive: true });
|
|
40
|
+
}
|
|
41
|
+
const config = { mcpServers: servers };
|
|
42
|
+
writeFileSync(filePath, JSON.stringify(config, null, 2) + '\n', 'utf-8');
|
|
43
|
+
}
|
|
44
|
+
// =============================================================================
|
|
45
|
+
// Resolution
|
|
46
|
+
// =============================================================================
|
|
47
|
+
/**
|
|
48
|
+
* Convert an MCPServerEntry to a ResolvedMCPServer.
|
|
49
|
+
* Returns null if the entry is invalid (neither command nor url) or disabled.
|
|
50
|
+
*/
|
|
51
|
+
export function resolveServerEntry(name, entry) {
|
|
52
|
+
if (entry.disabled)
|
|
53
|
+
return null;
|
|
54
|
+
if (entry.command) {
|
|
55
|
+
return {
|
|
56
|
+
name,
|
|
57
|
+
transport: 'stdio',
|
|
58
|
+
command: entry.command,
|
|
59
|
+
args: entry.args,
|
|
60
|
+
env: entry.env,
|
|
61
|
+
cwd: entry.cwd,
|
|
62
|
+
timeout: entry.timeout,
|
|
63
|
+
};
|
|
64
|
+
}
|
|
65
|
+
if (entry.url) {
|
|
66
|
+
return {
|
|
67
|
+
name,
|
|
68
|
+
transport: 'http',
|
|
69
|
+
url: entry.url,
|
|
70
|
+
headers: entry.headers,
|
|
71
|
+
timeout: entry.timeout,
|
|
72
|
+
};
|
|
73
|
+
}
|
|
74
|
+
return null;
|
|
75
|
+
}
|
|
76
|
+
// =============================================================================
|
|
77
|
+
// High-level helpers
|
|
78
|
+
// =============================================================================
|
|
79
|
+
/**
|
|
80
|
+
* Load and resolve MCP servers from one or more config file paths.
|
|
81
|
+
* Later paths override earlier ones (by server name).
|
|
82
|
+
*/
|
|
83
|
+
export function loadMCPServers(...configPaths) {
|
|
84
|
+
const merged = {};
|
|
85
|
+
for (const p of configPaths) {
|
|
86
|
+
const servers = readMCPConfigFile(p);
|
|
87
|
+
Object.assign(merged, servers);
|
|
88
|
+
}
|
|
89
|
+
const resolved = [];
|
|
90
|
+
for (const [name, entry] of Object.entries(merged)) {
|
|
91
|
+
const server = resolveServerEntry(name, entry);
|
|
92
|
+
if (server)
|
|
93
|
+
resolved.push(server);
|
|
94
|
+
}
|
|
95
|
+
return resolved;
|
|
96
|
+
}
|
|
97
|
+
/**
|
|
98
|
+
* Save a single MCP server entry to a config file (add or overwrite by name).
|
|
99
|
+
*/
|
|
100
|
+
export function saveMCPServerEntry(filePath, name, entry) {
|
|
101
|
+
const servers = readMCPConfigFile(filePath);
|
|
102
|
+
servers[name] = entry;
|
|
103
|
+
writeMCPConfigFile(filePath, servers);
|
|
104
|
+
}
|
|
105
|
+
/**
|
|
106
|
+
* Delete a single MCP server entry from a config file.
|
|
107
|
+
*/
|
|
108
|
+
export function deleteMCPServerEntry(filePath, name) {
|
|
109
|
+
const servers = readMCPConfigFile(filePath);
|
|
110
|
+
const { [name]: _, ...rest } = servers;
|
|
111
|
+
writeMCPConfigFile(filePath, rest);
|
|
112
|
+
}
|
|
113
|
+
/**
|
|
114
|
+
* Get all server names from one or more config files.
|
|
115
|
+
*/
|
|
116
|
+
export function getServerNames(...configPaths) {
|
|
117
|
+
const names = new Set();
|
|
118
|
+
for (const p of configPaths) {
|
|
119
|
+
for (const name of Object.keys(readMCPConfigFile(p))) {
|
|
120
|
+
names.add(name);
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
return names;
|
|
124
|
+
}
|
|
@@ -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
|
+
}
|