coding-agent-adapters 0.2.19 → 0.3.0
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/README.md +72 -0
- package/dist/index.cjs +419 -0
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +75 -9
- package/dist/index.d.ts +75 -9
- package/dist/index.js +408 -2
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.d.cts
CHANGED
|
@@ -1,5 +1,61 @@
|
|
|
1
1
|
import { BaseCLIAdapter, SpawnConfig, AutoResponseRule, LoginDetection, BlockingPromptDetection, ParsedOutput } from 'pty-manager';
|
|
2
2
|
|
|
3
|
+
/**
|
|
4
|
+
* Shared types for coding-agent-adapters
|
|
5
|
+
*/
|
|
6
|
+
/**
|
|
7
|
+
* Supported adapter types
|
|
8
|
+
*/
|
|
9
|
+
type AdapterType = 'claude' | 'gemini' | 'codex' | 'aider';
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* Approval Presets
|
|
13
|
+
*
|
|
14
|
+
* Unified preset system for controlling tool permissions across all supported
|
|
15
|
+
* coding agent CLIs. Each preset translates to the correct per-CLI config
|
|
16
|
+
* format (JSON settings files, CLI flags, env vars).
|
|
17
|
+
*/
|
|
18
|
+
|
|
19
|
+
type ToolCategory = 'file_read' | 'file_write' | 'shell' | 'web' | 'agent' | 'planning' | 'user_interaction';
|
|
20
|
+
type RiskLevel = 'low' | 'medium' | 'high';
|
|
21
|
+
type ApprovalPreset = 'readonly' | 'standard' | 'permissive' | 'autonomous';
|
|
22
|
+
interface ToolCategoryInfo {
|
|
23
|
+
category: ToolCategory;
|
|
24
|
+
risk: RiskLevel;
|
|
25
|
+
description: string;
|
|
26
|
+
}
|
|
27
|
+
interface PresetDefinition {
|
|
28
|
+
preset: ApprovalPreset;
|
|
29
|
+
description: string;
|
|
30
|
+
autoApprove: ToolCategory[];
|
|
31
|
+
requireApproval: ToolCategory[];
|
|
32
|
+
blocked: ToolCategory[];
|
|
33
|
+
}
|
|
34
|
+
interface ApprovalConfig {
|
|
35
|
+
preset: ApprovalPreset;
|
|
36
|
+
cliFlags: string[];
|
|
37
|
+
workspaceFiles: Array<{
|
|
38
|
+
relativePath: string;
|
|
39
|
+
content: string;
|
|
40
|
+
format: 'json' | 'yaml' | 'toml';
|
|
41
|
+
}>;
|
|
42
|
+
envVars: Record<string, string>;
|
|
43
|
+
summary: string;
|
|
44
|
+
}
|
|
45
|
+
declare const TOOL_CATEGORIES: ToolCategoryInfo[];
|
|
46
|
+
declare const PRESET_DEFINITIONS: PresetDefinition[];
|
|
47
|
+
declare const CLAUDE_TOOL_CATEGORIES: Record<string, ToolCategory>;
|
|
48
|
+
declare const GEMINI_TOOL_CATEGORIES: Record<string, ToolCategory>;
|
|
49
|
+
declare const CODEX_TOOL_CATEGORIES: Record<string, ToolCategory>;
|
|
50
|
+
declare const AIDER_COMMAND_CATEGORIES: Record<string, ToolCategory>;
|
|
51
|
+
declare function generateClaudeApprovalConfig(preset: ApprovalPreset): ApprovalConfig;
|
|
52
|
+
declare function generateGeminiApprovalConfig(preset: ApprovalPreset): ApprovalConfig;
|
|
53
|
+
declare function generateCodexApprovalConfig(preset: ApprovalPreset): ApprovalConfig;
|
|
54
|
+
declare function generateAiderApprovalConfig(preset: ApprovalPreset): ApprovalConfig;
|
|
55
|
+
declare function generateApprovalConfig(adapterType: AdapterType, preset: ApprovalPreset): ApprovalConfig;
|
|
56
|
+
declare function listPresets(): PresetDefinition[];
|
|
57
|
+
declare function getPresetDefinition(preset: ApprovalPreset): PresetDefinition;
|
|
58
|
+
|
|
3
59
|
/**
|
|
4
60
|
* Base Coding Agent Adapter
|
|
5
61
|
*
|
|
@@ -80,6 +136,11 @@ interface CodingAgentConfig extends SpawnConfig {
|
|
|
80
136
|
* pick its best model for that provider automatically.
|
|
81
137
|
*/
|
|
82
138
|
provider?: 'anthropic' | 'openai' | 'google';
|
|
139
|
+
/**
|
|
140
|
+
* Approval preset controlling tool permissions.
|
|
141
|
+
* Translates to CLI-specific config files and flags.
|
|
142
|
+
*/
|
|
143
|
+
approvalPreset?: ApprovalPreset;
|
|
83
144
|
} & Record<string, unknown>;
|
|
84
145
|
}
|
|
85
146
|
/**
|
|
@@ -146,6 +207,19 @@ declare abstract class BaseCodingAdapter extends BaseCLIAdapter {
|
|
|
146
207
|
* Extract the main content from CLI output, removing common artifacts
|
|
147
208
|
*/
|
|
148
209
|
protected extractContent(output: string, promptPattern: RegExp): string;
|
|
210
|
+
/**
|
|
211
|
+
* Extract the approval preset from a spawn config, if set.
|
|
212
|
+
*/
|
|
213
|
+
protected getApprovalPreset(config: SpawnConfig): ApprovalPreset | undefined;
|
|
214
|
+
/**
|
|
215
|
+
* Generate the approval config for this adapter, if a preset is set.
|
|
216
|
+
*/
|
|
217
|
+
getApprovalConfig(config: SpawnConfig): ApprovalConfig | null;
|
|
218
|
+
/**
|
|
219
|
+
* Write approval config files to a workspace directory.
|
|
220
|
+
* Returns the list of files written (absolute paths).
|
|
221
|
+
*/
|
|
222
|
+
writeApprovalConfig(workspacePath: string, config: SpawnConfig): Promise<string[]>;
|
|
149
223
|
/**
|
|
150
224
|
* Write content to this agent's memory file in a workspace.
|
|
151
225
|
* Creates parent directories as needed.
|
|
@@ -319,14 +393,6 @@ declare class AiderAdapter extends BaseCodingAdapter {
|
|
|
319
393
|
getHealthCheckCommand(): string;
|
|
320
394
|
}
|
|
321
395
|
|
|
322
|
-
/**
|
|
323
|
-
* Shared types for coding-agent-adapters
|
|
324
|
-
*/
|
|
325
|
-
/**
|
|
326
|
-
* Supported adapter types
|
|
327
|
-
*/
|
|
328
|
-
type AdapterType = 'claude' | 'gemini' | 'codex' | 'aider';
|
|
329
|
-
|
|
330
396
|
/**
|
|
331
397
|
* Dynamic Pattern Loader
|
|
332
398
|
*
|
|
@@ -481,4 +547,4 @@ declare function checkAllAdapters(): Promise<PreflightResult[]>;
|
|
|
481
547
|
*/
|
|
482
548
|
declare function printMissingAdapters(types?: AdapterType[]): Promise<void>;
|
|
483
549
|
|
|
484
|
-
export { ADAPTER_TYPES, type AdapterPatterns, type AdapterType, type AgentCredentials, type AgentFileDescriptor, AiderAdapter, BaseCodingAdapter, ClaudeAdapter, CodexAdapter, type CodingAgentConfig, GeminiAdapter, type InstallationInfo, type ModelRecommendations, type PreflightResult, type WriteMemoryOptions, checkAdapters, checkAllAdapters, clearPatternCache, createAdapter, createAllAdapters, getBaselinePatterns, hasDynamicPatterns, loadPatterns, loadPatternsSync, preloadAllPatterns, printMissingAdapters };
|
|
550
|
+
export { ADAPTER_TYPES, AIDER_COMMAND_CATEGORIES, type AdapterPatterns, type AdapterType, type AgentCredentials, type AgentFileDescriptor, AiderAdapter, type ApprovalConfig, type ApprovalPreset, BaseCodingAdapter, CLAUDE_TOOL_CATEGORIES, CODEX_TOOL_CATEGORIES, ClaudeAdapter, CodexAdapter, type CodingAgentConfig, GEMINI_TOOL_CATEGORIES, GeminiAdapter, type InstallationInfo, type ModelRecommendations, PRESET_DEFINITIONS, type PreflightResult, type PresetDefinition, type RiskLevel, TOOL_CATEGORIES, type ToolCategory, type ToolCategoryInfo, type WriteMemoryOptions, checkAdapters, checkAllAdapters, clearPatternCache, createAdapter, createAllAdapters, generateAiderApprovalConfig, generateApprovalConfig, generateClaudeApprovalConfig, generateCodexApprovalConfig, generateGeminiApprovalConfig, getBaselinePatterns, getPresetDefinition, hasDynamicPatterns, listPresets, loadPatterns, loadPatternsSync, preloadAllPatterns, printMissingAdapters };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,61 @@
|
|
|
1
1
|
import { BaseCLIAdapter, SpawnConfig, AutoResponseRule, LoginDetection, BlockingPromptDetection, ParsedOutput } from 'pty-manager';
|
|
2
2
|
|
|
3
|
+
/**
|
|
4
|
+
* Shared types for coding-agent-adapters
|
|
5
|
+
*/
|
|
6
|
+
/**
|
|
7
|
+
* Supported adapter types
|
|
8
|
+
*/
|
|
9
|
+
type AdapterType = 'claude' | 'gemini' | 'codex' | 'aider';
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* Approval Presets
|
|
13
|
+
*
|
|
14
|
+
* Unified preset system for controlling tool permissions across all supported
|
|
15
|
+
* coding agent CLIs. Each preset translates to the correct per-CLI config
|
|
16
|
+
* format (JSON settings files, CLI flags, env vars).
|
|
17
|
+
*/
|
|
18
|
+
|
|
19
|
+
type ToolCategory = 'file_read' | 'file_write' | 'shell' | 'web' | 'agent' | 'planning' | 'user_interaction';
|
|
20
|
+
type RiskLevel = 'low' | 'medium' | 'high';
|
|
21
|
+
type ApprovalPreset = 'readonly' | 'standard' | 'permissive' | 'autonomous';
|
|
22
|
+
interface ToolCategoryInfo {
|
|
23
|
+
category: ToolCategory;
|
|
24
|
+
risk: RiskLevel;
|
|
25
|
+
description: string;
|
|
26
|
+
}
|
|
27
|
+
interface PresetDefinition {
|
|
28
|
+
preset: ApprovalPreset;
|
|
29
|
+
description: string;
|
|
30
|
+
autoApprove: ToolCategory[];
|
|
31
|
+
requireApproval: ToolCategory[];
|
|
32
|
+
blocked: ToolCategory[];
|
|
33
|
+
}
|
|
34
|
+
interface ApprovalConfig {
|
|
35
|
+
preset: ApprovalPreset;
|
|
36
|
+
cliFlags: string[];
|
|
37
|
+
workspaceFiles: Array<{
|
|
38
|
+
relativePath: string;
|
|
39
|
+
content: string;
|
|
40
|
+
format: 'json' | 'yaml' | 'toml';
|
|
41
|
+
}>;
|
|
42
|
+
envVars: Record<string, string>;
|
|
43
|
+
summary: string;
|
|
44
|
+
}
|
|
45
|
+
declare const TOOL_CATEGORIES: ToolCategoryInfo[];
|
|
46
|
+
declare const PRESET_DEFINITIONS: PresetDefinition[];
|
|
47
|
+
declare const CLAUDE_TOOL_CATEGORIES: Record<string, ToolCategory>;
|
|
48
|
+
declare const GEMINI_TOOL_CATEGORIES: Record<string, ToolCategory>;
|
|
49
|
+
declare const CODEX_TOOL_CATEGORIES: Record<string, ToolCategory>;
|
|
50
|
+
declare const AIDER_COMMAND_CATEGORIES: Record<string, ToolCategory>;
|
|
51
|
+
declare function generateClaudeApprovalConfig(preset: ApprovalPreset): ApprovalConfig;
|
|
52
|
+
declare function generateGeminiApprovalConfig(preset: ApprovalPreset): ApprovalConfig;
|
|
53
|
+
declare function generateCodexApprovalConfig(preset: ApprovalPreset): ApprovalConfig;
|
|
54
|
+
declare function generateAiderApprovalConfig(preset: ApprovalPreset): ApprovalConfig;
|
|
55
|
+
declare function generateApprovalConfig(adapterType: AdapterType, preset: ApprovalPreset): ApprovalConfig;
|
|
56
|
+
declare function listPresets(): PresetDefinition[];
|
|
57
|
+
declare function getPresetDefinition(preset: ApprovalPreset): PresetDefinition;
|
|
58
|
+
|
|
3
59
|
/**
|
|
4
60
|
* Base Coding Agent Adapter
|
|
5
61
|
*
|
|
@@ -80,6 +136,11 @@ interface CodingAgentConfig extends SpawnConfig {
|
|
|
80
136
|
* pick its best model for that provider automatically.
|
|
81
137
|
*/
|
|
82
138
|
provider?: 'anthropic' | 'openai' | 'google';
|
|
139
|
+
/**
|
|
140
|
+
* Approval preset controlling tool permissions.
|
|
141
|
+
* Translates to CLI-specific config files and flags.
|
|
142
|
+
*/
|
|
143
|
+
approvalPreset?: ApprovalPreset;
|
|
83
144
|
} & Record<string, unknown>;
|
|
84
145
|
}
|
|
85
146
|
/**
|
|
@@ -146,6 +207,19 @@ declare abstract class BaseCodingAdapter extends BaseCLIAdapter {
|
|
|
146
207
|
* Extract the main content from CLI output, removing common artifacts
|
|
147
208
|
*/
|
|
148
209
|
protected extractContent(output: string, promptPattern: RegExp): string;
|
|
210
|
+
/**
|
|
211
|
+
* Extract the approval preset from a spawn config, if set.
|
|
212
|
+
*/
|
|
213
|
+
protected getApprovalPreset(config: SpawnConfig): ApprovalPreset | undefined;
|
|
214
|
+
/**
|
|
215
|
+
* Generate the approval config for this adapter, if a preset is set.
|
|
216
|
+
*/
|
|
217
|
+
getApprovalConfig(config: SpawnConfig): ApprovalConfig | null;
|
|
218
|
+
/**
|
|
219
|
+
* Write approval config files to a workspace directory.
|
|
220
|
+
* Returns the list of files written (absolute paths).
|
|
221
|
+
*/
|
|
222
|
+
writeApprovalConfig(workspacePath: string, config: SpawnConfig): Promise<string[]>;
|
|
149
223
|
/**
|
|
150
224
|
* Write content to this agent's memory file in a workspace.
|
|
151
225
|
* Creates parent directories as needed.
|
|
@@ -319,14 +393,6 @@ declare class AiderAdapter extends BaseCodingAdapter {
|
|
|
319
393
|
getHealthCheckCommand(): string;
|
|
320
394
|
}
|
|
321
395
|
|
|
322
|
-
/**
|
|
323
|
-
* Shared types for coding-agent-adapters
|
|
324
|
-
*/
|
|
325
|
-
/**
|
|
326
|
-
* Supported adapter types
|
|
327
|
-
*/
|
|
328
|
-
type AdapterType = 'claude' | 'gemini' | 'codex' | 'aider';
|
|
329
|
-
|
|
330
396
|
/**
|
|
331
397
|
* Dynamic Pattern Loader
|
|
332
398
|
*
|
|
@@ -481,4 +547,4 @@ declare function checkAllAdapters(): Promise<PreflightResult[]>;
|
|
|
481
547
|
*/
|
|
482
548
|
declare function printMissingAdapters(types?: AdapterType[]): Promise<void>;
|
|
483
549
|
|
|
484
|
-
export { ADAPTER_TYPES, type AdapterPatterns, type AdapterType, type AgentCredentials, type AgentFileDescriptor, AiderAdapter, BaseCodingAdapter, ClaudeAdapter, CodexAdapter, type CodingAgentConfig, GeminiAdapter, type InstallationInfo, type ModelRecommendations, type PreflightResult, type WriteMemoryOptions, checkAdapters, checkAllAdapters, clearPatternCache, createAdapter, createAllAdapters, getBaselinePatterns, hasDynamicPatterns, loadPatterns, loadPatternsSync, preloadAllPatterns, printMissingAdapters };
|
|
550
|
+
export { ADAPTER_TYPES, AIDER_COMMAND_CATEGORIES, type AdapterPatterns, type AdapterType, type AgentCredentials, type AgentFileDescriptor, AiderAdapter, type ApprovalConfig, type ApprovalPreset, BaseCodingAdapter, CLAUDE_TOOL_CATEGORIES, CODEX_TOOL_CATEGORIES, ClaudeAdapter, CodexAdapter, type CodingAgentConfig, GEMINI_TOOL_CATEGORIES, GeminiAdapter, type InstallationInfo, type ModelRecommendations, PRESET_DEFINITIONS, type PreflightResult, type PresetDefinition, type RiskLevel, TOOL_CATEGORIES, type ToolCategory, type ToolCategoryInfo, type WriteMemoryOptions, checkAdapters, checkAllAdapters, clearPatternCache, createAdapter, createAllAdapters, generateAiderApprovalConfig, generateApprovalConfig, generateClaudeApprovalConfig, generateCodexApprovalConfig, generateGeminiApprovalConfig, getBaselinePatterns, getPresetDefinition, hasDynamicPatterns, listPresets, loadPatterns, loadPatternsSync, preloadAllPatterns, printMissingAdapters };
|
package/dist/index.js
CHANGED
|
@@ -1,7 +1,363 @@
|
|
|
1
|
-
import { mkdir,
|
|
1
|
+
import { mkdir, writeFile, appendFile } from 'fs/promises';
|
|
2
2
|
import { join, dirname } from 'path';
|
|
3
3
|
import { BaseCLIAdapter } from 'pty-manager';
|
|
4
4
|
|
|
5
|
+
// src/base-coding-adapter.ts
|
|
6
|
+
|
|
7
|
+
// src/approval-presets.ts
|
|
8
|
+
var TOOL_CATEGORIES = [
|
|
9
|
+
{ category: "file_read", risk: "low", description: "Read files, search, list directories" },
|
|
10
|
+
{ category: "file_write", risk: "medium", description: "Write, edit, and create files" },
|
|
11
|
+
{ category: "shell", risk: "high", description: "Execute shell commands" },
|
|
12
|
+
{ category: "web", risk: "medium", description: "Web search and fetch" },
|
|
13
|
+
{ category: "agent", risk: "medium", description: "Spawn sub-agents, skills, MCP tools" },
|
|
14
|
+
{ category: "planning", risk: "low", description: "Task planning and todo management" },
|
|
15
|
+
{ category: "user_interaction", risk: "low", description: "Ask user questions" }
|
|
16
|
+
];
|
|
17
|
+
var PRESET_DEFINITIONS = [
|
|
18
|
+
{
|
|
19
|
+
preset: "readonly",
|
|
20
|
+
description: "Read-only. Safe for auditing.",
|
|
21
|
+
autoApprove: ["file_read", "planning", "user_interaction"],
|
|
22
|
+
requireApproval: [],
|
|
23
|
+
blocked: ["file_write", "shell", "web", "agent"]
|
|
24
|
+
},
|
|
25
|
+
{
|
|
26
|
+
preset: "standard",
|
|
27
|
+
description: "Standard dev. Reads + web auto, writes/shell prompt.",
|
|
28
|
+
autoApprove: ["file_read", "planning", "user_interaction", "web"],
|
|
29
|
+
requireApproval: ["file_write", "shell", "agent"],
|
|
30
|
+
blocked: []
|
|
31
|
+
},
|
|
32
|
+
{
|
|
33
|
+
preset: "permissive",
|
|
34
|
+
description: "File ops auto-approved, shell still prompts.",
|
|
35
|
+
autoApprove: ["file_read", "file_write", "planning", "user_interaction", "web", "agent"],
|
|
36
|
+
requireApproval: ["shell"],
|
|
37
|
+
blocked: []
|
|
38
|
+
},
|
|
39
|
+
{
|
|
40
|
+
preset: "autonomous",
|
|
41
|
+
description: "Everything auto-approved. Use with sandbox.",
|
|
42
|
+
autoApprove: ["file_read", "file_write", "shell", "web", "agent", "planning", "user_interaction"],
|
|
43
|
+
requireApproval: [],
|
|
44
|
+
blocked: []
|
|
45
|
+
}
|
|
46
|
+
];
|
|
47
|
+
var CLAUDE_TOOL_CATEGORIES = {
|
|
48
|
+
// file_read
|
|
49
|
+
Read: "file_read",
|
|
50
|
+
Grep: "file_read",
|
|
51
|
+
Glob: "file_read",
|
|
52
|
+
LS: "file_read",
|
|
53
|
+
NotebookRead: "file_read",
|
|
54
|
+
// file_write
|
|
55
|
+
Write: "file_write",
|
|
56
|
+
Edit: "file_write",
|
|
57
|
+
// shell
|
|
58
|
+
Bash: "shell",
|
|
59
|
+
BashOutput: "shell",
|
|
60
|
+
KillShell: "shell",
|
|
61
|
+
// web
|
|
62
|
+
WebSearch: "web",
|
|
63
|
+
WebFetch: "web",
|
|
64
|
+
// agent
|
|
65
|
+
Task: "agent",
|
|
66
|
+
Skill: "agent",
|
|
67
|
+
// planning
|
|
68
|
+
TodoWrite: "planning",
|
|
69
|
+
// user_interaction
|
|
70
|
+
AskUserQuestion: "user_interaction"
|
|
71
|
+
};
|
|
72
|
+
var GEMINI_TOOL_CATEGORIES = {
|
|
73
|
+
// file_read
|
|
74
|
+
read_file: "file_read",
|
|
75
|
+
read_many_files: "file_read",
|
|
76
|
+
list_directory: "file_read",
|
|
77
|
+
glob: "file_read",
|
|
78
|
+
search_file_content: "file_read",
|
|
79
|
+
// file_write
|
|
80
|
+
write_file: "file_write",
|
|
81
|
+
replace: "file_write",
|
|
82
|
+
// shell
|
|
83
|
+
run_shell_command: "shell",
|
|
84
|
+
// web
|
|
85
|
+
web_fetch: "web",
|
|
86
|
+
google_web_search: "web",
|
|
87
|
+
// agent
|
|
88
|
+
activate_skill: "agent",
|
|
89
|
+
get_internal_docs: "agent",
|
|
90
|
+
// planning
|
|
91
|
+
save_memory: "planning",
|
|
92
|
+
write_todos: "planning",
|
|
93
|
+
// user_interaction
|
|
94
|
+
ask_user: "user_interaction"
|
|
95
|
+
};
|
|
96
|
+
var CODEX_TOOL_CATEGORIES = {
|
|
97
|
+
// shell (codex uses shell for most operations)
|
|
98
|
+
exec_command: "shell",
|
|
99
|
+
write_stdin: "shell",
|
|
100
|
+
shell_command: "shell",
|
|
101
|
+
// file_write
|
|
102
|
+
apply_patch: "file_write",
|
|
103
|
+
// file_read
|
|
104
|
+
grep_files: "file_read",
|
|
105
|
+
read_file: "file_read",
|
|
106
|
+
list_dir: "file_read",
|
|
107
|
+
// web
|
|
108
|
+
web_search: "web",
|
|
109
|
+
view_image: "web",
|
|
110
|
+
// agent
|
|
111
|
+
spawn_agent: "agent",
|
|
112
|
+
send_input: "agent",
|
|
113
|
+
resume_agent: "agent",
|
|
114
|
+
wait: "agent",
|
|
115
|
+
close_agent: "agent",
|
|
116
|
+
// planning
|
|
117
|
+
update_plan: "planning",
|
|
118
|
+
// user_interaction
|
|
119
|
+
request_user_input: "user_interaction"
|
|
120
|
+
};
|
|
121
|
+
var AIDER_COMMAND_CATEGORIES = {
|
|
122
|
+
// file_read
|
|
123
|
+
"/read-only": "file_read",
|
|
124
|
+
"/ls": "file_read",
|
|
125
|
+
"/map": "file_read",
|
|
126
|
+
"/map-refresh": "file_read",
|
|
127
|
+
"/tokens": "file_read",
|
|
128
|
+
"/diff": "file_read",
|
|
129
|
+
"/context": "file_read",
|
|
130
|
+
// file_write
|
|
131
|
+
"/add": "file_write",
|
|
132
|
+
"/drop": "file_write",
|
|
133
|
+
"/edit": "file_write",
|
|
134
|
+
"/code": "file_write",
|
|
135
|
+
"/architect": "file_write",
|
|
136
|
+
"/undo": "file_write",
|
|
137
|
+
// shell
|
|
138
|
+
"/run": "shell",
|
|
139
|
+
"/test": "shell",
|
|
140
|
+
"/lint": "shell",
|
|
141
|
+
"/git": "shell",
|
|
142
|
+
// web
|
|
143
|
+
"/web": "web",
|
|
144
|
+
// planning
|
|
145
|
+
"/ask": "planning",
|
|
146
|
+
// user_interaction
|
|
147
|
+
"/voice": "user_interaction",
|
|
148
|
+
"/help": "user_interaction",
|
|
149
|
+
// config/other
|
|
150
|
+
"/model": "planning",
|
|
151
|
+
"/settings": "planning",
|
|
152
|
+
"/commit": "file_write",
|
|
153
|
+
"/clear": "planning",
|
|
154
|
+
"/reset": "planning"
|
|
155
|
+
};
|
|
156
|
+
function getToolsForCategories(mapping, categories) {
|
|
157
|
+
return Object.entries(mapping).filter(([, cat]) => categories.includes(cat)).map(([tool]) => tool);
|
|
158
|
+
}
|
|
159
|
+
function generateClaudeApprovalConfig(preset) {
|
|
160
|
+
const def = getPresetDefinition(preset);
|
|
161
|
+
const allowTools = getToolsForCategories(CLAUDE_TOOL_CATEGORIES, def.autoApprove);
|
|
162
|
+
const denyTools = getToolsForCategories(CLAUDE_TOOL_CATEGORIES, def.blocked);
|
|
163
|
+
const settings = {
|
|
164
|
+
permissions: {}
|
|
165
|
+
};
|
|
166
|
+
const permissions = settings.permissions;
|
|
167
|
+
if (allowTools.length > 0) {
|
|
168
|
+
permissions.allow = allowTools;
|
|
169
|
+
}
|
|
170
|
+
if (denyTools.length > 0) {
|
|
171
|
+
permissions.deny = denyTools;
|
|
172
|
+
}
|
|
173
|
+
if (preset === "autonomous") {
|
|
174
|
+
settings.sandbox = {
|
|
175
|
+
enabled: true,
|
|
176
|
+
autoAllowBashIfSandboxed: true
|
|
177
|
+
};
|
|
178
|
+
}
|
|
179
|
+
const cliFlags = [];
|
|
180
|
+
if (preset === "autonomous") {
|
|
181
|
+
const allTools = Object.keys(CLAUDE_TOOL_CATEGORIES);
|
|
182
|
+
cliFlags.push("--tools", allTools.join(","));
|
|
183
|
+
}
|
|
184
|
+
return {
|
|
185
|
+
preset,
|
|
186
|
+
cliFlags,
|
|
187
|
+
workspaceFiles: [
|
|
188
|
+
{
|
|
189
|
+
relativePath: ".claude/settings.json",
|
|
190
|
+
content: JSON.stringify(settings, null, 2),
|
|
191
|
+
format: "json"
|
|
192
|
+
}
|
|
193
|
+
],
|
|
194
|
+
envVars: {},
|
|
195
|
+
summary: `Claude Code: ${def.description}`
|
|
196
|
+
};
|
|
197
|
+
}
|
|
198
|
+
function generateGeminiApprovalConfig(preset) {
|
|
199
|
+
const def = getPresetDefinition(preset);
|
|
200
|
+
const cliFlags = [];
|
|
201
|
+
const allowedTools = getToolsForCategories(GEMINI_TOOL_CATEGORIES, def.autoApprove);
|
|
202
|
+
const excludeTools = getToolsForCategories(GEMINI_TOOL_CATEGORIES, def.blocked);
|
|
203
|
+
let approvalMode;
|
|
204
|
+
switch (preset) {
|
|
205
|
+
case "readonly":
|
|
206
|
+
approvalMode = "plan";
|
|
207
|
+
cliFlags.push("--approval-mode", "plan");
|
|
208
|
+
break;
|
|
209
|
+
case "standard":
|
|
210
|
+
approvalMode = "default";
|
|
211
|
+
break;
|
|
212
|
+
case "permissive":
|
|
213
|
+
approvalMode = "auto_edit";
|
|
214
|
+
cliFlags.push("--approval-mode", "auto_edit");
|
|
215
|
+
break;
|
|
216
|
+
case "autonomous":
|
|
217
|
+
approvalMode = "auto_edit";
|
|
218
|
+
cliFlags.push("-y");
|
|
219
|
+
break;
|
|
220
|
+
}
|
|
221
|
+
const settings = {
|
|
222
|
+
general: {
|
|
223
|
+
defaultApprovalMode: approvalMode
|
|
224
|
+
},
|
|
225
|
+
tools: {}
|
|
226
|
+
};
|
|
227
|
+
const tools = settings.tools;
|
|
228
|
+
if (allowedTools.length > 0) {
|
|
229
|
+
tools.allowed = allowedTools;
|
|
230
|
+
}
|
|
231
|
+
if (excludeTools.length > 0) {
|
|
232
|
+
tools.exclude = excludeTools;
|
|
233
|
+
}
|
|
234
|
+
return {
|
|
235
|
+
preset,
|
|
236
|
+
cliFlags,
|
|
237
|
+
workspaceFiles: [
|
|
238
|
+
{
|
|
239
|
+
relativePath: ".gemini/settings.json",
|
|
240
|
+
content: JSON.stringify(settings, null, 2),
|
|
241
|
+
format: "json"
|
|
242
|
+
}
|
|
243
|
+
],
|
|
244
|
+
envVars: {},
|
|
245
|
+
summary: `Gemini CLI: ${def.description}`
|
|
246
|
+
};
|
|
247
|
+
}
|
|
248
|
+
function generateCodexApprovalConfig(preset) {
|
|
249
|
+
const cliFlags = [];
|
|
250
|
+
let approvalPolicy;
|
|
251
|
+
let sandboxMode;
|
|
252
|
+
let webSearch;
|
|
253
|
+
switch (preset) {
|
|
254
|
+
case "readonly":
|
|
255
|
+
approvalPolicy = "untrusted";
|
|
256
|
+
sandboxMode = "workspace-read";
|
|
257
|
+
webSearch = false;
|
|
258
|
+
cliFlags.push("--sandbox", "workspace-read", "-a", "untrusted");
|
|
259
|
+
break;
|
|
260
|
+
case "standard":
|
|
261
|
+
approvalPolicy = "on-failure";
|
|
262
|
+
sandboxMode = "workspace-write";
|
|
263
|
+
webSearch = true;
|
|
264
|
+
cliFlags.push("--sandbox", "workspace-write");
|
|
265
|
+
break;
|
|
266
|
+
case "permissive":
|
|
267
|
+
approvalPolicy = "on-request";
|
|
268
|
+
sandboxMode = "workspace-write";
|
|
269
|
+
webSearch = true;
|
|
270
|
+
cliFlags.push("-a", "on-request");
|
|
271
|
+
break;
|
|
272
|
+
case "autonomous":
|
|
273
|
+
approvalPolicy = "never";
|
|
274
|
+
sandboxMode = "workspace-write";
|
|
275
|
+
webSearch = true;
|
|
276
|
+
cliFlags.push("--full-auto");
|
|
277
|
+
break;
|
|
278
|
+
}
|
|
279
|
+
const config = {
|
|
280
|
+
approval_policy: approvalPolicy,
|
|
281
|
+
sandbox_mode: sandboxMode,
|
|
282
|
+
tools: {
|
|
283
|
+
web_search: webSearch
|
|
284
|
+
}
|
|
285
|
+
};
|
|
286
|
+
return {
|
|
287
|
+
preset,
|
|
288
|
+
cliFlags,
|
|
289
|
+
workspaceFiles: [
|
|
290
|
+
{
|
|
291
|
+
relativePath: ".codex/config.json",
|
|
292
|
+
content: JSON.stringify(config, null, 2),
|
|
293
|
+
format: "json"
|
|
294
|
+
}
|
|
295
|
+
],
|
|
296
|
+
envVars: {},
|
|
297
|
+
summary: `Codex: ${getPresetDefinition(preset).description}`
|
|
298
|
+
};
|
|
299
|
+
}
|
|
300
|
+
function generateAiderApprovalConfig(preset) {
|
|
301
|
+
const def = getPresetDefinition(preset);
|
|
302
|
+
const cliFlags = [];
|
|
303
|
+
const lines = [];
|
|
304
|
+
switch (preset) {
|
|
305
|
+
case "readonly":
|
|
306
|
+
lines.push("yes-always: false");
|
|
307
|
+
lines.push("no-auto-commits: true");
|
|
308
|
+
cliFlags.push("--no-auto-commits");
|
|
309
|
+
break;
|
|
310
|
+
case "standard":
|
|
311
|
+
lines.push("yes-always: false");
|
|
312
|
+
break;
|
|
313
|
+
case "permissive":
|
|
314
|
+
lines.push("yes-always: true");
|
|
315
|
+
cliFlags.push("--yes-always");
|
|
316
|
+
break;
|
|
317
|
+
case "autonomous":
|
|
318
|
+
lines.push("yes-always: true");
|
|
319
|
+
cliFlags.push("--yes-always");
|
|
320
|
+
break;
|
|
321
|
+
}
|
|
322
|
+
return {
|
|
323
|
+
preset,
|
|
324
|
+
cliFlags,
|
|
325
|
+
workspaceFiles: [
|
|
326
|
+
{
|
|
327
|
+
relativePath: ".aider.conf.yml",
|
|
328
|
+
content: lines.join("\n") + "\n",
|
|
329
|
+
format: "yaml"
|
|
330
|
+
}
|
|
331
|
+
],
|
|
332
|
+
envVars: {},
|
|
333
|
+
summary: `Aider: ${def.description}`
|
|
334
|
+
};
|
|
335
|
+
}
|
|
336
|
+
function generateApprovalConfig(adapterType, preset) {
|
|
337
|
+
switch (adapterType) {
|
|
338
|
+
case "claude":
|
|
339
|
+
return generateClaudeApprovalConfig(preset);
|
|
340
|
+
case "gemini":
|
|
341
|
+
return generateGeminiApprovalConfig(preset);
|
|
342
|
+
case "codex":
|
|
343
|
+
return generateCodexApprovalConfig(preset);
|
|
344
|
+
case "aider":
|
|
345
|
+
return generateAiderApprovalConfig(preset);
|
|
346
|
+
default:
|
|
347
|
+
throw new Error(`Unknown adapter type: ${adapterType}`);
|
|
348
|
+
}
|
|
349
|
+
}
|
|
350
|
+
function listPresets() {
|
|
351
|
+
return [...PRESET_DEFINITIONS];
|
|
352
|
+
}
|
|
353
|
+
function getPresetDefinition(preset) {
|
|
354
|
+
const def = PRESET_DEFINITIONS.find((d) => d.preset === preset);
|
|
355
|
+
if (!def) {
|
|
356
|
+
throw new Error(`Unknown preset: ${preset}`);
|
|
357
|
+
}
|
|
358
|
+
return def;
|
|
359
|
+
}
|
|
360
|
+
|
|
5
361
|
// src/base-coding-adapter.ts
|
|
6
362
|
var BaseCodingAdapter = class extends BaseCLIAdapter {
|
|
7
363
|
/**
|
|
@@ -112,6 +468,40 @@ Docs: ${this.installation.docsUrl}`
|
|
|
112
468
|
content = content.trim();
|
|
113
469
|
return content;
|
|
114
470
|
}
|
|
471
|
+
// ─────────────────────────────────────────────────────────────────────────────
|
|
472
|
+
// Approval Presets
|
|
473
|
+
// ─────────────────────────────────────────────────────────────────────────────
|
|
474
|
+
/**
|
|
475
|
+
* Extract the approval preset from a spawn config, if set.
|
|
476
|
+
*/
|
|
477
|
+
getApprovalPreset(config) {
|
|
478
|
+
const adapterConfig = config.adapterConfig;
|
|
479
|
+
return adapterConfig?.approvalPreset;
|
|
480
|
+
}
|
|
481
|
+
/**
|
|
482
|
+
* Generate the approval config for this adapter, if a preset is set.
|
|
483
|
+
*/
|
|
484
|
+
getApprovalConfig(config) {
|
|
485
|
+
const preset = this.getApprovalPreset(config);
|
|
486
|
+
if (!preset) return null;
|
|
487
|
+
return generateApprovalConfig(this.adapterType, preset);
|
|
488
|
+
}
|
|
489
|
+
/**
|
|
490
|
+
* Write approval config files to a workspace directory.
|
|
491
|
+
* Returns the list of files written (absolute paths).
|
|
492
|
+
*/
|
|
493
|
+
async writeApprovalConfig(workspacePath, config) {
|
|
494
|
+
const approvalConfig = this.getApprovalConfig(config);
|
|
495
|
+
if (!approvalConfig) return [];
|
|
496
|
+
const written = [];
|
|
497
|
+
for (const file of approvalConfig.workspaceFiles) {
|
|
498
|
+
const fullPath = join(workspacePath, file.relativePath);
|
|
499
|
+
await mkdir(dirname(fullPath), { recursive: true });
|
|
500
|
+
await writeFile(fullPath, file.content, "utf-8");
|
|
501
|
+
written.push(fullPath);
|
|
502
|
+
}
|
|
503
|
+
return written;
|
|
504
|
+
}
|
|
115
505
|
/**
|
|
116
506
|
* Write content to this agent's memory file in a workspace.
|
|
117
507
|
* Creates parent directories as needed.
|
|
@@ -246,6 +636,10 @@ var ClaudeAdapter = class extends BaseCodingAdapter {
|
|
|
246
636
|
args.push("--cwd", config.workdir);
|
|
247
637
|
}
|
|
248
638
|
}
|
|
639
|
+
const approvalConfig = this.getApprovalConfig(config);
|
|
640
|
+
if (approvalConfig) {
|
|
641
|
+
args.push(...approvalConfig.cliFlags);
|
|
642
|
+
}
|
|
249
643
|
return args;
|
|
250
644
|
}
|
|
251
645
|
getEnv(config) {
|
|
@@ -478,6 +872,10 @@ var GeminiAdapter = class extends BaseCodingAdapter {
|
|
|
478
872
|
args.push("--cwd", config.workdir);
|
|
479
873
|
}
|
|
480
874
|
}
|
|
875
|
+
const approvalConfig = this.getApprovalConfig(config);
|
|
876
|
+
if (approvalConfig) {
|
|
877
|
+
args.push(...approvalConfig.cliFlags);
|
|
878
|
+
}
|
|
481
879
|
return args;
|
|
482
880
|
}
|
|
483
881
|
getEnv(config) {
|
|
@@ -782,6 +1180,10 @@ var CodexAdapter = class extends BaseCodingAdapter {
|
|
|
782
1180
|
args.push("--cwd", config.workdir);
|
|
783
1181
|
}
|
|
784
1182
|
}
|
|
1183
|
+
const approvalConfig = this.getApprovalConfig(config);
|
|
1184
|
+
if (approvalConfig) {
|
|
1185
|
+
args.push(...approvalConfig.cliFlags);
|
|
1186
|
+
}
|
|
785
1187
|
return args;
|
|
786
1188
|
}
|
|
787
1189
|
getEnv(config) {
|
|
@@ -1217,6 +1619,10 @@ var AiderAdapter = class extends BaseCodingAdapter {
|
|
|
1217
1619
|
if (credentials.anthropicKey) args.push("--api-key", `anthropic=${credentials.anthropicKey}`);
|
|
1218
1620
|
if (credentials.openaiKey) args.push("--api-key", `openai=${credentials.openaiKey}`);
|
|
1219
1621
|
if (credentials.googleKey) args.push("--api-key", `gemini=${credentials.googleKey}`);
|
|
1622
|
+
const approvalConfig = this.getApprovalConfig(config);
|
|
1623
|
+
if (approvalConfig) {
|
|
1624
|
+
args.push(...approvalConfig.cliFlags);
|
|
1625
|
+
}
|
|
1220
1626
|
return args;
|
|
1221
1627
|
}
|
|
1222
1628
|
getEnv(config) {
|
|
@@ -1572,6 +1978,6 @@ async function printMissingAdapters(types) {
|
|
|
1572
1978
|
}
|
|
1573
1979
|
}
|
|
1574
1980
|
|
|
1575
|
-
export { ADAPTER_TYPES, AiderAdapter, BaseCodingAdapter, ClaudeAdapter, CodexAdapter, GeminiAdapter, checkAdapters, checkAllAdapters, clearPatternCache, createAdapter, createAllAdapters, getBaselinePatterns, hasDynamicPatterns, loadPatterns, loadPatternsSync, preloadAllPatterns, printMissingAdapters };
|
|
1981
|
+
export { ADAPTER_TYPES, AIDER_COMMAND_CATEGORIES, AiderAdapter, BaseCodingAdapter, CLAUDE_TOOL_CATEGORIES, CODEX_TOOL_CATEGORIES, ClaudeAdapter, CodexAdapter, GEMINI_TOOL_CATEGORIES, GeminiAdapter, PRESET_DEFINITIONS, TOOL_CATEGORIES, checkAdapters, checkAllAdapters, clearPatternCache, createAdapter, createAllAdapters, generateAiderApprovalConfig, generateApprovalConfig, generateClaudeApprovalConfig, generateCodexApprovalConfig, generateGeminiApprovalConfig, getBaselinePatterns, getPresetDefinition, hasDynamicPatterns, listPresets, loadPatterns, loadPatternsSync, preloadAllPatterns, printMissingAdapters };
|
|
1576
1982
|
//# sourceMappingURL=index.js.map
|
|
1577
1983
|
//# sourceMappingURL=index.js.map
|