poe-code 3.0.68 → 3.0.69-beta.2
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 +18 -19
- package/dist/cli/commands/ensure-isolated-config.js +1 -1
- package/dist/cli/commands/ensure-isolated-config.js.map +1 -1
- package/dist/cli/commands/login.js +4 -6
- package/dist/cli/commands/login.js.map +1 -1
- package/dist/cli/commands/mcp.js +2 -9
- package/dist/cli/commands/mcp.js.map +1 -1
- package/dist/cli/commands/models.js +1 -5
- package/dist/cli/commands/models.js.map +1 -1
- package/dist/cli/commands/test.js +1 -1
- package/dist/cli/commands/test.js.map +1 -1
- package/dist/cli/commands/wrap.js +1 -0
- package/dist/cli/commands/wrap.js.map +1 -1
- package/dist/cli/container.d.ts +2 -0
- package/dist/cli/container.js +29 -11
- package/dist/cli/container.js.map +1 -1
- package/dist/cli/isolated-env-runner.d.ts +1 -0
- package/dist/cli/isolated-env-runner.js +2 -2
- package/dist/cli/isolated-env-runner.js.map +1 -1
- package/dist/cli/isolated-env.d.ts +2 -2
- package/dist/cli/isolated-env.js +15 -17
- package/dist/cli/isolated-env.js.map +1 -1
- package/dist/cli/poe-code-command-runner.js +2 -2
- package/dist/cli/poe-code-command-runner.js.map +1 -1
- package/dist/index.js +948 -499
- package/dist/index.js.map +4 -4
- package/dist/sdk/container.js +27 -11
- package/dist/sdk/container.js.map +1 -1
- package/dist/sdk/credentials.d.ts +1 -1
- package/dist/sdk/credentials.js +6 -19
- package/dist/sdk/credentials.js.map +1 -1
- package/package.json +2 -1
package/dist/index.js
CHANGED
|
@@ -31,34 +31,469 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
|
|
|
31
31
|
mod
|
|
32
32
|
));
|
|
33
33
|
|
|
34
|
+
// packages/auth/src/encrypted-file-auth-store.ts
|
|
35
|
+
import { createCipheriv, createDecipheriv, randomBytes, scrypt } from "node:crypto";
|
|
36
|
+
import { promises as fs } from "node:fs";
|
|
37
|
+
import { homedir, hostname, userInfo } from "node:os";
|
|
38
|
+
import path from "node:path";
|
|
39
|
+
function defaultMachineIdentity() {
|
|
40
|
+
return {
|
|
41
|
+
hostname: hostname(),
|
|
42
|
+
username: userInfo().username
|
|
43
|
+
};
|
|
44
|
+
}
|
|
45
|
+
async function deriveEncryptionKey(getMachineIdentity) {
|
|
46
|
+
const machineIdentity = await getMachineIdentity();
|
|
47
|
+
const secret = `${machineIdentity.hostname}:${machineIdentity.username}`;
|
|
48
|
+
return await new Promise((resolve, reject) => {
|
|
49
|
+
scrypt(secret, ENCRYPTION_SALT, ENCRYPTION_KEY_BYTES, (error2, derivedKey) => {
|
|
50
|
+
if (error2) {
|
|
51
|
+
reject(error2);
|
|
52
|
+
return;
|
|
53
|
+
}
|
|
54
|
+
resolve(Buffer.from(derivedKey));
|
|
55
|
+
});
|
|
56
|
+
});
|
|
57
|
+
}
|
|
58
|
+
function parseEncryptedDocument(raw) {
|
|
59
|
+
try {
|
|
60
|
+
const parsed = JSON.parse(raw);
|
|
61
|
+
if (!isRecord(parsed)) {
|
|
62
|
+
return null;
|
|
63
|
+
}
|
|
64
|
+
if (parsed.version !== ENCRYPTION_VERSION) {
|
|
65
|
+
return null;
|
|
66
|
+
}
|
|
67
|
+
if (typeof parsed.iv !== "string" || typeof parsed.authTag !== "string" || typeof parsed.ciphertext !== "string") {
|
|
68
|
+
return null;
|
|
69
|
+
}
|
|
70
|
+
return {
|
|
71
|
+
version: parsed.version,
|
|
72
|
+
iv: parsed.iv,
|
|
73
|
+
authTag: parsed.authTag,
|
|
74
|
+
ciphertext: parsed.ciphertext
|
|
75
|
+
};
|
|
76
|
+
} catch {
|
|
77
|
+
return null;
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
function isRecord(value) {
|
|
81
|
+
return Boolean(value && typeof value === "object" && !Array.isArray(value));
|
|
82
|
+
}
|
|
83
|
+
function isNotFoundError(error2) {
|
|
84
|
+
return Boolean(
|
|
85
|
+
error2 && typeof error2 === "object" && "code" in error2 && error2.code === "ENOENT"
|
|
86
|
+
);
|
|
87
|
+
}
|
|
88
|
+
var ENCRYPTION_ALGORITHM, ENCRYPTION_VERSION, ENCRYPTION_KEY_BYTES, ENCRYPTION_IV_BYTES, ENCRYPTION_AUTH_TAG_BYTES, ENCRYPTION_SALT, ENCRYPTION_FILE_MODE, EncryptedFileAuthStore;
|
|
89
|
+
var init_encrypted_file_auth_store = __esm({
|
|
90
|
+
"packages/auth/src/encrypted-file-auth-store.ts"() {
|
|
91
|
+
"use strict";
|
|
92
|
+
ENCRYPTION_ALGORITHM = "aes-256-gcm";
|
|
93
|
+
ENCRYPTION_VERSION = 1;
|
|
94
|
+
ENCRYPTION_KEY_BYTES = 32;
|
|
95
|
+
ENCRYPTION_IV_BYTES = 12;
|
|
96
|
+
ENCRYPTION_AUTH_TAG_BYTES = 16;
|
|
97
|
+
ENCRYPTION_SALT = "poe-code:encrypted-file-auth-store:v1";
|
|
98
|
+
ENCRYPTION_FILE_MODE = 384;
|
|
99
|
+
EncryptedFileAuthStore = class {
|
|
100
|
+
fs;
|
|
101
|
+
filePath;
|
|
102
|
+
getMachineIdentity;
|
|
103
|
+
getRandomBytes;
|
|
104
|
+
keyPromise = null;
|
|
105
|
+
constructor(input = {}) {
|
|
106
|
+
this.fs = input.fs ?? fs;
|
|
107
|
+
this.filePath = input.filePath ?? path.join(
|
|
108
|
+
(input.getHomeDirectory ?? homedir)(),
|
|
109
|
+
".poe-code",
|
|
110
|
+
"credentials.enc"
|
|
111
|
+
);
|
|
112
|
+
this.getMachineIdentity = input.getMachineIdentity ?? defaultMachineIdentity;
|
|
113
|
+
this.getRandomBytes = input.getRandomBytes ?? randomBytes;
|
|
114
|
+
}
|
|
115
|
+
async getApiKey() {
|
|
116
|
+
let rawDocument;
|
|
117
|
+
try {
|
|
118
|
+
rawDocument = await this.fs.readFile(this.filePath, "utf8");
|
|
119
|
+
} catch (error2) {
|
|
120
|
+
if (isNotFoundError(error2)) {
|
|
121
|
+
return null;
|
|
122
|
+
}
|
|
123
|
+
throw error2;
|
|
124
|
+
}
|
|
125
|
+
const document = parseEncryptedDocument(rawDocument);
|
|
126
|
+
if (!document) {
|
|
127
|
+
return null;
|
|
128
|
+
}
|
|
129
|
+
const key = await this.getEncryptionKey();
|
|
130
|
+
try {
|
|
131
|
+
const iv = Buffer.from(document.iv, "base64");
|
|
132
|
+
const authTag = Buffer.from(document.authTag, "base64");
|
|
133
|
+
const ciphertext = Buffer.from(document.ciphertext, "base64");
|
|
134
|
+
if (iv.byteLength !== ENCRYPTION_IV_BYTES || authTag.byteLength !== ENCRYPTION_AUTH_TAG_BYTES) {
|
|
135
|
+
return null;
|
|
136
|
+
}
|
|
137
|
+
const decipher = createDecipheriv(ENCRYPTION_ALGORITHM, key, iv);
|
|
138
|
+
decipher.setAuthTag(authTag);
|
|
139
|
+
const plaintext = Buffer.concat([decipher.update(ciphertext), decipher.final()]);
|
|
140
|
+
return plaintext.toString("utf8");
|
|
141
|
+
} catch {
|
|
142
|
+
return null;
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
async setApiKey(apiKey) {
|
|
146
|
+
const key = await this.getEncryptionKey();
|
|
147
|
+
const iv = this.getRandomBytes(ENCRYPTION_IV_BYTES);
|
|
148
|
+
const cipher = createCipheriv(ENCRYPTION_ALGORITHM, key, iv);
|
|
149
|
+
const ciphertext = Buffer.concat([
|
|
150
|
+
cipher.update(apiKey, "utf8"),
|
|
151
|
+
cipher.final()
|
|
152
|
+
]);
|
|
153
|
+
const authTag = cipher.getAuthTag();
|
|
154
|
+
const document = {
|
|
155
|
+
version: ENCRYPTION_VERSION,
|
|
156
|
+
iv: iv.toString("base64"),
|
|
157
|
+
authTag: authTag.toString("base64"),
|
|
158
|
+
ciphertext: ciphertext.toString("base64")
|
|
159
|
+
};
|
|
160
|
+
await this.fs.mkdir(path.dirname(this.filePath), { recursive: true });
|
|
161
|
+
await this.fs.writeFile(this.filePath, JSON.stringify(document), {
|
|
162
|
+
encoding: "utf8"
|
|
163
|
+
});
|
|
164
|
+
await this.fs.chmod(this.filePath, ENCRYPTION_FILE_MODE);
|
|
165
|
+
}
|
|
166
|
+
async deleteApiKey() {
|
|
167
|
+
try {
|
|
168
|
+
await this.fs.unlink(this.filePath);
|
|
169
|
+
} catch (error2) {
|
|
170
|
+
if (!isNotFoundError(error2)) {
|
|
171
|
+
throw error2;
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
getEncryptionKey() {
|
|
176
|
+
if (!this.keyPromise) {
|
|
177
|
+
this.keyPromise = deriveEncryptionKey(this.getMachineIdentity);
|
|
178
|
+
}
|
|
179
|
+
return this.keyPromise;
|
|
180
|
+
}
|
|
181
|
+
};
|
|
182
|
+
}
|
|
183
|
+
});
|
|
184
|
+
|
|
185
|
+
// packages/auth/src/keychain-auth-store.ts
|
|
186
|
+
import { spawn } from "node:child_process";
|
|
187
|
+
function runSecurityCommand(command, args) {
|
|
188
|
+
return new Promise((resolve) => {
|
|
189
|
+
const child = spawn(command, args, {
|
|
190
|
+
stdio: ["ignore", "pipe", "pipe"]
|
|
191
|
+
});
|
|
192
|
+
let stdout = "";
|
|
193
|
+
let stderr = "";
|
|
194
|
+
child.stdout?.setEncoding("utf8");
|
|
195
|
+
child.stdout?.on("data", (chunk) => {
|
|
196
|
+
stdout += chunk.toString();
|
|
197
|
+
});
|
|
198
|
+
child.stderr?.setEncoding("utf8");
|
|
199
|
+
child.stderr?.on("data", (chunk) => {
|
|
200
|
+
stderr += chunk.toString();
|
|
201
|
+
});
|
|
202
|
+
child.on("error", (error2) => {
|
|
203
|
+
const message = error2 instanceof Error ? error2.message : String(error2 ?? "Unknown error");
|
|
204
|
+
resolve({
|
|
205
|
+
stdout,
|
|
206
|
+
stderr: stderr ? `${stderr}${message}` : message,
|
|
207
|
+
exitCode: 127
|
|
208
|
+
});
|
|
209
|
+
});
|
|
210
|
+
child.on("close", (code) => {
|
|
211
|
+
resolve({
|
|
212
|
+
stdout,
|
|
213
|
+
stderr,
|
|
214
|
+
exitCode: code ?? 0
|
|
215
|
+
});
|
|
216
|
+
});
|
|
217
|
+
});
|
|
218
|
+
}
|
|
219
|
+
function stripTrailingLineBreak(value) {
|
|
220
|
+
if (value.endsWith("\r\n")) {
|
|
221
|
+
return value.slice(0, -2);
|
|
222
|
+
}
|
|
223
|
+
if (value.endsWith("\n") || value.endsWith("\r")) {
|
|
224
|
+
return value.slice(0, -1);
|
|
225
|
+
}
|
|
226
|
+
return value;
|
|
227
|
+
}
|
|
228
|
+
function isKeychainEntryNotFound(result) {
|
|
229
|
+
if (result.exitCode === KEYCHAIN_ITEM_NOT_FOUND_EXIT_CODE) {
|
|
230
|
+
return true;
|
|
231
|
+
}
|
|
232
|
+
const output = `${result.stderr}
|
|
233
|
+
${result.stdout}`.toLowerCase();
|
|
234
|
+
return output.includes("could not be found") || output.includes("item not found") || output.includes("errsecitemnotfound");
|
|
235
|
+
}
|
|
236
|
+
function createSecurityCliFailure(operation, result) {
|
|
237
|
+
const details = result.stderr.trim() || result.stdout.trim();
|
|
238
|
+
if (details) {
|
|
239
|
+
return new Error(
|
|
240
|
+
`Failed to ${operation}: security exited with code ${result.exitCode}: ${details}`
|
|
241
|
+
);
|
|
242
|
+
}
|
|
243
|
+
return new Error(`Failed to ${operation}: security exited with code ${result.exitCode}`);
|
|
244
|
+
}
|
|
245
|
+
var SECURITY_CLI, KEYCHAIN_SERVICE, KEYCHAIN_ACCOUNT, KEYCHAIN_ITEM_NOT_FOUND_EXIT_CODE, KeychainAuthStore;
|
|
246
|
+
var init_keychain_auth_store = __esm({
|
|
247
|
+
"packages/auth/src/keychain-auth-store.ts"() {
|
|
248
|
+
"use strict";
|
|
249
|
+
SECURITY_CLI = "security";
|
|
250
|
+
KEYCHAIN_SERVICE = "poe-code";
|
|
251
|
+
KEYCHAIN_ACCOUNT = "api-key";
|
|
252
|
+
KEYCHAIN_ITEM_NOT_FOUND_EXIT_CODE = 44;
|
|
253
|
+
KeychainAuthStore = class {
|
|
254
|
+
runCommand;
|
|
255
|
+
service;
|
|
256
|
+
account;
|
|
257
|
+
constructor(input = {}) {
|
|
258
|
+
this.runCommand = input.runCommand ?? runSecurityCommand;
|
|
259
|
+
this.service = input.service ?? KEYCHAIN_SERVICE;
|
|
260
|
+
this.account = input.account ?? KEYCHAIN_ACCOUNT;
|
|
261
|
+
}
|
|
262
|
+
async getApiKey() {
|
|
263
|
+
const result = await this.executeSecurityCommand(
|
|
264
|
+
["find-generic-password", "-s", this.service, "-a", this.account, "-w"],
|
|
265
|
+
"read API key from macOS Keychain"
|
|
266
|
+
);
|
|
267
|
+
if (result.exitCode === 0) {
|
|
268
|
+
return stripTrailingLineBreak(result.stdout);
|
|
269
|
+
}
|
|
270
|
+
if (isKeychainEntryNotFound(result)) {
|
|
271
|
+
return null;
|
|
272
|
+
}
|
|
273
|
+
throw createSecurityCliFailure("read API key from macOS Keychain", result);
|
|
274
|
+
}
|
|
275
|
+
async setApiKey(apiKey) {
|
|
276
|
+
const result = await this.executeSecurityCommand(
|
|
277
|
+
[
|
|
278
|
+
"add-generic-password",
|
|
279
|
+
"-s",
|
|
280
|
+
this.service,
|
|
281
|
+
"-a",
|
|
282
|
+
this.account,
|
|
283
|
+
"-w",
|
|
284
|
+
apiKey,
|
|
285
|
+
"-U"
|
|
286
|
+
],
|
|
287
|
+
"store API key in macOS Keychain"
|
|
288
|
+
);
|
|
289
|
+
if (result.exitCode !== 0) {
|
|
290
|
+
throw createSecurityCliFailure("store API key in macOS Keychain", result);
|
|
291
|
+
}
|
|
292
|
+
}
|
|
293
|
+
async deleteApiKey() {
|
|
294
|
+
const result = await this.executeSecurityCommand(
|
|
295
|
+
["delete-generic-password", "-s", this.service, "-a", this.account],
|
|
296
|
+
"delete API key from macOS Keychain"
|
|
297
|
+
);
|
|
298
|
+
if (result.exitCode === 0 || isKeychainEntryNotFound(result)) {
|
|
299
|
+
return;
|
|
300
|
+
}
|
|
301
|
+
throw createSecurityCliFailure("delete API key from macOS Keychain", result);
|
|
302
|
+
}
|
|
303
|
+
async executeSecurityCommand(args, operation) {
|
|
304
|
+
try {
|
|
305
|
+
return await this.runCommand(SECURITY_CLI, args);
|
|
306
|
+
} catch (error2) {
|
|
307
|
+
const message = error2 instanceof Error ? error2.message : String(error2);
|
|
308
|
+
throw new Error(`Failed to ${operation}: ${message}`);
|
|
309
|
+
}
|
|
310
|
+
}
|
|
311
|
+
};
|
|
312
|
+
}
|
|
313
|
+
});
|
|
314
|
+
|
|
315
|
+
// packages/auth/src/create-auth-store.ts
|
|
316
|
+
import { promises as nodeFs } from "node:fs";
|
|
317
|
+
import { homedir as homedir2 } from "node:os";
|
|
318
|
+
import path2 from "node:path";
|
|
319
|
+
function createAuthStore(input = {}) {
|
|
320
|
+
const backend = resolveBackend(input);
|
|
321
|
+
const platform = input.platform ?? process.platform;
|
|
322
|
+
if (backend === "keychain" && platform !== MACOS_PLATFORM) {
|
|
323
|
+
throw new Error(
|
|
324
|
+
`POE_AUTH_BACKEND=keychain is only supported on macOS. Current platform: ${platform}`
|
|
325
|
+
);
|
|
326
|
+
}
|
|
327
|
+
const store = authStoreFactories[backend](input);
|
|
328
|
+
return {
|
|
329
|
+
backend,
|
|
330
|
+
store: enableLegacyCredentialsMigration(store, input)
|
|
331
|
+
};
|
|
332
|
+
}
|
|
333
|
+
function resolveBackend(input) {
|
|
334
|
+
const configuredBackend = input.backend ?? input.env?.[AUTH_BACKEND_ENV_VAR] ?? process.env[AUTH_BACKEND_ENV_VAR];
|
|
335
|
+
if (configuredBackend === "keychain") {
|
|
336
|
+
return "keychain";
|
|
337
|
+
}
|
|
338
|
+
return "file";
|
|
339
|
+
}
|
|
340
|
+
function enableLegacyCredentialsMigration(store, input) {
|
|
341
|
+
const migrationContext = createLegacyMigrationContext(input);
|
|
342
|
+
const readApiKeyFromStore = store.getApiKey.bind(store);
|
|
343
|
+
let hasCheckedLegacyCredentials = false;
|
|
344
|
+
let legacyMigrationPromise = null;
|
|
345
|
+
store.getApiKey = async () => {
|
|
346
|
+
const storedApiKey = await readApiKeyFromStore();
|
|
347
|
+
if (isNonEmptyString(storedApiKey)) {
|
|
348
|
+
return storedApiKey;
|
|
349
|
+
}
|
|
350
|
+
if (hasCheckedLegacyCredentials) {
|
|
351
|
+
return null;
|
|
352
|
+
}
|
|
353
|
+
if (!legacyMigrationPromise) {
|
|
354
|
+
legacyMigrationPromise = migrateLegacyApiKey(store, migrationContext).finally(() => {
|
|
355
|
+
hasCheckedLegacyCredentials = true;
|
|
356
|
+
legacyMigrationPromise = null;
|
|
357
|
+
});
|
|
358
|
+
}
|
|
359
|
+
return legacyMigrationPromise;
|
|
360
|
+
};
|
|
361
|
+
return store;
|
|
362
|
+
}
|
|
363
|
+
async function migrateLegacyApiKey(store, migrationContext) {
|
|
364
|
+
const legacyCredentials = await loadLegacyCredentials(
|
|
365
|
+
migrationContext.fs,
|
|
366
|
+
migrationContext.filePath
|
|
367
|
+
);
|
|
368
|
+
if (!legacyCredentials || !isNonEmptyString(legacyCredentials.apiKey)) {
|
|
369
|
+
return null;
|
|
370
|
+
}
|
|
371
|
+
const plaintextApiKey = legacyCredentials.apiKey;
|
|
372
|
+
try {
|
|
373
|
+
await store.setApiKey(plaintextApiKey);
|
|
374
|
+
delete legacyCredentials.apiKey;
|
|
375
|
+
await saveLegacyCredentials(
|
|
376
|
+
migrationContext.fs,
|
|
377
|
+
migrationContext.filePath,
|
|
378
|
+
legacyCredentials
|
|
379
|
+
);
|
|
380
|
+
} catch (error2) {
|
|
381
|
+
migrationContext.logWarning(
|
|
382
|
+
`Failed to migrate plaintext API key from ${migrationContext.filePath}.`,
|
|
383
|
+
error2
|
|
384
|
+
);
|
|
385
|
+
}
|
|
386
|
+
return plaintextApiKey;
|
|
387
|
+
}
|
|
388
|
+
function createLegacyMigrationContext(input) {
|
|
389
|
+
const legacyCredentialsInput = input.legacyCredentials;
|
|
390
|
+
const getHomeDirectory = legacyCredentialsInput?.getHomeDirectory ?? homedir2;
|
|
391
|
+
return {
|
|
392
|
+
fs: legacyCredentialsInput?.fs ?? input.fileStore?.fs ?? nodeFs,
|
|
393
|
+
filePath: legacyCredentialsInput?.filePath ?? path2.join(
|
|
394
|
+
getHomeDirectory(),
|
|
395
|
+
LEGACY_CREDENTIALS_RELATIVE_PATH
|
|
396
|
+
),
|
|
397
|
+
logWarning: legacyCredentialsInput?.logWarning ?? defaultMigrationWarning
|
|
398
|
+
};
|
|
399
|
+
}
|
|
400
|
+
async function loadLegacyCredentials(fs3, filePath) {
|
|
401
|
+
let raw;
|
|
402
|
+
try {
|
|
403
|
+
raw = await fs3.readFile(filePath, "utf8");
|
|
404
|
+
} catch (error2) {
|
|
405
|
+
if (isNotFoundError2(error2)) {
|
|
406
|
+
return null;
|
|
407
|
+
}
|
|
408
|
+
return null;
|
|
409
|
+
}
|
|
410
|
+
try {
|
|
411
|
+
const parsed = JSON.parse(raw);
|
|
412
|
+
if (!isRecord2(parsed)) {
|
|
413
|
+
return null;
|
|
414
|
+
}
|
|
415
|
+
return parsed;
|
|
416
|
+
} catch {
|
|
417
|
+
return null;
|
|
418
|
+
}
|
|
419
|
+
}
|
|
420
|
+
async function saveLegacyCredentials(fs3, filePath, document) {
|
|
421
|
+
await fs3.mkdir(path2.dirname(filePath), { recursive: true });
|
|
422
|
+
await fs3.writeFile(filePath, `${JSON.stringify(document, null, 2)}
|
|
423
|
+
`, {
|
|
424
|
+
encoding: "utf8"
|
|
425
|
+
});
|
|
426
|
+
}
|
|
427
|
+
function defaultMigrationWarning(message, error2) {
|
|
428
|
+
const details = toErrorDetails(error2);
|
|
429
|
+
if (details.length > 0) {
|
|
430
|
+
console.warn(`${message} ${details}`);
|
|
431
|
+
return;
|
|
432
|
+
}
|
|
433
|
+
console.warn(message);
|
|
434
|
+
}
|
|
435
|
+
function toErrorDetails(error2) {
|
|
436
|
+
if (error2 instanceof Error) {
|
|
437
|
+
return error2.message;
|
|
438
|
+
}
|
|
439
|
+
return typeof error2 === "string" ? error2 : "";
|
|
440
|
+
}
|
|
441
|
+
function isNonEmptyString(value) {
|
|
442
|
+
return typeof value === "string" && value.length > 0;
|
|
443
|
+
}
|
|
444
|
+
function isRecord2(value) {
|
|
445
|
+
return Boolean(value && typeof value === "object" && !Array.isArray(value));
|
|
446
|
+
}
|
|
447
|
+
function isNotFoundError2(error2) {
|
|
448
|
+
return Boolean(
|
|
449
|
+
error2 && typeof error2 === "object" && "code" in error2 && error2.code === "ENOENT"
|
|
450
|
+
);
|
|
451
|
+
}
|
|
452
|
+
var AUTH_BACKEND_ENV_VAR, MACOS_PLATFORM, LEGACY_CREDENTIALS_RELATIVE_PATH, authStoreFactories;
|
|
453
|
+
var init_create_auth_store = __esm({
|
|
454
|
+
"packages/auth/src/create-auth-store.ts"() {
|
|
455
|
+
"use strict";
|
|
456
|
+
init_encrypted_file_auth_store();
|
|
457
|
+
init_keychain_auth_store();
|
|
458
|
+
AUTH_BACKEND_ENV_VAR = "POE_AUTH_BACKEND";
|
|
459
|
+
MACOS_PLATFORM = "darwin";
|
|
460
|
+
LEGACY_CREDENTIALS_RELATIVE_PATH = ".poe-code/credentials.json";
|
|
461
|
+
authStoreFactories = {
|
|
462
|
+
file: (input) => new EncryptedFileAuthStore(input.fileStore),
|
|
463
|
+
keychain: (input) => new KeychainAuthStore(input.keychainStore)
|
|
464
|
+
};
|
|
465
|
+
}
|
|
466
|
+
});
|
|
467
|
+
|
|
468
|
+
// packages/auth/src/index.ts
|
|
469
|
+
var init_src = __esm({
|
|
470
|
+
"packages/auth/src/index.ts"() {
|
|
471
|
+
"use strict";
|
|
472
|
+
init_create_auth_store();
|
|
473
|
+
init_encrypted_file_auth_store();
|
|
474
|
+
init_keychain_auth_store();
|
|
475
|
+
}
|
|
476
|
+
});
|
|
477
|
+
|
|
34
478
|
// src/sdk/credentials.ts
|
|
35
|
-
import * as fs from "node:fs/promises";
|
|
36
|
-
import * as os from "node:os";
|
|
37
|
-
import * as path from "node:path";
|
|
38
479
|
async function getPoeApiKey() {
|
|
39
480
|
const envKey = process.env.POE_API_KEY;
|
|
40
481
|
if (typeof envKey === "string" && envKey.trim().length > 0) {
|
|
41
482
|
return envKey.trim();
|
|
42
483
|
}
|
|
43
|
-
const
|
|
44
|
-
const
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
const parsed = JSON.parse(content);
|
|
48
|
-
if (typeof parsed === "object" && parsed !== null && typeof parsed.apiKey === "string" && parsed.apiKey.length > 0) {
|
|
49
|
-
return parsed.apiKey;
|
|
50
|
-
}
|
|
51
|
-
} catch {
|
|
484
|
+
const { store } = createAuthStore();
|
|
485
|
+
const storedKey = await store.getApiKey();
|
|
486
|
+
if (typeof storedKey === "string" && storedKey.trim().length > 0) {
|
|
487
|
+
return storedKey.trim();
|
|
52
488
|
}
|
|
53
489
|
throw new Error(
|
|
54
490
|
"No API key found. Set POE_API_KEY or run 'poe-code login'."
|
|
55
491
|
);
|
|
56
492
|
}
|
|
57
|
-
var CREDENTIALS_RELATIVE_PATH;
|
|
58
493
|
var init_credentials = __esm({
|
|
59
494
|
"src/sdk/credentials.ts"() {
|
|
60
495
|
"use strict";
|
|
61
|
-
|
|
496
|
+
init_src();
|
|
62
497
|
}
|
|
63
498
|
});
|
|
64
499
|
|
|
@@ -383,16 +818,16 @@ function getConfigFormat(pathOrFormat) {
|
|
|
383
818
|
}
|
|
384
819
|
return formatRegistry[formatName];
|
|
385
820
|
}
|
|
386
|
-
function detectFormat(
|
|
387
|
-
const ext = getExtension(
|
|
821
|
+
function detectFormat(path21) {
|
|
822
|
+
const ext = getExtension(path21);
|
|
388
823
|
return extensionMap[ext];
|
|
389
824
|
}
|
|
390
|
-
function getExtension(
|
|
391
|
-
const lastDot =
|
|
825
|
+
function getExtension(path21) {
|
|
826
|
+
const lastDot = path21.lastIndexOf(".");
|
|
392
827
|
if (lastDot === -1) {
|
|
393
828
|
return "";
|
|
394
829
|
}
|
|
395
|
-
return
|
|
830
|
+
return path21.slice(lastDot).toLowerCase();
|
|
396
831
|
}
|
|
397
832
|
var formatRegistry, extensionMap;
|
|
398
833
|
var init_formats = __esm({
|
|
@@ -414,7 +849,7 @@ var init_formats = __esm({
|
|
|
414
849
|
});
|
|
415
850
|
|
|
416
851
|
// packages/config-mutations/src/execution/path-utils.ts
|
|
417
|
-
import
|
|
852
|
+
import path3 from "node:path";
|
|
418
853
|
function expandHome(targetPath, homeDir) {
|
|
419
854
|
if (!targetPath?.startsWith("~")) {
|
|
420
855
|
return targetPath;
|
|
@@ -431,7 +866,7 @@ function expandHome(targetPath, homeDir) {
|
|
|
431
866
|
remainder = remainder.slice(1);
|
|
432
867
|
}
|
|
433
868
|
}
|
|
434
|
-
return remainder.length === 0 ? homeDir :
|
|
869
|
+
return remainder.length === 0 ? homeDir : path3.join(homeDir, remainder);
|
|
435
870
|
}
|
|
436
871
|
function validateHomePath(targetPath) {
|
|
437
872
|
if (typeof targetPath !== "string" || targetPath.length === 0) {
|
|
@@ -449,12 +884,12 @@ function resolvePath(rawPath, homeDir, pathMapper) {
|
|
|
449
884
|
if (!pathMapper) {
|
|
450
885
|
return expanded;
|
|
451
886
|
}
|
|
452
|
-
const rawDirectory =
|
|
887
|
+
const rawDirectory = path3.dirname(expanded);
|
|
453
888
|
const mappedDirectory = pathMapper.mapTargetDirectory({
|
|
454
889
|
targetDirectory: rawDirectory
|
|
455
890
|
});
|
|
456
|
-
const filename =
|
|
457
|
-
return filename.length === 0 ? mappedDirectory :
|
|
891
|
+
const filename = path3.basename(expanded);
|
|
892
|
+
return filename.length === 0 ? mappedDirectory : path3.join(mappedDirectory, filename);
|
|
458
893
|
}
|
|
459
894
|
var init_path_utils = __esm({
|
|
460
895
|
"packages/config-mutations/src/execution/path-utils.ts"() {
|
|
@@ -1115,7 +1550,7 @@ var init_types = __esm({
|
|
|
1115
1550
|
});
|
|
1116
1551
|
|
|
1117
1552
|
// packages/config-mutations/src/index.ts
|
|
1118
|
-
var
|
|
1553
|
+
var init_src2 = __esm({
|
|
1119
1554
|
"packages/config-mutations/src/index.ts"() {
|
|
1120
1555
|
"use strict";
|
|
1121
1556
|
init_config_mutation();
|
|
@@ -1135,38 +1570,38 @@ import { createTwoFilesPatch } from "diff";
|
|
|
1135
1570
|
import chalk from "chalk";
|
|
1136
1571
|
function createDryRunFileSystem(base, recorder) {
|
|
1137
1572
|
const proxy = {
|
|
1138
|
-
async readFile(
|
|
1573
|
+
async readFile(path21, encoding) {
|
|
1139
1574
|
if (encoding) {
|
|
1140
|
-
return base.readFile(
|
|
1575
|
+
return base.readFile(path21, encoding);
|
|
1141
1576
|
}
|
|
1142
|
-
return base.readFile(
|
|
1577
|
+
return base.readFile(path21);
|
|
1143
1578
|
},
|
|
1144
|
-
async writeFile(
|
|
1145
|
-
const previousContent = await tryReadText(base,
|
|
1579
|
+
async writeFile(path21, data, options) {
|
|
1580
|
+
const previousContent = await tryReadText(base, path21);
|
|
1146
1581
|
const nextContent = formatData(data, options?.encoding);
|
|
1147
1582
|
recorder.record({
|
|
1148
1583
|
type: "writeFile",
|
|
1149
|
-
path:
|
|
1584
|
+
path: path21,
|
|
1150
1585
|
nextContent,
|
|
1151
1586
|
previousContent
|
|
1152
1587
|
});
|
|
1153
1588
|
},
|
|
1154
|
-
async mkdir(
|
|
1155
|
-
recorder.record({ type: "mkdir", path:
|
|
1589
|
+
async mkdir(path21, options) {
|
|
1590
|
+
recorder.record({ type: "mkdir", path: path21, options });
|
|
1156
1591
|
},
|
|
1157
|
-
async stat(
|
|
1158
|
-
return base.stat(
|
|
1592
|
+
async stat(path21) {
|
|
1593
|
+
return base.stat(path21);
|
|
1159
1594
|
},
|
|
1160
|
-
async unlink(
|
|
1161
|
-
recorder.record({ type: "unlink", path:
|
|
1595
|
+
async unlink(path21) {
|
|
1596
|
+
recorder.record({ type: "unlink", path: path21 });
|
|
1162
1597
|
},
|
|
1163
|
-
async readdir(
|
|
1164
|
-
return base.readdir(
|
|
1598
|
+
async readdir(path21) {
|
|
1599
|
+
return base.readdir(path21);
|
|
1165
1600
|
}
|
|
1166
1601
|
};
|
|
1167
1602
|
if (typeof base.rm === "function") {
|
|
1168
|
-
proxy.rm = async (
|
|
1169
|
-
recorder.record({ type: "rm", path:
|
|
1603
|
+
proxy.rm = async (path21, options) => {
|
|
1604
|
+
recorder.record({ type: "rm", path: path21, options });
|
|
1170
1605
|
};
|
|
1171
1606
|
}
|
|
1172
1607
|
if (typeof base.copyFile === "function") {
|
|
@@ -1256,8 +1691,8 @@ function describeWriteChange(previous, next) {
|
|
|
1256
1691
|
}
|
|
1257
1692
|
return "update";
|
|
1258
1693
|
}
|
|
1259
|
-
function renderWriteCommand(
|
|
1260
|
-
const command = `cat > ${
|
|
1694
|
+
function renderWriteCommand(path21, change) {
|
|
1695
|
+
const command = `cat > ${path21}`;
|
|
1261
1696
|
if (change === "create") {
|
|
1262
1697
|
return renderOperationCommand(command, chalk.green, "# create");
|
|
1263
1698
|
}
|
|
@@ -1419,9 +1854,9 @@ function redactTomlLine(line) {
|
|
|
1419
1854
|
}
|
|
1420
1855
|
return line;
|
|
1421
1856
|
}
|
|
1422
|
-
async function tryReadText(base,
|
|
1857
|
+
async function tryReadText(base, path21) {
|
|
1423
1858
|
try {
|
|
1424
|
-
return await base.readFile(
|
|
1859
|
+
return await base.readFile(path21, "utf8");
|
|
1425
1860
|
} catch (error2) {
|
|
1426
1861
|
if (isNotFound(error2)) {
|
|
1427
1862
|
return null;
|
|
@@ -1447,7 +1882,7 @@ var REDACTED_PLACEHOLDER, JSON_SENSITIVE_KEYS, AUTH_SENSITIVE_KEYS, TOML_SENSITI
|
|
|
1447
1882
|
var init_dry_run = __esm({
|
|
1448
1883
|
"src/utils/dry-run.ts"() {
|
|
1449
1884
|
"use strict";
|
|
1450
|
-
|
|
1885
|
+
init_src2();
|
|
1451
1886
|
REDACTED_PLACEHOLDER = "<redacted>";
|
|
1452
1887
|
JSON_SENSITIVE_KEYS = ["apiKey", "api_key", "apiKeyHelper"];
|
|
1453
1888
|
AUTH_SENSITIVE_KEYS = ["key"];
|
|
@@ -1597,170 +2032,9 @@ var init_context = __esm({
|
|
|
1597
2032
|
}
|
|
1598
2033
|
});
|
|
1599
2034
|
|
|
1600
|
-
// src/services/credentials.ts
|
|
1601
|
-
import path3 from "node:path";
|
|
1602
|
-
async function saveCredentials(options) {
|
|
1603
|
-
const { fs: fs3, filePath, apiKey } = options;
|
|
1604
|
-
const document = await readCredentialsDocument(fs3, filePath);
|
|
1605
|
-
document.apiKey = apiKey;
|
|
1606
|
-
await writeCredentialsDocument(fs3, filePath, document);
|
|
1607
|
-
}
|
|
1608
|
-
async function loadCredentials(options) {
|
|
1609
|
-
const { fs: fs3, filePath } = options;
|
|
1610
|
-
const document = await readCredentialsDocument(fs3, filePath);
|
|
1611
|
-
return typeof document.apiKey === "string" && document.apiKey.length > 0 ? document.apiKey : null;
|
|
1612
|
-
}
|
|
1613
|
-
async function deleteCredentials(options) {
|
|
1614
|
-
const { fs: fs3, filePath } = options;
|
|
1615
|
-
try {
|
|
1616
|
-
await fs3.unlink(filePath);
|
|
1617
|
-
return true;
|
|
1618
|
-
} catch (error2) {
|
|
1619
|
-
if (isNotFound(error2)) {
|
|
1620
|
-
return false;
|
|
1621
|
-
}
|
|
1622
|
-
throw error2;
|
|
1623
|
-
}
|
|
1624
|
-
}
|
|
1625
|
-
async function loadConfiguredServices(options) {
|
|
1626
|
-
const { fs: fs3, filePath } = options;
|
|
1627
|
-
const document = await readCredentialsDocument(fs3, filePath);
|
|
1628
|
-
return { ...document.configured_services ?? {} };
|
|
1629
|
-
}
|
|
1630
|
-
async function saveConfiguredService(options) {
|
|
1631
|
-
const { fs: fs3, filePath, service, metadata } = options;
|
|
1632
|
-
const document = await readCredentialsDocument(fs3, filePath);
|
|
1633
|
-
const normalized = normalizeConfiguredServiceMetadata(metadata);
|
|
1634
|
-
document.configured_services = {
|
|
1635
|
-
...document.configured_services ?? {},
|
|
1636
|
-
[service]: normalized
|
|
1637
|
-
};
|
|
1638
|
-
await writeCredentialsDocument(fs3, filePath, document);
|
|
1639
|
-
}
|
|
1640
|
-
async function unconfigureService(options) {
|
|
1641
|
-
const { fs: fs3, filePath, service } = options;
|
|
1642
|
-
const document = await readCredentialsDocument(fs3, filePath);
|
|
1643
|
-
const services = document.configured_services;
|
|
1644
|
-
if (!services || !(service in services)) {
|
|
1645
|
-
return false;
|
|
1646
|
-
}
|
|
1647
|
-
delete services[service];
|
|
1648
|
-
if (Object.keys(services).length === 0) {
|
|
1649
|
-
delete document.configured_services;
|
|
1650
|
-
}
|
|
1651
|
-
await writeCredentialsDocument(fs3, filePath, document);
|
|
1652
|
-
return true;
|
|
1653
|
-
}
|
|
1654
|
-
function normalizeConfiguredServiceMetadata(metadata) {
|
|
1655
|
-
const seen = /* @__PURE__ */ new Set();
|
|
1656
|
-
const files = [];
|
|
1657
|
-
for (const entry of metadata.files ?? []) {
|
|
1658
|
-
if (typeof entry !== "string" || entry.length === 0) {
|
|
1659
|
-
continue;
|
|
1660
|
-
}
|
|
1661
|
-
if (!seen.has(entry)) {
|
|
1662
|
-
files.push(entry);
|
|
1663
|
-
seen.add(entry);
|
|
1664
|
-
}
|
|
1665
|
-
}
|
|
1666
|
-
return {
|
|
1667
|
-
files
|
|
1668
|
-
};
|
|
1669
|
-
}
|
|
1670
|
-
async function readCredentialsDocument(fs3, filePath) {
|
|
1671
|
-
try {
|
|
1672
|
-
const raw = await fs3.readFile(filePath, "utf8");
|
|
1673
|
-
return await parseCredentialsDocument(fs3, filePath, raw);
|
|
1674
|
-
} catch (error2) {
|
|
1675
|
-
if (isNotFound(error2)) {
|
|
1676
|
-
return {};
|
|
1677
|
-
}
|
|
1678
|
-
throw error2;
|
|
1679
|
-
}
|
|
1680
|
-
}
|
|
1681
|
-
async function parseCredentialsDocument(fs3, filePath, raw) {
|
|
1682
|
-
try {
|
|
1683
|
-
const parsed = JSON.parse(raw);
|
|
1684
|
-
return normalizeCredentialsDocument(parsed);
|
|
1685
|
-
} catch (error2) {
|
|
1686
|
-
if (error2 instanceof SyntaxError) {
|
|
1687
|
-
await recoverInvalidCredentials(fs3, filePath, raw);
|
|
1688
|
-
return {};
|
|
1689
|
-
}
|
|
1690
|
-
throw error2;
|
|
1691
|
-
}
|
|
1692
|
-
}
|
|
1693
|
-
function normalizeCredentialsDocument(value) {
|
|
1694
|
-
if (!isRecord(value)) {
|
|
1695
|
-
return {};
|
|
1696
|
-
}
|
|
1697
|
-
const document = {};
|
|
1698
|
-
if (typeof value.apiKey === "string" && value.apiKey.length > 0) {
|
|
1699
|
-
document.apiKey = value.apiKey;
|
|
1700
|
-
}
|
|
1701
|
-
const services = normalizeConfiguredServices(value.configured_services);
|
|
1702
|
-
if (Object.keys(services).length > 0) {
|
|
1703
|
-
document.configured_services = services;
|
|
1704
|
-
}
|
|
1705
|
-
return document;
|
|
1706
|
-
}
|
|
1707
|
-
function normalizeConfiguredServices(value) {
|
|
1708
|
-
if (!isRecord(value)) {
|
|
1709
|
-
return {};
|
|
1710
|
-
}
|
|
1711
|
-
const entries = {};
|
|
1712
|
-
for (const [key, entry] of Object.entries(value)) {
|
|
1713
|
-
if (!isRecord(entry)) {
|
|
1714
|
-
continue;
|
|
1715
|
-
}
|
|
1716
|
-
const normalized = normalizeConfiguredServiceMetadata({
|
|
1717
|
-
files: Array.isArray(entry.files) ? entry.files : []
|
|
1718
|
-
});
|
|
1719
|
-
entries[key] = normalized;
|
|
1720
|
-
}
|
|
1721
|
-
return entries;
|
|
1722
|
-
}
|
|
1723
|
-
async function writeCredentialsDocument(fs3, filePath, document) {
|
|
1724
|
-
await fs3.mkdir(path3.dirname(filePath), { recursive: true });
|
|
1725
|
-
const payload = {};
|
|
1726
|
-
if (document.apiKey) {
|
|
1727
|
-
payload.apiKey = document.apiKey;
|
|
1728
|
-
}
|
|
1729
|
-
if (document.configured_services) {
|
|
1730
|
-
payload.configured_services = document.configured_services;
|
|
1731
|
-
}
|
|
1732
|
-
await fs3.writeFile(filePath, `${JSON.stringify(payload, null, 2)}
|
|
1733
|
-
`, {
|
|
1734
|
-
encoding: "utf8"
|
|
1735
|
-
});
|
|
1736
|
-
}
|
|
1737
|
-
async function recoverInvalidCredentials(fs3, filePath, content) {
|
|
1738
|
-
const backupPath = createInvalidBackupPath(filePath);
|
|
1739
|
-
await fs3.writeFile(backupPath, content, { encoding: "utf8" });
|
|
1740
|
-
await fs3.writeFile(filePath, EMPTY_DOCUMENT, { encoding: "utf8" });
|
|
1741
|
-
}
|
|
1742
|
-
function createInvalidBackupPath(filePath) {
|
|
1743
|
-
const timestamp = (/* @__PURE__ */ new Date()).toISOString().replace(/[:.]/g, "-");
|
|
1744
|
-
const dir = path3.dirname(filePath);
|
|
1745
|
-
const base = path3.basename(filePath);
|
|
1746
|
-
return path3.join(dir, `${base}.invalid-${timestamp}.json`);
|
|
1747
|
-
}
|
|
1748
|
-
function isRecord(value) {
|
|
1749
|
-
return Boolean(value && typeof value === "object" && !Array.isArray(value));
|
|
1750
|
-
}
|
|
1751
|
-
var EMPTY_DOCUMENT;
|
|
1752
|
-
var init_credentials2 = __esm({
|
|
1753
|
-
"src/services/credentials.ts"() {
|
|
1754
|
-
"use strict";
|
|
1755
|
-
init_src();
|
|
1756
|
-
EMPTY_DOCUMENT = `${JSON.stringify({}, null, 2)}
|
|
1757
|
-
`;
|
|
1758
|
-
}
|
|
1759
|
-
});
|
|
1760
|
-
|
|
1761
2035
|
// src/cli/isolated-env.ts
|
|
1762
2036
|
import path4 from "node:path";
|
|
1763
|
-
async function resolveIsolatedEnvDetails(env, isolated, providerName,
|
|
2037
|
+
async function resolveIsolatedEnvDetails(env, isolated, providerName, readApiKey) {
|
|
1764
2038
|
if (!providerName) {
|
|
1765
2039
|
throw new Error("resolveIsolatedEnvDetails requires providerName.");
|
|
1766
2040
|
}
|
|
@@ -1773,7 +2047,7 @@ async function resolveIsolatedEnvDetails(env, isolated, providerName, fs3) {
|
|
|
1773
2047
|
}
|
|
1774
2048
|
return {
|
|
1775
2049
|
agentBinary: isolated.agentBinary,
|
|
1776
|
-
env: await resolveIsolatedEnvVars(env, baseDir, isolated.env,
|
|
2050
|
+
env: await resolveIsolatedEnvVars(env, baseDir, isolated.env, readApiKey),
|
|
1777
2051
|
configProbePath: isolated.configProbe ? resolveIsolatedEnvPath(env, baseDir, isolated.configProbe) : void 0
|
|
1778
2052
|
};
|
|
1779
2053
|
}
|
|
@@ -1802,14 +2076,14 @@ function resolveIsolatedTargetDirectory(input) {
|
|
|
1802
2076
|
function resolveIsolatedBaseDir(env, providerName) {
|
|
1803
2077
|
return env.resolveHomePath(".poe-code", providerName);
|
|
1804
2078
|
}
|
|
1805
|
-
async function resolveIsolatedEnvVars(env, baseDir, vars,
|
|
2079
|
+
async function resolveIsolatedEnvVars(env, baseDir, vars, readApiKey) {
|
|
1806
2080
|
const out = {};
|
|
1807
2081
|
for (const [key, value] of Object.entries(vars)) {
|
|
1808
|
-
out[key] = await resolveIsolatedEnvValue(env, baseDir, value,
|
|
2082
|
+
out[key] = await resolveIsolatedEnvValue(env, baseDir, value, readApiKey);
|
|
1809
2083
|
}
|
|
1810
2084
|
return out;
|
|
1811
2085
|
}
|
|
1812
|
-
async function resolveIsolatedEnvValue(env, baseDir, value,
|
|
2086
|
+
async function resolveIsolatedEnvValue(env, baseDir, value, readApiKey) {
|
|
1813
2087
|
if (typeof value === "string") {
|
|
1814
2088
|
return expandHomeShortcut(env, value);
|
|
1815
2089
|
}
|
|
@@ -1827,12 +2101,12 @@ async function resolveIsolatedEnvValue(env, baseDir, value, fs3) {
|
|
|
1827
2101
|
if (typeof resolved === "string" && resolved.trim().length > 0) {
|
|
1828
2102
|
return resolved;
|
|
1829
2103
|
}
|
|
1830
|
-
if (!
|
|
2104
|
+
if (!readApiKey) {
|
|
1831
2105
|
throw new Error(
|
|
1832
2106
|
'Missing Poe API key for isolated wrapper. Set "POE_API_KEY" or run "poe-code login".'
|
|
1833
2107
|
);
|
|
1834
2108
|
}
|
|
1835
|
-
return await
|
|
2109
|
+
return await resolvePoeApiKeyFromAuthStore(readApiKey);
|
|
1836
2110
|
}
|
|
1837
2111
|
if (isPoeBaseUrlReference(value)) {
|
|
1838
2112
|
return env.poeBaseUrl;
|
|
@@ -1859,8 +2133,8 @@ function isPoeApiKeyReference(value) {
|
|
|
1859
2133
|
function isPoeBaseUrlReference(value) {
|
|
1860
2134
|
return typeof value === "object" && value.kind === "poeBaseUrl";
|
|
1861
2135
|
}
|
|
1862
|
-
async function
|
|
1863
|
-
const stored = await
|
|
2136
|
+
async function resolvePoeApiKeyFromAuthStore(readApiKey) {
|
|
2137
|
+
const stored = await readApiKey();
|
|
1864
2138
|
if (typeof stored !== "string" || stored.trim().length === 0) {
|
|
1865
2139
|
throw new Error(
|
|
1866
2140
|
'Missing Poe API key for isolated wrapper. Set "POE_API_KEY" or run "poe-code login".'
|
|
@@ -1903,11 +2177,11 @@ async function applyIsolatedEnvRepairs(input) {
|
|
|
1903
2177
|
}
|
|
1904
2178
|
}
|
|
1905
2179
|
}
|
|
1906
|
-
async function resolveCliSettings(cliSettings, env,
|
|
2180
|
+
async function resolveCliSettings(cliSettings, env, readApiKey) {
|
|
1907
2181
|
const result = { ...cliSettings.values };
|
|
1908
2182
|
if (cliSettings.resolved) {
|
|
1909
2183
|
for (const [key, value] of Object.entries(cliSettings.resolved)) {
|
|
1910
|
-
result[key] = await resolveCliSettingValue(value, env,
|
|
2184
|
+
result[key] = await resolveCliSettingValue(value, env, readApiKey);
|
|
1911
2185
|
}
|
|
1912
2186
|
}
|
|
1913
2187
|
if (cliSettings.env) {
|
|
@@ -1916,21 +2190,21 @@ async function resolveCliSettings(cliSettings, env, fs3) {
|
|
|
1916
2190
|
if (typeof value === "string") {
|
|
1917
2191
|
resolvedEnv[key] = value;
|
|
1918
2192
|
} else {
|
|
1919
|
-
resolvedEnv[key] = await resolveCliSettingValue(value, env,
|
|
2193
|
+
resolvedEnv[key] = await resolveCliSettingValue(value, env, readApiKey);
|
|
1920
2194
|
}
|
|
1921
2195
|
}
|
|
1922
2196
|
result.env = resolvedEnv;
|
|
1923
2197
|
}
|
|
1924
2198
|
return result;
|
|
1925
2199
|
}
|
|
1926
|
-
async function resolveCliSettingValue(value, env,
|
|
2200
|
+
async function resolveCliSettingValue(value, env, readApiKey) {
|
|
1927
2201
|
if (isPoeApiKeyReference(value)) {
|
|
1928
2202
|
const resolved = env.getVariable("POE_API_KEY");
|
|
1929
2203
|
if (typeof resolved === "string" && resolved.trim().length > 0) {
|
|
1930
2204
|
return resolved;
|
|
1931
2205
|
}
|
|
1932
|
-
if (
|
|
1933
|
-
return await
|
|
2206
|
+
if (readApiKey) {
|
|
2207
|
+
return await resolvePoeApiKeyFromAuthStore(readApiKey);
|
|
1934
2208
|
}
|
|
1935
2209
|
throw new Error(
|
|
1936
2210
|
'Missing Poe API key for CLI settings. Set "POE_API_KEY" or run "poe-code login".'
|
|
@@ -1971,17 +2245,16 @@ function expandHomeShortcut(env, input) {
|
|
|
1971
2245
|
var init_isolated_env = __esm({
|
|
1972
2246
|
"src/cli/isolated-env.ts"() {
|
|
1973
2247
|
"use strict";
|
|
1974
|
-
|
|
1975
|
-
init_credentials2();
|
|
2248
|
+
init_src2();
|
|
1976
2249
|
}
|
|
1977
2250
|
});
|
|
1978
2251
|
|
|
1979
2252
|
// packages/agent-spawn/src/run-command.ts
|
|
1980
|
-
import { spawn } from "node:child_process";
|
|
2253
|
+
import { spawn as spawn2 } from "node:child_process";
|
|
1981
2254
|
function runCommand(command, args, options) {
|
|
1982
2255
|
return new Promise((resolve) => {
|
|
1983
2256
|
const hasStdin = options?.stdin != null;
|
|
1984
|
-
const child =
|
|
2257
|
+
const child = spawn2(command, args, {
|
|
1985
2258
|
stdio: [hasStdin ? "pipe" : "ignore", "pipe", "pipe"],
|
|
1986
2259
|
cwd: options?.cwd,
|
|
1987
2260
|
env: options?.env ? {
|
|
@@ -2184,7 +2457,7 @@ var init_registry = __esm({
|
|
|
2184
2457
|
});
|
|
2185
2458
|
|
|
2186
2459
|
// packages/agent-defs/src/index.ts
|
|
2187
|
-
var
|
|
2460
|
+
var init_src3 = __esm({
|
|
2188
2461
|
"packages/agent-defs/src/index.ts"() {
|
|
2189
2462
|
"use strict";
|
|
2190
2463
|
init_agents();
|
|
@@ -2337,7 +2610,7 @@ var allSpawnConfigs, lookup2;
|
|
|
2337
2610
|
var init_configs = __esm({
|
|
2338
2611
|
"packages/agent-spawn/src/configs/index.ts"() {
|
|
2339
2612
|
"use strict";
|
|
2340
|
-
|
|
2613
|
+
init_src3();
|
|
2341
2614
|
init_claude_code2();
|
|
2342
2615
|
init_codex2();
|
|
2343
2616
|
init_opencode2();
|
|
@@ -2372,7 +2645,7 @@ function resolveConfig(agentId) {
|
|
|
2372
2645
|
var init_resolve_config = __esm({
|
|
2373
2646
|
"packages/agent-spawn/src/configs/resolve-config.ts"() {
|
|
2374
2647
|
"use strict";
|
|
2375
|
-
|
|
2648
|
+
init_src3();
|
|
2376
2649
|
init_configs();
|
|
2377
2650
|
}
|
|
2378
2651
|
});
|
|
@@ -2425,7 +2698,7 @@ function buildCliArgs(config2, options, stdinMode) {
|
|
|
2425
2698
|
}
|
|
2426
2699
|
return args;
|
|
2427
2700
|
}
|
|
2428
|
-
async function
|
|
2701
|
+
async function spawn3(agentId, options, context) {
|
|
2429
2702
|
const { agentId: resolvedId, binaryName, spawnConfig } = resolveCliConfig(agentId);
|
|
2430
2703
|
const stdinMode = options.useStdin && spawnConfig.stdinMode ? spawnConfig.stdinMode : void 0;
|
|
2431
2704
|
const spawnArgs = buildCliArgs(spawnConfig, options, stdinMode);
|
|
@@ -3235,7 +3508,7 @@ var init_static = __esm({
|
|
|
3235
3508
|
});
|
|
3236
3509
|
|
|
3237
3510
|
// packages/design-system/src/index.ts
|
|
3238
|
-
var
|
|
3511
|
+
var init_src4 = __esm({
|
|
3239
3512
|
"packages/design-system/src/index.ts"() {
|
|
3240
3513
|
"use strict";
|
|
3241
3514
|
init_tokens();
|
|
@@ -3328,7 +3601,7 @@ async function renderAcpStream(events) {
|
|
|
3328
3601
|
var init_renderer = __esm({
|
|
3329
3602
|
"packages/agent-spawn/src/acp/renderer.ts"() {
|
|
3330
3603
|
"use strict";
|
|
3331
|
-
|
|
3604
|
+
init_src4();
|
|
3332
3605
|
}
|
|
3333
3606
|
});
|
|
3334
3607
|
|
|
@@ -3338,13 +3611,13 @@ function truncate2(text4, maxLength) {
|
|
|
3338
3611
|
if (maxLength <= 3) return text4.slice(0, maxLength);
|
|
3339
3612
|
return `${text4.slice(0, maxLength - 3)}...`;
|
|
3340
3613
|
}
|
|
3341
|
-
function
|
|
3614
|
+
function isNonEmptyString2(value) {
|
|
3342
3615
|
return typeof value === "string" && value.length > 0;
|
|
3343
3616
|
}
|
|
3344
3617
|
function extractThreadId(value) {
|
|
3345
3618
|
if (!value || typeof value !== "object") return;
|
|
3346
3619
|
const obj = value;
|
|
3347
|
-
const maybeThreadId =
|
|
3620
|
+
const maybeThreadId = isNonEmptyString2(obj.thread_id) && obj.thread_id || isNonEmptyString2(obj.threadId) && obj.threadId || isNonEmptyString2(obj.threadID) && obj.threadID || isNonEmptyString2(obj.session_id) && obj.session_id || isNonEmptyString2(obj.sessionId) && obj.sessionId || isNonEmptyString2(obj.sessionID) && obj.sessionID;
|
|
3348
3621
|
return maybeThreadId || void 0;
|
|
3349
3622
|
}
|
|
3350
3623
|
var init_utils = __esm({
|
|
@@ -3390,7 +3663,7 @@ async function* adaptClaude(lines) {
|
|
|
3390
3663
|
continue;
|
|
3391
3664
|
}
|
|
3392
3665
|
const eventType = event.type;
|
|
3393
|
-
if (!
|
|
3666
|
+
if (!isNonEmptyString2(eventType)) continue;
|
|
3394
3667
|
if (!emittedSessionStart) {
|
|
3395
3668
|
const threadId = extractThreadId(event);
|
|
3396
3669
|
emittedSessionStart = true;
|
|
@@ -3413,16 +3686,16 @@ async function* adaptClaude(lines) {
|
|
|
3413
3686
|
const item = block;
|
|
3414
3687
|
if (!item || typeof item !== "object") continue;
|
|
3415
3688
|
const blockType = item.type;
|
|
3416
|
-
if (!
|
|
3689
|
+
if (!isNonEmptyString2(blockType)) continue;
|
|
3417
3690
|
if (eventType === "assistant") {
|
|
3418
|
-
if (blockType === "text" &&
|
|
3691
|
+
if (blockType === "text" && isNonEmptyString2(item.text)) {
|
|
3419
3692
|
yield {
|
|
3420
3693
|
event: "agent_message",
|
|
3421
3694
|
text: item.text
|
|
3422
3695
|
};
|
|
3423
3696
|
continue;
|
|
3424
3697
|
}
|
|
3425
|
-
if (blockType === "tool_use" &&
|
|
3698
|
+
if (blockType === "tool_use" && isNonEmptyString2(item.id) && isNonEmptyString2(item.name)) {
|
|
3426
3699
|
const kind = TOOL_KIND_MAP[item.name] ?? "other";
|
|
3427
3700
|
toolKindsById.set(item.id, kind);
|
|
3428
3701
|
yield {
|
|
@@ -3436,25 +3709,25 @@ async function* adaptClaude(lines) {
|
|
|
3436
3709
|
continue;
|
|
3437
3710
|
}
|
|
3438
3711
|
if (eventType === "user") {
|
|
3439
|
-
if (!
|
|
3712
|
+
if (!isNonEmptyString2(item.tool_use_id)) continue;
|
|
3440
3713
|
if (blockType !== "tool_result") continue;
|
|
3441
3714
|
const kind = toolKindsById.get(item.tool_use_id);
|
|
3442
3715
|
toolKindsById.delete(item.tool_use_id);
|
|
3443
|
-
let
|
|
3716
|
+
let path21;
|
|
3444
3717
|
if (typeof item.content === "string") {
|
|
3445
|
-
|
|
3718
|
+
path21 = item.content;
|
|
3446
3719
|
} else {
|
|
3447
3720
|
try {
|
|
3448
|
-
|
|
3721
|
+
path21 = JSON.stringify(item.content);
|
|
3449
3722
|
} catch {
|
|
3450
|
-
|
|
3723
|
+
path21 = String(item.content);
|
|
3451
3724
|
}
|
|
3452
3725
|
}
|
|
3453
3726
|
yield {
|
|
3454
3727
|
event: "tool_complete",
|
|
3455
3728
|
id: item.tool_use_id,
|
|
3456
3729
|
kind,
|
|
3457
|
-
path:
|
|
3730
|
+
path: path21
|
|
3458
3731
|
};
|
|
3459
3732
|
}
|
|
3460
3733
|
}
|
|
@@ -3508,7 +3781,7 @@ async function* adaptCodex(lines) {
|
|
|
3508
3781
|
continue;
|
|
3509
3782
|
}
|
|
3510
3783
|
const eventType = event.type;
|
|
3511
|
-
if (!
|
|
3784
|
+
if (!isNonEmptyString2(eventType)) continue;
|
|
3512
3785
|
if (eventType === "thread.started") {
|
|
3513
3786
|
const maybeThreadId = extractThreadId(event);
|
|
3514
3787
|
yield { event: "session_start", threadId: maybeThreadId };
|
|
@@ -3532,23 +3805,23 @@ async function* adaptCodex(lines) {
|
|
|
3532
3805
|
const item = event.item ?? null;
|
|
3533
3806
|
if (!item || typeof item !== "object") continue;
|
|
3534
3807
|
const itemType = item.type;
|
|
3535
|
-
if (!
|
|
3808
|
+
if (!isNonEmptyString2(itemType)) continue;
|
|
3536
3809
|
if (eventType === "item.started") {
|
|
3537
|
-
if (!
|
|
3810
|
+
if (!isNonEmptyString2(item.id)) continue;
|
|
3538
3811
|
let kind;
|
|
3539
3812
|
let title;
|
|
3540
3813
|
if (itemType === "command_execution") {
|
|
3541
3814
|
kind = "exec";
|
|
3542
|
-
title = truncate2(
|
|
3815
|
+
title = truncate2(isNonEmptyString2(item.command) ? item.command : "", 80);
|
|
3543
3816
|
} else if (itemType === "file_edit") {
|
|
3544
3817
|
kind = "edit";
|
|
3545
|
-
title =
|
|
3818
|
+
title = isNonEmptyString2(item.path) ? item.path : "";
|
|
3546
3819
|
} else if (itemType === "thinking") {
|
|
3547
3820
|
kind = "think";
|
|
3548
3821
|
title = "thinking...";
|
|
3549
3822
|
} else if (itemType === "mcp_tool_call") {
|
|
3550
|
-
const server =
|
|
3551
|
-
const tool =
|
|
3823
|
+
const server = isNonEmptyString2(item.server) ? item.server : "unknown";
|
|
3824
|
+
const tool = isNonEmptyString2(item.tool) ? item.tool : "unknown";
|
|
3552
3825
|
kind = "other";
|
|
3553
3826
|
title = `${server}.${tool}`;
|
|
3554
3827
|
}
|
|
@@ -3561,25 +3834,25 @@ async function* adaptCodex(lines) {
|
|
|
3561
3834
|
}
|
|
3562
3835
|
if (eventType === "item.completed") {
|
|
3563
3836
|
if (itemType === "agent_message") {
|
|
3564
|
-
if (!
|
|
3837
|
+
if (!isNonEmptyString2(item.text)) continue;
|
|
3565
3838
|
yield { event: "agent_message", text: item.text };
|
|
3566
3839
|
continue;
|
|
3567
3840
|
}
|
|
3568
3841
|
if (itemType === "reasoning") {
|
|
3569
|
-
const text4 =
|
|
3842
|
+
const text4 = isNonEmptyString2(item.text) ? item.text : isNonEmptyString2(item.content) ? item.content : isNonEmptyString2(item.summary) ? item.summary : void 0;
|
|
3570
3843
|
if (!text4) continue;
|
|
3571
3844
|
yield { event: "reasoning", text: text4 };
|
|
3572
3845
|
continue;
|
|
3573
3846
|
}
|
|
3574
|
-
if (!
|
|
3847
|
+
if (!isNonEmptyString2(item.id)) continue;
|
|
3575
3848
|
if (itemType === "command_execution" || itemType === "file_edit" || itemType === "mcp_tool_call") {
|
|
3576
3849
|
const kindFromStart = toolKindById.get(item.id);
|
|
3577
3850
|
const kind = kindFromStart ?? (itemType === "command_execution" ? "exec" : itemType === "file_edit" ? "edit" : "other");
|
|
3578
|
-
const titleFromEvent =
|
|
3579
|
-
const
|
|
3851
|
+
const titleFromEvent = isNonEmptyString2(item.path) ? item.path : itemType === "mcp_tool_call" ? `${isNonEmptyString2(item.server) ? item.server : "unknown"}.${isNonEmptyString2(item.tool) ? item.tool : "unknown"}` : void 0;
|
|
3852
|
+
const path21 = titleFromEvent ?? toolTitleById.get(item.id) ?? "";
|
|
3580
3853
|
toolTitleById.delete(item.id);
|
|
3581
3854
|
toolKindById.delete(item.id);
|
|
3582
|
-
yield { event: "tool_complete", id: item.id, kind, path:
|
|
3855
|
+
yield { event: "tool_complete", id: item.id, kind, path: path21 };
|
|
3583
3856
|
}
|
|
3584
3857
|
}
|
|
3585
3858
|
}
|
|
@@ -3618,9 +3891,9 @@ async function* adaptKimi(lines) {
|
|
|
3618
3891
|
}
|
|
3619
3892
|
}
|
|
3620
3893
|
const role = event.role;
|
|
3621
|
-
if (!
|
|
3894
|
+
if (!isNonEmptyString2(role) || role !== "assistant") continue;
|
|
3622
3895
|
const content = event.content;
|
|
3623
|
-
if (!
|
|
3896
|
+
if (!isNonEmptyString2(content)) continue;
|
|
3624
3897
|
yield { event: "agent_message", text: content };
|
|
3625
3898
|
}
|
|
3626
3899
|
}
|
|
@@ -3649,7 +3922,7 @@ async function* adaptNative(lines) {
|
|
|
3649
3922
|
continue;
|
|
3650
3923
|
}
|
|
3651
3924
|
const maybeEventType = event?.event;
|
|
3652
|
-
if (!
|
|
3925
|
+
if (!isNonEmptyString2(maybeEventType)) {
|
|
3653
3926
|
yield {
|
|
3654
3927
|
event: "error",
|
|
3655
3928
|
message: `[adaptNative] Line missing string "event" field: ${truncate2(line, 200)}`
|
|
@@ -3708,23 +3981,23 @@ async function* adaptOpenCode(lines) {
|
|
|
3708
3981
|
}
|
|
3709
3982
|
if (!event || typeof event !== "object") continue;
|
|
3710
3983
|
const sessionID = extractThreadId(event);
|
|
3711
|
-
if (!emittedSessionStart &&
|
|
3984
|
+
if (!emittedSessionStart && isNonEmptyString2(sessionID)) {
|
|
3712
3985
|
emittedSessionStart = true;
|
|
3713
3986
|
yield { event: "session_start", threadId: sessionID };
|
|
3714
3987
|
}
|
|
3715
3988
|
const eventType = event.type;
|
|
3716
|
-
if (!
|
|
3989
|
+
if (!isNonEmptyString2(eventType)) continue;
|
|
3717
3990
|
if (eventType === "text") {
|
|
3718
3991
|
const part = event.part ?? null;
|
|
3719
3992
|
if (!part || typeof part !== "object") continue;
|
|
3720
|
-
if (!
|
|
3993
|
+
if (!isNonEmptyString2(part.text)) continue;
|
|
3721
3994
|
yield { event: "agent_message", text: part.text };
|
|
3722
3995
|
continue;
|
|
3723
3996
|
}
|
|
3724
3997
|
if (eventType === "tool_use") {
|
|
3725
3998
|
const part = event.part ?? null;
|
|
3726
3999
|
if (!part || typeof part !== "object") continue;
|
|
3727
|
-
if (!
|
|
4000
|
+
if (!isNonEmptyString2(part.callID) || !isNonEmptyString2(part.tool)) continue;
|
|
3728
4001
|
const state = part.state ?? null;
|
|
3729
4002
|
if (!state || typeof state !== "object") continue;
|
|
3730
4003
|
const kind = guessToolKind(part.tool);
|
|
@@ -3736,7 +4009,7 @@ async function* adaptOpenCode(lines) {
|
|
|
3736
4009
|
const maybeInput = state.input;
|
|
3737
4010
|
if (kind === "exec" && maybeInput && typeof maybeInput === "object") {
|
|
3738
4011
|
const command = maybeInput.command;
|
|
3739
|
-
if (
|
|
4012
|
+
if (isNonEmptyString2(command)) {
|
|
3740
4013
|
title = truncate2(command, 80);
|
|
3741
4014
|
}
|
|
3742
4015
|
}
|
|
@@ -3938,7 +4211,7 @@ var init_spawn2 = __esm({
|
|
|
3938
4211
|
});
|
|
3939
4212
|
|
|
3940
4213
|
// packages/agent-spawn/src/index.ts
|
|
3941
|
-
var
|
|
4214
|
+
var init_src5 = __esm({
|
|
3942
4215
|
"packages/agent-spawn/src/index.ts"() {
|
|
3943
4216
|
"use strict";
|
|
3944
4217
|
init_run_command();
|
|
@@ -4118,8 +4391,8 @@ var init_shared = __esm({
|
|
|
4118
4391
|
"use strict";
|
|
4119
4392
|
init_context();
|
|
4120
4393
|
init_isolated_env();
|
|
4121
|
-
|
|
4122
|
-
|
|
4394
|
+
init_src5();
|
|
4395
|
+
init_src3();
|
|
4123
4396
|
}
|
|
4124
4397
|
});
|
|
4125
4398
|
|
|
@@ -4429,7 +4702,7 @@ function createServiceRegistry() {
|
|
|
4429
4702
|
var init_service_registry = __esm({
|
|
4430
4703
|
"src/cli/service-registry.ts"() {
|
|
4431
4704
|
"use strict";
|
|
4432
|
-
|
|
4705
|
+
init_src3();
|
|
4433
4706
|
}
|
|
4434
4707
|
});
|
|
4435
4708
|
|
|
@@ -4793,7 +5066,7 @@ function createLoggerFactory(emitter, theme) {
|
|
|
4793
5066
|
var init_logger2 = __esm({
|
|
4794
5067
|
"src/cli/logger.ts"() {
|
|
4795
5068
|
"use strict";
|
|
4796
|
-
|
|
5069
|
+
init_src4();
|
|
4797
5070
|
}
|
|
4798
5071
|
});
|
|
4799
5072
|
|
|
@@ -5178,7 +5451,7 @@ async function ensureIsolatedConfigForService(input) {
|
|
|
5178
5451
|
container.env,
|
|
5179
5452
|
isolated,
|
|
5180
5453
|
adapter.name,
|
|
5181
|
-
container.
|
|
5454
|
+
container.readApiKey
|
|
5182
5455
|
);
|
|
5183
5456
|
const hasConfig = await isolatedConfigExists(
|
|
5184
5457
|
container.fs,
|
|
@@ -5253,7 +5526,7 @@ function createPoeCodeCommandRunner(input) {
|
|
|
5253
5526
|
container.env,
|
|
5254
5527
|
adapter.isolatedEnv,
|
|
5255
5528
|
adapter.name,
|
|
5256
|
-
container.
|
|
5529
|
+
container.readApiKey
|
|
5257
5530
|
);
|
|
5258
5531
|
if (adapter.isolatedEnv.requiresConfig !== false) {
|
|
5259
5532
|
const hasConfig = await isolatedConfigExists(
|
|
@@ -5284,7 +5557,7 @@ function createPoeCodeCommandRunner(input) {
|
|
|
5284
5557
|
const resolvedSettings = await resolveCliSettings(
|
|
5285
5558
|
adapter.isolatedEnv.cliSettings,
|
|
5286
5559
|
container.env,
|
|
5287
|
-
container.
|
|
5560
|
+
container.readApiKey
|
|
5288
5561
|
);
|
|
5289
5562
|
forwarded = buildArgsWithMergedSettings(forwarded, resolvedSettings);
|
|
5290
5563
|
}
|
|
@@ -5313,11 +5586,11 @@ var init_poe_code_command_runner = __esm({
|
|
|
5313
5586
|
|
|
5314
5587
|
// src/sdk/container.ts
|
|
5315
5588
|
import * as fs2 from "node:fs/promises";
|
|
5316
|
-
import * as
|
|
5589
|
+
import * as os from "node:os";
|
|
5317
5590
|
import * as nodeFsSync from "node:fs";
|
|
5318
5591
|
function createSdkContainer(options) {
|
|
5319
5592
|
const cwd = options?.cwd ?? process.cwd();
|
|
5320
|
-
const homeDir = options?.homeDir ??
|
|
5593
|
+
const homeDir = options?.homeDir ?? os.homedir();
|
|
5321
5594
|
const variables = options?.variables ?? process.env;
|
|
5322
5595
|
const verbose = options?.verbose ?? false;
|
|
5323
5596
|
const environment = createCliEnvironment({
|
|
@@ -5336,23 +5609,44 @@ function createSdkContainer(options) {
|
|
|
5336
5609
|
});
|
|
5337
5610
|
loggerFactory.setErrorLogger(errorLogger);
|
|
5338
5611
|
const asyncFs = {
|
|
5339
|
-
readFile: ((
|
|
5612
|
+
readFile: ((path21, encoding) => {
|
|
5340
5613
|
if (encoding) {
|
|
5341
|
-
return fs2.readFile(
|
|
5614
|
+
return fs2.readFile(path21, encoding);
|
|
5342
5615
|
}
|
|
5343
|
-
return fs2.readFile(
|
|
5616
|
+
return fs2.readFile(path21);
|
|
5344
5617
|
}),
|
|
5345
|
-
writeFile: (
|
|
5346
|
-
mkdir: (
|
|
5618
|
+
writeFile: (path21, data, opts) => fs2.writeFile(path21, data, opts),
|
|
5619
|
+
mkdir: (path21, opts) => fs2.mkdir(path21, opts).then(() => {
|
|
5347
5620
|
}),
|
|
5348
|
-
stat: (
|
|
5349
|
-
rm: (
|
|
5350
|
-
unlink: (
|
|
5351
|
-
readdir: (
|
|
5621
|
+
stat: (path21) => fs2.stat(path21),
|
|
5622
|
+
rm: (path21, opts) => fs2.rm(path21, opts),
|
|
5623
|
+
unlink: (path21) => fs2.unlink(path21),
|
|
5624
|
+
readdir: (path21) => fs2.readdir(path21),
|
|
5352
5625
|
copyFile: (src, dest) => fs2.copyFile(src, dest),
|
|
5353
|
-
chmod: (
|
|
5626
|
+
chmod: (path21, mode) => fs2.chmod(path21, mode)
|
|
5354
5627
|
};
|
|
5355
5628
|
const contextFactory = createCommandContextFactory({ fs: asyncFs });
|
|
5629
|
+
const authFs = {
|
|
5630
|
+
readFile: (filePath, encoding) => fs2.readFile(filePath, encoding),
|
|
5631
|
+
writeFile: (filePath, data, options2) => fs2.writeFile(filePath, data, options2),
|
|
5632
|
+
mkdir: (directoryPath, options2) => fs2.mkdir(directoryPath, options2).then(() => void 0),
|
|
5633
|
+
unlink: (filePath) => fs2.unlink(filePath),
|
|
5634
|
+
chmod: (filePath, mode) => fs2.chmod(filePath, mode)
|
|
5635
|
+
};
|
|
5636
|
+
const { store: authStore } = createAuthStore({
|
|
5637
|
+
env: variables,
|
|
5638
|
+
platform: process.platform,
|
|
5639
|
+
fileStore: {
|
|
5640
|
+
fs: authFs,
|
|
5641
|
+
getHomeDirectory: () => homeDir
|
|
5642
|
+
},
|
|
5643
|
+
legacyCredentials: {
|
|
5644
|
+
fs: authFs,
|
|
5645
|
+
getHomeDirectory: () => homeDir
|
|
5646
|
+
}
|
|
5647
|
+
});
|
|
5648
|
+
const readApiKey = authStore.getApiKey.bind(authStore);
|
|
5649
|
+
const writeApiKey = authStore.setApiKey.bind(authStore);
|
|
5356
5650
|
const noopPrompts = async () => {
|
|
5357
5651
|
throw new Error("SDK does not support interactive prompts");
|
|
5358
5652
|
};
|
|
@@ -5361,15 +5655,8 @@ function createSdkContainer(options) {
|
|
|
5361
5655
|
prompts: noopPrompts,
|
|
5362
5656
|
promptLibrary,
|
|
5363
5657
|
apiKeyStore: {
|
|
5364
|
-
read:
|
|
5365
|
-
|
|
5366
|
-
filePath: environment.credentialsPath
|
|
5367
|
-
}),
|
|
5368
|
-
write: (value) => saveCredentials({
|
|
5369
|
-
fs: asyncFs,
|
|
5370
|
-
filePath: environment.credentialsPath,
|
|
5371
|
-
apiKey: value
|
|
5372
|
-
})
|
|
5658
|
+
read: readApiKey,
|
|
5659
|
+
write: writeApiKey
|
|
5373
5660
|
}
|
|
5374
5661
|
});
|
|
5375
5662
|
const registry2 = createServiceRegistry();
|
|
@@ -5415,7 +5702,9 @@ function createSdkContainer(options) {
|
|
|
5415
5702
|
platform: process.platform,
|
|
5416
5703
|
variables
|
|
5417
5704
|
}
|
|
5418
|
-
}
|
|
5705
|
+
},
|
|
5706
|
+
readApiKey,
|
|
5707
|
+
writeApiKey
|
|
5419
5708
|
};
|
|
5420
5709
|
return container;
|
|
5421
5710
|
}
|
|
@@ -5429,15 +5718,15 @@ var init_container = __esm({
|
|
|
5429
5718
|
init_options();
|
|
5430
5719
|
init_logger2();
|
|
5431
5720
|
init_error_logger();
|
|
5432
|
-
|
|
5721
|
+
init_src5();
|
|
5433
5722
|
await init_providers();
|
|
5434
5723
|
init_poe_code_command_runner();
|
|
5435
|
-
|
|
5724
|
+
init_src();
|
|
5436
5725
|
}
|
|
5437
5726
|
});
|
|
5438
5727
|
|
|
5439
5728
|
// src/sdk/spawn.ts
|
|
5440
|
-
function
|
|
5729
|
+
function spawn4(service, promptOrOptions, maybeOptions) {
|
|
5441
5730
|
const options = typeof promptOrOptions === "string" ? { ...maybeOptions, prompt: promptOrOptions } : promptOrOptions;
|
|
5442
5731
|
const emptyEvents = (async function* () {
|
|
5443
5732
|
})();
|
|
@@ -5498,7 +5787,7 @@ function spawn3(service, promptOrOptions, maybeOptions) {
|
|
|
5498
5787
|
}
|
|
5499
5788
|
if (spawnConfig && spawnConfig.kind === "cli") {
|
|
5500
5789
|
resolveEventsOnce(emptyEvents);
|
|
5501
|
-
return
|
|
5790
|
+
return spawn3(service, {
|
|
5502
5791
|
prompt: options.prompt,
|
|
5503
5792
|
cwd: options.cwd,
|
|
5504
5793
|
model: options.model,
|
|
@@ -5530,7 +5819,7 @@ var init_spawn3 = __esm({
|
|
|
5530
5819
|
init_credentials();
|
|
5531
5820
|
init_spawn_core();
|
|
5532
5821
|
await init_container();
|
|
5533
|
-
|
|
5822
|
+
init_src5();
|
|
5534
5823
|
}
|
|
5535
5824
|
});
|
|
5536
5825
|
|
|
@@ -5588,6 +5877,161 @@ var init_errors = __esm({
|
|
|
5588
5877
|
}
|
|
5589
5878
|
});
|
|
5590
5879
|
|
|
5880
|
+
// src/services/credentials.ts
|
|
5881
|
+
import path10 from "node:path";
|
|
5882
|
+
async function loadCredentials(options) {
|
|
5883
|
+
const { fs: fs3, filePath } = options;
|
|
5884
|
+
const document = await readCredentialsDocument(fs3, filePath);
|
|
5885
|
+
return typeof document.apiKey === "string" && document.apiKey.length > 0 ? document.apiKey : null;
|
|
5886
|
+
}
|
|
5887
|
+
async function deleteCredentials(options) {
|
|
5888
|
+
const { fs: fs3, filePath } = options;
|
|
5889
|
+
try {
|
|
5890
|
+
await fs3.unlink(filePath);
|
|
5891
|
+
return true;
|
|
5892
|
+
} catch (error2) {
|
|
5893
|
+
if (isNotFound(error2)) {
|
|
5894
|
+
return false;
|
|
5895
|
+
}
|
|
5896
|
+
throw error2;
|
|
5897
|
+
}
|
|
5898
|
+
}
|
|
5899
|
+
async function loadConfiguredServices(options) {
|
|
5900
|
+
const { fs: fs3, filePath } = options;
|
|
5901
|
+
const document = await readCredentialsDocument(fs3, filePath);
|
|
5902
|
+
return { ...document.configured_services ?? {} };
|
|
5903
|
+
}
|
|
5904
|
+
async function saveConfiguredService(options) {
|
|
5905
|
+
const { fs: fs3, filePath, service, metadata } = options;
|
|
5906
|
+
const document = await readCredentialsDocument(fs3, filePath);
|
|
5907
|
+
const normalized = normalizeConfiguredServiceMetadata(metadata);
|
|
5908
|
+
document.configured_services = {
|
|
5909
|
+
...document.configured_services ?? {},
|
|
5910
|
+
[service]: normalized
|
|
5911
|
+
};
|
|
5912
|
+
await writeCredentialsDocument(fs3, filePath, document);
|
|
5913
|
+
}
|
|
5914
|
+
async function unconfigureService(options) {
|
|
5915
|
+
const { fs: fs3, filePath, service } = options;
|
|
5916
|
+
const document = await readCredentialsDocument(fs3, filePath);
|
|
5917
|
+
const services = document.configured_services;
|
|
5918
|
+
if (!services || !(service in services)) {
|
|
5919
|
+
return false;
|
|
5920
|
+
}
|
|
5921
|
+
delete services[service];
|
|
5922
|
+
if (Object.keys(services).length === 0) {
|
|
5923
|
+
delete document.configured_services;
|
|
5924
|
+
}
|
|
5925
|
+
await writeCredentialsDocument(fs3, filePath, document);
|
|
5926
|
+
return true;
|
|
5927
|
+
}
|
|
5928
|
+
function normalizeConfiguredServiceMetadata(metadata) {
|
|
5929
|
+
const seen = /* @__PURE__ */ new Set();
|
|
5930
|
+
const files = [];
|
|
5931
|
+
for (const entry of metadata.files ?? []) {
|
|
5932
|
+
if (typeof entry !== "string" || entry.length === 0) {
|
|
5933
|
+
continue;
|
|
5934
|
+
}
|
|
5935
|
+
if (!seen.has(entry)) {
|
|
5936
|
+
files.push(entry);
|
|
5937
|
+
seen.add(entry);
|
|
5938
|
+
}
|
|
5939
|
+
}
|
|
5940
|
+
return {
|
|
5941
|
+
files
|
|
5942
|
+
};
|
|
5943
|
+
}
|
|
5944
|
+
async function readCredentialsDocument(fs3, filePath) {
|
|
5945
|
+
try {
|
|
5946
|
+
const raw = await fs3.readFile(filePath, "utf8");
|
|
5947
|
+
return await parseCredentialsDocument(fs3, filePath, raw);
|
|
5948
|
+
} catch (error2) {
|
|
5949
|
+
if (isNotFound(error2)) {
|
|
5950
|
+
return {};
|
|
5951
|
+
}
|
|
5952
|
+
throw error2;
|
|
5953
|
+
}
|
|
5954
|
+
}
|
|
5955
|
+
async function parseCredentialsDocument(fs3, filePath, raw) {
|
|
5956
|
+
try {
|
|
5957
|
+
const parsed = JSON.parse(raw);
|
|
5958
|
+
return normalizeCredentialsDocument(parsed);
|
|
5959
|
+
} catch (error2) {
|
|
5960
|
+
if (error2 instanceof SyntaxError) {
|
|
5961
|
+
await recoverInvalidCredentials(fs3, filePath, raw);
|
|
5962
|
+
return {};
|
|
5963
|
+
}
|
|
5964
|
+
throw error2;
|
|
5965
|
+
}
|
|
5966
|
+
}
|
|
5967
|
+
function normalizeCredentialsDocument(value) {
|
|
5968
|
+
if (!isRecord3(value)) {
|
|
5969
|
+
return {};
|
|
5970
|
+
}
|
|
5971
|
+
const document = {};
|
|
5972
|
+
if (typeof value.apiKey === "string" && value.apiKey.length > 0) {
|
|
5973
|
+
document.apiKey = value.apiKey;
|
|
5974
|
+
}
|
|
5975
|
+
const services = normalizeConfiguredServices(value.configured_services);
|
|
5976
|
+
if (Object.keys(services).length > 0) {
|
|
5977
|
+
document.configured_services = services;
|
|
5978
|
+
}
|
|
5979
|
+
return document;
|
|
5980
|
+
}
|
|
5981
|
+
function normalizeConfiguredServices(value) {
|
|
5982
|
+
if (!isRecord3(value)) {
|
|
5983
|
+
return {};
|
|
5984
|
+
}
|
|
5985
|
+
const entries = {};
|
|
5986
|
+
for (const [key, entry] of Object.entries(value)) {
|
|
5987
|
+
if (!isRecord3(entry)) {
|
|
5988
|
+
continue;
|
|
5989
|
+
}
|
|
5990
|
+
const normalized = normalizeConfiguredServiceMetadata({
|
|
5991
|
+
files: Array.isArray(entry.files) ? entry.files : []
|
|
5992
|
+
});
|
|
5993
|
+
entries[key] = normalized;
|
|
5994
|
+
}
|
|
5995
|
+
return entries;
|
|
5996
|
+
}
|
|
5997
|
+
async function writeCredentialsDocument(fs3, filePath, document) {
|
|
5998
|
+
await fs3.mkdir(path10.dirname(filePath), { recursive: true });
|
|
5999
|
+
const payload = {};
|
|
6000
|
+
if (document.apiKey) {
|
|
6001
|
+
payload.apiKey = document.apiKey;
|
|
6002
|
+
}
|
|
6003
|
+
if (document.configured_services) {
|
|
6004
|
+
payload.configured_services = document.configured_services;
|
|
6005
|
+
}
|
|
6006
|
+
await fs3.writeFile(filePath, `${JSON.stringify(payload, null, 2)}
|
|
6007
|
+
`, {
|
|
6008
|
+
encoding: "utf8"
|
|
6009
|
+
});
|
|
6010
|
+
}
|
|
6011
|
+
async function recoverInvalidCredentials(fs3, filePath, content) {
|
|
6012
|
+
const backupPath = createInvalidBackupPath(filePath);
|
|
6013
|
+
await fs3.writeFile(backupPath, content, { encoding: "utf8" });
|
|
6014
|
+
await fs3.writeFile(filePath, EMPTY_DOCUMENT, { encoding: "utf8" });
|
|
6015
|
+
}
|
|
6016
|
+
function createInvalidBackupPath(filePath) {
|
|
6017
|
+
const timestamp = (/* @__PURE__ */ new Date()).toISOString().replace(/[:.]/g, "-");
|
|
6018
|
+
const dir = path10.dirname(filePath);
|
|
6019
|
+
const base = path10.basename(filePath);
|
|
6020
|
+
return path10.join(dir, `${base}.invalid-${timestamp}.json`);
|
|
6021
|
+
}
|
|
6022
|
+
function isRecord3(value) {
|
|
6023
|
+
return Boolean(value && typeof value === "object" && !Array.isArray(value));
|
|
6024
|
+
}
|
|
6025
|
+
var EMPTY_DOCUMENT;
|
|
6026
|
+
var init_credentials2 = __esm({
|
|
6027
|
+
"src/services/credentials.ts"() {
|
|
6028
|
+
"use strict";
|
|
6029
|
+
init_src2();
|
|
6030
|
+
EMPTY_DOCUMENT = `${JSON.stringify({}, null, 2)}
|
|
6031
|
+
`;
|
|
6032
|
+
}
|
|
6033
|
+
});
|
|
6034
|
+
|
|
5591
6035
|
// src/services/llm-client.ts
|
|
5592
6036
|
function createPoeClient(options) {
|
|
5593
6037
|
const httpClient = options.httpClient ?? createDefaultHttpClient();
|
|
@@ -5652,13 +6096,13 @@ async function readErrorBody(response) {
|
|
|
5652
6096
|
}
|
|
5653
6097
|
}
|
|
5654
6098
|
function extractTextContent(data) {
|
|
5655
|
-
if (!
|
|
6099
|
+
if (!isRecord4(data)) return void 0;
|
|
5656
6100
|
const choices = data.choices;
|
|
5657
6101
|
if (!Array.isArray(choices) || choices.length === 0) return void 0;
|
|
5658
6102
|
const first = choices[0];
|
|
5659
|
-
if (!
|
|
6103
|
+
if (!isRecord4(first)) return void 0;
|
|
5660
6104
|
const message = first.message;
|
|
5661
|
-
if (!
|
|
6105
|
+
if (!isRecord4(message)) return void 0;
|
|
5662
6106
|
return typeof message.content === "string" ? message.content : void 0;
|
|
5663
6107
|
}
|
|
5664
6108
|
function extractMediaFromCompletion(data) {
|
|
@@ -5666,14 +6110,14 @@ function extractMediaFromCompletion(data) {
|
|
|
5666
6110
|
if (!content) return {};
|
|
5667
6111
|
try {
|
|
5668
6112
|
const parsed = JSON.parse(content);
|
|
5669
|
-
if (
|
|
6113
|
+
if (isRecord4(parsed) && typeof parsed.url === "string") {
|
|
5670
6114
|
return {
|
|
5671
6115
|
url: parsed.url,
|
|
5672
6116
|
mimeType: typeof parsed.mimeType === "string" ? parsed.mimeType : void 0,
|
|
5673
6117
|
data: typeof parsed.data === "string" ? parsed.data : void 0
|
|
5674
6118
|
};
|
|
5675
6119
|
}
|
|
5676
|
-
if (
|
|
6120
|
+
if (isRecord4(parsed) && typeof parsed.data === "string") {
|
|
5677
6121
|
return {
|
|
5678
6122
|
data: parsed.data,
|
|
5679
6123
|
mimeType: typeof parsed.mimeType === "string" ? parsed.mimeType : void 0
|
|
@@ -5707,7 +6151,7 @@ function isValidUrl(value) {
|
|
|
5707
6151
|
return false;
|
|
5708
6152
|
}
|
|
5709
6153
|
}
|
|
5710
|
-
function
|
|
6154
|
+
function isRecord4(value) {
|
|
5711
6155
|
return Boolean(value && typeof value === "object" && !Array.isArray(value));
|
|
5712
6156
|
}
|
|
5713
6157
|
var init_llm_client = __esm({
|
|
@@ -5793,19 +6237,33 @@ function createCliContainer(dependencies) {
|
|
|
5793
6237
|
});
|
|
5794
6238
|
const commandRunner = dependencies.commandRunner ?? runCommand;
|
|
5795
6239
|
const promptLibrary = createPromptLibrary();
|
|
6240
|
+
const authFs = {
|
|
6241
|
+
readFile: (filePath, encoding) => dependencies.fs.readFile(filePath, encoding),
|
|
6242
|
+
writeFile: (filePath, data, opts) => dependencies.fs.writeFile(filePath, data, opts),
|
|
6243
|
+
mkdir: (directoryPath, opts) => dependencies.fs.mkdir(directoryPath, opts).then(() => void 0),
|
|
6244
|
+
unlink: (filePath) => dependencies.fs.unlink(filePath),
|
|
6245
|
+
chmod: (filePath, mode) => dependencies.fs.chmod ? dependencies.fs.chmod(filePath, mode) : Promise.resolve()
|
|
6246
|
+
};
|
|
6247
|
+
const { store: authStore } = createAuthStore({
|
|
6248
|
+
env: dependencies.env.variables,
|
|
6249
|
+
platform: dependencies.env.platform,
|
|
6250
|
+
fileStore: {
|
|
6251
|
+
fs: authFs,
|
|
6252
|
+
getHomeDirectory: () => dependencies.env.homeDir
|
|
6253
|
+
},
|
|
6254
|
+
legacyCredentials: {
|
|
6255
|
+
fs: authFs,
|
|
6256
|
+
getHomeDirectory: () => dependencies.env.homeDir
|
|
6257
|
+
}
|
|
6258
|
+
});
|
|
6259
|
+
const readApiKey = authStore.getApiKey.bind(authStore);
|
|
6260
|
+
const writeApiKey = authStore.setApiKey.bind(authStore);
|
|
5796
6261
|
const options = createOptionResolvers({
|
|
5797
6262
|
prompts: dependencies.prompts,
|
|
5798
6263
|
promptLibrary,
|
|
5799
6264
|
apiKeyStore: {
|
|
5800
|
-
read:
|
|
5801
|
-
|
|
5802
|
-
filePath: environment.credentialsPath
|
|
5803
|
-
}),
|
|
5804
|
-
write: (value) => saveCredentials({
|
|
5805
|
-
fs: dependencies.fs,
|
|
5806
|
-
filePath: environment.credentialsPath,
|
|
5807
|
-
apiKey: value
|
|
5808
|
-
})
|
|
6265
|
+
read: readApiKey,
|
|
6266
|
+
write: writeApiKey
|
|
5809
6267
|
}
|
|
5810
6268
|
});
|
|
5811
6269
|
const registry2 = createServiceRegistry();
|
|
@@ -5833,14 +6291,16 @@ function createCliContainer(dependencies) {
|
|
|
5833
6291
|
httpClient,
|
|
5834
6292
|
commandRunner: wrappedRunner,
|
|
5835
6293
|
providers,
|
|
5836
|
-
dependencies
|
|
6294
|
+
dependencies,
|
|
6295
|
+
readApiKey,
|
|
6296
|
+
writeApiKey
|
|
5837
6297
|
};
|
|
5838
6298
|
return container;
|
|
5839
6299
|
}
|
|
5840
6300
|
var init_container2 = __esm({
|
|
5841
6301
|
async "src/cli/container.ts"() {
|
|
5842
6302
|
"use strict";
|
|
5843
|
-
|
|
6303
|
+
init_src();
|
|
5844
6304
|
init_environment();
|
|
5845
6305
|
init_service_registry();
|
|
5846
6306
|
init_context();
|
|
@@ -5848,8 +6308,8 @@ var init_container2 = __esm({
|
|
|
5848
6308
|
init_options();
|
|
5849
6309
|
init_logger2();
|
|
5850
6310
|
init_error_logger();
|
|
6311
|
+
init_src5();
|
|
5851
6312
|
init_src4();
|
|
5852
|
-
init_src3();
|
|
5853
6313
|
await init_providers();
|
|
5854
6314
|
init_poe_code_command_runner();
|
|
5855
6315
|
}
|
|
@@ -6027,7 +6487,7 @@ var init_configure = __esm({
|
|
|
6027
6487
|
});
|
|
6028
6488
|
|
|
6029
6489
|
// src/cli/commands/spawn.ts
|
|
6030
|
-
import
|
|
6490
|
+
import path11 from "node:path";
|
|
6031
6491
|
function registerSpawnCommand(program, container, options = {}) {
|
|
6032
6492
|
const spawnServices = container.registry.list().filter((service) => typeof service.spawn === "function" || getSpawnConfig(service.name)).map((service) => service.name);
|
|
6033
6493
|
const extraServices = options.extraServices ?? [];
|
|
@@ -6152,7 +6612,7 @@ function registerSpawnCommand(program, container, options = {}) {
|
|
|
6152
6612
|
if (!proceed) {
|
|
6153
6613
|
return;
|
|
6154
6614
|
}
|
|
6155
|
-
const { events, result } =
|
|
6615
|
+
const { events, result } = spawn4(canonicalService, {
|
|
6156
6616
|
prompt: spawnOptions.prompt,
|
|
6157
6617
|
args: spawnOptions.args,
|
|
6158
6618
|
model: spawnOptions.model,
|
|
@@ -6215,16 +6675,16 @@ function resolveSpawnWorkingDirectory2(baseDir, candidate) {
|
|
|
6215
6675
|
if (!candidate || candidate.trim().length === 0) {
|
|
6216
6676
|
return void 0;
|
|
6217
6677
|
}
|
|
6218
|
-
if (
|
|
6678
|
+
if (path11.isAbsolute(candidate)) {
|
|
6219
6679
|
return candidate;
|
|
6220
6680
|
}
|
|
6221
|
-
return
|
|
6681
|
+
return path11.resolve(baseDir, candidate);
|
|
6222
6682
|
}
|
|
6223
6683
|
var init_spawn4 = __esm({
|
|
6224
6684
|
async "src/cli/commands/spawn.ts"() {
|
|
6225
6685
|
"use strict";
|
|
6686
|
+
init_src5();
|
|
6226
6687
|
init_src4();
|
|
6227
|
-
init_src3();
|
|
6228
6688
|
init_credentials2();
|
|
6229
6689
|
init_shared();
|
|
6230
6690
|
init_spawn_core();
|
|
@@ -6233,7 +6693,7 @@ var init_spawn4 = __esm({
|
|
|
6233
6693
|
});
|
|
6234
6694
|
|
|
6235
6695
|
// src/sdk/research.ts
|
|
6236
|
-
import
|
|
6696
|
+
import path12 from "node:path";
|
|
6237
6697
|
async function research(container, options) {
|
|
6238
6698
|
const logger2 = options.logger;
|
|
6239
6699
|
const source = await resolveSource({
|
|
@@ -6243,7 +6703,7 @@ async function research(container, options) {
|
|
|
6243
6703
|
});
|
|
6244
6704
|
const researchPrompt = buildResearchPrompt(options.prompt);
|
|
6245
6705
|
const mode = options.mode ?? "read";
|
|
6246
|
-
const { events, result } =
|
|
6706
|
+
const { events, result } = spawn4(options.agent, {
|
|
6247
6707
|
prompt: researchPrompt,
|
|
6248
6708
|
args: options.args ?? [],
|
|
6249
6709
|
model: options.model,
|
|
@@ -6268,7 +6728,7 @@ async function research(container, options) {
|
|
|
6268
6728
|
markdown: markdownOutput
|
|
6269
6729
|
});
|
|
6270
6730
|
outputPath = buildOutputPath(container.env.homeDir, options.prompt);
|
|
6271
|
-
await ensureDirectory2(container.fs,
|
|
6731
|
+
await ensureDirectory2(container.fs, path12.dirname(outputPath));
|
|
6272
6732
|
await container.fs.writeFile(outputPath, document, {
|
|
6273
6733
|
encoding: "utf8"
|
|
6274
6734
|
});
|
|
@@ -6343,7 +6803,7 @@ function buildResearchDocument(input) {
|
|
|
6343
6803
|
}
|
|
6344
6804
|
function buildClonePath(homeDir, github) {
|
|
6345
6805
|
const slug = extractRepoSlug(github);
|
|
6346
|
-
return
|
|
6806
|
+
return path12.join(homeDir, ".poe-code", "repos", slug);
|
|
6347
6807
|
}
|
|
6348
6808
|
function extractRepoSlug(value) {
|
|
6349
6809
|
const trimmed = value.trim();
|
|
@@ -6381,7 +6841,7 @@ function extractRepoSlug(value) {
|
|
|
6381
6841
|
function buildOutputPath(homeDir, prompt, now = /* @__PURE__ */ new Date()) {
|
|
6382
6842
|
const timestamp = formatTimestamp(now);
|
|
6383
6843
|
const slug = buildSlug(prompt);
|
|
6384
|
-
return
|
|
6844
|
+
return path12.join(
|
|
6385
6845
|
homeDir,
|
|
6386
6846
|
".poe-code",
|
|
6387
6847
|
"research",
|
|
@@ -6402,7 +6862,7 @@ async function resolveSource(input) {
|
|
|
6402
6862
|
if (options.github) {
|
|
6403
6863
|
const cloneUrl = resolveGithubCloneUrl(options.github);
|
|
6404
6864
|
const clonePath = buildClonePath(container.env.homeDir, options.github);
|
|
6405
|
-
await ensureDirectory2(container.fs,
|
|
6865
|
+
await ensureDirectory2(container.fs, path12.dirname(clonePath));
|
|
6406
6866
|
const exists = await pathExists2(container.fs, clonePath);
|
|
6407
6867
|
if (!exists) {
|
|
6408
6868
|
const cloneResult = await container.commandRunner(
|
|
@@ -6500,10 +6960,10 @@ function formatYamlString(value) {
|
|
|
6500
6960
|
return JSON.stringify(value);
|
|
6501
6961
|
}
|
|
6502
6962
|
function resolvePath2(baseDir, candidate) {
|
|
6503
|
-
if (
|
|
6963
|
+
if (path12.isAbsolute(candidate)) {
|
|
6504
6964
|
return candidate;
|
|
6505
6965
|
}
|
|
6506
|
-
return
|
|
6966
|
+
return path12.resolve(baseDir, candidate);
|
|
6507
6967
|
}
|
|
6508
6968
|
function teeAcpStream(events) {
|
|
6509
6969
|
const chunks = [];
|
|
@@ -6563,7 +7023,7 @@ async function removePathFallback(fs3, target) {
|
|
|
6563
7023
|
if (stats && typeof stats.isDirectory === "function" && stats.isDirectory()) {
|
|
6564
7024
|
const entries = await fs3.readdir(target);
|
|
6565
7025
|
for (const entry of entries) {
|
|
6566
|
-
await removePathFallback(fs3,
|
|
7026
|
+
await removePathFallback(fs3, path12.join(target, entry));
|
|
6567
7027
|
}
|
|
6568
7028
|
}
|
|
6569
7029
|
try {
|
|
@@ -6729,7 +7189,7 @@ async function resolveResearchModel(input) {
|
|
|
6729
7189
|
var init_research2 = __esm({
|
|
6730
7190
|
async "src/cli/commands/research.ts"() {
|
|
6731
7191
|
"use strict";
|
|
6732
|
-
|
|
7192
|
+
init_src5();
|
|
6733
7193
|
init_credentials2();
|
|
6734
7194
|
await init_research();
|
|
6735
7195
|
init_errors();
|
|
@@ -6738,13 +7198,13 @@ var init_research2 = __esm({
|
|
|
6738
7198
|
});
|
|
6739
7199
|
|
|
6740
7200
|
// src/cli/isolated-env-runner.ts
|
|
6741
|
-
import { spawn as
|
|
7201
|
+
import { spawn as spawn5 } from "node:child_process";
|
|
6742
7202
|
async function isolatedEnvRunner(input) {
|
|
6743
7203
|
const details = await resolveIsolatedEnvDetails(
|
|
6744
7204
|
input.env,
|
|
6745
7205
|
input.isolated,
|
|
6746
7206
|
input.providerName,
|
|
6747
|
-
input.
|
|
7207
|
+
input.readApiKey
|
|
6748
7208
|
);
|
|
6749
7209
|
let args = input.argv.slice(2);
|
|
6750
7210
|
if (input.isolated.requiresConfig !== false) {
|
|
@@ -6759,11 +7219,11 @@ async function isolatedEnvRunner(input) {
|
|
|
6759
7219
|
const resolvedSettings = await resolveCliSettings(
|
|
6760
7220
|
input.isolated.cliSettings,
|
|
6761
7221
|
input.env,
|
|
6762
|
-
input.
|
|
7222
|
+
input.readApiKey
|
|
6763
7223
|
);
|
|
6764
7224
|
args = buildArgsWithMergedSettings(args, resolvedSettings);
|
|
6765
7225
|
}
|
|
6766
|
-
const child =
|
|
7226
|
+
const child = spawn5(details.agentBinary, args, {
|
|
6767
7227
|
stdio: "inherit",
|
|
6768
7228
|
env: {
|
|
6769
7229
|
...process.env,
|
|
@@ -6796,7 +7256,7 @@ async function configExists(fs3, filePath) {
|
|
|
6796
7256
|
var init_isolated_env_runner = __esm({
|
|
6797
7257
|
"src/cli/isolated-env-runner.ts"() {
|
|
6798
7258
|
"use strict";
|
|
6799
|
-
|
|
7259
|
+
init_src2();
|
|
6800
7260
|
init_isolated_env();
|
|
6801
7261
|
init_cli_settings_merge();
|
|
6802
7262
|
}
|
|
@@ -6846,6 +7306,7 @@ function registerWrapCommand(program, container) {
|
|
|
6846
7306
|
await isolatedEnvRunner({
|
|
6847
7307
|
env: container.env,
|
|
6848
7308
|
fs: container.fs,
|
|
7309
|
+
readApiKey: container.readApiKey,
|
|
6849
7310
|
providerName: adapter.name,
|
|
6850
7311
|
isolated,
|
|
6851
7312
|
argv: ["node", "poe-code", ...forwarded]
|
|
@@ -6879,11 +7340,9 @@ function registerLoginCommand(program, container) {
|
|
|
6879
7340
|
fs: container.fs,
|
|
6880
7341
|
filePath: container.env.credentialsPath
|
|
6881
7342
|
});
|
|
6882
|
-
|
|
6883
|
-
|
|
6884
|
-
|
|
6885
|
-
apiKey: normalized
|
|
6886
|
-
});
|
|
7343
|
+
if (!flags.dryRun) {
|
|
7344
|
+
await container.writeApiKey(normalized);
|
|
7345
|
+
}
|
|
6887
7346
|
await reconfigureServices({
|
|
6888
7347
|
program,
|
|
6889
7348
|
container,
|
|
@@ -7253,7 +7712,7 @@ async function executeTest(program, container, service, options = {}) {
|
|
|
7253
7712
|
container.env,
|
|
7254
7713
|
adapter.isolatedEnv,
|
|
7255
7714
|
adapter.name,
|
|
7256
|
-
container.
|
|
7715
|
+
container.readApiKey
|
|
7257
7716
|
) : null;
|
|
7258
7717
|
if (options.isolated && adapter.isolatedEnv) {
|
|
7259
7718
|
const { ensureIsolatedConfigForService: ensureIsolatedConfigForService2 } = await Promise.resolve().then(() => (init_ensure_isolated_config(), ensure_isolated_config_exports));
|
|
@@ -7302,7 +7761,7 @@ var init_test = __esm({
|
|
|
7302
7761
|
init_shared();
|
|
7303
7762
|
init_configure();
|
|
7304
7763
|
init_isolated_env();
|
|
7305
|
-
|
|
7764
|
+
init_src4();
|
|
7306
7765
|
}
|
|
7307
7766
|
});
|
|
7308
7767
|
|
|
@@ -7355,7 +7814,7 @@ var init_media_download = __esm({
|
|
|
7355
7814
|
});
|
|
7356
7815
|
|
|
7357
7816
|
// src/cli/commands/generate.ts
|
|
7358
|
-
import
|
|
7817
|
+
import path13 from "node:path";
|
|
7359
7818
|
function registerGenerateCommand(program, container) {
|
|
7360
7819
|
const generate2 = program.command("generate").description("Generate content via Poe API").option("--model <model>", `Model identifier (default: ${DEFAULT_TEXT_MODEL})`).option(
|
|
7361
7820
|
"--param <key=value>",
|
|
@@ -7618,11 +8077,11 @@ function getDefaultMimeType(type) {
|
|
|
7618
8077
|
return defaults[type];
|
|
7619
8078
|
}
|
|
7620
8079
|
function resolveOutputPath(filename, cwd) {
|
|
7621
|
-
if (
|
|
8080
|
+
if (path13.isAbsolute(filename)) {
|
|
7622
8081
|
return { path: filename, label: filename };
|
|
7623
8082
|
}
|
|
7624
8083
|
return {
|
|
7625
|
-
path:
|
|
8084
|
+
path: path13.join(cwd, filename),
|
|
7626
8085
|
label: `./${filename}`
|
|
7627
8086
|
};
|
|
7628
8087
|
}
|
|
@@ -7630,7 +8089,7 @@ var MODEL_ENV_KEYS2, DEFAULT_MODELS2;
|
|
|
7630
8089
|
var init_generate = __esm({
|
|
7631
8090
|
"src/cli/commands/generate.ts"() {
|
|
7632
8091
|
"use strict";
|
|
7633
|
-
|
|
8092
|
+
init_src4();
|
|
7634
8093
|
init_constants();
|
|
7635
8094
|
init_shared();
|
|
7636
8095
|
init_client_instance();
|
|
@@ -8726,8 +9185,8 @@ var init_parseUtil = __esm({
|
|
|
8726
9185
|
init_errors2();
|
|
8727
9186
|
init_en();
|
|
8728
9187
|
makeIssue = (params) => {
|
|
8729
|
-
const { data, path:
|
|
8730
|
-
const fullPath = [...
|
|
9188
|
+
const { data, path: path21, errorMaps, issueData } = params;
|
|
9189
|
+
const fullPath = [...path21, ...issueData.path || []];
|
|
8731
9190
|
const fullIssue = {
|
|
8732
9191
|
...issueData,
|
|
8733
9192
|
path: fullPath
|
|
@@ -9007,11 +9466,11 @@ var init_types3 = __esm({
|
|
|
9007
9466
|
init_parseUtil();
|
|
9008
9467
|
init_util();
|
|
9009
9468
|
ParseInputLazyPath = class {
|
|
9010
|
-
constructor(parent, value,
|
|
9469
|
+
constructor(parent, value, path21, key) {
|
|
9011
9470
|
this._cachedPath = [];
|
|
9012
9471
|
this.parent = parent;
|
|
9013
9472
|
this.data = value;
|
|
9014
|
-
this._path =
|
|
9473
|
+
this._path = path21;
|
|
9015
9474
|
this._key = key;
|
|
9016
9475
|
}
|
|
9017
9476
|
get path() {
|
|
@@ -12515,10 +12974,10 @@ function mergeDefs(...defs) {
|
|
|
12515
12974
|
function cloneDef(schema) {
|
|
12516
12975
|
return mergeDefs(schema._zod.def);
|
|
12517
12976
|
}
|
|
12518
|
-
function getElementAtPath(obj,
|
|
12519
|
-
if (!
|
|
12977
|
+
function getElementAtPath(obj, path21) {
|
|
12978
|
+
if (!path21)
|
|
12520
12979
|
return obj;
|
|
12521
|
-
return
|
|
12980
|
+
return path21.reduce((acc, key) => acc?.[key], obj);
|
|
12522
12981
|
}
|
|
12523
12982
|
function promiseAllObject(promisesObj) {
|
|
12524
12983
|
const keys = Object.keys(promisesObj);
|
|
@@ -12830,11 +13289,11 @@ function aborted(x, startIndex = 0) {
|
|
|
12830
13289
|
}
|
|
12831
13290
|
return false;
|
|
12832
13291
|
}
|
|
12833
|
-
function prefixIssues(
|
|
13292
|
+
function prefixIssues(path21, issues) {
|
|
12834
13293
|
return issues.map((iss) => {
|
|
12835
13294
|
var _a2;
|
|
12836
13295
|
(_a2 = iss).path ?? (_a2.path = []);
|
|
12837
|
-
iss.path.unshift(
|
|
13296
|
+
iss.path.unshift(path21);
|
|
12838
13297
|
return iss;
|
|
12839
13298
|
});
|
|
12840
13299
|
}
|
|
@@ -13210,7 +13669,7 @@ __export(regexes_exports, {
|
|
|
13210
13669
|
extendedDuration: () => extendedDuration,
|
|
13211
13670
|
guid: () => guid,
|
|
13212
13671
|
hex: () => hex,
|
|
13213
|
-
hostname: () =>
|
|
13672
|
+
hostname: () => hostname2,
|
|
13214
13673
|
html5Email: () => html5Email,
|
|
13215
13674
|
idnEmail: () => idnEmail,
|
|
13216
13675
|
integer: () => integer,
|
|
@@ -13277,7 +13736,7 @@ function fixedBase64(bodyLength, padding) {
|
|
|
13277
13736
|
function fixedBase64url(length) {
|
|
13278
13737
|
return new RegExp(`^[A-Za-z0-9_-]{${length}}$`);
|
|
13279
13738
|
}
|
|
13280
|
-
var cuid, cuid2, ulid, xid, ksuid, nanoid, duration, extendedDuration, guid, uuid, uuid4, uuid6, uuid7, email, html5Email, rfc5322Email, unicodeEmail, idnEmail, browserEmail, _emoji, ipv4, ipv6, mac, cidrv4, cidrv6, base64, base64url,
|
|
13739
|
+
var cuid, cuid2, ulid, xid, ksuid, nanoid, duration, extendedDuration, guid, uuid, uuid4, uuid6, uuid7, email, html5Email, rfc5322Email, unicodeEmail, idnEmail, browserEmail, _emoji, ipv4, ipv6, mac, cidrv4, cidrv6, base64, base64url, hostname2, domain, e164, dateSource, date, string, bigint, integer, number, boolean, _null, _undefined, lowercase, uppercase, hex, md5_hex, md5_base64, md5_base64url, sha1_hex, sha1_base64, sha1_base64url, sha256_hex, sha256_base64, sha256_base64url, sha384_hex, sha384_base64, sha384_base64url, sha512_hex, sha512_base64, sha512_base64url;
|
|
13281
13740
|
var init_regexes = __esm({
|
|
13282
13741
|
"node_modules/zod/v4/core/regexes.js"() {
|
|
13283
13742
|
init_util2();
|
|
@@ -13315,7 +13774,7 @@ var init_regexes = __esm({
|
|
|
13315
13774
|
cidrv6 = /^(([0-9a-fA-F]{1,4}:){7}[0-9a-fA-F]{1,4}|::|([0-9a-fA-F]{1,4})?::([0-9a-fA-F]{1,4}:?){0,6})\/(12[0-8]|1[01][0-9]|[1-9]?[0-9])$/;
|
|
13316
13775
|
base64 = /^$|^(?:[0-9a-zA-Z+/]{4})*(?:(?:[0-9a-zA-Z+/]{2}==)|(?:[0-9a-zA-Z+/]{3}=))?$/;
|
|
13317
13776
|
base64url = /^[A-Za-z0-9_-]*$/;
|
|
13318
|
-
|
|
13777
|
+
hostname2 = /^(?=.{1,253}\.?$)[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?(?:\.[a-zA-Z0-9](?:[-0-9a-zA-Z]{0,61}[0-9a-zA-Z])?)*\.?$/;
|
|
13319
13778
|
domain = /^([a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?\.)+[a-zA-Z]{2,}$/;
|
|
13320
13779
|
e164 = /^\+[1-9]\d{6,14}$/;
|
|
13321
13780
|
dateSource = `(?:(?:\\d\\d[2468][048]|\\d\\d[13579][26]|\\d\\d0[48]|[02468][048]00|[13579][26]00)-02-29|\\d{4}-(?:(?:0[13578]|1[02])-(?:0[1-9]|[12]\\d|3[01])|(?:0[469]|11)-(?:0[1-9]|[12]\\d|30)|(?:02)-(?:0[1-9]|1\\d|2[0-8])))`;
|
|
@@ -18521,7 +18980,7 @@ __export(schemas_exports3, {
|
|
|
18521
18980
|
guid: () => guid2,
|
|
18522
18981
|
hash: () => hash,
|
|
18523
18982
|
hex: () => hex2,
|
|
18524
|
-
hostname: () =>
|
|
18983
|
+
hostname: () => hostname3,
|
|
18525
18984
|
httpUrl: () => httpUrl,
|
|
18526
18985
|
instanceof: () => _instanceof,
|
|
18527
18986
|
int: () => int,
|
|
@@ -18668,7 +19127,7 @@ function jwt(params) {
|
|
|
18668
19127
|
function stringFormat(format, fnOrRegex, _params = {}) {
|
|
18669
19128
|
return _stringFormat(ZodCustomStringFormat, format, fnOrRegex, _params);
|
|
18670
19129
|
}
|
|
18671
|
-
function
|
|
19130
|
+
function hostname3(_params) {
|
|
18672
19131
|
return _stringFormat(ZodCustomStringFormat, "hostname", regexes_exports.hostname, _params);
|
|
18673
19132
|
}
|
|
18674
19133
|
function hex2(_params) {
|
|
@@ -24792,8 +25251,8 @@ var require_utils = __commonJS({
|
|
|
24792
25251
|
}
|
|
24793
25252
|
return ind;
|
|
24794
25253
|
}
|
|
24795
|
-
function removeDotSegments(
|
|
24796
|
-
let input =
|
|
25254
|
+
function removeDotSegments(path21) {
|
|
25255
|
+
let input = path21;
|
|
24797
25256
|
const output = [];
|
|
24798
25257
|
let nextSlash = -1;
|
|
24799
25258
|
let len = 0;
|
|
@@ -24992,8 +25451,8 @@ var require_schemes = __commonJS({
|
|
|
24992
25451
|
wsComponent.secure = void 0;
|
|
24993
25452
|
}
|
|
24994
25453
|
if (wsComponent.resourceName) {
|
|
24995
|
-
const [
|
|
24996
|
-
wsComponent.path =
|
|
25454
|
+
const [path21, query] = wsComponent.resourceName.split("?");
|
|
25455
|
+
wsComponent.path = path21 && path21 !== "/" ? path21 : void 0;
|
|
24997
25456
|
wsComponent.query = query;
|
|
24998
25457
|
wsComponent.resourceName = void 0;
|
|
24999
25458
|
}
|
|
@@ -34107,7 +34566,7 @@ var init_content = __esm({
|
|
|
34107
34566
|
});
|
|
34108
34567
|
|
|
34109
34568
|
// packages/tiny-stdio-mcp-server/src/index.ts
|
|
34110
|
-
var
|
|
34569
|
+
var init_src6 = __esm({
|
|
34111
34570
|
"packages/tiny-stdio-mcp-server/src/index.ts"() {
|
|
34112
34571
|
"use strict";
|
|
34113
34572
|
init_server();
|
|
@@ -34411,7 +34870,7 @@ var generateTextSchema, generateImageSchema, generateVideoSchema, generateAudioS
|
|
|
34411
34870
|
var init_mcp_server = __esm({
|
|
34412
34871
|
"src/cli/mcp-server.ts"() {
|
|
34413
34872
|
"use strict";
|
|
34414
|
-
|
|
34873
|
+
init_src6();
|
|
34415
34874
|
init_client_instance();
|
|
34416
34875
|
init_constants();
|
|
34417
34876
|
generateTextSchema = defineSchema({
|
|
@@ -34669,7 +35128,7 @@ ${panel.footer}`);
|
|
|
34669
35128
|
var init_command_not_found = __esm({
|
|
34670
35129
|
"src/cli/command-not-found.ts"() {
|
|
34671
35130
|
"use strict";
|
|
34672
|
-
|
|
35131
|
+
init_src4();
|
|
34673
35132
|
init_execution_context();
|
|
34674
35133
|
init_errors();
|
|
34675
35134
|
}
|
|
@@ -34704,7 +35163,7 @@ var agentMcpConfigs, supportedAgents;
|
|
|
34704
35163
|
var init_configs2 = __esm({
|
|
34705
35164
|
"packages/agent-mcp-config/src/configs.ts"() {
|
|
34706
35165
|
"use strict";
|
|
34707
|
-
|
|
35166
|
+
init_src3();
|
|
34708
35167
|
agentMcpConfigs = {
|
|
34709
35168
|
"claude-code": {
|
|
34710
35169
|
configFile: "~/.claude.json",
|
|
@@ -34817,9 +35276,9 @@ var init_shapes = __esm({
|
|
|
34817
35276
|
});
|
|
34818
35277
|
|
|
34819
35278
|
// packages/agent-mcp-config/src/apply.ts
|
|
34820
|
-
import
|
|
35279
|
+
import path14 from "node:path";
|
|
34821
35280
|
function getConfigDirectory(configPath) {
|
|
34822
|
-
return
|
|
35281
|
+
return path14.dirname(configPath);
|
|
34823
35282
|
}
|
|
34824
35283
|
function isConfigObject5(value) {
|
|
34825
35284
|
return Boolean(value) && typeof value === "object" && !Array.isArray(value);
|
|
@@ -34908,7 +35367,7 @@ var UnsupportedAgentError;
|
|
|
34908
35367
|
var init_apply = __esm({
|
|
34909
35368
|
"packages/agent-mcp-config/src/apply.ts"() {
|
|
34910
35369
|
"use strict";
|
|
34911
|
-
|
|
35370
|
+
init_src2();
|
|
34912
35371
|
init_configs2();
|
|
34913
35372
|
init_shapes();
|
|
34914
35373
|
UnsupportedAgentError = class extends Error {
|
|
@@ -34921,7 +35380,7 @@ var init_apply = __esm({
|
|
|
34921
35380
|
});
|
|
34922
35381
|
|
|
34923
35382
|
// packages/agent-mcp-config/src/index.ts
|
|
34924
|
-
var
|
|
35383
|
+
var init_src7 = __esm({
|
|
34925
35384
|
"packages/agent-mcp-config/src/index.ts"() {
|
|
34926
35385
|
"use strict";
|
|
34927
35386
|
init_configs2();
|
|
@@ -34979,10 +35438,7 @@ function registerMcpCommand(program, container) {
|
|
|
34979
35438
|
mcp.command("configure [agent]").description("Configure MCP client to use poe-code").option("-y, --yes", "Skip prompt, use claude-code").action(async (agentArg, options) => {
|
|
34980
35439
|
const flags = resolveCommandFlags(program);
|
|
34981
35440
|
const resources = createExecutionResources(container, flags, "mcp");
|
|
34982
|
-
const existingKey = await
|
|
34983
|
-
fs: container.fs,
|
|
34984
|
-
filePath: container.env.credentialsPath
|
|
34985
|
-
});
|
|
35441
|
+
const existingKey = await container.readApiKey();
|
|
34986
35442
|
if (!existingKey) {
|
|
34987
35443
|
resources.logger.intro("login");
|
|
34988
35444
|
await container.options.resolveApiKey({ dryRun: flags.dryRun });
|
|
@@ -35082,10 +35538,7 @@ async function runMcpServer(container, options) {
|
|
|
35082
35538
|
const outputFormatPreferences = parseMcpOutputFormatPreferences(
|
|
35083
35539
|
options.outputFormat
|
|
35084
35540
|
);
|
|
35085
|
-
const apiKey = await
|
|
35086
|
-
fs: container.fs,
|
|
35087
|
-
filePath: container.env.credentialsPath
|
|
35088
|
-
});
|
|
35541
|
+
const apiKey = await container.readApiKey();
|
|
35089
35542
|
if (!apiKey) {
|
|
35090
35543
|
process.stderr.write("No credentials found. Run 'poe-code login' first.\n");
|
|
35091
35544
|
process.exit(1);
|
|
@@ -35102,22 +35555,21 @@ var DEFAULT_MCP_AGENT;
|
|
|
35102
35555
|
var init_mcp = __esm({
|
|
35103
35556
|
"src/cli/commands/mcp.ts"() {
|
|
35104
35557
|
"use strict";
|
|
35105
|
-
|
|
35106
|
-
init_credentials2();
|
|
35558
|
+
init_src4();
|
|
35107
35559
|
init_client_instance();
|
|
35108
35560
|
init_mcp_server();
|
|
35109
35561
|
init_shared();
|
|
35110
35562
|
init_mcp_output_format();
|
|
35111
35563
|
init_command_not_found();
|
|
35112
|
-
|
|
35564
|
+
init_src7();
|
|
35113
35565
|
init_execution_context();
|
|
35114
35566
|
DEFAULT_MCP_AGENT = "claude-code";
|
|
35115
35567
|
}
|
|
35116
35568
|
});
|
|
35117
35569
|
|
|
35118
35570
|
// packages/agent-skill-config/src/configs.ts
|
|
35119
|
-
import
|
|
35120
|
-
import
|
|
35571
|
+
import os2 from "node:os";
|
|
35572
|
+
import path15 from "node:path";
|
|
35121
35573
|
function resolveAgentSupport2(input, registry2 = agentSkillConfigs) {
|
|
35122
35574
|
const resolvedId = resolveAgentId(input);
|
|
35123
35575
|
if (!resolvedId) {
|
|
@@ -35133,7 +35585,7 @@ var agentSkillConfigs, supportedAgents2;
|
|
|
35133
35585
|
var init_configs3 = __esm({
|
|
35134
35586
|
"packages/agent-skill-config/src/configs.ts"() {
|
|
35135
35587
|
"use strict";
|
|
35136
|
-
|
|
35588
|
+
init_src3();
|
|
35137
35589
|
agentSkillConfigs = {
|
|
35138
35590
|
"claude-code": {
|
|
35139
35591
|
globalSkillDir: "~/.claude/skills",
|
|
@@ -35153,7 +35605,7 @@ var init_configs3 = __esm({
|
|
|
35153
35605
|
});
|
|
35154
35606
|
|
|
35155
35607
|
// packages/agent-skill-config/src/templates.ts
|
|
35156
|
-
import { readFile as
|
|
35608
|
+
import { readFile as readFile2 } from "node:fs/promises";
|
|
35157
35609
|
async function getTemplates() {
|
|
35158
35610
|
if (templatesCache) {
|
|
35159
35611
|
return templatesCache;
|
|
@@ -35162,7 +35614,7 @@ async function getTemplates() {
|
|
|
35162
35614
|
"./templates/poe-generate.md",
|
|
35163
35615
|
import.meta.url
|
|
35164
35616
|
);
|
|
35165
|
-
const poeGenerateTemplate = await
|
|
35617
|
+
const poeGenerateTemplate = await readFile2(poeGenerateTemplateUrl, "utf8");
|
|
35166
35618
|
templatesCache = {
|
|
35167
35619
|
"poe-generate.md": poeGenerateTemplate
|
|
35168
35620
|
};
|
|
@@ -35294,7 +35746,7 @@ var UnsupportedAgentError2, bundledSkillTemplateIds, SKILL_TEMPLATE_ID;
|
|
|
35294
35746
|
var init_apply2 = __esm({
|
|
35295
35747
|
"packages/agent-skill-config/src/apply.ts"() {
|
|
35296
35748
|
"use strict";
|
|
35297
|
-
|
|
35749
|
+
init_src2();
|
|
35298
35750
|
init_configs3();
|
|
35299
35751
|
init_templates();
|
|
35300
35752
|
UnsupportedAgentError2 = class extends Error {
|
|
@@ -35309,7 +35761,7 @@ var init_apply2 = __esm({
|
|
|
35309
35761
|
});
|
|
35310
35762
|
|
|
35311
35763
|
// packages/agent-skill-config/src/index.ts
|
|
35312
|
-
var
|
|
35764
|
+
var init_src8 = __esm({
|
|
35313
35765
|
"packages/agent-skill-config/src/index.ts"() {
|
|
35314
35766
|
"use strict";
|
|
35315
35767
|
init_configs3();
|
|
@@ -35533,8 +35985,8 @@ var DEFAULT_SKILL_AGENT;
|
|
|
35533
35985
|
var init_skill = __esm({
|
|
35534
35986
|
"src/cli/commands/skill.ts"() {
|
|
35535
35987
|
"use strict";
|
|
35536
|
-
|
|
35537
|
-
|
|
35988
|
+
init_src4();
|
|
35989
|
+
init_src8();
|
|
35538
35990
|
init_shared();
|
|
35539
35991
|
init_command_not_found();
|
|
35540
35992
|
DEFAULT_SKILL_AGENT = "claude-code";
|
|
@@ -35624,7 +36076,7 @@ async function displayVersion(container, currentVersion) {
|
|
|
35624
36076
|
var init_version2 = __esm({
|
|
35625
36077
|
"src/cli/commands/version.ts"() {
|
|
35626
36078
|
"use strict";
|
|
35627
|
-
|
|
36079
|
+
init_src4();
|
|
35628
36080
|
init_version();
|
|
35629
36081
|
init_exit_signals();
|
|
35630
36082
|
}
|
|
@@ -35749,10 +36201,10 @@ var init_registry2 = __esm({
|
|
|
35749
36201
|
});
|
|
35750
36202
|
|
|
35751
36203
|
// packages/worktree/src/create.ts
|
|
35752
|
-
import { join
|
|
36204
|
+
import { join } from "node:path";
|
|
35753
36205
|
async function createWorktree(opts) {
|
|
35754
36206
|
const branch = `poe-code/${opts.name}`;
|
|
35755
|
-
const worktreePath =
|
|
36207
|
+
const worktreePath = join(opts.worktreeDir, opts.name);
|
|
35756
36208
|
try {
|
|
35757
36209
|
await opts.deps.exec(`git worktree remove ${worktreePath} --force`, { cwd: opts.cwd });
|
|
35758
36210
|
} catch {
|
|
@@ -35827,7 +36279,7 @@ var init_list = __esm({
|
|
|
35827
36279
|
});
|
|
35828
36280
|
|
|
35829
36281
|
// packages/worktree/src/index.ts
|
|
35830
|
-
var
|
|
36282
|
+
var init_src9 = __esm({
|
|
35831
36283
|
"packages/worktree/src/index.ts"() {
|
|
35832
36284
|
"use strict";
|
|
35833
36285
|
init_create();
|
|
@@ -35916,13 +36368,13 @@ function getDirtyFiles(cwd) {
|
|
|
35916
36368
|
for (const line of lines) {
|
|
35917
36369
|
if (!line) continue;
|
|
35918
36370
|
if (line.length < 4) continue;
|
|
35919
|
-
let
|
|
36371
|
+
let path21 = line.slice(3).trim();
|
|
35920
36372
|
const renameArrow = " -> ";
|
|
35921
|
-
const arrowIndex =
|
|
36373
|
+
const arrowIndex = path21.lastIndexOf(renameArrow);
|
|
35922
36374
|
if (arrowIndex >= 0) {
|
|
35923
|
-
|
|
36375
|
+
path21 = path21.slice(arrowIndex + renameArrow.length).trim();
|
|
35924
36376
|
}
|
|
35925
|
-
if (
|
|
36377
|
+
if (path21) files.push(path21);
|
|
35926
36378
|
}
|
|
35927
36379
|
return files;
|
|
35928
36380
|
}
|
|
@@ -35934,7 +36386,7 @@ var init_utils2 = __esm({
|
|
|
35934
36386
|
|
|
35935
36387
|
// packages/ralph/src/plan/parser.ts
|
|
35936
36388
|
import { parse as parse7 } from "yaml";
|
|
35937
|
-
function
|
|
36389
|
+
function isRecord5(value) {
|
|
35938
36390
|
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
35939
36391
|
}
|
|
35940
36392
|
function asOptionalString(value, field) {
|
|
@@ -35985,7 +36437,7 @@ function normalizeStatus(value) {
|
|
|
35985
36437
|
);
|
|
35986
36438
|
}
|
|
35987
36439
|
function parseStory(value, index) {
|
|
35988
|
-
if (!
|
|
36440
|
+
if (!isRecord5(value)) throw new Error(`Invalid stories[${index}]: expected object`);
|
|
35989
36441
|
return {
|
|
35990
36442
|
id: asRequiredString(value.id, `stories[${index}].id`),
|
|
35991
36443
|
title: asRequiredString(value.title, `stories[${index}].title`),
|
|
@@ -36009,7 +36461,7 @@ function parsePlan(yamlContent) {
|
|
|
36009
36461
|
const message = error2 instanceof Error ? error2.message : String(error2);
|
|
36010
36462
|
throw new Error(`Invalid plan YAML: ${message}`, { cause: error2 });
|
|
36011
36463
|
}
|
|
36012
|
-
if (!
|
|
36464
|
+
if (!isRecord5(doc)) {
|
|
36013
36465
|
throw new Error("Invalid plan YAML: expected top-level object");
|
|
36014
36466
|
}
|
|
36015
36467
|
const storiesValue = doc.stories;
|
|
@@ -36075,17 +36527,17 @@ function serializePlan(prd) {
|
|
|
36075
36527
|
return yaml.endsWith("\n") ? yaml : `${yaml}
|
|
36076
36528
|
`;
|
|
36077
36529
|
}
|
|
36078
|
-
function lockPlanFile(
|
|
36079
|
-
return lockFile(
|
|
36530
|
+
function lockPlanFile(path21) {
|
|
36531
|
+
return lockFile(path21, { retries: 20, minTimeout: 25, maxTimeout: 250 });
|
|
36080
36532
|
}
|
|
36081
|
-
async function writePlan(
|
|
36533
|
+
async function writePlan(path21, prd, options = {}) {
|
|
36082
36534
|
const fs3 = options.fs ?? fsPromises2;
|
|
36083
36535
|
const lock = options.lock ?? lockPlanFile;
|
|
36084
|
-
await fs3.mkdir(dirname3(
|
|
36085
|
-
const release = await lock(
|
|
36536
|
+
await fs3.mkdir(dirname3(path21), { recursive: true });
|
|
36537
|
+
const release = await lock(path21);
|
|
36086
36538
|
try {
|
|
36087
36539
|
const yaml = serializePlan(prd);
|
|
36088
|
-
await fs3.writeFile(
|
|
36540
|
+
await fs3.writeFile(path21, yaml, { encoding: "utf8" });
|
|
36089
36541
|
} finally {
|
|
36090
36542
|
await release();
|
|
36091
36543
|
}
|
|
@@ -36104,7 +36556,7 @@ function renderPrompt(template, variables) {
|
|
|
36104
36556
|
var init_renderer2 = __esm({
|
|
36105
36557
|
"packages/ralph/src/prompt/renderer.ts"() {
|
|
36106
36558
|
"use strict";
|
|
36107
|
-
|
|
36559
|
+
init_src2();
|
|
36108
36560
|
}
|
|
36109
36561
|
});
|
|
36110
36562
|
|
|
@@ -36173,8 +36625,8 @@ var init_selector = __esm({
|
|
|
36173
36625
|
// packages/ralph/src/story/updater.ts
|
|
36174
36626
|
import { dirname as dirname4 } from "node:path";
|
|
36175
36627
|
import * as fsPromises3 from "node:fs/promises";
|
|
36176
|
-
function lockPlanFile2(
|
|
36177
|
-
return lockFile(
|
|
36628
|
+
function lockPlanFile2(path21) {
|
|
36629
|
+
return lockFile(path21, { retries: 20, minTimeout: 25, maxTimeout: 250 });
|
|
36178
36630
|
}
|
|
36179
36631
|
function assertStoryStatus(value) {
|
|
36180
36632
|
if (value === "open") return;
|
|
@@ -36255,9 +36707,9 @@ function appendSection(lines, title, items, options) {
|
|
|
36255
36707
|
}
|
|
36256
36708
|
lines.push("");
|
|
36257
36709
|
}
|
|
36258
|
-
async function writeRunMeta(
|
|
36710
|
+
async function writeRunMeta(path21, metadata, options = {}) {
|
|
36259
36711
|
const fs3 = options.fs ?? fsPromises4;
|
|
36260
|
-
await fs3.mkdir(dirname5(
|
|
36712
|
+
await fs3.mkdir(dirname5(path21), { recursive: true });
|
|
36261
36713
|
const lines = [];
|
|
36262
36714
|
lines.push("# Ralph Run Summary", "");
|
|
36263
36715
|
lines.push(`- Run ID: ${metadata.runId}`);
|
|
@@ -36286,7 +36738,7 @@ async function writeRunMeta(path20, metadata, options = {}) {
|
|
|
36286
36738
|
const git = metadata.git ?? null;
|
|
36287
36739
|
if (!git) {
|
|
36288
36740
|
lines.push("");
|
|
36289
|
-
await fs3.writeFile(
|
|
36741
|
+
await fs3.writeFile(path21, lines.join("\n"), { encoding: "utf8" });
|
|
36290
36742
|
return;
|
|
36291
36743
|
}
|
|
36292
36744
|
lines.push("", "## Git");
|
|
@@ -36301,7 +36753,7 @@ async function writeRunMeta(path20, metadata, options = {}) {
|
|
|
36301
36753
|
lines.push("");
|
|
36302
36754
|
} else {
|
|
36303
36755
|
lines.push("");
|
|
36304
|
-
await fs3.writeFile(
|
|
36756
|
+
await fs3.writeFile(path21, lines.join("\n"), { encoding: "utf8" });
|
|
36305
36757
|
return;
|
|
36306
36758
|
}
|
|
36307
36759
|
if (git.commits !== void 0 && git.commits !== null) {
|
|
@@ -36321,7 +36773,7 @@ async function writeRunMeta(path20, metadata, options = {}) {
|
|
|
36321
36773
|
appendSection(lines, "### Uncommitted Changes", git.dirtyFiles, {
|
|
36322
36774
|
emptyLabel: "(none)"
|
|
36323
36775
|
});
|
|
36324
|
-
await fs3.writeFile(
|
|
36776
|
+
await fs3.writeFile(path21, lines.join("\n"), { encoding: "utf8" });
|
|
36325
36777
|
}
|
|
36326
36778
|
var init_metadata = __esm({
|
|
36327
36779
|
"packages/ralph/src/run/metadata.ts"() {
|
|
@@ -36409,9 +36861,9 @@ async function defaultStreamingSpawn(agentId, options) {
|
|
|
36409
36861
|
exitCode: result.exitCode
|
|
36410
36862
|
};
|
|
36411
36863
|
}
|
|
36412
|
-
function absPath(cwd,
|
|
36413
|
-
if (!
|
|
36414
|
-
return
|
|
36864
|
+
function absPath(cwd, path21) {
|
|
36865
|
+
if (!path21) return resolvePath3(cwd);
|
|
36866
|
+
return path21.startsWith("/") ? path21 : resolvePath3(cwd, path21);
|
|
36415
36867
|
}
|
|
36416
36868
|
function pad2(value) {
|
|
36417
36869
|
return value < 10 ? `0${value}` : String(value);
|
|
@@ -36461,8 +36913,8 @@ async function appendToErrorsLog(fs3, errorsLogPath, message) {
|
|
|
36461
36913
|
await fs3.mkdir(dirname6(errorsLogPath), { recursive: true });
|
|
36462
36914
|
await fs3.writeFile(errorsLogPath, `${previous}${next}`, { encoding: "utf8" });
|
|
36463
36915
|
}
|
|
36464
|
-
function lockPlanFile3(
|
|
36465
|
-
return lockFile(
|
|
36916
|
+
function lockPlanFile3(path21) {
|
|
36917
|
+
return lockFile(path21, { retries: 20, minTimeout: 25, maxTimeout: 250 });
|
|
36466
36918
|
}
|
|
36467
36919
|
function getCurrentBranch(cwd) {
|
|
36468
36920
|
try {
|
|
@@ -36564,7 +37016,7 @@ async function defaultPromptOverbake(args) {
|
|
|
36564
37016
|
async function buildLoop(options) {
|
|
36565
37017
|
const fs3 = options.deps?.fs ?? fsPromises5;
|
|
36566
37018
|
const lock = options.deps?.lock ?? lockPlanFile3;
|
|
36567
|
-
const
|
|
37019
|
+
const spawn6 = options.deps?.spawn ?? defaultStreamingSpawn;
|
|
36568
37020
|
const git = options.deps?.git ?? {
|
|
36569
37021
|
getHead,
|
|
36570
37022
|
getCommitList,
|
|
@@ -36618,7 +37070,7 @@ async function buildLoop(options) {
|
|
|
36618
37070
|
});
|
|
36619
37071
|
worktreeBranch = entry.branch;
|
|
36620
37072
|
const worktreePath = entry.path;
|
|
36621
|
-
const symlinkFn = fs3.symlink ?? ((target,
|
|
37073
|
+
const symlinkFn = fs3.symlink ?? ((target, path21) => fsPromises5.symlink(target, path21));
|
|
36622
37074
|
const exec = worktreeDeps.exec;
|
|
36623
37075
|
const dirsToLink = [".poe-code-ralph", ".agents/poe-code-ralph"];
|
|
36624
37076
|
for (const dir of dirsToLink) {
|
|
@@ -36733,7 +37185,7 @@ async function buildLoop(options) {
|
|
|
36733
37185
|
let stderrForErrorsLog;
|
|
36734
37186
|
let overbakeAction = null;
|
|
36735
37187
|
try {
|
|
36736
|
-
const result = await
|
|
37188
|
+
const result = await spawn6(options.agent, {
|
|
36737
37189
|
prompt,
|
|
36738
37190
|
cwd,
|
|
36739
37191
|
model: options.model,
|
|
@@ -36906,10 +37358,10 @@ var init_loop = __esm({
|
|
|
36906
37358
|
"packages/ralph/src/build/loop.ts"() {
|
|
36907
37359
|
"use strict";
|
|
36908
37360
|
init_lock();
|
|
37361
|
+
init_src5();
|
|
36909
37362
|
init_src4();
|
|
36910
|
-
|
|
36911
|
-
|
|
36912
|
-
init_src8();
|
|
37363
|
+
init_src2();
|
|
37364
|
+
init_src9();
|
|
36913
37365
|
init_detector();
|
|
36914
37366
|
init_utils2();
|
|
36915
37367
|
init_parser();
|
|
@@ -36923,18 +37375,18 @@ var init_loop = __esm({
|
|
|
36923
37375
|
});
|
|
36924
37376
|
|
|
36925
37377
|
// packages/ralph/src/plan/resolver.ts
|
|
36926
|
-
import
|
|
37378
|
+
import path16 from "node:path";
|
|
36927
37379
|
import * as fsPromises6 from "node:fs/promises";
|
|
36928
37380
|
function isPlanCandidateFile(fileName) {
|
|
36929
37381
|
const lower = fileName.toLowerCase();
|
|
36930
37382
|
if (!lower.startsWith("plan")) {
|
|
36931
37383
|
return false;
|
|
36932
37384
|
}
|
|
36933
|
-
const ext =
|
|
37385
|
+
const ext = path16.extname(lower);
|
|
36934
37386
|
return ext === ".yml" || ext === ".yaml";
|
|
36935
37387
|
}
|
|
36936
37388
|
async function listPlanCandidates(fs3, cwd) {
|
|
36937
|
-
const plansDir =
|
|
37389
|
+
const plansDir = path16.join(cwd, ".agents", "poe-code-ralph", "plans");
|
|
36938
37390
|
let entries;
|
|
36939
37391
|
try {
|
|
36940
37392
|
entries = await fs3.readdir(plansDir);
|
|
@@ -36949,12 +37401,12 @@ async function listPlanCandidates(fs3, cwd) {
|
|
|
36949
37401
|
if (!isPlanCandidateFile(entry)) {
|
|
36950
37402
|
continue;
|
|
36951
37403
|
}
|
|
36952
|
-
const absPath2 =
|
|
37404
|
+
const absPath2 = path16.join(plansDir, entry);
|
|
36953
37405
|
const stats = await fs3.stat(absPath2);
|
|
36954
37406
|
if (!stats.isFile()) {
|
|
36955
37407
|
continue;
|
|
36956
37408
|
}
|
|
36957
|
-
const relativePath =
|
|
37409
|
+
const relativePath = path16.relative(cwd, absPath2);
|
|
36958
37410
|
const content = await fs3.readFile(absPath2, "utf8");
|
|
36959
37411
|
const plan = parsePlan(content);
|
|
36960
37412
|
const done = plan.stories.filter((s) => s.status === "done").length;
|
|
@@ -36973,7 +37425,7 @@ async function resolvePlanPath(options) {
|
|
|
36973
37425
|
const cwd = options.cwd;
|
|
36974
37426
|
const provided = options.plan?.trim();
|
|
36975
37427
|
if (provided) {
|
|
36976
|
-
const absPath2 =
|
|
37428
|
+
const absPath2 = path16.isAbsolute(provided) ? provided : path16.resolve(cwd, provided);
|
|
36977
37429
|
try {
|
|
36978
37430
|
const stats = await fs3.stat(absPath2);
|
|
36979
37431
|
if (!stats.isFile()) {
|
|
@@ -37022,21 +37474,21 @@ async function resolvePlanPath(options) {
|
|
|
37022
37474
|
var init_resolver = __esm({
|
|
37023
37475
|
"packages/ralph/src/plan/resolver.ts"() {
|
|
37024
37476
|
"use strict";
|
|
37025
|
-
|
|
37026
|
-
|
|
37477
|
+
init_src4();
|
|
37478
|
+
init_src2();
|
|
37027
37479
|
init_parser();
|
|
37028
37480
|
}
|
|
37029
37481
|
});
|
|
37030
37482
|
|
|
37031
37483
|
// packages/ralph/src/plan/generator.ts
|
|
37032
|
-
import
|
|
37484
|
+
import path17 from "node:path";
|
|
37033
37485
|
import * as fsPromises7 from "node:fs/promises";
|
|
37034
37486
|
var PLAN_PROMPT_TEMPLATE;
|
|
37035
37487
|
var init_generator = __esm({
|
|
37036
37488
|
"packages/ralph/src/plan/generator.ts"() {
|
|
37037
37489
|
"use strict";
|
|
37038
|
-
|
|
37039
|
-
|
|
37490
|
+
init_src5();
|
|
37491
|
+
init_src2();
|
|
37040
37492
|
init_renderer2();
|
|
37041
37493
|
PLAN_PROMPT_TEMPLATE = [
|
|
37042
37494
|
"# Plan",
|
|
@@ -37098,27 +37550,27 @@ function formatTimestamp3(date4) {
|
|
|
37098
37550
|
const seconds = pad22(date4.getSeconds());
|
|
37099
37551
|
return `${year}-${month}-${day} ${hours}:${minutes}:${seconds}`;
|
|
37100
37552
|
}
|
|
37101
|
-
function validateLogPath(
|
|
37102
|
-
if (typeof
|
|
37553
|
+
function validateLogPath(path21) {
|
|
37554
|
+
if (typeof path21 !== "string" || path21.trim().length === 0) {
|
|
37103
37555
|
throw new Error(
|
|
37104
|
-
`Invalid activity log path: expected a non-empty string, got ${String(
|
|
37556
|
+
`Invalid activity log path: expected a non-empty string, got ${String(path21)}`
|
|
37105
37557
|
);
|
|
37106
37558
|
}
|
|
37107
|
-
if (
|
|
37559
|
+
if (path21.includes("\0")) {
|
|
37108
37560
|
throw new Error("Invalid activity log path: contains null byte");
|
|
37109
37561
|
}
|
|
37110
37562
|
}
|
|
37111
|
-
async function logActivity(
|
|
37112
|
-
validateLogPath(
|
|
37563
|
+
async function logActivity(path21, message, options = {}) {
|
|
37564
|
+
validateLogPath(path21);
|
|
37113
37565
|
const fs3 = options.fs ?? fsPromises8;
|
|
37114
|
-
const parent = dirname7(
|
|
37566
|
+
const parent = dirname7(path21);
|
|
37115
37567
|
if (parent && parent !== ".") {
|
|
37116
37568
|
await fs3.mkdir(parent, { recursive: true });
|
|
37117
37569
|
}
|
|
37118
37570
|
const entry = `[${formatTimestamp3(/* @__PURE__ */ new Date())}] ${message}
|
|
37119
37571
|
`;
|
|
37120
37572
|
try {
|
|
37121
|
-
await fs3.appendFile(
|
|
37573
|
+
await fs3.appendFile(path21, entry, { encoding: "utf8" });
|
|
37122
37574
|
} catch (error2) {
|
|
37123
37575
|
const detail = error2 instanceof Error ? error2.message : `Unknown error: ${String(error2)}`;
|
|
37124
37576
|
throw new Error(`Failed to append activity log entry: ${detail}`, { cause: error2 });
|
|
@@ -37131,7 +37583,7 @@ var init_activity = __esm({
|
|
|
37131
37583
|
});
|
|
37132
37584
|
|
|
37133
37585
|
// packages/ralph/src/config/loader.ts
|
|
37134
|
-
import
|
|
37586
|
+
import path18 from "node:path";
|
|
37135
37587
|
import * as fsPromises9 from "node:fs/promises";
|
|
37136
37588
|
import YAML from "yaml";
|
|
37137
37589
|
function isPlainObject2(value) {
|
|
@@ -37166,8 +37618,8 @@ function pickOptionalPositiveInt(config2, key, options) {
|
|
|
37166
37618
|
return value;
|
|
37167
37619
|
}
|
|
37168
37620
|
async function loadSingleConfig(configDir, fs3) {
|
|
37169
|
-
const yamlPath =
|
|
37170
|
-
const jsonPath =
|
|
37621
|
+
const yamlPath = path18.join(configDir, "config.yaml");
|
|
37622
|
+
const jsonPath = path18.join(configDir, "config.json");
|
|
37171
37623
|
let raw = null;
|
|
37172
37624
|
let format = null;
|
|
37173
37625
|
let sourcePath = null;
|
|
@@ -37240,14 +37692,14 @@ async function loadConfig(cwd, deps) {
|
|
|
37240
37692
|
const sources = [];
|
|
37241
37693
|
let merged = {};
|
|
37242
37694
|
if (deps?.homeDir) {
|
|
37243
|
-
const globalDir =
|
|
37695
|
+
const globalDir = path18.join(deps.homeDir, ".poe-code", "ralph");
|
|
37244
37696
|
const globalResult = await loadSingleConfig(globalDir, fs3);
|
|
37245
37697
|
if (globalResult) {
|
|
37246
37698
|
merged = globalResult.config;
|
|
37247
37699
|
sources.push({ path: globalResult.sourcePath, scope: "global" });
|
|
37248
37700
|
}
|
|
37249
37701
|
}
|
|
37250
|
-
const localDir =
|
|
37702
|
+
const localDir = path18.join(cwd, ".agents", "poe-code-ralph");
|
|
37251
37703
|
const localResult = await loadSingleConfig(localDir, fs3);
|
|
37252
37704
|
if (localResult) {
|
|
37253
37705
|
merged = mergeConfigs(merged, localResult.config);
|
|
@@ -37258,7 +37710,7 @@ async function loadConfig(cwd, deps) {
|
|
|
37258
37710
|
var init_loader = __esm({
|
|
37259
37711
|
"packages/ralph/src/config/loader.ts"() {
|
|
37260
37712
|
"use strict";
|
|
37261
|
-
|
|
37713
|
+
init_src2();
|
|
37262
37714
|
}
|
|
37263
37715
|
});
|
|
37264
37716
|
|
|
@@ -37269,7 +37721,7 @@ async function ralphBuild(options) {
|
|
|
37269
37721
|
cwd: options.cwd ?? process.cwd()
|
|
37270
37722
|
});
|
|
37271
37723
|
}
|
|
37272
|
-
var
|
|
37724
|
+
var init_src10 = __esm({
|
|
37273
37725
|
"packages/ralph/src/index.ts"() {
|
|
37274
37726
|
"use strict";
|
|
37275
37727
|
init_loop();
|
|
@@ -37289,12 +37741,12 @@ var require_PROMPT_worktree_merge = __commonJS({
|
|
|
37289
37741
|
});
|
|
37290
37742
|
|
|
37291
37743
|
// src/cli/commands/ralph-worktree.ts
|
|
37292
|
-
import
|
|
37744
|
+
import path19 from "node:path";
|
|
37293
37745
|
import { execSync as execSync3 } from "node:child_process";
|
|
37294
37746
|
function registerRalphWorktreeCommand(ralph, container) {
|
|
37295
37747
|
ralph.command("worktree").description("Merge a completed worktree back into the main branch.").argument("<name>", "Name of the worktree to merge").option("--agent <name>", "Agent to use for the merge").action(async function(name) {
|
|
37296
37748
|
const cwd = container.env.cwd;
|
|
37297
|
-
const registryFile =
|
|
37749
|
+
const registryFile = path19.join(cwd, ".poe-code-ralph", "worktrees.yaml");
|
|
37298
37750
|
const worktrees = await listWorktrees(cwd, registryFile, {
|
|
37299
37751
|
fs: {
|
|
37300
37752
|
readFile: (p, enc) => container.fs.readFile(p, enc),
|
|
@@ -37357,10 +37809,10 @@ function registerRalphWorktreeCommand(ralph, container) {
|
|
|
37357
37809
|
var init_ralph_worktree = __esm({
|
|
37358
37810
|
"src/cli/commands/ralph-worktree.ts"() {
|
|
37359
37811
|
"use strict";
|
|
37360
|
-
init_src3();
|
|
37361
|
-
init_src8();
|
|
37362
37812
|
init_src4();
|
|
37363
|
-
|
|
37813
|
+
init_src9();
|
|
37814
|
+
init_src5();
|
|
37815
|
+
init_src2();
|
|
37364
37816
|
init_errors();
|
|
37365
37817
|
}
|
|
37366
37818
|
});
|
|
@@ -37436,7 +37888,7 @@ var require_activity = __commonJS({
|
|
|
37436
37888
|
});
|
|
37437
37889
|
|
|
37438
37890
|
// src/cli/commands/ralph.ts
|
|
37439
|
-
import
|
|
37891
|
+
import path20 from "node:path";
|
|
37440
37892
|
async function loadRalphTemplates() {
|
|
37441
37893
|
const [
|
|
37442
37894
|
promptPartialPlan,
|
|
@@ -37521,7 +37973,7 @@ async function writeFileOrSkip(args) {
|
|
|
37521
37973
|
args.logger.info(`Skip: ${args.displayPath} (already exists)`);
|
|
37522
37974
|
return "skipped";
|
|
37523
37975
|
}
|
|
37524
|
-
await args.fs.mkdir(
|
|
37976
|
+
await args.fs.mkdir(path20.dirname(args.filePath), { recursive: true });
|
|
37525
37977
|
await args.fs.writeFile(args.filePath, args.contents, { encoding: "utf8" });
|
|
37526
37978
|
args.logger.info(`${exists ? "Overwrite" : "Create"}: ${args.displayPath}`);
|
|
37527
37979
|
return "written";
|
|
@@ -37557,22 +38009,22 @@ async function installRalphTemplates(args) {
|
|
|
37557
38009
|
const promptPlanContents = templates.promptPlan.replace("{{{PROMPT_PARTIAL_PLAN}}}", templates.promptPartialPlan);
|
|
37558
38010
|
const templateWrites = [
|
|
37559
38011
|
{
|
|
37560
|
-
targetPath:
|
|
38012
|
+
targetPath: path20.join(cwd, ".agents", "poe-code-ralph", "PROMPT_plan.md"),
|
|
37561
38013
|
displayPath: ".agents/poe-code-ralph/PROMPT_plan.md",
|
|
37562
38014
|
contents: promptPlanContents
|
|
37563
38015
|
},
|
|
37564
38016
|
{
|
|
37565
|
-
targetPath:
|
|
38017
|
+
targetPath: path20.join(cwd, ".agents", "poe-code-ralph", "PROMPT_build.md"),
|
|
37566
38018
|
displayPath: ".agents/poe-code-ralph/PROMPT_build.md",
|
|
37567
38019
|
contents: templates.promptBuild
|
|
37568
38020
|
},
|
|
37569
38021
|
{
|
|
37570
|
-
targetPath:
|
|
38022
|
+
targetPath: path20.join(cwd, ".agents", "poe-code-ralph", "references", "GUARDRAILS.md"),
|
|
37571
38023
|
displayPath: ".agents/poe-code-ralph/references/GUARDRAILS.md",
|
|
37572
38024
|
contents: templates.refGuardrails
|
|
37573
38025
|
},
|
|
37574
38026
|
{
|
|
37575
|
-
targetPath:
|
|
38027
|
+
targetPath: path20.join(cwd, ".agents", "poe-code-ralph", "references", "CONTEXT_ENGINEERING.md"),
|
|
37576
38028
|
displayPath: ".agents/poe-code-ralph/references/CONTEXT_ENGINEERING.md",
|
|
37577
38029
|
contents: templates.refContextEngineering
|
|
37578
38030
|
}
|
|
@@ -37590,22 +38042,22 @@ async function installRalphTemplates(args) {
|
|
|
37590
38042
|
const stateFiles = [
|
|
37591
38043
|
{
|
|
37592
38044
|
contents: templates.stateProgress,
|
|
37593
|
-
targetPath:
|
|
38045
|
+
targetPath: path20.join(cwd, ".poe-code-ralph", "progress.md"),
|
|
37594
38046
|
displayPath: ".poe-code-ralph/progress.md"
|
|
37595
38047
|
},
|
|
37596
38048
|
{
|
|
37597
38049
|
contents: templates.stateGuardrails,
|
|
37598
|
-
targetPath:
|
|
38050
|
+
targetPath: path20.join(cwd, ".poe-code-ralph", "guardrails.md"),
|
|
37599
38051
|
displayPath: ".poe-code-ralph/guardrails.md"
|
|
37600
38052
|
},
|
|
37601
38053
|
{
|
|
37602
38054
|
contents: templates.stateErrors,
|
|
37603
|
-
targetPath:
|
|
38055
|
+
targetPath: path20.join(cwd, ".poe-code-ralph", "errors.log"),
|
|
37604
38056
|
displayPath: ".poe-code-ralph/errors.log"
|
|
37605
38057
|
},
|
|
37606
38058
|
{
|
|
37607
38059
|
contents: templates.stateActivity,
|
|
37608
|
-
targetPath:
|
|
38060
|
+
targetPath: path20.join(cwd, ".poe-code-ralph", "activity.log"),
|
|
37609
38061
|
displayPath: ".poe-code-ralph/activity.log"
|
|
37610
38062
|
}
|
|
37611
38063
|
];
|
|
@@ -37652,7 +38104,7 @@ function registerRalphCommand(program, container) {
|
|
|
37652
38104
|
throw new ValidationError(message2);
|
|
37653
38105
|
}
|
|
37654
38106
|
const rawPath = options.activityLog?.trim() || configActivityLogPath || ".poe-code-ralph/activity.log";
|
|
37655
|
-
const resolvedPath =
|
|
38107
|
+
const resolvedPath = path20.isAbsolute(rawPath) ? rawPath : path20.resolve(container.env.cwd, rawPath);
|
|
37656
38108
|
await logActivity(resolvedPath, trimmedMessage, {
|
|
37657
38109
|
fs: container.fs
|
|
37658
38110
|
});
|
|
@@ -37664,7 +38116,7 @@ function registerRalphCommand(program, container) {
|
|
|
37664
38116
|
if (!planPath) {
|
|
37665
38117
|
throw new ValidationError("--plan <path> is required.");
|
|
37666
38118
|
}
|
|
37667
|
-
const resolvedPath =
|
|
38119
|
+
const resolvedPath = path20.isAbsolute(planPath) ? planPath : path20.resolve(cwd, planPath);
|
|
37668
38120
|
let content;
|
|
37669
38121
|
try {
|
|
37670
38122
|
content = await container.fs.readFile(resolvedPath, "utf8");
|
|
@@ -37838,7 +38290,7 @@ function registerRalphCommand(program, container) {
|
|
|
37838
38290
|
} else {
|
|
37839
38291
|
try {
|
|
37840
38292
|
const planContent = await container.fs.readFile(
|
|
37841
|
-
|
|
38293
|
+
path20.resolve(cwd, planPath),
|
|
37842
38294
|
"utf8"
|
|
37843
38295
|
);
|
|
37844
38296
|
const plan = parsePlan(planContent);
|
|
@@ -37872,7 +38324,7 @@ function registerRalphCommand(program, container) {
|
|
|
37872
38324
|
} else {
|
|
37873
38325
|
try {
|
|
37874
38326
|
const planContent = await container.fs.readFile(
|
|
37875
|
-
|
|
38327
|
+
path20.resolve(cwd, planPath),
|
|
37876
38328
|
"utf8"
|
|
37877
38329
|
);
|
|
37878
38330
|
const plan = parsePlan(planContent);
|
|
@@ -37928,10 +38380,10 @@ var templateImports, DEFAULT_RALPH_AGENT;
|
|
|
37928
38380
|
var init_ralph = __esm({
|
|
37929
38381
|
"src/cli/commands/ralph.ts"() {
|
|
37930
38382
|
"use strict";
|
|
37931
|
-
|
|
37932
|
-
|
|
37933
|
-
|
|
37934
|
-
|
|
38383
|
+
init_src4();
|
|
38384
|
+
init_src10();
|
|
38385
|
+
init_src8();
|
|
38386
|
+
init_src2();
|
|
37935
38387
|
init_errors();
|
|
37936
38388
|
init_shared();
|
|
37937
38389
|
init_ralph_worktree();
|
|
@@ -38149,7 +38601,7 @@ var init_usage = __esm({
|
|
|
38149
38601
|
"use strict";
|
|
38150
38602
|
init_shared();
|
|
38151
38603
|
init_errors();
|
|
38152
|
-
|
|
38604
|
+
init_src4();
|
|
38153
38605
|
}
|
|
38154
38606
|
});
|
|
38155
38607
|
|
|
@@ -38242,10 +38694,7 @@ function registerModelsCommand(program, container) {
|
|
|
38242
38694
|
const commandOptions = this.opts();
|
|
38243
38695
|
resources.logger.intro("models");
|
|
38244
38696
|
try {
|
|
38245
|
-
const apiKey = await
|
|
38246
|
-
fs: container.fs,
|
|
38247
|
-
filePath: container.env.credentialsPath
|
|
38248
|
-
});
|
|
38697
|
+
const apiKey = await container.readApiKey();
|
|
38249
38698
|
if (flags.dryRun) {
|
|
38250
38699
|
resources.logger.dryRun(
|
|
38251
38700
|
"Dry run: would fetch models from Poe API."
|
|
@@ -38433,9 +38882,8 @@ var init_models = __esm({
|
|
|
38433
38882
|
"src/cli/commands/models.ts"() {
|
|
38434
38883
|
"use strict";
|
|
38435
38884
|
init_shared();
|
|
38436
|
-
init_credentials2();
|
|
38437
38885
|
init_errors();
|
|
38438
|
-
|
|
38886
|
+
init_src4();
|
|
38439
38887
|
MAX_VALUES_LENGTH = 105;
|
|
38440
38888
|
MAX_DEFAULT_LENGTH = 36;
|
|
38441
38889
|
}
|
|
@@ -38447,7 +38895,7 @@ var init_package = __esm({
|
|
|
38447
38895
|
"package.json"() {
|
|
38448
38896
|
package_default = {
|
|
38449
38897
|
name: "poe-code",
|
|
38450
|
-
version: "3.0.
|
|
38898
|
+
version: "3.0.69-beta.2",
|
|
38451
38899
|
description: "CLI tool to configure Poe API for developer workflows.",
|
|
38452
38900
|
type: "module",
|
|
38453
38901
|
main: "./dist/index.js",
|
|
@@ -38528,6 +38976,7 @@ var init_package = __esm({
|
|
|
38528
38976
|
devDependencies: {
|
|
38529
38977
|
"@eslint/js": "^9.0.0",
|
|
38530
38978
|
"@modelcontextprotocol/sdk": "^1.26.0",
|
|
38979
|
+
"@poe-code/auth": "*",
|
|
38531
38980
|
"@poe-code/agent-spawn": "*",
|
|
38532
38981
|
"@poe-code/config-mutations": "*",
|
|
38533
38982
|
"@poe-code/design-system": "*",
|
|
@@ -38830,7 +39279,7 @@ var init_program = __esm({
|
|
|
38830
39279
|
async "src/cli/program.ts"() {
|
|
38831
39280
|
"use strict";
|
|
38832
39281
|
await init_container2();
|
|
38833
|
-
|
|
39282
|
+
init_src4();
|
|
38834
39283
|
init_configure();
|
|
38835
39284
|
await init_spawn4();
|
|
38836
39285
|
await init_research2();
|
|
@@ -38927,7 +39376,7 @@ function createPromptRunner(adapter = {
|
|
|
38927
39376
|
var init_prompt_runner = __esm({
|
|
38928
39377
|
"src/cli/prompt-runner.ts"() {
|
|
38929
39378
|
"use strict";
|
|
38930
|
-
|
|
39379
|
+
init_src4();
|
|
38931
39380
|
init_errors();
|
|
38932
39381
|
}
|
|
38933
39382
|
});
|
|
@@ -38938,17 +39387,17 @@ __export(bootstrap_exports, {
|
|
|
38938
39387
|
createCliMain: () => createCliMain,
|
|
38939
39388
|
isCliInvocation: () => isCliInvocation
|
|
38940
39389
|
});
|
|
38941
|
-
import * as
|
|
39390
|
+
import * as nodeFs2 from "node:fs/promises";
|
|
38942
39391
|
import * as nodeFsSync3 from "node:fs";
|
|
38943
39392
|
import { realpathSync } from "node:fs";
|
|
38944
|
-
import { homedir as
|
|
39393
|
+
import { homedir as homedir4 } from "node:os";
|
|
38945
39394
|
import { pathToFileURL as pathToFileURL2 } from "node:url";
|
|
38946
|
-
import { join as
|
|
39395
|
+
import { join as join2 } from "node:path";
|
|
38947
39396
|
import chalk13 from "chalk";
|
|
38948
39397
|
function createCliMain(programFactory) {
|
|
38949
39398
|
return async function runCli() {
|
|
38950
|
-
const homeDir =
|
|
38951
|
-
const logDir =
|
|
39399
|
+
const homeDir = homedir4();
|
|
39400
|
+
const logDir = join2(homeDir, ".poe-code", "logs");
|
|
38952
39401
|
const promptRunner = createPromptRunner();
|
|
38953
39402
|
const shouldLogToStderr = process.env.POE_CODE_STDERR_LOGS === "1" || process.env.POE_CODE_STDERR_LOGS === "true";
|
|
38954
39403
|
const errorLogger = new ErrorLogger({
|
|
@@ -38983,7 +39432,7 @@ function createCliMain(programFactory) {
|
|
|
38983
39432
|
} else {
|
|
38984
39433
|
log2.error(`Error: ${error2.message}`);
|
|
38985
39434
|
log2.message(
|
|
38986
|
-
`See logs at ${
|
|
39435
|
+
`See logs at ${join2(logDir, "errors.log")} for more details.`,
|
|
38987
39436
|
{ symbol: chalk13.magenta("\u25CF") }
|
|
38988
39437
|
);
|
|
38989
39438
|
}
|
|
@@ -39009,11 +39458,11 @@ var fsAdapter;
|
|
|
39009
39458
|
var init_bootstrap = __esm({
|
|
39010
39459
|
"src/cli/bootstrap.ts"() {
|
|
39011
39460
|
"use strict";
|
|
39012
|
-
|
|
39461
|
+
init_src4();
|
|
39013
39462
|
init_error_logger();
|
|
39014
39463
|
init_errors();
|
|
39015
39464
|
init_prompt_runner();
|
|
39016
|
-
fsAdapter =
|
|
39465
|
+
fsAdapter = nodeFs2;
|
|
39017
39466
|
}
|
|
39018
39467
|
});
|
|
39019
39468
|
|
|
@@ -39152,6 +39601,6 @@ export {
|
|
|
39152
39601
|
getPoeApiKey,
|
|
39153
39602
|
isCliInvocation2 as isCliInvocation,
|
|
39154
39603
|
main,
|
|
39155
|
-
|
|
39604
|
+
spawn4 as spawn
|
|
39156
39605
|
};
|
|
39157
39606
|
//# sourceMappingURL=index.js.map
|