@agentknight/client 0.9.52 → 0.9.53
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/LICENSE +201 -201
- package/README.md +358 -360
- package/dist/chunks/{chunk-KYTI7A5R.js → chunk-CG5LD6VF.js} +1 -1
- package/dist/chunks/{chunk-YNKNHR5K.js → chunk-CNWBK4LE.js} +0 -2
- package/dist/chunks/{chunk-FLU66YYO.js → chunk-HQX6KKVV.js} +1 -1
- package/dist/chunks/{client-home-LAKFDPXO.js → client-home-GPFY7NJP.js} +6 -101
- package/dist/chunks/{start-client-OBVH54YU.js → start-client-YUTN4EXF.js} +29 -72
- package/dist/chunks/stop-client-PHRAMW5R.js +40 -0
- package/dist/chunks/{upgrade-T32WY4HC.js → upgrade-4IKPYFYS.js} +2 -2
- package/dist/cli.js +28 -8
- package/dist/upgrade-worker.js +0 -1
- package/package.json +2 -2
|
@@ -5,7 +5,6 @@ import { homedir } from "node:os";
|
|
|
5
5
|
import { join, resolve } from "node:path";
|
|
6
6
|
import { fileURLToPath } from "node:url";
|
|
7
7
|
var directoryAliases = [
|
|
8
|
-
["COPILOT_REMOTE_HOME", "AGENTKNIGHT_HOME"],
|
|
9
8
|
["AGENTKNIGHT_PI_DIRECTORY", "PI_CODING_AGENT_DIR"]
|
|
10
9
|
];
|
|
11
10
|
var defaultPairingPagePort = 17888;
|
|
@@ -66,7 +65,6 @@ function normalizeClientEnvironment(source, cwd = process.cwd(), onDeprecated) {
|
|
|
66
65
|
export {
|
|
67
66
|
defaultPairingPagePort,
|
|
68
67
|
defaultClientHome,
|
|
69
|
-
sameClientPath,
|
|
70
68
|
hasDeprecatedClientEnvironment,
|
|
71
69
|
isClientConfigurationKey,
|
|
72
70
|
clearClientConfiguration,
|
|
@@ -18,7 +18,7 @@ function toErrorDetails(error) {
|
|
|
18
18
|
// src/app-version.ts
|
|
19
19
|
import { readFileSync } from "node:fs";
|
|
20
20
|
function readAppVersion() {
|
|
21
|
-
if (true) return "0.9.
|
|
21
|
+
if (true) return "0.9.53";
|
|
22
22
|
const metadata = JSON.parse(readFileSync(new URL("../package.json", import.meta.url), "utf8"));
|
|
23
23
|
if (typeof metadata !== "object" || metadata === null || !("version" in metadata) || typeof metadata.version !== "string" || metadata.version.length === 0) {
|
|
24
24
|
throw new Error("AgentKnight package metadata does not contain a version");
|
|
@@ -4,19 +4,15 @@ import {
|
|
|
4
4
|
defaultClientHome,
|
|
5
5
|
defaultPairingPagePort,
|
|
6
6
|
hasDeprecatedClientEnvironment,
|
|
7
|
-
normalizeClientEnvironment
|
|
8
|
-
|
|
9
|
-
} from "./chunk-YNKNHR5K.js";
|
|
7
|
+
normalizeClientEnvironment
|
|
8
|
+
} from "./chunk-CNWBK4LE.js";
|
|
10
9
|
|
|
11
10
|
// src/client-home.ts
|
|
12
|
-
import {
|
|
13
|
-
import { constants, createReadStream } from "node:fs";
|
|
14
|
-
import { chmod, copyFile, lstat, mkdir, readFile, readdir, writeFile } from "node:fs/promises";
|
|
11
|
+
import { lstat, mkdir, readFile, writeFile } from "node:fs/promises";
|
|
15
12
|
import { homedir } from "node:os";
|
|
16
|
-
import {
|
|
13
|
+
import { join, resolve } from "node:path";
|
|
17
14
|
import { parseEnv } from "node:util";
|
|
18
15
|
var environmentFileName = "agentknight.env";
|
|
19
|
-
var migrationMarker = ".legacy-home-migrated";
|
|
20
16
|
function hasCode(error, code) {
|
|
21
17
|
return error instanceof Error && "code" in error && error.code === code;
|
|
22
18
|
}
|
|
@@ -76,89 +72,11 @@ async function requireStoppedLegacyHome(legacyHome, environments) {
|
|
|
76
72
|
throw new Error(`A local service is running on legacy port ${port}. ${instruction}`);
|
|
77
73
|
}
|
|
78
74
|
}
|
|
79
|
-
async function fileDigest(path) {
|
|
80
|
-
const hash = createHash("sha256");
|
|
81
|
-
for await (const chunk of createReadStream(path)) hash.update(chunk);
|
|
82
|
-
return hash.digest("hex");
|
|
83
|
-
}
|
|
84
|
-
async function filesIn(directory, relative = "") {
|
|
85
|
-
const result = /* @__PURE__ */ new Map();
|
|
86
|
-
const info = await lstat(directory);
|
|
87
|
-
if (!info.isDirectory() || info.isSymbolicLink()) {
|
|
88
|
-
throw new Error(`Cannot safely migrate a linked or non-directory home: ${directory}`);
|
|
89
|
-
}
|
|
90
|
-
for (const entry of await readdir(directory, { withFileTypes: true })) {
|
|
91
|
-
const path = join(directory, entry.name);
|
|
92
|
-
const key = join(relative, entry.name);
|
|
93
|
-
if (entry.isDirectory()) {
|
|
94
|
-
result.set(key, null);
|
|
95
|
-
for (const [child, data] of await filesIn(path, key)) result.set(child, data);
|
|
96
|
-
} else if (entry.isFile()) {
|
|
97
|
-
result.set(key, await fileDigest(path));
|
|
98
|
-
} else {
|
|
99
|
-
throw new Error(`Cannot safely migrate a linked or special file: ${path}`);
|
|
100
|
-
}
|
|
101
|
-
}
|
|
102
|
-
return result;
|
|
103
|
-
}
|
|
104
|
-
async function legacyHomeMigrated(legacyHome, canonicalHome) {
|
|
105
|
-
const marker = join(canonicalHome, migrationMarker);
|
|
106
|
-
if (await exists(canonicalHome)) {
|
|
107
|
-
const info = await lstat(canonicalHome);
|
|
108
|
-
if (!info.isDirectory() || info.isSymbolicLink()) {
|
|
109
|
-
throw new Error(`Cannot safely migrate a linked or non-directory home: ${canonicalHome}`);
|
|
110
|
-
}
|
|
111
|
-
}
|
|
112
|
-
if (await exists(marker)) {
|
|
113
|
-
if (!(await lstat(marker)).isFile()) throw new Error(`Unsafe migration marker in ${canonicalHome}`);
|
|
114
|
-
if (await readFile(marker, "utf8") !== legacyHome) {
|
|
115
|
-
throw new Error(`Unrecognized migration marker in ${canonicalHome}; review the homes before starting.`);
|
|
116
|
-
}
|
|
117
|
-
return true;
|
|
118
|
-
}
|
|
119
|
-
return false;
|
|
120
|
-
}
|
|
121
|
-
async function migrateLegacyHome(legacyHome, canonicalHome, environments) {
|
|
122
|
-
if (await legacyHomeMigrated(legacyHome, canonicalHome)) return;
|
|
123
|
-
if (!await exists(legacyHome)) return;
|
|
124
|
-
await requireStoppedLegacyHome(legacyHome, environments);
|
|
125
|
-
const source = await filesIn(legacyHome);
|
|
126
|
-
if (source.has(migrationMarker)) throw new Error(`Unexpected migration marker in ${legacyHome}`);
|
|
127
|
-
const destination = await exists(canonicalHome) ? await filesIn(canonicalHome) : /* @__PURE__ */ new Map();
|
|
128
|
-
for (const [name, data] of destination) {
|
|
129
|
-
if (name === environmentFileName || name === "service" || name.startsWith(`service${sep}`) || name === "logs" && data === null || name === join("logs", "service") || name.startsWith(join("logs", "service") + sep)) continue;
|
|
130
|
-
if (source.get(name) !== data) {
|
|
131
|
-
throw new Error(`Conflicting legacy and canonical AgentKnight homes: ${legacyHome} and ${canonicalHome}. Choose the correct home with AGENTKNIGHT_HOME or reconcile them while both agents are stopped.`);
|
|
132
|
-
}
|
|
133
|
-
}
|
|
134
|
-
await mkdir(canonicalHome, { recursive: true, mode: 448 });
|
|
135
|
-
for (const [name, data] of source) {
|
|
136
|
-
if (name === environmentFileName || destination.has(name)) continue;
|
|
137
|
-
const target = join(canonicalHome, name);
|
|
138
|
-
if (data === null) {
|
|
139
|
-
await mkdir(target, { recursive: true, mode: 448 });
|
|
140
|
-
continue;
|
|
141
|
-
}
|
|
142
|
-
await mkdir(dirname(target), { recursive: true, mode: 448 });
|
|
143
|
-
await copyFile(join(legacyHome, name), target, constants.COPYFILE_EXCL);
|
|
144
|
-
await chmod(target, 384);
|
|
145
|
-
if (await fileDigest(target) !== data) {
|
|
146
|
-
throw new Error(`Legacy state changed during migration; stop the old agent and reconcile ${canonicalHome}.`);
|
|
147
|
-
}
|
|
148
|
-
}
|
|
149
|
-
await requireStoppedLegacyHome(legacyHome, environments);
|
|
150
|
-
const after = await filesIn(legacyHome);
|
|
151
|
-
if (source.size !== after.size || [...source].some(([name, data]) => after.get(name) !== data)) {
|
|
152
|
-
throw new Error(`Legacy state changed during migration; stop the old agent and reconcile ${canonicalHome}.`);
|
|
153
|
-
}
|
|
154
|
-
await writeFile(join(canonicalHome, migrationMarker), legacyHome, { flag: "wx", mode: 384 });
|
|
155
|
-
}
|
|
156
75
|
async function resolveClientEnvironment(options = {}) {
|
|
157
76
|
if (options.noEnv && options.envFile !== void 0) throw new Error("--no-env cannot be combined with --env.");
|
|
158
77
|
const cwd = resolve(options.cwd ?? process.cwd());
|
|
159
78
|
const home = resolve(options.homeDirectory ?? homedir());
|
|
160
79
|
const canonicalHome = defaultClientHome(home);
|
|
161
|
-
const legacyHome = join(home, ".copilot-remote");
|
|
162
80
|
const explicitEnvFile = options.envFile === void 0 ? void 0 : resolve(cwd, options.envFile);
|
|
163
81
|
const warnings = /* @__PURE__ */ new Set();
|
|
164
82
|
const inherited = { ...options.environment ?? process.env };
|
|
@@ -189,7 +107,6 @@ async function resolveClientEnvironment(options = {}) {
|
|
|
189
107
|
} else if (suppliedHome === void 0) {
|
|
190
108
|
for (const candidate of /* @__PURE__ */ new Set([
|
|
191
109
|
legacyServiceEnv,
|
|
192
|
-
join(legacyHome, environmentFileName),
|
|
193
110
|
join(cwd, ".env"),
|
|
194
111
|
resolve(cwd, "..", "..", ".env")
|
|
195
112
|
])) {
|
|
@@ -218,28 +135,17 @@ async function resolveClientEnvironment(options = {}) {
|
|
|
218
135
|
const fileHome = fileEnvironment.AGENTKNIGHT_HOME?.trim();
|
|
219
136
|
const configuredHome = environment.AGENTKNIGHT_HOME?.trim();
|
|
220
137
|
if (configuredHome === "") throw new Error("AGENTKNIGHT_HOME must not be empty");
|
|
221
|
-
const
|
|
222
|
-
const canonicalDefaultHome = explicitEnvFile === void 0 && envFile === canonicalEnv && fileHome !== void 0 && sameClientPath(fileHome, canonicalHome, cwd);
|
|
223
|
-
const implicitHome = configuredHome === void 0 || (fallbackLegacyHome || canonicalDefaultHome) && suppliedHome === void 0;
|
|
224
|
-
let dataDirectory = configuredHome !== void 0 && !implicitHome ? resolve(cwd, configuredHome) : canonicalHome;
|
|
225
|
-
const migrationPending = options.migrate === false && implicitHome && !await legacyHomeMigrated(legacyHome, canonicalHome) && await exists(legacyHome);
|
|
226
|
-
if (migrationPending && !await exists(canonicalHome)) {
|
|
227
|
-
dataDirectory = legacyHome;
|
|
228
|
-
}
|
|
138
|
+
const dataDirectory = resolve(cwd, configuredHome ?? canonicalHome);
|
|
229
139
|
if (options.migrate !== false) {
|
|
230
140
|
if (fallbackEnv && envFile === legacyServiceEnv) {
|
|
231
141
|
await requireStoppedLegacyHome(dataDirectory, [fileEnvironment, environment]);
|
|
232
142
|
}
|
|
233
|
-
if (implicitHome) {
|
|
234
|
-
await migrateLegacyHome(legacyHome, canonicalHome, [fileEnvironment, environment]);
|
|
235
|
-
}
|
|
236
143
|
if (fallbackEnv) {
|
|
237
144
|
await mkdir(canonicalHome, { recursive: true, mode: 448 });
|
|
238
145
|
let canonicalText = hasDeprecatedClientEnvironment(parseEnv(text)) ? Object.entries(fileEnvironment).flatMap(([key, value]) => value === void 0 ? [] : [environmentAssignment(key, value)]).join("\n") + "\n" : text;
|
|
239
146
|
if (fileHome !== void 0 && fileHome.length > 0) {
|
|
240
|
-
const persistedHome = fallbackLegacyHome ? canonicalHome : resolve(cwd, fileHome);
|
|
241
147
|
canonicalText += `
|
|
242
|
-
${environmentAssignment("AGENTKNIGHT_HOME",
|
|
148
|
+
${environmentAssignment("AGENTKNIGHT_HOME", resolve(cwd, fileHome))}
|
|
243
149
|
`;
|
|
244
150
|
}
|
|
245
151
|
try {
|
|
@@ -259,7 +165,6 @@ ${environmentAssignment("AGENTKNIGHT_HOME", persistedHome)}
|
|
|
259
165
|
environment,
|
|
260
166
|
...envFile === void 0 ? {} : { envFile },
|
|
261
167
|
dataDirectory,
|
|
262
|
-
...migrationPending ? { migrationPending: true } : {},
|
|
263
168
|
...warnings.size === 0 ? {} : { warnings: [...warnings] }
|
|
264
169
|
};
|
|
265
170
|
}
|