Summary
Two small API hardening improvements surfaced during a code audit:
1. maxHistory accepts invalid values silently
createAskableContext({ maxHistory: -1 }) stores -1 without error. The history cap check then behaves oddly (history.length > -1 is always true, so every push trims the array immediately). Passing NaN falls through to the default of 50 silently.
Fix: Add a runtime guard in the constructor:
if (options?.maxHistory !== undefined && (options.maxHistory < 0 || !Number.isInteger(options.maxHistory))) {
throw new RangeError('maxHistory must be a non-negative integer');
}
2. hierarchyDepth: 0 is undocumented
Passing hierarchyDepth: 0 to any serialization method returns an empty ancestors array (all ancestor context is suppressed). This is intentional and the implementation is correct, but it is not documented in the type definition or API docs, so users may be confused when their ancestors disappear.
Fix: Add a JSDoc note to AskablePromptContextOptions.hierarchyDepth:
/**
* Maximum number of ancestor segments to include.
* Pass `0` to suppress all ancestor context.
* Defaults to unlimited.
*/
hierarchyDepth?: number;
Acceptance criteria
Summary
Two small API hardening improvements surfaced during a code audit:
1.
maxHistoryaccepts invalid values silentlycreateAskableContext({ maxHistory: -1 })stores-1without error. The history cap check then behaves oddly (history.length > -1is always true, so every push trims the array immediately). PassingNaNfalls through to the default of50silently.Fix: Add a runtime guard in the constructor:
2.
hierarchyDepth: 0is undocumentedPassing
hierarchyDepth: 0to any serialization method returns an empty ancestors array (all ancestor context is suppressed). This is intentional and the implementation is correct, but it is not documented in the type definition or API docs, so users may be confused when their ancestors disappear.Fix: Add a JSDoc note to
AskablePromptContextOptions.hierarchyDepth:Acceptance criteria
createAskableContext({ maxHistory: -1 })throws aRangeErrorcreateAskableContext({ maxHistory: NaN })throws aRangeErrorhierarchyDepthJSDoc clarifies that0suppresses all ancestorsmaxHistorycases