mirror of
https://github.com/Ark0N/Codeman.git
synced 2026-10-05 23:19:43 +02:00
adjust formatting
This commit is contained in:
@@ -149,7 +149,7 @@ export class BufferAccumulator {
|
||||
* @returns True if buffer ends with the suffix
|
||||
*/
|
||||
endsWith(suffix: string): boolean {
|
||||
if (!suffix) return true; // All strings end with empty string
|
||||
if (!suffix) return true; // All strings end with empty string
|
||||
if (suffix.length > this.totalLength) return false;
|
||||
return this.tail(suffix.length) === suffix;
|
||||
}
|
||||
|
||||
@@ -57,7 +57,7 @@ export function findClaudeDir(): string | null {
|
||||
}
|
||||
}
|
||||
|
||||
_claudeDir = ''; // mark as searched, not found
|
||||
_claudeDir = ''; // mark as searched, not found
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
@@ -115,11 +115,7 @@ export class CleanupManager implements Disposable {
|
||||
* @param options - Optional configuration
|
||||
* @returns Timer ID for manual clearing if needed
|
||||
*/
|
||||
setTimeout(
|
||||
callback: () => void,
|
||||
delay: number,
|
||||
options?: TimerOptions
|
||||
): string {
|
||||
setTimeout(callback: () => void, delay: number, options?: TimerOptions): string {
|
||||
const id = uuidv4();
|
||||
const timeoutId = setTimeout(() => {
|
||||
// Remove registration when timer fires naturally
|
||||
@@ -148,11 +144,7 @@ export class CleanupManager implements Disposable {
|
||||
* @param options - Optional configuration
|
||||
* @returns Interval ID for manual clearing if needed
|
||||
*/
|
||||
setInterval(
|
||||
callback: () => void,
|
||||
delay: number,
|
||||
options?: TimerOptions
|
||||
): string {
|
||||
setInterval(callback: () => void, delay: number, options?: TimerOptions): string {
|
||||
const id = uuidv4();
|
||||
const intervalId = setInterval(() => {
|
||||
// Don't execute if stopped
|
||||
@@ -179,11 +171,7 @@ export class CleanupManager implements Disposable {
|
||||
* @param description - Human-readable description
|
||||
* @returns Registration ID for manual removal if needed
|
||||
*/
|
||||
registerCleanup(
|
||||
type: CleanupResourceType,
|
||||
cleanup: () => void,
|
||||
description: string
|
||||
): string {
|
||||
registerCleanup(type: CleanupResourceType, cleanup: () => void, description: string): string {
|
||||
const id = uuidv4();
|
||||
this.register({
|
||||
id,
|
||||
@@ -202,10 +190,7 @@ export class CleanupManager implements Disposable {
|
||||
* @param description - Human-readable description
|
||||
* @returns Registration ID
|
||||
*/
|
||||
registerWatcher(
|
||||
watcher: { close: () => void },
|
||||
description: string
|
||||
): string {
|
||||
registerWatcher(watcher: { close: () => void }, description: string): string {
|
||||
return this.registerCleanup('watcher', () => watcher.close(), description);
|
||||
}
|
||||
|
||||
@@ -218,19 +203,23 @@ export class CleanupManager implements Disposable {
|
||||
* @param description - Human-readable description
|
||||
* @returns Registration ID
|
||||
*/
|
||||
registerListener<T extends { removeListener?: (event: string, listener: () => void) => void; off?: (event: string, listener: () => void) => void }>(
|
||||
emitter: T,
|
||||
event: string,
|
||||
listener: () => void,
|
||||
description: string
|
||||
): string {
|
||||
return this.registerCleanup('listener', () => {
|
||||
if (emitter.removeListener) {
|
||||
emitter.removeListener(event, listener);
|
||||
} else if (emitter.off) {
|
||||
emitter.off(event, listener);
|
||||
}
|
||||
}, description);
|
||||
registerListener<
|
||||
T extends {
|
||||
removeListener?: (event: string, listener: () => void) => void;
|
||||
off?: (event: string, listener: () => void) => void;
|
||||
},
|
||||
>(emitter: T, event: string, listener: () => void, description: string): string {
|
||||
return this.registerCleanup(
|
||||
'listener',
|
||||
() => {
|
||||
if (emitter.removeListener) {
|
||||
emitter.removeListener(event, listener);
|
||||
} else if (emitter.off) {
|
||||
emitter.off(event, listener);
|
||||
}
|
||||
},
|
||||
description
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -244,13 +233,17 @@ export class CleanupManager implements Disposable {
|
||||
stream: { destroy?: () => void; close?: () => void },
|
||||
description: string
|
||||
): string {
|
||||
return this.registerCleanup('stream', () => {
|
||||
if (stream.destroy) {
|
||||
stream.destroy();
|
||||
} else if (stream.close) {
|
||||
stream.close();
|
||||
}
|
||||
}, description);
|
||||
return this.registerCleanup(
|
||||
'stream',
|
||||
() => {
|
||||
if (stream.destroy) {
|
||||
stream.destroy();
|
||||
} else if (stream.close) {
|
||||
stream.close();
|
||||
}
|
||||
},
|
||||
description
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -297,8 +290,10 @@ export class CleanupManager implements Disposable {
|
||||
this.registrations.clear();
|
||||
|
||||
if (errors.length > 0) {
|
||||
console.error(`[CleanupManager] ${errors.length} errors during disposal:`,
|
||||
errors.map(e => e.description).join(', '));
|
||||
console.error(
|
||||
`[CleanupManager] ${errors.length} errors during disposal:`,
|
||||
errors.map((e) => e.description).join(', ')
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+5
-1
@@ -33,4 +33,8 @@ export {
|
||||
export { assertNever } from './type-safety.js';
|
||||
export { wrapWithNice } from './nice-wrapper.js';
|
||||
export { findClaudeDir, getAugmentedPath } from './claude-cli-resolver.js';
|
||||
export { resolveOpenCodeDir, isOpenCodeAvailable, getOpenCodeAugmentedPath } from './opencode-cli-resolver.js';
|
||||
export {
|
||||
resolveOpenCodeDir,
|
||||
isOpenCodeAvailable,
|
||||
getOpenCodeAugmentedPath,
|
||||
} from './opencode-cli-resolver.js';
|
||||
|
||||
@@ -17,13 +17,13 @@ const EXEC_TIMEOUT_MS = 5000;
|
||||
|
||||
/** Common directories where the OpenCode CLI binary may be installed */
|
||||
const OPENCODE_SEARCH_DIRS = [
|
||||
join(homedir(), '.opencode', 'bin'), // Default install location
|
||||
join(homedir(), '.local', 'bin'), // Alternative install location
|
||||
'/usr/local/bin', // Homebrew / system
|
||||
join(homedir(), 'go', 'bin'), // Go install
|
||||
join(homedir(), '.bun', 'bin'), // Bun global
|
||||
join(homedir(), '.npm-global', 'bin'), // npm global
|
||||
join(homedir(), 'bin'), // User bin
|
||||
join(homedir(), '.opencode', 'bin'), // Default install location
|
||||
join(homedir(), '.local', 'bin'), // Alternative install location
|
||||
'/usr/local/bin', // Homebrew / system
|
||||
join(homedir(), 'go', 'bin'), // Go install
|
||||
join(homedir(), '.bun', 'bin'), // Bun global
|
||||
join(homedir(), '.npm-global', 'bin'), // npm global
|
||||
join(homedir(), 'bin'), // User bin
|
||||
];
|
||||
|
||||
/** Cached directory containing the opencode binary (empty string = searched but not found) */
|
||||
@@ -41,7 +41,10 @@ export function resolveOpenCodeDir(): string | null {
|
||||
|
||||
// Try `which` first (respects current PATH)
|
||||
try {
|
||||
const result = execSync('which opencode', { encoding: 'utf-8', timeout: EXEC_TIMEOUT_MS }).trim();
|
||||
const result = execSync('which opencode', {
|
||||
encoding: 'utf-8',
|
||||
timeout: EXEC_TIMEOUT_MS,
|
||||
}).trim();
|
||||
if (result && existsSync(result)) {
|
||||
_openCodeDir = dirname(result);
|
||||
return _openCodeDir;
|
||||
@@ -58,7 +61,7 @@ export function resolveOpenCodeDir(): string | null {
|
||||
}
|
||||
}
|
||||
|
||||
_openCodeDir = ''; // mark as searched, not found
|
||||
_openCodeDir = ''; // mark as searched, not found
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
@@ -17,7 +17,8 @@
|
||||
* Use this when you need complete ANSI stripping including OSC sequences.
|
||||
* Note: Has global flag - reset lastIndex before exec() if reusing.
|
||||
*/
|
||||
export const ANSI_ESCAPE_PATTERN_FULL = /\x1b(?:\[[0-9;?]*[A-Za-z]|\][^\x07\x1b]*(?:\x07|\x1b\\)|[=>])/g;
|
||||
export const ANSI_ESCAPE_PATTERN_FULL =
|
||||
/\x1b(?:\[[0-9;?]*[A-Za-z]|\][^\x07\x1b]*(?:\x07|\x1b\\)|[=>])/g;
|
||||
|
||||
/**
|
||||
* Simple ANSI CSI-only pattern for basic escape code stripping.
|
||||
@@ -75,4 +76,3 @@ export function stripAnsi(text: string): string {
|
||||
export const SPINNER_PATTERN = /[⠋⠙⠹⠸⠼⠴⠦⠧]/;
|
||||
|
||||
export const SAFE_PATH_PATTERN = /^[a-zA-Z0-9_\/\-. ~]+$/;
|
||||
|
||||
|
||||
@@ -55,8 +55,8 @@ export function levenshteinDistance(a: string, b: string): number {
|
||||
for (let i = 1; i <= m; i++) {
|
||||
const cost = a[i - 1] === b[j - 1] ? 0 : 1;
|
||||
curr[i] = Math.min(
|
||||
prev[i] + 1, // deletion
|
||||
curr[i - 1] + 1, // insertion
|
||||
prev[i] + 1, // deletion
|
||||
curr[i - 1] + 1, // insertion
|
||||
prev[i - 1] + cost // substitution
|
||||
);
|
||||
}
|
||||
@@ -161,11 +161,7 @@ export function normalizePhrase(phrase: string): string {
|
||||
* fuzzyPhraseMatch('TASK_DONE', 'TASKDONE') // true (separator)
|
||||
* fuzzyPhraseMatch('COMPLETE', 'FINISHED') // false (different word)
|
||||
*/
|
||||
export function fuzzyPhraseMatch(
|
||||
phrase1: string,
|
||||
phrase2: string,
|
||||
maxDistance = 2
|
||||
): boolean {
|
||||
export function fuzzyPhraseMatch(phrase1: string, phrase2: string, maxDistance = 2): boolean {
|
||||
const norm1 = normalizePhrase(phrase1);
|
||||
const norm2 = normalizePhrase(phrase2);
|
||||
|
||||
@@ -201,7 +197,7 @@ export function todoContentHash(content: string): string {
|
||||
let hash = 0;
|
||||
for (let i = 0; i < normalized.length; i++) {
|
||||
const char = normalized.charCodeAt(i);
|
||||
hash = ((hash << 5) - hash) + char;
|
||||
hash = (hash << 5) - hash + char;
|
||||
hash = hash & hash; // Convert to 32-bit integer
|
||||
}
|
||||
return hash.toString(36);
|
||||
|
||||
Reference in New Issue
Block a user