ampcode-connector 0.1.13 → 0.1.14
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 +2 -0
- package/package.json +1 -1
- package/src/cli/setup.ts +25 -12
package/README.md
CHANGED
|
@@ -10,6 +10,8 @@ bunx ampcode-connector # start
|
|
|
10
10
|
|
|
11
11
|
Requires [Bun](https://bun.sh) 1.3+. Config at `./config.yaml` or `~/.config/ampcode-connector/config.yaml` — see [`config.example.yaml`](config.example.yaml).
|
|
12
12
|
|
|
13
|
+
`setup` writes `amp.url` to Amp's canonical settings file (`~/.config/amp/settings.json`, or `AMP_SETTINGS_FILE` if set). Amp tokens are stored in `~/.local/share/amp/secrets.json`.
|
|
14
|
+
|
|
13
15
|
## License
|
|
14
16
|
|
|
15
17
|
[MIT](LICENSE)
|
package/package.json
CHANGED
package/src/cli/setup.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/** Auto-configure Amp CLI to route through ampcode-connector. */
|
|
2
2
|
|
|
3
|
-
import { existsSync, mkdirSync, readFileSync, writeFileSync } from "node:fs";
|
|
3
|
+
import { existsSync, lstatSync, mkdirSync, readFileSync, writeFileSync } from "node:fs";
|
|
4
4
|
import { homedir } from "node:os";
|
|
5
5
|
import { dirname, join } from "node:path";
|
|
6
6
|
import { loadConfig } from "../config/config.ts";
|
|
@@ -10,14 +10,26 @@ import * as status from "./status.ts";
|
|
|
10
10
|
const AMP_SECRETS_DIR = join(homedir(), ".local", "share", "amp");
|
|
11
11
|
const AMP_SECRETS_PATH = join(AMP_SECRETS_DIR, "secrets.json");
|
|
12
12
|
|
|
13
|
-
const
|
|
14
|
-
|
|
15
|
-
join(homedir(), ".amp", "settings.json"),
|
|
16
|
-
];
|
|
13
|
+
const AMP_SETTINGS_PATH = join(homedir(), ".config", "amp", "settings.json");
|
|
14
|
+
const AMP_LEGACY_SETTINGS_PATH = join(homedir(), ".amp", "settings.json");
|
|
17
15
|
|
|
18
|
-
function
|
|
16
|
+
function ampSettingsPath(): string {
|
|
19
17
|
const envPath = process.env.AMP_SETTINGS_FILE;
|
|
20
|
-
return envPath
|
|
18
|
+
return envPath || AMP_SETTINGS_PATH;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
function warnLegacySettingsFile(): void {
|
|
22
|
+
if (process.env.AMP_SETTINGS_FILE || !existsSync(AMP_LEGACY_SETTINGS_PATH)) return;
|
|
23
|
+
try {
|
|
24
|
+
if (lstatSync(AMP_LEGACY_SETTINGS_PATH).isSymbolicLink()) return;
|
|
25
|
+
} catch {
|
|
26
|
+
return;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
line(
|
|
30
|
+
`${s.yellow}!${s.reset} Legacy settings file detected at ${s.dim}${AMP_LEGACY_SETTINGS_PATH}${s.reset}. ` +
|
|
31
|
+
`Prefer a single source of truth at ${s.dim}${AMP_SETTINGS_PATH}${s.reset}.`,
|
|
32
|
+
);
|
|
21
33
|
}
|
|
22
34
|
|
|
23
35
|
function readJson(path: string): Record<string, unknown> {
|
|
@@ -88,14 +100,15 @@ export async function setup(): Promise<void> {
|
|
|
88
100
|
line(`${s.bold}ampcode-connector setup${s.reset}`);
|
|
89
101
|
line();
|
|
90
102
|
|
|
91
|
-
// Step 1: Configure amp.url in
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
103
|
+
// Step 1: Configure amp.url in canonical settings file
|
|
104
|
+
const settingsPath = ampSettingsPath();
|
|
105
|
+
const settings = readJson(settingsPath);
|
|
106
|
+
if (settings["amp.url"] !== proxyUrl) {
|
|
95
107
|
settings["amp.url"] = proxyUrl;
|
|
96
108
|
writeJson(settingsPath, settings);
|
|
97
109
|
}
|
|
98
|
-
line(`${s.green}ok${s.reset} amp.url = ${s.cyan}${proxyUrl}${s.reset}`);
|
|
110
|
+
line(`${s.green}ok${s.reset} amp.url = ${s.cyan}${proxyUrl}${s.reset} ${s.dim}${settingsPath}${s.reset}`);
|
|
111
|
+
warnLegacySettingsFile();
|
|
99
112
|
|
|
100
113
|
// Step 2: Amp API key
|
|
101
114
|
const existingKey = findAmpApiKey(proxyUrl);
|