amp-acp 0.6.1 → 0.7.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/dist/index.js +244 -51
- package/package.json +5 -5
package/dist/index.js
CHANGED
|
@@ -10,6 +10,12 @@ var __export = (target, all) => {
|
|
|
10
10
|
});
|
|
11
11
|
};
|
|
12
12
|
|
|
13
|
+
// src/index.ts
|
|
14
|
+
import fs2 from "node:fs";
|
|
15
|
+
import path3 from "node:path";
|
|
16
|
+
import os2 from "node:os";
|
|
17
|
+
import readline from "node:readline";
|
|
18
|
+
|
|
13
19
|
// node_modules/zod/v3/external.js
|
|
14
20
|
var exports_external = {};
|
|
15
21
|
__export(exports_external, {
|
|
@@ -5104,6 +5110,7 @@ import { spawn } from "node:child_process";
|
|
|
5104
5110
|
import fs from "node:fs";
|
|
5105
5111
|
import { mkdir, readFile, rm, writeFile } from "node:fs/promises";
|
|
5106
5112
|
import { createRequire } from "node:module";
|
|
5113
|
+
import os from "node:os";
|
|
5107
5114
|
import path from "node:path";
|
|
5108
5115
|
import { createInterface } from "node:readline";
|
|
5109
5116
|
var __defProp2 = Object.defineProperty;
|
|
@@ -9119,18 +9126,42 @@ var PermissionSchema = exports_external2.object({
|
|
|
9119
9126
|
});
|
|
9120
9127
|
}
|
|
9121
9128
|
});
|
|
9122
|
-
var
|
|
9129
|
+
var MCPOAuthConfigSchema = exports_external2.object({
|
|
9130
|
+
clientId: exports_external2.string().describe("OAuth client ID"),
|
|
9131
|
+
clientSecret: exports_external2.string().describe("OAuth client secret").optional(),
|
|
9132
|
+
authUrl: exports_external2.string().describe("OAuth authorization URL"),
|
|
9133
|
+
tokenUrl: exports_external2.string().describe("OAuth token URL"),
|
|
9134
|
+
scopes: exports_external2.array(exports_external2.string()).describe("OAuth scopes").optional(),
|
|
9135
|
+
redirectUrl: exports_external2.string().describe("OAuth redirect URL").optional()
|
|
9136
|
+
}).describe("OAuth configuration for HTTP MCP servers");
|
|
9137
|
+
var MCPStdioServerSchema = exports_external2.object({
|
|
9123
9138
|
command: exports_external2.string().describe("Command to run the MCP server"),
|
|
9124
9139
|
args: exports_external2.array(exports_external2.string()).describe("Arguments for the MCP server command").optional(),
|
|
9125
9140
|
env: exports_external2.record(exports_external2.string(), exports_external2.string()).describe("Environment variables for the server").optional(),
|
|
9126
9141
|
disabled: exports_external2.boolean().describe("Whether the server is disabled").optional()
|
|
9127
9142
|
});
|
|
9143
|
+
var MCPHttpServerSchema = exports_external2.object({
|
|
9144
|
+
url: exports_external2.string().describe("URL of the HTTP MCP server"),
|
|
9145
|
+
headers: exports_external2.record(exports_external2.string(), exports_external2.string()).describe("HTTP headers to send with requests").optional(),
|
|
9146
|
+
transport: exports_external2.string().describe('Transport type (e.g., "sse")').optional(),
|
|
9147
|
+
oauth: MCPOAuthConfigSchema.describe("OAuth configuration for authentication").optional(),
|
|
9148
|
+
disabled: exports_external2.boolean().describe("Whether the server is disabled").optional()
|
|
9149
|
+
});
|
|
9150
|
+
var MCPServerSchema = exports_external2.union([MCPStdioServerSchema, MCPHttpServerSchema]);
|
|
9128
9151
|
var MCPConfigSchema = exports_external2.record(exports_external2.string(), MCPServerSchema).describe("MCP server configurations keyed by server name");
|
|
9152
|
+
var VisibilitySchema = exports_external2.enum(["private", "public", "workspace", "group"]);
|
|
9153
|
+
var ThreadsNewOptionsSchema = exports_external2.object({
|
|
9154
|
+
visibility: VisibilitySchema.optional().describe("Thread visibility")
|
|
9155
|
+
});
|
|
9156
|
+
var ThreadsMarkdownOptionsSchema = exports_external2.object({
|
|
9157
|
+
threadId: exports_external2.string().describe("The thread ID to get markdown for")
|
|
9158
|
+
});
|
|
9129
9159
|
var AmpOptionsSchema = exports_external2.object({
|
|
9130
9160
|
cwd: exports_external2.string().describe("Current working directory").optional(),
|
|
9131
|
-
mode: exports_external2.enum(["smart", "rush", "large"]).describe("Agent mode - controls the model, system prompt, and tool selection").default("smart").optional(),
|
|
9161
|
+
mode: exports_external2.enum(["smart", "rush", "large", "deep"]).describe("Agent mode - controls the model, system prompt, and tool selection").default("smart").optional(),
|
|
9132
9162
|
dangerouslyAllowAll: exports_external2.boolean().describe("Allow all tool usage without asking for permission").optional(),
|
|
9133
|
-
|
|
9163
|
+
archive: exports_external2.boolean().describe("Archive the thread after execution completes").optional(),
|
|
9164
|
+
visibility: VisibilitySchema.describe("Visibility level for new threads").default("workspace").optional(),
|
|
9134
9165
|
settingsFile: exports_external2.string().describe("Settings file path").optional(),
|
|
9135
9166
|
logLevel: exports_external2.enum(["debug", "info", "warn", "error", "audit"]).describe("Log level").optional(),
|
|
9136
9167
|
logFile: exports_external2.string().describe("Log file path").optional(),
|
|
@@ -9138,7 +9169,11 @@ var AmpOptionsSchema = exports_external2.object({
|
|
|
9138
9169
|
env: exports_external2.record(exports_external2.string(), exports_external2.string()).describe("Additional environment variables").optional(),
|
|
9139
9170
|
continue: exports_external2.union([exports_external2.boolean(), exports_external2.string()]).describe("Continue the most recent thread (true) or a specific thread by ID (string)").optional(),
|
|
9140
9171
|
toolbox: exports_external2.string().describe("Folder path with toolbox scripts").optional(),
|
|
9141
|
-
|
|
9172
|
+
skills: exports_external2.string().describe("Folder path with custom skills").optional(),
|
|
9173
|
+
permissions: exports_external2.array(PermissionSchema).describe("Permission rules for tool usage").optional(),
|
|
9174
|
+
labels: exports_external2.array(exports_external2.string().regex(/^[a-zA-Z0-9][a-zA-Z0-9-]*$/, "Labels must start with alphanumeric and contain only alphanumeric characters and hyphens").min(1, "Label must be at least 1 character").max(32, "Label must be at most 32 characters")).max(20, "Maximum 20 labels allowed").describe("Labels to add to the thread (repeatable CLI --label)").optional(),
|
|
9175
|
+
enabledTools: exports_external2.array(exports_external2.string()).describe('Array of tool name patterns to enable. Supports glob patterns (e.g., "mcp__metabase__*"). If not provided, all tools are enabled. If provided, only matching tools are enabled.').optional(),
|
|
9176
|
+
systemPrompt: exports_external2.string().describe("Custom system prompt text to append to the base system prompt for integration-specific customizations").optional()
|
|
9142
9177
|
}).strict();
|
|
9143
9178
|
var isWindows = process.platform === "win32";
|
|
9144
9179
|
async function* execute(options) {
|
|
@@ -9172,22 +9207,9 @@ async function* execute(options) {
|
|
|
9172
9207
|
}
|
|
9173
9208
|
yield* processOutputStream(ampProcess.stdout);
|
|
9174
9209
|
const { exitCode, stderr, signal: processSignal } = await waitForProcess(ampProcess, signal);
|
|
9175
|
-
|
|
9176
|
-
if (signal?.aborted) {
|
|
9177
|
-
throw new Error("Amp CLI process was aborted");
|
|
9178
|
-
} else if (processSignal) {
|
|
9179
|
-
throw new Error(`Amp CLI process was killed by signal ${processSignal}`);
|
|
9180
|
-
} else {
|
|
9181
|
-
throw new Error("Amp CLI process terminated unexpectedly");
|
|
9182
|
-
}
|
|
9183
|
-
} else if (exitCode !== 0) {
|
|
9184
|
-
const errorDetails = stderr ? `: ${stderr}` : "";
|
|
9185
|
-
throw new Error(`Amp CLI process exited with code ${exitCode}${errorDetails}`);
|
|
9186
|
-
}
|
|
9210
|
+
throwIfProcessFailed(exitCode, stderr, processSignal, signal);
|
|
9187
9211
|
} catch (error) {
|
|
9188
|
-
|
|
9189
|
-
ampProcess.kill(isWindows ? "SIGKILL" : "SIGTERM");
|
|
9190
|
-
}
|
|
9212
|
+
killProcess(ampProcess);
|
|
9191
9213
|
throw error;
|
|
9192
9214
|
} finally {
|
|
9193
9215
|
await cleanupTempFile();
|
|
@@ -9198,7 +9220,14 @@ function generateSessionId() {
|
|
|
9198
9220
|
return `sdk-${Date.now()}-${randomHex}`;
|
|
9199
9221
|
}
|
|
9200
9222
|
async function buildSettingsFile(options, sessionId) {
|
|
9201
|
-
|
|
9223
|
+
const settingsFields = [
|
|
9224
|
+
options.permissions,
|
|
9225
|
+
options.mode,
|
|
9226
|
+
options.skills,
|
|
9227
|
+
options.enabledTools,
|
|
9228
|
+
options.systemPrompt
|
|
9229
|
+
];
|
|
9230
|
+
if (!settingsFields.some(Boolean)) {
|
|
9202
9231
|
return {
|
|
9203
9232
|
settingsFilePath: null,
|
|
9204
9233
|
cleanupTempFile: async () => {}
|
|
@@ -9218,11 +9247,22 @@ async function buildSettingsFile(options, sessionId) {
|
|
|
9218
9247
|
}
|
|
9219
9248
|
}
|
|
9220
9249
|
}
|
|
9221
|
-
|
|
9222
|
-
|
|
9223
|
-
|
|
9250
|
+
if (options.permissions) {
|
|
9251
|
+
mergedSettings["amp.permissions"] = options.permissions;
|
|
9252
|
+
}
|
|
9253
|
+
if (options.enabledTools) {
|
|
9254
|
+
mergedSettings["amp.tools.enable"] = options.enabledTools;
|
|
9255
|
+
}
|
|
9256
|
+
if (options.systemPrompt) {
|
|
9257
|
+
mergedSettings["amp.systemPrompt"] = options.systemPrompt;
|
|
9258
|
+
}
|
|
9259
|
+
if (options.skills) {
|
|
9260
|
+
mergedSettings["amp.skills.path"] = options.skills;
|
|
9224
9261
|
}
|
|
9225
9262
|
await mkdir(tempDir, { recursive: true });
|
|
9263
|
+
if (process.env.AMP_DEBUG) {
|
|
9264
|
+
console.log("[SDK] Writing settings file:", tempSettingsPath, mergedSettings);
|
|
9265
|
+
}
|
|
9226
9266
|
await writeFile(tempSettingsPath, JSON.stringify(mergedSettings, null, 2), "utf-8");
|
|
9227
9267
|
return {
|
|
9228
9268
|
settingsFilePath: tempSettingsPath,
|
|
@@ -9243,7 +9283,7 @@ function buildEnvironmentVariables(options) {
|
|
|
9243
9283
|
if (options.env) {
|
|
9244
9284
|
Object.assign(env, options.env);
|
|
9245
9285
|
}
|
|
9246
|
-
env.AMP_SDK_VERSION = "0.1.0-
|
|
9286
|
+
env.AMP_SDK_VERSION = "0.1.0-20260220044036-g88868e6";
|
|
9247
9287
|
return env;
|
|
9248
9288
|
}
|
|
9249
9289
|
function spawnAmpCli(args, options) {
|
|
@@ -9259,6 +9299,21 @@ function spawnAmpCli(args, options) {
|
|
|
9259
9299
|
return childProcess;
|
|
9260
9300
|
}
|
|
9261
9301
|
function findAmpCommand() {
|
|
9302
|
+
const localAmpCommand = resolveLocalAmpPackageCommand();
|
|
9303
|
+
if (localAmpCommand) {
|
|
9304
|
+
return localAmpCommand;
|
|
9305
|
+
}
|
|
9306
|
+
const homeAmpCommand = resolveLocalAmpCommand();
|
|
9307
|
+
if (homeAmpCommand) {
|
|
9308
|
+
return homeAmpCommand;
|
|
9309
|
+
}
|
|
9310
|
+
const pathAmpCommand = resolveAmpFromPath();
|
|
9311
|
+
if (pathAmpCommand) {
|
|
9312
|
+
return pathAmpCommand;
|
|
9313
|
+
}
|
|
9314
|
+
throw new Error("Could not find local @sourcegraph/amp package or amp binary. Make sure it is installed.");
|
|
9315
|
+
}
|
|
9316
|
+
function resolveLocalAmpPackageCommand() {
|
|
9262
9317
|
try {
|
|
9263
9318
|
const require2 = createRequire(import.meta.url);
|
|
9264
9319
|
const pkgJsonPath = require2.resolve("@sourcegraph/amp/package.json");
|
|
@@ -9276,29 +9331,41 @@ function findAmpCommand() {
|
|
|
9276
9331
|
if (error instanceof Error && error.message.includes("Local @sourcegraph/amp")) {
|
|
9277
9332
|
throw error;
|
|
9278
9333
|
}
|
|
9279
|
-
|
|
9280
|
-
|
|
9281
|
-
|
|
9282
|
-
|
|
9283
|
-
|
|
9284
|
-
|
|
9285
|
-
|
|
9286
|
-
|
|
9334
|
+
return null;
|
|
9335
|
+
}
|
|
9336
|
+
}
|
|
9337
|
+
function resolveLocalAmpCommand() {
|
|
9338
|
+
const candidates = isWindows ? ["amp.exe", "amp.cmd", "amp"] : ["amp"];
|
|
9339
|
+
const ampBinDir = path.join(os.homedir(), ".amp", "bin");
|
|
9340
|
+
for (const candidate of candidates) {
|
|
9341
|
+
const candidatePath = path.join(ampBinDir, candidate);
|
|
9342
|
+
if (fs.existsSync(candidatePath)) {
|
|
9343
|
+
return {
|
|
9344
|
+
command: candidatePath,
|
|
9345
|
+
args: []
|
|
9346
|
+
};
|
|
9347
|
+
}
|
|
9348
|
+
}
|
|
9349
|
+
return null;
|
|
9350
|
+
}
|
|
9351
|
+
function resolveAmpFromPath() {
|
|
9352
|
+
const pathEntries = process.env.PATH?.split(path.delimiter) ?? [];
|
|
9353
|
+
const candidates = isWindows ? ["amp.exe", "amp.cmd", "amp"] : ["amp"];
|
|
9354
|
+
for (const pathEntry of pathEntries) {
|
|
9355
|
+
if (!pathEntry) {
|
|
9356
|
+
continue;
|
|
9287
9357
|
}
|
|
9288
9358
|
for (const candidate of candidates) {
|
|
9289
|
-
|
|
9290
|
-
|
|
9359
|
+
const candidatePath = path.join(pathEntry, candidate);
|
|
9360
|
+
if (fs.existsSync(candidatePath)) {
|
|
9361
|
+
return {
|
|
9362
|
+
command: candidatePath,
|
|
9363
|
+
args: []
|
|
9364
|
+
};
|
|
9291
9365
|
}
|
|
9292
9366
|
}
|
|
9293
|
-
try {
|
|
9294
|
-
const whichCmd = process.platform === "win32" ? "where" : "which";
|
|
9295
|
-
const result = execFileSync(whichCmd, ["amp"], { encoding: "utf8", stdio: ["pipe", "pipe", "pipe"] }).trim();
|
|
9296
|
-
if (result) {
|
|
9297
|
-
return { command: result, args: [] };
|
|
9298
|
-
}
|
|
9299
|
-
} catch {}
|
|
9300
|
-
throw new Error("Could not find amp CLI. Install it from https://ampcode.com or ensure @sourcegraph/amp is available.");
|
|
9301
9367
|
}
|
|
9368
|
+
return null;
|
|
9302
9369
|
}
|
|
9303
9370
|
function buildCliArgs(options) {
|
|
9304
9371
|
const args = [];
|
|
@@ -9311,6 +9378,9 @@ function buildCliArgs(options) {
|
|
|
9311
9378
|
if (options.dangerouslyAllowAll) {
|
|
9312
9379
|
args.push("--dangerously-allow-all");
|
|
9313
9380
|
}
|
|
9381
|
+
if (options.archive) {
|
|
9382
|
+
args.push("--archive");
|
|
9383
|
+
}
|
|
9314
9384
|
if (options.visibility) {
|
|
9315
9385
|
args.push("--visibility", options.visibility);
|
|
9316
9386
|
}
|
|
@@ -9330,8 +9400,32 @@ function buildCliArgs(options) {
|
|
|
9330
9400
|
if (options.mode) {
|
|
9331
9401
|
args.push("--mode", options.mode);
|
|
9332
9402
|
}
|
|
9403
|
+
if (options.labels) {
|
|
9404
|
+
for (const label of options.labels) {
|
|
9405
|
+
args.push("--label", label);
|
|
9406
|
+
}
|
|
9407
|
+
}
|
|
9333
9408
|
return args;
|
|
9334
9409
|
}
|
|
9410
|
+
function throwIfProcessFailed(exitCode, stderr, processSignal, signal) {
|
|
9411
|
+
if (exitCode === null) {
|
|
9412
|
+
if (signal?.aborted) {
|
|
9413
|
+
throw new Error("Amp CLI process was aborted");
|
|
9414
|
+
} else if (processSignal) {
|
|
9415
|
+
throw new Error(`Amp CLI process was killed by signal ${processSignal}`);
|
|
9416
|
+
} else {
|
|
9417
|
+
throw new Error("Amp CLI process terminated unexpectedly");
|
|
9418
|
+
}
|
|
9419
|
+
} else if (exitCode !== 0) {
|
|
9420
|
+
const errorDetails = stderr ? `: ${stderr.trim()}` : "";
|
|
9421
|
+
throw new Error(`Amp CLI process exited with code ${exitCode}${errorDetails}`);
|
|
9422
|
+
}
|
|
9423
|
+
}
|
|
9424
|
+
function killProcess(proc) {
|
|
9425
|
+
if (!proc.killed) {
|
|
9426
|
+
proc.kill(isWindows ? "SIGKILL" : "SIGTERM");
|
|
9427
|
+
}
|
|
9428
|
+
}
|
|
9335
9429
|
async function* processOutputStream(stdout) {
|
|
9336
9430
|
if (!stdout) {
|
|
9337
9431
|
throw new Error("No stdout stream available from Amp CLI process");
|
|
@@ -9553,10 +9647,13 @@ function safeJson(x) {
|
|
|
9553
9647
|
return;
|
|
9554
9648
|
}
|
|
9555
9649
|
}
|
|
9650
|
+
|
|
9651
|
+
// src/server.ts
|
|
9652
|
+
import path2 from "node:path";
|
|
9556
9653
|
// package.json
|
|
9557
9654
|
var package_default = {
|
|
9558
9655
|
name: "amp-acp",
|
|
9559
|
-
version: "0.
|
|
9656
|
+
version: "0.7.0",
|
|
9560
9657
|
private: false,
|
|
9561
9658
|
type: "module",
|
|
9562
9659
|
main: "dist/index.js",
|
|
@@ -9573,18 +9670,18 @@ var package_default = {
|
|
|
9573
9670
|
url: "https://github.com/tao12345666333/amp-acp"
|
|
9574
9671
|
},
|
|
9575
9672
|
scripts: {
|
|
9576
|
-
build: "bun build src/index.ts --target=node --outdir=dist --entry-naming=[dir]/[name].js
|
|
9577
|
-
"build:binary": "bun build src/index.ts --target=node --outdir=dist --entry-naming=[dir]/[name].js && bun
|
|
9673
|
+
build: "bun build src/index.ts --target=node --outdir=dist --entry-naming=[dir]/[name].js",
|
|
9674
|
+
"build:binary": "bun build src/index.ts --target=node --outdir=dist --entry-naming=[dir]/[name].js && bun build dist/index.js --compile --outfile dist/amp-acp",
|
|
9578
9675
|
start: "bun dist/index.js",
|
|
9579
9676
|
lint: "tsc --noEmit",
|
|
9580
9677
|
test: "bun test src/",
|
|
9581
|
-
"test:binary": "bun build src/index.ts --target=node --outdir=dist --entry-naming=[dir]/[name].js && bun
|
|
9678
|
+
"test:binary": "bun build src/index.ts --target=node --outdir=dist --entry-naming=[dir]/[name].js && bun build dist/index.js --compile --outfile dist/amp-acp-test && bun test test/binary.test.ts",
|
|
9582
9679
|
"test:all": "bun run test && bun run test:binary"
|
|
9583
9680
|
},
|
|
9584
9681
|
dependencies: {
|
|
9585
9682
|
"@agentclientprotocol/sdk": "0.4.8",
|
|
9586
9683
|
"@sourcegraph/amp": "^0.0.1765685598-g5365e6",
|
|
9587
|
-
"@sourcegraph/amp-sdk": "
|
|
9684
|
+
"@sourcegraph/amp-sdk": "0.1.0-20260220044036-g88868e6"
|
|
9588
9685
|
},
|
|
9589
9686
|
devDependencies: {
|
|
9590
9687
|
"@types/bun": "^1.2.5",
|
|
@@ -9607,12 +9704,29 @@ class AmpAcpAgent {
|
|
|
9607
9704
|
console.info(`[acp] amp-acp v${PACKAGE_VERSION} initialized`);
|
|
9608
9705
|
return {
|
|
9609
9706
|
protocolVersion: 1,
|
|
9610
|
-
|
|
9707
|
+
agentInfo: {
|
|
9708
|
+
name: "amp-acp",
|
|
9709
|
+
title: "Amp ACP Agent",
|
|
9710
|
+
version: PACKAGE_VERSION
|
|
9711
|
+
},
|
|
9611
9712
|
agentCapabilities: {
|
|
9612
9713
|
promptCapabilities: { image: true, embeddedContext: true },
|
|
9613
9714
|
mcpCapabilities: { http: true, sse: true }
|
|
9614
9715
|
},
|
|
9615
|
-
authMethods: [
|
|
9716
|
+
authMethods: [
|
|
9717
|
+
{
|
|
9718
|
+
id: "setup",
|
|
9719
|
+
name: "Amp API Key Setup",
|
|
9720
|
+
description: "Run interactive setup to configure your Amp API key",
|
|
9721
|
+
_meta: {
|
|
9722
|
+
"terminal-auth": {
|
|
9723
|
+
command: getTerminalAuthCommand(),
|
|
9724
|
+
args: ["--setup"],
|
|
9725
|
+
label: "Amp API Key Setup"
|
|
9726
|
+
}
|
|
9727
|
+
}
|
|
9728
|
+
}
|
|
9729
|
+
]
|
|
9616
9730
|
};
|
|
9617
9731
|
}
|
|
9618
9732
|
async newSession(params) {
|
|
@@ -9658,6 +9772,9 @@ class AmpAcpAgent {
|
|
|
9658
9772
|
return result;
|
|
9659
9773
|
}
|
|
9660
9774
|
async authenticate(_params) {
|
|
9775
|
+
if (process.env.AMP_API_KEY) {
|
|
9776
|
+
return {};
|
|
9777
|
+
}
|
|
9661
9778
|
throw RequestError.authRequired();
|
|
9662
9779
|
}
|
|
9663
9780
|
async prompt(params) {
|
|
@@ -9733,6 +9850,10 @@ ${chunk.resource.text}
|
|
|
9733
9850
|
}
|
|
9734
9851
|
}
|
|
9735
9852
|
if (message.type === "result" && message.is_error) {
|
|
9853
|
+
if (typeof message.error === "string" && isAuthError(message.error)) {
|
|
9854
|
+
console.error("[amp] Auth error in result, requesting authentication:", message.error);
|
|
9855
|
+
throw RequestError.authRequired();
|
|
9856
|
+
}
|
|
9736
9857
|
await this.client.sessionUpdate({
|
|
9737
9858
|
sessionId: params.sessionId,
|
|
9738
9859
|
update: { sessionUpdate: "agent_message_chunk", content: { type: "text", text: `Error: ${message.error}` } }
|
|
@@ -9744,6 +9865,10 @@ ${chunk.resource.text}
|
|
|
9744
9865
|
if (s.cancelled || err instanceof Error && (err.name === "AbortError" || err.message.includes("aborted"))) {
|
|
9745
9866
|
return { stopReason: "cancelled" };
|
|
9746
9867
|
}
|
|
9868
|
+
if (err instanceof Error && isAuthError(err.message)) {
|
|
9869
|
+
console.error("[amp] Auth error, requesting authentication:", err.message);
|
|
9870
|
+
throw RequestError.authRequired();
|
|
9871
|
+
}
|
|
9747
9872
|
console.error("[amp] Execution error:", err);
|
|
9748
9873
|
throw err;
|
|
9749
9874
|
} finally {
|
|
@@ -9778,6 +9903,17 @@ ${chunk.resource.text}
|
|
|
9778
9903
|
return this.client.writeTextFile(params);
|
|
9779
9904
|
}
|
|
9780
9905
|
}
|
|
9906
|
+
function isAuthError(message) {
|
|
9907
|
+
const lower = message.toLowerCase();
|
|
9908
|
+
return lower.includes("invalid or missing api key") || lower.includes("run 'amp login'") || lower.includes("authentication") || lower.includes("unauthorized") || lower.includes("no api key found") || lower.includes("api key") && lower.includes("login flow") || lower.includes("api key") && (lower.includes("missing") || lower.includes("invalid"));
|
|
9909
|
+
}
|
|
9910
|
+
function getTerminalAuthCommand(argv1 = process.argv[1], execPath = process.execPath) {
|
|
9911
|
+
const resolvedArgv1 = argv1 ? path2.resolve(argv1) : "";
|
|
9912
|
+
if (!resolvedArgv1 || resolvedArgv1.startsWith("/$bunfs/")) {
|
|
9913
|
+
return execPath;
|
|
9914
|
+
}
|
|
9915
|
+
return resolvedArgv1;
|
|
9916
|
+
}
|
|
9781
9917
|
|
|
9782
9918
|
// src/run-acp.ts
|
|
9783
9919
|
function runAcp() {
|
|
@@ -9792,5 +9928,62 @@ console.log = console.error;
|
|
|
9792
9928
|
console.info = console.error;
|
|
9793
9929
|
console.warn = console.error;
|
|
9794
9930
|
console.debug = console.error;
|
|
9795
|
-
|
|
9796
|
-
process.
|
|
9931
|
+
function getConfigDir() {
|
|
9932
|
+
if (process.platform === "win32") {
|
|
9933
|
+
return path3.join(process.env.APPDATA ?? path3.join(os2.homedir(), "AppData", "Roaming"), "amp-acp");
|
|
9934
|
+
}
|
|
9935
|
+
return path3.join(process.env.XDG_CONFIG_HOME ?? path3.join(os2.homedir(), ".config"), "amp-acp");
|
|
9936
|
+
}
|
|
9937
|
+
function getCredentialsPath() {
|
|
9938
|
+
return path3.join(getConfigDir(), "credentials.json");
|
|
9939
|
+
}
|
|
9940
|
+
function loadStoredApiKey() {
|
|
9941
|
+
const credPath = getCredentialsPath();
|
|
9942
|
+
try {
|
|
9943
|
+
const data = JSON.parse(fs2.readFileSync(credPath, "utf-8"));
|
|
9944
|
+
return data.apiKey || undefined;
|
|
9945
|
+
} catch {
|
|
9946
|
+
return;
|
|
9947
|
+
}
|
|
9948
|
+
}
|
|
9949
|
+
function prompt(question) {
|
|
9950
|
+
const rl = readline.createInterface({ input: process.stdin, output: process.stderr });
|
|
9951
|
+
return new Promise((resolve) => {
|
|
9952
|
+
rl.question(question, (answer) => {
|
|
9953
|
+
rl.close();
|
|
9954
|
+
resolve(answer.trim());
|
|
9955
|
+
});
|
|
9956
|
+
});
|
|
9957
|
+
}
|
|
9958
|
+
async function setup() {
|
|
9959
|
+
const existing = process.env.AMP_API_KEY || loadStoredApiKey();
|
|
9960
|
+
if (existing) {
|
|
9961
|
+
console.error("AMP API key is already configured.");
|
|
9962
|
+
process.exit(0);
|
|
9963
|
+
}
|
|
9964
|
+
console.error("You can get your API key from: https://ampcode.com/settings");
|
|
9965
|
+
const apiKey = await prompt("Paste your AMP API key: ");
|
|
9966
|
+
if (!apiKey) {
|
|
9967
|
+
console.error("No API key provided. Aborting.");
|
|
9968
|
+
process.exit(1);
|
|
9969
|
+
}
|
|
9970
|
+
const configDir = getConfigDir();
|
|
9971
|
+
fs2.mkdirSync(configDir, { recursive: true });
|
|
9972
|
+
const credPath = getCredentialsPath();
|
|
9973
|
+
fs2.writeFileSync(credPath, JSON.stringify({ apiKey }, null, 2) + `
|
|
9974
|
+
`, { mode: 384 });
|
|
9975
|
+
console.error(`API key saved to ${credPath}`);
|
|
9976
|
+
process.exit(0);
|
|
9977
|
+
}
|
|
9978
|
+
if (process.argv.includes("--setup")) {
|
|
9979
|
+
await setup();
|
|
9980
|
+
} else {
|
|
9981
|
+
if (!process.env.AMP_API_KEY) {
|
|
9982
|
+
const stored = loadStoredApiKey();
|
|
9983
|
+
if (stored) {
|
|
9984
|
+
process.env.AMP_API_KEY = stored;
|
|
9985
|
+
}
|
|
9986
|
+
}
|
|
9987
|
+
runAcp();
|
|
9988
|
+
process.stdin.resume();
|
|
9989
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "amp-acp",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.7.0",
|
|
4
4
|
"private": false,
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "dist/index.js",
|
|
@@ -17,18 +17,18 @@
|
|
|
17
17
|
"url": "https://github.com/tao12345666333/amp-acp"
|
|
18
18
|
},
|
|
19
19
|
"scripts": {
|
|
20
|
-
"build": "bun build src/index.ts --target=node --outdir=dist --entry-naming=[dir]/[name].js
|
|
21
|
-
"build:binary": "bun build src/index.ts --target=node --outdir=dist --entry-naming=[dir]/[name].js && bun
|
|
20
|
+
"build": "bun build src/index.ts --target=node --outdir=dist --entry-naming=[dir]/[name].js",
|
|
21
|
+
"build:binary": "bun build src/index.ts --target=node --outdir=dist --entry-naming=[dir]/[name].js && bun build dist/index.js --compile --outfile dist/amp-acp",
|
|
22
22
|
"start": "bun dist/index.js",
|
|
23
23
|
"lint": "tsc --noEmit",
|
|
24
24
|
"test": "bun test src/",
|
|
25
|
-
"test:binary": "bun build src/index.ts --target=node --outdir=dist --entry-naming=[dir]/[name].js && bun
|
|
25
|
+
"test:binary": "bun build src/index.ts --target=node --outdir=dist --entry-naming=[dir]/[name].js && bun build dist/index.js --compile --outfile dist/amp-acp-test && bun test test/binary.test.ts",
|
|
26
26
|
"test:all": "bun run test && bun run test:binary"
|
|
27
27
|
},
|
|
28
28
|
"dependencies": {
|
|
29
29
|
"@agentclientprotocol/sdk": "0.4.8",
|
|
30
30
|
"@sourcegraph/amp": "^0.0.1765685598-g5365e6",
|
|
31
|
-
"@sourcegraph/amp-sdk": "
|
|
31
|
+
"@sourcegraph/amp-sdk": "0.1.0-20260220044036-g88868e6"
|
|
32
32
|
},
|
|
33
33
|
"devDependencies": {
|
|
34
34
|
"@types/bun": "^1.2.5",
|