@use-aistack/cli 0.21.0 → 0.22.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +10 -2
- package/dist/index.js +1646 -922
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -237,7 +237,7 @@ var init_errors = __esm({
|
|
|
237
237
|
...new Set(cleanupErrors.flatMap((error) => error.details.unverifiedResiduePaths))
|
|
238
238
|
].sort(compareCodePoints);
|
|
239
239
|
const unverifiedResidueSet = new Set(unverifiedResiduePaths);
|
|
240
|
-
const residuePaths = [...new Set(cleanupErrors.flatMap((error) => error.details.residuePaths))].filter((
|
|
240
|
+
const residuePaths = [...new Set(cleanupErrors.flatMap((error) => error.details.residuePaths))].filter((path21) => !unverifiedResidueSet.has(path21)).sort(compareCodePoints);
|
|
241
241
|
const cleanupRemedy = residuePaths.length > 0 || unverifiedResiduePaths.length > 0 ? " Remove only verified private temporary paths after confirming no operation is active; do not delete unverified paths blindly." : "";
|
|
242
242
|
super("RESTORE_ROLLBACK_INCOMPLETE", "Restore failed after one or more files were published; automatic rollback was not attempted.", {
|
|
243
243
|
publishedFileCount,
|
|
@@ -477,9 +477,9 @@ var init_errors3 = __esm({
|
|
|
477
477
|
name = "DatabaseLockedError";
|
|
478
478
|
/** Path to locked database file */
|
|
479
479
|
path;
|
|
480
|
-
constructor(
|
|
481
|
-
super(`Database is locked: ${
|
|
482
|
-
this.path =
|
|
480
|
+
constructor(path21) {
|
|
481
|
+
super(`Database is locked: ${path21}. Close Cursor or retry later.`);
|
|
482
|
+
this.path = path21;
|
|
483
483
|
if (Error.captureStackTrace) {
|
|
484
484
|
Error.captureStackTrace(this, _DatabaseLockedError);
|
|
485
485
|
}
|
|
@@ -489,9 +489,9 @@ var init_errors3 = __esm({
|
|
|
489
489
|
name = "DatabaseNotFoundError";
|
|
490
490
|
/** Path that was not found */
|
|
491
491
|
path;
|
|
492
|
-
constructor(
|
|
493
|
-
super(`Database not found: ${
|
|
494
|
-
this.path =
|
|
492
|
+
constructor(path21) {
|
|
493
|
+
super(`Database not found: ${path21}. Check dataPath configuration.`);
|
|
494
|
+
this.path = path21;
|
|
495
495
|
if (Error.captureStackTrace) {
|
|
496
496
|
Error.captureStackTrace(this, _DatabaseNotFoundError);
|
|
497
497
|
}
|
|
@@ -543,9 +543,9 @@ var init_errors3 = __esm({
|
|
|
543
543
|
name = "WorkspaceNotFoundError";
|
|
544
544
|
/** The workspace path that was not found */
|
|
545
545
|
path;
|
|
546
|
-
constructor(
|
|
547
|
-
super(`No workspace found for path: ${
|
|
548
|
-
this.path =
|
|
546
|
+
constructor(path21) {
|
|
547
|
+
super(`No workspace found for path: ${path21}. Please open the project in Cursor first.`);
|
|
548
|
+
this.path = path21;
|
|
549
549
|
if (Error.captureStackTrace) {
|
|
550
550
|
Error.captureStackTrace(this, _WorkspaceNotFoundError);
|
|
551
551
|
}
|
|
@@ -555,9 +555,9 @@ var init_errors3 = __esm({
|
|
|
555
555
|
name = "SameWorkspaceError";
|
|
556
556
|
/** The path that was specified for both source and destination */
|
|
557
557
|
path;
|
|
558
|
-
constructor(
|
|
559
|
-
super(`Source and destination are the same: ${
|
|
560
|
-
this.path =
|
|
558
|
+
constructor(path21) {
|
|
559
|
+
super(`Source and destination are the same: ${path21}`);
|
|
560
|
+
this.path = path21;
|
|
561
561
|
if (Error.captureStackTrace) {
|
|
562
562
|
Error.captureStackTrace(this, _SameWorkspaceError);
|
|
563
563
|
}
|
|
@@ -567,9 +567,9 @@ var init_errors3 = __esm({
|
|
|
567
567
|
name = "NoSessionsFoundError";
|
|
568
568
|
/** The source workspace path */
|
|
569
569
|
path;
|
|
570
|
-
constructor(
|
|
571
|
-
super(`No sessions found for workspace: ${
|
|
572
|
-
this.path =
|
|
570
|
+
constructor(path21) {
|
|
571
|
+
super(`No sessions found for workspace: ${path21}. Use 'cursor-history list --workspace "${path21}"' to verify.`);
|
|
572
|
+
this.path = path21;
|
|
573
573
|
if (Error.captureStackTrace) {
|
|
574
574
|
Error.captureStackTrace(this, _NoSessionsFoundError);
|
|
575
575
|
}
|
|
@@ -581,9 +581,9 @@ var init_errors3 = __esm({
|
|
|
581
581
|
path;
|
|
582
582
|
/** Number of existing sessions at destination */
|
|
583
583
|
sessionCount;
|
|
584
|
-
constructor(
|
|
585
|
-
super(`Destination already has ${sessionCount} session(s): ${
|
|
586
|
-
this.path =
|
|
584
|
+
constructor(path21, sessionCount) {
|
|
585
|
+
super(`Destination already has ${sessionCount} session(s): ${path21}. Use --force to proceed (will add sessions alongside existing ones).`);
|
|
586
|
+
this.path = path21;
|
|
587
587
|
this.sessionCount = sessionCount;
|
|
588
588
|
if (Error.captureStackTrace) {
|
|
589
589
|
Error.captureStackTrace(this, _DestinationHasSessionsError);
|
|
@@ -618,9 +618,9 @@ var init_errors3 = __esm({
|
|
|
618
618
|
name = "NoDataError";
|
|
619
619
|
/** Path that was checked for data */
|
|
620
620
|
path;
|
|
621
|
-
constructor(
|
|
622
|
-
super(`No Cursor data found at: ${
|
|
623
|
-
this.path =
|
|
621
|
+
constructor(path21) {
|
|
622
|
+
super(`No Cursor data found at: ${path21}. Verify Cursor is installed and has been used.`);
|
|
623
|
+
this.path = path21;
|
|
624
624
|
if (Error.captureStackTrace) {
|
|
625
625
|
Error.captureStackTrace(this, _NoDataError);
|
|
626
626
|
}
|
|
@@ -630,9 +630,9 @@ var init_errors3 = __esm({
|
|
|
630
630
|
name = "FileExistsError";
|
|
631
631
|
/** Path to existing file */
|
|
632
632
|
path;
|
|
633
|
-
constructor(
|
|
634
|
-
super(`File already exists: ${
|
|
635
|
-
this.path =
|
|
633
|
+
constructor(path21) {
|
|
634
|
+
super(`File already exists: ${path21}. Use --force to overwrite.`);
|
|
635
|
+
this.path = path21;
|
|
636
636
|
if (Error.captureStackTrace) {
|
|
637
637
|
Error.captureStackTrace(this, _FileExistsError);
|
|
638
638
|
}
|
|
@@ -668,9 +668,9 @@ var init_errors3 = __esm({
|
|
|
668
668
|
name = "BackupNotFoundError";
|
|
669
669
|
/** Path to backup file that was not found */
|
|
670
670
|
path;
|
|
671
|
-
constructor(
|
|
672
|
-
super(`Backup file not found: ${
|
|
673
|
-
this.path =
|
|
671
|
+
constructor(path21) {
|
|
672
|
+
super(`Backup file not found: ${path21}`);
|
|
673
|
+
this.path = path21;
|
|
674
674
|
if (Error.captureStackTrace) {
|
|
675
675
|
Error.captureStackTrace(this, _BackupNotFoundError);
|
|
676
676
|
}
|
|
@@ -682,9 +682,9 @@ var init_errors3 = __esm({
|
|
|
682
682
|
path;
|
|
683
683
|
/** Reason for invalidity */
|
|
684
684
|
reason;
|
|
685
|
-
constructor(
|
|
686
|
-
super(`Invalid backup file: ${
|
|
687
|
-
this.path =
|
|
685
|
+
constructor(path21, reason) {
|
|
686
|
+
super(`Invalid backup file: ${path21}. ${reason}`);
|
|
687
|
+
this.path = path21;
|
|
688
688
|
this.reason = reason;
|
|
689
689
|
if (Error.captureStackTrace) {
|
|
690
690
|
Error.captureStackTrace(this, _InvalidBackupError);
|
|
@@ -695,9 +695,9 @@ var init_errors3 = __esm({
|
|
|
695
695
|
name = "TargetExistsError";
|
|
696
696
|
/** Path to existing target */
|
|
697
697
|
path;
|
|
698
|
-
constructor(
|
|
699
|
-
super(`Target already has Cursor data: ${
|
|
700
|
-
this.path =
|
|
698
|
+
constructor(path21) {
|
|
699
|
+
super(`Target already has Cursor data: ${path21}. Use --force to overwrite.`);
|
|
700
|
+
this.path = path21;
|
|
701
701
|
if (Error.captureStackTrace) {
|
|
702
702
|
Error.captureStackTrace(this, _TargetExistsError);
|
|
703
703
|
}
|
|
@@ -720,7 +720,7 @@ var init_errors3 = __esm({
|
|
|
720
720
|
|
|
721
721
|
// ../../node_modules/.pnpm/cursor-history@0.18.0_patch_hash=dbff0ea0e399ea9504168452170a23ee2b432a6dc6a69a20b49bf95ef139fa74/node_modules/cursor-history/dist/lib/platform.js
|
|
722
722
|
import { existsSync as existsSync6, readFileSync as readFileSync7, readdirSync as readdirSync3 } from "node:fs";
|
|
723
|
-
import { homedir as
|
|
723
|
+
import { homedir as homedir11 } from "node:os";
|
|
724
724
|
import { basename as basename2, dirname as dirname3, join as join6 } from "node:path";
|
|
725
725
|
function detectPlatform() {
|
|
726
726
|
switch (process.platform) {
|
|
@@ -757,21 +757,21 @@ function detectPreferredStackSource(customDataPath) {
|
|
|
757
757
|
return findStoreRoot(explicit) ? "store" : "composer";
|
|
758
758
|
}
|
|
759
759
|
const storeRootEnv = process.env["CURSOR_STORE_ROOT"];
|
|
760
|
-
const defaultStoreRoot = join6(
|
|
760
|
+
const defaultStoreRoot = join6(homedir11(), ".cursor");
|
|
761
761
|
if (storeRootEnv && !pathsEqual(storeRootEnv, defaultStoreRoot)) {
|
|
762
762
|
return "store";
|
|
763
763
|
}
|
|
764
764
|
return isWSL() ? "store" : "composer";
|
|
765
765
|
}
|
|
766
|
-
function getDefaultCursorDataPath(
|
|
767
|
-
const p8 =
|
|
766
|
+
function getDefaultCursorDataPath(platform5) {
|
|
767
|
+
const p8 = platform5 ?? detectPlatform();
|
|
768
768
|
switch (p8) {
|
|
769
769
|
case "windows":
|
|
770
|
-
return join6(process.env["APPDATA"] ?? join6(
|
|
770
|
+
return join6(process.env["APPDATA"] ?? join6(homedir11(), "AppData", "Roaming"), "Cursor", "User", "workspaceStorage");
|
|
771
771
|
case "macos":
|
|
772
|
-
return join6(
|
|
772
|
+
return join6(homedir11(), "Library", "Application Support", "Cursor", "User", "workspaceStorage");
|
|
773
773
|
case "linux":
|
|
774
|
-
return join6(
|
|
774
|
+
return join6(homedir11(), ".config", "Cursor", "User", "workspaceStorage");
|
|
775
775
|
}
|
|
776
776
|
}
|
|
777
777
|
function getCursorDataPath(customPath) {
|
|
@@ -787,23 +787,23 @@ function getCursorDataPath(customPath) {
|
|
|
787
787
|
function getGlobalStoragePath(customDataPath) {
|
|
788
788
|
return join6(dirname3(getCursorDataPath(customDataPath)), "globalStorage");
|
|
789
789
|
}
|
|
790
|
-
function expandPath(
|
|
791
|
-
if (
|
|
792
|
-
return join6(
|
|
790
|
+
function expandPath(path21) {
|
|
791
|
+
if (path21.startsWith("~")) {
|
|
792
|
+
return join6(homedir11(), path21.slice(1));
|
|
793
793
|
}
|
|
794
|
-
return
|
|
794
|
+
return path21;
|
|
795
795
|
}
|
|
796
|
-
function contractPath(
|
|
797
|
-
const home =
|
|
798
|
-
if (
|
|
799
|
-
return "~" +
|
|
796
|
+
function contractPath(path21) {
|
|
797
|
+
const home = homedir11();
|
|
798
|
+
if (path21.startsWith(home)) {
|
|
799
|
+
return "~" + path21.slice(home.length);
|
|
800
800
|
}
|
|
801
|
-
return
|
|
801
|
+
return path21;
|
|
802
802
|
}
|
|
803
803
|
function normalizePath(filePath) {
|
|
804
804
|
let normalized = filePath;
|
|
805
805
|
if (normalized.startsWith("~")) {
|
|
806
|
-
normalized = join6(
|
|
806
|
+
normalized = join6(homedir11(), normalized.slice(1));
|
|
807
807
|
}
|
|
808
808
|
while (normalized.length > 1 && normalized.endsWith("/")) {
|
|
809
809
|
normalized = normalized.slice(0, -1);
|
|
@@ -908,7 +908,7 @@ function resolveStoreRoot(customDataPath) {
|
|
|
908
908
|
const storeEnv = process.env["CURSOR_STORE_ROOT"];
|
|
909
909
|
if (storeEnv)
|
|
910
910
|
return findStoreRoot(storeEnv) ?? storeEnv;
|
|
911
|
-
return join6(
|
|
911
|
+
return join6(homedir11(), ".cursor");
|
|
912
912
|
}
|
|
913
913
|
var cachedIsWsl, STORE_CHILDREN;
|
|
914
914
|
var init_platform = __esm({
|
|
@@ -1439,8 +1439,8 @@ function normalizePublicWorkspacePath(value) {
|
|
|
1439
1439
|
return void 0;
|
|
1440
1440
|
}
|
|
1441
1441
|
}
|
|
1442
|
-
function exactComparisonKey(
|
|
1443
|
-
return
|
|
1442
|
+
function exactComparisonKey(path21) {
|
|
1443
|
+
return path21.caseInsensitive ? path21.path.toLowerCase() : path21.path;
|
|
1444
1444
|
}
|
|
1445
1445
|
function componentsEndWith(candidate, request2) {
|
|
1446
1446
|
if (request2.drive && candidate.drive !== request2.drive)
|
|
@@ -2842,14 +2842,14 @@ var init_registry = __esm({
|
|
|
2842
2842
|
return this.selectDatabaseDriver(request2);
|
|
2843
2843
|
}
|
|
2844
2844
|
/** Open a database in read-only mode. */
|
|
2845
|
-
async openDatabase(
|
|
2845
|
+
async openDatabase(path21, request2 = READ_SESSION_REQUEST) {
|
|
2846
2846
|
const driver = await this.ensureDriver(request2);
|
|
2847
|
-
return openObservedDatabase(request2.io, request2, () => driver.open(
|
|
2847
|
+
return openObservedDatabase(request2.io, request2, () => driver.open(path21, { readonly: true }));
|
|
2848
2848
|
}
|
|
2849
2849
|
/** Open a database in read-write mode. */
|
|
2850
|
-
async openDatabaseReadWrite(
|
|
2850
|
+
async openDatabaseReadWrite(path21, request2 = MIGRATION_REQUEST) {
|
|
2851
2851
|
const driver = await this.ensureDriver(request2);
|
|
2852
|
-
return openObservedDatabase(request2.io, request2, () => driver.open(
|
|
2852
|
+
return openObservedDatabase(request2.io, request2, () => driver.open(path21, { readonly: false }));
|
|
2853
2853
|
}
|
|
2854
2854
|
/**
|
|
2855
2855
|
* Synchronous database open (requires a completed capability-aware selection).
|
|
@@ -2857,11 +2857,11 @@ var init_registry = __esm({
|
|
|
2857
2857
|
* This remains for backup parsing paths that perform synchronous reads after an awaited
|
|
2858
2858
|
* selection or snapshot operation.
|
|
2859
2859
|
*/
|
|
2860
|
-
openSync(
|
|
2860
|
+
openSync(path21, options) {
|
|
2861
2861
|
if (!this.currentDriver) {
|
|
2862
2862
|
throw new Error("No driver is currently active. Capability-aware selection must complete before using openSync().");
|
|
2863
2863
|
}
|
|
2864
|
-
return this.currentDriver.open(
|
|
2864
|
+
return this.currentDriver.open(path21, options);
|
|
2865
2865
|
}
|
|
2866
2866
|
/** Create an online database snapshot with a provider satisfying the complete request. */
|
|
2867
2867
|
async backupDatabase(sourcePath, destPath, request2 = BACKUP_REQUEST) {
|
|
@@ -3008,12 +3008,12 @@ var init_better_sqlite3 = __esm({
|
|
|
3008
3008
|
getCapabilityProfile() {
|
|
3009
3009
|
return loadBetterSqlite3Profile();
|
|
3010
3010
|
},
|
|
3011
|
-
open(
|
|
3011
|
+
open(path21, options) {
|
|
3012
3012
|
if (!BetterSqlite3) {
|
|
3013
3013
|
throw new Error("better-sqlite3 is not loaded. Call isAvailable() first.");
|
|
3014
3014
|
}
|
|
3015
|
-
const db = new BetterSqlite3(
|
|
3016
|
-
debugLog(`Opened database with better-sqlite3: ${
|
|
3015
|
+
const db = new BetterSqlite3(path21, { readonly: options.readonly });
|
|
3016
|
+
debugLog(`Opened database with better-sqlite3: ${path21} (readonly: ${options.readonly})`);
|
|
3017
3017
|
return new BetterSqlite3Database(db);
|
|
3018
3018
|
},
|
|
3019
3019
|
async backup(sourcePath, destPath) {
|
|
@@ -3204,12 +3204,12 @@ var init_node_sqlite = __esm({
|
|
|
3204
3204
|
getCapabilityProfile() {
|
|
3205
3205
|
return loadNodeSqliteProfile();
|
|
3206
3206
|
},
|
|
3207
|
-
open(
|
|
3207
|
+
open(path21, options) {
|
|
3208
3208
|
if (!nodeSqliteModule) {
|
|
3209
3209
|
throw new Error("node:sqlite is not loaded. Call isAvailable() first.");
|
|
3210
3210
|
}
|
|
3211
|
-
const db = new nodeSqliteModule.DatabaseSync(
|
|
3212
|
-
debugLog(`Opened database with node:sqlite: ${
|
|
3211
|
+
const db = new nodeSqliteModule.DatabaseSync(path21, { readOnly: options.readonly });
|
|
3212
|
+
debugLog(`Opened database with node:sqlite: ${path21} (readonly: ${options.readonly})`);
|
|
3213
3213
|
return new NodeSqliteDatabaseWrapper(db, options.readonly);
|
|
3214
3214
|
},
|
|
3215
3215
|
async backup(sourcePath, destPath) {
|
|
@@ -3233,11 +3233,11 @@ var init_node_sqlite = __esm({
|
|
|
3233
3233
|
});
|
|
3234
3234
|
|
|
3235
3235
|
// ../../node_modules/.pnpm/cursor-history@0.18.0_patch_hash=dbff0ea0e399ea9504168452170a23ee2b432a6dc6a69a20b49bf95ef139fa74/node_modules/cursor-history/dist/core/database/index.js
|
|
3236
|
-
async function openDatabase(
|
|
3237
|
-
return registry.openDatabase(
|
|
3236
|
+
async function openDatabase(path21, request2) {
|
|
3237
|
+
return registry.openDatabase(path21, request2);
|
|
3238
3238
|
}
|
|
3239
|
-
async function openDatabaseReadWrite(
|
|
3240
|
-
return registry.openDatabaseReadWrite(
|
|
3239
|
+
async function openDatabaseReadWrite(path21, request2) {
|
|
3240
|
+
return registry.openDatabaseReadWrite(path21, request2);
|
|
3241
3241
|
}
|
|
3242
3242
|
function getActiveDriver() {
|
|
3243
3243
|
return registry.getActiveDriver();
|
|
@@ -3374,8 +3374,8 @@ function exclusiveFlags() {
|
|
|
3374
3374
|
flags |= constants.O_NOFOLLOW;
|
|
3375
3375
|
return flags;
|
|
3376
3376
|
}
|
|
3377
|
-
function createExclusivePrivateFile(
|
|
3378
|
-
const descriptor = openSync(
|
|
3377
|
+
function createExclusivePrivateFile(path21, contents) {
|
|
3378
|
+
const descriptor = openSync(path21, exclusiveFlags(), 384);
|
|
3379
3379
|
try {
|
|
3380
3380
|
if (IS_PERMISSION_AWARE_POSIX)
|
|
3381
3381
|
fchmodSync(descriptor, 384);
|
|
@@ -3387,10 +3387,10 @@ function createExclusivePrivateFile(path19, contents) {
|
|
|
3387
3387
|
closeSync(descriptor);
|
|
3388
3388
|
}
|
|
3389
3389
|
}
|
|
3390
|
-
function attemptRemoveEntryNoFollow(
|
|
3390
|
+
function attemptRemoveEntryNoFollow(path21) {
|
|
3391
3391
|
let stats;
|
|
3392
3392
|
try {
|
|
3393
|
-
stats = lstatSync(
|
|
3393
|
+
stats = lstatSync(path21);
|
|
3394
3394
|
} catch (error) {
|
|
3395
3395
|
if (!isMissing(error)) {
|
|
3396
3396
|
}
|
|
@@ -3398,13 +3398,13 @@ function attemptRemoveEntryNoFollow(path19) {
|
|
|
3398
3398
|
}
|
|
3399
3399
|
if (stats.isDirectory() && !stats.isSymbolicLink()) {
|
|
3400
3400
|
try {
|
|
3401
|
-
rmdirSync(
|
|
3401
|
+
rmdirSync(path21);
|
|
3402
3402
|
} catch {
|
|
3403
3403
|
}
|
|
3404
3404
|
return;
|
|
3405
3405
|
}
|
|
3406
3406
|
try {
|
|
3407
|
-
unlinkSync(
|
|
3407
|
+
unlinkSync(path21);
|
|
3408
3408
|
} catch {
|
|
3409
3409
|
}
|
|
3410
3410
|
}
|
|
@@ -3432,9 +3432,9 @@ function attemptRemoveWorkspaceNoFollow(directoryPath) {
|
|
|
3432
3432
|
} catch {
|
|
3433
3433
|
}
|
|
3434
3434
|
}
|
|
3435
|
-
function mayStillExist(
|
|
3435
|
+
function mayStillExist(path21) {
|
|
3436
3436
|
try {
|
|
3437
|
-
lstatSync(
|
|
3437
|
+
lstatSync(path21);
|
|
3438
3438
|
return true;
|
|
3439
3439
|
} catch (error) {
|
|
3440
3440
|
return !isMissing(error);
|
|
@@ -3731,8 +3731,8 @@ var init_private_temp = __esm({
|
|
|
3731
3731
|
stateValue = "open";
|
|
3732
3732
|
abortSignal;
|
|
3733
3733
|
abortHandler;
|
|
3734
|
-
constructor(
|
|
3735
|
-
this.path =
|
|
3734
|
+
constructor(path21, marker, markerPath, signal) {
|
|
3735
|
+
this.path = path21;
|
|
3736
3736
|
this.marker = marker;
|
|
3737
3737
|
this.trackedPaths.add(markerPath);
|
|
3738
3738
|
this.abortSignal = signal;
|
|
@@ -3763,9 +3763,9 @@ var init_private_temp = __esm({
|
|
|
3763
3763
|
createExclusivePrivateFile(filePath);
|
|
3764
3764
|
return filePath;
|
|
3765
3765
|
}
|
|
3766
|
-
register(
|
|
3766
|
+
register(path21) {
|
|
3767
3767
|
this.assertOpen();
|
|
3768
|
-
const candidatePath = resolve(
|
|
3768
|
+
const candidatePath = resolve(path21);
|
|
3769
3769
|
if (!isDirectChildPath(this.path, candidatePath)) {
|
|
3770
3770
|
throw new TypeError("Tracked temporary artifacts must be direct children of their private workspace.");
|
|
3771
3771
|
}
|
|
@@ -3779,8 +3779,8 @@ var init_private_temp = __esm({
|
|
|
3779
3779
|
this.abortSignal.removeEventListener("abort", this.abortHandler);
|
|
3780
3780
|
}
|
|
3781
3781
|
const tracked = [...this.trackedPaths].sort((left, right) => right.length - left.length);
|
|
3782
|
-
for (const
|
|
3783
|
-
attemptRemoveEntryNoFollow(
|
|
3782
|
+
for (const path21 of tracked)
|
|
3783
|
+
attemptRemoveEntryNoFollow(path21);
|
|
3784
3784
|
attemptRemoveWorkspaceNoFollow(this.path);
|
|
3785
3785
|
const residuePaths = tracked.filter(mayStillExist);
|
|
3786
3786
|
if (mayStillExist(this.path))
|
|
@@ -4803,8 +4803,8 @@ async function writeBoundedZipArchive(destinationPath, inputs, options = {}) {
|
|
|
4803
4803
|
throw error;
|
|
4804
4804
|
}
|
|
4805
4805
|
}
|
|
4806
|
-
async function openBoundedZipArchive(
|
|
4807
|
-
return BoundedZipArchive.open(
|
|
4806
|
+
async function openBoundedZipArchive(path21, options) {
|
|
4807
|
+
return BoundedZipArchive.open(path21, options);
|
|
4808
4808
|
}
|
|
4809
4809
|
var EOCD_SIGNATURE, ZIP64_EOCD_SIGNATURE, ZIP64_LOCATOR_SIGNATURE, CENTRAL_FILE_SIGNATURE, LOCAL_FILE_SIGNATURE, ZIP64_EXTRA_FIELD_ID, MAX_EOCD_SEARCH_BYTES, UTF8_FLAG, ENCRYPTED_FLAG, STRONG_ENCRYPTION_FLAG, DATA_DESCRIPTOR_FLAG, STORE_METHOD, DEFLATE_METHOD, MANIFEST_MEMORY_LIMIT, STREAM_CHUNK_BYTES, ZIP_LIMIT_FIELDS, ZipArchiveFormatError, CRC32_TABLE, CompressedVerifier, OutputIntegrityVerifier, BoundedZipArchive;
|
|
4810
4810
|
var init_zip_stream = __esm({
|
|
@@ -4950,8 +4950,8 @@ var init_zip_stream = __esm({
|
|
|
4950
4950
|
actualAggregateBytes = 0;
|
|
4951
4951
|
byName;
|
|
4952
4952
|
localEndBoundary;
|
|
4953
|
-
constructor(
|
|
4954
|
-
this.path =
|
|
4953
|
+
constructor(path21, entries, archiveSize, centralOffset, handle, limits, signal, io) {
|
|
4954
|
+
this.path = path21;
|
|
4955
4955
|
this.entries = entries;
|
|
4956
4956
|
this.archiveSize = archiveSize;
|
|
4957
4957
|
this.centralOffset = centralOffset;
|
|
@@ -4963,7 +4963,7 @@ var init_zip_stream = __esm({
|
|
|
4963
4963
|
const offsets = entries.map((entry) => entry.localHeaderOffset).sort((a, b) => a - b);
|
|
4964
4964
|
this.localEndBoundary = new Map(offsets.map((offset, index) => [offset, offsets[index + 1] ?? centralOffset]));
|
|
4965
4965
|
}
|
|
4966
|
-
static async open(
|
|
4966
|
+
static async open(path21, options = {}) {
|
|
4967
4967
|
const limits = resolveSourceReadLimits(options.sourceReadLimits);
|
|
4968
4968
|
throwIfAborted(options.signal);
|
|
4969
4969
|
if (options.io) {
|
|
@@ -4973,7 +4973,7 @@ var init_zip_stream = __esm({
|
|
|
4973
4973
|
resourceClass: "backup-central-directory"
|
|
4974
4974
|
});
|
|
4975
4975
|
}
|
|
4976
|
-
const handle = await open2(
|
|
4976
|
+
const handle = await open2(path21, "r");
|
|
4977
4977
|
try {
|
|
4978
4978
|
if (options.io) {
|
|
4979
4979
|
observeAdapterIo(options.io, {
|
|
@@ -4989,7 +4989,7 @@ var init_zip_stream = __esm({
|
|
|
4989
4989
|
const archiveSize = toSafeOffset(metadata.size, "ZIP archive size");
|
|
4990
4990
|
const central = await locateCentralDirectory(handle, archiveSize, options.signal);
|
|
4991
4991
|
const entries = await parseCentralDirectory(handle, archiveSize, central, limits, options.signal);
|
|
4992
|
-
return new _BoundedZipArchive(
|
|
4992
|
+
return new _BoundedZipArchive(path21, entries, archiveSize, central.offset, handle, limits, options.signal, options.io);
|
|
4993
4993
|
} catch (error) {
|
|
4994
4994
|
await handle.close();
|
|
4995
4995
|
throw error;
|
|
@@ -5495,16 +5495,16 @@ var init_composer_sqlite = __esm({
|
|
|
5495
5495
|
|
|
5496
5496
|
// ../../node_modules/.pnpm/cursor-history@0.18.0_patch_hash=dbff0ea0e399ea9504168452170a23ee2b432a6dc6a69a20b49bf95ef139fa74/node_modules/cursor-history/dist/core/backup-publication.js
|
|
5497
5497
|
import { closeSync as closeSync2, constants as constants2, fchmodSync as fchmodSync2, fstatSync as fstatSync2, lstatSync as lstatSync2, openSync as openSync2 } from "node:fs";
|
|
5498
|
-
function projectStat(
|
|
5498
|
+
function projectStat(stat13) {
|
|
5499
5499
|
return {
|
|
5500
|
-
device: BigInt(
|
|
5501
|
-
inode: BigInt(
|
|
5502
|
-
mode: Number(
|
|
5503
|
-
regularFile:
|
|
5500
|
+
device: BigInt(stat13.dev),
|
|
5501
|
+
inode: BigInt(stat13.ino),
|
|
5502
|
+
mode: Number(stat13.mode) & 511,
|
|
5503
|
+
regularFile: stat13.isFile()
|
|
5504
5504
|
};
|
|
5505
5505
|
}
|
|
5506
|
-
function hasIdentity(
|
|
5507
|
-
return
|
|
5506
|
+
function hasIdentity(stat13, expected) {
|
|
5507
|
+
return stat13.device === expected.device && stat13.inode === expected.inode;
|
|
5508
5508
|
}
|
|
5509
5509
|
function identityError(message) {
|
|
5510
5510
|
const error = new Error(message);
|
|
@@ -5573,10 +5573,10 @@ var init_backup_publication = __esm({
|
|
|
5573
5573
|
"use strict";
|
|
5574
5574
|
init_errors();
|
|
5575
5575
|
DEFAULT_MODE_OPERATIONS = Object.freeze({
|
|
5576
|
-
openNoFollow: (
|
|
5576
|
+
openNoFollow: (path21) => openSync2(path21, constants2.O_RDONLY | (constants2.O_NOFOLLOW ?? 0)),
|
|
5577
5577
|
statDescriptor: (descriptor) => projectStat(fstatSync2(descriptor, { bigint: true })),
|
|
5578
5578
|
chmodDescriptor: (descriptor, mode) => fchmodSync2(descriptor, mode),
|
|
5579
|
-
statPathNoFollow: (
|
|
5579
|
+
statPathNoFollow: (path21) => projectStat(lstatSync2(path21, { bigint: true })),
|
|
5580
5580
|
close: (descriptor) => closeSync2(descriptor)
|
|
5581
5581
|
});
|
|
5582
5582
|
}
|
|
@@ -5587,12 +5587,12 @@ import { linkSync, lstatSync as lstatSync3, renameSync, unlinkSync as unlinkSync
|
|
|
5587
5587
|
function errorCode(error) {
|
|
5588
5588
|
return error instanceof Error && "code" in error ? String(error.code) : void 0;
|
|
5589
5589
|
}
|
|
5590
|
-
function hasIdentity2(
|
|
5591
|
-
return
|
|
5590
|
+
function hasIdentity2(stat13, expected) {
|
|
5591
|
+
return stat13.isFile() && stat13.dev === expected.device && stat13.ino === expected.inode;
|
|
5592
5592
|
}
|
|
5593
|
-
function pathIdentityVerified(
|
|
5593
|
+
function pathIdentityVerified(path21, expected, operations) {
|
|
5594
5594
|
try {
|
|
5595
|
-
return hasIdentity2(operations.statPathNoFollow(
|
|
5595
|
+
return hasIdentity2(operations.statPathNoFollow(path21), expected);
|
|
5596
5596
|
} catch {
|
|
5597
5597
|
return false;
|
|
5598
5598
|
}
|
|
@@ -5643,8 +5643,8 @@ var init_backup_archive_publication = __esm({
|
|
|
5643
5643
|
DEFAULT_OPERATIONS = Object.freeze({
|
|
5644
5644
|
rename: (sourcePath, destinationPath) => renameSync(sourcePath, destinationPath),
|
|
5645
5645
|
link: (sourcePath, destinationPath) => linkSync(sourcePath, destinationPath),
|
|
5646
|
-
unlink: (
|
|
5647
|
-
statPathNoFollow: (
|
|
5646
|
+
unlink: (path21) => unlinkSync2(path21),
|
|
5647
|
+
statPathNoFollow: (path21) => lstatSync3(path21, { bigint: true })
|
|
5648
5648
|
});
|
|
5649
5649
|
}
|
|
5650
5650
|
});
|
|
@@ -5654,11 +5654,11 @@ import { linkSync as linkSync2, lstatSync as lstatSync4, renameSync as renameSyn
|
|
|
5654
5654
|
function errorCode2(error) {
|
|
5655
5655
|
return error instanceof Error && "code" in error ? String(error.code) : void 0;
|
|
5656
5656
|
}
|
|
5657
|
-
function hasIdentity3(
|
|
5658
|
-
return
|
|
5657
|
+
function hasIdentity3(stat13, expected) {
|
|
5658
|
+
return stat13.isFile() && stat13.dev === expected.device && stat13.ino === expected.inode;
|
|
5659
5659
|
}
|
|
5660
|
-
function cleanupError(
|
|
5661
|
-
const error = new TemporaryArtifactCleanupError(identityVerified ? [
|
|
5660
|
+
function cleanupError(path21, cause, identityVerified = true) {
|
|
5661
|
+
const error = new TemporaryArtifactCleanupError(identityVerified ? [path21] : [], identityVerified ? [] : [path21]);
|
|
5662
5662
|
Object.defineProperty(error, "cause", { configurable: true, value: cause });
|
|
5663
5663
|
return error;
|
|
5664
5664
|
}
|
|
@@ -5706,8 +5706,8 @@ var init_restore_publication = __esm({
|
|
|
5706
5706
|
DEFAULT_OPERATIONS2 = Object.freeze({
|
|
5707
5707
|
rename: (sourcePath, destinationPath) => renameSync2(sourcePath, destinationPath),
|
|
5708
5708
|
link: (sourcePath, destinationPath) => linkSync2(sourcePath, destinationPath),
|
|
5709
|
-
unlink: (
|
|
5710
|
-
statPathNoFollow: (
|
|
5709
|
+
unlink: (path21) => unlinkSync3(path21),
|
|
5710
|
+
statPathNoFollow: (path21) => lstatSync4(path21, { bigint: true })
|
|
5711
5711
|
});
|
|
5712
5712
|
}
|
|
5713
5713
|
});
|
|
@@ -5761,7 +5761,7 @@ var init_session_id = __esm({
|
|
|
5761
5761
|
// ../../node_modules/.pnpm/cursor-history@0.18.0_patch_hash=dbff0ea0e399ea9504168452170a23ee2b432a6dc6a69a20b49bf95ef139fa74/node_modules/cursor-history/dist/core/backup.js
|
|
5762
5762
|
import { createHash as createHash4, randomUUID } from "node:crypto";
|
|
5763
5763
|
import { chmodSync as chmodSync3, closeSync as closeSync3, constants as constants3, existsSync as existsSync7, copyFileSync, fchmodSync as fchmodSync3, fstatSync as fstatSync3, fsyncSync as fsyncSync2, lstatSync as lstatSync5, mkdirSync as mkdirSync2, openSync as openSync3, readFileSync as readFileSync9, readSync, readdirSync as readdirSync5, realpathSync as realpathSync2, statSync as statSync3, unlinkSync as unlinkSync4, writeSync } from "node:fs";
|
|
5764
|
-
import { homedir as
|
|
5764
|
+
import { homedir as homedir12 } from "node:os";
|
|
5765
5765
|
import { basename as basename4, dirname as dirname4, isAbsolute as isAbsolute2, join as join8, relative as relative3, resolve as resolve2, sep as sep2 } from "node:path";
|
|
5766
5766
|
function backupDatabaseReadRequest(sqliteDriver, io, dbPath, logicalSessionId) {
|
|
5767
5767
|
const global = dbPath === "globalStorage/state.vscdb";
|
|
@@ -5801,7 +5801,7 @@ function freezeSourceReadOptions(options = {}) {
|
|
|
5801
5801
|
});
|
|
5802
5802
|
}
|
|
5803
5803
|
function getDefaultBackupDir() {
|
|
5804
|
-
return join8(
|
|
5804
|
+
return join8(homedir12(), "cursor-history-backups");
|
|
5805
5805
|
}
|
|
5806
5806
|
function computeChecksum(buffer) {
|
|
5807
5807
|
return `sha256:${createHash4("sha256").update(buffer).digest("hex")}`;
|
|
@@ -5821,11 +5821,11 @@ function scanDatabaseFiles(dataPath2) {
|
|
|
5821
5821
|
const userDir = dirname4(dataPath2);
|
|
5822
5822
|
const globalDbPath = join8(userDir, "globalStorage", "state.vscdb");
|
|
5823
5823
|
if (existsSync7(globalDbPath)) {
|
|
5824
|
-
const
|
|
5824
|
+
const stat13 = statSync3(globalDbPath);
|
|
5825
5825
|
files.push({
|
|
5826
5826
|
absolutePath: globalDbPath,
|
|
5827
5827
|
relativePath: "globalStorage/state.vscdb",
|
|
5828
|
-
size:
|
|
5828
|
+
size: stat13.size,
|
|
5829
5829
|
type: "global-db"
|
|
5830
5830
|
});
|
|
5831
5831
|
}
|
|
@@ -5838,22 +5838,22 @@ function scanDatabaseFiles(dataPath2) {
|
|
|
5838
5838
|
const workspaceDir = join8(workspaceStorageDir, entry.name);
|
|
5839
5839
|
const workspaceDbPath = join8(workspaceDir, "state.vscdb");
|
|
5840
5840
|
if (existsSync7(workspaceDbPath)) {
|
|
5841
|
-
const
|
|
5841
|
+
const stat13 = statSync3(workspaceDbPath);
|
|
5842
5842
|
files.push({
|
|
5843
5843
|
absolutePath: workspaceDbPath,
|
|
5844
5844
|
relativePath: `workspaceStorage/${entry.name}/state.vscdb`,
|
|
5845
|
-
size:
|
|
5845
|
+
size: stat13.size,
|
|
5846
5846
|
type: "workspace-db",
|
|
5847
5847
|
workspaceId: entry.name
|
|
5848
5848
|
});
|
|
5849
5849
|
}
|
|
5850
5850
|
const workspaceJsonPath = join8(workspaceDir, "workspace.json");
|
|
5851
5851
|
if (existsSync7(workspaceJsonPath)) {
|
|
5852
|
-
const
|
|
5852
|
+
const stat13 = statSync3(workspaceJsonPath);
|
|
5853
5853
|
files.push({
|
|
5854
5854
|
absolutePath: workspaceJsonPath,
|
|
5855
5855
|
relativePath: `workspaceStorage/${entry.name}/workspace.json`,
|
|
5856
|
-
size:
|
|
5856
|
+
size: stat13.size,
|
|
5857
5857
|
type: "workspace-json",
|
|
5858
5858
|
workspaceId: entry.name
|
|
5859
5859
|
});
|
|
@@ -5866,11 +5866,11 @@ function scanDatabaseFiles(dataPath2) {
|
|
|
5866
5866
|
return files;
|
|
5867
5867
|
}
|
|
5868
5868
|
function createManifest(files, stats, composerWorkspaceInventory) {
|
|
5869
|
-
const
|
|
5869
|
+
const platform5 = process.platform;
|
|
5870
5870
|
return {
|
|
5871
5871
|
version: MANIFEST_VERSION,
|
|
5872
5872
|
createdAt: (/* @__PURE__ */ new Date()).toISOString(),
|
|
5873
|
-
sourcePlatform:
|
|
5873
|
+
sourcePlatform: platform5,
|
|
5874
5874
|
producer: PACKAGE_VERSION,
|
|
5875
5875
|
cursorHistoryVersion: PACKAGE_VERSION,
|
|
5876
5876
|
files,
|
|
@@ -6075,12 +6075,12 @@ function checkDiskSpace(outputPath, requiredBytes) {
|
|
|
6075
6075
|
};
|
|
6076
6076
|
}
|
|
6077
6077
|
}
|
|
6078
|
-
function syncParentDirectory(
|
|
6078
|
+
function syncParentDirectory(path21) {
|
|
6079
6079
|
if (process.platform === "win32")
|
|
6080
6080
|
return;
|
|
6081
6081
|
let descriptor;
|
|
6082
6082
|
try {
|
|
6083
|
-
descriptor = openSync3(dirname4(
|
|
6083
|
+
descriptor = openSync3(dirname4(path21), constants3.O_RDONLY);
|
|
6084
6084
|
fsyncSync2(descriptor);
|
|
6085
6085
|
} catch {
|
|
6086
6086
|
} finally {
|
|
@@ -6092,13 +6092,13 @@ function syncParentDirectory(path19) {
|
|
|
6092
6092
|
}
|
|
6093
6093
|
}
|
|
6094
6094
|
}
|
|
6095
|
-
function removePrivateArchiveStage(
|
|
6095
|
+
function removePrivateArchiveStage(path21, operationError) {
|
|
6096
6096
|
try {
|
|
6097
|
-
unlinkSync4(
|
|
6097
|
+
unlinkSync4(path21);
|
|
6098
6098
|
} catch (error) {
|
|
6099
6099
|
if (errorCode3(error) === "ENOENT")
|
|
6100
6100
|
return;
|
|
6101
|
-
const cleanupError2 = new TemporaryArtifactCleanupError([
|
|
6101
|
+
const cleanupError2 = new TemporaryArtifactCleanupError([path21]);
|
|
6102
6102
|
attachCleanupCause(cleanupError2, operationError ?? error);
|
|
6103
6103
|
throw cleanupError2;
|
|
6104
6104
|
}
|
|
@@ -6362,7 +6362,7 @@ function combineTemporaryCleanupErrors(first, second) {
|
|
|
6362
6362
|
const unverifiedResidueSet = new Set(unverifiedResiduePaths);
|
|
6363
6363
|
const residuePaths = [
|
|
6364
6364
|
.../* @__PURE__ */ new Set([...first.details.residuePaths, ...second.details.residuePaths])
|
|
6365
|
-
].filter((
|
|
6365
|
+
].filter((path21) => !unverifiedResidueSet.has(path21));
|
|
6366
6366
|
const combined = new TemporaryArtifactCleanupError(residuePaths, unverifiedResiduePaths);
|
|
6367
6367
|
Object.defineProperty(combined, "cause", { configurable: true, value: first });
|
|
6368
6368
|
return combined;
|
|
@@ -6470,18 +6470,18 @@ function validatedManifestFiles(manifest) {
|
|
|
6470
6470
|
if (type !== "global-db" && type !== "workspace-db" && type !== "workspace-json" && type !== "manifest") {
|
|
6471
6471
|
throw new ZipArchiveFormatError(`Backup manifest file ${index + 1} has an invalid type.`);
|
|
6472
6472
|
}
|
|
6473
|
-
const
|
|
6474
|
-
const expectedType = backupEntryTypeForCanonicalPath(
|
|
6473
|
+
const path21 = entry["path"];
|
|
6474
|
+
const expectedType = backupEntryTypeForCanonicalPath(path21);
|
|
6475
6475
|
if (expectedType === void 0 || type !== expectedType) {
|
|
6476
6476
|
throw new ZipArchiveFormatError(`Backup manifest file ${index + 1} has an unsupported path/type combination.`);
|
|
6477
6477
|
}
|
|
6478
|
-
const destinationKey =
|
|
6478
|
+
const destinationKey = path21.normalize("NFC").toLowerCase();
|
|
6479
6479
|
if (destinationKeys.has(destinationKey)) {
|
|
6480
|
-
throw new ZipArchiveFormatError(`Backup manifest contains a duplicate restore destination: ${
|
|
6480
|
+
throw new ZipArchiveFormatError(`Backup manifest contains a duplicate restore destination: ${path21}`);
|
|
6481
6481
|
}
|
|
6482
6482
|
destinationKeys.add(destinationKey);
|
|
6483
6483
|
return {
|
|
6484
|
-
path:
|
|
6484
|
+
path: path21,
|
|
6485
6485
|
size: Number(entry["size"]),
|
|
6486
6486
|
checksum: entry["checksum"].toLowerCase(),
|
|
6487
6487
|
type
|
|
@@ -6498,10 +6498,10 @@ function isCanonicalBackupPathSegment(value) {
|
|
|
6498
6498
|
}
|
|
6499
6499
|
return true;
|
|
6500
6500
|
}
|
|
6501
|
-
function backupEntryTypeForCanonicalPath(
|
|
6502
|
-
if (
|
|
6501
|
+
function backupEntryTypeForCanonicalPath(path21) {
|
|
6502
|
+
if (path21 === "globalStorage/state.vscdb")
|
|
6503
6503
|
return "global-db";
|
|
6504
|
-
const match = /^workspaceStorage\/([^/]+)\/(state\.vscdb|workspace\.json)$/u.exec(
|
|
6504
|
+
const match = /^workspaceStorage\/([^/]+)\/(state\.vscdb|workspace\.json)$/u.exec(path21);
|
|
6505
6505
|
if (!match || !isCanonicalBackupPathSegment(match[1]))
|
|
6506
6506
|
return void 0;
|
|
6507
6507
|
return match[2] === "state.vscdb" ? "workspace-db" : "workspace-json";
|
|
@@ -6520,8 +6520,8 @@ function validateComposerWorkspaceInventory(manifest, files) {
|
|
|
6520
6520
|
if (!Array.isArray(inventory["workspaces"])) {
|
|
6521
6521
|
throw new ZipArchiveFormatError("Backup manifest Composer workspace inventory workspaces must be an array.");
|
|
6522
6522
|
}
|
|
6523
|
-
const expectedWorkspaceIds = files.filter(({ type }) => type === "workspace-db").map(({ path:
|
|
6524
|
-
const containsGlobalDatabase = files.some(({ type, path:
|
|
6523
|
+
const expectedWorkspaceIds = files.filter(({ type }) => type === "workspace-db").map(({ path: path21 }) => /^workspaceStorage\/([^/]+)\/state\.vscdb$/u.exec(path21)?.[1]).filter((workspaceId) => workspaceId !== void 0).sort(compareCodePoints4);
|
|
6524
|
+
const containsGlobalDatabase = files.some(({ type, path: path21 }) => type === "global-db" && path21 === "globalStorage/state.vscdb");
|
|
6525
6525
|
if (inventory["workspaces"].length !== expectedWorkspaceIds.length) {
|
|
6526
6526
|
throw new ZipArchiveFormatError("Backup manifest Composer workspace inventory does not cover every workspace database.");
|
|
6527
6527
|
}
|
|
@@ -6677,7 +6677,7 @@ async function openBackupDatabase(backupPath, dbPath, options = {}) {
|
|
|
6677
6677
|
if (!entry || entry.isDirectory) {
|
|
6678
6678
|
throw new BackupEntryNotFoundError(dbPath);
|
|
6679
6679
|
}
|
|
6680
|
-
const manifestEntry = manifestFiles.find(({ path:
|
|
6680
|
+
const manifestEntry = manifestFiles.find(({ path: path21 }) => path21 === dbPath);
|
|
6681
6681
|
if (!manifestEntry) {
|
|
6682
6682
|
throw new ZipArchiveFormatError(`Backup database is not declared by the manifest: ${dbPath}`);
|
|
6683
6683
|
}
|
|
@@ -6732,7 +6732,7 @@ async function readBackupEntryBuffer(backupPath, entryPath, options = {}, maxByt
|
|
|
6732
6732
|
const manifest = await readManifestFromArchive(archive);
|
|
6733
6733
|
if (!manifest)
|
|
6734
6734
|
throw new ZipArchiveFormatError("Manifest file not found in backup.");
|
|
6735
|
-
const manifestEntry = validatedManifestFiles(manifest).find(({ path:
|
|
6735
|
+
const manifestEntry = validatedManifestFiles(manifest).find(({ path: path21 }) => path21 === entryPath);
|
|
6736
6736
|
const entry = archive.getEntry(entryPath);
|
|
6737
6737
|
if (!entry || entry.isDirectory) {
|
|
6738
6738
|
if (manifestEntry) {
|
|
@@ -6788,18 +6788,18 @@ async function validateBackup(backupPath, options = {}) {
|
|
|
6788
6788
|
};
|
|
6789
6789
|
}
|
|
6790
6790
|
}
|
|
6791
|
-
function lstatIfPresent(
|
|
6791
|
+
function lstatIfPresent(path21) {
|
|
6792
6792
|
try {
|
|
6793
|
-
return lstatSync5(
|
|
6793
|
+
return lstatSync5(path21);
|
|
6794
6794
|
} catch (error) {
|
|
6795
6795
|
if (errorCode3(error) === "ENOENT")
|
|
6796
6796
|
return void 0;
|
|
6797
6797
|
throw error;
|
|
6798
6798
|
}
|
|
6799
6799
|
}
|
|
6800
|
-
function assertNoLinkedRestorePath(trustedRoot,
|
|
6800
|
+
function assertNoLinkedRestorePath(trustedRoot, path21, leafKind) {
|
|
6801
6801
|
const absoluteRoot = resolve2(trustedRoot);
|
|
6802
|
-
const absolutePath = resolve2(
|
|
6802
|
+
const absolutePath = resolve2(path21);
|
|
6803
6803
|
const suffix = relative3(absoluteRoot, absolutePath);
|
|
6804
6804
|
if (suffix === ".." || suffix.startsWith(`..${sep2}`) || isAbsolute2(suffix)) {
|
|
6805
6805
|
throw new Error(`Restore destination escapes the Cursor data directory: ${absolutePath}`);
|
|
@@ -7103,12 +7103,12 @@ async function listBackups(directory, options = {}) {
|
|
|
7103
7103
|
continue;
|
|
7104
7104
|
}
|
|
7105
7105
|
const filePath = join8(dir, entry.name);
|
|
7106
|
-
const
|
|
7106
|
+
const stat13 = statSync3(filePath);
|
|
7107
7107
|
const info = {
|
|
7108
7108
|
filePath,
|
|
7109
7109
|
filename: entry.name,
|
|
7110
|
-
fileSize:
|
|
7111
|
-
modifiedAt:
|
|
7110
|
+
fileSize: stat13.size,
|
|
7111
|
+
modifiedAt: stat13.mtime
|
|
7112
7112
|
};
|
|
7113
7113
|
try {
|
|
7114
7114
|
const manifest = await readBackupManifest(filePath, readOptions);
|
|
@@ -7132,7 +7132,7 @@ async function listBackups(directory, options = {}) {
|
|
|
7132
7132
|
return backups;
|
|
7133
7133
|
}
|
|
7134
7134
|
function getDefaultCursorDataPath2() {
|
|
7135
|
-
const home =
|
|
7135
|
+
const home = homedir12();
|
|
7136
7136
|
switch (process.platform) {
|
|
7137
7137
|
case "win32":
|
|
7138
7138
|
return join8(process.env["APPDATA"] ?? join8(home, "AppData", "Roaming"), "Cursor", "User", "workspaceStorage");
|
|
@@ -7761,11 +7761,11 @@ function attachErrorCause(error, cause) {
|
|
|
7761
7761
|
});
|
|
7762
7762
|
}
|
|
7763
7763
|
}
|
|
7764
|
-
async function parseStoreDb(
|
|
7764
|
+
async function parseStoreDb(path21, options = {}) {
|
|
7765
7765
|
const limits = options.limits ?? SOURCE_READ_LIMITS_V1_DEFAULTS;
|
|
7766
7766
|
const failureOutcome = options.failureOutcome ?? "fatal";
|
|
7767
7767
|
throwIfAborted4(options.signal);
|
|
7768
|
-
if (!pathExists(
|
|
7768
|
+
if (!pathExists(path21, options.signal, options.io, options.logicalSessionId))
|
|
7769
7769
|
return null;
|
|
7770
7770
|
const budget = new SqliteSourceReadBudget(limits, failureOutcome);
|
|
7771
7771
|
let workspace = null;
|
|
@@ -7777,7 +7777,7 @@ async function parseStoreDb(path19, options = {}) {
|
|
|
7777
7777
|
workspace = createPrivateTempWorkspace({ prefix: "ch-store-", signal: options.signal });
|
|
7778
7778
|
const tmpPath = workspace.createFile("store.db");
|
|
7779
7779
|
throwIfAborted4(options.signal);
|
|
7780
|
-
await backupDatabase(
|
|
7780
|
+
await backupDatabase(path21, tmpPath, databaseRequest("store-snapshot", STORE_SNAPSHOT_CAPABILITIES, options.sqliteDriver, options, "store-database"));
|
|
7781
7781
|
snapshotComplete = true;
|
|
7782
7782
|
throwIfAborted4(options.signal);
|
|
7783
7783
|
if (process.platform !== "win32")
|
|
@@ -7824,12 +7824,12 @@ async function parseStoreDb(path19, options = {}) {
|
|
|
7824
7824
|
operationError = error;
|
|
7825
7825
|
else {
|
|
7826
7826
|
options.onDiagnostic?.(error);
|
|
7827
|
-
debugLogStorage(`store.db defensive parse failed for ${
|
|
7827
|
+
debugLogStorage(`store.db defensive parse failed for ${path21}: ${error.code}`);
|
|
7828
7828
|
}
|
|
7829
7829
|
} else if (isSessionIntegrityError(error)) {
|
|
7830
7830
|
operationError = error;
|
|
7831
7831
|
} else if (error instanceof StoreSourceCorruptError || isSqliteSourceCorruptionError(error)) {
|
|
7832
|
-
debugLogStorage(`store.db source/schema parse failed for ${
|
|
7832
|
+
debugLogStorage(`store.db source/schema parse failed for ${path21}: ${String(error)}`);
|
|
7833
7833
|
} else {
|
|
7834
7834
|
operationError = error;
|
|
7835
7835
|
}
|
|
@@ -7854,7 +7854,7 @@ async function parseStoreDb(path19, options = {}) {
|
|
|
7854
7854
|
throw operationError;
|
|
7855
7855
|
return result;
|
|
7856
7856
|
}
|
|
7857
|
-
function pathExists(
|
|
7857
|
+
function pathExists(path21, signal, io, logicalSessionId) {
|
|
7858
7858
|
throwIfAborted4(signal);
|
|
7859
7859
|
try {
|
|
7860
7860
|
if (io) {
|
|
@@ -7867,7 +7867,7 @@ function pathExists(path19, signal, io, logicalSessionId) {
|
|
|
7867
7867
|
...logicalSessionId ? { logicalSessionId } : {}
|
|
7868
7868
|
});
|
|
7869
7869
|
}
|
|
7870
|
-
statSync4(
|
|
7870
|
+
statSync4(path21);
|
|
7871
7871
|
return true;
|
|
7872
7872
|
} catch (error) {
|
|
7873
7873
|
const code2 = error?.code;
|
|
@@ -8237,14 +8237,14 @@ function decodeMessageObject(data, outcome) {
|
|
|
8237
8237
|
return direct;
|
|
8238
8238
|
let offset = 0;
|
|
8239
8239
|
while (offset < data.length) {
|
|
8240
|
-
const tag =
|
|
8240
|
+
const tag = readVarint2(data, offset);
|
|
8241
8241
|
if (!tag)
|
|
8242
8242
|
return null;
|
|
8243
8243
|
offset = tag.next;
|
|
8244
8244
|
const field = tag.value >>> 3;
|
|
8245
8245
|
const wire = tag.value & 7;
|
|
8246
8246
|
if (wire === 0) {
|
|
8247
|
-
const value =
|
|
8247
|
+
const value = readVarint2(data, offset);
|
|
8248
8248
|
if (!value)
|
|
8249
8249
|
return null;
|
|
8250
8250
|
offset = value.next;
|
|
@@ -8260,7 +8260,7 @@ function decodeMessageObject(data, outcome) {
|
|
|
8260
8260
|
}
|
|
8261
8261
|
if (wire !== 2)
|
|
8262
8262
|
return null;
|
|
8263
|
-
const length =
|
|
8263
|
+
const length = readVarint2(data, offset);
|
|
8264
8264
|
if (!length)
|
|
8265
8265
|
return null;
|
|
8266
8266
|
offset = length.next;
|
|
@@ -8290,7 +8290,7 @@ function parseLeafJson(data, outcome) {
|
|
|
8290
8290
|
return null;
|
|
8291
8291
|
}
|
|
8292
8292
|
}
|
|
8293
|
-
function
|
|
8293
|
+
function readVarint2(data, start) {
|
|
8294
8294
|
let value = 0;
|
|
8295
8295
|
let shift = 0;
|
|
8296
8296
|
let offset = start;
|
|
@@ -8705,7 +8705,7 @@ function mapLine(parsed, sourceLine) {
|
|
|
8705
8705
|
return { kind: "skip", rawContentBlocks };
|
|
8706
8706
|
}
|
|
8707
8707
|
const sourceRelationships = {};
|
|
8708
|
-
const parent =
|
|
8708
|
+
const parent = firstString2(obj["parentMessageId"], obj["parentId"], nestedRecord["parentMessageId"], nestedRecord["parentId"]);
|
|
8709
8709
|
const sidechain = firstBoolean(obj["isSidechain"], nestedRecord["isSidechain"]);
|
|
8710
8710
|
if (parent !== void 0)
|
|
8711
8711
|
sourceRelationships["parentMessageId"] = parent;
|
|
@@ -8750,7 +8750,7 @@ function retainUnsupportedTranscriptValue(value) {
|
|
|
8750
8750
|
const blocks = Array.isArray(value) ? value : [value];
|
|
8751
8751
|
return blocks.map((block) => retainRawContentBlock(block, "unsupported", "transcript"));
|
|
8752
8752
|
}
|
|
8753
|
-
function
|
|
8753
|
+
function firstString2(...values) {
|
|
8754
8754
|
return values.find((value) => typeof value === "string" && value.length > 0);
|
|
8755
8755
|
}
|
|
8756
8756
|
function firstBoolean(...values) {
|
|
@@ -8835,15 +8835,15 @@ function compareStringArrays2(left, right) {
|
|
|
8835
8835
|
function getStorePhysicalOccurrences(session) {
|
|
8836
8836
|
return physicalOccurrences.get(session) ?? [];
|
|
8837
8837
|
}
|
|
8838
|
-
function occurrenceKey(representation,
|
|
8839
|
-
return `${representation}\0${
|
|
8838
|
+
function occurrenceKey(representation, path21) {
|
|
8839
|
+
return `${representation}\0${path21}`;
|
|
8840
8840
|
}
|
|
8841
|
-
function occurrence(logicalSessionId, representation,
|
|
8841
|
+
function occurrence(logicalSessionId, representation, path21, workspacePath) {
|
|
8842
8842
|
return {
|
|
8843
|
-
instanceKey: occurrenceKey(representation,
|
|
8843
|
+
instanceKey: occurrenceKey(representation, path21),
|
|
8844
8844
|
logicalSessionId,
|
|
8845
8845
|
representation,
|
|
8846
|
-
path:
|
|
8846
|
+
path: path21,
|
|
8847
8847
|
...workspacePath ? { workspacePath: normalizeWorkspacePath(workspacePath) } : {},
|
|
8848
8848
|
sourceOrder: 0
|
|
8849
8849
|
};
|
|
@@ -9191,7 +9191,7 @@ async function discoverStoreSessions(storeRoot2, options = {}) {
|
|
|
9191
9191
|
const evidence = evidenceFor(uuid);
|
|
9192
9192
|
evidence.transcriptInventoried = true;
|
|
9193
9193
|
const transcriptOccurrence = occurrence(uuid, "store-transcript", nested, transcriptWorkspacePath(sanitized, metadataCandidates.get(logicalSessionIdKey(uuid)) ?? []));
|
|
9194
|
-
if (!evidence.transcriptOccurrences.some(({ path:
|
|
9194
|
+
if (!evidence.transcriptOccurrences.some(({ path: path21 }) => path21 === nested)) {
|
|
9195
9195
|
evidence.transcriptOccurrences.push(transcriptOccurrence);
|
|
9196
9196
|
}
|
|
9197
9197
|
if (options.metadataOnly) {
|
|
@@ -9208,7 +9208,7 @@ async function discoverStoreSessions(storeRoot2, options = {}) {
|
|
|
9208
9208
|
evidence.transcriptInventoried = true;
|
|
9209
9209
|
const transcriptPath = join10(transcriptDir, entry.name);
|
|
9210
9210
|
const transcriptOccurrence = occurrence(uuid, "store-transcript", transcriptPath, transcriptWorkspacePath(sanitized, metadataCandidates.get(logicalSessionIdKey(uuid)) ?? []));
|
|
9211
|
-
if (!evidence.transcriptOccurrences.some(({ path:
|
|
9211
|
+
if (!evidence.transcriptOccurrences.some(({ path: path21 }) => path21 === transcriptPath)) {
|
|
9212
9212
|
evidence.transcriptOccurrences.push(transcriptOccurrence);
|
|
9213
9213
|
}
|
|
9214
9214
|
if (options.metadataOnly) {
|
|
@@ -9282,7 +9282,7 @@ async function discoverStoreSessions(storeRoot2, options = {}) {
|
|
|
9282
9282
|
const usableDbCandidates = dbCandidates.filter((candidate) => Boolean(candidate.parsed && candidate.parsed.messages.length > 0));
|
|
9283
9283
|
const selectedDbFidelity = usableDbCandidates.some(({ parsed }) => parsed.completeness === "complete") ? "complete" : "partial";
|
|
9284
9284
|
const selectedDbTier = usableDbCandidates.filter(({ parsed }) => parsed.completeness === selectedDbFidelity);
|
|
9285
|
-
let selectedDbCandidate = selectedDbTier[0] ?? dbCandidates.find(({ path:
|
|
9285
|
+
let selectedDbCandidate = selectedDbTier[0] ?? dbCandidates.find(({ path: path21 }) => path21 === ss.storeDbPath) ?? dbCandidates[0];
|
|
9286
9286
|
let dbReplicaInstances = [];
|
|
9287
9287
|
if (selectedDbTier.length > 1) {
|
|
9288
9288
|
const physical = physicalStoreCandidates(ss.id, "store-db", selectedDbFidelity, selectedDbTier.map((candidate) => ({
|
|
@@ -9496,12 +9496,12 @@ function recordInventory(evidence, logicalSessionId, metaRead, sessionDir, dbPat
|
|
|
9496
9496
|
if (metaRead.diagnostic)
|
|
9497
9497
|
evidence.metadataFailures.push(metaRead.diagnostic);
|
|
9498
9498
|
const metadataOccurrence = occurrence(logicalSessionId, "store-metadata", sessionDir, metaRead.meta?.cwd);
|
|
9499
|
-
if (!evidence.metadataOccurrences.some(({ path:
|
|
9499
|
+
if (!evidence.metadataOccurrences.some(({ path: path21 }) => path21 === sessionDir)) {
|
|
9500
9500
|
evidence.metadataOccurrences.push(metadataOccurrence);
|
|
9501
9501
|
}
|
|
9502
9502
|
if (dbInventoried) {
|
|
9503
9503
|
evidence.dbInventoried = true;
|
|
9504
|
-
if (!evidence.dbOccurrences.some(({ path:
|
|
9504
|
+
if (!evidence.dbOccurrences.some(({ path: path21 }) => path21 === dbPath)) {
|
|
9505
9505
|
evidence.dbOccurrences.push(occurrence(logicalSessionId, "store-db", dbPath, metaRead.meta?.cwd));
|
|
9506
9506
|
}
|
|
9507
9507
|
}
|
|
@@ -9747,12 +9747,12 @@ function listEntries(dir, signal, io) {
|
|
|
9747
9747
|
throw error;
|
|
9748
9748
|
}
|
|
9749
9749
|
}
|
|
9750
|
-
function readMeta(
|
|
9750
|
+
function readMeta(path21, signal, io, logicalSessionId, includeDisplayMetadata = true) {
|
|
9751
9751
|
throwIfAborted6(signal);
|
|
9752
9752
|
let raw;
|
|
9753
9753
|
try {
|
|
9754
9754
|
observeStoreFs(io, "read", "store-session-metadata", logicalSessionId, "store-db");
|
|
9755
|
-
raw = readFileSync10(
|
|
9755
|
+
raw = readFileSync10(path21);
|
|
9756
9756
|
} catch (error) {
|
|
9757
9757
|
if (isAbsentOrWrongType(error)) {
|
|
9758
9758
|
return { present: false, unsupportedExpectationMetadata: false };
|
|
@@ -9883,11 +9883,11 @@ function decodeJsonObjectKey(raw, start, end) {
|
|
|
9883
9883
|
function isJsonWhitespace(byte) {
|
|
9884
9884
|
return byte === 32 || byte === 9 || byte === 10 || byte === 13;
|
|
9885
9885
|
}
|
|
9886
|
-
function pathExists2(
|
|
9886
|
+
function pathExists2(path21, signal, io, resourceClass = "store-root-directory", logicalSessionId) {
|
|
9887
9887
|
throwIfAborted6(signal);
|
|
9888
9888
|
try {
|
|
9889
9889
|
observeStoreFs(io, "open", resourceClass, logicalSessionId);
|
|
9890
|
-
statSync5(
|
|
9890
|
+
statSync5(path21);
|
|
9891
9891
|
return true;
|
|
9892
9892
|
} catch (error) {
|
|
9893
9893
|
if (isAbsentOrWrongType(error))
|
|
@@ -11515,7 +11515,7 @@ async function resolveBackupWorkspaceInventory(manifest, backupPath, readOptions
|
|
|
11515
11515
|
throw new ZipArchiveFormatError("No intact restorable files found in backup.");
|
|
11516
11516
|
}
|
|
11517
11517
|
const databases = backupWorkspaceDatabaseEntries(manifest);
|
|
11518
|
-
const containsGlobalDatabase = manifest.files.some(({ type, path:
|
|
11518
|
+
const containsGlobalDatabase = manifest.files.some(({ type, path: path21 }) => type === "global-db" && path21 === "globalStorage/state.vscdb");
|
|
11519
11519
|
const inventory = manifest.composerWorkspaceInventory;
|
|
11520
11520
|
if (inventory) {
|
|
11521
11521
|
const dbPathByWorkspaceId = new Map(databases.map(({ workspaceId, dbPath }) => [workspaceId, dbPath]));
|
|
@@ -11565,7 +11565,7 @@ async function findWorkspacesFromBackup(backupPath, readOptions) {
|
|
|
11565
11565
|
let legacyLinkedGlobalIds;
|
|
11566
11566
|
if (!countedIds) {
|
|
11567
11567
|
let db = null;
|
|
11568
|
-
let
|
|
11568
|
+
let readError4;
|
|
11569
11569
|
try {
|
|
11570
11570
|
db = await openBackupDatabase(backupPath, workspace.dbPath, readOptions);
|
|
11571
11571
|
throwIfReadAborted(readOptions.signal);
|
|
@@ -11584,18 +11584,18 @@ async function findWorkspacesFromBackup(backupPath, readOptions) {
|
|
|
11584
11584
|
legacyLinkedGlobalIds = getWorkspaceComposerPointerIds(db, createComposerSqliteBudget(resolveSourceReadLimits(readOptions.sourceReadLimits)), readOptions.signal);
|
|
11585
11585
|
}
|
|
11586
11586
|
} catch (error) {
|
|
11587
|
-
|
|
11587
|
+
readError4 = error;
|
|
11588
11588
|
}
|
|
11589
11589
|
if (db) {
|
|
11590
11590
|
try {
|
|
11591
11591
|
db.close();
|
|
11592
11592
|
} catch (closeError) {
|
|
11593
|
-
attachReadFailureCause(closeError,
|
|
11593
|
+
attachReadFailureCause(closeError, readError4);
|
|
11594
11594
|
throw closeError;
|
|
11595
11595
|
}
|
|
11596
11596
|
}
|
|
11597
|
-
if (
|
|
11598
|
-
throw
|
|
11597
|
+
if (readError4 !== void 0)
|
|
11598
|
+
throw readError4;
|
|
11599
11599
|
}
|
|
11600
11600
|
const effectiveLinkedGlobalIds = [
|
|
11601
11601
|
...getBackupLinkedGlobalSessionIds(workspace) ?? legacyLinkedGlobalIds ?? []
|
|
@@ -12305,7 +12305,7 @@ async function getWorkspaceLinkedComposerIds(workspace, customDataPath) {
|
|
|
12305
12305
|
return [];
|
|
12306
12306
|
}
|
|
12307
12307
|
let db = null;
|
|
12308
|
-
let
|
|
12308
|
+
let readError4;
|
|
12309
12309
|
try {
|
|
12310
12310
|
db = await openDatabase2(globalDbPath);
|
|
12311
12311
|
const tableCheck = db.prepare("SELECT name FROM sqlite_master WHERE type='table' AND name='cursorDiskKV'").get();
|
|
@@ -12350,12 +12350,12 @@ async function getWorkspaceLinkedComposerIds(workspace, customDataPath) {
|
|
|
12350
12350
|
}
|
|
12351
12351
|
return [...ids];
|
|
12352
12352
|
} catch (error) {
|
|
12353
|
-
|
|
12353
|
+
readError4 = error;
|
|
12354
12354
|
if (shouldPropagateReadFailure(error))
|
|
12355
12355
|
throw error;
|
|
12356
12356
|
throwOwningDatabaseReadFailure(error);
|
|
12357
12357
|
} finally {
|
|
12358
|
-
closeDatabaseOrThrow(db,
|
|
12358
|
+
closeDatabaseOrThrow(db, readError4);
|
|
12359
12359
|
}
|
|
12360
12360
|
}
|
|
12361
12361
|
function privateReadState(context) {
|
|
@@ -12713,8 +12713,8 @@ function loadExactGlobalComposerSession(db, exactId, workspacePath, budget = cre
|
|
|
12713
12713
|
function composerWorkspaceMemberships(candidates) {
|
|
12714
12714
|
const counts2 = /* @__PURE__ */ new Map();
|
|
12715
12715
|
for (const candidate of candidates) {
|
|
12716
|
-
const
|
|
12717
|
-
counts2.set(
|
|
12716
|
+
const path21 = normalizeWorkspacePath(candidate.workspace.path);
|
|
12717
|
+
counts2.set(path21, (counts2.get(path21) ?? 0) + 1);
|
|
12718
12718
|
}
|
|
12719
12719
|
return [...counts2.entries()].sort(([left], [right]) => compareCodePoints8(left, right)).map(([workspacePath, contributingInstanceCount]) => ({
|
|
12720
12720
|
workspacePath,
|
|
@@ -13406,7 +13406,7 @@ async function listSessions(options, customDataPath, backupPath, context) {
|
|
|
13406
13406
|
composerWorkspaceInventory = await findComposerWorkspaceInventory(customDataPath, backupPath, context);
|
|
13407
13407
|
const storeWorkspacePaths = storeCatalogSessions.flatMap(verifiedStoreWorkspacePaths);
|
|
13408
13408
|
workspaceScopeResult = resolveWorkspaceScope(options.workspacePath, [
|
|
13409
|
-
...composerWorkspaceInventory.map(({ path:
|
|
13409
|
+
...composerWorkspaceInventory.map(({ path: path21 }) => path21),
|
|
13410
13410
|
...storeWorkspacePaths
|
|
13411
13411
|
]);
|
|
13412
13412
|
if (workspaceScopeResult.kind === "not-found") {
|
|
@@ -13672,7 +13672,7 @@ async function listSessions(options, customDataPath, backupPath, context) {
|
|
|
13672
13672
|
}
|
|
13673
13673
|
}
|
|
13674
13674
|
if (activeWorkspacePath) {
|
|
13675
|
-
const offScopeWorkspaces = composerWorkspaceInventory.filter(({ path:
|
|
13675
|
+
const offScopeWorkspaces = composerWorkspaceInventory.filter(({ path: path21 }) => !workspaceFilterMatches(path21, activeWorkspacePath));
|
|
13676
13676
|
for (const workspace of offScopeWorkspaces) {
|
|
13677
13677
|
if (backupPath) {
|
|
13678
13678
|
for (const id of getBackupComposerSessionIds(workspace) ?? []) {
|
|
@@ -14965,11 +14965,11 @@ function formatToolCall(toolData, codeBlocks) {
|
|
|
14965
14965
|
} else if (toolName === "grep" || toolName === "search" || toolName === "codebase_search") {
|
|
14966
14966
|
lines2.push(`[Tool: ${toolName === "grep" ? "Grep" : "Search"}]`);
|
|
14967
14967
|
const pattern = getParam(params, "pattern", "query", "searchQuery", "regex");
|
|
14968
|
-
const
|
|
14968
|
+
const path21 = getParam(params, "path", "directory", "targetDirectory");
|
|
14969
14969
|
if (pattern)
|
|
14970
14970
|
lines2.push(`Pattern: ${pattern}`);
|
|
14971
|
-
if (
|
|
14972
|
-
lines2.push(`Path: ${
|
|
14971
|
+
if (path21)
|
|
14972
|
+
lines2.push(`Path: ${path21}`);
|
|
14973
14973
|
} else if (toolName === "run_terminal_command" || toolName === "run_terminal_cmd" || toolName === "execute_command") {
|
|
14974
14974
|
lines2.push(`[Tool: Terminal Command]`);
|
|
14975
14975
|
const cmd = getParam(params, "command", "cmd");
|
|
@@ -15474,9 +15474,9 @@ import { pathToFileURL } from "node:url";
|
|
|
15474
15474
|
function generateSessionId() {
|
|
15475
15475
|
return randomUUID2();
|
|
15476
15476
|
}
|
|
15477
|
-
function transformPath(
|
|
15477
|
+
function transformPath(path21, sourcePrefix, destPrefix) {
|
|
15478
15478
|
const normalizedSource = sourcePrefix.replace(/\/+$/, "");
|
|
15479
|
-
const normalizedPath =
|
|
15479
|
+
const normalizedPath = path21;
|
|
15480
15480
|
if (normalizedPath.startsWith(normalizedSource + "/") || normalizedPath === normalizedSource) {
|
|
15481
15481
|
return destPrefix + normalizedPath.slice(normalizedSource.length);
|
|
15482
15482
|
}
|
|
@@ -15592,8 +15592,8 @@ function isNestedPath(source, destination) {
|
|
|
15592
15592
|
const normalizedDest = normalizePath(destination).replace(/\/+$/, "");
|
|
15593
15593
|
return normalizedDest.startsWith(normalizedSource + "/");
|
|
15594
15594
|
}
|
|
15595
|
-
function toFileUri(
|
|
15596
|
-
const normalized = normalizePath(
|
|
15595
|
+
function toFileUri(path21) {
|
|
15596
|
+
const normalized = normalizePath(path21);
|
|
15597
15597
|
const windowsDrivePath = normalized.match(/^([A-Za-z]):[\\/](.*)$/);
|
|
15598
15598
|
if (windowsDrivePath) {
|
|
15599
15599
|
const drive = windowsDrivePath[1].toLowerCase();
|
|
@@ -15647,13 +15647,13 @@ function createMigrationReadGuard(limits, signal, sqliteDriver) {
|
|
|
15647
15647
|
sqliteDriver
|
|
15648
15648
|
};
|
|
15649
15649
|
}
|
|
15650
|
-
function physicalPathIdentity(label,
|
|
15651
|
-
const normalized = normalizedPathKey(
|
|
15652
|
-
if (!existsSync9(
|
|
15650
|
+
function physicalPathIdentity(label, path21) {
|
|
15651
|
+
const normalized = normalizedPathKey(path21);
|
|
15652
|
+
if (!existsSync9(path21))
|
|
15653
15653
|
return `${label}:${normalized}|missing`;
|
|
15654
15654
|
try {
|
|
15655
|
-
const
|
|
15656
|
-
return `${label}:${normalized}|dev:${String(
|
|
15655
|
+
const stat13 = statSync6(path21);
|
|
15656
|
+
return `${label}:${normalized}|dev:${String(stat13.dev)}|ino:${String(stat13.ino)}`;
|
|
15657
15657
|
} catch {
|
|
15658
15658
|
return `${label}:${normalized}|unavailable`;
|
|
15659
15659
|
}
|
|
@@ -15801,13 +15801,13 @@ async function findMigrationWorkspaceByPath(requested, dataPath2, guard) {
|
|
|
15801
15801
|
const databasePath = join12(workspaceDirectory, "state.vscdb");
|
|
15802
15802
|
if (!existsSync9(databasePath))
|
|
15803
15803
|
continue;
|
|
15804
|
-
const
|
|
15805
|
-
if (!
|
|
15804
|
+
const path21 = readWorkspaceJson(workspaceDirectory);
|
|
15805
|
+
if (!path21 || !pathsEqual(path21, normalizedRequest))
|
|
15806
15806
|
continue;
|
|
15807
15807
|
return {
|
|
15808
15808
|
workspace: {
|
|
15809
15809
|
id: entry.name,
|
|
15810
|
-
path: normalizePath(
|
|
15810
|
+
path: normalizePath(path21),
|
|
15811
15811
|
dbPath: databasePath,
|
|
15812
15812
|
sessionCount: 0
|
|
15813
15813
|
},
|
|
@@ -15825,7 +15825,7 @@ function loadWorkspaceComposerAddressInventory(db, budget, signal) {
|
|
|
15825
15825
|
if (rootType !== "array" && rootType !== "object") {
|
|
15826
15826
|
throw new TypeError("Composer workspace catalog is not a JSON array or object.");
|
|
15827
15827
|
}
|
|
15828
|
-
const scanIds = (
|
|
15828
|
+
const scanIds = (path21, objectIds) => {
|
|
15829
15829
|
const scanBudget = new SqliteSourceReadBudget(budget.limits, budget.outcome);
|
|
15830
15830
|
const results = [];
|
|
15831
15831
|
const pageRows = scanBudget.limits.sqlitePageRows;
|
|
@@ -15836,7 +15836,7 @@ function loadWorkspaceComposerAddressInventory(db, budget, signal) {
|
|
|
15836
15836
|
throwIfMigrationAborted(signal);
|
|
15837
15837
|
const rows = db.prepare(`SELECT CAST(j.key AS INTEGER) AS itemIndex,
|
|
15838
15838
|
length(CAST(${valueExpression} AS BLOB)) AS byteLength
|
|
15839
|
-
FROM ItemTable AS i, json_each(i.value, '${
|
|
15839
|
+
FROM ItemTable AS i, json_each(i.value, '${path21}') AS j
|
|
15840
15840
|
WHERE i.rowid = ?
|
|
15841
15841
|
AND ${typePredicate}
|
|
15842
15842
|
AND CAST(j.key AS INTEGER) > ?
|
|
@@ -15855,7 +15855,7 @@ function loadWorkspaceComposerAddressInventory(db, budget, signal) {
|
|
|
15855
15855
|
for (const item of metadata) {
|
|
15856
15856
|
throwIfMigrationAborted(signal);
|
|
15857
15857
|
const projected = db.prepare(`SELECT ${valueExpression} AS sessionId
|
|
15858
|
-
FROM ItemTable AS i, json_each(i.value, '${
|
|
15858
|
+
FROM ItemTable AS i, json_each(i.value, '${path21}') AS j
|
|
15859
15859
|
WHERE i.rowid = ? AND CAST(j.key AS INTEGER) = ?`).get(source.rowId, item.itemIndex);
|
|
15860
15860
|
if (typeof projected?.sessionId !== "string") {
|
|
15861
15861
|
throw new Error("Composer ID projection changed after metadata admission.");
|
|
@@ -19808,6 +19808,7 @@ var PHASES = [
|
|
|
19808
19808
|
var PHASE_RULES_V1 = "phase-rules/v1";
|
|
19809
19809
|
var UNKNOWN_GATE = 0.2;
|
|
19810
19810
|
var HANDOFF_MARKERS = {
|
|
19811
|
+
antigravity: ["ask_question"],
|
|
19811
19812
|
"claude-code": [
|
|
19812
19813
|
"AskUserQuestion",
|
|
19813
19814
|
"ExitPlanMode",
|
|
@@ -19851,7 +19852,14 @@ var SCOUT_TOOLS = [
|
|
|
19851
19852
|
"search_tool",
|
|
19852
19853
|
"search_files",
|
|
19853
19854
|
"list_dir",
|
|
19854
|
-
"read_file"
|
|
19855
|
+
"read_file",
|
|
19856
|
+
// Antigravity's read and search tools
|
|
19857
|
+
"view_file",
|
|
19858
|
+
"view_code_item",
|
|
19859
|
+
"grep_search",
|
|
19860
|
+
"find_by_name",
|
|
19861
|
+
"search_web",
|
|
19862
|
+
"read_url_content"
|
|
19855
19863
|
];
|
|
19856
19864
|
var EDIT_TOOLS = [
|
|
19857
19865
|
"Edit",
|
|
@@ -19864,7 +19872,8 @@ var EDIT_TOOLS = [
|
|
|
19864
19872
|
"multiedit",
|
|
19865
19873
|
"apply_patch",
|
|
19866
19874
|
"write_file",
|
|
19867
|
-
"edit_file"
|
|
19875
|
+
"edit_file",
|
|
19876
|
+
"replace_file_content"
|
|
19868
19877
|
];
|
|
19869
19878
|
var REVIEW_SKILLS = ["code-review", "security-review", "review"];
|
|
19870
19879
|
var SCOUT_AGENTS = ["Explore", "Plan", "research"];
|
|
@@ -19874,7 +19883,8 @@ var SHELL_TOOLS = [
|
|
|
19874
19883
|
"shell",
|
|
19875
19884
|
"local_shell",
|
|
19876
19885
|
"exec_command",
|
|
19877
|
-
"run_terminal_command"
|
|
19886
|
+
"run_terminal_command",
|
|
19887
|
+
"run_command"
|
|
19878
19888
|
];
|
|
19879
19889
|
var SKILL_TOOLS = ["Skill", "skill"];
|
|
19880
19890
|
var AGENT_TOOLS = ["Agent", "Task", "task", "agent"];
|
|
@@ -19888,7 +19898,12 @@ var BOOKKEEPING_TOOLS = [
|
|
|
19888
19898
|
"Monitor",
|
|
19889
19899
|
"SendUserFile",
|
|
19890
19900
|
"SendMessage",
|
|
19891
|
-
"ListAgents"
|
|
19901
|
+
"ListAgents",
|
|
19902
|
+
// Antigravity's task list and swarm coordination
|
|
19903
|
+
"manage_task",
|
|
19904
|
+
"read_board",
|
|
19905
|
+
"post_message",
|
|
19906
|
+
"swarm_wait"
|
|
19892
19907
|
];
|
|
19893
19908
|
function isShell(tool) {
|
|
19894
19909
|
return SHELL_TOOLS.includes(tool);
|
|
@@ -20341,13 +20356,13 @@ var KNOWN_ROW_IDS = /* @__PURE__ */ new Set([
|
|
|
20341
20356
|
]);
|
|
20342
20357
|
|
|
20343
20358
|
// src/version.ts
|
|
20344
|
-
var CLI_VERSION = true ? "0.
|
|
20359
|
+
var CLI_VERSION = true ? "0.22.0" : "0.0.0-dev";
|
|
20345
20360
|
|
|
20346
20361
|
// src/api.ts
|
|
20347
20362
|
var BASE_URL = process.env.AISTACK_URL || "https://aistack.to";
|
|
20348
20363
|
var STARTUP_READ_TIMEOUT_MS = 5e3;
|
|
20349
|
-
async function request(
|
|
20350
|
-
return fetch(`${BASE_URL}${
|
|
20364
|
+
async function request(path21, options = {}) {
|
|
20365
|
+
return fetch(`${BASE_URL}${path21}`, {
|
|
20351
20366
|
...options,
|
|
20352
20367
|
headers: {
|
|
20353
20368
|
"Content-Type": "application/json",
|
|
@@ -20879,9 +20894,9 @@ function canonicalizeRepoUrl(input) {
|
|
|
20879
20894
|
function repoNameFromCanonical(canonical) {
|
|
20880
20895
|
return parseRepo(canonical)?.repo ?? "";
|
|
20881
20896
|
}
|
|
20882
|
-
function normalizeUpstreamPath(
|
|
20883
|
-
if (!
|
|
20884
|
-
return
|
|
20897
|
+
function normalizeUpstreamPath(path21) {
|
|
20898
|
+
if (!path21) return "";
|
|
20899
|
+
return path21.split("/").filter(Boolean).join("/");
|
|
20885
20900
|
}
|
|
20886
20901
|
|
|
20887
20902
|
// src/git.ts
|
|
@@ -20927,16 +20942,16 @@ function buildRepoLinkResource(canonical) {
|
|
|
20927
20942
|
import { existsSync as existsSync2, readFileSync as readFileSync2 } from "node:fs";
|
|
20928
20943
|
import { homedir as homedir2 } from "node:os";
|
|
20929
20944
|
import { join as join2 } from "node:path";
|
|
20930
|
-
function readJson(
|
|
20945
|
+
function readJson(path21) {
|
|
20931
20946
|
try {
|
|
20932
|
-
if (!existsSync2(
|
|
20933
|
-
return JSON.parse(readFileSync2(
|
|
20947
|
+
if (!existsSync2(path21)) return null;
|
|
20948
|
+
return JSON.parse(readFileSync2(path21, "utf-8"));
|
|
20934
20949
|
} catch {
|
|
20935
20950
|
return null;
|
|
20936
20951
|
}
|
|
20937
20952
|
}
|
|
20938
|
-
function hooksFrom(
|
|
20939
|
-
const hooks = readJson(
|
|
20953
|
+
function hooksFrom(path21, source, out, seen) {
|
|
20954
|
+
const hooks = readJson(path21)?.hooks;
|
|
20940
20955
|
if (!hooks || typeof hooks !== "object") return;
|
|
20941
20956
|
for (const [event, config] of Object.entries(hooks)) {
|
|
20942
20957
|
const stableKey = `hooks:${source}:${event}`;
|
|
@@ -21085,16 +21100,16 @@ function buildMcpResource(name, group, pkg) {
|
|
|
21085
21100
|
pkg
|
|
21086
21101
|
};
|
|
21087
21102
|
}
|
|
21088
|
-
function readText(
|
|
21103
|
+
function readText(path21) {
|
|
21089
21104
|
try {
|
|
21090
|
-
if (!existsSync3(
|
|
21091
|
-
return readFileSync3(
|
|
21105
|
+
if (!existsSync3(path21)) return null;
|
|
21106
|
+
return readFileSync3(path21, "utf-8");
|
|
21092
21107
|
} catch {
|
|
21093
21108
|
return null;
|
|
21094
21109
|
}
|
|
21095
21110
|
}
|
|
21096
|
-
function readParsed(
|
|
21097
|
-
const raw = readText(
|
|
21111
|
+
function readParsed(path21, parse2) {
|
|
21112
|
+
const raw = readText(path21);
|
|
21098
21113
|
if (raw === null) return null;
|
|
21099
21114
|
try {
|
|
21100
21115
|
return parse2(raw);
|
|
@@ -21102,14 +21117,14 @@ function readParsed(path19, parse2) {
|
|
|
21102
21117
|
return null;
|
|
21103
21118
|
}
|
|
21104
21119
|
}
|
|
21105
|
-
function readJson2(
|
|
21106
|
-
return readParsed(
|
|
21120
|
+
function readJson2(path21) {
|
|
21121
|
+
return readParsed(path21, JSON.parse);
|
|
21107
21122
|
}
|
|
21108
|
-
function readYaml(
|
|
21109
|
-
return readParsed(
|
|
21123
|
+
function readYaml(path21) {
|
|
21124
|
+
return readParsed(path21, parseYaml);
|
|
21110
21125
|
}
|
|
21111
|
-
function readToml(
|
|
21112
|
-
return readParsed(
|
|
21126
|
+
function readToml(path21) {
|
|
21127
|
+
return readParsed(path21, parseToml);
|
|
21113
21128
|
}
|
|
21114
21129
|
function continueListToMap(file) {
|
|
21115
21130
|
if (!file?.mcpServers?.length) return void 0;
|
|
@@ -21248,8 +21263,8 @@ function resolveSource(entry, mpRepoUrl) {
|
|
|
21248
21263
|
const src = entry.source;
|
|
21249
21264
|
if (typeof src === "string") {
|
|
21250
21265
|
if (!mpRepoUrl) return null;
|
|
21251
|
-
const
|
|
21252
|
-
return { url: mpRepoUrl, path:
|
|
21266
|
+
const path21 = src.replace(/^\.\//, "").replace(/\/+$/, "");
|
|
21267
|
+
return { url: mpRepoUrl, path: path21 || void 0 };
|
|
21253
21268
|
}
|
|
21254
21269
|
if (src && typeof src === "object" && src.url) {
|
|
21255
21270
|
return { url: src.url, path: src.path, sha: src.sha };
|
|
@@ -21286,10 +21301,10 @@ function resolvePluginLinks(installed, marketplaces, manifests) {
|
|
|
21286
21301
|
}
|
|
21287
21302
|
return out;
|
|
21288
21303
|
}
|
|
21289
|
-
function readJson3(
|
|
21304
|
+
function readJson3(path21) {
|
|
21290
21305
|
try {
|
|
21291
|
-
if (!existsSync4(
|
|
21292
|
-
return JSON.parse(readFileSync4(
|
|
21306
|
+
if (!existsSync4(path21)) return null;
|
|
21307
|
+
return JSON.parse(readFileSync4(path21, "utf-8"));
|
|
21293
21308
|
} catch {
|
|
21294
21309
|
return null;
|
|
21295
21310
|
}
|
|
@@ -21378,8 +21393,8 @@ function loadGitignore(cwd) {
|
|
|
21378
21393
|
}
|
|
21379
21394
|
function readFileSafe(filePath) {
|
|
21380
21395
|
try {
|
|
21381
|
-
const
|
|
21382
|
-
if (
|
|
21396
|
+
const stat13 = statSync(filePath);
|
|
21397
|
+
if (stat13.size > MAX_FILE_SIZE) return null;
|
|
21383
21398
|
return readFileSync5(filePath, "utf-8");
|
|
21384
21399
|
} catch {
|
|
21385
21400
|
return null;
|
|
@@ -21923,9 +21938,9 @@ function diffResources(current, existing) {
|
|
|
21923
21938
|
// src/commands/connect.ts
|
|
21924
21939
|
import { spawnSync } from "node:child_process";
|
|
21925
21940
|
import { cpSync, existsSync as existsSync11 } from "node:fs";
|
|
21926
|
-
import { homedir as
|
|
21941
|
+
import { homedir as homedir20 } from "node:os";
|
|
21927
21942
|
import { dirname as dirname5, join as join13 } from "node:path";
|
|
21928
|
-
import { fileURLToPath } from "node:url";
|
|
21943
|
+
import { fileURLToPath as fileURLToPath2 } from "node:url";
|
|
21929
21944
|
import * as p3 from "@clack/prompts";
|
|
21930
21945
|
|
|
21931
21946
|
// src/trace.ts
|
|
@@ -22062,6 +22077,9 @@ function traceEnvironment(facts) {
|
|
|
22062
22077
|
);
|
|
22063
22078
|
}
|
|
22064
22079
|
|
|
22080
|
+
// src/harness/antigravity/analyzer.ts
|
|
22081
|
+
import { fileURLToPath } from "node:url";
|
|
22082
|
+
|
|
22065
22083
|
// src/harness/shared/aggregate.ts
|
|
22066
22084
|
var asObj = (v) => typeof v === "object" && v !== null && !Array.isArray(v) ? v : null;
|
|
22067
22085
|
var asStr = (v) => typeof v === "string" && v.length > 0 ? v : null;
|
|
@@ -22679,41 +22697,6 @@ function filterAtoms(atoms, sets) {
|
|
|
22679
22697
|
return { allowed, keptPrivate, withheld: keptPrivate.length };
|
|
22680
22698
|
}
|
|
22681
22699
|
|
|
22682
|
-
// src/harness/shared/recency.ts
|
|
22683
|
-
import { readdir, stat } from "node:fs/promises";
|
|
22684
|
-
import path from "node:path";
|
|
22685
|
-
async function hasRecentFile(roots, matches, sinceMs, opts = {}) {
|
|
22686
|
-
const readDir = opts.readdirImpl ?? ((dir) => readdir(dir, { withFileTypes: true }));
|
|
22687
|
-
const statFile = opts.statImpl ?? stat;
|
|
22688
|
-
const seen = /* @__PURE__ */ new Set();
|
|
22689
|
-
const pending = [...roots];
|
|
22690
|
-
while (pending.length > 0) {
|
|
22691
|
-
const dir = pending.pop();
|
|
22692
|
-
if (seen.has(dir)) continue;
|
|
22693
|
-
seen.add(dir);
|
|
22694
|
-
let entries;
|
|
22695
|
-
try {
|
|
22696
|
-
entries = await readDir(dir);
|
|
22697
|
-
} catch {
|
|
22698
|
-
continue;
|
|
22699
|
-
}
|
|
22700
|
-
for (const e of entries) {
|
|
22701
|
-
const full = path.join(dir, e.name);
|
|
22702
|
-
if (e.isDirectory()) {
|
|
22703
|
-
pending.push(full);
|
|
22704
|
-
continue;
|
|
22705
|
-
}
|
|
22706
|
-
if (!e.isFile() || !matches(e.name)) continue;
|
|
22707
|
-
try {
|
|
22708
|
-
const st = await statFile(full);
|
|
22709
|
-
if (st.mtimeMs >= sinceMs) return true;
|
|
22710
|
-
} catch {
|
|
22711
|
-
}
|
|
22712
|
-
}
|
|
22713
|
-
}
|
|
22714
|
-
return false;
|
|
22715
|
-
}
|
|
22716
|
-
|
|
22717
22700
|
// src/harness/shared/window.ts
|
|
22718
22701
|
var DEFAULT_WINDOW_DAYS = 30;
|
|
22719
22702
|
function windowStartMs(now, days) {
|
|
@@ -23251,7 +23234,9 @@ function createHarnessWorkflowReducer(harness, localSources = createWorkflowLoca
|
|
|
23251
23234
|
const cells = eventCells.get(date) ?? /* @__PURE__ */ new Map();
|
|
23252
23235
|
bump2(cells, `${at.getUTCDay()}:${at.getUTCHours()}`);
|
|
23253
23236
|
eventCells.set(date, cells);
|
|
23254
|
-
if (["WebSearch", "web_search", "websearch"].includes(
|
|
23237
|
+
if (["WebSearch", "web_search", "websearch", "search_web"].includes(
|
|
23238
|
+
observation.tool
|
|
23239
|
+
))
|
|
23255
23240
|
bump2(webSearchesByDate, date);
|
|
23256
23241
|
} else if (observation.type === "response") {
|
|
23257
23242
|
const responseId = observation.responseId ?? `anonymous:${state.nextAnonymousResponse++}`;
|
|
@@ -23594,7 +23579,7 @@ function createHarnessWorkflowReducer(harness, localSources = createWorkflowLoca
|
|
|
23594
23579
|
0
|
|
23595
23580
|
);
|
|
23596
23581
|
const unknown = attributed === 0 ? 0 : windowPhaseSec.unknown / attributed;
|
|
23597
|
-
const routesModels = harness === "claude-code" || harness === "opencode" || harness === "grok-build" || harness === "cursor";
|
|
23582
|
+
const routesModels = harness === "claude-code" || harness === "opencode" || harness === "grok-build" || harness === "cursor" || harness === "antigravity";
|
|
23598
23583
|
const asRows = (map) => {
|
|
23599
23584
|
const safe = /* @__PURE__ */ new Map();
|
|
23600
23585
|
for (const [model, tokens] of map) {
|
|
@@ -23740,162 +23725,920 @@ function createHarnessWorkflowReducer(harness, localSources = createWorkflowLoca
|
|
|
23740
23725
|
};
|
|
23741
23726
|
}
|
|
23742
23727
|
|
|
23743
|
-
// src/harness/
|
|
23728
|
+
// src/harness/antigravity/wire.ts
|
|
23729
|
+
var WireError = class extends Error {
|
|
23730
|
+
code = "wire-malformed";
|
|
23731
|
+
};
|
|
23732
|
+
function readVarint(buf, at) {
|
|
23733
|
+
let value = 0;
|
|
23734
|
+
let scale = 1;
|
|
23735
|
+
for (let i = 0; i < 10; i++) {
|
|
23736
|
+
if (at + i >= buf.length) throw new WireError("truncated varint");
|
|
23737
|
+
const byte = buf[at + i];
|
|
23738
|
+
value += (byte & 127) * scale;
|
|
23739
|
+
scale *= 128;
|
|
23740
|
+
if (byte < 128) return [value, at + i + 1];
|
|
23741
|
+
}
|
|
23742
|
+
throw new WireError("varint too long");
|
|
23743
|
+
}
|
|
23744
|
+
function decodeMessage(buf) {
|
|
23745
|
+
const fields = /* @__PURE__ */ new Map();
|
|
23746
|
+
let at = 0;
|
|
23747
|
+
while (at < buf.length) {
|
|
23748
|
+
const [key2, next] = readVarint(buf, at);
|
|
23749
|
+
at = next;
|
|
23750
|
+
const field = Math.floor(key2 / 8);
|
|
23751
|
+
const wireType = key2 % 8;
|
|
23752
|
+
if (field === 0) throw new WireError("field number 0");
|
|
23753
|
+
let value = null;
|
|
23754
|
+
if (wireType === 0) {
|
|
23755
|
+
[value, at] = readVarint(buf, at);
|
|
23756
|
+
} else if (wireType === 2) {
|
|
23757
|
+
const [length, start] = readVarint(buf, at);
|
|
23758
|
+
if (start + length > buf.length) throw new WireError("truncated bytes");
|
|
23759
|
+
value = buf.subarray(start, start + length);
|
|
23760
|
+
at = start + length;
|
|
23761
|
+
} else if (wireType === 1 || wireType === 5) {
|
|
23762
|
+
const width = wireType === 1 ? 8 : 4;
|
|
23763
|
+
if (at + width > buf.length) throw new WireError("truncated fixed");
|
|
23764
|
+
at += width;
|
|
23765
|
+
} else {
|
|
23766
|
+
throw new WireError(`unsupported wire type ${wireType}`);
|
|
23767
|
+
}
|
|
23768
|
+
if (value === null) continue;
|
|
23769
|
+
const list = fields.get(field);
|
|
23770
|
+
if (list) list.push(value);
|
|
23771
|
+
else fields.set(field, [value]);
|
|
23772
|
+
}
|
|
23773
|
+
return fields;
|
|
23774
|
+
}
|
|
23775
|
+
function firstUint(fields, field) {
|
|
23776
|
+
const value = fields.get(field)?.find((v) => typeof v === "number");
|
|
23777
|
+
return typeof value === "number" ? value : null;
|
|
23778
|
+
}
|
|
23779
|
+
function firstBytes(fields, field) {
|
|
23780
|
+
const value = fields.get(field)?.find((v) => v instanceof Uint8Array);
|
|
23781
|
+
return value instanceof Uint8Array ? value : null;
|
|
23782
|
+
}
|
|
23783
|
+
var utf8 = new TextDecoder("utf-8", { fatal: false });
|
|
23784
|
+
function firstString(fields, field) {
|
|
23785
|
+
const bytes = firstBytes(fields, field);
|
|
23786
|
+
if (!bytes || bytes.length === 0) return null;
|
|
23787
|
+
return utf8.decode(bytes);
|
|
23788
|
+
}
|
|
23789
|
+
function firstMessage(fields, field) {
|
|
23790
|
+
const bytes = firstBytes(fields, field);
|
|
23791
|
+
return bytes ? decodeMessage(bytes) : null;
|
|
23792
|
+
}
|
|
23793
|
+
function timestampMs(buf) {
|
|
23794
|
+
if (buf === null) return null;
|
|
23795
|
+
const fields = buf instanceof Map ? buf : decodeMessage(buf);
|
|
23796
|
+
const seconds2 = firstUint(fields, 1);
|
|
23797
|
+
if (seconds2 === null || seconds2 === 0) return null;
|
|
23798
|
+
const nanos = firstUint(fields, 2) ?? 0;
|
|
23799
|
+
return seconds2 * 1e3 + Math.floor(nanos / 1e6);
|
|
23800
|
+
}
|
|
23801
|
+
|
|
23802
|
+
// src/harness/antigravity/analyzer.ts
|
|
23803
|
+
var ANTIGRAVITY_BUILTIN_TOOLS = /* @__PURE__ */ new Set([
|
|
23804
|
+
"ask_question",
|
|
23805
|
+
"browser_subagent",
|
|
23806
|
+
"command_status",
|
|
23807
|
+
"edit_file",
|
|
23808
|
+
"find_by_name",
|
|
23809
|
+
"generate_image",
|
|
23810
|
+
"grep_search",
|
|
23811
|
+
"list_dir",
|
|
23812
|
+
"list_permissions",
|
|
23813
|
+
"manage_task",
|
|
23814
|
+
"notify_user",
|
|
23815
|
+
"post_message",
|
|
23816
|
+
"read_board",
|
|
23817
|
+
"read_file",
|
|
23818
|
+
"read_url_content",
|
|
23819
|
+
"replace_file_content",
|
|
23820
|
+
"run_command",
|
|
23821
|
+
"schedule",
|
|
23822
|
+
"search_web",
|
|
23823
|
+
"send_command_input",
|
|
23824
|
+
"swarm",
|
|
23825
|
+
"swarm_wait",
|
|
23826
|
+
"task_boundary",
|
|
23827
|
+
"view_code_item",
|
|
23828
|
+
"view_file",
|
|
23829
|
+
"write_file"
|
|
23830
|
+
]);
|
|
23831
|
+
var STEP_USER_INPUT = 14;
|
|
23832
|
+
var STEP_CHECKPOINT = 23;
|
|
23833
|
+
var GOOGLE_API_PROVIDERS = /* @__PURE__ */ new Set([
|
|
23834
|
+
3,
|
|
23835
|
+
// API_PROVIDER_GOOGLE_VERTEX
|
|
23836
|
+
24,
|
|
23837
|
+
// API_PROVIDER_GOOGLE_GEMINI
|
|
23838
|
+
26,
|
|
23839
|
+
// API_PROVIDER_ANTHROPIC_VERTEX
|
|
23840
|
+
30,
|
|
23841
|
+
// API_PROVIDER_GOOGLE_EVERGREEN
|
|
23842
|
+
31,
|
|
23843
|
+
// API_PROVIDER_OPENAI_VERTEX
|
|
23844
|
+
32
|
|
23845
|
+
// API_PROVIDER_OPENAI_RESPONSES_VERTEX
|
|
23846
|
+
]);
|
|
23744
23847
|
function createAggregate2() {
|
|
23745
23848
|
const workflowLocal = createWorkflowLocalSources();
|
|
23746
23849
|
return Object.assign(createAggregate(), {
|
|
23747
|
-
|
|
23748
|
-
|
|
23749
|
-
workflowLocal,
|
|
23750
|
-
workflowSeenCalls: /* @__PURE__ */ new Set(),
|
|
23751
|
-
workflowSeenTurns: /* @__PURE__ */ new Set(),
|
|
23752
|
-
contextFirstCall: /* @__PURE__ */ new Map(),
|
|
23753
|
-
workflowToolNames: /* @__PURE__ */ new Map(),
|
|
23754
|
-
typedCommands: /* @__PURE__ */ new Map()
|
|
23850
|
+
workflow: createHarnessWorkflowReducer("antigravity", workflowLocal),
|
|
23851
|
+
workflowLocal
|
|
23755
23852
|
});
|
|
23756
23853
|
}
|
|
23757
|
-
|
|
23758
|
-
|
|
23759
|
-
if (
|
|
23760
|
-
if (
|
|
23761
|
-
return
|
|
23762
|
-
}
|
|
23763
|
-
function
|
|
23764
|
-
|
|
23765
|
-
const
|
|
23766
|
-
if (!
|
|
23767
|
-
|
|
23768
|
-
|
|
23769
|
-
|
|
23770
|
-
|
|
23771
|
-
if (!rec || !isApiCall(rec)) return;
|
|
23772
|
-
const session = workflowSessionKey(rec);
|
|
23773
|
-
if (session && !agg.contextFirstCall.has(session)) {
|
|
23774
|
-
agg.contextFirstCall.set(session, null);
|
|
23854
|
+
var asBytes = (v) => v instanceof Uint8Array && v.length > 0 ? v : null;
|
|
23855
|
+
var asInt = (v) => {
|
|
23856
|
+
if (typeof v === "number" && Number.isInteger(v)) return v;
|
|
23857
|
+
if (typeof v === "bigint") return Number(v);
|
|
23858
|
+
return null;
|
|
23859
|
+
};
|
|
23860
|
+
function workspaceOf(trajectory) {
|
|
23861
|
+
const workspace = firstMessage(trajectory, 1);
|
|
23862
|
+
const uri = (workspace && firstString(workspace, 1)) ?? firstString(trajectory, 7);
|
|
23863
|
+
if (!uri?.startsWith("file:")) return null;
|
|
23864
|
+
try {
|
|
23865
|
+
return fileURLToPath(uri);
|
|
23866
|
+
} catch {
|
|
23867
|
+
return null;
|
|
23775
23868
|
}
|
|
23776
23869
|
}
|
|
23777
|
-
function
|
|
23778
|
-
|
|
23779
|
-
|
|
23780
|
-
|
|
23781
|
-
|
|
23782
|
-
|
|
23783
|
-
|
|
23784
|
-
|
|
23785
|
-
if (uuid) {
|
|
23786
|
-
if (agg.recordUuids.has(uuid)) return;
|
|
23787
|
-
agg.recordUuids.add(uuid);
|
|
23870
|
+
function commandOf(argumentsJson) {
|
|
23871
|
+
if (!argumentsJson) return "";
|
|
23872
|
+
try {
|
|
23873
|
+
const args = JSON.parse(argumentsJson);
|
|
23874
|
+
const command = args?.CommandLine;
|
|
23875
|
+
return typeof command === "string" ? command : "";
|
|
23876
|
+
} catch {
|
|
23877
|
+
return "";
|
|
23788
23878
|
}
|
|
23789
|
-
|
|
23790
|
-
|
|
23791
|
-
|
|
23792
|
-
|
|
23793
|
-
|
|
23794
|
-
|
|
23795
|
-
|
|
23796
|
-
|
|
23797
|
-
|
|
23798
|
-
|
|
23799
|
-
|
|
23800
|
-
|
|
23801
|
-
|
|
23802
|
-
|
|
23803
|
-
agg.lastTs = agg.lastTs === null ? ts : Math.max(agg.lastTs, ts);
|
|
23879
|
+
}
|
|
23880
|
+
function decodeConversation(raw) {
|
|
23881
|
+
let parseErrors = 0;
|
|
23882
|
+
const cascadeId = typeof raw.cascadeId === "string" && raw.cascadeId ? raw.cascadeId : null;
|
|
23883
|
+
let parentId = null;
|
|
23884
|
+
let workspace = null;
|
|
23885
|
+
const trajectoryBytes = asBytes(raw.trajectory);
|
|
23886
|
+
if (trajectoryBytes) {
|
|
23887
|
+
try {
|
|
23888
|
+
const trajectory = decodeMessage(trajectoryBytes);
|
|
23889
|
+
parentId = firstString(trajectory, 5);
|
|
23890
|
+
workspace = workspaceOf(trajectory);
|
|
23891
|
+
} catch {
|
|
23892
|
+
parseErrors++;
|
|
23804
23893
|
}
|
|
23805
23894
|
}
|
|
23806
|
-
|
|
23807
|
-
|
|
23808
|
-
|
|
23895
|
+
const gens = /* @__PURE__ */ new Map();
|
|
23896
|
+
const modelNames = /* @__PURE__ */ new Map();
|
|
23897
|
+
for (const row of raw.gens) {
|
|
23898
|
+
const idx = asInt(row.idx);
|
|
23899
|
+
const data = asBytes(row.data);
|
|
23900
|
+
if (idx === null || data === null) continue;
|
|
23901
|
+
try {
|
|
23902
|
+
const chat = firstMessage(decodeMessage(data), 1);
|
|
23903
|
+
if (!chat) continue;
|
|
23904
|
+
const modelEnum = firstUint(chat, 3);
|
|
23905
|
+
const name = firstString(chat, 19);
|
|
23906
|
+
gens.set(idx, { modelEnum, name });
|
|
23907
|
+
if (modelEnum !== null && name) modelNames.set(modelEnum, name);
|
|
23908
|
+
} catch {
|
|
23909
|
+
parseErrors++;
|
|
23910
|
+
}
|
|
23809
23911
|
}
|
|
23810
|
-
|
|
23811
|
-
const
|
|
23812
|
-
|
|
23813
|
-
|
|
23814
|
-
|
|
23815
|
-
|
|
23816
|
-
|
|
23817
|
-
|
|
23818
|
-
|
|
23819
|
-
|
|
23820
|
-
|
|
23912
|
+
const id = cascadeId ?? "";
|
|
23913
|
+
const responses = [];
|
|
23914
|
+
const tools = [];
|
|
23915
|
+
const userTurns = [];
|
|
23916
|
+
for (const row of raw.steps) {
|
|
23917
|
+
const idx = asInt(row.idx);
|
|
23918
|
+
const metadata = asBytes(row.metadata);
|
|
23919
|
+
if (idx === null || metadata === null) continue;
|
|
23920
|
+
let step;
|
|
23921
|
+
try {
|
|
23922
|
+
step = decodeMessage(metadata);
|
|
23923
|
+
} catch {
|
|
23924
|
+
parseErrors++;
|
|
23925
|
+
continue;
|
|
23926
|
+
}
|
|
23927
|
+
try {
|
|
23928
|
+
const tsMs = timestampMs(firstMessage(step, 1));
|
|
23929
|
+
if (tsMs === null) continue;
|
|
23930
|
+
const key2 = `${id}:${idx}`;
|
|
23931
|
+
const stepType = asInt(row.stepType);
|
|
23932
|
+
if (stepType === STEP_USER_INPUT) userTurns.push({ key: key2, tsMs });
|
|
23933
|
+
const usageBytes = firstBytes(step, 9);
|
|
23934
|
+
if (usageBytes) {
|
|
23935
|
+
const usage = decodeMessage(usageBytes);
|
|
23936
|
+
const modelEnum = firstUint(usage, 1);
|
|
23937
|
+
const info = firstMessage(step, 20);
|
|
23938
|
+
const gen = gens.get((info && firstUint(info, 3)) ?? 0);
|
|
23939
|
+
responses.push({
|
|
23940
|
+
key: key2,
|
|
23941
|
+
tsMs,
|
|
23942
|
+
finishedMs: timestampMs(firstMessage(step, 7)) ?? timestampMs(firstMessage(step, 8)),
|
|
23943
|
+
modelEnum,
|
|
23944
|
+
modelName: gen?.name && gen.modelEnum === modelEnum ? gen.name : null,
|
|
23945
|
+
apiProvider: firstUint(usage, 6),
|
|
23946
|
+
input: firstUint(usage, 2) ?? 0,
|
|
23947
|
+
output: firstUint(usage, 3) ?? 0,
|
|
23948
|
+
cacheWrite: firstUint(usage, 4) ?? 0,
|
|
23949
|
+
cacheRead: firstUint(usage, 5) ?? 0,
|
|
23950
|
+
thinking: firstUint(usage, 9),
|
|
23951
|
+
checkpoint: stepType === STEP_CHECKPOINT
|
|
23952
|
+
});
|
|
23953
|
+
}
|
|
23954
|
+
const toolCall2 = firstMessage(step, 4);
|
|
23955
|
+
const name = toolCall2 && firstString(toolCall2, 2);
|
|
23956
|
+
if (toolCall2 && name) {
|
|
23957
|
+
tools.push({
|
|
23958
|
+
key: key2,
|
|
23959
|
+
tsMs,
|
|
23960
|
+
name: cleanName(name),
|
|
23961
|
+
command: name === "run_command" ? commandOf(firstString(toolCall2, 3)) : ""
|
|
23962
|
+
});
|
|
23963
|
+
}
|
|
23964
|
+
} catch {
|
|
23965
|
+
parseErrors++;
|
|
23966
|
+
}
|
|
23821
23967
|
}
|
|
23968
|
+
return {
|
|
23969
|
+
id,
|
|
23970
|
+
parentId,
|
|
23971
|
+
workspace,
|
|
23972
|
+
responses,
|
|
23973
|
+
tools,
|
|
23974
|
+
userTurns,
|
|
23975
|
+
modelNames,
|
|
23976
|
+
parseErrors
|
|
23977
|
+
};
|
|
23822
23978
|
}
|
|
23823
|
-
function
|
|
23824
|
-
|
|
23825
|
-
|
|
23826
|
-
|
|
23827
|
-
|
|
23828
|
-
|
|
23829
|
-
|
|
23830
|
-
|
|
23831
|
-
|
|
23832
|
-
|
|
23833
|
-
|
|
23834
|
-
|
|
23835
|
-
|
|
23836
|
-
|
|
23837
|
-
|
|
23838
|
-
|
|
23839
|
-
|
|
23840
|
-
|
|
23841
|
-
|
|
23842
|
-
|
|
23843
|
-
if (!session) return;
|
|
23844
|
-
agg.workflow.ingest({
|
|
23845
|
-
type: "response",
|
|
23846
|
-
session,
|
|
23847
|
-
projectWorkspace: projectWorkspaceDirectory(rec) ?? ctx.projectDir,
|
|
23848
|
-
tsMs,
|
|
23849
|
-
...asStr(rec.uuid) ? { responseId: `duration:${asStr(rec.uuid)}` } : {},
|
|
23850
|
-
durationSec: asNum(rec.durationMs) / 1e3
|
|
23851
|
-
});
|
|
23979
|
+
function createFoldState() {
|
|
23980
|
+
return { seen: /* @__PURE__ */ new Set() };
|
|
23981
|
+
}
|
|
23982
|
+
function foldConversations(agg, state, conversations, sinceMs) {
|
|
23983
|
+
const modelNames = /* @__PURE__ */ new Map();
|
|
23984
|
+
for (const c of conversations)
|
|
23985
|
+
for (const [modelEnum, name] of c.modelNames)
|
|
23986
|
+
if (!modelNames.has(modelEnum)) modelNames.set(modelEnum, name);
|
|
23987
|
+
for (const c of conversations)
|
|
23988
|
+
foldConversation(agg, state, c, modelNames, sinceMs);
|
|
23989
|
+
}
|
|
23990
|
+
function modelKeyOf(response, modelNames) {
|
|
23991
|
+
const name = response.modelName ?? (response.modelEnum === null ? null : modelNames.get(response.modelEnum));
|
|
23992
|
+
if (!name) return { key: "(unknown)" };
|
|
23993
|
+
const provider = response.apiProvider !== null && GOOGLE_API_PROVIDERS.has(response.apiProvider) ? "google" : "antigravity";
|
|
23994
|
+
const model = cleanName(name);
|
|
23995
|
+
return {
|
|
23996
|
+
key: normalizeModel(modelKeyFor(provider, model)),
|
|
23997
|
+
workflowModel: `${provider}:${model}`
|
|
23998
|
+
};
|
|
23852
23999
|
}
|
|
23853
|
-
function
|
|
23854
|
-
|
|
23855
|
-
|
|
23856
|
-
const
|
|
23857
|
-
|
|
23858
|
-
const
|
|
23859
|
-
|
|
23860
|
-
|
|
23861
|
-
|
|
23862
|
-
|
|
23863
|
-
const
|
|
23864
|
-
|
|
23865
|
-
|
|
23866
|
-
|
|
23867
|
-
|
|
23868
|
-
|
|
23869
|
-
|
|
23870
|
-
|
|
23871
|
-
|
|
23872
|
-
|
|
23873
|
-
|
|
24000
|
+
function foldConversation(agg, state, c, modelNames, sinceMs) {
|
|
24001
|
+
agg.parseErrors += c.parseErrors;
|
|
24002
|
+
if (!c.id) return;
|
|
24003
|
+
const parentSession = c.parentId ?? void 0;
|
|
24004
|
+
const projectWorkspace = c.workspace ?? void 0;
|
|
24005
|
+
const fresh = (key2, tsMs) => {
|
|
24006
|
+
if (tsMs < sinceMs || state.seen.has(key2)) return false;
|
|
24007
|
+
state.seen.add(key2);
|
|
24008
|
+
return true;
|
|
24009
|
+
};
|
|
24010
|
+
const noteActivity3 = (tsMs) => {
|
|
24011
|
+
agg.sessions.add(c.id);
|
|
24012
|
+
noteSessionStart(agg, c.id, tsMs);
|
|
24013
|
+
agg.activeDays.add(new Date(tsMs).toISOString().slice(0, 10));
|
|
24014
|
+
agg.firstTs = agg.firstTs === null ? tsMs : Math.min(agg.firstTs, tsMs);
|
|
24015
|
+
agg.lastTs = agg.lastTs === null ? tsMs : Math.max(agg.lastTs, tsMs);
|
|
24016
|
+
if (c.workspace) {
|
|
24017
|
+
agg.projectDirs.add(c.workspace);
|
|
24018
|
+
noteProjectDay(agg, c.workspace, tsMs);
|
|
24019
|
+
}
|
|
24020
|
+
};
|
|
24021
|
+
for (const turn of c.userTurns) {
|
|
24022
|
+
if (!fresh(`turn:${turn.key}`, turn.tsMs)) continue;
|
|
24023
|
+
agg.records++;
|
|
24024
|
+
noteActivity3(turn.tsMs);
|
|
24025
|
+
agg.workflow.ingest({
|
|
24026
|
+
type: "turn",
|
|
24027
|
+
session: c.id,
|
|
24028
|
+
turnId: turn.key,
|
|
24029
|
+
projectWorkspace,
|
|
24030
|
+
parentSession,
|
|
24031
|
+
tsMs: turn.tsMs,
|
|
24032
|
+
questionBack: false
|
|
24033
|
+
});
|
|
23874
24034
|
}
|
|
23875
|
-
|
|
23876
|
-
|
|
23877
|
-
|
|
23878
|
-
|
|
23879
|
-
|
|
23880
|
-
|
|
23881
|
-
|
|
23882
|
-
|
|
23883
|
-
|
|
23884
|
-
|
|
23885
|
-
|
|
23886
|
-
|
|
23887
|
-
|
|
23888
|
-
// The TTL this call wrote under (v5): a subscription within plan
|
|
23889
|
-
// usage writes the main conversation at one hour.
|
|
23890
|
-
...counts2.cacheWrite1h > 0 ? { cacheTtlSec: 3600 } : counts2.cacheWrite5m > 0 ? { cacheTtlSec: 300 } : {},
|
|
23891
|
-
...first ? {
|
|
23892
|
-
firstCall: {
|
|
23893
|
-
harnessTokens: counts2.cacheRead,
|
|
23894
|
-
instructionsTokens: contextOf(counts2) - counts2.cacheRead
|
|
23895
|
-
}
|
|
23896
|
-
} : {}
|
|
24035
|
+
for (const r of c.responses) {
|
|
24036
|
+
if (!fresh(r.key, r.tsMs)) continue;
|
|
24037
|
+
agg.records++;
|
|
24038
|
+
agg.assistantRecords++;
|
|
24039
|
+
agg.distinctResponses++;
|
|
24040
|
+
noteActivity3(r.tsMs);
|
|
24041
|
+
const counts2 = {
|
|
24042
|
+
input: r.input,
|
|
24043
|
+
output: r.output,
|
|
24044
|
+
cacheWrite5m: 0,
|
|
24045
|
+
cacheWrite1h: 0,
|
|
24046
|
+
cacheWriteUnsplit: r.cacheWrite,
|
|
24047
|
+
cacheRead: r.cacheRead
|
|
23897
24048
|
};
|
|
23898
|
-
|
|
24049
|
+
const total = r.input + r.output + r.cacheWrite + r.cacheRead;
|
|
24050
|
+
if (parentSession) agg.sidechainTokens += total;
|
|
24051
|
+
else agg.mainTokens += total;
|
|
24052
|
+
const { key: key2, workflowModel } = modelKeyOf(r, modelNames);
|
|
24053
|
+
addModelUsage(agg, key2, counts2, apiEquivalentCost(key2, counts2, r.tsMs), 1, {
|
|
24054
|
+
tsMs: r.tsMs,
|
|
24055
|
+
sidechain: Boolean(parentSession)
|
|
24056
|
+
});
|
|
24057
|
+
agg.workflow.ingest({
|
|
24058
|
+
type: "response",
|
|
24059
|
+
session: c.id,
|
|
24060
|
+
responseId: r.key,
|
|
24061
|
+
projectWorkspace,
|
|
24062
|
+
parentSession,
|
|
24063
|
+
tsMs: r.tsMs,
|
|
24064
|
+
...workflowModel ? { model: workflowModel } : {},
|
|
24065
|
+
...r.thinking !== null ? { thinkingTokens: r.thinking } : {},
|
|
24066
|
+
responseTokens: r.output,
|
|
24067
|
+
routingTokens: total,
|
|
24068
|
+
contextTokens: r.input + r.cacheRead + r.cacheWrite,
|
|
24069
|
+
inputTokens: r.input,
|
|
24070
|
+
cacheReadTokens: r.cacheRead,
|
|
24071
|
+
cacheWriteTokens: r.cacheWrite,
|
|
24072
|
+
...r.finishedMs !== null && r.finishedMs > r.tsMs ? { durationSec: (r.finishedMs - r.tsMs) / 1e3 } : {}
|
|
24073
|
+
});
|
|
24074
|
+
if (r.checkpoint)
|
|
24075
|
+
agg.workflow.ingest({
|
|
24076
|
+
type: "compaction",
|
|
24077
|
+
session: c.id,
|
|
24078
|
+
projectWorkspace,
|
|
24079
|
+
parentSession,
|
|
24080
|
+
tsMs: r.tsMs
|
|
24081
|
+
});
|
|
24082
|
+
}
|
|
24083
|
+
for (const t of c.tools) {
|
|
24084
|
+
if (!fresh(`tool:${t.key}`, t.tsMs)) continue;
|
|
24085
|
+
agg.records++;
|
|
24086
|
+
noteActivity3(t.tsMs);
|
|
24087
|
+
bump(agg.toolCalls, t.name);
|
|
24088
|
+
agg.workflow.ingest({
|
|
24089
|
+
type: "event",
|
|
24090
|
+
session: c.id,
|
|
24091
|
+
projectWorkspace,
|
|
24092
|
+
parentSession,
|
|
24093
|
+
tsMs: t.tsMs,
|
|
24094
|
+
tool: t.name,
|
|
24095
|
+
arg: t.command
|
|
24096
|
+
});
|
|
24097
|
+
if (t.name === "ask_question")
|
|
24098
|
+
agg.workflow.ingest({
|
|
24099
|
+
type: "turn",
|
|
24100
|
+
session: c.id,
|
|
24101
|
+
turnId: `question:${t.key}`,
|
|
24102
|
+
projectWorkspace,
|
|
24103
|
+
parentSession,
|
|
24104
|
+
tsMs: t.tsMs,
|
|
24105
|
+
questionBack: true
|
|
24106
|
+
});
|
|
24107
|
+
}
|
|
24108
|
+
}
|
|
24109
|
+
|
|
24110
|
+
// src/harness/antigravity/scan.ts
|
|
24111
|
+
import { readdir as readdir2, realpath as realpath2, stat as stat2 } from "node:fs/promises";
|
|
24112
|
+
import { homedir as homedir7 } from "node:os";
|
|
24113
|
+
import path2 from "node:path";
|
|
24114
|
+
|
|
24115
|
+
// src/harness/shared/homes.ts
|
|
24116
|
+
import {
|
|
24117
|
+
mkdir,
|
|
24118
|
+
readdir,
|
|
24119
|
+
readFile,
|
|
24120
|
+
realpath,
|
|
24121
|
+
stat,
|
|
24122
|
+
writeFile
|
|
24123
|
+
} from "node:fs/promises";
|
|
24124
|
+
import { homedir as homedir6 } from "node:os";
|
|
24125
|
+
import path from "node:path";
|
|
24126
|
+
async function discoverHomes(options) {
|
|
24127
|
+
let complete = true;
|
|
24128
|
+
const resolve3 = async (dir) => {
|
|
24129
|
+
try {
|
|
24130
|
+
const real = await realpath(dir);
|
|
24131
|
+
return (await stat(real)).isDirectory() ? real : null;
|
|
24132
|
+
} catch (error) {
|
|
24133
|
+
if (!absent(error)) {
|
|
24134
|
+
complete = false;
|
|
24135
|
+
traceError("harness home resolution", error, "warn");
|
|
24136
|
+
}
|
|
24137
|
+
return null;
|
|
24138
|
+
}
|
|
24139
|
+
};
|
|
24140
|
+
const named = [...options.defaults];
|
|
24141
|
+
for (const { parent, prefix } of options.siblings ?? []) {
|
|
24142
|
+
try {
|
|
24143
|
+
named.push(
|
|
24144
|
+
...(await readdir(parent, { withFileTypes: true })).filter(
|
|
24145
|
+
(entry) => entry.name.startsWith(prefix) && (entry.isDirectory() || entry.isSymbolicLink())
|
|
24146
|
+
).map((entry) => path.join(parent, entry.name)).sort()
|
|
24147
|
+
);
|
|
24148
|
+
} catch (error) {
|
|
24149
|
+
if (!absent(error)) {
|
|
24150
|
+
complete = false;
|
|
24151
|
+
traceError("harness home discovery", error, "warn");
|
|
24152
|
+
}
|
|
24153
|
+
}
|
|
24154
|
+
}
|
|
24155
|
+
const homes = [];
|
|
24156
|
+
const add = (real) => {
|
|
24157
|
+
if (real && !homes.includes(real)) homes.push(real);
|
|
24158
|
+
};
|
|
24159
|
+
for (const dir of named) add(await resolve3(dir));
|
|
24160
|
+
const found = new Set(homes);
|
|
24161
|
+
const remembered = options.remember ? await readRemembered(options.remember) : [];
|
|
24162
|
+
const fresh = [];
|
|
24163
|
+
for (const dir of (options.configured ?? []).filter((dir2) => Boolean(dir2?.trim())).map(expandHome)) {
|
|
24164
|
+
const real = await resolve3(dir);
|
|
24165
|
+
add(real);
|
|
24166
|
+
if (real && !found.has(real) && !remembered.includes(real))
|
|
24167
|
+
fresh.push(real);
|
|
24168
|
+
}
|
|
24169
|
+
for (const dir of remembered) add(await resolve3(dir));
|
|
24170
|
+
if (options.remember && fresh.length)
|
|
24171
|
+
await writeRemembered(options.remember, [...remembered, ...fresh]);
|
|
24172
|
+
return { homes, complete };
|
|
24173
|
+
}
|
|
24174
|
+
var rememberedFile = () => path.join(homedir6(), ".config", "aistack", "harness-homes.json");
|
|
24175
|
+
async function rememberedHomes(harness) {
|
|
24176
|
+
return readRemembered(harness);
|
|
24177
|
+
}
|
|
24178
|
+
async function rememberHome(harness, dir) {
|
|
24179
|
+
const list = await readRemembered(harness);
|
|
24180
|
+
if (list.includes(dir)) return false;
|
|
24181
|
+
if (!await writeRemembered(harness, [...list, dir]))
|
|
24182
|
+
throw new Error("Could not save the folder list");
|
|
24183
|
+
return true;
|
|
24184
|
+
}
|
|
24185
|
+
async function forgetHome(harness, dir) {
|
|
24186
|
+
const list = await readRemembered(harness);
|
|
24187
|
+
if (!list.includes(dir)) return false;
|
|
24188
|
+
if (!await writeRemembered(
|
|
24189
|
+
harness,
|
|
24190
|
+
list.filter((entry) => entry !== dir)
|
|
24191
|
+
))
|
|
24192
|
+
throw new Error("Could not save the folder list");
|
|
24193
|
+
return true;
|
|
24194
|
+
}
|
|
24195
|
+
async function readRemembered(harness) {
|
|
24196
|
+
try {
|
|
24197
|
+
const parsed = JSON.parse(await readFile(rememberedFile(), "utf8"));
|
|
24198
|
+
const list = parsed?.[harness];
|
|
24199
|
+
return Array.isArray(list) ? list.filter((dir) => typeof dir === "string") : [];
|
|
24200
|
+
} catch (error) {
|
|
24201
|
+
if (!absent(error)) traceError("remembered harness homes", error, "warn");
|
|
24202
|
+
return [];
|
|
24203
|
+
}
|
|
24204
|
+
}
|
|
24205
|
+
async function writeRemembered(harness, dirs) {
|
|
24206
|
+
const file = rememberedFile();
|
|
24207
|
+
try {
|
|
24208
|
+
let all = {};
|
|
24209
|
+
try {
|
|
24210
|
+
const parsed = JSON.parse(await readFile(file, "utf8"));
|
|
24211
|
+
if (parsed && typeof parsed === "object" && !Array.isArray(parsed))
|
|
24212
|
+
all = parsed;
|
|
24213
|
+
} catch (error) {
|
|
24214
|
+
if (!absent(error)) throw error;
|
|
24215
|
+
}
|
|
24216
|
+
all[harness] = dirs;
|
|
24217
|
+
await mkdir(path.dirname(file), { recursive: true, mode: 448 });
|
|
24218
|
+
await writeFile(file, `${JSON.stringify(all, null, 2)}
|
|
24219
|
+
`, { mode: 384 });
|
|
24220
|
+
return true;
|
|
24221
|
+
} catch (error) {
|
|
24222
|
+
traceError("remembered harness homes", error, "warn");
|
|
24223
|
+
return false;
|
|
24224
|
+
}
|
|
24225
|
+
}
|
|
24226
|
+
function expandHome(dir) {
|
|
24227
|
+
const trimmed = dir.trim();
|
|
24228
|
+
return path.resolve(
|
|
24229
|
+
trimmed.startsWith("~/") ? path.join(homedir6(), trimmed.slice(2)) : trimmed
|
|
24230
|
+
);
|
|
24231
|
+
}
|
|
24232
|
+
function absent(error) {
|
|
24233
|
+
const code2 = error?.code;
|
|
24234
|
+
return code2 === "ENOENT" || code2 === "ENOTDIR";
|
|
24235
|
+
}
|
|
24236
|
+
|
|
24237
|
+
// src/harness/antigravity/scan.ts
|
|
24238
|
+
function geminiDirs() {
|
|
24239
|
+
const base = path2.join(homedir7(), ".gemini");
|
|
24240
|
+
const configured = process.env.ANTIGRAVITY_GEMINI_DIR?.trim();
|
|
24241
|
+
if (!configured) return [base];
|
|
24242
|
+
return [base, path2.resolve(homedir7(), configured)];
|
|
24243
|
+
}
|
|
24244
|
+
async function antigravityHomes() {
|
|
24245
|
+
const dirs = geminiDirs();
|
|
24246
|
+
const appDataDir = process.env.ANTIGRAVITY_APP_DATA_DIR?.trim();
|
|
24247
|
+
return discoverHomes({
|
|
24248
|
+
defaults: [path2.join(dirs[0], "antigravity-cli")],
|
|
24249
|
+
configured: appDataDir ? dirs.map((dir) => path2.resolve(dir, appDataDir)) : [],
|
|
24250
|
+
siblings: dirs.map((parent) => ({ parent, prefix: "antigravity" })),
|
|
24251
|
+
remember: "antigravity"
|
|
24252
|
+
});
|
|
24253
|
+
}
|
|
24254
|
+
async function storeFilesIn(home) {
|
|
24255
|
+
const dir = path2.join(home, "conversations");
|
|
24256
|
+
try {
|
|
24257
|
+
return (await readdir2(dir, { withFileTypes: true })).filter((e) => e.isFile()).flatMap((e) => {
|
|
24258
|
+
if (e.name.endsWith(".db"))
|
|
24259
|
+
return [{ file: path2.join(dir, e.name), kind: "db" }];
|
|
24260
|
+
if (e.name.endsWith(".pb"))
|
|
24261
|
+
return [{ file: path2.join(dir, e.name), kind: "encrypted" }];
|
|
24262
|
+
return [];
|
|
24263
|
+
}).sort((a, b) => a.file.localeCompare(b.file));
|
|
24264
|
+
} catch (error) {
|
|
24265
|
+
const code2 = error?.code;
|
|
24266
|
+
if (code2 !== "ENOENT" && code2 !== "ENOTDIR")
|
|
24267
|
+
traceError("antigravity conversation discovery", error, "warn");
|
|
24268
|
+
return [];
|
|
24269
|
+
}
|
|
24270
|
+
}
|
|
24271
|
+
async function storeFiles(homes) {
|
|
24272
|
+
const out = [];
|
|
24273
|
+
const seen = /* @__PURE__ */ new Set();
|
|
24274
|
+
for (const home of homes) {
|
|
24275
|
+
for (const store of await storeFilesIn(home)) {
|
|
24276
|
+
let key2 = store.file;
|
|
24277
|
+
try {
|
|
24278
|
+
key2 = await realpath2(store.file);
|
|
24279
|
+
} catch {
|
|
24280
|
+
}
|
|
24281
|
+
if (seen.has(key2)) continue;
|
|
24282
|
+
seen.add(key2);
|
|
24283
|
+
out.push(store);
|
|
24284
|
+
}
|
|
24285
|
+
}
|
|
24286
|
+
return out;
|
|
24287
|
+
}
|
|
24288
|
+
async function loadSqlite() {
|
|
24289
|
+
try {
|
|
24290
|
+
const mod = await import("node:sqlite");
|
|
24291
|
+
if (typeof mod.DatabaseSync !== "function") return null;
|
|
24292
|
+
return (file) => new mod.DatabaseSync(file, { readOnly: true });
|
|
24293
|
+
} catch (error) {
|
|
24294
|
+
traceError("antigravity SQLite initialization", error, "warn");
|
|
24295
|
+
return null;
|
|
24296
|
+
}
|
|
24297
|
+
}
|
|
24298
|
+
function errorClass(e) {
|
|
24299
|
+
const code2 = e?.code;
|
|
24300
|
+
if (typeof code2 === "string" && code2.length > 0) return code2;
|
|
24301
|
+
return e instanceof Error ? e.constructor.name : "unknown";
|
|
24302
|
+
}
|
|
24303
|
+
var readError = (reason) => Object.assign(new Error(reason), { code: reason });
|
|
24304
|
+
function closeQuietly(db) {
|
|
24305
|
+
try {
|
|
24306
|
+
db?.close();
|
|
24307
|
+
} catch {
|
|
24308
|
+
}
|
|
24309
|
+
}
|
|
24310
|
+
function readStore(db) {
|
|
24311
|
+
return {
|
|
24312
|
+
cascadeId: db.prepare("select cascade_id from trajectory_meta limit 1").get()?.cascade_id,
|
|
24313
|
+
trajectory: db.prepare(
|
|
24314
|
+
"select data from trajectory_metadata_blob order by id = 'main' desc limit 1"
|
|
24315
|
+
).get()?.data,
|
|
24316
|
+
steps: db.prepare("select idx, step_type, metadata from steps order by idx").all().map((r) => ({
|
|
24317
|
+
idx: r.idx,
|
|
24318
|
+
stepType: r.step_type,
|
|
24319
|
+
metadata: r.metadata
|
|
24320
|
+
})),
|
|
24321
|
+
gens: db.prepare("select idx, data from gen_metadata order by idx").all().map((r) => ({ idx: r.idx, data: r.data }))
|
|
24322
|
+
};
|
|
24323
|
+
}
|
|
24324
|
+
function parseSummaryTime(value) {
|
|
24325
|
+
if (typeof value !== "string") return null;
|
|
24326
|
+
const m = /^(\d{4}-\d{2}-\d{2})[ T](\d{2}:\d{2}:\d{2})(?:\.(\d{1,9}))?(Z|[+-]\d{2}:\d{2})?$/.exec(
|
|
24327
|
+
value.trim()
|
|
24328
|
+
);
|
|
24329
|
+
if (!m) return null;
|
|
24330
|
+
const ms = (m[3] ?? "").padEnd(3, "0").slice(0, 3);
|
|
24331
|
+
const parsed = Date.parse(`${m[1]}T${m[2]}.${ms}${m[4] ?? "Z"}`);
|
|
24332
|
+
return Number.isFinite(parsed) && parsed > Date.UTC(2e3, 0, 1) ? parsed : null;
|
|
24333
|
+
}
|
|
24334
|
+
function readConversationIndex(open4, homes) {
|
|
24335
|
+
const out = /* @__PURE__ */ new Map();
|
|
24336
|
+
for (const home of homes) {
|
|
24337
|
+
let db = null;
|
|
24338
|
+
try {
|
|
24339
|
+
db = open4(path2.join(home, "conversation_summaries.db"));
|
|
24340
|
+
for (const row of db.prepare(
|
|
24341
|
+
"select conversation_id, last_modified_time from conversation_summaries"
|
|
24342
|
+
).all()) {
|
|
24343
|
+
const id = row.conversation_id;
|
|
24344
|
+
const at = parseSummaryTime(row.last_modified_time);
|
|
24345
|
+
if (typeof id !== "string" || at === null) continue;
|
|
24346
|
+
out.set(id, Math.max(out.get(id) ?? at, at));
|
|
24347
|
+
}
|
|
24348
|
+
} catch {
|
|
24349
|
+
} finally {
|
|
24350
|
+
closeQuietly(db);
|
|
24351
|
+
}
|
|
24352
|
+
}
|
|
24353
|
+
return out;
|
|
24354
|
+
}
|
|
24355
|
+
async function scan(agg, opts = {}) {
|
|
24356
|
+
const stats = emptyScanStats();
|
|
24357
|
+
const sinceMs = opts.sinceMs ?? 0;
|
|
24358
|
+
const discovery = opts.roots ? { homes: opts.roots, complete: true } : await antigravityHomes();
|
|
24359
|
+
if (!discovery.complete) stats.sourceDiscoveryComplete = false;
|
|
24360
|
+
const stores = await storeFiles(discovery.homes);
|
|
24361
|
+
const open4 = await loadSqlite();
|
|
24362
|
+
const index = open4 ? readConversationIndex(open4, discovery.homes) : /* @__PURE__ */ new Map();
|
|
24363
|
+
const conversations = [];
|
|
24364
|
+
let done = 0;
|
|
24365
|
+
for (const store of stores) {
|
|
24366
|
+
stats.filesFound++;
|
|
24367
|
+
const name = path2.basename(store.file);
|
|
24368
|
+
try {
|
|
24369
|
+
const indexed = store.kind === "encrypted" ? index.get(path2.basename(store.file, ".pb")) : void 0;
|
|
24370
|
+
const changedMs = indexed ?? (await stat2(store.file)).mtimeMs;
|
|
24371
|
+
if (changedMs < sinceMs) {
|
|
24372
|
+
stats.filesSkippedByMtime++;
|
|
24373
|
+
continue;
|
|
24374
|
+
}
|
|
24375
|
+
if (store.kind === "encrypted") throw readError("encrypted");
|
|
24376
|
+
if (open4 === null) throw readError("sqlite-unsupported");
|
|
24377
|
+
let db = null;
|
|
24378
|
+
try {
|
|
24379
|
+
db = open4(store.file);
|
|
24380
|
+
conversations.push(decodeConversation(readStore(db)));
|
|
24381
|
+
} finally {
|
|
24382
|
+
closeQuietly(db);
|
|
24383
|
+
}
|
|
24384
|
+
agg.files++;
|
|
24385
|
+
stats.filesRead++;
|
|
24386
|
+
} catch (e) {
|
|
24387
|
+
traceError("antigravity conversation read", e, "warn");
|
|
24388
|
+
stats.filesUnreadable++;
|
|
24389
|
+
stats.unreadableFiles.push({ path: name, reason: errorClass(e) });
|
|
24390
|
+
} finally {
|
|
24391
|
+
done++;
|
|
24392
|
+
opts.onProgress?.(done, stores.length);
|
|
24393
|
+
}
|
|
24394
|
+
}
|
|
24395
|
+
foldConversations(agg, createFoldState(), conversations, sinceMs);
|
|
24396
|
+
return stats;
|
|
24397
|
+
}
|
|
24398
|
+
async function detectAntigravity(opts) {
|
|
24399
|
+
const homes = opts.roots ?? (await antigravityHomes()).homes;
|
|
24400
|
+
const stores = (await storeFiles(homes)).filter((s) => s.kind === "db");
|
|
24401
|
+
if (stores.length === 0) return false;
|
|
24402
|
+
const open4 = await loadSqlite();
|
|
24403
|
+
if (open4 === null) return false;
|
|
24404
|
+
for (const store of stores) {
|
|
24405
|
+
try {
|
|
24406
|
+
if ((await stat2(store.file)).mtimeMs < opts.sinceMs) continue;
|
|
24407
|
+
} catch {
|
|
24408
|
+
continue;
|
|
24409
|
+
}
|
|
24410
|
+
let db = null;
|
|
24411
|
+
try {
|
|
24412
|
+
db = open4(store.file);
|
|
24413
|
+
if (db.prepare("select 1 as hit from steps limit 1").get() !== void 0)
|
|
24414
|
+
return true;
|
|
24415
|
+
} catch (error) {
|
|
24416
|
+
traceError("antigravity detection", error, "warn");
|
|
24417
|
+
} finally {
|
|
24418
|
+
closeQuietly(db);
|
|
24419
|
+
}
|
|
24420
|
+
}
|
|
24421
|
+
return false;
|
|
24422
|
+
}
|
|
24423
|
+
|
|
24424
|
+
// src/harness/antigravity/adapter.ts
|
|
24425
|
+
var ANTIGRAVITY_HARNESS_NAME = "antigravity";
|
|
24426
|
+
var antigravityAdapter = {
|
|
24427
|
+
name: ANTIGRAVITY_HARNESS_NAME,
|
|
24428
|
+
builtinTools: ANTIGRAVITY_BUILTIN_TOOLS,
|
|
24429
|
+
async detect(opts) {
|
|
24430
|
+
return detectAntigravity({
|
|
24431
|
+
sinceMs: opts.sinceMs,
|
|
24432
|
+
...opts.roots ? { roots: opts.roots } : {}
|
|
24433
|
+
});
|
|
24434
|
+
},
|
|
24435
|
+
async scan(opts) {
|
|
24436
|
+
const aggregate = createAggregate2();
|
|
24437
|
+
const stats = await scan(aggregate, {
|
|
24438
|
+
sinceMs: opts.sinceMs,
|
|
24439
|
+
...opts.onProgress ? { onProgress: opts.onProgress } : {}
|
|
24440
|
+
});
|
|
24441
|
+
return {
|
|
24442
|
+
aggregate,
|
|
24443
|
+
stats,
|
|
24444
|
+
scanComplete: stats.sourceDiscoveryComplete !== false,
|
|
24445
|
+
workflow: aggregate.workflow.finish(),
|
|
24446
|
+
workflowLocal: aggregate.workflowLocal
|
|
24447
|
+
};
|
|
24448
|
+
}
|
|
24449
|
+
};
|
|
24450
|
+
|
|
24451
|
+
// src/harness/shared/recency.ts
|
|
24452
|
+
import { readdir as readdir3, stat as stat3 } from "node:fs/promises";
|
|
24453
|
+
import path3 from "node:path";
|
|
24454
|
+
async function hasRecentFile(roots, matches, sinceMs, opts = {}) {
|
|
24455
|
+
const readDir = opts.readdirImpl ?? ((dir) => readdir3(dir, { withFileTypes: true }));
|
|
24456
|
+
const statFile = opts.statImpl ?? stat3;
|
|
24457
|
+
const seen = /* @__PURE__ */ new Set();
|
|
24458
|
+
const pending = [...roots];
|
|
24459
|
+
while (pending.length > 0) {
|
|
24460
|
+
const dir = pending.pop();
|
|
24461
|
+
if (seen.has(dir)) continue;
|
|
24462
|
+
seen.add(dir);
|
|
24463
|
+
let entries;
|
|
24464
|
+
try {
|
|
24465
|
+
entries = await readDir(dir);
|
|
24466
|
+
} catch {
|
|
24467
|
+
continue;
|
|
24468
|
+
}
|
|
24469
|
+
for (const e of entries) {
|
|
24470
|
+
const full = path3.join(dir, e.name);
|
|
24471
|
+
if (e.isDirectory()) {
|
|
24472
|
+
pending.push(full);
|
|
24473
|
+
continue;
|
|
24474
|
+
}
|
|
24475
|
+
if (!e.isFile() || !matches(e.name)) continue;
|
|
24476
|
+
try {
|
|
24477
|
+
const st = await statFile(full);
|
|
24478
|
+
if (st.mtimeMs >= sinceMs) return true;
|
|
24479
|
+
} catch {
|
|
24480
|
+
}
|
|
24481
|
+
}
|
|
24482
|
+
}
|
|
24483
|
+
return false;
|
|
24484
|
+
}
|
|
24485
|
+
|
|
24486
|
+
// src/harness/claude/analyzer.ts
|
|
24487
|
+
function createAggregate3() {
|
|
24488
|
+
const workflowLocal = createWorkflowLocalSources();
|
|
24489
|
+
return Object.assign(createAggregate(), {
|
|
24490
|
+
recordUuids: /* @__PURE__ */ new Set(),
|
|
24491
|
+
workflow: createHarnessWorkflowReducer("claude-code", workflowLocal),
|
|
24492
|
+
workflowLocal,
|
|
24493
|
+
workflowSeenCalls: /* @__PURE__ */ new Set(),
|
|
24494
|
+
workflowSeenTurns: /* @__PURE__ */ new Set(),
|
|
24495
|
+
contextFirstCall: /* @__PURE__ */ new Map(),
|
|
24496
|
+
workflowToolNames: /* @__PURE__ */ new Map(),
|
|
24497
|
+
typedCommands: /* @__PURE__ */ new Map()
|
|
24498
|
+
});
|
|
24499
|
+
}
|
|
24500
|
+
function workflowSessionKey(rec) {
|
|
24501
|
+
const baseSession = asStr(rec.sessionId);
|
|
24502
|
+
if (!baseSession) return null;
|
|
24503
|
+
if (rec.isSidechain !== true) return baseSession;
|
|
24504
|
+
return `${baseSession}:agent:${asStr(rec.agentId) ?? "unknown"}`;
|
|
24505
|
+
}
|
|
24506
|
+
function isApiCall(rec) {
|
|
24507
|
+
if (asStr(rec.type) !== "assistant") return false;
|
|
24508
|
+
const msg = asObj(rec.message);
|
|
24509
|
+
if (!msg || !asObj(msg.usage)) return false;
|
|
24510
|
+
return !(asName(msg.model) ?? "").startsWith("<");
|
|
24511
|
+
}
|
|
24512
|
+
function noteRecordBeforeWindow(agg, raw) {
|
|
24513
|
+
const rec = asObj(raw);
|
|
24514
|
+
if (!rec || !isApiCall(rec)) return;
|
|
24515
|
+
const session = workflowSessionKey(rec);
|
|
24516
|
+
if (session && !agg.contextFirstCall.has(session)) {
|
|
24517
|
+
agg.contextFirstCall.set(session, null);
|
|
24518
|
+
}
|
|
24519
|
+
}
|
|
24520
|
+
function projectWorkspaceDirectory(raw) {
|
|
24521
|
+
const rec = asObj(raw);
|
|
24522
|
+
return rec ? asStr(rec.cwd) : null;
|
|
24523
|
+
}
|
|
24524
|
+
function ingestRecord(agg, raw, ctx) {
|
|
24525
|
+
const rec = asObj(raw);
|
|
24526
|
+
if (!rec) return;
|
|
24527
|
+
const uuid = asStr(rec.uuid);
|
|
24528
|
+
if (uuid) {
|
|
24529
|
+
if (agg.recordUuids.has(uuid)) return;
|
|
24530
|
+
agg.recordUuids.add(uuid);
|
|
24531
|
+
}
|
|
24532
|
+
agg.records++;
|
|
24533
|
+
const projectDir = projectWorkspaceDirectory(rec) ?? ctx.projectDir;
|
|
24534
|
+
const version = asStr(rec.version);
|
|
24535
|
+
if (version) agg.ccVersions.add(cleanName(version));
|
|
24536
|
+
const sessionId = asStr(rec.sessionId);
|
|
24537
|
+
if (sessionId) agg.sessions.add(sessionId);
|
|
24538
|
+
let tsMs = null;
|
|
24539
|
+
const timestamp2 = asStr(rec.timestamp);
|
|
24540
|
+
if (timestamp2) {
|
|
24541
|
+
const ts = Date.parse(timestamp2);
|
|
24542
|
+
if (!Number.isNaN(ts)) {
|
|
24543
|
+
tsMs = ts;
|
|
24544
|
+
agg.activeDays.add(timestamp2.slice(0, 10));
|
|
24545
|
+
agg.firstTs = agg.firstTs === null ? ts : Math.min(agg.firstTs, ts);
|
|
24546
|
+
agg.lastTs = agg.lastTs === null ? ts : Math.max(agg.lastTs, ts);
|
|
24547
|
+
}
|
|
24548
|
+
}
|
|
24549
|
+
if (sessionId) noteSessionStart(agg, sessionId, tsMs);
|
|
24550
|
+
if (projectDir !== void 0) {
|
|
24551
|
+
agg.projectDirs.add(projectDir);
|
|
24552
|
+
}
|
|
24553
|
+
noteProjectDay(agg, projectDir, tsMs);
|
|
24554
|
+
const type = asStr(rec.type);
|
|
24555
|
+
if (type === "assistant") {
|
|
24556
|
+
ingestClaudeWorkflow(agg, rec, ctx, tsMs);
|
|
24557
|
+
ingestAssistant(agg, rec, tsMs);
|
|
24558
|
+
} else if (type === "user") {
|
|
24559
|
+
ingestUser(agg, rec);
|
|
24560
|
+
ingestClaudeToolResults(agg, rec, ctx, tsMs);
|
|
24561
|
+
} else if (type === "system") {
|
|
24562
|
+
ingestClaudeTurnDuration(agg, rec, ctx, tsMs);
|
|
24563
|
+
ingestClaudeCompaction(agg, rec, ctx, tsMs);
|
|
24564
|
+
}
|
|
24565
|
+
}
|
|
24566
|
+
function ingestClaudeCompaction(agg, rec, ctx, tsMs) {
|
|
24567
|
+
if (tsMs === null || asStr(rec.subtype) !== "compact_boundary") return;
|
|
24568
|
+
const session = workflowSessionKey(rec);
|
|
24569
|
+
if (!session) return;
|
|
24570
|
+
agg.workflow.ingest({
|
|
24571
|
+
type: "compaction",
|
|
24572
|
+
session,
|
|
24573
|
+
projectWorkspace: projectWorkspaceDirectory(rec) ?? ctx.projectDir,
|
|
24574
|
+
tsMs,
|
|
24575
|
+
...rec.isSidechain === true ? { sidechain: true } : {}
|
|
24576
|
+
});
|
|
24577
|
+
}
|
|
24578
|
+
function contextOf(counts2) {
|
|
24579
|
+
return counts2.input + counts2.cacheWrite5m + counts2.cacheWrite1h + counts2.cacheWriteUnsplit + counts2.cacheRead;
|
|
24580
|
+
}
|
|
24581
|
+
function ingestClaudeTurnDuration(agg, rec, ctx, tsMs) {
|
|
24582
|
+
if (tsMs === null || asStr(rec.subtype) !== "turn_duration" || asNum(rec.durationMs) <= 0) {
|
|
24583
|
+
return;
|
|
24584
|
+
}
|
|
24585
|
+
const session = asStr(rec.sessionId);
|
|
24586
|
+
if (!session) return;
|
|
24587
|
+
agg.workflow.ingest({
|
|
24588
|
+
type: "response",
|
|
24589
|
+
session,
|
|
24590
|
+
projectWorkspace: projectWorkspaceDirectory(rec) ?? ctx.projectDir,
|
|
24591
|
+
tsMs,
|
|
24592
|
+
...asStr(rec.uuid) ? { responseId: `duration:${asStr(rec.uuid)}` } : {},
|
|
24593
|
+
durationSec: asNum(rec.durationMs) / 1e3
|
|
24594
|
+
});
|
|
24595
|
+
}
|
|
24596
|
+
function ingestClaudeWorkflow(agg, rec, ctx, tsMs) {
|
|
24597
|
+
if (tsMs === null) return;
|
|
24598
|
+
const baseSession = asStr(rec.sessionId);
|
|
24599
|
+
const msg = asObj(rec.message);
|
|
24600
|
+
if (!baseSession || !msg) return;
|
|
24601
|
+
const projectWorkspace = projectWorkspaceDirectory(rec) ?? ctx.projectDir;
|
|
24602
|
+
const sidechain = rec.isSidechain === true;
|
|
24603
|
+
const agentId = asStr(rec.agentId);
|
|
24604
|
+
const session = sidechain ? `${baseSession}:agent:${agentId ?? "unknown"}` : baseSession;
|
|
24605
|
+
const parentSession = sidechain ? baseSession : void 0;
|
|
24606
|
+
const usage = asObj(msg.usage);
|
|
24607
|
+
const counts2 = usage ? readCounts(usage) : null;
|
|
24608
|
+
const messageId = asStr(msg.id);
|
|
24609
|
+
const newTurn = messageId ? !agg.workflowSeenTurns.has(messageId) : true;
|
|
24610
|
+
if (messageId) agg.workflowSeenTurns.add(messageId);
|
|
24611
|
+
const blocks = { thinking: 0, text: 0 };
|
|
24612
|
+
for (const rawBlock of asArr(msg.content)) {
|
|
24613
|
+
const block = asObj(rawBlock);
|
|
24614
|
+
const kind = block ? asStr(block.type) : null;
|
|
24615
|
+
if (kind === "thinking") blocks.thinking++;
|
|
24616
|
+
else if (kind === "text") blocks.text++;
|
|
24617
|
+
}
|
|
24618
|
+
let context = null;
|
|
24619
|
+
if (counts2 && isApiCall(rec)) {
|
|
24620
|
+
const held = agg.contextFirstCall.get(session);
|
|
24621
|
+
let first = false;
|
|
24622
|
+
if (held === void 0) {
|
|
24623
|
+
agg.contextFirstCall.set(session, messageId);
|
|
24624
|
+
first = true;
|
|
24625
|
+
} else if (held !== null && held === messageId) first = true;
|
|
24626
|
+
context = {
|
|
24627
|
+
contextTokens: contextOf(counts2),
|
|
24628
|
+
inputTokens: counts2.input,
|
|
24629
|
+
cacheReadTokens: counts2.cacheRead,
|
|
24630
|
+
cacheWriteTokens: counts2.cacheWrite5m + counts2.cacheWrite1h + counts2.cacheWriteUnsplit,
|
|
24631
|
+
// The TTL this call wrote under (v5): a subscription within plan
|
|
24632
|
+
// usage writes the main conversation at one hour.
|
|
24633
|
+
...counts2.cacheWrite1h > 0 ? { cacheTtlSec: 3600 } : counts2.cacheWrite5m > 0 ? { cacheTtlSec: 300 } : {},
|
|
24634
|
+
...first ? {
|
|
24635
|
+
firstCall: {
|
|
24636
|
+
harnessTokens: counts2.cacheRead,
|
|
24637
|
+
instructionsTokens: contextOf(counts2) - counts2.cacheRead
|
|
24638
|
+
}
|
|
24639
|
+
} : {}
|
|
24640
|
+
};
|
|
24641
|
+
}
|
|
23899
24642
|
agg.workflow.ingest({
|
|
23900
24643
|
type: "response",
|
|
23901
24644
|
session,
|
|
@@ -24243,13 +24986,13 @@ function ingestTypedSkill(agg, rec, text) {
|
|
|
24243
24986
|
}
|
|
24244
24987
|
|
|
24245
24988
|
// src/harness/claude/roots.ts
|
|
24246
|
-
import { readdir as
|
|
24247
|
-
import { homedir as
|
|
24248
|
-
import
|
|
24989
|
+
import { readdir as readdir4, realpath as realpath3, stat as stat4 } from "node:fs/promises";
|
|
24990
|
+
import { homedir as homedir8 } from "node:os";
|
|
24991
|
+
import path4 from "node:path";
|
|
24249
24992
|
async function discoverClaudeRoots() {
|
|
24250
|
-
const home =
|
|
24251
|
-
const configHome = process.env.XDG_CONFIG_HOME ||
|
|
24252
|
-
const dataHome = process.env.XDG_DATA_HOME ||
|
|
24993
|
+
const home = homedir8();
|
|
24994
|
+
const configHome = process.env.XDG_CONFIG_HOME || path4.join(home, ".config");
|
|
24995
|
+
const dataHome = process.env.XDG_DATA_HOME || path4.join(home, ".local", "share");
|
|
24253
24996
|
let complete = true;
|
|
24254
24997
|
const failed = (error) => {
|
|
24255
24998
|
const code2 = error?.code;
|
|
@@ -24259,44 +25002,44 @@ async function discoverClaudeRoots() {
|
|
|
24259
25002
|
};
|
|
24260
25003
|
const children = async (dir, prefix = "") => {
|
|
24261
25004
|
try {
|
|
24262
|
-
return (await
|
|
25005
|
+
return (await readdir4(dir, { withFileTypes: true })).filter(
|
|
24263
25006
|
(entry) => entry.name.startsWith(prefix) && (entry.isDirectory() || entry.isSymbolicLink())
|
|
24264
|
-
).map((entry) =>
|
|
25007
|
+
).map((entry) => path4.join(dir, entry.name)).sort();
|
|
24265
25008
|
} catch (error) {
|
|
24266
25009
|
failed(error);
|
|
24267
25010
|
return [];
|
|
24268
25011
|
}
|
|
24269
25012
|
};
|
|
24270
25013
|
const configured = (process.env.CLAUDE_CONFIG_DIR ?? "").split(",").map((s) => s.trim()).filter(Boolean).map(
|
|
24271
|
-
(dir) =>
|
|
25014
|
+
(dir) => path4.resolve(dir.startsWith("~/") ? path4.join(home, dir.slice(2)) : dir)
|
|
24272
25015
|
);
|
|
24273
25016
|
const profiles = /* @__PURE__ */ new Set([
|
|
24274
|
-
|
|
24275
|
-
|
|
25017
|
+
path4.join(home, ".claude"),
|
|
25018
|
+
path4.join(configHome, "claude"),
|
|
24276
25019
|
...configured,
|
|
24277
25020
|
...await children(home, ".claude"),
|
|
24278
25021
|
...await children(configHome, "claude")
|
|
24279
25022
|
]);
|
|
24280
25023
|
for (const profile of [...profiles]) {
|
|
24281
25024
|
for (const collection of ["profiles", "accounts"]) {
|
|
24282
|
-
for (const child of await children(
|
|
25025
|
+
for (const child of await children(path4.join(profile, collection)))
|
|
24283
25026
|
profiles.add(child);
|
|
24284
25027
|
}
|
|
24285
25028
|
}
|
|
24286
25029
|
for (const manager of [
|
|
24287
|
-
|
|
24288
|
-
|
|
25030
|
+
path4.join(home, ".claude-swap-backup"),
|
|
25031
|
+
path4.join(dataHome, "claude-swap")
|
|
24289
25032
|
]) {
|
|
24290
|
-
for (const collection of [manager,
|
|
25033
|
+
for (const collection of [manager, path4.join(manager, "sessions")]) {
|
|
24291
25034
|
for (const child of await children(collection)) profiles.add(child);
|
|
24292
25035
|
}
|
|
24293
25036
|
}
|
|
24294
25037
|
const roots = /* @__PURE__ */ new Set();
|
|
24295
25038
|
for (const profile of profiles) {
|
|
24296
|
-
const projects =
|
|
25039
|
+
const projects = path4.join(profile, "projects");
|
|
24297
25040
|
try {
|
|
24298
|
-
if ((await
|
|
24299
|
-
roots.add(await
|
|
25041
|
+
if ((await stat4(projects)).isDirectory())
|
|
25042
|
+
roots.add(await realpath3(projects));
|
|
24300
25043
|
} catch (error) {
|
|
24301
25044
|
failed(error);
|
|
24302
25045
|
}
|
|
@@ -24306,8 +25049,8 @@ async function discoverClaudeRoots() {
|
|
|
24306
25049
|
|
|
24307
25050
|
// src/harness/claude/scan.ts
|
|
24308
25051
|
import { createReadStream } from "node:fs";
|
|
24309
|
-
import { readdir as
|
|
24310
|
-
import
|
|
25052
|
+
import { readdir as readdir5, realpath as realpath4, stat as stat5 } from "node:fs/promises";
|
|
25053
|
+
import path5 from "node:path";
|
|
24311
25054
|
import readline from "node:readline";
|
|
24312
25055
|
var WORKSPACE_FALLBACK_PREFIX = "claude-project:";
|
|
24313
25056
|
function isClaudeWorkspaceFallback(directory) {
|
|
@@ -24319,19 +25062,19 @@ function isTranscriptFile(basename6) {
|
|
|
24319
25062
|
async function* walkJsonl(dir) {
|
|
24320
25063
|
let entries;
|
|
24321
25064
|
try {
|
|
24322
|
-
entries = await
|
|
25065
|
+
entries = await readdir5(dir, { withFileTypes: true });
|
|
24323
25066
|
} catch (error) {
|
|
24324
25067
|
if (error?.code !== "ENOENT")
|
|
24325
25068
|
traceError("claude transcript discovery", error, "warn");
|
|
24326
25069
|
return;
|
|
24327
25070
|
}
|
|
24328
25071
|
for (const e of entries) {
|
|
24329
|
-
const full =
|
|
25072
|
+
const full = path5.join(dir, e.name);
|
|
24330
25073
|
if (e.isDirectory()) yield* walkJsonl(full);
|
|
24331
25074
|
else if (e.isFile() && isTranscriptFile(e.name)) yield full;
|
|
24332
25075
|
}
|
|
24333
25076
|
}
|
|
24334
|
-
async function
|
|
25077
|
+
async function scan2(agg, opts = {}) {
|
|
24335
25078
|
const stats = emptyScanStats();
|
|
24336
25079
|
const visited = /* @__PURE__ */ new Set();
|
|
24337
25080
|
const projectWorkspaces = /* @__PURE__ */ new Map();
|
|
@@ -24343,7 +25086,7 @@ async function scan(agg, opts = {}) {
|
|
|
24343
25086
|
stats.filesFound++;
|
|
24344
25087
|
let resolved;
|
|
24345
25088
|
try {
|
|
24346
|
-
resolved = await
|
|
25089
|
+
resolved = await realpath4(file);
|
|
24347
25090
|
} catch (error) {
|
|
24348
25091
|
if (error?.code !== "ENOENT")
|
|
24349
25092
|
traceError("claude transcript path resolution", error, "warn");
|
|
@@ -24356,7 +25099,7 @@ async function scan(agg, opts = {}) {
|
|
|
24356
25099
|
visited.add(resolved);
|
|
24357
25100
|
if (opts.sinceMs !== void 0) {
|
|
24358
25101
|
try {
|
|
24359
|
-
const st = await
|
|
25102
|
+
const st = await stat5(file);
|
|
24360
25103
|
if (st.mtimeMs < opts.sinceMs) {
|
|
24361
25104
|
stats.filesSkippedByMtime++;
|
|
24362
25105
|
continue;
|
|
@@ -24366,8 +25109,8 @@ async function scan(agg, opts = {}) {
|
|
|
24366
25109
|
traceError("claude transcript stat", error, "warn");
|
|
24367
25110
|
}
|
|
24368
25111
|
}
|
|
24369
|
-
const parts =
|
|
24370
|
-
const projectDir = parts.length > 1 ? `${WORKSPACE_FALLBACK_PREFIX}${
|
|
25112
|
+
const parts = path5.relative(root, file).split(path5.sep);
|
|
25113
|
+
const projectDir = parts.length > 1 ? `${WORKSPACE_FALLBACK_PREFIX}${path5.resolve(root, parts[0])}` : void 0;
|
|
24371
25114
|
agg.files++;
|
|
24372
25115
|
stats.filesRead++;
|
|
24373
25116
|
if (opts.onProgress && agg.files % 20 === 0) opts.onProgress(agg.files);
|
|
@@ -24390,7 +25133,7 @@ async function scan(agg, opts = {}) {
|
|
|
24390
25133
|
}
|
|
24391
25134
|
async function exists(p8) {
|
|
24392
25135
|
try {
|
|
24393
|
-
await
|
|
25136
|
+
await stat5(p8);
|
|
24394
25137
|
return true;
|
|
24395
25138
|
} catch (error) {
|
|
24396
25139
|
if (error?.code !== "ENOENT")
|
|
@@ -24451,8 +25194,8 @@ var claudeAdapter = {
|
|
|
24451
25194
|
return hasRecentFile(discovery.roots, isTranscriptFile, opts.sinceMs);
|
|
24452
25195
|
},
|
|
24453
25196
|
async scan(opts) {
|
|
24454
|
-
const aggregate =
|
|
24455
|
-
const stats = await
|
|
25197
|
+
const aggregate = createAggregate3();
|
|
25198
|
+
const stats = await scan2(aggregate, {
|
|
24456
25199
|
sinceMs: opts.sinceMs,
|
|
24457
25200
|
...opts.onProgress ? { onProgress: opts.onProgress } : {}
|
|
24458
25201
|
});
|
|
@@ -24467,7 +25210,7 @@ var claudeAdapter = {
|
|
|
24467
25210
|
};
|
|
24468
25211
|
|
|
24469
25212
|
// src/harness/codex/analyzer.ts
|
|
24470
|
-
function
|
|
25213
|
+
function createAggregate4() {
|
|
24471
25214
|
const workflowLocal = createWorkflowLocalSources();
|
|
24472
25215
|
return Object.assign(createAggregate(), {
|
|
24473
25216
|
workflow: createHarnessWorkflowReducer("codex", workflowLocal),
|
|
@@ -24742,194 +25485,70 @@ function ingestToolResult(agg, payload, state, tsMs) {
|
|
|
24742
25485
|
const callId = asStr(payload.call_id) ?? asStr(payload.id);
|
|
24743
25486
|
const output = payload.output;
|
|
24744
25487
|
const bytes = typeof output === "string" ? Buffer.byteLength(output) : output === void 0 || output === null ? 0 : Buffer.byteLength(JSON.stringify(output));
|
|
24745
|
-
agg.workflow.ingest({
|
|
24746
|
-
type: "toolResult",
|
|
24747
|
-
session: state.sessionId,
|
|
24748
|
-
projectWorkspace: state.cwd ?? void 0,
|
|
24749
|
-
tsMs,
|
|
24750
|
-
tool: callId && state.callNames.get(callId) || "other",
|
|
24751
|
-
bytes
|
|
24752
|
-
});
|
|
24753
|
-
}
|
|
24754
|
-
function ingestWorkflowCall(agg, payload, name, callId, state, tsMs) {
|
|
24755
|
-
if (tsMs === null || !state.sessionId) return;
|
|
24756
|
-
if (callId) {
|
|
24757
|
-
if (agg.workflowSeenCalls.has(callId)) return;
|
|
24758
|
-
agg.workflowSeenCalls.add(callId);
|
|
24759
|
-
}
|
|
24760
|
-
state.currentQuestionBack = name === "request_user_input";
|
|
24761
|
-
let arg = "";
|
|
24762
|
-
if (["exec_command", "shell", "container.exec", "local_shell"].includes(name)) {
|
|
24763
|
-
const raw = name === "local_shell" ? asObj(payload.action)?.command : payload.arguments ?? payload.input;
|
|
24764
|
-
if (Array.isArray(raw)) arg = unwrapShellCommand(raw.map(String));
|
|
24765
|
-
else if (typeof raw === "string" && !raw.trim().startsWith("{")) arg = raw;
|
|
24766
|
-
else {
|
|
24767
|
-
try {
|
|
24768
|
-
const parsed = JSON.parse(String(raw ?? "{}"));
|
|
24769
|
-
const command = parsed.cmd ?? parsed.command;
|
|
24770
|
-
arg = Array.isArray(command) ? unwrapShellCommand(command.map(String)) : typeof command === "string" ? command : "";
|
|
24771
|
-
} catch {
|
|
24772
|
-
arg = "";
|
|
24773
|
-
}
|
|
24774
|
-
}
|
|
24775
|
-
}
|
|
24776
|
-
agg.workflow.ingest({
|
|
24777
|
-
type: "event",
|
|
24778
|
-
session: state.sessionId,
|
|
24779
|
-
projectWorkspace: state.cwd ?? void 0,
|
|
24780
|
-
tsMs,
|
|
24781
|
-
tool: name,
|
|
24782
|
-
arg
|
|
24783
|
-
});
|
|
24784
|
-
}
|
|
24785
|
-
function unwrapShellCommand(command) {
|
|
24786
|
-
if (command.length >= 3 && /^(bash|sh|zsh)$/.test(command[0] ?? "") && /^-l?c$/.test(command[1] ?? ""))
|
|
24787
|
-
return command.slice(2).join(" ");
|
|
24788
|
-
return command.join(" ");
|
|
24789
|
-
}
|
|
24790
|
-
function noteConfiguredMcpServers(agg, serverNames) {
|
|
24791
|
-
for (const raw of serverNames) {
|
|
24792
|
-
const name = cleanName(raw);
|
|
24793
|
-
if (!agg.mcpServerCalls.has(name)) agg.mcpServerCalls.set(name, 0);
|
|
24794
|
-
}
|
|
24795
|
-
}
|
|
24796
|
-
|
|
24797
|
-
// src/harness/codex/scan.ts
|
|
24798
|
-
import { readFileSync as readFileSync6 } from "node:fs";
|
|
24799
|
-
import { open, readdir as readdir5, stat as stat5 } from "node:fs/promises";
|
|
24800
|
-
import { homedir as homedir8 } from "node:os";
|
|
24801
|
-
import path5 from "node:path";
|
|
24802
|
-
import { Readable } from "node:stream";
|
|
24803
|
-
import * as zlib from "node:zlib";
|
|
24804
|
-
import { parse as parseToml2 } from "smol-toml";
|
|
24805
|
-
|
|
24806
|
-
// src/harness/shared/homes.ts
|
|
24807
|
-
import {
|
|
24808
|
-
mkdir,
|
|
24809
|
-
readdir as readdir4,
|
|
24810
|
-
readFile,
|
|
24811
|
-
realpath as realpath3,
|
|
24812
|
-
stat as stat4,
|
|
24813
|
-
writeFile
|
|
24814
|
-
} from "node:fs/promises";
|
|
24815
|
-
import { homedir as homedir7 } from "node:os";
|
|
24816
|
-
import path4 from "node:path";
|
|
24817
|
-
async function discoverHomes(options) {
|
|
24818
|
-
let complete = true;
|
|
24819
|
-
const resolve3 = async (dir) => {
|
|
24820
|
-
try {
|
|
24821
|
-
const real = await realpath3(dir);
|
|
24822
|
-
return (await stat4(real)).isDirectory() ? real : null;
|
|
24823
|
-
} catch (error) {
|
|
24824
|
-
if (!absent(error)) {
|
|
24825
|
-
complete = false;
|
|
24826
|
-
traceError("harness home resolution", error, "warn");
|
|
24827
|
-
}
|
|
24828
|
-
return null;
|
|
24829
|
-
}
|
|
24830
|
-
};
|
|
24831
|
-
const named = [...options.defaults];
|
|
24832
|
-
for (const { parent, prefix } of options.siblings ?? []) {
|
|
24833
|
-
try {
|
|
24834
|
-
named.push(
|
|
24835
|
-
...(await readdir4(parent, { withFileTypes: true })).filter(
|
|
24836
|
-
(entry) => entry.name.startsWith(prefix) && (entry.isDirectory() || entry.isSymbolicLink())
|
|
24837
|
-
).map((entry) => path4.join(parent, entry.name)).sort()
|
|
24838
|
-
);
|
|
24839
|
-
} catch (error) {
|
|
24840
|
-
if (!absent(error)) {
|
|
24841
|
-
complete = false;
|
|
24842
|
-
traceError("harness home discovery", error, "warn");
|
|
24843
|
-
}
|
|
24844
|
-
}
|
|
24845
|
-
}
|
|
24846
|
-
const homes = [];
|
|
24847
|
-
const add = (real) => {
|
|
24848
|
-
if (real && !homes.includes(real)) homes.push(real);
|
|
24849
|
-
};
|
|
24850
|
-
for (const dir of named) add(await resolve3(dir));
|
|
24851
|
-
const found = new Set(homes);
|
|
24852
|
-
const remembered = options.remember ? await readRemembered(options.remember) : [];
|
|
24853
|
-
const fresh = [];
|
|
24854
|
-
for (const dir of (options.configured ?? []).filter((dir2) => Boolean(dir2?.trim())).map(expandHome)) {
|
|
24855
|
-
const real = await resolve3(dir);
|
|
24856
|
-
add(real);
|
|
24857
|
-
if (real && !found.has(real) && !remembered.includes(real))
|
|
24858
|
-
fresh.push(real);
|
|
24859
|
-
}
|
|
24860
|
-
for (const dir of remembered) add(await resolve3(dir));
|
|
24861
|
-
if (options.remember && fresh.length)
|
|
24862
|
-
await writeRemembered(options.remember, [...remembered, ...fresh]);
|
|
24863
|
-
return { homes, complete };
|
|
24864
|
-
}
|
|
24865
|
-
var rememberedFile = () => path4.join(homedir7(), ".config", "aistack", "harness-homes.json");
|
|
24866
|
-
async function rememberedHomes(harness) {
|
|
24867
|
-
return readRemembered(harness);
|
|
24868
|
-
}
|
|
24869
|
-
async function rememberHome(harness, dir) {
|
|
24870
|
-
const list = await readRemembered(harness);
|
|
24871
|
-
if (list.includes(dir)) return false;
|
|
24872
|
-
if (!await writeRemembered(harness, [...list, dir]))
|
|
24873
|
-
throw new Error("Could not save the folder list");
|
|
24874
|
-
return true;
|
|
24875
|
-
}
|
|
24876
|
-
async function forgetHome(harness, dir) {
|
|
24877
|
-
const list = await readRemembered(harness);
|
|
24878
|
-
if (!list.includes(dir)) return false;
|
|
24879
|
-
if (!await writeRemembered(
|
|
24880
|
-
harness,
|
|
24881
|
-
list.filter((entry) => entry !== dir)
|
|
24882
|
-
))
|
|
24883
|
-
throw new Error("Could not save the folder list");
|
|
24884
|
-
return true;
|
|
25488
|
+
agg.workflow.ingest({
|
|
25489
|
+
type: "toolResult",
|
|
25490
|
+
session: state.sessionId,
|
|
25491
|
+
projectWorkspace: state.cwd ?? void 0,
|
|
25492
|
+
tsMs,
|
|
25493
|
+
tool: callId && state.callNames.get(callId) || "other",
|
|
25494
|
+
bytes
|
|
25495
|
+
});
|
|
24885
25496
|
}
|
|
24886
|
-
|
|
24887
|
-
|
|
24888
|
-
|
|
24889
|
-
|
|
24890
|
-
|
|
24891
|
-
} catch (error) {
|
|
24892
|
-
if (!absent(error)) traceError("remembered harness homes", error, "warn");
|
|
24893
|
-
return [];
|
|
25497
|
+
function ingestWorkflowCall(agg, payload, name, callId, state, tsMs) {
|
|
25498
|
+
if (tsMs === null || !state.sessionId) return;
|
|
25499
|
+
if (callId) {
|
|
25500
|
+
if (agg.workflowSeenCalls.has(callId)) return;
|
|
25501
|
+
agg.workflowSeenCalls.add(callId);
|
|
24894
25502
|
}
|
|
24895
|
-
|
|
24896
|
-
|
|
24897
|
-
|
|
24898
|
-
|
|
24899
|
-
|
|
24900
|
-
|
|
24901
|
-
|
|
24902
|
-
|
|
24903
|
-
|
|
24904
|
-
|
|
24905
|
-
|
|
25503
|
+
state.currentQuestionBack = name === "request_user_input";
|
|
25504
|
+
let arg = "";
|
|
25505
|
+
if (["exec_command", "shell", "container.exec", "local_shell"].includes(name)) {
|
|
25506
|
+
const raw = name === "local_shell" ? asObj(payload.action)?.command : payload.arguments ?? payload.input;
|
|
25507
|
+
if (Array.isArray(raw)) arg = unwrapShellCommand(raw.map(String));
|
|
25508
|
+
else if (typeof raw === "string" && !raw.trim().startsWith("{")) arg = raw;
|
|
25509
|
+
else {
|
|
25510
|
+
try {
|
|
25511
|
+
const parsed = JSON.parse(String(raw ?? "{}"));
|
|
25512
|
+
const command = parsed.cmd ?? parsed.command;
|
|
25513
|
+
arg = Array.isArray(command) ? unwrapShellCommand(command.map(String)) : typeof command === "string" ? command : "";
|
|
25514
|
+
} catch {
|
|
25515
|
+
arg = "";
|
|
25516
|
+
}
|
|
24906
25517
|
}
|
|
24907
|
-
all[harness] = dirs;
|
|
24908
|
-
await mkdir(path4.dirname(file), { recursive: true, mode: 448 });
|
|
24909
|
-
await writeFile(file, `${JSON.stringify(all, null, 2)}
|
|
24910
|
-
`, { mode: 384 });
|
|
24911
|
-
return true;
|
|
24912
|
-
} catch (error) {
|
|
24913
|
-
traceError("remembered harness homes", error, "warn");
|
|
24914
|
-
return false;
|
|
24915
25518
|
}
|
|
25519
|
+
agg.workflow.ingest({
|
|
25520
|
+
type: "event",
|
|
25521
|
+
session: state.sessionId,
|
|
25522
|
+
projectWorkspace: state.cwd ?? void 0,
|
|
25523
|
+
tsMs,
|
|
25524
|
+
tool: name,
|
|
25525
|
+
arg
|
|
25526
|
+
});
|
|
24916
25527
|
}
|
|
24917
|
-
function
|
|
24918
|
-
|
|
24919
|
-
|
|
24920
|
-
|
|
24921
|
-
);
|
|
25528
|
+
function unwrapShellCommand(command) {
|
|
25529
|
+
if (command.length >= 3 && /^(bash|sh|zsh)$/.test(command[0] ?? "") && /^-l?c$/.test(command[1] ?? ""))
|
|
25530
|
+
return command.slice(2).join(" ");
|
|
25531
|
+
return command.join(" ");
|
|
24922
25532
|
}
|
|
24923
|
-
function
|
|
24924
|
-
const
|
|
24925
|
-
|
|
25533
|
+
function noteConfiguredMcpServers(agg, serverNames) {
|
|
25534
|
+
for (const raw of serverNames) {
|
|
25535
|
+
const name = cleanName(raw);
|
|
25536
|
+
if (!agg.mcpServerCalls.has(name)) agg.mcpServerCalls.set(name, 0);
|
|
25537
|
+
}
|
|
24926
25538
|
}
|
|
24927
25539
|
|
|
24928
25540
|
// src/harness/codex/scan.ts
|
|
25541
|
+
import { readFileSync as readFileSync6 } from "node:fs";
|
|
25542
|
+
import { open, readdir as readdir6, stat as stat6 } from "node:fs/promises";
|
|
25543
|
+
import { homedir as homedir9 } from "node:os";
|
|
25544
|
+
import path6 from "node:path";
|
|
25545
|
+
import { Readable } from "node:stream";
|
|
25546
|
+
import * as zlib from "node:zlib";
|
|
25547
|
+
import { parse as parseToml2 } from "smol-toml";
|
|
24929
25548
|
async function discoverCodexHomes() {
|
|
24930
|
-
const home =
|
|
25549
|
+
const home = homedir9();
|
|
24931
25550
|
return discoverHomes({
|
|
24932
|
-
defaults: [
|
|
25551
|
+
defaults: [path6.join(home, ".codex")],
|
|
24933
25552
|
configured: [process.env.CODEX_HOME],
|
|
24934
25553
|
siblings: [{ parent: home, prefix: ".codex" }],
|
|
24935
25554
|
remember: "codex"
|
|
@@ -24937,7 +25556,7 @@ async function discoverCodexHomes() {
|
|
|
24937
25556
|
}
|
|
24938
25557
|
async function rolloutRoots() {
|
|
24939
25558
|
return (await discoverCodexHomes()).homes.map(
|
|
24940
|
-
(home) =>
|
|
25559
|
+
(home) => path6.join(home, "sessions")
|
|
24941
25560
|
);
|
|
24942
25561
|
}
|
|
24943
25562
|
var ROLLOUT_RE = /^rollout-.*\.jsonl(\.zst)?$/;
|
|
@@ -24947,21 +25566,21 @@ function isRolloutFile(basename6) {
|
|
|
24947
25566
|
async function* walkRollouts(dir) {
|
|
24948
25567
|
let entries;
|
|
24949
25568
|
try {
|
|
24950
|
-
entries = await
|
|
25569
|
+
entries = await readdir6(dir, { withFileTypes: true });
|
|
24951
25570
|
} catch (error) {
|
|
24952
25571
|
if (error?.code !== "ENOENT")
|
|
24953
25572
|
traceError("codex rollout discovery", error, "warn");
|
|
24954
25573
|
return;
|
|
24955
25574
|
}
|
|
24956
25575
|
for (const e of entries) {
|
|
24957
|
-
const full =
|
|
25576
|
+
const full = path6.join(dir, e.name);
|
|
24958
25577
|
if (e.isDirectory()) yield* walkRollouts(full);
|
|
24959
25578
|
else if (e.isFile() && isRolloutFile(e.name)) yield full;
|
|
24960
25579
|
}
|
|
24961
25580
|
}
|
|
24962
25581
|
var createZstdDecompress2 = typeof zlib.createZstdDecompress === "function" ? zlib.createZstdDecompress : null;
|
|
24963
25582
|
var MAX_LINE_BYTES = 64 * 1024 * 1024;
|
|
24964
|
-
async function
|
|
25583
|
+
async function scan3(agg, opts = {}) {
|
|
24965
25584
|
return (await scanWindows(
|
|
24966
25585
|
[{ aggregate: agg, sinceMs: opts.sinceMs, onProgress: opts.onProgress }],
|
|
24967
25586
|
opts
|
|
@@ -24975,7 +25594,7 @@ async function scanWindows(windows, opts = {}) {
|
|
|
24975
25594
|
const discovery = opts.roots ? { homes: [], complete: true } : await discoverCodexHomes();
|
|
24976
25595
|
for (const { stats } of targets)
|
|
24977
25596
|
stats.sourceDiscoveryComplete = discovery.complete;
|
|
24978
|
-
const roots = opts.roots ?? discovery.homes.map((home) =>
|
|
25597
|
+
const roots = opts.roots ?? discovery.homes.map((home) => path6.join(home, "sessions"));
|
|
24979
25598
|
const chosen = /* @__PURE__ */ new Map();
|
|
24980
25599
|
for (const root of roots) {
|
|
24981
25600
|
if (!await exists2(root)) continue;
|
|
@@ -24984,14 +25603,14 @@ async function scanWindows(windows, opts = {}) {
|
|
|
24984
25603
|
let size = -1;
|
|
24985
25604
|
let mtimeMs;
|
|
24986
25605
|
try {
|
|
24987
|
-
const st = await
|
|
25606
|
+
const st = await stat6(file);
|
|
24988
25607
|
size = st.size;
|
|
24989
25608
|
mtimeMs = st.mtimeMs;
|
|
24990
25609
|
} catch (error) {
|
|
24991
25610
|
if (error?.code !== "ENOENT")
|
|
24992
25611
|
traceError("codex rollout stat", error, "warn");
|
|
24993
25612
|
}
|
|
24994
|
-
const key2 =
|
|
25613
|
+
const key2 = path6.basename(file).replace(/\.zst$/, "");
|
|
24995
25614
|
const held = chosen.get(key2);
|
|
24996
25615
|
if (held) {
|
|
24997
25616
|
for (const { stats } of targets) stats.filesSkippedAsDuplicate++;
|
|
@@ -25021,7 +25640,7 @@ async function scanWindows(windows, opts = {}) {
|
|
|
25021
25640
|
stats.filesRead--;
|
|
25022
25641
|
if (outcome.reason === "zstd-unsupported") stats.filesZstdUnsupported++;
|
|
25023
25642
|
stats.unreadableFiles.push({
|
|
25024
|
-
path:
|
|
25643
|
+
path: path6.relative(root, file),
|
|
25025
25644
|
reason: outcome.reason
|
|
25026
25645
|
});
|
|
25027
25646
|
} else if (!outcome.genuine) {
|
|
@@ -25034,14 +25653,14 @@ async function scanWindows(windows, opts = {}) {
|
|
|
25034
25653
|
}
|
|
25035
25654
|
}
|
|
25036
25655
|
}
|
|
25037
|
-
const configFiles = opts.configFile ? [opts.configFile] : discovery.homes.map((home) =>
|
|
25656
|
+
const configFiles = opts.configFile ? [opts.configFile] : discovery.homes.map((home) => path6.join(home, "config.toml"));
|
|
25038
25657
|
for (const { aggregate } of targets)
|
|
25039
25658
|
for (const file of configFiles) readConfiguredMcpServers(aggregate, file);
|
|
25040
25659
|
return targets.map((target) => target.stats);
|
|
25041
25660
|
}
|
|
25042
25661
|
async function exists2(p8) {
|
|
25043
25662
|
try {
|
|
25044
|
-
await
|
|
25663
|
+
await stat6(p8);
|
|
25045
25664
|
return true;
|
|
25046
25665
|
} catch (error) {
|
|
25047
25666
|
if (error?.code !== "ENOENT")
|
|
@@ -25049,31 +25668,31 @@ async function exists2(p8) {
|
|
|
25049
25668
|
return false;
|
|
25050
25669
|
}
|
|
25051
25670
|
}
|
|
25052
|
-
function
|
|
25671
|
+
function errorClass2(e) {
|
|
25053
25672
|
const code2 = e?.code;
|
|
25054
25673
|
if (typeof code2 === "string" && code2.length > 0) return code2;
|
|
25055
25674
|
return e instanceof Error ? e.constructor.name : "unknown";
|
|
25056
25675
|
}
|
|
25057
|
-
var
|
|
25676
|
+
var readError2 = (reason) => Object.assign(new Error(reason), { code: reason });
|
|
25058
25677
|
async function ingestWithRetry(windows, file, opts) {
|
|
25059
25678
|
try {
|
|
25060
25679
|
return await ingestFile2(windows, file, opts);
|
|
25061
25680
|
} catch (e) {
|
|
25062
25681
|
traceError("codex rollout read", e);
|
|
25063
|
-
if (
|
|
25682
|
+
if (errorClass2(e) === "ENOENT" && !file.endsWith(".zst")) {
|
|
25064
25683
|
try {
|
|
25065
25684
|
return await ingestFile2(windows, `${file}.zst`, opts);
|
|
25066
25685
|
} catch (e2) {
|
|
25067
25686
|
traceError("codex compressed rollout retry", e2);
|
|
25068
|
-
return { ok: false, reason:
|
|
25687
|
+
return { ok: false, reason: errorClass2(e2) };
|
|
25069
25688
|
}
|
|
25070
25689
|
}
|
|
25071
|
-
return { ok: false, reason:
|
|
25690
|
+
return { ok: false, reason: errorClass2(e) };
|
|
25072
25691
|
}
|
|
25073
25692
|
}
|
|
25074
25693
|
async function ingestFile2(windows, file, opts) {
|
|
25075
25694
|
const compressed = file.endsWith(".zst");
|
|
25076
|
-
if (compressed && !createZstdDecompress2) throw
|
|
25695
|
+
if (compressed && !createZstdDecompress2) throw readError2("zstd-unsupported");
|
|
25077
25696
|
const handle = await open(file, "r");
|
|
25078
25697
|
try {
|
|
25079
25698
|
const { size } = await handle.stat();
|
|
@@ -25092,7 +25711,7 @@ async function ingestFile2(windows, file, opts) {
|
|
|
25092
25711
|
buffer.length,
|
|
25093
25712
|
position
|
|
25094
25713
|
);
|
|
25095
|
-
if (bytesRead === 0) throw
|
|
25714
|
+
if (bytesRead === 0) throw readError2("rollout-truncated");
|
|
25096
25715
|
position += bytesRead;
|
|
25097
25716
|
yield buffer.subarray(0, bytesRead);
|
|
25098
25717
|
}
|
|
@@ -25118,7 +25737,7 @@ async function ingestFile2(windows, file, opts) {
|
|
|
25118
25737
|
if (count2) nonEmptyLines++;
|
|
25119
25738
|
let record;
|
|
25120
25739
|
try {
|
|
25121
|
-
if (line === null) throw
|
|
25740
|
+
if (line === null) throw readError2("record-too-large");
|
|
25122
25741
|
record = JSON.parse(line);
|
|
25123
25742
|
} catch (error) {
|
|
25124
25743
|
if (count2) {
|
|
@@ -25133,7 +25752,7 @@ async function ingestFile2(windows, file, opts) {
|
|
|
25133
25752
|
} catch (error) {
|
|
25134
25753
|
if (decoder && !sourceError) {
|
|
25135
25754
|
traceError("codex zstd decompression", error);
|
|
25136
|
-
throw
|
|
25755
|
+
throw readError2("zstd-corrupt");
|
|
25137
25756
|
}
|
|
25138
25757
|
throw sourceError ?? error;
|
|
25139
25758
|
} finally {
|
|
@@ -25258,8 +25877,8 @@ var codexAdapter = {
|
|
|
25258
25877
|
);
|
|
25259
25878
|
},
|
|
25260
25879
|
async scan(opts) {
|
|
25261
|
-
const aggregate =
|
|
25262
|
-
const stats = await
|
|
25880
|
+
const aggregate = createAggregate4();
|
|
25881
|
+
const stats = await scan3(aggregate, {
|
|
25263
25882
|
sinceMs: opts.sinceMs,
|
|
25264
25883
|
...opts.onProgress ? { onProgress: opts.onProgress } : {}
|
|
25265
25884
|
});
|
|
@@ -25273,7 +25892,7 @@ var codexAdapter = {
|
|
|
25273
25892
|
},
|
|
25274
25893
|
async scanWindows(options) {
|
|
25275
25894
|
const windows = options.map((opts) => ({
|
|
25276
|
-
aggregate:
|
|
25895
|
+
aggregate: createAggregate4(),
|
|
25277
25896
|
sinceMs: opts.sinceMs,
|
|
25278
25897
|
onProgress: opts.onProgress
|
|
25279
25898
|
}));
|
|
@@ -25290,8 +25909,8 @@ var codexAdapter = {
|
|
|
25290
25909
|
|
|
25291
25910
|
// src/harness/cursor/cache.ts
|
|
25292
25911
|
import { mkdir as mkdir3, readFile as readFile3, rename as rename2, writeFile as writeFile3 } from "node:fs/promises";
|
|
25293
|
-
import { homedir as
|
|
25294
|
-
import
|
|
25912
|
+
import { homedir as homedir14 } from "node:os";
|
|
25913
|
+
import path9 from "node:path";
|
|
25295
25914
|
|
|
25296
25915
|
// src/harness/cursor/account.ts
|
|
25297
25916
|
import { createHash as createHash7 } from "node:crypto";
|
|
@@ -25504,9 +26123,9 @@ function reconcile(local, api) {
|
|
|
25504
26123
|
|
|
25505
26124
|
// src/harness/cursor/local.ts
|
|
25506
26125
|
import { existsSync as existsSync10 } from "node:fs";
|
|
25507
|
-
import { stat as
|
|
25508
|
-
import { homedir as
|
|
25509
|
-
import
|
|
26126
|
+
import { stat as stat7 } from "node:fs/promises";
|
|
26127
|
+
import { homedir as homedir13 } from "node:os";
|
|
26128
|
+
import path8 from "node:path";
|
|
25510
26129
|
import { Worker } from "node:worker_threads";
|
|
25511
26130
|
|
|
25512
26131
|
// src/harness/cursor/composer.ts
|
|
@@ -25710,12 +26329,12 @@ function hasComposerHalf(summary) {
|
|
|
25710
26329
|
|
|
25711
26330
|
// src/harness/cursor/sessionCache.ts
|
|
25712
26331
|
import { mkdir as mkdir2, readFile as readFile2, rename, writeFile as writeFile2 } from "node:fs/promises";
|
|
25713
|
-
import { homedir as
|
|
25714
|
-
import
|
|
26332
|
+
import { homedir as homedir10 } from "node:os";
|
|
26333
|
+
import path7 from "node:path";
|
|
25715
26334
|
import { gunzipSync, gzipSync } from "node:zlib";
|
|
25716
26335
|
var SESSION_CACHE_FORMAT = 1;
|
|
25717
|
-
var defaultSessionCacheDir = () =>
|
|
25718
|
-
var sessionCacheFile = (dir, root, store) =>
|
|
26336
|
+
var defaultSessionCacheDir = () => path7.join(homedir10(), ".config", "aistack", "cursor");
|
|
26337
|
+
var sessionCacheFile = (dir, root, store) => path7.join(dir, `${digest(`${root}\0${store}`)}.sessions.json.gz`);
|
|
25719
26338
|
function sessionStamp(summary, newest) {
|
|
25720
26339
|
if (newest === null) return null;
|
|
25721
26340
|
const count2 = summary.messageCount;
|
|
@@ -25775,7 +26394,7 @@ async function loadSessionCache(file) {
|
|
|
25775
26394
|
return out;
|
|
25776
26395
|
}
|
|
25777
26396
|
async function saveSessionCache(file, cache) {
|
|
25778
|
-
await mkdir2(
|
|
26397
|
+
await mkdir2(path7.dirname(file), { recursive: true, mode: 448 });
|
|
25779
26398
|
const body = gzipSync(
|
|
25780
26399
|
JSON.stringify({
|
|
25781
26400
|
format: SESSION_CACHE_FORMAT,
|
|
@@ -25788,16 +26407,16 @@ async function saveSessionCache(file, cache) {
|
|
|
25788
26407
|
}
|
|
25789
26408
|
|
|
25790
26409
|
// src/harness/cursor/local.ts
|
|
25791
|
-
function dataPath(env = process.env, home =
|
|
25792
|
-
if (env.CURSOR_DATA_PATH) return
|
|
25793
|
-
const base =
|
|
25794
|
-
return
|
|
26410
|
+
function dataPath(env = process.env, home = homedir13(), platform5 = process.platform) {
|
|
26411
|
+
if (env.CURSOR_DATA_PATH) return path8.resolve(env.CURSOR_DATA_PATH);
|
|
26412
|
+
const base = platform5 === "darwin" ? path8.join(home, "Library", "Application Support") : platform5 === "win32" ? env.APPDATA || path8.join(home, "AppData", "Roaming") : env.XDG_CONFIG_HOME || path8.join(home, ".config");
|
|
26413
|
+
return path8.join(base, "Cursor", "User", "workspaceStorage");
|
|
25795
26414
|
}
|
|
25796
|
-
var storeRoot = () => process.env.CURSOR_STORE_ROOT ||
|
|
25797
|
-
var globalDb = (root) =>
|
|
26415
|
+
var storeRoot = () => process.env.CURSOR_STORE_ROOT || path8.join(homedir13(), ".cursor");
|
|
26416
|
+
var globalDb = (root) => path8.join(path8.dirname(root), "globalStorage", "state.vscdb");
|
|
25798
26417
|
async function exists3(file) {
|
|
25799
26418
|
try {
|
|
25800
|
-
await
|
|
26419
|
+
await stat7(file);
|
|
25801
26420
|
return true;
|
|
25802
26421
|
} catch (error) {
|
|
25803
26422
|
return error.code !== "ENOENT";
|
|
@@ -25808,9 +26427,9 @@ async function hasLocalSource(root = dataPath()) {
|
|
|
25808
26427
|
[
|
|
25809
26428
|
root,
|
|
25810
26429
|
globalDb(root),
|
|
25811
|
-
|
|
25812
|
-
|
|
25813
|
-
|
|
26430
|
+
path8.join(storeRoot(), "projects"),
|
|
26431
|
+
path8.join(storeRoot(), "chats"),
|
|
26432
|
+
path8.join(storeRoot(), "acp-sessions")
|
|
25814
26433
|
].map(exists3)
|
|
25815
26434
|
)).some(Boolean);
|
|
25816
26435
|
}
|
|
@@ -25882,7 +26501,7 @@ async function sourceStamp(root) {
|
|
|
25882
26501
|
const values = await Promise.all(
|
|
25883
26502
|
[globalDb(root), `${globalDb(root)}-wal`].map(async (file) => {
|
|
25884
26503
|
try {
|
|
25885
|
-
const info = await
|
|
26504
|
+
const info = await stat7(file);
|
|
25886
26505
|
return `${info.size}:${info.mtimeMs}`;
|
|
25887
26506
|
} catch {
|
|
25888
26507
|
return "unavailable";
|
|
@@ -26271,7 +26890,7 @@ async function readLocalOnce(root, before, onProgress, sourceReadLimits, stallMs
|
|
|
26271
26890
|
}
|
|
26272
26891
|
async function globalDbSize(root) {
|
|
26273
26892
|
try {
|
|
26274
|
-
const info = await
|
|
26893
|
+
const info = await stat7(globalDb(root));
|
|
26275
26894
|
return `${(info.size / 1048576).toFixed(0)} MB`;
|
|
26276
26895
|
} catch {
|
|
26277
26896
|
return "absent";
|
|
@@ -26472,8 +27091,8 @@ var emptyCache = () => ({
|
|
|
26472
27091
|
local: [],
|
|
26473
27092
|
sessions: []
|
|
26474
27093
|
});
|
|
26475
|
-
var cacheFile = (root, store) =>
|
|
26476
|
-
|
|
27094
|
+
var cacheFile = (root, store) => path9.join(
|
|
27095
|
+
homedir14(),
|
|
26477
27096
|
".config",
|
|
26478
27097
|
"aistack",
|
|
26479
27098
|
"cursor",
|
|
@@ -26512,7 +27131,7 @@ async function loadCache(file) {
|
|
|
26512
27131
|
}
|
|
26513
27132
|
}
|
|
26514
27133
|
async function saveCache(file, value) {
|
|
26515
|
-
await mkdir3(
|
|
27134
|
+
await mkdir3(path9.dirname(file), { recursive: true, mode: 448 });
|
|
26516
27135
|
const temporary = `${file}.${process.pid}.${Date.now()}.tmp`;
|
|
26517
27136
|
await writeFile3(temporary, JSON.stringify(value), { mode: 384 });
|
|
26518
27137
|
await rename2(temporary, file);
|
|
@@ -26568,17 +27187,17 @@ function cachedEvents(cache, sessionIds) {
|
|
|
26568
27187
|
}
|
|
26569
27188
|
|
|
26570
27189
|
// src/harness/cursor/roots.ts
|
|
26571
|
-
import { readdir as
|
|
26572
|
-
import { homedir as
|
|
26573
|
-
import
|
|
27190
|
+
import { readdir as readdir7, readFile as readFile4, stat as stat8 } from "node:fs/promises";
|
|
27191
|
+
import { homedir as homedir15 } from "node:os";
|
|
27192
|
+
import path10 from "node:path";
|
|
26574
27193
|
var CURSOR_HOMES_KEY = "cursor";
|
|
26575
27194
|
async function cursorRootFor(dir) {
|
|
26576
27195
|
const expanded = expandHome(dir);
|
|
26577
|
-
if (
|
|
26578
|
-
const user =
|
|
27196
|
+
if (path10.basename(expanded) === "workspaceStorage") return expanded;
|
|
27197
|
+
const user = path10.join(expanded, "User");
|
|
26579
27198
|
try {
|
|
26580
|
-
if ((await
|
|
26581
|
-
return
|
|
27199
|
+
if ((await stat8(user)).isDirectory())
|
|
27200
|
+
return path10.join(user, "workspaceStorage");
|
|
26582
27201
|
} catch {
|
|
26583
27202
|
}
|
|
26584
27203
|
return expanded;
|
|
@@ -26587,7 +27206,7 @@ var FLAG = "--user-data-dir";
|
|
|
26587
27206
|
async function runningUserDataDirs(procDir = "/proc") {
|
|
26588
27207
|
let pids;
|
|
26589
27208
|
try {
|
|
26590
|
-
pids = (await
|
|
27209
|
+
pids = (await readdir7(procDir)).filter((name) => /^\d+$/.test(name));
|
|
26591
27210
|
} catch {
|
|
26592
27211
|
return [];
|
|
26593
27212
|
}
|
|
@@ -26595,12 +27214,12 @@ async function runningUserDataDirs(procDir = "/proc") {
|
|
|
26595
27214
|
for (const pid of pids) {
|
|
26596
27215
|
let args;
|
|
26597
27216
|
try {
|
|
26598
|
-
args = (await readFile4(
|
|
27217
|
+
args = (await readFile4(path10.join(procDir, pid, "cmdline"), "utf8")).split("\0").filter(Boolean);
|
|
26599
27218
|
} catch {
|
|
26600
27219
|
continue;
|
|
26601
27220
|
}
|
|
26602
27221
|
for (const value of userDataDirArgs(args))
|
|
26603
|
-
if (
|
|
27222
|
+
if (path10.isAbsolute(value)) candidates.add(path10.normalize(value));
|
|
26604
27223
|
}
|
|
26605
27224
|
const found = [];
|
|
26606
27225
|
for (const dir of [...candidates].sort())
|
|
@@ -26623,10 +27242,10 @@ function userDataDirArgs(args) {
|
|
|
26623
27242
|
return values;
|
|
26624
27243
|
}
|
|
26625
27244
|
async function holdsCursorData(dir) {
|
|
26626
|
-
const file =
|
|
27245
|
+
const file = path10.join(dir, "User", "globalStorage", "state.vscdb");
|
|
26627
27246
|
let db;
|
|
26628
27247
|
try {
|
|
26629
|
-
if (!(await
|
|
27248
|
+
if (!(await stat8(file)).isFile()) return false;
|
|
26630
27249
|
const { DatabaseSync } = await import("node:sqlite");
|
|
26631
27250
|
db = new DatabaseSync(file, { readOnly: true });
|
|
26632
27251
|
return Boolean(
|
|
@@ -26642,14 +27261,14 @@ async function holdsCursorData(dir) {
|
|
|
26642
27261
|
}
|
|
26643
27262
|
async function discoverCursorRoots(options = {}) {
|
|
26644
27263
|
const env = options.env ?? process.env;
|
|
26645
|
-
const
|
|
27264
|
+
const platform5 = options.platform ?? process.platform;
|
|
26646
27265
|
const fallback = dataPath(
|
|
26647
27266
|
{ ...env, CURSOR_DATA_PATH: void 0 },
|
|
26648
|
-
|
|
26649
|
-
|
|
27267
|
+
homedir15(),
|
|
27268
|
+
platform5
|
|
26650
27269
|
);
|
|
26651
27270
|
const procDir = options.procDir ?? process.env.AISTACK_CURSOR_PROC_DIR ?? "/proc";
|
|
26652
|
-
const running =
|
|
27271
|
+
const running = platform5 === "linux" && procDir ? await runningUserDataDirs(procDir) : [];
|
|
26653
27272
|
const configured = await Promise.all(
|
|
26654
27273
|
[env.CURSOR_DATA_PATH, ...running].filter((dir) => Boolean(dir?.trim())).map(cursorRootFor)
|
|
26655
27274
|
);
|
|
@@ -26662,10 +27281,10 @@ async function discoverCursorRoots(options = {}) {
|
|
|
26662
27281
|
}
|
|
26663
27282
|
|
|
26664
27283
|
// src/harness/cursor/scan.ts
|
|
26665
|
-
import
|
|
27284
|
+
import path12 from "node:path";
|
|
26666
27285
|
|
|
26667
27286
|
// src/harness/cursor/workflow.ts
|
|
26668
|
-
import
|
|
27287
|
+
import path11 from "node:path";
|
|
26669
27288
|
var TOOLS = {
|
|
26670
27289
|
read_file: "Read",
|
|
26671
27290
|
read_file_v2: "Read",
|
|
@@ -26706,7 +27325,7 @@ function projectHistory(options) {
|
|
|
26706
27325
|
const scopes = /* @__PURE__ */ new Map();
|
|
26707
27326
|
const inWindow = (t) => t !== null && t >= sinceMs && t <= now;
|
|
26708
27327
|
for (const { session } of locals) {
|
|
26709
|
-
const projectWorkspace = session.canonicalWorkspacePath &&
|
|
27328
|
+
const projectWorkspace = session.canonicalWorkspacePath && path11.isAbsolute(session.canonicalWorkspacePath) ? session.canonicalWorkspacePath : void 0;
|
|
26710
27329
|
const times = messageTimes(session, api);
|
|
26711
27330
|
const scopeOf = (message) => {
|
|
26712
27331
|
const parent = message.parentMessageId && nativeOwners.get(message.parentMessageId);
|
|
@@ -26793,7 +27412,7 @@ function projectHistory(options) {
|
|
|
26793
27412
|
session: row.sidechain ? `${row.session}:sidechain` : row.session,
|
|
26794
27413
|
sidechain: row.sidechain
|
|
26795
27414
|
},
|
|
26796
|
-
...project &&
|
|
27415
|
+
...project && path11.isAbsolute(project) ? { projectWorkspace: project } : {},
|
|
26797
27416
|
type: "response",
|
|
26798
27417
|
tsMs: row.tsMs,
|
|
26799
27418
|
responseId: `${row.source}:${row.id ?? index}`,
|
|
@@ -26896,7 +27515,7 @@ function addStats(into, from) {
|
|
|
26896
27515
|
if (from.sourceDiscoveryComplete === false)
|
|
26897
27516
|
into.sourceDiscoveryComplete = false;
|
|
26898
27517
|
}
|
|
26899
|
-
async function
|
|
27518
|
+
async function scan4(options) {
|
|
26900
27519
|
const now = options.now ?? Date.now();
|
|
26901
27520
|
let discoveryComplete = true;
|
|
26902
27521
|
let roots = options.roots ?? (options.root ? [options.root] : void 0);
|
|
@@ -26971,7 +27590,7 @@ async function scan3(options) {
|
|
|
26971
27590
|
aggregate.byModel.set(model, emptyUsage());
|
|
26972
27591
|
}
|
|
26973
27592
|
const project = session.canonicalWorkspacePath;
|
|
26974
|
-
if (project &&
|
|
27593
|
+
if (project && path12.isAbsolute(project)) aggregate.projectDirs.add(project);
|
|
26975
27594
|
if (session.metadata?.cursorVersion)
|
|
26976
27595
|
aggregate.ccVersions.add(session.metadata.cursorVersion);
|
|
26977
27596
|
let firstTime = null;
|
|
@@ -27028,7 +27647,7 @@ async function scan3(options) {
|
|
|
27028
27647
|
else aggregate.mainTokens += countsTotal(counts2);
|
|
27029
27648
|
noteSessionStart(aggregate, session, tsMs);
|
|
27030
27649
|
const project = sessions.get(session)?.session.canonicalWorkspacePath;
|
|
27031
|
-
if (project &&
|
|
27650
|
+
if (project && path12.isAbsolute(project))
|
|
27032
27651
|
noteProjectDay(aggregate, project, tsMs);
|
|
27033
27652
|
}
|
|
27034
27653
|
aggregate.files = local.stats.filesRead;
|
|
@@ -27070,11 +27689,11 @@ var cursorAdapter = {
|
|
|
27070
27689
|
}
|
|
27071
27690
|
return false;
|
|
27072
27691
|
},
|
|
27073
|
-
scan:
|
|
27692
|
+
scan: scan4
|
|
27074
27693
|
};
|
|
27075
27694
|
|
|
27076
27695
|
// src/harness/grok/analyzer.ts
|
|
27077
|
-
function
|
|
27696
|
+
function createAggregate5() {
|
|
27078
27697
|
const workflowLocal = createWorkflowLocalSources();
|
|
27079
27698
|
return Object.assign(createAggregate(), {
|
|
27080
27699
|
workflow: createHarnessWorkflowReducer("grok-build", workflowLocal),
|
|
@@ -27098,7 +27717,7 @@ function ingestUpdate(agg, state, value, projectDir, sinceMs) {
|
|
|
27098
27717
|
const params = root && asObj(root.params);
|
|
27099
27718
|
const update2 = params && asObj(params.update);
|
|
27100
27719
|
const session = params && asStr(params.sessionId);
|
|
27101
|
-
const tsMs =
|
|
27720
|
+
const tsMs = timestampMs2(
|
|
27102
27721
|
asObj(params?._meta)?.agentTimestampMs ?? root?.timestamp
|
|
27103
27722
|
);
|
|
27104
27723
|
if (!update2 || !session || tsMs === null) return;
|
|
@@ -27186,7 +27805,7 @@ function ingestEvent2(agg, state, value, sessionFallback, projectDir, sinceMs) {
|
|
|
27186
27805
|
const row = asObj(value);
|
|
27187
27806
|
if (!row) return;
|
|
27188
27807
|
const session = asStr(row.session_id) ?? sessionFallback;
|
|
27189
|
-
const tsMs =
|
|
27808
|
+
const tsMs = timestampMs2(row.ts);
|
|
27190
27809
|
if (!session || tsMs === null) return;
|
|
27191
27810
|
if (asStr(row.type) === "tool_started") {
|
|
27192
27811
|
const id = asStr(row.tool_call_id);
|
|
@@ -27207,7 +27826,7 @@ function ingestEvent2(agg, state, value, sessionFallback, projectDir, sinceMs) {
|
|
|
27207
27826
|
});
|
|
27208
27827
|
}
|
|
27209
27828
|
}
|
|
27210
|
-
var
|
|
27829
|
+
var timestampMs2 = (value) => {
|
|
27211
27830
|
if (typeof value === "string") {
|
|
27212
27831
|
const parsed = Date.parse(value);
|
|
27213
27832
|
return Number.isFinite(parsed) ? parsed : null;
|
|
@@ -27240,7 +27859,7 @@ function sidecarContributions(value, projectDir) {
|
|
|
27240
27859
|
const out = [];
|
|
27241
27860
|
for (const raw of turns) {
|
|
27242
27861
|
const turn = asObj(raw);
|
|
27243
|
-
const tsMs = turn &&
|
|
27862
|
+
const tsMs = turn && timestampMs2(turn.endedAt);
|
|
27244
27863
|
if (!turn || tsMs === null) continue;
|
|
27245
27864
|
const models = [];
|
|
27246
27865
|
const perModel = asObj(turn.modelUsage);
|
|
@@ -27272,7 +27891,7 @@ function terminalContribution(value, projectDir) {
|
|
|
27272
27891
|
if (!update2 || asStr(update2.sessionUpdate) !== "turn_completed") return null;
|
|
27273
27892
|
const usage = asObj(update2.usage);
|
|
27274
27893
|
const sessionId = params && asStr(params.sessionId);
|
|
27275
|
-
const tsMs =
|
|
27894
|
+
const tsMs = timestampMs2(meta?.agentTimestampMs ?? root?.timestamp);
|
|
27276
27895
|
if (!usage || !sessionId || tsMs === null) return null;
|
|
27277
27896
|
const models = [];
|
|
27278
27897
|
for (const [model, row] of Object.entries(asObj(usage.modelUsage) ?? {})) {
|
|
@@ -27317,17 +27936,17 @@ function ingestContribution(agg, row) {
|
|
|
27317
27936
|
|
|
27318
27937
|
// src/harness/grok/scan.ts
|
|
27319
27938
|
import { createReadStream as createReadStream2 } from "node:fs";
|
|
27320
|
-
import { readdir as
|
|
27321
|
-
import { homedir as
|
|
27322
|
-
import
|
|
27939
|
+
import { readdir as readdir9, readFile as readFile6, stat as stat9 } from "node:fs/promises";
|
|
27940
|
+
import { homedir as homedir17 } from "node:os";
|
|
27941
|
+
import path14 from "node:path";
|
|
27323
27942
|
import readline2 from "node:readline";
|
|
27324
27943
|
import { parse as parseToml3 } from "smol-toml";
|
|
27325
27944
|
|
|
27326
27945
|
// src/harness/grok/context.ts
|
|
27327
27946
|
import { createHash as createHash8 } from "node:crypto";
|
|
27328
|
-
import { appendFile, mkdir as mkdir4, readdir as
|
|
27329
|
-
import { homedir as
|
|
27330
|
-
import
|
|
27947
|
+
import { appendFile, mkdir as mkdir4, readdir as readdir8, readFile as readFile5, unlink as unlink2 } from "node:fs/promises";
|
|
27948
|
+
import { homedir as homedir16 } from "node:os";
|
|
27949
|
+
import path13 from "node:path";
|
|
27331
27950
|
var DAY_MS = 864e5;
|
|
27332
27951
|
var hash = (value) => createHash8("sha256").update(value).digest("hex");
|
|
27333
27952
|
function contextCall(value) {
|
|
@@ -27350,12 +27969,12 @@ function contextCall(value) {
|
|
|
27350
27969
|
};
|
|
27351
27970
|
}
|
|
27352
27971
|
function contextCacheDirectory(root) {
|
|
27353
|
-
return
|
|
27354
|
-
|
|
27972
|
+
return path13.join(
|
|
27973
|
+
homedir16(),
|
|
27355
27974
|
".config",
|
|
27356
27975
|
"aistack",
|
|
27357
27976
|
"grok-context",
|
|
27358
|
-
hash(
|
|
27977
|
+
hash(path13.resolve(root))
|
|
27359
27978
|
);
|
|
27360
27979
|
}
|
|
27361
27980
|
async function optionalRead(file) {
|
|
@@ -27371,21 +27990,21 @@ async function retainedContextCalls(root, sessions, cacheDir = contextCacheDirec
|
|
|
27371
27990
|
const calls = /* @__PURE__ */ new Map();
|
|
27372
27991
|
let files = [];
|
|
27373
27992
|
try {
|
|
27374
|
-
files = await
|
|
27993
|
+
files = await readdir8(cacheDir);
|
|
27375
27994
|
} catch (error) {
|
|
27376
27995
|
if (error.code !== "ENOENT") throw error;
|
|
27377
27996
|
}
|
|
27378
27997
|
for (const file of files) {
|
|
27379
27998
|
if (!/^\d{4}-\d{2}-\d{2}\.jsonl$/.test(file)) continue;
|
|
27380
27999
|
if (Date.parse(file.slice(0, 10)) + DAY_MS < cutoff) {
|
|
27381
|
-
await unlink2(
|
|
28000
|
+
await unlink2(path13.join(cacheDir, file)).catch(
|
|
27382
28001
|
(error) => {
|
|
27383
28002
|
if (error.code !== "ENOENT") throw error;
|
|
27384
28003
|
}
|
|
27385
28004
|
);
|
|
27386
28005
|
continue;
|
|
27387
28006
|
}
|
|
27388
|
-
const raw2 = await optionalRead(
|
|
28007
|
+
const raw2 = await optionalRead(path13.join(cacheDir, file));
|
|
27389
28008
|
if (raw2 && !raw2.endsWith("\n"))
|
|
27390
28009
|
throw Object.assign(new Error("Incomplete Grok context cache"), {
|
|
27391
28010
|
code: "GROK_INCOMPLETE_CONTEXT_CACHE"
|
|
@@ -27406,7 +28025,7 @@ async function retainedContextCalls(root, sessions, cacheDir = contextCacheDirec
|
|
|
27406
28025
|
}
|
|
27407
28026
|
}
|
|
27408
28027
|
const raw = await optionalRead(
|
|
27409
|
-
|
|
28028
|
+
path13.join(root, "..", "logs", "unified.jsonl")
|
|
27410
28029
|
);
|
|
27411
28030
|
const additions = /* @__PURE__ */ new Map();
|
|
27412
28031
|
for (const line of raw.slice(0, raw.lastIndexOf("\n") + 1).split("\n")) {
|
|
@@ -27429,7 +28048,7 @@ async function retainedContextCalls(root, sessions, cacheDir = contextCacheDirec
|
|
|
27429
28048
|
await mkdir4(cacheDir, { recursive: true, mode: 448 });
|
|
27430
28049
|
for (const [date, lines2] of additions) {
|
|
27431
28050
|
await appendFile(
|
|
27432
|
-
|
|
28051
|
+
path13.join(cacheDir, `${date}.jsonl`),
|
|
27433
28052
|
`${lines2.join("\n")}
|
|
27434
28053
|
`,
|
|
27435
28054
|
{ mode: 384 }
|
|
@@ -27441,9 +28060,9 @@ async function retainedContextCalls(root, sessions, cacheDir = contextCacheDirec
|
|
|
27441
28060
|
|
|
27442
28061
|
// src/harness/grok/scan.ts
|
|
27443
28062
|
async function discoverGrokHomes() {
|
|
27444
|
-
const home =
|
|
28063
|
+
const home = homedir17();
|
|
27445
28064
|
return discoverHomes({
|
|
27446
|
-
defaults: [
|
|
28065
|
+
defaults: [path14.join(home, ".grok")],
|
|
27447
28066
|
configured: [process.env.GROK_HOME],
|
|
27448
28067
|
siblings: [{ parent: home, prefix: ".grok" }],
|
|
27449
28068
|
remember: "grok-build"
|
|
@@ -27451,14 +28070,14 @@ async function discoverGrokHomes() {
|
|
|
27451
28070
|
}
|
|
27452
28071
|
async function sessionRoots() {
|
|
27453
28072
|
return (await discoverGrokHomes()).homes.map(
|
|
27454
|
-
(home) =>
|
|
28073
|
+
(home) => path14.join(home, "sessions")
|
|
27455
28074
|
);
|
|
27456
28075
|
}
|
|
27457
28076
|
async function evidenceBytes(dir) {
|
|
27458
28077
|
let total = 0;
|
|
27459
28078
|
for (const name of ["usage.json", "updates.jsonl", "events.jsonl"]) {
|
|
27460
28079
|
try {
|
|
27461
|
-
total += (await
|
|
28080
|
+
total += (await stat9(path14.join(dir, name))).size;
|
|
27462
28081
|
} catch (error) {
|
|
27463
28082
|
if (error?.code !== "ENOENT")
|
|
27464
28083
|
traceError("grok evidence stat", error, "warn");
|
|
@@ -27473,7 +28092,7 @@ async function stableRead(file, jsonl) {
|
|
|
27473
28092
|
for (const delay of delays) {
|
|
27474
28093
|
if (delay) await pause(delay);
|
|
27475
28094
|
try {
|
|
27476
|
-
const before = await
|
|
28095
|
+
const before = await stat9(file);
|
|
27477
28096
|
if (!before.isFile()) return { complete: false };
|
|
27478
28097
|
if (jsonl) {
|
|
27479
28098
|
const lines2 = [];
|
|
@@ -27491,12 +28110,12 @@ async function stableRead(file, jsonl) {
|
|
|
27491
28110
|
lines2.push(null);
|
|
27492
28111
|
}
|
|
27493
28112
|
}
|
|
27494
|
-
const after = await
|
|
28113
|
+
const after = await stat9(file);
|
|
27495
28114
|
if (before.size === after.size && before.mtimeMs === after.mtimeMs)
|
|
27496
28115
|
return { lines: lines2, complete: true };
|
|
27497
28116
|
} else {
|
|
27498
28117
|
const raw = await readFile6(file, "utf8");
|
|
27499
|
-
const after = await
|
|
28118
|
+
const after = await stat9(file);
|
|
27500
28119
|
if (before.size === after.size && before.mtimeMs === after.mtimeMs)
|
|
27501
28120
|
return { json: JSON.parse(raw), complete: true };
|
|
27502
28121
|
}
|
|
@@ -27509,16 +28128,16 @@ async function stableRead(file, jsonl) {
|
|
|
27509
28128
|
}
|
|
27510
28129
|
function absoluteCwd(value) {
|
|
27511
28130
|
const cwd = asStr(value);
|
|
27512
|
-
return cwd &&
|
|
28131
|
+
return cwd && path14.isAbsolute(cwd) && !cwd.includes("\0") ? cwd : void 0;
|
|
27513
28132
|
}
|
|
27514
28133
|
async function workspaceCwd(workspacePath, entries) {
|
|
27515
28134
|
try {
|
|
27516
|
-
const cwd = absoluteCwd(decodeURIComponent(
|
|
28135
|
+
const cwd = absoluteCwd(decodeURIComponent(path14.basename(workspacePath)));
|
|
27517
28136
|
if (cwd !== void 0) return cwd;
|
|
27518
28137
|
} catch {
|
|
27519
28138
|
}
|
|
27520
28139
|
if (entries.some((entry) => entry.name === ".cwd" && entry.isFile())) {
|
|
27521
|
-
const raw = await readFile6(
|
|
28140
|
+
const raw = await readFile6(path14.join(workspacePath, ".cwd"), "utf8").catch(
|
|
27522
28141
|
() => void 0
|
|
27523
28142
|
);
|
|
27524
28143
|
return absoluteCwd(raw);
|
|
@@ -27526,18 +28145,18 @@ async function workspaceCwd(workspacePath, entries) {
|
|
|
27526
28145
|
}
|
|
27527
28146
|
async function directories(root) {
|
|
27528
28147
|
try {
|
|
27529
|
-
const workspaces = await
|
|
28148
|
+
const workspaces = await readdir9(root, { withFileTypes: true });
|
|
27530
28149
|
const out = [];
|
|
27531
28150
|
for (const workspace of workspaces) {
|
|
27532
28151
|
if (!workspace.isDirectory() || workspace.isSymbolicLink()) continue;
|
|
27533
|
-
const workspacePath =
|
|
27534
|
-
const entries = await
|
|
28152
|
+
const workspacePath = path14.join(root, workspace.name);
|
|
28153
|
+
const entries = await readdir9(workspacePath, {
|
|
27535
28154
|
withFileTypes: true
|
|
27536
28155
|
});
|
|
27537
28156
|
const cwd = await workspaceCwd(workspacePath, entries);
|
|
27538
28157
|
for (const session of entries) {
|
|
27539
28158
|
if (session.isDirectory() && !session.isSymbolicLink())
|
|
27540
|
-
out.push({ dir:
|
|
28159
|
+
out.push({ dir: path14.join(workspacePath, session.name), cwd });
|
|
27541
28160
|
}
|
|
27542
28161
|
}
|
|
27543
28162
|
return out.sort((a, b) => {
|
|
@@ -27554,7 +28173,7 @@ async function modelAliasesForRoot(root) {
|
|
|
27554
28173
|
if (process.env.GROK_MODELS_BASE_URL) return /* @__PURE__ */ new Map();
|
|
27555
28174
|
try {
|
|
27556
28175
|
const parsed = asObj(
|
|
27557
|
-
parseToml3(await readFile6(
|
|
28176
|
+
parseToml3(await readFile6(path14.join(root, "..", "config.toml"), "utf8"))
|
|
27558
28177
|
);
|
|
27559
28178
|
if (!parsed || asObj(parsed.endpoints)?.models_base_url) return /* @__PURE__ */ new Map();
|
|
27560
28179
|
const models = asObj(parsed.model);
|
|
@@ -27570,7 +28189,7 @@ async function modelAliasesForRoot(root) {
|
|
|
27570
28189
|
return /* @__PURE__ */ new Map();
|
|
27571
28190
|
}
|
|
27572
28191
|
}
|
|
27573
|
-
async function
|
|
28192
|
+
async function scan5(agg, opts = {}) {
|
|
27574
28193
|
return (await scanWindows2(
|
|
27575
28194
|
[{ aggregate: agg, sinceMs: opts.sinceMs, onProgress: opts.onProgress }],
|
|
27576
28195
|
opts
|
|
@@ -27585,14 +28204,14 @@ async function scanWindows2(windows, opts = {}) {
|
|
|
27585
28204
|
}));
|
|
27586
28205
|
const discovery = opts.roots ? { homes: [], complete: true } : await discoverGrokHomes();
|
|
27587
28206
|
let complete = discovery.complete;
|
|
27588
|
-
const roots = opts.roots ?? discovery.homes.map((home) =>
|
|
28207
|
+
const roots = opts.roots ?? discovery.homes.map((home) => path14.join(home, "sessions"));
|
|
27589
28208
|
const listed = /* @__PURE__ */ new Map();
|
|
27590
28209
|
const fullest = /* @__PURE__ */ new Map();
|
|
27591
28210
|
for (const root of roots) {
|
|
27592
28211
|
const dirs = await directories(root);
|
|
27593
28212
|
listed.set(root, dirs);
|
|
27594
28213
|
for (const { dir } of dirs ?? []) {
|
|
27595
|
-
const key2 =
|
|
28214
|
+
const key2 = path14.relative(root, dir);
|
|
27596
28215
|
const bytes = await evidenceBytes(dir);
|
|
27597
28216
|
const held = fullest.get(key2);
|
|
27598
28217
|
if (!held || bytes > held.bytes) fullest.set(key2, { dir, bytes });
|
|
@@ -27607,13 +28226,13 @@ async function scanWindows2(windows, opts = {}) {
|
|
|
27607
28226
|
continue;
|
|
27608
28227
|
}
|
|
27609
28228
|
for (const { dir, cwd } of dirs) {
|
|
27610
|
-
if (fullest.get(
|
|
28229
|
+
if (fullest.get(path14.relative(root, dir))?.dir !== dir) {
|
|
27611
28230
|
stats.filesSkippedAsDuplicate++;
|
|
27612
28231
|
continue;
|
|
27613
28232
|
}
|
|
27614
28233
|
let entries;
|
|
27615
28234
|
try {
|
|
27616
|
-
entries = await
|
|
28235
|
+
entries = await readdir9(dir, { withFileTypes: true });
|
|
27617
28236
|
} catch (error) {
|
|
27618
28237
|
traceError("grok session listing", error);
|
|
27619
28238
|
complete = false;
|
|
@@ -27622,10 +28241,10 @@ async function scanWindows2(windows, opts = {}) {
|
|
|
27622
28241
|
const files = new Map(
|
|
27623
28242
|
entries.filter(
|
|
27624
28243
|
(e) => e.isFile() && (isGrokEvidenceFile(e.name) || e.name === "summary.json")
|
|
27625
|
-
).map((e) => [e.name,
|
|
28244
|
+
).map((e) => [e.name, path14.join(dir, e.name)])
|
|
27626
28245
|
);
|
|
27627
28246
|
let projectDir = cwd;
|
|
27628
|
-
let sessionFallback =
|
|
28247
|
+
let sessionFallback = path14.basename(dir);
|
|
27629
28248
|
let child = false;
|
|
27630
28249
|
let parentSession;
|
|
27631
28250
|
const summary = files.get("summary.json");
|
|
@@ -27803,8 +28422,8 @@ var grokAdapter = {
|
|
|
27803
28422
|
opts.sinceMs
|
|
27804
28423
|
),
|
|
27805
28424
|
async scan(opts) {
|
|
27806
|
-
const aggregate =
|
|
27807
|
-
const result = await
|
|
28425
|
+
const aggregate = createAggregate5();
|
|
28426
|
+
const result = await scan5(aggregate, opts);
|
|
27808
28427
|
return {
|
|
27809
28428
|
aggregate,
|
|
27810
28429
|
stats: result.stats,
|
|
@@ -27816,7 +28435,7 @@ var grokAdapter = {
|
|
|
27816
28435
|
},
|
|
27817
28436
|
async scanWindows(options) {
|
|
27818
28437
|
const windows = options.map((opts) => ({
|
|
27819
|
-
aggregate:
|
|
28438
|
+
aggregate: createAggregate5(),
|
|
27820
28439
|
sinceMs: opts.sinceMs,
|
|
27821
28440
|
onProgress: opts.onProgress
|
|
27822
28441
|
}));
|
|
@@ -27851,7 +28470,7 @@ var OPENCODE_BUILTIN_TOOLS = /* @__PURE__ */ new Set([
|
|
|
27851
28470
|
"websearch",
|
|
27852
28471
|
"write"
|
|
27853
28472
|
]);
|
|
27854
|
-
function
|
|
28473
|
+
function createAggregate6() {
|
|
27855
28474
|
const workflowLocal = createWorkflowLocalSources();
|
|
27856
28475
|
return Object.assign(createAggregate(), {
|
|
27857
28476
|
workflow: createHarnessWorkflowReducer("opencode", workflowLocal),
|
|
@@ -28026,15 +28645,15 @@ function ingestTypedSkill2(agg, row) {
|
|
|
28026
28645
|
|
|
28027
28646
|
// src/harness/opencode/scan.ts
|
|
28028
28647
|
import { readFileSync as readFileSync12 } from "node:fs";
|
|
28029
|
-
import { readdir as
|
|
28030
|
-
import { homedir as
|
|
28031
|
-
import
|
|
28648
|
+
import { readdir as readdir10, realpath as realpath5, stat as stat10 } from "node:fs/promises";
|
|
28649
|
+
import { homedir as homedir18 } from "node:os";
|
|
28650
|
+
import path15 from "node:path";
|
|
28032
28651
|
var OPENCODE_MIGRATION_CEILING = 20260622202450;
|
|
28033
28652
|
async function opencodeDataDirs() {
|
|
28034
28653
|
const xdg = process.env.XDG_DATA_HOME?.trim();
|
|
28035
28654
|
return discoverHomes({
|
|
28036
|
-
defaults: [
|
|
28037
|
-
configured: [xdg ?
|
|
28655
|
+
defaults: [path15.join(homedir18(), ".local", "share", "opencode")],
|
|
28656
|
+
configured: [xdg ? path15.join(xdg, "opencode") : void 0],
|
|
28038
28657
|
remember: "opencode"
|
|
28039
28658
|
});
|
|
28040
28659
|
}
|
|
@@ -28043,23 +28662,23 @@ function isStoreFile(basename6) {
|
|
|
28043
28662
|
}
|
|
28044
28663
|
async function dbFilesIn(root) {
|
|
28045
28664
|
try {
|
|
28046
|
-
const entries = await
|
|
28047
|
-
return entries.filter((e) => e.isFile() && isStoreFile(e.name)).map((e) =>
|
|
28665
|
+
const entries = await readdir10(root, { withFileTypes: true });
|
|
28666
|
+
return entries.filter((e) => e.isFile() && isStoreFile(e.name)).map((e) => path15.join(root, e.name)).sort();
|
|
28048
28667
|
} catch (error) {
|
|
28049
28668
|
if (error?.code !== "ENOENT")
|
|
28050
28669
|
traceError("opencode database discovery", error, "warn");
|
|
28051
28670
|
return [];
|
|
28052
28671
|
}
|
|
28053
28672
|
}
|
|
28054
|
-
async function
|
|
28673
|
+
async function storeFiles2(roots) {
|
|
28055
28674
|
const dirs = roots ?? (await opencodeDataDirs()).homes;
|
|
28056
28675
|
const candidates = [];
|
|
28057
28676
|
for (const root of dirs) candidates.push(...await dbFilesIn(root));
|
|
28058
28677
|
const override = roots ? void 0 : process.env.OPENCODE_DB?.trim();
|
|
28059
28678
|
if (override)
|
|
28060
28679
|
candidates.push(
|
|
28061
|
-
|
|
28062
|
-
process.env.XDG_DATA_HOME?.trim() ||
|
|
28680
|
+
path15.resolve(
|
|
28681
|
+
process.env.XDG_DATA_HOME?.trim() || path15.join(homedir18(), ".local", "share"),
|
|
28063
28682
|
"opencode",
|
|
28064
28683
|
override
|
|
28065
28684
|
)
|
|
@@ -28069,7 +28688,7 @@ async function storeFiles(roots) {
|
|
|
28069
28688
|
for (const file of candidates) {
|
|
28070
28689
|
let key2 = file;
|
|
28071
28690
|
try {
|
|
28072
|
-
key2 = await
|
|
28691
|
+
key2 = await realpath5(file);
|
|
28073
28692
|
} catch (error) {
|
|
28074
28693
|
if (error?.code !== "ENOENT")
|
|
28075
28694
|
traceError("opencode database path resolution", error, "warn");
|
|
@@ -28080,7 +28699,7 @@ async function storeFiles(roots) {
|
|
|
28080
28699
|
}
|
|
28081
28700
|
return files;
|
|
28082
28701
|
}
|
|
28083
|
-
async function
|
|
28702
|
+
async function loadSqlite2() {
|
|
28084
28703
|
try {
|
|
28085
28704
|
const mod = await import("node:sqlite");
|
|
28086
28705
|
if (typeof mod.DatabaseSync !== "function") return null;
|
|
@@ -28091,31 +28710,31 @@ async function loadSqlite() {
|
|
|
28091
28710
|
return null;
|
|
28092
28711
|
}
|
|
28093
28712
|
}
|
|
28094
|
-
function
|
|
28713
|
+
function errorClass3(e) {
|
|
28095
28714
|
const code2 = e?.code;
|
|
28096
28715
|
if (typeof code2 === "string" && code2.length > 0) return code2;
|
|
28097
28716
|
return e instanceof Error ? e.constructor.name : "unknown";
|
|
28098
28717
|
}
|
|
28099
|
-
var
|
|
28100
|
-
async function
|
|
28718
|
+
var readError3 = (reason) => Object.assign(new Error(reason), { code: reason });
|
|
28719
|
+
async function scan6(agg, opts = {}) {
|
|
28101
28720
|
const stats = emptyScanStats();
|
|
28102
|
-
const open4 = await
|
|
28721
|
+
const open4 = await loadSqlite2();
|
|
28103
28722
|
const sinceMs = opts.sinceMs ?? 0;
|
|
28104
28723
|
const state = createDbFoldState();
|
|
28105
28724
|
readConfiguredMcpServers2(agg, state, opts.configFile);
|
|
28106
|
-
for (const file of await
|
|
28725
|
+
for (const file of await storeFiles2(opts.roots)) {
|
|
28107
28726
|
stats.filesFound++;
|
|
28108
28727
|
agg.files++;
|
|
28109
28728
|
try {
|
|
28110
|
-
if (open4 === null) throw
|
|
28729
|
+
if (open4 === null) throw readError3("sqlite-unsupported");
|
|
28111
28730
|
readDb(agg, state, open4, file, sinceMs);
|
|
28112
28731
|
stats.filesRead++;
|
|
28113
28732
|
} catch (e) {
|
|
28114
28733
|
traceError("opencode database read", e);
|
|
28115
28734
|
stats.filesUnreadable++;
|
|
28116
28735
|
stats.unreadableFiles.push({
|
|
28117
|
-
path:
|
|
28118
|
-
reason:
|
|
28736
|
+
path: path15.basename(file),
|
|
28737
|
+
reason: errorClass3(e)
|
|
28119
28738
|
});
|
|
28120
28739
|
}
|
|
28121
28740
|
if (opts.onProgress) opts.onProgress(stats.filesFound);
|
|
@@ -28129,11 +28748,11 @@ function checkMigrationCeiling(db) {
|
|
|
28129
28748
|
} catch (error) {
|
|
28130
28749
|
if (error?.code !== "ENOENT")
|
|
28131
28750
|
traceError("opencode database close", error, "warn");
|
|
28132
|
-
throw
|
|
28751
|
+
throw readError3("schema-unversioned");
|
|
28133
28752
|
}
|
|
28134
28753
|
const prefix = Number.parseInt(String(newest ?? ""), 10);
|
|
28135
|
-
if (!Number.isFinite(prefix)) throw
|
|
28136
|
-
if (prefix > OPENCODE_MIGRATION_CEILING) throw
|
|
28754
|
+
if (!Number.isFinite(prefix)) throw readError3("schema-unversioned");
|
|
28755
|
+
if (prefix > OPENCODE_MIGRATION_CEILING) throw readError3("schema-too-new");
|
|
28137
28756
|
}
|
|
28138
28757
|
function readDb(agg, state, open4, file, sinceMs) {
|
|
28139
28758
|
const db = open4(file);
|
|
@@ -28300,8 +28919,8 @@ function pickTs(jsonTs, columnTs) {
|
|
|
28300
28919
|
}
|
|
28301
28920
|
function opencodeConfigFile() {
|
|
28302
28921
|
const xdg = process.env.XDG_CONFIG_HOME;
|
|
28303
|
-
const base = xdg ||
|
|
28304
|
-
return
|
|
28922
|
+
const base = xdg || path15.join(homedir18(), ".config");
|
|
28923
|
+
return path15.join(base, "opencode", "opencode.json");
|
|
28305
28924
|
}
|
|
28306
28925
|
function readConfiguredMcpServers2(agg, state, configFile) {
|
|
28307
28926
|
const file = configFile ?? opencodeConfigFile();
|
|
@@ -28351,9 +28970,9 @@ function stripJsonc(text) {
|
|
|
28351
28970
|
return out.replace(/,(\s*[}\]])/g, "$1");
|
|
28352
28971
|
}
|
|
28353
28972
|
async function detectOpencode(opts) {
|
|
28354
|
-
const open4 = await
|
|
28973
|
+
const open4 = await loadSqlite2();
|
|
28355
28974
|
if (open4 === null) return false;
|
|
28356
|
-
for (const file of await
|
|
28975
|
+
for (const file of await storeFiles2(opts.roots)) {
|
|
28357
28976
|
if (!await exists4(file)) continue;
|
|
28358
28977
|
let db = null;
|
|
28359
28978
|
try {
|
|
@@ -28378,7 +28997,7 @@ async function detectOpencode(opts) {
|
|
|
28378
28997
|
}
|
|
28379
28998
|
async function exists4(p8) {
|
|
28380
28999
|
try {
|
|
28381
|
-
await
|
|
29000
|
+
await stat10(p8);
|
|
28382
29001
|
return true;
|
|
28383
29002
|
} catch (error) {
|
|
28384
29003
|
if (error?.code !== "ENOENT")
|
|
@@ -28399,8 +29018,8 @@ var opencodeAdapter = {
|
|
|
28399
29018
|
});
|
|
28400
29019
|
},
|
|
28401
29020
|
async scan(opts) {
|
|
28402
|
-
const aggregate =
|
|
28403
|
-
const stats = await
|
|
29021
|
+
const aggregate = createAggregate6();
|
|
29022
|
+
const stats = await scan6(aggregate, {
|
|
28404
29023
|
sinceMs: opts.sinceMs,
|
|
28405
29024
|
...opts.onProgress ? { onProgress: opts.onProgress } : {}
|
|
28406
29025
|
});
|
|
@@ -28414,14 +29033,14 @@ var opencodeAdapter = {
|
|
|
28414
29033
|
};
|
|
28415
29034
|
|
|
28416
29035
|
// src/harness/pi/analyzer.ts
|
|
28417
|
-
function
|
|
29036
|
+
function createAggregate7() {
|
|
28418
29037
|
const workflowLocal = createWorkflowLocalSources();
|
|
28419
29038
|
return Object.assign(createAggregate(), {
|
|
28420
29039
|
workflow: createHarnessWorkflowReducer("pi-mono", workflowLocal),
|
|
28421
29040
|
workflowLocal
|
|
28422
29041
|
});
|
|
28423
29042
|
}
|
|
28424
|
-
function
|
|
29043
|
+
function createFoldState2() {
|
|
28425
29044
|
return { seenUsage: /* @__PURE__ */ new Set() };
|
|
28426
29045
|
}
|
|
28427
29046
|
function createFileState2() {
|
|
@@ -28608,17 +29227,17 @@ function readCounts2(usageRaw) {
|
|
|
28608
29227
|
|
|
28609
29228
|
// src/harness/pi/scan.ts
|
|
28610
29229
|
import { createReadStream as createReadStream3 } from "node:fs";
|
|
28611
|
-
import { readdir as
|
|
28612
|
-
import { homedir as
|
|
28613
|
-
import
|
|
29230
|
+
import { readdir as readdir11, realpath as realpath6, stat as stat11 } from "node:fs/promises";
|
|
29231
|
+
import { homedir as homedir19 } from "node:os";
|
|
29232
|
+
import path16 from "node:path";
|
|
28614
29233
|
import readline3 from "node:readline";
|
|
28615
29234
|
var MAX_SESSION_VERSION = 3;
|
|
28616
29235
|
async function discoverSessionRoots() {
|
|
28617
29236
|
const agentDir = process.env.PI_CODING_AGENT_DIR?.trim();
|
|
28618
29237
|
return discoverHomes({
|
|
28619
|
-
defaults: [
|
|
29238
|
+
defaults: [path16.join(homedir19(), ".pi", "agent", "sessions")],
|
|
28620
29239
|
configured: [
|
|
28621
|
-
agentDir ?
|
|
29240
|
+
agentDir ? path16.join(agentDir, "sessions") : void 0,
|
|
28622
29241
|
process.env.PI_CODING_AGENT_SESSION_DIR
|
|
28623
29242
|
],
|
|
28624
29243
|
remember: "pi-mono"
|
|
@@ -28634,22 +29253,22 @@ function isSessionFile(basename6) {
|
|
|
28634
29253
|
async function* walkSessions(dir) {
|
|
28635
29254
|
let entries;
|
|
28636
29255
|
try {
|
|
28637
|
-
entries = await
|
|
29256
|
+
entries = await readdir11(dir, { withFileTypes: true });
|
|
28638
29257
|
} catch (error) {
|
|
28639
29258
|
if (error?.code !== "ENOENT")
|
|
28640
29259
|
traceError("pi transcript discovery", error, "warn");
|
|
28641
29260
|
return;
|
|
28642
29261
|
}
|
|
28643
29262
|
for (const e of entries) {
|
|
28644
|
-
const full =
|
|
29263
|
+
const full = path16.join(dir, e.name);
|
|
28645
29264
|
if (e.isDirectory()) yield* walkSessions(full);
|
|
28646
29265
|
else if (e.isFile() && isSessionFile(e.name)) yield full;
|
|
28647
29266
|
}
|
|
28648
29267
|
}
|
|
28649
|
-
async function
|
|
29268
|
+
async function scan7(agg, opts = {}) {
|
|
28650
29269
|
const stats = emptyScanStats();
|
|
28651
29270
|
const visited = /* @__PURE__ */ new Set();
|
|
28652
|
-
const fold =
|
|
29271
|
+
const fold = createFoldState2();
|
|
28653
29272
|
const discovery = opts.roots ? { homes: opts.roots, complete: true } : await discoverSessionRoots();
|
|
28654
29273
|
stats.sourceDiscoveryComplete = discovery.complete;
|
|
28655
29274
|
for (const root of discovery.homes) {
|
|
@@ -28658,7 +29277,7 @@ async function scan6(agg, opts = {}) {
|
|
|
28658
29277
|
stats.filesFound++;
|
|
28659
29278
|
let resolved;
|
|
28660
29279
|
try {
|
|
28661
|
-
resolved = await
|
|
29280
|
+
resolved = await realpath6(file);
|
|
28662
29281
|
} catch (error) {
|
|
28663
29282
|
if (error?.code !== "ENOENT")
|
|
28664
29283
|
traceError("pi transcript path resolution", error, "warn");
|
|
@@ -28671,7 +29290,7 @@ async function scan6(agg, opts = {}) {
|
|
|
28671
29290
|
visited.add(resolved);
|
|
28672
29291
|
if (opts.sinceMs !== void 0) {
|
|
28673
29292
|
try {
|
|
28674
|
-
const st = await
|
|
29293
|
+
const st = await stat11(file);
|
|
28675
29294
|
if (st.mtimeMs < opts.sinceMs) {
|
|
28676
29295
|
stats.filesSkippedByMtime++;
|
|
28677
29296
|
continue;
|
|
@@ -28695,7 +29314,7 @@ async function scan6(agg, opts = {}) {
|
|
|
28695
29314
|
stats.filesUnreadable++;
|
|
28696
29315
|
stats.filesRead--;
|
|
28697
29316
|
stats.unreadableFiles.push({
|
|
28698
|
-
path:
|
|
29317
|
+
path: path16.relative(root, file),
|
|
28699
29318
|
reason: "version-too-new"
|
|
28700
29319
|
});
|
|
28701
29320
|
}
|
|
@@ -28704,7 +29323,7 @@ async function scan6(agg, opts = {}) {
|
|
|
28704
29323
|
stats.filesUnreadable++;
|
|
28705
29324
|
stats.filesRead--;
|
|
28706
29325
|
stats.unreadableFiles.push({
|
|
28707
|
-
path:
|
|
29326
|
+
path: path16.relative(root, file),
|
|
28708
29327
|
reason: "read-error"
|
|
28709
29328
|
});
|
|
28710
29329
|
}
|
|
@@ -28714,7 +29333,7 @@ async function scan6(agg, opts = {}) {
|
|
|
28714
29333
|
}
|
|
28715
29334
|
async function exists5(p8) {
|
|
28716
29335
|
try {
|
|
28717
|
-
await
|
|
29336
|
+
await stat11(p8);
|
|
28718
29337
|
return true;
|
|
28719
29338
|
} catch (error) {
|
|
28720
29339
|
if (error?.code !== "ENOENT")
|
|
@@ -28785,8 +29404,8 @@ var piAdapter = {
|
|
|
28785
29404
|
);
|
|
28786
29405
|
},
|
|
28787
29406
|
async scan(opts) {
|
|
28788
|
-
const aggregate =
|
|
28789
|
-
const stats = await
|
|
29407
|
+
const aggregate = createAggregate7();
|
|
29408
|
+
const stats = await scan7(aggregate, {
|
|
28790
29409
|
sinceMs: opts.sinceMs,
|
|
28791
29410
|
...opts.onProgress ? { onProgress: opts.onProgress } : {}
|
|
28792
29411
|
});
|
|
@@ -28807,7 +29426,8 @@ var HARNESS_ADAPTERS = [
|
|
|
28807
29426
|
grokAdapter,
|
|
28808
29427
|
cursorAdapter,
|
|
28809
29428
|
opencodeAdapter,
|
|
28810
|
-
piAdapter
|
|
29429
|
+
piAdapter,
|
|
29430
|
+
antigravityAdapter
|
|
28811
29431
|
];
|
|
28812
29432
|
function harnessLabel2(name) {
|
|
28813
29433
|
if (name === CLAUDE_HARNESS_NAME) return "Claude Code";
|
|
@@ -28816,6 +29436,7 @@ function harnessLabel2(name) {
|
|
|
28816
29436
|
if (name === GROK_HARNESS_NAME) return "Grok Build";
|
|
28817
29437
|
if (name === OPENCODE_HARNESS_NAME) return "opencode";
|
|
28818
29438
|
if (name === PI_HARNESS_NAME) return "Pi";
|
|
29439
|
+
if (name === ANTIGRAVITY_HARNESS_NAME) return "Antigravity";
|
|
28819
29440
|
return name;
|
|
28820
29441
|
}
|
|
28821
29442
|
function harnessListLabel(adapters) {
|
|
@@ -28850,7 +29471,7 @@ var MCP_ADD_ARGS = [
|
|
|
28850
29471
|
"mcp"
|
|
28851
29472
|
];
|
|
28852
29473
|
var MCP_REMOVE_ARGS = ["mcp", "remove", "--scope", "user", "aistack"];
|
|
28853
|
-
var SKILL_DEST = join13(
|
|
29474
|
+
var SKILL_DEST = join13(homedir20(), ".claude", "skills", "aistack-sync");
|
|
28854
29475
|
function runClaude(args) {
|
|
28855
29476
|
const r = spawnSync("claude", args, { encoding: "utf-8" });
|
|
28856
29477
|
const notFound = r.error !== void 0 && r.error.code === "ENOENT";
|
|
@@ -28863,7 +29484,7 @@ function runClaude(args) {
|
|
|
28863
29484
|
function claudeOnPath(run = runClaude) {
|
|
28864
29485
|
return !run(["--version"]).notFound;
|
|
28865
29486
|
}
|
|
28866
|
-
function findSkillSource(fromDir = dirname5(
|
|
29487
|
+
function findSkillSource(fromDir = dirname5(fileURLToPath2(import.meta.url))) {
|
|
28867
29488
|
let dir = fromDir;
|
|
28868
29489
|
for (let i = 0; i < 4; i++) {
|
|
28869
29490
|
const candidate = join13(dir, "skills", "aistack-sync");
|
|
@@ -29080,8 +29701,8 @@ async function createCommand() {
|
|
|
29080
29701
|
}
|
|
29081
29702
|
|
|
29082
29703
|
// src/commands/cursorFolders.ts
|
|
29083
|
-
import { realpath as
|
|
29084
|
-
import
|
|
29704
|
+
import { realpath as realpath7, stat as stat12 } from "node:fs/promises";
|
|
29705
|
+
import path17 from "node:path";
|
|
29085
29706
|
var console_ = { print: (line) => process.stdout.write(`${line}
|
|
29086
29707
|
`) };
|
|
29087
29708
|
async function cursorFoldersCommand(action = "list", dir, out = console_) {
|
|
@@ -29113,7 +29734,7 @@ async function cursorFoldersCommand(action = "list", dir, out = console_) {
|
|
|
29113
29734
|
const root = await cursorRootFor(dir);
|
|
29114
29735
|
if (action === "remove") {
|
|
29115
29736
|
const stored = await rememberedHomes(CURSOR_HOMES_KEY);
|
|
29116
|
-
const target = [root, await
|
|
29737
|
+
const target = [root, await realpath7(root).catch(() => root)].find(
|
|
29117
29738
|
(entry) => stored.includes(entry)
|
|
29118
29739
|
) ?? root;
|
|
29119
29740
|
if (await forgetHome(CURSOR_HOMES_KEY, target))
|
|
@@ -29123,8 +29744,8 @@ async function cursorFoldersCommand(action = "list", dir, out = console_) {
|
|
|
29123
29744
|
}
|
|
29124
29745
|
let real;
|
|
29125
29746
|
try {
|
|
29126
|
-
real = await
|
|
29127
|
-
if (
|
|
29747
|
+
real = await realpath7(root);
|
|
29748
|
+
if (path17.basename(real) !== "workspaceStorage" || !(await stat12(real)).isDirectory())
|
|
29128
29749
|
throw new Error("not a Cursor folder");
|
|
29129
29750
|
} catch {
|
|
29130
29751
|
fail(
|
|
@@ -29234,25 +29855,104 @@ async function loginCommand(options = {}) {
|
|
|
29234
29855
|
import * as p7 from "@clack/prompts";
|
|
29235
29856
|
|
|
29236
29857
|
// src/autosync/optin.ts
|
|
29237
|
-
import { existsSync as
|
|
29238
|
-
import { homedir as
|
|
29239
|
-
import { dirname as
|
|
29858
|
+
import { existsSync as existsSync18 } from "node:fs";
|
|
29859
|
+
import { homedir as homedir27 } from "node:os";
|
|
29860
|
+
import { dirname as dirname13, join as join20 } from "node:path";
|
|
29240
29861
|
import * as p6 from "@clack/prompts";
|
|
29241
29862
|
|
|
29242
|
-
// src/autosync/
|
|
29243
|
-
import { createHash as createHash9 } from "node:crypto";
|
|
29863
|
+
// src/autosync/antigravityHook.ts
|
|
29244
29864
|
import {
|
|
29245
29865
|
existsSync as existsSync13,
|
|
29246
29866
|
mkdirSync as mkdirSync4,
|
|
29247
29867
|
readFileSync as readFileSync14,
|
|
29248
|
-
|
|
29868
|
+
unlinkSync as unlinkSync5,
|
|
29249
29869
|
writeFileSync as writeFileSync4
|
|
29250
29870
|
} from "node:fs";
|
|
29251
|
-
import { homedir as
|
|
29252
|
-
import { dirname as dirname7
|
|
29871
|
+
import { homedir as homedir21, platform as platform2 } from "node:os";
|
|
29872
|
+
import path18, { dirname as dirname7 } from "node:path";
|
|
29873
|
+
var HOOK_NAME = "aistack";
|
|
29874
|
+
function antigravityHookFile() {
|
|
29875
|
+
const configured = process.env.ANTIGRAVITY_GEMINI_DIR?.trim();
|
|
29876
|
+
const gemini = configured ? path18.resolve(homedir21(), configured) : path18.join(homedir21(), ".gemini");
|
|
29877
|
+
return path18.join(gemini, "config", "hooks.json");
|
|
29878
|
+
}
|
|
29879
|
+
var SYNC_COMMAND = "npx -y @use-aistack/cli@latest sync --auto || npx -y --prefer-offline @use-aistack/cli sync --auto";
|
|
29880
|
+
function antigravityHookCommand(os = platform2()) {
|
|
29881
|
+
if (os === "win32") {
|
|
29882
|
+
return `Start-Process -WindowStyle Hidden -FilePath "cmd.exe" -ArgumentList '/d /s /c "set AISTACK_HOOK_SOURCE=antigravity&& (${SYNC_COMMAND}) <NUL >NUL 2>&1"'`;
|
|
29883
|
+
}
|
|
29884
|
+
const detach = os === "darwin" ? "nohup" : "setsid nohup";
|
|
29885
|
+
return `${detach} sh -c 'export AISTACK_HOOK_SOURCE=antigravity; ${SYNC_COMMAND}' </dev/null >/dev/null 2>&1 &`;
|
|
29886
|
+
}
|
|
29887
|
+
function readHooksFile(file) {
|
|
29888
|
+
if (!existsSync13(file)) return { value: {} };
|
|
29889
|
+
try {
|
|
29890
|
+
const value = JSON.parse(readFileSync14(file, "utf-8"));
|
|
29891
|
+
if (value && typeof value === "object" && !Array.isArray(value))
|
|
29892
|
+
return { value };
|
|
29893
|
+
} catch {
|
|
29894
|
+
return { error: `${file} is not valid JSON. Fix it, then retry.` };
|
|
29895
|
+
}
|
|
29896
|
+
return { error: `${file} does not hold a JSON object. Fix it, then retry.` };
|
|
29897
|
+
}
|
|
29898
|
+
function isOurs(entry) {
|
|
29899
|
+
const command = entry?.command;
|
|
29900
|
+
return typeof command === "string" && command.includes("@use-aistack/cli") && command.includes("sync --auto");
|
|
29901
|
+
}
|
|
29902
|
+
function installAntigravityAutoSyncHook(file = antigravityHookFile(), os = platform2()) {
|
|
29903
|
+
const read3 = readHooksFile(file);
|
|
29904
|
+
if ("error" in read3) return { ok: false, message: read3.error };
|
|
29905
|
+
const value = {
|
|
29906
|
+
...read3.value,
|
|
29907
|
+
[HOOK_NAME]: {
|
|
29908
|
+
SessionStart: [
|
|
29909
|
+
{ type: "command", command: antigravityHookCommand(os), timeout: 10 }
|
|
29910
|
+
]
|
|
29911
|
+
}
|
|
29912
|
+
};
|
|
29913
|
+
mkdirSync4(dirname7(file), { recursive: true });
|
|
29914
|
+
writeFileSync4(file, `${JSON.stringify(value, null, 2)}
|
|
29915
|
+
`);
|
|
29916
|
+
return {
|
|
29917
|
+
ok: true,
|
|
29918
|
+
message: `Antigravity SessionStart hook written to ${file}. It runs from the next Antigravity session.`
|
|
29919
|
+
};
|
|
29920
|
+
}
|
|
29921
|
+
function removeAntigravityAutoSyncHook(file = antigravityHookFile()) {
|
|
29922
|
+
if (!existsSync13(file))
|
|
29923
|
+
return { ok: true, message: "no Antigravity hook to remove" };
|
|
29924
|
+
const read3 = readHooksFile(file);
|
|
29925
|
+
if ("error" in read3) return { ok: false, message: read3.error };
|
|
29926
|
+
if (!(HOOK_NAME in read3.value))
|
|
29927
|
+
return { ok: true, message: "no Antigravity hook to remove" };
|
|
29928
|
+
const { [HOOK_NAME]: _ours, ...rest } = read3.value;
|
|
29929
|
+
if (Object.keys(rest).length === 0) unlinkSync5(file);
|
|
29930
|
+
else writeFileSync4(file, `${JSON.stringify(rest, null, 2)}
|
|
29931
|
+
`);
|
|
29932
|
+
return { ok: true, message: `Antigravity hook removed from ${file}` };
|
|
29933
|
+
}
|
|
29934
|
+
function antigravityAutoSyncHookInstalled(file = antigravityHookFile()) {
|
|
29935
|
+
const read3 = readHooksFile(file);
|
|
29936
|
+
if ("error" in read3) return false;
|
|
29937
|
+
const entry = read3.value[HOOK_NAME];
|
|
29938
|
+
const handlers = entry?.SessionStart;
|
|
29939
|
+
return Array.isArray(handlers) && handlers.some(isOurs);
|
|
29940
|
+
}
|
|
29941
|
+
|
|
29942
|
+
// src/autosync/codexHook.ts
|
|
29943
|
+
import { createHash as createHash9 } from "node:crypto";
|
|
29944
|
+
import {
|
|
29945
|
+
existsSync as existsSync14,
|
|
29946
|
+
mkdirSync as mkdirSync5,
|
|
29947
|
+
readFileSync as readFileSync15,
|
|
29948
|
+
realpathSync as realpathSync3,
|
|
29949
|
+
writeFileSync as writeFileSync5
|
|
29950
|
+
} from "node:fs";
|
|
29951
|
+
import { homedir as homedir22 } from "node:os";
|
|
29952
|
+
import { dirname as dirname8, join as join15 } from "node:path";
|
|
29253
29953
|
import { parse } from "smol-toml";
|
|
29254
29954
|
function codexHome() {
|
|
29255
|
-
return process.env.CODEX_HOME || join15(
|
|
29955
|
+
return process.env.CODEX_HOME || join15(homedir22(), ".codex");
|
|
29256
29956
|
}
|
|
29257
29957
|
function codexHooksFile() {
|
|
29258
29958
|
return join15(codexHome(), "hooks.json");
|
|
@@ -29261,13 +29961,13 @@ function codexConfigFile() {
|
|
|
29261
29961
|
return join15(codexHome(), "config.toml");
|
|
29262
29962
|
}
|
|
29263
29963
|
var CODEX_HOOK_COMMAND = `sh -c 'setsid nohup sh -c "npx -y @use-aistack/cli@latest sync --auto || npx -y --prefer-offline @use-aistack/cli sync --auto" >/dev/null 2>&1 &'`;
|
|
29264
|
-
function
|
|
29964
|
+
function isOurs2(entry) {
|
|
29265
29965
|
return typeof entry.command === "string" && entry.command.includes("@use-aistack/cli") && entry.command.includes("sync --auto");
|
|
29266
29966
|
}
|
|
29267
29967
|
function readHooksJson(file) {
|
|
29268
|
-
if (!
|
|
29968
|
+
if (!existsSync14(file)) return { settings: {} };
|
|
29269
29969
|
try {
|
|
29270
|
-
const raw = JSON.parse(
|
|
29970
|
+
const raw = JSON.parse(readFileSync15(file, "utf-8"));
|
|
29271
29971
|
if (raw && typeof raw === "object" && !Array.isArray(raw)) {
|
|
29272
29972
|
return { settings: raw };
|
|
29273
29973
|
}
|
|
@@ -29285,20 +29985,20 @@ function installCodexAutoSyncHook(file = codexHooksFile()) {
|
|
|
29285
29985
|
const sessionStart = Array.isArray(hooks.SessionStart) ? hooks.SessionStart : [];
|
|
29286
29986
|
const kept = sessionStart.map((m) => ({
|
|
29287
29987
|
...m,
|
|
29288
|
-
hooks: (m.hooks ?? []).filter((h) => !
|
|
29988
|
+
hooks: (m.hooks ?? []).filter((h) => !isOurs2(h))
|
|
29289
29989
|
})).filter((m) => (m.hooks?.length ?? 0) > 0);
|
|
29290
29990
|
kept.push({
|
|
29291
29991
|
matcher: "startup",
|
|
29292
29992
|
hooks: [{ type: "command", command: CODEX_HOOK_COMMAND, timeout: 30 }]
|
|
29293
29993
|
});
|
|
29294
29994
|
settings.hooks = { ...hooks, SessionStart: kept };
|
|
29295
|
-
|
|
29296
|
-
|
|
29995
|
+
mkdirSync5(dirname8(file), { recursive: true });
|
|
29996
|
+
writeFileSync5(file, `${JSON.stringify(settings, null, 2)}
|
|
29297
29997
|
`);
|
|
29298
29998
|
return { ok: true, message: CODEX_TRUST_INSTRUCTION };
|
|
29299
29999
|
}
|
|
29300
30000
|
function removeCodexAutoSyncHook(file = codexHooksFile()) {
|
|
29301
|
-
if (!
|
|
30001
|
+
if (!existsSync14(file))
|
|
29302
30002
|
return { ok: true, message: "no Codex hook to remove" };
|
|
29303
30003
|
const read3 = readHooksJson(file);
|
|
29304
30004
|
if ("error" in read3) return { ok: false, message: read3.error };
|
|
@@ -29309,7 +30009,7 @@ function removeCodexAutoSyncHook(file = codexHooksFile()) {
|
|
|
29309
30009
|
}
|
|
29310
30010
|
const kept = sessionStart.map((m) => ({
|
|
29311
30011
|
...m,
|
|
29312
|
-
hooks: (m.hooks ?? []).filter((h) => !
|
|
30012
|
+
hooks: (m.hooks ?? []).filter((h) => !isOurs2(h))
|
|
29313
30013
|
})).filter((m) => (m.hooks?.length ?? 0) > 0);
|
|
29314
30014
|
const hooks = { ...settings.hooks };
|
|
29315
30015
|
if (kept.length > 0) {
|
|
@@ -29322,7 +30022,7 @@ function removeCodexAutoSyncHook(file = codexHooksFile()) {
|
|
|
29322
30022
|
} else {
|
|
29323
30023
|
delete settings.hooks;
|
|
29324
30024
|
}
|
|
29325
|
-
|
|
30025
|
+
writeFileSync5(file, `${JSON.stringify(settings, null, 2)}
|
|
29326
30026
|
`);
|
|
29327
30027
|
return { ok: true, message: `hook removed from ${file}` };
|
|
29328
30028
|
}
|
|
@@ -29331,11 +30031,11 @@ function codexAutoSyncHookInstalled(file = codexHooksFile()) {
|
|
|
29331
30031
|
if ("error" in read3) return false;
|
|
29332
30032
|
const sessionStart = read3.settings.hooks?.SessionStart;
|
|
29333
30033
|
if (!Array.isArray(sessionStart)) return false;
|
|
29334
|
-
return sessionStart.some((m) => (m.hooks ?? []).some((h) =>
|
|
30034
|
+
return sessionStart.some((m) => (m.hooks ?? []).some((h) => isOurs2(h)));
|
|
29335
30035
|
}
|
|
29336
30036
|
function codexHookTrusted(configFile = codexConfigFile(), hooksFile = codexHooksFile()) {
|
|
29337
30037
|
try {
|
|
29338
|
-
const config = parse(
|
|
30038
|
+
const config = parse(readFileSync15(configFile, "utf-8"));
|
|
29339
30039
|
const read3 = readHooksJson(hooksFile);
|
|
29340
30040
|
if ("error" in read3) return null;
|
|
29341
30041
|
const sessionStart = read3.settings.hooks?.SessionStart;
|
|
@@ -29343,7 +30043,7 @@ function codexHookTrusted(configFile = codexConfigFile(), hooksFile = codexHooks
|
|
|
29343
30043
|
const matches = [];
|
|
29344
30044
|
for (const [groupIndex, group] of sessionStart.entries()) {
|
|
29345
30045
|
for (const [handlerIndex, handler] of (group.hooks ?? []).entries()) {
|
|
29346
|
-
if (!
|
|
30046
|
+
if (!isOurs2(handler) || typeof handler.command !== "string") continue;
|
|
29347
30047
|
const normalizedHandler = {
|
|
29348
30048
|
type: "command",
|
|
29349
30049
|
command: handler.command,
|
|
@@ -29401,23 +30101,23 @@ function canonicalJson2(value) {
|
|
|
29401
30101
|
}
|
|
29402
30102
|
|
|
29403
30103
|
// src/autosync/cursorHook.ts
|
|
29404
|
-
import { existsSync as
|
|
29405
|
-
import { homedir as
|
|
29406
|
-
import { dirname as
|
|
30104
|
+
import { existsSync as existsSync16, mkdirSync as mkdirSync7, readFileSync as readFileSync17, writeFileSync as writeFileSync7 } from "node:fs";
|
|
30105
|
+
import { homedir as homedir24, platform as platform3 } from "node:os";
|
|
30106
|
+
import { dirname as dirname10, join as join17 } from "node:path";
|
|
29407
30107
|
|
|
29408
30108
|
// src/autosync/hook.ts
|
|
29409
|
-
import { existsSync as
|
|
29410
|
-
import { homedir as
|
|
29411
|
-
import { dirname as
|
|
29412
|
-
var CLAUDE_SETTINGS_FILE = join16(
|
|
30109
|
+
import { existsSync as existsSync15, mkdirSync as mkdirSync6, readFileSync as readFileSync16, writeFileSync as writeFileSync6 } from "node:fs";
|
|
30110
|
+
import { homedir as homedir23 } from "node:os";
|
|
30111
|
+
import { dirname as dirname9, join as join16 } from "node:path";
|
|
30112
|
+
var CLAUDE_SETTINGS_FILE = join16(homedir23(), ".claude", "settings.json");
|
|
29413
30113
|
var AUTO_SYNC_HOOK_COMMAND = "npx -y @use-aistack/cli@latest sync --auto || npx -y --prefer-offline @use-aistack/cli sync --auto";
|
|
29414
|
-
function
|
|
30114
|
+
function isOurs3(entry) {
|
|
29415
30115
|
return typeof entry.command === "string" && entry.command.includes("@use-aistack/cli") && entry.command.includes("sync --auto");
|
|
29416
30116
|
}
|
|
29417
30117
|
function readClaudeSettings(file) {
|
|
29418
|
-
if (!
|
|
30118
|
+
if (!existsSync15(file)) return { settings: {} };
|
|
29419
30119
|
try {
|
|
29420
|
-
const raw = JSON.parse(
|
|
30120
|
+
const raw = JSON.parse(readFileSync16(file, "utf-8"));
|
|
29421
30121
|
if (raw && typeof raw === "object" && !Array.isArray(raw)) {
|
|
29422
30122
|
return { settings: raw };
|
|
29423
30123
|
}
|
|
@@ -29434,19 +30134,19 @@ function installAutoSyncHook(file = CLAUDE_SETTINGS_FILE) {
|
|
|
29434
30134
|
const sessionStart = Array.isArray(hooks.SessionStart) ? hooks.SessionStart : [];
|
|
29435
30135
|
const kept = sessionStart.map((m) => ({
|
|
29436
30136
|
...m,
|
|
29437
|
-
hooks: (m.hooks ?? []).filter((h) => !
|
|
30137
|
+
hooks: (m.hooks ?? []).filter((h) => !isOurs3(h))
|
|
29438
30138
|
})).filter((m) => (m.hooks?.length ?? 0) > 0);
|
|
29439
30139
|
kept.push({
|
|
29440
30140
|
hooks: [{ type: "command", command: AUTO_SYNC_HOOK_COMMAND, async: true }]
|
|
29441
30141
|
});
|
|
29442
30142
|
settings.hooks = { ...hooks, SessionStart: kept };
|
|
29443
|
-
|
|
29444
|
-
|
|
30143
|
+
mkdirSync6(dirname9(file), { recursive: true });
|
|
30144
|
+
writeFileSync6(file, `${JSON.stringify(settings, null, 2)}
|
|
29445
30145
|
`);
|
|
29446
30146
|
return { ok: true, message: `SessionStart hook written to ${file}` };
|
|
29447
30147
|
}
|
|
29448
30148
|
function removeAutoSyncHook(file = CLAUDE_SETTINGS_FILE) {
|
|
29449
|
-
if (!
|
|
30149
|
+
if (!existsSync15(file)) return { ok: true, message: "no hook to remove" };
|
|
29450
30150
|
const read3 = readClaudeSettings(file);
|
|
29451
30151
|
if ("error" in read3) return { ok: false, message: read3.error };
|
|
29452
30152
|
const settings = read3.settings;
|
|
@@ -29456,7 +30156,7 @@ function removeAutoSyncHook(file = CLAUDE_SETTINGS_FILE) {
|
|
|
29456
30156
|
}
|
|
29457
30157
|
const kept = sessionStart.map((m) => ({
|
|
29458
30158
|
...m,
|
|
29459
|
-
hooks: (m.hooks ?? []).filter((h) => !
|
|
30159
|
+
hooks: (m.hooks ?? []).filter((h) => !isOurs3(h))
|
|
29460
30160
|
})).filter((m) => (m.hooks?.length ?? 0) > 0);
|
|
29461
30161
|
const hooks = { ...settings.hooks };
|
|
29462
30162
|
if (kept.length > 0) {
|
|
@@ -29469,7 +30169,7 @@ function removeAutoSyncHook(file = CLAUDE_SETTINGS_FILE) {
|
|
|
29469
30169
|
} else {
|
|
29470
30170
|
delete settings.hooks;
|
|
29471
30171
|
}
|
|
29472
|
-
|
|
30172
|
+
writeFileSync6(file, `${JSON.stringify(settings, null, 2)}
|
|
29473
30173
|
`);
|
|
29474
30174
|
return { ok: true, message: `hook removed from ${file}` };
|
|
29475
30175
|
}
|
|
@@ -29478,12 +30178,12 @@ function autoSyncHookInstalled(file = CLAUDE_SETTINGS_FILE) {
|
|
|
29478
30178
|
if ("error" in read3) return false;
|
|
29479
30179
|
const sessionStart = read3.settings.hooks?.SessionStart;
|
|
29480
30180
|
if (!Array.isArray(sessionStart)) return false;
|
|
29481
|
-
return sessionStart.some((m) => (m.hooks ?? []).some((h) =>
|
|
30181
|
+
return sessionStart.some((m) => (m.hooks ?? []).some((h) => isOurs3(h)));
|
|
29482
30182
|
}
|
|
29483
30183
|
|
|
29484
30184
|
// src/autosync/cursorHook.ts
|
|
29485
|
-
var CURSOR_HOOK_FILE = join17(
|
|
29486
|
-
function cursorHookCommand(os =
|
|
30185
|
+
var CURSOR_HOOK_FILE = join17(homedir24(), ".cursor", "hooks.json");
|
|
30186
|
+
function cursorHookCommand(os = platform3()) {
|
|
29487
30187
|
if (os === "win32") {
|
|
29488
30188
|
const script = `Start-Process -WindowStyle Hidden -FilePath 'cmd.exe' -ArgumentList '/d /s /c "set AISTACK_HOOK_SOURCE=cursor&& (${AUTO_SYNC_HOOK_COMMAND}) <NUL >NUL 2>&1"'`;
|
|
29489
30189
|
return `powershell.exe -NoProfile -NonInteractive -EncodedCommand ${Buffer.from(script, "utf16le").toString("base64")}`;
|
|
@@ -29492,8 +30192,8 @@ function cursorHookCommand(os = platform2()) {
|
|
|
29492
30192
|
return `${detach} sh -c 'export AISTACK_HOOK_SOURCE=cursor; ${AUTO_SYNC_HOOK_COMMAND}' </dev/null >/dev/null 2>&1 &`;
|
|
29493
30193
|
}
|
|
29494
30194
|
function read(file) {
|
|
29495
|
-
if (!
|
|
29496
|
-
const value = JSON.parse(
|
|
30195
|
+
if (!existsSync16(file)) return {};
|
|
30196
|
+
const value = JSON.parse(readFileSync17(file, "utf8"));
|
|
29497
30197
|
if (!value || typeof value !== "object" || Array.isArray(value))
|
|
29498
30198
|
throw new Error("expected a JSON object");
|
|
29499
30199
|
const config = value;
|
|
@@ -29507,7 +30207,7 @@ function read(file) {
|
|
|
29507
30207
|
throw new Error("malformed hooks object");
|
|
29508
30208
|
return config;
|
|
29509
30209
|
}
|
|
29510
|
-
function
|
|
30210
|
+
function isOurs4(entry) {
|
|
29511
30211
|
return ["linux", "darwin", "win32"].some(
|
|
29512
30212
|
(os) => entry.command === cursorHookCommand(os)
|
|
29513
30213
|
);
|
|
@@ -29516,7 +30216,7 @@ function update(file, install, os) {
|
|
|
29516
30216
|
try {
|
|
29517
30217
|
const config = read(file);
|
|
29518
30218
|
const existing = config.hooks?.stop ?? [];
|
|
29519
|
-
const kept = existing.filter((entry) => !
|
|
30219
|
+
const kept = existing.filter((entry) => !isOurs4(entry));
|
|
29520
30220
|
if (!install && kept.length === existing.length)
|
|
29521
30221
|
return { ok: true, message: "no Cursor hook to remove" };
|
|
29522
30222
|
if (install) kept.push({ command: cursorHookCommand(os) });
|
|
@@ -29526,8 +30226,8 @@ function update(file, install, os) {
|
|
|
29526
30226
|
if (Object.keys(hooks).length) config.hooks = hooks;
|
|
29527
30227
|
else delete config.hooks;
|
|
29528
30228
|
if (install) config.version = 1;
|
|
29529
|
-
|
|
29530
|
-
|
|
30229
|
+
mkdirSync7(dirname10(file), { recursive: true });
|
|
30230
|
+
writeFileSync7(file, `${JSON.stringify(config, null, 2)}
|
|
29531
30231
|
`);
|
|
29532
30232
|
return {
|
|
29533
30233
|
ok: true,
|
|
@@ -29540,15 +30240,15 @@ function update(file, install, os) {
|
|
|
29540
30240
|
};
|
|
29541
30241
|
}
|
|
29542
30242
|
}
|
|
29543
|
-
function installCursorAutoSyncHook(file = CURSOR_HOOK_FILE, os =
|
|
30243
|
+
function installCursorAutoSyncHook(file = CURSOR_HOOK_FILE, os = platform3()) {
|
|
29544
30244
|
return update(file, true, os);
|
|
29545
30245
|
}
|
|
29546
30246
|
function removeCursorAutoSyncHook(file = CURSOR_HOOK_FILE) {
|
|
29547
|
-
return update(file, false,
|
|
30247
|
+
return update(file, false, platform3());
|
|
29548
30248
|
}
|
|
29549
30249
|
function cursorAutoSyncHookInstalled(file = CURSOR_HOOK_FILE) {
|
|
29550
30250
|
try {
|
|
29551
|
-
return (read(file).hooks?.stop ?? []).some(
|
|
30251
|
+
return (read(file).hooks?.stop ?? []).some(isOurs4);
|
|
29552
30252
|
} catch {
|
|
29553
30253
|
return false;
|
|
29554
30254
|
}
|
|
@@ -29556,33 +30256,33 @@ function cursorAutoSyncHookInstalled(file = CURSOR_HOOK_FILE) {
|
|
|
29556
30256
|
|
|
29557
30257
|
// src/autosync/grokHook.ts
|
|
29558
30258
|
import {
|
|
29559
|
-
existsSync as
|
|
29560
|
-
mkdirSync as
|
|
29561
|
-
readFileSync as
|
|
29562
|
-
unlinkSync as
|
|
29563
|
-
writeFileSync as
|
|
30259
|
+
existsSync as existsSync17,
|
|
30260
|
+
mkdirSync as mkdirSync8,
|
|
30261
|
+
readFileSync as readFileSync18,
|
|
30262
|
+
unlinkSync as unlinkSync6,
|
|
30263
|
+
writeFileSync as writeFileSync8
|
|
29564
30264
|
} from "node:fs";
|
|
29565
|
-
import { homedir as
|
|
29566
|
-
import { dirname as
|
|
30265
|
+
import { homedir as homedir25, platform as platform4 } from "node:os";
|
|
30266
|
+
import { dirname as dirname11, join as join18 } from "node:path";
|
|
29567
30267
|
var GROK_HOOK_FILE = join18(
|
|
29568
|
-
process.env.GROK_HOME || join18(
|
|
30268
|
+
process.env.GROK_HOME || join18(homedir25(), ".grok"),
|
|
29569
30269
|
"hooks",
|
|
29570
30270
|
"aistack.json"
|
|
29571
30271
|
);
|
|
29572
|
-
var
|
|
29573
|
-
function grokHookCommand(os =
|
|
30272
|
+
var SYNC_COMMAND2 = "npx -y @use-aistack/cli@latest sync --auto || npx -y --prefer-offline @use-aistack/cli sync --auto";
|
|
30273
|
+
function grokHookCommand(os = platform4()) {
|
|
29574
30274
|
if (os === "win32") {
|
|
29575
|
-
return `Start-Process -WindowStyle Hidden -FilePath "cmd.exe" -ArgumentList '/d /s /c "set AISTACK_HOOK_SOURCE=grok&& (${
|
|
30275
|
+
return `Start-Process -WindowStyle Hidden -FilePath "cmd.exe" -ArgumentList '/d /s /c "set AISTACK_HOOK_SOURCE=grok&& (${SYNC_COMMAND2}) >NUL 2>&1"'`;
|
|
29576
30276
|
}
|
|
29577
30277
|
if (os === "darwin") {
|
|
29578
|
-
return `nohup sh -c 'export AISTACK_HOOK_SOURCE=grok; ${
|
|
30278
|
+
return `nohup sh -c 'export AISTACK_HOOK_SOURCE=grok; ${SYNC_COMMAND2}' </dev/null >/dev/null 2>&1 &`;
|
|
29579
30279
|
}
|
|
29580
|
-
return `setsid nohup sh -c 'export AISTACK_HOOK_SOURCE=grok; ${
|
|
30280
|
+
return `setsid nohup sh -c 'export AISTACK_HOOK_SOURCE=grok; ${SYNC_COMMAND2}' >/dev/null 2>&1 &`;
|
|
29581
30281
|
}
|
|
29582
30282
|
function readHookFile(file) {
|
|
29583
|
-
if (!
|
|
30283
|
+
if (!existsSync17(file)) return { value: {} };
|
|
29584
30284
|
try {
|
|
29585
|
-
const value = JSON.parse(
|
|
30285
|
+
const value = JSON.parse(readFileSync18(file, "utf-8"));
|
|
29586
30286
|
if (value && typeof value === "object" && !Array.isArray(value)) {
|
|
29587
30287
|
const candidate = value;
|
|
29588
30288
|
if (candidate.hooks !== void 0 && (!candidate.hooks || typeof candidate.hooks !== "object" || Array.isArray(candidate.hooks) || Object.values(candidate.hooks).some(
|
|
@@ -29599,10 +30299,10 @@ function readHookFile(file) {
|
|
|
29599
30299
|
}
|
|
29600
30300
|
return { error: `${file} does not hold a JSON object` };
|
|
29601
30301
|
}
|
|
29602
|
-
function
|
|
30302
|
+
function isOurs5(entry) {
|
|
29603
30303
|
return typeof entry.command === "string" && entry.command.includes("@use-aistack/cli") && entry.command.includes("sync --auto");
|
|
29604
30304
|
}
|
|
29605
|
-
function installGrokAutoSyncHook(file = GROK_HOOK_FILE, os =
|
|
30305
|
+
function installGrokAutoSyncHook(file = GROK_HOOK_FILE, os = platform4()) {
|
|
29606
30306
|
const read3 = readHookFile(file);
|
|
29607
30307
|
if ("error" in read3) return { ok: false, message: read3.error };
|
|
29608
30308
|
const foreignKeys = Object.keys(read3.value).filter((key2) => key2 !== "hooks");
|
|
@@ -29611,7 +30311,7 @@ function installGrokAutoSyncHook(file = GROK_HOOK_FILE, os = platform3()) {
|
|
|
29611
30311
|
);
|
|
29612
30312
|
const sessionStart = read3.value.hooks?.SessionStart ?? [];
|
|
29613
30313
|
const foreignHandlers = sessionStart.flatMap(
|
|
29614
|
-
(group) => (group.hooks ?? []).filter((entry) => !
|
|
30314
|
+
(group) => (group.hooks ?? []).filter((entry) => !isOurs5(entry))
|
|
29615
30315
|
);
|
|
29616
30316
|
if (foreignKeys.length > 0 || foreignEvents.length > 0 || foreignHandlers.length > 0) {
|
|
29617
30317
|
return {
|
|
@@ -29630,8 +30330,8 @@ function installGrokAutoSyncHook(file = GROK_HOOK_FILE, os = platform3()) {
|
|
|
29630
30330
|
]
|
|
29631
30331
|
}
|
|
29632
30332
|
};
|
|
29633
|
-
|
|
29634
|
-
|
|
30333
|
+
mkdirSync8(dirname11(file), { recursive: true });
|
|
30334
|
+
writeFileSync8(file, `${JSON.stringify(value, null, 2)}
|
|
29635
30335
|
`);
|
|
29636
30336
|
return {
|
|
29637
30337
|
ok: true,
|
|
@@ -29639,7 +30339,7 @@ function installGrokAutoSyncHook(file = GROK_HOOK_FILE, os = platform3()) {
|
|
|
29639
30339
|
};
|
|
29640
30340
|
}
|
|
29641
30341
|
function removeGrokAutoSyncHook(file = GROK_HOOK_FILE) {
|
|
29642
|
-
if (!
|
|
30342
|
+
if (!existsSync17(file))
|
|
29643
30343
|
return { ok: true, message: "no Grok Build hook to remove" };
|
|
29644
30344
|
const read3 = readHookFile(file);
|
|
29645
30345
|
if ("error" in read3) return { ok: false, message: read3.error };
|
|
@@ -29647,7 +30347,7 @@ function removeGrokAutoSyncHook(file = GROK_HOOK_FILE) {
|
|
|
29647
30347
|
const onlyOurs = Object.keys(read3.value).every((key2) => key2 === "hooks") && Object.keys(read3.value.hooks ?? {}).every(
|
|
29648
30348
|
(key2) => key2 === "SessionStart"
|
|
29649
30349
|
) && entries.every(
|
|
29650
|
-
(group) => (group.hooks ?? []).every((entry) =>
|
|
30350
|
+
(group) => (group.hooks ?? []).every((entry) => isOurs5(entry))
|
|
29651
30351
|
);
|
|
29652
30352
|
if (!onlyOurs) {
|
|
29653
30353
|
return {
|
|
@@ -29655,21 +30355,21 @@ function removeGrokAutoSyncHook(file = GROK_HOOK_FILE) {
|
|
|
29655
30355
|
message: `${file} contains hooks not owned by AI Stack and was not removed.`
|
|
29656
30356
|
};
|
|
29657
30357
|
}
|
|
29658
|
-
|
|
30358
|
+
unlinkSync6(file);
|
|
29659
30359
|
return { ok: true, message: `Grok Build hook removed from ${file}` };
|
|
29660
30360
|
}
|
|
29661
30361
|
function grokAutoSyncHookInstalled(file = GROK_HOOK_FILE) {
|
|
29662
30362
|
const read3 = readHookFile(file);
|
|
29663
30363
|
if ("error" in read3) return false;
|
|
29664
30364
|
return (read3.value.hooks?.SessionStart ?? []).some(
|
|
29665
|
-
(group) => (group.hooks ?? []).some((entry) =>
|
|
30365
|
+
(group) => (group.hooks ?? []).some((entry) => isOurs5(entry))
|
|
29666
30366
|
);
|
|
29667
30367
|
}
|
|
29668
30368
|
|
|
29669
30369
|
// src/autosync/homes.ts
|
|
29670
30370
|
import { realpathSync as realpathSync4 } from "node:fs";
|
|
29671
|
-
import { homedir as
|
|
29672
|
-
import { basename as basename5, dirname as
|
|
30371
|
+
import { homedir as homedir26 } from "node:os";
|
|
30372
|
+
import { basename as basename5, dirname as dirname12, join as join19, relative as relative4, sep as sep3 } from "node:path";
|
|
29673
30373
|
var HOOK_HARNESSES = [
|
|
29674
30374
|
"claude",
|
|
29675
30375
|
"codex",
|
|
@@ -29693,7 +30393,7 @@ function withDefault(fallback, found) {
|
|
|
29693
30393
|
return homes;
|
|
29694
30394
|
}
|
|
29695
30395
|
async function discoverHookHomes() {
|
|
29696
|
-
const home =
|
|
30396
|
+
const home = homedir26();
|
|
29697
30397
|
const [claude, codex, grok] = await Promise.all([
|
|
29698
30398
|
discoverClaudeRoots(),
|
|
29699
30399
|
discoverCodexHomes(),
|
|
@@ -29701,7 +30401,7 @@ async function discoverHookHomes() {
|
|
|
29701
30401
|
]);
|
|
29702
30402
|
return {
|
|
29703
30403
|
// A Claude Code profile is the folder that holds its `projects` folder.
|
|
29704
|
-
claude: withDefault(join19(home, ".claude"), claude.roots.map(
|
|
30404
|
+
claude: withDefault(join19(home, ".claude"), claude.roots.map(dirname12)),
|
|
29705
30405
|
codex: withDefault(
|
|
29706
30406
|
process.env.CODEX_HOME || join19(home, ".codex"),
|
|
29707
30407
|
codex.homes
|
|
@@ -29709,7 +30409,7 @@ async function discoverHookHomes() {
|
|
|
29709
30409
|
grok: withDefault(process.env.GROK_HOME || join19(home, ".grok"), grok.homes)
|
|
29710
30410
|
};
|
|
29711
30411
|
}
|
|
29712
|
-
function displayHome(dir, home =
|
|
30412
|
+
function displayHome(dir, home = homedir26()) {
|
|
29713
30413
|
const rel = relative4(home, dir);
|
|
29714
30414
|
if (rel === "") return "~";
|
|
29715
30415
|
if (!rel.startsWith("..") && !rel.startsWith(sep3) && rel !== dir)
|
|
@@ -29718,6 +30418,9 @@ function displayHome(dir, home = homedir24()) {
|
|
|
29718
30418
|
}
|
|
29719
30419
|
|
|
29720
30420
|
// src/autosync/optin.ts
|
|
30421
|
+
function withArticle(label) {
|
|
30422
|
+
return `${/^[aeiou]/i.test(label) ? "an" : "a"} ${label}`;
|
|
30423
|
+
}
|
|
29721
30424
|
var HARNESS_NAME = {
|
|
29722
30425
|
claude: CLAUDE_HARNESS_NAME,
|
|
29723
30426
|
codex: CODEX_HARNESS_NAME,
|
|
@@ -29797,6 +30500,9 @@ function removeHooks(homes, deps) {
|
|
|
29797
30500
|
const cursor = (deps.removeCursorHook ?? removeCursorAutoSyncHook)();
|
|
29798
30501
|
results.push(cursor);
|
|
29799
30502
|
if (!cursor.ok) failures.push(cursor.message);
|
|
30503
|
+
const antigravity = (deps.removeAntigravityHook ?? removeAntigravityAutoSyncHook)();
|
|
30504
|
+
results.push(antigravity);
|
|
30505
|
+
if (!antigravity.ok) failures.push(antigravity.message);
|
|
29800
30506
|
return { results, failures };
|
|
29801
30507
|
}
|
|
29802
30508
|
function codexTrustLine(written, deps) {
|
|
@@ -29849,6 +30555,10 @@ async function enableAutoSync(frequencyHours = DEFAULT_FREQUENCY_HOURS, deps = {
|
|
|
29849
30555
|
const result = (deps.installCursorHook ?? installCursorAutoSyncHook)();
|
|
29850
30556
|
if (!result.ok) return result;
|
|
29851
30557
|
}
|
|
30558
|
+
if (names.has(ANTIGRAVITY_HARNESS_NAME)) {
|
|
30559
|
+
const result = (deps.installAntigravityHook ?? installAntigravityAutoSyncHook)();
|
|
30560
|
+
if (!result.ok) return result;
|
|
30561
|
+
}
|
|
29852
30562
|
saveSettings(
|
|
29853
30563
|
{
|
|
29854
30564
|
autoSyncAnswered: true,
|
|
@@ -29859,7 +30569,7 @@ async function enableAutoSync(frequencyHours = DEFAULT_FREQUENCY_HOURS, deps = {
|
|
|
29859
30569
|
return {
|
|
29860
30570
|
ok: true,
|
|
29861
30571
|
message: [
|
|
29862
|
-
`Auto-sync is on. It runs about every ${frequencyHours}h when
|
|
30572
|
+
`Auto-sync is on. It runs about every ${frequencyHours}h when ${withArticle(harnessListLabel(detected))} ${names.has(CURSOR_HARNESS_NAME) ? "session is active" : "session starts"}. Turn it off any time: npx @use-aistack/cli@latest sync --auto off`,
|
|
29863
30573
|
...trustLine ? [trustLine] : []
|
|
29864
30574
|
].join("\n")
|
|
29865
30575
|
};
|
|
@@ -29956,6 +30666,11 @@ async function reconcileAutoSync(permission, deps = {}) {
|
|
|
29956
30666
|
if (result.ok) installed.push(harnessLabel2(CURSOR_HARNESS_NAME));
|
|
29957
30667
|
else failures.push(result.message);
|
|
29958
30668
|
}
|
|
30669
|
+
if (names.has(ANTIGRAVITY_HARNESS_NAME) && !(deps.antigravityHookInstalledImpl ?? antigravityAutoSyncHookInstalled)()) {
|
|
30670
|
+
const result = (deps.installAntigravityHook ?? installAntigravityAutoSyncHook)();
|
|
30671
|
+
if (result.ok) installed.push(harnessLabel2(ANTIGRAVITY_HARNESS_NAME));
|
|
30672
|
+
else failures.push(result.message);
|
|
30673
|
+
}
|
|
29959
30674
|
if (failures.length > 0) {
|
|
29960
30675
|
return {
|
|
29961
30676
|
ok: false,
|
|
@@ -29975,7 +30690,7 @@ async function reconcileAutoSync(permission, deps = {}) {
|
|
|
29975
30690
|
return {
|
|
29976
30691
|
ok: true,
|
|
29977
30692
|
message: [
|
|
29978
|
-
installed.length > 0 ? `Auto-sync is on for this stack. Installed the ${installed.join(" and ")} trigger on this machine; it runs about every ${frequencyHours}h during session activity.` : `Auto-sync is on for this stack. It runs about every ${frequencyHours}h when
|
|
30693
|
+
installed.length > 0 ? `Auto-sync is on for this stack. Installed the ${installed.join(" and ")} trigger on this machine; it runs about every ${frequencyHours}h during session activity.` : `Auto-sync is on for this stack. It runs about every ${frequencyHours}h when ${withArticle(harnessListLabel(detected))} ${names.has(CURSOR_HARNESS_NAME) ? "session is active" : "session starts"}.`,
|
|
29979
30694
|
...trustLine ? [trustLine] : []
|
|
29980
30695
|
].join("\n")
|
|
29981
30696
|
};
|
|
@@ -30003,7 +30718,7 @@ async function autoSyncStatus(deps = {}) {
|
|
|
30003
30718
|
for (const home of hookTargets(harness, homes, deps.settingsFile)) {
|
|
30004
30719
|
const file = hookFile(harness, home);
|
|
30005
30720
|
const installed = ops[harness].installed(file);
|
|
30006
|
-
if (!installed && !
|
|
30721
|
+
if (!installed && !existsSync18(home)) continue;
|
|
30007
30722
|
let state = installed ? "hook installed" : "no hook";
|
|
30008
30723
|
if (installed && harness === "codex") {
|
|
30009
30724
|
const trust = trusted(join20(home, "config.toml"), file);
|
|
@@ -30018,15 +30733,24 @@ async function autoSyncStatus(deps = {}) {
|
|
|
30018
30733
|
]);
|
|
30019
30734
|
}
|
|
30020
30735
|
}
|
|
30021
|
-
const cursorHome =
|
|
30736
|
+
const cursorHome = dirname13(CURSOR_HOOK_FILE);
|
|
30022
30737
|
const cursorInstalled = (deps.cursorHookInstalledImpl ?? cursorAutoSyncHookInstalled)();
|
|
30023
|
-
if (cursorInstalled ||
|
|
30738
|
+
if (cursorInstalled || existsSync18(cursorHome)) {
|
|
30024
30739
|
rows.push([
|
|
30025
30740
|
harnessLabel2(CURSOR_HARNESS_NAME),
|
|
30026
|
-
displayHome(cursorHome, deps.homeDir ??
|
|
30741
|
+
displayHome(cursorHome, deps.homeDir ?? homedir27()),
|
|
30027
30742
|
cursorInstalled ? "hook installed" : "no hook"
|
|
30028
30743
|
]);
|
|
30029
30744
|
}
|
|
30745
|
+
const antigravityConfig = dirname13(antigravityHookFile());
|
|
30746
|
+
const antigravityInstalled = (deps.antigravityHookInstalledImpl ?? antigravityAutoSyncHookInstalled)();
|
|
30747
|
+
if (antigravityInstalled || existsSync18(antigravityConfig)) {
|
|
30748
|
+
rows.push([
|
|
30749
|
+
harnessLabel2(ANTIGRAVITY_HARNESS_NAME),
|
|
30750
|
+
displayHome(antigravityConfig, deps.homeDir ?? homedir27()),
|
|
30751
|
+
antigravityInstalled ? "hook installed" : "no hook"
|
|
30752
|
+
]);
|
|
30753
|
+
}
|
|
30030
30754
|
if (rows.length === 0) {
|
|
30031
30755
|
lines2.push("No harness folders found on this machine.");
|
|
30032
30756
|
return lines2;
|
|
@@ -30061,7 +30785,7 @@ async function offerAutoSyncOptIn(deps = {}) {
|
|
|
30061
30785
|
{
|
|
30062
30786
|
value: "enable",
|
|
30063
30787
|
label: "Enable",
|
|
30064
|
-
hint: `a silent sync at most every 6 hours when
|
|
30788
|
+
hint: `a silent sync at most every 6 hours when ${withArticle(harnessListLabel(detected))} ${names.has(CURSOR_HARNESS_NAME) ? "session is active" : "session starts"}`
|
|
30065
30789
|
},
|
|
30066
30790
|
{
|
|
30067
30791
|
value: "later",
|
|
@@ -30103,12 +30827,12 @@ async function offerAutoSyncOptIn(deps = {}) {
|
|
|
30103
30827
|
// src/autosync/run.ts
|
|
30104
30828
|
import {
|
|
30105
30829
|
appendFileSync,
|
|
30106
|
-
mkdirSync as
|
|
30107
|
-
readFileSync as
|
|
30108
|
-
writeFileSync as
|
|
30830
|
+
mkdirSync as mkdirSync11,
|
|
30831
|
+
readFileSync as readFileSync21,
|
|
30832
|
+
writeFileSync as writeFileSync11
|
|
30109
30833
|
} from "node:fs";
|
|
30110
|
-
import { homedir as
|
|
30111
|
-
import { dirname as
|
|
30834
|
+
import { homedir as homedir29 } from "node:os";
|
|
30835
|
+
import { dirname as dirname15, join as join21 } from "node:path";
|
|
30112
30836
|
|
|
30113
30837
|
// src/sync/stage.ts
|
|
30114
30838
|
import { createHash as createHash11 } from "node:crypto";
|
|
@@ -30268,8 +30992,8 @@ function selectDaysToPublish(input) {
|
|
|
30268
30992
|
|
|
30269
30993
|
// src/workflow/git.ts
|
|
30270
30994
|
import { execFile, execFileSync as execFileSync2 } from "node:child_process";
|
|
30271
|
-
import { existsSync as
|
|
30272
|
-
import
|
|
30995
|
+
import { existsSync as existsSync19 } from "node:fs";
|
|
30996
|
+
import path19 from "node:path";
|
|
30273
30997
|
var TEST_FILE_RULE_VERSION = "test-files/v2";
|
|
30274
30998
|
var FILE_TYPE_RULE_VERSION = "file-types/v3";
|
|
30275
30999
|
var COMMIT_SET_RULE_VERSION = "commit-set/v1";
|
|
@@ -30279,7 +31003,7 @@ function gitDiagnostics() {
|
|
|
30279
31003
|
const report = (error, cwd, args, stderr) => {
|
|
30280
31004
|
const details = error;
|
|
30281
31005
|
if (args[0] === "rev-parse") {
|
|
30282
|
-
if (details.code === "ENOENT" && !
|
|
31006
|
+
if (details.code === "ENOENT" && !existsSync19(cwd)) {
|
|
30283
31007
|
missing++;
|
|
30284
31008
|
return;
|
|
30285
31009
|
}
|
|
@@ -30686,9 +31410,9 @@ function reduceGitHistories(histories, options) {
|
|
|
30686
31410
|
if (included) seenCommits.add(hash2);
|
|
30687
31411
|
continue;
|
|
30688
31412
|
}
|
|
30689
|
-
const
|
|
30690
|
-
if (!
|
|
30691
|
-
let file =
|
|
31413
|
+
const stat13 = parseNumstat(field);
|
|
31414
|
+
if (!stat13) continue;
|
|
31415
|
+
let file = stat13.file;
|
|
30692
31416
|
if (file.length === 0) {
|
|
30693
31417
|
fieldIndex += 2;
|
|
30694
31418
|
file = fields[fieldIndex] ?? fields[fieldIndex - 1] ?? "";
|
|
@@ -30696,13 +31420,13 @@ function reduceGitHistories(histories, options) {
|
|
|
30696
31420
|
if (!current?.included) continue;
|
|
30697
31421
|
if (isUnauthoredPath(file)) continue;
|
|
30698
31422
|
current.authored = true;
|
|
30699
|
-
const fileChangedLines =
|
|
30700
|
-
current.additions +=
|
|
30701
|
-
current.removals +=
|
|
31423
|
+
const fileChangedLines = stat13.additions + stat13.removals;
|
|
31424
|
+
current.additions += stat13.additions;
|
|
31425
|
+
current.removals += stat13.removals;
|
|
30702
31426
|
current.changedLines += fileChangedLines;
|
|
30703
31427
|
if (isTestFile(file)) current.touchesTest = true;
|
|
30704
31428
|
if (fileChangedLines <= 0) continue;
|
|
30705
|
-
const extension =
|
|
31429
|
+
const extension = path19.extname(file).toLowerCase();
|
|
30706
31430
|
if (APPROVED_EXTENSIONS.has(extension)) {
|
|
30707
31431
|
current.extensionLines.set(
|
|
30708
31432
|
extension,
|
|
@@ -30807,11 +31531,11 @@ function buildWorkflowExtraction(harnessWorkflows, git, utcOffsetMinutes = machi
|
|
|
30807
31531
|
|
|
30808
31532
|
// src/sync/grokDateCache.ts
|
|
30809
31533
|
import { createHash as createHash10 } from "node:crypto";
|
|
30810
|
-
import { existsSync as
|
|
30811
|
-
import { homedir as
|
|
30812
|
-
import
|
|
30813
|
-
var defaultFile =
|
|
30814
|
-
|
|
31534
|
+
import { existsSync as existsSync20, mkdirSync as mkdirSync9, readFileSync as readFileSync19, writeFileSync as writeFileSync9 } from "node:fs";
|
|
31535
|
+
import { homedir as homedir28 } from "node:os";
|
|
31536
|
+
import path20 from "node:path";
|
|
31537
|
+
var defaultFile = path20.join(
|
|
31538
|
+
homedir28(),
|
|
30815
31539
|
".config",
|
|
30816
31540
|
"aistack",
|
|
30817
31541
|
"grok-session-dates.json"
|
|
@@ -30820,9 +31544,9 @@ function grokCacheScope(baseUrl, stack, token) {
|
|
|
30820
31544
|
return createHash10("sha256").update(`${baseUrl}\0${stack}\0${token}`).digest("hex");
|
|
30821
31545
|
}
|
|
30822
31546
|
function read2(file) {
|
|
30823
|
-
if (!
|
|
31547
|
+
if (!existsSync20(file)) return {};
|
|
30824
31548
|
try {
|
|
30825
|
-
const value = JSON.parse(
|
|
31549
|
+
const value = JSON.parse(readFileSync19(file, "utf8"));
|
|
30826
31550
|
return value && typeof value === "object" ? value : {};
|
|
30827
31551
|
} catch {
|
|
30828
31552
|
return {};
|
|
@@ -30834,8 +31558,8 @@ function loadGrokDateHints(scope, file = defaultFile) {
|
|
|
30834
31558
|
function saveGrokDateHints(scope, hints, file = defaultFile) {
|
|
30835
31559
|
const cache = read2(file);
|
|
30836
31560
|
cache[scope] = hints;
|
|
30837
|
-
|
|
30838
|
-
|
|
31561
|
+
mkdirSync9(path20.dirname(file), { recursive: true });
|
|
31562
|
+
writeFileSync9(file, JSON.stringify(cache, null, 2));
|
|
30839
31563
|
}
|
|
30840
31564
|
function mapToHints(value, floor) {
|
|
30841
31565
|
return Object.fromEntries(
|
|
@@ -31721,14 +32445,14 @@ function describeScan(stats) {
|
|
|
31721
32445
|
// src/autosync/reserve.ts
|
|
31722
32446
|
import { randomUUID as randomUUID3 } from "node:crypto";
|
|
31723
32447
|
import {
|
|
31724
|
-
mkdirSync as
|
|
31725
|
-
readFileSync as
|
|
32448
|
+
mkdirSync as mkdirSync10,
|
|
32449
|
+
readFileSync as readFileSync20,
|
|
31726
32450
|
renameSync as renameSync3,
|
|
31727
32451
|
rmSync,
|
|
31728
32452
|
statSync as statSync7,
|
|
31729
|
-
writeFileSync as
|
|
32453
|
+
writeFileSync as writeFileSync10
|
|
31730
32454
|
} from "node:fs";
|
|
31731
|
-
import { dirname as
|
|
32455
|
+
import { dirname as dirname14 } from "node:path";
|
|
31732
32456
|
var MUTEX_WAIT_MS = 2e3;
|
|
31733
32457
|
var MUTEX_STALE_MS = 3e4;
|
|
31734
32458
|
var code = (error) => error?.code;
|
|
@@ -31739,7 +32463,7 @@ function acquire(mutex) {
|
|
|
31739
32463
|
const deadline = Date.now() + MUTEX_WAIT_MS;
|
|
31740
32464
|
for (; ; ) {
|
|
31741
32465
|
try {
|
|
31742
|
-
|
|
32466
|
+
mkdirSync10(mutex);
|
|
31743
32467
|
return true;
|
|
31744
32468
|
} catch (error) {
|
|
31745
32469
|
if (code(error) !== "EEXIST") throw error;
|
|
@@ -31757,7 +32481,7 @@ function acquire(mutex) {
|
|
|
31757
32481
|
function isHeld(file, now, windowMs) {
|
|
31758
32482
|
let content;
|
|
31759
32483
|
try {
|
|
31760
|
-
content =
|
|
32484
|
+
content = readFileSync20(file, "utf-8").trim();
|
|
31761
32485
|
} catch (error) {
|
|
31762
32486
|
if (code(error) === "ENOENT") return false;
|
|
31763
32487
|
throw error;
|
|
@@ -31767,13 +32491,13 @@ function isHeld(file, now, windowMs) {
|
|
|
31767
32491
|
return Date.now() - statSync7(file).mtimeMs < windowMs;
|
|
31768
32492
|
}
|
|
31769
32493
|
function reserveAttempt(file, now, windowMs) {
|
|
31770
|
-
|
|
32494
|
+
mkdirSync10(dirname14(file), { recursive: true });
|
|
31771
32495
|
const mutex = `${file}.lock`;
|
|
31772
32496
|
if (!acquire(mutex)) return false;
|
|
31773
32497
|
try {
|
|
31774
32498
|
if (isHeld(file, now, windowMs)) return false;
|
|
31775
32499
|
const own = `${file}.${process.pid}.${randomUUID3()}`;
|
|
31776
|
-
|
|
32500
|
+
writeFileSync10(own, String(now));
|
|
31777
32501
|
renameSync3(own, file);
|
|
31778
32502
|
return true;
|
|
31779
32503
|
} finally {
|
|
@@ -31782,17 +32506,17 @@ function reserveAttempt(file, now, windowMs) {
|
|
|
31782
32506
|
}
|
|
31783
32507
|
|
|
31784
32508
|
// src/autosync/run.ts
|
|
31785
|
-
var SYNC_LOG_FILE = join21(
|
|
32509
|
+
var SYNC_LOG_FILE = join21(homedir29(), ".config", "aistack", "sync.log");
|
|
31786
32510
|
var SYNC_LOG_MAX_LINES = 200;
|
|
31787
32511
|
var FIX_COMMAND = "npx @use-aistack/cli@latest sync";
|
|
31788
32512
|
var REVOKED_RESULT = "off - auto-sync is switched off for this stack";
|
|
31789
32513
|
function appendLogLine(file, line) {
|
|
31790
|
-
|
|
32514
|
+
mkdirSync11(dirname15(file), { recursive: true });
|
|
31791
32515
|
appendFileSync(file, `${line}
|
|
31792
32516
|
`);
|
|
31793
|
-
const lines2 =
|
|
32517
|
+
const lines2 = readFileSync21(file, "utf-8").split("\n").filter(Boolean);
|
|
31794
32518
|
if (lines2.length > SYNC_LOG_MAX_LINES) {
|
|
31795
|
-
|
|
32519
|
+
writeFileSync11(file, `${lines2.slice(-SYNC_LOG_MAX_LINES).join("\n")}
|
|
31796
32520
|
`);
|
|
31797
32521
|
}
|
|
31798
32522
|
}
|
|
@@ -31814,7 +32538,7 @@ async function runAutoSync(deps) {
|
|
|
31814
32538
|
const state = settings.autoSyncState ?? {};
|
|
31815
32539
|
const lastRunAt = state.lastRunAt ?? 0;
|
|
31816
32540
|
if (now - lastRunAt < windowMs) return;
|
|
31817
|
-
const reservationFile = deps.reservationFile ?? `${settingsFile ?? join21(
|
|
32541
|
+
const reservationFile = deps.reservationFile ?? `${settingsFile ?? join21(homedir29(), ".config", "aistack", "settings.json")}.auto-sync-attempt`;
|
|
31818
32542
|
if (!reserveAttempt(reservationFile, now, windowMs)) return;
|
|
31819
32543
|
saveSettings({ autoSyncState: { ...state, lastRunAt: now } }, settingsFile);
|
|
31820
32544
|
const stage = deps.stageImpl ?? stageSync;
|
|
@@ -31908,7 +32632,7 @@ async function runAutoSync(deps) {
|
|
|
31908
32632
|
logFile,
|
|
31909
32633
|
`${stamp} fail (${consecutiveFailures} in a row) - ${failure2}`
|
|
31910
32634
|
);
|
|
31911
|
-
if (shouldWarn && deps.suppressOutput !== true && process.env.AISTACK_HOOK_SOURCE !== "grok" && process.env.AISTACK_HOOK_SOURCE !== "cursor") {
|
|
32635
|
+
if (shouldWarn && deps.suppressOutput !== true && process.env.AISTACK_HOOK_SOURCE !== "grok" && process.env.AISTACK_HOOK_SOURCE !== "cursor" && process.env.AISTACK_HOOK_SOURCE !== "antigravity") {
|
|
31912
32636
|
emit2(
|
|
31913
32637
|
JSON.stringify({
|
|
31914
32638
|
systemMessage: `aistack auto-sync failed ${consecutiveFailures} times in a row (${failure2}). Run \`${FIX_COMMAND}\` in a terminal to fix it, or \`${FIX_COMMAND} --auto off\` to stop these runs.`
|