@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
|
|
|
@@ -203,7 +293,7 @@ var init_child_process = __esm(() => {
|
|
|
203
293
|
// src/utils/paths.ts
|
|
204
294
|
import { realpathSync } from "node:fs";
|
|
205
295
|
import { homedir } from "node:os";
|
|
206
|
-
import { isAbsolute, join, resolve as nodeResolvePath, relative, sep } from "node:path";
|
|
296
|
+
import { isAbsolute, join as join2, resolve as nodeResolvePath, relative, sep } from "node:path";
|
|
207
297
|
import { fileURLToPath } from "node:url";
|
|
208
298
|
function getHomeDir() {
|
|
209
299
|
if (process.platform === "win32") {
|
|
@@ -256,7 +346,7 @@ function normalizePath(input, options = {}) {
|
|
|
256
346
|
if (normalized === "~")
|
|
257
347
|
return home;
|
|
258
348
|
if (normalized.startsWith("~/") || process.platform === "win32" && normalized.startsWith("~\\")) {
|
|
259
|
-
return
|
|
349
|
+
return join2(home, normalized.slice(2));
|
|
260
350
|
}
|
|
261
351
|
}
|
|
262
352
|
if (/^file:\/\//.test(normalized)) {
|
|
@@ -298,20 +388,20 @@ var init_paths = __esm(() => {
|
|
|
298
388
|
});
|
|
299
389
|
|
|
300
390
|
// src/utils/split-launcher.ts
|
|
301
|
-
import { dirname, join as
|
|
391
|
+
import { dirname as dirname2, join as join3 } from "node:path";
|
|
302
392
|
import { fileURLToPath as fileURLToPath2 } from "node:url";
|
|
303
393
|
function isSplitLauncherRuntime() {
|
|
304
394
|
return process.env.ATOMIC_CODING_AGENT === "true" && /(?:^|[\\/])atomic(?:\.exe)?$/i.test(process.execPath);
|
|
305
395
|
}
|
|
306
396
|
function splitLauncherDir() {
|
|
307
|
-
return
|
|
397
|
+
return dirname2(process.execPath);
|
|
308
398
|
}
|
|
309
399
|
function moduleDirFromMetaUrl(metaUrl, ...execRelativeSegments) {
|
|
310
400
|
try {
|
|
311
|
-
return
|
|
401
|
+
return dirname2(fileURLToPath2(metaUrl));
|
|
312
402
|
} catch (error) {
|
|
313
403
|
if (isSplitLauncherRuntime())
|
|
314
|
-
return
|
|
404
|
+
return join3(splitLauncherDir(), ...execRelativeSegments);
|
|
315
405
|
throw error;
|
|
316
406
|
}
|
|
317
407
|
}
|
|
@@ -320,16 +410,16 @@ function moduleFileFromMetaUrl(metaUrl, execRelativeFile) {
|
|
|
320
410
|
return fileURLToPath2(metaUrl);
|
|
321
411
|
} catch (error) {
|
|
322
412
|
if (isSplitLauncherRuntime())
|
|
323
|
-
return
|
|
413
|
+
return join3(splitLauncherDir(), execRelativeFile);
|
|
324
414
|
throw error;
|
|
325
415
|
}
|
|
326
416
|
}
|
|
327
417
|
var init_split_launcher = () => {};
|
|
328
418
|
|
|
329
419
|
// src/config-self-update.ts
|
|
330
|
-
import { accessSync, constants, existsSync, realpathSync as realpathSync2 } from "fs";
|
|
420
|
+
import { accessSync, constants, existsSync as existsSync2, realpathSync as realpathSync2 } from "fs";
|
|
331
421
|
import { homedir as homedir2 } from "os";
|
|
332
|
-
import { basename as basename2, dirname as
|
|
422
|
+
import { basename as basename2, dirname as dirname3, join as join4, resolve, sep as sep2, win32 } from "path";
|
|
333
423
|
function normalizeSelfUpdateTarget(target) {
|
|
334
424
|
if (typeof target === "string")
|
|
335
425
|
return { packageName: target, installSpec: target };
|
|
@@ -372,7 +462,7 @@ function detectInstallMethodForRuntime(runtime) {
|
|
|
372
462
|
}
|
|
373
463
|
function getInferredNpmInstall(runtime) {
|
|
374
464
|
const packageDir = runtime.getPackageDir();
|
|
375
|
-
const path = process.platform === "win32" || packageDir.includes("\\") ? win32 : { basename: basename2, dirname:
|
|
465
|
+
const path = process.platform === "win32" || packageDir.includes("\\") ? win32 : { basename: basename2, dirname: dirname3 };
|
|
376
466
|
const parent = path.dirname(packageDir);
|
|
377
467
|
let root;
|
|
378
468
|
if (path.basename(parent).startsWith("@") && path.basename(path.dirname(parent)) === "node_modules") {
|
|
@@ -393,7 +483,7 @@ function getSelfUpdateCommandForMethod(runtime, method, installedPackageName, up
|
|
|
393
483
|
return;
|
|
394
484
|
case "pnpm": {
|
|
395
485
|
const match = readCommandOutput("pnpm", ["root", "-g"]) ? undefined : /^(.*[\\/]global[\\/][^\\/]+)[\\/]\.pnpm[\\/]/.exec(runtime.getPackageDir());
|
|
396
|
-
const binDirArgs = match ? [`--config.global-bin-dir=${process.env.PNPM_HOME ||
|
|
486
|
+
const binDirArgs = match ? [`--config.global-bin-dir=${process.env.PNPM_HOME || dirname3(dirname3(match[1]))}`] : [];
|
|
397
487
|
return makeSelfUpdateCommand(makeSelfUpdateCommandStep("pnpm", [
|
|
398
488
|
"install",
|
|
399
489
|
"-g",
|
|
@@ -456,9 +546,9 @@ function getGlobalPackageRoots(runtime, method, _packageName, npmCommand) {
|
|
|
456
546
|
const bunBin = readCommandOutput(command, [...npmArgs, "pm", "bin", "-g"], {
|
|
457
547
|
requireSuccess: true
|
|
458
548
|
});
|
|
459
|
-
const roots = [
|
|
549
|
+
const roots = [join4(homedir2(), ".bun", "install", "global", "node_modules")];
|
|
460
550
|
if (bunBin) {
|
|
461
|
-
roots.push(
|
|
551
|
+
roots.push(join4(dirname3(bunBin), "install", "global", "node_modules"));
|
|
462
552
|
}
|
|
463
553
|
return roots;
|
|
464
554
|
}
|
|
@@ -471,19 +561,19 @@ function getGlobalPackageRoots(runtime, method, _packageName, npmCommand) {
|
|
|
471
561
|
case "pnpm": {
|
|
472
562
|
const root = readCommandOutput("pnpm", ["root", "-g"]);
|
|
473
563
|
if (root)
|
|
474
|
-
return [root,
|
|
564
|
+
return [root, dirname3(root)];
|
|
475
565
|
const match = /^(.*[\\/]global[\\/][^\\/]+)[\\/]\.pnpm[\\/]/.exec(runtime.getPackageDir());
|
|
476
566
|
return match ? [match[1]] : [];
|
|
477
567
|
}
|
|
478
568
|
case "yarn": {
|
|
479
569
|
const dir = readCommandOutput("yarn", ["global", "dir"]);
|
|
480
|
-
return dir ? [dir,
|
|
570
|
+
return dir ? [dir, join4(dir, "node_modules")] : [];
|
|
481
571
|
}
|
|
482
572
|
case "bun": {
|
|
483
573
|
const bunBin = readCommandOutput("bun", ["pm", "bin", "-g"]);
|
|
484
|
-
const roots = [
|
|
574
|
+
const roots = [join4(homedir2(), ".bun", "install", "global", "node_modules")];
|
|
485
575
|
if (bunBin) {
|
|
486
|
-
roots.push(
|
|
576
|
+
roots.push(join4(dirname3(bunBin), "install", "global", "node_modules"));
|
|
487
577
|
}
|
|
488
578
|
return roots;
|
|
489
579
|
}
|
|
@@ -494,7 +584,7 @@ function getGlobalPackageRoots(runtime, method, _packageName, npmCommand) {
|
|
|
494
584
|
}
|
|
495
585
|
function normalizeExistingPathForComparison(path, resolveSymlinks) {
|
|
496
586
|
const resolvedPath = resolve(path);
|
|
497
|
-
if (!
|
|
587
|
+
if (!existsSync2(resolvedPath)) {
|
|
498
588
|
return;
|
|
499
589
|
}
|
|
500
590
|
let normalizedPath = resolvedPath;
|
|
@@ -517,12 +607,12 @@ function getEntrypointPackageDir() {
|
|
|
517
607
|
const entrypoint = process.argv[1];
|
|
518
608
|
if (!entrypoint)
|
|
519
609
|
return;
|
|
520
|
-
let dir =
|
|
521
|
-
while (dir !==
|
|
522
|
-
if (
|
|
610
|
+
let dir = dirname3(entrypoint);
|
|
611
|
+
while (dir !== dirname3(dir)) {
|
|
612
|
+
if (existsSync2(join4(dir, "package.json"))) {
|
|
523
613
|
return dir;
|
|
524
614
|
}
|
|
525
|
-
dir =
|
|
615
|
+
dir = dirname3(dir);
|
|
526
616
|
}
|
|
527
617
|
return;
|
|
528
618
|
}
|
|
@@ -530,7 +620,7 @@ function isSelfUpdatePathWritable(runtime) {
|
|
|
530
620
|
const packageDir = runtime.getPackageDir();
|
|
531
621
|
try {
|
|
532
622
|
accessSync(packageDir, constants.W_OK);
|
|
533
|
-
accessSync(
|
|
623
|
+
accessSync(dirname3(packageDir), constants.W_OK);
|
|
534
624
|
return true;
|
|
535
625
|
} catch {
|
|
536
626
|
return false;
|
|
@@ -575,8 +665,8 @@ var init_config_self_update = __esm(() => {
|
|
|
575
665
|
});
|
|
576
666
|
|
|
577
667
|
// src/config.ts
|
|
578
|
-
import { existsSync as
|
|
579
|
-
import { dirname as
|
|
668
|
+
import { existsSync as existsSync3, readFileSync as readFileSync2 } from "fs";
|
|
669
|
+
import { dirname as dirname4, join as join5, resolve as resolve2 } from "path";
|
|
580
670
|
function selfUpdateRuntime() {
|
|
581
671
|
return {
|
|
582
672
|
isBunBinary,
|
|
@@ -600,16 +690,9 @@ function getPackageDir() {
|
|
|
600
690
|
return normalizePath(envDir);
|
|
601
691
|
}
|
|
602
692
|
if (isBunBinary) {
|
|
603
|
-
return
|
|
604
|
-
}
|
|
605
|
-
let dir = __dirname2;
|
|
606
|
-
while (dir !== dirname3(dir)) {
|
|
607
|
-
if (existsSync2(join4(dir, "package.json"))) {
|
|
608
|
-
return dir;
|
|
609
|
-
}
|
|
610
|
-
dir = dirname3(dir);
|
|
693
|
+
return dirname4(process.execPath);
|
|
611
694
|
}
|
|
612
|
-
return __dirname2;
|
|
695
|
+
return resolvePackageDirFrom(__dirname2);
|
|
613
696
|
}
|
|
614
697
|
function getModuleAssetRoot() {
|
|
615
698
|
const hasPackageDirOverride = !!(process.env.ATOMIC_PACKAGE_DIR || process.env.PI_PACKAGE_DIR);
|
|
@@ -617,43 +700,43 @@ function getModuleAssetRoot() {
|
|
|
617
700
|
return __dirname2;
|
|
618
701
|
}
|
|
619
702
|
const packageDir = getPackageDir();
|
|
620
|
-
return
|
|
703
|
+
return join5(packageDir, existsSync3(join5(packageDir, "src")) ? "src" : "dist");
|
|
621
704
|
}
|
|
622
705
|
function getThemesDir() {
|
|
623
706
|
if (isBunBinary) {
|
|
624
|
-
return
|
|
707
|
+
return join5(getPackageDir(), "theme");
|
|
625
708
|
}
|
|
626
|
-
return
|
|
709
|
+
return join5(getModuleAssetRoot(), "modes", "interactive", "theme");
|
|
627
710
|
}
|
|
628
711
|
function getExportTemplateDir() {
|
|
629
712
|
if (isBunBinary) {
|
|
630
|
-
return
|
|
713
|
+
return join5(getPackageDir(), "export-html");
|
|
631
714
|
}
|
|
632
|
-
return
|
|
715
|
+
return join5(getModuleAssetRoot(), "core", "export-html");
|
|
633
716
|
}
|
|
634
717
|
function getPackageJsonPath() {
|
|
635
|
-
return
|
|
718
|
+
return join5(getPackageDir(), "package.json");
|
|
636
719
|
}
|
|
637
720
|
function getReadmePath() {
|
|
638
|
-
return resolve2(
|
|
721
|
+
return resolve2(join5(getPackageDir(), "README.md"));
|
|
639
722
|
}
|
|
640
723
|
function getDocsPath() {
|
|
641
|
-
return resolve2(
|
|
724
|
+
return resolve2(join5(getPackageDir(), "docs"));
|
|
642
725
|
}
|
|
643
726
|
function getExamplesPath() {
|
|
644
|
-
return resolve2(
|
|
727
|
+
return resolve2(join5(getPackageDir(), "examples"));
|
|
645
728
|
}
|
|
646
729
|
function getChangelogPath() {
|
|
647
|
-
return resolve2(
|
|
730
|
+
return resolve2(join5(getPackageDir(), "CHANGELOG.md"));
|
|
648
731
|
}
|
|
649
732
|
function getInteractiveAssetsDir() {
|
|
650
733
|
if (isBunBinary) {
|
|
651
|
-
return
|
|
734
|
+
return join5(getPackageDir(), "assets");
|
|
652
735
|
}
|
|
653
|
-
return
|
|
736
|
+
return join5(getModuleAssetRoot(), "modes", "interactive", "assets");
|
|
654
737
|
}
|
|
655
738
|
function getBundledInteractiveAssetPath(name) {
|
|
656
|
-
return
|
|
739
|
+
return join5(getInteractiveAssetsDir(), name);
|
|
657
740
|
}
|
|
658
741
|
function appNameFromPackageName(packageName) {
|
|
659
742
|
const localName = packageName?.split("/").pop()?.trim();
|
|
@@ -743,10 +826,10 @@ function getAgentDir() {
|
|
|
743
826
|
if (envDir) {
|
|
744
827
|
return expandTildePath(envDir);
|
|
745
828
|
}
|
|
746
|
-
return
|
|
829
|
+
return join5(getHomeDir(), CONFIG_DIR_NAME, "agent");
|
|
747
830
|
}
|
|
748
831
|
function getLegacyAgentDir() {
|
|
749
|
-
return
|
|
832
|
+
return join5(getHomeDir(), LEGACY_CONFIG_DIR_NAME, "agent");
|
|
750
833
|
}
|
|
751
834
|
function getAgentDirs() {
|
|
752
835
|
const primary = getAgentDir();
|
|
@@ -757,55 +840,56 @@ function getAgentDirs() {
|
|
|
757
840
|
return legacy === primary ? [primary] : [primary, legacy];
|
|
758
841
|
}
|
|
759
842
|
function getUserConfigDirs() {
|
|
760
|
-
return CONFIG_DIR_NAMES.map((name) =>
|
|
843
|
+
return CONFIG_DIR_NAMES.map((name) => join5(getHomeDir(), name));
|
|
761
844
|
}
|
|
762
845
|
function getProjectConfigDirs(cwd) {
|
|
763
|
-
return CONFIG_DIR_NAMES.map((name) =>
|
|
846
|
+
return CONFIG_DIR_NAMES.map((name) => join5(cwd, name));
|
|
764
847
|
}
|
|
765
848
|
function getUserConfigPaths(...segments) {
|
|
766
|
-
return getUserConfigDirs().map((dir) =>
|
|
849
|
+
return getUserConfigDirs().map((dir) => join5(dir, ...segments));
|
|
767
850
|
}
|
|
768
851
|
function getAgentConfigPaths(...segments) {
|
|
769
|
-
return getAgentDirs().map((dir) =>
|
|
852
|
+
return getAgentDirs().map((dir) => join5(dir, ...segments));
|
|
770
853
|
}
|
|
771
854
|
function getProjectConfigPaths(cwd, ...segments) {
|
|
772
|
-
return getProjectConfigDirs(cwd).map((dir) =>
|
|
855
|
+
return getProjectConfigDirs(cwd).map((dir) => join5(dir, ...segments));
|
|
773
856
|
}
|
|
774
857
|
function getCustomThemesDir() {
|
|
775
|
-
return
|
|
858
|
+
return join5(getAgentDir(), "themes");
|
|
776
859
|
}
|
|
777
860
|
function getAuthPath() {
|
|
778
|
-
return
|
|
861
|
+
return join5(getAgentDir(), "auth.json");
|
|
779
862
|
}
|
|
780
863
|
function getSettingsPath() {
|
|
781
|
-
return
|
|
864
|
+
return join5(getAgentDir(), "settings.json");
|
|
782
865
|
}
|
|
783
866
|
function getBinDir() {
|
|
784
|
-
return
|
|
867
|
+
return join5(getAgentDir(), "bin");
|
|
785
868
|
}
|
|
786
869
|
function getExtensionTranspileCacheDir() {
|
|
787
|
-
return
|
|
870
|
+
return join5(getAgentDir(), "cache", "jiti", VERSION);
|
|
788
871
|
}
|
|
789
872
|
function getSessionsDir() {
|
|
790
|
-
return
|
|
873
|
+
return join5(getAgentDir(), "sessions");
|
|
791
874
|
}
|
|
792
875
|
function getDebugLogPath() {
|
|
793
|
-
return
|
|
876
|
+
return join5(getAgentDir(), `${APP_NAME}-debug.log`);
|
|
794
877
|
}
|
|
795
878
|
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/";
|
|
796
879
|
var init_config = __esm(() => {
|
|
880
|
+
init_config_package_identity();
|
|
797
881
|
init_paths();
|
|
798
882
|
init_split_launcher();
|
|
799
883
|
init_config_self_update();
|
|
800
884
|
__filename2 = moduleFileFromMetaUrl(import.meta.url, "app.js");
|
|
801
|
-
__dirname2 =
|
|
885
|
+
__dirname2 = dirname4(__filename2);
|
|
802
886
|
bunFsMarkers = ["$bunfs", "~BUN", "%7EBUN"];
|
|
803
887
|
isBunBinary = isSplitLauncherRuntime() || [import.meta.url, process.argv[1] ?? ""].some((candidate) => bunFsMarkers.some((marker) => candidate.includes(marker)));
|
|
804
888
|
isBundledBuild = process.env.ATOMIC_BUNDLED_BUILD === "1";
|
|
805
889
|
isBunRuntime = !!process.versions.bun;
|
|
806
890
|
pkg = {};
|
|
807
891
|
try {
|
|
808
|
-
pkg = JSON.parse(
|
|
892
|
+
pkg = JSON.parse(readFileSync2(getPackageJsonPath(), "utf-8"));
|
|
809
893
|
} catch (e) {
|
|
810
894
|
const err = e;
|
|
811
895
|
if (err.code !== "ENOENT")
|
|
@@ -2303,14 +2387,14 @@ var init_planner_outcome = __esm(() => {
|
|
|
2303
2387
|
// src/core/compaction/range-planner-diagnostics.ts
|
|
2304
2388
|
import { uuidv7 } from "@bastani/pi-ai";
|
|
2305
2389
|
import { chmodSync, writeFileSync } from "fs";
|
|
2306
|
-
import { basename as basename3, dirname as
|
|
2390
|
+
import { basename as basename3, dirname as dirname5, join as join6 } from "path";
|
|
2307
2391
|
function writeSidecar(sessionFilePath, kind, payload) {
|
|
2308
|
-
const dir =
|
|
2392
|
+
const dir = dirname5(sessionFilePath);
|
|
2309
2393
|
const base = basename3(sessionFilePath, ".jsonl");
|
|
2310
2394
|
const timestamp = Date.now();
|
|
2311
2395
|
const body = JSON.stringify(payload, null, 2);
|
|
2312
2396
|
for (let attempt = 0;attempt < 4; attempt++) {
|
|
2313
|
-
const filePath =
|
|
2397
|
+
const filePath = join6(dir, `${base}-compaction-${kind}-${timestamp}-${uuidv7()}.json`);
|
|
2314
2398
|
try {
|
|
2315
2399
|
writeFileSync(filePath, body, { encoding: "utf-8", mode: 384, flag: "wx" });
|
|
2316
2400
|
try {
|
|
@@ -3738,7 +3822,7 @@ function generateId(byId) {
|
|
|
3738
3822
|
var init_session_manager_validation = () => {};
|
|
3739
3823
|
|
|
3740
3824
|
// src/core/session-manager-entries.ts
|
|
3741
|
-
import { join as
|
|
3825
|
+
import { join as join7 } from "path";
|
|
3742
3826
|
function entryBase(byId, parentId) {
|
|
3743
3827
|
return {
|
|
3744
3828
|
id: generateId(byId),
|
|
@@ -3765,7 +3849,7 @@ function createSessionHeader(id, cwd, timestamp = new Date().toISOString(), pare
|
|
|
3765
3849
|
}
|
|
3766
3850
|
function createSessionFilePath(sessionDir, timestamp, sessionId) {
|
|
3767
3851
|
const fileTimestamp = timestamp.replace(/[:.]/g, "-");
|
|
3768
|
-
return
|
|
3852
|
+
return join7(sessionDir, `${fileTimestamp}_${sessionId}.jsonl`);
|
|
3769
3853
|
}
|
|
3770
3854
|
function createMessageEntry(message, byId, parentId) {
|
|
3771
3855
|
return {
|
|
@@ -3896,17 +3980,17 @@ var init_session_manager_entries = __esm(() => {
|
|
|
3896
3980
|
});
|
|
3897
3981
|
|
|
3898
3982
|
// src/core/session-manager-paths.ts
|
|
3899
|
-
import { existsSync as
|
|
3900
|
-
import { join as
|
|
3983
|
+
import { existsSync as existsSync4, mkdirSync } from "fs";
|
|
3984
|
+
import { join as join8 } from "path";
|
|
3901
3985
|
function getDefaultSessionDirPath(cwd, agentDir = getAgentDir()) {
|
|
3902
3986
|
const resolvedCwd = resolvePath(cwd);
|
|
3903
3987
|
const resolvedAgentDir = resolvePath(agentDir);
|
|
3904
3988
|
const safePath = `--${resolvedCwd.replace(/^[/\\]/, "").replace(/[/\\:]/g, "-")}--`;
|
|
3905
|
-
return
|
|
3989
|
+
return join8(resolvedAgentDir, "sessions", safePath);
|
|
3906
3990
|
}
|
|
3907
3991
|
function getDefaultSessionDir(cwd, agentDir = getAgentDir()) {
|
|
3908
3992
|
const sessionDir = getDefaultSessionDirPath(cwd, agentDir);
|
|
3909
|
-
if (!
|
|
3993
|
+
if (!existsSync4(sessionDir)) {
|
|
3910
3994
|
mkdirSync(sessionDir, { recursive: true });
|
|
3911
3995
|
}
|
|
3912
3996
|
return sessionDir;
|
|
@@ -3920,7 +4004,7 @@ var init_session_manager_paths = __esm(() => {
|
|
|
3920
4004
|
import {
|
|
3921
4005
|
appendFileSync,
|
|
3922
4006
|
closeSync,
|
|
3923
|
-
existsSync as
|
|
4007
|
+
existsSync as existsSync5,
|
|
3924
4008
|
mkdirSync as mkdirSync2,
|
|
3925
4009
|
openSync,
|
|
3926
4010
|
readdirSync,
|
|
@@ -3930,7 +4014,7 @@ import {
|
|
|
3930
4014
|
unlinkSync,
|
|
3931
4015
|
writeFileSync as writeFileSync2
|
|
3932
4016
|
} from "fs";
|
|
3933
|
-
import { join as
|
|
4017
|
+
import { join as join9 } from "path";
|
|
3934
4018
|
import { StringDecoder } from "string_decoder";
|
|
3935
4019
|
function parseSessionEntryLine(line) {
|
|
3936
4020
|
if (!line.trim())
|
|
@@ -3943,7 +4027,7 @@ function parseSessionEntryLine(line) {
|
|
|
3943
4027
|
}
|
|
3944
4028
|
function loadEntriesFromFile(filePath) {
|
|
3945
4029
|
const resolvedFilePath = normalizePath(filePath);
|
|
3946
|
-
if (!
|
|
4030
|
+
if (!existsSync5(resolvedFilePath))
|
|
3947
4031
|
return [];
|
|
3948
4032
|
const entries = [];
|
|
3949
4033
|
const fd = openSync(resolvedFilePath, "r");
|
|
@@ -4038,7 +4122,7 @@ function findMostRecentSession(sessionDir, cwd, includeInternal = false) {
|
|
|
4038
4122
|
const resolvedSessionDir = normalizePath(sessionDir);
|
|
4039
4123
|
const resolvedCwd = cwd ? resolvePath(cwd) : undefined;
|
|
4040
4124
|
try {
|
|
4041
|
-
const files = readdirSync(resolvedSessionDir).filter((f) => f.endsWith(".jsonl")).map((f) =>
|
|
4125
|
+
const files = readdirSync(resolvedSessionDir).filter((f) => f.endsWith(".jsonl")).map((f) => join9(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());
|
|
4042
4126
|
return files[0]?.path || null;
|
|
4043
4127
|
} catch {
|
|
4044
4128
|
return null;
|
|
@@ -4053,7 +4137,7 @@ function writeSessionEntries(filePath, entries) {
|
|
|
4053
4137
|
writeFileSync2(filePath, serializeSessionEntries(entries));
|
|
4054
4138
|
}
|
|
4055
4139
|
function appendSessionPayload(filePath, payload) {
|
|
4056
|
-
const existed =
|
|
4140
|
+
const existed = existsSync5(filePath);
|
|
4057
4141
|
const offset = existed ? statSync(filePath).size : 0;
|
|
4058
4142
|
try {
|
|
4059
4143
|
appendFileSync(filePath, payload);
|
|
@@ -4061,7 +4145,7 @@ function appendSessionPayload(filePath, payload) {
|
|
|
4061
4145
|
try {
|
|
4062
4146
|
if (existed)
|
|
4063
4147
|
truncateSync(filePath, offset);
|
|
4064
|
-
else if (
|
|
4148
|
+
else if (existsSync5(filePath))
|
|
4065
4149
|
unlinkSync(filePath);
|
|
4066
4150
|
} catch (rollbackError) {
|
|
4067
4151
|
throw new AggregateError([writeError, rollbackError], "Session append and rollback failed");
|
|
@@ -4091,7 +4175,7 @@ function persistAppendedEntry(filePath, entries, entry, flushed) {
|
|
|
4091
4175
|
return true;
|
|
4092
4176
|
}
|
|
4093
4177
|
function ensureDirectory(dir) {
|
|
4094
|
-
if (!
|
|
4178
|
+
if (!existsSync5(dir)) {
|
|
4095
4179
|
mkdirSync2(dir, { recursive: true });
|
|
4096
4180
|
}
|
|
4097
4181
|
}
|
|
@@ -4103,7 +4187,7 @@ var init_session_manager_storage = __esm(() => {
|
|
|
4103
4187
|
});
|
|
4104
4188
|
|
|
4105
4189
|
// src/core/session-manager-archive.ts
|
|
4106
|
-
import { join as
|
|
4190
|
+
import { join as join10 } from "path";
|
|
4107
4191
|
function createBackupSnapshot(sessionFile, entries, label = "compact") {
|
|
4108
4192
|
if (!sessionFile)
|
|
4109
4193
|
return;
|
|
@@ -4194,7 +4278,7 @@ function forkSessionFromFile(sourcePath, targetCwd, sessionDir, options) {
|
|
|
4194
4278
|
}
|
|
4195
4279
|
const newSessionId = options?.id ?? createSessionId();
|
|
4196
4280
|
const timestamp = new Date().toISOString();
|
|
4197
|
-
const newSessionFile =
|
|
4281
|
+
const newSessionFile = join10(dir, `${timestamp.replace(/[:.]/g, "-")}_${newSessionId}.jsonl`);
|
|
4198
4282
|
const newHeader = createSessionHeader(newSessionId, resolvedTargetCwd, timestamp, resolvedSourcePath, options?.internal, options?.workflow);
|
|
4199
4283
|
appendSessionEntry(newSessionFile, newHeader);
|
|
4200
4284
|
for (const entry of sourceEntries) {
|
|
@@ -4295,9 +4379,9 @@ var init_session_manager_migrations = __esm(() => {
|
|
|
4295
4379
|
});
|
|
4296
4380
|
|
|
4297
4381
|
// src/core/session-manager-list.ts
|
|
4298
|
-
import { existsSync as
|
|
4382
|
+
import { existsSync as existsSync6 } from "fs";
|
|
4299
4383
|
import { readdir, readFile, stat } from "fs/promises";
|
|
4300
|
-
import { join as
|
|
4384
|
+
import { join as join11 } from "path";
|
|
4301
4385
|
function isMessageWithContent(message) {
|
|
4302
4386
|
return typeof message.role === "string" && "content" in message;
|
|
4303
4387
|
}
|
|
@@ -4446,12 +4530,12 @@ async function buildSessionInfo(filePath) {
|
|
|
4446
4530
|
}
|
|
4447
4531
|
async function listSessionsFromDir(dir, onProgress, progressOffset = 0, progressTotal, includeInternal = false) {
|
|
4448
4532
|
const sessions = [];
|
|
4449
|
-
if (!
|
|
4533
|
+
if (!existsSync6(dir)) {
|
|
4450
4534
|
return sessions;
|
|
4451
4535
|
}
|
|
4452
4536
|
try {
|
|
4453
4537
|
const dirEntries = await readdir(dir);
|
|
4454
|
-
const files = dirEntries.filter((f) => f.endsWith(".jsonl")).map((f) =>
|
|
4538
|
+
const files = dirEntries.filter((f) => f.endsWith(".jsonl")).map((f) => join11(dir, f));
|
|
4455
4539
|
const total = progressTotal ?? files.length;
|
|
4456
4540
|
let loaded = 0;
|
|
4457
4541
|
const results = await mapSessionFilesCooperatively(files, includeInternal, () => {
|
|
@@ -4484,17 +4568,17 @@ async function listAllSessions(sessionDirOrOnProgress, onProgress, includeIntern
|
|
|
4484
4568
|
}
|
|
4485
4569
|
const sessionsDir = getSessionsDir();
|
|
4486
4570
|
try {
|
|
4487
|
-
if (!
|
|
4571
|
+
if (!existsSync6(sessionsDir)) {
|
|
4488
4572
|
return [];
|
|
4489
4573
|
}
|
|
4490
4574
|
const entries = await readdir(sessionsDir, { withFileTypes: true });
|
|
4491
|
-
const dirs = entries.filter((entry) => entry.isDirectory() || entry.isSymbolicLink()).map((entry) =>
|
|
4575
|
+
const dirs = entries.filter((entry) => entry.isDirectory() || entry.isSymbolicLink()).map((entry) => join11(sessionsDir, entry.name));
|
|
4492
4576
|
let totalFiles = 0;
|
|
4493
4577
|
const dirFiles = [];
|
|
4494
4578
|
for (const dir of dirs) {
|
|
4495
4579
|
try {
|
|
4496
4580
|
const files = (await readdir(dir)).filter((f) => f.endsWith(".jsonl"));
|
|
4497
|
-
dirFiles.push(files.map((f) =>
|
|
4581
|
+
dirFiles.push(files.map((f) => join11(dir, f)));
|
|
4498
4582
|
totalFiles += files.length;
|
|
4499
4583
|
} catch {
|
|
4500
4584
|
dirFiles.push([]);
|
|
@@ -4531,7 +4615,7 @@ var init_session_manager_list = __esm(() => {
|
|
|
4531
4615
|
});
|
|
4532
4616
|
|
|
4533
4617
|
// src/core/session-manager-core.ts
|
|
4534
|
-
import { existsSync as
|
|
4618
|
+
import { existsSync as existsSync7, statSync as statSync2 } from "fs";
|
|
4535
4619
|
import { resolve as resolve3 } from "path";
|
|
4536
4620
|
|
|
4537
4621
|
class SessionManager {
|
|
@@ -4564,7 +4648,7 @@ class SessionManager {
|
|
|
4564
4648
|
}
|
|
4565
4649
|
_setSessionFile(sessionFile, preloadedFileEntries) {
|
|
4566
4650
|
this.sessionFile = resolvePath(sessionFile);
|
|
4567
|
-
if (
|
|
4651
|
+
if (existsSync7(this.sessionFile)) {
|
|
4568
4652
|
this.fileEntries = preloadedFileEntries ?? loadEntriesFromFile(this.sessionFile);
|
|
4569
4653
|
if (this.fileEntries.length === 0) {
|
|
4570
4654
|
const explicitPath = this.sessionFile;
|
|
@@ -5285,7 +5369,7 @@ var init_agent_session_auto_compaction = __esm(() => {
|
|
|
5285
5369
|
});
|
|
5286
5370
|
|
|
5287
5371
|
// src/utils/shell.ts
|
|
5288
|
-
import { existsSync as
|
|
5372
|
+
import { existsSync as existsSync8 } from "node:fs";
|
|
5289
5373
|
import { delimiter } from "node:path";
|
|
5290
5374
|
import { Worker } from "node:worker_threads";
|
|
5291
5375
|
import { spawn, spawnSync } from "child_process";
|
|
@@ -5306,7 +5390,7 @@ function findBashOnPath() {
|
|
|
5306
5390
|
});
|
|
5307
5391
|
if (result.status === 0 && result.stdout) {
|
|
5308
5392
|
const firstMatch = result.stdout.trim().split(/\r?\n/)[0];
|
|
5309
|
-
if (firstMatch &&
|
|
5393
|
+
if (firstMatch && existsSync8(firstMatch)) {
|
|
5310
5394
|
return firstMatch;
|
|
5311
5395
|
}
|
|
5312
5396
|
}
|
|
@@ -5330,7 +5414,7 @@ function findBashOnPath() {
|
|
|
5330
5414
|
}
|
|
5331
5415
|
function getShellConfig(customShellPath) {
|
|
5332
5416
|
if (customShellPath) {
|
|
5333
|
-
if (
|
|
5417
|
+
if (existsSync8(customShellPath)) {
|
|
5334
5418
|
return getBashShellConfig(customShellPath);
|
|
5335
5419
|
}
|
|
5336
5420
|
throw new Error(`Custom shell path not found: ${customShellPath}`);
|
|
@@ -5346,7 +5430,7 @@ function getShellConfig(customShellPath) {
|
|
|
5346
5430
|
paths.push(`${programFilesX86}\\Git\\bin\\bash.exe`);
|
|
5347
5431
|
}
|
|
5348
5432
|
for (const path of paths) {
|
|
5349
|
-
if (
|
|
5433
|
+
if (existsSync8(path)) {
|
|
5350
5434
|
return getBashShellConfig(path);
|
|
5351
5435
|
}
|
|
5352
5436
|
}
|
|
@@ -5363,7 +5447,7 @@ function getShellConfig(customShellPath) {
|
|
|
5363
5447
|
${paths.map((p) => ` ${p}`).join(`
|
|
5364
5448
|
`)}`);
|
|
5365
5449
|
}
|
|
5366
|
-
if (
|
|
5450
|
+
if (existsSync8("/bin/bash")) {
|
|
5367
5451
|
return getBashShellConfig("/bin/bash");
|
|
5368
5452
|
}
|
|
5369
5453
|
const bashOnPath = findBashOnPath();
|
|
@@ -5660,7 +5744,7 @@ var init_windows_directory_security = __esm(() => {
|
|
|
5660
5744
|
import { createHash as createHash2 } from "node:crypto";
|
|
5661
5745
|
import { chmodSync as chmodSync2, lstatSync, mkdirSync as mkdirSync3, realpathSync as realpathSync3, rmSync } from "node:fs";
|
|
5662
5746
|
import { tmpdir, userInfo } from "node:os";
|
|
5663
|
-
import { dirname as
|
|
5747
|
+
import { dirname as dirname6, join as join12, sep as sep3 } from "node:path";
|
|
5664
5748
|
function sanitizeTempPathComponent(value, fallback) {
|
|
5665
5749
|
const collapsed = value.replace(/[^a-zA-Z0-9._-]+/g, "_");
|
|
5666
5750
|
let start = 0;
|
|
@@ -5717,11 +5801,11 @@ function baseTempDirs() {
|
|
|
5717
5801
|
}
|
|
5718
5802
|
function getTempRootDir() {
|
|
5719
5803
|
const app = sanitizeTempPathComponent(APP_NAME, "atomic");
|
|
5720
|
-
return
|
|
5804
|
+
return join12(baseTempDirs().raw, `${app}-${ownerComponent()}`);
|
|
5721
5805
|
}
|
|
5722
5806
|
function resolveSessionTempDirPath(sessionId) {
|
|
5723
5807
|
const id = sessionId ?? activeSessionId ?? `pid-${process.pid}`;
|
|
5724
|
-
return
|
|
5808
|
+
return join12(getTempRootDir(), sanitizeTempPathComponent(id, FALLBACK_SESSION_COMPONENT));
|
|
5725
5809
|
}
|
|
5726
5810
|
function isRealDirectory(path) {
|
|
5727
5811
|
try {
|
|
@@ -5795,7 +5879,7 @@ function canonicalTempChild(dir, base) {
|
|
|
5795
5879
|
for (const candidate of [base.raw, base.canonical]) {
|
|
5796
5880
|
const prefix = `${candidate}${sep3}`;
|
|
5797
5881
|
if (dir.startsWith(prefix)) {
|
|
5798
|
-
return
|
|
5882
|
+
return join12(base.canonical, dir.slice(prefix.length));
|
|
5799
5883
|
}
|
|
5800
5884
|
}
|
|
5801
5885
|
return;
|
|
@@ -5808,13 +5892,13 @@ function ensureTempDir(dir) {
|
|
|
5808
5892
|
const parts = checkedDir.slice(prefix.length).split(sep3).filter((part) => part.length > 0);
|
|
5809
5893
|
let current = base.canonical;
|
|
5810
5894
|
for (const part of parts.slice(0, -1)) {
|
|
5811
|
-
current =
|
|
5895
|
+
current = join12(current, part);
|
|
5812
5896
|
ensureOwnedDirectory(current);
|
|
5813
5897
|
}
|
|
5814
5898
|
ensureLeafDirectory(checkedDir);
|
|
5815
5899
|
} else {
|
|
5816
5900
|
if (!(ensuredDirs.has(dir) && isRealDirectory(dir))) {
|
|
5817
|
-
mkdirSync3(
|
|
5901
|
+
mkdirSync3(dirname6(dir), { recursive: true, mode: SESSION_TEMP_DIR_MODE });
|
|
5818
5902
|
ensureLeafDirectory(dir);
|
|
5819
5903
|
}
|
|
5820
5904
|
}
|
|
@@ -6260,7 +6344,7 @@ var init_truncate = __esm(() => {
|
|
|
6260
6344
|
|
|
6261
6345
|
// src/core/bash-executor.ts
|
|
6262
6346
|
import { randomBytes } from "node:crypto";
|
|
6263
|
-
import { join as
|
|
6347
|
+
import { join as join13 } from "node:path";
|
|
6264
6348
|
async function executeBashWithOperations(command, cwd, operations, options) {
|
|
6265
6349
|
const outputChunks = [];
|
|
6266
6350
|
let outputBytes = 0;
|
|
@@ -6276,7 +6360,7 @@ async function executeBashWithOperations(command, cwd, operations, options) {
|
|
|
6276
6360
|
try {
|
|
6277
6361
|
const dir = ensureSessionTempDir(options?.sessionTempDir);
|
|
6278
6362
|
const id = randomBytes(8).toString("hex");
|
|
6279
|
-
tempFilePath =
|
|
6363
|
+
tempFilePath = join13(dir, `${APP_NAME}-bash-${id}.log`);
|
|
6280
6364
|
tempFile = new PersistedOutputFile(tempFilePath);
|
|
6281
6365
|
} catch {
|
|
6282
6366
|
tempFileUnavailable = true;
|
|
@@ -8088,10 +8172,10 @@ var init_bash_session_environment = __esm(() => {
|
|
|
8088
8172
|
|
|
8089
8173
|
// src/core/tools/output-accumulator.ts
|
|
8090
8174
|
import { randomBytes as randomBytes2 } from "node:crypto";
|
|
8091
|
-
import { join as
|
|
8175
|
+
import { join as join16 } from "node:path";
|
|
8092
8176
|
function defaultTempFilePath(prefix, tempDir) {
|
|
8093
8177
|
const id = randomBytes2(8).toString("hex");
|
|
8094
|
-
return
|
|
8178
|
+
return join16(ensureSessionTempDir(tempDir), `${prefix}-${id}.log`);
|
|
8095
8179
|
}
|
|
8096
8180
|
function byteLength(text) {
|
|
8097
8181
|
return Buffer.byteLength(text, "utf-8");
|
|
@@ -8373,9 +8457,9 @@ var init_search_native = __esm(() => {
|
|
|
8373
8457
|
});
|
|
8374
8458
|
|
|
8375
8459
|
// src/core/tools/resource-selectors.ts
|
|
8376
|
-
import { existsSync as
|
|
8460
|
+
import { existsSync as existsSync11, mkdirSync as mkdirSync4, readFileSync as readFileSync4, realpathSync as realpathSync5, rmSync as rmSync2, writeFileSync as writeFileSync3 } from "node:fs";
|
|
8377
8461
|
import { createRequire as createRequire3 } from "node:module";
|
|
8378
|
-
import { dirname as
|
|
8462
|
+
import { dirname as dirname7, isAbsolute as isAbsolute2, relative as relative2, resolve as resolve4 } from "node:path";
|
|
8379
8463
|
import { deflateRawSync, gunzipSync, gzipSync, inflateRawSync } from "node:zlib";
|
|
8380
8464
|
function toSqliteBindValues(params) {
|
|
8381
8465
|
return params.map((param) => typeof param === "boolean" ? param ? 1 : 0 : param);
|
|
@@ -8413,9 +8497,9 @@ function sqliteDatabase() {
|
|
|
8413
8497
|
}
|
|
8414
8498
|
}
|
|
8415
8499
|
function existingSqliteFile(path3) {
|
|
8416
|
-
if (!
|
|
8500
|
+
if (!existsSync11(path3))
|
|
8417
8501
|
return;
|
|
8418
|
-
return
|
|
8502
|
+
return readFileSync4(path3).subarray(0, 16).toString("binary") === "SQLite format 3\x00";
|
|
8419
8503
|
}
|
|
8420
8504
|
function sqliteSelectorForPath(value, cwd) {
|
|
8421
8505
|
const selector = parseSqliteSelector(value);
|
|
@@ -8529,7 +8613,7 @@ function readZipEntriesFromBuffer(buf, label) {
|
|
|
8529
8613
|
return entries;
|
|
8530
8614
|
}
|
|
8531
8615
|
function readZipEntries(path3) {
|
|
8532
|
-
return readZipEntriesFromBuffer(
|
|
8616
|
+
return readZipEntriesFromBuffer(readFileSync4(path3), path3);
|
|
8533
8617
|
}
|
|
8534
8618
|
function writeZipEntries(path3, entries) {
|
|
8535
8619
|
const locals = [], centrals = [];
|
|
@@ -8568,7 +8652,7 @@ function writeZipEntries(path3, entries) {
|
|
|
8568
8652
|
writeFileSync3(path3, Buffer.concat([...locals, ...centrals, eocd]));
|
|
8569
8653
|
}
|
|
8570
8654
|
function parseTar(path3) {
|
|
8571
|
-
const raw =
|
|
8655
|
+
const raw = readFileSync4(path3);
|
|
8572
8656
|
if (raw.length > MAX_TAR_ARCHIVE_BYTES)
|
|
8573
8657
|
throw new Error(`Archive too large: ${path3}`);
|
|
8574
8658
|
const buf = isGzipTar(path3) ? gunzipSync(raw, { maxOutputLength: MAX_TAR_ARCHIVE_BYTES }) : raw;
|
|
@@ -8640,7 +8724,7 @@ function listArchiveDirectory(names, memberPath) {
|
|
|
8640
8724
|
`);
|
|
8641
8725
|
}
|
|
8642
8726
|
function readZipSelector(path3, memberPath) {
|
|
8643
|
-
const buf =
|
|
8727
|
+
const buf = readFileSync4(path3);
|
|
8644
8728
|
let eocd = -1;
|
|
8645
8729
|
for (let i = buf.length - 22;i >= 0; i--)
|
|
8646
8730
|
if (buf.readUInt32LE(i) === 101010256) {
|
|
@@ -8702,7 +8786,7 @@ function validateArchiveMemberPath(memberPath) {
|
|
|
8702
8786
|
throw new Error(`Invalid archive member path: ${memberPath}`);
|
|
8703
8787
|
}
|
|
8704
8788
|
function writeZipEntrySelective(path3, memberPath, data) {
|
|
8705
|
-
const source =
|
|
8789
|
+
const source = existsSync11(path3) ? readFileSync4(path3) : Buffer.alloc(0);
|
|
8706
8790
|
const locals = [], centrals = [];
|
|
8707
8791
|
let offset = 0;
|
|
8708
8792
|
if (source.length > 0) {
|
|
@@ -8738,7 +8822,7 @@ function writeZipEntrySelective(path3, memberPath, data) {
|
|
|
8738
8822
|
}
|
|
8739
8823
|
const tmp = `${path3}.atomic-entry-${Date.now()}`;
|
|
8740
8824
|
writeZipEntries(tmp, new Map([[memberPath, data]]));
|
|
8741
|
-
const built =
|
|
8825
|
+
const built = readFileSync4(tmp);
|
|
8742
8826
|
rmSync2(tmp, { force: true });
|
|
8743
8827
|
const eocdStart = built.length - 22, localLen = built.readUInt32LE(eocdStart + 16), centralSizeOne = built.readUInt32LE(eocdStart + 12);
|
|
8744
8828
|
const central = Buffer.from(built.subarray(localLen, localLen + centralSizeOne));
|
|
@@ -8756,12 +8840,12 @@ function writeZipEntrySelective(path3, memberPath, data) {
|
|
|
8756
8840
|
}
|
|
8757
8841
|
function writeArchiveSelector(selector, content) {
|
|
8758
8842
|
validateArchiveMemberPath(selector.memberPath);
|
|
8759
|
-
mkdirSync4(
|
|
8843
|
+
mkdirSync4(dirname7(selector.archivePath), { recursive: true });
|
|
8760
8844
|
if (isZipArchive(selector.archivePath)) {
|
|
8761
8845
|
writeZipEntrySelective(selector.archivePath, selector.memberPath, Buffer.from(content));
|
|
8762
8846
|
return;
|
|
8763
8847
|
}
|
|
8764
|
-
const entries =
|
|
8848
|
+
const entries = existsSync11(selector.archivePath) ? parseTar(selector.archivePath) : new Map;
|
|
8765
8849
|
entries.set(selector.memberPath, Buffer.from(content));
|
|
8766
8850
|
writeTar(selector.archivePath, entries);
|
|
8767
8851
|
}
|
|
@@ -8897,8 +8981,8 @@ function isContained(root, candidate) {
|
|
|
8897
8981
|
}
|
|
8898
8982
|
function nearestExistingAncestor(pathValue) {
|
|
8899
8983
|
let current = pathValue;
|
|
8900
|
-
while (!
|
|
8901
|
-
const parent =
|
|
8984
|
+
while (!existsSync11(current)) {
|
|
8985
|
+
const parent = dirname7(current);
|
|
8902
8986
|
if (parent === current)
|
|
8903
8987
|
return current;
|
|
8904
8988
|
current = parent;
|
|
@@ -8923,7 +9007,7 @@ function fallbackInternalPath(value, cwd) {
|
|
|
8923
9007
|
const skill = value.match(/^skill:\/\/([^/]+)(?:\/(.*))?$/);
|
|
8924
9008
|
if (skill) {
|
|
8925
9009
|
const name = skill[1] ?? "", rest = skill[2] || "SKILL.md";
|
|
8926
|
-
return [".agents/skills", "packages/subagents/skills", "packages/workflows/skills"].map((base) => resolveContainedPath(resolveContainedLocalPath(cwd, base, "skill:// resource"), `${name}/${rest}`, "skill:// resource")).find((candidate) =>
|
|
9010
|
+
return [".agents/skills", "packages/subagents/skills", "packages/workflows/skills"].map((base) => resolveContainedPath(resolveContainedLocalPath(cwd, base, "skill:// resource"), `${name}/${rest}`, "skill:// resource")).find((candidate) => existsSync11(candidate));
|
|
8927
9011
|
}
|
|
8928
9012
|
const local = value.match(/^local:\/\/(.+)$/);
|
|
8929
9013
|
if (local)
|
|
@@ -8941,9 +9025,9 @@ async function readInternalSelector(value, cwd, context) {
|
|
|
8941
9025
|
if (Buffer.isBuffer(routed))
|
|
8942
9026
|
return routed.toString("utf8");
|
|
8943
9027
|
const resolved = await resolveViaRouter(value, cwd, context);
|
|
8944
|
-
if (!resolved || !
|
|
9028
|
+
if (!resolved || !existsSync11(resolved))
|
|
8945
9029
|
throw new Error(`Internal resource not found or no session router supports it: ${value}`);
|
|
8946
|
-
return
|
|
9030
|
+
return readFileSync4(resolved, "utf8");
|
|
8947
9031
|
}
|
|
8948
9032
|
async function writeInternalSelector(value, cwd, content, context) {
|
|
8949
9033
|
const router = routerFromContext(context);
|
|
@@ -8954,7 +9038,7 @@ async function writeInternalSelector(value, cwd, content, context) {
|
|
|
8954
9038
|
const resolved = await resolveViaRouter(value, cwd, context);
|
|
8955
9039
|
if (!resolved)
|
|
8956
9040
|
throw new Error(`Unsupported writable internal resource without a session router: ${value}`);
|
|
8957
|
-
mkdirSync4(
|
|
9041
|
+
mkdirSync4(dirname7(resolved), { recursive: true });
|
|
8958
9042
|
writeFileSync3(resolved, content);
|
|
8959
9043
|
}
|
|
8960
9044
|
async function searchInternalSelector(value, cwd, pattern, ignoreCase = false, literal = false, context, contextBefore = 1, contextAfter = 3) {
|
|
@@ -9236,7 +9320,7 @@ function parseLooseJsonObject(content) {
|
|
|
9236
9320
|
function writeSqliteSelector(selector, content) {
|
|
9237
9321
|
if (!selector.table)
|
|
9238
9322
|
throw new Error("SQLite write target must include a table name");
|
|
9239
|
-
if (!
|
|
9323
|
+
if (!existsSync11(selector.databasePath))
|
|
9240
9324
|
throw new Error(`SQLite database does not exist: ${selector.databasePath}`);
|
|
9241
9325
|
if (content.trim() === "") {
|
|
9242
9326
|
if (!selector.rowId)
|
|
@@ -10015,12 +10099,12 @@ var init_agent_session_bash = __esm(() => {
|
|
|
10015
10099
|
});
|
|
10016
10100
|
|
|
10017
10101
|
// src/core/auth-guidance.ts
|
|
10018
|
-
import { join as
|
|
10102
|
+
import { join as join17 } from "node:path";
|
|
10019
10103
|
function getProviderLoginHelp() {
|
|
10020
10104
|
return [
|
|
10021
10105
|
"Use /login to log into a provider via OAuth or API key. See:",
|
|
10022
|
-
` ${
|
|
10023
|
-
` ${
|
|
10106
|
+
` ${join17(getDocsPath(), "providers.md")}`,
|
|
10107
|
+
` ${join17(getDocsPath(), "models.md")}`
|
|
10024
10108
|
].join(`
|
|
10025
10109
|
`);
|
|
10026
10110
|
}
|
|
@@ -11197,10 +11281,10 @@ function getUsageCostBreakdown(entries) {
|
|
|
11197
11281
|
}
|
|
11198
11282
|
|
|
11199
11283
|
// src/core/export-html/template-script.ts
|
|
11200
|
-
import { readFileSync as
|
|
11201
|
-
import { join as
|
|
11284
|
+
import { readFileSync as readFileSync5 } from "fs";
|
|
11285
|
+
import { join as join18 } from "path";
|
|
11202
11286
|
function readExportHtmlTemplateScript(templateDir) {
|
|
11203
|
-
return EXPORT_HTML_TEMPLATE_SCRIPT_CHUNKS.map((fileName) =>
|
|
11287
|
+
return EXPORT_HTML_TEMPLATE_SCRIPT_CHUNKS.map((fileName) => readFileSync5(join18(templateDir, "template-js", fileName), "utf-8")).join("");
|
|
11204
11288
|
}
|
|
11205
11289
|
var EXPORT_HTML_TEMPLATE_SCRIPT_CHUNKS;
|
|
11206
11290
|
var init_template_script = __esm(() => {
|
|
@@ -11219,8 +11303,8 @@ __export(exports_export_html, {
|
|
|
11219
11303
|
exportFromFile: () => exportFromFile,
|
|
11220
11304
|
exportSessionToHtml: () => exportSessionToHtml
|
|
11221
11305
|
});
|
|
11222
|
-
import { existsSync as
|
|
11223
|
-
import { basename as basename4, join as
|
|
11306
|
+
import { existsSync as existsSync12, readFileSync as readFileSync6, writeFileSync as writeFileSync4 } from "fs";
|
|
11307
|
+
import { basename as basename4, join as join19 } from "path";
|
|
11224
11308
|
function parseColor(color) {
|
|
11225
11309
|
const hexMatch = color.match(/^#([0-9a-fA-F]{2})([0-9a-fA-F]{2})([0-9a-fA-F]{2})$/);
|
|
11226
11310
|
if (hexMatch) {
|
|
@@ -11295,11 +11379,11 @@ function generateThemeVars(themeName) {
|
|
|
11295
11379
|
}
|
|
11296
11380
|
function generateHtml(sessionData, themeName) {
|
|
11297
11381
|
const templateDir = getExportTemplateDir();
|
|
11298
|
-
const template =
|
|
11299
|
-
const templateCss =
|
|
11382
|
+
const template = readFileSync6(join19(templateDir, "template.html"), "utf-8");
|
|
11383
|
+
const templateCss = readFileSync6(join19(templateDir, "template.css"), "utf-8");
|
|
11300
11384
|
const templateJs = readExportHtmlTemplateScript(templateDir);
|
|
11301
|
-
const markedJs =
|
|
11302
|
-
const hljsJs =
|
|
11385
|
+
const markedJs = readFileSync6(join19(templateDir, "vendor", "marked.min.js"), "utf-8");
|
|
11386
|
+
const hljsJs = readFileSync6(join19(templateDir, "vendor", "highlight.min.js"), "utf-8");
|
|
11303
11387
|
const themeVars = generateThemeVars(themeName);
|
|
11304
11388
|
const colors = getResolvedThemeColors(themeName);
|
|
11305
11389
|
const themeExport = getThemeExportColors(themeName);
|
|
@@ -11350,7 +11434,7 @@ async function exportSessionToHtml(sm, state, options) {
|
|
|
11350
11434
|
if (!sessionFile) {
|
|
11351
11435
|
throw new Error("Cannot export in-memory session to HTML");
|
|
11352
11436
|
}
|
|
11353
|
-
if (!
|
|
11437
|
+
if (!existsSync12(sessionFile)) {
|
|
11354
11438
|
throw new Error("Nothing to export yet - start a conversation first");
|
|
11355
11439
|
}
|
|
11356
11440
|
const entries = sm.getEntries();
|
|
@@ -11381,7 +11465,7 @@ async function exportSessionToHtml(sm, state, options) {
|
|
|
11381
11465
|
async function exportFromFile(inputPath, options) {
|
|
11382
11466
|
const opts = typeof options === "string" ? { outputPath: options } : options || {};
|
|
11383
11467
|
const resolvedInputPath = resolvePath(inputPath);
|
|
11384
|
-
if (!
|
|
11468
|
+
if (!existsSync12(resolvedInputPath)) {
|
|
11385
11469
|
throw new Error(`File not found: ${resolvedInputPath}`);
|
|
11386
11470
|
}
|
|
11387
11471
|
const sm = SessionManager.open(resolvedInputPath);
|
|
@@ -11683,8 +11767,8 @@ var init_tool_renderer = __esm(() => {
|
|
|
11683
11767
|
});
|
|
11684
11768
|
|
|
11685
11769
|
// src/core/agent-session-export.ts
|
|
11686
|
-
import { existsSync as
|
|
11687
|
-
import { dirname as
|
|
11770
|
+
import { existsSync as existsSync13, mkdirSync as mkdirSync5, writeFileSync as writeFileSync5 } from "node:fs";
|
|
11771
|
+
import { dirname as dirname8 } from "node:path";
|
|
11688
11772
|
function getSessionStats() {
|
|
11689
11773
|
let userMessages = 0;
|
|
11690
11774
|
let assistantMessages = 0;
|
|
@@ -11788,8 +11872,8 @@ async function exportToHtml(outputPath, options = {}) {
|
|
|
11788
11872
|
}
|
|
11789
11873
|
function exportToJsonl(outputPath) {
|
|
11790
11874
|
const filePath = resolvePath(outputPath ?? `session-${new Date().toISOString().replace(/[:.]/g, "-")}.jsonl`, process.cwd());
|
|
11791
|
-
const dir =
|
|
11792
|
-
if (!
|
|
11875
|
+
const dir = dirname8(filePath);
|
|
11876
|
+
if (!existsSync13(dir)) {
|
|
11793
11877
|
mkdirSync5(dir, { recursive: true });
|
|
11794
11878
|
}
|
|
11795
11879
|
const header = {
|
|
@@ -12123,8 +12207,8 @@ var init_loader_runtime = __esm(() => {
|
|
|
12123
12207
|
});
|
|
12124
12208
|
|
|
12125
12209
|
// src/core/tools/artifacts.ts
|
|
12126
|
-
import { existsSync as
|
|
12127
|
-
import { join as
|
|
12210
|
+
import { existsSync as existsSync14, mkdirSync as mkdirSync6, readdirSync as readdirSync3, writeFileSync as writeFileSync6 } from "node:fs";
|
|
12211
|
+
import { join as join20 } from "node:path";
|
|
12128
12212
|
|
|
12129
12213
|
class ArtifactManager {
|
|
12130
12214
|
#nextId = 0;
|
|
@@ -12141,7 +12225,7 @@ class ArtifactManager {
|
|
|
12141
12225
|
return;
|
|
12142
12226
|
this.#initialized = true;
|
|
12143
12227
|
let max = -1;
|
|
12144
|
-
if (
|
|
12228
|
+
if (existsSync14(this.#dir)) {
|
|
12145
12229
|
for (const name of readdirSync3(this.#dir)) {
|
|
12146
12230
|
const match = name.match(/^(\d+)\..*\.log$/);
|
|
12147
12231
|
if (match) {
|
|
@@ -12156,30 +12240,30 @@ class ArtifactManager {
|
|
|
12156
12240
|
allocate(toolType) {
|
|
12157
12241
|
this.#init();
|
|
12158
12242
|
const id = String(this.#nextId++);
|
|
12159
|
-
const path3 =
|
|
12243
|
+
const path3 = join20(this.#dir, `${id}.${toolType}.log`);
|
|
12160
12244
|
return { path: path3, id };
|
|
12161
12245
|
}
|
|
12162
12246
|
save(content, toolType) {
|
|
12163
12247
|
this.#init();
|
|
12164
12248
|
const { path: path3, id } = this.allocate(toolType);
|
|
12165
|
-
if (!
|
|
12249
|
+
if (!existsSync14(this.#dir))
|
|
12166
12250
|
mkdirSync6(this.#dir, { recursive: true });
|
|
12167
12251
|
writeFileSync6(path3, content, "utf8");
|
|
12168
12252
|
return id;
|
|
12169
12253
|
}
|
|
12170
12254
|
resolve(id) {
|
|
12171
12255
|
this.#init();
|
|
12172
|
-
if (!
|
|
12256
|
+
if (!existsSync14(this.#dir))
|
|
12173
12257
|
return;
|
|
12174
12258
|
const prefix = `${id}.`;
|
|
12175
12259
|
for (const name of readdirSync3(this.#dir))
|
|
12176
12260
|
if (name.startsWith(prefix) && name.endsWith(".log"))
|
|
12177
|
-
return
|
|
12261
|
+
return join20(this.#dir, name);
|
|
12178
12262
|
return;
|
|
12179
12263
|
}
|
|
12180
12264
|
list() {
|
|
12181
12265
|
this.#init();
|
|
12182
|
-
if (!
|
|
12266
|
+
if (!existsSync14(this.#dir))
|
|
12183
12267
|
return [];
|
|
12184
12268
|
const ids = [];
|
|
12185
12269
|
for (const name of readdirSync3(this.#dir)) {
|
|
@@ -12204,7 +12288,7 @@ var init_artifacts = __esm(() => {
|
|
|
12204
12288
|
});
|
|
12205
12289
|
|
|
12206
12290
|
// src/core/tools/artifact-protocol.ts
|
|
12207
|
-
import { existsSync as
|
|
12291
|
+
import { existsSync as existsSync15, readFileSync as readFileSync7 } from "node:fs";
|
|
12208
12292
|
function registerArtifactDir(dir) {
|
|
12209
12293
|
activeArtifactDirs.add(dir);
|
|
12210
12294
|
}
|
|
@@ -12249,9 +12333,9 @@ function createArtifactRouter(getPinnedDirs) {
|
|
|
12249
12333
|
if (!/^artifact:\/\//i.test(url))
|
|
12250
12334
|
return;
|
|
12251
12335
|
const path3 = resolveArtifactUrl(url, getPinnedDirs());
|
|
12252
|
-
if (!path3 || !
|
|
12336
|
+
if (!path3 || !existsSync15(path3))
|
|
12253
12337
|
throw new Error(`Artifact not found: ${url}`);
|
|
12254
|
-
return
|
|
12338
|
+
return readFileSync7(path3, "utf8");
|
|
12255
12339
|
}
|
|
12256
12340
|
};
|
|
12257
12341
|
}
|
|
@@ -12262,7 +12346,7 @@ var init_artifact_protocol = __esm(() => {
|
|
|
12262
12346
|
});
|
|
12263
12347
|
|
|
12264
12348
|
// src/core/extensions/runner-context.ts
|
|
12265
|
-
import { join as
|
|
12349
|
+
import { join as join21 } from "node:path";
|
|
12266
12350
|
function deepFrozenCopy(value) {
|
|
12267
12351
|
if (Array.isArray(value))
|
|
12268
12352
|
return Object.freeze(value.map(deepFrozenCopy));
|
|
@@ -12322,7 +12406,7 @@ function createExtensionContext(source) {
|
|
|
12322
12406
|
const sessionDir = source.getSessionManager().getSessionDir();
|
|
12323
12407
|
if (!sessionDir)
|
|
12324
12408
|
return;
|
|
12325
|
-
const artifactsDir =
|
|
12409
|
+
const artifactsDir = join21(sessionDir, "artifacts");
|
|
12326
12410
|
registerArtifactDir(artifactsDir);
|
|
12327
12411
|
return createArtifactRouter(() => [artifactsDir]);
|
|
12328
12412
|
},
|
|
@@ -13263,7 +13347,7 @@ var init_runner = __esm(() => {
|
|
|
13263
13347
|
|
|
13264
13348
|
// src/core/skill-catalog.ts
|
|
13265
13349
|
import { createHash as createHash3 } from "node:crypto";
|
|
13266
|
-
import { basename as basename5, dirname as
|
|
13350
|
+
import { basename as basename5, dirname as dirname9, sep as sep4 } from "node:path";
|
|
13267
13351
|
function candidateId(skill) {
|
|
13268
13352
|
return `skill_${createHash3("sha256").update(canonicalizePath(skill.filePath)).digest("hex").slice(0, 20)}`;
|
|
13269
13353
|
}
|
|
@@ -13307,7 +13391,7 @@ function sourceLabel(skill) {
|
|
|
13307
13391
|
}
|
|
13308
13392
|
const pathParts = canonicalizePath(skill.filePath).split(sep4).filter(Boolean);
|
|
13309
13393
|
const configPart = [...pathParts].reverse().find((part) => part === ".atomic" || part === ".pi" || part === ".agents");
|
|
13310
|
-
return configPart ? configPart.slice(1) : readableToken(basename5(skill.sourceInfo.baseDir ??
|
|
13394
|
+
return configPart ? configPart.slice(1) : readableToken(basename5(skill.sourceInfo.baseDir ?? dirname9(skill.filePath)));
|
|
13311
13395
|
}
|
|
13312
13396
|
function uniquePathLabels(candidates) {
|
|
13313
13397
|
const labels = new Map(candidates.map((candidate) => [candidate.id, sourceLabel(candidate.skill)]));
|
|
@@ -13321,7 +13405,7 @@ function uniquePathLabels(candidates) {
|
|
|
13321
13405
|
for (const [label, matching] of byLabel) {
|
|
13322
13406
|
if (matching.length === 1)
|
|
13323
13407
|
continue;
|
|
13324
|
-
const pathParts = matching.map((candidate) => canonicalizePath(
|
|
13408
|
+
const pathParts = matching.map((candidate) => canonicalizePath(dirname9(candidate.skill.filePath)).split(sep4).filter(Boolean));
|
|
13325
13409
|
for (let depth = 1;depth <= Math.max(...pathParts.map((parts) => parts.length)); depth++) {
|
|
13326
13410
|
const suffixes = pathParts.map((parts) => parts.slice(-depth).join("/"));
|
|
13327
13411
|
if (new Set(suffixes).size !== suffixes.length)
|
|
@@ -13513,7 +13597,7 @@ var init_skill_catalog = __esm(() => {
|
|
|
13513
13597
|
});
|
|
13514
13598
|
|
|
13515
13599
|
// src/core/agent-session-extension-bindings.ts
|
|
13516
|
-
import { basename as basename6, dirname as
|
|
13600
|
+
import { basename as basename6, dirname as dirname10 } from "node:path";
|
|
13517
13601
|
import { resetApiProviders } from "@bastani/pi-ai/compat";
|
|
13518
13602
|
async function bindExtensions(bindings) {
|
|
13519
13603
|
if (bindings.uiContext !== undefined) {
|
|
@@ -13561,7 +13645,7 @@ function buildExtensionResourcePaths(entries) {
|
|
|
13561
13645
|
const extension = extensions.find((candidate) => candidate.path === entry.extensionPath || candidate.resolvedPath === entry.extensionPath || candidate.sourceInfo.path === entry.extensionPath);
|
|
13562
13646
|
const sourceInfo = extension?.sourceInfo;
|
|
13563
13647
|
const source = sourceInfo?.source ?? this.getExtensionSourceLabel(entry.extensionPath);
|
|
13564
|
-
const baseDir = sourceInfo?.baseDir ?? (entry.extensionPath.startsWith("<") ? undefined :
|
|
13648
|
+
const baseDir = sourceInfo?.baseDir ?? (entry.extensionPath.startsWith("<") ? undefined : dirname10(entry.extensionPath));
|
|
13565
13649
|
return {
|
|
13566
13650
|
path: entry.path,
|
|
13567
13651
|
metadata: {
|
|
@@ -14658,7 +14742,7 @@ var init_frontmatter = () => {};
|
|
|
14658
14742
|
|
|
14659
14743
|
// src/utils/changelog.ts
|
|
14660
14744
|
import path3 from "node:path";
|
|
14661
|
-
import { existsSync as
|
|
14745
|
+
import { existsSync as existsSync16, readFileSync as readFileSync8 } from "fs";
|
|
14662
14746
|
function parsedVersionFromMatch(match) {
|
|
14663
14747
|
return {
|
|
14664
14748
|
version: match[1],
|
|
@@ -14752,11 +14836,11 @@ function normalizeChangelogLinks(markdown, version) {
|
|
|
14752
14836
|
});
|
|
14753
14837
|
}
|
|
14754
14838
|
function parseChangelog(changelogPath) {
|
|
14755
|
-
if (!
|
|
14839
|
+
if (!existsSync16(changelogPath)) {
|
|
14756
14840
|
return [];
|
|
14757
14841
|
}
|
|
14758
14842
|
try {
|
|
14759
|
-
const content =
|
|
14843
|
+
const content = readFileSync8(changelogPath, "utf-8");
|
|
14760
14844
|
const lines = content.split(`
|
|
14761
14845
|
`);
|
|
14762
14846
|
const entries = [];
|
|
@@ -15265,7 +15349,7 @@ var init_prompt_templates = __esm(() => {
|
|
|
15265
15349
|
});
|
|
15266
15350
|
|
|
15267
15351
|
// src/core/agent-session-prompt.ts
|
|
15268
|
-
import { readFileSync as
|
|
15352
|
+
import { readFileSync as readFileSync9 } from "node:fs";
|
|
15269
15353
|
async function tryExecuteSessionSlashCommand(session, text) {
|
|
15270
15354
|
if (!text.startsWith("/"))
|
|
15271
15355
|
return false;
|
|
@@ -15537,7 +15621,7 @@ function _expandSkillCommand(text) {
|
|
|
15537
15621
|
}
|
|
15538
15622
|
const { skill, id } = resolution.candidate;
|
|
15539
15623
|
try {
|
|
15540
|
-
const content =
|
|
15624
|
+
const content = readFileSync9(skill.filePath, "utf-8");
|
|
15541
15625
|
const body = stripFrontmatter(content).trim();
|
|
15542
15626
|
const skillBlock = `<skill name="${selector}" location="${skill.filePath}" candidate="${id}">
|
|
15543
15627
|
References are relative to ${skill.baseDir}.
|
|
@@ -16599,9 +16683,9 @@ var init_agent_session_retry = __esm(() => {
|
|
|
16599
16683
|
});
|
|
16600
16684
|
|
|
16601
16685
|
// src/core/skills.ts
|
|
16602
|
-
import { existsSync as
|
|
16686
|
+
import { existsSync as existsSync17, readdirSync as readdirSync4, readFileSync as readFileSync10, statSync as statSync4 } from "fs";
|
|
16603
16687
|
import ignore from "ignore";
|
|
16604
|
-
import { basename as basename7, dirname as
|
|
16688
|
+
import { basename as basename7, dirname as dirname11, join as join22, relative as relative4, resolve as resolve5, sep as sep5 } from "path";
|
|
16605
16689
|
function toPosixPath(p) {
|
|
16606
16690
|
return p.split(sep5).join("/");
|
|
16607
16691
|
}
|
|
@@ -16629,11 +16713,11 @@ function addIgnoreRules(ig, dir, rootDir) {
|
|
|
16629
16713
|
const relativeDir = relative4(rootDir, dir);
|
|
16630
16714
|
const prefix = relativeDir ? `${toPosixPath(relativeDir)}/` : "";
|
|
16631
16715
|
for (const filename of IGNORE_FILE_NAMES) {
|
|
16632
|
-
const ignorePath =
|
|
16633
|
-
if (!
|
|
16716
|
+
const ignorePath = join22(dir, filename);
|
|
16717
|
+
if (!existsSync17(ignorePath))
|
|
16634
16718
|
continue;
|
|
16635
16719
|
try {
|
|
16636
|
-
const content =
|
|
16720
|
+
const content = readFileSync10(ignorePath, "utf-8");
|
|
16637
16721
|
const patterns = content.split(/\r?\n/).map((line) => prefixIgnorePattern(line, prefix)).filter((line) => Boolean(line));
|
|
16638
16722
|
if (patterns.length > 0) {
|
|
16639
16723
|
ig.add(patterns);
|
|
@@ -16696,7 +16780,7 @@ function loadSkillsFromDir(options) {
|
|
|
16696
16780
|
function loadSkillsFromDirInternal(dir, source, includeRootFiles, ignoreMatcher, rootDir) {
|
|
16697
16781
|
const skills = [];
|
|
16698
16782
|
const diagnostics = [];
|
|
16699
|
-
if (!
|
|
16783
|
+
if (!existsSync17(dir)) {
|
|
16700
16784
|
return { skills, candidates: skills, diagnostics };
|
|
16701
16785
|
}
|
|
16702
16786
|
const root = rootDir ?? dir;
|
|
@@ -16708,7 +16792,7 @@ function loadSkillsFromDirInternal(dir, source, includeRootFiles, ignoreMatcher,
|
|
|
16708
16792
|
if (entry.name !== "SKILL.md") {
|
|
16709
16793
|
continue;
|
|
16710
16794
|
}
|
|
16711
|
-
const fullPath =
|
|
16795
|
+
const fullPath = join22(dir, entry.name);
|
|
16712
16796
|
let isFile = entry.isFile();
|
|
16713
16797
|
if (entry.isSymbolicLink()) {
|
|
16714
16798
|
try {
|
|
@@ -16735,7 +16819,7 @@ function loadSkillsFromDirInternal(dir, source, includeRootFiles, ignoreMatcher,
|
|
|
16735
16819
|
if (entry.name === "node_modules") {
|
|
16736
16820
|
continue;
|
|
16737
16821
|
}
|
|
16738
|
-
const fullPath =
|
|
16822
|
+
const fullPath = join22(dir, entry.name);
|
|
16739
16823
|
let isDirectory = entry.isDirectory();
|
|
16740
16824
|
let isFile = entry.isFile();
|
|
16741
16825
|
if (entry.isSymbolicLink()) {
|
|
@@ -16773,9 +16857,9 @@ function loadSkillsFromDirInternal(dir, source, includeRootFiles, ignoreMatcher,
|
|
|
16773
16857
|
function loadSkillFromFile(filePath, source) {
|
|
16774
16858
|
const diagnostics = [];
|
|
16775
16859
|
try {
|
|
16776
|
-
const rawContent =
|
|
16860
|
+
const rawContent = readFileSync10(filePath, "utf-8");
|
|
16777
16861
|
const { frontmatter } = parseFrontmatter(rawContent);
|
|
16778
|
-
const skillDir =
|
|
16862
|
+
const skillDir = dirname11(filePath);
|
|
16779
16863
|
const parentDirName = basename7(skillDir);
|
|
16780
16864
|
const descErrors = validateDescription(frontmatter.description);
|
|
16781
16865
|
for (const error of descErrors) {
|
|
@@ -16871,10 +16955,10 @@ function loadSkills(options) {
|
|
|
16871
16955
|
}
|
|
16872
16956
|
}
|
|
16873
16957
|
if (includeDefaults) {
|
|
16874
|
-
addSkills(loadSkillsFromDirInternal(
|
|
16958
|
+
addSkills(loadSkillsFromDirInternal(join22(resolvedAgentDir, "skills"), "user", true));
|
|
16875
16959
|
addSkills(loadSkillsFromDirInternal(resolve5(resolvedCwd, CONFIG_DIR_NAME, "skills"), "project", true));
|
|
16876
16960
|
}
|
|
16877
|
-
const userSkillsDir =
|
|
16961
|
+
const userSkillsDir = join22(resolvedAgentDir, "skills");
|
|
16878
16962
|
const projectSkillsDir = resolve5(resolvedCwd, CONFIG_DIR_NAME, "skills");
|
|
16879
16963
|
const isUnderPath = (target, root) => {
|
|
16880
16964
|
const normalizedRoot = resolve5(root);
|
|
@@ -16895,7 +16979,7 @@ function loadSkills(options) {
|
|
|
16895
16979
|
};
|
|
16896
16980
|
for (const rawPath of skillPaths) {
|
|
16897
16981
|
const resolvedPath = resolvePath(rawPath, resolvedCwd, { trim: true });
|
|
16898
|
-
if (!
|
|
16982
|
+
if (!existsSync17(resolvedPath)) {
|
|
16899
16983
|
allDiagnostics.push({ type: "warning", message: "skill path does not exist", path: resolvedPath });
|
|
16900
16984
|
continue;
|
|
16901
16985
|
}
|
|
@@ -17931,7 +18015,7 @@ function assertToolPairingInvariant(messages) {
|
|
|
17931
18015
|
import { Buffer as Buffer3 } from "node:buffer";
|
|
17932
18016
|
import { constants as constants3 } from "node:fs";
|
|
17933
18017
|
import { chmod, lstat, mkdir, open } from "node:fs/promises";
|
|
17934
|
-
import { join as
|
|
18018
|
+
import { join as join24 } from "node:path";
|
|
17935
18019
|
function getPersistenceThreshold(declaredMaxResultSizeChars) {
|
|
17936
18020
|
if (declaredMaxResultSizeChars === undefined) {
|
|
17937
18021
|
return DEFAULT_MAX_RESULT_SIZE_CHARS;
|
|
@@ -18020,14 +18104,14 @@ function sanitizePathComponent(value, fallback) {
|
|
|
18020
18104
|
}
|
|
18021
18105
|
async function ensureToolResultsDir(input) {
|
|
18022
18106
|
if (input.sessionDir?.trim()) {
|
|
18023
|
-
const dir =
|
|
18107
|
+
const dir = join24(input.sessionDir, TOOL_RESULTS_SUBDIR);
|
|
18024
18108
|
await mkdir(dir, { recursive: true, mode: SESSION_TEMP_DIR_MODE });
|
|
18025
18109
|
if (process.platform !== "win32") {
|
|
18026
18110
|
await chmod(dir, SESSION_TEMP_DIR_MODE);
|
|
18027
18111
|
}
|
|
18028
18112
|
return dir;
|
|
18029
18113
|
}
|
|
18030
|
-
return ensureTempDir(
|
|
18114
|
+
return ensureTempDir(join24(resolveSessionTempDirPath(input.sessionId), TOOL_RESULTS_SUBDIR));
|
|
18031
18115
|
}
|
|
18032
18116
|
function isOwnedByCurrentUser(uid) {
|
|
18033
18117
|
const currentUid = typeof process.getuid === "function" ? process.getuid() : undefined;
|
|
@@ -18093,7 +18177,7 @@ async function persistToolOutput(input) {
|
|
|
18093
18177
|
} catch {
|
|
18094
18178
|
return;
|
|
18095
18179
|
}
|
|
18096
|
-
const filepath =
|
|
18180
|
+
const filepath = join24(dir, `${sanitizePathComponent(input.toolCallId, "tool-result")}.txt`);
|
|
18097
18181
|
try {
|
|
18098
18182
|
const handle = await open(filepath, "wx", SESSION_TEMP_FILE_MODE);
|
|
18099
18183
|
try {
|
|
@@ -19162,8 +19246,8 @@ var init_loader_core = __esm(() => {
|
|
|
19162
19246
|
});
|
|
19163
19247
|
|
|
19164
19248
|
// src/core/package-manager-manifest.ts
|
|
19165
|
-
import { existsSync as
|
|
19166
|
-
import { join as
|
|
19249
|
+
import { existsSync as existsSync19, readFileSync as readFileSync12 } from "node:fs";
|
|
19250
|
+
import { join as join26 } from "node:path";
|
|
19167
19251
|
function isRecord(value) {
|
|
19168
19252
|
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
19169
19253
|
}
|
|
@@ -19186,7 +19270,7 @@ function getManifestFromPackageJson(pkg2) {
|
|
|
19186
19270
|
}
|
|
19187
19271
|
function readPiManifestFile(packageJsonPath) {
|
|
19188
19272
|
try {
|
|
19189
|
-
const content =
|
|
19273
|
+
const content = readFileSync12(packageJsonPath, "utf-8");
|
|
19190
19274
|
const pkg2 = JSON.parse(content);
|
|
19191
19275
|
return getManifestFromPackageJson(pkg2);
|
|
19192
19276
|
} catch {
|
|
@@ -19195,9 +19279,9 @@ function readPiManifestFile(packageJsonPath) {
|
|
|
19195
19279
|
}
|
|
19196
19280
|
function conventionDirsForResource(packageRoot, resourceType) {
|
|
19197
19281
|
if (resourceType === "workflows") {
|
|
19198
|
-
return [
|
|
19282
|
+
return [join26(packageRoot, "workflows"), join26(packageRoot, "workflow")];
|
|
19199
19283
|
}
|
|
19200
|
-
return [
|
|
19284
|
+
return [join26(packageRoot, resourceType)];
|
|
19201
19285
|
}
|
|
19202
19286
|
function manifestEntriesForResource(manifest, resourceType) {
|
|
19203
19287
|
if (!manifest)
|
|
@@ -20281,14 +20365,14 @@ var init_model_registry = __esm(() => {
|
|
|
20281
20365
|
});
|
|
20282
20366
|
|
|
20283
20367
|
// src/core/tools/ask-user-question/config.ts
|
|
20284
|
-
import { existsSync as
|
|
20368
|
+
import { existsSync as existsSync21, readFileSync as readFileSync13 } from "node:fs";
|
|
20285
20369
|
import { homedir as homedir5 } from "node:os";
|
|
20286
|
-
import { join as
|
|
20370
|
+
import { join as join28 } from "node:path";
|
|
20287
20371
|
function loadConfig() {
|
|
20288
|
-
if (!
|
|
20372
|
+
if (!existsSync21(CONFIG_PATH))
|
|
20289
20373
|
return {};
|
|
20290
20374
|
try {
|
|
20291
|
-
const parsed = JSON.parse(
|
|
20375
|
+
const parsed = JSON.parse(readFileSync13(CONFIG_PATH, "utf-8"));
|
|
20292
20376
|
if (parsed === null || typeof parsed !== "object")
|
|
20293
20377
|
return {};
|
|
20294
20378
|
return parsed;
|
|
@@ -20311,8 +20395,8 @@ function validateGuidanceFields(fields) {
|
|
|
20311
20395
|
}
|
|
20312
20396
|
var CONFIG_DIR, CONFIG_PATH;
|
|
20313
20397
|
var init_config2 = __esm(() => {
|
|
20314
|
-
CONFIG_DIR =
|
|
20315
|
-
CONFIG_PATH =
|
|
20398
|
+
CONFIG_DIR = join28(homedir5(), ".config", "rpiv-ask-user-question");
|
|
20399
|
+
CONFIG_PATH = join28(CONFIG_DIR, "config.json");
|
|
20316
20400
|
});
|
|
20317
20401
|
|
|
20318
20402
|
// src/core/tools/ask-user-question/view/component-binding.ts
|
|
@@ -23127,7 +23211,7 @@ var init_chat_message_renderer = __esm(() => {
|
|
|
23127
23211
|
|
|
23128
23212
|
// src/utils/clipboard-native.ts
|
|
23129
23213
|
import { createRequire as createRequire6 } from "module";
|
|
23130
|
-
import { dirname as
|
|
23214
|
+
import { dirname as dirname15, join as join29 } from "path";
|
|
23131
23215
|
import { pathToFileURL as pathToFileURL4 } from "url";
|
|
23132
23216
|
function loadClipboardNative(requires = [moduleRequire, executableDirRequire]) {
|
|
23133
23217
|
for (const requireClipboard of requires) {
|
|
@@ -23140,7 +23224,7 @@ function loadClipboardNative(requires = [moduleRequire, executableDirRequire]) {
|
|
|
23140
23224
|
var moduleRequire, executableDirRequire, hasDisplay, clipboard;
|
|
23141
23225
|
var init_clipboard_native = __esm(() => {
|
|
23142
23226
|
moduleRequire = createRequire6(import.meta.url);
|
|
23143
|
-
executableDirRequire = createRequire6(pathToFileURL4(
|
|
23227
|
+
executableDirRequire = createRequire6(pathToFileURL4(join29(dirname15(process.execPath), "package.json")).href);
|
|
23144
23228
|
hasDisplay = process.platform !== "linux" || Boolean(process.env.DISPLAY || process.env.WAYLAND_DISPLAY);
|
|
23145
23229
|
clipboard = !process.env.TERMUX_VERSION && hasDisplay ? loadClipboardNative() : null;
|
|
23146
23230
|
});
|
|
@@ -23148,9 +23232,9 @@ var init_clipboard_native = __esm(() => {
|
|
|
23148
23232
|
// src/utils/clipboard-image.ts
|
|
23149
23233
|
import { spawnSync as spawnSync4 } from "child_process";
|
|
23150
23234
|
import { randomUUID as randomUUID2 } from "crypto";
|
|
23151
|
-
import { readFileSync as
|
|
23235
|
+
import { readFileSync as readFileSync14, unlinkSync as unlinkSync2 } from "fs";
|
|
23152
23236
|
import { tmpdir as tmpdir2 } from "os";
|
|
23153
|
-
import { join as
|
|
23237
|
+
import { join as join30 } from "path";
|
|
23154
23238
|
function isWaylandSession(env = process.env) {
|
|
23155
23239
|
return Boolean(env.WAYLAND_DISPLAY) || env.XDG_SESSION_TYPE === "wayland";
|
|
23156
23240
|
}
|
|
@@ -23240,14 +23324,14 @@ function isWSL(env = process.env) {
|
|
|
23240
23324
|
return true;
|
|
23241
23325
|
}
|
|
23242
23326
|
try {
|
|
23243
|
-
const release =
|
|
23327
|
+
const release = readFileSync14("/proc/version", "utf-8");
|
|
23244
23328
|
return /microsoft|wsl/i.test(release);
|
|
23245
23329
|
} catch {
|
|
23246
23330
|
return false;
|
|
23247
23331
|
}
|
|
23248
23332
|
}
|
|
23249
23333
|
function readClipboardImageViaPowerShell() {
|
|
23250
|
-
const tmpFile =
|
|
23334
|
+
const tmpFile = join30(tmpdir2(), `pi-wsl-clip-${randomUUID2()}.png`);
|
|
23251
23335
|
try {
|
|
23252
23336
|
const winPathResult = runCommand("wslpath", ["-w", tmpFile], { timeoutMs: DEFAULT_LIST_TIMEOUT_MS });
|
|
23253
23337
|
if (!winPathResult.ok) {
|
|
@@ -23275,7 +23359,7 @@ function readClipboardImageViaPowerShell() {
|
|
|
23275
23359
|
if (output !== "ok") {
|
|
23276
23360
|
return null;
|
|
23277
23361
|
}
|
|
23278
|
-
const bytes =
|
|
23362
|
+
const bytes = readFileSync14(tmpFile);
|
|
23279
23363
|
if (bytes.length === 0) {
|
|
23280
23364
|
return null;
|
|
23281
23365
|
}
|
|
@@ -23488,9 +23572,9 @@ var init_clipboard = __esm(() => {
|
|
|
23488
23572
|
|
|
23489
23573
|
// src/modes/interactive/external-editor.ts
|
|
23490
23574
|
import { spawn as spawn5 } from "node:child_process";
|
|
23491
|
-
import { mkdtempSync, readFileSync as
|
|
23575
|
+
import { mkdtempSync, readFileSync as readFileSync15, rmSync as rmSync4, writeFileSync as writeFileSync8 } from "node:fs";
|
|
23492
23576
|
import { tmpdir as tmpdir3 } from "node:os";
|
|
23493
|
-
import { join as
|
|
23577
|
+
import { join as join31 } from "node:path";
|
|
23494
23578
|
function parseEditorCommand(command) {
|
|
23495
23579
|
const args = [];
|
|
23496
23580
|
let current = "";
|
|
@@ -23555,8 +23639,8 @@ function resolveExternalEditorCommand(configuredCommand, environment = process.e
|
|
|
23555
23639
|
return platform2 === "win32" ? "notepad" : "nano";
|
|
23556
23640
|
}
|
|
23557
23641
|
async function editInExternalEditor(request) {
|
|
23558
|
-
const directory = mkdtempSync(
|
|
23559
|
-
const filePath =
|
|
23642
|
+
const directory = mkdtempSync(join31(tmpdir3(), `${APP_NAME}-editor-`));
|
|
23643
|
+
const filePath = join31(directory, "prompt.md");
|
|
23560
23644
|
try {
|
|
23561
23645
|
writeFileSync8(filePath, request.content, {
|
|
23562
23646
|
encoding: "utf-8",
|
|
@@ -23580,7 +23664,7 @@ ${APP_NAME} will resume when the editor exits.
|
|
|
23580
23664
|
return { status: "failed" };
|
|
23581
23665
|
return {
|
|
23582
23666
|
status: "complete",
|
|
23583
|
-
content:
|
|
23667
|
+
content: readFileSync15(filePath, "utf-8").replace(/\n$/, "")
|
|
23584
23668
|
};
|
|
23585
23669
|
} finally {
|
|
23586
23670
|
try {
|
|
@@ -28932,8 +29016,8 @@ import {
|
|
|
28932
29016
|
TUI_KEYBINDINGS,
|
|
28933
29017
|
KeybindingsManager as TuiKeybindingsManager
|
|
28934
29018
|
} from "@earendil-works/pi-tui";
|
|
28935
|
-
import { existsSync as
|
|
28936
|
-
import { join as
|
|
29019
|
+
import { existsSync as existsSync22, readFileSync as readFileSync16 } from "fs";
|
|
29020
|
+
import { join as join33 } from "path";
|
|
28937
29021
|
function isRecord3(value) {
|
|
28938
29022
|
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
28939
29023
|
}
|
|
@@ -28985,10 +29069,10 @@ function orderKeybindingsConfig(config) {
|
|
|
28985
29069
|
return ordered;
|
|
28986
29070
|
}
|
|
28987
29071
|
function loadRawConfig(path10) {
|
|
28988
|
-
if (!
|
|
29072
|
+
if (!existsSync22(path10))
|
|
28989
29073
|
return;
|
|
28990
29074
|
try {
|
|
28991
|
-
const parsed = JSON.parse(
|
|
29075
|
+
const parsed = JSON.parse(readFileSync16(path10, "utf-8"));
|
|
28992
29076
|
return isRecord3(parsed) ? parsed : undefined;
|
|
28993
29077
|
} catch {
|
|
28994
29078
|
return;
|
|
@@ -29209,7 +29293,7 @@ var init_keybindings = __esm(() => {
|
|
|
29209
29293
|
this.configPath = configPath;
|
|
29210
29294
|
}
|
|
29211
29295
|
static create(agentDir = getAgentDir()) {
|
|
29212
|
-
const configPath =
|
|
29296
|
+
const configPath = join33(agentDir, "keybindings.json");
|
|
29213
29297
|
const userBindings = KeybindingsManager.loadFromFile(configPath);
|
|
29214
29298
|
return new KeybindingsManager(userBindings, configPath);
|
|
29215
29299
|
}
|
|
@@ -29232,7 +29316,7 @@ var init_keybindings = __esm(() => {
|
|
|
29232
29316
|
|
|
29233
29317
|
// src/modes/interactive/components/session-selector-delete.ts
|
|
29234
29318
|
import { spawnSync as spawnSync5 } from "node:child_process";
|
|
29235
|
-
import { existsSync as
|
|
29319
|
+
import { existsSync as existsSync23 } from "node:fs";
|
|
29236
29320
|
import { unlink } from "node:fs/promises";
|
|
29237
29321
|
async function deleteSessionFile(sessionPath) {
|
|
29238
29322
|
const trashArgs = sessionPath.startsWith("-") ? ["--", sessionPath] : [sessionPath];
|
|
@@ -29251,7 +29335,7 @@ async function deleteSessionFile(sessionPath) {
|
|
|
29251
29335
|
return null;
|
|
29252
29336
|
return `trash: ${parts.join(" · ").slice(0, 200)}`;
|
|
29253
29337
|
};
|
|
29254
|
-
if (trashResult.status === 0 || !
|
|
29338
|
+
if (trashResult.status === 0 || !existsSync23(sessionPath)) {
|
|
29255
29339
|
return { ok: true, method: "trash" };
|
|
29256
29340
|
}
|
|
29257
29341
|
try {
|
|
@@ -32248,8 +32332,8 @@ function parseJsonFileContent(input) {
|
|
|
32248
32332
|
}
|
|
32249
32333
|
|
|
32250
32334
|
// src/core/trust-manager.ts
|
|
32251
|
-
import { existsSync as
|
|
32252
|
-
import { dirname as
|
|
32335
|
+
import { existsSync as existsSync24, mkdirSync as mkdirSync8, readFileSync as readFileSync17, writeFileSync as writeFileSync10 } from "node:fs";
|
|
32336
|
+
import { dirname as dirname16, join as join34 } from "node:path";
|
|
32253
32337
|
import lockfile from "proper-lockfile";
|
|
32254
32338
|
function normalizeCwd(cwd) {
|
|
32255
32339
|
return canonicalizePath(resolvePath(cwd));
|
|
@@ -32261,7 +32345,7 @@ function findNearestTrustEntry(data, cwd) {
|
|
|
32261
32345
|
if (value === true || value === false) {
|
|
32262
32346
|
return { path: currentDir, decision: value };
|
|
32263
32347
|
}
|
|
32264
|
-
const parentDir =
|
|
32348
|
+
const parentDir = dirname16(currentDir);
|
|
32265
32349
|
if (parentDir === currentDir) {
|
|
32266
32350
|
return null;
|
|
32267
32351
|
}
|
|
@@ -32273,7 +32357,7 @@ function getProjectTrustPath(cwd) {
|
|
|
32273
32357
|
}
|
|
32274
32358
|
function getProjectTrustParentPath(cwd) {
|
|
32275
32359
|
const trustPath = getProjectTrustPath(cwd);
|
|
32276
|
-
const parentDir =
|
|
32360
|
+
const parentDir = dirname16(trustPath);
|
|
32277
32361
|
return parentDir === trustPath ? undefined : parentDir;
|
|
32278
32362
|
}
|
|
32279
32363
|
function getProjectTrustOptions(cwd, options) {
|
|
@@ -32308,12 +32392,12 @@ function getProjectTrustOptions(cwd, options) {
|
|
|
32308
32392
|
return trustOptions;
|
|
32309
32393
|
}
|
|
32310
32394
|
function readTrustFile(path10) {
|
|
32311
|
-
if (!
|
|
32395
|
+
if (!existsSync24(path10)) {
|
|
32312
32396
|
return {};
|
|
32313
32397
|
}
|
|
32314
32398
|
let parsed;
|
|
32315
32399
|
try {
|
|
32316
|
-
parsed = parseJsonFileContent(
|
|
32400
|
+
parsed = parseJsonFileContent(readFileSync17(path10, "utf-8"));
|
|
32317
32401
|
} catch (error) {
|
|
32318
32402
|
const message = error instanceof Error ? error.message : String(error);
|
|
32319
32403
|
throw new Error(`Failed to read trust store ${path10}: ${message}`);
|
|
@@ -32338,12 +32422,12 @@ function writeTrustFile(path10, data) {
|
|
|
32338
32422
|
sorted[key] = value;
|
|
32339
32423
|
}
|
|
32340
32424
|
}
|
|
32341
|
-
mkdirSync8(
|
|
32425
|
+
mkdirSync8(dirname16(path10), { recursive: true });
|
|
32342
32426
|
writeFileSync10(path10, `${JSON.stringify(sorted, null, 2)}
|
|
32343
32427
|
`, "utf-8");
|
|
32344
32428
|
}
|
|
32345
32429
|
function acquireTrustLockSync(path10) {
|
|
32346
|
-
const trustDir =
|
|
32430
|
+
const trustDir = dirname16(path10);
|
|
32347
32431
|
mkdirSync8(trustDir, { recursive: true });
|
|
32348
32432
|
const maxAttempts = 10;
|
|
32349
32433
|
const delayMs = 20;
|
|
@@ -32377,22 +32461,22 @@ function withTrustFileLock(path10, fn) {
|
|
|
32377
32461
|
function hasTrustRequiringConfigResources(cwd) {
|
|
32378
32462
|
const projectCwd = canonicalizePath(resolvePath(cwd));
|
|
32379
32463
|
return CONFIG_DIR_NAMES.some((configDirName) => {
|
|
32380
|
-
const configDir =
|
|
32381
|
-
return TRUST_REQUIRING_PROJECT_CONFIG_RESOURCES.some((entry) =>
|
|
32464
|
+
const configDir = join34(projectCwd, configDirName);
|
|
32465
|
+
return TRUST_REQUIRING_PROJECT_CONFIG_RESOURCES.some((entry) => existsSync24(join34(configDir, entry)));
|
|
32382
32466
|
});
|
|
32383
32467
|
}
|
|
32384
32468
|
function hasTrustRequiringProjectResources(cwd) {
|
|
32385
32469
|
if (hasTrustRequiringConfigResources(cwd)) {
|
|
32386
32470
|
return true;
|
|
32387
32471
|
}
|
|
32388
|
-
const userGlobalSkillsDir = canonicalizePath(resolvePath(
|
|
32472
|
+
const userGlobalSkillsDir = canonicalizePath(resolvePath(join34(getHomeDir(), ".agents", "skills")));
|
|
32389
32473
|
let currentDir = canonicalizePath(resolvePath(cwd));
|
|
32390
32474
|
while (true) {
|
|
32391
|
-
const skillsDir = canonicalizePath(resolvePath(
|
|
32392
|
-
if (skillsDir !== userGlobalSkillsDir &&
|
|
32475
|
+
const skillsDir = canonicalizePath(resolvePath(join34(currentDir, ".agents", "skills")));
|
|
32476
|
+
if (skillsDir !== userGlobalSkillsDir && existsSync24(skillsDir)) {
|
|
32393
32477
|
return true;
|
|
32394
32478
|
}
|
|
32395
|
-
const parentDir =
|
|
32479
|
+
const parentDir = dirname16(currentDir);
|
|
32396
32480
|
if (parentDir === currentDir) {
|
|
32397
32481
|
return false;
|
|
32398
32482
|
}
|
|
@@ -32404,19 +32488,19 @@ function hasProjectTrustInputs(cwd) {
|
|
|
32404
32488
|
if (hasTrustRequiringConfigResources(currentDir)) {
|
|
32405
32489
|
return true;
|
|
32406
32490
|
}
|
|
32407
|
-
const userGlobalSkillsDir = canonicalizePath(resolvePath(
|
|
32491
|
+
const userGlobalSkillsDir = canonicalizePath(resolvePath(join34(getHomeDir(), ".agents", "skills")));
|
|
32408
32492
|
const contextFileNames = ["AGENTS.override.md", "AGENTS.md", "AGENTS.MD", "CLAUDE.md", "CLAUDE.MD"];
|
|
32409
32493
|
while (true) {
|
|
32410
32494
|
for (const contextFileName of contextFileNames) {
|
|
32411
|
-
if (
|
|
32495
|
+
if (existsSync24(join34(currentDir, contextFileName))) {
|
|
32412
32496
|
return true;
|
|
32413
32497
|
}
|
|
32414
32498
|
}
|
|
32415
|
-
const skillsDir = canonicalizePath(resolvePath(
|
|
32416
|
-
if (skillsDir !== userGlobalSkillsDir &&
|
|
32499
|
+
const skillsDir = canonicalizePath(resolvePath(join34(currentDir, ".agents", "skills")));
|
|
32500
|
+
if (skillsDir !== userGlobalSkillsDir && existsSync24(skillsDir)) {
|
|
32417
32501
|
return true;
|
|
32418
32502
|
}
|
|
32419
|
-
const parentDir =
|
|
32503
|
+
const parentDir = dirname16(currentDir);
|
|
32420
32504
|
if (parentDir === currentDir) {
|
|
32421
32505
|
return false;
|
|
32422
32506
|
}
|
|
@@ -32427,7 +32511,7 @@ function hasProjectTrustInputs(cwd) {
|
|
|
32427
32511
|
class ProjectTrustStore {
|
|
32428
32512
|
trustPath;
|
|
32429
32513
|
constructor(agentDir) {
|
|
32430
|
-
this.trustPath =
|
|
32514
|
+
this.trustPath = join34(resolvePath(agentDir), "trust.json");
|
|
32431
32515
|
}
|
|
32432
32516
|
get(cwd) {
|
|
32433
32517
|
return this.getEntry(cwd)?.decision ?? null;
|
|
@@ -37196,7 +37280,7 @@ var init_hashline = __esm(() => {
|
|
|
37196
37280
|
});
|
|
37197
37281
|
|
|
37198
37282
|
// src/core/tools/notebook.ts
|
|
37199
|
-
import { existsSync as
|
|
37283
|
+
import { existsSync as existsSync25, readFileSync as readFileSync18 } from "node:fs";
|
|
37200
37284
|
function isNotebookPath(absolutePath) {
|
|
37201
37285
|
return /\.ipynb$/i.test(absolutePath);
|
|
37202
37286
|
}
|
|
@@ -37298,11 +37382,11 @@ function applyNotebookEditableText(notebook, text, displayPath) {
|
|
|
37298
37382
|
return next;
|
|
37299
37383
|
}
|
|
37300
37384
|
function readEditableNotebookText(absolutePath, displayPath) {
|
|
37301
|
-
const notebook =
|
|
37385
|
+
const notebook = existsSync25(absolutePath) ? parseNotebookSafe(readFileSync18(absolutePath, "utf8"), displayPath) : emptyNotebook();
|
|
37302
37386
|
return notebookToEditableText(notebook);
|
|
37303
37387
|
}
|
|
37304
37388
|
function serializeEditedNotebookText(absolutePath, displayPath, text) {
|
|
37305
|
-
const notebook =
|
|
37389
|
+
const notebook = existsSync25(absolutePath) ? parseNotebookSafe(readFileSync18(absolutePath, "utf8"), displayPath) : emptyNotebook();
|
|
37306
37390
|
const next = applyNotebookEditableText(notebook, text, displayPath);
|
|
37307
37391
|
return JSON.stringify(next, null, 1);
|
|
37308
37392
|
}
|
|
@@ -37636,10 +37720,10 @@ var init_management_http = __esm(() => {
|
|
|
37636
37720
|
|
|
37637
37721
|
// src/utils/tools-manager.ts
|
|
37638
37722
|
import { spawnSync as spawnSync6 } from "child_process";
|
|
37639
|
-
import { chmodSync as chmodSync3, existsSync as
|
|
37723
|
+
import { chmodSync as chmodSync3, existsSync as existsSync26, mkdirSync as mkdirSync9, readdirSync as readdirSync7, renameSync as renameSync2, rmSync as rmSync5 } from "fs";
|
|
37640
37724
|
import { writeFile } from "fs/promises";
|
|
37641
37725
|
import { arch, platform as platform2 } from "os";
|
|
37642
|
-
import { join as
|
|
37726
|
+
import { join as join35 } from "path";
|
|
37643
37727
|
function isOfflineModeEnabled() {
|
|
37644
37728
|
const value = getEnvValue(ENV_OFFLINE);
|
|
37645
37729
|
if (!value)
|
|
@@ -37658,8 +37742,8 @@ function getToolPath(tool) {
|
|
|
37658
37742
|
const config = TOOLS[tool];
|
|
37659
37743
|
if (!config)
|
|
37660
37744
|
return null;
|
|
37661
|
-
const localPath =
|
|
37662
|
-
if (
|
|
37745
|
+
const localPath = join35(TOOLS_DIR, config.binaryName + (platform2() === "win32" ? ".exe" : ""));
|
|
37746
|
+
if (existsSync26(localPath)) {
|
|
37663
37747
|
return localPath;
|
|
37664
37748
|
}
|
|
37665
37749
|
const systemBinaryNames = config.systemBinaryNames ?? [config.binaryName];
|
|
@@ -37698,7 +37782,7 @@ function findBinaryRecursively(rootDir, binaryFileName) {
|
|
|
37698
37782
|
continue;
|
|
37699
37783
|
const entries = readdirSync7(currentDir, { withFileTypes: true });
|
|
37700
37784
|
for (const entry of entries) {
|
|
37701
|
-
const fullPath =
|
|
37785
|
+
const fullPath = join35(currentDir, entry.name);
|
|
37702
37786
|
if (entry.isFile() && entry.name === binaryFileName) {
|
|
37703
37787
|
return fullPath;
|
|
37704
37788
|
}
|
|
@@ -37739,8 +37823,8 @@ function extractTarGzArchive(archivePath, extractDir, assetName) {
|
|
|
37739
37823
|
function getWindowsTarCommand() {
|
|
37740
37824
|
const systemRoot = process.env.SystemRoot ?? process.env.WINDIR;
|
|
37741
37825
|
if (systemRoot) {
|
|
37742
|
-
const systemTar =
|
|
37743
|
-
if (
|
|
37826
|
+
const systemTar = join35(systemRoot, "System32", "tar.exe");
|
|
37827
|
+
if (existsSync26(systemTar)) {
|
|
37744
37828
|
return systemTar;
|
|
37745
37829
|
}
|
|
37746
37830
|
}
|
|
@@ -37793,11 +37877,11 @@ async function downloadTool(tool) {
|
|
|
37793
37877
|
}
|
|
37794
37878
|
mkdirSync9(TOOLS_DIR, { recursive: true });
|
|
37795
37879
|
const downloadUrl = `https://github.com/${config.repo}/releases/download/${config.tagPrefix}${version}/${assetName}`;
|
|
37796
|
-
const archivePath =
|
|
37880
|
+
const archivePath = join35(TOOLS_DIR, assetName);
|
|
37797
37881
|
const binaryExt = plat === "win32" ? ".exe" : "";
|
|
37798
|
-
const binaryPath =
|
|
37882
|
+
const binaryPath = join35(TOOLS_DIR, config.binaryName + binaryExt);
|
|
37799
37883
|
await downloadFile(downloadUrl, archivePath);
|
|
37800
|
-
const extractDir =
|
|
37884
|
+
const extractDir = join35(TOOLS_DIR, `extract_tmp_${config.binaryName}_${process.pid}_${Date.now()}_${Math.random().toString(36).slice(2, 10)}`);
|
|
37801
37885
|
mkdirSync9(extractDir, { recursive: true });
|
|
37802
37886
|
try {
|
|
37803
37887
|
if (assetName.endsWith(".tar.gz")) {
|
|
@@ -37808,9 +37892,9 @@ async function downloadTool(tool) {
|
|
|
37808
37892
|
throw new Error(`Unsupported archive format: ${assetName}`);
|
|
37809
37893
|
}
|
|
37810
37894
|
const binaryFileName = config.binaryName + binaryExt;
|
|
37811
|
-
const extractedDir =
|
|
37812
|
-
const extractedBinaryCandidates = [
|
|
37813
|
-
let extractedBinary = extractedBinaryCandidates.find((candidate) =>
|
|
37895
|
+
const extractedDir = join35(extractDir, assetName.replace(/\.(tar\.gz|zip)$/, ""));
|
|
37896
|
+
const extractedBinaryCandidates = [join35(extractedDir, binaryFileName), join35(extractDir, binaryFileName)];
|
|
37897
|
+
let extractedBinary = extractedBinaryCandidates.find((candidate) => existsSync26(candidate));
|
|
37814
37898
|
if (!extractedBinary) {
|
|
37815
37899
|
extractedBinary = findBinaryRecursively(extractDir, binaryFileName) ?? undefined;
|
|
37816
37900
|
}
|
|
@@ -39404,7 +39488,7 @@ var init_read_selectors = __esm(() => {
|
|
|
39404
39488
|
});
|
|
39405
39489
|
|
|
39406
39490
|
// src/core/tools/read-document-extract.ts
|
|
39407
|
-
import { existsSync as
|
|
39491
|
+
import { existsSync as existsSync27 } from "node:fs";
|
|
39408
39492
|
function isDocumentPath(pathValue) {
|
|
39409
39493
|
return DOCUMENT_EXTENSIONS.test(pathValue);
|
|
39410
39494
|
}
|
|
@@ -39601,7 +39685,7 @@ function documentExtension(source) {
|
|
|
39601
39685
|
}
|
|
39602
39686
|
async function extractMarkitDocument(buffer, source) {
|
|
39603
39687
|
const ext = documentExtension(source);
|
|
39604
|
-
const result =
|
|
39688
|
+
const result = existsSync27(source) ? await convertFileWithMarkit(source) : await convertBufferWithMarkit(buffer, ext);
|
|
39605
39689
|
return result.ok ? result.content : `[Cannot read ${ext} file: ${result.error || "conversion failed"}]`;
|
|
39606
39690
|
}
|
|
39607
39691
|
async function extractDocumentMarkdown(buffer, source) {
|
|
@@ -40464,7 +40548,7 @@ var init_read_url = __esm(() => {
|
|
|
40464
40548
|
});
|
|
40465
40549
|
|
|
40466
40550
|
// src/core/tools/read.ts
|
|
40467
|
-
import { basename as basename9, dirname as
|
|
40551
|
+
import { basename as basename9, dirname as dirname17, isAbsolute as isAbsolute7, relative as relative8, resolve as resolvePath5, sep as sep9 } from "node:path";
|
|
40468
40552
|
import { Text as Text32 } from "@earendil-works/pi-tui";
|
|
40469
40553
|
import { constants as constants6 } from "fs";
|
|
40470
40554
|
import { access as fsAccess3, readFile as fsReadFile2, stat as fsStat4 } from "fs/promises";
|
|
@@ -40542,7 +40626,7 @@ function oversizedReadResult(details) {
|
|
|
40542
40626
|
};
|
|
40543
40627
|
}
|
|
40544
40628
|
function getPiDocsClassification(absolutePath) {
|
|
40545
|
-
const packageRoot =
|
|
40629
|
+
const packageRoot = dirname17(getReadmePath());
|
|
40546
40630
|
const relativePath = relative8(resolvePath5(packageRoot), resolvePath5(absolutePath));
|
|
40547
40631
|
if (relativePath === "" || relativePath === ".." || relativePath.startsWith(`..${sep9}`) || isAbsolute7(relativePath)) {
|
|
40548
40632
|
return;
|
|
@@ -40560,7 +40644,7 @@ function getCompactReadClassification(args, cwd) {
|
|
|
40560
40644
|
const absolutePath = resolveToCwd(rawPath, cwd);
|
|
40561
40645
|
const fileName = basename9(absolutePath);
|
|
40562
40646
|
if (fileName === "SKILL.md") {
|
|
40563
|
-
return { kind: "skill", label: basename9(
|
|
40647
|
+
return { kind: "skill", label: basename9(dirname17(absolutePath)) || fileName };
|
|
40564
40648
|
}
|
|
40565
40649
|
const docsClassification = getPiDocsClassification(absolutePath);
|
|
40566
40650
|
if (docsClassification)
|
|
@@ -41723,22 +41807,22 @@ function filterSearchOutputByLineRange(text, ranges, contextBefore = 1, contextA
|
|
|
41723
41807
|
}
|
|
41724
41808
|
|
|
41725
41809
|
// src/core/tools/search.ts
|
|
41726
|
-
import { existsSync as
|
|
41810
|
+
import { existsSync as existsSync28 } from "node:fs";
|
|
41727
41811
|
import { readFile as fsReadFile4, stat as fsStat6 } from "node:fs/promises";
|
|
41728
|
-
import { dirname as
|
|
41812
|
+
import { dirname as dirname18, join as join36, resolve as resolvePath6 } from "node:path";
|
|
41729
41813
|
import { Text as Text34 } from "@earendil-works/pi-tui";
|
|
41730
41814
|
import { Type as Type9 } from "typebox";
|
|
41731
41815
|
function delimiterInExistingSearchGlobRoot(value, cwd) {
|
|
41732
41816
|
const selector = splitLineRangeSelector(value);
|
|
41733
41817
|
const parsed = splitPathLikeGlob(selector.path);
|
|
41734
|
-
return !!parsed.glob && /[;,\s]/.test(parsed.basePath) &&
|
|
41818
|
+
return !!parsed.glob && /[;,\s]/.test(parsed.basePath) && existsSync28(resolveToCwd(parsed.basePath, cwd));
|
|
41735
41819
|
}
|
|
41736
41820
|
function archiveSelectorExists(value, cwd) {
|
|
41737
41821
|
const archive = parseArchiveSelector(value);
|
|
41738
41822
|
if (!archive)
|
|
41739
41823
|
return false;
|
|
41740
41824
|
const resolved = resolveArchiveSelector(archive, cwd);
|
|
41741
|
-
if (!
|
|
41825
|
+
if (!existsSync28(resolved.archivePath))
|
|
41742
41826
|
return false;
|
|
41743
41827
|
if (!resolved.memberPath)
|
|
41744
41828
|
return true;
|
|
@@ -41754,7 +41838,7 @@ function searchPathResolvable(value, cwd) {
|
|
|
41754
41838
|
if (archive)
|
|
41755
41839
|
return archiveSelectorExists(selector.path, cwd);
|
|
41756
41840
|
const sqlite = sqliteSelectorForPath(selector.path, cwd);
|
|
41757
|
-
return !!sqlite || /^(?:skill|agent|artifact|history|issue|local|memory|pr|conflict|omp|rule|mcp|vault):\/\//.test(selector.path) ||
|
|
41841
|
+
return !!sqlite || /^(?:skill|agent|artifact|history|issue|local|memory|pr|conflict|omp|rule|mcp|vault):\/\//.test(selector.path) || existsSync28(resolveToCwd(splitPathLikeGlob(selector.path).basePath, cwd));
|
|
41758
41842
|
}
|
|
41759
41843
|
function normalizePaths(pathsValue, cwd) {
|
|
41760
41844
|
const inputs = Array.isArray(pathsValue) ? pathsValue.length > 0 ? pathsValue : ["."] : pathsValue === undefined ? ["."] : [pathsValue];
|
|
@@ -41766,7 +41850,7 @@ function normalizePaths(pathsValue, cwd) {
|
|
|
41766
41850
|
continue;
|
|
41767
41851
|
}
|
|
41768
41852
|
const resourceLike = /^[a-z]+:\/\//i.test(raw) || /^[^:]+\.(?:zip|jar|tar|tgz|gz|sqlite|db):/i.test(raw);
|
|
41769
|
-
if (
|
|
41853
|
+
if (existsSync28(resolveToCwd(splitLineRangeSelector(raw).path, cwd)) || delimiterInExistingSearchGlobRoot(raw, cwd) || archiveSelectorExists(raw, cwd)) {
|
|
41770
41854
|
expanded.push(raw);
|
|
41771
41855
|
continue;
|
|
41772
41856
|
}
|
|
@@ -41951,7 +42035,7 @@ async function addHashlineHeadersToSearchOutput(text, cwd, targetPath, hashlineS
|
|
|
41951
42035
|
const rendered = [];
|
|
41952
42036
|
let lastDir = "";
|
|
41953
42037
|
for (const group of groups) {
|
|
41954
|
-
let absolutePath = targetIsFile ? searchRoot :
|
|
42038
|
+
let absolutePath = targetIsFile ? searchRoot : join36(searchRoot, group.path);
|
|
41955
42039
|
try {
|
|
41956
42040
|
await fsReadFile4(absolutePath);
|
|
41957
42041
|
} catch {
|
|
@@ -41960,7 +42044,7 @@ async function addHashlineHeadersToSearchOutput(text, cwd, targetPath, hashlineS
|
|
|
41960
42044
|
try {
|
|
41961
42045
|
const content = await fsReadFile4(absolutePath, "utf-8");
|
|
41962
42046
|
const snapshot = recordHashlineSnapshot(absolutePath, cwd, content, hashlineStore);
|
|
41963
|
-
const dir =
|
|
42047
|
+
const dir = dirname18(snapshot.displayPath);
|
|
41964
42048
|
if (dir !== "." && dir !== lastDir) {
|
|
41965
42049
|
rendered.push(`# ${dir}/`);
|
|
41966
42050
|
lastDir = dir;
|
|
@@ -42684,7 +42768,7 @@ var init_todos_locks = __esm(() => {
|
|
|
42684
42768
|
|
|
42685
42769
|
// src/core/tools/todos-storage.ts
|
|
42686
42770
|
import crypto4 from "node:crypto";
|
|
42687
|
-
import { existsSync as
|
|
42771
|
+
import { existsSync as existsSync29 } from "node:fs";
|
|
42688
42772
|
import fs10 from "node:fs/promises";
|
|
42689
42773
|
import path15 from "node:path";
|
|
42690
42774
|
function parseFrontMatter(text, idFallback) {
|
|
@@ -42816,7 +42900,7 @@ async function generateTodoId(todosDir) {
|
|
|
42816
42900
|
for (let attempt = 0;attempt < 10; attempt += 1) {
|
|
42817
42901
|
const id = crypto4.randomBytes(4).toString("hex");
|
|
42818
42902
|
const todoPath = getTodoPath(todosDir, id);
|
|
42819
|
-
if (!
|
|
42903
|
+
if (!existsSync29(todoPath))
|
|
42820
42904
|
return id;
|
|
42821
42905
|
}
|
|
42822
42906
|
throw new Error("Failed to generate unique todo id");
|
|
@@ -42851,7 +42935,7 @@ async function listTodos(todosDir) {
|
|
|
42851
42935
|
return sortTodos(todos);
|
|
42852
42936
|
}
|
|
42853
42937
|
async function ensureTodoExists(filePath, id) {
|
|
42854
|
-
if (!
|
|
42938
|
+
if (!existsSync29(filePath))
|
|
42855
42939
|
return null;
|
|
42856
42940
|
return readTodoFile(filePath, id);
|
|
42857
42941
|
}
|
|
@@ -42870,7 +42954,7 @@ var init_todos_storage = __esm(() => {
|
|
|
42870
42954
|
});
|
|
42871
42955
|
|
|
42872
42956
|
// src/core/tools/todos-mutations.ts
|
|
42873
|
-
import { existsSync as
|
|
42957
|
+
import { existsSync as existsSync30 } from "node:fs";
|
|
42874
42958
|
import fs11 from "node:fs/promises";
|
|
42875
42959
|
async function claimTodoAssignment(todosDir, id, ctx, force = false) {
|
|
42876
42960
|
const validated = validateTodoId(id);
|
|
@@ -42879,7 +42963,7 @@ async function claimTodoAssignment(todosDir, id, ctx, force = false) {
|
|
|
42879
42963
|
}
|
|
42880
42964
|
const normalizedId = validated.id;
|
|
42881
42965
|
const filePath = getTodoPath(todosDir, normalizedId);
|
|
42882
|
-
if (!
|
|
42966
|
+
if (!existsSync30(filePath)) {
|
|
42883
42967
|
return { error: `Todo ${displayTodoId(id)} not found` };
|
|
42884
42968
|
}
|
|
42885
42969
|
const sessionId = ctx.sessionManager.getSessionId();
|
|
@@ -42910,7 +42994,7 @@ async function releaseTodoAssignment(todosDir, id, ctx, force = false) {
|
|
|
42910
42994
|
}
|
|
42911
42995
|
const normalizedId = validated.id;
|
|
42912
42996
|
const filePath = getTodoPath(todosDir, normalizedId);
|
|
42913
|
-
if (!
|
|
42997
|
+
if (!existsSync30(filePath)) {
|
|
42914
42998
|
return { error: `Todo ${displayTodoId(id)} not found` };
|
|
42915
42999
|
}
|
|
42916
43000
|
const sessionId = ctx.sessionManager.getSessionId();
|
|
@@ -42939,7 +43023,7 @@ async function deleteTodo(todosDir, id, ctx) {
|
|
|
42939
43023
|
}
|
|
42940
43024
|
const normalizedId = validated.id;
|
|
42941
43025
|
const filePath = getTodoPath(todosDir, normalizedId);
|
|
42942
|
-
if (!
|
|
43026
|
+
if (!existsSync30(filePath)) {
|
|
42943
43027
|
return { error: `Todo ${displayTodoId(id)} not found` };
|
|
42944
43028
|
}
|
|
42945
43029
|
return withTodoLock(todosDir, normalizedId, ctx, async () => {
|
|
@@ -43111,7 +43195,7 @@ var init_todos_render = __esm(() => {
|
|
|
43111
43195
|
});
|
|
43112
43196
|
|
|
43113
43197
|
// src/core/tools/todos-execute.ts
|
|
43114
|
-
import { existsSync as
|
|
43198
|
+
import { existsSync as existsSync31 } from "node:fs";
|
|
43115
43199
|
function todoActionResult(action, text, detailsError) {
|
|
43116
43200
|
return {
|
|
43117
43201
|
content: [{ type: "text", text }],
|
|
@@ -43195,7 +43279,7 @@ async function executeUpdateAction(todosDir, params, ctx) {
|
|
|
43195
43279
|
const normalizedId = validated.id;
|
|
43196
43280
|
const displayId = formatTodoId(normalizedId);
|
|
43197
43281
|
const filePath = getTodoPath(todosDir, normalizedId);
|
|
43198
|
-
if (!
|
|
43282
|
+
if (!existsSync31(filePath)) {
|
|
43199
43283
|
return todoActionResult("update", `Todo ${displayId} not found`, "not found");
|
|
43200
43284
|
}
|
|
43201
43285
|
const result = await withTodoLock(todosDir, normalizedId, ctx, async () => {
|
|
@@ -43232,7 +43316,7 @@ async function executeAppendAction(todosDir, params, ctx) {
|
|
|
43232
43316
|
const normalizedId = validated.id;
|
|
43233
43317
|
const displayId = formatTodoId(normalizedId);
|
|
43234
43318
|
const filePath = getTodoPath(todosDir, normalizedId);
|
|
43235
|
-
if (!
|
|
43319
|
+
if (!existsSync31(filePath)) {
|
|
43236
43320
|
return todoActionResult("append", `Todo ${displayId} not found`, "not found");
|
|
43237
43321
|
}
|
|
43238
43322
|
const result = await withTodoLock(todosDir, normalizedId, ctx, async () => {
|
|
@@ -43352,7 +43436,7 @@ import {
|
|
|
43352
43436
|
stat as fsStat7,
|
|
43353
43437
|
writeFile as fsWriteFile2
|
|
43354
43438
|
} from "fs/promises";
|
|
43355
|
-
import { dirname as
|
|
43439
|
+
import { dirname as dirname20, join as join37 } from "path";
|
|
43356
43440
|
import { Type as Type11 } from "typebox";
|
|
43357
43441
|
async function findConflictBlocks(root, limit = 100) {
|
|
43358
43442
|
const out = [];
|
|
@@ -43360,7 +43444,7 @@ async function findConflictBlocks(root, limit = 100) {
|
|
|
43360
43444
|
for (const entry of await fsReaddir2(dir, { withFileTypes: true }).catch(() => [])) {
|
|
43361
43445
|
if (out.length >= limit || entry.name === ".git" || entry.name === "node_modules")
|
|
43362
43446
|
continue;
|
|
43363
|
-
const full =
|
|
43447
|
+
const full = join37(dir, entry.name);
|
|
43364
43448
|
if (entry.isDirectory())
|
|
43365
43449
|
await walk(full);
|
|
43366
43450
|
else if (entry.isFile()) {
|
|
@@ -43650,7 +43734,7 @@ ${headers[0]}` : ""}` }],
|
|
|
43650
43734
|
};
|
|
43651
43735
|
}
|
|
43652
43736
|
const absolutePath = resolveToCwd(path16, cwd);
|
|
43653
|
-
const dir =
|
|
43737
|
+
const dir = dirname20(absolutePath);
|
|
43654
43738
|
return withFileMutationQueue(absolutePath, async () => {
|
|
43655
43739
|
const throwIfAborted2 = () => {
|
|
43656
43740
|
if (signal?.aborted)
|
|
@@ -44191,20 +44275,20 @@ import {
|
|
|
44191
44275
|
lstatSync as lstatSync2,
|
|
44192
44276
|
openSync as openSync3,
|
|
44193
44277
|
readdirSync as readdirSync8,
|
|
44194
|
-
readFileSync as
|
|
44278
|
+
readFileSync as readFileSync19,
|
|
44195
44279
|
renameSync as renameSync3,
|
|
44196
44280
|
rmSync as rmSync6,
|
|
44197
44281
|
statSync as statSync8,
|
|
44198
44282
|
unlinkSync as unlinkSync4,
|
|
44199
44283
|
writeSync
|
|
44200
44284
|
} from "node:fs";
|
|
44201
|
-
import { join as
|
|
44285
|
+
import { join as join38 } from "node:path";
|
|
44202
44286
|
function getCleanupControlRoot() {
|
|
44203
|
-
return
|
|
44287
|
+
return join38(getTempRootDir(), CLEANUP_CONTROL_SUBDIR);
|
|
44204
44288
|
}
|
|
44205
44289
|
function getCleanupControlDir(target, controlRoot) {
|
|
44206
44290
|
const key = createHash5("sha256").update(target).digest("hex").slice(0, 16);
|
|
44207
|
-
return
|
|
44291
|
+
return join38(controlRoot ?? getCleanupControlRoot(), key);
|
|
44208
44292
|
}
|
|
44209
44293
|
function sameFileIdentity2(left, right) {
|
|
44210
44294
|
return left.dev === right.dev && left.ino === right.ino;
|
|
@@ -44331,7 +44415,7 @@ function breakStaleLock(lockPath, observedMtimeMs) {
|
|
|
44331
44415
|
}
|
|
44332
44416
|
function ownsCleanupLock(lockPath, lock) {
|
|
44333
44417
|
try {
|
|
44334
|
-
return pathIdentifiesFile(lockPath, lock) &&
|
|
44418
|
+
return pathIdentifiesFile(lockPath, lock) && readFileSync19(lockPath, "utf-8") === lock.token && pathIdentifiesFile(lockPath, lock);
|
|
44335
44419
|
} catch {
|
|
44336
44420
|
return false;
|
|
44337
44421
|
}
|
|
@@ -44420,7 +44504,7 @@ function scanFreshness(entryPath, cutoff, depth = 0) {
|
|
|
44420
44504
|
}
|
|
44421
44505
|
let foundUnknown = false;
|
|
44422
44506
|
for (const child of children) {
|
|
44423
|
-
const freshness = scanFreshness(
|
|
44507
|
+
const freshness = scanFreshness(join38(entryPath, child), cutoff, depth + 1);
|
|
44424
44508
|
if (freshness === "fresh") {
|
|
44425
44509
|
return "fresh";
|
|
44426
44510
|
}
|
|
@@ -44438,11 +44522,11 @@ function withCleanupGate(controlDir, options, scan) {
|
|
|
44438
44522
|
} catch {
|
|
44439
44523
|
return "locked";
|
|
44440
44524
|
}
|
|
44441
|
-
const markerPath =
|
|
44525
|
+
const markerPath = join38(controlDir, CLEANUP_MARKER_FILE);
|
|
44442
44526
|
if (markerIsFresh(markerPath, now, throttleMs)) {
|
|
44443
44527
|
return "throttled";
|
|
44444
44528
|
}
|
|
44445
|
-
const lockPath =
|
|
44529
|
+
const lockPath = join38(controlDir, CLEANUP_LOCK_FILE);
|
|
44446
44530
|
const token = acquireCleanupLock(lockPath, now, SESSION_TEMP_CLEANUP_LOCK_STALE_MS);
|
|
44447
44531
|
if (token === null) {
|
|
44448
44532
|
return "locked";
|
|
@@ -44493,7 +44577,7 @@ function sweepSessionTempRoot(root = getTempRootDir(), options = {}) {
|
|
|
44493
44577
|
if (isCleanupArtifact(entry)) {
|
|
44494
44578
|
continue;
|
|
44495
44579
|
}
|
|
44496
|
-
const entryPath =
|
|
44580
|
+
const entryPath = join38(root, entry);
|
|
44497
44581
|
if (gate.protectedPaths.has(entryPath)) {
|
|
44498
44582
|
continue;
|
|
44499
44583
|
}
|
|
@@ -44518,7 +44602,7 @@ function sweepSessionTempRoot(root = getTempRootDir(), options = {}) {
|
|
|
44518
44602
|
});
|
|
44519
44603
|
}
|
|
44520
44604
|
function reapToolResultsDir(parent, cutoff, protectedPaths) {
|
|
44521
|
-
const toolResultsDir =
|
|
44605
|
+
const toolResultsDir = join38(parent, TOOL_RESULTS_SUBDIR);
|
|
44522
44606
|
if (protectedPaths.has(toolResultsDir) || !isRealDirectory2(toolResultsDir)) {
|
|
44523
44607
|
return;
|
|
44524
44608
|
}
|
|
@@ -44543,7 +44627,7 @@ function sweepToolResultsRoot(sessionsRoot, options = {}) {
|
|
|
44543
44627
|
return;
|
|
44544
44628
|
}
|
|
44545
44629
|
for (const entry of entries) {
|
|
44546
|
-
const projectDir =
|
|
44630
|
+
const projectDir = join38(sessionsRoot, entry);
|
|
44547
44631
|
if (!isRealDirectory2(projectDir) || gate.protectedPaths.has(projectDir)) {
|
|
44548
44632
|
continue;
|
|
44549
44633
|
}
|
|
@@ -44784,7 +44868,7 @@ function parseSkillBlock(text) {
|
|
|
44784
44868
|
}
|
|
44785
44869
|
|
|
44786
44870
|
// src/core/agent-session.ts
|
|
44787
|
-
import { join as
|
|
44871
|
+
import { join as join39 } from "node:path";
|
|
44788
44872
|
|
|
44789
44873
|
class AgentSessionBase {
|
|
44790
44874
|
agent;
|
|
@@ -44907,7 +44991,7 @@ class AgentSessionBase {
|
|
|
44907
44991
|
const sessionDir = this.sessionManager.getSessionDir() || undefined;
|
|
44908
44992
|
this._tempStorageLease = acquireProtectedPaths([
|
|
44909
44993
|
setActiveSessionTempId(sessionId),
|
|
44910
|
-
...sessionDir ? [
|
|
44994
|
+
...sessionDir ? [join39(sessionDir, TOOL_RESULTS_SUBDIR)] : []
|
|
44911
44995
|
]);
|
|
44912
44996
|
const customSessionDir = this.sessionManager.usesDefaultSessionDir() ? undefined : sessionDir;
|
|
44913
44997
|
scheduleSessionTempCleanup(customSessionDir ? { sessionDirs: [customSessionDir] } : {});
|
|
@@ -44952,23 +45036,23 @@ var init_agent_session = __esm(() => {
|
|
|
44952
45036
|
});
|
|
44953
45037
|
|
|
44954
45038
|
// src/core/auth-storage-backends.ts
|
|
44955
|
-
import { chmodSync as chmodSync4, existsSync as
|
|
44956
|
-
import { dirname as
|
|
45039
|
+
import { chmodSync as chmodSync4, existsSync as existsSync32, mkdirSync as mkdirSync10, readFileSync as readFileSync20, renameSync as renameSync4, rmSync as rmSync7, writeFileSync as writeFileSync11 } from "fs";
|
|
45040
|
+
import { dirname as dirname21, join as join40 } from "path";
|
|
44957
45041
|
import lockfile2 from "proper-lockfile";
|
|
44958
45042
|
|
|
44959
45043
|
class FileAuthStorageBackend {
|
|
44960
|
-
constructor(authPath =
|
|
45044
|
+
constructor(authPath = join40(getAgentDir(), "auth.json"), readPaths = [authPath]) {
|
|
44961
45045
|
this.authPath = normalizePath(authPath);
|
|
44962
45046
|
this.readPaths = readPaths.map((readPath) => normalizePath(readPath));
|
|
44963
45047
|
}
|
|
44964
45048
|
ensureParentDir() {
|
|
44965
|
-
const dir =
|
|
44966
|
-
if (!
|
|
45049
|
+
const dir = dirname21(this.authPath);
|
|
45050
|
+
if (!existsSync32(dir)) {
|
|
44967
45051
|
mkdirSync10(dir, { recursive: true, mode: 448 });
|
|
44968
45052
|
}
|
|
44969
45053
|
}
|
|
44970
45054
|
ensureFileExists() {
|
|
44971
|
-
if (!
|
|
45055
|
+
if (!existsSync32(this.authPath)) {
|
|
44972
45056
|
writeFileSync11(this.authPath, "{}", AUTH_FILE_WRITE_OPTIONS);
|
|
44973
45057
|
chmodSync4(this.authPath, 384);
|
|
44974
45058
|
}
|
|
@@ -44997,24 +45081,24 @@ class FileAuthStorageBackend {
|
|
|
44997
45081
|
let found = false;
|
|
44998
45082
|
for (let i = this.readPaths.length - 1;i >= 0; i--) {
|
|
44999
45083
|
const readPath = this.readPaths[i];
|
|
45000
|
-
if (!
|
|
45084
|
+
if (!existsSync32(readPath))
|
|
45001
45085
|
continue;
|
|
45002
|
-
const parsed = JSON.parse(
|
|
45086
|
+
const parsed = JSON.parse(readFileSync20(readPath, "utf-8"));
|
|
45003
45087
|
merged = { ...merged, ...parsed };
|
|
45004
45088
|
found = true;
|
|
45005
45089
|
}
|
|
45006
45090
|
return found ? JSON.stringify(merged, null, 2) : undefined;
|
|
45007
45091
|
}
|
|
45008
45092
|
writeAtomic(content, path16 = this.authPath) {
|
|
45009
|
-
const dir =
|
|
45010
|
-
const tempPath =
|
|
45093
|
+
const dir = dirname21(path16);
|
|
45094
|
+
const tempPath = join40(dir, `.${`auth.${process.pid}.${Date.now()}.${Math.random().toString(36).slice(2)}`}.tmp`);
|
|
45011
45095
|
try {
|
|
45012
45096
|
writeFileSync11(tempPath, content, AUTH_FILE_WRITE_OPTIONS);
|
|
45013
45097
|
chmodSync4(tempPath, 384);
|
|
45014
45098
|
renameSync4(tempPath, path16);
|
|
45015
45099
|
} catch (error) {
|
|
45016
45100
|
try {
|
|
45017
|
-
if (
|
|
45101
|
+
if (existsSync32(tempPath))
|
|
45018
45102
|
rmSync7(tempPath, { force: true });
|
|
45019
45103
|
} catch {}
|
|
45020
45104
|
throw error;
|
|
@@ -45024,13 +45108,13 @@ class FileAuthStorageBackend {
|
|
|
45024
45108
|
return this.readMergedAuth();
|
|
45025
45109
|
}
|
|
45026
45110
|
deleteProvider(provider) {
|
|
45027
|
-
const paths = [...new Set(this.readPaths.filter((path16) =>
|
|
45111
|
+
const paths = [...new Set(this.readPaths.filter((path16) => existsSync32(path16)))].sort();
|
|
45028
45112
|
const releases = [];
|
|
45029
45113
|
try {
|
|
45030
45114
|
for (const path16 of paths)
|
|
45031
45115
|
releases.push(this.acquireLockSyncWithRetry(path16));
|
|
45032
45116
|
for (const path16 of paths) {
|
|
45033
|
-
const data = JSON.parse(
|
|
45117
|
+
const data = JSON.parse(readFileSync20(path16, "utf-8"));
|
|
45034
45118
|
if (!(provider in data))
|
|
45035
45119
|
continue;
|
|
45036
45120
|
delete data[provider];
|
|
@@ -45043,7 +45127,7 @@ class FileAuthStorageBackend {
|
|
|
45043
45127
|
}
|
|
45044
45128
|
}
|
|
45045
45129
|
async deleteProviderAsync(provider) {
|
|
45046
|
-
const paths = [...new Set(this.readPaths.filter((path16) =>
|
|
45130
|
+
const paths = [...new Set(this.readPaths.filter((path16) => existsSync32(path16)))].sort();
|
|
45047
45131
|
const releases = [];
|
|
45048
45132
|
try {
|
|
45049
45133
|
for (const path16 of paths) {
|
|
@@ -45054,7 +45138,7 @@ class FileAuthStorageBackend {
|
|
|
45054
45138
|
}));
|
|
45055
45139
|
}
|
|
45056
45140
|
for (const path16 of paths) {
|
|
45057
|
-
const data = JSON.parse(
|
|
45141
|
+
const data = JSON.parse(readFileSync20(path16, "utf-8"));
|
|
45058
45142
|
if (!(provider in data))
|
|
45059
45143
|
continue;
|
|
45060
45144
|
delete data[provider];
|
|
@@ -45070,13 +45154,13 @@ class FileAuthStorageBackend {
|
|
|
45070
45154
|
this.ensureParentDir();
|
|
45071
45155
|
let release;
|
|
45072
45156
|
try {
|
|
45073
|
-
if (
|
|
45157
|
+
if (existsSync32(this.authPath)) {
|
|
45074
45158
|
release = this.acquireLockSyncWithRetry(this.authPath);
|
|
45075
45159
|
}
|
|
45076
45160
|
const current = this.readMergedAuth();
|
|
45077
45161
|
const { result, next } = fn(current);
|
|
45078
45162
|
if (next !== undefined) {
|
|
45079
|
-
if (!
|
|
45163
|
+
if (!existsSync32(this.authPath)) {
|
|
45080
45164
|
this.ensureFileExists();
|
|
45081
45165
|
}
|
|
45082
45166
|
if (!release) {
|
|
@@ -45102,7 +45186,7 @@ class FileAuthStorageBackend {
|
|
|
45102
45186
|
}
|
|
45103
45187
|
};
|
|
45104
45188
|
try {
|
|
45105
|
-
if (!
|
|
45189
|
+
if (!existsSync32(this.authPath)) {
|
|
45106
45190
|
this.ensureFileExists();
|
|
45107
45191
|
}
|
|
45108
45192
|
release = await lockfile2.lock(this.authPath, {
|
|
@@ -45184,7 +45268,7 @@ var init_auth_storage_backends = __esm(() => {
|
|
|
45184
45268
|
});
|
|
45185
45269
|
|
|
45186
45270
|
// src/core/auth-storage.ts
|
|
45187
|
-
import { join as
|
|
45271
|
+
import { join as join41 } from "path";
|
|
45188
45272
|
|
|
45189
45273
|
class AuthStorage {
|
|
45190
45274
|
data = {};
|
|
@@ -45195,7 +45279,7 @@ class AuthStorage {
|
|
|
45195
45279
|
}
|
|
45196
45280
|
static create(authPath) {
|
|
45197
45281
|
const paths = authPath === undefined ? getAgentConfigPaths("auth.json") : Array.isArray(authPath) ? authPath : [authPath];
|
|
45198
|
-
return new AuthStorage(new FileAuthStorageBackend(paths[0] ??
|
|
45282
|
+
return new AuthStorage(new FileAuthStorageBackend(paths[0] ?? join41(getAgentDir(), "auth.json"), paths));
|
|
45199
45283
|
}
|
|
45200
45284
|
static fromStorage(storage) {
|
|
45201
45285
|
return new AuthStorage(storage);
|
|
@@ -45276,7 +45360,7 @@ class ReadOnlyAuthStorage {
|
|
|
45276
45360
|
storage;
|
|
45277
45361
|
constructor(authPath) {
|
|
45278
45362
|
const paths = authPath === undefined ? getAgentConfigPaths("auth.json") : Array.isArray(authPath) ? authPath : [authPath];
|
|
45279
|
-
this.storage = new FileAuthStorageBackend(paths[0] ??
|
|
45363
|
+
this.storage = new FileAuthStorageBackend(paths[0] ?? join41(getAgentDir(), "auth.json"), paths);
|
|
45280
45364
|
}
|
|
45281
45365
|
load() {
|
|
45282
45366
|
if (this.data !== undefined)
|
|
@@ -45339,7 +45423,7 @@ class ReadOnlyAuthStorage {
|
|
|
45339
45423
|
}
|
|
45340
45424
|
function readStoredCredential(providerId, authPath) {
|
|
45341
45425
|
const paths = authPath === undefined ? getAgentConfigPaths("auth.json") : Array.isArray(authPath) ? authPath : [authPath];
|
|
45342
|
-
const storage = new FileAuthStorageBackend(paths[0] ??
|
|
45426
|
+
const storage = new FileAuthStorageBackend(paths[0] ?? join41(getAgentDir(), "auth.json"), paths);
|
|
45343
45427
|
try {
|
|
45344
45428
|
let credential;
|
|
45345
45429
|
storage.withLock((content) => {
|
|
@@ -45358,41 +45442,19 @@ var init_auth_storage = __esm(() => {
|
|
|
45358
45442
|
init_auth_storage_backends();
|
|
45359
45443
|
});
|
|
45360
45444
|
|
|
45361
|
-
// src/core/builtin-install-layout.ts
|
|
45362
|
-
function requiredEntriesForBuiltin(dirName) {
|
|
45363
|
-
return [INSTALLED_EXTENSION_ENTRIES[dirName], SOURCE_EXTENSION_ENTRIES[dirName]];
|
|
45364
|
-
}
|
|
45365
|
-
var SOURCE_EXTENSION_ENTRIES, INSTALLED_EXTENSION_ENTRIES;
|
|
45366
|
-
var init_builtin_install_layout = __esm(() => {
|
|
45367
|
-
SOURCE_EXTENSION_ENTRIES = {
|
|
45368
|
-
workflows: "src/extension/index.ts",
|
|
45369
|
-
subagents: "src/extension/index.ts",
|
|
45370
|
-
mcp: "index.ts",
|
|
45371
|
-
"web-access": "index.ts",
|
|
45372
|
-
intercom: "index.ts"
|
|
45373
|
-
};
|
|
45374
|
-
INSTALLED_EXTENSION_ENTRIES = {
|
|
45375
|
-
workflows: "src/extension/index.bundle.mjs",
|
|
45376
|
-
subagents: "src/extension/index.bundle.mjs",
|
|
45377
|
-
mcp: "index.bundle.mjs",
|
|
45378
|
-
"web-access": "index.bundle.mjs",
|
|
45379
|
-
intercom: "index.bundle.mjs"
|
|
45380
|
-
};
|
|
45381
|
-
});
|
|
45382
|
-
|
|
45383
45445
|
// src/core/builtin-packages.ts
|
|
45384
|
-
import { existsSync as
|
|
45385
|
-
import { join as
|
|
45446
|
+
import { existsSync as existsSync33, readFileSync as readFileSync21 } from "node:fs";
|
|
45447
|
+
import { join as join42, resolve as resolve12 } from "node:path";
|
|
45386
45448
|
function readPackageName(packageJsonPath) {
|
|
45387
45449
|
try {
|
|
45388
|
-
const pkg2 = JSON.parse(
|
|
45450
|
+
const pkg2 = JSON.parse(readFileSync21(packageJsonPath, "utf-8"));
|
|
45389
45451
|
return pkg2.name;
|
|
45390
45452
|
} catch {
|
|
45391
45453
|
return;
|
|
45392
45454
|
}
|
|
45393
45455
|
}
|
|
45394
45456
|
function isPackageDir(dir, descriptor) {
|
|
45395
|
-
return descriptor.requiredEntries.some((entry) =>
|
|
45457
|
+
return descriptor.requiredEntries.some((entry) => existsSync33(join42(dir, entry))) && readPackageName(join42(dir, "package.json")) === descriptor.packageName;
|
|
45396
45458
|
}
|
|
45397
45459
|
function firstExistingPackageDir(candidates, descriptor) {
|
|
45398
45460
|
const seen = new Set;
|
|
@@ -45411,9 +45473,9 @@ function firstExistingPackageDir(candidates, descriptor) {
|
|
|
45411
45473
|
function distCandidates(context, descriptor) {
|
|
45412
45474
|
const { here, packageDir } = context;
|
|
45413
45475
|
return [
|
|
45414
|
-
|
|
45415
|
-
|
|
45416
|
-
|
|
45476
|
+
join42(here, "..", "builtin", descriptor.distDirName),
|
|
45477
|
+
join42(packageDir, "builtin", descriptor.distDirName),
|
|
45478
|
+
join42(packageDir, "dist", "builtin", descriptor.distDirName)
|
|
45417
45479
|
];
|
|
45418
45480
|
}
|
|
45419
45481
|
function getBuiltinPackageCandidateContext() {
|
|
@@ -45425,7 +45487,7 @@ function getBuiltinPackageCandidateContext() {
|
|
|
45425
45487
|
};
|
|
45426
45488
|
return {
|
|
45427
45489
|
...context,
|
|
45428
|
-
isSourceCheckout:
|
|
45490
|
+
isSourceCheckout: existsSync33(join42(context.packageDir, "src", "main.ts"))
|
|
45429
45491
|
};
|
|
45430
45492
|
}
|
|
45431
45493
|
function getBuiltinPackagePaths() {
|
|
@@ -45451,7 +45513,7 @@ var init_builtin_packages = __esm(() => {
|
|
|
45451
45513
|
packageName: spec.packageName,
|
|
45452
45514
|
distDirName: spec.distDirName,
|
|
45453
45515
|
requiredEntries: requiredEntriesForBuiltin(spec.distDirName),
|
|
45454
|
-
sourceCandidates: ({ here, packageDir, isSourceCheckout }) => isSourceCheckout ? [
|
|
45516
|
+
sourceCandidates: ({ here, packageDir, isSourceCheckout }) => isSourceCheckout ? [join42(packageDir, "..", spec.workspaceDirName), join42(here, "..", "..", "..", spec.workspaceDirName)] : []
|
|
45455
45517
|
}));
|
|
45456
45518
|
});
|
|
45457
45519
|
|
|
@@ -46039,7 +46101,7 @@ function getSnapshotProviderAuthStatus(snapshot, providerId, hasRuntimeApiKey, c
|
|
|
46039
46101
|
}
|
|
46040
46102
|
|
|
46041
46103
|
// src/core/models-store.ts
|
|
46042
|
-
import { join as
|
|
46104
|
+
import { join as join43 } from "node:path";
|
|
46043
46105
|
|
|
46044
46106
|
class InMemoryCodingAgentModelsStore {
|
|
46045
46107
|
entries = new Map;
|
|
@@ -46056,7 +46118,7 @@ class InMemoryCodingAgentModelsStore {
|
|
|
46056
46118
|
|
|
46057
46119
|
class FileModelsStore {
|
|
46058
46120
|
storage;
|
|
46059
|
-
constructor(path16 =
|
|
46121
|
+
constructor(path16 = join43(getAgentDir(), "models-store.json")) {
|
|
46060
46122
|
this.storage = new FileAuthStorageBackend(path16);
|
|
46061
46123
|
}
|
|
46062
46124
|
parse(content) {
|
|
@@ -46139,14 +46201,14 @@ var init_git_env = __esm(() => {
|
|
|
46139
46201
|
});
|
|
46140
46202
|
|
|
46141
46203
|
// src/core/package-manager-env.ts
|
|
46142
|
-
import { readFileSync as
|
|
46204
|
+
import { readFileSync as readFileSync22 } from "node:fs";
|
|
46143
46205
|
import { basename as basename10 } from "node:path";
|
|
46144
46206
|
function getEnv() {
|
|
46145
46207
|
if (process.platform !== "linux" || Object.keys(process.env).length > 0) {
|
|
46146
46208
|
return process.env;
|
|
46147
46209
|
}
|
|
46148
46210
|
try {
|
|
46149
|
-
const data =
|
|
46211
|
+
const data = readFileSync22("/proc/self/environ", "utf-8");
|
|
46150
46212
|
const env = {};
|
|
46151
46213
|
for (const entry of data.split("\x00")) {
|
|
46152
46214
|
const idx = entry.indexOf("=");
|
|
@@ -46492,8 +46554,8 @@ var init_model_runtime_restoration = __esm(() => {
|
|
|
46492
46554
|
|
|
46493
46555
|
// src/core/model-runtime.ts
|
|
46494
46556
|
import { createHash as createHash6 } from "node:crypto";
|
|
46495
|
-
import { readFileSync as
|
|
46496
|
-
import { dirname as
|
|
46557
|
+
import { readFileSync as readFileSync23 } from "node:fs";
|
|
46558
|
+
import { dirname as dirname22, join as join44 } from "node:path";
|
|
46497
46559
|
import {
|
|
46498
46560
|
createModels
|
|
46499
46561
|
} from "@bastani/pi-ai";
|
|
@@ -46536,9 +46598,9 @@ class ModelRuntime {
|
|
|
46536
46598
|
}
|
|
46537
46599
|
static async create(options = {}) {
|
|
46538
46600
|
const credentials = new RuntimeCredentials(options.credentials ?? AuthStorage.create(options.authPath));
|
|
46539
|
-
const modelsPath = options.modelsPath === null ? undefined : options.modelsPath ??
|
|
46601
|
+
const modelsPath = options.modelsPath === null ? undefined : options.modelsPath ?? join44(getAgentDir(), "models.json");
|
|
46540
46602
|
const config = await ModelConfig.load(modelsPath);
|
|
46541
|
-
const modelsStore = options.modelsStore ?? (modelsPath ? new FileModelsStore(options.modelsStorePath ??
|
|
46603
|
+
const modelsStore = options.modelsStore ?? (modelsPath ? new FileModelsStore(options.modelsStorePath ?? join44(dirname22(modelsPath), "models-store.json")) : new InMemoryCodingAgentModelsStore);
|
|
46542
46604
|
const builtinModelDataGeneratedAt = builtinProviderCatalog2.getBuiltinModelDataGeneratedAt();
|
|
46543
46605
|
const providers = builtinProviderCatalog2.builtinProviders().map((provider) => provider.id === "radius" ? provider : withRemoteCatalog(provider, options.catalogBaseUrl, builtinModelDataGeneratedAt));
|
|
46544
46606
|
const runtime = new ModelRuntime(credentials, config, modelsPath, modelsStore, providers, !isOfflineModeEnabled2());
|
|
@@ -46788,7 +46850,7 @@ class ModelRuntime {
|
|
|
46788
46850
|
if (!this.modelsPath)
|
|
46789
46851
|
return "none";
|
|
46790
46852
|
try {
|
|
46791
|
-
return createHash6("sha1").update(
|
|
46853
|
+
return createHash6("sha1").update(readFileSync23(normalizePath(this.modelsPath))).digest("hex");
|
|
46792
46854
|
} catch (error) {
|
|
46793
46855
|
const code = error.code;
|
|
46794
46856
|
return code === "ENOENT" ? "absent" : `unreadable:${code ?? "unknown"}`;
|
|
@@ -47370,13 +47432,13 @@ var NETWORK_TIMEOUT_MS2 = 1e4, UPDATE_CHECK_CONCURRENCY = 4, GIT_UPDATE_CONCURRE
|
|
|
47370
47432
|
// src/core/package-manager-paths.ts
|
|
47371
47433
|
import { createHash as createHash7 } from "node:crypto";
|
|
47372
47434
|
import { homedir as homedir7, tmpdir as tmpdir5 } from "node:os";
|
|
47373
|
-
import { join as
|
|
47435
|
+
import { join as join45 } from "node:path";
|
|
47374
47436
|
function getHomeDir2() {
|
|
47375
47437
|
return process.env.HOME || homedir7();
|
|
47376
47438
|
}
|
|
47377
47439
|
function getTemporaryDir(prefix, suffix) {
|
|
47378
47440
|
const hash = createHash7("sha256").update(`${prefix}-${suffix ?? ""}`).digest("hex").slice(0, 8);
|
|
47379
|
-
return
|
|
47441
|
+
return join45(tmpdir5(), `${APP_NAME}-extensions`, prefix, hash, suffix ?? "");
|
|
47380
47442
|
}
|
|
47381
47443
|
function getBaseDirsForScope(context, scope) {
|
|
47382
47444
|
if (scope === "project") {
|
|
@@ -47401,27 +47463,27 @@ function getNpmInstallRoot(context, scope, temporary) {
|
|
|
47401
47463
|
return getTemporaryDir("npm");
|
|
47402
47464
|
}
|
|
47403
47465
|
if (scope === "project") {
|
|
47404
|
-
return
|
|
47466
|
+
return join45(context.cwd, CONFIG_DIR_NAME, "npm");
|
|
47405
47467
|
}
|
|
47406
|
-
return
|
|
47468
|
+
return join45(context.agentDir, "npm");
|
|
47407
47469
|
}
|
|
47408
47470
|
function getGitInstallPath(context, source, scope) {
|
|
47409
47471
|
if (scope === "temporary") {
|
|
47410
47472
|
return getTemporaryDir(`git-${source.host}`, source.path);
|
|
47411
47473
|
}
|
|
47412
47474
|
if (scope === "project") {
|
|
47413
|
-
return
|
|
47475
|
+
return join45(context.cwd, CONFIG_DIR_NAME, "git", source.host, source.path);
|
|
47414
47476
|
}
|
|
47415
|
-
return
|
|
47477
|
+
return join45(context.agentDir, "git", source.host, source.path);
|
|
47416
47478
|
}
|
|
47417
47479
|
function getGitInstallRoot(context, scope) {
|
|
47418
47480
|
if (scope === "temporary") {
|
|
47419
47481
|
return;
|
|
47420
47482
|
}
|
|
47421
47483
|
if (scope === "project") {
|
|
47422
|
-
return
|
|
47484
|
+
return join45(context.cwd, CONFIG_DIR_NAME, "git");
|
|
47423
47485
|
}
|
|
47424
|
-
return
|
|
47486
|
+
return join45(context.agentDir, "git");
|
|
47425
47487
|
}
|
|
47426
47488
|
var init_package_manager_paths = __esm(() => {
|
|
47427
47489
|
init_config();
|
|
@@ -47429,8 +47491,8 @@ var init_package_manager_paths = __esm(() => {
|
|
|
47429
47491
|
});
|
|
47430
47492
|
|
|
47431
47493
|
// src/core/package-manager-npm.ts
|
|
47432
|
-
import { existsSync as
|
|
47433
|
-
import { basename as basename11, dirname as
|
|
47494
|
+
import { existsSync as existsSync34, mkdirSync as mkdirSync11, readFileSync as readFileSync24, writeFileSync as writeFileSync12 } from "node:fs";
|
|
47495
|
+
import { basename as basename11, dirname as dirname23, join as join46 } from "node:path";
|
|
47434
47496
|
import { maxSatisfying, rcompare, satisfies } from "semver";
|
|
47435
47497
|
function getNpmCommand(context) {
|
|
47436
47498
|
const configuredCommand = context.settingsManager.getNpmCommand();
|
|
@@ -47497,7 +47559,7 @@ async function installNpm(context, source, scope, temporary) {
|
|
|
47497
47559
|
}
|
|
47498
47560
|
async function uninstallNpm(context, source, scope) {
|
|
47499
47561
|
const installRoot = getNpmInstallRoot(context, scope, false);
|
|
47500
|
-
if (!
|
|
47562
|
+
if (!existsSync34(installRoot)) {
|
|
47501
47563
|
return;
|
|
47502
47564
|
}
|
|
47503
47565
|
if (getPackageManagerName(context) === "bun") {
|
|
@@ -47512,23 +47574,23 @@ async function installNpmBatch(context, specs, scope) {
|
|
|
47512
47574
|
await runNpmCommand(context, getNpmInstallArgs(context, specs, installRoot));
|
|
47513
47575
|
}
|
|
47514
47576
|
function ensureNpmProject(installRoot) {
|
|
47515
|
-
if (!
|
|
47577
|
+
if (!existsSync34(installRoot)) {
|
|
47516
47578
|
mkdirSync11(installRoot, { recursive: true });
|
|
47517
47579
|
}
|
|
47518
47580
|
markPathIgnoredByCloudSync(installRoot);
|
|
47519
47581
|
ensureGitIgnore(installRoot);
|
|
47520
|
-
const packageJsonPath =
|
|
47521
|
-
if (!
|
|
47582
|
+
const packageJsonPath = join46(installRoot, "package.json");
|
|
47583
|
+
if (!existsSync34(packageJsonPath)) {
|
|
47522
47584
|
const pkgJson = { name: `${APP_NAME}-extensions`, private: true };
|
|
47523
47585
|
writeFileSync12(packageJsonPath, JSON.stringify(pkgJson, null, 2), "utf-8");
|
|
47524
47586
|
}
|
|
47525
47587
|
}
|
|
47526
47588
|
function ensureGitIgnore(dir) {
|
|
47527
|
-
if (!
|
|
47589
|
+
if (!existsSync34(dir)) {
|
|
47528
47590
|
mkdirSync11(dir, { recursive: true });
|
|
47529
47591
|
}
|
|
47530
|
-
const ignorePath =
|
|
47531
|
-
if (!
|
|
47592
|
+
const ignorePath = join46(dir, ".gitignore");
|
|
47593
|
+
if (!existsSync34(ignorePath)) {
|
|
47532
47594
|
writeFileSync12(ignorePath, `*
|
|
47533
47595
|
!.gitignore
|
|
47534
47596
|
`, "utf-8");
|
|
@@ -47536,12 +47598,12 @@ function ensureGitIgnore(dir) {
|
|
|
47536
47598
|
}
|
|
47537
47599
|
function getManagedNpmInstallPath(context, source, scope) {
|
|
47538
47600
|
if (scope === "temporary") {
|
|
47539
|
-
return
|
|
47601
|
+
return join46(getNpmInstallRoot(context, scope, true), "node_modules", source.name);
|
|
47540
47602
|
}
|
|
47541
47603
|
if (scope === "project") {
|
|
47542
|
-
return
|
|
47604
|
+
return join46(context.cwd, CONFIG_DIR_NAME, "npm", "node_modules", source.name);
|
|
47543
47605
|
}
|
|
47544
|
-
return
|
|
47606
|
+
return join46(context.agentDir, "npm", "node_modules", source.name);
|
|
47545
47607
|
}
|
|
47546
47608
|
function getGlobalNpmRoot(context) {
|
|
47547
47609
|
const npmCommand = getNpmCommand(context);
|
|
@@ -47551,7 +47613,7 @@ function getGlobalNpmRoot(context) {
|
|
|
47551
47613
|
}
|
|
47552
47614
|
if (getPackageManagerName(context) === "bun") {
|
|
47553
47615
|
const binDir = runNpmCommandSync(context, ["pm", "bin", "-g"]).trim();
|
|
47554
|
-
context.globalNpmRoot =
|
|
47616
|
+
context.globalNpmRoot = join46(dirname23(binDir), "install", "global", "node_modules");
|
|
47555
47617
|
} else {
|
|
47556
47618
|
context.globalNpmRoot = runNpmCommandSync(context, ["root", "-g"]).trim();
|
|
47557
47619
|
}
|
|
@@ -47577,28 +47639,28 @@ function getLegacyGlobalNpmInstallPath(context, source) {
|
|
|
47577
47639
|
if (pnpmPath)
|
|
47578
47640
|
return pnpmPath;
|
|
47579
47641
|
const globalRoot = context.driver?.getGlobalNpmRoot ? context.driver.getGlobalNpmRoot() : getGlobalNpmRoot(context);
|
|
47580
|
-
return
|
|
47642
|
+
return join46(globalRoot, source.name);
|
|
47581
47643
|
} catch {
|
|
47582
47644
|
return;
|
|
47583
47645
|
}
|
|
47584
47646
|
}
|
|
47585
47647
|
function getNpmInstallPath(context, source, scope) {
|
|
47586
47648
|
const managedPath = getManagedNpmInstallPath(context, source, scope);
|
|
47587
|
-
if (scope !== "user" ||
|
|
47649
|
+
if (scope !== "user" || existsSync34(managedPath)) {
|
|
47588
47650
|
return managedPath;
|
|
47589
47651
|
}
|
|
47590
47652
|
const legacyPath = getLegacyGlobalNpmInstallPath(context, source);
|
|
47591
|
-
return legacyPath &&
|
|
47653
|
+
return legacyPath && existsSync34(legacyPath) ? legacyPath : managedPath;
|
|
47592
47654
|
}
|
|
47593
47655
|
function getExistingNpmInstallPath(context, source, scope) {
|
|
47594
47656
|
const candidates = [getNpmInstallPath(context, source, scope)];
|
|
47595
47657
|
if (scope === "project") {
|
|
47596
47658
|
for (const configDir of getProjectConfigDirs(context.cwd)) {
|
|
47597
|
-
candidates.push(
|
|
47659
|
+
candidates.push(join46(configDir, "npm", "node_modules", source.name));
|
|
47598
47660
|
}
|
|
47599
47661
|
}
|
|
47600
47662
|
for (const candidate of Array.from(new Set(candidates))) {
|
|
47601
|
-
if (
|
|
47663
|
+
if (existsSync34(candidate))
|
|
47602
47664
|
return candidate;
|
|
47603
47665
|
}
|
|
47604
47666
|
return;
|
|
@@ -47635,11 +47697,11 @@ async function npmHasAvailableUpdate(context, source, installedPath) {
|
|
|
47635
47697
|
}
|
|
47636
47698
|
}
|
|
47637
47699
|
function getInstalledNpmVersion(installedPath) {
|
|
47638
|
-
const packageJsonPath =
|
|
47639
|
-
if (!
|
|
47700
|
+
const packageJsonPath = join46(installedPath, "package.json");
|
|
47701
|
+
if (!existsSync34(packageJsonPath))
|
|
47640
47702
|
return;
|
|
47641
47703
|
try {
|
|
47642
|
-
const content =
|
|
47704
|
+
const content = readFileSync24(packageJsonPath, "utf-8");
|
|
47643
47705
|
const pkg2 = JSON.parse(content);
|
|
47644
47706
|
return pkg2.version;
|
|
47645
47707
|
} catch {
|
|
@@ -47694,8 +47756,8 @@ async function withProgress(context, action, source, message, operation) {
|
|
|
47694
47756
|
}
|
|
47695
47757
|
|
|
47696
47758
|
// src/core/package-manager-git.ts
|
|
47697
|
-
import { existsSync as
|
|
47698
|
-
import { basename as basename12, dirname as
|
|
47759
|
+
import { existsSync as existsSync35, mkdirSync as mkdirSync12, readdirSync as readdirSync9, readFileSync as readFileSync25, rmSync as rmSync8, writeFileSync as writeFileSync13 } from "node:fs";
|
|
47760
|
+
import { basename as basename12, dirname as dirname24, join as join47, resolve as resolve13, sep as sep10 } from "node:path";
|
|
47699
47761
|
function runGitProcess(context, command, args, options) {
|
|
47700
47762
|
return context.driver ? context.driver.runCommand(command, args, options) : runCommand2(command, args, options);
|
|
47701
47763
|
}
|
|
@@ -47724,28 +47786,28 @@ function getExistingGitInstallPath(context, source, scope) {
|
|
|
47724
47786
|
const candidates = [getGitInstallPath(context, source, scope)];
|
|
47725
47787
|
if (scope === "project") {
|
|
47726
47788
|
for (const configDir of getProjectConfigDirs(context.cwd)) {
|
|
47727
|
-
candidates.push(
|
|
47789
|
+
candidates.push(join47(configDir, "git", source.host, source.path));
|
|
47728
47790
|
}
|
|
47729
47791
|
} else if (scope === "user") {
|
|
47730
47792
|
for (const agentDir of getBaseDirsForScope(context, "user")) {
|
|
47731
|
-
candidates.push(
|
|
47793
|
+
candidates.push(join47(agentDir, "git", source.host, source.path));
|
|
47732
47794
|
}
|
|
47733
47795
|
}
|
|
47734
47796
|
for (const candidate of Array.from(new Set(candidates))) {
|
|
47735
|
-
if (
|
|
47797
|
+
if (existsSync35(candidate))
|
|
47736
47798
|
return candidate;
|
|
47737
47799
|
}
|
|
47738
47800
|
return;
|
|
47739
47801
|
}
|
|
47740
47802
|
function getGitUpdateMarkerPath(targetDir) {
|
|
47741
|
-
return
|
|
47803
|
+
return join47(dirname24(targetDir), `.${basename12(targetDir)}.${APP_NAME}-update-incomplete`);
|
|
47742
47804
|
}
|
|
47743
47805
|
function hasMissingGitDependencies(targetDir) {
|
|
47744
|
-
const packageJsonPath =
|
|
47745
|
-
if (!
|
|
47806
|
+
const packageJsonPath = join47(targetDir, "package.json");
|
|
47807
|
+
if (!existsSync35(packageJsonPath))
|
|
47746
47808
|
return false;
|
|
47747
47809
|
try {
|
|
47748
|
-
const manifest = JSON.parse(
|
|
47810
|
+
const manifest = JSON.parse(readFileSync25(packageJsonPath, "utf-8"));
|
|
47749
47811
|
if (!manifest.dependencies || typeof manifest.dependencies !== "object" || Array.isArray(manifest.dependencies)) {
|
|
47750
47812
|
return false;
|
|
47751
47813
|
}
|
|
@@ -47754,7 +47816,7 @@ function hasMissingGitDependencies(targetDir) {
|
|
|
47754
47816
|
const dependencyPath = resolve13(nodeModulesDir, name);
|
|
47755
47817
|
if (!dependencyPath.startsWith(`${nodeModulesDir}${sep10}`))
|
|
47756
47818
|
return false;
|
|
47757
|
-
return !
|
|
47819
|
+
return !existsSync35(dependencyPath);
|
|
47758
47820
|
});
|
|
47759
47821
|
} catch {
|
|
47760
47822
|
return false;
|
|
@@ -47772,7 +47834,7 @@ async function cleanAndInstallGitDependencies(context, targetDir, markerPath) {
|
|
|
47772
47834
|
await repairMissingGitDependencies(context, targetDir).catch(() => {});
|
|
47773
47835
|
throw error;
|
|
47774
47836
|
}
|
|
47775
|
-
if (
|
|
47837
|
+
if (existsSync35(join47(targetDir, "package.json"))) {
|
|
47776
47838
|
await runNpmCommand(context, getGitDependencyInstallArgs(context), { cwd: targetDir });
|
|
47777
47839
|
}
|
|
47778
47840
|
rmSync8(markerPath, { force: true });
|
|
@@ -47780,7 +47842,7 @@ async function cleanAndInstallGitDependencies(context, targetDir, markerPath) {
|
|
|
47780
47842
|
async function installGit(context, source, scope) {
|
|
47781
47843
|
const safeRef = source.ref ? getSafeGitRef(source.ref) : undefined;
|
|
47782
47844
|
const targetDir = getGitInstallPath(context, source, scope);
|
|
47783
|
-
if (
|
|
47845
|
+
if (existsSync35(targetDir)) {
|
|
47784
47846
|
if (safeRef) {
|
|
47785
47847
|
await ensureGitRef(context, targetDir, ["fetch", "origin", "--", safeRef], "FETCH_HEAD");
|
|
47786
47848
|
return;
|
|
@@ -47793,7 +47855,7 @@ async function installGit(context, source, scope) {
|
|
|
47793
47855
|
if (gitRoot) {
|
|
47794
47856
|
ensureGitIgnore(gitRoot);
|
|
47795
47857
|
}
|
|
47796
|
-
mkdirSync12(
|
|
47858
|
+
mkdirSync12(dirname24(targetDir), { recursive: true });
|
|
47797
47859
|
rmSync8(getGitUpdateMarkerPath(targetDir), { force: true });
|
|
47798
47860
|
const cloneUrl = source.repo;
|
|
47799
47861
|
if (!/^[A-Za-z0-9._~:@/%+-]+$/.test(cloneUrl)) {
|
|
@@ -47804,8 +47866,8 @@ async function installGit(context, source, scope) {
|
|
|
47804
47866
|
if (safeRef) {
|
|
47805
47867
|
await runGitProcess(context, "git", ["checkout", safeRef], { cwd: targetDir });
|
|
47806
47868
|
}
|
|
47807
|
-
const packageJsonPath =
|
|
47808
|
-
if (
|
|
47869
|
+
const packageJsonPath = join47(targetDir, "package.json");
|
|
47870
|
+
if (existsSync35(packageJsonPath)) {
|
|
47809
47871
|
await runNpmCommand(context, getGitDependencyInstallArgs(context), { cwd: targetDir });
|
|
47810
47872
|
}
|
|
47811
47873
|
} catch (error) {
|
|
@@ -47817,7 +47879,7 @@ async function installGit(context, source, scope) {
|
|
|
47817
47879
|
async function updateGit(context, source, scope) {
|
|
47818
47880
|
const safeRef = source.ref ? getSafeGitRef(source.ref) : undefined;
|
|
47819
47881
|
const targetDir = getExistingGitInstallPath(context, source, scope) ?? getGitInstallPath(context, source, scope);
|
|
47820
|
-
if (!
|
|
47882
|
+
if (!existsSync35(targetDir)) {
|
|
47821
47883
|
await installGit(context, source, scope);
|
|
47822
47884
|
return;
|
|
47823
47885
|
}
|
|
@@ -47841,7 +47903,7 @@ async function ensureGitRef(context, targetDir, fetchArgs, ref) {
|
|
|
47841
47903
|
});
|
|
47842
47904
|
const markerPath = getGitUpdateMarkerPath(targetDir);
|
|
47843
47905
|
if (localHead.trim() === targetHead.trim()) {
|
|
47844
|
-
if (
|
|
47906
|
+
if (existsSync35(markerPath)) {
|
|
47845
47907
|
await cleanAndInstallGitDependencies(context, targetDir, markerPath);
|
|
47846
47908
|
} else {
|
|
47847
47909
|
await repairMissingGitDependencies(context, targetDir);
|
|
@@ -47872,10 +47934,10 @@ function pruneEmptyGitParents(targetDir, installRoot) {
|
|
|
47872
47934
|
if (!installRoot)
|
|
47873
47935
|
return;
|
|
47874
47936
|
const resolvedRoot = resolve13(installRoot);
|
|
47875
|
-
let current =
|
|
47937
|
+
let current = dirname24(targetDir);
|
|
47876
47938
|
while (current.startsWith(resolvedRoot) && current !== resolvedRoot) {
|
|
47877
|
-
if (!
|
|
47878
|
-
current =
|
|
47939
|
+
if (!existsSync35(current)) {
|
|
47940
|
+
current = dirname24(current);
|
|
47879
47941
|
continue;
|
|
47880
47942
|
}
|
|
47881
47943
|
const entries = readdirSync9(current);
|
|
@@ -47886,7 +47948,7 @@ function pruneEmptyGitParents(targetDir, installRoot) {
|
|
|
47886
47948
|
} catch {
|
|
47887
47949
|
break;
|
|
47888
47950
|
}
|
|
47889
|
-
current =
|
|
47951
|
+
current = dirname24(current);
|
|
47890
47952
|
}
|
|
47891
47953
|
}
|
|
47892
47954
|
async function gitHasAvailableUpdate(context, installedPath) {
|
|
@@ -48341,7 +48403,7 @@ var init_package_manager_source = __esm(() => {
|
|
|
48341
48403
|
});
|
|
48342
48404
|
|
|
48343
48405
|
// src/core/package-manager-operations.ts
|
|
48344
|
-
import { existsSync as
|
|
48406
|
+
import { existsSync as existsSync36 } from "node:fs";
|
|
48345
48407
|
async function install2(context, source, options) {
|
|
48346
48408
|
const parsed = parseSource(source);
|
|
48347
48409
|
const scope = options?.local ? "project" : "user";
|
|
@@ -48357,7 +48419,7 @@ async function install2(context, source, options) {
|
|
|
48357
48419
|
}
|
|
48358
48420
|
if (parsed.type === "local") {
|
|
48359
48421
|
const resolved = resolveManagerPath(context, parsed.path);
|
|
48360
|
-
if (!
|
|
48422
|
+
if (!existsSync36(resolved)) {
|
|
48361
48423
|
throw new Error(`Path does not exist: ${resolved}`);
|
|
48362
48424
|
}
|
|
48363
48425
|
return;
|
|
@@ -48467,7 +48529,7 @@ async function updateConfiguredSources(context, sources) {
|
|
|
48467
48529
|
}
|
|
48468
48530
|
async function shouldUpdateNpmSource(context, source, scope) {
|
|
48469
48531
|
const installedPath = getManagedNpmInstallPath(context, source, scope);
|
|
48470
|
-
const installedVersion =
|
|
48532
|
+
const installedVersion = existsSync36(installedPath) ? getInstalledNpmVersion(installedPath) : undefined;
|
|
48471
48533
|
if (!installedVersion)
|
|
48472
48534
|
return true;
|
|
48473
48535
|
try {
|
|
@@ -48504,7 +48566,7 @@ async function checkForAvailableUpdates(context) {
|
|
|
48504
48566
|
return;
|
|
48505
48567
|
if (parsed.type === "npm") {
|
|
48506
48568
|
const installedPath2 = getNpmInstallPath(context, parsed, entry.scope);
|
|
48507
|
-
if (!
|
|
48569
|
+
if (!existsSync36(installedPath2))
|
|
48508
48570
|
return;
|
|
48509
48571
|
const hasUpdate2 = await npmHasAvailableUpdate(context, parsed, installedPath2);
|
|
48510
48572
|
if (!hasUpdate2)
|
|
@@ -48602,7 +48664,7 @@ var init_package_manager_resource_accumulator = __esm(() => {
|
|
|
48602
48664
|
});
|
|
48603
48665
|
|
|
48604
48666
|
// src/core/package-manager-resource-patterns.ts
|
|
48605
|
-
import { basename as basename13, dirname as
|
|
48667
|
+
import { basename as basename13, dirname as dirname25, relative as relative10, sep as sep11 } from "node:path";
|
|
48606
48668
|
import { minimatch } from "minimatch";
|
|
48607
48669
|
function toPosixPath5(p) {
|
|
48608
48670
|
return p.split(sep11).join("/");
|
|
@@ -48633,7 +48695,7 @@ function matchesAnyPattern(filePath, patterns, baseDir) {
|
|
|
48633
48695
|
const name = basename13(filePath);
|
|
48634
48696
|
const filePathPosix = toPosixPath5(filePath);
|
|
48635
48697
|
const isSkillFile = name === "SKILL.md";
|
|
48636
|
-
const parentDir = isSkillFile ?
|
|
48698
|
+
const parentDir = isSkillFile ? dirname25(filePath) : undefined;
|
|
48637
48699
|
const parentRel = isSkillFile ? toPosixPath5(relative10(baseDir, parentDir)) : undefined;
|
|
48638
48700
|
const parentName = isSkillFile ? basename13(parentDir) : undefined;
|
|
48639
48701
|
const parentDirPosix = isSkillFile ? toPosixPath5(parentDir) : undefined;
|
|
@@ -48658,7 +48720,7 @@ function matchesAnyExactPattern(filePath, patterns, baseDir) {
|
|
|
48658
48720
|
const name = basename13(filePath);
|
|
48659
48721
|
const filePathPosix = toPosixPath5(filePath);
|
|
48660
48722
|
const isSkillFile = name === "SKILL.md";
|
|
48661
|
-
const parentDir = isSkillFile ?
|
|
48723
|
+
const parentDir = isSkillFile ? dirname25(filePath) : undefined;
|
|
48662
48724
|
const parentRel = isSkillFile ? toPosixPath5(relative10(baseDir, parentDir)) : undefined;
|
|
48663
48725
|
const parentDirPosix = isSkillFile ? toPosixPath5(parentDir) : undefined;
|
|
48664
48726
|
return patterns.some((pattern) => {
|
|
@@ -48759,7 +48821,7 @@ var init_package_manager_types = __esm(() => {
|
|
|
48759
48821
|
|
|
48760
48822
|
// src/core/package-manager-resource-files.ts
|
|
48761
48823
|
import { access as access2, readdir as readdir3, readFile as readFile3, stat as stat3 } from "node:fs/promises";
|
|
48762
|
-
import { dirname as
|
|
48824
|
+
import { dirname as dirname26, join as join48, relative as relative11, resolve as resolve14, sep as sep12 } from "node:path";
|
|
48763
48825
|
import ignore2 from "ignore";
|
|
48764
48826
|
async function exists(path16) {
|
|
48765
48827
|
try {
|
|
@@ -48790,7 +48852,7 @@ async function addIgnoreRules2(ig, dir, rootDir) {
|
|
|
48790
48852
|
const prefix = relativeDir ? `${toPosixPath5(relativeDir)}/` : "";
|
|
48791
48853
|
for (const filename of IGNORE_FILE_NAMES2) {
|
|
48792
48854
|
try {
|
|
48793
|
-
const content = await readFile3(
|
|
48855
|
+
const content = await readFile3(join48(dir, filename), "utf-8");
|
|
48794
48856
|
const patterns = content.split(/\r?\n/).map((line) => prefixIgnorePattern2(line, prefix)).filter((line) => Boolean(line));
|
|
48795
48857
|
if (patterns.length > 0)
|
|
48796
48858
|
ig.add(patterns);
|
|
@@ -48798,7 +48860,7 @@ async function addIgnoreRules2(ig, dir, rootDir) {
|
|
|
48798
48860
|
}
|
|
48799
48861
|
}
|
|
48800
48862
|
async function getEntryInfo(dir, name, isDirectory, isFileEntry, isSymlink) {
|
|
48801
|
-
const fullPath =
|
|
48863
|
+
const fullPath = join48(dir, name);
|
|
48802
48864
|
let isDir = isDirectory;
|
|
48803
48865
|
let isFile = isFileEntry;
|
|
48804
48866
|
if (isSymlink) {
|
|
@@ -48888,9 +48950,9 @@ async function collectAutoSkillEntries(dir, mode) {
|
|
|
48888
48950
|
async function findGitRepoRoot(startDir) {
|
|
48889
48951
|
let dir = resolve14(startDir);
|
|
48890
48952
|
while (true) {
|
|
48891
|
-
if (await exists(
|
|
48953
|
+
if (await exists(join48(dir, ".git")))
|
|
48892
48954
|
return dir;
|
|
48893
|
-
const parent =
|
|
48955
|
+
const parent = dirname26(dir);
|
|
48894
48956
|
if (parent === dir)
|
|
48895
48957
|
return null;
|
|
48896
48958
|
dir = parent;
|
|
@@ -48902,10 +48964,10 @@ async function collectAncestorAgentsSkillDirs(startDir) {
|
|
|
48902
48964
|
const gitRepoRoot = await findGitRepoRoot(resolvedStartDir);
|
|
48903
48965
|
let dir = resolvedStartDir;
|
|
48904
48966
|
while (true) {
|
|
48905
|
-
skillDirs.push(
|
|
48967
|
+
skillDirs.push(join48(dir, ".agents", "skills"));
|
|
48906
48968
|
if (gitRepoRoot && dir === gitRepoRoot)
|
|
48907
48969
|
break;
|
|
48908
|
-
const parent =
|
|
48970
|
+
const parent = dirname26(dir);
|
|
48909
48971
|
if (parent === dir)
|
|
48910
48972
|
break;
|
|
48911
48973
|
dir = parent;
|
|
@@ -48944,7 +49006,7 @@ async function collectAutoThemeEntries(dir) {
|
|
|
48944
49006
|
return collectFlatEntries(dir, ".json");
|
|
48945
49007
|
}
|
|
48946
49008
|
async function resolveExtensionEntries2(dir) {
|
|
48947
|
-
const packageJsonPath =
|
|
49009
|
+
const packageJsonPath = join48(dir, "package.json");
|
|
48948
49010
|
if (await exists(packageJsonPath)) {
|
|
48949
49011
|
try {
|
|
48950
49012
|
const manifest = getManifestFromPackageJson(JSON.parse(await readFile3(packageJsonPath, "utf-8")));
|
|
@@ -48960,8 +49022,8 @@ async function resolveExtensionEntries2(dir) {
|
|
|
48960
49022
|
}
|
|
48961
49023
|
} catch {}
|
|
48962
49024
|
}
|
|
48963
|
-
const indexTs =
|
|
48964
|
-
const indexJs =
|
|
49025
|
+
const indexTs = join48(dir, "index.ts");
|
|
49026
|
+
const indexJs = join48(dir, "index.js");
|
|
48965
49027
|
if (await exists(indexTs))
|
|
48966
49028
|
return [indexTs];
|
|
48967
49029
|
if (await exists(indexJs))
|
|
@@ -49019,7 +49081,7 @@ var init_package_manager_resource_files = __esm(() => {
|
|
|
49019
49081
|
});
|
|
49020
49082
|
|
|
49021
49083
|
// src/core/package-manager-auto-resources.ts
|
|
49022
|
-
import { dirname as
|
|
49084
|
+
import { dirname as dirname27, join as join49, resolve as resolve15 } from "node:path";
|
|
49023
49085
|
async function collectProjectLocalResources(sourceRoot, accumulator, filter, metadata) {
|
|
49024
49086
|
let found = false;
|
|
49025
49087
|
const projectMetadata = { ...metadata, origin: "top-level", borrowedProjectLocal: true };
|
|
@@ -49034,14 +49096,14 @@ async function collectProjectLocalResources(sourceRoot, accumulator, filter, met
|
|
|
49034
49096
|
};
|
|
49035
49097
|
for (const configDir of getProjectConfigDirs(sourceRoot)) {
|
|
49036
49098
|
const configMetadata = { ...projectMetadata, baseDir: configDir };
|
|
49037
|
-
addResources("extensions", await collectAutoExtensionEntries(
|
|
49038
|
-
addResources("skills", await collectAutoSkillEntries(
|
|
49039
|
-
addResources("prompts", await collectAutoPromptEntries(
|
|
49040
|
-
addResources("themes", await collectAutoThemeEntries(
|
|
49041
|
-
addResources("workflows", await collectResourceFiles(
|
|
49042
|
-
}
|
|
49043
|
-
const agentsSkillsDir =
|
|
49044
|
-
addResources("skills", await collectAutoSkillEntries(agentsSkillsDir, "agents"), { ...projectMetadata, baseDir:
|
|
49099
|
+
addResources("extensions", await collectAutoExtensionEntries(join49(configDir, "extensions")), configMetadata, filter?.extensions);
|
|
49100
|
+
addResources("skills", await collectAutoSkillEntries(join49(configDir, "skills"), "pi"), configMetadata, filter?.skills);
|
|
49101
|
+
addResources("prompts", await collectAutoPromptEntries(join49(configDir, "prompts")), configMetadata, filter?.prompts);
|
|
49102
|
+
addResources("themes", await collectAutoThemeEntries(join49(configDir, "themes")), configMetadata, filter?.themes);
|
|
49103
|
+
addResources("workflows", await collectResourceFiles(join49(configDir, "workflows"), "workflows"), configMetadata, filter?.workflows);
|
|
49104
|
+
}
|
|
49105
|
+
const agentsSkillsDir = join49(sourceRoot, ".agents", "skills");
|
|
49106
|
+
addResources("skills", await collectAutoSkillEntries(agentsSkillsDir, "agents"), { ...projectMetadata, baseDir: dirname27(agentsSkillsDir) }, filter?.skills);
|
|
49045
49107
|
return found;
|
|
49046
49108
|
}
|
|
49047
49109
|
async function addAutoDiscoveredResources(context, accumulator, globalSettings, projectSettings, globalBaseDir, projectBaseDir) {
|
|
@@ -49068,7 +49130,7 @@ async function addAutoDiscoveredResources(context, accumulator, globalSettings,
|
|
|
49068
49130
|
};
|
|
49069
49131
|
const userConfigDirs = getBaseDirsForScope(context, "user");
|
|
49070
49132
|
const projectConfigDirs = getBaseDirsForScope(context, "project");
|
|
49071
|
-
const userAgentsSkillsDir =
|
|
49133
|
+
const userAgentsSkillsDir = join49(getHomeDir2(), ".agents", "skills");
|
|
49072
49134
|
const projectTrusted = context.settingsManager.isProjectTrusted();
|
|
49073
49135
|
const projectAgentsSkillDirs = projectTrusted ? (await collectAncestorAgentsSkillDirs(context.cwd)).filter((dir) => resolve15(dir) !== resolve15(userAgentsSkillsDir)) : [];
|
|
49074
49136
|
const addResources = (resourceType, paths, metadata, overrides, baseDir) => {
|
|
@@ -49083,15 +49145,15 @@ async function addAutoDiscoveredResources(context, accumulator, globalSettings,
|
|
|
49083
49145
|
baseDir: configDir,
|
|
49084
49146
|
configurationOrigin: index === 0 ? "atomic" : "inherited-pi"
|
|
49085
49147
|
};
|
|
49086
|
-
addResources("extensions", await collectAutoExtensionEntries(
|
|
49087
|
-
addResources("skills", await collectAutoSkillEntries(
|
|
49088
|
-
addResources("prompts", await collectAutoPromptEntries(
|
|
49089
|
-
addResources("themes", await collectAutoThemeEntries(
|
|
49090
|
-
addResources("workflows", await collectResourceFiles(
|
|
49148
|
+
addResources("extensions", await collectAutoExtensionEntries(join49(configDir, "extensions")), metadata, projectOverrides.extensions, configDir);
|
|
49149
|
+
addResources("skills", await collectAutoSkillEntries(join49(configDir, "skills"), "pi"), metadata, projectOverrides.skills, configDir);
|
|
49150
|
+
addResources("prompts", await collectAutoPromptEntries(join49(configDir, "prompts")), metadata, projectOverrides.prompts, configDir);
|
|
49151
|
+
addResources("themes", await collectAutoThemeEntries(join49(configDir, "themes")), metadata, projectOverrides.themes, configDir);
|
|
49152
|
+
addResources("workflows", await collectResourceFiles(join49(configDir, "workflows"), "workflows"), metadata, projectOverrides.workflows, configDir);
|
|
49091
49153
|
}
|
|
49092
49154
|
}
|
|
49093
49155
|
for (const agentsSkillsDir of projectAgentsSkillDirs) {
|
|
49094
|
-
const agentsBaseDir =
|
|
49156
|
+
const agentsBaseDir = dirname27(agentsSkillsDir);
|
|
49095
49157
|
addResources("skills", await collectAutoSkillEntries(agentsSkillsDir, "agents"), { ...projectMetadata, baseDir: agentsBaseDir }, projectOverrides.skills, agentsBaseDir);
|
|
49096
49158
|
}
|
|
49097
49159
|
for (const [index, configDir] of userConfigDirs.entries()) {
|
|
@@ -49100,13 +49162,13 @@ async function addAutoDiscoveredResources(context, accumulator, globalSettings,
|
|
|
49100
49162
|
baseDir: configDir,
|
|
49101
49163
|
configurationOrigin: index === 0 ? "atomic" : "inherited-pi"
|
|
49102
49164
|
};
|
|
49103
|
-
addResources("extensions", await collectAutoExtensionEntries(
|
|
49104
|
-
addResources("skills", await collectAutoSkillEntries(
|
|
49105
|
-
addResources("prompts", await collectAutoPromptEntries(
|
|
49106
|
-
addResources("themes", await collectAutoThemeEntries(
|
|
49107
|
-
addResources("workflows", await collectResourceFiles(
|
|
49165
|
+
addResources("extensions", await collectAutoExtensionEntries(join49(configDir, "extensions")), metadata, userOverrides.extensions, configDir);
|
|
49166
|
+
addResources("skills", await collectAutoSkillEntries(join49(configDir, "skills"), "pi"), metadata, userOverrides.skills, configDir);
|
|
49167
|
+
addResources("prompts", await collectAutoPromptEntries(join49(configDir, "prompts")), metadata, userOverrides.prompts, configDir);
|
|
49168
|
+
addResources("themes", await collectAutoThemeEntries(join49(configDir, "themes")), metadata, userOverrides.themes, configDir);
|
|
49169
|
+
addResources("workflows", await collectResourceFiles(join49(configDir, "workflows"), "workflows"), metadata, userOverrides.workflows, configDir);
|
|
49108
49170
|
}
|
|
49109
|
-
const userAgentsBaseDir =
|
|
49171
|
+
const userAgentsBaseDir = dirname27(userAgentsSkillsDir);
|
|
49110
49172
|
addResources("skills", await collectAutoSkillEntries(userAgentsSkillsDir, "agents"), { ...userMetadata, baseDir: userAgentsBaseDir }, userOverrides.skills, userAgentsBaseDir);
|
|
49111
49173
|
}
|
|
49112
49174
|
var init_package_manager_auto_resources = __esm(() => {
|
|
@@ -49275,7 +49337,7 @@ var init_package_manager_resource_collector = __esm(() => {
|
|
|
49275
49337
|
|
|
49276
49338
|
// src/core/package-manager-resolver.ts
|
|
49277
49339
|
import { access as access4, stat as stat5 } from "node:fs/promises";
|
|
49278
|
-
import { dirname as
|
|
49340
|
+
import { dirname as dirname28, isAbsolute as isAbsolute8, join as join50 } from "node:path";
|
|
49279
49341
|
async function exists3(path16) {
|
|
49280
49342
|
try {
|
|
49281
49343
|
await access4(path16);
|
|
@@ -49298,7 +49360,7 @@ async function resolvePackages(context, onMissing) {
|
|
|
49298
49360
|
const packageSources = dedupePackages(context, allPackages);
|
|
49299
49361
|
await resolvePackageSources(context, packageSources, accumulator, onMissing, { settingsField: "packages" });
|
|
49300
49362
|
const globalBaseDir = context.agentDir;
|
|
49301
|
-
const projectBaseDir =
|
|
49363
|
+
const projectBaseDir = join50(context.cwd, CONFIG_DIR_NAME);
|
|
49302
49364
|
const globalBaseDirs = getBaseDirsForScope(context, "user");
|
|
49303
49365
|
const projectBaseDirs = getBaseDirsForScope(context, "project");
|
|
49304
49366
|
for (const resourceType of ["extensions", "skills", "prompts", "themes", "workflows"]) {
|
|
@@ -49433,7 +49495,7 @@ async function resolveLocalExtensionSource(source, accumulator, filter, metadata
|
|
|
49433
49495
|
try {
|
|
49434
49496
|
const stats = await stat5(resolved);
|
|
49435
49497
|
if (stats.isFile()) {
|
|
49436
|
-
addResource(accumulator.extensions, resolved, { ...metadata, baseDir:
|
|
49498
|
+
addResource(accumulator.extensions, resolved, { ...metadata, baseDir: dirname28(resolved) }, true);
|
|
49437
49499
|
return;
|
|
49438
49500
|
}
|
|
49439
49501
|
if (stats.isDirectory()) {
|
|
@@ -49464,7 +49526,7 @@ var init_package_manager_resolver = __esm(() => {
|
|
|
49464
49526
|
});
|
|
49465
49527
|
|
|
49466
49528
|
// src/core/package-manager-settings.ts
|
|
49467
|
-
import { existsSync as
|
|
49529
|
+
import { existsSync as existsSync37 } from "node:fs";
|
|
49468
49530
|
function addSourceToSettings(context, source, options) {
|
|
49469
49531
|
const scope = options?.local ? "project" : "user";
|
|
49470
49532
|
const currentSettings = scope === "project" ? context.settingsManager.getProjectSettings() : context.settingsManager.getGlobalSettings();
|
|
@@ -49518,7 +49580,7 @@ function getInstalledPath(context, source, scope) {
|
|
|
49518
49580
|
}
|
|
49519
49581
|
for (const baseDir of getBaseDirsForScope(context, scope)) {
|
|
49520
49582
|
const path16 = resolvePathFromBase(parsed.path, baseDir);
|
|
49521
|
-
if (
|
|
49583
|
+
if (existsSync37(path16))
|
|
49522
49584
|
return path16;
|
|
49523
49585
|
}
|
|
49524
49586
|
return;
|
|
@@ -49742,29 +49804,29 @@ var init_package_manager = __esm(() => {
|
|
|
49742
49804
|
|
|
49743
49805
|
// src/core/footer-data-provider.ts
|
|
49744
49806
|
import { execFile, spawnSync as spawnSync7 } from "child_process";
|
|
49745
|
-
import { existsSync as
|
|
49746
|
-
import { dirname as
|
|
49807
|
+
import { existsSync as existsSync38, readFileSync as readFileSync26, statSync as statSync9, unwatchFile as unwatchFile2, watchFile as watchFile2 } from "fs";
|
|
49808
|
+
import { dirname as dirname29, join as join51, resolve as resolve17 } from "path";
|
|
49747
49809
|
function findGitPaths(cwd) {
|
|
49748
49810
|
let dir = cwd;
|
|
49749
49811
|
while (true) {
|
|
49750
|
-
const gitPath =
|
|
49751
|
-
if (
|
|
49812
|
+
const gitPath = join51(dir, ".git");
|
|
49813
|
+
if (existsSync38(gitPath)) {
|
|
49752
49814
|
try {
|
|
49753
49815
|
const stat6 = statSync9(gitPath);
|
|
49754
49816
|
if (stat6.isFile()) {
|
|
49755
|
-
const content =
|
|
49817
|
+
const content = readFileSync26(gitPath, "utf8").trim();
|
|
49756
49818
|
if (content.startsWith("gitdir: ")) {
|
|
49757
49819
|
const gitDir = resolve17(dir, content.slice(8).trim());
|
|
49758
|
-
const headPath =
|
|
49759
|
-
if (!
|
|
49820
|
+
const headPath = join51(gitDir, "HEAD");
|
|
49821
|
+
if (!existsSync38(headPath))
|
|
49760
49822
|
return null;
|
|
49761
|
-
const commonDirPath =
|
|
49762
|
-
const commonGitDir =
|
|
49823
|
+
const commonDirPath = join51(gitDir, "commondir");
|
|
49824
|
+
const commonGitDir = existsSync38(commonDirPath) ? resolve17(gitDir, readFileSync26(commonDirPath, "utf8").trim()) : gitDir;
|
|
49763
49825
|
return { repoDir: dir, commonGitDir, headPath };
|
|
49764
49826
|
}
|
|
49765
49827
|
} else if (stat6.isDirectory()) {
|
|
49766
|
-
const headPath =
|
|
49767
|
-
if (!
|
|
49828
|
+
const headPath = join51(gitPath, "HEAD");
|
|
49829
|
+
if (!existsSync38(headPath))
|
|
49768
49830
|
return null;
|
|
49769
49831
|
return { repoDir: dir, commonGitDir: gitPath, headPath };
|
|
49770
49832
|
}
|
|
@@ -49772,7 +49834,7 @@ function findGitPaths(cwd) {
|
|
|
49772
49834
|
return null;
|
|
49773
49835
|
}
|
|
49774
49836
|
}
|
|
49775
|
-
const parent =
|
|
49837
|
+
const parent = dirname29(dir);
|
|
49776
49838
|
if (parent === dir)
|
|
49777
49839
|
return null;
|
|
49778
49840
|
dir = parent;
|
|
@@ -49956,7 +50018,7 @@ class FooterDataProvider {
|
|
|
49956
50018
|
try {
|
|
49957
50019
|
if (!this.gitPaths)
|
|
49958
50020
|
return null;
|
|
49959
|
-
const content =
|
|
50021
|
+
const content = readFileSync26(this.gitPaths.headPath, "utf8").trim();
|
|
49960
50022
|
if (content.startsWith("ref: refs/heads/")) {
|
|
49961
50023
|
const branch = content.slice(16);
|
|
49962
50024
|
return branch === ".invalid" ? resolveBranchWithGitSync(this.gitPaths.repoDir) ?? "detached" : branch;
|
|
@@ -49970,7 +50032,7 @@ class FooterDataProvider {
|
|
|
49970
50032
|
try {
|
|
49971
50033
|
if (!this.gitPaths)
|
|
49972
50034
|
return null;
|
|
49973
|
-
const content =
|
|
50035
|
+
const content = readFileSync26(this.gitPaths.headPath, "utf8").trim();
|
|
49974
50036
|
if (content.startsWith("ref: refs/heads/")) {
|
|
49975
50037
|
const branch = content.slice(16);
|
|
49976
50038
|
return branch === ".invalid" ? await resolveBranchWithGitAsync(this.gitPaths.repoDir) ?? "detached" : branch;
|
|
@@ -50041,12 +50103,12 @@ class FooterDataProvider {
|
|
|
50041
50103
|
this.scheduleGitWatcherRetry();
|
|
50042
50104
|
}
|
|
50043
50105
|
readReftableTablesListFingerprint() {
|
|
50044
|
-
if (!this.reftableTablesListPath || !
|
|
50106
|
+
if (!this.reftableTablesListPath || !existsSync38(this.reftableTablesListPath)) {
|
|
50045
50107
|
return null;
|
|
50046
50108
|
}
|
|
50047
50109
|
try {
|
|
50048
50110
|
const stat6 = statSync9(this.reftableTablesListPath);
|
|
50049
|
-
const content =
|
|
50111
|
+
const content = readFileSync26(this.reftableTablesListPath, "utf8");
|
|
50050
50112
|
return `${stat6.size}:${stat6.mtimeMs}:${stat6.ctimeMs}:${content}`;
|
|
50051
50113
|
} catch {
|
|
50052
50114
|
return null;
|
|
@@ -50073,7 +50135,7 @@ class FooterDataProvider {
|
|
|
50073
50135
|
if (!this.gitPaths)
|
|
50074
50136
|
return;
|
|
50075
50137
|
const pollGitHead = shouldPollGitHead(this.gitPaths.repoDir);
|
|
50076
|
-
this.headWatcher = watchWithErrorHandler(
|
|
50138
|
+
this.headWatcher = watchWithErrorHandler(dirname29(this.gitPaths.headPath), (_eventType, filename) => {
|
|
50077
50139
|
if (!filename || filename === "HEAD") {
|
|
50078
50140
|
this.scheduleRefresh();
|
|
50079
50141
|
}
|
|
@@ -50090,9 +50152,9 @@ class FooterDataProvider {
|
|
|
50090
50152
|
if (!this.headWatcher && !this.headWatchFileListener) {
|
|
50091
50153
|
return;
|
|
50092
50154
|
}
|
|
50093
|
-
const reftableDir =
|
|
50094
|
-
if (
|
|
50095
|
-
this.reftableTablesListPath =
|
|
50155
|
+
const reftableDir = join51(this.gitPaths.commonGitDir, "reftable");
|
|
50156
|
+
if (existsSync38(reftableDir)) {
|
|
50157
|
+
this.reftableTablesListPath = join51(reftableDir, "tables.list");
|
|
50096
50158
|
this.reftableTablesListFingerprint = this.readReftableTablesListFingerprint();
|
|
50097
50159
|
this.reftableWatcher = watchWithErrorHandler(reftableDir, (_eventType, filename) => {
|
|
50098
50160
|
this.handleReftableDirectoryEvent(filename);
|
|
@@ -50103,7 +50165,7 @@ class FooterDataProvider {
|
|
|
50103
50165
|
this.handleGitWatcherError();
|
|
50104
50166
|
});
|
|
50105
50167
|
const tablesListPath = this.reftableTablesListPath;
|
|
50106
|
-
if (tablesListPath &&
|
|
50168
|
+
if (tablesListPath && existsSync38(tablesListPath)) {
|
|
50107
50169
|
this.reftableTablesListWatcher = watchWithErrorHandler(tablesListPath, () => {
|
|
50108
50170
|
this.scheduleReftableRefresh();
|
|
50109
50171
|
}, (error) => {
|
|
@@ -50125,16 +50187,16 @@ var init_footer_data_provider = __esm(() => {
|
|
|
50125
50187
|
});
|
|
50126
50188
|
|
|
50127
50189
|
// src/core/resource-loader-context-files.ts
|
|
50128
|
-
import { existsSync as
|
|
50129
|
-
import { basename as basename14, dirname as
|
|
50190
|
+
import { existsSync as existsSync39, readFileSync as readFileSync27, realpathSync as realpathSync6, statSync as statSync10 } from "node:fs";
|
|
50191
|
+
import { basename as basename14, dirname as dirname30, join as join52, sep as sep13 } from "node:path";
|
|
50130
50192
|
import chalk4 from "chalk";
|
|
50131
50193
|
function resolvePromptInput(input2, description) {
|
|
50132
50194
|
if (!input2) {
|
|
50133
50195
|
return;
|
|
50134
50196
|
}
|
|
50135
|
-
if (
|
|
50197
|
+
if (existsSync39(input2)) {
|
|
50136
50198
|
try {
|
|
50137
|
-
return
|
|
50199
|
+
return readFileSync27(input2, "utf-8");
|
|
50138
50200
|
} catch (error) {
|
|
50139
50201
|
console.error(chalk4.yellow(`Warning: Could not read ${description} file ${input2}: ${error}`));
|
|
50140
50202
|
return input2;
|
|
@@ -50143,7 +50205,7 @@ function resolvePromptInput(input2, description) {
|
|
|
50143
50205
|
return input2;
|
|
50144
50206
|
}
|
|
50145
50207
|
function resolveExistingPromptSourcePath(input2) {
|
|
50146
|
-
return input2 &&
|
|
50208
|
+
return input2 && existsSync39(input2) ? resolvePath(input2) : undefined;
|
|
50147
50209
|
}
|
|
50148
50210
|
function resolveExistingPromptSourcePaths(inputs) {
|
|
50149
50211
|
return inputs.map((input2) => resolveExistingPromptSourcePath(input2)).filter((path16) => path16 !== undefined);
|
|
@@ -50151,14 +50213,14 @@ function resolveExistingPromptSourcePaths(inputs) {
|
|
|
50151
50213
|
function loadContextFileFromDir(dir) {
|
|
50152
50214
|
const candidates = ["AGENTS.override.md", "AGENTS.md", "AGENTS.MD", "CLAUDE.md", "CLAUDE.MD"];
|
|
50153
50215
|
for (const filename of candidates) {
|
|
50154
|
-
const filePath =
|
|
50155
|
-
if (
|
|
50216
|
+
const filePath = join52(dir, filename);
|
|
50217
|
+
if (existsSync39(filePath)) {
|
|
50156
50218
|
try {
|
|
50157
50219
|
if (!statSync10(filePath).isFile())
|
|
50158
50220
|
continue;
|
|
50159
50221
|
return {
|
|
50160
50222
|
path: filePath,
|
|
50161
|
-
content:
|
|
50223
|
+
content: readFileSync27(filePath, "utf-8")
|
|
50162
50224
|
};
|
|
50163
50225
|
} catch (error) {
|
|
50164
50226
|
console.error(chalk4.yellow(`Warning: Could not read ${filePath}: ${error}`));
|
|
@@ -50167,7 +50229,7 @@ function loadContextFileFromDir(dir) {
|
|
|
50167
50229
|
}
|
|
50168
50230
|
return null;
|
|
50169
50231
|
}
|
|
50170
|
-
function getAncestorDirectories(startDir, parentOf =
|
|
50232
|
+
function getAncestorDirectories(startDir, parentOf = dirname30) {
|
|
50171
50233
|
const directories = [];
|
|
50172
50234
|
let currentDir = startDir;
|
|
50173
50235
|
while (true) {
|
|
@@ -50198,10 +50260,10 @@ function findShadowedContextFile(cwd) {
|
|
|
50198
50260
|
return;
|
|
50199
50261
|
const commonGitDir = realPath(gitPaths.commonGitDir);
|
|
50200
50262
|
const worktreeRoot = realPath(gitPaths.repoDir);
|
|
50201
|
-
const mainRepoRoot =
|
|
50263
|
+
const mainRepoRoot = dirname30(commonGitDir);
|
|
50202
50264
|
if (!isDescendantOf(mainRepoRoot, worktreeRoot))
|
|
50203
50265
|
return;
|
|
50204
|
-
if (!samePath(realPath(
|
|
50266
|
+
if (!samePath(realPath(join52(mainRepoRoot, ".git")), commonGitDir))
|
|
50205
50267
|
return;
|
|
50206
50268
|
const worktreeContextFile = loadContextFileFromDir(worktreeRoot);
|
|
50207
50269
|
if (!worktreeContextFile)
|
|
@@ -50210,7 +50272,7 @@ function findShadowedContextFile(cwd) {
|
|
|
50210
50272
|
const mainRepoContextFile = loadContextFileFromDir(mainRepoRoot);
|
|
50211
50273
|
return mainRepoContextFile ? realPath(mainRepoContextFile.path) : undefined;
|
|
50212
50274
|
}
|
|
50213
|
-
return realPath(
|
|
50275
|
+
return realPath(join52(mainRepoRoot, basename14(worktreeContextFile.path)));
|
|
50214
50276
|
}
|
|
50215
50277
|
function loadProjectContextFiles(options) {
|
|
50216
50278
|
const resolvedCwd = resolvePath(options.cwd);
|
|
@@ -50249,7 +50311,7 @@ var init_resource_loader_context_files = __esm(() => {
|
|
|
50249
50311
|
|
|
50250
50312
|
// src/core/prompt-templates-async.ts
|
|
50251
50313
|
import { access as access5, readdir as readdir4, readFile as readFile5, stat as stat6 } from "node:fs/promises";
|
|
50252
|
-
import { basename as basename15, dirname as
|
|
50314
|
+
import { basename as basename15, dirname as dirname31, join as join53, resolve as resolve18, sep as sep14 } from "node:path";
|
|
50253
50315
|
async function exists4(path16) {
|
|
50254
50316
|
try {
|
|
50255
50317
|
await access5(path16);
|
|
@@ -50291,7 +50353,7 @@ async function loadTemplatesFromDir(dir, getSourceInfo) {
|
|
|
50291
50353
|
const entries = await readdir4(dir, { withFileTypes: true });
|
|
50292
50354
|
for (const entry of entries) {
|
|
50293
50355
|
await yieldToEventLoopIfSlow(startedAt, YIELD_AFTER_MS);
|
|
50294
|
-
const fullPath =
|
|
50356
|
+
const fullPath = join53(dir, entry.name);
|
|
50295
50357
|
let isFile = entry.isFile();
|
|
50296
50358
|
if (entry.isSymbolicLink()) {
|
|
50297
50359
|
try {
|
|
@@ -50315,7 +50377,7 @@ async function loadPromptTemplatesAsync(options) {
|
|
|
50315
50377
|
const promptPaths = options.promptPaths ?? [];
|
|
50316
50378
|
const includeDefaults = options.includeDefaults ?? true;
|
|
50317
50379
|
const templates = [];
|
|
50318
|
-
const globalPromptsDir =
|
|
50380
|
+
const globalPromptsDir = join53(resolvedAgentDir, "prompts");
|
|
50319
50381
|
const projectPromptsDir = resolve18(resolvedCwd, CONFIG_DIR_NAME, "prompts");
|
|
50320
50382
|
const isUnderPath = (target, root) => {
|
|
50321
50383
|
const normalizedRoot = resolve18(root);
|
|
@@ -50335,7 +50397,7 @@ async function loadPromptTemplatesAsync(options) {
|
|
|
50335
50397
|
const stats = await stat6(resolvedPath);
|
|
50336
50398
|
return createSyntheticSourceInfo(resolvedPath, {
|
|
50337
50399
|
source: "local",
|
|
50338
|
-
baseDir: stats.isDirectory() ? resolvedPath :
|
|
50400
|
+
baseDir: stats.isDirectory() ? resolvedPath : dirname31(resolvedPath)
|
|
50339
50401
|
});
|
|
50340
50402
|
};
|
|
50341
50403
|
if (includeDefaults) {
|
|
@@ -50401,7 +50463,7 @@ var init_resource_loader_paths = __esm(() => {
|
|
|
50401
50463
|
|
|
50402
50464
|
// src/core/resource-loader-source-info.ts
|
|
50403
50465
|
import { statSync as statSync11 } from "node:fs";
|
|
50404
|
-
import { join as
|
|
50466
|
+
import { join as join54, resolve as resolve19, sep as sep15 } from "node:path";
|
|
50405
50467
|
function applyExtensionSourceInfo(loader, extensions, metadataByPath) {
|
|
50406
50468
|
for (const extension of extensions) {
|
|
50407
50469
|
const sourceInfo = findSourceInfoForPath(loader, extension.path, undefined, metadataByPath) ?? getDefaultSourceInfoForPath(loader, extension.path);
|
|
@@ -50459,16 +50521,16 @@ function getDefaultSourceInfoForPath(loader, filePath) {
|
|
|
50459
50521
|
}
|
|
50460
50522
|
const normalizedPath = resolve19(filePath);
|
|
50461
50523
|
const agentRoots = getLoaderAgentDirs(state.agentDir).flatMap((agentDir) => [
|
|
50462
|
-
|
|
50463
|
-
|
|
50464
|
-
|
|
50465
|
-
|
|
50524
|
+
join54(agentDir, "skills"),
|
|
50525
|
+
join54(agentDir, "prompts"),
|
|
50526
|
+
join54(agentDir, "themes"),
|
|
50527
|
+
join54(agentDir, "extensions")
|
|
50466
50528
|
]);
|
|
50467
50529
|
const projectRoots = getProjectConfigDirs(state.cwd).flatMap((configDir) => [
|
|
50468
|
-
|
|
50469
|
-
|
|
50470
|
-
|
|
50471
|
-
|
|
50530
|
+
join54(configDir, "skills"),
|
|
50531
|
+
join54(configDir, "prompts"),
|
|
50532
|
+
join54(configDir, "themes"),
|
|
50533
|
+
join54(configDir, "extensions")
|
|
50472
50534
|
]);
|
|
50473
50535
|
for (const root of agentRoots) {
|
|
50474
50536
|
if (isUnderPath(normalizedPath, root)) {
|
|
@@ -50503,7 +50565,7 @@ var init_resource_loader_source_info = __esm(() => {
|
|
|
50503
50565
|
|
|
50504
50566
|
// src/core/skills-async.ts
|
|
50505
50567
|
import { access as access6, readdir as readdir5, readFile as readFile6, stat as stat7 } from "node:fs/promises";
|
|
50506
|
-
import { basename as basename16, dirname as
|
|
50568
|
+
import { basename as basename16, dirname as dirname32, join as join55, relative as relative12, resolve as resolve20, sep as sep16 } from "node:path";
|
|
50507
50569
|
import ignore3 from "ignore";
|
|
50508
50570
|
async function exists5(path16) {
|
|
50509
50571
|
try {
|
|
@@ -50537,7 +50599,7 @@ async function addIgnoreRules3(ig, dir, rootDir) {
|
|
|
50537
50599
|
const relativeDir = relative12(rootDir, dir);
|
|
50538
50600
|
const prefix = relativeDir ? `${toPosixPath6(relativeDir)}/` : "";
|
|
50539
50601
|
for (const filename of IGNORE_FILE_NAMES3) {
|
|
50540
|
-
const ignorePath =
|
|
50602
|
+
const ignorePath = join55(dir, filename);
|
|
50541
50603
|
try {
|
|
50542
50604
|
const content = await readFile6(ignorePath, "utf-8");
|
|
50543
50605
|
const patterns = content.split(/\r?\n/).map((line) => prefixIgnorePattern3(line, prefix)).filter((line) => Boolean(line));
|
|
@@ -50583,7 +50645,7 @@ async function loadSkillFromFile2(filePath, source) {
|
|
|
50583
50645
|
try {
|
|
50584
50646
|
const rawContent = await readFile6(filePath, "utf-8");
|
|
50585
50647
|
const { frontmatter } = parseFrontmatter(rawContent);
|
|
50586
|
-
const skillDir =
|
|
50648
|
+
const skillDir = dirname32(filePath);
|
|
50587
50649
|
for (const error of validateDescription2(frontmatter.description))
|
|
50588
50650
|
diagnostics.push({ type: "warning", message: error, path: filePath });
|
|
50589
50651
|
const name = frontmatter.name || basename16(skillDir);
|
|
@@ -50622,7 +50684,7 @@ async function loadSkillsFromDirInternal2(dir, source, includeRootFiles, ignoreM
|
|
|
50622
50684
|
for (const entry of entries) {
|
|
50623
50685
|
if (entry.name !== "SKILL.md")
|
|
50624
50686
|
continue;
|
|
50625
|
-
const fullPath =
|
|
50687
|
+
const fullPath = join55(dir, entry.name);
|
|
50626
50688
|
let isFile = entry.isFile();
|
|
50627
50689
|
if (entry.isSymbolicLink()) {
|
|
50628
50690
|
try {
|
|
@@ -50644,7 +50706,7 @@ async function loadSkillsFromDirInternal2(dir, source, includeRootFiles, ignoreM
|
|
|
50644
50706
|
await yieldToEventLoopIfSlow(startedAt, YIELD_AFTER_MS2);
|
|
50645
50707
|
if (entry.name.startsWith(".") || entry.name === "node_modules")
|
|
50646
50708
|
continue;
|
|
50647
|
-
const fullPath =
|
|
50709
|
+
const fullPath = join55(dir, entry.name);
|
|
50648
50710
|
let isDirectory = entry.isDirectory();
|
|
50649
50711
|
let isFile = entry.isFile();
|
|
50650
50712
|
if (entry.isSymbolicLink()) {
|
|
@@ -50684,7 +50746,7 @@ async function loadSkillsAsync(options) {
|
|
|
50684
50746
|
const realPathSet = new Set;
|
|
50685
50747
|
const allDiagnostics = [];
|
|
50686
50748
|
const collisionDiagnostics = [];
|
|
50687
|
-
const userSkillsDir =
|
|
50749
|
+
const userSkillsDir = join55(resolvedAgentDir, "skills");
|
|
50688
50750
|
const projectSkillsDir = resolve20(resolvedCwd, CONFIG_DIR_NAME, "skills");
|
|
50689
50751
|
const addSkills = (result) => {
|
|
50690
50752
|
allDiagnostics.push(...result.diagnostics);
|
|
@@ -50773,7 +50835,7 @@ var init_skills_async = __esm(() => {
|
|
|
50773
50835
|
|
|
50774
50836
|
// src/core/resource-loader-assets.ts
|
|
50775
50837
|
import { access as access7, readdir as readdir6, readFile as readFile7, stat as stat8 } from "node:fs/promises";
|
|
50776
|
-
import { join as
|
|
50838
|
+
import { join as join56 } from "node:path";
|
|
50777
50839
|
async function existsAsync(path16) {
|
|
50778
50840
|
try {
|
|
50779
50841
|
await access7(path16);
|
|
@@ -50861,7 +50923,7 @@ async function loadThemesAsync(loader, paths, includeDefaults = true) {
|
|
|
50861
50923
|
const diagnostics = [];
|
|
50862
50924
|
if (includeDefaults) {
|
|
50863
50925
|
for (const dir of [
|
|
50864
|
-
...getLoaderAgentDirs(state.agentDir).map((agentDir) =>
|
|
50926
|
+
...getLoaderAgentDirs(state.agentDir).map((agentDir) => join56(agentDir, "themes")),
|
|
50865
50927
|
...getProjectThemeDirs(state.cwd)
|
|
50866
50928
|
]) {
|
|
50867
50929
|
await loadThemesFromDirAsync(dir, themes, diagnostics);
|
|
@@ -50891,7 +50953,7 @@ async function loadThemesAsync(loader, paths, includeDefaults = true) {
|
|
|
50891
50953
|
return { themes, diagnostics };
|
|
50892
50954
|
}
|
|
50893
50955
|
function getProjectThemeDirs(cwd) {
|
|
50894
|
-
return getProjectConfigDirs(cwd).map((configDir) =>
|
|
50956
|
+
return getProjectConfigDirs(cwd).map((configDir) => join56(configDir, "themes"));
|
|
50895
50957
|
}
|
|
50896
50958
|
async function loadThemesFromDirAsync(dir, themes, diagnostics) {
|
|
50897
50959
|
if (!await existsAsync(dir))
|
|
@@ -50904,13 +50966,13 @@ async function loadThemesFromDirAsync(dir, themes, diagnostics) {
|
|
|
50904
50966
|
let isFile = entry.isFile();
|
|
50905
50967
|
if (entry.isSymbolicLink()) {
|
|
50906
50968
|
try {
|
|
50907
|
-
isFile = (await stat8(
|
|
50969
|
+
isFile = (await stat8(join56(dir, entry.name))).isFile();
|
|
50908
50970
|
} catch {
|
|
50909
50971
|
continue;
|
|
50910
50972
|
}
|
|
50911
50973
|
}
|
|
50912
50974
|
if (isFile && entry.name.endsWith(".json"))
|
|
50913
|
-
await loadThemeFromFileAsync(
|
|
50975
|
+
await loadThemeFromFileAsync(join56(dir, entry.name), themes, diagnostics);
|
|
50914
50976
|
}
|
|
50915
50977
|
} catch (error) {
|
|
50916
50978
|
const message = error instanceof Error ? error.message : "failed to read theme directory";
|
|
@@ -51145,25 +51207,25 @@ var init_resource_loader_package_resources = __esm(() => {
|
|
|
51145
51207
|
});
|
|
51146
51208
|
|
|
51147
51209
|
// src/core/resource-loader-discovery.ts
|
|
51148
|
-
import { existsSync as
|
|
51149
|
-
import { join as
|
|
51210
|
+
import { existsSync as existsSync40 } from "node:fs";
|
|
51211
|
+
import { join as join57 } from "node:path";
|
|
51150
51212
|
function discoverSystemPromptFile(loader) {
|
|
51151
51213
|
const state = resourceInternals(loader);
|
|
51152
|
-
const projectCandidates = state.settingsManager.isProjectTrusted() ? getProjectConfigDirs(state.cwd).map((configDir) =>
|
|
51214
|
+
const projectCandidates = state.settingsManager.isProjectTrusted() ? getProjectConfigDirs(state.cwd).map((configDir) => join57(configDir, "SYSTEM.md")) : [];
|
|
51153
51215
|
const candidates = [
|
|
51154
51216
|
...projectCandidates,
|
|
51155
|
-
...getLoaderAgentDirs(state.agentDir).map((agentDir) =>
|
|
51217
|
+
...getLoaderAgentDirs(state.agentDir).map((agentDir) => join57(agentDir, "SYSTEM.md"))
|
|
51156
51218
|
];
|
|
51157
|
-
return candidates.find((candidate) =>
|
|
51219
|
+
return candidates.find((candidate) => existsSync40(candidate));
|
|
51158
51220
|
}
|
|
51159
51221
|
function discoverAppendSystemPromptFile(loader) {
|
|
51160
51222
|
const state = resourceInternals(loader);
|
|
51161
|
-
const projectCandidates = state.settingsManager.isProjectTrusted() ? getProjectConfigDirs(state.cwd).map((configDir) =>
|
|
51223
|
+
const projectCandidates = state.settingsManager.isProjectTrusted() ? getProjectConfigDirs(state.cwd).map((configDir) => join57(configDir, "APPEND_SYSTEM.md")) : [];
|
|
51162
51224
|
const candidates = [
|
|
51163
51225
|
...projectCandidates,
|
|
51164
|
-
...getLoaderAgentDirs(state.agentDir).map((agentDir) =>
|
|
51226
|
+
...getLoaderAgentDirs(state.agentDir).map((agentDir) => join57(agentDir, "APPEND_SYSTEM.md"))
|
|
51165
51227
|
];
|
|
51166
|
-
return candidates.find((candidate) =>
|
|
51228
|
+
return candidates.find((candidate) => existsSync40(candidate));
|
|
51167
51229
|
}
|
|
51168
51230
|
var init_resource_loader_discovery = __esm(() => {
|
|
51169
51231
|
init_config();
|
|
@@ -51398,8 +51460,8 @@ var init_resource_loader_extensions = __esm(() => {
|
|
|
51398
51460
|
});
|
|
51399
51461
|
|
|
51400
51462
|
// src/core/resource-loader-reload.ts
|
|
51401
|
-
import { existsSync as
|
|
51402
|
-
import { join as
|
|
51463
|
+
import { existsSync as existsSync41, statSync as statSync12 } from "node:fs";
|
|
51464
|
+
import { join as join58 } from "node:path";
|
|
51403
51465
|
function getEnabledResources(resources, metadataByPath) {
|
|
51404
51466
|
for (const r of resources) {
|
|
51405
51467
|
if (!metadataByPath.has(r.path)) {
|
|
@@ -51423,8 +51485,8 @@ function mapSkillPath(resource, metadataByPath) {
|
|
|
51423
51485
|
} catch {
|
|
51424
51486
|
return resource.path;
|
|
51425
51487
|
}
|
|
51426
|
-
const skillFile =
|
|
51427
|
-
if (
|
|
51488
|
+
const skillFile = join58(resource.path, "SKILL.md");
|
|
51489
|
+
if (existsSync41(skillFile)) {
|
|
51428
51490
|
if (!metadataByPath.has(skillFile)) {
|
|
51429
51491
|
metadataByPath.set(skillFile, resource.metadata);
|
|
51430
51492
|
}
|
|
@@ -51559,7 +51621,7 @@ async function reloadDefaultResourceLoader(loader, options) {
|
|
|
51559
51621
|
for (const p of state.additionalExtensionPaths) {
|
|
51560
51622
|
if (isLocalPath(p)) {
|
|
51561
51623
|
const resolved = resolveResourcePath(state.cwd, p);
|
|
51562
|
-
if (!
|
|
51624
|
+
if (!existsSync41(resolved)) {
|
|
51563
51625
|
extensionsResult.errors.push({ path: resolved, error: `Extension path does not exist: ${resolved}` });
|
|
51564
51626
|
}
|
|
51565
51627
|
}
|
|
@@ -51577,7 +51639,7 @@ async function reloadDefaultResourceLoader(loader, options) {
|
|
|
51577
51639
|
for (const p of state.additionalSkillPaths) {
|
|
51578
51640
|
if (isLocalPath(p)) {
|
|
51579
51641
|
const resolved = resolveResourcePath(state.cwd, p);
|
|
51580
|
-
if (!
|
|
51642
|
+
if (!existsSync41(resolved) && !state.skillDiagnostics.some((d) => d.path === resolved)) {
|
|
51581
51643
|
state.skillDiagnostics.push({ type: "error", message: "Skill path does not exist", path: resolved });
|
|
51582
51644
|
}
|
|
51583
51645
|
}
|
|
@@ -51592,7 +51654,7 @@ async function reloadDefaultResourceLoader(loader, options) {
|
|
|
51592
51654
|
for (const p of state.additionalPromptTemplatePaths) {
|
|
51593
51655
|
if (isLocalPath(p)) {
|
|
51594
51656
|
const resolved = resolveResourcePath(state.cwd, p);
|
|
51595
|
-
if (!
|
|
51657
|
+
if (!existsSync41(resolved) && !state.promptDiagnostics.some((d) => d.path === resolved)) {
|
|
51596
51658
|
state.promptDiagnostics.push({
|
|
51597
51659
|
type: "error",
|
|
51598
51660
|
message: "Prompt template path does not exist",
|
|
@@ -51610,7 +51672,7 @@ async function reloadDefaultResourceLoader(loader, options) {
|
|
|
51610
51672
|
await yieldToEventLoopIfSlow(themesStartedAt);
|
|
51611
51673
|
for (const p of state.additionalThemePaths) {
|
|
51612
51674
|
const resolved = resolveResourcePath(state.cwd, p);
|
|
51613
|
-
if (!
|
|
51675
|
+
if (!existsSync41(resolved) && !state.themeDiagnostics.some((d) => d.path === resolved)) {
|
|
51614
51676
|
state.themeDiagnostics.push({ type: "error", message: "Theme path does not exist", path: resolved });
|
|
51615
51677
|
}
|
|
51616
51678
|
}
|
|
@@ -51678,8 +51740,8 @@ function deepMergeSettings(base, overrides) {
|
|
|
51678
51740
|
}
|
|
51679
51741
|
|
|
51680
51742
|
// src/core/settings-storage.ts
|
|
51681
|
-
import { existsSync as
|
|
51682
|
-
import { dirname as
|
|
51743
|
+
import { existsSync as existsSync42, mkdirSync as mkdirSync13, readFileSync as readFileSync28, writeFileSync as writeFileSync14 } from "fs";
|
|
51744
|
+
import { dirname as dirname33, join as join59 } from "path";
|
|
51683
51745
|
import lockfile3 from "proper-lockfile";
|
|
51684
51746
|
|
|
51685
51747
|
class FileSettingsStorage {
|
|
@@ -51690,18 +51752,18 @@ class FileSettingsStorage {
|
|
|
51690
51752
|
constructor(cwd, agentDir, options) {
|
|
51691
51753
|
const resolvedCwd = resolvePath(cwd);
|
|
51692
51754
|
const resolvedAgentDir = resolvePath(agentDir);
|
|
51693
|
-
this.globalSettingsPath =
|
|
51694
|
-
this.projectSettingsPath =
|
|
51755
|
+
this.globalSettingsPath = join59(resolvedAgentDir, "settings.json");
|
|
51756
|
+
this.projectSettingsPath = join59(resolvedCwd, CONFIG_DIR_NAME, "settings.json");
|
|
51695
51757
|
this.globalReadPaths = (options?.globalReadPaths ?? [this.globalSettingsPath]).map((path16) => normalizePath(path16));
|
|
51696
51758
|
this.projectReadPaths = (options?.projectReadPaths ?? [this.projectSettingsPath]).map((path16) => normalizePath(path16));
|
|
51697
51759
|
}
|
|
51698
51760
|
getFieldOrigin(scope, field2) {
|
|
51699
51761
|
const readPaths = scope === "global" ? this.globalReadPaths : this.projectReadPaths;
|
|
51700
51762
|
for (const [index, readPath] of readPaths.entries()) {
|
|
51701
|
-
if (!
|
|
51763
|
+
if (!existsSync42(readPath))
|
|
51702
51764
|
continue;
|
|
51703
51765
|
try {
|
|
51704
|
-
const parsed = parseJsonFileContent(
|
|
51766
|
+
const parsed = parseJsonFileContent(readFileSync28(readPath, "utf-8"));
|
|
51705
51767
|
if (Object.hasOwn(parsed, field2)) {
|
|
51706
51768
|
return index === 0 ? "primary" : "legacy";
|
|
51707
51769
|
}
|
|
@@ -51735,9 +51797,9 @@ class FileSettingsStorage {
|
|
|
51735
51797
|
let found = false;
|
|
51736
51798
|
for (let i = readPaths.length - 1;i >= 0; i--) {
|
|
51737
51799
|
const readPath = readPaths[i];
|
|
51738
|
-
if (!
|
|
51800
|
+
if (!existsSync42(readPath))
|
|
51739
51801
|
continue;
|
|
51740
|
-
const parsed = parseJsonFileContent(
|
|
51802
|
+
const parsed = parseJsonFileContent(readFileSync28(readPath, "utf-8"));
|
|
51741
51803
|
merged = deepMergeSettings(merged, parsed);
|
|
51742
51804
|
found = true;
|
|
51743
51805
|
}
|
|
@@ -51746,21 +51808,21 @@ class FileSettingsStorage {
|
|
|
51746
51808
|
withLock(scope, fn) {
|
|
51747
51809
|
const path16 = scope === "global" ? this.globalSettingsPath : this.projectSettingsPath;
|
|
51748
51810
|
const readPaths = scope === "global" ? this.globalReadPaths : this.projectReadPaths;
|
|
51749
|
-
const dir =
|
|
51811
|
+
const dir = dirname33(path16);
|
|
51750
51812
|
let release;
|
|
51751
51813
|
try {
|
|
51752
|
-
const fileExists2 =
|
|
51814
|
+
const fileExists2 = existsSync42(path16);
|
|
51753
51815
|
if (fileExists2) {
|
|
51754
51816
|
release = this.acquireLockSyncWithRetry(path16);
|
|
51755
51817
|
}
|
|
51756
51818
|
const current = this.readMergedSettings(readPaths);
|
|
51757
51819
|
const next = fn(current);
|
|
51758
51820
|
if (next !== undefined) {
|
|
51759
|
-
if (!
|
|
51821
|
+
if (!existsSync42(dir)) {
|
|
51760
51822
|
mkdirSync13(dir, { recursive: true });
|
|
51761
51823
|
}
|
|
51762
51824
|
if (!release) {
|
|
51763
|
-
if (!
|
|
51825
|
+
if (!existsSync42(path16))
|
|
51764
51826
|
writeFileSync14(path16, "{}", "utf-8");
|
|
51765
51827
|
release = this.acquireLockSyncWithRetry(path16);
|
|
51766
51828
|
}
|
|
@@ -51800,7 +51862,7 @@ var init_settings_storage = __esm(() => {
|
|
|
51800
51862
|
});
|
|
51801
51863
|
|
|
51802
51864
|
// src/core/settings-manager-core.ts
|
|
51803
|
-
import { join as
|
|
51865
|
+
import { join as join60 } from "path";
|
|
51804
51866
|
|
|
51805
51867
|
class SettingsManager {
|
|
51806
51868
|
storage;
|
|
@@ -51838,7 +51900,7 @@ class SettingsManager {
|
|
|
51838
51900
|
}
|
|
51839
51901
|
static create(cwd, agentDir = getAgentDir(), options = {}) {
|
|
51840
51902
|
const storage = new FileSettingsStorage(cwd, agentDir, {
|
|
51841
|
-
globalReadPaths: agentDir === getAgentDir() ? getAgentConfigPaths("settings.json") : [
|
|
51903
|
+
globalReadPaths: agentDir === getAgentDir() ? getAgentConfigPaths("settings.json") : [join60(agentDir, "settings.json")],
|
|
51842
51904
|
projectReadPaths: getProjectConfigPaths(cwd, "settings.json")
|
|
51843
51905
|
});
|
|
51844
51906
|
return SettingsManager.fromStorage(storage, options);
|
|
@@ -54034,14 +54096,14 @@ var init_agent_session_runtime_auth = __esm(() => {
|
|
|
54034
54096
|
});
|
|
54035
54097
|
|
|
54036
54098
|
// src/core/session-cwd.ts
|
|
54037
|
-
import { existsSync as
|
|
54099
|
+
import { existsSync as existsSync43 } from "node:fs";
|
|
54038
54100
|
function getMissingSessionCwdIssue(sessionManager, fallbackCwd) {
|
|
54039
54101
|
const sessionFile = sessionManager.getSessionFile();
|
|
54040
54102
|
if (!sessionFile) {
|
|
54041
54103
|
return;
|
|
54042
54104
|
}
|
|
54043
54105
|
const sessionCwd = sessionManager.getCwd();
|
|
54044
|
-
if (!sessionCwd ||
|
|
54106
|
+
if (!sessionCwd || existsSync43(sessionCwd)) {
|
|
54045
54107
|
return;
|
|
54046
54108
|
}
|
|
54047
54109
|
return {
|
|
@@ -54082,7 +54144,7 @@ var init_session_cwd = __esm(() => {
|
|
|
54082
54144
|
});
|
|
54083
54145
|
|
|
54084
54146
|
// src/core/agent-session-services.ts
|
|
54085
|
-
import { join as
|
|
54147
|
+
import { join as join61 } from "node:path";
|
|
54086
54148
|
function applyExtensionFlagValues(resourceLoader, extensionFlagValues) {
|
|
54087
54149
|
if (!extensionFlagValues) {
|
|
54088
54150
|
return [];
|
|
@@ -54132,8 +54194,8 @@ async function createAgentSessionServices(options) {
|
|
|
54132
54194
|
const agentDir = options.agentDir ? resolvePath(options.agentDir) : getAgentDir();
|
|
54133
54195
|
const modelRuntimeSpan = startTimingSpan("createAgentSessionServices.modelRuntime");
|
|
54134
54196
|
const modelRuntime = options.modelRuntime ?? await ModelRuntime.create({
|
|
54135
|
-
authPath:
|
|
54136
|
-
modelsPath:
|
|
54197
|
+
authPath: join61(agentDir, "auth.json"),
|
|
54198
|
+
modelsPath: join61(agentDir, "models.json")
|
|
54137
54199
|
});
|
|
54138
54200
|
endTimingSpan(modelRuntimeSpan);
|
|
54139
54201
|
const settingsSpan = startTimingSpan("createAgentSessionServices.settingsManager");
|
|
@@ -54207,8 +54269,8 @@ var init_agent_session_services = __esm(() => {
|
|
|
54207
54269
|
});
|
|
54208
54270
|
|
|
54209
54271
|
// src/core/agent-session-runtime.ts
|
|
54210
|
-
import { copyFileSync, existsSync as
|
|
54211
|
-
import { basename as basename17, join as
|
|
54272
|
+
import { copyFileSync, existsSync as existsSync44, mkdirSync as mkdirSync14 } from "node:fs";
|
|
54273
|
+
import { basename as basename17, join as join62, resolve as resolve21 } from "node:path";
|
|
54212
54274
|
import { modelsAreEqual as modelsAreEqual5 } from "@bastani/pi-ai/compat";
|
|
54213
54275
|
function extractUserMessageText(content) {
|
|
54214
54276
|
if (typeof content === "string") {
|
|
@@ -54424,7 +54486,7 @@ class AgentSessionRuntime {
|
|
|
54424
54486
|
await this.finishSessionReplacement(options?.withSession);
|
|
54425
54487
|
return { cancelled: false, selectedText };
|
|
54426
54488
|
}
|
|
54427
|
-
if (!
|
|
54489
|
+
if (!existsSync44(currentSessionFile)) {
|
|
54428
54490
|
throw new Error("This session has not been saved yet. Wait for the first assistant response before cloning or forking it.");
|
|
54429
54491
|
}
|
|
54430
54492
|
const sessionManager2 = SessionManager.open(currentSessionFile, sessionDir);
|
|
@@ -54460,14 +54522,14 @@ class AgentSessionRuntime {
|
|
|
54460
54522
|
}
|
|
54461
54523
|
async importFromJsonl(inputPath, cwdOverride) {
|
|
54462
54524
|
const resolvedPath = resolvePath(inputPath);
|
|
54463
|
-
if (!
|
|
54525
|
+
if (!existsSync44(resolvedPath)) {
|
|
54464
54526
|
throw new SessionImportFileNotFoundError(resolvedPath);
|
|
54465
54527
|
}
|
|
54466
54528
|
const sessionDir = this.session.sessionManager.getSessionDir();
|
|
54467
|
-
if (!
|
|
54529
|
+
if (!existsSync44(sessionDir)) {
|
|
54468
54530
|
mkdirSync14(sessionDir, { recursive: true });
|
|
54469
54531
|
}
|
|
54470
|
-
const destinationPath =
|
|
54532
|
+
const destinationPath = join62(sessionDir, basename17(resolvedPath));
|
|
54471
54533
|
const beforeResult = await this.emitBeforeSwitch("resume", destinationPath);
|
|
54472
54534
|
if (beforeResult.cancelled) {
|
|
54473
54535
|
return beforeResult;
|
|
@@ -54527,7 +54589,7 @@ var init_sdk_exports = __esm(() => {
|
|
|
54527
54589
|
});
|
|
54528
54590
|
|
|
54529
54591
|
// src/core/sdk.ts
|
|
54530
|
-
import { join as
|
|
54592
|
+
import { join as join63 } from "node:path";
|
|
54531
54593
|
import {
|
|
54532
54594
|
clampThinkingLevel as clampThinkingLevel4,
|
|
54533
54595
|
streamSimple as streamSimple2
|
|
@@ -54556,8 +54618,8 @@ async function createAgentSession(options = {}) {
|
|
|
54556
54618
|
const cwd = resolvePath(options.cwd ?? options.sessionManager?.getCwd() ?? process.cwd());
|
|
54557
54619
|
const agentDir = options.agentDir ? resolvePath(options.agentDir) : getDefaultAgentDir();
|
|
54558
54620
|
let resourceLoader = options.resourceLoader;
|
|
54559
|
-
const authPath = options.agentDir ?
|
|
54560
|
-
const modelsPath = options.agentDir ?
|
|
54621
|
+
const authPath = options.agentDir ? join63(agentDir, "auth.json") : undefined;
|
|
54622
|
+
const modelsPath = options.agentDir ? join63(agentDir, "models.json") : undefined;
|
|
54561
54623
|
const modelRuntime = options.modelRuntime ?? await ModelRuntime.create({ authPath, modelsPath });
|
|
54562
54624
|
await modelRuntime.refresh({ allowNetwork: false });
|
|
54563
54625
|
const settingsManager = options.settingsManager ?? SettingsManager.create(cwd, agentDir);
|
|
@@ -55375,7 +55437,7 @@ var init_list_models = __esm(() => {
|
|
|
55375
55437
|
});
|
|
55376
55438
|
|
|
55377
55439
|
// src/cli/startup-ui.ts
|
|
55378
|
-
import { existsSync as
|
|
55440
|
+
import { existsSync as existsSync45 } from "node:fs";
|
|
55379
55441
|
import { ProcessTerminal, setKeybindings, TuiMainScreen } from "@earendil-works/pi-tui";
|
|
55380
55442
|
function createStartupTui(settingsManager) {
|
|
55381
55443
|
initTheme(settingsManager.getTheme());
|
|
@@ -55393,7 +55455,7 @@ async function detectStartupTheme(ui) {
|
|
|
55393
55455
|
return detectTerminalThemeForAuto({ ui, timeoutMs: 100 });
|
|
55394
55456
|
}
|
|
55395
55457
|
function shouldRunFirstTimeSetup(settingsPath = getSettingsPath()) {
|
|
55396
|
-
return !getEnvValue(ENV_AGENT_DIR) && !
|
|
55458
|
+
return !getEnvValue(ENV_AGENT_DIR) && !existsSync45(settingsPath);
|
|
55397
55459
|
}
|
|
55398
55460
|
async function showFirstTimeSetup(settingsManager) {
|
|
55399
55461
|
const ui = createStartupTui(settingsManager);
|
|
@@ -55894,7 +55956,7 @@ class LlamaClient {
|
|
|
55894
55956
|
// src/extensions/llama/huggingface.ts
|
|
55895
55957
|
import { readFile as readFile8 } from "node:fs/promises";
|
|
55896
55958
|
import { homedir as homedir8 } from "node:os";
|
|
55897
|
-
import { join as
|
|
55959
|
+
import { join as join64 } from "node:path";
|
|
55898
55960
|
function payloadError(payload, fallback) {
|
|
55899
55961
|
if (typeof payload !== "object" || payload === null)
|
|
55900
55962
|
return fallback;
|
|
@@ -55919,9 +55981,9 @@ async function findHuggingFaceToken(env = process.env) {
|
|
|
55919
55981
|
return fromEnvironment;
|
|
55920
55982
|
const paths = [
|
|
55921
55983
|
env.HF_TOKEN_PATH,
|
|
55922
|
-
env.HF_HOME ?
|
|
55923
|
-
env.XDG_CACHE_HOME ?
|
|
55924
|
-
|
|
55984
|
+
env.HF_HOME ? join64(env.HF_HOME, "token") : undefined,
|
|
55985
|
+
env.XDG_CACHE_HOME ? join64(env.XDG_CACHE_HOME, "huggingface", "token") : undefined,
|
|
55986
|
+
join64(homedir8(), ".cache", "huggingface", "token")
|
|
55925
55987
|
].filter((path16) => Boolean(path16));
|
|
55926
55988
|
for (const path16 of new Set(paths)) {
|
|
55927
55989
|
const token = await readToken(path16);
|
|
@@ -57530,8 +57592,8 @@ async function drainProcessStdio() {
|
|
|
57530
57592
|
var init_main_stdio = () => {};
|
|
57531
57593
|
|
|
57532
57594
|
// src/migrations-config-values.ts
|
|
57533
|
-
import { chmodSync as chmodSync5, existsSync as
|
|
57534
|
-
import { join as
|
|
57595
|
+
import { chmodSync as chmodSync5, existsSync as existsSync46, readFileSync as readFileSync29, writeFileSync as writeFileSync15 } from "fs";
|
|
57596
|
+
import { join as join65 } from "path";
|
|
57535
57597
|
function migrateLegacyEnvVarString(value) {
|
|
57536
57598
|
return isLegacyEnvVarNameConfigValue(value) && process.env[value] !== undefined ? `$${value}` : undefined;
|
|
57537
57599
|
}
|
|
@@ -57564,11 +57626,11 @@ function migrateHeadersConfig(headers, location, migrations) {
|
|
|
57564
57626
|
return migrated;
|
|
57565
57627
|
}
|
|
57566
57628
|
function migrateAuthJsonConfigValues(agentDir) {
|
|
57567
|
-
const authPath =
|
|
57568
|
-
if (!
|
|
57629
|
+
const authPath = join65(agentDir, "auth.json");
|
|
57630
|
+
if (!existsSync46(authPath))
|
|
57569
57631
|
return [];
|
|
57570
57632
|
try {
|
|
57571
|
-
const parsed = JSON.parse(
|
|
57633
|
+
const parsed = JSON.parse(readFileSync29(authPath, "utf-8"));
|
|
57572
57634
|
if (typeof parsed !== "object" || parsed === null || Array.isArray(parsed))
|
|
57573
57635
|
return [];
|
|
57574
57636
|
const authData = parsed;
|
|
@@ -57771,11 +57833,11 @@ function replaceMigratedJsonStringValues(content, migrations) {
|
|
|
57771
57833
|
return result;
|
|
57772
57834
|
}
|
|
57773
57835
|
function migrateModelsJsonConfigValues(agentDir) {
|
|
57774
|
-
const modelsPath =
|
|
57775
|
-
if (!
|
|
57836
|
+
const modelsPath = join65(agentDir, "models.json");
|
|
57837
|
+
if (!existsSync46(modelsPath))
|
|
57776
57838
|
return [];
|
|
57777
57839
|
try {
|
|
57778
|
-
const content =
|
|
57840
|
+
const content = readFileSync29(modelsPath, "utf-8");
|
|
57779
57841
|
const parsed = JSON.parse(stripJsonComments(content));
|
|
57780
57842
|
if (typeof parsed !== "object" || parsed === null || Array.isArray(parsed))
|
|
57781
57843
|
return [];
|
|
@@ -57825,20 +57887,20 @@ var init_migrations_config_values = __esm(() => {
|
|
|
57825
57887
|
|
|
57826
57888
|
// src/migrations.ts
|
|
57827
57889
|
import chalk12 from "chalk";
|
|
57828
|
-
import { existsSync as
|
|
57829
|
-
import { dirname as
|
|
57890
|
+
import { existsSync as existsSync47, mkdirSync as mkdirSync15, readdirSync as readdirSync10, readFileSync as readFileSync30, renameSync as renameSync5, rmSync as rmSync9, writeFileSync as writeFileSync16 } from "fs";
|
|
57891
|
+
import { dirname as dirname34, join as join66 } from "path";
|
|
57830
57892
|
function migrateAuthToAuthJson() {
|
|
57831
57893
|
const agentDir = getAgentDir();
|
|
57832
|
-
const authPath =
|
|
57833
|
-
const oauthPath =
|
|
57834
|
-
const settingsPath =
|
|
57835
|
-
if (
|
|
57894
|
+
const authPath = join66(agentDir, "auth.json");
|
|
57895
|
+
const oauthPath = join66(agentDir, "oauth.json");
|
|
57896
|
+
const settingsPath = join66(agentDir, "settings.json");
|
|
57897
|
+
if (existsSync47(authPath))
|
|
57836
57898
|
return [];
|
|
57837
57899
|
const migrated = {};
|
|
57838
57900
|
const providers = [];
|
|
57839
|
-
if (
|
|
57901
|
+
if (existsSync47(oauthPath)) {
|
|
57840
57902
|
try {
|
|
57841
|
-
const oauth = JSON.parse(
|
|
57903
|
+
const oauth = JSON.parse(readFileSync30(oauthPath, "utf-8"));
|
|
57842
57904
|
for (const [provider, cred] of Object.entries(oauth)) {
|
|
57843
57905
|
migrated[provider] = { type: "oauth", ...cred };
|
|
57844
57906
|
providers.push(provider);
|
|
@@ -57846,9 +57908,9 @@ function migrateAuthToAuthJson() {
|
|
|
57846
57908
|
renameSync5(oauthPath, `${oauthPath}.migrated`);
|
|
57847
57909
|
} catch {}
|
|
57848
57910
|
}
|
|
57849
|
-
if (
|
|
57911
|
+
if (existsSync47(settingsPath)) {
|
|
57850
57912
|
try {
|
|
57851
|
-
const content =
|
|
57913
|
+
const content = readFileSync30(settingsPath, "utf-8");
|
|
57852
57914
|
const settings = JSON.parse(content);
|
|
57853
57915
|
if (settings.apiKeys && typeof settings.apiKeys === "object") {
|
|
57854
57916
|
for (const [provider, key] of Object.entries(settings.apiKeys)) {
|
|
@@ -57863,7 +57925,7 @@ function migrateAuthToAuthJson() {
|
|
|
57863
57925
|
} catch {}
|
|
57864
57926
|
}
|
|
57865
57927
|
if (Object.keys(migrated).length > 0) {
|
|
57866
|
-
mkdirSync15(
|
|
57928
|
+
mkdirSync15(dirname34(authPath), { recursive: true });
|
|
57867
57929
|
writeFileSync16(authPath, JSON.stringify(migrated, null, 2), { mode: 384 });
|
|
57868
57930
|
}
|
|
57869
57931
|
return providers;
|
|
@@ -57871,7 +57933,7 @@ function migrateAuthToAuthJson() {
|
|
|
57871
57933
|
function getAgentDirsForConfigMigration() {
|
|
57872
57934
|
const dirs = new Set;
|
|
57873
57935
|
for (const path16 of [...getAgentConfigPaths("auth.json"), ...getAgentConfigPaths("models.json")]) {
|
|
57874
|
-
dirs.add(
|
|
57936
|
+
dirs.add(dirname34(path16));
|
|
57875
57937
|
}
|
|
57876
57938
|
return [...dirs];
|
|
57877
57939
|
}
|
|
@@ -57893,7 +57955,7 @@ function migrateSessionsFromAgentRoot() {
|
|
|
57893
57955
|
const agentDir = getAgentDir();
|
|
57894
57956
|
let files;
|
|
57895
57957
|
try {
|
|
57896
|
-
files = readdirSync10(agentDir).filter((f) => f.endsWith(".jsonl")).map((f) =>
|
|
57958
|
+
files = readdirSync10(agentDir).filter((f) => f.endsWith(".jsonl")).map((f) => join66(agentDir, f));
|
|
57897
57959
|
} catch {
|
|
57898
57960
|
return;
|
|
57899
57961
|
}
|
|
@@ -57901,7 +57963,7 @@ function migrateSessionsFromAgentRoot() {
|
|
|
57901
57963
|
return;
|
|
57902
57964
|
for (const file of files) {
|
|
57903
57965
|
try {
|
|
57904
|
-
const content =
|
|
57966
|
+
const content = readFileSync30(file, "utf8");
|
|
57905
57967
|
const firstLine = content.split(`
|
|
57906
57968
|
`)[0];
|
|
57907
57969
|
if (!firstLine?.trim())
|
|
@@ -57911,22 +57973,22 @@ function migrateSessionsFromAgentRoot() {
|
|
|
57911
57973
|
continue;
|
|
57912
57974
|
const cwd = header.cwd;
|
|
57913
57975
|
const safePath = `--${cwd.replace(/^[/\\]/, "").replace(/[/\\:]/g, "-")}--`;
|
|
57914
|
-
const correctDir =
|
|
57915
|
-
if (!
|
|
57976
|
+
const correctDir = join66(agentDir, "sessions", safePath);
|
|
57977
|
+
if (!existsSync47(correctDir)) {
|
|
57916
57978
|
mkdirSync15(correctDir, { recursive: true });
|
|
57917
57979
|
}
|
|
57918
57980
|
const fileName = file.split("/").pop() || file.split("\\").pop();
|
|
57919
|
-
const newPath =
|
|
57920
|
-
if (
|
|
57981
|
+
const newPath = join66(correctDir, fileName);
|
|
57982
|
+
if (existsSync47(newPath))
|
|
57921
57983
|
continue;
|
|
57922
57984
|
renameSync5(file, newPath);
|
|
57923
57985
|
} catch {}
|
|
57924
57986
|
}
|
|
57925
57987
|
}
|
|
57926
57988
|
function migrateCommandsToPrompts(baseDir, label) {
|
|
57927
|
-
const commandsDir =
|
|
57928
|
-
const promptsDir =
|
|
57929
|
-
if (
|
|
57989
|
+
const commandsDir = join66(baseDir, "commands");
|
|
57990
|
+
const promptsDir = join66(baseDir, "prompts");
|
|
57991
|
+
if (existsSync47(commandsDir) && !existsSync47(promptsDir)) {
|
|
57930
57992
|
try {
|
|
57931
57993
|
renameSync5(commandsDir, promptsDir);
|
|
57932
57994
|
console.log(chalk12.green(`Migrated ${label} commands/ → prompts/`));
|
|
@@ -57938,11 +58000,11 @@ function migrateCommandsToPrompts(baseDir, label) {
|
|
|
57938
58000
|
return false;
|
|
57939
58001
|
}
|
|
57940
58002
|
function migrateKeybindingsConfigFile() {
|
|
57941
|
-
const configPath =
|
|
57942
|
-
if (!
|
|
58003
|
+
const configPath = join66(getAgentDir(), "keybindings.json");
|
|
58004
|
+
if (!existsSync47(configPath))
|
|
57943
58005
|
return;
|
|
57944
58006
|
try {
|
|
57945
|
-
const parsed = JSON.parse(
|
|
58007
|
+
const parsed = JSON.parse(readFileSync30(configPath, "utf-8"));
|
|
57946
58008
|
if (typeof parsed !== "object" || parsed === null || Array.isArray(parsed)) {
|
|
57947
58009
|
return;
|
|
57948
58010
|
}
|
|
@@ -57955,20 +58017,20 @@ function migrateKeybindingsConfigFile() {
|
|
|
57955
58017
|
}
|
|
57956
58018
|
function migrateToolsToBin() {
|
|
57957
58019
|
const agentDir = getAgentDir();
|
|
57958
|
-
const toolsDir =
|
|
58020
|
+
const toolsDir = join66(agentDir, "tools");
|
|
57959
58021
|
const binDir = getBinDir();
|
|
57960
|
-
if (!
|
|
58022
|
+
if (!existsSync47(toolsDir))
|
|
57961
58023
|
return;
|
|
57962
58024
|
const binaries = ["fd", "rg", "fd.exe", "rg.exe"];
|
|
57963
58025
|
let movedAny = false;
|
|
57964
58026
|
for (const bin of binaries) {
|
|
57965
|
-
const oldPath =
|
|
57966
|
-
const newPath =
|
|
57967
|
-
if (
|
|
57968
|
-
if (!
|
|
58027
|
+
const oldPath = join66(toolsDir, bin);
|
|
58028
|
+
const newPath = join66(binDir, bin);
|
|
58029
|
+
if (existsSync47(oldPath)) {
|
|
58030
|
+
if (!existsSync47(binDir)) {
|
|
57969
58031
|
mkdirSync15(binDir, { recursive: true });
|
|
57970
58032
|
}
|
|
57971
|
-
if (!
|
|
58033
|
+
if (!existsSync47(newPath)) {
|
|
57972
58034
|
try {
|
|
57973
58035
|
renameSync5(oldPath, newPath);
|
|
57974
58036
|
movedAny = true;
|
|
@@ -57985,13 +58047,13 @@ function migrateToolsToBin() {
|
|
|
57985
58047
|
}
|
|
57986
58048
|
}
|
|
57987
58049
|
function checkDeprecatedExtensionDirs(baseDir, label) {
|
|
57988
|
-
const hooksDir =
|
|
57989
|
-
const toolsDir =
|
|
58050
|
+
const hooksDir = join66(baseDir, "hooks");
|
|
58051
|
+
const toolsDir = join66(baseDir, "tools");
|
|
57990
58052
|
const warnings = [];
|
|
57991
|
-
if (
|
|
58053
|
+
if (existsSync47(hooksDir)) {
|
|
57992
58054
|
warnings.push(`${label} hooks/ directory found. Hooks have been renamed to extensions.`);
|
|
57993
58055
|
}
|
|
57994
|
-
if (
|
|
58056
|
+
if (existsSync47(toolsDir)) {
|
|
57995
58057
|
try {
|
|
57996
58058
|
const entries = readdirSync10(toolsDir);
|
|
57997
58059
|
const customTools = entries.filter((e) => {
|
|
@@ -58007,7 +58069,7 @@ function checkDeprecatedExtensionDirs(baseDir, label) {
|
|
|
58007
58069
|
}
|
|
58008
58070
|
function migrateExtensionSystem(cwd, options) {
|
|
58009
58071
|
const agentDir = getAgentDir();
|
|
58010
|
-
const projectDir =
|
|
58072
|
+
const projectDir = join66(cwd, CONFIG_DIR_NAME);
|
|
58011
58073
|
migrateCommandsToPrompts(agentDir, "Global");
|
|
58012
58074
|
if (options?.projectTrusted !== false) {
|
|
58013
58075
|
migrateCommandsToPrompts(projectDir, "Project");
|
|
@@ -69194,30 +69256,30 @@ var init_print_mode = __esm(() => {
|
|
|
69194
69256
|
});
|
|
69195
69257
|
|
|
69196
69258
|
// src/modes/interactive-engine/protocol.ts
|
|
69197
|
-
function
|
|
69259
|
+
function isJsonValue2(value) {
|
|
69198
69260
|
if (value === null || typeof value !== "object")
|
|
69199
69261
|
return true;
|
|
69200
69262
|
if (Array.isArray(value))
|
|
69201
|
-
return value.every((item) =>
|
|
69202
|
-
return Object.values(value).every((item) => item !== undefined &&
|
|
69263
|
+
return value.every((item) => isJsonValue2(item));
|
|
69264
|
+
return Object.values(value).every((item) => item !== undefined && isJsonValue2(item));
|
|
69203
69265
|
}
|
|
69204
|
-
function
|
|
69266
|
+
function isJsonObject2(value) {
|
|
69205
69267
|
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
69206
69268
|
}
|
|
69207
69269
|
function isActivityKind(value) {
|
|
69208
69270
|
return typeof value === "string" && ACTIVITY_KINDS.includes(value);
|
|
69209
69271
|
}
|
|
69210
69272
|
function isCallbackActivity(value) {
|
|
69211
|
-
return
|
|
69273
|
+
return isJsonObject2(value) && typeof value.id === "string" && isActivityKind(value.kind) && typeof value.name === "string" && typeof value.startedAt === "number";
|
|
69212
69274
|
}
|
|
69213
69275
|
function parseEngineTerminalControl(value) {
|
|
69214
|
-
if (value === undefined || !
|
|
69276
|
+
if (value === undefined || !isJsonObject2(value) || value.kind !== "autowrap" || typeof value.enabled !== "boolean") {
|
|
69215
69277
|
return;
|
|
69216
69278
|
}
|
|
69217
69279
|
return { kind: "autowrap", enabled: value.enabled };
|
|
69218
69280
|
}
|
|
69219
69281
|
function parseSessionPickerRow(value) {
|
|
69220
|
-
if (!
|
|
69282
|
+
if (!isJsonObject2(value))
|
|
69221
69283
|
return;
|
|
69222
69284
|
const {
|
|
69223
69285
|
path: path17,
|
|
@@ -69273,7 +69335,7 @@ function parseInputFormFields(value) {
|
|
|
69273
69335
|
return;
|
|
69274
69336
|
const fields = [];
|
|
69275
69337
|
for (const entry of value) {
|
|
69276
|
-
if (!
|
|
69338
|
+
if (!isJsonObject2(entry))
|
|
69277
69339
|
return;
|
|
69278
69340
|
const { name, type, description, required, choices, placeholder, initialValue } = entry;
|
|
69279
69341
|
if (typeof name !== "string" || !INPUT_FORM_FIELD_TYPES.includes(type) || typeof initialValue !== "string")
|
|
@@ -69299,7 +69361,7 @@ function parseInputFormFields(value) {
|
|
|
69299
69361
|
return fields;
|
|
69300
69362
|
}
|
|
69301
69363
|
function parseStringRecord(value) {
|
|
69302
|
-
if (value === undefined || !
|
|
69364
|
+
if (value === undefined || !isJsonObject2(value))
|
|
69303
69365
|
return;
|
|
69304
69366
|
const entries = Object.entries(value);
|
|
69305
69367
|
if (entries.some(([, entry]) => typeof entry !== "string"))
|
|
@@ -69307,7 +69369,7 @@ function parseStringRecord(value) {
|
|
|
69307
69369
|
return Object.fromEntries(entries);
|
|
69308
69370
|
}
|
|
69309
69371
|
function parseKeybindingsConfig(value) {
|
|
69310
|
-
if (value === undefined || !
|
|
69372
|
+
if (value === undefined || !isJsonObject2(value))
|
|
69311
69373
|
return;
|
|
69312
69374
|
const config = {};
|
|
69313
69375
|
for (const [key, binding] of Object.entries(value)) {
|
|
@@ -69321,7 +69383,7 @@ function parseKeybindingsConfig(value) {
|
|
|
69321
69383
|
return config;
|
|
69322
69384
|
}
|
|
69323
69385
|
function parseKeybindingState(value) {
|
|
69324
|
-
if (value === undefined || !
|
|
69386
|
+
if (value === undefined || !isJsonObject2(value) || !Array.isArray(value.shortcuts))
|
|
69325
69387
|
return;
|
|
69326
69388
|
const userBindings = parseKeybindingsConfig(value.userBindings);
|
|
69327
69389
|
const effectiveBindings = parseKeybindingsConfig(value.effectiveBindings);
|
|
@@ -69329,7 +69391,7 @@ function parseKeybindingState(value) {
|
|
|
69329
69391
|
return;
|
|
69330
69392
|
const shortcuts = [];
|
|
69331
69393
|
for (const shortcut of value.shortcuts) {
|
|
69332
|
-
if (!
|
|
69394
|
+
if (!isJsonObject2(shortcut) || typeof shortcut.key !== "string" || shortcut.description !== undefined && typeof shortcut.description !== "string")
|
|
69333
69395
|
return;
|
|
69334
69396
|
shortcuts.push({
|
|
69335
69397
|
key: shortcut.key,
|
|
@@ -69345,7 +69407,7 @@ function parseJsonObject(line) {
|
|
|
69345
69407
|
} catch {
|
|
69346
69408
|
return;
|
|
69347
69409
|
}
|
|
69348
|
-
return
|
|
69410
|
+
return isJsonObject2(value) ? value : undefined;
|
|
69349
69411
|
}
|
|
69350
69412
|
function parseInteractiveEngineMessage(line) {
|
|
69351
69413
|
const value = parseJsonObject(line);
|
|
@@ -69377,7 +69439,7 @@ function parseInteractiveEngineMessage(line) {
|
|
|
69377
69439
|
handlesCtrlC: value.handlesCtrlC === true,
|
|
69378
69440
|
handlesInternalUiAction: value.handlesInternalUiAction === true,
|
|
69379
69441
|
reserveTranscriptRows: value.reserveTranscriptRows === true,
|
|
69380
|
-
overlayOptions:
|
|
69442
|
+
overlayOptions: isJsonObject2(value.overlayOptions) ? value.overlayOptions : undefined,
|
|
69381
69443
|
widgetKey: typeof value.widgetKey === "string" ? value.widgetKey : undefined,
|
|
69382
69444
|
widgetPlacement: value.widgetPlacement === "belowEditor" ? "belowEditor" : value.widgetPlacement === "aboveEditor" ? "aboveEditor" : undefined
|
|
69383
69445
|
} : undefined;
|
|
@@ -69471,7 +69533,7 @@ function parseInteractiveEngineCommand(line) {
|
|
|
69471
69533
|
toolName: value.toolName,
|
|
69472
69534
|
toolCallId: value.toolCallId,
|
|
69473
69535
|
args: value.args,
|
|
69474
|
-
result:
|
|
69536
|
+
result: isJsonObject2(value.result) ? value.result : undefined,
|
|
69475
69537
|
executionStarted: value.executionStarted,
|
|
69476
69538
|
argsComplete: value.argsComplete,
|
|
69477
69539
|
isPartial: value.isPartial,
|
|
@@ -69480,7 +69542,7 @@ function parseInteractiveEngineCommand(line) {
|
|
|
69480
69542
|
imageWidthCells: value.imageWidthCells
|
|
69481
69543
|
};
|
|
69482
69544
|
}
|
|
69483
|
-
if (value.type === "engine_message_render" && typeof value.requestId === "number" && typeof value.width === "number" &&
|
|
69545
|
+
if (value.type === "engine_message_render" && typeof value.requestId === "number" && typeof value.width === "number" && isJsonObject2(value.message) && typeof value.expanded === "boolean" && typeof value.outputPad === "number") {
|
|
69484
69546
|
return {
|
|
69485
69547
|
type: value.type,
|
|
69486
69548
|
componentId: value.componentId,
|
|
@@ -69938,12 +70000,12 @@ var init_compile_cache = __esm(() => {
|
|
|
69938
70000
|
});
|
|
69939
70001
|
|
|
69940
70002
|
// src/utils/interactive-engine-bootstrap.ts
|
|
69941
|
-
import { mkdtempSync as mkdtempSync2, readFileSync as
|
|
70003
|
+
import { mkdtempSync as mkdtempSync2, readFileSync as readFileSync32, renameSync as renameSync6, rmSync as rmSync10, writeFileSync as writeFileSync17 } from "node:fs";
|
|
69942
70004
|
import { tmpdir as tmpdir6 } from "node:os";
|
|
69943
|
-
import { join as
|
|
70005
|
+
import { join as join67 } from "node:path";
|
|
69944
70006
|
function writeInteractiveEngineBootstrap(record) {
|
|
69945
|
-
const directory = mkdtempSync2(
|
|
69946
|
-
const path17 =
|
|
70007
|
+
const directory = mkdtempSync2(join67(tmpdir6(), "atomic-engine-bootstrap-"));
|
|
70008
|
+
const path17 = join67(directory, "bootstrap.json");
|
|
69947
70009
|
const tempPath = `${path17}.tmp`;
|
|
69948
70010
|
const payload = { version: INTERACTIVE_ENGINE_BOOTSTRAP_VERSION, ...record };
|
|
69949
70011
|
try {
|
|
@@ -69981,7 +70043,7 @@ function takeInteractiveEngineBootstrapArg(args) {
|
|
|
69981
70043
|
function readInteractiveEngineBootstrap(path17) {
|
|
69982
70044
|
let raw;
|
|
69983
70045
|
try {
|
|
69984
|
-
raw =
|
|
70046
|
+
raw = readFileSync32(path17, "utf8");
|
|
69985
70047
|
} catch {
|
|
69986
70048
|
return;
|
|
69987
70049
|
} finally {
|
|
@@ -70051,12 +70113,12 @@ var init_interactive_engine_env = __esm(() => {
|
|
|
70051
70113
|
import { spawn as spawn10 } from "node:child_process";
|
|
70052
70114
|
import { rm, writeFile as writeFile3 } from "node:fs/promises";
|
|
70053
70115
|
import { tmpdir as tmpdir7 } from "node:os";
|
|
70054
|
-
import { join as
|
|
70116
|
+
import { join as join68 } from "node:path";
|
|
70055
70117
|
function createRpcClientProcessEnvironment(overrides, baseEnv = process.env) {
|
|
70056
70118
|
return scrubInteractiveEngineEnv(createChildProcessEnvironment(overrides, baseEnv));
|
|
70057
70119
|
}
|
|
70058
70120
|
function spawnRpcClientProcess(options) {
|
|
70059
|
-
const guardianFile = options.interactiveEngine ?
|
|
70121
|
+
const guardianFile = options.interactiveEngine ? join68(tmpdir7(), `atomic-engine-guardian-${process.pid}-${crypto.randomUUID()}`) : undefined;
|
|
70060
70122
|
const bootstrap = options.interactiveEngine ? writeInteractiveEngineBootstrap({
|
|
70061
70123
|
hostPid: process.pid,
|
|
70062
70124
|
guardFile: guardianFile,
|
|
@@ -70920,7 +70982,7 @@ function jsonResult(value) {
|
|
|
70920
70982
|
if (encoded === undefined)
|
|
70921
70983
|
return;
|
|
70922
70984
|
const decoded = JSON.parse(encoded);
|
|
70923
|
-
if (!
|
|
70985
|
+
if (!isJsonValue2(decoded))
|
|
70924
70986
|
throw new Error("Custom UI result is not JSON-safe");
|
|
70925
70987
|
return decoded;
|
|
70926
70988
|
}
|
|
@@ -73006,7 +73068,7 @@ var init_create_isolated_runtime = __esm(() => {
|
|
|
73006
73068
|
});
|
|
73007
73069
|
|
|
73008
73070
|
// src/modes/interactive/components/config-selector-project-scope.ts
|
|
73009
|
-
import { dirname as
|
|
73071
|
+
import { dirname as dirname35, join as join69, relative as relative13 } from "node:path";
|
|
73010
73072
|
function stripPrefix(pattern) {
|
|
73011
73073
|
return /^[!+-]/.test(pattern) ? pattern.slice(1) : pattern;
|
|
73012
73074
|
}
|
|
@@ -73023,11 +73085,11 @@ function setProjectPaths(settings, type, paths) {
|
|
|
73023
73085
|
settings.setProjectWorkflowPaths(paths);
|
|
73024
73086
|
}
|
|
73025
73087
|
function packagePattern(item) {
|
|
73026
|
-
return relative13(item.metadata.baseDir ??
|
|
73088
|
+
return relative13(item.metadata.baseDir ?? dirname35(item.path), item.path);
|
|
73027
73089
|
}
|
|
73028
73090
|
function toggleProjectPackage(settings, item, cwd, enabled) {
|
|
73029
73091
|
const packages = [...settings.getProjectSettings().packages ?? []];
|
|
73030
|
-
const projectBase =
|
|
73092
|
+
const projectBase = join69(cwd, CONFIG_DIR_NAME);
|
|
73031
73093
|
const itemRoot = item.metadata.baseDir;
|
|
73032
73094
|
let index = packages.findIndex((pkg3) => {
|
|
73033
73095
|
const source = typeof pkg3 === "string" ? pkg3 : pkg3.source;
|
|
@@ -73056,7 +73118,7 @@ function toggleProjectResource(settings, item, cwd, enabled) {
|
|
|
73056
73118
|
return;
|
|
73057
73119
|
}
|
|
73058
73120
|
const current = [...settings.getProjectSettings()[item.resourceType] ?? []];
|
|
73059
|
-
const projectBase =
|
|
73121
|
+
const projectBase = join69(cwd, CONFIG_DIR_NAME);
|
|
73060
73122
|
const pattern = item.metadata.scope === "user" ? item.path : relative13(item.metadata.baseDir ?? projectBase, item.path);
|
|
73061
73123
|
const updated = current.filter((entry) => stripPrefix(entry) !== pattern);
|
|
73062
73124
|
updated.push(`${enabled ? "+" : "-"}${pattern}`);
|
|
@@ -73069,7 +73131,7 @@ var init_config_selector_project_scope = __esm(() => {
|
|
|
73069
73131
|
|
|
73070
73132
|
// src/modes/interactive/components/config-selector-list.ts
|
|
73071
73133
|
import { homedir as homedir9 } from "node:os";
|
|
73072
|
-
import { basename as basename19, dirname as
|
|
73134
|
+
import { basename as basename19, dirname as dirname36, join as join70, relative as relative14 } from "node:path";
|
|
73073
73135
|
import {
|
|
73074
73136
|
getKeybindings as getKeybindings19,
|
|
73075
73137
|
Input as Input12,
|
|
@@ -73129,7 +73191,7 @@ function buildGroups(resolved, agentDir) {
|
|
|
73129
73191
|
group.subgroups.push(subgroup);
|
|
73130
73192
|
}
|
|
73131
73193
|
const fileName = basename19(path17);
|
|
73132
|
-
const parentFolder = basename19(
|
|
73194
|
+
const parentFolder = basename19(dirname36(path17));
|
|
73133
73195
|
let displayName;
|
|
73134
73196
|
if (resourceType === "extensions" && parentFolder !== "extensions") {
|
|
73135
73197
|
displayName = `${parentFolder}/${fileName}`;
|
|
@@ -73443,7 +73505,7 @@ class ResourceList {
|
|
|
73443
73505
|
this.settingsManager.setPackages(packages);
|
|
73444
73506
|
}
|
|
73445
73507
|
getTopLevelBaseDir(scope) {
|
|
73446
|
-
return scope === "project" ?
|
|
73508
|
+
return scope === "project" ? join70(this.cwd, CONFIG_DIR_NAME) : this.agentDir;
|
|
73447
73509
|
}
|
|
73448
73510
|
getResourcePattern(item) {
|
|
73449
73511
|
const scope = item.metadata.scope;
|
|
@@ -73451,7 +73513,7 @@ class ResourceList {
|
|
|
73451
73513
|
return relative14(baseDir, item.path);
|
|
73452
73514
|
}
|
|
73453
73515
|
getPackageResourcePattern(item) {
|
|
73454
|
-
const baseDir = item.metadata.baseDir ??
|
|
73516
|
+
const baseDir = item.metadata.baseDir ?? dirname36(item.path);
|
|
73455
73517
|
return relative14(baseDir, item.path);
|
|
73456
73518
|
}
|
|
73457
73519
|
}
|
|
@@ -73919,8 +73981,8 @@ var init_self_update_plan = __esm(() => {
|
|
|
73919
73981
|
|
|
73920
73982
|
// src/utils/windows-self-update.ts
|
|
73921
73983
|
import { randomUUID as randomUUID9 } from "node:crypto";
|
|
73922
|
-
import { copyFileSync as copyFileSync2, existsSync as
|
|
73923
|
-
import { basename as basename20, dirname as
|
|
73984
|
+
import { copyFileSync as copyFileSync2, existsSync as existsSync48, mkdirSync as mkdirSync16, renameSync as renameSync7, rmSync as rmSync11 } from "node:fs";
|
|
73985
|
+
import { basename as basename20, dirname as dirname37, join as join71, relative as relative15, resolve as resolve23, toNamespacedPath } from "node:path";
|
|
73924
73986
|
function normalizePath3(path17) {
|
|
73925
73987
|
return toNamespacedPath(resolve23(path17));
|
|
73926
73988
|
}
|
|
@@ -73928,9 +73990,9 @@ function getQuarantineRoot(packageDir) {
|
|
|
73928
73990
|
let current = resolve23(packageDir);
|
|
73929
73991
|
while (true) {
|
|
73930
73992
|
if (basename20(current).toLowerCase() === "node_modules") {
|
|
73931
|
-
return
|
|
73993
|
+
return join71(current, QUARANTINE_DIR_NAME);
|
|
73932
73994
|
}
|
|
73933
|
-
const parent =
|
|
73995
|
+
const parent = dirname37(current);
|
|
73934
73996
|
if (parent === current) {
|
|
73935
73997
|
return;
|
|
73936
73998
|
}
|
|
@@ -73978,13 +74040,13 @@ function quarantineWindowsNativeDependencies(packageDir) {
|
|
|
73978
74040
|
if (loadedFiles.length === 0) {
|
|
73979
74041
|
return;
|
|
73980
74042
|
}
|
|
73981
|
-
const quarantineRunDir =
|
|
74043
|
+
const quarantineRunDir = join71(quarantineRoot, `${Date.now()}-${process.pid}-${randomUUID9()}`);
|
|
73982
74044
|
for (const loadedFile of loadedFiles) {
|
|
73983
|
-
if (!
|
|
74045
|
+
if (!existsSync48(loadedFile)) {
|
|
73984
74046
|
continue;
|
|
73985
74047
|
}
|
|
73986
|
-
const quarantinePath =
|
|
73987
|
-
mkdirSync16(
|
|
74048
|
+
const quarantinePath = join71(quarantineRunDir, relative15(resolvedPackageDir, loadedFile));
|
|
74049
|
+
mkdirSync16(dirname37(quarantinePath), { recursive: true });
|
|
73988
74050
|
renameSync7(loadedFile, quarantinePath);
|
|
73989
74051
|
copyFileSync2(quarantinePath, loadedFile);
|
|
73990
74052
|
}
|
|
@@ -73997,7 +74059,7 @@ var init_windows_self_update = __esm(() => {
|
|
|
73997
74059
|
});
|
|
73998
74060
|
|
|
73999
74061
|
// src/package-manager-cli.ts
|
|
74000
|
-
import { join as
|
|
74062
|
+
import { join as join72 } from "node:path";
|
|
74001
74063
|
import chalk14 from "chalk";
|
|
74002
74064
|
function reportSettingsErrors(settingsManager, context) {
|
|
74003
74065
|
const errors = settingsManager.drainErrors();
|
|
@@ -74035,10 +74097,10 @@ async function refreshModelCatalogs2(agentDir, options = {}) {
|
|
|
74035
74097
|
const loaded = await Promise.race([resourceLoader.reload().then(() => true), aborted]);
|
|
74036
74098
|
if (!loaded)
|
|
74037
74099
|
throw new Error("Model catalog refresh timed out.");
|
|
74038
|
-
const authPaths = [
|
|
74100
|
+
const authPaths = [join72(agentDir, "auth.json"), ...getAgentConfigPaths("auth.json")].filter((path17, index, paths) => paths.indexOf(path17) === index);
|
|
74039
74101
|
const modelRuntime = await ModelRuntime.create({
|
|
74040
74102
|
credentials: AuthStorage.create(authPaths),
|
|
74041
|
-
modelsPath:
|
|
74103
|
+
modelsPath: join72(agentDir, "models.json")
|
|
74042
74104
|
});
|
|
74043
74105
|
const extensionsResult = resourceLoader.getExtensions();
|
|
74044
74106
|
if (extensionsResult.errors.length > 0) {
|
|
@@ -78592,8 +78654,8 @@ function handleSubagentControlNotice(input2) {
|
|
|
78592
78654
|
|
|
78593
78655
|
// dist/builtin/subagents/src/runs/inprocess/runner.ts
|
|
78594
78656
|
init_src();
|
|
78595
|
-
import { appendFileSync as appendFileSync3, existsSync as
|
|
78596
|
-
import { basename as basename22, dirname as
|
|
78657
|
+
import { appendFileSync as appendFileSync3, existsSync as existsSync57, mkdirSync as mkdirSync20, statSync as statSync16 } from "node:fs";
|
|
78658
|
+
import { basename as basename22, dirname as dirname44, join as join82, relative as relative17, resolve as resolve29 } from "node:path";
|
|
78597
78659
|
import {
|
|
78598
78660
|
SubagentControl
|
|
78599
78661
|
} from "@bastani/atomic-natives";
|
|
@@ -79261,10 +79323,10 @@ Full output: ${artifactPath}` : result2.text;
|
|
|
79261
79323
|
function canonicalArtifactPaths(artifactsDir, childPath) {
|
|
79262
79324
|
const prefix = childPath.replaceAll("/", "_");
|
|
79263
79325
|
return {
|
|
79264
|
-
inputPath:
|
|
79265
|
-
outputPath:
|
|
79266
|
-
jsonlPath:
|
|
79267
|
-
metadataPath:
|
|
79326
|
+
inputPath: join82(artifactsDir, `${prefix}_input.md`),
|
|
79327
|
+
outputPath: join82(artifactsDir, `${prefix}_output.md`),
|
|
79328
|
+
jsonlPath: join82(artifactsDir, `${prefix}.jsonl`),
|
|
79329
|
+
metadataPath: join82(artifactsDir, `${prefix}_meta.json`)
|
|
79268
79330
|
};
|
|
79269
79331
|
}
|
|
79270
79332
|
function validatePath(pathValue) {
|
|
@@ -79274,7 +79336,7 @@ function validatePath(pathValue) {
|
|
|
79274
79336
|
}
|
|
79275
79337
|
function trustedSessionRoot(parent, requestedRoot) {
|
|
79276
79338
|
validatePath(parent.path);
|
|
79277
|
-
const root = resolve29(requestedRoot ??
|
|
79339
|
+
const root = resolve29(requestedRoot ?? join82(process.cwd(), ".atomic", "subagents"));
|
|
79278
79340
|
const child = resolve29(root, ...parent.path.split("/"));
|
|
79279
79341
|
if (relative17(root, child).startsWith(".."))
|
|
79280
79342
|
throw new Error("subagent session root escapes trusted root");
|
|
@@ -79323,7 +79385,7 @@ function writeEvent(pathValue, event) {
|
|
|
79323
79385
|
}
|
|
79324
79386
|
if (existingBytes + Buffer.byteLength(line, "utf8") > DEFAULT_MAX_JSONL_BYTES)
|
|
79325
79387
|
return;
|
|
79326
|
-
mkdirSync20(
|
|
79388
|
+
mkdirSync20(dirname44(pathValue), { recursive: true });
|
|
79327
79389
|
appendFileSync3(pathValue, line, "utf8");
|
|
79328
79390
|
}
|
|
79329
79391
|
|
|
@@ -79370,7 +79432,7 @@ class SubagentControlRuntime {
|
|
|
79370
79432
|
this.native.registerAgent(agent.name);
|
|
79371
79433
|
}
|
|
79372
79434
|
admitChildSession(spec, parent = this.parent) {
|
|
79373
|
-
if (!
|
|
79435
|
+
if (!existsSync57(spec.cwd) || !statSync16(spec.cwd).isDirectory()) {
|
|
79374
79436
|
return {
|
|
79375
79437
|
refusal: {
|
|
79376
79438
|
kind: "invalidCwd",
|
|
@@ -79383,7 +79445,7 @@ class SubagentControlRuntime {
|
|
|
79383
79445
|
return refusal(native);
|
|
79384
79446
|
const identity = native.child;
|
|
79385
79447
|
const childModePolicy = resolveChildModePolicy(spec);
|
|
79386
|
-
const sessionDir = spec.sessionFile ?
|
|
79448
|
+
const sessionDir = spec.sessionFile ? dirname44(spec.sessionFile) : sessionDirectory(this.sessionRoot, identity.path);
|
|
79387
79449
|
mkdirSync20(sessionDir, { recursive: true });
|
|
79388
79450
|
return {
|
|
79389
79451
|
admitted: AdmittedChild.create({
|
|
@@ -79493,7 +79555,7 @@ class SubagentControlRuntime {
|
|
|
79493
79555
|
try {
|
|
79494
79556
|
const workflow = workflowMetadataFromContext(admitted.spec.parent?.orchestrationContext);
|
|
79495
79557
|
if (admitted.sessionFile)
|
|
79496
|
-
mkdirSync20(
|
|
79558
|
+
mkdirSync20(dirname44(admitted.sessionFile), { recursive: true });
|
|
79497
79559
|
const sessionManager = admitted.sessionFile ? SessionManager.open(admitted.sessionFile, admitted.sessionDir, admitted.policy.cwd) : SessionManager.create(admitted.policy.cwd, admitted.sessionDir, workflow ? { internal: true, workflow } : { internal: true });
|
|
79498
79560
|
activeSessionManager = sessionManager;
|
|
79499
79561
|
if (workflow)
|
|
@@ -79797,7 +79859,7 @@ class SubagentControlRuntime {
|
|
|
79797
79859
|
...deliveredEnvelope,
|
|
79798
79860
|
outputPath: paths.outputPath
|
|
79799
79861
|
});
|
|
79800
|
-
appendFileSync3(
|
|
79862
|
+
appendFileSync3(join82(artifactDir, "run-history.jsonl"), `${JSON.stringify(deliveredEnvelope)}
|
|
79801
79863
|
`, "utf8");
|
|
79802
79864
|
}
|
|
79803
79865
|
getDeliveredResult(pathValue) {
|
|
@@ -82543,8 +82605,8 @@ ${worktreeSuffix}` : childContent;
|
|
|
82543
82605
|
}
|
|
82544
82606
|
|
|
82545
82607
|
// dist/builtin/subagents/src/runs/foreground/inprocess-run-sync.ts
|
|
82546
|
-
import { existsSync as
|
|
82547
|
-
import { join as
|
|
82608
|
+
import { existsSync as existsSync62, statSync as statSync20 } from "node:fs";
|
|
82609
|
+
import { join as join90 } from "node:path";
|
|
82548
82610
|
|
|
82549
82611
|
// dist/builtin/subagents/src/runs/shared/model-candidate-filter.ts
|
|
82550
82612
|
function providerFromModel(model) {
|
|
@@ -82836,7 +82898,7 @@ function noSpawnableCandidatesResult(agent, task, skippedAttempts) {
|
|
|
82836
82898
|
}
|
|
82837
82899
|
async function runSingleInProcess(runtimeCwd, agent, task, options) {
|
|
82838
82900
|
const cwd = options.cwd ?? runtimeCwd;
|
|
82839
|
-
if (!
|
|
82901
|
+
if (!existsSync62(cwd))
|
|
82840
82902
|
return refusedResult(agent, task, `cwd does not exist: ${cwd}`);
|
|
82841
82903
|
if (!statSync20(cwd).isDirectory())
|
|
82842
82904
|
return refusedResult(agent, task, `cwd is not a directory: ${cwd}`);
|
|
@@ -82869,7 +82931,7 @@ async function runSingleInProcess(runtimeCwd, agent, task, options) {
|
|
|
82869
82931
|
...options.workflowStageSubagentGuard === undefined ? {} : { workflowStageSubagentGuard: options.workflowStageSubagentGuard },
|
|
82870
82932
|
...orchestrationContext ? { orchestrationContext } : {}
|
|
82871
82933
|
};
|
|
82872
|
-
const sessionRoot = options.sessionDir ??
|
|
82934
|
+
const sessionRoot = options.sessionDir ?? join90(options.artifactsDir ?? cwd, ".atomic", "subagents");
|
|
82873
82935
|
const control = getOrCreateSubagentControl(parent, sessionRoot);
|
|
82874
82936
|
control.registerAgents([agent]);
|
|
82875
82937
|
const artifactsDir = options.artifactsDir && options.artifactConfig?.enabled !== false ? options.artifactsDir : undefined;
|