@oneharness/sdk 0.4.0 → 0.4.2

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.
@@ -1,36 +1,53 @@
1
- /**
2
- * The normalized, closed set of failure reasons oneharness can classify from a
3
- * harness's output. It is the single source for the `failure_kind` contract
4
- * value: serialized as the snake_case token a consumer reads in the report
5
- * (`auth`, `rate_limit`, `model_not_found`, `quota`, `tool_deferred`), so the
6
- * wire shape is unchanged — modeling it as an enum keeps a misspelled or
7
- * invalid kind unrepresentable and gives every producer/consumer (classifier,
8
- * `is_failure`, the fallback fall-through rule, the report, history) one
9
- * definition to share instead of scattered string literals.
10
- */
11
- export type FailureKind = "auth" | "rate_limit" | "model_not_found" | "quota" | "tool_deferred";
12
- /**
13
- * The outcome of attempting to run one harness.
14
- */
15
- export type Status = "ok" | "nonzero" | "timeout" | "spawn-error" | "skipped" | "planned";
16
1
  /**
17
2
  * One harness run, normalized and frozen for the history log. Serialized as one
18
3
  * JSONL line per harness run, appended as the run finalizes. Carries only the
19
4
  * normalized cross-harness signals — no raw stdout/stderr.
20
5
  */
