Files
oh-my-openagent/src/hooks/auto-slash-command/processed-command-store.ts
YeonGyu-Kim 1c54fdad26 feat(compat): package rename compatibility layer for oh-my-opencode → oh-my-openagent
- Add legacy plugin startup warning when oh-my-opencode config detected
- Update CLI installer and TUI installer for new package name
- Split monolithic config-manager.test.ts into focused test modules
- Add plugin config detection tests for legacy name fallback
- Update processed-command-store to use plugin-identity constants
- Add claude-code-plugin-loader discovery test for both config names
- Update chat-params and ultrawork-db tests for plugin identity

Part of #2823
2026-03-26 19:44:55 +09:00

75 lines
1.8 KiB
TypeScript

const MAX_PROCESSED_ENTRY_COUNT = 10_000
const PROCESSED_COMMAND_TTL_MS = 30_000
function pruneExpiredEntries(entries: Map<string, number>, now: number): void {
for (const [commandKey, expiresAt] of entries) {
if (expiresAt <= now) {
entries.delete(commandKey)
}
}
}
function trimProcessedEntries(entries: Map<string, number>): void {
if (entries.size <= MAX_PROCESSED_ENTRY_COUNT) {
return
}
const targetSize = Math.floor(entries.size / 2)
for (const commandKey of entries.keys()) {
if (entries.size <= targetSize) {
return
}
entries.delete(commandKey)
}
}
function removeSessionEntries(entries: Map<string, number>, sessionID: string): void {
const sessionPrefix = `${sessionID}:`
for (const entry of entries.keys()) {
if (entry.startsWith(sessionPrefix)) {
entries.delete(entry)
}
}
}
export interface ProcessedCommandStore {
has(commandKey: string): boolean
add(commandKey: string, ttlMs?: number): void
cleanupSession(sessionID: string): void
clear(): void
}
export function createProcessedCommandStore(): ProcessedCommandStore {
let entries = new Map<string, number>()
return {
has(commandKey: string): boolean {
const expiresAt = entries.get(commandKey)
if (expiresAt === undefined) {
return false
}
if (expiresAt <= Date.now()) {
entries.delete(commandKey)
return false
}
return true
},
add(commandKey: string, ttlMs = PROCESSED_COMMAND_TTL_MS): void {
const now = Date.now()
pruneExpiredEntries(entries, now)
entries.delete(commandKey)
entries.set(commandKey, now + ttlMs)
trimProcessedEntries(entries)
},
cleanupSession(sessionID: string): void {
removeSessionEntries(entries, sessionID)
},
clear(): void {
entries.clear()
},
}
}