Run the dsh-archive-agent-notes audit over every active Agent Note on current master, judging each record by whether its rationale still guides work rather than by size or age. - Archive 453 implemented bilingual triplets (417,882 English words): completed UI chrome, narrow adapters, closed bug fixes, implementation walkthroughs whose package READMEs, docs pages, generators, or successor notes now carry the useful behavior, and 51 records fully superseded by a later active note. Keep 201 implemented notes whose ownership rules, negative guarantees, durable or wire semantics, security rules, reintroduction conditions, or still-tempting rejected alternatives remain useful. - Reject 7 proposals whose premise is gone or whose work shipped in amended form under other records; delete 2 rejected notes that no longer prevent a plausible mistake. - Retarget every remaining inbound link to the archived path, and repair active prose that named an archived record as the owner of a live fact: parenthetical citations drop, ownership sentences redirect to the README, docs page, or active note that states the fact, and history citations say so. Chinese files link the English archived path because the pairing gate treats the frozen tree as outside the bilingual corpus. - Seal 1,359 new frozen artifacts; existing seals are unchanged and outbound links from archived notes are neither inspected nor repaired. - Regenerate docs/config-catalog.md after the hook-bridge comment edits shifted two source line numbers.
108 lines
4.0 KiB
TypeScript
108 lines
4.0 KiB
TypeScript
/** Cross-platform native single-directory chooser behind the native backend's capability. */
|
|
|
|
import { runNativeCommand, type NativeCommandRunner } from '@deepseek-ai/dsh-native-command'
|
|
import { pickWin32Directory } from './win32-dialog.ts'
|
|
|
|
/** Testable command boundary; native implementations never invoke a shell. */
|
|
export type DirectoryPickerRunner = NativeCommandRunner
|
|
|
|
/** Injectable platform facts for deterministic adapter tests. */
|
|
export interface DirectoryPickerInternals {
|
|
platform?: NodeJS.Platform
|
|
run?: DirectoryPickerRunner
|
|
/** Replaces the in-process Win32 dialog (`pickWin32Directory`) for deterministic tests. */
|
|
pickWin32Dialog?: (signal: AbortSignal) => Promise<string | null>
|
|
}
|
|
|
|
function outputPath(stdout: string): string | null {
|
|
const path = stdout.replace(/[\r\n]+$/, '')
|
|
return path === '' ? null : path
|
|
}
|
|
|
|
function errorCode(error: unknown): string | number | undefined {
|
|
if (typeof error !== 'object' || error === null || !('code' in error)) return undefined
|
|
const code = (error as { code?: unknown }).code
|
|
return typeof code === 'string' || typeof code === 'number' ? code : undefined
|
|
}
|
|
|
|
function errorStderr(error: unknown): string {
|
|
if (typeof error !== 'object' || error === null || !('stderr' in error)) return ''
|
|
const stderr = (error as { stderr?: unknown }).stderr
|
|
return typeof stderr === 'string' ? stderr : ''
|
|
}
|
|
|
|
function isMissingCommand(error: unknown): boolean {
|
|
return errorCode(error) === 'ENOENT'
|
|
}
|
|
|
|
function rethrowIfAborted(signal: AbortSignal, error: unknown): void {
|
|
if (signal.aborted) throw error
|
|
}
|
|
|
|
/**
|
|
* Open the platform directory picker.
|
|
* @param signal - caller/connection lifetime; abort terminates the native command.
|
|
* @param internals - Platform and runner hooks for deterministic tests.
|
|
* @returns the selected path, or null when the user cancels.
|
|
*/
|
|
export async function pickNativeDirectory(
|
|
signal: AbortSignal,
|
|
internals: DirectoryPickerInternals = {},
|
|
): Promise<string | null> {
|
|
const platform = internals.platform ?? process.platform
|
|
const run = internals.run ?? runNativeCommand
|
|
|
|
if (platform === 'darwin') {
|
|
try {
|
|
const result = await run('osascript', [
|
|
'-e', 'set selectedFolder to choose folder with prompt "Select Workspace Directory"',
|
|
'-e', 'POSIX path of selectedFolder',
|
|
], signal)
|
|
return outputPath(result.stdout)
|
|
} catch (error: unknown) {
|
|
if (!signal.aborted && errorCode(error) === 1
|
|
&& /(?:User canceled|-128)/i.test(errorStderr(error))) return null
|
|
throw error
|
|
}
|
|
}
|
|
|
|
if (platform === 'win32') {
|
|
// The koffi-backed IFileOpenDialog child process — the modern picker with
|
|
// per-monitor-v2 DPI and abort support. koffi is a packaged dependency
|
|
// whose availability the install guarantees, so there is no fallback
|
|
// tier: any failure surfaces as-is (no PowerShell fallback tier; see
|
|
// .agents/notes/archived/simplification/2026-08-04-drop-windows-powershell-picker-fallback.md).
|
|
const pickDialog = internals.pickWin32Dialog ?? pickWin32Directory
|
|
return await pickDialog(signal)
|
|
}
|
|
|
|
if (platform === 'linux') {
|
|
try {
|
|
const result = await run('zenity', [
|
|
'--file-selection', '--directory', '--title=Select Workspace Directory',
|
|
], signal)
|
|
return outputPath(result.stdout)
|
|
} catch (error: unknown) {
|
|
rethrowIfAborted(signal, error)
|
|
if (errorCode(error) === 1) return null
|
|
if (!isMissingCommand(error)) throw error
|
|
}
|
|
|
|
try {
|
|
const result = await run('kdialog', [
|
|
'--getexistingdirectory', '.', '--title', 'Select Workspace Directory',
|
|
], signal)
|
|
return outputPath(result.stdout)
|
|
} catch (error: unknown) {
|
|
rethrowIfAborted(signal, error)
|
|
if (errorCode(error) === 1) return null
|
|
if (isMissingCommand(error)) {
|
|
throw new Error('no supported native directory picker found (install zenity or kdialog)')
|
|
}
|
|
throw error
|
|
}
|
|
}
|
|
|
|
throw new Error(`native directory picker is unsupported on ${platform}`)
|
|
}
|