21
- export interface HistoryRecord {
22
- duration_ms: number | null;
6
+ export type HistoryRecord = {
7
+ duration_ms: number;
23
8
  /**
24
9
  * Best-effort normalized tool-call events; `null` when the harness exposes
25
10
  * no machine-readable trace.
26
11
  */
27
- events: ActionEvent[] | null;
12
+ events: ((ActionEvent & {
13
+ duration_ms: number;
14
+ finished_at: string;
15
+ kind: "tool_call";
16
+ started_at: string;
17
+ status: "completed";
18
+ tool_call_id: string;
19
+ [k: string]: unknown;
20
+ }) | (ActionEvent & {
21
+ duration_ms: number;
22
+ finished_at: string;
23
+ kind: "tool_call";
24
+ started_at: string;
25
+ status: "failed";
26
+ tool_call_id: string;
27
+ [k: string]: unknown;
28
+ }) | (ActionEvent & {
29
+ kind: "tool_call";
30
+ started_at: string;
31
+ status: "timeout";
32
+ tool_call_id: string;
33
+ [k: string]: unknown;
34
+ }) | (ActionEvent & {
35
+ kind: "tool_call";
36
+ started_at: string;
37
+ status: "interrupted";
38
+ tool_call_id: string;
39
+ [k: string]: unknown;
40
+ }) | (ActionEvent & {
41
+ kind?: "tool_result" | undefined;
42
+ [k: string]: unknown;
43
+ }))[] | null;
28
44
  exit_code: number | null;
29
45
  /**
30
46
  * Best-effort classified failure reason (see [`FailureKind`]); `null` when
31
47
  * unclassified.
32
48
  */
33
49
  failure_kind: FailureKind | null;
50
+ finished_at: string | null;
34
51
  /**
35
52
  * Canonical harness id (e.g. `claude-code`).
36
53
  */
@@ -45,6 +62,7 @@ export interface HistoryRecord {
45
62
  * The effective top-level model for the run, if any.
46
63
  */
47
64
  model: string | null;
65
+ model_ms: number;
48
66
  /**
49
67
  * The human-meaningful session name (see [`session_name`]); repeated on
50
68
  * every record so a reader can resolve a session by name from any line.
@@ -64,7 +82,7 @@ export interface HistoryRecord {
64
82
  * run's single prompt).
65
83
  */
66
84
  prompt: string;
67
- schema_version: string;
85
+ schema_version: "0.3";
68
86
  /**
69
87
  * The oneharness session id this run belongs to (the history file's stem).
70
88
  */
@@ -73,6 +91,7 @@ export interface HistoryRecord {
73
91
  * The harness's own continuation id, when it exposed one; `null` otherwise.
74
92
  */
75
93
  session_id: string | null;
94
+ started_at: string;
76
95
  status: Status;
77
96
  /**
78
97
  * Best-effort final assistant text; `null` when extraction was impossible.
@@ -82,19 +101,126 @@ export interface HistoryRecord {
82
101
  * How `text` was extracted; `null` when absent.
83
102
  */
84
103
  text_source: string | null;
104
+ time_to_first_token_ms?: number | null | undefined;
85
105
  /**
86
106
  * RFC3339 UTC instant the record was written (append time).
87
107
  */
88
108
  timestamp: string;
109
+ tool_ms: number;
89
110
  usage: Usage;
90
111
  [k: string]: unknown;
91
- }
112
+ } | {
113
+ duration_ms: number | null;
114
+ events: {
115
+ index: number;
116
+ input: unknown;
117
+ kind: string;
118
+ name: string | null;
119
+ output: string | null;
120
+ [k: string]: unknown;
121
+ }[] | null;
122
+ exit_code: number | null;
123
+ /**
124
+ * Best-effort classified failure reason (see [`FailureKind`]); `null` when
125
+ * unclassified.
126
+ */
127
+ failure_kind: FailureKind | null;
128
+ finished_at?: string | null | undefined;
129
+ /**
130
+ * Canonical harness id (e.g. `claude-code`).
131
+ */
132
+ harness: string;
133
+ /**
134
+ * Globally unique, time-ordered record id. This is also the cursor accepted
135
+ * by `history watch --after` and the exact id accepted by history lookup.
136
+ */
137
+ history_id: string;
138
+ labels?: HistoryLabels1 | undefined;
139
+ /**
140
+ * The effective top-level model for the run, if any.
141
+ */
142
+ model: string | null;
143
+ model_ms?: number | null | undefined;
144
+ /**
145
+ * The human-meaningful session name (see [`session_name`]); repeated on
146
+ * every record so a reader can resolve a session by name from any line.
147
+ */
148
+ name: string;
149
+ /**
150
+ * The normalized approval mode requested for the run.
151
+ */
152
+ permission_mode: "read-only" | "plan" | "default" | "edit" | "auto" | "bypass";
153
+ /**
154
+ * The project directory the run operated in (the real path, not the
155
+ * on-disk slug), so the list view can show where a session ran.
156
+ */
157
+ project: string;
158
+ /**
159
+ * The prompt this harness run received (its own, on a batch run; else the
160
+ * run's single prompt).
161
+ */
162
+ prompt: string;
163
+ schema_version: "0.1" | "0.2";
164
+ /**
165
+ * The oneharness session id this run belongs to (the history file's stem).
166
+ */
167
+ session: string;
168
+ /**
169
+ * The harness's own continuation id, when it exposed one; `null` otherwise.
170
+ */
171
+ session_id: string | null;
172
+ /**
173
+ * UTC invocation bounds and monotonic time attribution. The provider/tool
174
+ * split is conservative when a transcript has tool calls but lacks native
175
+ * boundaries: the observed invocation interval is attributed to the union
176
+ * of those calls, never double-counted.
177
+ */
178
+ started_at?: string | null | undefined;
179
+ status: Status;
180
+ /**
181
+ * Best-effort final assistant text; `null` when extraction was impossible.
182
+ */
183
+ text: string | null;
184
+ /**
185
+ * How `text` was extracted; `null` when absent.
186
+ */
187
+ text_source: string | null;
188
+ time_to_first_token_ms?: number | null | undefined;
189
+ /**
190
+ * RFC3339 UTC instant the record was written (append time).
191
+ */
192
+ timestamp: string;
193
+ tool_ms?: number | null | undefined;
194
+ usage: Usage1;
195
+ [k: string]: unknown;
196
+ };
197
+ export type ToolCallStatus = "completed" | "failed" | "timeout" | "interrupted";
198
+ /**
199
+ * The normalized, closed set of failure reasons oneharness can classify from a
200
+ * harness's output. It is the single source for the `failure_kind` contract
201
+ * value: serialized as the snake_case token a consumer reads in the report
202
+ * (`auth`, `rate_limit`, `model_not_found`, `quota`, `tool_deferred`), so the
203
+ * wire shape is unchanged — modeling it as an enum keeps a misspelled or
204
+ * invalid kind unrepresentable and gives every producer/consumer (classifier,
205
+ * `is_failure`, the fallback fall-through rule, the report, history) one
206
+ * definition to share instead of scattered string literals.
207
+ */
208
+ export type FailureKind = "auth" | "rate_limit" | "model_not_found" | "quota" | "tool_deferred";
209
+ /**
210
+ * The outcome of attempting to run one harness.
211
+ */
212
+ export type Status = "ok" | "nonzero" | "timeout" | "spawn-error" | "skipped" | "planned";
92
213
  /**
93
214
  * One normalized action a harness took, harness-agnostic so a single consumer
94
215
  * assertion works across harnesses. Every field is always serialized (null when
95
216
  * absent) so the shape is stable, mirroring the `usage` contract.
96
217
  */
97
218
  export interface ActionEvent {
219
+ /**
220
+ * Monotonic elapsed tool time. `None` means no terminal boundary was seen.
221
+ */
222
+ duration_ms: number | null;
223
+ finished_at: string | null;
98
224
  /**
99
225
  * Position of this event within the run, so "≤ N tool calls" and "did X
100
226
  * before Y" are expressible from a stable ordering (also array order).
@@ -121,6 +247,20 @@ export interface ActionEvent {
121
247
  * The result/observation text, when the trace exposes it; `null` otherwise.
122
248
  */
123
249
  output: string | null;
250
+ /**
251
+ * UTC interval bounds for tool execution, populated on history records.
252
+ */
253
+ started_at: string | null;
254
+ /**
255
+ * Terminal tool state, populated on history tool-call events.
256
+ */
257
+ status: ToolCallStatus | null;
258
+ /**
259
+ * Stable call identity within the session. Present on tool calls and their
260
+ * matching results when the provider exposes an identity; history fills a
261
+ * deterministic run-local identity for providers that do not.
262
+ */
263
+ tool_call_id: string | null;
124
264
  [k: string]: unknown;
125
265
  }
126
266
  /**
@@ -160,3 +300,40 @@ export interface Usage {
160
300
  output_tokens: number | null;
161
301
  [k: string]: unknown;
162
302
  }
303
+ /**
304
+ * Caller-supplied metadata used to select related task-graph records.
305
+ * Omitted on the wire when empty for additive compatibility.
306
+ */
307
+ export interface HistoryLabels1 {
308
+ [k: string]: string;
309
+ }
310
+ /**
311
+ * Best-effort token/cost accounting (every field `null` when unreported).
312
+ */
313
+ export interface Usage1 {
314
+ /**
315
+ * Prompt tokens served from the provider's prompt cache (a cheap read of a
316
+ * previously-written prefix), when the harness reports them. `None` when the
317
+ * harness does not surface cache counts — never `0` as a guess.
318
+ */
319
+ cache_read_tokens: number | null;
320
+ /**
321
+ * Prompt tokens written to the provider's prompt cache (a.k.a. cache
322
+ * creation), when the harness reports them. `None` when not surfaced.
323
+ */
324
+ cache_write_tokens: number | null;
325
+ /**
326
+ * Total cost in USD, when the harness reports it (often absent on
327
+ * subscription auth, where there is no per-call dollar figure).
328
+ */
329
+ cost_usd: number | null;
330
+ /**
331
+ * Prompt/input tokens billed, when the harness reports them.
332
+ */
333
+ input_tokens: number | null;
334
+ /**
335
+ * Completion/output tokens billed, when the harness reports them.
336
+ */
337
+ output_tokens: number | null;
338
+ [k: string]: unknown;
339
+ }
@@ -15,6 +15,7 @@ export type RunStreamEnvelope = {
15
15
  type: "result";
16
16
  [k: string]: unknown;
17
17
  };
18
+ export type ToolCallStatus = "completed" | "failed" | "timeout" | "interrupted";
18
19
  /**
19
20
  * The normalized, closed set of failure reasons oneharness can classify from a
20
21
  * harness's output. It is the single source for the `failure_kind` contract
@@ -44,6 +45,11 @@ export type Status = "ok" | "nonzero" | "timeout" | "spawn-error" | "skipped" |
44
45
  * absent) so the shape is stable, mirroring the `usage` contract.
45
46
  */
46
47
  export interface ActionEvent {
48
+ /**
49
+ * Monotonic elapsed tool time. `None` means no terminal boundary was seen.
50
+ */
51
+ duration_ms: number | null;
52
+ finished_at: string | null;
47
53
  /**
48
54
  * Position of this event within the run, so "≤ N tool calls" and "did X
49
55
  * before Y" are expressible from a stable ordering (also array order).
@@ -70,6 +76,20 @@ export interface ActionEvent {
70
76
  * The result/observation text, when the trace exposes it; `null` otherwise.
71
77
  */
72
78
  output: string | null;
79
+ /**
80
+ * UTC interval bounds for tool execution, populated on history records.
81
+ */
82
+ started_at: string | null;
83
+ /**
84
+ * Terminal tool state, populated on history tool-call events.
85
+ */
86
+ status: ToolCallStatus | null;
87
+ /**
88
+ * Stable call identity within the session. Present on tool calls and their
89
+ * matching results when the provider exposes an identity; history fills a
90
+ * deterministic run-local identity for providers that do not.
91
+ */
92
+ tool_call_id: string | null;
73
93
  [k: string]: unknown;
74
94
  }
75
95
  /**