isValidStatus()
SignatureSessionView
SessionView — typed wrapper over Session[] with collection helpers. Provides discoverable query methods for common session lookups. Does NOT change the DataAccessor interface — consumers create views from Session[]. Signaturefrom()
Create a SessionView from a Session array.findActive()
Find the currently active session (if any).findById()
Find a session by ID.filterByStatus()
Filter sessions by one or more statuses.findByScope()
Find sessions matching a scope type and optional rootTaskId.sortByDate()
Sort sessions by a date field. Returns a new array (does not mutate).mostRecent()
Get the most recently started session.toArray()
Convert back to a plain Session array (shallow copy).[Symbol.iterator]()
Support for-of iteration.normalizeError(error, fallbackMessage)
Normalize any thrown value into a standardized error object. Handles: - Error instances (preserves stack trace info) - Strings (wraps in Error) - Objects with message property - null/undefined (provides fallback) Signature| Name | Type | Description |
|---|---|---|
error | unknown | The thrown value to normalize |
fallbackMessage | : string | Message to use if error provides none |
getErrorMessage(error, fallback)
Extract a human-readable message from any error value. Safe to use on unknown thrown values without type guards. Signature| Name | Type | Description |
|---|---|---|
error | unknown | The error value |
fallback | : string | Fallback message if extraction fails |
formatError(error, context, includeStack)
Format error details for logging or display. Includes stack trace for Error instances when includeStack is true. Signature| Name | Type | Description |
|---|---|---|
error | unknown | The error to format |
context | : string | Optional context to prepend |
includeStack | : boolean | Whether to include stack traces (default: false) |
isErrorType(error, codeOrName)
Check if an error represents a specific error type by code or name. Useful for conditional error handling based on error types. Signature| Name | Type | Description |
|---|---|---|
error | unknown | The error to check |
codeOrName | string | The error code or name to match |
createErrorResult(error)
Create a standardized error result object. Common pattern for operations that return success: boolean, error?: string Signature| Name | Type | Description |
|---|---|---|
error | unknown | The error value |
createSuccessResult()
Create a standardized success result object. SignatureisErrorResult(result)
Type guard for error results. Signature| Name | Type | Description |
|---|---|---|
result | { success: boolean; error?: string; } | The result to check |
isErrorCode()
Check if an exit code represents an error (1-99). SignatureisSuccessCode()
Check if an exit code represents success (0 or 100+). SignatureisNoChangeCode()
Check if an exit code indicates no change (idempotent operation). SignatureisRecoverableCode()
Check if an exit code is recoverable (retry may succeed). SignaturegetExitCodeName()
Human-readable name for an exit code. SignatureisLafsSuccess(envelope)
Type guard for success responses. Signature| Name | Type | Description |
|---|---|---|
envelope | LafsEnvelope<T> | The envelope to check. |
true if the envelope represents a successful operation.
Example
isLafsError(envelope)
Type guard for error responses. Signature| Name | Type | Description |
|---|---|---|
envelope | LafsEnvelope<T> | The envelope to check. |
true if the envelope represents a failed operation.
Example
isGatewayEnvelope(envelope)
Type guard for gateway responses (has _meta). Signature| Name | Type | Description |
|---|---|---|
envelope | CleoResponse<T> | The response to check. |
true if the response includes gateway metadata.
Example