mirror of
https://github.com/AgentSeal/codeburn.git
synced 2026-11-29 02:39:13 +00:00
Honor redirected Copilot and Cursor storage roots (#1624)
Some checks are pending
CI / semgrep (push) Waiting to run
Tests / test (22) (push) Waiting to run
Tests / test (24) (push) Waiting to run
Tests / test (26) (push) Waiting to run
Tests / test-platforms (macos-latest) (push) Waiting to run
Tests / test (22.13.0) (push) Waiting to run
Tests / test-platforms (windows-latest) (push) Waiting to run
Tests / desktop (push) Waiting to run
Some checks are pending
CI / semgrep (push) Waiting to run
Tests / test (22) (push) Waiting to run
Tests / test (24) (push) Waiting to run
Tests / test (26) (push) Waiting to run
Tests / test-platforms (macos-latest) (push) Waiting to run
Tests / test (22.13.0) (push) Waiting to run
Tests / test-platforms (windows-latest) (push) Waiting to run
Tests / desktop (push) Waiting to run
* Add regressions for redirected editor storage roots * Honor redirected data roots for Copilot and Cursor * Verify redirected Copilot OTel discovery on Linux * Reproduce Cursor cache collisions across storage roots * Bind Cursor result caches to their database and backfill redirected history * Verify redirected discovery against the latest daily cache * Update env guard and document editor storage overrides
This commit is contained in:
parent
fa12ebb971
commit
2f2a14fb70
14 changed files with 273 additions and 88 deletions
|
|
@ -1,5 +1,5 @@
|
|||
import { readFile, writeFile, mkdir, rename, stat, unlink } from 'fs/promises'
|
||||
import { join } from 'path'
|
||||
import { join, resolve } from 'path'
|
||||
import { randomBytes } from 'crypto'
|
||||
|
||||
import { getCodeburnCacheDir, readExistingTextFile } from './cache-dir.js'
|
||||
|
|
@ -19,7 +19,9 @@ import type { ParsedProviderCall } from './providers/types.js'
|
|||
// (cursor:composer-input:<id>) with per-conversation source selection, the
|
||||
// agent stream regained tool/system context and stream-only sessions, and
|
||||
// tool names are canonicalized. v5 results mix crediting regimes.
|
||||
export const CURSOR_CACHE_VERSION = 6
|
||||
// Version 7: a redirected data root can select a different database whose
|
||||
// size and timestamps happen to match. Cache identity includes its path.
|
||||
export const CURSOR_CACHE_VERSION = 7
|
||||
export const CURSOR_LEGACY_CACHE_FILE = 'cursor-results.json'
|
||||
export function cursorCacheFileName(version = CURSOR_CACHE_VERSION): string {
|
||||
return `cursor-results.v${version}.json`
|
||||
|
|
@ -27,6 +29,7 @@ export function cursorCacheFileName(version = CURSOR_CACHE_VERSION): string {
|
|||
|
||||
type ResultCache = {
|
||||
version?: number
|
||||
dbPath: string
|
||||
dbMtimeMs: number
|
||||
dbSizeBytes: number
|
||||
lookbackFloor: string
|
||||
|
|
@ -41,9 +44,10 @@ function getLegacyCachePath(): string {
|
|||
return join(getCodeburnCacheDir(), CURSOR_LEGACY_CACHE_FILE)
|
||||
}
|
||||
|
||||
function isCurrentHit(cache: ResultCache, fp: { mtimeMs: number; size: number }, requestedFloor: string): boolean {
|
||||
function isCurrentHit(cache: ResultCache, dbPath: string, fp: { mtimeMs: number; size: number }, requestedFloor: string): boolean {
|
||||
return (
|
||||
cache.version === CURSOR_CACHE_VERSION
|
||||
&& cache.dbPath === resolve(dbPath)
|
||||
&& cache.dbMtimeMs === fp.mtimeMs
|
||||
&& cache.dbSizeBytes === fp.size
|
||||
&& typeof cache.lookbackFloor === 'string'
|
||||
|
|
@ -93,7 +97,7 @@ export async function readCachedResults(
|
|||
if (versioned.status === 'ok') {
|
||||
try {
|
||||
const cache = JSON.parse(versioned.text) as ResultCache
|
||||
if (cache && typeof cache === 'object' && isCurrentHit(cache, fp, requestedFloor)) return cache.calls
|
||||
if (cache && typeof cache === 'object' && isCurrentHit(cache, dbPath, fp, requestedFloor)) return cache.calls
|
||||
} catch {}
|
||||
return null
|
||||
}
|
||||
|
|
@ -102,7 +106,7 @@ export async function readCachedResults(
|
|||
// Versioned file is absent (ENOENT). Adopt the unsuffixed file only when its
|
||||
// version and fingerprint match — old binaries still own that path.
|
||||
const legacy = await readCacheFile(getLegacyCachePath())
|
||||
if (legacy && isCurrentHit(legacy, fp, requestedFloor)) return legacy.calls
|
||||
if (legacy && isCurrentHit(legacy, dbPath, fp, requestedFloor)) return legacy.calls
|
||||
return null
|
||||
} catch {
|
||||
return null
|
||||
|
|
@ -125,6 +129,7 @@ export async function writeCachedResults(
|
|||
await mkdir(dir, { recursive: true }).catch(() => {})
|
||||
const cache: ResultCache = {
|
||||
version: CURSOR_CACHE_VERSION,
|
||||
dbPath: resolve(dbPath),
|
||||
dbMtimeMs: fp.mtimeMs,
|
||||
dbSizeBytes: fp.size,
|
||||
lookbackFloor,
|
||||
|
|
|
|||
|
|
@ -254,7 +254,9 @@ import type { DateRange, ProjectSummary } from './types.js'
|
|||
// needed.
|
||||
// v50: Hermes uses its native Windows LOCALAPPDATA root; finalized days can
|
||||
// miss sessions there and must be re-derived after the default path is fixed.
|
||||
export const DAILY_CACHE_VERSION = 50
|
||||
// v51: honor redirected Copilot and Cursor editor data roots. Backfill settled
|
||||
// days that previously missed usage stored under APPDATA or XDG_CONFIG_HOME.
|
||||
export const DAILY_CACHE_VERSION = 51
|
||||
const MIN_SUPPORTED_VERSION = 28
|
||||
|
||||
/// Providers whose per-day CALL COUNT means something different at
|
||||
|
|
|
|||
10
src/editor-data-dir.ts
Normal file
10
src/editor-data-dir.ts
Normal file
|
|
@ -0,0 +1,10 @@
|
|||
import { posix, win32 } from 'node:path'
|
||||
|
||||
/** Default Electron editor data directory, honoring the OS's redirected root. */
|
||||
export function getEditorDataDir(editor: string, home: string, os: string): string {
|
||||
if (os === 'darwin') return posix.join(home, 'Library', 'Application Support', editor)
|
||||
if (os === 'win32') {
|
||||
return win32.join(process.env['APPDATA'] || win32.join(home, 'AppData', 'Roaming'), editor)
|
||||
}
|
||||
return posix.join(process.env['XDG_CONFIG_HOME'] || posix.join(home, '.config'), editor)
|
||||
}
|
||||
|
|
@ -62,6 +62,7 @@ import { readdir, stat } from 'fs/promises'
|
|||
import { homedir, platform } from 'os'
|
||||
import { join, basename, dirname, posix, win32 } from 'path'
|
||||
import { existsSync } from 'fs'
|
||||
import { getEditorDataDir } from '../editor-data-dir.js'
|
||||
import { createHash } from 'crypto'
|
||||
import { readSessionFile } from '../fs-utils.js'
|
||||
import { calculateCost, modelKeyMatches } from '../models.js'
|
||||
|
|
@ -942,33 +943,8 @@ function getAgentTracesDbPath(): string | null {
|
|||
return existsSync(envOverride) ? envOverride : null
|
||||
}
|
||||
|
||||
const home = homedir()
|
||||
const candidates: string[] = []
|
||||
|
||||
const p = platform()
|
||||
if (p === 'darwin') {
|
||||
// macOS: VS Code, VS Code Insiders, VSCodium
|
||||
candidates.push(
|
||||
join(home, 'Library', 'Application Support', 'Code', 'User', 'globalStorage', 'github.copilot-chat', 'agent-traces.db'),
|
||||
join(home, 'Library', 'Application Support', 'Code - Insiders', 'User', 'globalStorage', 'github.copilot-chat', 'agent-traces.db'),
|
||||
join(home, 'Library', 'Application Support', 'VSCodium', 'User', 'globalStorage', 'github.copilot-chat', 'agent-traces.db'),
|
||||
)
|
||||
} else if (p === 'linux') {
|
||||
// Linux: VS Code, VS Code Insiders, VSCodium
|
||||
candidates.push(
|
||||
join(home, '.config', 'Code', 'User', 'globalStorage', 'github.copilot-chat', 'agent-traces.db'),
|
||||
join(home, '.config', 'Code - Insiders', 'User', 'globalStorage', 'github.copilot-chat', 'agent-traces.db'),
|
||||
join(home, '.config', 'VSCodium', 'User', 'globalStorage', 'github.copilot-chat', 'agent-traces.db'),
|
||||
)
|
||||
} else if (p === 'win32') {
|
||||
// Windows
|
||||
const appdata = process.env['APPDATA'] ?? join(home, 'AppData', 'Roaming')
|
||||
candidates.push(
|
||||
join(appdata, 'Code', 'User', 'globalStorage', 'github.copilot-chat', 'agent-traces.db'),
|
||||
join(appdata, 'Code - Insiders', 'User', 'globalStorage', 'github.copilot-chat', 'agent-traces.db'),
|
||||
join(appdata, 'VSCodium', 'User', 'globalStorage', 'github.copilot-chat', 'agent-traces.db'),
|
||||
)
|
||||
}
|
||||
const candidates = getVSCodeGlobalStorageDirs(homedir(), platform())
|
||||
.map(dir => join(dir, 'github.copilot-chat', 'agent-traces.db'))
|
||||
|
||||
for (const candidate of candidates) {
|
||||
if (existsSync(candidate)) return candidate
|
||||
|
|
@ -3392,54 +3368,19 @@ async function resolveJetBrainsProjectNames(
|
|||
* (Code, Code Insiders, VSCodium) on the given platform. Used to discover
|
||||
* transcript sessions written by the Copilot Chat extension.
|
||||
*
|
||||
* Accepts explicit `home` and `os` arguments so callers (and tests) can pass
|
||||
* custom values without relying on process-level globals.
|
||||
* Accepts explicit `home` and `os` arguments for the platform fallback.
|
||||
* APPDATA and XDG_CONFIG_HOME still come from the process environment.
|
||||
*/
|
||||
export function getVSCodeWorkspaceStorageDirs(home: string, os: string): string[] {
|
||||
const j = os === 'win32' ? win32.join : posix.join
|
||||
if (os === 'darwin') {
|
||||
return [
|
||||
j(home, 'Library', 'Application Support', 'Code', 'User', 'workspaceStorage'),
|
||||
j(home, 'Library', 'Application Support', 'Code - Insiders', 'User', 'workspaceStorage'),
|
||||
j(home, 'Library', 'Application Support', 'VSCodium', 'User', 'workspaceStorage'),
|
||||
]
|
||||
}
|
||||
if (os === 'linux') {
|
||||
return [
|
||||
j(home, '.config', 'Code', 'User', 'workspaceStorage'),
|
||||
j(home, '.config', 'Code - Insiders', 'User', 'workspaceStorage'),
|
||||
j(home, '.config', 'VSCodium', 'User', 'workspaceStorage'),
|
||||
]
|
||||
}
|
||||
// win32
|
||||
return [
|
||||
j(home, 'AppData', 'Roaming', 'Code', 'User', 'workspaceStorage'),
|
||||
j(home, 'AppData', 'Roaming', 'Code - Insiders', 'User', 'workspaceStorage'),
|
||||
j(home, 'AppData', 'Roaming', 'VSCodium', 'User', 'workspaceStorage'),
|
||||
]
|
||||
return ['Code', 'Code - Insiders', 'VSCodium']
|
||||
.map(editor => j(getEditorDataDir(editor, home, os), 'User', 'workspaceStorage'))
|
||||
}
|
||||
|
||||
export function getVSCodeGlobalStorageDirs(home: string, os: string): string[] {
|
||||
const j = os === 'win32' ? win32.join : posix.join
|
||||
if (os === 'darwin') {
|
||||
return [
|
||||
j(home, 'Library', 'Application Support', 'Code', 'User', 'globalStorage'),
|
||||
j(home, 'Library', 'Application Support', 'Code - Insiders', 'User', 'globalStorage'),
|
||||
j(home, 'Library', 'Application Support', 'VSCodium', 'User', 'globalStorage'),
|
||||
]
|
||||
}
|
||||
if (os === 'linux') {
|
||||
return [
|
||||
j(home, '.config', 'Code', 'User', 'globalStorage'),
|
||||
j(home, '.config', 'Code - Insiders', 'User', 'globalStorage'),
|
||||
j(home, '.config', 'VSCodium', 'User', 'globalStorage'),
|
||||
]
|
||||
}
|
||||
return [
|
||||
j(home, 'AppData', 'Roaming', 'Code', 'User', 'globalStorage'),
|
||||
j(home, 'AppData', 'Roaming', 'Code - Insiders', 'User', 'globalStorage'),
|
||||
j(home, 'AppData', 'Roaming', 'VSCodium', 'User', 'globalStorage'),
|
||||
]
|
||||
return ['Code', 'Code - Insiders', 'VSCodium']
|
||||
.map(editor => j(getEditorDataDir(editor, home, os), 'User', 'globalStorage'))
|
||||
}
|
||||
|
||||
// workspace.json holds `folder` (single root) or `workspace` (a multi-root
|
||||
|
|
|
|||
|
|
@ -1,6 +1,7 @@
|
|||
import { existsSync, readdirSync, readFileSync, statSync } from 'fs'
|
||||
import { join } from 'path'
|
||||
import { homedir } from 'os'
|
||||
import { getEditorDataDir } from '../editor-data-dir.js'
|
||||
|
||||
import { calculateCost } from '../models.js'
|
||||
import { extractBashCommands } from '../bash-utils.js'
|
||||
|
|
@ -86,13 +87,7 @@ function rethrowBusy(err: unknown): void {
|
|||
}
|
||||
|
||||
function getCursorDbPath(): string {
|
||||
if (process.platform === 'darwin') {
|
||||
return join(homedir(), 'Library', 'Application Support', 'Cursor', 'User', 'globalStorage', 'state.vscdb')
|
||||
}
|
||||
if (process.platform === 'win32') {
|
||||
return join(homedir(), 'AppData', 'Roaming', 'Cursor', 'User', 'globalStorage', 'state.vscdb')
|
||||
}
|
||||
return join(homedir(), '.config', 'Cursor', 'User', 'globalStorage', 'state.vscdb')
|
||||
return join(getEditorDataDir('Cursor', homedir(), process.platform), 'User', 'globalStorage', 'state.vscdb')
|
||||
}
|
||||
|
||||
function getCursorWorkspaceStorageDir(globalDbPath: string): string {
|
||||
|
|
|
|||
|
|
@ -305,7 +305,7 @@ export const PROVIDER_ENV_VARS: Record<string, string[]> = {
|
|||
'lingtai-tui': ['LINGTAI_HOME', 'LINGTAI_TUI_HOME', 'LINGTAI_TUI_GLOBAL_DIR'],
|
||||
droid: ['FACTORY_DIR'],
|
||||
dsh: ['DSH_HOME'],
|
||||
cursor: ['CODEBURN_CURSOR_MAX_BUBBLES'],
|
||||
cursor: ['CODEBURN_CURSOR_MAX_BUBBLES', 'APPDATA', 'XDG_CONFIG_HOME'],
|
||||
// XDG_DATA_HOME is stale here (cursor-agent never reads it) but deliberately
|
||||
// kept: removing it would force a re-parse to fix nothing.
|
||||
'cursor-agent': ['XDG_DATA_HOME'],
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue