mirror of
https://github.com/AgentSeal/codeburn.git
synced 2026-11-29 02:39:13 +00:00
Some checks are pending
CI / semgrep (push) Waiting to run
macOS Menubar CI / test (push) Waiting to run
Tests / test (22) (push) Waiting to run
Tests / test (22.13.0) (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-platforms (windows-latest) (push) Waiting to run
Tests / desktop (push) Waiting to run
Tests / vscode (push) Waiting to run
Windows Menubar CI / check (ubuntu-latest) (push) Waiting to run
Windows Menubar CI / check (windows-latest) (push) Waiting to run
* feat(app): transient project selector in the desktop top bar Scopes every report to one project path for the current session through the same narrowing the VS Code workspace scope uses. The saved project filter is never written; a restart is back on all projects. * fix(app): let the name pickers ellipsize before the top bar overflows * fix(app): list only selectable, non-zero projects in the top bar picker Rows with no session cwd (the Cursor and Grok Bot imports, provider label fallbacks) report their label as the path, so the picker offered names the bridge refuses and dash-to-slash guesses like eywa/lab. Keep only absolute paths, and drop rows whose lifetime cost rounds to $0.00. The old test that rooted a slashless Codex path is replaced: Codex now records the absolute cwd, and a slashless path is always the label fallback. * fix(app): show a toast when a project pick is refused The pick was dropped silently. Also pin that an encoded -Users-... label never reaches the picker list.
49 lines
2.1 KiB
TypeScript
49 lines
2.1 KiB
TypeScript
import { createHash } from 'node:crypto'
|
|
import { lstatSync, readFileSync } from 'node:fs'
|
|
import { dirname, isAbsolute, resolve } from 'node:path'
|
|
|
|
export { scopeFilter } from '../../app/electron/bridge-handlers'
|
|
|
|
/**
|
|
* The project path the CLI files a session under when it was started in `dir`:
|
|
* the directory itself, except inside a linked git worktree, which the CLI
|
|
* folds into its main repository (src/parser.ts resolveCanonicalProjectPath).
|
|
*/
|
|
export function canonicalProjectPath(dir: string): string {
|
|
if (!isAbsolute(dir)) return dir
|
|
let current = dir
|
|
for (;;) {
|
|
const gitEntry = resolve(current, '.git')
|
|
let stat
|
|
try { stat = lstatSync(gitEntry) } catch { stat = null }
|
|
if (stat?.isDirectory()) return dir
|
|
if (stat?.isFile()) {
|
|
let gitFile: string
|
|
try { gitFile = readFileSync(gitEntry, 'utf-8') } catch { return dir }
|
|
const match = gitFile.match(/^gitdir:\s*(.+?)\s*$/m)
|
|
if (!match?.[1]) return dir
|
|
const gitDir = resolve(current, match[1])
|
|
const markerIndex = gitDir.replace(/\\/g, '/').lastIndexOf('/.git/worktrees/')
|
|
return markerIndex === -1 ? dir : gitDir.slice(0, markerIndex)
|
|
}
|
|
const parent = dirname(current)
|
|
if (parent === current) return dir
|
|
current = parent
|
|
}
|
|
}
|
|
|
|
export type WorkspaceScope = {
|
|
/** Rooted `--project` patterns, one per workspace folder. */
|
|
paths: string[]
|
|
/** What the scope switch calls this workspace; null with no folder open. */
|
|
label: string | null
|
|
/** Stable id for the paths, used to keep each scope's cached views apart. */
|
|
id: string
|
|
}
|
|
|
|
export function workspaceScope(folders: ReadonlyArray<{ fsPath: string; name: string }>, workspaceName?: string): WorkspaceScope {
|
|
const paths = [...new Set(folders.filter(folder => isAbsolute(folder.fsPath)).map(folder => canonicalProjectPath(folder.fsPath)))]
|
|
if (paths.length === 0) return { paths, label: null, id: 'none' }
|
|
const label = folders.length > 1 && workspaceName ? workspaceName : folders[0]!.name
|
|
return { paths, label, id: createHash('sha256').update(paths.join('\0')).digest('hex').slice(0, 12) }
|
|
}
|