File size: 2,392 Bytes
e249c6d | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 | /**
* Agent harness error helpers.
*
* Registry and runtime callers use this stable error type to distinguish missing
* harness selection from ordinary harness execution failures.
*/
/** Error thrown when a requested harness id is not registered. */
export class MissingAgentHarnessError extends Error {
readonly harnessId: string;
constructor(harnessId: string) {
super(`Requested agent harness "${harnessId}" is not registered.`);
this.name = "MissingAgentHarnessError";
this.harnessId = harnessId;
}
}
/** Returns whether an error is a missing harness error. */
export function isMissingAgentHarnessError(err: unknown): err is MissingAgentHarnessError {
return err instanceof MissingAgentHarnessError;
}
/** A harness lost ownership of the session generation before the attempt could start. */
export class AgentHarnessSessionSupersededError extends Error {
constructor(message: string, options?: ErrorOptions) {
super(message, options);
this.name = "AgentHarnessSessionSupersededError";
}
}
/** A model-independent harness preflight failed before an attempt could start. */
export class AgentHarnessPreflightError extends Error {
/** Opts fallback into skipping only candidates owned by the selected harness. */
readonly scope?: "harness";
constructor(message: string, options?: ErrorOptions & { scope?: "harness" }) {
super(message, options);
this.name = "AgentHarnessPreflightError";
this.scope = options?.scope;
}
}
// The host records the selected harness where the attempt runs. Plugins can opt
// into harness-local fallback, but cannot suppress candidates by naming an owner.
const agentHarnessPreflightOwners = new WeakMap<AgentHarnessPreflightError, string>();
export function recordAgentHarnessPreflightOwner(error: unknown, harnessId: string): void {
if (isAgentHarnessPreflightError(error) && error.scope === "harness") {
agentHarnessPreflightOwners.set(error, harnessId);
}
}
export function resolveAgentHarnessPreflightOwner(error: unknown): string | undefined {
return isAgentHarnessPreflightError(error) ? agentHarnessPreflightOwners.get(error) : undefined;
}
/** Returns whether fallback would only repeat the same harness preflight failure. */
export function isAgentHarnessPreflightError(err: unknown): err is AgentHarnessPreflightError {
return err instanceof AgentHarnessPreflightError;
}
|