mirror of
https://github.com/Ark0N/Codeman.git
synced 2026-10-04 22:49:41 +02:00
chore: project setup and tooling cleanup (#26)
* add project setup * add tools to eslint * remove contributing.md * update claude md * chore: simplify CI to single Node.js version (22) Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com> * use node 20 * adjust formatting * fix linting * format * fix layout * fix: align CI node version to .nvmrc (22), remove redundant gotcha Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com> --------- Co-authored-by: Claude Sonnet 4.6 <noreply@anthropic.com> Co-authored-by: arkon <arkon.85@hotmail.com>
This commit is contained in:
co-authored by
Claude Sonnet 4.6
arkon
parent
2b2829ebde
commit
480584de63
@@ -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
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -240,17 +229,18 @@ export class CleanupManager implements Disposable {
|
||||
* @param description - Human-readable description
|
||||
* @returns Registration ID
|
||||
*/
|
||||
registerStream(
|
||||
stream: { destroy?: () => void; close?: () => void },
|
||||
description: string
|
||||
): string {
|
||||
return this.registerCleanup('stream', () => {
|
||||
if (stream.destroy) {
|
||||
stream.destroy();
|
||||
} else if (stream.close) {
|
||||
stream.close();
|
||||
}
|
||||
}, description);
|
||||
registerStream(stream: { destroy?: () => void; close?: () => void }, description: string): string {
|
||||
return this.registerCleanup(
|
||||
'stream',
|
||||
() => {
|
||||
if (stream.destroy) {
|
||||
stream.destroy();
|
||||
} else if (stream.close) {
|
||||
stream.close();
|
||||
}
|
||||
},
|
||||
description
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -297,8 +287,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(', ')
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+2
-11
@@ -19,17 +19,8 @@ export {
|
||||
createAnsiPatternSimple,
|
||||
stripAnsi,
|
||||
} from './regex-patterns.js';
|
||||
export {
|
||||
MAX_SESSION_TOKENS,
|
||||
validateTokenCounts,
|
||||
validateTokensAndCost,
|
||||
} from './token-validation.js';
|
||||
export {
|
||||
stringSimilarity,
|
||||
normalizePhrase,
|
||||
fuzzyPhraseMatch,
|
||||
todoContentHash,
|
||||
} from './string-similarity.js';
|
||||
export { MAX_SESSION_TOKENS, validateTokenCounts, validateTokensAndCost } from './token-validation.js';
|
||||
export { stringSimilarity, normalizePhrase, fuzzyPhraseMatch, todoContentHash } from './string-similarity.js';
|
||||
export { assertNever } from './type-safety.js';
|
||||
export { wrapWithNice } from './nice-wrapper.js';
|
||||
export { findClaudeDir, getAugmentedPath } from './claude-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,6 +17,7 @@
|
||||
* Use this when you need complete ANSI stripping including OSC sequences.
|
||||
* Note: Has global flag - reset lastIndex before exec() if reusing.
|
||||
*/
|
||||
// eslint-disable-next-line no-control-regex
|
||||
export const ANSI_ESCAPE_PATTERN_FULL = /\x1b(?:\[[0-9;?]*[A-Za-z]|\][^\x07\x1b]*(?:\x07|\x1b\\)|[=>])/g;
|
||||
|
||||
/**
|
||||
@@ -26,6 +27,7 @@ export const ANSI_ESCAPE_PATTERN_FULL = /\x1b(?:\[[0-9;?]*[A-Za-z]|\][^\x07\x1b]
|
||||
* Use this for faster stripping when OSC sequences aren't a concern.
|
||||
* Note: Has global flag - reset lastIndex before exec() if reusing.
|
||||
*/
|
||||
// eslint-disable-next-line no-control-regex
|
||||
export const ANSI_ESCAPE_PATTERN_SIMPLE = /\x1b\[[0-9;]*[A-Za-z]/g;
|
||||
|
||||
/**
|
||||
@@ -43,6 +45,7 @@ export const TOKEN_PATTERN = /(\d+(?:\.\d+)?)\s*([kKmM])?\s*tokens/;
|
||||
* Use when you need a pattern without shared lastIndex state.
|
||||
*/
|
||||
export function createAnsiPatternFull(): RegExp {
|
||||
// eslint-disable-next-line no-control-regex
|
||||
return /\x1b(?:\[[0-9;?]*[A-Za-z]|\][^\x07\x1b]*(?:\x07|\x1b\\)|[=>])/g;
|
||||
}
|
||||
|
||||
@@ -51,6 +54,7 @@ export function createAnsiPatternFull(): RegExp {
|
||||
* Use when you need a pattern without shared lastIndex state.
|
||||
*/
|
||||
export function createAnsiPatternSimple(): RegExp {
|
||||
// eslint-disable-next-line no-control-regex
|
||||
return /\x1b\[[0-9;]*[A-Za-z]/g;
|
||||
}
|
||||
|
||||
@@ -74,5 +78,4 @@ export function stripAnsi(text: string): string {
|
||||
*/
|
||||
export const SPINNER_PATTERN = /[⠋⠙⠹⠸⠼⠴⠦⠧]/;
|
||||
|
||||
export const SAFE_PATH_PATTERN = /^[a-zA-Z0-9_\/\-. ~]+$/;
|
||||
|
||||
export const SAFE_PATH_PATTERN = /^[a-zA-Z0-9_/\-. ~]+$/;
|
||||
|
||||
@@ -245,29 +245,23 @@ export class StaleExpirationMap<K, V> implements Disposable {
|
||||
/**
|
||||
* Get all keys (non-expired).
|
||||
*/
|
||||
keys(): IterableIterator<K> {
|
||||
const self = this;
|
||||
return (function* () {
|
||||
for (const [key, entry] of self.entries) {
|
||||
if (!self.isExpired(entry)) {
|
||||
yield key;
|
||||
}
|
||||
*keys(): IterableIterator<K> {
|
||||
for (const [key, entry] of this.entries) {
|
||||
if (!this.isExpired(entry)) {
|
||||
yield key;
|
||||
}
|
||||
})();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get all values (non-expired).
|
||||
*/
|
||||
values(): IterableIterator<V> {
|
||||
const self = this;
|
||||
return (function* () {
|
||||
for (const [, entry] of self.entries) {
|
||||
if (!self.isExpired(entry)) {
|
||||
yield entry.value;
|
||||
}
|
||||
*values(): IterableIterator<V> {
|
||||
for (const [, entry] of this.entries) {
|
||||
if (!this.isExpired(entry)) {
|
||||
yield entry.value;
|
||||
}
|
||||
})();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -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
|
||||
);
|
||||
}
|
||||
@@ -139,7 +139,7 @@ export function isSimilarByDistance(a: string, b: string, maxDistance = 2): bool
|
||||
export function normalizePhrase(phrase: string): string {
|
||||
return phrase
|
||||
.toUpperCase()
|
||||
.replace(/[\s_\-\.]+/g, '') // Remove whitespace, underscores, hyphens, dots
|
||||
.replace(/[\s_\-.]+/g, '') // Remove whitespace, underscores, hyphens, dots
|
||||
.trim();
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -21,10 +21,7 @@ export const MAX_SESSION_TOKENS = 500_000;
|
||||
* @param outputTokens - Output token count to validate
|
||||
* @returns Object with isValid flag and optional error reason
|
||||
*/
|
||||
export function validateTokenCounts(
|
||||
inputTokens: number,
|
||||
outputTokens: number
|
||||
): { isValid: boolean; reason?: string } {
|
||||
export function validateTokenCounts(inputTokens: number, outputTokens: number): { isValid: boolean; reason?: string } {
|
||||
if (inputTokens < 0 || outputTokens < 0) {
|
||||
return {
|
||||
isValid: false,
|
||||
|
||||
Reference in New Issue
Block a user