@bastani/atomic 0.9.16-alpha.3 → 0.9.16-alpha.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +7 -0
- package/dist/builtin/intercom/index.bundle.mjs +498 -436
- package/dist/builtin/intercom/package.json +1 -1
- package/dist/builtin/mcp/index.bundle.mjs +553 -491
- package/dist/builtin/mcp/package.json +1 -1
- package/dist/builtin/subagents/package.json +1 -1
- package/dist/builtin/subagents/src/extension/index.bundle.mjs +714 -652
- package/dist/builtin/web-access/index.bundle.mjs +547 -485
- package/dist/builtin/web-access/package.json +1 -1
- package/dist/builtin/workflows/package.json +1 -1
- package/dist/builtin/workflows/src/extension/index.bundle.mjs +845 -783
- package/dist/builtin/workflows/src/index.bundle.mjs +485 -423
- package/dist/config-package-identity.d.ts +22 -0
- package/dist/config-package-identity.d.ts.map +1 -0
- package/dist/config-package-identity.js +73 -0
- package/dist/config-package-identity.js.map +1 -0
- package/dist/config.d.ts.map +1 -1
- package/dist/config.js +5 -10
- package/dist/config.js.map +1 -1
- package/npm-shrinkwrap.json +32 -32
- package/package.json +3 -3
|
@@ -16,6 +16,96 @@ var __export = (target, all) => {
|
|
|
16
16
|
var __esm = (fn, res) => () => (fn && (res = fn(fn = 0)), res);
|
|
17
17
|
var __require = /* @__PURE__ */ createRequire(import.meta.url);
|
|
18
18
|
|
|
19
|
+
// src/core/builtin-install-layout.ts
|
|
20
|
+
function requiredEntriesForBuiltin(dirName) {
|
|
21
|
+
return [INSTALLED_EXTENSION_ENTRIES[dirName], SOURCE_EXTENSION_ENTRIES[dirName]];
|
|
22
|
+
}
|
|
23
|
+
var BUILTIN_PACKAGE_DIR_NAMES, SOURCE_EXTENSION_ENTRIES, INSTALLED_EXTENSION_ENTRIES;
|
|
24
|
+
var init_builtin_install_layout = __esm(() => {
|
|
25
|
+
BUILTIN_PACKAGE_DIR_NAMES = ["workflows", "subagents", "mcp", "web-access", "intercom"];
|
|
26
|
+
SOURCE_EXTENSION_ENTRIES = {
|
|
27
|
+
workflows: "src/extension/index.ts",
|
|
28
|
+
subagents: "src/extension/index.ts",
|
|
29
|
+
mcp: "index.ts",
|
|
30
|
+
"web-access": "index.ts",
|
|
31
|
+
intercom: "index.ts"
|
|
32
|
+
};
|
|
33
|
+
INSTALLED_EXTENSION_ENTRIES = {
|
|
34
|
+
workflows: "src/extension/index.bundle.mjs",
|
|
35
|
+
subagents: "src/extension/index.bundle.mjs",
|
|
36
|
+
mcp: "index.bundle.mjs",
|
|
37
|
+
"web-access": "index.bundle.mjs",
|
|
38
|
+
intercom: "index.bundle.mjs"
|
|
39
|
+
};
|
|
40
|
+
});
|
|
41
|
+
|
|
42
|
+
// src/config-package-identity.ts
|
|
43
|
+
import { existsSync, readFileSync } from "fs";
|
|
44
|
+
import { dirname, join } from "path";
|
|
45
|
+
function isCompanionBuiltinPackageName(name) {
|
|
46
|
+
return name !== undefined && COMPANION_BUILTIN_PACKAGE_NAMES.includes(name);
|
|
47
|
+
}
|
|
48
|
+
function packageJsonDefinesAppIdentity(pkg) {
|
|
49
|
+
if (pkg.name === "@bastani/atomic" || pkg.name === "@mariozechner/pi")
|
|
50
|
+
return true;
|
|
51
|
+
return pkg.atomicConfig !== undefined || pkg.piConfig !== undefined;
|
|
52
|
+
}
|
|
53
|
+
function resolvePackageDirFrom(startDir) {
|
|
54
|
+
let dir = startDir;
|
|
55
|
+
let firstPackageDir;
|
|
56
|
+
while (dir !== dirname(dir)) {
|
|
57
|
+
const packageJsonPath = join(dir, "package.json");
|
|
58
|
+
if (existsSync(packageJsonPath)) {
|
|
59
|
+
firstPackageDir ??= dir;
|
|
60
|
+
if (shouldUsePackageDir(readPackageIdentity(packageJsonPath))) {
|
|
61
|
+
return dir;
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
dir = dirname(dir);
|
|
65
|
+
}
|
|
66
|
+
return firstPackageDir ?? startDir;
|
|
67
|
+
}
|
|
68
|
+
function shouldUsePackageDir(pkg) {
|
|
69
|
+
if (packageJsonDefinesAppIdentity(pkg))
|
|
70
|
+
return true;
|
|
71
|
+
return !isCompanionBuiltinPackageName(pkg.name);
|
|
72
|
+
}
|
|
73
|
+
function isJsonValue(value) {
|
|
74
|
+
if (value === null || typeof value === "boolean" || typeof value === "string")
|
|
75
|
+
return true;
|
|
76
|
+
if (typeof value === "number")
|
|
77
|
+
return Number.isFinite(value);
|
|
78
|
+
if (Array.isArray(value))
|
|
79
|
+
return value.every(isJsonValue);
|
|
80
|
+
if (typeof value !== "object" || Object.getPrototypeOf(value) !== Object.prototype)
|
|
81
|
+
return false;
|
|
82
|
+
return Object.values(value).every(isJsonValue);
|
|
83
|
+
}
|
|
84
|
+
function isJsonObject(value) {
|
|
85
|
+
return value !== null && typeof value === "object" && !Array.isArray(value);
|
|
86
|
+
}
|
|
87
|
+
function readPackageIdentity(packageJsonPath) {
|
|
88
|
+
try {
|
|
89
|
+
const parsed = JSON.parse(readFileSync(packageJsonPath, "utf-8"));
|
|
90
|
+
if (!isJsonValue(parsed) || !isJsonObject(parsed))
|
|
91
|
+
return {};
|
|
92
|
+
const name = parsed.name;
|
|
93
|
+
const atomicConfig = parsed.atomicConfig;
|
|
94
|
+
const piConfig = parsed.piConfig;
|
|
95
|
+
return {
|
|
96
|
+
...typeof name === "string" ? { name } : {},
|
|
97
|
+
...atomicConfig !== undefined && isJsonObject(atomicConfig) ? { atomicConfig } : {},
|
|
98
|
+
...piConfig !== undefined && isJsonObject(piConfig) ? { piConfig } : {}
|
|
99
|
+
};
|
|
100
|
+
} catch {}
|
|
101
|
+
return {};
|
|
102
|
+
}
|
|
103
|
+
var COMPANION_BUILTIN_PACKAGE_NAMES;
|
|
104
|
+
var init_config_package_identity = __esm(() => {
|
|
105
|
+
init_builtin_install_layout();
|
|
106
|
+
COMPANION_BUILTIN_PACKAGE_NAMES = BUILTIN_PACKAGE_DIR_NAMES.map((dirName) => `@bastani/${dirName}`);
|
|
107
|
+
});
|
|
108
|
+
|
|
19
109
|
// src/utils/agent-attribution.ts
|
|
20
110
|
var ATOMIC_AI_AGENT = "atomic";
|
|
21
111
|
|
|
@@ -196,7 +286,7 @@ var init_child_process = __esm(() => {
|
|
|
196
286
|
// src/utils/paths.ts
|
|
197
287
|
import { realpathSync } from "node:fs";
|
|
198
288
|
import { homedir } from "node:os";
|
|
199
|
-
import { isAbsolute, join, resolve as nodeResolvePath, relative, sep } from "node:path";
|
|
289
|
+
import { isAbsolute, join as join2, resolve as nodeResolvePath, relative, sep } from "node:path";
|
|
200
290
|
import { fileURLToPath as fileURLToPath2 } from "node:url";
|
|
201
291
|
function getHomeDir() {
|
|
202
292
|
if (process.platform === "win32") {
|
|
@@ -249,7 +339,7 @@ function normalizePath(input, options = {}) {
|
|
|
249
339
|
if (normalized === "~")
|
|
250
340
|
return home;
|
|
251
341
|
if (normalized.startsWith("~/") || process.platform === "win32" && normalized.startsWith("~\\")) {
|
|
252
|
-
return
|
|
342
|
+
return join2(home, normalized.slice(2));
|
|
253
343
|
}
|
|
254
344
|
}
|
|
255
345
|
if (/^file:\/\//.test(normalized)) {
|
|
@@ -291,20 +381,20 @@ var init_paths = __esm(() => {
|
|
|
291
381
|
});
|
|
292
382
|
|
|
293
383
|
// src/utils/split-launcher.ts
|
|
294
|
-
import { dirname, join as
|
|
384
|
+
import { dirname as dirname2, join as join3 } from "node:path";
|
|
295
385
|
import { fileURLToPath as fileURLToPath3 } from "node:url";
|
|
296
386
|
function isSplitLauncherRuntime() {
|
|
297
387
|
return process.env.ATOMIC_CODING_AGENT === "true" && /(?:^|[\\/])atomic(?:\.exe)?$/i.test(process.execPath);
|
|
298
388
|
}
|
|
299
389
|
function splitLauncherDir() {
|
|
300
|
-
return
|
|
390
|
+
return dirname2(process.execPath);
|
|
301
391
|
}
|
|
302
392
|
function moduleFileFromMetaUrl(metaUrl, execRelativeFile) {
|
|
303
393
|
try {
|
|
304
394
|
return fileURLToPath3(metaUrl);
|
|
305
395
|
} catch (error) {
|
|
306
396
|
if (isSplitLauncherRuntime())
|
|
307
|
-
return
|
|
397
|
+
return join3(splitLauncherDir(), execRelativeFile);
|
|
308
398
|
throw error;
|
|
309
399
|
}
|
|
310
400
|
}
|
|
@@ -316,24 +406,17 @@ var init_config_self_update = __esm(() => {
|
|
|
316
406
|
});
|
|
317
407
|
|
|
318
408
|
// src/config.ts
|
|
319
|
-
import { existsSync, readFileSync } from "fs";
|
|
320
|
-
import { dirname as
|
|
409
|
+
import { existsSync as existsSync2, readFileSync as readFileSync2 } from "fs";
|
|
410
|
+
import { dirname as dirname3, join as join4, resolve } from "path";
|
|
321
411
|
function getPackageDir() {
|
|
322
412
|
const envDir = process.env.ATOMIC_PACKAGE_DIR ?? process.env.PI_PACKAGE_DIR;
|
|
323
413
|
if (envDir) {
|
|
324
414
|
return normalizePath(envDir);
|
|
325
415
|
}
|
|
326
416
|
if (isBunBinary) {
|
|
327
|
-
return
|
|
417
|
+
return dirname3(process.execPath);
|
|
328
418
|
}
|
|
329
|
-
|
|
330
|
-
while (dir !== dirname2(dir)) {
|
|
331
|
-
if (existsSync(join3(dir, "package.json"))) {
|
|
332
|
-
return dir;
|
|
333
|
-
}
|
|
334
|
-
dir = dirname2(dir);
|
|
335
|
-
}
|
|
336
|
-
return __dirname2;
|
|
419
|
+
return resolvePackageDirFrom(__dirname2);
|
|
337
420
|
}
|
|
338
421
|
function getModuleAssetRoot() {
|
|
339
422
|
const hasPackageDirOverride = !!(process.env.ATOMIC_PACKAGE_DIR || process.env.PI_PACKAGE_DIR);
|
|
@@ -341,43 +424,43 @@ function getModuleAssetRoot() {
|
|
|
341
424
|
return __dirname2;
|
|
342
425
|
}
|
|
343
426
|
const packageDir = getPackageDir();
|
|
344
|
-
return
|
|
427
|
+
return join4(packageDir, existsSync2(join4(packageDir, "src")) ? "src" : "dist");
|
|
345
428
|
}
|
|
346
429
|
function getThemesDir() {
|
|
347
430
|
if (isBunBinary) {
|
|
348
|
-
return
|
|
431
|
+
return join4(getPackageDir(), "theme");
|
|
349
432
|
}
|
|
350
|
-
return
|
|
433
|
+
return join4(getModuleAssetRoot(), "modes", "interactive", "theme");
|
|
351
434
|
}
|
|
352
435
|
function getExportTemplateDir() {
|
|
353
436
|
if (isBunBinary) {
|
|
354
|
-
return
|
|
437
|
+
return join4(getPackageDir(), "export-html");
|
|
355
438
|
}
|
|
356
|
-
return
|
|
439
|
+
return join4(getModuleAssetRoot(), "core", "export-html");
|
|
357
440
|
}
|
|
358
441
|
function getPackageJsonPath() {
|
|
359
|
-
return
|
|
442
|
+
return join4(getPackageDir(), "package.json");
|
|
360
443
|
}
|
|
361
444
|
function getReadmePath() {
|
|
362
|
-
return resolve(
|
|
445
|
+
return resolve(join4(getPackageDir(), "README.md"));
|
|
363
446
|
}
|
|
364
447
|
function getDocsPath() {
|
|
365
|
-
return resolve(
|
|
448
|
+
return resolve(join4(getPackageDir(), "docs"));
|
|
366
449
|
}
|
|
367
450
|
function getExamplesPath() {
|
|
368
|
-
return resolve(
|
|
451
|
+
return resolve(join4(getPackageDir(), "examples"));
|
|
369
452
|
}
|
|
370
453
|
function getChangelogPath() {
|
|
371
|
-
return resolve(
|
|
454
|
+
return resolve(join4(getPackageDir(), "CHANGELOG.md"));
|
|
372
455
|
}
|
|
373
456
|
function getInteractiveAssetsDir() {
|
|
374
457
|
if (isBunBinary) {
|
|
375
|
-
return
|
|
458
|
+
return join4(getPackageDir(), "assets");
|
|
376
459
|
}
|
|
377
|
-
return
|
|
460
|
+
return join4(getModuleAssetRoot(), "modes", "interactive", "assets");
|
|
378
461
|
}
|
|
379
462
|
function getBundledInteractiveAssetPath(name) {
|
|
380
|
-
return
|
|
463
|
+
return join4(getInteractiveAssetsDir(), name);
|
|
381
464
|
}
|
|
382
465
|
function appNameFromPackageName(packageName) {
|
|
383
466
|
const localName = packageName?.split("/").pop()?.trim();
|
|
@@ -467,10 +550,10 @@ function getAgentDir() {
|
|
|
467
550
|
if (envDir) {
|
|
468
551
|
return expandTildePath(envDir);
|
|
469
552
|
}
|
|
470
|
-
return
|
|
553
|
+
return join4(getHomeDir(), CONFIG_DIR_NAME, "agent");
|
|
471
554
|
}
|
|
472
555
|
function getLegacyAgentDir() {
|
|
473
|
-
return
|
|
556
|
+
return join4(getHomeDir(), LEGACY_CONFIG_DIR_NAME, "agent");
|
|
474
557
|
}
|
|
475
558
|
function getAgentDirs() {
|
|
476
559
|
const primary = getAgentDir();
|
|
@@ -481,43 +564,44 @@ function getAgentDirs() {
|
|
|
481
564
|
return legacy === primary ? [primary] : [primary, legacy];
|
|
482
565
|
}
|
|
483
566
|
function getProjectConfigDirs(cwd) {
|
|
484
|
-
return CONFIG_DIR_NAMES.map((name) =>
|
|
567
|
+
return CONFIG_DIR_NAMES.map((name) => join4(cwd, name));
|
|
485
568
|
}
|
|
486
569
|
function getAgentConfigPaths(...segments) {
|
|
487
|
-
return getAgentDirs().map((dir) =>
|
|
570
|
+
return getAgentDirs().map((dir) => join4(dir, ...segments));
|
|
488
571
|
}
|
|
489
572
|
function getProjectConfigPaths(cwd, ...segments) {
|
|
490
|
-
return getProjectConfigDirs(cwd).map((dir) =>
|
|
573
|
+
return getProjectConfigDirs(cwd).map((dir) => join4(dir, ...segments));
|
|
491
574
|
}
|
|
492
575
|
function getCustomThemesDir() {
|
|
493
|
-
return
|
|
576
|
+
return join4(getAgentDir(), "themes");
|
|
494
577
|
}
|
|
495
578
|
function getAuthPath() {
|
|
496
|
-
return
|
|
579
|
+
return join4(getAgentDir(), "auth.json");
|
|
497
580
|
}
|
|
498
581
|
function getBinDir() {
|
|
499
|
-
return
|
|
582
|
+
return join4(getAgentDir(), "bin");
|
|
500
583
|
}
|
|
501
584
|
function getSessionsDir() {
|
|
502
|
-
return
|
|
585
|
+
return join4(getAgentDir(), "sessions");
|
|
503
586
|
}
|
|
504
587
|
function getDebugLogPath() {
|
|
505
|
-
return
|
|
588
|
+
return join4(getAgentDir(), `${APP_NAME}-debug.log`);
|
|
506
589
|
}
|
|
507
590
|
var __filename2, __dirname2, bunFsMarkers, isBunBinary, isBundledBuild, isBunRuntime, pkg, PACKAGE_NAME, packageAppName, appConfig, APP_NAME, APP_TITLE, CONFIG_DIR_NAME, LEGACY_CONFIG_DIR_NAME = ".pi", CONFIG_DIR_NAMES, VERSION, CHANGELOG_URL, ENV_PREFIX, LEGACY_ENV_PREFIX = "PI", ENV_AGENT_DIR, ENV_SESSION_DIR, ENV_PACKAGE_DIR, ENV_OFFLINE, ENV_SKIP_VERSION_CHECK, ENV_STARTUP_BENCHMARK, ENV_TELEMETRY, ENV_SHARE_VIEWER_URL, ENV_CLEAR_ON_SHRINK, ENV_HARDWARE_CURSOR, ENV_TIMING, ENV_CODEX_FAST_MODE, WORKFLOW_STAGE_SUBAGENT_GUARD_ENV, DEFAULT_SHARE_VIEWER_URL = "https://pi.dev/session/";
|
|
508
591
|
var init_config = __esm(() => {
|
|
592
|
+
init_config_package_identity();
|
|
509
593
|
init_paths();
|
|
510
594
|
init_split_launcher();
|
|
511
595
|
init_config_self_update();
|
|
512
596
|
__filename2 = moduleFileFromMetaUrl(import.meta.url, "app.js");
|
|
513
|
-
__dirname2 =
|
|
597
|
+
__dirname2 = dirname3(__filename2);
|
|
514
598
|
bunFsMarkers = ["$bunfs", "~BUN", "%7EBUN"];
|
|
515
599
|
isBunBinary = isSplitLauncherRuntime() || [import.meta.url, process.argv[1] ?? ""].some((candidate) => bunFsMarkers.some((marker) => candidate.includes(marker)));
|
|
516
600
|
isBundledBuild = process.env.ATOMIC_BUNDLED_BUILD === "1";
|
|
517
601
|
isBunRuntime = !!process.versions.bun;
|
|
518
602
|
pkg = {};
|
|
519
603
|
try {
|
|
520
|
-
pkg = JSON.parse(
|
|
604
|
+
pkg = JSON.parse(readFileSync2(getPackageJsonPath(), "utf-8"));
|
|
521
605
|
} catch (e) {
|
|
522
606
|
const err = e;
|
|
523
607
|
if (err.code !== "ENOENT")
|
|
@@ -1655,14 +1739,14 @@ var init_planner_outcome = __esm(() => {
|
|
|
1655
1739
|
// src/core/compaction/range-planner-diagnostics.ts
|
|
1656
1740
|
import { uuidv7 } from "@bastani/pi-ai";
|
|
1657
1741
|
import { chmodSync, writeFileSync } from "fs";
|
|
1658
|
-
import { basename as basename2, dirname as
|
|
1742
|
+
import { basename as basename2, dirname as dirname4, join as join5 } from "path";
|
|
1659
1743
|
function writeSidecar(sessionFilePath, kind, payload) {
|
|
1660
|
-
const dir =
|
|
1744
|
+
const dir = dirname4(sessionFilePath);
|
|
1661
1745
|
const base = basename2(sessionFilePath, ".jsonl");
|
|
1662
1746
|
const timestamp = Date.now();
|
|
1663
1747
|
const body = JSON.stringify(payload, null, 2);
|
|
1664
1748
|
for (let attempt = 0;attempt < 4; attempt++) {
|
|
1665
|
-
const filePath =
|
|
1749
|
+
const filePath = join5(dir, `${base}-compaction-${kind}-${timestamp}-${uuidv7()}.json`);
|
|
1666
1750
|
try {
|
|
1667
1751
|
writeFileSync(filePath, body, { encoding: "utf-8", mode: 384, flag: "wx" });
|
|
1668
1752
|
try {
|
|
@@ -3008,7 +3092,7 @@ function generateId(byId) {
|
|
|
3008
3092
|
var init_session_manager_validation = () => {};
|
|
3009
3093
|
|
|
3010
3094
|
// src/core/session-manager-entries.ts
|
|
3011
|
-
import { join as
|
|
3095
|
+
import { join as join6 } from "path";
|
|
3012
3096
|
function entryBase(byId, parentId) {
|
|
3013
3097
|
return {
|
|
3014
3098
|
id: generateId(byId),
|
|
@@ -3035,7 +3119,7 @@ function createSessionHeader(id, cwd, timestamp = new Date().toISOString(), pare
|
|
|
3035
3119
|
}
|
|
3036
3120
|
function createSessionFilePath(sessionDir, timestamp, sessionId) {
|
|
3037
3121
|
const fileTimestamp = timestamp.replace(/[:.]/g, "-");
|
|
3038
|
-
return
|
|
3122
|
+
return join6(sessionDir, `${fileTimestamp}_${sessionId}.jsonl`);
|
|
3039
3123
|
}
|
|
3040
3124
|
function createMessageEntry(message, byId, parentId) {
|
|
3041
3125
|
return {
|
|
@@ -3166,17 +3250,17 @@ var init_session_manager_entries = __esm(() => {
|
|
|
3166
3250
|
});
|
|
3167
3251
|
|
|
3168
3252
|
// src/core/session-manager-paths.ts
|
|
3169
|
-
import { existsSync as
|
|
3170
|
-
import { join as
|
|
3253
|
+
import { existsSync as existsSync3, mkdirSync } from "fs";
|
|
3254
|
+
import { join as join7 } from "path";
|
|
3171
3255
|
function getDefaultSessionDirPath(cwd, agentDir = getAgentDir()) {
|
|
3172
3256
|
const resolvedCwd = resolvePath(cwd);
|
|
3173
3257
|
const resolvedAgentDir = resolvePath(agentDir);
|
|
3174
3258
|
const safePath = `--${resolvedCwd.replace(/^[/\\]/, "").replace(/[/\\:]/g, "-")}--`;
|
|
3175
|
-
return
|
|
3259
|
+
return join7(resolvedAgentDir, "sessions", safePath);
|
|
3176
3260
|
}
|
|
3177
3261
|
function getDefaultSessionDir(cwd, agentDir = getAgentDir()) {
|
|
3178
3262
|
const sessionDir = getDefaultSessionDirPath(cwd, agentDir);
|
|
3179
|
-
if (!
|
|
3263
|
+
if (!existsSync3(sessionDir)) {
|
|
3180
3264
|
mkdirSync(sessionDir, { recursive: true });
|
|
3181
3265
|
}
|
|
3182
3266
|
return sessionDir;
|
|
@@ -3190,7 +3274,7 @@ var init_session_manager_paths = __esm(() => {
|
|
|
3190
3274
|
import {
|
|
3191
3275
|
appendFileSync,
|
|
3192
3276
|
closeSync,
|
|
3193
|
-
existsSync as
|
|
3277
|
+
existsSync as existsSync4,
|
|
3194
3278
|
mkdirSync as mkdirSync2,
|
|
3195
3279
|
openSync,
|
|
3196
3280
|
readdirSync,
|
|
@@ -3200,7 +3284,7 @@ import {
|
|
|
3200
3284
|
unlinkSync,
|
|
3201
3285
|
writeFileSync as writeFileSync2
|
|
3202
3286
|
} from "fs";
|
|
3203
|
-
import { join as
|
|
3287
|
+
import { join as join8 } from "path";
|
|
3204
3288
|
import { StringDecoder } from "string_decoder";
|
|
3205
3289
|
function parseSessionEntryLine(line) {
|
|
3206
3290
|
if (!line.trim())
|
|
@@ -3213,7 +3297,7 @@ function parseSessionEntryLine(line) {
|
|
|
3213
3297
|
}
|
|
3214
3298
|
function loadEntriesFromFile(filePath) {
|
|
3215
3299
|
const resolvedFilePath = normalizePath(filePath);
|
|
3216
|
-
if (!
|
|
3300
|
+
if (!existsSync4(resolvedFilePath))
|
|
3217
3301
|
return [];
|
|
3218
3302
|
const entries = [];
|
|
3219
3303
|
const fd = openSync(resolvedFilePath, "r");
|
|
@@ -3308,7 +3392,7 @@ function findMostRecentSession(sessionDir, cwd, includeInternal = false) {
|
|
|
3308
3392
|
const resolvedSessionDir = normalizePath(sessionDir);
|
|
3309
3393
|
const resolvedCwd = cwd ? resolvePath(cwd) : undefined;
|
|
3310
3394
|
try {
|
|
3311
|
-
const files = readdirSync(resolvedSessionDir).filter((f) => f.endsWith(".jsonl")).map((f) =>
|
|
3395
|
+
const files = readdirSync(resolvedSessionDir).filter((f) => f.endsWith(".jsonl")).map((f) => join8(resolvedSessionDir, f)).map((path) => ({ path, header: readSessionHeader(path) })).filter((file) => file.header !== null && (!resolvedCwd || sessionCwdMatches(getSessionHeaderCwd(file.header), resolvedCwd)) && (includeInternal || !isInternalHeader(file.header))).map(({ path }) => ({ path, mtime: statSync(path).mtime })).sort((a, b) => b.mtime.getTime() - a.mtime.getTime());
|
|
3312
3396
|
return files[0]?.path || null;
|
|
3313
3397
|
} catch {
|
|
3314
3398
|
return null;
|
|
@@ -3323,7 +3407,7 @@ function writeSessionEntries(filePath, entries) {
|
|
|
3323
3407
|
writeFileSync2(filePath, serializeSessionEntries(entries));
|
|
3324
3408
|
}
|
|
3325
3409
|
function appendSessionPayload(filePath, payload) {
|
|
3326
|
-
const existed =
|
|
3410
|
+
const existed = existsSync4(filePath);
|
|
3327
3411
|
const offset = existed ? statSync(filePath).size : 0;
|
|
3328
3412
|
try {
|
|
3329
3413
|
appendFileSync(filePath, payload);
|
|
@@ -3331,7 +3415,7 @@ function appendSessionPayload(filePath, payload) {
|
|
|
3331
3415
|
try {
|
|
3332
3416
|
if (existed)
|
|
3333
3417
|
truncateSync(filePath, offset);
|
|
3334
|
-
else if (
|
|
3418
|
+
else if (existsSync4(filePath))
|
|
3335
3419
|
unlinkSync(filePath);
|
|
3336
3420
|
} catch (rollbackError) {
|
|
3337
3421
|
throw new AggregateError([writeError, rollbackError], "Session append and rollback failed");
|
|
@@ -3361,7 +3445,7 @@ function persistAppendedEntry(filePath, entries, entry, flushed) {
|
|
|
3361
3445
|
return true;
|
|
3362
3446
|
}
|
|
3363
3447
|
function ensureDirectory(dir) {
|
|
3364
|
-
if (!
|
|
3448
|
+
if (!existsSync4(dir)) {
|
|
3365
3449
|
mkdirSync2(dir, { recursive: true });
|
|
3366
3450
|
}
|
|
3367
3451
|
}
|
|
@@ -3373,7 +3457,7 @@ var init_session_manager_storage = __esm(() => {
|
|
|
3373
3457
|
});
|
|
3374
3458
|
|
|
3375
3459
|
// src/core/session-manager-archive.ts
|
|
3376
|
-
import { join as
|
|
3460
|
+
import { join as join9 } from "path";
|
|
3377
3461
|
function createBackupSnapshot(sessionFile, entries, label = "compact") {
|
|
3378
3462
|
if (!sessionFile)
|
|
3379
3463
|
return;
|
|
@@ -3464,7 +3548,7 @@ function forkSessionFromFile(sourcePath, targetCwd, sessionDir, options) {
|
|
|
3464
3548
|
}
|
|
3465
3549
|
const newSessionId = options?.id ?? createSessionId();
|
|
3466
3550
|
const timestamp = new Date().toISOString();
|
|
3467
|
-
const newSessionFile =
|
|
3551
|
+
const newSessionFile = join9(dir, `${timestamp.replace(/[:.]/g, "-")}_${newSessionId}.jsonl`);
|
|
3468
3552
|
const newHeader = createSessionHeader(newSessionId, resolvedTargetCwd, timestamp, resolvedSourcePath, options?.internal, options?.workflow);
|
|
3469
3553
|
appendSessionEntry(newSessionFile, newHeader);
|
|
3470
3554
|
for (const entry of sourceEntries) {
|
|
@@ -3562,9 +3646,9 @@ var init_session_manager_migrations = __esm(() => {
|
|
|
3562
3646
|
});
|
|
3563
3647
|
|
|
3564
3648
|
// src/core/session-manager-list.ts
|
|
3565
|
-
import { existsSync as
|
|
3649
|
+
import { existsSync as existsSync5 } from "fs";
|
|
3566
3650
|
import { readdir, readFile, stat } from "fs/promises";
|
|
3567
|
-
import { join as
|
|
3651
|
+
import { join as join10 } from "path";
|
|
3568
3652
|
function isMessageWithContent(message) {
|
|
3569
3653
|
return typeof message.role === "string" && "content" in message;
|
|
3570
3654
|
}
|
|
@@ -3713,12 +3797,12 @@ async function buildSessionInfo(filePath) {
|
|
|
3713
3797
|
}
|
|
3714
3798
|
async function listSessionsFromDir(dir, onProgress, progressOffset = 0, progressTotal, includeInternal = false) {
|
|
3715
3799
|
const sessions = [];
|
|
3716
|
-
if (!
|
|
3800
|
+
if (!existsSync5(dir)) {
|
|
3717
3801
|
return sessions;
|
|
3718
3802
|
}
|
|
3719
3803
|
try {
|
|
3720
3804
|
const dirEntries = await readdir(dir);
|
|
3721
|
-
const files = dirEntries.filter((f) => f.endsWith(".jsonl")).map((f) =>
|
|
3805
|
+
const files = dirEntries.filter((f) => f.endsWith(".jsonl")).map((f) => join10(dir, f));
|
|
3722
3806
|
const total = progressTotal ?? files.length;
|
|
3723
3807
|
let loaded = 0;
|
|
3724
3808
|
const results = await mapSessionFilesCooperatively(files, includeInternal, () => {
|
|
@@ -3751,17 +3835,17 @@ async function listAllSessions(sessionDirOrOnProgress, onProgress, includeIntern
|
|
|
3751
3835
|
}
|
|
3752
3836
|
const sessionsDir = getSessionsDir();
|
|
3753
3837
|
try {
|
|
3754
|
-
if (!
|
|
3838
|
+
if (!existsSync5(sessionsDir)) {
|
|
3755
3839
|
return [];
|
|
3756
3840
|
}
|
|
3757
3841
|
const entries = await readdir(sessionsDir, { withFileTypes: true });
|
|
3758
|
-
const dirs = entries.filter((entry) => entry.isDirectory() || entry.isSymbolicLink()).map((entry) =>
|
|
3842
|
+
const dirs = entries.filter((entry) => entry.isDirectory() || entry.isSymbolicLink()).map((entry) => join10(sessionsDir, entry.name));
|
|
3759
3843
|
let totalFiles = 0;
|
|
3760
3844
|
const dirFiles = [];
|
|
3761
3845
|
for (const dir of dirs) {
|
|
3762
3846
|
try {
|
|
3763
3847
|
const files = (await readdir(dir)).filter((f) => f.endsWith(".jsonl"));
|
|
3764
|
-
dirFiles.push(files.map((f) =>
|
|
3848
|
+
dirFiles.push(files.map((f) => join10(dir, f)));
|
|
3765
3849
|
totalFiles += files.length;
|
|
3766
3850
|
} catch {
|
|
3767
3851
|
dirFiles.push([]);
|
|
@@ -3798,7 +3882,7 @@ var init_session_manager_list = __esm(() => {
|
|
|
3798
3882
|
});
|
|
3799
3883
|
|
|
3800
3884
|
// src/core/session-manager-core.ts
|
|
3801
|
-
import { existsSync as
|
|
3885
|
+
import { existsSync as existsSync6, statSync as statSync2 } from "fs";
|
|
3802
3886
|
import { resolve as resolve2 } from "path";
|
|
3803
3887
|
|
|
3804
3888
|
class SessionManager {
|
|
@@ -3831,7 +3915,7 @@ class SessionManager {
|
|
|
3831
3915
|
}
|
|
3832
3916
|
_setSessionFile(sessionFile, preloadedFileEntries) {
|
|
3833
3917
|
this.sessionFile = resolvePath(sessionFile);
|
|
3834
|
-
if (
|
|
3918
|
+
if (existsSync6(this.sessionFile)) {
|
|
3835
3919
|
this.fileEntries = preloadedFileEntries ?? loadEntriesFromFile(this.sessionFile);
|
|
3836
3920
|
if (this.fileEntries.length === 0) {
|
|
3837
3921
|
const explicitPath = this.sessionFile;
|
|
@@ -4552,7 +4636,7 @@ var init_agent_session_auto_compaction = __esm(() => {
|
|
|
4552
4636
|
});
|
|
4553
4637
|
|
|
4554
4638
|
// src/utils/shell.ts
|
|
4555
|
-
import { existsSync as
|
|
4639
|
+
import { existsSync as existsSync7 } from "node:fs";
|
|
4556
4640
|
import { delimiter } from "node:path";
|
|
4557
4641
|
import { spawn, spawnSync } from "child_process";
|
|
4558
4642
|
function isLegacyWslBashPath(path) {
|
|
@@ -4572,7 +4656,7 @@ function findBashOnPath() {
|
|
|
4572
4656
|
});
|
|
4573
4657
|
if (result.status === 0 && result.stdout) {
|
|
4574
4658
|
const firstMatch = result.stdout.trim().split(/\r?\n/)[0];
|
|
4575
|
-
if (firstMatch &&
|
|
4659
|
+
if (firstMatch && existsSync7(firstMatch)) {
|
|
4576
4660
|
return firstMatch;
|
|
4577
4661
|
}
|
|
4578
4662
|
}
|
|
@@ -4596,7 +4680,7 @@ function findBashOnPath() {
|
|
|
4596
4680
|
}
|
|
4597
4681
|
function getShellConfig(customShellPath) {
|
|
4598
4682
|
if (customShellPath) {
|
|
4599
|
-
if (
|
|
4683
|
+
if (existsSync7(customShellPath)) {
|
|
4600
4684
|
return getBashShellConfig(customShellPath);
|
|
4601
4685
|
}
|
|
4602
4686
|
throw new Error(`Custom shell path not found: ${customShellPath}`);
|
|
@@ -4612,7 +4696,7 @@ function getShellConfig(customShellPath) {
|
|
|
4612
4696
|
paths.push(`${programFilesX86}\\Git\\bin\\bash.exe`);
|
|
4613
4697
|
}
|
|
4614
4698
|
for (const path of paths) {
|
|
4615
|
-
if (
|
|
4699
|
+
if (existsSync7(path)) {
|
|
4616
4700
|
return getBashShellConfig(path);
|
|
4617
4701
|
}
|
|
4618
4702
|
}
|
|
@@ -4629,7 +4713,7 @@ function getShellConfig(customShellPath) {
|
|
|
4629
4713
|
${paths.map((p) => ` ${p}`).join(`
|
|
4630
4714
|
`)}`);
|
|
4631
4715
|
}
|
|
4632
|
-
if (
|
|
4716
|
+
if (existsSync7("/bin/bash")) {
|
|
4633
4717
|
return getBashShellConfig("/bin/bash");
|
|
4634
4718
|
}
|
|
4635
4719
|
const bashOnPath = findBashOnPath();
|
|
@@ -4883,7 +4967,7 @@ var init_windows_directory_security = __esm(() => {
|
|
|
4883
4967
|
import { createHash } from "node:crypto";
|
|
4884
4968
|
import { chmodSync as chmodSync2, lstatSync, mkdirSync as mkdirSync3, realpathSync as realpathSync2, rmSync } from "node:fs";
|
|
4885
4969
|
import { tmpdir, userInfo } from "node:os";
|
|
4886
|
-
import { dirname as
|
|
4970
|
+
import { dirname as dirname5, join as join11, sep as sep2 } from "node:path";
|
|
4887
4971
|
function sanitizeTempPathComponent(value, fallback) {
|
|
4888
4972
|
const collapsed = value.replace(/[^a-zA-Z0-9._-]+/g, "_");
|
|
4889
4973
|
let start = 0;
|
|
@@ -4940,11 +5024,11 @@ function baseTempDirs() {
|
|
|
4940
5024
|
}
|
|
4941
5025
|
function getTempRootDir() {
|
|
4942
5026
|
const app = sanitizeTempPathComponent(APP_NAME, "atomic");
|
|
4943
|
-
return
|
|
5027
|
+
return join11(baseTempDirs().raw, `${app}-${ownerComponent()}`);
|
|
4944
5028
|
}
|
|
4945
5029
|
function resolveSessionTempDirPath(sessionId) {
|
|
4946
5030
|
const id = sessionId ?? activeSessionId ?? `pid-${process.pid}`;
|
|
4947
|
-
return
|
|
5031
|
+
return join11(getTempRootDir(), sanitizeTempPathComponent(id, FALLBACK_SESSION_COMPONENT));
|
|
4948
5032
|
}
|
|
4949
5033
|
function isRealDirectory(path) {
|
|
4950
5034
|
try {
|
|
@@ -5018,7 +5102,7 @@ function canonicalTempChild(dir, base) {
|
|
|
5018
5102
|
for (const candidate of [base.raw, base.canonical]) {
|
|
5019
5103
|
const prefix = `${candidate}${sep2}`;
|
|
5020
5104
|
if (dir.startsWith(prefix)) {
|
|
5021
|
-
return
|
|
5105
|
+
return join11(base.canonical, dir.slice(prefix.length));
|
|
5022
5106
|
}
|
|
5023
5107
|
}
|
|
5024
5108
|
return;
|
|
@@ -5031,13 +5115,13 @@ function ensureTempDir(dir) {
|
|
|
5031
5115
|
const parts = checkedDir.slice(prefix.length).split(sep2).filter((part) => part.length > 0);
|
|
5032
5116
|
let current = base.canonical;
|
|
5033
5117
|
for (const part of parts.slice(0, -1)) {
|
|
5034
|
-
current =
|
|
5118
|
+
current = join11(current, part);
|
|
5035
5119
|
ensureOwnedDirectory(current);
|
|
5036
5120
|
}
|
|
5037
5121
|
ensureLeafDirectory(checkedDir);
|
|
5038
5122
|
} else {
|
|
5039
5123
|
if (!(ensuredDirs.has(dir) && isRealDirectory(dir))) {
|
|
5040
|
-
mkdirSync3(
|
|
5124
|
+
mkdirSync3(dirname5(dir), { recursive: true, mode: SESSION_TEMP_DIR_MODE });
|
|
5041
5125
|
ensureLeafDirectory(dir);
|
|
5042
5126
|
}
|
|
5043
5127
|
}
|
|
@@ -5483,7 +5567,7 @@ var init_truncate = __esm(() => {
|
|
|
5483
5567
|
|
|
5484
5568
|
// src/core/bash-executor.ts
|
|
5485
5569
|
import { randomBytes } from "node:crypto";
|
|
5486
|
-
import { join as
|
|
5570
|
+
import { join as join12 } from "node:path";
|
|
5487
5571
|
async function executeBashWithOperations(command, cwd, operations, options) {
|
|
5488
5572
|
const outputChunks = [];
|
|
5489
5573
|
let outputBytes = 0;
|
|
@@ -5499,7 +5583,7 @@ async function executeBashWithOperations(command, cwd, operations, options) {
|
|
|
5499
5583
|
try {
|
|
5500
5584
|
const dir = ensureSessionTempDir(options?.sessionTempDir);
|
|
5501
5585
|
const id = randomBytes(8).toString("hex");
|
|
5502
|
-
tempFilePath =
|
|
5586
|
+
tempFilePath = join12(dir, `${APP_NAME}-bash-${id}.log`);
|
|
5503
5587
|
tempFile = new PersistedOutputFile(tempFilePath);
|
|
5504
5588
|
} catch {
|
|
5505
5589
|
tempFileUnavailable = true;
|
|
@@ -7308,10 +7392,10 @@ var init_bash_session_environment = __esm(() => {
|
|
|
7308
7392
|
|
|
7309
7393
|
// src/core/tools/output-accumulator.ts
|
|
7310
7394
|
import { randomBytes as randomBytes2 } from "node:crypto";
|
|
7311
|
-
import { join as
|
|
7395
|
+
import { join as join15 } from "node:path";
|
|
7312
7396
|
function defaultTempFilePath(prefix, tempDir) {
|
|
7313
7397
|
const id = randomBytes2(8).toString("hex");
|
|
7314
|
-
return
|
|
7398
|
+
return join15(ensureSessionTempDir(tempDir), `${prefix}-${id}.log`);
|
|
7315
7399
|
}
|
|
7316
7400
|
function byteLength(text) {
|
|
7317
7401
|
return Buffer.byteLength(text, "utf-8");
|
|
@@ -7593,9 +7677,9 @@ var init_search_native = __esm(() => {
|
|
|
7593
7677
|
});
|
|
7594
7678
|
|
|
7595
7679
|
// src/core/tools/resource-selectors.ts
|
|
7596
|
-
import { existsSync as
|
|
7680
|
+
import { existsSync as existsSync10, mkdirSync as mkdirSync4, readFileSync as readFileSync4, realpathSync as realpathSync4, rmSync as rmSync2, writeFileSync as writeFileSync3 } from "node:fs";
|
|
7597
7681
|
import { createRequire as createRequire3 } from "node:module";
|
|
7598
|
-
import { dirname as
|
|
7682
|
+
import { dirname as dirname6, isAbsolute as isAbsolute2, relative as relative2, resolve as resolve3 } from "node:path";
|
|
7599
7683
|
import { deflateRawSync, gunzipSync, gzipSync, inflateRawSync } from "node:zlib";
|
|
7600
7684
|
function toSqliteBindValues(params) {
|
|
7601
7685
|
return params.map((param) => typeof param === "boolean" ? param ? 1 : 0 : param);
|
|
@@ -7633,9 +7717,9 @@ function sqliteDatabase() {
|
|
|
7633
7717
|
}
|
|
7634
7718
|
}
|
|
7635
7719
|
function existingSqliteFile(path3) {
|
|
7636
|
-
if (!
|
|
7720
|
+
if (!existsSync10(path3))
|
|
7637
7721
|
return;
|
|
7638
|
-
return
|
|
7722
|
+
return readFileSync4(path3).subarray(0, 16).toString("binary") === "SQLite format 3\x00";
|
|
7639
7723
|
}
|
|
7640
7724
|
function sqliteSelectorForPath(value, cwd) {
|
|
7641
7725
|
const selector = parseSqliteSelector(value);
|
|
@@ -7749,7 +7833,7 @@ function readZipEntriesFromBuffer(buf, label) {
|
|
|
7749
7833
|
return entries;
|
|
7750
7834
|
}
|
|
7751
7835
|
function readZipEntries(path3) {
|
|
7752
|
-
return readZipEntriesFromBuffer(
|
|
7836
|
+
return readZipEntriesFromBuffer(readFileSync4(path3), path3);
|
|
7753
7837
|
}
|
|
7754
7838
|
function writeZipEntries(path3, entries) {
|
|
7755
7839
|
const locals = [], centrals = [];
|
|
@@ -7788,7 +7872,7 @@ function writeZipEntries(path3, entries) {
|
|
|
7788
7872
|
writeFileSync3(path3, Buffer.concat([...locals, ...centrals, eocd]));
|
|
7789
7873
|
}
|
|
7790
7874
|
function parseTar(path3) {
|
|
7791
|
-
const raw =
|
|
7875
|
+
const raw = readFileSync4(path3);
|
|
7792
7876
|
if (raw.length > MAX_TAR_ARCHIVE_BYTES)
|
|
7793
7877
|
throw new Error(`Archive too large: ${path3}`);
|
|
7794
7878
|
const buf = isGzipTar(path3) ? gunzipSync(raw, { maxOutputLength: MAX_TAR_ARCHIVE_BYTES }) : raw;
|
|
@@ -7860,7 +7944,7 @@ function listArchiveDirectory(names, memberPath) {
|
|
|
7860
7944
|
`);
|
|
7861
7945
|
}
|
|
7862
7946
|
function readZipSelector(path3, memberPath) {
|
|
7863
|
-
const buf =
|
|
7947
|
+
const buf = readFileSync4(path3);
|
|
7864
7948
|
let eocd = -1;
|
|
7865
7949
|
for (let i = buf.length - 22;i >= 0; i--)
|
|
7866
7950
|
if (buf.readUInt32LE(i) === 101010256) {
|
|
@@ -7922,7 +8006,7 @@ function validateArchiveMemberPath(memberPath) {
|
|
|
7922
8006
|
throw new Error(`Invalid archive member path: ${memberPath}`);
|
|
7923
8007
|
}
|
|
7924
8008
|
function writeZipEntrySelective(path3, memberPath, data) {
|
|
7925
|
-
const source =
|
|
8009
|
+
const source = existsSync10(path3) ? readFileSync4(path3) : Buffer.alloc(0);
|
|
7926
8010
|
const locals = [], centrals = [];
|
|
7927
8011
|
let offset = 0;
|
|
7928
8012
|
if (source.length > 0) {
|
|
@@ -7958,7 +8042,7 @@ function writeZipEntrySelective(path3, memberPath, data) {
|
|
|
7958
8042
|
}
|
|
7959
8043
|
const tmp = `${path3}.atomic-entry-${Date.now()}`;
|
|
7960
8044
|
writeZipEntries(tmp, new Map([[memberPath, data]]));
|
|
7961
|
-
const built =
|
|
8045
|
+
const built = readFileSync4(tmp);
|
|
7962
8046
|
rmSync2(tmp, { force: true });
|
|
7963
8047
|
const eocdStart = built.length - 22, localLen = built.readUInt32LE(eocdStart + 16), centralSizeOne = built.readUInt32LE(eocdStart + 12);
|
|
7964
8048
|
const central = Buffer.from(built.subarray(localLen, localLen + centralSizeOne));
|
|
@@ -7976,12 +8060,12 @@ function writeZipEntrySelective(path3, memberPath, data) {
|
|
|
7976
8060
|
}
|
|
7977
8061
|
function writeArchiveSelector(selector, content) {
|
|
7978
8062
|
validateArchiveMemberPath(selector.memberPath);
|
|
7979
|
-
mkdirSync4(
|
|
8063
|
+
mkdirSync4(dirname6(selector.archivePath), { recursive: true });
|
|
7980
8064
|
if (isZipArchive(selector.archivePath)) {
|
|
7981
8065
|
writeZipEntrySelective(selector.archivePath, selector.memberPath, Buffer.from(content));
|
|
7982
8066
|
return;
|
|
7983
8067
|
}
|
|
7984
|
-
const entries =
|
|
8068
|
+
const entries = existsSync10(selector.archivePath) ? parseTar(selector.archivePath) : new Map;
|
|
7985
8069
|
entries.set(selector.memberPath, Buffer.from(content));
|
|
7986
8070
|
writeTar(selector.archivePath, entries);
|
|
7987
8071
|
}
|
|
@@ -8117,8 +8201,8 @@ function isContained(root, candidate) {
|
|
|
8117
8201
|
}
|
|
8118
8202
|
function nearestExistingAncestor(pathValue) {
|
|
8119
8203
|
let current = pathValue;
|
|
8120
|
-
while (!
|
|
8121
|
-
const parent =
|
|
8204
|
+
while (!existsSync10(current)) {
|
|
8205
|
+
const parent = dirname6(current);
|
|
8122
8206
|
if (parent === current)
|
|
8123
8207
|
return current;
|
|
8124
8208
|
current = parent;
|
|
@@ -8143,7 +8227,7 @@ function fallbackInternalPath(value, cwd) {
|
|
|
8143
8227
|
const skill = value.match(/^skill:\/\/([^/]+)(?:\/(.*))?$/);
|
|
8144
8228
|
if (skill) {
|
|
8145
8229
|
const name = skill[1] ?? "", rest = skill[2] || "SKILL.md";
|
|
8146
|
-
return [".agents/skills", "packages/subagents/skills", "packages/workflows/skills"].map((base) => resolveContainedPath(resolveContainedLocalPath(cwd, base, "skill:// resource"), `${name}/${rest}`, "skill:// resource")).find((candidate) =>
|
|
8230
|
+
return [".agents/skills", "packages/subagents/skills", "packages/workflows/skills"].map((base) => resolveContainedPath(resolveContainedLocalPath(cwd, base, "skill:// resource"), `${name}/${rest}`, "skill:// resource")).find((candidate) => existsSync10(candidate));
|
|
8147
8231
|
}
|
|
8148
8232
|
const local = value.match(/^local:\/\/(.+)$/);
|
|
8149
8233
|
if (local)
|
|
@@ -8161,9 +8245,9 @@ async function readInternalSelector(value, cwd, context) {
|
|
|
8161
8245
|
if (Buffer.isBuffer(routed))
|
|
8162
8246
|
return routed.toString("utf8");
|
|
8163
8247
|
const resolved = await resolveViaRouter(value, cwd, context);
|
|
8164
|
-
if (!resolved || !
|
|
8248
|
+
if (!resolved || !existsSync10(resolved))
|
|
8165
8249
|
throw new Error(`Internal resource not found or no session router supports it: ${value}`);
|
|
8166
|
-
return
|
|
8250
|
+
return readFileSync4(resolved, "utf8");
|
|
8167
8251
|
}
|
|
8168
8252
|
async function writeInternalSelector(value, cwd, content, context) {
|
|
8169
8253
|
const router = routerFromContext(context);
|
|
@@ -8174,7 +8258,7 @@ async function writeInternalSelector(value, cwd, content, context) {
|
|
|
8174
8258
|
const resolved = await resolveViaRouter(value, cwd, context);
|
|
8175
8259
|
if (!resolved)
|
|
8176
8260
|
throw new Error(`Unsupported writable internal resource without a session router: ${value}`);
|
|
8177
|
-
mkdirSync4(
|
|
8261
|
+
mkdirSync4(dirname6(resolved), { recursive: true });
|
|
8178
8262
|
writeFileSync3(resolved, content);
|
|
8179
8263
|
}
|
|
8180
8264
|
async function searchInternalSelector(value, cwd, pattern, ignoreCase = false, literal = false, context, contextBefore = 1, contextAfter = 3) {
|
|
@@ -8456,7 +8540,7 @@ function parseLooseJsonObject(content) {
|
|
|
8456
8540
|
function writeSqliteSelector(selector, content) {
|
|
8457
8541
|
if (!selector.table)
|
|
8458
8542
|
throw new Error("SQLite write target must include a table name");
|
|
8459
|
-
if (!
|
|
8543
|
+
if (!existsSync10(selector.databasePath))
|
|
8460
8544
|
throw new Error(`SQLite database does not exist: ${selector.databasePath}`);
|
|
8461
8545
|
if (content.trim() === "") {
|
|
8462
8546
|
if (!selector.rowId)
|
|
@@ -9229,12 +9313,12 @@ var init_agent_session_bash = __esm(() => {
|
|
|
9229
9313
|
});
|
|
9230
9314
|
|
|
9231
9315
|
// src/core/auth-guidance.ts
|
|
9232
|
-
import { join as
|
|
9316
|
+
import { join as join16 } from "node:path";
|
|
9233
9317
|
function getProviderLoginHelp() {
|
|
9234
9318
|
return [
|
|
9235
9319
|
"Use /login to log into a provider via OAuth or API key. See:",
|
|
9236
|
-
` ${
|
|
9237
|
-
` ${
|
|
9320
|
+
` ${join16(getDocsPath(), "providers.md")}`,
|
|
9321
|
+
` ${join16(getDocsPath(), "models.md")}`
|
|
9238
9322
|
].join(`
|
|
9239
9323
|
`);
|
|
9240
9324
|
}
|
|
@@ -10408,10 +10492,10 @@ function getUsageCostBreakdown(entries) {
|
|
|
10408
10492
|
}
|
|
10409
10493
|
|
|
10410
10494
|
// src/core/export-html/template-script.ts
|
|
10411
|
-
import { readFileSync as
|
|
10412
|
-
import { join as
|
|
10495
|
+
import { readFileSync as readFileSync5 } from "fs";
|
|
10496
|
+
import { join as join17 } from "path";
|
|
10413
10497
|
function readExportHtmlTemplateScript(templateDir) {
|
|
10414
|
-
return EXPORT_HTML_TEMPLATE_SCRIPT_CHUNKS.map((fileName) =>
|
|
10498
|
+
return EXPORT_HTML_TEMPLATE_SCRIPT_CHUNKS.map((fileName) => readFileSync5(join17(templateDir, "template-js", fileName), "utf-8")).join("");
|
|
10415
10499
|
}
|
|
10416
10500
|
var EXPORT_HTML_TEMPLATE_SCRIPT_CHUNKS;
|
|
10417
10501
|
var init_template_script = __esm(() => {
|
|
@@ -10430,8 +10514,8 @@ __export(exports_export_html, {
|
|
|
10430
10514
|
exportFromFile: () => exportFromFile,
|
|
10431
10515
|
exportSessionToHtml: () => exportSessionToHtml
|
|
10432
10516
|
});
|
|
10433
|
-
import { existsSync as
|
|
10434
|
-
import { basename as basename3, join as
|
|
10517
|
+
import { existsSync as existsSync11, readFileSync as readFileSync6, writeFileSync as writeFileSync4 } from "fs";
|
|
10518
|
+
import { basename as basename3, join as join18 } from "path";
|
|
10435
10519
|
function parseColor(color) {
|
|
10436
10520
|
const hexMatch = color.match(/^#([0-9a-fA-F]{2})([0-9a-fA-F]{2})([0-9a-fA-F]{2})$/);
|
|
10437
10521
|
if (hexMatch) {
|
|
@@ -10506,11 +10590,11 @@ function generateThemeVars(themeName) {
|
|
|
10506
10590
|
}
|
|
10507
10591
|
function generateHtml(sessionData, themeName) {
|
|
10508
10592
|
const templateDir = getExportTemplateDir();
|
|
10509
|
-
const template =
|
|
10510
|
-
const templateCss =
|
|
10593
|
+
const template = readFileSync6(join18(templateDir, "template.html"), "utf-8");
|
|
10594
|
+
const templateCss = readFileSync6(join18(templateDir, "template.css"), "utf-8");
|
|
10511
10595
|
const templateJs = readExportHtmlTemplateScript(templateDir);
|
|
10512
|
-
const markedJs =
|
|
10513
|
-
const hljsJs =
|
|
10596
|
+
const markedJs = readFileSync6(join18(templateDir, "vendor", "marked.min.js"), "utf-8");
|
|
10597
|
+
const hljsJs = readFileSync6(join18(templateDir, "vendor", "highlight.min.js"), "utf-8");
|
|
10514
10598
|
const themeVars = generateThemeVars(themeName);
|
|
10515
10599
|
const colors = getResolvedThemeColors(themeName);
|
|
10516
10600
|
const themeExport = getThemeExportColors(themeName);
|
|
@@ -10561,7 +10645,7 @@ async function exportSessionToHtml(sm, state, options) {
|
|
|
10561
10645
|
if (!sessionFile) {
|
|
10562
10646
|
throw new Error("Cannot export in-memory session to HTML");
|
|
10563
10647
|
}
|
|
10564
|
-
if (!
|
|
10648
|
+
if (!existsSync11(sessionFile)) {
|
|
10565
10649
|
throw new Error("Nothing to export yet - start a conversation first");
|
|
10566
10650
|
}
|
|
10567
10651
|
const entries = sm.getEntries();
|
|
@@ -10592,7 +10676,7 @@ async function exportSessionToHtml(sm, state, options) {
|
|
|
10592
10676
|
async function exportFromFile(inputPath, options) {
|
|
10593
10677
|
const opts = typeof options === "string" ? { outputPath: options } : options || {};
|
|
10594
10678
|
const resolvedInputPath = resolvePath(inputPath);
|
|
10595
|
-
if (!
|
|
10679
|
+
if (!existsSync11(resolvedInputPath)) {
|
|
10596
10680
|
throw new Error(`File not found: ${resolvedInputPath}`);
|
|
10597
10681
|
}
|
|
10598
10682
|
const sm = SessionManager.open(resolvedInputPath);
|
|
@@ -10894,8 +10978,8 @@ var init_tool_renderer = __esm(() => {
|
|
|
10894
10978
|
});
|
|
10895
10979
|
|
|
10896
10980
|
// src/core/agent-session-export.ts
|
|
10897
|
-
import { existsSync as
|
|
10898
|
-
import { dirname as
|
|
10981
|
+
import { existsSync as existsSync12, mkdirSync as mkdirSync5, writeFileSync as writeFileSync5 } from "node:fs";
|
|
10982
|
+
import { dirname as dirname7 } from "node:path";
|
|
10899
10983
|
function getSessionStats() {
|
|
10900
10984
|
let userMessages = 0;
|
|
10901
10985
|
let assistantMessages = 0;
|
|
@@ -10999,8 +11083,8 @@ async function exportToHtml(outputPath, options = {}) {
|
|
|
10999
11083
|
}
|
|
11000
11084
|
function exportToJsonl(outputPath) {
|
|
11001
11085
|
const filePath = resolvePath(outputPath ?? `session-${new Date().toISOString().replace(/[:.]/g, "-")}.jsonl`, process.cwd());
|
|
11002
|
-
const dir =
|
|
11003
|
-
if (!
|
|
11086
|
+
const dir = dirname7(filePath);
|
|
11087
|
+
if (!existsSync12(dir)) {
|
|
11004
11088
|
mkdirSync5(dir, { recursive: true });
|
|
11005
11089
|
}
|
|
11006
11090
|
const header = {
|
|
@@ -11084,8 +11168,8 @@ var init_loader_runtime = __esm(() => {
|
|
|
11084
11168
|
});
|
|
11085
11169
|
|
|
11086
11170
|
// src/core/tools/artifacts.ts
|
|
11087
|
-
import { existsSync as
|
|
11088
|
-
import { join as
|
|
11171
|
+
import { existsSync as existsSync13, mkdirSync as mkdirSync6, readdirSync as readdirSync3, writeFileSync as writeFileSync6 } from "node:fs";
|
|
11172
|
+
import { join as join19 } from "node:path";
|
|
11089
11173
|
|
|
11090
11174
|
class ArtifactManager {
|
|
11091
11175
|
#nextId = 0;
|
|
@@ -11102,7 +11186,7 @@ class ArtifactManager {
|
|
|
11102
11186
|
return;
|
|
11103
11187
|
this.#initialized = true;
|
|
11104
11188
|
let max = -1;
|
|
11105
|
-
if (
|
|
11189
|
+
if (existsSync13(this.#dir)) {
|
|
11106
11190
|
for (const name of readdirSync3(this.#dir)) {
|
|
11107
11191
|
const match = name.match(/^(\d+)\..*\.log$/);
|
|
11108
11192
|
if (match) {
|
|
@@ -11117,30 +11201,30 @@ class ArtifactManager {
|
|
|
11117
11201
|
allocate(toolType) {
|
|
11118
11202
|
this.#init();
|
|
11119
11203
|
const id = String(this.#nextId++);
|
|
11120
|
-
const path3 =
|
|
11204
|
+
const path3 = join19(this.#dir, `${id}.${toolType}.log`);
|
|
11121
11205
|
return { path: path3, id };
|
|
11122
11206
|
}
|
|
11123
11207
|
save(content, toolType) {
|
|
11124
11208
|
this.#init();
|
|
11125
11209
|
const { path: path3, id } = this.allocate(toolType);
|
|
11126
|
-
if (!
|
|
11210
|
+
if (!existsSync13(this.#dir))
|
|
11127
11211
|
mkdirSync6(this.#dir, { recursive: true });
|
|
11128
11212
|
writeFileSync6(path3, content, "utf8");
|
|
11129
11213
|
return id;
|
|
11130
11214
|
}
|
|
11131
11215
|
resolve(id) {
|
|
11132
11216
|
this.#init();
|
|
11133
|
-
if (!
|
|
11217
|
+
if (!existsSync13(this.#dir))
|
|
11134
11218
|
return;
|
|
11135
11219
|
const prefix = `${id}.`;
|
|
11136
11220
|
for (const name of readdirSync3(this.#dir))
|
|
11137
11221
|
if (name.startsWith(prefix) && name.endsWith(".log"))
|
|
11138
|
-
return
|
|
11222
|
+
return join19(this.#dir, name);
|
|
11139
11223
|
return;
|
|
11140
11224
|
}
|
|
11141
11225
|
list() {
|
|
11142
11226
|
this.#init();
|
|
11143
|
-
if (!
|
|
11227
|
+
if (!existsSync13(this.#dir))
|
|
11144
11228
|
return [];
|
|
11145
11229
|
const ids = [];
|
|
11146
11230
|
for (const name of readdirSync3(this.#dir)) {
|
|
@@ -11165,7 +11249,7 @@ var init_artifacts = __esm(() => {
|
|
|
11165
11249
|
});
|
|
11166
11250
|
|
|
11167
11251
|
// src/core/tools/artifact-protocol.ts
|
|
11168
|
-
import { existsSync as
|
|
11252
|
+
import { existsSync as existsSync14, readFileSync as readFileSync7 } from "node:fs";
|
|
11169
11253
|
function registerArtifactDir(dir) {
|
|
11170
11254
|
activeArtifactDirs.add(dir);
|
|
11171
11255
|
}
|
|
@@ -11210,9 +11294,9 @@ function createArtifactRouter(getPinnedDirs) {
|
|
|
11210
11294
|
if (!/^artifact:\/\//i.test(url))
|
|
11211
11295
|
return;
|
|
11212
11296
|
const path3 = resolveArtifactUrl(url, getPinnedDirs());
|
|
11213
|
-
if (!path3 || !
|
|
11297
|
+
if (!path3 || !existsSync14(path3))
|
|
11214
11298
|
throw new Error(`Artifact not found: ${url}`);
|
|
11215
|
-
return
|
|
11299
|
+
return readFileSync7(path3, "utf8");
|
|
11216
11300
|
}
|
|
11217
11301
|
};
|
|
11218
11302
|
}
|
|
@@ -11223,7 +11307,7 @@ var init_artifact_protocol = __esm(() => {
|
|
|
11223
11307
|
});
|
|
11224
11308
|
|
|
11225
11309
|
// src/core/extensions/runner-context.ts
|
|
11226
|
-
import { join as
|
|
11310
|
+
import { join as join20 } from "node:path";
|
|
11227
11311
|
function deepFrozenCopy(value) {
|
|
11228
11312
|
if (Array.isArray(value))
|
|
11229
11313
|
return Object.freeze(value.map(deepFrozenCopy));
|
|
@@ -11283,7 +11367,7 @@ function createExtensionContext(source) {
|
|
|
11283
11367
|
const sessionDir = source.getSessionManager().getSessionDir();
|
|
11284
11368
|
if (!sessionDir)
|
|
11285
11369
|
return;
|
|
11286
|
-
const artifactsDir =
|
|
11370
|
+
const artifactsDir = join20(sessionDir, "artifacts");
|
|
11287
11371
|
registerArtifactDir(artifactsDir);
|
|
11288
11372
|
return createArtifactRouter(() => [artifactsDir]);
|
|
11289
11373
|
},
|
|
@@ -12196,7 +12280,7 @@ var init_runner = __esm(() => {
|
|
|
12196
12280
|
|
|
12197
12281
|
// src/core/skill-catalog.ts
|
|
12198
12282
|
import { createHash as createHash2 } from "node:crypto";
|
|
12199
|
-
import { basename as basename4, dirname as
|
|
12283
|
+
import { basename as basename4, dirname as dirname8, sep as sep3 } from "node:path";
|
|
12200
12284
|
function candidateId(skill) {
|
|
12201
12285
|
return `skill_${createHash2("sha256").update(canonicalizePath(skill.filePath)).digest("hex").slice(0, 20)}`;
|
|
12202
12286
|
}
|
|
@@ -12240,7 +12324,7 @@ function sourceLabel(skill) {
|
|
|
12240
12324
|
}
|
|
12241
12325
|
const pathParts = canonicalizePath(skill.filePath).split(sep3).filter(Boolean);
|
|
12242
12326
|
const configPart = [...pathParts].reverse().find((part) => part === ".atomic" || part === ".pi" || part === ".agents");
|
|
12243
|
-
return configPart ? configPart.slice(1) : readableToken(basename4(skill.sourceInfo.baseDir ??
|
|
12327
|
+
return configPart ? configPart.slice(1) : readableToken(basename4(skill.sourceInfo.baseDir ?? dirname8(skill.filePath)));
|
|
12244
12328
|
}
|
|
12245
12329
|
function uniquePathLabels(candidates) {
|
|
12246
12330
|
const labels = new Map(candidates.map((candidate) => [candidate.id, sourceLabel(candidate.skill)]));
|
|
@@ -12254,7 +12338,7 @@ function uniquePathLabels(candidates) {
|
|
|
12254
12338
|
for (const [label, matching] of byLabel) {
|
|
12255
12339
|
if (matching.length === 1)
|
|
12256
12340
|
continue;
|
|
12257
|
-
const pathParts = matching.map((candidate) => canonicalizePath(
|
|
12341
|
+
const pathParts = matching.map((candidate) => canonicalizePath(dirname8(candidate.skill.filePath)).split(sep3).filter(Boolean));
|
|
12258
12342
|
for (let depth = 1;depth <= Math.max(...pathParts.map((parts) => parts.length)); depth++) {
|
|
12259
12343
|
const suffixes = pathParts.map((parts) => parts.slice(-depth).join("/"));
|
|
12260
12344
|
if (new Set(suffixes).size !== suffixes.length)
|
|
@@ -12427,7 +12511,7 @@ var init_skill_catalog = __esm(() => {
|
|
|
12427
12511
|
});
|
|
12428
12512
|
|
|
12429
12513
|
// src/core/agent-session-extension-bindings.ts
|
|
12430
|
-
import { basename as basename5, dirname as
|
|
12514
|
+
import { basename as basename5, dirname as dirname9 } from "node:path";
|
|
12431
12515
|
import { resetApiProviders } from "@bastani/pi-ai/compat";
|
|
12432
12516
|
async function bindExtensions(bindings) {
|
|
12433
12517
|
if (bindings.uiContext !== undefined) {
|
|
@@ -12475,7 +12559,7 @@ function buildExtensionResourcePaths(entries) {
|
|
|
12475
12559
|
const extension = extensions.find((candidate) => candidate.path === entry.extensionPath || candidate.resolvedPath === entry.extensionPath || candidate.sourceInfo.path === entry.extensionPath);
|
|
12476
12560
|
const sourceInfo = extension?.sourceInfo;
|
|
12477
12561
|
const source = sourceInfo?.source ?? this.getExtensionSourceLabel(entry.extensionPath);
|
|
12478
|
-
const baseDir = sourceInfo?.baseDir ?? (entry.extensionPath.startsWith("<") ? undefined :
|
|
12562
|
+
const baseDir = sourceInfo?.baseDir ?? (entry.extensionPath.startsWith("<") ? undefined : dirname9(entry.extensionPath));
|
|
12479
12563
|
return {
|
|
12480
12564
|
path: entry.path,
|
|
12481
12565
|
metadata: {
|
|
@@ -13572,7 +13656,7 @@ var init_frontmatter = () => {};
|
|
|
13572
13656
|
|
|
13573
13657
|
// src/utils/changelog.ts
|
|
13574
13658
|
import path3 from "node:path";
|
|
13575
|
-
import { existsSync as
|
|
13659
|
+
import { existsSync as existsSync15, readFileSync as readFileSync8 } from "fs";
|
|
13576
13660
|
function parsedVersionFromMatch(match) {
|
|
13577
13661
|
return {
|
|
13578
13662
|
version: match[1],
|
|
@@ -13666,11 +13750,11 @@ function normalizeChangelogLinks(markdown, version) {
|
|
|
13666
13750
|
});
|
|
13667
13751
|
}
|
|
13668
13752
|
function parseChangelog(changelogPath) {
|
|
13669
|
-
if (!
|
|
13753
|
+
if (!existsSync15(changelogPath)) {
|
|
13670
13754
|
return [];
|
|
13671
13755
|
}
|
|
13672
13756
|
try {
|
|
13673
|
-
const content =
|
|
13757
|
+
const content = readFileSync8(changelogPath, "utf-8");
|
|
13674
13758
|
const lines = content.split(`
|
|
13675
13759
|
`);
|
|
13676
13760
|
const entries = [];
|
|
@@ -14169,7 +14253,7 @@ var init_prompt_templates = __esm(() => {
|
|
|
14169
14253
|
});
|
|
14170
14254
|
|
|
14171
14255
|
// src/core/agent-session-prompt.ts
|
|
14172
|
-
import { readFileSync as
|
|
14256
|
+
import { readFileSync as readFileSync9 } from "node:fs";
|
|
14173
14257
|
async function tryExecuteSessionSlashCommand(session, text) {
|
|
14174
14258
|
if (!text.startsWith("/"))
|
|
14175
14259
|
return false;
|
|
@@ -14441,7 +14525,7 @@ function _expandSkillCommand(text) {
|
|
|
14441
14525
|
}
|
|
14442
14526
|
const { skill, id } = resolution.candidate;
|
|
14443
14527
|
try {
|
|
14444
|
-
const content =
|
|
14528
|
+
const content = readFileSync9(skill.filePath, "utf-8");
|
|
14445
14529
|
const body = stripFrontmatter(content).trim();
|
|
14446
14530
|
const skillBlock = `<skill name="${selector}" location="${skill.filePath}" candidate="${id}">
|
|
14447
14531
|
References are relative to ${skill.baseDir}.
|
|
@@ -16535,7 +16619,7 @@ function assertToolPairingInvariant(messages) {
|
|
|
16535
16619
|
import { Buffer as Buffer3 } from "node:buffer";
|
|
16536
16620
|
import { constants as constants2 } from "node:fs";
|
|
16537
16621
|
import { chmod, lstat, mkdir, open } from "node:fs/promises";
|
|
16538
|
-
import { join as
|
|
16622
|
+
import { join as join22 } from "node:path";
|
|
16539
16623
|
function getPersistenceThreshold(declaredMaxResultSizeChars) {
|
|
16540
16624
|
if (declaredMaxResultSizeChars === undefined) {
|
|
16541
16625
|
return DEFAULT_MAX_RESULT_SIZE_CHARS;
|
|
@@ -16624,14 +16708,14 @@ function sanitizePathComponent(value, fallback) {
|
|
|
16624
16708
|
}
|
|
16625
16709
|
async function ensureToolResultsDir(input) {
|
|
16626
16710
|
if (input.sessionDir?.trim()) {
|
|
16627
|
-
const dir =
|
|
16711
|
+
const dir = join22(input.sessionDir, TOOL_RESULTS_SUBDIR);
|
|
16628
16712
|
await mkdir(dir, { recursive: true, mode: SESSION_TEMP_DIR_MODE });
|
|
16629
16713
|
if (process.platform !== "win32") {
|
|
16630
16714
|
await chmod(dir, SESSION_TEMP_DIR_MODE);
|
|
16631
16715
|
}
|
|
16632
16716
|
return dir;
|
|
16633
16717
|
}
|
|
16634
|
-
return ensureTempDir(
|
|
16718
|
+
return ensureTempDir(join22(resolveSessionTempDirPath(input.sessionId), TOOL_RESULTS_SUBDIR));
|
|
16635
16719
|
}
|
|
16636
16720
|
function isOwnedByCurrentUser(uid) {
|
|
16637
16721
|
const currentUid = typeof process.getuid === "function" ? process.getuid() : undefined;
|
|
@@ -16697,7 +16781,7 @@ async function persistToolOutput(input) {
|
|
|
16697
16781
|
} catch {
|
|
16698
16782
|
return;
|
|
16699
16783
|
}
|
|
16700
|
-
const filepath =
|
|
16784
|
+
const filepath = join22(dir, `${sanitizePathComponent(input.toolCallId, "tool-result")}.txt`);
|
|
16701
16785
|
try {
|
|
16702
16786
|
const handle = await open(filepath, "wx", SESSION_TEMP_FILE_MODE);
|
|
16703
16787
|
try {
|
|
@@ -16964,7 +17048,7 @@ var init_loader_core = __esm(() => {
|
|
|
16964
17048
|
});
|
|
16965
17049
|
|
|
16966
17050
|
// src/core/package-manager-manifest.ts
|
|
16967
|
-
import { join as
|
|
17051
|
+
import { join as join23 } from "node:path";
|
|
16968
17052
|
function isRecord(value) {
|
|
16969
17053
|
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
16970
17054
|
}
|
|
@@ -16987,9 +17071,9 @@ function getManifestFromPackageJson(pkg2) {
|
|
|
16987
17071
|
}
|
|
16988
17072
|
function conventionDirsForResource(packageRoot, resourceType) {
|
|
16989
17073
|
if (resourceType === "workflows") {
|
|
16990
|
-
return [
|
|
17074
|
+
return [join23(packageRoot, "workflows"), join23(packageRoot, "workflow")];
|
|
16991
17075
|
}
|
|
16992
|
-
return [
|
|
17076
|
+
return [join23(packageRoot, resourceType)];
|
|
16993
17077
|
}
|
|
16994
17078
|
function manifestEntriesForResource(manifest, resourceType) {
|
|
16995
17079
|
if (!manifest)
|
|
@@ -17180,14 +17264,14 @@ var init_model_registry = __esm(() => {
|
|
|
17180
17264
|
});
|
|
17181
17265
|
|
|
17182
17266
|
// src/core/tools/ask-user-question/config.ts
|
|
17183
|
-
import { existsSync as
|
|
17267
|
+
import { existsSync as existsSync16, readFileSync as readFileSync10 } from "node:fs";
|
|
17184
17268
|
import { homedir as homedir4 } from "node:os";
|
|
17185
|
-
import { join as
|
|
17269
|
+
import { join as join24 } from "node:path";
|
|
17186
17270
|
function loadConfig() {
|
|
17187
|
-
if (!
|
|
17271
|
+
if (!existsSync16(CONFIG_PATH))
|
|
17188
17272
|
return {};
|
|
17189
17273
|
try {
|
|
17190
|
-
const parsed = JSON.parse(
|
|
17274
|
+
const parsed = JSON.parse(readFileSync10(CONFIG_PATH, "utf-8"));
|
|
17191
17275
|
if (parsed === null || typeof parsed !== "object")
|
|
17192
17276
|
return {};
|
|
17193
17277
|
return parsed;
|
|
@@ -17210,8 +17294,8 @@ function validateGuidanceFields(fields) {
|
|
|
17210
17294
|
}
|
|
17211
17295
|
var CONFIG_DIR, CONFIG_PATH;
|
|
17212
17296
|
var init_config2 = __esm(() => {
|
|
17213
|
-
CONFIG_DIR =
|
|
17214
|
-
CONFIG_PATH =
|
|
17297
|
+
CONFIG_DIR = join24(homedir4(), ".config", "rpiv-ask-user-question");
|
|
17298
|
+
CONFIG_PATH = join24(CONFIG_DIR, "config.json");
|
|
17215
17299
|
});
|
|
17216
17300
|
|
|
17217
17301
|
// src/core/tools/ask-user-question/view/component-binding.ts
|
|
@@ -19715,7 +19799,7 @@ var init_chat_message_renderer = __esm(() => {
|
|
|
19715
19799
|
|
|
19716
19800
|
// src/utils/clipboard-native.ts
|
|
19717
19801
|
import { createRequire as createRequire6 } from "module";
|
|
19718
|
-
import { dirname as
|
|
19802
|
+
import { dirname as dirname11, join as join25 } from "path";
|
|
19719
19803
|
import { pathToFileURL as pathToFileURL3 } from "url";
|
|
19720
19804
|
function loadClipboardNative(requires = [moduleRequire, executableDirRequire]) {
|
|
19721
19805
|
for (const requireClipboard of requires) {
|
|
@@ -19728,7 +19812,7 @@ function loadClipboardNative(requires = [moduleRequire, executableDirRequire]) {
|
|
|
19728
19812
|
var moduleRequire, executableDirRequire, hasDisplay, clipboard;
|
|
19729
19813
|
var init_clipboard_native = __esm(() => {
|
|
19730
19814
|
moduleRequire = createRequire6(import.meta.url);
|
|
19731
|
-
executableDirRequire = createRequire6(pathToFileURL3(
|
|
19815
|
+
executableDirRequire = createRequire6(pathToFileURL3(join25(dirname11(process.execPath), "package.json")).href);
|
|
19732
19816
|
hasDisplay = process.platform !== "linux" || Boolean(process.env.DISPLAY || process.env.WAYLAND_DISPLAY);
|
|
19733
19817
|
clipboard = !process.env.TERMUX_VERSION && hasDisplay ? loadClipboardNative() : null;
|
|
19734
19818
|
});
|
|
@@ -19736,9 +19820,9 @@ var init_clipboard_native = __esm(() => {
|
|
|
19736
19820
|
// src/utils/clipboard-image.ts
|
|
19737
19821
|
import { spawnSync as spawnSync3 } from "child_process";
|
|
19738
19822
|
import { randomUUID as randomUUID2 } from "crypto";
|
|
19739
|
-
import { readFileSync as
|
|
19823
|
+
import { readFileSync as readFileSync11, unlinkSync as unlinkSync2 } from "fs";
|
|
19740
19824
|
import { tmpdir as tmpdir2 } from "os";
|
|
19741
|
-
import { join as
|
|
19825
|
+
import { join as join26 } from "path";
|
|
19742
19826
|
function isWaylandSession(env = process.env) {
|
|
19743
19827
|
return Boolean(env.WAYLAND_DISPLAY) || env.XDG_SESSION_TYPE === "wayland";
|
|
19744
19828
|
}
|
|
@@ -19828,14 +19912,14 @@ function isWSL(env = process.env) {
|
|
|
19828
19912
|
return true;
|
|
19829
19913
|
}
|
|
19830
19914
|
try {
|
|
19831
|
-
const release =
|
|
19915
|
+
const release = readFileSync11("/proc/version", "utf-8");
|
|
19832
19916
|
return /microsoft|wsl/i.test(release);
|
|
19833
19917
|
} catch {
|
|
19834
19918
|
return false;
|
|
19835
19919
|
}
|
|
19836
19920
|
}
|
|
19837
19921
|
function readClipboardImageViaPowerShell() {
|
|
19838
|
-
const tmpFile =
|
|
19922
|
+
const tmpFile = join26(tmpdir2(), `pi-wsl-clip-${randomUUID2()}.png`);
|
|
19839
19923
|
try {
|
|
19840
19924
|
const winPathResult = runCommand("wslpath", ["-w", tmpFile], { timeoutMs: DEFAULT_LIST_TIMEOUT_MS });
|
|
19841
19925
|
if (!winPathResult.ok) {
|
|
@@ -19863,7 +19947,7 @@ function readClipboardImageViaPowerShell() {
|
|
|
19863
19947
|
if (output !== "ok") {
|
|
19864
19948
|
return null;
|
|
19865
19949
|
}
|
|
19866
|
-
const bytes =
|
|
19950
|
+
const bytes = readFileSync11(tmpFile);
|
|
19867
19951
|
if (bytes.length === 0) {
|
|
19868
19952
|
return null;
|
|
19869
19953
|
}
|
|
@@ -20076,9 +20160,9 @@ var init_clipboard = __esm(() => {
|
|
|
20076
20160
|
|
|
20077
20161
|
// src/modes/interactive/external-editor.ts
|
|
20078
20162
|
import { spawn as spawn4 } from "node:child_process";
|
|
20079
|
-
import { mkdtempSync, readFileSync as
|
|
20163
|
+
import { mkdtempSync, readFileSync as readFileSync12, rmSync as rmSync3, writeFileSync as writeFileSync7 } from "node:fs";
|
|
20080
20164
|
import { tmpdir as tmpdir3 } from "node:os";
|
|
20081
|
-
import { join as
|
|
20165
|
+
import { join as join27 } from "node:path";
|
|
20082
20166
|
function parseEditorCommand(command) {
|
|
20083
20167
|
const args = [];
|
|
20084
20168
|
let current = "";
|
|
@@ -20143,8 +20227,8 @@ function resolveExternalEditorCommand(configuredCommand, environment = process.e
|
|
|
20143
20227
|
return platform2 === "win32" ? "notepad" : "nano";
|
|
20144
20228
|
}
|
|
20145
20229
|
async function editInExternalEditor(request) {
|
|
20146
|
-
const directory = mkdtempSync(
|
|
20147
|
-
const filePath =
|
|
20230
|
+
const directory = mkdtempSync(join27(tmpdir3(), `${APP_NAME}-editor-`));
|
|
20231
|
+
const filePath = join27(directory, "prompt.md");
|
|
20148
20232
|
try {
|
|
20149
20233
|
writeFileSync7(filePath, request.content, {
|
|
20150
20234
|
encoding: "utf-8",
|
|
@@ -20168,7 +20252,7 @@ ${APP_NAME} will resume when the editor exits.
|
|
|
20168
20252
|
return { status: "failed" };
|
|
20169
20253
|
return {
|
|
20170
20254
|
status: "complete",
|
|
20171
|
-
content:
|
|
20255
|
+
content: readFileSync12(filePath, "utf-8").replace(/\n$/, "")
|
|
20172
20256
|
};
|
|
20173
20257
|
} finally {
|
|
20174
20258
|
try {
|
|
@@ -23226,8 +23310,8 @@ import {
|
|
|
23226
23310
|
TUI_KEYBINDINGS,
|
|
23227
23311
|
KeybindingsManager as TuiKeybindingsManager
|
|
23228
23312
|
} from "@earendil-works/pi-tui";
|
|
23229
|
-
import { existsSync as
|
|
23230
|
-
import { join as
|
|
23313
|
+
import { existsSync as existsSync17, readFileSync as readFileSync13 } from "fs";
|
|
23314
|
+
import { join as join29 } from "path";
|
|
23231
23315
|
function isRecord2(value) {
|
|
23232
23316
|
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
23233
23317
|
}
|
|
@@ -23279,10 +23363,10 @@ function orderKeybindingsConfig(config) {
|
|
|
23279
23363
|
return ordered;
|
|
23280
23364
|
}
|
|
23281
23365
|
function loadRawConfig(path7) {
|
|
23282
|
-
if (!
|
|
23366
|
+
if (!existsSync17(path7))
|
|
23283
23367
|
return;
|
|
23284
23368
|
try {
|
|
23285
|
-
const parsed = JSON.parse(
|
|
23369
|
+
const parsed = JSON.parse(readFileSync13(path7, "utf-8"));
|
|
23286
23370
|
return isRecord2(parsed) ? parsed : undefined;
|
|
23287
23371
|
} catch {
|
|
23288
23372
|
return;
|
|
@@ -23503,7 +23587,7 @@ var init_keybindings = __esm(() => {
|
|
|
23503
23587
|
this.configPath = configPath;
|
|
23504
23588
|
}
|
|
23505
23589
|
static create(agentDir = getAgentDir()) {
|
|
23506
|
-
const configPath =
|
|
23590
|
+
const configPath = join29(agentDir, "keybindings.json");
|
|
23507
23591
|
const userBindings = KeybindingsManager.loadFromFile(configPath);
|
|
23508
23592
|
return new KeybindingsManager(userBindings, configPath);
|
|
23509
23593
|
}
|
|
@@ -23526,7 +23610,7 @@ var init_keybindings = __esm(() => {
|
|
|
23526
23610
|
|
|
23527
23611
|
// src/modes/interactive/components/session-selector-delete.ts
|
|
23528
23612
|
import { spawnSync as spawnSync4 } from "node:child_process";
|
|
23529
|
-
import { existsSync as
|
|
23613
|
+
import { existsSync as existsSync18 } from "node:fs";
|
|
23530
23614
|
import { unlink } from "node:fs/promises";
|
|
23531
23615
|
async function deleteSessionFile(sessionPath) {
|
|
23532
23616
|
const trashArgs = sessionPath.startsWith("-") ? ["--", sessionPath] : [sessionPath];
|
|
@@ -23545,7 +23629,7 @@ async function deleteSessionFile(sessionPath) {
|
|
|
23545
23629
|
return null;
|
|
23546
23630
|
return `trash: ${parts.join(" · ").slice(0, 200)}`;
|
|
23547
23631
|
};
|
|
23548
|
-
if (trashResult.status === 0 || !
|
|
23632
|
+
if (trashResult.status === 0 || !existsSync18(sessionPath)) {
|
|
23549
23633
|
return { ok: true, method: "trash" };
|
|
23550
23634
|
}
|
|
23551
23635
|
try {
|
|
@@ -26422,8 +26506,8 @@ function parseJsonFileContent(input) {
|
|
|
26422
26506
|
}
|
|
26423
26507
|
|
|
26424
26508
|
// src/core/trust-manager.ts
|
|
26425
|
-
import { existsSync as
|
|
26426
|
-
import { dirname as
|
|
26509
|
+
import { existsSync as existsSync19, mkdirSync as mkdirSync7, readFileSync as readFileSync14, writeFileSync as writeFileSync9 } from "node:fs";
|
|
26510
|
+
import { dirname as dirname12, join as join30 } from "node:path";
|
|
26427
26511
|
import lockfile from "proper-lockfile";
|
|
26428
26512
|
function normalizeCwd(cwd) {
|
|
26429
26513
|
return canonicalizePath(resolvePath(cwd));
|
|
@@ -26435,7 +26519,7 @@ function findNearestTrustEntry(data, cwd) {
|
|
|
26435
26519
|
if (value === true || value === false) {
|
|
26436
26520
|
return { path: currentDir, decision: value };
|
|
26437
26521
|
}
|
|
26438
|
-
const parentDir =
|
|
26522
|
+
const parentDir = dirname12(currentDir);
|
|
26439
26523
|
if (parentDir === currentDir) {
|
|
26440
26524
|
return null;
|
|
26441
26525
|
}
|
|
@@ -26447,7 +26531,7 @@ function getProjectTrustPath(cwd) {
|
|
|
26447
26531
|
}
|
|
26448
26532
|
function getProjectTrustParentPath(cwd) {
|
|
26449
26533
|
const trustPath = getProjectTrustPath(cwd);
|
|
26450
|
-
const parentDir =
|
|
26534
|
+
const parentDir = dirname12(trustPath);
|
|
26451
26535
|
return parentDir === trustPath ? undefined : parentDir;
|
|
26452
26536
|
}
|
|
26453
26537
|
function getProjectTrustOptions(cwd, options) {
|
|
@@ -26482,12 +26566,12 @@ function getProjectTrustOptions(cwd, options) {
|
|
|
26482
26566
|
return trustOptions;
|
|
26483
26567
|
}
|
|
26484
26568
|
function readTrustFile(path7) {
|
|
26485
|
-
if (!
|
|
26569
|
+
if (!existsSync19(path7)) {
|
|
26486
26570
|
return {};
|
|
26487
26571
|
}
|
|
26488
26572
|
let parsed;
|
|
26489
26573
|
try {
|
|
26490
|
-
parsed = parseJsonFileContent(
|
|
26574
|
+
parsed = parseJsonFileContent(readFileSync14(path7, "utf-8"));
|
|
26491
26575
|
} catch (error) {
|
|
26492
26576
|
const message = error instanceof Error ? error.message : String(error);
|
|
26493
26577
|
throw new Error(`Failed to read trust store ${path7}: ${message}`);
|
|
@@ -26512,12 +26596,12 @@ function writeTrustFile(path7, data) {
|
|
|
26512
26596
|
sorted[key] = value;
|
|
26513
26597
|
}
|
|
26514
26598
|
}
|
|
26515
|
-
mkdirSync7(
|
|
26599
|
+
mkdirSync7(dirname12(path7), { recursive: true });
|
|
26516
26600
|
writeFileSync9(path7, `${JSON.stringify(sorted, null, 2)}
|
|
26517
26601
|
`, "utf-8");
|
|
26518
26602
|
}
|
|
26519
26603
|
function acquireTrustLockSync(path7) {
|
|
26520
|
-
const trustDir =
|
|
26604
|
+
const trustDir = dirname12(path7);
|
|
26521
26605
|
mkdirSync7(trustDir, { recursive: true });
|
|
26522
26606
|
const maxAttempts = 10;
|
|
26523
26607
|
const delayMs = 20;
|
|
@@ -26551,22 +26635,22 @@ function withTrustFileLock(path7, fn) {
|
|
|
26551
26635
|
function hasTrustRequiringConfigResources(cwd) {
|
|
26552
26636
|
const projectCwd = canonicalizePath(resolvePath(cwd));
|
|
26553
26637
|
return CONFIG_DIR_NAMES.some((configDirName) => {
|
|
26554
|
-
const configDir =
|
|
26555
|
-
return TRUST_REQUIRING_PROJECT_CONFIG_RESOURCES.some((entry) =>
|
|
26638
|
+
const configDir = join30(projectCwd, configDirName);
|
|
26639
|
+
return TRUST_REQUIRING_PROJECT_CONFIG_RESOURCES.some((entry) => existsSync19(join30(configDir, entry)));
|
|
26556
26640
|
});
|
|
26557
26641
|
}
|
|
26558
26642
|
function hasTrustRequiringProjectResources(cwd) {
|
|
26559
26643
|
if (hasTrustRequiringConfigResources(cwd)) {
|
|
26560
26644
|
return true;
|
|
26561
26645
|
}
|
|
26562
|
-
const userGlobalSkillsDir = canonicalizePath(resolvePath(
|
|
26646
|
+
const userGlobalSkillsDir = canonicalizePath(resolvePath(join30(getHomeDir(), ".agents", "skills")));
|
|
26563
26647
|
let currentDir = canonicalizePath(resolvePath(cwd));
|
|
26564
26648
|
while (true) {
|
|
26565
|
-
const skillsDir = canonicalizePath(resolvePath(
|
|
26566
|
-
if (skillsDir !== userGlobalSkillsDir &&
|
|
26649
|
+
const skillsDir = canonicalizePath(resolvePath(join30(currentDir, ".agents", "skills")));
|
|
26650
|
+
if (skillsDir !== userGlobalSkillsDir && existsSync19(skillsDir)) {
|
|
26567
26651
|
return true;
|
|
26568
26652
|
}
|
|
26569
|
-
const parentDir =
|
|
26653
|
+
const parentDir = dirname12(currentDir);
|
|
26570
26654
|
if (parentDir === currentDir) {
|
|
26571
26655
|
return false;
|
|
26572
26656
|
}
|
|
@@ -26577,7 +26661,7 @@ function hasTrustRequiringProjectResources(cwd) {
|
|
|
26577
26661
|
class ProjectTrustStore {
|
|
26578
26662
|
trustPath;
|
|
26579
26663
|
constructor(agentDir) {
|
|
26580
|
-
this.trustPath =
|
|
26664
|
+
this.trustPath = join30(resolvePath(agentDir), "trust.json");
|
|
26581
26665
|
}
|
|
26582
26666
|
get(cwd) {
|
|
26583
26667
|
return this.getEntry(cwd)?.decision ?? null;
|
|
@@ -31346,7 +31430,7 @@ var init_hashline = __esm(() => {
|
|
|
31346
31430
|
});
|
|
31347
31431
|
|
|
31348
31432
|
// src/core/tools/notebook.ts
|
|
31349
|
-
import { existsSync as
|
|
31433
|
+
import { existsSync as existsSync20, readFileSync as readFileSync15 } from "node:fs";
|
|
31350
31434
|
function isNotebookPath(absolutePath) {
|
|
31351
31435
|
return /\.ipynb$/i.test(absolutePath);
|
|
31352
31436
|
}
|
|
@@ -31448,11 +31532,11 @@ function applyNotebookEditableText(notebook, text, displayPath) {
|
|
|
31448
31532
|
return next;
|
|
31449
31533
|
}
|
|
31450
31534
|
function readEditableNotebookText(absolutePath, displayPath) {
|
|
31451
|
-
const notebook =
|
|
31535
|
+
const notebook = existsSync20(absolutePath) ? parseNotebookSafe(readFileSync15(absolutePath, "utf8"), displayPath) : emptyNotebook();
|
|
31452
31536
|
return notebookToEditableText(notebook);
|
|
31453
31537
|
}
|
|
31454
31538
|
function serializeEditedNotebookText(absolutePath, displayPath, text) {
|
|
31455
|
-
const notebook =
|
|
31539
|
+
const notebook = existsSync20(absolutePath) ? parseNotebookSafe(readFileSync15(absolutePath, "utf8"), displayPath) : emptyNotebook();
|
|
31456
31540
|
const next = applyNotebookEditableText(notebook, text, displayPath);
|
|
31457
31541
|
return JSON.stringify(next, null, 1);
|
|
31458
31542
|
}
|
|
@@ -31783,10 +31867,10 @@ var init_management_http = __esm(() => {
|
|
|
31783
31867
|
|
|
31784
31868
|
// src/utils/tools-manager.ts
|
|
31785
31869
|
import { spawnSync as spawnSync5 } from "child_process";
|
|
31786
|
-
import { chmodSync as chmodSync3, existsSync as
|
|
31870
|
+
import { chmodSync as chmodSync3, existsSync as existsSync21, mkdirSync as mkdirSync8, readdirSync as readdirSync5, renameSync, rmSync as rmSync4 } from "fs";
|
|
31787
31871
|
import { writeFile } from "fs/promises";
|
|
31788
31872
|
import { arch, platform as platform2 } from "os";
|
|
31789
|
-
import { join as
|
|
31873
|
+
import { join as join31 } from "path";
|
|
31790
31874
|
function isOfflineModeEnabled() {
|
|
31791
31875
|
const value = getEnvValue(ENV_OFFLINE);
|
|
31792
31876
|
if (!value)
|
|
@@ -31805,8 +31889,8 @@ function getToolPath(tool) {
|
|
|
31805
31889
|
const config = TOOLS[tool];
|
|
31806
31890
|
if (!config)
|
|
31807
31891
|
return null;
|
|
31808
|
-
const localPath =
|
|
31809
|
-
if (
|
|
31892
|
+
const localPath = join31(TOOLS_DIR, config.binaryName + (platform2() === "win32" ? ".exe" : ""));
|
|
31893
|
+
if (existsSync21(localPath)) {
|
|
31810
31894
|
return localPath;
|
|
31811
31895
|
}
|
|
31812
31896
|
const systemBinaryNames = config.systemBinaryNames ?? [config.binaryName];
|
|
@@ -31845,7 +31929,7 @@ function findBinaryRecursively(rootDir, binaryFileName) {
|
|
|
31845
31929
|
continue;
|
|
31846
31930
|
const entries = readdirSync5(currentDir, { withFileTypes: true });
|
|
31847
31931
|
for (const entry of entries) {
|
|
31848
|
-
const fullPath =
|
|
31932
|
+
const fullPath = join31(currentDir, entry.name);
|
|
31849
31933
|
if (entry.isFile() && entry.name === binaryFileName) {
|
|
31850
31934
|
return fullPath;
|
|
31851
31935
|
}
|
|
@@ -31886,8 +31970,8 @@ function extractTarGzArchive(archivePath, extractDir, assetName) {
|
|
|
31886
31970
|
function getWindowsTarCommand() {
|
|
31887
31971
|
const systemRoot = process.env.SystemRoot ?? process.env.WINDIR;
|
|
31888
31972
|
if (systemRoot) {
|
|
31889
|
-
const systemTar =
|
|
31890
|
-
if (
|
|
31973
|
+
const systemTar = join31(systemRoot, "System32", "tar.exe");
|
|
31974
|
+
if (existsSync21(systemTar)) {
|
|
31891
31975
|
return systemTar;
|
|
31892
31976
|
}
|
|
31893
31977
|
}
|
|
@@ -31940,11 +32024,11 @@ async function downloadTool(tool) {
|
|
|
31940
32024
|
}
|
|
31941
32025
|
mkdirSync8(TOOLS_DIR, { recursive: true });
|
|
31942
32026
|
const downloadUrl = `https://github.com/${config.repo}/releases/download/${config.tagPrefix}${version}/${assetName}`;
|
|
31943
|
-
const archivePath =
|
|
32027
|
+
const archivePath = join31(TOOLS_DIR, assetName);
|
|
31944
32028
|
const binaryExt = plat === "win32" ? ".exe" : "";
|
|
31945
|
-
const binaryPath =
|
|
32029
|
+
const binaryPath = join31(TOOLS_DIR, config.binaryName + binaryExt);
|
|
31946
32030
|
await downloadFile(downloadUrl, archivePath);
|
|
31947
|
-
const extractDir =
|
|
32031
|
+
const extractDir = join31(TOOLS_DIR, `extract_tmp_${config.binaryName}_${process.pid}_${Date.now()}_${Math.random().toString(36).slice(2, 10)}`);
|
|
31948
32032
|
mkdirSync8(extractDir, { recursive: true });
|
|
31949
32033
|
try {
|
|
31950
32034
|
if (assetName.endsWith(".tar.gz")) {
|
|
@@ -31955,9 +32039,9 @@ async function downloadTool(tool) {
|
|
|
31955
32039
|
throw new Error(`Unsupported archive format: ${assetName}`);
|
|
31956
32040
|
}
|
|
31957
32041
|
const binaryFileName = config.binaryName + binaryExt;
|
|
31958
|
-
const extractedDir =
|
|
31959
|
-
const extractedBinaryCandidates = [
|
|
31960
|
-
let extractedBinary = extractedBinaryCandidates.find((candidate) =>
|
|
32042
|
+
const extractedDir = join31(extractDir, assetName.replace(/\.(tar\.gz|zip)$/, ""));
|
|
32043
|
+
const extractedBinaryCandidates = [join31(extractedDir, binaryFileName), join31(extractDir, binaryFileName)];
|
|
32044
|
+
let extractedBinary = extractedBinaryCandidates.find((candidate) => existsSync21(candidate));
|
|
31961
32045
|
if (!extractedBinary) {
|
|
31962
32046
|
extractedBinary = findBinaryRecursively(extractDir, binaryFileName) ?? undefined;
|
|
31963
32047
|
}
|
|
@@ -33545,7 +33629,7 @@ var init_read_selectors = __esm(() => {
|
|
|
33545
33629
|
});
|
|
33546
33630
|
|
|
33547
33631
|
// src/core/tools/read-document-extract.ts
|
|
33548
|
-
import { existsSync as
|
|
33632
|
+
import { existsSync as existsSync22 } from "node:fs";
|
|
33549
33633
|
function isDocumentPath(pathValue) {
|
|
33550
33634
|
return DOCUMENT_EXTENSIONS.test(pathValue);
|
|
33551
33635
|
}
|
|
@@ -33742,7 +33826,7 @@ function documentExtension(source) {
|
|
|
33742
33826
|
}
|
|
33743
33827
|
async function extractMarkitDocument(buffer, source) {
|
|
33744
33828
|
const ext = documentExtension(source);
|
|
33745
|
-
const result =
|
|
33829
|
+
const result = existsSync22(source) ? await convertFileWithMarkit(source) : await convertBufferWithMarkit(buffer, ext);
|
|
33746
33830
|
return result.ok ? result.content : `[Cannot read ${ext} file: ${result.error || "conversion failed"}]`;
|
|
33747
33831
|
}
|
|
33748
33832
|
async function extractDocumentMarkdown(buffer, source) {
|
|
@@ -34605,7 +34689,7 @@ var init_read_url = __esm(() => {
|
|
|
34605
34689
|
});
|
|
34606
34690
|
|
|
34607
34691
|
// src/core/tools/read.ts
|
|
34608
|
-
import { basename as basename6, dirname as
|
|
34692
|
+
import { basename as basename6, dirname as dirname13, isAbsolute as isAbsolute6, relative as relative7, resolve as resolvePath5, sep as sep6 } from "node:path";
|
|
34609
34693
|
import { Text as Text32 } from "@earendil-works/pi-tui";
|
|
34610
34694
|
import { constants as constants5 } from "fs";
|
|
34611
34695
|
import { access as fsAccess3, readFile as fsReadFile2, stat as fsStat4 } from "fs/promises";
|
|
@@ -34683,7 +34767,7 @@ function oversizedReadResult(details) {
|
|
|
34683
34767
|
};
|
|
34684
34768
|
}
|
|
34685
34769
|
function getPiDocsClassification(absolutePath) {
|
|
34686
|
-
const packageRoot =
|
|
34770
|
+
const packageRoot = dirname13(getReadmePath());
|
|
34687
34771
|
const relativePath = relative7(resolvePath5(packageRoot), resolvePath5(absolutePath));
|
|
34688
34772
|
if (relativePath === "" || relativePath === ".." || relativePath.startsWith(`..${sep6}`) || isAbsolute6(relativePath)) {
|
|
34689
34773
|
return;
|
|
@@ -34701,7 +34785,7 @@ function getCompactReadClassification(args, cwd) {
|
|
|
34701
34785
|
const absolutePath = resolveToCwd(rawPath, cwd);
|
|
34702
34786
|
const fileName = basename6(absolutePath);
|
|
34703
34787
|
if (fileName === "SKILL.md") {
|
|
34704
|
-
return { kind: "skill", label: basename6(
|
|
34788
|
+
return { kind: "skill", label: basename6(dirname13(absolutePath)) || fileName };
|
|
34705
34789
|
}
|
|
34706
34790
|
const docsClassification = getPiDocsClassification(absolutePath);
|
|
34707
34791
|
if (docsClassification)
|
|
@@ -35861,22 +35945,22 @@ function filterSearchOutputByLineRange(text, ranges, contextBefore = 1, contextA
|
|
|
35861
35945
|
}
|
|
35862
35946
|
|
|
35863
35947
|
// src/core/tools/search.ts
|
|
35864
|
-
import { existsSync as
|
|
35948
|
+
import { existsSync as existsSync23 } from "node:fs";
|
|
35865
35949
|
import { readFile as fsReadFile4, stat as fsStat6 } from "node:fs/promises";
|
|
35866
|
-
import { dirname as
|
|
35950
|
+
import { dirname as dirname14, join as join32, resolve as resolvePath6 } from "node:path";
|
|
35867
35951
|
import { Text as Text34 } from "@earendil-works/pi-tui";
|
|
35868
35952
|
import { Type as Type9 } from "typebox";
|
|
35869
35953
|
function delimiterInExistingSearchGlobRoot(value, cwd) {
|
|
35870
35954
|
const selector = splitLineRangeSelector(value);
|
|
35871
35955
|
const parsed = splitPathLikeGlob(selector.path);
|
|
35872
|
-
return !!parsed.glob && /[;,\s]/.test(parsed.basePath) &&
|
|
35956
|
+
return !!parsed.glob && /[;,\s]/.test(parsed.basePath) && existsSync23(resolveToCwd(parsed.basePath, cwd));
|
|
35873
35957
|
}
|
|
35874
35958
|
function archiveSelectorExists(value, cwd) {
|
|
35875
35959
|
const archive = parseArchiveSelector(value);
|
|
35876
35960
|
if (!archive)
|
|
35877
35961
|
return false;
|
|
35878
35962
|
const resolved = resolveArchiveSelector(archive, cwd);
|
|
35879
|
-
if (!
|
|
35963
|
+
if (!existsSync23(resolved.archivePath))
|
|
35880
35964
|
return false;
|
|
35881
35965
|
if (!resolved.memberPath)
|
|
35882
35966
|
return true;
|
|
@@ -35892,7 +35976,7 @@ function searchPathResolvable(value, cwd) {
|
|
|
35892
35976
|
if (archive)
|
|
35893
35977
|
return archiveSelectorExists(selector.path, cwd);
|
|
35894
35978
|
const sqlite = sqliteSelectorForPath(selector.path, cwd);
|
|
35895
|
-
return !!sqlite || /^(?:skill|agent|artifact|history|issue|local|memory|pr|conflict|omp|rule|mcp|vault):\/\//.test(selector.path) ||
|
|
35979
|
+
return !!sqlite || /^(?:skill|agent|artifact|history|issue|local|memory|pr|conflict|omp|rule|mcp|vault):\/\//.test(selector.path) || existsSync23(resolveToCwd(splitPathLikeGlob(selector.path).basePath, cwd));
|
|
35896
35980
|
}
|
|
35897
35981
|
function normalizePaths(pathsValue, cwd) {
|
|
35898
35982
|
const inputs = Array.isArray(pathsValue) ? pathsValue.length > 0 ? pathsValue : ["."] : pathsValue === undefined ? ["."] : [pathsValue];
|
|
@@ -35904,7 +35988,7 @@ function normalizePaths(pathsValue, cwd) {
|
|
|
35904
35988
|
continue;
|
|
35905
35989
|
}
|
|
35906
35990
|
const resourceLike = /^[a-z]+:\/\//i.test(raw) || /^[^:]+\.(?:zip|jar|tar|tgz|gz|sqlite|db):/i.test(raw);
|
|
35907
|
-
if (
|
|
35991
|
+
if (existsSync23(resolveToCwd(splitLineRangeSelector(raw).path, cwd)) || delimiterInExistingSearchGlobRoot(raw, cwd) || archiveSelectorExists(raw, cwd)) {
|
|
35908
35992
|
expanded.push(raw);
|
|
35909
35993
|
continue;
|
|
35910
35994
|
}
|
|
@@ -36089,7 +36173,7 @@ async function addHashlineHeadersToSearchOutput(text, cwd, targetPath, hashlineS
|
|
|
36089
36173
|
const rendered = [];
|
|
36090
36174
|
let lastDir = "";
|
|
36091
36175
|
for (const group of groups) {
|
|
36092
|
-
let absolutePath = targetIsFile ? searchRoot :
|
|
36176
|
+
let absolutePath = targetIsFile ? searchRoot : join32(searchRoot, group.path);
|
|
36093
36177
|
try {
|
|
36094
36178
|
await fsReadFile4(absolutePath);
|
|
36095
36179
|
} catch {
|
|
@@ -36098,7 +36182,7 @@ async function addHashlineHeadersToSearchOutput(text, cwd, targetPath, hashlineS
|
|
|
36098
36182
|
try {
|
|
36099
36183
|
const content = await fsReadFile4(absolutePath, "utf-8");
|
|
36100
36184
|
const snapshot = recordHashlineSnapshot(absolutePath, cwd, content, hashlineStore);
|
|
36101
|
-
const dir =
|
|
36185
|
+
const dir = dirname14(snapshot.displayPath);
|
|
36102
36186
|
if (dir !== "." && dir !== lastDir) {
|
|
36103
36187
|
rendered.push(`# ${dir}/`);
|
|
36104
36188
|
lastDir = dir;
|
|
@@ -36819,7 +36903,7 @@ var init_todos_locks = __esm(() => {
|
|
|
36819
36903
|
|
|
36820
36904
|
// src/core/tools/todos-storage.ts
|
|
36821
36905
|
import crypto3 from "node:crypto";
|
|
36822
|
-
import { existsSync as
|
|
36906
|
+
import { existsSync as existsSync24 } from "node:fs";
|
|
36823
36907
|
import fs8 from "node:fs/promises";
|
|
36824
36908
|
import path12 from "node:path";
|
|
36825
36909
|
function parseFrontMatter(text, idFallback) {
|
|
@@ -36951,7 +37035,7 @@ async function generateTodoId(todosDir) {
|
|
|
36951
37035
|
for (let attempt = 0;attempt < 10; attempt += 1) {
|
|
36952
37036
|
const id = crypto3.randomBytes(4).toString("hex");
|
|
36953
37037
|
const todoPath = getTodoPath(todosDir, id);
|
|
36954
|
-
if (!
|
|
37038
|
+
if (!existsSync24(todoPath))
|
|
36955
37039
|
return id;
|
|
36956
37040
|
}
|
|
36957
37041
|
throw new Error("Failed to generate unique todo id");
|
|
@@ -36986,7 +37070,7 @@ async function listTodos(todosDir) {
|
|
|
36986
37070
|
return sortTodos(todos);
|
|
36987
37071
|
}
|
|
36988
37072
|
async function ensureTodoExists(filePath, id) {
|
|
36989
|
-
if (!
|
|
37073
|
+
if (!existsSync24(filePath))
|
|
36990
37074
|
return null;
|
|
36991
37075
|
return readTodoFile(filePath, id);
|
|
36992
37076
|
}
|
|
@@ -37005,7 +37089,7 @@ var init_todos_storage = __esm(() => {
|
|
|
37005
37089
|
});
|
|
37006
37090
|
|
|
37007
37091
|
// src/core/tools/todos-mutations.ts
|
|
37008
|
-
import { existsSync as
|
|
37092
|
+
import { existsSync as existsSync25 } from "node:fs";
|
|
37009
37093
|
import fs9 from "node:fs/promises";
|
|
37010
37094
|
async function claimTodoAssignment(todosDir, id, ctx, force = false) {
|
|
37011
37095
|
const validated = validateTodoId(id);
|
|
@@ -37014,7 +37098,7 @@ async function claimTodoAssignment(todosDir, id, ctx, force = false) {
|
|
|
37014
37098
|
}
|
|
37015
37099
|
const normalizedId = validated.id;
|
|
37016
37100
|
const filePath = getTodoPath(todosDir, normalizedId);
|
|
37017
|
-
if (!
|
|
37101
|
+
if (!existsSync25(filePath)) {
|
|
37018
37102
|
return { error: `Todo ${displayTodoId(id)} not found` };
|
|
37019
37103
|
}
|
|
37020
37104
|
const sessionId = ctx.sessionManager.getSessionId();
|
|
@@ -37045,7 +37129,7 @@ async function releaseTodoAssignment(todosDir, id, ctx, force = false) {
|
|
|
37045
37129
|
}
|
|
37046
37130
|
const normalizedId = validated.id;
|
|
37047
37131
|
const filePath = getTodoPath(todosDir, normalizedId);
|
|
37048
|
-
if (!
|
|
37132
|
+
if (!existsSync25(filePath)) {
|
|
37049
37133
|
return { error: `Todo ${displayTodoId(id)} not found` };
|
|
37050
37134
|
}
|
|
37051
37135
|
const sessionId = ctx.sessionManager.getSessionId();
|
|
@@ -37074,7 +37158,7 @@ async function deleteTodo(todosDir, id, ctx) {
|
|
|
37074
37158
|
}
|
|
37075
37159
|
const normalizedId = validated.id;
|
|
37076
37160
|
const filePath = getTodoPath(todosDir, normalizedId);
|
|
37077
|
-
if (!
|
|
37161
|
+
if (!existsSync25(filePath)) {
|
|
37078
37162
|
return { error: `Todo ${displayTodoId(id)} not found` };
|
|
37079
37163
|
}
|
|
37080
37164
|
return withTodoLock(todosDir, normalizedId, ctx, async () => {
|
|
@@ -37246,7 +37330,7 @@ var init_todos_render = __esm(() => {
|
|
|
37246
37330
|
});
|
|
37247
37331
|
|
|
37248
37332
|
// src/core/tools/todos-execute.ts
|
|
37249
|
-
import { existsSync as
|
|
37333
|
+
import { existsSync as existsSync26 } from "node:fs";
|
|
37250
37334
|
function todoActionResult(action, text, detailsError) {
|
|
37251
37335
|
return {
|
|
37252
37336
|
content: [{ type: "text", text }],
|
|
@@ -37330,7 +37414,7 @@ async function executeUpdateAction(todosDir, params, ctx) {
|
|
|
37330
37414
|
const normalizedId = validated.id;
|
|
37331
37415
|
const displayId = formatTodoId(normalizedId);
|
|
37332
37416
|
const filePath = getTodoPath(todosDir, normalizedId);
|
|
37333
|
-
if (!
|
|
37417
|
+
if (!existsSync26(filePath)) {
|
|
37334
37418
|
return todoActionResult("update", `Todo ${displayId} not found`, "not found");
|
|
37335
37419
|
}
|
|
37336
37420
|
const result = await withTodoLock(todosDir, normalizedId, ctx, async () => {
|
|
@@ -37367,7 +37451,7 @@ async function executeAppendAction(todosDir, params, ctx) {
|
|
|
37367
37451
|
const normalizedId = validated.id;
|
|
37368
37452
|
const displayId = formatTodoId(normalizedId);
|
|
37369
37453
|
const filePath = getTodoPath(todosDir, normalizedId);
|
|
37370
|
-
if (!
|
|
37454
|
+
if (!existsSync26(filePath)) {
|
|
37371
37455
|
return todoActionResult("append", `Todo ${displayId} not found`, "not found");
|
|
37372
37456
|
}
|
|
37373
37457
|
const result = await withTodoLock(todosDir, normalizedId, ctx, async () => {
|
|
@@ -37487,7 +37571,7 @@ import {
|
|
|
37487
37571
|
stat as fsStat7,
|
|
37488
37572
|
writeFile as fsWriteFile2
|
|
37489
37573
|
} from "fs/promises";
|
|
37490
|
-
import { dirname as
|
|
37574
|
+
import { dirname as dirname16, join as join33 } from "path";
|
|
37491
37575
|
import { Type as Type11 } from "typebox";
|
|
37492
37576
|
async function findConflictBlocks(root, limit = 100) {
|
|
37493
37577
|
const out = [];
|
|
@@ -37495,7 +37579,7 @@ async function findConflictBlocks(root, limit = 100) {
|
|
|
37495
37579
|
for (const entry of await fsReaddir2(dir, { withFileTypes: true }).catch(() => [])) {
|
|
37496
37580
|
if (out.length >= limit || entry.name === ".git" || entry.name === "node_modules")
|
|
37497
37581
|
continue;
|
|
37498
|
-
const full =
|
|
37582
|
+
const full = join33(dir, entry.name);
|
|
37499
37583
|
if (entry.isDirectory())
|
|
37500
37584
|
await walk(full);
|
|
37501
37585
|
else if (entry.isFile()) {
|
|
@@ -37785,7 +37869,7 @@ ${headers[0]}` : ""}` }],
|
|
|
37785
37869
|
};
|
|
37786
37870
|
}
|
|
37787
37871
|
const absolutePath = resolveToCwd(path13, cwd);
|
|
37788
|
-
const dir =
|
|
37872
|
+
const dir = dirname16(absolutePath);
|
|
37789
37873
|
return withFileMutationQueue(absolutePath, async () => {
|
|
37790
37874
|
const throwIfAborted2 = () => {
|
|
37791
37875
|
if (signal?.aborted)
|
|
@@ -38292,20 +38376,20 @@ import {
|
|
|
38292
38376
|
lstatSync as lstatSync2,
|
|
38293
38377
|
openSync as openSync3,
|
|
38294
38378
|
readdirSync as readdirSync6,
|
|
38295
|
-
readFileSync as
|
|
38379
|
+
readFileSync as readFileSync16,
|
|
38296
38380
|
renameSync as renameSync2,
|
|
38297
38381
|
rmSync as rmSync5,
|
|
38298
38382
|
statSync as statSync6,
|
|
38299
38383
|
unlinkSync as unlinkSync4,
|
|
38300
38384
|
writeSync
|
|
38301
38385
|
} from "node:fs";
|
|
38302
|
-
import { join as
|
|
38386
|
+
import { join as join34 } from "node:path";
|
|
38303
38387
|
function getCleanupControlRoot() {
|
|
38304
|
-
return
|
|
38388
|
+
return join34(getTempRootDir(), CLEANUP_CONTROL_SUBDIR);
|
|
38305
38389
|
}
|
|
38306
38390
|
function getCleanupControlDir(target, controlRoot) {
|
|
38307
38391
|
const key = createHash3("sha256").update(target).digest("hex").slice(0, 16);
|
|
38308
|
-
return
|
|
38392
|
+
return join34(controlRoot ?? getCleanupControlRoot(), key);
|
|
38309
38393
|
}
|
|
38310
38394
|
function sameFileIdentity2(left, right) {
|
|
38311
38395
|
return left.dev === right.dev && left.ino === right.ino;
|
|
@@ -38432,7 +38516,7 @@ function breakStaleLock(lockPath, observedMtimeMs) {
|
|
|
38432
38516
|
}
|
|
38433
38517
|
function ownsCleanupLock(lockPath, lock) {
|
|
38434
38518
|
try {
|
|
38435
|
-
return pathIdentifiesFile(lockPath, lock) &&
|
|
38519
|
+
return pathIdentifiesFile(lockPath, lock) && readFileSync16(lockPath, "utf-8") === lock.token && pathIdentifiesFile(lockPath, lock);
|
|
38436
38520
|
} catch {
|
|
38437
38521
|
return false;
|
|
38438
38522
|
}
|
|
@@ -38521,7 +38605,7 @@ function scanFreshness(entryPath, cutoff, depth = 0) {
|
|
|
38521
38605
|
}
|
|
38522
38606
|
let foundUnknown = false;
|
|
38523
38607
|
for (const child of children) {
|
|
38524
|
-
const freshness = scanFreshness(
|
|
38608
|
+
const freshness = scanFreshness(join34(entryPath, child), cutoff, depth + 1);
|
|
38525
38609
|
if (freshness === "fresh") {
|
|
38526
38610
|
return "fresh";
|
|
38527
38611
|
}
|
|
@@ -38539,11 +38623,11 @@ function withCleanupGate(controlDir, options, scan) {
|
|
|
38539
38623
|
} catch {
|
|
38540
38624
|
return "locked";
|
|
38541
38625
|
}
|
|
38542
|
-
const markerPath =
|
|
38626
|
+
const markerPath = join34(controlDir, CLEANUP_MARKER_FILE);
|
|
38543
38627
|
if (markerIsFresh(markerPath, now, throttleMs)) {
|
|
38544
38628
|
return "throttled";
|
|
38545
38629
|
}
|
|
38546
|
-
const lockPath =
|
|
38630
|
+
const lockPath = join34(controlDir, CLEANUP_LOCK_FILE);
|
|
38547
38631
|
const token = acquireCleanupLock(lockPath, now, SESSION_TEMP_CLEANUP_LOCK_STALE_MS);
|
|
38548
38632
|
if (token === null) {
|
|
38549
38633
|
return "locked";
|
|
@@ -38594,7 +38678,7 @@ function sweepSessionTempRoot(root = getTempRootDir(), options = {}) {
|
|
|
38594
38678
|
if (isCleanupArtifact(entry)) {
|
|
38595
38679
|
continue;
|
|
38596
38680
|
}
|
|
38597
|
-
const entryPath =
|
|
38681
|
+
const entryPath = join34(root, entry);
|
|
38598
38682
|
if (gate.protectedPaths.has(entryPath)) {
|
|
38599
38683
|
continue;
|
|
38600
38684
|
}
|
|
@@ -38619,7 +38703,7 @@ function sweepSessionTempRoot(root = getTempRootDir(), options = {}) {
|
|
|
38619
38703
|
});
|
|
38620
38704
|
}
|
|
38621
38705
|
function reapToolResultsDir(parent, cutoff, protectedPaths) {
|
|
38622
|
-
const toolResultsDir =
|
|
38706
|
+
const toolResultsDir = join34(parent, TOOL_RESULTS_SUBDIR);
|
|
38623
38707
|
if (protectedPaths.has(toolResultsDir) || !isRealDirectory2(toolResultsDir)) {
|
|
38624
38708
|
return;
|
|
38625
38709
|
}
|
|
@@ -38644,7 +38728,7 @@ function sweepToolResultsRoot(sessionsRoot, options = {}) {
|
|
|
38644
38728
|
return;
|
|
38645
38729
|
}
|
|
38646
38730
|
for (const entry of entries) {
|
|
38647
|
-
const projectDir =
|
|
38731
|
+
const projectDir = join34(sessionsRoot, entry);
|
|
38648
38732
|
if (!isRealDirectory2(projectDir) || gate.protectedPaths.has(projectDir)) {
|
|
38649
38733
|
continue;
|
|
38650
38734
|
}
|
|
@@ -38885,7 +38969,7 @@ function parseSkillBlock(text) {
|
|
|
38885
38969
|
}
|
|
38886
38970
|
|
|
38887
38971
|
// src/core/agent-session.ts
|
|
38888
|
-
import { join as
|
|
38972
|
+
import { join as join35 } from "node:path";
|
|
38889
38973
|
|
|
38890
38974
|
class AgentSessionBase {
|
|
38891
38975
|
agent;
|
|
@@ -39008,7 +39092,7 @@ class AgentSessionBase {
|
|
|
39008
39092
|
const sessionDir = this.sessionManager.getSessionDir() || undefined;
|
|
39009
39093
|
this._tempStorageLease = acquireProtectedPaths([
|
|
39010
39094
|
setActiveSessionTempId(sessionId),
|
|
39011
|
-
...sessionDir ? [
|
|
39095
|
+
...sessionDir ? [join35(sessionDir, TOOL_RESULTS_SUBDIR)] : []
|
|
39012
39096
|
]);
|
|
39013
39097
|
const customSessionDir = this.sessionManager.usesDefaultSessionDir() ? undefined : sessionDir;
|
|
39014
39098
|
scheduleSessionTempCleanup(customSessionDir ? { sessionDirs: [customSessionDir] } : {});
|
|
@@ -39067,30 +39151,8 @@ var init_auth_storage = __esm(() => {
|
|
|
39067
39151
|
init_auth_storage_backends();
|
|
39068
39152
|
});
|
|
39069
39153
|
|
|
39070
|
-
// src/core/builtin-install-layout.ts
|
|
39071
|
-
function requiredEntriesForBuiltin(dirName) {
|
|
39072
|
-
return [INSTALLED_EXTENSION_ENTRIES[dirName], SOURCE_EXTENSION_ENTRIES[dirName]];
|
|
39073
|
-
}
|
|
39074
|
-
var SOURCE_EXTENSION_ENTRIES, INSTALLED_EXTENSION_ENTRIES;
|
|
39075
|
-
var init_builtin_install_layout = __esm(() => {
|
|
39076
|
-
SOURCE_EXTENSION_ENTRIES = {
|
|
39077
|
-
workflows: "src/extension/index.ts",
|
|
39078
|
-
subagents: "src/extension/index.ts",
|
|
39079
|
-
mcp: "index.ts",
|
|
39080
|
-
"web-access": "index.ts",
|
|
39081
|
-
intercom: "index.ts"
|
|
39082
|
-
};
|
|
39083
|
-
INSTALLED_EXTENSION_ENTRIES = {
|
|
39084
|
-
workflows: "src/extension/index.bundle.mjs",
|
|
39085
|
-
subagents: "src/extension/index.bundle.mjs",
|
|
39086
|
-
mcp: "index.bundle.mjs",
|
|
39087
|
-
"web-access": "index.bundle.mjs",
|
|
39088
|
-
intercom: "index.bundle.mjs"
|
|
39089
|
-
};
|
|
39090
|
-
});
|
|
39091
|
-
|
|
39092
39154
|
// src/core/builtin-packages.ts
|
|
39093
|
-
import { join as
|
|
39155
|
+
import { join as join36, resolve as resolve8 } from "node:path";
|
|
39094
39156
|
var WORKSPACE_BUILTINS, BUILTIN_PACKAGES;
|
|
39095
39157
|
var init_builtin_packages = __esm(() => {
|
|
39096
39158
|
init_config();
|
|
@@ -39107,7 +39169,7 @@ var init_builtin_packages = __esm(() => {
|
|
|
39107
39169
|
packageName: spec.packageName,
|
|
39108
39170
|
distDirName: spec.distDirName,
|
|
39109
39171
|
requiredEntries: requiredEntriesForBuiltin(spec.distDirName),
|
|
39110
|
-
sourceCandidates: ({ here, packageDir, isSourceCheckout }) => isSourceCheckout ? [
|
|
39172
|
+
sourceCandidates: ({ here, packageDir, isSourceCheckout }) => isSourceCheckout ? [join36(packageDir, "..", spec.workspaceDirName), join36(here, "..", "..", "..", spec.workspaceDirName)] : []
|
|
39111
39173
|
}));
|
|
39112
39174
|
});
|
|
39113
39175
|
|
|
@@ -39385,14 +39447,14 @@ var init_git_env = __esm(() => {
|
|
|
39385
39447
|
});
|
|
39386
39448
|
|
|
39387
39449
|
// src/core/package-manager-env.ts
|
|
39388
|
-
import { readFileSync as
|
|
39450
|
+
import { readFileSync as readFileSync17 } from "node:fs";
|
|
39389
39451
|
import { basename as basename7 } from "node:path";
|
|
39390
39452
|
function getEnv() {
|
|
39391
39453
|
if (process.platform !== "linux" || Object.keys(process.env).length > 0) {
|
|
39392
39454
|
return process.env;
|
|
39393
39455
|
}
|
|
39394
39456
|
try {
|
|
39395
|
-
const data =
|
|
39457
|
+
const data = readFileSync17("/proc/self/environ", "utf-8");
|
|
39396
39458
|
const env = {};
|
|
39397
39459
|
for (const entry of data.split("\x00")) {
|
|
39398
39460
|
const idx = entry.indexOf("=");
|
|
@@ -39624,13 +39686,13 @@ var NETWORK_TIMEOUT_MS2 = 1e4, UPDATE_CHECK_CONCURRENCY = 4, GIT_UPDATE_CONCURRE
|
|
|
39624
39686
|
// src/core/package-manager-paths.ts
|
|
39625
39687
|
import { createHash as createHash4 } from "node:crypto";
|
|
39626
39688
|
import { homedir as homedir6, tmpdir as tmpdir5 } from "node:os";
|
|
39627
|
-
import { join as
|
|
39689
|
+
import { join as join37 } from "node:path";
|
|
39628
39690
|
function getHomeDir2() {
|
|
39629
39691
|
return process.env.HOME || homedir6();
|
|
39630
39692
|
}
|
|
39631
39693
|
function getTemporaryDir(prefix, suffix) {
|
|
39632
39694
|
const hash = createHash4("sha256").update(`${prefix}-${suffix ?? ""}`).digest("hex").slice(0, 8);
|
|
39633
|
-
return
|
|
39695
|
+
return join37(tmpdir5(), `${APP_NAME}-extensions`, prefix, hash, suffix ?? "");
|
|
39634
39696
|
}
|
|
39635
39697
|
function getBaseDirsForScope(context, scope) {
|
|
39636
39698
|
if (scope === "project") {
|
|
@@ -39655,27 +39717,27 @@ function getNpmInstallRoot(context, scope, temporary) {
|
|
|
39655
39717
|
return getTemporaryDir("npm");
|
|
39656
39718
|
}
|
|
39657
39719
|
if (scope === "project") {
|
|
39658
|
-
return
|
|
39720
|
+
return join37(context.cwd, CONFIG_DIR_NAME, "npm");
|
|
39659
39721
|
}
|
|
39660
|
-
return
|
|
39722
|
+
return join37(context.agentDir, "npm");
|
|
39661
39723
|
}
|
|
39662
39724
|
function getGitInstallPath(context, source, scope) {
|
|
39663
39725
|
if (scope === "temporary") {
|
|
39664
39726
|
return getTemporaryDir(`git-${source.host}`, source.path);
|
|
39665
39727
|
}
|
|
39666
39728
|
if (scope === "project") {
|
|
39667
|
-
return
|
|
39729
|
+
return join37(context.cwd, CONFIG_DIR_NAME, "git", source.host, source.path);
|
|
39668
39730
|
}
|
|
39669
|
-
return
|
|
39731
|
+
return join37(context.agentDir, "git", source.host, source.path);
|
|
39670
39732
|
}
|
|
39671
39733
|
function getGitInstallRoot(context, scope) {
|
|
39672
39734
|
if (scope === "temporary") {
|
|
39673
39735
|
return;
|
|
39674
39736
|
}
|
|
39675
39737
|
if (scope === "project") {
|
|
39676
|
-
return
|
|
39738
|
+
return join37(context.cwd, CONFIG_DIR_NAME, "git");
|
|
39677
39739
|
}
|
|
39678
|
-
return
|
|
39740
|
+
return join37(context.agentDir, "git");
|
|
39679
39741
|
}
|
|
39680
39742
|
var init_package_manager_paths = __esm(() => {
|
|
39681
39743
|
init_config();
|
|
@@ -39683,8 +39745,8 @@ var init_package_manager_paths = __esm(() => {
|
|
|
39683
39745
|
});
|
|
39684
39746
|
|
|
39685
39747
|
// src/core/package-manager-npm.ts
|
|
39686
|
-
import { existsSync as
|
|
39687
|
-
import { basename as basename8, dirname as
|
|
39748
|
+
import { existsSync as existsSync27, mkdirSync as mkdirSync9, readFileSync as readFileSync18, writeFileSync as writeFileSync10 } from "node:fs";
|
|
39749
|
+
import { basename as basename8, dirname as dirname17, join as join38 } from "node:path";
|
|
39688
39750
|
import { maxSatisfying, rcompare, satisfies } from "semver";
|
|
39689
39751
|
function getNpmCommand(context) {
|
|
39690
39752
|
const configuredCommand = context.settingsManager.getNpmCommand();
|
|
@@ -39751,7 +39813,7 @@ async function installNpm(context, source, scope, temporary) {
|
|
|
39751
39813
|
}
|
|
39752
39814
|
async function uninstallNpm(context, source, scope) {
|
|
39753
39815
|
const installRoot = getNpmInstallRoot(context, scope, false);
|
|
39754
|
-
if (!
|
|
39816
|
+
if (!existsSync27(installRoot)) {
|
|
39755
39817
|
return;
|
|
39756
39818
|
}
|
|
39757
39819
|
if (getPackageManagerName(context) === "bun") {
|
|
@@ -39766,23 +39828,23 @@ async function installNpmBatch(context, specs, scope) {
|
|
|
39766
39828
|
await runNpmCommand(context, getNpmInstallArgs(context, specs, installRoot));
|
|
39767
39829
|
}
|
|
39768
39830
|
function ensureNpmProject(installRoot) {
|
|
39769
|
-
if (!
|
|
39831
|
+
if (!existsSync27(installRoot)) {
|
|
39770
39832
|
mkdirSync9(installRoot, { recursive: true });
|
|
39771
39833
|
}
|
|
39772
39834
|
markPathIgnoredByCloudSync(installRoot);
|
|
39773
39835
|
ensureGitIgnore(installRoot);
|
|
39774
|
-
const packageJsonPath =
|
|
39775
|
-
if (!
|
|
39836
|
+
const packageJsonPath = join38(installRoot, "package.json");
|
|
39837
|
+
if (!existsSync27(packageJsonPath)) {
|
|
39776
39838
|
const pkgJson = { name: `${APP_NAME}-extensions`, private: true };
|
|
39777
39839
|
writeFileSync10(packageJsonPath, JSON.stringify(pkgJson, null, 2), "utf-8");
|
|
39778
39840
|
}
|
|
39779
39841
|
}
|
|
39780
39842
|
function ensureGitIgnore(dir) {
|
|
39781
|
-
if (!
|
|
39843
|
+
if (!existsSync27(dir)) {
|
|
39782
39844
|
mkdirSync9(dir, { recursive: true });
|
|
39783
39845
|
}
|
|
39784
|
-
const ignorePath =
|
|
39785
|
-
if (!
|
|
39846
|
+
const ignorePath = join38(dir, ".gitignore");
|
|
39847
|
+
if (!existsSync27(ignorePath)) {
|
|
39786
39848
|
writeFileSync10(ignorePath, `*
|
|
39787
39849
|
!.gitignore
|
|
39788
39850
|
`, "utf-8");
|
|
@@ -39790,12 +39852,12 @@ function ensureGitIgnore(dir) {
|
|
|
39790
39852
|
}
|
|
39791
39853
|
function getManagedNpmInstallPath(context, source, scope) {
|
|
39792
39854
|
if (scope === "temporary") {
|
|
39793
|
-
return
|
|
39855
|
+
return join38(getNpmInstallRoot(context, scope, true), "node_modules", source.name);
|
|
39794
39856
|
}
|
|
39795
39857
|
if (scope === "project") {
|
|
39796
|
-
return
|
|
39858
|
+
return join38(context.cwd, CONFIG_DIR_NAME, "npm", "node_modules", source.name);
|
|
39797
39859
|
}
|
|
39798
|
-
return
|
|
39860
|
+
return join38(context.agentDir, "npm", "node_modules", source.name);
|
|
39799
39861
|
}
|
|
39800
39862
|
function getGlobalNpmRoot(context) {
|
|
39801
39863
|
const npmCommand = getNpmCommand(context);
|
|
@@ -39805,7 +39867,7 @@ function getGlobalNpmRoot(context) {
|
|
|
39805
39867
|
}
|
|
39806
39868
|
if (getPackageManagerName(context) === "bun") {
|
|
39807
39869
|
const binDir = runNpmCommandSync(context, ["pm", "bin", "-g"]).trim();
|
|
39808
|
-
context.globalNpmRoot =
|
|
39870
|
+
context.globalNpmRoot = join38(dirname17(binDir), "install", "global", "node_modules");
|
|
39809
39871
|
} else {
|
|
39810
39872
|
context.globalNpmRoot = runNpmCommandSync(context, ["root", "-g"]).trim();
|
|
39811
39873
|
}
|
|
@@ -39831,28 +39893,28 @@ function getLegacyGlobalNpmInstallPath(context, source) {
|
|
|
39831
39893
|
if (pnpmPath)
|
|
39832
39894
|
return pnpmPath;
|
|
39833
39895
|
const globalRoot = context.driver?.getGlobalNpmRoot ? context.driver.getGlobalNpmRoot() : getGlobalNpmRoot(context);
|
|
39834
|
-
return
|
|
39896
|
+
return join38(globalRoot, source.name);
|
|
39835
39897
|
} catch {
|
|
39836
39898
|
return;
|
|
39837
39899
|
}
|
|
39838
39900
|
}
|
|
39839
39901
|
function getNpmInstallPath(context, source, scope) {
|
|
39840
39902
|
const managedPath = getManagedNpmInstallPath(context, source, scope);
|
|
39841
|
-
if (scope !== "user" ||
|
|
39903
|
+
if (scope !== "user" || existsSync27(managedPath)) {
|
|
39842
39904
|
return managedPath;
|
|
39843
39905
|
}
|
|
39844
39906
|
const legacyPath = getLegacyGlobalNpmInstallPath(context, source);
|
|
39845
|
-
return legacyPath &&
|
|
39907
|
+
return legacyPath && existsSync27(legacyPath) ? legacyPath : managedPath;
|
|
39846
39908
|
}
|
|
39847
39909
|
function getExistingNpmInstallPath(context, source, scope) {
|
|
39848
39910
|
const candidates = [getNpmInstallPath(context, source, scope)];
|
|
39849
39911
|
if (scope === "project") {
|
|
39850
39912
|
for (const configDir of getProjectConfigDirs(context.cwd)) {
|
|
39851
|
-
candidates.push(
|
|
39913
|
+
candidates.push(join38(configDir, "npm", "node_modules", source.name));
|
|
39852
39914
|
}
|
|
39853
39915
|
}
|
|
39854
39916
|
for (const candidate of Array.from(new Set(candidates))) {
|
|
39855
|
-
if (
|
|
39917
|
+
if (existsSync27(candidate))
|
|
39856
39918
|
return candidate;
|
|
39857
39919
|
}
|
|
39858
39920
|
return;
|
|
@@ -39889,11 +39951,11 @@ async function npmHasAvailableUpdate(context, source, installedPath) {
|
|
|
39889
39951
|
}
|
|
39890
39952
|
}
|
|
39891
39953
|
function getInstalledNpmVersion(installedPath) {
|
|
39892
|
-
const packageJsonPath =
|
|
39893
|
-
if (!
|
|
39954
|
+
const packageJsonPath = join38(installedPath, "package.json");
|
|
39955
|
+
if (!existsSync27(packageJsonPath))
|
|
39894
39956
|
return;
|
|
39895
39957
|
try {
|
|
39896
|
-
const content =
|
|
39958
|
+
const content = readFileSync18(packageJsonPath, "utf-8");
|
|
39897
39959
|
const pkg2 = JSON.parse(content);
|
|
39898
39960
|
return pkg2.version;
|
|
39899
39961
|
} catch {
|
|
@@ -39948,8 +40010,8 @@ async function withProgress(context, action, source, message, operation) {
|
|
|
39948
40010
|
}
|
|
39949
40011
|
|
|
39950
40012
|
// src/core/package-manager-git.ts
|
|
39951
|
-
import { existsSync as
|
|
39952
|
-
import { basename as basename9, dirname as
|
|
40013
|
+
import { existsSync as existsSync28, mkdirSync as mkdirSync10, readdirSync as readdirSync7, readFileSync as readFileSync19, rmSync as rmSync6, writeFileSync as writeFileSync11 } from "node:fs";
|
|
40014
|
+
import { basename as basename9, dirname as dirname18, join as join39, resolve as resolve9, sep as sep7 } from "node:path";
|
|
39953
40015
|
function runGitProcess(context, command, args, options) {
|
|
39954
40016
|
return context.driver ? context.driver.runCommand(command, args, options) : runCommand2(command, args, options);
|
|
39955
40017
|
}
|
|
@@ -39978,28 +40040,28 @@ function getExistingGitInstallPath(context, source, scope) {
|
|
|
39978
40040
|
const candidates = [getGitInstallPath(context, source, scope)];
|
|
39979
40041
|
if (scope === "project") {
|
|
39980
40042
|
for (const configDir of getProjectConfigDirs(context.cwd)) {
|
|
39981
|
-
candidates.push(
|
|
40043
|
+
candidates.push(join39(configDir, "git", source.host, source.path));
|
|
39982
40044
|
}
|
|
39983
40045
|
} else if (scope === "user") {
|
|
39984
40046
|
for (const agentDir of getBaseDirsForScope(context, "user")) {
|
|
39985
|
-
candidates.push(
|
|
40047
|
+
candidates.push(join39(agentDir, "git", source.host, source.path));
|
|
39986
40048
|
}
|
|
39987
40049
|
}
|
|
39988
40050
|
for (const candidate of Array.from(new Set(candidates))) {
|
|
39989
|
-
if (
|
|
40051
|
+
if (existsSync28(candidate))
|
|
39990
40052
|
return candidate;
|
|
39991
40053
|
}
|
|
39992
40054
|
return;
|
|
39993
40055
|
}
|
|
39994
40056
|
function getGitUpdateMarkerPath(targetDir) {
|
|
39995
|
-
return
|
|
40057
|
+
return join39(dirname18(targetDir), `.${basename9(targetDir)}.${APP_NAME}-update-incomplete`);
|
|
39996
40058
|
}
|
|
39997
40059
|
function hasMissingGitDependencies(targetDir) {
|
|
39998
|
-
const packageJsonPath =
|
|
39999
|
-
if (!
|
|
40060
|
+
const packageJsonPath = join39(targetDir, "package.json");
|
|
40061
|
+
if (!existsSync28(packageJsonPath))
|
|
40000
40062
|
return false;
|
|
40001
40063
|
try {
|
|
40002
|
-
const manifest = JSON.parse(
|
|
40064
|
+
const manifest = JSON.parse(readFileSync19(packageJsonPath, "utf-8"));
|
|
40003
40065
|
if (!manifest.dependencies || typeof manifest.dependencies !== "object" || Array.isArray(manifest.dependencies)) {
|
|
40004
40066
|
return false;
|
|
40005
40067
|
}
|
|
@@ -40008,7 +40070,7 @@ function hasMissingGitDependencies(targetDir) {
|
|
|
40008
40070
|
const dependencyPath = resolve9(nodeModulesDir, name);
|
|
40009
40071
|
if (!dependencyPath.startsWith(`${nodeModulesDir}${sep7}`))
|
|
40010
40072
|
return false;
|
|
40011
|
-
return !
|
|
40073
|
+
return !existsSync28(dependencyPath);
|
|
40012
40074
|
});
|
|
40013
40075
|
} catch {
|
|
40014
40076
|
return false;
|
|
@@ -40026,7 +40088,7 @@ async function cleanAndInstallGitDependencies(context, targetDir, markerPath) {
|
|
|
40026
40088
|
await repairMissingGitDependencies(context, targetDir).catch(() => {});
|
|
40027
40089
|
throw error;
|
|
40028
40090
|
}
|
|
40029
|
-
if (
|
|
40091
|
+
if (existsSync28(join39(targetDir, "package.json"))) {
|
|
40030
40092
|
await runNpmCommand(context, getGitDependencyInstallArgs(context), { cwd: targetDir });
|
|
40031
40093
|
}
|
|
40032
40094
|
rmSync6(markerPath, { force: true });
|
|
@@ -40034,7 +40096,7 @@ async function cleanAndInstallGitDependencies(context, targetDir, markerPath) {
|
|
|
40034
40096
|
async function installGit(context, source, scope) {
|
|
40035
40097
|
const safeRef = source.ref ? getSafeGitRef(source.ref) : undefined;
|
|
40036
40098
|
const targetDir = getGitInstallPath(context, source, scope);
|
|
40037
|
-
if (
|
|
40099
|
+
if (existsSync28(targetDir)) {
|
|
40038
40100
|
if (safeRef) {
|
|
40039
40101
|
await ensureGitRef(context, targetDir, ["fetch", "origin", "--", safeRef], "FETCH_HEAD");
|
|
40040
40102
|
return;
|
|
@@ -40047,7 +40109,7 @@ async function installGit(context, source, scope) {
|
|
|
40047
40109
|
if (gitRoot) {
|
|
40048
40110
|
ensureGitIgnore(gitRoot);
|
|
40049
40111
|
}
|
|
40050
|
-
mkdirSync10(
|
|
40112
|
+
mkdirSync10(dirname18(targetDir), { recursive: true });
|
|
40051
40113
|
rmSync6(getGitUpdateMarkerPath(targetDir), { force: true });
|
|
40052
40114
|
const cloneUrl = source.repo;
|
|
40053
40115
|
if (!/^[A-Za-z0-9._~:@/%+-]+$/.test(cloneUrl)) {
|
|
@@ -40058,8 +40120,8 @@ async function installGit(context, source, scope) {
|
|
|
40058
40120
|
if (safeRef) {
|
|
40059
40121
|
await runGitProcess(context, "git", ["checkout", safeRef], { cwd: targetDir });
|
|
40060
40122
|
}
|
|
40061
|
-
const packageJsonPath =
|
|
40062
|
-
if (
|
|
40123
|
+
const packageJsonPath = join39(targetDir, "package.json");
|
|
40124
|
+
if (existsSync28(packageJsonPath)) {
|
|
40063
40125
|
await runNpmCommand(context, getGitDependencyInstallArgs(context), { cwd: targetDir });
|
|
40064
40126
|
}
|
|
40065
40127
|
} catch (error) {
|
|
@@ -40071,7 +40133,7 @@ async function installGit(context, source, scope) {
|
|
|
40071
40133
|
async function updateGit(context, source, scope) {
|
|
40072
40134
|
const safeRef = source.ref ? getSafeGitRef(source.ref) : undefined;
|
|
40073
40135
|
const targetDir = getExistingGitInstallPath(context, source, scope) ?? getGitInstallPath(context, source, scope);
|
|
40074
|
-
if (!
|
|
40136
|
+
if (!existsSync28(targetDir)) {
|
|
40075
40137
|
await installGit(context, source, scope);
|
|
40076
40138
|
return;
|
|
40077
40139
|
}
|
|
@@ -40095,7 +40157,7 @@ async function ensureGitRef(context, targetDir, fetchArgs, ref) {
|
|
|
40095
40157
|
});
|
|
40096
40158
|
const markerPath = getGitUpdateMarkerPath(targetDir);
|
|
40097
40159
|
if (localHead.trim() === targetHead.trim()) {
|
|
40098
|
-
if (
|
|
40160
|
+
if (existsSync28(markerPath)) {
|
|
40099
40161
|
await cleanAndInstallGitDependencies(context, targetDir, markerPath);
|
|
40100
40162
|
} else {
|
|
40101
40163
|
await repairMissingGitDependencies(context, targetDir);
|
|
@@ -40126,10 +40188,10 @@ function pruneEmptyGitParents(targetDir, installRoot) {
|
|
|
40126
40188
|
if (!installRoot)
|
|
40127
40189
|
return;
|
|
40128
40190
|
const resolvedRoot = resolve9(installRoot);
|
|
40129
|
-
let current =
|
|
40191
|
+
let current = dirname18(targetDir);
|
|
40130
40192
|
while (current.startsWith(resolvedRoot) && current !== resolvedRoot) {
|
|
40131
|
-
if (!
|
|
40132
|
-
current =
|
|
40193
|
+
if (!existsSync28(current)) {
|
|
40194
|
+
current = dirname18(current);
|
|
40133
40195
|
continue;
|
|
40134
40196
|
}
|
|
40135
40197
|
const entries = readdirSync7(current);
|
|
@@ -40140,7 +40202,7 @@ function pruneEmptyGitParents(targetDir, installRoot) {
|
|
|
40140
40202
|
} catch {
|
|
40141
40203
|
break;
|
|
40142
40204
|
}
|
|
40143
|
-
current =
|
|
40205
|
+
current = dirname18(current);
|
|
40144
40206
|
}
|
|
40145
40207
|
}
|
|
40146
40208
|
async function gitHasAvailableUpdate(context, installedPath) {
|
|
@@ -40595,7 +40657,7 @@ var init_package_manager_source = __esm(() => {
|
|
|
40595
40657
|
});
|
|
40596
40658
|
|
|
40597
40659
|
// src/core/package-manager-operations.ts
|
|
40598
|
-
import { existsSync as
|
|
40660
|
+
import { existsSync as existsSync29 } from "node:fs";
|
|
40599
40661
|
async function install2(context, source, options) {
|
|
40600
40662
|
const parsed = parseSource(source);
|
|
40601
40663
|
const scope = options?.local ? "project" : "user";
|
|
@@ -40611,7 +40673,7 @@ async function install2(context, source, options) {
|
|
|
40611
40673
|
}
|
|
40612
40674
|
if (parsed.type === "local") {
|
|
40613
40675
|
const resolved = resolveManagerPath(context, parsed.path);
|
|
40614
|
-
if (!
|
|
40676
|
+
if (!existsSync29(resolved)) {
|
|
40615
40677
|
throw new Error(`Path does not exist: ${resolved}`);
|
|
40616
40678
|
}
|
|
40617
40679
|
return;
|
|
@@ -40721,7 +40783,7 @@ async function updateConfiguredSources(context, sources) {
|
|
|
40721
40783
|
}
|
|
40722
40784
|
async function shouldUpdateNpmSource(context, source, scope) {
|
|
40723
40785
|
const installedPath = getManagedNpmInstallPath(context, source, scope);
|
|
40724
|
-
const installedVersion =
|
|
40786
|
+
const installedVersion = existsSync29(installedPath) ? getInstalledNpmVersion(installedPath) : undefined;
|
|
40725
40787
|
if (!installedVersion)
|
|
40726
40788
|
return true;
|
|
40727
40789
|
try {
|
|
@@ -40758,7 +40820,7 @@ async function checkForAvailableUpdates(context) {
|
|
|
40758
40820
|
return;
|
|
40759
40821
|
if (parsed.type === "npm") {
|
|
40760
40822
|
const installedPath2 = getNpmInstallPath(context, parsed, entry.scope);
|
|
40761
|
-
if (!
|
|
40823
|
+
if (!existsSync29(installedPath2))
|
|
40762
40824
|
return;
|
|
40763
40825
|
const hasUpdate2 = await npmHasAvailableUpdate(context, parsed, installedPath2);
|
|
40764
40826
|
if (!hasUpdate2)
|
|
@@ -40856,7 +40918,7 @@ var init_package_manager_resource_accumulator = __esm(() => {
|
|
|
40856
40918
|
});
|
|
40857
40919
|
|
|
40858
40920
|
// src/core/package-manager-resource-patterns.ts
|
|
40859
|
-
import { basename as basename10, dirname as
|
|
40921
|
+
import { basename as basename10, dirname as dirname19, relative as relative9, sep as sep8 } from "node:path";
|
|
40860
40922
|
import { minimatch } from "minimatch";
|
|
40861
40923
|
function toPosixPath4(p) {
|
|
40862
40924
|
return p.split(sep8).join("/");
|
|
@@ -40887,7 +40949,7 @@ function matchesAnyPattern(filePath, patterns, baseDir) {
|
|
|
40887
40949
|
const name = basename10(filePath);
|
|
40888
40950
|
const filePathPosix = toPosixPath4(filePath);
|
|
40889
40951
|
const isSkillFile = name === "SKILL.md";
|
|
40890
|
-
const parentDir = isSkillFile ?
|
|
40952
|
+
const parentDir = isSkillFile ? dirname19(filePath) : undefined;
|
|
40891
40953
|
const parentRel = isSkillFile ? toPosixPath4(relative9(baseDir, parentDir)) : undefined;
|
|
40892
40954
|
const parentName = isSkillFile ? basename10(parentDir) : undefined;
|
|
40893
40955
|
const parentDirPosix = isSkillFile ? toPosixPath4(parentDir) : undefined;
|
|
@@ -40912,7 +40974,7 @@ function matchesAnyExactPattern(filePath, patterns, baseDir) {
|
|
|
40912
40974
|
const name = basename10(filePath);
|
|
40913
40975
|
const filePathPosix = toPosixPath4(filePath);
|
|
40914
40976
|
const isSkillFile = name === "SKILL.md";
|
|
40915
|
-
const parentDir = isSkillFile ?
|
|
40977
|
+
const parentDir = isSkillFile ? dirname19(filePath) : undefined;
|
|
40916
40978
|
const parentRel = isSkillFile ? toPosixPath4(relative9(baseDir, parentDir)) : undefined;
|
|
40917
40979
|
const parentDirPosix = isSkillFile ? toPosixPath4(parentDir) : undefined;
|
|
40918
40980
|
return patterns.some((pattern) => {
|
|
@@ -41013,7 +41075,7 @@ var init_package_manager_types = __esm(() => {
|
|
|
41013
41075
|
|
|
41014
41076
|
// src/core/package-manager-resource-files.ts
|
|
41015
41077
|
import { access as access2, readdir as readdir3, readFile as readFile2, stat as stat3 } from "node:fs/promises";
|
|
41016
|
-
import { dirname as
|
|
41078
|
+
import { dirname as dirname20, join as join40, relative as relative10, resolve as resolve10, sep as sep9 } from "node:path";
|
|
41017
41079
|
import ignore2 from "ignore";
|
|
41018
41080
|
async function exists(path13) {
|
|
41019
41081
|
try {
|
|
@@ -41044,7 +41106,7 @@ async function addIgnoreRules(ig, dir, rootDir) {
|
|
|
41044
41106
|
const prefix = relativeDir ? `${toPosixPath4(relativeDir)}/` : "";
|
|
41045
41107
|
for (const filename of IGNORE_FILE_NAMES) {
|
|
41046
41108
|
try {
|
|
41047
|
-
const content = await readFile2(
|
|
41109
|
+
const content = await readFile2(join40(dir, filename), "utf-8");
|
|
41048
41110
|
const patterns = content.split(/\r?\n/).map((line) => prefixIgnorePattern(line, prefix)).filter((line) => Boolean(line));
|
|
41049
41111
|
if (patterns.length > 0)
|
|
41050
41112
|
ig.add(patterns);
|
|
@@ -41052,7 +41114,7 @@ async function addIgnoreRules(ig, dir, rootDir) {
|
|
|
41052
41114
|
}
|
|
41053
41115
|
}
|
|
41054
41116
|
async function getEntryInfo(dir, name, isDirectory, isFileEntry, isSymlink) {
|
|
41055
|
-
const fullPath =
|
|
41117
|
+
const fullPath = join40(dir, name);
|
|
41056
41118
|
let isDir = isDirectory;
|
|
41057
41119
|
let isFile = isFileEntry;
|
|
41058
41120
|
if (isSymlink) {
|
|
@@ -41142,9 +41204,9 @@ async function collectAutoSkillEntries(dir, mode) {
|
|
|
41142
41204
|
async function findGitRepoRoot(startDir) {
|
|
41143
41205
|
let dir = resolve10(startDir);
|
|
41144
41206
|
while (true) {
|
|
41145
|
-
if (await exists(
|
|
41207
|
+
if (await exists(join40(dir, ".git")))
|
|
41146
41208
|
return dir;
|
|
41147
|
-
const parent =
|
|
41209
|
+
const parent = dirname20(dir);
|
|
41148
41210
|
if (parent === dir)
|
|
41149
41211
|
return null;
|
|
41150
41212
|
dir = parent;
|
|
@@ -41156,10 +41218,10 @@ async function collectAncestorAgentsSkillDirs(startDir) {
|
|
|
41156
41218
|
const gitRepoRoot = await findGitRepoRoot(resolvedStartDir);
|
|
41157
41219
|
let dir = resolvedStartDir;
|
|
41158
41220
|
while (true) {
|
|
41159
|
-
skillDirs.push(
|
|
41221
|
+
skillDirs.push(join40(dir, ".agents", "skills"));
|
|
41160
41222
|
if (gitRepoRoot && dir === gitRepoRoot)
|
|
41161
41223
|
break;
|
|
41162
|
-
const parent =
|
|
41224
|
+
const parent = dirname20(dir);
|
|
41163
41225
|
if (parent === dir)
|
|
41164
41226
|
break;
|
|
41165
41227
|
dir = parent;
|
|
@@ -41198,7 +41260,7 @@ async function collectAutoThemeEntries(dir) {
|
|
|
41198
41260
|
return collectFlatEntries(dir, ".json");
|
|
41199
41261
|
}
|
|
41200
41262
|
async function resolveExtensionEntries(dir) {
|
|
41201
|
-
const packageJsonPath =
|
|
41263
|
+
const packageJsonPath = join40(dir, "package.json");
|
|
41202
41264
|
if (await exists(packageJsonPath)) {
|
|
41203
41265
|
try {
|
|
41204
41266
|
const manifest = getManifestFromPackageJson(JSON.parse(await readFile2(packageJsonPath, "utf-8")));
|
|
@@ -41214,8 +41276,8 @@ async function resolveExtensionEntries(dir) {
|
|
|
41214
41276
|
}
|
|
41215
41277
|
} catch {}
|
|
41216
41278
|
}
|
|
41217
|
-
const indexTs =
|
|
41218
|
-
const indexJs =
|
|
41279
|
+
const indexTs = join40(dir, "index.ts");
|
|
41280
|
+
const indexJs = join40(dir, "index.js");
|
|
41219
41281
|
if (await exists(indexTs))
|
|
41220
41282
|
return [indexTs];
|
|
41221
41283
|
if (await exists(indexJs))
|
|
@@ -41273,7 +41335,7 @@ var init_package_manager_resource_files = __esm(() => {
|
|
|
41273
41335
|
});
|
|
41274
41336
|
|
|
41275
41337
|
// src/core/package-manager-auto-resources.ts
|
|
41276
|
-
import { dirname as
|
|
41338
|
+
import { dirname as dirname21, join as join41, resolve as resolve11 } from "node:path";
|
|
41277
41339
|
async function collectProjectLocalResources(sourceRoot, accumulator, filter, metadata) {
|
|
41278
41340
|
let found = false;
|
|
41279
41341
|
const projectMetadata = { ...metadata, origin: "top-level", borrowedProjectLocal: true };
|
|
@@ -41288,14 +41350,14 @@ async function collectProjectLocalResources(sourceRoot, accumulator, filter, met
|
|
|
41288
41350
|
};
|
|
41289
41351
|
for (const configDir of getProjectConfigDirs(sourceRoot)) {
|
|
41290
41352
|
const configMetadata = { ...projectMetadata, baseDir: configDir };
|
|
41291
|
-
addResources("extensions", await collectAutoExtensionEntries(
|
|
41292
|
-
addResources("skills", await collectAutoSkillEntries(
|
|
41293
|
-
addResources("prompts", await collectAutoPromptEntries(
|
|
41294
|
-
addResources("themes", await collectAutoThemeEntries(
|
|
41295
|
-
addResources("workflows", await collectResourceFiles(
|
|
41296
|
-
}
|
|
41297
|
-
const agentsSkillsDir =
|
|
41298
|
-
addResources("skills", await collectAutoSkillEntries(agentsSkillsDir, "agents"), { ...projectMetadata, baseDir:
|
|
41353
|
+
addResources("extensions", await collectAutoExtensionEntries(join41(configDir, "extensions")), configMetadata, filter?.extensions);
|
|
41354
|
+
addResources("skills", await collectAutoSkillEntries(join41(configDir, "skills"), "pi"), configMetadata, filter?.skills);
|
|
41355
|
+
addResources("prompts", await collectAutoPromptEntries(join41(configDir, "prompts")), configMetadata, filter?.prompts);
|
|
41356
|
+
addResources("themes", await collectAutoThemeEntries(join41(configDir, "themes")), configMetadata, filter?.themes);
|
|
41357
|
+
addResources("workflows", await collectResourceFiles(join41(configDir, "workflows"), "workflows"), configMetadata, filter?.workflows);
|
|
41358
|
+
}
|
|
41359
|
+
const agentsSkillsDir = join41(sourceRoot, ".agents", "skills");
|
|
41360
|
+
addResources("skills", await collectAutoSkillEntries(agentsSkillsDir, "agents"), { ...projectMetadata, baseDir: dirname21(agentsSkillsDir) }, filter?.skills);
|
|
41299
41361
|
return found;
|
|
41300
41362
|
}
|
|
41301
41363
|
async function addAutoDiscoveredResources(context, accumulator, globalSettings, projectSettings, globalBaseDir, projectBaseDir) {
|
|
@@ -41322,7 +41384,7 @@ async function addAutoDiscoveredResources(context, accumulator, globalSettings,
|
|
|
41322
41384
|
};
|
|
41323
41385
|
const userConfigDirs = getBaseDirsForScope(context, "user");
|
|
41324
41386
|
const projectConfigDirs = getBaseDirsForScope(context, "project");
|
|
41325
|
-
const userAgentsSkillsDir =
|
|
41387
|
+
const userAgentsSkillsDir = join41(getHomeDir2(), ".agents", "skills");
|
|
41326
41388
|
const projectTrusted = context.settingsManager.isProjectTrusted();
|
|
41327
41389
|
const projectAgentsSkillDirs = projectTrusted ? (await collectAncestorAgentsSkillDirs(context.cwd)).filter((dir) => resolve11(dir) !== resolve11(userAgentsSkillsDir)) : [];
|
|
41328
41390
|
const addResources = (resourceType, paths, metadata, overrides, baseDir) => {
|
|
@@ -41337,15 +41399,15 @@ async function addAutoDiscoveredResources(context, accumulator, globalSettings,
|
|
|
41337
41399
|
baseDir: configDir,
|
|
41338
41400
|
configurationOrigin: index === 0 ? "atomic" : "inherited-pi"
|
|
41339
41401
|
};
|
|
41340
|
-
addResources("extensions", await collectAutoExtensionEntries(
|
|
41341
|
-
addResources("skills", await collectAutoSkillEntries(
|
|
41342
|
-
addResources("prompts", await collectAutoPromptEntries(
|
|
41343
|
-
addResources("themes", await collectAutoThemeEntries(
|
|
41344
|
-
addResources("workflows", await collectResourceFiles(
|
|
41402
|
+
addResources("extensions", await collectAutoExtensionEntries(join41(configDir, "extensions")), metadata, projectOverrides.extensions, configDir);
|
|
41403
|
+
addResources("skills", await collectAutoSkillEntries(join41(configDir, "skills"), "pi"), metadata, projectOverrides.skills, configDir);
|
|
41404
|
+
addResources("prompts", await collectAutoPromptEntries(join41(configDir, "prompts")), metadata, projectOverrides.prompts, configDir);
|
|
41405
|
+
addResources("themes", await collectAutoThemeEntries(join41(configDir, "themes")), metadata, projectOverrides.themes, configDir);
|
|
41406
|
+
addResources("workflows", await collectResourceFiles(join41(configDir, "workflows"), "workflows"), metadata, projectOverrides.workflows, configDir);
|
|
41345
41407
|
}
|
|
41346
41408
|
}
|
|
41347
41409
|
for (const agentsSkillsDir of projectAgentsSkillDirs) {
|
|
41348
|
-
const agentsBaseDir =
|
|
41410
|
+
const agentsBaseDir = dirname21(agentsSkillsDir);
|
|
41349
41411
|
addResources("skills", await collectAutoSkillEntries(agentsSkillsDir, "agents"), { ...projectMetadata, baseDir: agentsBaseDir }, projectOverrides.skills, agentsBaseDir);
|
|
41350
41412
|
}
|
|
41351
41413
|
for (const [index, configDir] of userConfigDirs.entries()) {
|
|
@@ -41354,13 +41416,13 @@ async function addAutoDiscoveredResources(context, accumulator, globalSettings,
|
|
|
41354
41416
|
baseDir: configDir,
|
|
41355
41417
|
configurationOrigin: index === 0 ? "atomic" : "inherited-pi"
|
|
41356
41418
|
};
|
|
41357
|
-
addResources("extensions", await collectAutoExtensionEntries(
|
|
41358
|
-
addResources("skills", await collectAutoSkillEntries(
|
|
41359
|
-
addResources("prompts", await collectAutoPromptEntries(
|
|
41360
|
-
addResources("themes", await collectAutoThemeEntries(
|
|
41361
|
-
addResources("workflows", await collectResourceFiles(
|
|
41419
|
+
addResources("extensions", await collectAutoExtensionEntries(join41(configDir, "extensions")), metadata, userOverrides.extensions, configDir);
|
|
41420
|
+
addResources("skills", await collectAutoSkillEntries(join41(configDir, "skills"), "pi"), metadata, userOverrides.skills, configDir);
|
|
41421
|
+
addResources("prompts", await collectAutoPromptEntries(join41(configDir, "prompts")), metadata, userOverrides.prompts, configDir);
|
|
41422
|
+
addResources("themes", await collectAutoThemeEntries(join41(configDir, "themes")), metadata, userOverrides.themes, configDir);
|
|
41423
|
+
addResources("workflows", await collectResourceFiles(join41(configDir, "workflows"), "workflows"), metadata, userOverrides.workflows, configDir);
|
|
41362
41424
|
}
|
|
41363
|
-
const userAgentsBaseDir =
|
|
41425
|
+
const userAgentsBaseDir = dirname21(userAgentsSkillsDir);
|
|
41364
41426
|
addResources("skills", await collectAutoSkillEntries(userAgentsSkillsDir, "agents"), { ...userMetadata, baseDir: userAgentsBaseDir }, userOverrides.skills, userAgentsBaseDir);
|
|
41365
41427
|
}
|
|
41366
41428
|
var init_package_manager_auto_resources = __esm(() => {
|
|
@@ -41529,7 +41591,7 @@ var init_package_manager_resource_collector = __esm(() => {
|
|
|
41529
41591
|
|
|
41530
41592
|
// src/core/package-manager-resolver.ts
|
|
41531
41593
|
import { access as access4, stat as stat5 } from "node:fs/promises";
|
|
41532
|
-
import { dirname as
|
|
41594
|
+
import { dirname as dirname22, isAbsolute as isAbsolute7, join as join42 } from "node:path";
|
|
41533
41595
|
async function exists3(path13) {
|
|
41534
41596
|
try {
|
|
41535
41597
|
await access4(path13);
|
|
@@ -41552,7 +41614,7 @@ async function resolvePackages(context, onMissing) {
|
|
|
41552
41614
|
const packageSources = dedupePackages(context, allPackages);
|
|
41553
41615
|
await resolvePackageSources(context, packageSources, accumulator, onMissing, { settingsField: "packages" });
|
|
41554
41616
|
const globalBaseDir = context.agentDir;
|
|
41555
|
-
const projectBaseDir =
|
|
41617
|
+
const projectBaseDir = join42(context.cwd, CONFIG_DIR_NAME);
|
|
41556
41618
|
const globalBaseDirs = getBaseDirsForScope(context, "user");
|
|
41557
41619
|
const projectBaseDirs = getBaseDirsForScope(context, "project");
|
|
41558
41620
|
for (const resourceType of ["extensions", "skills", "prompts", "themes", "workflows"]) {
|
|
@@ -41687,7 +41749,7 @@ async function resolveLocalExtensionSource(source, accumulator, filter, metadata
|
|
|
41687
41749
|
try {
|
|
41688
41750
|
const stats = await stat5(resolved);
|
|
41689
41751
|
if (stats.isFile()) {
|
|
41690
|
-
addResource(accumulator.extensions, resolved, { ...metadata, baseDir:
|
|
41752
|
+
addResource(accumulator.extensions, resolved, { ...metadata, baseDir: dirname22(resolved) }, true);
|
|
41691
41753
|
return;
|
|
41692
41754
|
}
|
|
41693
41755
|
if (stats.isDirectory()) {
|
|
@@ -41718,7 +41780,7 @@ var init_package_manager_resolver = __esm(() => {
|
|
|
41718
41780
|
});
|
|
41719
41781
|
|
|
41720
41782
|
// src/core/package-manager-settings.ts
|
|
41721
|
-
import { existsSync as
|
|
41783
|
+
import { existsSync as existsSync30 } from "node:fs";
|
|
41722
41784
|
function addSourceToSettings(context, source, options) {
|
|
41723
41785
|
const scope = options?.local ? "project" : "user";
|
|
41724
41786
|
const currentSettings = scope === "project" ? context.settingsManager.getProjectSettings() : context.settingsManager.getGlobalSettings();
|
|
@@ -41772,7 +41834,7 @@ function getInstalledPath(context, source, scope) {
|
|
|
41772
41834
|
}
|
|
41773
41835
|
for (const baseDir of getBaseDirsForScope(context, scope)) {
|
|
41774
41836
|
const path13 = resolvePathFromBase(parsed.path, baseDir);
|
|
41775
|
-
if (
|
|
41837
|
+
if (existsSync30(path13))
|
|
41776
41838
|
return path13;
|
|
41777
41839
|
}
|
|
41778
41840
|
return;
|
|
@@ -41996,29 +42058,29 @@ var init_package_manager = __esm(() => {
|
|
|
41996
42058
|
|
|
41997
42059
|
// src/core/footer-data-provider.ts
|
|
41998
42060
|
import { execFile, spawnSync as spawnSync6 } from "child_process";
|
|
41999
|
-
import { existsSync as
|
|
42000
|
-
import { dirname as
|
|
42061
|
+
import { existsSync as existsSync31, readFileSync as readFileSync20, statSync as statSync7, unwatchFile as unwatchFile2, watchFile as watchFile2 } from "fs";
|
|
42062
|
+
import { dirname as dirname23, join as join43, resolve as resolve13 } from "path";
|
|
42001
42063
|
function findGitPaths(cwd) {
|
|
42002
42064
|
let dir = cwd;
|
|
42003
42065
|
while (true) {
|
|
42004
|
-
const gitPath =
|
|
42005
|
-
if (
|
|
42066
|
+
const gitPath = join43(dir, ".git");
|
|
42067
|
+
if (existsSync31(gitPath)) {
|
|
42006
42068
|
try {
|
|
42007
42069
|
const stat6 = statSync7(gitPath);
|
|
42008
42070
|
if (stat6.isFile()) {
|
|
42009
|
-
const content =
|
|
42071
|
+
const content = readFileSync20(gitPath, "utf8").trim();
|
|
42010
42072
|
if (content.startsWith("gitdir: ")) {
|
|
42011
42073
|
const gitDir = resolve13(dir, content.slice(8).trim());
|
|
42012
|
-
const headPath =
|
|
42013
|
-
if (!
|
|
42074
|
+
const headPath = join43(gitDir, "HEAD");
|
|
42075
|
+
if (!existsSync31(headPath))
|
|
42014
42076
|
return null;
|
|
42015
|
-
const commonDirPath =
|
|
42016
|
-
const commonGitDir =
|
|
42077
|
+
const commonDirPath = join43(gitDir, "commondir");
|
|
42078
|
+
const commonGitDir = existsSync31(commonDirPath) ? resolve13(gitDir, readFileSync20(commonDirPath, "utf8").trim()) : gitDir;
|
|
42017
42079
|
return { repoDir: dir, commonGitDir, headPath };
|
|
42018
42080
|
}
|
|
42019
42081
|
} else if (stat6.isDirectory()) {
|
|
42020
|
-
const headPath =
|
|
42021
|
-
if (!
|
|
42082
|
+
const headPath = join43(gitPath, "HEAD");
|
|
42083
|
+
if (!existsSync31(headPath))
|
|
42022
42084
|
return null;
|
|
42023
42085
|
return { repoDir: dir, commonGitDir: gitPath, headPath };
|
|
42024
42086
|
}
|
|
@@ -42026,7 +42088,7 @@ function findGitPaths(cwd) {
|
|
|
42026
42088
|
return null;
|
|
42027
42089
|
}
|
|
42028
42090
|
}
|
|
42029
|
-
const parent =
|
|
42091
|
+
const parent = dirname23(dir);
|
|
42030
42092
|
if (parent === dir)
|
|
42031
42093
|
return null;
|
|
42032
42094
|
dir = parent;
|
|
@@ -42210,7 +42272,7 @@ class FooterDataProvider {
|
|
|
42210
42272
|
try {
|
|
42211
42273
|
if (!this.gitPaths)
|
|
42212
42274
|
return null;
|
|
42213
|
-
const content =
|
|
42275
|
+
const content = readFileSync20(this.gitPaths.headPath, "utf8").trim();
|
|
42214
42276
|
if (content.startsWith("ref: refs/heads/")) {
|
|
42215
42277
|
const branch = content.slice(16);
|
|
42216
42278
|
return branch === ".invalid" ? resolveBranchWithGitSync(this.gitPaths.repoDir) ?? "detached" : branch;
|
|
@@ -42224,7 +42286,7 @@ class FooterDataProvider {
|
|
|
42224
42286
|
try {
|
|
42225
42287
|
if (!this.gitPaths)
|
|
42226
42288
|
return null;
|
|
42227
|
-
const content =
|
|
42289
|
+
const content = readFileSync20(this.gitPaths.headPath, "utf8").trim();
|
|
42228
42290
|
if (content.startsWith("ref: refs/heads/")) {
|
|
42229
42291
|
const branch = content.slice(16);
|
|
42230
42292
|
return branch === ".invalid" ? await resolveBranchWithGitAsync(this.gitPaths.repoDir) ?? "detached" : branch;
|
|
@@ -42295,12 +42357,12 @@ class FooterDataProvider {
|
|
|
42295
42357
|
this.scheduleGitWatcherRetry();
|
|
42296
42358
|
}
|
|
42297
42359
|
readReftableTablesListFingerprint() {
|
|
42298
|
-
if (!this.reftableTablesListPath || !
|
|
42360
|
+
if (!this.reftableTablesListPath || !existsSync31(this.reftableTablesListPath)) {
|
|
42299
42361
|
return null;
|
|
42300
42362
|
}
|
|
42301
42363
|
try {
|
|
42302
42364
|
const stat6 = statSync7(this.reftableTablesListPath);
|
|
42303
|
-
const content =
|
|
42365
|
+
const content = readFileSync20(this.reftableTablesListPath, "utf8");
|
|
42304
42366
|
return `${stat6.size}:${stat6.mtimeMs}:${stat6.ctimeMs}:${content}`;
|
|
42305
42367
|
} catch {
|
|
42306
42368
|
return null;
|
|
@@ -42327,7 +42389,7 @@ class FooterDataProvider {
|
|
|
42327
42389
|
if (!this.gitPaths)
|
|
42328
42390
|
return;
|
|
42329
42391
|
const pollGitHead = shouldPollGitHead(this.gitPaths.repoDir);
|
|
42330
|
-
this.headWatcher = watchWithErrorHandler(
|
|
42392
|
+
this.headWatcher = watchWithErrorHandler(dirname23(this.gitPaths.headPath), (_eventType, filename) => {
|
|
42331
42393
|
if (!filename || filename === "HEAD") {
|
|
42332
42394
|
this.scheduleRefresh();
|
|
42333
42395
|
}
|
|
@@ -42344,9 +42406,9 @@ class FooterDataProvider {
|
|
|
42344
42406
|
if (!this.headWatcher && !this.headWatchFileListener) {
|
|
42345
42407
|
return;
|
|
42346
42408
|
}
|
|
42347
|
-
const reftableDir =
|
|
42348
|
-
if (
|
|
42349
|
-
this.reftableTablesListPath =
|
|
42409
|
+
const reftableDir = join43(this.gitPaths.commonGitDir, "reftable");
|
|
42410
|
+
if (existsSync31(reftableDir)) {
|
|
42411
|
+
this.reftableTablesListPath = join43(reftableDir, "tables.list");
|
|
42350
42412
|
this.reftableTablesListFingerprint = this.readReftableTablesListFingerprint();
|
|
42351
42413
|
this.reftableWatcher = watchWithErrorHandler(reftableDir, (_eventType, filename) => {
|
|
42352
42414
|
this.handleReftableDirectoryEvent(filename);
|
|
@@ -42357,7 +42419,7 @@ class FooterDataProvider {
|
|
|
42357
42419
|
this.handleGitWatcherError();
|
|
42358
42420
|
});
|
|
42359
42421
|
const tablesListPath = this.reftableTablesListPath;
|
|
42360
|
-
if (tablesListPath &&
|
|
42422
|
+
if (tablesListPath && existsSync31(tablesListPath)) {
|
|
42361
42423
|
this.reftableTablesListWatcher = watchWithErrorHandler(tablesListPath, () => {
|
|
42362
42424
|
this.scheduleReftableRefresh();
|
|
42363
42425
|
}, (error) => {
|
|
@@ -42482,8 +42544,8 @@ function deepMergeSettings(base, overrides) {
|
|
|
42482
42544
|
}
|
|
42483
42545
|
|
|
42484
42546
|
// src/core/settings-storage.ts
|
|
42485
|
-
import { existsSync as
|
|
42486
|
-
import { dirname as
|
|
42547
|
+
import { existsSync as existsSync32, mkdirSync as mkdirSync11, readFileSync as readFileSync21, writeFileSync as writeFileSync12 } from "fs";
|
|
42548
|
+
import { dirname as dirname24, join as join44 } from "path";
|
|
42487
42549
|
import lockfile3 from "proper-lockfile";
|
|
42488
42550
|
|
|
42489
42551
|
class FileSettingsStorage {
|
|
@@ -42494,18 +42556,18 @@ class FileSettingsStorage {
|
|
|
42494
42556
|
constructor(cwd, agentDir, options) {
|
|
42495
42557
|
const resolvedCwd = resolvePath(cwd);
|
|
42496
42558
|
const resolvedAgentDir = resolvePath(agentDir);
|
|
42497
|
-
this.globalSettingsPath =
|
|
42498
|
-
this.projectSettingsPath =
|
|
42559
|
+
this.globalSettingsPath = join44(resolvedAgentDir, "settings.json");
|
|
42560
|
+
this.projectSettingsPath = join44(resolvedCwd, CONFIG_DIR_NAME, "settings.json");
|
|
42499
42561
|
this.globalReadPaths = (options?.globalReadPaths ?? [this.globalSettingsPath]).map((path13) => normalizePath(path13));
|
|
42500
42562
|
this.projectReadPaths = (options?.projectReadPaths ?? [this.projectSettingsPath]).map((path13) => normalizePath(path13));
|
|
42501
42563
|
}
|
|
42502
42564
|
getFieldOrigin(scope, field2) {
|
|
42503
42565
|
const readPaths = scope === "global" ? this.globalReadPaths : this.projectReadPaths;
|
|
42504
42566
|
for (const [index, readPath] of readPaths.entries()) {
|
|
42505
|
-
if (!
|
|
42567
|
+
if (!existsSync32(readPath))
|
|
42506
42568
|
continue;
|
|
42507
42569
|
try {
|
|
42508
|
-
const parsed = parseJsonFileContent(
|
|
42570
|
+
const parsed = parseJsonFileContent(readFileSync21(readPath, "utf-8"));
|
|
42509
42571
|
if (Object.hasOwn(parsed, field2)) {
|
|
42510
42572
|
return index === 0 ? "primary" : "legacy";
|
|
42511
42573
|
}
|
|
@@ -42539,9 +42601,9 @@ class FileSettingsStorage {
|
|
|
42539
42601
|
let found = false;
|
|
42540
42602
|
for (let i = readPaths.length - 1;i >= 0; i--) {
|
|
42541
42603
|
const readPath = readPaths[i];
|
|
42542
|
-
if (!
|
|
42604
|
+
if (!existsSync32(readPath))
|
|
42543
42605
|
continue;
|
|
42544
|
-
const parsed = parseJsonFileContent(
|
|
42606
|
+
const parsed = parseJsonFileContent(readFileSync21(readPath, "utf-8"));
|
|
42545
42607
|
merged = deepMergeSettings(merged, parsed);
|
|
42546
42608
|
found = true;
|
|
42547
42609
|
}
|
|
@@ -42550,21 +42612,21 @@ class FileSettingsStorage {
|
|
|
42550
42612
|
withLock(scope, fn) {
|
|
42551
42613
|
const path13 = scope === "global" ? this.globalSettingsPath : this.projectSettingsPath;
|
|
42552
42614
|
const readPaths = scope === "global" ? this.globalReadPaths : this.projectReadPaths;
|
|
42553
|
-
const dir =
|
|
42615
|
+
const dir = dirname24(path13);
|
|
42554
42616
|
let release;
|
|
42555
42617
|
try {
|
|
42556
|
-
const fileExists2 =
|
|
42618
|
+
const fileExists2 = existsSync32(path13);
|
|
42557
42619
|
if (fileExists2) {
|
|
42558
42620
|
release = this.acquireLockSyncWithRetry(path13);
|
|
42559
42621
|
}
|
|
42560
42622
|
const current = this.readMergedSettings(readPaths);
|
|
42561
42623
|
const next = fn(current);
|
|
42562
42624
|
if (next !== undefined) {
|
|
42563
|
-
if (!
|
|
42625
|
+
if (!existsSync32(dir)) {
|
|
42564
42626
|
mkdirSync11(dir, { recursive: true });
|
|
42565
42627
|
}
|
|
42566
42628
|
if (!release) {
|
|
42567
|
-
if (!
|
|
42629
|
+
if (!existsSync32(path13))
|
|
42568
42630
|
writeFileSync12(path13, "{}", "utf-8");
|
|
42569
42631
|
release = this.acquireLockSyncWithRetry(path13);
|
|
42570
42632
|
}
|
|
@@ -42604,7 +42666,7 @@ var init_settings_storage = __esm(() => {
|
|
|
42604
42666
|
});
|
|
42605
42667
|
|
|
42606
42668
|
// src/core/settings-manager-core.ts
|
|
42607
|
-
import { join as
|
|
42669
|
+
import { join as join45 } from "path";
|
|
42608
42670
|
|
|
42609
42671
|
class SettingsManager {
|
|
42610
42672
|
storage;
|
|
@@ -42642,7 +42704,7 @@ class SettingsManager {
|
|
|
42642
42704
|
}
|
|
42643
42705
|
static create(cwd, agentDir = getAgentDir(), options = {}) {
|
|
42644
42706
|
const storage = new FileSettingsStorage(cwd, agentDir, {
|
|
42645
|
-
globalReadPaths: agentDir === getAgentDir() ? getAgentConfigPaths("settings.json") : [
|
|
42707
|
+
globalReadPaths: agentDir === getAgentDir() ? getAgentConfigPaths("settings.json") : [join45(agentDir, "settings.json")],
|
|
42646
42708
|
projectReadPaths: getProjectConfigPaths(cwd, "settings.json")
|
|
42647
42709
|
});
|
|
42648
42710
|
return SettingsManager.fromStorage(storage, options);
|
|
@@ -44356,14 +44418,14 @@ var init_agent_session_runtime_auth = __esm(() => {
|
|
|
44356
44418
|
});
|
|
44357
44419
|
|
|
44358
44420
|
// src/core/session-cwd.ts
|
|
44359
|
-
import { existsSync as
|
|
44421
|
+
import { existsSync as existsSync33 } from "node:fs";
|
|
44360
44422
|
function getMissingSessionCwdIssue(sessionManager, fallbackCwd) {
|
|
44361
44423
|
const sessionFile = sessionManager.getSessionFile();
|
|
44362
44424
|
if (!sessionFile) {
|
|
44363
44425
|
return;
|
|
44364
44426
|
}
|
|
44365
44427
|
const sessionCwd = sessionManager.getCwd();
|
|
44366
|
-
if (!sessionCwd ||
|
|
44428
|
+
if (!sessionCwd || existsSync33(sessionCwd)) {
|
|
44367
44429
|
return;
|
|
44368
44430
|
}
|
|
44369
44431
|
return {
|
|
@@ -44415,8 +44477,8 @@ var init_agent_session_services = __esm(() => {
|
|
|
44415
44477
|
});
|
|
44416
44478
|
|
|
44417
44479
|
// src/core/agent-session-runtime.ts
|
|
44418
|
-
import { copyFileSync, existsSync as
|
|
44419
|
-
import { basename as basename11, join as
|
|
44480
|
+
import { copyFileSync, existsSync as existsSync34, mkdirSync as mkdirSync12 } from "node:fs";
|
|
44481
|
+
import { basename as basename11, join as join46, resolve as resolve14 } from "node:path";
|
|
44420
44482
|
import { modelsAreEqual as modelsAreEqual5 } from "@bastani/pi-ai/compat";
|
|
44421
44483
|
function extractUserMessageText(content) {
|
|
44422
44484
|
if (typeof content === "string") {
|
|
@@ -44632,7 +44694,7 @@ class AgentSessionRuntime {
|
|
|
44632
44694
|
await this.finishSessionReplacement(options?.withSession);
|
|
44633
44695
|
return { cancelled: false, selectedText };
|
|
44634
44696
|
}
|
|
44635
|
-
if (!
|
|
44697
|
+
if (!existsSync34(currentSessionFile)) {
|
|
44636
44698
|
throw new Error("This session has not been saved yet. Wait for the first assistant response before cloning or forking it.");
|
|
44637
44699
|
}
|
|
44638
44700
|
const sessionManager2 = SessionManager.open(currentSessionFile, sessionDir);
|
|
@@ -44668,14 +44730,14 @@ class AgentSessionRuntime {
|
|
|
44668
44730
|
}
|
|
44669
44731
|
async importFromJsonl(inputPath, cwdOverride) {
|
|
44670
44732
|
const resolvedPath = resolvePath(inputPath);
|
|
44671
|
-
if (!
|
|
44733
|
+
if (!existsSync34(resolvedPath)) {
|
|
44672
44734
|
throw new SessionImportFileNotFoundError(resolvedPath);
|
|
44673
44735
|
}
|
|
44674
44736
|
const sessionDir = this.session.sessionManager.getSessionDir();
|
|
44675
|
-
if (!
|
|
44737
|
+
if (!existsSync34(sessionDir)) {
|
|
44676
44738
|
mkdirSync12(sessionDir, { recursive: true });
|
|
44677
44739
|
}
|
|
44678
|
-
const destinationPath =
|
|
44740
|
+
const destinationPath = join46(sessionDir, basename11(resolvedPath));
|
|
44679
44741
|
const beforeResult = await this.emitBeforeSwitch("resume", destinationPath);
|
|
44680
44742
|
if (beforeResult.cancelled) {
|
|
44681
44743
|
return beforeResult;
|
|
@@ -62349,12 +62411,12 @@ function stripOnePrefix(value, prefix) {
|
|
|
62349
62411
|
|
|
62350
62412
|
// dist/builtin/workflows/src/runs/foreground/executor-direct-helpers.ts
|
|
62351
62413
|
init_src();
|
|
62352
|
-
import { isAbsolute as isAbsolute14, join as
|
|
62414
|
+
import { isAbsolute as isAbsolute14, join as join54, resolve as resolve22 } from "node:path";
|
|
62353
62415
|
|
|
62354
62416
|
// dist/builtin/workflows/src/shared/workflow-artifacts.ts
|
|
62355
62417
|
init_src();
|
|
62356
62418
|
import { mkdir as mkdir3, readdir as readdir4, rm, stat as stat6 } from "node:fs/promises";
|
|
62357
|
-
import { dirname as
|
|
62419
|
+
import { dirname as dirname25, join as join47 } from "node:path";
|
|
62358
62420
|
|
|
62359
62421
|
// dist/builtin/workflows/src/shared/workflow-artifact-env.ts
|
|
62360
62422
|
var WORKFLOW_ARTIFACT_RETENTION_MS = 30 * 24 * 60 * 60 * 1000;
|
|
@@ -62368,17 +62430,17 @@ function workflowArtifactRoot() {
|
|
|
62368
62430
|
const override = getEnvValue(ENV_WORKFLOW_ARTIFACT_DIR);
|
|
62369
62431
|
if (override !== undefined && override.length > 0)
|
|
62370
62432
|
return override;
|
|
62371
|
-
return
|
|
62433
|
+
return join47(dirname25(getAgentDir()), "workflows");
|
|
62372
62434
|
}
|
|
62373
62435
|
function workflowArtifactRunsRoot() {
|
|
62374
|
-
return
|
|
62436
|
+
return join47(workflowArtifactRoot(), "runs");
|
|
62375
62437
|
}
|
|
62376
62438
|
function safeRunId(runId) {
|
|
62377
62439
|
const safe = runId.replace(/[^A-Za-z0-9._-]/g, "_");
|
|
62378
62440
|
return safe.length > 0 ? safe : "run";
|
|
62379
62441
|
}
|
|
62380
62442
|
function workflowArtifactRunPath(runId) {
|
|
62381
|
-
return
|
|
62443
|
+
return join47(workflowArtifactRunsRoot(), safeRunId(runId));
|
|
62382
62444
|
}
|
|
62383
62445
|
function storeRunState(run) {
|
|
62384
62446
|
const hasPendingInput = run.pendingPrompt !== undefined || run.stages.some((stage) => stage.status === "awaiting_input" || stage.status === "paused" || stage.status === "blocked");
|
|
@@ -62447,7 +62509,7 @@ async function pruneWorkflowArtifactRuns(root = workflowArtifactRunsRoot(), now
|
|
|
62447
62509
|
for (const entry of entries) {
|
|
62448
62510
|
if (!entry.isDirectory())
|
|
62449
62511
|
continue;
|
|
62450
|
-
const entryPath =
|
|
62512
|
+
const entryPath = join47(root, entry.name);
|
|
62451
62513
|
let metadata;
|
|
62452
62514
|
try {
|
|
62453
62515
|
metadata = await stat6(entryPath);
|
|
@@ -63808,7 +63870,7 @@ function cleanupWorktrees(setup) {
|
|
|
63808
63870
|
}
|
|
63809
63871
|
// dist/builtin/workflows/src/runs/shared/worktree-cwd.ts
|
|
63810
63872
|
import { lstatSync as lstatSync6, realpathSync as realpathSync8 } from "node:fs";
|
|
63811
|
-
import { dirname as
|
|
63873
|
+
import { dirname as dirname30, isAbsolute as isAbsolute12, relative as relative14, resolve as resolve20, sep as sep14 } from "node:path";
|
|
63812
63874
|
function relativePathWithin(root, candidate) {
|
|
63813
63875
|
const path20 = relative14(root, candidate);
|
|
63814
63876
|
return path20 === ".." || path20.startsWith(`..${sep14}`) || isAbsolute12(path20) ? undefined : path20;
|
|
@@ -63854,7 +63916,7 @@ function resolveWorktreeStageCwd(cwd, setup) {
|
|
|
63854
63916
|
}
|
|
63855
63917
|
|
|
63856
63918
|
// dist/builtin/workflows/src/runs/foreground/executor-task-prompts.ts
|
|
63857
|
-
import { existsSync as
|
|
63919
|
+
import { existsSync as existsSync37 } from "node:fs";
|
|
63858
63920
|
import { isAbsolute as isAbsolute13, resolve as resolve21 } from "node:path";
|
|
63859
63921
|
function normalizeTaskContexts(previous2) {
|
|
63860
63922
|
if (previous2 === undefined)
|
|
@@ -63924,7 +63986,7 @@ function taskReadInstruction(options) {
|
|
|
63924
63986
|
return "";
|
|
63925
63987
|
const baseDir = taskBaseDir(options);
|
|
63926
63988
|
const files = options.reads.map((file) => resolveWorkflowPath(file, baseDir));
|
|
63927
|
-
const missing = files.find((file) => !
|
|
63989
|
+
const missing = files.find((file) => !existsSync37(file));
|
|
63928
63990
|
if (missing !== undefined) {
|
|
63929
63991
|
throw new Error(`atomic-workflows: referenced artifact does not exist: ${missing}`);
|
|
63930
63992
|
}
|
|
@@ -64190,7 +64252,7 @@ function resolvedTaskCwd(cwd, workflowInvocationCwd) {
|
|
|
64190
64252
|
return isAbsolute14(cwd) ? cwd : resolve22(workflowInvocationCwd, cwd);
|
|
64191
64253
|
}
|
|
64192
64254
|
function taskWorktreeOutputsRoot(runId) {
|
|
64193
|
-
return
|
|
64255
|
+
return join54(workflowArtifactRunPath(runId), "task-outputs");
|
|
64194
64256
|
}
|
|
64195
64257
|
function prepareTaskWorktrees(tasks, options, runId, scope, workflowInvocationCwd = process.cwd(), symlinkDirectories) {
|
|
64196
64258
|
if (options.worktree !== true && !tasks.some((task) => task.worktree === true)) {
|
|
@@ -64215,9 +64277,9 @@ function prepareTaskWorktrees(tasks, options, runId, scope, workflowInvocationCw
|
|
|
64215
64277
|
tasks: tasks.map((task, index) => ({ ...task, cwd: setup.worktrees[index].agentCwd })),
|
|
64216
64278
|
setup,
|
|
64217
64279
|
agents,
|
|
64218
|
-
diffsDir:
|
|
64280
|
+
diffsDir: join54(setup.cwd, CONFIG_DIR_NAME, "workflows", "worktree-diffs", runId, scope),
|
|
64219
64281
|
outputIsolations: tasks.map((_, index) => ({
|
|
64220
|
-
baseDir:
|
|
64282
|
+
baseDir: join54(trustedRoot, runId, scope, String(index)),
|
|
64221
64283
|
trustedRoot
|
|
64222
64284
|
}))
|
|
64223
64285
|
};
|
|
@@ -71557,7 +71619,7 @@ class StageSessionController {
|
|
|
71557
71619
|
// dist/builtin/workflows/src/runs/foreground/stage-runner-output.ts
|
|
71558
71620
|
import { createHash as createHash7 } from "node:crypto";
|
|
71559
71621
|
import { mkdir as mkdir4, writeFile as writeFile3 } from "node:fs/promises";
|
|
71560
|
-
import { basename as basename14, dirname as
|
|
71622
|
+
import { basename as basename14, dirname as dirname31, isAbsolute as isAbsolute15, join as join55, resolve as resolve23 } from "node:path";
|
|
71561
71623
|
var DEFAULT_MAX_OUTPUT_BYTES = 200 * 1024;
|
|
71562
71624
|
var DEFAULT_MAX_OUTPUT_LINES = 5000;
|
|
71563
71625
|
function normalizeMaxOutput2(maxOutput) {
|
|
@@ -71622,7 +71684,7 @@ function formatByteSize(bytes) {
|
|
|
71622
71684
|
}
|
|
71623
71685
|
function transcriptPath(runId, outputPath) {
|
|
71624
71686
|
const digest = createHash7("sha256").update(outputPath).digest("hex").slice(0, 16);
|
|
71625
|
-
return
|
|
71687
|
+
return join55(workflowArtifactRunPath(runId), "transcripts", `${digest}-${basename14(outputPath)}.transcript.md`);
|
|
71626
71688
|
}
|
|
71627
71689
|
function appendContent(lines, content) {
|
|
71628
71690
|
if (typeof content === "string") {
|
|
@@ -71742,7 +71804,7 @@ async function finalizePromptOutput(fullOutput, outputOptions, runtimeCwd, runId
|
|
|
71742
71804
|
const transcriptFile = transcriptPath(runId, outputPath);
|
|
71743
71805
|
const transcript = renderTranscript(messages2, fullOutput);
|
|
71744
71806
|
try {
|
|
71745
|
-
await mkdir4(
|
|
71807
|
+
await mkdir4(dirname31(outputPath), { recursive: true });
|
|
71746
71808
|
await writeFile3(outputPath, fullOutput, "utf8");
|
|
71747
71809
|
} catch (err) {
|
|
71748
71810
|
return `${displayOutput}
|
|
@@ -71754,7 +71816,7 @@ ${err instanceof Error ? err.message : String(err)}`;
|
|
|
71754
71816
|
let transcriptError;
|
|
71755
71817
|
try {
|
|
71756
71818
|
await ensureWorkflowArtifactRunDirectory(runId);
|
|
71757
|
-
await mkdir4(
|
|
71819
|
+
await mkdir4(dirname31(transcriptFile), { recursive: true });
|
|
71758
71820
|
await writeFile3(transcriptFile, transcript, "utf8");
|
|
71759
71821
|
transcriptAvailable = true;
|
|
71760
71822
|
} catch (err) {
|