feat: add TypeScript declaration files for all core libraries
Add .d.ts type definitions for all four library modules:
- utils.d.ts: Platform detection, file ops, hook I/O, git helpers
- package-manager.d.ts: PM detection with PackageManagerName union type,
DetectionSource union, and typed config interfaces
- session-manager.d.ts: Session CRUD with Session, SessionMetadata,
SessionStats, and SessionListResult interfaces
- session-aliases.d.ts: Alias management with typed result interfaces
for set, delete, rename, and cleanup operations
These provide IDE autocomplete and type-checking for TypeScript
consumers of the npm package without converting the source to TS.
2026-02-12 13:56:48 -08:00
|
|
|
/**
|
|
|
|
|
* Session Aliases Library for Claude Code.
|
|
|
|
|
* Manages named aliases for session files, stored in ~/.claude/session-aliases.json.
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
/** Internal alias storage entry */
|
|
|
|
|
export interface AliasEntry {
|
|
|
|
|
sessionPath: string;
|
|
|
|
|
createdAt: string;
|
|
|
|
|
updatedAt?: string;
|
|
|
|
|
title: string | null;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/** Alias data structure stored on disk */
|
|
|
|
|
export interface AliasStore {
|
|
|
|
|
version: string;
|
|
|
|
|
aliases: Record<string, AliasEntry>;
|
|
|
|
|
metadata: {
|
|
|
|
|
totalCount: number;
|
|
|
|
|
lastUpdated: string;
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/** Resolved alias information returned by resolveAlias */
|
|
|
|
|
export interface ResolvedAlias {
|
|
|
|
|
alias: string;
|
|
|
|
|
sessionPath: string;
|
|
|
|
|
createdAt: string;
|
|
|
|
|
title: string | null;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/** Alias entry returned by listAliases */
|
|
|
|
|
export interface AliasListItem {
|
|
|
|
|
name: string;
|
|
|
|
|
sessionPath: string;
|
|
|
|
|
createdAt: string;
|
|
|
|
|
updatedAt?: string;
|
|
|
|
|
title: string | null;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/** Result from mutation operations (set, delete, rename, update, cleanup) */
|
|
|
|
|
export interface AliasResult {
|
|
|
|
|
success: boolean;
|
|
|
|
|
error?: string;
|
|
|
|
|
[key: string]: unknown;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export interface SetAliasResult extends AliasResult {
|
|
|
|
|
isNew?: boolean;
|
|
|
|
|
alias?: string;
|
|
|
|
|
sessionPath?: string;
|
|
|
|
|
title?: string | null;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export interface DeleteAliasResult extends AliasResult {
|
|
|
|
|
alias?: string;
|
|
|
|
|
deletedSessionPath?: string;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export interface RenameAliasResult extends AliasResult {
|
|
|
|
|
oldAlias?: string;
|
|
|
|
|
newAlias?: string;
|
|
|
|
|
sessionPath?: string;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export interface CleanupResult {
|
|
|
|
|
totalChecked: number;
|
|
|
|
|
removed: number;
|
|
|
|
|
removedAliases: Array<{ name: string; sessionPath: string }>;
|
|
|
|
|
error?: string;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export interface ListAliasesOptions {
|
|
|
|
|
/** Filter aliases by name or title (partial match, case-insensitive) */
|
|
|
|
|
search?: string | null;
|
|
|
|
|
/** Maximum number of aliases to return */
|
|
|
|
|
limit?: number | null;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/** Get the path to the aliases JSON file */
|
|
|
|
|
export function getAliasesPath(): string;
|
|
|
|
|
|
|
|
|
|
/** Load all aliases from disk. Returns default structure if file doesn't exist. */
|
|
|
|
|
export function loadAliases(): AliasStore;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Save aliases to disk with atomic write (temp file + rename).
|
|
|
|
|
* Creates backup before writing; restores on failure.
|
|
|
|
|
*/
|
|
|
|
|
export function saveAliases(aliases: AliasStore): boolean;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Resolve an alias name to its session data.
|
|
|
|
|
* @returns Alias data, or null if not found or invalid name
|
|
|
|
|
*/
|
|
|
|
|
export function resolveAlias(alias: string): ResolvedAlias | null;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Create or update an alias for a session.
|
|
|
|
|
* Alias names must be alphanumeric with dashes/underscores.
|
|
|
|
|
* Reserved names (list, help, remove, delete, create, set) are rejected.
|
|
|
|
|
*/
|
|
|
|
|
export function setAlias(alias: string, sessionPath: string, title?: string | null): SetAliasResult;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* List all aliases, optionally filtered and limited.
|
|
|
|
|
* Results are sorted by updated time (newest first).
|
|
|
|
|
*/
|
|
|
|
|
export function listAliases(options?: ListAliasesOptions): AliasListItem[];
|
|
|
|
|
|
|
|
|
|
/** Delete an alias by name */
|
|
|
|
|
export function deleteAlias(alias: string): DeleteAliasResult;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Rename an alias. Fails if old alias doesn't exist or new alias already exists.
|
|
|
|
|
* New alias name must be alphanumeric with dashes/underscores.
|
|
|
|
|
*/
|
|
|
|
|
export function renameAlias(oldAlias: string, newAlias: string): RenameAliasResult;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Resolve an alias or pass through a session path.
|
|
|
|
|
* First tries to resolve as alias; if not found, returns the input as-is.
|
|
|
|
|
*/
|
|
|
|
|
export function resolveSessionAlias(aliasOrId: string): string;
|
|
|
|
|
|
fix: 6 bugs fixed, 67 tests added for session-manager and session-aliases
Bug fixes:
- utils.js: prevent duplicate 'g' flag in countInFile regex construction
- validate-agents.js: handle CRLF line endings in frontmatter parsing
- validate-hooks.js: handle \t and \\ escape sequences in inline JS validation
- session-aliases.js: prevent NaN in date sort when timestamps are missing
- session-aliases.js: persist rollback on rename failure instead of silent loss
- session-manager.js: require absolute paths in getSessionStats to prevent
content strings ending with .tmp from being treated as file paths
New tests (164 total, up from 97):
- session-manager.test.js: 27 tests covering parseSessionFilename,
parseSessionMetadata, getSessionStats, CRUD operations, getSessionSize,
getSessionTitle, edge cases (null input, non-existent files, directories)
- session-aliases.test.js: 40 tests covering loadAliases (corrupted JSON,
invalid structure), setAlias (validation, reserved names), resolveAlias,
listAliases (sort, search, limit), deleteAlias, renameAlias, updateAliasTitle,
resolveSessionAlias, getAliasesForSession, cleanupAliases, atomic write
Also includes hook-generated improvements:
- utils.d.ts: document that readStdinJson never rejects
- session-aliases.d.ts: fix updateAliasTitle type to accept null
- package-manager.js: add try-catch to setProjectPackageManager writeFile
2026-02-12 15:50:04 -08:00
|
|
|
/** Update the title of an existing alias. Pass null to clear. */
|
|
|
|
|
export function updateAliasTitle(alias: string, title: string | null): AliasResult;
|
feat: add TypeScript declaration files for all core libraries
Add .d.ts type definitions for all four library modules:
- utils.d.ts: Platform detection, file ops, hook I/O, git helpers
- package-manager.d.ts: PM detection with PackageManagerName union type,
DetectionSource union, and typed config interfaces
- session-manager.d.ts: Session CRUD with Session, SessionMetadata,
SessionStats, and SessionListResult interfaces
- session-aliases.d.ts: Alias management with typed result interfaces
for set, delete, rename, and cleanup operations
These provide IDE autocomplete and type-checking for TypeScript
consumers of the npm package without converting the source to TS.
2026-02-12 13:56:48 -08:00
|
|
|
|
|
|
|
|
/** Get all aliases that point to a specific session path */
|
|
|
|
|
export function getAliasesForSession(sessionPath: string): Array<{ name: string; createdAt: string; title: string | null }>;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Remove aliases whose sessions no longer exist.
|
|
|
|
|
* @param sessionExists - Function that returns true if a session path is valid
|
|
|
|
|
*/
|
|
|
|
|
export function cleanupAliases(sessionExists: (sessionPath: string) => boolean): CleanupResult;
|