@cr1ms0n/pi-subagent 0.9.0 → 0.11.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/src/types.ts CHANGED
@@ -41,6 +41,66 @@ export interface UsageStats {
41
41
 
42
42
  export type BackendName = "pi" | "codex" | "claude";
43
43
 
44
+ /**
45
+ * Sticky current-invocation tool activity for the pre-tool switch boundary. `started` latches on tool_execution_start, a newly observed
46
+ * completed assistant toolCall or a toolResult; `unknown` marks malformed,
47
+ * truncated or absent evidence. Both are sticky: neither can be erased by a
48
+ * later complete event, and only a conclusive `none` authorizes a new child.
49
+ */
50
+ export type ToolActivity = "none" | "started" | "unknown";
51
+
52
+ /**
53
+ * Conservative classification of the latest completed assistant provider error
54
+ * (see `model-failover.ts`). Only the availability categories advance the
55
+ * ranked path; everything else stops and is reported without switching.
56
+ */
57
+ export type ModelFailureCategory =
58
+ | "model_unavailable"
59
+ | "rate_limited"
60
+ | "service_overload"
61
+ | "transport"
62
+ | "auth"
63
+ | "quota"
64
+ | "invalid_request"
65
+ | "context_overflow"
66
+ | "refusal"
67
+ | "unknown";
68
+
69
+ /**
70
+ * One locally finalized ranked execution candidate. Internal contract built by
71
+ * `policy.ts` from the validated ranking and the original model catalog; never
72
+ * a tool-request/config field and never decoded from a persisted snapshot into
73
+ * an executable plan. Thinking follows explicit > agent > profile > candidate >
74
+ * parent per entry; tools/writer classification are shared across all entries.
75
+ */
76
+ export interface ModelAttemptSpec {
77
+ readonly model: string;
78
+ readonly probability: number;
79
+ readonly thinking?: ThinkingLevel;
80
+ }
81
+
82
+ /**
83
+ * Bounded descriptive history for one ranked/legacy attempt. Records are not
84
+ * a second usage ledger (TaskResult.usage stays cumulative) and never become
85
+ * executable: they carry the reason for a switch, the session pointer for
86
+ * discoverable partial work, and a 1 KiB output preview (16 KiB per task).
87
+ */
88
+ export interface ModelAttemptRecord {
89
+ /** 1-based launch count for this task. */
90
+ attempt: number;
91
+ /** 0-based ranking position of the candidate that ran. */
92
+ rank: number;
93
+ model: string;
94
+ probability: number;
95
+ outcome: RunState;
96
+ stopReason?: string;
97
+ failureCategory?: ModelFailureCategory;
98
+ toolActivity?: ToolActivity;
99
+ sessionId?: string;
100
+ /** Bounded output preview; metadata/session pointer survive when text is trimmed. */
101
+ outputPreview?: string;
102
+ }
103
+
44
104
  export interface TaskSpec {
45
105
  /** Agent CLI powering this child. Defaults to "pi". */
46
106
  backend?: BackendName;
@@ -75,8 +135,15 @@ export interface TaskSpec {
75
135
  graceTurns?: number;
76
136
  /** Ordered backup models tried on transient provider failures. */
77
137
  fallbackModels?: string[];
78
- /** Extra attempts on transient failures (queue timeout, stall, provider error). */
138
+ /** Extra launches: ranked pre-tool recovery, or the legacy SDK transient loop. */
79
139
  maxRetries?: number;
140
+ /**
141
+ * Locally finalized probability-ranked candidate plan for extension-managed
142
+ * tasks (internal; built only by `policy.finalizeRoutedTasks`). Its presence
143
+ * selects the ranked attempt loop; the legacy `fallbackModels` loop stays
144
+ * untouched for trusted unranked SDK tasks.
145
+ */
146
+ modelAttemptPlan?: readonly ModelAttemptSpec[];
80
147
  /** Fork the parent conversation into the child (real branched session). */
81
148
  contextFork?: boolean;
82
149
  /** Parent session file used for contextFork. */
@@ -129,6 +196,22 @@ export interface TaskResult {
129
196
  attempts?: number;
130
197
  /** Models tried across attempts, in order. */
131
198
  attemptedModels?: string[];
199
+ /** Sticky current-invocation tool activity across this task's attempts. */
200
+ toolActivity?: ToolActivity;
201
+ /**
202
+ * Bounded errorMessage + primitive diagnostics.error.code from the latest
203
+ * completed assistant provider error. Set only for stopReason "error";
204
+ * generic runner/RPC errors and diagnostic bodies never fill it.
205
+ */
206
+ providerError?: string;
207
+ /**
208
+ * Runner-owned positive proof that no child/task work could have begun
209
+ * (queue/admission timeout or a spawn that never produced a process). Only
210
+ * this conclusive evidence permits a same-model infrastructure retry.
211
+ */
212
+ preWorkInfraFailure?: boolean;
213
+ /** Bounded per-attempt history for ranked runs (descriptive, never executable). */
214
+ modelAttempts?: ModelAttemptRecord[];
132
215
  /** Parsed structured result when output_schema was requested and validated. */
133
216
  structuredOutput?: unknown;
134
217
  /** Validation errors when output_schema was requested but the result failed. */
@@ -182,6 +265,10 @@ export interface RunSnapshot {
182
265
  stalledSince?: number;
183
266
  attempts?: number;
184
267
  attemptedModels?: string[];
268
+ /** Sticky tool-activity boundary state across the task's attempts. */
269
+ toolActivity?: ToolActivity;
270
+ /** Bounded ranked attempt history (descriptive; previews capped). */
271
+ modelAttempts?: ModelAttemptRecord[];
185
272
  structuredOutput?: unknown;
186
273
  structuredError?: string;
187
274
  }>;