feat(coding-agent/session): typed CompactionCancelledError sentinel and CompactionOutcome
Introduce `CompactionCancelledError` and `CompactionOutcome` ("ok" |
"cancelled" | "failed") so callers can discriminate user-driven aborts
from generic failures via `instanceof`, instead of inspecting error
messages or `AbortError`-name strings.
`AgentSession.compact()`'s two abort-rejection sites now throw the
typed sentinel; the model-call wrapper normalizes AbortError-shaped
rejections to the sentinel only when the compaction's abort signal
is actually set, preserving every other exception unchanged so real
compaction bugs are not silently relabeled as cancellations.
`CommandController.executeCompaction` and `handleCompactCommand`
return `Promise<CompactionOutcome>`; the catch classifies via
`instanceof CompactionCancelledError`. Existing callers (`/compact`,
loop runner, auto-compact) ignore the return value — non-breaking.
Op: extend
This commit is contained in:
@@ -0,0 +1,31 @@
|
||||
/**
|
||||
* Compaction error types.
|
||||
*
|
||||
* `CompactionCancelledError` is the canonical signal raised when a compaction
|
||||
* is explicitly aborted — operator Esc, extension hook returning `cancel`,
|
||||
* programmatic `session.abortCompaction()` call, or any other deliberate
|
||||
* abort source. Downstream callers (e.g. `executeCompaction`) discriminate
|
||||
* cancellation from other failures via `instanceof CompactionCancelledError`
|
||||
* rather than introspecting error messages or `name` fields — the typed
|
||||
* sentinel makes classification source-agnostic and refactor-stable.
|
||||
*/
|
||||
|
||||
export class CompactionCancelledError extends Error {
|
||||
readonly name = "CompactionCancelledError" as const;
|
||||
|
||||
constructor(message = "Compaction cancelled") {
|
||||
super(message);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Outcome of a compaction attempt, surfaced by `CommandController.executeCompaction`
|
||||
* so callers (e.g. the plan-mode approval flow) can distinguish a deliberate abort
|
||||
* from an unrelated failure.
|
||||
*
|
||||
* "ok" — compaction completed; transcript was summarized.
|
||||
* "cancelled" — `CompactionCancelledError` was raised. Operator Esc, extension
|
||||
* hook, programmatic abort — all source-agnostic.
|
||||
* "failed" — any other rejection from `session.compact()`.
|
||||
*/
|
||||
export type CompactionOutcome = "ok" | "cancelled" | "failed";
|
||||
@@ -4,4 +4,5 @@
|
||||
|
||||
export * from "./branch-summarization";
|
||||
export * from "./compaction";
|
||||
export * from "./errors";
|
||||
export * from "./utils";
|
||||
|
||||
Reference in New Issue
Block a user