@bastani/atomic 0.9.16-alpha.3 → 0.9.16-alpha.4
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/CHANGELOG.md +7 -0
- package/dist/builtin/intercom/index.bundle.mjs +498 -436
- package/dist/builtin/intercom/package.json +1 -1
- package/dist/builtin/mcp/index.bundle.mjs +553 -491
- package/dist/builtin/mcp/package.json +1 -1
- package/dist/builtin/subagents/package.json +1 -1
- package/dist/builtin/subagents/src/extension/index.bundle.mjs +714 -652
- package/dist/builtin/web-access/index.bundle.mjs +547 -485
- package/dist/builtin/web-access/package.json +1 -1
- package/dist/builtin/workflows/package.json +1 -1
- package/dist/builtin/workflows/src/extension/index.bundle.mjs +845 -783
- package/dist/builtin/workflows/src/index.bundle.mjs +485 -423
- package/dist/config-package-identity.d.ts +22 -0
- package/dist/config-package-identity.d.ts.map +1 -0
- package/dist/config-package-identity.js +73 -0
- package/dist/config-package-identity.js.map +1 -0
- package/dist/config.d.ts.map +1 -1
- package/dist/config.js +5 -10
- package/dist/config.js.map +1 -1
- package/npm-shrinkwrap.json +32 -32
- package/package.json +3 -3
|
@@ -16,6 +16,96 @@ var __export = (target, all) => {
|
|
|
16
16
|
var __esm = (fn, res) => () => (fn && (res = fn(fn = 0)), res);
|
|
17
17
|
var __require = /* @__PURE__ */ createRequire(import.meta.url);
|
|
18
18
|
|
|
19
|
+
// src/core/builtin-install-layout.ts
|
|
20
|
+
function requiredEntriesForBuiltin(dirName) {
|
|
21
|
+
return [INSTALLED_EXTENSION_ENTRIES[dirName], SOURCE_EXTENSION_ENTRIES[dirName]];
|
|
22
|
+
}
|
|
23
|
+
var BUILTIN_PACKAGE_DIR_NAMES, SOURCE_EXTENSION_ENTRIES, INSTALLED_EXTENSION_ENTRIES;
|
|
24
|
+
var init_builtin_install_layout = __esm(() => {
|
|
25
|
+
BUILTIN_PACKAGE_DIR_NAMES = ["workflows", "subagents", "mcp", "web-access", "intercom"];
|
|
26
|
+
SOURCE_EXTENSION_ENTRIES = {
|
|
27
|
+
workflows: "src/extension/index.ts",
|
|
28
|
+
subagents: "src/extension/index.ts",
|
|
29
|
+
mcp: "index.ts",
|
|
30
|
+
"web-access": "index.ts",
|
|
31
|
+
intercom: "index.ts"
|
|
32
|
+
};
|
|
33
|
+
INSTALLED_EXTENSION_ENTRIES = {
|
|
34
|
+
workflows: "src/extension/index.bundle.mjs",
|
|
35
|
+
subagents: "src/extension/index.bundle.mjs",
|
|
36
|
+
mcp: "index.bundle.mjs",
|
|
37
|
+
"web-access": "index.bundle.mjs",
|
|
38
|
+
intercom: "index.bundle.mjs"
|
|
39
|
+
};
|
|
40
|
+
});
|
|
41
|
+
|
|
42
|
+
// src/config-package-identity.ts
|
|
43
|
+
import { existsSync, readFileSync } from "fs";
|
|
44
|
+
import { dirname, join } from "path";
|
|
45
|
+
function isCompanionBuiltinPackageName(name) {
|
|
46
|
+
return name !== undefined && COMPANION_BUILTIN_PACKAGE_NAMES.includes(name);
|
|
47
|
+
}
|
|
48
|
+
function packageJsonDefinesAppIdentity(pkg) {
|
|
49
|
+
if (pkg.name === "@bastani/atomic" || pkg.name === "@mariozechner/pi")
|
|
50
|
+
return true;
|
|
51
|
+
return pkg.atomicConfig !== undefined || pkg.piConfig !== undefined;
|
|
52
|
+
}
|
|
53
|
+
function resolvePackageDirFrom(startDir) {
|
|
54
|
+
let dir = startDir;
|
|
55
|
+
let firstPackageDir;
|
|
56
|
+
while (dir !== dirname(dir)) {
|
|
57
|
+
const packageJsonPath = join(dir, "package.json");
|
|
58
|
+
if (existsSync(packageJsonPath)) {
|
|
59
|
+
firstPackageDir ??= dir;
|
|
60
|
+
if (shouldUsePackageDir(readPackageIdentity(packageJsonPath))) {
|
|
61
|
+
return dir;
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
dir = dirname(dir);
|
|
65
|
+
}
|
|
66
|
+
return firstPackageDir ?? startDir;
|
|
67
|
+
}
|
|
68
|
+
function shouldUsePackageDir(pkg) {
|
|
69
|
+
if (packageJsonDefinesAppIdentity(pkg))
|
|
70
|
+
return true;
|
|
71
|
+
return !isCompanionBuiltinPackageName(pkg.name);
|
|
72
|
+
}
|
|
73
|
+
function isJsonValue(value) {
|
|
74
|
+
if (value === null || typeof value === "boolean" || typeof value === "string")
|
|
75
|
+
return true;
|
|
76
|
+
if (typeof value === "number")
|
|
77
|
+
return Number.isFinite(value);
|
|
78
|
+
if (Array.isArray(value))
|
|
79
|
+
return value.every(isJsonValue);
|
|
80
|
+
if (typeof value !== "object" || Object.getPrototypeOf(value) !== Object.prototype)
|
|
81
|
+
return false;
|
|
82
|
+
return Object.values(value).every(isJsonValue);
|
|
83
|
+
}
|
|
84
|
+
function isJsonObject(value) {
|
|
85
|
+
return value !== null && typeof value === "object" && !Array.isArray(value);
|
|
86
|
+
}
|
|
87
|
+
function readPackageIdentity(packageJsonPath) {
|
|
88
|
+
try {
|
|
89
|
+
const parsed = JSON.parse(readFileSync(packageJsonPath, "utf-8"));
|
|
90
|
+
if (!isJsonValue(parsed) || !isJsonObject(parsed))
|
|
91
|
+
return {};
|
|
92
|
+
const name = parsed.name;
|
|
93
|
+
const atomicConfig = parsed.atomicConfig;
|
|
94
|
+
const piConfig = parsed.piConfig;
|
|
95
|
+
return {
|
|
96
|
+
...typeof name === "string" ? { name } : {},
|
|
97
|
+
...atomicConfig !== undefined && isJsonObject(atomicConfig) ? { atomicConfig } : {},
|
|
98
|
+
...piConfig !== undefined && isJsonObject(piConfig) ? { piConfig } : {}
|
|
99
|
+
};
|
|
100
|
+
} catch {}
|
|
101
|
+
return {};
|
|
102
|
+
}
|
|
103
|
+
var COMPANION_BUILTIN_PACKAGE_NAMES;
|
|
104
|
+
var init_config_package_identity = __esm(() => {
|
|
105
|
+
init_builtin_install_layout();
|
|
106
|
+
COMPANION_BUILTIN_PACKAGE_NAMES = BUILTIN_PACKAGE_DIR_NAMES.map((dirName) => `@bastani/${dirName}`);
|
|
107
|
+
});
|
|
108
|
+
|
|
19
109
|
// src/utils/agent-attribution.ts
|
|
20
110
|
var ATOMIC_AI_AGENT = "atomic";
|
|
21
111
|
|
|
@@ -196,7 +286,7 @@ var init_child_process = __esm(() => {
|
|
|
196
286
|
// src/utils/paths.ts
|
|
197
287
|
import { realpathSync } from "node:fs";
|
|
198
288
|
import { homedir } from "node:os";
|
|
199
|
-
import { isAbsolute, join, resolve as nodeResolvePath, relative, sep } from "node:path";
|
|
289
|
+
import { isAbsolute, join as join2, resolve as nodeResolvePath, relative, sep } from "node:path";
|
|
200
290
|
import { fileURLToPath } from "node:url";
|
|
201
291
|
function getHomeDir() {
|
|
202
292
|
if (process.platform === "win32") {
|
|
@@ -249,7 +339,7 @@ function normalizePath(input, options = {}) {
|
|
|
249
339
|
if (normalized === "~")
|
|
250
340
|
return home;
|
|
251
341
|
if (normalized.startsWith("~/") || process.platform === "win32" && normalized.startsWith("~\\")) {
|
|
252
|
-
return
|
|
342
|
+
return join2(home, normalized.slice(2));
|
|
253
343
|
}
|
|
254
344
|
}
|
|
255
345
|
if (/^file:\/\//.test(normalized)) {
|
|
@@ -291,20 +381,20 @@ var init_paths = __esm(() => {
|
|
|
291
381
|
});
|
|
292
382
|
|
|
293
383
|
// src/utils/split-launcher.ts
|
|
294
|
-
import { dirname, join as
|
|
384
|
+
import { dirname as dirname2, join as join3 } from "node:path";
|
|
295
385
|
import { fileURLToPath as fileURLToPath2 } from "node:url";
|
|
296
386
|
function isSplitLauncherRuntime() {
|
|
297
387
|
return process.env.ATOMIC_CODING_AGENT === "true" && /(?:^|[\\/])atomic(?:\.exe)?$/i.test(process.execPath);
|
|
298
388
|
}
|
|
299
389
|
function splitLauncherDir() {
|
|
300
|
-
return
|
|
390
|
+
return dirname2(process.execPath);
|
|
301
391
|
}
|
|
302
392
|
function moduleFileFromMetaUrl(metaUrl, execRelativeFile) {
|
|
303
393
|
try {
|
|
304
394
|
return fileURLToPath2(metaUrl);
|
|
305
395
|
} catch (error) {
|
|
306
396
|
if (isSplitLauncherRuntime())
|
|
307
|
-
return
|
|
397
|
+
return join3(splitLauncherDir(), execRelativeFile);
|
|
308
398
|
throw error;
|
|
309
399
|
}
|
|
310
400
|
}
|
|
@@ -316,24 +406,17 @@ var init_config_self_update = __esm(() => {
|
|
|
316
406
|
});
|
|
317
407
|
|
|
318
408
|
// src/config.ts
|
|
319
|
-
import { existsSync, readFileSync } from "fs";
|
|
320
|
-
import { dirname as
|
|
409
|
+
import { existsSync as existsSync2, readFileSync as readFileSync2 } from "fs";
|
|
410
|
+
import { dirname as dirname3, join as join4, resolve } from "path";
|
|
321
411
|
function getPackageDir() {
|
|
322
412
|
const envDir = process.env.ATOMIC_PACKAGE_DIR ?? process.env.PI_PACKAGE_DIR;
|
|
323
413
|
if (envDir) {
|
|
324
414
|
return normalizePath(envDir);
|
|
325
415
|
}
|
|
326
416
|
if (isBunBinary) {
|
|
327
|
-
return
|
|
328
|
-
}
|
|
329
|
-
let dir = __dirname2;
|
|
330
|
-
while (dir !== dirname2(dir)) {
|
|
331
|
-
if (existsSync(join3(dir, "package.json"))) {
|
|
332
|
-
return dir;
|
|
333
|
-
}
|
|
334
|
-
dir = dirname2(dir);
|
|
417
|
+
return dirname3(process.execPath);
|
|
335
418
|
}
|
|
336
|
-
return __dirname2;
|
|
419
|
+
return resolvePackageDirFrom(__dirname2);
|
|
337
420
|
}
|
|
338
421
|
function getModuleAssetRoot() {
|
|
339
422
|
const hasPackageDirOverride = !!(process.env.ATOMIC_PACKAGE_DIR || process.env.PI_PACKAGE_DIR);
|
|
@@ -341,43 +424,43 @@ function getModuleAssetRoot() {
|
|
|
341
424
|
return __dirname2;
|
|
342
425
|
}
|
|
343
426
|
const packageDir = getPackageDir();
|
|
344
|
-
return
|
|
427
|
+
return join4(packageDir, existsSync2(join4(packageDir, "src")) ? "src" : "dist");
|
|
345
428
|
}
|
|
346
429
|
function getThemesDir() {
|
|
347
430
|
if (isBunBinary) {
|
|
348
|
-
return
|
|
431
|
+
return join4(getPackageDir(), "theme");
|
|
349
432
|
}
|
|
350
|
-
return
|
|
433
|
+
return join4(getModuleAssetRoot(), "modes", "interactive", "theme");
|
|
351
434
|
}
|
|
352
435
|
function getExportTemplateDir() {
|
|
353
436
|
if (isBunBinary) {
|
|
354
|
-
return
|
|
437
|
+
return join4(getPackageDir(), "export-html");
|
|
355
438
|
}
|
|
356
|
-
return
|
|
439
|
+
return join4(getModuleAssetRoot(), "core", "export-html");
|
|
357
440
|
}
|
|
358
441
|
function getPackageJsonPath() {
|
|
359
|
-
return
|
|
442
|
+
return join4(getPackageDir(), "package.json");
|
|
360
443
|
}
|
|
361
444
|
function getReadmePath() {
|
|
362
|
-
return resolve(
|
|
445
|
+
return resolve(join4(getPackageDir(), "README.md"));
|
|
363
446
|
}
|
|
364
447
|
function getDocsPath() {
|
|
365
|
-
return resolve(
|
|
448
|
+
return resolve(join4(getPackageDir(), "docs"));
|
|
366
449
|
}
|
|
367
450
|
function getExamplesPath() {
|
|
368
|
-
return resolve(
|
|
451
|
+
return resolve(join4(getPackageDir(), "examples"));
|
|
369
452
|
}
|
|
370
453
|
function getChangelogPath() {
|
|
371
|
-
return resolve(
|
|
454
|
+
return resolve(join4(getPackageDir(), "CHANGELOG.md"));
|
|
372
455
|
}
|
|
373
456
|
function getInteractiveAssetsDir() {
|
|
374
457
|
if (isBunBinary) {
|
|
375
|
-
return
|
|
458
|
+
return join4(getPackageDir(), "assets");
|
|
376
459
|
}
|
|
377
|
-
return
|
|
460
|
+
return join4(getModuleAssetRoot(), "modes", "interactive", "assets");
|
|
378
461
|
}
|
|
379
462
|
function getBundledInteractiveAssetPath(name) {
|
|
380
|
-
return
|
|
463
|
+
return join4(getInteractiveAssetsDir(), name);
|
|
381
464
|
}
|
|
382
465
|
function appNameFromPackageName(packageName) {
|
|
383
466
|
const localName = packageName?.split("/").pop()?.trim();
|
|
@@ -467,10 +550,10 @@ function getAgentDir() {
|
|
|
467
550
|
if (envDir) {
|
|
468
551
|
return expandTildePath(envDir);
|
|
469
552
|
}
|
|
470
|
-
return
|
|
553
|
+
return join4(getHomeDir(), CONFIG_DIR_NAME, "agent");
|
|
471
554
|
}
|
|
472
555
|
function getLegacyAgentDir() {
|
|
473
|
-
return
|
|
556
|
+
return join4(getHomeDir(), LEGACY_CONFIG_DIR_NAME, "agent");
|
|
474
557
|
}
|
|
475
558
|
function getAgentDirs() {
|
|
476
559
|
const primary = getAgentDir();
|
|
@@ -481,43 +564,44 @@ function getAgentDirs() {
|
|
|
481
564
|
return legacy === primary ? [primary] : [primary, legacy];
|
|
482
565
|
}
|
|
483
566
|
function getProjectConfigDirs(cwd) {
|
|
484
|
-
return CONFIG_DIR_NAMES.map((name) =>
|
|
567
|
+
return CONFIG_DIR_NAMES.map((name) => join4(cwd, name));
|
|
485
568
|
}
|
|
486
569
|
function getAgentConfigPaths(...segments) {
|
|
487
|
-
return getAgentDirs().map((dir) =>
|
|
570
|
+
return getAgentDirs().map((dir) => join4(dir, ...segments));
|
|
488
571
|
}
|
|
489
572
|
function getProjectConfigPaths(cwd, ...segments) {
|
|
490
|
-
return getProjectConfigDirs(cwd).map((dir) =>
|
|
573
|
+
return getProjectConfigDirs(cwd).map((dir) => join4(dir, ...segments));
|
|
491
574
|
}
|
|
492
575
|
function getCustomThemesDir() {
|
|
493
|
-
return
|
|
576
|
+
return join4(getAgentDir(), "themes");
|
|
494
577
|
}
|
|
495
578
|
function getAuthPath() {
|
|
496
|
-
return
|
|
579
|
+
return join4(getAgentDir(), "auth.json");
|
|
497
580
|
}
|
|
498
581
|
function getBinDir() {
|
|
499
|
-
return
|
|
582
|
+
return join4(getAgentDir(), "bin");
|
|
500
583
|
}
|
|
501
584
|
function getSessionsDir() {
|
|
502
|
-
return
|
|
585
|
+
return join4(getAgentDir(), "sessions");
|
|
503
586
|
}
|
|
504
587
|
function getDebugLogPath() {
|
|
505
|
-
return
|
|
588
|
+
return join4(getAgentDir(), `${APP_NAME}-debug.log`);
|
|
506
589
|
}
|
|
507
590
|
var __filename2, __dirname2, bunFsMarkers, isBunBinary, isBundledBuild, isBunRuntime, pkg, PACKAGE_NAME, packageAppName, appConfig, APP_NAME, APP_TITLE, CONFIG_DIR_NAME, LEGACY_CONFIG_DIR_NAME = ".pi", CONFIG_DIR_NAMES, VERSION, CHANGELOG_URL, ENV_PREFIX, LEGACY_ENV_PREFIX = "PI", ENV_AGENT_DIR, ENV_SESSION_DIR, ENV_PACKAGE_DIR, ENV_OFFLINE, ENV_SKIP_VERSION_CHECK, ENV_STARTUP_BENCHMARK, ENV_TELEMETRY, ENV_SHARE_VIEWER_URL, ENV_CLEAR_ON_SHRINK, ENV_HARDWARE_CURSOR, ENV_TIMING, ENV_CODEX_FAST_MODE, WORKFLOW_STAGE_SUBAGENT_GUARD_ENV, DEFAULT_SHARE_VIEWER_URL = "https://pi.dev/session/";
|
|
508
591
|
var init_config = __esm(() => {
|
|
592
|
+
init_config_package_identity();
|
|
509
593
|
init_paths();
|
|
510
594
|
init_split_launcher();
|
|
511
595
|
init_config_self_update();
|
|
512
596
|
__filename2 = moduleFileFromMetaUrl(import.meta.url, "app.js");
|
|
513
|
-
__dirname2 =
|
|
597
|
+
__dirname2 = dirname3(__filename2);
|
|
514
598
|
bunFsMarkers = ["$bunfs", "~BUN", "%7EBUN"];
|
|
515
599
|
isBunBinary = isSplitLauncherRuntime() || [import.meta.url, process.argv[1] ?? ""].some((candidate) => bunFsMarkers.some((marker) => candidate.includes(marker)));
|
|
516
600
|
isBundledBuild = process.env.ATOMIC_BUNDLED_BUILD === "1";
|
|
517
601
|
isBunRuntime = !!process.versions.bun;
|
|
518
602
|
pkg = {};
|
|
519
603
|
try {
|
|
520
|
-
pkg = JSON.parse(
|
|
604
|
+
pkg = JSON.parse(readFileSync2(getPackageJsonPath(), "utf-8"));
|
|
521
605
|
} catch (e) {
|
|
522
606
|
const err = e;
|
|
523
607
|
if (err.code !== "ENOENT")
|
|
@@ -1655,14 +1739,14 @@ var init_planner_outcome = __esm(() => {
|
|
|
1655
1739
|
// src/core/compaction/range-planner-diagnostics.ts
|
|
1656
1740
|
import { uuidv7 } from "@bastani/pi-ai";
|
|
1657
1741
|
import { chmodSync, writeFileSync } from "fs";
|
|
1658
|
-
import { basename, dirname as
|
|
1742
|
+
import { basename, dirname as dirname4, join as join5 } from "path";
|
|
1659
1743
|
function writeSidecar(sessionFilePath, kind, payload) {
|
|
1660
|
-
const dir =
|
|
1744
|
+
const dir = dirname4(sessionFilePath);
|
|
1661
1745
|
const base = basename(sessionFilePath, ".jsonl");
|
|
1662
1746
|
const timestamp = Date.now();
|
|
1663
1747
|
const body = JSON.stringify(payload, null, 2);
|
|
1664
1748
|
for (let attempt = 0;attempt < 4; attempt++) {
|
|
1665
|
-
const filePath =
|
|
1749
|
+
const filePath = join5(dir, `${base}-compaction-${kind}-${timestamp}-${uuidv7()}.json`);
|
|
1666
1750
|
try {
|
|
1667
1751
|
writeFileSync(filePath, body, { encoding: "utf-8", mode: 384, flag: "wx" });
|
|
1668
1752
|
try {
|
|
@@ -3008,7 +3092,7 @@ function generateId(byId) {
|
|
|
3008
3092
|
var init_session_manager_validation = () => {};
|
|
3009
3093
|
|
|
3010
3094
|
// src/core/session-manager-entries.ts
|
|
3011
|
-
import { join as
|
|
3095
|
+
import { join as join6 } from "path";
|
|
3012
3096
|
function entryBase(byId, parentId) {
|
|
3013
3097
|
return {
|
|
3014
3098
|
id: generateId(byId),
|
|
@@ -3035,7 +3119,7 @@ function createSessionHeader(id, cwd, timestamp = new Date().toISOString(), pare
|
|
|
3035
3119
|
}
|
|
3036
3120
|
function createSessionFilePath(sessionDir, timestamp, sessionId) {
|
|
3037
3121
|
const fileTimestamp = timestamp.replace(/[:.]/g, "-");
|
|
3038
|
-
return
|
|
3122
|
+
return join6(sessionDir, `${fileTimestamp}_${sessionId}.jsonl`);
|
|
3039
3123
|
}
|
|
3040
3124
|
function createMessageEntry(message, byId, parentId) {
|
|
3041
3125
|
return {
|
|
@@ -3166,17 +3250,17 @@ var init_session_manager_entries = __esm(() => {
|
|
|
3166
3250
|
});
|
|
3167
3251
|
|
|
3168
3252
|
// src/core/session-manager-paths.ts
|
|
3169
|
-
import { existsSync as
|
|
3170
|
-
import { join as
|
|
3253
|
+
import { existsSync as existsSync3, mkdirSync } from "fs";
|
|
3254
|
+
import { join as join7 } from "path";
|
|
3171
3255
|
function getDefaultSessionDirPath(cwd, agentDir = getAgentDir()) {
|
|
3172
3256
|
const resolvedCwd = resolvePath(cwd);
|
|
3173
3257
|
const resolvedAgentDir = resolvePath(agentDir);
|
|
3174
3258
|
const safePath = `--${resolvedCwd.replace(/^[/\\]/, "").replace(/[/\\:]/g, "-")}--`;
|
|
3175
|
-
return
|
|
3259
|
+
return join7(resolvedAgentDir, "sessions", safePath);
|
|
3176
3260
|
}
|
|
3177
3261
|
function getDefaultSessionDir(cwd, agentDir = getAgentDir()) {
|
|
3178
3262
|
const sessionDir = getDefaultSessionDirPath(cwd, agentDir);
|
|
3179
|
-
if (!
|
|
3263
|
+
if (!existsSync3(sessionDir)) {
|
|
3180
3264
|
mkdirSync(sessionDir, { recursive: true });
|
|
3181
3265
|
}
|
|
3182
3266
|
return sessionDir;
|
|
@@ -3190,7 +3274,7 @@ var init_session_manager_paths = __esm(() => {
|
|
|
3190
3274
|
import {
|
|
3191
3275
|
appendFileSync,
|
|
3192
3276
|
closeSync,
|
|
3193
|
-
existsSync as
|
|
3277
|
+
existsSync as existsSync4,
|
|
3194
3278
|
mkdirSync as mkdirSync2,
|
|
3195
3279
|
openSync,
|
|
3196
3280
|
readdirSync,
|
|
@@ -3200,7 +3284,7 @@ import {
|
|
|
3200
3284
|
unlinkSync,
|
|
3201
3285
|
writeFileSync as writeFileSync2
|
|
3202
3286
|
} from "fs";
|
|
3203
|
-
import { join as
|
|
3287
|
+
import { join as join8 } from "path";
|
|
3204
3288
|
import { StringDecoder } from "string_decoder";
|
|
3205
3289
|
function parseSessionEntryLine(line) {
|
|
3206
3290
|
if (!line.trim())
|
|
@@ -3213,7 +3297,7 @@ function parseSessionEntryLine(line) {
|
|
|
3213
3297
|
}
|
|
3214
3298
|
function loadEntriesFromFile(filePath) {
|
|
3215
3299
|
const resolvedFilePath = normalizePath(filePath);
|
|
3216
|
-
if (!
|
|
3300
|
+
if (!existsSync4(resolvedFilePath))
|
|
3217
3301
|
return [];
|
|
3218
3302
|
const entries = [];
|
|
3219
3303
|
const fd = openSync(resolvedFilePath, "r");
|
|
@@ -3308,7 +3392,7 @@ function findMostRecentSession(sessionDir, cwd, includeInternal = false) {
|
|
|
3308
3392
|
const resolvedSessionDir = normalizePath(sessionDir);
|
|
3309
3393
|
const resolvedCwd = cwd ? resolvePath(cwd) : undefined;
|
|
3310
3394
|
try {
|
|
3311
|
-
const files = readdirSync(resolvedSessionDir).filter((f) => f.endsWith(".jsonl")).map((f) =>
|
|
3395
|
+
const files = readdirSync(resolvedSessionDir).filter((f) => f.endsWith(".jsonl")).map((f) => join8(resolvedSessionDir, f)).map((path) => ({ path, header: readSessionHeader(path) })).filter((file) => file.header !== null && (!resolvedCwd || sessionCwdMatches(getSessionHeaderCwd(file.header), resolvedCwd)) && (includeInternal || !isInternalHeader(file.header))).map(({ path }) => ({ path, mtime: statSync(path).mtime })).sort((a, b) => b.mtime.getTime() - a.mtime.getTime());
|
|
3312
3396
|
return files[0]?.path || null;
|
|
3313
3397
|
} catch {
|
|
3314
3398
|
return null;
|
|
@@ -3323,7 +3407,7 @@ function writeSessionEntries(filePath, entries) {
|
|
|
3323
3407
|
writeFileSync2(filePath, serializeSessionEntries(entries));
|
|
3324
3408
|
}
|
|
3325
3409
|
function appendSessionPayload(filePath, payload) {
|
|
3326
|
-
const existed =
|
|
3410
|
+
const existed = existsSync4(filePath);
|
|
3327
3411
|
const offset = existed ? statSync(filePath).size : 0;
|
|
3328
3412
|
try {
|
|
3329
3413
|
appendFileSync(filePath, payload);
|
|
@@ -3331,7 +3415,7 @@ function appendSessionPayload(filePath, payload) {
|
|
|
3331
3415
|
try {
|
|
3332
3416
|
if (existed)
|
|
3333
3417
|
truncateSync(filePath, offset);
|
|
3334
|
-
else if (
|
|
3418
|
+
else if (existsSync4(filePath))
|
|
3335
3419
|
unlinkSync(filePath);
|
|
3336
3420
|
} catch (rollbackError) {
|
|
3337
3421
|
throw new AggregateError([writeError, rollbackError], "Session append and rollback failed");
|
|
@@ -3361,7 +3445,7 @@ function persistAppendedEntry(filePath, entries, entry, flushed) {
|
|
|
3361
3445
|
return true;
|
|
3362
3446
|
}
|
|
3363
3447
|
function ensureDirectory(dir) {
|
|
3364
|
-
if (!
|
|
3448
|
+
if (!existsSync4(dir)) {
|
|
3365
3449
|
mkdirSync2(dir, { recursive: true });
|
|
3366
3450
|
}
|
|
3367
3451
|
}
|
|
@@ -3373,7 +3457,7 @@ var init_session_manager_storage = __esm(() => {
|
|
|
3373
3457
|
});
|
|
3374
3458
|
|
|
3375
3459
|
// src/core/session-manager-archive.ts
|
|
3376
|
-
import { join as
|
|
3460
|
+
import { join as join9 } from "path";
|
|
3377
3461
|
function createBackupSnapshot(sessionFile, entries, label = "compact") {
|
|
3378
3462
|
if (!sessionFile)
|
|
3379
3463
|
return;
|
|
@@ -3464,7 +3548,7 @@ function forkSessionFromFile(sourcePath, targetCwd, sessionDir, options) {
|
|
|
3464
3548
|
}
|
|
3465
3549
|
const newSessionId = options?.id ?? createSessionId();
|
|
3466
3550
|
const timestamp = new Date().toISOString();
|
|
3467
|
-
const newSessionFile =
|
|
3551
|
+
const newSessionFile = join9(dir, `${timestamp.replace(/[:.]/g, "-")}_${newSessionId}.jsonl`);
|
|
3468
3552
|
const newHeader = createSessionHeader(newSessionId, resolvedTargetCwd, timestamp, resolvedSourcePath, options?.internal, options?.workflow);
|
|
3469
3553
|
appendSessionEntry(newSessionFile, newHeader);
|
|
3470
3554
|
for (const entry of sourceEntries) {
|
|
@@ -3562,9 +3646,9 @@ var init_session_manager_migrations = __esm(() => {
|
|
|
3562
3646
|
});
|
|
3563
3647
|
|
|
3564
3648
|
// src/core/session-manager-list.ts
|
|
3565
|
-
import { existsSync as
|
|
3649
|
+
import { existsSync as existsSync5 } from "fs";
|
|
3566
3650
|
import { readdir, readFile, stat } from "fs/promises";
|
|
3567
|
-
import { join as
|
|
3651
|
+
import { join as join10 } from "path";
|
|
3568
3652
|
function isMessageWithContent(message) {
|
|
3569
3653
|
return typeof message.role === "string" && "content" in message;
|
|
3570
3654
|
}
|
|
@@ -3713,12 +3797,12 @@ async function buildSessionInfo(filePath) {
|
|
|
3713
3797
|
}
|
|
3714
3798
|
async function listSessionsFromDir(dir, onProgress, progressOffset = 0, progressTotal, includeInternal = false) {
|
|
3715
3799
|
const sessions = [];
|
|
3716
|
-
if (!
|
|
3800
|
+
if (!existsSync5(dir)) {
|
|
3717
3801
|
return sessions;
|
|
3718
3802
|
}
|
|
3719
3803
|
try {
|
|
3720
3804
|
const dirEntries = await readdir(dir);
|
|
3721
|
-
const files = dirEntries.filter((f) => f.endsWith(".jsonl")).map((f) =>
|
|
3805
|
+
const files = dirEntries.filter((f) => f.endsWith(".jsonl")).map((f) => join10(dir, f));
|
|
3722
3806
|
const total = progressTotal ?? files.length;
|
|
3723
3807
|
let loaded = 0;
|
|
3724
3808
|
const results = await mapSessionFilesCooperatively(files, includeInternal, () => {
|
|
@@ -3751,17 +3835,17 @@ async function listAllSessions(sessionDirOrOnProgress, onProgress, includeIntern
|
|
|
3751
3835
|
}
|
|
3752
3836
|
const sessionsDir = getSessionsDir();
|
|
3753
3837
|
try {
|
|
3754
|
-
if (!
|
|
3838
|
+
if (!existsSync5(sessionsDir)) {
|
|
3755
3839
|
return [];
|
|
3756
3840
|
}
|
|
3757
3841
|
const entries = await readdir(sessionsDir, { withFileTypes: true });
|
|
3758
|
-
const dirs = entries.filter((entry) => entry.isDirectory() || entry.isSymbolicLink()).map((entry) =>
|
|
3842
|
+
const dirs = entries.filter((entry) => entry.isDirectory() || entry.isSymbolicLink()).map((entry) => join10(sessionsDir, entry.name));
|
|
3759
3843
|
let totalFiles = 0;
|
|
3760
3844
|
const dirFiles = [];
|
|
3761
3845
|
for (const dir of dirs) {
|
|
3762
3846
|
try {
|
|
3763
3847
|
const files = (await readdir(dir)).filter((f) => f.endsWith(".jsonl"));
|
|
3764
|
-
dirFiles.push(files.map((f) =>
|
|
3848
|
+
dirFiles.push(files.map((f) => join10(dir, f)));
|
|
3765
3849
|
totalFiles += files.length;
|
|
3766
3850
|
} catch {
|
|
3767
3851
|
dirFiles.push([]);
|
|
@@ -3798,7 +3882,7 @@ var init_session_manager_list = __esm(() => {
|
|
|
3798
3882
|
});
|
|
3799
3883
|
|
|
3800
3884
|
// src/core/session-manager-core.ts
|
|
3801
|
-
import { existsSync as
|
|
3885
|
+
import { existsSync as existsSync6, statSync as statSync2 } from "fs";
|
|
3802
3886
|
import { resolve as resolve2 } from "path";
|
|
3803
3887
|
|
|
3804
3888
|
class SessionManager {
|
|
@@ -3831,7 +3915,7 @@ class SessionManager {
|
|
|
3831
3915
|
}
|
|
3832
3916
|
_setSessionFile(sessionFile, preloadedFileEntries) {
|
|
3833
3917
|
this.sessionFile = resolvePath(sessionFile);
|
|
3834
|
-
if (
|
|
3918
|
+
if (existsSync6(this.sessionFile)) {
|
|
3835
3919
|
this.fileEntries = preloadedFileEntries ?? loadEntriesFromFile(this.sessionFile);
|
|
3836
3920
|
if (this.fileEntries.length === 0) {
|
|
3837
3921
|
const explicitPath = this.sessionFile;
|
|
@@ -4552,7 +4636,7 @@ var init_agent_session_auto_compaction = __esm(() => {
|
|
|
4552
4636
|
});
|
|
4553
4637
|
|
|
4554
4638
|
// src/utils/shell.ts
|
|
4555
|
-
import { existsSync as
|
|
4639
|
+
import { existsSync as existsSync7 } from "node:fs";
|
|
4556
4640
|
import { delimiter } from "node:path";
|
|
4557
4641
|
import { spawn, spawnSync } from "child_process";
|
|
4558
4642
|
function isLegacyWslBashPath(path) {
|
|
@@ -4572,7 +4656,7 @@ function findBashOnPath() {
|
|
|
4572
4656
|
});
|
|
4573
4657
|
if (result.status === 0 && result.stdout) {
|
|
4574
4658
|
const firstMatch = result.stdout.trim().split(/\r?\n/)[0];
|
|
4575
|
-
if (firstMatch &&
|
|
4659
|
+
if (firstMatch && existsSync7(firstMatch)) {
|
|
4576
4660
|
return firstMatch;
|
|
4577
4661
|
}
|
|
4578
4662
|
}
|
|
@@ -4596,7 +4680,7 @@ function findBashOnPath() {
|
|
|
4596
4680
|
}
|
|
4597
4681
|
function getShellConfig(customShellPath) {
|
|
4598
4682
|
if (customShellPath) {
|
|
4599
|
-
if (
|
|
4683
|
+
if (existsSync7(customShellPath)) {
|
|
4600
4684
|
return getBashShellConfig(customShellPath);
|
|
4601
4685
|
}
|
|
4602
4686
|
throw new Error(`Custom shell path not found: ${customShellPath}`);
|
|
@@ -4612,7 +4696,7 @@ function getShellConfig(customShellPath) {
|
|
|
4612
4696
|
paths.push(`${programFilesX86}\\Git\\bin\\bash.exe`);
|
|
4613
4697
|
}
|
|
4614
4698
|
for (const path of paths) {
|
|
4615
|
-
if (
|
|
4699
|
+
if (existsSync7(path)) {
|
|
4616
4700
|
return getBashShellConfig(path);
|
|
4617
4701
|
}
|
|
4618
4702
|
}
|
|
@@ -4629,7 +4713,7 @@ function getShellConfig(customShellPath) {
|
|
|
4629
4713
|
${paths.map((p) => ` ${p}`).join(`
|
|
4630
4714
|
`)}`);
|
|
4631
4715
|
}
|
|
4632
|
-
if (
|
|
4716
|
+
if (existsSync7("/bin/bash")) {
|
|
4633
4717
|
return getBashShellConfig("/bin/bash");
|
|
4634
4718
|
}
|
|
4635
4719
|
const bashOnPath = findBashOnPath();
|
|
@@ -4883,7 +4967,7 @@ var init_windows_directory_security = __esm(() => {
|
|
|
4883
4967
|
import { createHash } from "node:crypto";
|
|
4884
4968
|
import { chmodSync as chmodSync2, lstatSync, mkdirSync as mkdirSync3, realpathSync as realpathSync2, rmSync } from "node:fs";
|
|
4885
4969
|
import { tmpdir, userInfo } from "node:os";
|
|
4886
|
-
import { dirname as
|
|
4970
|
+
import { dirname as dirname5, join as join11, sep as sep2 } from "node:path";
|
|
4887
4971
|
function sanitizeTempPathComponent(value, fallback) {
|
|
4888
4972
|
const collapsed = value.replace(/[^a-zA-Z0-9._-]+/g, "_");
|
|
4889
4973
|
let start = 0;
|
|
@@ -4940,11 +5024,11 @@ function baseTempDirs() {
|
|
|
4940
5024
|
}
|
|
4941
5025
|
function getTempRootDir() {
|
|
4942
5026
|
const app = sanitizeTempPathComponent(APP_NAME, "atomic");
|
|
4943
|
-
return
|
|
5027
|
+
return join11(baseTempDirs().raw, `${app}-${ownerComponent()}`);
|
|
4944
5028
|
}
|
|
4945
5029
|
function resolveSessionTempDirPath(sessionId) {
|
|
4946
5030
|
const id = sessionId ?? activeSessionId ?? `pid-${process.pid}`;
|
|
4947
|
-
return
|
|
5031
|
+
return join11(getTempRootDir(), sanitizeTempPathComponent(id, FALLBACK_SESSION_COMPONENT));
|
|
4948
5032
|
}
|
|
4949
5033
|
function isRealDirectory(path) {
|
|
4950
5034
|
try {
|
|
@@ -5018,7 +5102,7 @@ function canonicalTempChild(dir, base) {
|
|
|
5018
5102
|
for (const candidate of [base.raw, base.canonical]) {
|
|
5019
5103
|
const prefix = `${candidate}${sep2}`;
|
|
5020
5104
|
if (dir.startsWith(prefix)) {
|
|
5021
|
-
return
|
|
5105
|
+
return join11(base.canonical, dir.slice(prefix.length));
|
|
5022
5106
|
}
|
|
5023
5107
|
}
|
|
5024
5108
|
return;
|
|
@@ -5031,13 +5115,13 @@ function ensureTempDir(dir) {
|
|
|
5031
5115
|
const parts = checkedDir.slice(prefix.length).split(sep2).filter((part) => part.length > 0);
|
|
5032
5116
|
let current = base.canonical;
|
|
5033
5117
|
for (const part of parts.slice(0, -1)) {
|
|
5034
|
-
current =
|
|
5118
|
+
current = join11(current, part);
|
|
5035
5119
|
ensureOwnedDirectory(current);
|
|
5036
5120
|
}
|
|
5037
5121
|
ensureLeafDirectory(checkedDir);
|
|
5038
5122
|
} else {
|
|
5039
5123
|
if (!(ensuredDirs.has(dir) && isRealDirectory(dir))) {
|
|
5040
|
-
mkdirSync3(
|
|
5124
|
+
mkdirSync3(dirname5(dir), { recursive: true, mode: SESSION_TEMP_DIR_MODE });
|
|
5041
5125
|
ensureLeafDirectory(dir);
|
|
5042
5126
|
}
|
|
5043
5127
|
}
|
|
@@ -5483,7 +5567,7 @@ var init_truncate = __esm(() => {
|
|
|
5483
5567
|
|
|
5484
5568
|
// src/core/bash-executor.ts
|
|
5485
5569
|
import { randomBytes } from "node:crypto";
|
|
5486
|
-
import { join as
|
|
5570
|
+
import { join as join12 } from "node:path";
|
|
5487
5571
|
async function executeBashWithOperations(command, cwd, operations, options) {
|
|
5488
5572
|
const outputChunks = [];
|
|
5489
5573
|
let outputBytes = 0;
|
|
@@ -5499,7 +5583,7 @@ async function executeBashWithOperations(command, cwd, operations, options) {
|
|
|
5499
5583
|
try {
|
|
5500
5584
|
const dir = ensureSessionTempDir(options?.sessionTempDir);
|
|
5501
5585
|
const id = randomBytes(8).toString("hex");
|
|
5502
|
-
tempFilePath =
|
|
5586
|
+
tempFilePath = join12(dir, `${APP_NAME}-bash-${id}.log`);
|
|
5503
5587
|
tempFile = new PersistedOutputFile(tempFilePath);
|
|
5504
5588
|
} catch {
|
|
5505
5589
|
tempFileUnavailable = true;
|
|
@@ -7308,10 +7392,10 @@ var init_bash_session_environment = __esm(() => {
|
|
|
7308
7392
|
|
|
7309
7393
|
// src/core/tools/output-accumulator.ts
|
|
7310
7394
|
import { randomBytes as randomBytes2 } from "node:crypto";
|
|
7311
|
-
import { join as
|
|
7395
|
+
import { join as join15 } from "node:path";
|
|
7312
7396
|
function defaultTempFilePath(prefix, tempDir) {
|
|
7313
7397
|
const id = randomBytes2(8).toString("hex");
|
|
7314
|
-
return
|
|
7398
|
+
return join15(ensureSessionTempDir(tempDir), `${prefix}-${id}.log`);
|
|
7315
7399
|
}
|
|
7316
7400
|
function byteLength(text) {
|
|
7317
7401
|
return Buffer.byteLength(text, "utf-8");
|
|
@@ -7593,9 +7677,9 @@ var init_search_native = __esm(() => {
|
|
|
7593
7677
|
});
|
|
7594
7678
|
|
|
7595
7679
|
// src/core/tools/resource-selectors.ts
|
|
7596
|
-
import { existsSync as
|
|
7680
|
+
import { existsSync as existsSync10, mkdirSync as mkdirSync4, readFileSync as readFileSync4, realpathSync as realpathSync4, rmSync as rmSync2, writeFileSync as writeFileSync3 } from "node:fs";
|
|
7597
7681
|
import { createRequire as createRequire3 } from "node:module";
|
|
7598
|
-
import { dirname as
|
|
7682
|
+
import { dirname as dirname6, isAbsolute as isAbsolute2, relative as relative2, resolve as resolve3 } from "node:path";
|
|
7599
7683
|
import { deflateRawSync, gunzipSync, gzipSync, inflateRawSync } from "node:zlib";
|
|
7600
7684
|
function toSqliteBindValues(params) {
|
|
7601
7685
|
return params.map((param) => typeof param === "boolean" ? param ? 1 : 0 : param);
|
|
@@ -7633,9 +7717,9 @@ function sqliteDatabase() {
|
|
|
7633
7717
|
}
|
|
7634
7718
|
}
|
|
7635
7719
|
function existingSqliteFile(path3) {
|
|
7636
|
-
if (!
|
|
7720
|
+
if (!existsSync10(path3))
|
|
7637
7721
|
return;
|
|
7638
|
-
return
|
|
7722
|
+
return readFileSync4(path3).subarray(0, 16).toString("binary") === "SQLite format 3\x00";
|
|
7639
7723
|
}
|
|
7640
7724
|
function sqliteSelectorForPath(value, cwd) {
|
|
7641
7725
|
const selector = parseSqliteSelector(value);
|
|
@@ -7749,7 +7833,7 @@ function readZipEntriesFromBuffer(buf, label) {
|
|
|
7749
7833
|
return entries;
|
|
7750
7834
|
}
|
|
7751
7835
|
function readZipEntries(path3) {
|
|
7752
|
-
return readZipEntriesFromBuffer(
|
|
7836
|
+
return readZipEntriesFromBuffer(readFileSync4(path3), path3);
|
|
7753
7837
|
}
|
|
7754
7838
|
function writeZipEntries(path3, entries) {
|
|
7755
7839
|
const locals = [], centrals = [];
|
|
@@ -7788,7 +7872,7 @@ function writeZipEntries(path3, entries) {
|
|
|
7788
7872
|
writeFileSync3(path3, Buffer.concat([...locals, ...centrals, eocd]));
|
|
7789
7873
|
}
|
|
7790
7874
|
function parseTar(path3) {
|
|
7791
|
-
const raw =
|
|
7875
|
+
const raw = readFileSync4(path3);
|
|
7792
7876
|
if (raw.length > MAX_TAR_ARCHIVE_BYTES)
|
|
7793
7877
|
throw new Error(`Archive too large: ${path3}`);
|
|
7794
7878
|
const buf = isGzipTar(path3) ? gunzipSync(raw, { maxOutputLength: MAX_TAR_ARCHIVE_BYTES }) : raw;
|
|
@@ -7860,7 +7944,7 @@ function listArchiveDirectory(names, memberPath) {
|
|
|
7860
7944
|
`);
|
|
7861
7945
|
}
|
|
7862
7946
|
function readZipSelector(path3, memberPath) {
|
|
7863
|
-
const buf =
|
|
7947
|
+
const buf = readFileSync4(path3);
|
|
7864
7948
|
let eocd = -1;
|
|
7865
7949
|
for (let i = buf.length - 22;i >= 0; i--)
|
|
7866
7950
|
if (buf.readUInt32LE(i) === 101010256) {
|
|
@@ -7922,7 +8006,7 @@ function validateArchiveMemberPath(memberPath) {
|
|
|
7922
8006
|
throw new Error(`Invalid archive member path: ${memberPath}`);
|
|
7923
8007
|
}
|
|
7924
8008
|
function writeZipEntrySelective(path3, memberPath, data) {
|
|
7925
|
-
const source =
|
|
8009
|
+
const source = existsSync10(path3) ? readFileSync4(path3) : Buffer.alloc(0);
|
|
7926
8010
|
const locals = [], centrals = [];
|
|
7927
8011
|
let offset = 0;
|
|
7928
8012
|
if (source.length > 0) {
|
|
@@ -7958,7 +8042,7 @@ function writeZipEntrySelective(path3, memberPath, data) {
|
|
|
7958
8042
|
}
|
|
7959
8043
|
const tmp = `${path3}.atomic-entry-${Date.now()}`;
|
|
7960
8044
|
writeZipEntries(tmp, new Map([[memberPath, data]]));
|
|
7961
|
-
const built =
|
|
8045
|
+
const built = readFileSync4(tmp);
|
|
7962
8046
|
rmSync2(tmp, { force: true });
|
|
7963
8047
|
const eocdStart = built.length - 22, localLen = built.readUInt32LE(eocdStart + 16), centralSizeOne = built.readUInt32LE(eocdStart + 12);
|
|
7964
8048
|
const central = Buffer.from(built.subarray(localLen, localLen + centralSizeOne));
|
|
@@ -7976,12 +8060,12 @@ function writeZipEntrySelective(path3, memberPath, data) {
|
|
|
7976
8060
|
}
|
|
7977
8061
|
function writeArchiveSelector(selector, content) {
|
|
7978
8062
|
validateArchiveMemberPath(selector.memberPath);
|
|
7979
|
-
mkdirSync4(
|
|
8063
|
+
mkdirSync4(dirname6(selector.archivePath), { recursive: true });
|
|
7980
8064
|
if (isZipArchive(selector.archivePath)) {
|
|
7981
8065
|
writeZipEntrySelective(selector.archivePath, selector.memberPath, Buffer.from(content));
|
|
7982
8066
|
return;
|
|
7983
8067
|
}
|
|
7984
|
-
const entries =
|
|
8068
|
+
const entries = existsSync10(selector.archivePath) ? parseTar(selector.archivePath) : new Map;
|
|
7985
8069
|
entries.set(selector.memberPath, Buffer.from(content));
|
|
7986
8070
|
writeTar(selector.archivePath, entries);
|
|
7987
8071
|
}
|
|
@@ -8117,8 +8201,8 @@ function isContained(root, candidate) {
|
|
|
8117
8201
|
}
|
|
8118
8202
|
function nearestExistingAncestor(pathValue) {
|
|
8119
8203
|
let current = pathValue;
|
|
8120
|
-
while (!
|
|
8121
|
-
const parent =
|
|
8204
|
+
while (!existsSync10(current)) {
|
|
8205
|
+
const parent = dirname6(current);
|
|
8122
8206
|
if (parent === current)
|
|
8123
8207
|
return current;
|
|
8124
8208
|
current = parent;
|
|
@@ -8143,7 +8227,7 @@ function fallbackInternalPath(value, cwd) {
|
|
|
8143
8227
|
const skill = value.match(/^skill:\/\/([^/]+)(?:\/(.*))?$/);
|
|
8144
8228
|
if (skill) {
|
|
8145
8229
|
const name = skill[1] ?? "", rest = skill[2] || "SKILL.md";
|
|
8146
|
-
return [".agents/skills", "packages/subagents/skills", "packages/workflows/skills"].map((base) => resolveContainedPath(resolveContainedLocalPath(cwd, base, "skill:// resource"), `${name}/${rest}`, "skill:// resource")).find((candidate) =>
|
|
8230
|
+
return [".agents/skills", "packages/subagents/skills", "packages/workflows/skills"].map((base) => resolveContainedPath(resolveContainedLocalPath(cwd, base, "skill:// resource"), `${name}/${rest}`, "skill:// resource")).find((candidate) => existsSync10(candidate));
|
|
8147
8231
|
}
|
|
8148
8232
|
const local = value.match(/^local:\/\/(.+)$/);
|
|
8149
8233
|
if (local)
|
|
@@ -8161,9 +8245,9 @@ async function readInternalSelector(value, cwd, context) {
|
|
|
8161
8245
|
if (Buffer.isBuffer(routed))
|
|
8162
8246
|
return routed.toString("utf8");
|
|
8163
8247
|
const resolved = await resolveViaRouter(value, cwd, context);
|
|
8164
|
-
if (!resolved || !
|
|
8248
|
+
if (!resolved || !existsSync10(resolved))
|
|
8165
8249
|
throw new Error(`Internal resource not found or no session router supports it: ${value}`);
|
|
8166
|
-
return
|
|
8250
|
+
return readFileSync4(resolved, "utf8");
|
|
8167
8251
|
}
|
|
8168
8252
|
async function writeInternalSelector(value, cwd, content, context) {
|
|
8169
8253
|
const router = routerFromContext(context);
|
|
@@ -8174,7 +8258,7 @@ async function writeInternalSelector(value, cwd, content, context) {
|
|
|
8174
8258
|
const resolved = await resolveViaRouter(value, cwd, context);
|
|
8175
8259
|
if (!resolved)
|
|
8176
8260
|
throw new Error(`Unsupported writable internal resource without a session router: ${value}`);
|
|
8177
|
-
mkdirSync4(
|
|
8261
|
+
mkdirSync4(dirname6(resolved), { recursive: true });
|
|
8178
8262
|
writeFileSync3(resolved, content);
|
|
8179
8263
|
}
|
|
8180
8264
|
async function searchInternalSelector(value, cwd, pattern, ignoreCase = false, literal = false, context, contextBefore = 1, contextAfter = 3) {
|
|
@@ -8456,7 +8540,7 @@ function parseLooseJsonObject(content) {
|
|
|
8456
8540
|
function writeSqliteSelector(selector, content) {
|
|
8457
8541
|
if (!selector.table)
|
|
8458
8542
|
throw new Error("SQLite write target must include a table name");
|
|
8459
|
-
if (!
|
|
8543
|
+
if (!existsSync10(selector.databasePath))
|
|
8460
8544
|
throw new Error(`SQLite database does not exist: ${selector.databasePath}`);
|
|
8461
8545
|
if (content.trim() === "") {
|
|
8462
8546
|
if (!selector.rowId)
|
|
@@ -9229,12 +9313,12 @@ var init_agent_session_bash = __esm(() => {
|
|
|
9229
9313
|
});
|
|
9230
9314
|
|
|
9231
9315
|
// src/core/auth-guidance.ts
|
|
9232
|
-
import { join as
|
|
9316
|
+
import { join as join16 } from "node:path";
|
|
9233
9317
|
function getProviderLoginHelp() {
|
|
9234
9318
|
return [
|
|
9235
9319
|
"Use /login to log into a provider via OAuth or API key. See:",
|
|
9236
|
-
` ${
|
|
9237
|
-
` ${
|
|
9320
|
+
` ${join16(getDocsPath(), "providers.md")}`,
|
|
9321
|
+
` ${join16(getDocsPath(), "models.md")}`
|
|
9238
9322
|
].join(`
|
|
9239
9323
|
`);
|
|
9240
9324
|
}
|
|
@@ -10411,10 +10495,10 @@ function getUsageCostBreakdown(entries) {
|
|
|
10411
10495
|
}
|
|
10412
10496
|
|
|
10413
10497
|
// src/core/export-html/template-script.ts
|
|
10414
|
-
import { readFileSync as
|
|
10415
|
-
import { join as
|
|
10498
|
+
import { readFileSync as readFileSync5 } from "fs";
|
|
10499
|
+
import { join as join17 } from "path";
|
|
10416
10500
|
function readExportHtmlTemplateScript(templateDir) {
|
|
10417
|
-
return EXPORT_HTML_TEMPLATE_SCRIPT_CHUNKS.map((fileName) =>
|
|
10501
|
+
return EXPORT_HTML_TEMPLATE_SCRIPT_CHUNKS.map((fileName) => readFileSync5(join17(templateDir, "template-js", fileName), "utf-8")).join("");
|
|
10418
10502
|
}
|
|
10419
10503
|
var EXPORT_HTML_TEMPLATE_SCRIPT_CHUNKS;
|
|
10420
10504
|
var init_template_script = __esm(() => {
|
|
@@ -10433,8 +10517,8 @@ __export(exports_export_html, {
|
|
|
10433
10517
|
exportFromFile: () => exportFromFile,
|
|
10434
10518
|
exportSessionToHtml: () => exportSessionToHtml
|
|
10435
10519
|
});
|
|
10436
|
-
import { existsSync as
|
|
10437
|
-
import { basename as basename2, join as
|
|
10520
|
+
import { existsSync as existsSync11, readFileSync as readFileSync6, writeFileSync as writeFileSync4 } from "fs";
|
|
10521
|
+
import { basename as basename2, join as join18 } from "path";
|
|
10438
10522
|
function parseColor(color) {
|
|
10439
10523
|
const hexMatch = color.match(/^#([0-9a-fA-F]{2})([0-9a-fA-F]{2})([0-9a-fA-F]{2})$/);
|
|
10440
10524
|
if (hexMatch) {
|
|
@@ -10509,11 +10593,11 @@ function generateThemeVars(themeName) {
|
|
|
10509
10593
|
}
|
|
10510
10594
|
function generateHtml(sessionData, themeName) {
|
|
10511
10595
|
const templateDir = getExportTemplateDir();
|
|
10512
|
-
const template =
|
|
10513
|
-
const templateCss =
|
|
10596
|
+
const template = readFileSync6(join18(templateDir, "template.html"), "utf-8");
|
|
10597
|
+
const templateCss = readFileSync6(join18(templateDir, "template.css"), "utf-8");
|
|
10514
10598
|
const templateJs = readExportHtmlTemplateScript(templateDir);
|
|
10515
|
-
const markedJs =
|
|
10516
|
-
const hljsJs =
|
|
10599
|
+
const markedJs = readFileSync6(join18(templateDir, "vendor", "marked.min.js"), "utf-8");
|
|
10600
|
+
const hljsJs = readFileSync6(join18(templateDir, "vendor", "highlight.min.js"), "utf-8");
|
|
10517
10601
|
const themeVars = generateThemeVars(themeName);
|
|
10518
10602
|
const colors = getResolvedThemeColors(themeName);
|
|
10519
10603
|
const themeExport = getThemeExportColors(themeName);
|
|
@@ -10564,7 +10648,7 @@ async function exportSessionToHtml(sm, state, options) {
|
|
|
10564
10648
|
if (!sessionFile) {
|
|
10565
10649
|
throw new Error("Cannot export in-memory session to HTML");
|
|
10566
10650
|
}
|
|
10567
|
-
if (!
|
|
10651
|
+
if (!existsSync11(sessionFile)) {
|
|
10568
10652
|
throw new Error("Nothing to export yet - start a conversation first");
|
|
10569
10653
|
}
|
|
10570
10654
|
const entries = sm.getEntries();
|
|
@@ -10595,7 +10679,7 @@ async function exportSessionToHtml(sm, state, options) {
|
|
|
10595
10679
|
async function exportFromFile(inputPath, options) {
|
|
10596
10680
|
const opts = typeof options === "string" ? { outputPath: options } : options || {};
|
|
10597
10681
|
const resolvedInputPath = resolvePath(inputPath);
|
|
10598
|
-
if (!
|
|
10682
|
+
if (!existsSync11(resolvedInputPath)) {
|
|
10599
10683
|
throw new Error(`File not found: ${resolvedInputPath}`);
|
|
10600
10684
|
}
|
|
10601
10685
|
const sm = SessionManager.open(resolvedInputPath);
|
|
@@ -10897,8 +10981,8 @@ var init_tool_renderer = __esm(() => {
|
|
|
10897
10981
|
});
|
|
10898
10982
|
|
|
10899
10983
|
// src/core/agent-session-export.ts
|
|
10900
|
-
import { existsSync as
|
|
10901
|
-
import { dirname as
|
|
10984
|
+
import { existsSync as existsSync12, mkdirSync as mkdirSync5, writeFileSync as writeFileSync5 } from "node:fs";
|
|
10985
|
+
import { dirname as dirname7 } from "node:path";
|
|
10902
10986
|
function getSessionStats() {
|
|
10903
10987
|
let userMessages = 0;
|
|
10904
10988
|
let assistantMessages = 0;
|
|
@@ -11002,8 +11086,8 @@ async function exportToHtml(outputPath, options = {}) {
|
|
|
11002
11086
|
}
|
|
11003
11087
|
function exportToJsonl(outputPath) {
|
|
11004
11088
|
const filePath = resolvePath(outputPath ?? `session-${new Date().toISOString().replace(/[:.]/g, "-")}.jsonl`, process.cwd());
|
|
11005
|
-
const dir =
|
|
11006
|
-
if (!
|
|
11089
|
+
const dir = dirname7(filePath);
|
|
11090
|
+
if (!existsSync12(dir)) {
|
|
11007
11091
|
mkdirSync5(dir, { recursive: true });
|
|
11008
11092
|
}
|
|
11009
11093
|
const header = {
|
|
@@ -11087,8 +11171,8 @@ var init_loader_runtime = __esm(() => {
|
|
|
11087
11171
|
});
|
|
11088
11172
|
|
|
11089
11173
|
// src/core/tools/artifacts.ts
|
|
11090
|
-
import { existsSync as
|
|
11091
|
-
import { join as
|
|
11174
|
+
import { existsSync as existsSync13, mkdirSync as mkdirSync6, readdirSync as readdirSync3, writeFileSync as writeFileSync6 } from "node:fs";
|
|
11175
|
+
import { join as join19 } from "node:path";
|
|
11092
11176
|
|
|
11093
11177
|
class ArtifactManager {
|
|
11094
11178
|
#nextId = 0;
|
|
@@ -11105,7 +11189,7 @@ class ArtifactManager {
|
|
|
11105
11189
|
return;
|
|
11106
11190
|
this.#initialized = true;
|
|
11107
11191
|
let max = -1;
|
|
11108
|
-
if (
|
|
11192
|
+
if (existsSync13(this.#dir)) {
|
|
11109
11193
|
for (const name of readdirSync3(this.#dir)) {
|
|
11110
11194
|
const match = name.match(/^(\d+)\..*\.log$/);
|
|
11111
11195
|
if (match) {
|
|
@@ -11120,30 +11204,30 @@ class ArtifactManager {
|
|
|
11120
11204
|
allocate(toolType) {
|
|
11121
11205
|
this.#init();
|
|
11122
11206
|
const id = String(this.#nextId++);
|
|
11123
|
-
const path3 =
|
|
11207
|
+
const path3 = join19(this.#dir, `${id}.${toolType}.log`);
|
|
11124
11208
|
return { path: path3, id };
|
|
11125
11209
|
}
|
|
11126
11210
|
save(content, toolType) {
|
|
11127
11211
|
this.#init();
|
|
11128
11212
|
const { path: path3, id } = this.allocate(toolType);
|
|
11129
|
-
if (!
|
|
11213
|
+
if (!existsSync13(this.#dir))
|
|
11130
11214
|
mkdirSync6(this.#dir, { recursive: true });
|
|
11131
11215
|
writeFileSync6(path3, content, "utf8");
|
|
11132
11216
|
return id;
|
|
11133
11217
|
}
|
|
11134
11218
|
resolve(id) {
|
|
11135
11219
|
this.#init();
|
|
11136
|
-
if (!
|
|
11220
|
+
if (!existsSync13(this.#dir))
|
|
11137
11221
|
return;
|
|
11138
11222
|
const prefix = `${id}.`;
|
|
11139
11223
|
for (const name of readdirSync3(this.#dir))
|
|
11140
11224
|
if (name.startsWith(prefix) && name.endsWith(".log"))
|
|
11141
|
-
return
|
|
11225
|
+
return join19(this.#dir, name);
|
|
11142
11226
|
return;
|
|
11143
11227
|
}
|
|
11144
11228
|
list() {
|
|
11145
11229
|
this.#init();
|
|
11146
|
-
if (!
|
|
11230
|
+
if (!existsSync13(this.#dir))
|
|
11147
11231
|
return [];
|
|
11148
11232
|
const ids = [];
|
|
11149
11233
|
for (const name of readdirSync3(this.#dir)) {
|
|
@@ -11168,7 +11252,7 @@ var init_artifacts = __esm(() => {
|
|
|
11168
11252
|
});
|
|
11169
11253
|
|
|
11170
11254
|
// src/core/tools/artifact-protocol.ts
|
|
11171
|
-
import { existsSync as
|
|
11255
|
+
import { existsSync as existsSync14, readFileSync as readFileSync7 } from "node:fs";
|
|
11172
11256
|
function registerArtifactDir(dir) {
|
|
11173
11257
|
activeArtifactDirs.add(dir);
|
|
11174
11258
|
}
|
|
@@ -11213,9 +11297,9 @@ function createArtifactRouter(getPinnedDirs) {
|
|
|
11213
11297
|
if (!/^artifact:\/\//i.test(url))
|
|
11214
11298
|
return;
|
|
11215
11299
|
const path3 = resolveArtifactUrl(url, getPinnedDirs());
|
|
11216
|
-
if (!path3 || !
|
|
11300
|
+
if (!path3 || !existsSync14(path3))
|
|
11217
11301
|
throw new Error(`Artifact not found: ${url}`);
|
|
11218
|
-
return
|
|
11302
|
+
return readFileSync7(path3, "utf8");
|
|
11219
11303
|
}
|
|
11220
11304
|
};
|
|
11221
11305
|
}
|
|
@@ -11226,7 +11310,7 @@ var init_artifact_protocol = __esm(() => {
|
|
|
11226
11310
|
});
|
|
11227
11311
|
|
|
11228
11312
|
// src/core/extensions/runner-context.ts
|
|
11229
|
-
import { join as
|
|
11313
|
+
import { join as join20 } from "node:path";
|
|
11230
11314
|
function deepFrozenCopy(value) {
|
|
11231
11315
|
if (Array.isArray(value))
|
|
11232
11316
|
return Object.freeze(value.map(deepFrozenCopy));
|
|
@@ -11286,7 +11370,7 @@ function createExtensionContext(source) {
|
|
|
11286
11370
|
const sessionDir = source.getSessionManager().getSessionDir();
|
|
11287
11371
|
if (!sessionDir)
|
|
11288
11372
|
return;
|
|
11289
|
-
const artifactsDir =
|
|
11373
|
+
const artifactsDir = join20(sessionDir, "artifacts");
|
|
11290
11374
|
registerArtifactDir(artifactsDir);
|
|
11291
11375
|
return createArtifactRouter(() => [artifactsDir]);
|
|
11292
11376
|
},
|
|
@@ -12199,7 +12283,7 @@ var init_runner = __esm(() => {
|
|
|
12199
12283
|
|
|
12200
12284
|
// src/core/skill-catalog.ts
|
|
12201
12285
|
import { createHash as createHash2 } from "node:crypto";
|
|
12202
|
-
import { basename as basename3, dirname as
|
|
12286
|
+
import { basename as basename3, dirname as dirname8, sep as sep3 } from "node:path";
|
|
12203
12287
|
function candidateId(skill) {
|
|
12204
12288
|
return `skill_${createHash2("sha256").update(canonicalizePath(skill.filePath)).digest("hex").slice(0, 20)}`;
|
|
12205
12289
|
}
|
|
@@ -12243,7 +12327,7 @@ function sourceLabel(skill) {
|
|
|
12243
12327
|
}
|
|
12244
12328
|
const pathParts = canonicalizePath(skill.filePath).split(sep3).filter(Boolean);
|
|
12245
12329
|
const configPart = [...pathParts].reverse().find((part) => part === ".atomic" || part === ".pi" || part === ".agents");
|
|
12246
|
-
return configPart ? configPart.slice(1) : readableToken(basename3(skill.sourceInfo.baseDir ??
|
|
12330
|
+
return configPart ? configPart.slice(1) : readableToken(basename3(skill.sourceInfo.baseDir ?? dirname8(skill.filePath)));
|
|
12247
12331
|
}
|
|
12248
12332
|
function uniquePathLabels(candidates) {
|
|
12249
12333
|
const labels = new Map(candidates.map((candidate) => [candidate.id, sourceLabel(candidate.skill)]));
|
|
@@ -12257,7 +12341,7 @@ function uniquePathLabels(candidates) {
|
|
|
12257
12341
|
for (const [label, matching] of byLabel) {
|
|
12258
12342
|
if (matching.length === 1)
|
|
12259
12343
|
continue;
|
|
12260
|
-
const pathParts = matching.map((candidate) => canonicalizePath(
|
|
12344
|
+
const pathParts = matching.map((candidate) => canonicalizePath(dirname8(candidate.skill.filePath)).split(sep3).filter(Boolean));
|
|
12261
12345
|
for (let depth = 1;depth <= Math.max(...pathParts.map((parts) => parts.length)); depth++) {
|
|
12262
12346
|
const suffixes = pathParts.map((parts) => parts.slice(-depth).join("/"));
|
|
12263
12347
|
if (new Set(suffixes).size !== suffixes.length)
|
|
@@ -12430,7 +12514,7 @@ var init_skill_catalog = __esm(() => {
|
|
|
12430
12514
|
});
|
|
12431
12515
|
|
|
12432
12516
|
// src/core/agent-session-extension-bindings.ts
|
|
12433
|
-
import { basename as basename4, dirname as
|
|
12517
|
+
import { basename as basename4, dirname as dirname9 } from "node:path";
|
|
12434
12518
|
import { resetApiProviders } from "@bastani/pi-ai/compat";
|
|
12435
12519
|
async function bindExtensions(bindings) {
|
|
12436
12520
|
if (bindings.uiContext !== undefined) {
|
|
@@ -12478,7 +12562,7 @@ function buildExtensionResourcePaths(entries) {
|
|
|
12478
12562
|
const extension = extensions.find((candidate) => candidate.path === entry.extensionPath || candidate.resolvedPath === entry.extensionPath || candidate.sourceInfo.path === entry.extensionPath);
|
|
12479
12563
|
const sourceInfo = extension?.sourceInfo;
|
|
12480
12564
|
const source = sourceInfo?.source ?? this.getExtensionSourceLabel(entry.extensionPath);
|
|
12481
|
-
const baseDir = sourceInfo?.baseDir ?? (entry.extensionPath.startsWith("<") ? undefined :
|
|
12565
|
+
const baseDir = sourceInfo?.baseDir ?? (entry.extensionPath.startsWith("<") ? undefined : dirname9(entry.extensionPath));
|
|
12482
12566
|
return {
|
|
12483
12567
|
path: entry.path,
|
|
12484
12568
|
metadata: {
|
|
@@ -13575,7 +13659,7 @@ var init_frontmatter = () => {};
|
|
|
13575
13659
|
|
|
13576
13660
|
// src/utils/changelog.ts
|
|
13577
13661
|
import path3 from "node:path";
|
|
13578
|
-
import { existsSync as
|
|
13662
|
+
import { existsSync as existsSync15, readFileSync as readFileSync8 } from "fs";
|
|
13579
13663
|
function parsedVersionFromMatch(match) {
|
|
13580
13664
|
return {
|
|
13581
13665
|
version: match[1],
|
|
@@ -13669,11 +13753,11 @@ function normalizeChangelogLinks(markdown, version) {
|
|
|
13669
13753
|
});
|
|
13670
13754
|
}
|
|
13671
13755
|
function parseChangelog(changelogPath) {
|
|
13672
|
-
if (!
|
|
13756
|
+
if (!existsSync15(changelogPath)) {
|
|
13673
13757
|
return [];
|
|
13674
13758
|
}
|
|
13675
13759
|
try {
|
|
13676
|
-
const content =
|
|
13760
|
+
const content = readFileSync8(changelogPath, "utf-8");
|
|
13677
13761
|
const lines = content.split(`
|
|
13678
13762
|
`);
|
|
13679
13763
|
const entries = [];
|
|
@@ -14172,7 +14256,7 @@ var init_prompt_templates = __esm(() => {
|
|
|
14172
14256
|
});
|
|
14173
14257
|
|
|
14174
14258
|
// src/core/agent-session-prompt.ts
|
|
14175
|
-
import { readFileSync as
|
|
14259
|
+
import { readFileSync as readFileSync9 } from "node:fs";
|
|
14176
14260
|
async function tryExecuteSessionSlashCommand(session, text) {
|
|
14177
14261
|
if (!text.startsWith("/"))
|
|
14178
14262
|
return false;
|
|
@@ -14444,7 +14528,7 @@ function _expandSkillCommand(text) {
|
|
|
14444
14528
|
}
|
|
14445
14529
|
const { skill, id } = resolution.candidate;
|
|
14446
14530
|
try {
|
|
14447
|
-
const content =
|
|
14531
|
+
const content = readFileSync9(skill.filePath, "utf-8");
|
|
14448
14532
|
const body = stripFrontmatter(content).trim();
|
|
14449
14533
|
const skillBlock = `<skill name="${selector}" location="${skill.filePath}" candidate="${id}">
|
|
14450
14534
|
References are relative to ${skill.baseDir}.
|
|
@@ -16538,7 +16622,7 @@ function assertToolPairingInvariant(messages) {
|
|
|
16538
16622
|
import { Buffer as Buffer3 } from "node:buffer";
|
|
16539
16623
|
import { constants as constants2 } from "node:fs";
|
|
16540
16624
|
import { chmod, lstat, mkdir, open } from "node:fs/promises";
|
|
16541
|
-
import { join as
|
|
16625
|
+
import { join as join22 } from "node:path";
|
|
16542
16626
|
function getPersistenceThreshold(declaredMaxResultSizeChars) {
|
|
16543
16627
|
if (declaredMaxResultSizeChars === undefined) {
|
|
16544
16628
|
return DEFAULT_MAX_RESULT_SIZE_CHARS;
|
|
@@ -16627,14 +16711,14 @@ function sanitizePathComponent(value, fallback) {
|
|
|
16627
16711
|
}
|
|
16628
16712
|
async function ensureToolResultsDir(input) {
|
|
16629
16713
|
if (input.sessionDir?.trim()) {
|
|
16630
|
-
const dir =
|
|
16714
|
+
const dir = join22(input.sessionDir, TOOL_RESULTS_SUBDIR);
|
|
16631
16715
|
await mkdir(dir, { recursive: true, mode: SESSION_TEMP_DIR_MODE });
|
|
16632
16716
|
if (process.platform !== "win32") {
|
|
16633
16717
|
await chmod(dir, SESSION_TEMP_DIR_MODE);
|
|
16634
16718
|
}
|
|
16635
16719
|
return dir;
|
|
16636
16720
|
}
|
|
16637
|
-
return ensureTempDir(
|
|
16721
|
+
return ensureTempDir(join22(resolveSessionTempDirPath(input.sessionId), TOOL_RESULTS_SUBDIR));
|
|
16638
16722
|
}
|
|
16639
16723
|
function isOwnedByCurrentUser(uid) {
|
|
16640
16724
|
const currentUid = typeof process.getuid === "function" ? process.getuid() : undefined;
|
|
@@ -16700,7 +16784,7 @@ async function persistToolOutput(input) {
|
|
|
16700
16784
|
} catch {
|
|
16701
16785
|
return;
|
|
16702
16786
|
}
|
|
16703
|
-
const filepath =
|
|
16787
|
+
const filepath = join22(dir, `${sanitizePathComponent(input.toolCallId, "tool-result")}.txt`);
|
|
16704
16788
|
try {
|
|
16705
16789
|
const handle = await open(filepath, "wx", SESSION_TEMP_FILE_MODE);
|
|
16706
16790
|
try {
|
|
@@ -16952,7 +17036,7 @@ var init_loader_core = __esm(() => {
|
|
|
16952
17036
|
});
|
|
16953
17037
|
|
|
16954
17038
|
// src/core/package-manager-manifest.ts
|
|
16955
|
-
import { join as
|
|
17039
|
+
import { join as join23 } from "node:path";
|
|
16956
17040
|
function isRecord(value) {
|
|
16957
17041
|
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
16958
17042
|
}
|
|
@@ -16975,9 +17059,9 @@ function getManifestFromPackageJson(pkg2) {
|
|
|
16975
17059
|
}
|
|
16976
17060
|
function conventionDirsForResource(packageRoot, resourceType) {
|
|
16977
17061
|
if (resourceType === "workflows") {
|
|
16978
|
-
return [
|
|
17062
|
+
return [join23(packageRoot, "workflows"), join23(packageRoot, "workflow")];
|
|
16979
17063
|
}
|
|
16980
|
-
return [
|
|
17064
|
+
return [join23(packageRoot, resourceType)];
|
|
16981
17065
|
}
|
|
16982
17066
|
function manifestEntriesForResource(manifest, resourceType) {
|
|
16983
17067
|
if (!manifest)
|
|
@@ -17163,14 +17247,14 @@ var init_model_registry = __esm(() => {
|
|
|
17163
17247
|
});
|
|
17164
17248
|
|
|
17165
17249
|
// src/core/tools/ask-user-question/config.ts
|
|
17166
|
-
import { existsSync as
|
|
17250
|
+
import { existsSync as existsSync16, readFileSync as readFileSync10 } from "node:fs";
|
|
17167
17251
|
import { homedir as homedir4 } from "node:os";
|
|
17168
|
-
import { join as
|
|
17252
|
+
import { join as join24 } from "node:path";
|
|
17169
17253
|
function loadConfig() {
|
|
17170
|
-
if (!
|
|
17254
|
+
if (!existsSync16(CONFIG_PATH))
|
|
17171
17255
|
return {};
|
|
17172
17256
|
try {
|
|
17173
|
-
const parsed = JSON.parse(
|
|
17257
|
+
const parsed = JSON.parse(readFileSync10(CONFIG_PATH, "utf-8"));
|
|
17174
17258
|
if (parsed === null || typeof parsed !== "object")
|
|
17175
17259
|
return {};
|
|
17176
17260
|
return parsed;
|
|
@@ -17193,8 +17277,8 @@ function validateGuidanceFields(fields) {
|
|
|
17193
17277
|
}
|
|
17194
17278
|
var CONFIG_DIR, CONFIG_PATH;
|
|
17195
17279
|
var init_config2 = __esm(() => {
|
|
17196
|
-
CONFIG_DIR =
|
|
17197
|
-
CONFIG_PATH =
|
|
17280
|
+
CONFIG_DIR = join24(homedir4(), ".config", "rpiv-ask-user-question");
|
|
17281
|
+
CONFIG_PATH = join24(CONFIG_DIR, "config.json");
|
|
17198
17282
|
});
|
|
17199
17283
|
|
|
17200
17284
|
// src/core/tools/ask-user-question/view/component-binding.ts
|
|
@@ -19698,7 +19782,7 @@ var init_chat_message_renderer = __esm(() => {
|
|
|
19698
19782
|
|
|
19699
19783
|
// src/utils/clipboard-native.ts
|
|
19700
19784
|
import { createRequire as createRequire6 } from "module";
|
|
19701
|
-
import { dirname as
|
|
19785
|
+
import { dirname as dirname11, join as join25 } from "path";
|
|
19702
19786
|
import { pathToFileURL as pathToFileURL3 } from "url";
|
|
19703
19787
|
function loadClipboardNative(requires = [moduleRequire, executableDirRequire]) {
|
|
19704
19788
|
for (const requireClipboard of requires) {
|
|
@@ -19711,7 +19795,7 @@ function loadClipboardNative(requires = [moduleRequire, executableDirRequire]) {
|
|
|
19711
19795
|
var moduleRequire, executableDirRequire, hasDisplay, clipboard;
|
|
19712
19796
|
var init_clipboard_native = __esm(() => {
|
|
19713
19797
|
moduleRequire = createRequire6(import.meta.url);
|
|
19714
|
-
executableDirRequire = createRequire6(pathToFileURL3(
|
|
19798
|
+
executableDirRequire = createRequire6(pathToFileURL3(join25(dirname11(process.execPath), "package.json")).href);
|
|
19715
19799
|
hasDisplay = process.platform !== "linux" || Boolean(process.env.DISPLAY || process.env.WAYLAND_DISPLAY);
|
|
19716
19800
|
clipboard = !process.env.TERMUX_VERSION && hasDisplay ? loadClipboardNative() : null;
|
|
19717
19801
|
});
|
|
@@ -19719,9 +19803,9 @@ var init_clipboard_native = __esm(() => {
|
|
|
19719
19803
|
// src/utils/clipboard-image.ts
|
|
19720
19804
|
import { spawnSync as spawnSync3 } from "child_process";
|
|
19721
19805
|
import { randomUUID as randomUUID2 } from "crypto";
|
|
19722
|
-
import { readFileSync as
|
|
19806
|
+
import { readFileSync as readFileSync11, unlinkSync as unlinkSync2 } from "fs";
|
|
19723
19807
|
import { tmpdir as tmpdir2 } from "os";
|
|
19724
|
-
import { join as
|
|
19808
|
+
import { join as join26 } from "path";
|
|
19725
19809
|
function isWaylandSession(env = process.env) {
|
|
19726
19810
|
return Boolean(env.WAYLAND_DISPLAY) || env.XDG_SESSION_TYPE === "wayland";
|
|
19727
19811
|
}
|
|
@@ -19811,14 +19895,14 @@ function isWSL(env = process.env) {
|
|
|
19811
19895
|
return true;
|
|
19812
19896
|
}
|
|
19813
19897
|
try {
|
|
19814
|
-
const release =
|
|
19898
|
+
const release = readFileSync11("/proc/version", "utf-8");
|
|
19815
19899
|
return /microsoft|wsl/i.test(release);
|
|
19816
19900
|
} catch {
|
|
19817
19901
|
return false;
|
|
19818
19902
|
}
|
|
19819
19903
|
}
|
|
19820
19904
|
function readClipboardImageViaPowerShell() {
|
|
19821
|
-
const tmpFile =
|
|
19905
|
+
const tmpFile = join26(tmpdir2(), `pi-wsl-clip-${randomUUID2()}.png`);
|
|
19822
19906
|
try {
|
|
19823
19907
|
const winPathResult = runCommand("wslpath", ["-w", tmpFile], { timeoutMs: DEFAULT_LIST_TIMEOUT_MS });
|
|
19824
19908
|
if (!winPathResult.ok) {
|
|
@@ -19846,7 +19930,7 @@ function readClipboardImageViaPowerShell() {
|
|
|
19846
19930
|
if (output !== "ok") {
|
|
19847
19931
|
return null;
|
|
19848
19932
|
}
|
|
19849
|
-
const bytes =
|
|
19933
|
+
const bytes = readFileSync11(tmpFile);
|
|
19850
19934
|
if (bytes.length === 0) {
|
|
19851
19935
|
return null;
|
|
19852
19936
|
}
|
|
@@ -20059,9 +20143,9 @@ var init_clipboard = __esm(() => {
|
|
|
20059
20143
|
|
|
20060
20144
|
// src/modes/interactive/external-editor.ts
|
|
20061
20145
|
import { spawn as spawn4 } from "node:child_process";
|
|
20062
|
-
import { mkdtempSync, readFileSync as
|
|
20146
|
+
import { mkdtempSync, readFileSync as readFileSync12, rmSync as rmSync3, writeFileSync as writeFileSync7 } from "node:fs";
|
|
20063
20147
|
import { tmpdir as tmpdir3 } from "node:os";
|
|
20064
|
-
import { join as
|
|
20148
|
+
import { join as join27 } from "node:path";
|
|
20065
20149
|
function parseEditorCommand(command) {
|
|
20066
20150
|
const args = [];
|
|
20067
20151
|
let current = "";
|
|
@@ -20126,8 +20210,8 @@ function resolveExternalEditorCommand(configuredCommand, environment = process.e
|
|
|
20126
20210
|
return platform2 === "win32" ? "notepad" : "nano";
|
|
20127
20211
|
}
|
|
20128
20212
|
async function editInExternalEditor(request) {
|
|
20129
|
-
const directory = mkdtempSync(
|
|
20130
|
-
const filePath =
|
|
20213
|
+
const directory = mkdtempSync(join27(tmpdir3(), `${APP_NAME}-editor-`));
|
|
20214
|
+
const filePath = join27(directory, "prompt.md");
|
|
20131
20215
|
try {
|
|
20132
20216
|
writeFileSync7(filePath, request.content, {
|
|
20133
20217
|
encoding: "utf-8",
|
|
@@ -20151,7 +20235,7 @@ ${APP_NAME} will resume when the editor exits.
|
|
|
20151
20235
|
return { status: "failed" };
|
|
20152
20236
|
return {
|
|
20153
20237
|
status: "complete",
|
|
20154
|
-
content:
|
|
20238
|
+
content: readFileSync12(filePath, "utf-8").replace(/\n$/, "")
|
|
20155
20239
|
};
|
|
20156
20240
|
} finally {
|
|
20157
20241
|
try {
|
|
@@ -23205,8 +23289,8 @@ import {
|
|
|
23205
23289
|
TUI_KEYBINDINGS,
|
|
23206
23290
|
KeybindingsManager as TuiKeybindingsManager
|
|
23207
23291
|
} from "@earendil-works/pi-tui";
|
|
23208
|
-
import { existsSync as
|
|
23209
|
-
import { join as
|
|
23292
|
+
import { existsSync as existsSync17, readFileSync as readFileSync13 } from "fs";
|
|
23293
|
+
import { join as join29 } from "path";
|
|
23210
23294
|
function isRecord2(value) {
|
|
23211
23295
|
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
23212
23296
|
}
|
|
@@ -23258,10 +23342,10 @@ function orderKeybindingsConfig(config) {
|
|
|
23258
23342
|
return ordered;
|
|
23259
23343
|
}
|
|
23260
23344
|
function loadRawConfig(path7) {
|
|
23261
|
-
if (!
|
|
23345
|
+
if (!existsSync17(path7))
|
|
23262
23346
|
return;
|
|
23263
23347
|
try {
|
|
23264
|
-
const parsed = JSON.parse(
|
|
23348
|
+
const parsed = JSON.parse(readFileSync13(path7, "utf-8"));
|
|
23265
23349
|
return isRecord2(parsed) ? parsed : undefined;
|
|
23266
23350
|
} catch {
|
|
23267
23351
|
return;
|
|
@@ -23482,7 +23566,7 @@ var init_keybindings = __esm(() => {
|
|
|
23482
23566
|
this.configPath = configPath;
|
|
23483
23567
|
}
|
|
23484
23568
|
static create(agentDir = getAgentDir()) {
|
|
23485
|
-
const configPath =
|
|
23569
|
+
const configPath = join29(agentDir, "keybindings.json");
|
|
23486
23570
|
const userBindings = KeybindingsManager.loadFromFile(configPath);
|
|
23487
23571
|
return new KeybindingsManager(userBindings, configPath);
|
|
23488
23572
|
}
|
|
@@ -23505,7 +23589,7 @@ var init_keybindings = __esm(() => {
|
|
|
23505
23589
|
|
|
23506
23590
|
// src/modes/interactive/components/session-selector-delete.ts
|
|
23507
23591
|
import { spawnSync as spawnSync4 } from "node:child_process";
|
|
23508
|
-
import { existsSync as
|
|
23592
|
+
import { existsSync as existsSync18 } from "node:fs";
|
|
23509
23593
|
import { unlink } from "node:fs/promises";
|
|
23510
23594
|
async function deleteSessionFile(sessionPath) {
|
|
23511
23595
|
const trashArgs = sessionPath.startsWith("-") ? ["--", sessionPath] : [sessionPath];
|
|
@@ -23524,7 +23608,7 @@ async function deleteSessionFile(sessionPath) {
|
|
|
23524
23608
|
return null;
|
|
23525
23609
|
return `trash: ${parts.join(" · ").slice(0, 200)}`;
|
|
23526
23610
|
};
|
|
23527
|
-
if (trashResult.status === 0 || !
|
|
23611
|
+
if (trashResult.status === 0 || !existsSync18(sessionPath)) {
|
|
23528
23612
|
return { ok: true, method: "trash" };
|
|
23529
23613
|
}
|
|
23530
23614
|
try {
|
|
@@ -26401,8 +26485,8 @@ function parseJsonFileContent(input) {
|
|
|
26401
26485
|
}
|
|
26402
26486
|
|
|
26403
26487
|
// src/core/trust-manager.ts
|
|
26404
|
-
import { existsSync as
|
|
26405
|
-
import { dirname as
|
|
26488
|
+
import { existsSync as existsSync19, mkdirSync as mkdirSync7, readFileSync as readFileSync14, writeFileSync as writeFileSync9 } from "node:fs";
|
|
26489
|
+
import { dirname as dirname12, join as join30 } from "node:path";
|
|
26406
26490
|
import lockfile from "proper-lockfile";
|
|
26407
26491
|
function normalizeCwd(cwd) {
|
|
26408
26492
|
return canonicalizePath(resolvePath(cwd));
|
|
@@ -26414,7 +26498,7 @@ function findNearestTrustEntry(data, cwd) {
|
|
|
26414
26498
|
if (value === true || value === false) {
|
|
26415
26499
|
return { path: currentDir, decision: value };
|
|
26416
26500
|
}
|
|
26417
|
-
const parentDir =
|
|
26501
|
+
const parentDir = dirname12(currentDir);
|
|
26418
26502
|
if (parentDir === currentDir) {
|
|
26419
26503
|
return null;
|
|
26420
26504
|
}
|
|
@@ -26426,7 +26510,7 @@ function getProjectTrustPath(cwd) {
|
|
|
26426
26510
|
}
|
|
26427
26511
|
function getProjectTrustParentPath(cwd) {
|
|
26428
26512
|
const trustPath = getProjectTrustPath(cwd);
|
|
26429
|
-
const parentDir =
|
|
26513
|
+
const parentDir = dirname12(trustPath);
|
|
26430
26514
|
return parentDir === trustPath ? undefined : parentDir;
|
|
26431
26515
|
}
|
|
26432
26516
|
function getProjectTrustOptions(cwd, options) {
|
|
@@ -26461,12 +26545,12 @@ function getProjectTrustOptions(cwd, options) {
|
|
|
26461
26545
|
return trustOptions;
|
|
26462
26546
|
}
|
|
26463
26547
|
function readTrustFile(path7) {
|
|
26464
|
-
if (!
|
|
26548
|
+
if (!existsSync19(path7)) {
|
|
26465
26549
|
return {};
|
|
26466
26550
|
}
|
|
26467
26551
|
let parsed;
|
|
26468
26552
|
try {
|
|
26469
|
-
parsed = parseJsonFileContent(
|
|
26553
|
+
parsed = parseJsonFileContent(readFileSync14(path7, "utf-8"));
|
|
26470
26554
|
} catch (error) {
|
|
26471
26555
|
const message = error instanceof Error ? error.message : String(error);
|
|
26472
26556
|
throw new Error(`Failed to read trust store ${path7}: ${message}`);
|
|
@@ -26491,12 +26575,12 @@ function writeTrustFile(path7, data) {
|
|
|
26491
26575
|
sorted[key] = value;
|
|
26492
26576
|
}
|
|
26493
26577
|
}
|
|
26494
|
-
mkdirSync7(
|
|
26578
|
+
mkdirSync7(dirname12(path7), { recursive: true });
|
|
26495
26579
|
writeFileSync9(path7, `${JSON.stringify(sorted, null, 2)}
|
|
26496
26580
|
`, "utf-8");
|
|
26497
26581
|
}
|
|
26498
26582
|
function acquireTrustLockSync(path7) {
|
|
26499
|
-
const trustDir =
|
|
26583
|
+
const trustDir = dirname12(path7);
|
|
26500
26584
|
mkdirSync7(trustDir, { recursive: true });
|
|
26501
26585
|
const maxAttempts = 10;
|
|
26502
26586
|
const delayMs = 20;
|
|
@@ -26530,22 +26614,22 @@ function withTrustFileLock(path7, fn) {
|
|
|
26530
26614
|
function hasTrustRequiringConfigResources(cwd) {
|
|
26531
26615
|
const projectCwd = canonicalizePath(resolvePath(cwd));
|
|
26532
26616
|
return CONFIG_DIR_NAMES.some((configDirName) => {
|
|
26533
|
-
const configDir =
|
|
26534
|
-
return TRUST_REQUIRING_PROJECT_CONFIG_RESOURCES.some((entry) =>
|
|
26617
|
+
const configDir = join30(projectCwd, configDirName);
|
|
26618
|
+
return TRUST_REQUIRING_PROJECT_CONFIG_RESOURCES.some((entry) => existsSync19(join30(configDir, entry)));
|
|
26535
26619
|
});
|
|
26536
26620
|
}
|
|
26537
26621
|
function hasTrustRequiringProjectResources(cwd) {
|
|
26538
26622
|
if (hasTrustRequiringConfigResources(cwd)) {
|
|
26539
26623
|
return true;
|
|
26540
26624
|
}
|
|
26541
|
-
const userGlobalSkillsDir = canonicalizePath(resolvePath(
|
|
26625
|
+
const userGlobalSkillsDir = canonicalizePath(resolvePath(join30(getHomeDir(), ".agents", "skills")));
|
|
26542
26626
|
let currentDir = canonicalizePath(resolvePath(cwd));
|
|
26543
26627
|
while (true) {
|
|
26544
|
-
const skillsDir = canonicalizePath(resolvePath(
|
|
26545
|
-
if (skillsDir !== userGlobalSkillsDir &&
|
|
26628
|
+
const skillsDir = canonicalizePath(resolvePath(join30(currentDir, ".agents", "skills")));
|
|
26629
|
+
if (skillsDir !== userGlobalSkillsDir && existsSync19(skillsDir)) {
|
|
26546
26630
|
return true;
|
|
26547
26631
|
}
|
|
26548
|
-
const parentDir =
|
|
26632
|
+
const parentDir = dirname12(currentDir);
|
|
26549
26633
|
if (parentDir === currentDir) {
|
|
26550
26634
|
return false;
|
|
26551
26635
|
}
|
|
@@ -26556,7 +26640,7 @@ function hasTrustRequiringProjectResources(cwd) {
|
|
|
26556
26640
|
class ProjectTrustStore {
|
|
26557
26641
|
trustPath;
|
|
26558
26642
|
constructor(agentDir) {
|
|
26559
|
-
this.trustPath =
|
|
26643
|
+
this.trustPath = join30(resolvePath(agentDir), "trust.json");
|
|
26560
26644
|
}
|
|
26561
26645
|
get(cwd) {
|
|
26562
26646
|
return this.getEntry(cwd)?.decision ?? null;
|
|
@@ -31325,7 +31409,7 @@ var init_hashline = __esm(() => {
|
|
|
31325
31409
|
});
|
|
31326
31410
|
|
|
31327
31411
|
// src/core/tools/notebook.ts
|
|
31328
|
-
import { existsSync as
|
|
31412
|
+
import { existsSync as existsSync20, readFileSync as readFileSync15 } from "node:fs";
|
|
31329
31413
|
function isNotebookPath(absolutePath) {
|
|
31330
31414
|
return /\.ipynb$/i.test(absolutePath);
|
|
31331
31415
|
}
|
|
@@ -31427,11 +31511,11 @@ function applyNotebookEditableText(notebook, text, displayPath) {
|
|
|
31427
31511
|
return next;
|
|
31428
31512
|
}
|
|
31429
31513
|
function readEditableNotebookText(absolutePath, displayPath) {
|
|
31430
|
-
const notebook =
|
|
31514
|
+
const notebook = existsSync20(absolutePath) ? parseNotebookSafe(readFileSync15(absolutePath, "utf8"), displayPath) : emptyNotebook();
|
|
31431
31515
|
return notebookToEditableText(notebook);
|
|
31432
31516
|
}
|
|
31433
31517
|
function serializeEditedNotebookText(absolutePath, displayPath, text) {
|
|
31434
|
-
const notebook =
|
|
31518
|
+
const notebook = existsSync20(absolutePath) ? parseNotebookSafe(readFileSync15(absolutePath, "utf8"), displayPath) : emptyNotebook();
|
|
31435
31519
|
const next = applyNotebookEditableText(notebook, text, displayPath);
|
|
31436
31520
|
return JSON.stringify(next, null, 1);
|
|
31437
31521
|
}
|
|
@@ -31762,10 +31846,10 @@ var init_management_http = __esm(() => {
|
|
|
31762
31846
|
|
|
31763
31847
|
// src/utils/tools-manager.ts
|
|
31764
31848
|
import { spawnSync as spawnSync5 } from "child_process";
|
|
31765
|
-
import { chmodSync as chmodSync3, existsSync as
|
|
31849
|
+
import { chmodSync as chmodSync3, existsSync as existsSync21, mkdirSync as mkdirSync8, readdirSync as readdirSync5, renameSync, rmSync as rmSync4 } from "fs";
|
|
31766
31850
|
import { writeFile } from "fs/promises";
|
|
31767
31851
|
import { arch, platform as platform2 } from "os";
|
|
31768
|
-
import { join as
|
|
31852
|
+
import { join as join31 } from "path";
|
|
31769
31853
|
function isOfflineModeEnabled() {
|
|
31770
31854
|
const value = getEnvValue(ENV_OFFLINE);
|
|
31771
31855
|
if (!value)
|
|
@@ -31784,8 +31868,8 @@ function getToolPath(tool) {
|
|
|
31784
31868
|
const config = TOOLS[tool];
|
|
31785
31869
|
if (!config)
|
|
31786
31870
|
return null;
|
|
31787
|
-
const localPath =
|
|
31788
|
-
if (
|
|
31871
|
+
const localPath = join31(TOOLS_DIR, config.binaryName + (platform2() === "win32" ? ".exe" : ""));
|
|
31872
|
+
if (existsSync21(localPath)) {
|
|
31789
31873
|
return localPath;
|
|
31790
31874
|
}
|
|
31791
31875
|
const systemBinaryNames = config.systemBinaryNames ?? [config.binaryName];
|
|
@@ -31824,7 +31908,7 @@ function findBinaryRecursively(rootDir, binaryFileName) {
|
|
|
31824
31908
|
continue;
|
|
31825
31909
|
const entries = readdirSync5(currentDir, { withFileTypes: true });
|
|
31826
31910
|
for (const entry of entries) {
|
|
31827
|
-
const fullPath =
|
|
31911
|
+
const fullPath = join31(currentDir, entry.name);
|
|
31828
31912
|
if (entry.isFile() && entry.name === binaryFileName) {
|
|
31829
31913
|
return fullPath;
|
|
31830
31914
|
}
|
|
@@ -31865,8 +31949,8 @@ function extractTarGzArchive(archivePath, extractDir, assetName) {
|
|
|
31865
31949
|
function getWindowsTarCommand() {
|
|
31866
31950
|
const systemRoot = process.env.SystemRoot ?? process.env.WINDIR;
|
|
31867
31951
|
if (systemRoot) {
|
|
31868
|
-
const systemTar =
|
|
31869
|
-
if (
|
|
31952
|
+
const systemTar = join31(systemRoot, "System32", "tar.exe");
|
|
31953
|
+
if (existsSync21(systemTar)) {
|
|
31870
31954
|
return systemTar;
|
|
31871
31955
|
}
|
|
31872
31956
|
}
|
|
@@ -31919,11 +32003,11 @@ async function downloadTool(tool) {
|
|
|
31919
32003
|
}
|
|
31920
32004
|
mkdirSync8(TOOLS_DIR, { recursive: true });
|
|
31921
32005
|
const downloadUrl = `https://github.com/${config.repo}/releases/download/${config.tagPrefix}${version}/${assetName}`;
|
|
31922
|
-
const archivePath =
|
|
32006
|
+
const archivePath = join31(TOOLS_DIR, assetName);
|
|
31923
32007
|
const binaryExt = plat === "win32" ? ".exe" : "";
|
|
31924
|
-
const binaryPath =
|
|
32008
|
+
const binaryPath = join31(TOOLS_DIR, config.binaryName + binaryExt);
|
|
31925
32009
|
await downloadFile(downloadUrl, archivePath);
|
|
31926
|
-
const extractDir =
|
|
32010
|
+
const extractDir = join31(TOOLS_DIR, `extract_tmp_${config.binaryName}_${process.pid}_${Date.now()}_${Math.random().toString(36).slice(2, 10)}`);
|
|
31927
32011
|
mkdirSync8(extractDir, { recursive: true });
|
|
31928
32012
|
try {
|
|
31929
32013
|
if (assetName.endsWith(".tar.gz")) {
|
|
@@ -31934,9 +32018,9 @@ async function downloadTool(tool) {
|
|
|
31934
32018
|
throw new Error(`Unsupported archive format: ${assetName}`);
|
|
31935
32019
|
}
|
|
31936
32020
|
const binaryFileName = config.binaryName + binaryExt;
|
|
31937
|
-
const extractedDir =
|
|
31938
|
-
const extractedBinaryCandidates = [
|
|
31939
|
-
let extractedBinary = extractedBinaryCandidates.find((candidate) =>
|
|
32021
|
+
const extractedDir = join31(extractDir, assetName.replace(/\.(tar\.gz|zip)$/, ""));
|
|
32022
|
+
const extractedBinaryCandidates = [join31(extractedDir, binaryFileName), join31(extractDir, binaryFileName)];
|
|
32023
|
+
let extractedBinary = extractedBinaryCandidates.find((candidate) => existsSync21(candidate));
|
|
31940
32024
|
if (!extractedBinary) {
|
|
31941
32025
|
extractedBinary = findBinaryRecursively(extractDir, binaryFileName) ?? undefined;
|
|
31942
32026
|
}
|
|
@@ -33524,7 +33608,7 @@ var init_read_selectors = __esm(() => {
|
|
|
33524
33608
|
});
|
|
33525
33609
|
|
|
33526
33610
|
// src/core/tools/read-document-extract.ts
|
|
33527
|
-
import { existsSync as
|
|
33611
|
+
import { existsSync as existsSync22 } from "node:fs";
|
|
33528
33612
|
function isDocumentPath(pathValue) {
|
|
33529
33613
|
return DOCUMENT_EXTENSIONS.test(pathValue);
|
|
33530
33614
|
}
|
|
@@ -33721,7 +33805,7 @@ function documentExtension(source) {
|
|
|
33721
33805
|
}
|
|
33722
33806
|
async function extractMarkitDocument(buffer, source) {
|
|
33723
33807
|
const ext = documentExtension(source);
|
|
33724
|
-
const result =
|
|
33808
|
+
const result = existsSync22(source) ? await convertFileWithMarkit(source) : await convertBufferWithMarkit(buffer, ext);
|
|
33725
33809
|
return result.ok ? result.content : `[Cannot read ${ext} file: ${result.error || "conversion failed"}]`;
|
|
33726
33810
|
}
|
|
33727
33811
|
async function extractDocumentMarkdown(buffer, source) {
|
|
@@ -34584,7 +34668,7 @@ var init_read_url = __esm(() => {
|
|
|
34584
34668
|
});
|
|
34585
34669
|
|
|
34586
34670
|
// src/core/tools/read.ts
|
|
34587
|
-
import { basename as basename5, dirname as
|
|
34671
|
+
import { basename as basename5, dirname as dirname13, isAbsolute as isAbsolute6, relative as relative7, resolve as resolvePath5, sep as sep6 } from "node:path";
|
|
34588
34672
|
import { Text as Text32 } from "@earendil-works/pi-tui";
|
|
34589
34673
|
import { constants as constants5 } from "fs";
|
|
34590
34674
|
import { access as fsAccess3, readFile as fsReadFile2, stat as fsStat4 } from "fs/promises";
|
|
@@ -34662,7 +34746,7 @@ function oversizedReadResult(details) {
|
|
|
34662
34746
|
};
|
|
34663
34747
|
}
|
|
34664
34748
|
function getPiDocsClassification(absolutePath) {
|
|
34665
|
-
const packageRoot =
|
|
34749
|
+
const packageRoot = dirname13(getReadmePath());
|
|
34666
34750
|
const relativePath = relative7(resolvePath5(packageRoot), resolvePath5(absolutePath));
|
|
34667
34751
|
if (relativePath === "" || relativePath === ".." || relativePath.startsWith(`..${sep6}`) || isAbsolute6(relativePath)) {
|
|
34668
34752
|
return;
|
|
@@ -34680,7 +34764,7 @@ function getCompactReadClassification(args, cwd) {
|
|
|
34680
34764
|
const absolutePath = resolveToCwd(rawPath, cwd);
|
|
34681
34765
|
const fileName = basename5(absolutePath);
|
|
34682
34766
|
if (fileName === "SKILL.md") {
|
|
34683
|
-
return { kind: "skill", label: basename5(
|
|
34767
|
+
return { kind: "skill", label: basename5(dirname13(absolutePath)) || fileName };
|
|
34684
34768
|
}
|
|
34685
34769
|
const docsClassification = getPiDocsClassification(absolutePath);
|
|
34686
34770
|
if (docsClassification)
|
|
@@ -35840,22 +35924,22 @@ function filterSearchOutputByLineRange(text, ranges, contextBefore = 1, contextA
|
|
|
35840
35924
|
}
|
|
35841
35925
|
|
|
35842
35926
|
// src/core/tools/search.ts
|
|
35843
|
-
import { existsSync as
|
|
35927
|
+
import { existsSync as existsSync23 } from "node:fs";
|
|
35844
35928
|
import { readFile as fsReadFile4, stat as fsStat6 } from "node:fs/promises";
|
|
35845
|
-
import { dirname as
|
|
35929
|
+
import { dirname as dirname14, join as join32, resolve as resolvePath6 } from "node:path";
|
|
35846
35930
|
import { Text as Text34 } from "@earendil-works/pi-tui";
|
|
35847
35931
|
import { Type as Type9 } from "typebox";
|
|
35848
35932
|
function delimiterInExistingSearchGlobRoot(value, cwd) {
|
|
35849
35933
|
const selector = splitLineRangeSelector(value);
|
|
35850
35934
|
const parsed = splitPathLikeGlob(selector.path);
|
|
35851
|
-
return !!parsed.glob && /[;,\s]/.test(parsed.basePath) &&
|
|
35935
|
+
return !!parsed.glob && /[;,\s]/.test(parsed.basePath) && existsSync23(resolveToCwd(parsed.basePath, cwd));
|
|
35852
35936
|
}
|
|
35853
35937
|
function archiveSelectorExists(value, cwd) {
|
|
35854
35938
|
const archive = parseArchiveSelector(value);
|
|
35855
35939
|
if (!archive)
|
|
35856
35940
|
return false;
|
|
35857
35941
|
const resolved = resolveArchiveSelector(archive, cwd);
|
|
35858
|
-
if (!
|
|
35942
|
+
if (!existsSync23(resolved.archivePath))
|
|
35859
35943
|
return false;
|
|
35860
35944
|
if (!resolved.memberPath)
|
|
35861
35945
|
return true;
|
|
@@ -35871,7 +35955,7 @@ function searchPathResolvable(value, cwd) {
|
|
|
35871
35955
|
if (archive)
|
|
35872
35956
|
return archiveSelectorExists(selector.path, cwd);
|
|
35873
35957
|
const sqlite = sqliteSelectorForPath(selector.path, cwd);
|
|
35874
|
-
return !!sqlite || /^(?:skill|agent|artifact|history|issue|local|memory|pr|conflict|omp|rule|mcp|vault):\/\//.test(selector.path) ||
|
|
35958
|
+
return !!sqlite || /^(?:skill|agent|artifact|history|issue|local|memory|pr|conflict|omp|rule|mcp|vault):\/\//.test(selector.path) || existsSync23(resolveToCwd(splitPathLikeGlob(selector.path).basePath, cwd));
|
|
35875
35959
|
}
|
|
35876
35960
|
function normalizePaths(pathsValue, cwd) {
|
|
35877
35961
|
const inputs = Array.isArray(pathsValue) ? pathsValue.length > 0 ? pathsValue : ["."] : pathsValue === undefined ? ["."] : [pathsValue];
|
|
@@ -35883,7 +35967,7 @@ function normalizePaths(pathsValue, cwd) {
|
|
|
35883
35967
|
continue;
|
|
35884
35968
|
}
|
|
35885
35969
|
const resourceLike = /^[a-z]+:\/\//i.test(raw) || /^[^:]+\.(?:zip|jar|tar|tgz|gz|sqlite|db):/i.test(raw);
|
|
35886
|
-
if (
|
|
35970
|
+
if (existsSync23(resolveToCwd(splitLineRangeSelector(raw).path, cwd)) || delimiterInExistingSearchGlobRoot(raw, cwd) || archiveSelectorExists(raw, cwd)) {
|
|
35887
35971
|
expanded.push(raw);
|
|
35888
35972
|
continue;
|
|
35889
35973
|
}
|
|
@@ -36068,7 +36152,7 @@ async function addHashlineHeadersToSearchOutput(text, cwd, targetPath, hashlineS
|
|
|
36068
36152
|
const rendered = [];
|
|
36069
36153
|
let lastDir = "";
|
|
36070
36154
|
for (const group of groups) {
|
|
36071
|
-
let absolutePath = targetIsFile ? searchRoot :
|
|
36155
|
+
let absolutePath = targetIsFile ? searchRoot : join32(searchRoot, group.path);
|
|
36072
36156
|
try {
|
|
36073
36157
|
await fsReadFile4(absolutePath);
|
|
36074
36158
|
} catch {
|
|
@@ -36077,7 +36161,7 @@ async function addHashlineHeadersToSearchOutput(text, cwd, targetPath, hashlineS
|
|
|
36077
36161
|
try {
|
|
36078
36162
|
const content = await fsReadFile4(absolutePath, "utf-8");
|
|
36079
36163
|
const snapshot = recordHashlineSnapshot(absolutePath, cwd, content, hashlineStore);
|
|
36080
|
-
const dir =
|
|
36164
|
+
const dir = dirname14(snapshot.displayPath);
|
|
36081
36165
|
if (dir !== "." && dir !== lastDir) {
|
|
36082
36166
|
rendered.push(`# ${dir}/`);
|
|
36083
36167
|
lastDir = dir;
|
|
@@ -36742,7 +36826,7 @@ var init_todos_locks = __esm(() => {
|
|
|
36742
36826
|
|
|
36743
36827
|
// src/core/tools/todos-storage.ts
|
|
36744
36828
|
import crypto3 from "node:crypto";
|
|
36745
|
-
import { existsSync as
|
|
36829
|
+
import { existsSync as existsSync24 } from "node:fs";
|
|
36746
36830
|
import fs7 from "node:fs/promises";
|
|
36747
36831
|
import path11 from "node:path";
|
|
36748
36832
|
function parseFrontMatter(text, idFallback) {
|
|
@@ -36874,7 +36958,7 @@ async function generateTodoId(todosDir) {
|
|
|
36874
36958
|
for (let attempt = 0;attempt < 10; attempt += 1) {
|
|
36875
36959
|
const id = crypto3.randomBytes(4).toString("hex");
|
|
36876
36960
|
const todoPath = getTodoPath(todosDir, id);
|
|
36877
|
-
if (!
|
|
36961
|
+
if (!existsSync24(todoPath))
|
|
36878
36962
|
return id;
|
|
36879
36963
|
}
|
|
36880
36964
|
throw new Error("Failed to generate unique todo id");
|
|
@@ -36909,7 +36993,7 @@ async function listTodos(todosDir) {
|
|
|
36909
36993
|
return sortTodos(todos);
|
|
36910
36994
|
}
|
|
36911
36995
|
async function ensureTodoExists(filePath, id) {
|
|
36912
|
-
if (!
|
|
36996
|
+
if (!existsSync24(filePath))
|
|
36913
36997
|
return null;
|
|
36914
36998
|
return readTodoFile(filePath, id);
|
|
36915
36999
|
}
|
|
@@ -36928,7 +37012,7 @@ var init_todos_storage = __esm(() => {
|
|
|
36928
37012
|
});
|
|
36929
37013
|
|
|
36930
37014
|
// src/core/tools/todos-mutations.ts
|
|
36931
|
-
import { existsSync as
|
|
37015
|
+
import { existsSync as existsSync25 } from "node:fs";
|
|
36932
37016
|
import fs8 from "node:fs/promises";
|
|
36933
37017
|
async function claimTodoAssignment(todosDir, id, ctx, force = false) {
|
|
36934
37018
|
const validated = validateTodoId(id);
|
|
@@ -36937,7 +37021,7 @@ async function claimTodoAssignment(todosDir, id, ctx, force = false) {
|
|
|
36937
37021
|
}
|
|
36938
37022
|
const normalizedId = validated.id;
|
|
36939
37023
|
const filePath = getTodoPath(todosDir, normalizedId);
|
|
36940
|
-
if (!
|
|
37024
|
+
if (!existsSync25(filePath)) {
|
|
36941
37025
|
return { error: `Todo ${displayTodoId(id)} not found` };
|
|
36942
37026
|
}
|
|
36943
37027
|
const sessionId = ctx.sessionManager.getSessionId();
|
|
@@ -36968,7 +37052,7 @@ async function releaseTodoAssignment(todosDir, id, ctx, force = false) {
|
|
|
36968
37052
|
}
|
|
36969
37053
|
const normalizedId = validated.id;
|
|
36970
37054
|
const filePath = getTodoPath(todosDir, normalizedId);
|
|
36971
|
-
if (!
|
|
37055
|
+
if (!existsSync25(filePath)) {
|
|
36972
37056
|
return { error: `Todo ${displayTodoId(id)} not found` };
|
|
36973
37057
|
}
|
|
36974
37058
|
const sessionId = ctx.sessionManager.getSessionId();
|
|
@@ -36997,7 +37081,7 @@ async function deleteTodo(todosDir, id, ctx) {
|
|
|
36997
37081
|
}
|
|
36998
37082
|
const normalizedId = validated.id;
|
|
36999
37083
|
const filePath = getTodoPath(todosDir, normalizedId);
|
|
37000
|
-
if (!
|
|
37084
|
+
if (!existsSync25(filePath)) {
|
|
37001
37085
|
return { error: `Todo ${displayTodoId(id)} not found` };
|
|
37002
37086
|
}
|
|
37003
37087
|
return withTodoLock(todosDir, normalizedId, ctx, async () => {
|
|
@@ -37169,7 +37253,7 @@ var init_todos_render = __esm(() => {
|
|
|
37169
37253
|
});
|
|
37170
37254
|
|
|
37171
37255
|
// src/core/tools/todos-execute.ts
|
|
37172
|
-
import { existsSync as
|
|
37256
|
+
import { existsSync as existsSync26 } from "node:fs";
|
|
37173
37257
|
function todoActionResult(action, text, detailsError) {
|
|
37174
37258
|
return {
|
|
37175
37259
|
content: [{ type: "text", text }],
|
|
@@ -37253,7 +37337,7 @@ async function executeUpdateAction(todosDir, params, ctx) {
|
|
|
37253
37337
|
const normalizedId = validated.id;
|
|
37254
37338
|
const displayId = formatTodoId(normalizedId);
|
|
37255
37339
|
const filePath = getTodoPath(todosDir, normalizedId);
|
|
37256
|
-
if (!
|
|
37340
|
+
if (!existsSync26(filePath)) {
|
|
37257
37341
|
return todoActionResult("update", `Todo ${displayId} not found`, "not found");
|
|
37258
37342
|
}
|
|
37259
37343
|
const result = await withTodoLock(todosDir, normalizedId, ctx, async () => {
|
|
@@ -37290,7 +37374,7 @@ async function executeAppendAction(todosDir, params, ctx) {
|
|
|
37290
37374
|
const normalizedId = validated.id;
|
|
37291
37375
|
const displayId = formatTodoId(normalizedId);
|
|
37292
37376
|
const filePath = getTodoPath(todosDir, normalizedId);
|
|
37293
|
-
if (!
|
|
37377
|
+
if (!existsSync26(filePath)) {
|
|
37294
37378
|
return todoActionResult("append", `Todo ${displayId} not found`, "not found");
|
|
37295
37379
|
}
|
|
37296
37380
|
const result = await withTodoLock(todosDir, normalizedId, ctx, async () => {
|
|
@@ -37410,7 +37494,7 @@ import {
|
|
|
37410
37494
|
stat as fsStat7,
|
|
37411
37495
|
writeFile as fsWriteFile2
|
|
37412
37496
|
} from "fs/promises";
|
|
37413
|
-
import { dirname as
|
|
37497
|
+
import { dirname as dirname15, join as join33 } from "path";
|
|
37414
37498
|
import { Type as Type11 } from "typebox";
|
|
37415
37499
|
async function findConflictBlocks(root, limit = 100) {
|
|
37416
37500
|
const out = [];
|
|
@@ -37418,7 +37502,7 @@ async function findConflictBlocks(root, limit = 100) {
|
|
|
37418
37502
|
for (const entry of await fsReaddir2(dir, { withFileTypes: true }).catch(() => [])) {
|
|
37419
37503
|
if (out.length >= limit || entry.name === ".git" || entry.name === "node_modules")
|
|
37420
37504
|
continue;
|
|
37421
|
-
const full =
|
|
37505
|
+
const full = join33(dir, entry.name);
|
|
37422
37506
|
if (entry.isDirectory())
|
|
37423
37507
|
await walk(full);
|
|
37424
37508
|
else if (entry.isFile()) {
|
|
@@ -37708,7 +37792,7 @@ ${headers[0]}` : ""}` }],
|
|
|
37708
37792
|
};
|
|
37709
37793
|
}
|
|
37710
37794
|
const absolutePath = resolveToCwd(path12, cwd);
|
|
37711
|
-
const dir =
|
|
37795
|
+
const dir = dirname15(absolutePath);
|
|
37712
37796
|
return withFileMutationQueue(absolutePath, async () => {
|
|
37713
37797
|
const throwIfAborted2 = () => {
|
|
37714
37798
|
if (signal?.aborted)
|
|
@@ -38215,20 +38299,20 @@ import {
|
|
|
38215
38299
|
lstatSync as lstatSync2,
|
|
38216
38300
|
openSync as openSync3,
|
|
38217
38301
|
readdirSync as readdirSync6,
|
|
38218
|
-
readFileSync as
|
|
38302
|
+
readFileSync as readFileSync16,
|
|
38219
38303
|
renameSync as renameSync2,
|
|
38220
38304
|
rmSync as rmSync5,
|
|
38221
38305
|
statSync as statSync6,
|
|
38222
38306
|
unlinkSync as unlinkSync4,
|
|
38223
38307
|
writeSync
|
|
38224
38308
|
} from "node:fs";
|
|
38225
|
-
import { join as
|
|
38309
|
+
import { join as join34 } from "node:path";
|
|
38226
38310
|
function getCleanupControlRoot() {
|
|
38227
|
-
return
|
|
38311
|
+
return join34(getTempRootDir(), CLEANUP_CONTROL_SUBDIR);
|
|
38228
38312
|
}
|
|
38229
38313
|
function getCleanupControlDir(target, controlRoot) {
|
|
38230
38314
|
const key = createHash3("sha256").update(target).digest("hex").slice(0, 16);
|
|
38231
|
-
return
|
|
38315
|
+
return join34(controlRoot ?? getCleanupControlRoot(), key);
|
|
38232
38316
|
}
|
|
38233
38317
|
function sameFileIdentity2(left, right) {
|
|
38234
38318
|
return left.dev === right.dev && left.ino === right.ino;
|
|
@@ -38355,7 +38439,7 @@ function breakStaleLock(lockPath, observedMtimeMs) {
|
|
|
38355
38439
|
}
|
|
38356
38440
|
function ownsCleanupLock(lockPath, lock) {
|
|
38357
38441
|
try {
|
|
38358
|
-
return pathIdentifiesFile(lockPath, lock) &&
|
|
38442
|
+
return pathIdentifiesFile(lockPath, lock) && readFileSync16(lockPath, "utf-8") === lock.token && pathIdentifiesFile(lockPath, lock);
|
|
38359
38443
|
} catch {
|
|
38360
38444
|
return false;
|
|
38361
38445
|
}
|
|
@@ -38444,7 +38528,7 @@ function scanFreshness(entryPath, cutoff, depth = 0) {
|
|
|
38444
38528
|
}
|
|
38445
38529
|
let foundUnknown = false;
|
|
38446
38530
|
for (const child of children) {
|
|
38447
|
-
const freshness = scanFreshness(
|
|
38531
|
+
const freshness = scanFreshness(join34(entryPath, child), cutoff, depth + 1);
|
|
38448
38532
|
if (freshness === "fresh") {
|
|
38449
38533
|
return "fresh";
|
|
38450
38534
|
}
|
|
@@ -38462,11 +38546,11 @@ function withCleanupGate(controlDir, options, scan) {
|
|
|
38462
38546
|
} catch {
|
|
38463
38547
|
return "locked";
|
|
38464
38548
|
}
|
|
38465
|
-
const markerPath =
|
|
38549
|
+
const markerPath = join34(controlDir, CLEANUP_MARKER_FILE);
|
|
38466
38550
|
if (markerIsFresh(markerPath, now, throttleMs)) {
|
|
38467
38551
|
return "throttled";
|
|
38468
38552
|
}
|
|
38469
|
-
const lockPath =
|
|
38553
|
+
const lockPath = join34(controlDir, CLEANUP_LOCK_FILE);
|
|
38470
38554
|
const token = acquireCleanupLock(lockPath, now, SESSION_TEMP_CLEANUP_LOCK_STALE_MS);
|
|
38471
38555
|
if (token === null) {
|
|
38472
38556
|
return "locked";
|
|
@@ -38517,7 +38601,7 @@ function sweepSessionTempRoot(root = getTempRootDir(), options = {}) {
|
|
|
38517
38601
|
if (isCleanupArtifact(entry)) {
|
|
38518
38602
|
continue;
|
|
38519
38603
|
}
|
|
38520
|
-
const entryPath =
|
|
38604
|
+
const entryPath = join34(root, entry);
|
|
38521
38605
|
if (gate.protectedPaths.has(entryPath)) {
|
|
38522
38606
|
continue;
|
|
38523
38607
|
}
|
|
@@ -38542,7 +38626,7 @@ function sweepSessionTempRoot(root = getTempRootDir(), options = {}) {
|
|
|
38542
38626
|
});
|
|
38543
38627
|
}
|
|
38544
38628
|
function reapToolResultsDir(parent, cutoff, protectedPaths) {
|
|
38545
|
-
const toolResultsDir =
|
|
38629
|
+
const toolResultsDir = join34(parent, TOOL_RESULTS_SUBDIR);
|
|
38546
38630
|
if (protectedPaths.has(toolResultsDir) || !isRealDirectory2(toolResultsDir)) {
|
|
38547
38631
|
return;
|
|
38548
38632
|
}
|
|
@@ -38567,7 +38651,7 @@ function sweepToolResultsRoot(sessionsRoot, options = {}) {
|
|
|
38567
38651
|
return;
|
|
38568
38652
|
}
|
|
38569
38653
|
for (const entry of entries) {
|
|
38570
|
-
const projectDir =
|
|
38654
|
+
const projectDir = join34(sessionsRoot, entry);
|
|
38571
38655
|
if (!isRealDirectory2(projectDir) || gate.protectedPaths.has(projectDir)) {
|
|
38572
38656
|
continue;
|
|
38573
38657
|
}
|
|
@@ -38808,7 +38892,7 @@ function parseSkillBlock(text) {
|
|
|
38808
38892
|
}
|
|
38809
38893
|
|
|
38810
38894
|
// src/core/agent-session.ts
|
|
38811
|
-
import { join as
|
|
38895
|
+
import { join as join35 } from "node:path";
|
|
38812
38896
|
|
|
38813
38897
|
class AgentSessionBase {
|
|
38814
38898
|
agent;
|
|
@@ -38931,7 +39015,7 @@ class AgentSessionBase {
|
|
|
38931
39015
|
const sessionDir = this.sessionManager.getSessionDir() || undefined;
|
|
38932
39016
|
this._tempStorageLease = acquireProtectedPaths([
|
|
38933
39017
|
setActiveSessionTempId(sessionId),
|
|
38934
|
-
...sessionDir ? [
|
|
39018
|
+
...sessionDir ? [join35(sessionDir, TOOL_RESULTS_SUBDIR)] : []
|
|
38935
39019
|
]);
|
|
38936
39020
|
const customSessionDir = this.sessionManager.usesDefaultSessionDir() ? undefined : sessionDir;
|
|
38937
39021
|
scheduleSessionTempCleanup(customSessionDir ? { sessionDirs: [customSessionDir] } : {});
|
|
@@ -38990,30 +39074,8 @@ var init_auth_storage = __esm(() => {
|
|
|
38990
39074
|
init_auth_storage_backends();
|
|
38991
39075
|
});
|
|
38992
39076
|
|
|
38993
|
-
// src/core/builtin-install-layout.ts
|
|
38994
|
-
function requiredEntriesForBuiltin(dirName) {
|
|
38995
|
-
return [INSTALLED_EXTENSION_ENTRIES[dirName], SOURCE_EXTENSION_ENTRIES[dirName]];
|
|
38996
|
-
}
|
|
38997
|
-
var SOURCE_EXTENSION_ENTRIES, INSTALLED_EXTENSION_ENTRIES;
|
|
38998
|
-
var init_builtin_install_layout = __esm(() => {
|
|
38999
|
-
SOURCE_EXTENSION_ENTRIES = {
|
|
39000
|
-
workflows: "src/extension/index.ts",
|
|
39001
|
-
subagents: "src/extension/index.ts",
|
|
39002
|
-
mcp: "index.ts",
|
|
39003
|
-
"web-access": "index.ts",
|
|
39004
|
-
intercom: "index.ts"
|
|
39005
|
-
};
|
|
39006
|
-
INSTALLED_EXTENSION_ENTRIES = {
|
|
39007
|
-
workflows: "src/extension/index.bundle.mjs",
|
|
39008
|
-
subagents: "src/extension/index.bundle.mjs",
|
|
39009
|
-
mcp: "index.bundle.mjs",
|
|
39010
|
-
"web-access": "index.bundle.mjs",
|
|
39011
|
-
intercom: "index.bundle.mjs"
|
|
39012
|
-
};
|
|
39013
|
-
});
|
|
39014
|
-
|
|
39015
39077
|
// src/core/builtin-packages.ts
|
|
39016
|
-
import { join as
|
|
39078
|
+
import { join as join36, resolve as resolve8 } from "node:path";
|
|
39017
39079
|
var WORKSPACE_BUILTINS, BUILTIN_PACKAGES;
|
|
39018
39080
|
var init_builtin_packages = __esm(() => {
|
|
39019
39081
|
init_config();
|
|
@@ -39030,7 +39092,7 @@ var init_builtin_packages = __esm(() => {
|
|
|
39030
39092
|
packageName: spec.packageName,
|
|
39031
39093
|
distDirName: spec.distDirName,
|
|
39032
39094
|
requiredEntries: requiredEntriesForBuiltin(spec.distDirName),
|
|
39033
|
-
sourceCandidates: ({ here, packageDir, isSourceCheckout }) => isSourceCheckout ? [
|
|
39095
|
+
sourceCandidates: ({ here, packageDir, isSourceCheckout }) => isSourceCheckout ? [join36(packageDir, "..", spec.workspaceDirName), join36(here, "..", "..", "..", spec.workspaceDirName)] : []
|
|
39034
39096
|
}));
|
|
39035
39097
|
});
|
|
39036
39098
|
|
|
@@ -39427,14 +39489,14 @@ var init_git_env = __esm(() => {
|
|
|
39427
39489
|
});
|
|
39428
39490
|
|
|
39429
39491
|
// src/core/package-manager-env.ts
|
|
39430
|
-
import { readFileSync as
|
|
39492
|
+
import { readFileSync as readFileSync17 } from "node:fs";
|
|
39431
39493
|
import { basename as basename6 } from "node:path";
|
|
39432
39494
|
function getEnv() {
|
|
39433
39495
|
if (process.platform !== "linux" || Object.keys(process.env).length > 0) {
|
|
39434
39496
|
return process.env;
|
|
39435
39497
|
}
|
|
39436
39498
|
try {
|
|
39437
|
-
const data =
|
|
39499
|
+
const data = readFileSync17("/proc/self/environ", "utf-8");
|
|
39438
39500
|
const env = {};
|
|
39439
39501
|
for (const entry of data.split("\x00")) {
|
|
39440
39502
|
const idx = entry.indexOf("=");
|
|
@@ -39666,13 +39728,13 @@ var NETWORK_TIMEOUT_MS2 = 1e4, UPDATE_CHECK_CONCURRENCY = 4, GIT_UPDATE_CONCURRE
|
|
|
39666
39728
|
// src/core/package-manager-paths.ts
|
|
39667
39729
|
import { createHash as createHash4 } from "node:crypto";
|
|
39668
39730
|
import { homedir as homedir6, tmpdir as tmpdir5 } from "node:os";
|
|
39669
|
-
import { join as
|
|
39731
|
+
import { join as join37 } from "node:path";
|
|
39670
39732
|
function getHomeDir2() {
|
|
39671
39733
|
return process.env.HOME || homedir6();
|
|
39672
39734
|
}
|
|
39673
39735
|
function getTemporaryDir(prefix, suffix) {
|
|
39674
39736
|
const hash = createHash4("sha256").update(`${prefix}-${suffix ?? ""}`).digest("hex").slice(0, 8);
|
|
39675
|
-
return
|
|
39737
|
+
return join37(tmpdir5(), `${APP_NAME}-extensions`, prefix, hash, suffix ?? "");
|
|
39676
39738
|
}
|
|
39677
39739
|
function getBaseDirsForScope(context, scope) {
|
|
39678
39740
|
if (scope === "project") {
|
|
@@ -39697,27 +39759,27 @@ function getNpmInstallRoot(context, scope, temporary) {
|
|
|
39697
39759
|
return getTemporaryDir("npm");
|
|
39698
39760
|
}
|
|
39699
39761
|
if (scope === "project") {
|
|
39700
|
-
return
|
|
39762
|
+
return join37(context.cwd, CONFIG_DIR_NAME, "npm");
|
|
39701
39763
|
}
|
|
39702
|
-
return
|
|
39764
|
+
return join37(context.agentDir, "npm");
|
|
39703
39765
|
}
|
|
39704
39766
|
function getGitInstallPath(context, source, scope) {
|
|
39705
39767
|
if (scope === "temporary") {
|
|
39706
39768
|
return getTemporaryDir(`git-${source.host}`, source.path);
|
|
39707
39769
|
}
|
|
39708
39770
|
if (scope === "project") {
|
|
39709
|
-
return
|
|
39771
|
+
return join37(context.cwd, CONFIG_DIR_NAME, "git", source.host, source.path);
|
|
39710
39772
|
}
|
|
39711
|
-
return
|
|
39773
|
+
return join37(context.agentDir, "git", source.host, source.path);
|
|
39712
39774
|
}
|
|
39713
39775
|
function getGitInstallRoot(context, scope) {
|
|
39714
39776
|
if (scope === "temporary") {
|
|
39715
39777
|
return;
|
|
39716
39778
|
}
|
|
39717
39779
|
if (scope === "project") {
|
|
39718
|
-
return
|
|
39780
|
+
return join37(context.cwd, CONFIG_DIR_NAME, "git");
|
|
39719
39781
|
}
|
|
39720
|
-
return
|
|
39782
|
+
return join37(context.agentDir, "git");
|
|
39721
39783
|
}
|
|
39722
39784
|
var init_package_manager_paths = __esm(() => {
|
|
39723
39785
|
init_config();
|
|
@@ -39725,8 +39787,8 @@ var init_package_manager_paths = __esm(() => {
|
|
|
39725
39787
|
});
|
|
39726
39788
|
|
|
39727
39789
|
// src/core/package-manager-npm.ts
|
|
39728
|
-
import { existsSync as
|
|
39729
|
-
import { basename as basename7, dirname as
|
|
39790
|
+
import { existsSync as existsSync27, mkdirSync as mkdirSync9, readFileSync as readFileSync18, writeFileSync as writeFileSync10 } from "node:fs";
|
|
39791
|
+
import { basename as basename7, dirname as dirname16, join as join38 } from "node:path";
|
|
39730
39792
|
import { maxSatisfying, rcompare, satisfies } from "semver";
|
|
39731
39793
|
function getNpmCommand(context) {
|
|
39732
39794
|
const configuredCommand = context.settingsManager.getNpmCommand();
|
|
@@ -39793,7 +39855,7 @@ async function installNpm(context, source, scope, temporary) {
|
|
|
39793
39855
|
}
|
|
39794
39856
|
async function uninstallNpm(context, source, scope) {
|
|
39795
39857
|
const installRoot = getNpmInstallRoot(context, scope, false);
|
|
39796
|
-
if (!
|
|
39858
|
+
if (!existsSync27(installRoot)) {
|
|
39797
39859
|
return;
|
|
39798
39860
|
}
|
|
39799
39861
|
if (getPackageManagerName(context) === "bun") {
|
|
@@ -39808,23 +39870,23 @@ async function installNpmBatch(context, specs, scope) {
|
|
|
39808
39870
|
await runNpmCommand(context, getNpmInstallArgs(context, specs, installRoot));
|
|
39809
39871
|
}
|
|
39810
39872
|
function ensureNpmProject(installRoot) {
|
|
39811
|
-
if (!
|
|
39873
|
+
if (!existsSync27(installRoot)) {
|
|
39812
39874
|
mkdirSync9(installRoot, { recursive: true });
|
|
39813
39875
|
}
|
|
39814
39876
|
markPathIgnoredByCloudSync(installRoot);
|
|
39815
39877
|
ensureGitIgnore(installRoot);
|
|
39816
|
-
const packageJsonPath =
|
|
39817
|
-
if (!
|
|
39878
|
+
const packageJsonPath = join38(installRoot, "package.json");
|
|
39879
|
+
if (!existsSync27(packageJsonPath)) {
|
|
39818
39880
|
const pkgJson = { name: `${APP_NAME}-extensions`, private: true };
|
|
39819
39881
|
writeFileSync10(packageJsonPath, JSON.stringify(pkgJson, null, 2), "utf-8");
|
|
39820
39882
|
}
|
|
39821
39883
|
}
|
|
39822
39884
|
function ensureGitIgnore(dir) {
|
|
39823
|
-
if (!
|
|
39885
|
+
if (!existsSync27(dir)) {
|
|
39824
39886
|
mkdirSync9(dir, { recursive: true });
|
|
39825
39887
|
}
|
|
39826
|
-
const ignorePath =
|
|
39827
|
-
if (!
|
|
39888
|
+
const ignorePath = join38(dir, ".gitignore");
|
|
39889
|
+
if (!existsSync27(ignorePath)) {
|
|
39828
39890
|
writeFileSync10(ignorePath, `*
|
|
39829
39891
|
!.gitignore
|
|
39830
39892
|
`, "utf-8");
|
|
@@ -39832,12 +39894,12 @@ function ensureGitIgnore(dir) {
|
|
|
39832
39894
|
}
|
|
39833
39895
|
function getManagedNpmInstallPath(context, source, scope) {
|
|
39834
39896
|
if (scope === "temporary") {
|
|
39835
|
-
return
|
|
39897
|
+
return join38(getNpmInstallRoot(context, scope, true), "node_modules", source.name);
|
|
39836
39898
|
}
|
|
39837
39899
|
if (scope === "project") {
|
|
39838
|
-
return
|
|
39900
|
+
return join38(context.cwd, CONFIG_DIR_NAME, "npm", "node_modules", source.name);
|
|
39839
39901
|
}
|
|
39840
|
-
return
|
|
39902
|
+
return join38(context.agentDir, "npm", "node_modules", source.name);
|
|
39841
39903
|
}
|
|
39842
39904
|
function getGlobalNpmRoot(context) {
|
|
39843
39905
|
const npmCommand = getNpmCommand(context);
|
|
@@ -39847,7 +39909,7 @@ function getGlobalNpmRoot(context) {
|
|
|
39847
39909
|
}
|
|
39848
39910
|
if (getPackageManagerName(context) === "bun") {
|
|
39849
39911
|
const binDir = runNpmCommandSync(context, ["pm", "bin", "-g"]).trim();
|
|
39850
|
-
context.globalNpmRoot =
|
|
39912
|
+
context.globalNpmRoot = join38(dirname16(binDir), "install", "global", "node_modules");
|
|
39851
39913
|
} else {
|
|
39852
39914
|
context.globalNpmRoot = runNpmCommandSync(context, ["root", "-g"]).trim();
|
|
39853
39915
|
}
|
|
@@ -39873,28 +39935,28 @@ function getLegacyGlobalNpmInstallPath(context, source) {
|
|
|
39873
39935
|
if (pnpmPath)
|
|
39874
39936
|
return pnpmPath;
|
|
39875
39937
|
const globalRoot = context.driver?.getGlobalNpmRoot ? context.driver.getGlobalNpmRoot() : getGlobalNpmRoot(context);
|
|
39876
|
-
return
|
|
39938
|
+
return join38(globalRoot, source.name);
|
|
39877
39939
|
} catch {
|
|
39878
39940
|
return;
|
|
39879
39941
|
}
|
|
39880
39942
|
}
|
|
39881
39943
|
function getNpmInstallPath(context, source, scope) {
|
|
39882
39944
|
const managedPath = getManagedNpmInstallPath(context, source, scope);
|
|
39883
|
-
if (scope !== "user" ||
|
|
39945
|
+
if (scope !== "user" || existsSync27(managedPath)) {
|
|
39884
39946
|
return managedPath;
|
|
39885
39947
|
}
|
|
39886
39948
|
const legacyPath = getLegacyGlobalNpmInstallPath(context, source);
|
|
39887
|
-
return legacyPath &&
|
|
39949
|
+
return legacyPath && existsSync27(legacyPath) ? legacyPath : managedPath;
|
|
39888
39950
|
}
|
|
39889
39951
|
function getExistingNpmInstallPath(context, source, scope) {
|
|
39890
39952
|
const candidates = [getNpmInstallPath(context, source, scope)];
|
|
39891
39953
|
if (scope === "project") {
|
|
39892
39954
|
for (const configDir of getProjectConfigDirs(context.cwd)) {
|
|
39893
|
-
candidates.push(
|
|
39955
|
+
candidates.push(join38(configDir, "npm", "node_modules", source.name));
|
|
39894
39956
|
}
|
|
39895
39957
|
}
|
|
39896
39958
|
for (const candidate of Array.from(new Set(candidates))) {
|
|
39897
|
-
if (
|
|
39959
|
+
if (existsSync27(candidate))
|
|
39898
39960
|
return candidate;
|
|
39899
39961
|
}
|
|
39900
39962
|
return;
|
|
@@ -39931,11 +39993,11 @@ async function npmHasAvailableUpdate(context, source, installedPath) {
|
|
|
39931
39993
|
}
|
|
39932
39994
|
}
|
|
39933
39995
|
function getInstalledNpmVersion(installedPath) {
|
|
39934
|
-
const packageJsonPath =
|
|
39935
|
-
if (!
|
|
39996
|
+
const packageJsonPath = join38(installedPath, "package.json");
|
|
39997
|
+
if (!existsSync27(packageJsonPath))
|
|
39936
39998
|
return;
|
|
39937
39999
|
try {
|
|
39938
|
-
const content =
|
|
40000
|
+
const content = readFileSync18(packageJsonPath, "utf-8");
|
|
39939
40001
|
const pkg2 = JSON.parse(content);
|
|
39940
40002
|
return pkg2.version;
|
|
39941
40003
|
} catch {
|
|
@@ -39990,8 +40052,8 @@ async function withProgress(context, action, source, message, operation) {
|
|
|
39990
40052
|
}
|
|
39991
40053
|
|
|
39992
40054
|
// src/core/package-manager-git.ts
|
|
39993
|
-
import { existsSync as
|
|
39994
|
-
import { basename as basename8, dirname as
|
|
40055
|
+
import { existsSync as existsSync28, mkdirSync as mkdirSync10, readdirSync as readdirSync7, readFileSync as readFileSync19, rmSync as rmSync6, writeFileSync as writeFileSync11 } from "node:fs";
|
|
40056
|
+
import { basename as basename8, dirname as dirname17, join as join39, resolve as resolve9, sep as sep7 } from "node:path";
|
|
39995
40057
|
function runGitProcess(context, command, args, options) {
|
|
39996
40058
|
return context.driver ? context.driver.runCommand(command, args, options) : runCommand2(command, args, options);
|
|
39997
40059
|
}
|
|
@@ -40020,28 +40082,28 @@ function getExistingGitInstallPath(context, source, scope) {
|
|
|
40020
40082
|
const candidates = [getGitInstallPath(context, source, scope)];
|
|
40021
40083
|
if (scope === "project") {
|
|
40022
40084
|
for (const configDir of getProjectConfigDirs(context.cwd)) {
|
|
40023
|
-
candidates.push(
|
|
40085
|
+
candidates.push(join39(configDir, "git", source.host, source.path));
|
|
40024
40086
|
}
|
|
40025
40087
|
} else if (scope === "user") {
|
|
40026
40088
|
for (const agentDir of getBaseDirsForScope(context, "user")) {
|
|
40027
|
-
candidates.push(
|
|
40089
|
+
candidates.push(join39(agentDir, "git", source.host, source.path));
|
|
40028
40090
|
}
|
|
40029
40091
|
}
|
|
40030
40092
|
for (const candidate of Array.from(new Set(candidates))) {
|
|
40031
|
-
if (
|
|
40093
|
+
if (existsSync28(candidate))
|
|
40032
40094
|
return candidate;
|
|
40033
40095
|
}
|
|
40034
40096
|
return;
|
|
40035
40097
|
}
|
|
40036
40098
|
function getGitUpdateMarkerPath(targetDir) {
|
|
40037
|
-
return
|
|
40099
|
+
return join39(dirname17(targetDir), `.${basename8(targetDir)}.${APP_NAME}-update-incomplete`);
|
|
40038
40100
|
}
|
|
40039
40101
|
function hasMissingGitDependencies(targetDir) {
|
|
40040
|
-
const packageJsonPath =
|
|
40041
|
-
if (!
|
|
40102
|
+
const packageJsonPath = join39(targetDir, "package.json");
|
|
40103
|
+
if (!existsSync28(packageJsonPath))
|
|
40042
40104
|
return false;
|
|
40043
40105
|
try {
|
|
40044
|
-
const manifest = JSON.parse(
|
|
40106
|
+
const manifest = JSON.parse(readFileSync19(packageJsonPath, "utf-8"));
|
|
40045
40107
|
if (!manifest.dependencies || typeof manifest.dependencies !== "object" || Array.isArray(manifest.dependencies)) {
|
|
40046
40108
|
return false;
|
|
40047
40109
|
}
|
|
@@ -40050,7 +40112,7 @@ function hasMissingGitDependencies(targetDir) {
|
|
|
40050
40112
|
const dependencyPath = resolve9(nodeModulesDir, name);
|
|
40051
40113
|
if (!dependencyPath.startsWith(`${nodeModulesDir}${sep7}`))
|
|
40052
40114
|
return false;
|
|
40053
|
-
return !
|
|
40115
|
+
return !existsSync28(dependencyPath);
|
|
40054
40116
|
});
|
|
40055
40117
|
} catch {
|
|
40056
40118
|
return false;
|
|
@@ -40068,7 +40130,7 @@ async function cleanAndInstallGitDependencies(context, targetDir, markerPath) {
|
|
|
40068
40130
|
await repairMissingGitDependencies(context, targetDir).catch(() => {});
|
|
40069
40131
|
throw error;
|
|
40070
40132
|
}
|
|
40071
|
-
if (
|
|
40133
|
+
if (existsSync28(join39(targetDir, "package.json"))) {
|
|
40072
40134
|
await runNpmCommand(context, getGitDependencyInstallArgs(context), { cwd: targetDir });
|
|
40073
40135
|
}
|
|
40074
40136
|
rmSync6(markerPath, { force: true });
|
|
@@ -40076,7 +40138,7 @@ async function cleanAndInstallGitDependencies(context, targetDir, markerPath) {
|
|
|
40076
40138
|
async function installGit(context, source, scope) {
|
|
40077
40139
|
const safeRef = source.ref ? getSafeGitRef(source.ref) : undefined;
|
|
40078
40140
|
const targetDir = getGitInstallPath(context, source, scope);
|
|
40079
|
-
if (
|
|
40141
|
+
if (existsSync28(targetDir)) {
|
|
40080
40142
|
if (safeRef) {
|
|
40081
40143
|
await ensureGitRef(context, targetDir, ["fetch", "origin", "--", safeRef], "FETCH_HEAD");
|
|
40082
40144
|
return;
|
|
@@ -40089,7 +40151,7 @@ async function installGit(context, source, scope) {
|
|
|
40089
40151
|
if (gitRoot) {
|
|
40090
40152
|
ensureGitIgnore(gitRoot);
|
|
40091
40153
|
}
|
|
40092
|
-
mkdirSync10(
|
|
40154
|
+
mkdirSync10(dirname17(targetDir), { recursive: true });
|
|
40093
40155
|
rmSync6(getGitUpdateMarkerPath(targetDir), { force: true });
|
|
40094
40156
|
const cloneUrl = source.repo;
|
|
40095
40157
|
if (!/^[A-Za-z0-9._~:@/%+-]+$/.test(cloneUrl)) {
|
|
@@ -40100,8 +40162,8 @@ async function installGit(context, source, scope) {
|
|
|
40100
40162
|
if (safeRef) {
|
|
40101
40163
|
await runGitProcess(context, "git", ["checkout", safeRef], { cwd: targetDir });
|
|
40102
40164
|
}
|
|
40103
|
-
const packageJsonPath =
|
|
40104
|
-
if (
|
|
40165
|
+
const packageJsonPath = join39(targetDir, "package.json");
|
|
40166
|
+
if (existsSync28(packageJsonPath)) {
|
|
40105
40167
|
await runNpmCommand(context, getGitDependencyInstallArgs(context), { cwd: targetDir });
|
|
40106
40168
|
}
|
|
40107
40169
|
} catch (error) {
|
|
@@ -40113,7 +40175,7 @@ async function installGit(context, source, scope) {
|
|
|
40113
40175
|
async function updateGit(context, source, scope) {
|
|
40114
40176
|
const safeRef = source.ref ? getSafeGitRef(source.ref) : undefined;
|
|
40115
40177
|
const targetDir = getExistingGitInstallPath(context, source, scope) ?? getGitInstallPath(context, source, scope);
|
|
40116
|
-
if (!
|
|
40178
|
+
if (!existsSync28(targetDir)) {
|
|
40117
40179
|
await installGit(context, source, scope);
|
|
40118
40180
|
return;
|
|
40119
40181
|
}
|
|
@@ -40137,7 +40199,7 @@ async function ensureGitRef(context, targetDir, fetchArgs, ref) {
|
|
|
40137
40199
|
});
|
|
40138
40200
|
const markerPath = getGitUpdateMarkerPath(targetDir);
|
|
40139
40201
|
if (localHead.trim() === targetHead.trim()) {
|
|
40140
|
-
if (
|
|
40202
|
+
if (existsSync28(markerPath)) {
|
|
40141
40203
|
await cleanAndInstallGitDependencies(context, targetDir, markerPath);
|
|
40142
40204
|
} else {
|
|
40143
40205
|
await repairMissingGitDependencies(context, targetDir);
|
|
@@ -40168,10 +40230,10 @@ function pruneEmptyGitParents(targetDir, installRoot) {
|
|
|
40168
40230
|
if (!installRoot)
|
|
40169
40231
|
return;
|
|
40170
40232
|
const resolvedRoot = resolve9(installRoot);
|
|
40171
|
-
let current =
|
|
40233
|
+
let current = dirname17(targetDir);
|
|
40172
40234
|
while (current.startsWith(resolvedRoot) && current !== resolvedRoot) {
|
|
40173
|
-
if (!
|
|
40174
|
-
current =
|
|
40235
|
+
if (!existsSync28(current)) {
|
|
40236
|
+
current = dirname17(current);
|
|
40175
40237
|
continue;
|
|
40176
40238
|
}
|
|
40177
40239
|
const entries = readdirSync7(current);
|
|
@@ -40182,7 +40244,7 @@ function pruneEmptyGitParents(targetDir, installRoot) {
|
|
|
40182
40244
|
} catch {
|
|
40183
40245
|
break;
|
|
40184
40246
|
}
|
|
40185
|
-
current =
|
|
40247
|
+
current = dirname17(current);
|
|
40186
40248
|
}
|
|
40187
40249
|
}
|
|
40188
40250
|
async function gitHasAvailableUpdate(context, installedPath) {
|
|
@@ -40637,7 +40699,7 @@ var init_package_manager_source = __esm(() => {
|
|
|
40637
40699
|
});
|
|
40638
40700
|
|
|
40639
40701
|
// src/core/package-manager-operations.ts
|
|
40640
|
-
import { existsSync as
|
|
40702
|
+
import { existsSync as existsSync29 } from "node:fs";
|
|
40641
40703
|
async function install2(context, source, options) {
|
|
40642
40704
|
const parsed = parseSource(source);
|
|
40643
40705
|
const scope = options?.local ? "project" : "user";
|
|
@@ -40653,7 +40715,7 @@ async function install2(context, source, options) {
|
|
|
40653
40715
|
}
|
|
40654
40716
|
if (parsed.type === "local") {
|
|
40655
40717
|
const resolved = resolveManagerPath(context, parsed.path);
|
|
40656
|
-
if (!
|
|
40718
|
+
if (!existsSync29(resolved)) {
|
|
40657
40719
|
throw new Error(`Path does not exist: ${resolved}`);
|
|
40658
40720
|
}
|
|
40659
40721
|
return;
|
|
@@ -40763,7 +40825,7 @@ async function updateConfiguredSources(context, sources) {
|
|
|
40763
40825
|
}
|
|
40764
40826
|
async function shouldUpdateNpmSource(context, source, scope) {
|
|
40765
40827
|
const installedPath = getManagedNpmInstallPath(context, source, scope);
|
|
40766
|
-
const installedVersion =
|
|
40828
|
+
const installedVersion = existsSync29(installedPath) ? getInstalledNpmVersion(installedPath) : undefined;
|
|
40767
40829
|
if (!installedVersion)
|
|
40768
40830
|
return true;
|
|
40769
40831
|
try {
|
|
@@ -40800,7 +40862,7 @@ async function checkForAvailableUpdates(context) {
|
|
|
40800
40862
|
return;
|
|
40801
40863
|
if (parsed.type === "npm") {
|
|
40802
40864
|
const installedPath2 = getNpmInstallPath(context, parsed, entry.scope);
|
|
40803
|
-
if (!
|
|
40865
|
+
if (!existsSync29(installedPath2))
|
|
40804
40866
|
return;
|
|
40805
40867
|
const hasUpdate2 = await npmHasAvailableUpdate(context, parsed, installedPath2);
|
|
40806
40868
|
if (!hasUpdate2)
|
|
@@ -40898,7 +40960,7 @@ var init_package_manager_resource_accumulator = __esm(() => {
|
|
|
40898
40960
|
});
|
|
40899
40961
|
|
|
40900
40962
|
// src/core/package-manager-resource-patterns.ts
|
|
40901
|
-
import { basename as basename9, dirname as
|
|
40963
|
+
import { basename as basename9, dirname as dirname18, relative as relative9, sep as sep8 } from "node:path";
|
|
40902
40964
|
import { minimatch } from "minimatch";
|
|
40903
40965
|
function toPosixPath4(p) {
|
|
40904
40966
|
return p.split(sep8).join("/");
|
|
@@ -40929,7 +40991,7 @@ function matchesAnyPattern(filePath, patterns, baseDir) {
|
|
|
40929
40991
|
const name = basename9(filePath);
|
|
40930
40992
|
const filePathPosix = toPosixPath4(filePath);
|
|
40931
40993
|
const isSkillFile = name === "SKILL.md";
|
|
40932
|
-
const parentDir = isSkillFile ?
|
|
40994
|
+
const parentDir = isSkillFile ? dirname18(filePath) : undefined;
|
|
40933
40995
|
const parentRel = isSkillFile ? toPosixPath4(relative9(baseDir, parentDir)) : undefined;
|
|
40934
40996
|
const parentName = isSkillFile ? basename9(parentDir) : undefined;
|
|
40935
40997
|
const parentDirPosix = isSkillFile ? toPosixPath4(parentDir) : undefined;
|
|
@@ -40954,7 +41016,7 @@ function matchesAnyExactPattern(filePath, patterns, baseDir) {
|
|
|
40954
41016
|
const name = basename9(filePath);
|
|
40955
41017
|
const filePathPosix = toPosixPath4(filePath);
|
|
40956
41018
|
const isSkillFile = name === "SKILL.md";
|
|
40957
|
-
const parentDir = isSkillFile ?
|
|
41019
|
+
const parentDir = isSkillFile ? dirname18(filePath) : undefined;
|
|
40958
41020
|
const parentRel = isSkillFile ? toPosixPath4(relative9(baseDir, parentDir)) : undefined;
|
|
40959
41021
|
const parentDirPosix = isSkillFile ? toPosixPath4(parentDir) : undefined;
|
|
40960
41022
|
return patterns.some((pattern) => {
|
|
@@ -41055,7 +41117,7 @@ var init_package_manager_types = __esm(() => {
|
|
|
41055
41117
|
|
|
41056
41118
|
// src/core/package-manager-resource-files.ts
|
|
41057
41119
|
import { access as access2, readdir as readdir3, readFile as readFile2, stat as stat3 } from "node:fs/promises";
|
|
41058
|
-
import { dirname as
|
|
41120
|
+
import { dirname as dirname19, join as join40, relative as relative10, resolve as resolve10, sep as sep9 } from "node:path";
|
|
41059
41121
|
import ignore2 from "ignore";
|
|
41060
41122
|
async function exists(path12) {
|
|
41061
41123
|
try {
|
|
@@ -41086,7 +41148,7 @@ async function addIgnoreRules(ig, dir, rootDir) {
|
|
|
41086
41148
|
const prefix = relativeDir ? `${toPosixPath4(relativeDir)}/` : "";
|
|
41087
41149
|
for (const filename of IGNORE_FILE_NAMES) {
|
|
41088
41150
|
try {
|
|
41089
|
-
const content = await readFile2(
|
|
41151
|
+
const content = await readFile2(join40(dir, filename), "utf-8");
|
|
41090
41152
|
const patterns = content.split(/\r?\n/).map((line) => prefixIgnorePattern(line, prefix)).filter((line) => Boolean(line));
|
|
41091
41153
|
if (patterns.length > 0)
|
|
41092
41154
|
ig.add(patterns);
|
|
@@ -41094,7 +41156,7 @@ async function addIgnoreRules(ig, dir, rootDir) {
|
|
|
41094
41156
|
}
|
|
41095
41157
|
}
|
|
41096
41158
|
async function getEntryInfo(dir, name, isDirectory, isFileEntry, isSymlink) {
|
|
41097
|
-
const fullPath =
|
|
41159
|
+
const fullPath = join40(dir, name);
|
|
41098
41160
|
let isDir = isDirectory;
|
|
41099
41161
|
let isFile = isFileEntry;
|
|
41100
41162
|
if (isSymlink) {
|
|
@@ -41184,9 +41246,9 @@ async function collectAutoSkillEntries(dir, mode) {
|
|
|
41184
41246
|
async function findGitRepoRoot(startDir) {
|
|
41185
41247
|
let dir = resolve10(startDir);
|
|
41186
41248
|
while (true) {
|
|
41187
|
-
if (await exists(
|
|
41249
|
+
if (await exists(join40(dir, ".git")))
|
|
41188
41250
|
return dir;
|
|
41189
|
-
const parent =
|
|
41251
|
+
const parent = dirname19(dir);
|
|
41190
41252
|
if (parent === dir)
|
|
41191
41253
|
return null;
|
|
41192
41254
|
dir = parent;
|
|
@@ -41198,10 +41260,10 @@ async function collectAncestorAgentsSkillDirs(startDir) {
|
|
|
41198
41260
|
const gitRepoRoot = await findGitRepoRoot(resolvedStartDir);
|
|
41199
41261
|
let dir = resolvedStartDir;
|
|
41200
41262
|
while (true) {
|
|
41201
|
-
skillDirs.push(
|
|
41263
|
+
skillDirs.push(join40(dir, ".agents", "skills"));
|
|
41202
41264
|
if (gitRepoRoot && dir === gitRepoRoot)
|
|
41203
41265
|
break;
|
|
41204
|
-
const parent =
|
|
41266
|
+
const parent = dirname19(dir);
|
|
41205
41267
|
if (parent === dir)
|
|
41206
41268
|
break;
|
|
41207
41269
|
dir = parent;
|
|
@@ -41240,7 +41302,7 @@ async function collectAutoThemeEntries(dir) {
|
|
|
41240
41302
|
return collectFlatEntries(dir, ".json");
|
|
41241
41303
|
}
|
|
41242
41304
|
async function resolveExtensionEntries(dir) {
|
|
41243
|
-
const packageJsonPath =
|
|
41305
|
+
const packageJsonPath = join40(dir, "package.json");
|
|
41244
41306
|
if (await exists(packageJsonPath)) {
|
|
41245
41307
|
try {
|
|
41246
41308
|
const manifest = getManifestFromPackageJson(JSON.parse(await readFile2(packageJsonPath, "utf-8")));
|
|
@@ -41256,8 +41318,8 @@ async function resolveExtensionEntries(dir) {
|
|
|
41256
41318
|
}
|
|
41257
41319
|
} catch {}
|
|
41258
41320
|
}
|
|
41259
|
-
const indexTs =
|
|
41260
|
-
const indexJs =
|
|
41321
|
+
const indexTs = join40(dir, "index.ts");
|
|
41322
|
+
const indexJs = join40(dir, "index.js");
|
|
41261
41323
|
if (await exists(indexTs))
|
|
41262
41324
|
return [indexTs];
|
|
41263
41325
|
if (await exists(indexJs))
|
|
@@ -41315,7 +41377,7 @@ var init_package_manager_resource_files = __esm(() => {
|
|
|
41315
41377
|
});
|
|
41316
41378
|
|
|
41317
41379
|
// src/core/package-manager-auto-resources.ts
|
|
41318
|
-
import { dirname as
|
|
41380
|
+
import { dirname as dirname20, join as join41, resolve as resolve11 } from "node:path";
|
|
41319
41381
|
async function collectProjectLocalResources(sourceRoot, accumulator, filter, metadata) {
|
|
41320
41382
|
let found = false;
|
|
41321
41383
|
const projectMetadata = { ...metadata, origin: "top-level", borrowedProjectLocal: true };
|
|
@@ -41330,14 +41392,14 @@ async function collectProjectLocalResources(sourceRoot, accumulator, filter, met
|
|
|
41330
41392
|
};
|
|
41331
41393
|
for (const configDir of getProjectConfigDirs(sourceRoot)) {
|
|
41332
41394
|
const configMetadata = { ...projectMetadata, baseDir: configDir };
|
|
41333
|
-
addResources("extensions", await collectAutoExtensionEntries(
|
|
41334
|
-
addResources("skills", await collectAutoSkillEntries(
|
|
41335
|
-
addResources("prompts", await collectAutoPromptEntries(
|
|
41336
|
-
addResources("themes", await collectAutoThemeEntries(
|
|
41337
|
-
addResources("workflows", await collectResourceFiles(
|
|
41338
|
-
}
|
|
41339
|
-
const agentsSkillsDir =
|
|
41340
|
-
addResources("skills", await collectAutoSkillEntries(agentsSkillsDir, "agents"), { ...projectMetadata, baseDir:
|
|
41395
|
+
addResources("extensions", await collectAutoExtensionEntries(join41(configDir, "extensions")), configMetadata, filter?.extensions);
|
|
41396
|
+
addResources("skills", await collectAutoSkillEntries(join41(configDir, "skills"), "pi"), configMetadata, filter?.skills);
|
|
41397
|
+
addResources("prompts", await collectAutoPromptEntries(join41(configDir, "prompts")), configMetadata, filter?.prompts);
|
|
41398
|
+
addResources("themes", await collectAutoThemeEntries(join41(configDir, "themes")), configMetadata, filter?.themes);
|
|
41399
|
+
addResources("workflows", await collectResourceFiles(join41(configDir, "workflows"), "workflows"), configMetadata, filter?.workflows);
|
|
41400
|
+
}
|
|
41401
|
+
const agentsSkillsDir = join41(sourceRoot, ".agents", "skills");
|
|
41402
|
+
addResources("skills", await collectAutoSkillEntries(agentsSkillsDir, "agents"), { ...projectMetadata, baseDir: dirname20(agentsSkillsDir) }, filter?.skills);
|
|
41341
41403
|
return found;
|
|
41342
41404
|
}
|
|
41343
41405
|
async function addAutoDiscoveredResources(context, accumulator, globalSettings, projectSettings, globalBaseDir, projectBaseDir) {
|
|
@@ -41364,7 +41426,7 @@ async function addAutoDiscoveredResources(context, accumulator, globalSettings,
|
|
|
41364
41426
|
};
|
|
41365
41427
|
const userConfigDirs = getBaseDirsForScope(context, "user");
|
|
41366
41428
|
const projectConfigDirs = getBaseDirsForScope(context, "project");
|
|
41367
|
-
const userAgentsSkillsDir =
|
|
41429
|
+
const userAgentsSkillsDir = join41(getHomeDir2(), ".agents", "skills");
|
|
41368
41430
|
const projectTrusted = context.settingsManager.isProjectTrusted();
|
|
41369
41431
|
const projectAgentsSkillDirs = projectTrusted ? (await collectAncestorAgentsSkillDirs(context.cwd)).filter((dir) => resolve11(dir) !== resolve11(userAgentsSkillsDir)) : [];
|
|
41370
41432
|
const addResources = (resourceType, paths, metadata, overrides, baseDir) => {
|
|
@@ -41379,15 +41441,15 @@ async function addAutoDiscoveredResources(context, accumulator, globalSettings,
|
|
|
41379
41441
|
baseDir: configDir,
|
|
41380
41442
|
configurationOrigin: index === 0 ? "atomic" : "inherited-pi"
|
|
41381
41443
|
};
|
|
41382
|
-
addResources("extensions", await collectAutoExtensionEntries(
|
|
41383
|
-
addResources("skills", await collectAutoSkillEntries(
|
|
41384
|
-
addResources("prompts", await collectAutoPromptEntries(
|
|
41385
|
-
addResources("themes", await collectAutoThemeEntries(
|
|
41386
|
-
addResources("workflows", await collectResourceFiles(
|
|
41444
|
+
addResources("extensions", await collectAutoExtensionEntries(join41(configDir, "extensions")), metadata, projectOverrides.extensions, configDir);
|
|
41445
|
+
addResources("skills", await collectAutoSkillEntries(join41(configDir, "skills"), "pi"), metadata, projectOverrides.skills, configDir);
|
|
41446
|
+
addResources("prompts", await collectAutoPromptEntries(join41(configDir, "prompts")), metadata, projectOverrides.prompts, configDir);
|
|
41447
|
+
addResources("themes", await collectAutoThemeEntries(join41(configDir, "themes")), metadata, projectOverrides.themes, configDir);
|
|
41448
|
+
addResources("workflows", await collectResourceFiles(join41(configDir, "workflows"), "workflows"), metadata, projectOverrides.workflows, configDir);
|
|
41387
41449
|
}
|
|
41388
41450
|
}
|
|
41389
41451
|
for (const agentsSkillsDir of projectAgentsSkillDirs) {
|
|
41390
|
-
const agentsBaseDir =
|
|
41452
|
+
const agentsBaseDir = dirname20(agentsSkillsDir);
|
|
41391
41453
|
addResources("skills", await collectAutoSkillEntries(agentsSkillsDir, "agents"), { ...projectMetadata, baseDir: agentsBaseDir }, projectOverrides.skills, agentsBaseDir);
|
|
41392
41454
|
}
|
|
41393
41455
|
for (const [index, configDir] of userConfigDirs.entries()) {
|
|
@@ -41396,13 +41458,13 @@ async function addAutoDiscoveredResources(context, accumulator, globalSettings,
|
|
|
41396
41458
|
baseDir: configDir,
|
|
41397
41459
|
configurationOrigin: index === 0 ? "atomic" : "inherited-pi"
|
|
41398
41460
|
};
|
|
41399
|
-
addResources("extensions", await collectAutoExtensionEntries(
|
|
41400
|
-
addResources("skills", await collectAutoSkillEntries(
|
|
41401
|
-
addResources("prompts", await collectAutoPromptEntries(
|
|
41402
|
-
addResources("themes", await collectAutoThemeEntries(
|
|
41403
|
-
addResources("workflows", await collectResourceFiles(
|
|
41461
|
+
addResources("extensions", await collectAutoExtensionEntries(join41(configDir, "extensions")), metadata, userOverrides.extensions, configDir);
|
|
41462
|
+
addResources("skills", await collectAutoSkillEntries(join41(configDir, "skills"), "pi"), metadata, userOverrides.skills, configDir);
|
|
41463
|
+
addResources("prompts", await collectAutoPromptEntries(join41(configDir, "prompts")), metadata, userOverrides.prompts, configDir);
|
|
41464
|
+
addResources("themes", await collectAutoThemeEntries(join41(configDir, "themes")), metadata, userOverrides.themes, configDir);
|
|
41465
|
+
addResources("workflows", await collectResourceFiles(join41(configDir, "workflows"), "workflows"), metadata, userOverrides.workflows, configDir);
|
|
41404
41466
|
}
|
|
41405
|
-
const userAgentsBaseDir =
|
|
41467
|
+
const userAgentsBaseDir = dirname20(userAgentsSkillsDir);
|
|
41406
41468
|
addResources("skills", await collectAutoSkillEntries(userAgentsSkillsDir, "agents"), { ...userMetadata, baseDir: userAgentsBaseDir }, userOverrides.skills, userAgentsBaseDir);
|
|
41407
41469
|
}
|
|
41408
41470
|
var init_package_manager_auto_resources = __esm(() => {
|
|
@@ -41571,7 +41633,7 @@ var init_package_manager_resource_collector = __esm(() => {
|
|
|
41571
41633
|
|
|
41572
41634
|
// src/core/package-manager-resolver.ts
|
|
41573
41635
|
import { access as access4, stat as stat5 } from "node:fs/promises";
|
|
41574
|
-
import { dirname as
|
|
41636
|
+
import { dirname as dirname21, isAbsolute as isAbsolute7, join as join42 } from "node:path";
|
|
41575
41637
|
async function exists3(path12) {
|
|
41576
41638
|
try {
|
|
41577
41639
|
await access4(path12);
|
|
@@ -41594,7 +41656,7 @@ async function resolvePackages(context, onMissing) {
|
|
|
41594
41656
|
const packageSources = dedupePackages(context, allPackages);
|
|
41595
41657
|
await resolvePackageSources(context, packageSources, accumulator, onMissing, { settingsField: "packages" });
|
|
41596
41658
|
const globalBaseDir = context.agentDir;
|
|
41597
|
-
const projectBaseDir =
|
|
41659
|
+
const projectBaseDir = join42(context.cwd, CONFIG_DIR_NAME);
|
|
41598
41660
|
const globalBaseDirs = getBaseDirsForScope(context, "user");
|
|
41599
41661
|
const projectBaseDirs = getBaseDirsForScope(context, "project");
|
|
41600
41662
|
for (const resourceType of ["extensions", "skills", "prompts", "themes", "workflows"]) {
|
|
@@ -41729,7 +41791,7 @@ async function resolveLocalExtensionSource(source, accumulator, filter, metadata
|
|
|
41729
41791
|
try {
|
|
41730
41792
|
const stats = await stat5(resolved);
|
|
41731
41793
|
if (stats.isFile()) {
|
|
41732
|
-
addResource(accumulator.extensions, resolved, { ...metadata, baseDir:
|
|
41794
|
+
addResource(accumulator.extensions, resolved, { ...metadata, baseDir: dirname21(resolved) }, true);
|
|
41733
41795
|
return;
|
|
41734
41796
|
}
|
|
41735
41797
|
if (stats.isDirectory()) {
|
|
@@ -41760,7 +41822,7 @@ var init_package_manager_resolver = __esm(() => {
|
|
|
41760
41822
|
});
|
|
41761
41823
|
|
|
41762
41824
|
// src/core/package-manager-settings.ts
|
|
41763
|
-
import { existsSync as
|
|
41825
|
+
import { existsSync as existsSync30 } from "node:fs";
|
|
41764
41826
|
function addSourceToSettings(context, source, options) {
|
|
41765
41827
|
const scope = options?.local ? "project" : "user";
|
|
41766
41828
|
const currentSettings = scope === "project" ? context.settingsManager.getProjectSettings() : context.settingsManager.getGlobalSettings();
|
|
@@ -41814,7 +41876,7 @@ function getInstalledPath(context, source, scope) {
|
|
|
41814
41876
|
}
|
|
41815
41877
|
for (const baseDir of getBaseDirsForScope(context, scope)) {
|
|
41816
41878
|
const path12 = resolvePathFromBase(parsed.path, baseDir);
|
|
41817
|
-
if (
|
|
41879
|
+
if (existsSync30(path12))
|
|
41818
41880
|
return path12;
|
|
41819
41881
|
}
|
|
41820
41882
|
return;
|
|
@@ -42038,29 +42100,29 @@ var init_package_manager = __esm(() => {
|
|
|
42038
42100
|
|
|
42039
42101
|
// src/core/footer-data-provider.ts
|
|
42040
42102
|
import { execFile, spawnSync as spawnSync6 } from "child_process";
|
|
42041
|
-
import { existsSync as
|
|
42042
|
-
import { dirname as
|
|
42103
|
+
import { existsSync as existsSync31, readFileSync as readFileSync20, statSync as statSync7, unwatchFile as unwatchFile2, watchFile as watchFile2 } from "fs";
|
|
42104
|
+
import { dirname as dirname22, join as join43, resolve as resolve13 } from "path";
|
|
42043
42105
|
function findGitPaths(cwd) {
|
|
42044
42106
|
let dir = cwd;
|
|
42045
42107
|
while (true) {
|
|
42046
|
-
const gitPath =
|
|
42047
|
-
if (
|
|
42108
|
+
const gitPath = join43(dir, ".git");
|
|
42109
|
+
if (existsSync31(gitPath)) {
|
|
42048
42110
|
try {
|
|
42049
42111
|
const stat6 = statSync7(gitPath);
|
|
42050
42112
|
if (stat6.isFile()) {
|
|
42051
|
-
const content =
|
|
42113
|
+
const content = readFileSync20(gitPath, "utf8").trim();
|
|
42052
42114
|
if (content.startsWith("gitdir: ")) {
|
|
42053
42115
|
const gitDir = resolve13(dir, content.slice(8).trim());
|
|
42054
|
-
const headPath =
|
|
42055
|
-
if (!
|
|
42116
|
+
const headPath = join43(gitDir, "HEAD");
|
|
42117
|
+
if (!existsSync31(headPath))
|
|
42056
42118
|
return null;
|
|
42057
|
-
const commonDirPath =
|
|
42058
|
-
const commonGitDir =
|
|
42119
|
+
const commonDirPath = join43(gitDir, "commondir");
|
|
42120
|
+
const commonGitDir = existsSync31(commonDirPath) ? resolve13(gitDir, readFileSync20(commonDirPath, "utf8").trim()) : gitDir;
|
|
42059
42121
|
return { repoDir: dir, commonGitDir, headPath };
|
|
42060
42122
|
}
|
|
42061
42123
|
} else if (stat6.isDirectory()) {
|
|
42062
|
-
const headPath =
|
|
42063
|
-
if (!
|
|
42124
|
+
const headPath = join43(gitPath, "HEAD");
|
|
42125
|
+
if (!existsSync31(headPath))
|
|
42064
42126
|
return null;
|
|
42065
42127
|
return { repoDir: dir, commonGitDir: gitPath, headPath };
|
|
42066
42128
|
}
|
|
@@ -42068,7 +42130,7 @@ function findGitPaths(cwd) {
|
|
|
42068
42130
|
return null;
|
|
42069
42131
|
}
|
|
42070
42132
|
}
|
|
42071
|
-
const parent =
|
|
42133
|
+
const parent = dirname22(dir);
|
|
42072
42134
|
if (parent === dir)
|
|
42073
42135
|
return null;
|
|
42074
42136
|
dir = parent;
|
|
@@ -42252,7 +42314,7 @@ class FooterDataProvider {
|
|
|
42252
42314
|
try {
|
|
42253
42315
|
if (!this.gitPaths)
|
|
42254
42316
|
return null;
|
|
42255
|
-
const content =
|
|
42317
|
+
const content = readFileSync20(this.gitPaths.headPath, "utf8").trim();
|
|
42256
42318
|
if (content.startsWith("ref: refs/heads/")) {
|
|
42257
42319
|
const branch = content.slice(16);
|
|
42258
42320
|
return branch === ".invalid" ? resolveBranchWithGitSync(this.gitPaths.repoDir) ?? "detached" : branch;
|
|
@@ -42266,7 +42328,7 @@ class FooterDataProvider {
|
|
|
42266
42328
|
try {
|
|
42267
42329
|
if (!this.gitPaths)
|
|
42268
42330
|
return null;
|
|
42269
|
-
const content =
|
|
42331
|
+
const content = readFileSync20(this.gitPaths.headPath, "utf8").trim();
|
|
42270
42332
|
if (content.startsWith("ref: refs/heads/")) {
|
|
42271
42333
|
const branch = content.slice(16);
|
|
42272
42334
|
return branch === ".invalid" ? await resolveBranchWithGitAsync(this.gitPaths.repoDir) ?? "detached" : branch;
|
|
@@ -42337,12 +42399,12 @@ class FooterDataProvider {
|
|
|
42337
42399
|
this.scheduleGitWatcherRetry();
|
|
42338
42400
|
}
|
|
42339
42401
|
readReftableTablesListFingerprint() {
|
|
42340
|
-
if (!this.reftableTablesListPath || !
|
|
42402
|
+
if (!this.reftableTablesListPath || !existsSync31(this.reftableTablesListPath)) {
|
|
42341
42403
|
return null;
|
|
42342
42404
|
}
|
|
42343
42405
|
try {
|
|
42344
42406
|
const stat6 = statSync7(this.reftableTablesListPath);
|
|
42345
|
-
const content =
|
|
42407
|
+
const content = readFileSync20(this.reftableTablesListPath, "utf8");
|
|
42346
42408
|
return `${stat6.size}:${stat6.mtimeMs}:${stat6.ctimeMs}:${content}`;
|
|
42347
42409
|
} catch {
|
|
42348
42410
|
return null;
|
|
@@ -42369,7 +42431,7 @@ class FooterDataProvider {
|
|
|
42369
42431
|
if (!this.gitPaths)
|
|
42370
42432
|
return;
|
|
42371
42433
|
const pollGitHead = shouldPollGitHead(this.gitPaths.repoDir);
|
|
42372
|
-
this.headWatcher = watchWithErrorHandler(
|
|
42434
|
+
this.headWatcher = watchWithErrorHandler(dirname22(this.gitPaths.headPath), (_eventType, filename) => {
|
|
42373
42435
|
if (!filename || filename === "HEAD") {
|
|
42374
42436
|
this.scheduleRefresh();
|
|
42375
42437
|
}
|
|
@@ -42386,9 +42448,9 @@ class FooterDataProvider {
|
|
|
42386
42448
|
if (!this.headWatcher && !this.headWatchFileListener) {
|
|
42387
42449
|
return;
|
|
42388
42450
|
}
|
|
42389
|
-
const reftableDir =
|
|
42390
|
-
if (
|
|
42391
|
-
this.reftableTablesListPath =
|
|
42451
|
+
const reftableDir = join43(this.gitPaths.commonGitDir, "reftable");
|
|
42452
|
+
if (existsSync31(reftableDir)) {
|
|
42453
|
+
this.reftableTablesListPath = join43(reftableDir, "tables.list");
|
|
42392
42454
|
this.reftableTablesListFingerprint = this.readReftableTablesListFingerprint();
|
|
42393
42455
|
this.reftableWatcher = watchWithErrorHandler(reftableDir, (_eventType, filename) => {
|
|
42394
42456
|
this.handleReftableDirectoryEvent(filename);
|
|
@@ -42399,7 +42461,7 @@ class FooterDataProvider {
|
|
|
42399
42461
|
this.handleGitWatcherError();
|
|
42400
42462
|
});
|
|
42401
42463
|
const tablesListPath = this.reftableTablesListPath;
|
|
42402
|
-
if (tablesListPath &&
|
|
42464
|
+
if (tablesListPath && existsSync31(tablesListPath)) {
|
|
42403
42465
|
this.reftableTablesListWatcher = watchWithErrorHandler(tablesListPath, () => {
|
|
42404
42466
|
this.scheduleReftableRefresh();
|
|
42405
42467
|
}, (error) => {
|
|
@@ -42524,8 +42586,8 @@ function deepMergeSettings(base, overrides) {
|
|
|
42524
42586
|
}
|
|
42525
42587
|
|
|
42526
42588
|
// src/core/settings-storage.ts
|
|
42527
|
-
import { existsSync as
|
|
42528
|
-
import { dirname as
|
|
42589
|
+
import { existsSync as existsSync32, mkdirSync as mkdirSync11, readFileSync as readFileSync21, writeFileSync as writeFileSync12 } from "fs";
|
|
42590
|
+
import { dirname as dirname23, join as join44 } from "path";
|
|
42529
42591
|
import lockfile3 from "proper-lockfile";
|
|
42530
42592
|
|
|
42531
42593
|
class FileSettingsStorage {
|
|
@@ -42536,18 +42598,18 @@ class FileSettingsStorage {
|
|
|
42536
42598
|
constructor(cwd, agentDir, options) {
|
|
42537
42599
|
const resolvedCwd = resolvePath(cwd);
|
|
42538
42600
|
const resolvedAgentDir = resolvePath(agentDir);
|
|
42539
|
-
this.globalSettingsPath =
|
|
42540
|
-
this.projectSettingsPath =
|
|
42601
|
+
this.globalSettingsPath = join44(resolvedAgentDir, "settings.json");
|
|
42602
|
+
this.projectSettingsPath = join44(resolvedCwd, CONFIG_DIR_NAME, "settings.json");
|
|
42541
42603
|
this.globalReadPaths = (options?.globalReadPaths ?? [this.globalSettingsPath]).map((path12) => normalizePath(path12));
|
|
42542
42604
|
this.projectReadPaths = (options?.projectReadPaths ?? [this.projectSettingsPath]).map((path12) => normalizePath(path12));
|
|
42543
42605
|
}
|
|
42544
42606
|
getFieldOrigin(scope, field2) {
|
|
42545
42607
|
const readPaths = scope === "global" ? this.globalReadPaths : this.projectReadPaths;
|
|
42546
42608
|
for (const [index, readPath] of readPaths.entries()) {
|
|
42547
|
-
if (!
|
|
42609
|
+
if (!existsSync32(readPath))
|
|
42548
42610
|
continue;
|
|
42549
42611
|
try {
|
|
42550
|
-
const parsed = parseJsonFileContent(
|
|
42612
|
+
const parsed = parseJsonFileContent(readFileSync21(readPath, "utf-8"));
|
|
42551
42613
|
if (Object.hasOwn(parsed, field2)) {
|
|
42552
42614
|
return index === 0 ? "primary" : "legacy";
|
|
42553
42615
|
}
|
|
@@ -42581,9 +42643,9 @@ class FileSettingsStorage {
|
|
|
42581
42643
|
let found = false;
|
|
42582
42644
|
for (let i = readPaths.length - 1;i >= 0; i--) {
|
|
42583
42645
|
const readPath = readPaths[i];
|
|
42584
|
-
if (!
|
|
42646
|
+
if (!existsSync32(readPath))
|
|
42585
42647
|
continue;
|
|
42586
|
-
const parsed = parseJsonFileContent(
|
|
42648
|
+
const parsed = parseJsonFileContent(readFileSync21(readPath, "utf-8"));
|
|
42587
42649
|
merged = deepMergeSettings(merged, parsed);
|
|
42588
42650
|
found = true;
|
|
42589
42651
|
}
|
|
@@ -42592,21 +42654,21 @@ class FileSettingsStorage {
|
|
|
42592
42654
|
withLock(scope, fn) {
|
|
42593
42655
|
const path12 = scope === "global" ? this.globalSettingsPath : this.projectSettingsPath;
|
|
42594
42656
|
const readPaths = scope === "global" ? this.globalReadPaths : this.projectReadPaths;
|
|
42595
|
-
const dir =
|
|
42657
|
+
const dir = dirname23(path12);
|
|
42596
42658
|
let release;
|
|
42597
42659
|
try {
|
|
42598
|
-
const fileExists2 =
|
|
42660
|
+
const fileExists2 = existsSync32(path12);
|
|
42599
42661
|
if (fileExists2) {
|
|
42600
42662
|
release = this.acquireLockSyncWithRetry(path12);
|
|
42601
42663
|
}
|
|
42602
42664
|
const current = this.readMergedSettings(readPaths);
|
|
42603
42665
|
const next = fn(current);
|
|
42604
42666
|
if (next !== undefined) {
|
|
42605
|
-
if (!
|
|
42667
|
+
if (!existsSync32(dir)) {
|
|
42606
42668
|
mkdirSync11(dir, { recursive: true });
|
|
42607
42669
|
}
|
|
42608
42670
|
if (!release) {
|
|
42609
|
-
if (!
|
|
42671
|
+
if (!existsSync32(path12))
|
|
42610
42672
|
writeFileSync12(path12, "{}", "utf-8");
|
|
42611
42673
|
release = this.acquireLockSyncWithRetry(path12);
|
|
42612
42674
|
}
|
|
@@ -42646,7 +42708,7 @@ var init_settings_storage = __esm(() => {
|
|
|
42646
42708
|
});
|
|
42647
42709
|
|
|
42648
42710
|
// src/core/settings-manager-core.ts
|
|
42649
|
-
import { join as
|
|
42711
|
+
import { join as join45 } from "path";
|
|
42650
42712
|
|
|
42651
42713
|
class SettingsManager {
|
|
42652
42714
|
storage;
|
|
@@ -42684,7 +42746,7 @@ class SettingsManager {
|
|
|
42684
42746
|
}
|
|
42685
42747
|
static create(cwd, agentDir = getAgentDir(), options = {}) {
|
|
42686
42748
|
const storage = new FileSettingsStorage(cwd, agentDir, {
|
|
42687
|
-
globalReadPaths: agentDir === getAgentDir() ? getAgentConfigPaths("settings.json") : [
|
|
42749
|
+
globalReadPaths: agentDir === getAgentDir() ? getAgentConfigPaths("settings.json") : [join45(agentDir, "settings.json")],
|
|
42688
42750
|
projectReadPaths: getProjectConfigPaths(cwd, "settings.json")
|
|
42689
42751
|
});
|
|
42690
42752
|
return SettingsManager.fromStorage(storage, options);
|
|
@@ -44398,14 +44460,14 @@ var init_agent_session_runtime_auth = __esm(() => {
|
|
|
44398
44460
|
});
|
|
44399
44461
|
|
|
44400
44462
|
// src/core/session-cwd.ts
|
|
44401
|
-
import { existsSync as
|
|
44463
|
+
import { existsSync as existsSync33 } from "node:fs";
|
|
44402
44464
|
function getMissingSessionCwdIssue(sessionManager, fallbackCwd) {
|
|
44403
44465
|
const sessionFile = sessionManager.getSessionFile();
|
|
44404
44466
|
if (!sessionFile) {
|
|
44405
44467
|
return;
|
|
44406
44468
|
}
|
|
44407
44469
|
const sessionCwd = sessionManager.getCwd();
|
|
44408
|
-
if (!sessionCwd ||
|
|
44470
|
+
if (!sessionCwd || existsSync33(sessionCwd)) {
|
|
44409
44471
|
return;
|
|
44410
44472
|
}
|
|
44411
44473
|
return {
|
|
@@ -44457,8 +44519,8 @@ var init_agent_session_services = __esm(() => {
|
|
|
44457
44519
|
});
|
|
44458
44520
|
|
|
44459
44521
|
// src/core/agent-session-runtime.ts
|
|
44460
|
-
import { copyFileSync, existsSync as
|
|
44461
|
-
import { basename as basename10, join as
|
|
44522
|
+
import { copyFileSync, existsSync as existsSync34, mkdirSync as mkdirSync12 } from "node:fs";
|
|
44523
|
+
import { basename as basename10, join as join46, resolve as resolve14 } from "node:path";
|
|
44462
44524
|
import { modelsAreEqual as modelsAreEqual5 } from "@bastani/pi-ai/compat";
|
|
44463
44525
|
function extractUserMessageText(content) {
|
|
44464
44526
|
if (typeof content === "string") {
|
|
@@ -44674,7 +44736,7 @@ class AgentSessionRuntime {
|
|
|
44674
44736
|
await this.finishSessionReplacement(options?.withSession);
|
|
44675
44737
|
return { cancelled: false, selectedText };
|
|
44676
44738
|
}
|
|
44677
|
-
if (!
|
|
44739
|
+
if (!existsSync34(currentSessionFile)) {
|
|
44678
44740
|
throw new Error("This session has not been saved yet. Wait for the first assistant response before cloning or forking it.");
|
|
44679
44741
|
}
|
|
44680
44742
|
const sessionManager2 = SessionManager.open(currentSessionFile, sessionDir);
|
|
@@ -44710,14 +44772,14 @@ class AgentSessionRuntime {
|
|
|
44710
44772
|
}
|
|
44711
44773
|
async importFromJsonl(inputPath, cwdOverride) {
|
|
44712
44774
|
const resolvedPath = resolvePath(inputPath);
|
|
44713
|
-
if (!
|
|
44775
|
+
if (!existsSync34(resolvedPath)) {
|
|
44714
44776
|
throw new SessionImportFileNotFoundError(resolvedPath);
|
|
44715
44777
|
}
|
|
44716
44778
|
const sessionDir = this.session.sessionManager.getSessionDir();
|
|
44717
|
-
if (!
|
|
44779
|
+
if (!existsSync34(sessionDir)) {
|
|
44718
44780
|
mkdirSync12(sessionDir, { recursive: true });
|
|
44719
44781
|
}
|
|
44720
|
-
const destinationPath =
|
|
44782
|
+
const destinationPath = join46(sessionDir, basename10(resolvedPath));
|
|
44721
44783
|
const beforeResult = await this.emitBeforeSwitch("resume", destinationPath);
|
|
44722
44784
|
if (beforeResult.cancelled) {
|
|
44723
44785
|
return beforeResult;
|
|
@@ -56315,11 +56377,11 @@ var init_state_lease = __esm(() => {
|
|
|
56315
56377
|
|
|
56316
56378
|
// dist/builtin/mcp/agent-dir.ts
|
|
56317
56379
|
import { homedir as homedir7 } from "node:os";
|
|
56318
|
-
import { join as
|
|
56380
|
+
import { join as join47, resolve as resolve15 } from "node:path";
|
|
56319
56381
|
function getAgentDir2() {
|
|
56320
56382
|
const configured = getEnvValue(`${APP_NAME.toUpperCase()}_CODING_AGENT_DIR`)?.trim();
|
|
56321
56383
|
if (!configured) {
|
|
56322
|
-
return
|
|
56384
|
+
return join47(homedir7(), CONFIG_DIR_NAME, "agent");
|
|
56323
56385
|
}
|
|
56324
56386
|
if (configured === "~") {
|
|
56325
56387
|
return homedir7();
|
|
@@ -56334,18 +56396,18 @@ function getAgentDirs2() {
|
|
|
56334
56396
|
return configured ? [getAgentDir2()] : getAgentDirs();
|
|
56335
56397
|
}
|
|
56336
56398
|
function getAgentPath(...segments) {
|
|
56337
|
-
return
|
|
56399
|
+
return join47(getAgentDir2(), ...segments);
|
|
56338
56400
|
}
|
|
56339
56401
|
function getAgentPaths(...segments) {
|
|
56340
|
-
return getAgentDirs2().map((dir) =>
|
|
56402
|
+
return getAgentDirs2().map((dir) => join47(dir, ...segments));
|
|
56341
56403
|
}
|
|
56342
56404
|
var init_agent_dir = __esm(() => {
|
|
56343
56405
|
init_src();
|
|
56344
56406
|
});
|
|
56345
56407
|
|
|
56346
56408
|
// dist/builtin/mcp/config-write-utils.ts
|
|
56347
|
-
import { existsSync as
|
|
56348
|
-
import { dirname as
|
|
56409
|
+
import { existsSync as existsSync35, mkdirSync as mkdirSync13, readFileSync as readFileSync23, renameSync as renameSync3, writeFileSync as writeFileSync13 } from "node:fs";
|
|
56410
|
+
import { dirname as dirname24 } from "node:path";
|
|
56349
56411
|
function serializeRawConfig(raw) {
|
|
56350
56412
|
return `${JSON.stringify(raw, null, 2)}
|
|
56351
56413
|
`;
|
|
@@ -56389,7 +56451,7 @@ function buildUnifiedDiff(beforeText, afterText) {
|
|
|
56389
56451
|
`);
|
|
56390
56452
|
}
|
|
56391
56453
|
function buildConfigWritePreview(filePath, nextRaw) {
|
|
56392
|
-
const existed =
|
|
56454
|
+
const existed = existsSync35(filePath);
|
|
56393
56455
|
const beforeRaw = readRawConfigObject(filePath);
|
|
56394
56456
|
const beforeText = existed ? serializeRawConfig(beforeRaw) : "";
|
|
56395
56457
|
const afterText = serializeRawConfig(nextRaw);
|
|
@@ -56403,17 +56465,17 @@ function buildConfigWritePreview(filePath, nextRaw) {
|
|
|
56403
56465
|
};
|
|
56404
56466
|
}
|
|
56405
56467
|
function readRawConfigObject(filePath) {
|
|
56406
|
-
if (!
|
|
56468
|
+
if (!existsSync35(filePath))
|
|
56407
56469
|
return {};
|
|
56408
56470
|
try {
|
|
56409
|
-
const raw = JSON.parse(
|
|
56471
|
+
const raw = JSON.parse(readFileSync23(filePath, "utf-8"));
|
|
56410
56472
|
return raw && typeof raw === "object" && !Array.isArray(raw) ? raw : {};
|
|
56411
56473
|
} catch {
|
|
56412
56474
|
return {};
|
|
56413
56475
|
}
|
|
56414
56476
|
}
|
|
56415
56477
|
function writeRawConfigObject(filePath, raw) {
|
|
56416
|
-
mkdirSync13(
|
|
56478
|
+
mkdirSync13(dirname24(filePath), { recursive: true });
|
|
56417
56479
|
const tmpPath = `${filePath}.${process.pid}.tmp`;
|
|
56418
56480
|
writeFileSync13(tmpPath, `${JSON.stringify(raw, null, 2)}
|
|
56419
56481
|
`, "utf-8");
|
|
@@ -56504,9 +56566,9 @@ var init_tool_call_timeout = __esm(() => {
|
|
|
56504
56566
|
});
|
|
56505
56567
|
|
|
56506
56568
|
// dist/builtin/mcp/config.ts
|
|
56507
|
-
import { existsSync as
|
|
56569
|
+
import { existsSync as existsSync36, readFileSync as readFileSync24 } from "node:fs";
|
|
56508
56570
|
import { homedir as homedir8 } from "node:os";
|
|
56509
|
-
import { dirname as
|
|
56571
|
+
import { dirname as dirname25, join as join48, resolve as resolve16 } from "node:path";
|
|
56510
56572
|
function getPiGlobalConfigPath(overridePath) {
|
|
56511
56573
|
return overridePath ? resolve16(overridePath) : getAgentPath("mcp.json");
|
|
56512
56574
|
}
|
|
@@ -56526,7 +56588,7 @@ function getMcpDiscoverySummary(overridePath, cwd = process.cwd()) {
|
|
|
56526
56588
|
id: source.id,
|
|
56527
56589
|
label: source.label,
|
|
56528
56590
|
path: source.readPath,
|
|
56529
|
-
exists:
|
|
56591
|
+
exists: existsSync36(source.readPath),
|
|
56530
56592
|
scope: source.scope,
|
|
56531
56593
|
kind: source.shared ? "shared" : "pi",
|
|
56532
56594
|
serverCount: loaded ? Object.keys(loaded.mcpServers).length : 0
|
|
@@ -56653,7 +56715,7 @@ function expandImports(config, cwd = process.cwd()) {
|
|
|
56653
56715
|
if (!importPath)
|
|
56654
56716
|
continue;
|
|
56655
56717
|
try {
|
|
56656
|
-
const imported = JSON.parse(
|
|
56718
|
+
const imported = JSON.parse(readFileSync24(importPath, "utf-8"));
|
|
56657
56719
|
const servers = extractServers(imported, importKind);
|
|
56658
56720
|
for (const [name, definition] of Object.entries(servers)) {
|
|
56659
56721
|
if (!importedServers[name]) {
|
|
@@ -56676,7 +56738,7 @@ function resolveImportPath(importKind, cwd = process.cwd()) {
|
|
|
56676
56738
|
const candidates = IMPORT_PATHS[importKind] ?? [];
|
|
56677
56739
|
for (const candidate of candidates) {
|
|
56678
56740
|
const fullPath = candidate.startsWith(".") ? resolve16(cwd, candidate) : candidate;
|
|
56679
|
-
if (
|
|
56741
|
+
if (existsSync36(fullPath)) {
|
|
56680
56742
|
return fullPath;
|
|
56681
56743
|
}
|
|
56682
56744
|
}
|
|
@@ -56684,17 +56746,17 @@ function resolveImportPath(importKind, cwd = process.cwd()) {
|
|
|
56684
56746
|
}
|
|
56685
56747
|
function getImportServerCount(importKind, path13) {
|
|
56686
56748
|
try {
|
|
56687
|
-
const raw = JSON.parse(
|
|
56749
|
+
const raw = JSON.parse(readFileSync24(path13, "utf-8"));
|
|
56688
56750
|
return Object.keys(extractServers(raw, importKind)).length;
|
|
56689
56751
|
} catch {
|
|
56690
56752
|
return 0;
|
|
56691
56753
|
}
|
|
56692
56754
|
}
|
|
56693
56755
|
function readValidatedConfig(path13, label) {
|
|
56694
|
-
if (!
|
|
56756
|
+
if (!existsSync36(path13))
|
|
56695
56757
|
return null;
|
|
56696
56758
|
try {
|
|
56697
|
-
return validateMcpConfig(JSON.parse(
|
|
56759
|
+
return validateMcpConfig(JSON.parse(readFileSync24(path13, "utf-8")));
|
|
56698
56760
|
} catch (error) {
|
|
56699
56761
|
if (error instanceof McpTimeoutConfigError)
|
|
56700
56762
|
throw error;
|
|
@@ -56754,10 +56816,10 @@ function isRepoPromptServer(name, entry) {
|
|
|
56754
56816
|
function findProjectRoot(cwd = process.cwd()) {
|
|
56755
56817
|
let current = resolve16(cwd);
|
|
56756
56818
|
while (true) {
|
|
56757
|
-
if (
|
|
56819
|
+
if (existsSync36(join48(current, ".git")) || existsSync36(join48(current, "package.json")) || existsSync36(join48(current, PROJECT_CONFIG_NAME)) || existsSync36(join48(current, CONFIG_DIR_NAME))) {
|
|
56758
56820
|
return current;
|
|
56759
56821
|
}
|
|
56760
|
-
const parent =
|
|
56822
|
+
const parent = dirname25(current);
|
|
56761
56823
|
if (parent === current)
|
|
56762
56824
|
return null;
|
|
56763
56825
|
current = parent;
|
|
@@ -56783,12 +56845,12 @@ function detectRepoPrompt(summary, cwd = process.cwd()) {
|
|
|
56783
56845
|
}
|
|
56784
56846
|
}
|
|
56785
56847
|
}
|
|
56786
|
-
const executablePath = REPOPROMPT_BINARY_CANDIDATES.find((candidate) =>
|
|
56848
|
+
const executablePath = REPOPROMPT_BINARY_CANDIDATES.find((candidate) => existsSync36(candidate));
|
|
56787
56849
|
if (!executablePath) {
|
|
56788
56850
|
return { configured: false };
|
|
56789
56851
|
}
|
|
56790
56852
|
const projectRoot = findProjectRoot(cwd);
|
|
56791
|
-
const targetPath = projectRoot ?
|
|
56853
|
+
const targetPath = projectRoot ? join48(projectRoot, PROJECT_CONFIG_NAME) : GENERIC_GLOBAL_CONFIG_PATH;
|
|
56792
56854
|
return {
|
|
56793
56855
|
configured: false,
|
|
56794
56856
|
executablePath,
|
|
@@ -56866,7 +56928,7 @@ function getServerProvenance(overridePath, cwd = process.cwd()) {
|
|
|
56866
56928
|
if (!importPath)
|
|
56867
56929
|
continue;
|
|
56868
56930
|
try {
|
|
56869
|
-
const imported = JSON.parse(
|
|
56931
|
+
const imported = JSON.parse(readFileSync24(importPath, "utf-8"));
|
|
56870
56932
|
const servers = extractServers(imported, importKind);
|
|
56871
56933
|
for (const name of Object.keys(servers)) {
|
|
56872
56934
|
if (!provenance.has(name)) {
|
|
@@ -56920,18 +56982,18 @@ var init_config3 = __esm(() => {
|
|
|
56920
56982
|
init_agent_dir();
|
|
56921
56983
|
init_config_write_utils();
|
|
56922
56984
|
init_tool_call_timeout();
|
|
56923
|
-
GENERIC_GLOBAL_CONFIG_PATH =
|
|
56985
|
+
GENERIC_GLOBAL_CONFIG_PATH = join48(homedir8(), ".config", "mcp", "mcp.json");
|
|
56924
56986
|
PROJECT_PI_CONFIG_NAME = `${CONFIG_DIR_NAME}/mcp.json`;
|
|
56925
|
-
REPOPROMPT_BINARY_CANDIDATES = [
|
|
56987
|
+
REPOPROMPT_BINARY_CANDIDATES = [join48(homedir8(), "RepoPrompt", "repoprompt_cli"), "/Applications/Repo Prompt.app/Contents/MacOS/repoprompt-mcp"];
|
|
56926
56988
|
IMPORT_PATHS = {
|
|
56927
56989
|
"claude-code": [
|
|
56928
|
-
|
|
56929
|
-
|
|
56930
|
-
|
|
56990
|
+
join48(homedir8(), ".claude", "mcp.json"),
|
|
56991
|
+
join48(homedir8(), ".claude.json"),
|
|
56992
|
+
join48(homedir8(), ".claude", "claude_desktop_config.json")
|
|
56931
56993
|
],
|
|
56932
|
-
"claude-desktop": [
|
|
56933
|
-
codex: [
|
|
56934
|
-
windsurf: [
|
|
56994
|
+
"claude-desktop": [join48(homedir8(), "Library", "Application Support", "Claude", "claude_desktop_config.json")],
|
|
56995
|
+
codex: [join48(homedir8(), ".codex", "config.json")],
|
|
56996
|
+
windsurf: [join48(homedir8(), ".windsurf", "mcp.json")],
|
|
56935
56997
|
vscode: [".vscode/mcp.json"]
|
|
56936
56998
|
};
|
|
56937
56999
|
});
|
|
@@ -57450,7 +57512,7 @@ __export(exports_utils, {
|
|
|
57450
57512
|
unflattenToolArguments: () => unflattenToolArguments
|
|
57451
57513
|
});
|
|
57452
57514
|
import { homedir as homedir9, platform as platform3 } from "node:os";
|
|
57453
|
-
import { join as
|
|
57515
|
+
import { join as join49 } from "node:path";
|
|
57454
57516
|
async function execOpen(pi, target, browser) {
|
|
57455
57517
|
const os5 = platform3();
|
|
57456
57518
|
if (os5 === "darwin") {
|
|
@@ -57512,7 +57574,7 @@ function resolveConfigPath(value) {
|
|
|
57512
57574
|
if (resolved === "~")
|
|
57513
57575
|
return homedir9();
|
|
57514
57576
|
if (resolved.startsWith("~/") || resolved.startsWith("~\\")) {
|
|
57515
|
-
return
|
|
57577
|
+
return join49(homedir9(), resolved.slice(2));
|
|
57516
57578
|
}
|
|
57517
57579
|
return resolved;
|
|
57518
57580
|
}
|
|
@@ -57567,8 +57629,8 @@ __export(exports_metadata_cache, {
|
|
|
57567
57629
|
serializeResources: () => serializeResources,
|
|
57568
57630
|
serializeTools: () => serializeTools
|
|
57569
57631
|
});
|
|
57570
|
-
import { existsSync as
|
|
57571
|
-
import { dirname as
|
|
57632
|
+
import { existsSync as existsSync37, readFileSync as readFileSync25, writeFileSync as writeFileSync14, renameSync as renameSync4, mkdirSync as mkdirSync14 } from "node:fs";
|
|
57633
|
+
import { dirname as dirname26 } from "node:path";
|
|
57572
57634
|
import { createHash as createHash5 } from "node:crypto";
|
|
57573
57635
|
import { getToolUiResourceUri } from "@modelcontextprotocol/ext-apps/app-bridge";
|
|
57574
57636
|
function getMetadataCachePath() {
|
|
@@ -57576,10 +57638,10 @@ function getMetadataCachePath() {
|
|
|
57576
57638
|
}
|
|
57577
57639
|
function loadMetadataCache() {
|
|
57578
57640
|
const cachePath = getMetadataCachePath();
|
|
57579
|
-
if (!
|
|
57641
|
+
if (!existsSync37(cachePath))
|
|
57580
57642
|
return null;
|
|
57581
57643
|
try {
|
|
57582
|
-
const raw = JSON.parse(
|
|
57644
|
+
const raw = JSON.parse(readFileSync25(cachePath, "utf-8"));
|
|
57583
57645
|
if (!raw || typeof raw !== "object")
|
|
57584
57646
|
return null;
|
|
57585
57647
|
if (raw.version !== CACHE_VERSION)
|
|
@@ -57593,12 +57655,12 @@ function loadMetadataCache() {
|
|
|
57593
57655
|
}
|
|
57594
57656
|
function saveMetadataCache(cache) {
|
|
57595
57657
|
const cachePath = getMetadataCachePath();
|
|
57596
|
-
const dir =
|
|
57658
|
+
const dir = dirname26(cachePath);
|
|
57597
57659
|
mkdirSync14(dir, { recursive: true });
|
|
57598
57660
|
let merged = { version: CACHE_VERSION, servers: {} };
|
|
57599
57661
|
try {
|
|
57600
|
-
if (
|
|
57601
|
-
const existing = JSON.parse(
|
|
57662
|
+
if (existsSync37(cachePath)) {
|
|
57663
|
+
const existing = JSON.parse(readFileSync25(cachePath, "utf-8"));
|
|
57602
57664
|
if (existing && existing.version === CACHE_VERSION && existing.servers) {
|
|
57603
57665
|
merged.servers = { ...existing.servers };
|
|
57604
57666
|
}
|
|
@@ -57715,8 +57777,8 @@ var init_metadata_cache = __esm(() => {
|
|
|
57715
57777
|
});
|
|
57716
57778
|
|
|
57717
57779
|
// dist/builtin/mcp/npx-resolver.ts
|
|
57718
|
-
import { existsSync as
|
|
57719
|
-
import { join as
|
|
57780
|
+
import { existsSync as existsSync38, readFileSync as readFileSync26, realpathSync as realpathSync5, readdirSync as readdirSync8, statSync as statSync8, writeFileSync as writeFileSync15, renameSync as renameSync5, mkdirSync as mkdirSync15, openSync as openSync4, readSync as readSync2, closeSync as closeSync4 } from "node:fs";
|
|
57781
|
+
import { join as join50, dirname as dirname27, extname, resolve as resolve17, sep as sep10 } from "node:path";
|
|
57720
57782
|
import { spawn as spawn9, spawnSync as spawnSync8 } from "node:child_process";
|
|
57721
57783
|
async function resolveNpxBinary(command, args) {
|
|
57722
57784
|
const parsed = command === "npx" ? parseNpxArgs(args) : command === "npm" ? parseNpmExecArgs(args) : null;
|
|
@@ -57725,7 +57787,7 @@ async function resolveNpxBinary(command, args) {
|
|
|
57725
57787
|
const cacheKey2 = JSON.stringify([command, ...args]);
|
|
57726
57788
|
const cache = loadCache();
|
|
57727
57789
|
const cached = cache?.entries?.[cacheKey2];
|
|
57728
|
-
if (cached && Date.now() - cached.resolvedAt < CACHE_TTL_MS2 &&
|
|
57790
|
+
if (cached && Date.now() - cached.resolvedAt < CACHE_TTL_MS2 && existsSync38(cached.resolvedBin)) {
|
|
57729
57791
|
return { binPath: cached.resolvedBin, extraArgs: parsed.extraArgs, isJs: cached.isJs };
|
|
57730
57792
|
}
|
|
57731
57793
|
const resolved = resolveFromNpmCache(parsed.packageSpec, parsed.binName);
|
|
@@ -57846,12 +57908,12 @@ function resolveFromNpmCache(packageSpec, binName) {
|
|
|
57846
57908
|
const packageDir = findCachedPackageDir(cacheDir, packageName);
|
|
57847
57909
|
if (!packageDir)
|
|
57848
57910
|
return null;
|
|
57849
|
-
const packageJsonPath =
|
|
57850
|
-
if (!
|
|
57911
|
+
const packageJsonPath = join50(packageDir, "package.json");
|
|
57912
|
+
if (!existsSync38(packageJsonPath))
|
|
57851
57913
|
return null;
|
|
57852
57914
|
let pkg2 = null;
|
|
57853
57915
|
try {
|
|
57854
|
-
pkg2 = JSON.parse(
|
|
57916
|
+
pkg2 = JSON.parse(readFileSync26(packageJsonPath, "utf-8"));
|
|
57855
57917
|
} catch {
|
|
57856
57918
|
return null;
|
|
57857
57919
|
}
|
|
@@ -57883,11 +57945,11 @@ function resolveFromNpmCache(packageSpec, binName) {
|
|
|
57883
57945
|
if (!binRel)
|
|
57884
57946
|
return null;
|
|
57885
57947
|
const nodeModulesDir = findNodeModulesDir(packageDir);
|
|
57886
|
-
const binLink = chosenBinName ?
|
|
57887
|
-
let resolvedBin = binLink &&
|
|
57948
|
+
const binLink = chosenBinName ? join50(nodeModulesDir, ".bin", chosenBinName) : null;
|
|
57949
|
+
let resolvedBin = binLink && existsSync38(binLink) ? safeRealpath(binLink) : "";
|
|
57888
57950
|
if (!resolvedBin) {
|
|
57889
57951
|
resolvedBin = resolve17(packageDir, binRel);
|
|
57890
|
-
if (!
|
|
57952
|
+
if (!existsSync38(resolvedBin))
|
|
57891
57953
|
return null;
|
|
57892
57954
|
}
|
|
57893
57955
|
const isJs = detectJsBinary(resolvedBin);
|
|
@@ -57959,18 +58021,18 @@ function defaultBinName(packageName) {
|
|
|
57959
58021
|
return packageName;
|
|
57960
58022
|
}
|
|
57961
58023
|
function findCachedPackageDir(cacheDir, packageName) {
|
|
57962
|
-
const npxDir =
|
|
57963
|
-
if (!
|
|
58024
|
+
const npxDir = join50(cacheDir, "_npx");
|
|
58025
|
+
if (!existsSync38(npxDir))
|
|
57964
58026
|
return null;
|
|
57965
58027
|
const packagePathParts = packageName.startsWith("@") ? packageName.split("/") : [packageName];
|
|
57966
58028
|
const candidates = readdirSync8(npxDir, { withFileTypes: true }).filter((entry) => entry.isDirectory()).map((entry) => {
|
|
57967
|
-
const full =
|
|
58029
|
+
const full = join50(npxDir, entry.name);
|
|
57968
58030
|
const mtime = safeStatMtime(full);
|
|
57969
58031
|
return { name: entry.name, mtime };
|
|
57970
58032
|
}).sort((a, b) => b.mtime - a.mtime);
|
|
57971
58033
|
for (const entry of candidates) {
|
|
57972
|
-
const pkgDir =
|
|
57973
|
-
if (
|
|
58034
|
+
const pkgDir = join50(npxDir, entry.name, "node_modules", ...packagePathParts);
|
|
58035
|
+
if (existsSync38(join50(pkgDir, "package.json"))) {
|
|
57974
58036
|
return pkgDir;
|
|
57975
58037
|
}
|
|
57976
58038
|
}
|
|
@@ -57982,7 +58044,7 @@ function findNodeModulesDir(packageDir) {
|
|
|
57982
58044
|
if (idx >= 0) {
|
|
57983
58045
|
return parts.slice(0, idx + 1).join(sep10);
|
|
57984
58046
|
}
|
|
57985
|
-
return
|
|
58047
|
+
return join50(packageDir, "..");
|
|
57986
58048
|
}
|
|
57987
58049
|
function detectJsBinary(binPath) {
|
|
57988
58050
|
const ext = extname(binPath).toLowerCase();
|
|
@@ -58029,10 +58091,10 @@ function getNpxCachePath() {
|
|
|
58029
58091
|
}
|
|
58030
58092
|
function loadCache() {
|
|
58031
58093
|
const cachePath = getNpxCachePath();
|
|
58032
|
-
if (!
|
|
58094
|
+
if (!existsSync38(cachePath))
|
|
58033
58095
|
return null;
|
|
58034
58096
|
try {
|
|
58035
|
-
const raw = JSON.parse(
|
|
58097
|
+
const raw = JSON.parse(readFileSync26(cachePath, "utf-8"));
|
|
58036
58098
|
if (!raw || typeof raw !== "object")
|
|
58037
58099
|
return null;
|
|
58038
58100
|
if (raw.version !== CACHE_VERSION2)
|
|
@@ -58046,12 +58108,12 @@ function loadCache() {
|
|
|
58046
58108
|
}
|
|
58047
58109
|
function saveCacheEntry(key, entry) {
|
|
58048
58110
|
const cachePath = getNpxCachePath();
|
|
58049
|
-
const dir =
|
|
58111
|
+
const dir = dirname27(cachePath);
|
|
58050
58112
|
mkdirSync15(dir, { recursive: true });
|
|
58051
58113
|
let merged = { version: CACHE_VERSION2, entries: {} };
|
|
58052
58114
|
try {
|
|
58053
|
-
if (
|
|
58054
|
-
const existing = JSON.parse(
|
|
58115
|
+
if (existsSync38(cachePath)) {
|
|
58116
|
+
const existing = JSON.parse(readFileSync26(cachePath, "utf-8"));
|
|
58055
58117
|
if (existing && existing.version === CACHE_VERSION2 && existing.entries) {
|
|
58056
58118
|
merged.entries = { ...existing.entries };
|
|
58057
58119
|
}
|
|
@@ -58084,31 +58146,31 @@ var init_npx_resolver = __esm(() => {
|
|
|
58084
58146
|
});
|
|
58085
58147
|
|
|
58086
58148
|
// dist/builtin/mcp/mcp-auth.ts
|
|
58087
|
-
import { mkdirSync as mkdirSync16, readFileSync as
|
|
58088
|
-
import { join as
|
|
58149
|
+
import { mkdirSync as mkdirSync16, readFileSync as readFileSync27, writeFileSync as writeFileSync16, existsSync as existsSync39, rmSync as rmSync7 } from "fs";
|
|
58150
|
+
import { join as join51 } from "path";
|
|
58089
58151
|
function getAuthBaseDir() {
|
|
58090
58152
|
const override = process.env.MCP_OAUTH_DIR?.trim();
|
|
58091
58153
|
return override ? override : getAgentPath("mcp-oauth");
|
|
58092
58154
|
}
|
|
58093
58155
|
function getServerDir(serverName) {
|
|
58094
|
-
return
|
|
58156
|
+
return join51(getAuthBaseDir(), serverName);
|
|
58095
58157
|
}
|
|
58096
58158
|
function getTokensFilePath(serverName) {
|
|
58097
|
-
return
|
|
58159
|
+
return join51(getServerDir(serverName), "tokens.json");
|
|
58098
58160
|
}
|
|
58099
58161
|
function ensureServerDir(serverName) {
|
|
58100
58162
|
const dir = getServerDir(serverName);
|
|
58101
|
-
if (!
|
|
58163
|
+
if (!existsSync39(dir)) {
|
|
58102
58164
|
mkdirSync16(dir, { recursive: true, mode: 448 });
|
|
58103
58165
|
}
|
|
58104
58166
|
}
|
|
58105
58167
|
function readAuthEntry(serverName) {
|
|
58106
58168
|
try {
|
|
58107
58169
|
const filePath = getTokensFilePath(serverName);
|
|
58108
|
-
if (!
|
|
58170
|
+
if (!existsSync39(filePath)) {
|
|
58109
58171
|
return;
|
|
58110
58172
|
}
|
|
58111
|
-
const data =
|
|
58173
|
+
const data = readFileSync27(filePath, "utf-8");
|
|
58112
58174
|
return JSON.parse(data);
|
|
58113
58175
|
} catch (error) {
|
|
58114
58176
|
console.error(`Failed to read auth entry for ${serverName}:`, error);
|
|
@@ -58142,11 +58204,11 @@ function saveAuthEntry(serverName, entry, serverUrl) {
|
|
|
58142
58204
|
function removeAuthEntry(serverName) {
|
|
58143
58205
|
try {
|
|
58144
58206
|
const filePath = getTokensFilePath(serverName);
|
|
58145
|
-
if (
|
|
58207
|
+
if (existsSync39(filePath)) {
|
|
58146
58208
|
writeFileSync16(filePath, "{}", { mode: 384 });
|
|
58147
58209
|
}
|
|
58148
58210
|
const dir = getServerDir(serverName);
|
|
58149
|
-
if (
|
|
58211
|
+
if (existsSync39(dir)) {
|
|
58150
58212
|
try {
|
|
58151
58213
|
rmSync7(dir, { recursive: true });
|
|
58152
58214
|
} catch {}
|
|
@@ -59684,7 +59746,7 @@ __export(exports_init, {
|
|
|
59684
59746
|
updateServerMetadata: () => updateServerMetadata,
|
|
59685
59747
|
updateStatusBar: () => updateStatusBar
|
|
59686
59748
|
});
|
|
59687
|
-
import { existsSync as
|
|
59749
|
+
import { existsSync as existsSync40 } from "node:fs";
|
|
59688
59750
|
async function initializeMcp(pi, ctx) {
|
|
59689
59751
|
const configPath = pi.getFlag("mcp-config");
|
|
59690
59752
|
const config = loadMcpConfig(configPath, ctx.cwd);
|
|
@@ -59727,7 +59789,7 @@ async function initializeMcp(pi, ctx) {
|
|
|
59727
59789
|
const idleSetting = typeof config.settings?.idleTimeout === "number" ? config.settings.idleTimeout : 10;
|
|
59728
59790
|
lifecycle.setGlobalIdleTimeout(idleSetting);
|
|
59729
59791
|
const cachePath = getMetadataCachePath();
|
|
59730
|
-
const cacheFileExists =
|
|
59792
|
+
const cacheFileExists = existsSync40(cachePath);
|
|
59731
59793
|
let cache = loadMetadataCache();
|
|
59732
59794
|
if (!cacheFileExists) {
|
|
59733
59795
|
saveMetadataCache({ version: 1, servers: {} });
|
|
@@ -59947,17 +60009,17 @@ var init_init = __esm(() => {
|
|
|
59947
60009
|
});
|
|
59948
60010
|
|
|
59949
60011
|
// dist/builtin/mcp/onboarding-state.ts
|
|
59950
|
-
import { existsSync as
|
|
59951
|
-
import { dirname as
|
|
60012
|
+
import { existsSync as existsSync41, mkdirSync as mkdirSync17, readFileSync as readFileSync28, writeFileSync as writeFileSync17, renameSync as renameSync6 } from "node:fs";
|
|
60013
|
+
import { dirname as dirname28 } from "node:path";
|
|
59952
60014
|
function getOnboardingStatePath() {
|
|
59953
60015
|
return getAgentPath("mcp-onboarding.json");
|
|
59954
60016
|
}
|
|
59955
60017
|
function loadOnboardingState() {
|
|
59956
60018
|
const path13 = getOnboardingStatePath();
|
|
59957
|
-
if (!
|
|
60019
|
+
if (!existsSync41(path13))
|
|
59958
60020
|
return { ...DEFAULT_STATE };
|
|
59959
60021
|
try {
|
|
59960
|
-
const raw = JSON.parse(
|
|
60022
|
+
const raw = JSON.parse(readFileSync28(path13, "utf-8"));
|
|
59961
60023
|
if (!raw || typeof raw !== "object")
|
|
59962
60024
|
return { ...DEFAULT_STATE };
|
|
59963
60025
|
return {
|
|
@@ -59972,7 +60034,7 @@ function loadOnboardingState() {
|
|
|
59972
60034
|
}
|
|
59973
60035
|
function saveOnboardingState(state) {
|
|
59974
60036
|
const path13 = getOnboardingStatePath();
|
|
59975
|
-
mkdirSync17(
|
|
60037
|
+
mkdirSync17(dirname28(path13), { recursive: true });
|
|
59976
60038
|
const tmpPath = `${path13}.${process.pid}.tmp`;
|
|
59977
60039
|
writeFileSync17(tmpPath, `${JSON.stringify(state, null, 2)}
|
|
59978
60040
|
`, "utf-8");
|
|
@@ -62546,9 +62608,9 @@ var init_ui_server = __esm(() => {
|
|
|
62546
62608
|
});
|
|
62547
62609
|
|
|
62548
62610
|
// dist/builtin/mcp/glimpse-ui.ts
|
|
62549
|
-
import { existsSync as
|
|
62611
|
+
import { existsSync as existsSync42 } from "node:fs";
|
|
62550
62612
|
import { execFileSync } from "node:child_process";
|
|
62551
|
-
import { join as
|
|
62613
|
+
import { join as join52, dirname as dirname29 } from "node:path";
|
|
62552
62614
|
import { platform as platform4 } from "node:os";
|
|
62553
62615
|
import { createRequire as createRequire7 } from "node:module";
|
|
62554
62616
|
function isGlimpseAvailable() {
|
|
@@ -62563,26 +62625,26 @@ function isGlimpseAvailable() {
|
|
|
62563
62625
|
return glimpseAvailable;
|
|
62564
62626
|
}
|
|
62565
62627
|
function getGlimpseBinaryPath() {
|
|
62566
|
-
if (process.env.GLIMPSE_BINARY &&
|
|
62628
|
+
if (process.env.GLIMPSE_BINARY && existsSync42(process.env.GLIMPSE_BINARY)) {
|
|
62567
62629
|
return process.env.GLIMPSE_BINARY;
|
|
62568
62630
|
}
|
|
62569
62631
|
try {
|
|
62570
62632
|
const require4 = createRequire7(import.meta.url);
|
|
62571
62633
|
const glimpseuiPath = require4.resolve("glimpseui");
|
|
62572
|
-
const binaryPath =
|
|
62573
|
-
if (
|
|
62634
|
+
const binaryPath = join52(dirname29(glimpseuiPath), "glimpse");
|
|
62635
|
+
if (existsSync42(binaryPath))
|
|
62574
62636
|
return binaryPath;
|
|
62575
62637
|
} catch {}
|
|
62576
62638
|
try {
|
|
62577
62639
|
const globalRoot = execFileSync("npm", ["root", "-g"], { encoding: "utf-8", env: createChildProcessEnvironment() }).trim();
|
|
62578
|
-
const binaryPath =
|
|
62579
|
-
if (
|
|
62640
|
+
const binaryPath = join52(globalRoot, "glimpseui", "src", "glimpse");
|
|
62641
|
+
if (existsSync42(binaryPath))
|
|
62580
62642
|
return binaryPath;
|
|
62581
62643
|
} catch {}
|
|
62582
62644
|
return null;
|
|
62583
62645
|
}
|
|
62584
62646
|
async function openGlimpseWindow(html, options) {
|
|
62585
|
-
const modulePath = resolvedBinaryPath ?
|
|
62647
|
+
const modulePath = resolvedBinaryPath ? join52(dirname29(resolvedBinaryPath), "glimpse.mjs") : "glimpseui";
|
|
62586
62648
|
const glimpse = await import(modulePath);
|
|
62587
62649
|
let active = true;
|
|
62588
62650
|
const win = glimpse.open(html, {
|