Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 | 4x 4x 4x 4x 1x 1x 1x 1x 26x 24x 6x 3x 15x 15x 13x 4x 2x 1x 2x 1x 1x 1x 2x 2x 6x 3x 3x 3x 15x 15x 15x 9x 9x 4x 4x 2x 2x 2x 2x 1x 1x 1x 1x 2x 20x 13x 7x | // Centralized configuration for amp-acp adapter
export const config = {
// Amp CLI binary path
ampExecutable: process.env.AMP_EXECUTABLE || 'amp',
// Whether to strip npx/node_modules paths to prefer system amp
preferSystemPath: process.env.AMP_PREFER_SYSTEM_PATH === '1',
// Amp CLI flags for new sessions
ampFlags: ['--execute', '--stream-json', '--no-notifications'],
// Amp CLI flags appended after 'threads continue <threadId>'
ampContinueFlags: ['--execute', '--stream-json', '--no-notifications'],
// Prompt timeout in milliseconds (default: 10 minutes)
timeoutMs: Number(process.env.AMP_ACP_TIMEOUT_MS) || 10 * 60 * 1000,
// ACP protocol version
protocolVersion: 1,
// Nested tool call display mode:
// - 'inline': embed child tool calls as consolidated progress in parent's content (default)
// - 'separate': emit child tool calls as separate ACP tool_call notifications
nestedToolMode: process.env.AMP_ACP_NESTED_MODE || 'inline',
// Slash command to Amp mode mapping
commandToMode: {
plan: 'plan',
code: 'default',
yolo: 'bypassPermissions',
},
};
// Slash commands exposed to ACP clients
export const slashCommands = [
{
name: 'plan',
description: 'Switch to plan mode (read-only analysis)',
input: { hint: 'Optional follow-up prompt' },
},
{ name: 'code', description: 'Switch to code mode (default)', input: { hint: 'Optional follow-up prompt' } },
{ name: 'yolo', description: 'Bypass all permission prompts', input: { hint: 'Optional follow-up prompt' } },
];
// Tool name to ACP ToolKind mapping (spec-compliant values only)
// Valid kinds: read, edit, delete, move, search, execute, think, fetch, switch_mode, other
export const toolKindMap = {
// Read tools
Read: 'read',
// Search tools
Grep: 'search',
glob: 'search',
finder: 'search',
web_search: 'fetch',
read_web_page: 'fetch',
// Edit tools
edit_file: 'edit',
create_file: 'edit',
undo_edit: 'edit',
format_file: 'edit',
// Delete/Move tools
delete_file: 'delete',
move_file: 'move',
// Execution tools
Bash: 'execute',
Task: 'execute',
// Thinking/analysis tools
oracle: 'think',
todo_read: 'search',
todo_write: 'edit',
// Plan tools
read_plan: 'search',
edit_plan: 'edit',
};
export function getAmpSettingsOverridesForMode(modeId) {
switch (modeId) {
case 'bypassPermissions':
return {
dangerouslyAllowAll: true,
prependPermissions: [],
disableTools: [],
};
case 'acceptEdits':
return {
dangerouslyAllowAll: false,
prependPermissions: [
{ tool: 'create_file', action: 'allow' },
{ tool: 'edit_file', action: 'allow' },
{ tool: 'delete_file', action: 'allow' },
{ tool: 'move_file', action: 'allow' },
{ tool: 'undo_edit', action: 'allow' },
{ tool: 'format_file', action: 'allow' },
],
disableTools: [],
};
case 'plan':
return {
dangerouslyAllowAll: false,
prependPermissions: [
{ tool: 'Bash', action: 'reject' },
{ tool: 'create_file', action: 'reject' },
{ tool: 'edit_file', action: 'reject' },
{ tool: 'delete_file', action: 'reject' },
{ tool: 'move_file', action: 'reject' },
{ tool: 'undo_edit', action: 'reject' },
{ tool: 'format_file', action: 'reject' },
],
disableTools: [
'builtin:Bash',
'builtin:create_file',
'builtin:edit_file',
'builtin:delete_file',
'builtin:move_file',
'builtin:undo_edit',
'builtin:format_file',
],
};
case 'default':
default:
return {
dangerouslyAllowAll: false,
prependPermissions: [],
disableTools: [],
};
}
}
/**
* Get ACP-compliant tool kind for a given tool name
*/
export function getToolKind(name) {
if (!name) return 'other';
if (toolKindMap[name]) return toolKindMap[name];
if (name.startsWith('mcp__')) return 'fetch';
return 'other';
}
/**
* Get display title for a tool, including context from input when available
*/
export function getToolTitle(name, parentToolUseId, input) {
const prefix = parentToolUseId ? '[Subagent] ' : '';
if (!name) return prefix + 'Unknown';
// Generate contextual titles based on tool input
switch (name) {
case 'Read':
if (input?.path) return prefix + `Read ${shortenPath(input.path)}`;
break;
case 'Grep':
Eif (input?.pattern) return prefix + `Grep "${truncate(input.pattern, 30)}"`;
break;
case 'glob':
if (input?.filePattern) return prefix + `glob ${truncate(input.filePattern, 40)}`;
break;
case 'finder':
if (input?.query) return prefix + `finder: ${truncate(input.query, 40)}`;
break;
case 'Bash':
if (input?.cmd) return prefix + `Bash: ${truncate(input.cmd, 50)}`;
break;
case 'edit_file':
if (input?.path) return prefix + `Edit ${shortenPath(input.path)}`;
break;
case 'create_file':
if (input?.path) return prefix + `Create ${shortenPath(input.path)}`;
break;
case 'Task':
Iif (input?.description) return prefix + `Task: ${truncate(input.description, 40)}`;
return prefix + 'Spawn Subagent';
case 'oracle':
Iif (input?.task) return prefix + `Oracle: ${truncate(input.task, 40)}`;
return prefix + 'Oracle';
case 'todo_write':
return prefix + 'Update Plan';
case 'todo_read':
return prefix + 'Read Plan';
case 'web_search':
if (input?.query) return prefix + `Search: ${truncate(input.query, 40)}`;
break;
case 'read_web_page':
if (input?.url) return prefix + `Fetch ${truncate(input.url, 50)}`;
break;
}
// MCP tools
if (name.startsWith('mcp__')) {
const parts = name.replace('mcp__', '').split('__');
return prefix + `MCP: ${parts.join('.')}`;
}
return prefix + name;
}
/**
* Shorten a file path for display (show last 2-3 components)
*/
function shortenPath(path) {
Iif (!path) return '';
const parts = path.split('/').filter(Boolean);
Eif (parts.length <= 3) return parts.join('/');
return '…/' + parts.slice(-2).join('/');
}
/**
* Truncate string with ellipsis
*/
function truncate(str, maxLen) {
Iif (!str) return '';
Eif (str.length <= maxLen) return str;
return str.slice(0, maxLen - 1) + '…';
}
/**
* Extract file locations from tool input for ACP locations array
*/
export function getToolLocations(name, input) {
Iif (!input) return [];
switch (name) {
case 'Read':
case 'edit_file':
case 'create_file':
case 'undo_edit':
Eif (input.path) {
const loc = { path: input.path };
Iif (input.read_range?.[0]) loc.line = input.read_range[0];
return [loc];
}
break;
case 'Grep':
Iif (input.path) return [{ path: input.path }];
break;
case 'Bash':
Iif (input.cwd) return [{ path: input.cwd }];
break;
}
return [];
}
/**
* Get a short inline description for embedding child tool calls in parent content
*/
export function getInlineToolDescription(name, input) {
switch (name) {
case 'Read':
return input?.path ? `Read ${shortenPath(input.path)}` : 'Read';
case 'Grep':
return input?.pattern ? `Grep "${truncate(input.pattern, 25)}"` : 'Grep';
case 'glob':
return input?.filePattern ? `glob ${truncate(input.filePattern, 30)}` : 'glob';
case 'finder':
return input?.query ? `finder: ${truncate(input.query, 30)}` : 'finder';
case 'Bash':
return input?.cmd ? `Bash: ${truncate(input.cmd, 40)}` : 'Bash';
case 'edit_file':
return input?.path ? `Edit ${shortenPath(input.path)}` : 'edit_file';
case 'create_file':
return input?.path ? `Create ${shortenPath(input.path)}` : 'create_file';
case 'web_search':
return input?.query ? `Search: ${truncate(input.query, 30)}` : 'web_search';
case 'read_web_page':
return input?.url ? `Fetch ${truncate(input.url, 40)}` : 'read_web_page';
default:
if (name?.startsWith('mcp__')) {
const parts = name.replace('mcp__', '').split('__');
return `MCP: ${parts.join('.')}`;
}
return name || 'Unknown';
}
}
/**
* Build environment for spawning amp process
*/
export function buildSpawnEnv() {
const env = { ...process.env };
if (config.preferSystemPath && env.PATH) {
// Drop npx/npm-local node_modules/.bin segments
const separator = process.platform === 'win32' ? ';' : ':';
const parts = env.PATH.split(separator).filter((p) => !/\bnode_modules\/\.bin\b|\/_npx\//.test(p));
env.PATH = parts.join(separator);
}
return env;
}
|