@oneharness/sdk 0.3.22
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/README.md +46 -0
- package/dist/generated/contracts.d.ts +421 -0
- package/dist/generated/contracts.js +2 -0
- package/dist/generated/detection.d.ts +13 -0
- package/dist/generated/detection.js +2 -0
- package/dist/generated/history-list-options.d.ts +8 -0
- package/dist/generated/history-list-options.js +2 -0
- package/dist/generated/history-list.d.ts +37 -0
- package/dist/generated/history-list.js +2 -0
- package/dist/generated/history-lookup.d.ts +66 -0
- package/dist/generated/history-lookup.js +2 -0
- package/dist/generated/history-records.d.ts +150 -0
- package/dist/generated/history-records.js +2 -0
- package/dist/generated/history.d.ts +149 -0
- package/dist/generated/history.js +2 -0
- package/dist/generated/options.d.ts +40 -0
- package/dist/generated/options.js +2 -0
- package/dist/generated/registry.d.ts +125 -0
- package/dist/generated/registry.js +2 -0
- package/dist/generated/schemas.json +1914 -0
- package/dist/generated/zod.d.ts +42 -0
- package/dist/generated/zod.js +268 -0
- package/dist/index.d.ts +33 -0
- package/dist/index.js +146 -0
- package/package.json +25 -0
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
import type { ActionEvent, BatchReport, FailureKind, FallThrough, FallbackReport, OutputFormat, RunReport, RunResult, SessionReport, Status, Usage } from "./contracts.js";
|
|
3
|
+
import type { DetectInfo, DetectReport } from "./detection.js";
|
|
4
|
+
import type { HistoryRecord } from "./history.js";
|
|
5
|
+
import type { HistoryList, HistorySessionSummary } from "./history-list.js";
|
|
6
|
+
import type { HistoryListOptions } from "./history-list-options.js";
|
|
7
|
+
import type { HistoryLookup, HistoryLookupByLast, HistoryLookupBySession } from "./history-lookup.js";
|
|
8
|
+
import type { HistoryRecords } from "./history-records.js";
|
|
9
|
+
import type { PermissionMode, RunOptions } from "./options.js";
|
|
10
|
+
import type { HarnessInfo, ListReport, ModeInfo } from "./registry.js";
|
|
11
|
+
export type BatchStrategy = BatchReport["strategy"];
|
|
12
|
+
export type ModeHeadless = ModeInfo["headless"];
|
|
13
|
+
export type SessionPhase = SessionReport["phase"];
|
|
14
|
+
export declare const ActionEventSchema: z.ZodType<ActionEvent>;
|
|
15
|
+
export declare const BatchReportSchema: z.ZodType<BatchReport>;
|
|
16
|
+
export declare const BatchStrategySchema: z.ZodType<BatchStrategy>;
|
|
17
|
+
export declare const DetectInfoSchema: z.ZodType<DetectInfo>;
|
|
18
|
+
export declare const DetectReportSchema: z.ZodType<DetectReport>;
|
|
19
|
+
export declare const FailureKindSchema: z.ZodType<FailureKind>;
|
|
20
|
+
export declare const FallThroughSchema: z.ZodType<FallThrough>;
|
|
21
|
+
export declare const FallbackReportSchema: z.ZodType<FallbackReport>;
|
|
22
|
+
export declare const HarnessInfoSchema: z.ZodType<HarnessInfo>;
|
|
23
|
+
export declare const HistoryListSchema: z.ZodType<HistoryList>;
|
|
24
|
+
export declare const HistoryListOptionsSchema: z.ZodType<HistoryListOptions>;
|
|
25
|
+
export declare const HistoryLookupSchema: z.ZodType<HistoryLookup>;
|
|
26
|
+
export declare const HistoryLookupByLastSchema: z.ZodType<HistoryLookupByLast>;
|
|
27
|
+
export declare const HistoryLookupBySessionSchema: z.ZodType<HistoryLookupBySession>;
|
|
28
|
+
export declare const HistoryRecordSchema: z.ZodType<HistoryRecord>;
|
|
29
|
+
export declare const HistoryRecordsSchema: z.ZodType<HistoryRecords>;
|
|
30
|
+
export declare const HistorySessionSummarySchema: z.ZodType<HistorySessionSummary>;
|
|
31
|
+
export declare const ListReportSchema: z.ZodType<ListReport>;
|
|
32
|
+
export declare const ModeHeadlessSchema: z.ZodType<ModeHeadless>;
|
|
33
|
+
export declare const ModeInfoSchema: z.ZodType<ModeInfo>;
|
|
34
|
+
export declare const OutputFormatSchema: z.ZodType<OutputFormat>;
|
|
35
|
+
export declare const PermissionModeSchema: z.ZodType<PermissionMode>;
|
|
36
|
+
export declare const RunOptionsSchema: z.ZodType<RunOptions>;
|
|
37
|
+
export declare const RunReportSchema: z.ZodType<RunReport>;
|
|
38
|
+
export declare const RunResultSchema: z.ZodType<RunResult>;
|
|
39
|
+
export declare const SessionPhaseSchema: z.ZodType<SessionPhase>;
|
|
40
|
+
export declare const SessionReportSchema: z.ZodType<SessionReport>;
|
|
41
|
+
export declare const StatusSchema: z.ZodType<Status>;
|
|
42
|
+
export declare const UsageSchema: z.ZodType<Usage>;
|
|
@@ -0,0 +1,268 @@
|
|
|
1
|
+
/* Generated from oneharness Rust JSON Schemas. Do not edit. */
|
|
2
|
+
import { z } from "zod";
|
|
3
|
+
export const ActionEventSchema = z.looseObject({
|
|
4
|
+
index: z
|
|
5
|
+
.int()
|
|
6
|
+
.gte(0)
|
|
7
|
+
.refine((value) => value !== undefined, { message: "Required" }),
|
|
8
|
+
input: z.unknown().refine((value) => value !== undefined, { message: "Required" }),
|
|
9
|
+
kind: z.string().refine((value) => value !== undefined, { message: "Required" }),
|
|
10
|
+
name: z.union([z.string(), z.null()]).refine((value) => value !== undefined, { message: "Required" }),
|
|
11
|
+
output: z.union([z.string(), z.null()]).refine((value) => value !== undefined, { message: "Required" }),
|
|
12
|
+
});
|
|
13
|
+
export const BatchReportSchema = z.looseObject({
|
|
14
|
+
forked: z.boolean().refine((value) => value !== undefined, { message: "Required" }),
|
|
15
|
+
prompt_count: z
|
|
16
|
+
.int()
|
|
17
|
+
.gte(0)
|
|
18
|
+
.refine((value) => value !== undefined, { message: "Required" }),
|
|
19
|
+
strategy: z.lazy(() => BatchStrategySchema).refine((value) => value !== undefined, { message: "Required" }),
|
|
20
|
+
});
|
|
21
|
+
export const BatchStrategySchema = z.union([z.literal("speed"), z.literal("min-tokens")]);
|
|
22
|
+
export const DetectInfoSchema = z.looseObject({
|
|
23
|
+
available: z.boolean().refine((value) => value !== undefined, { message: "Required" }),
|
|
24
|
+
bin: z.string().refine((value) => value !== undefined, { message: "Required" }),
|
|
25
|
+
id: z.string().refine((value) => value !== undefined, { message: "Required" }),
|
|
26
|
+
path: z.union([z.string(), z.null()]).refine((value) => value !== undefined, { message: "Required" }),
|
|
27
|
+
version: z.union([z.string(), z.null()]).refine((value) => value !== undefined, { message: "Required" }),
|
|
28
|
+
});
|
|
29
|
+
export const DetectReportSchema = z.looseObject({
|
|
30
|
+
detected: z.array(z.lazy(() => DetectInfoSchema)).refine((value) => value !== undefined, { message: "Required" }),
|
|
31
|
+
schema_version: z.string().refine((value) => value !== undefined, { message: "Required" }),
|
|
32
|
+
});
|
|
33
|
+
export const FailureKindSchema = z.union([
|
|
34
|
+
z.literal("auth"),
|
|
35
|
+
z.literal("rate_limit"),
|
|
36
|
+
z.literal("model_not_found"),
|
|
37
|
+
z.literal("quota"),
|
|
38
|
+
z.literal("tool_deferred"),
|
|
39
|
+
]);
|
|
40
|
+
export const FallThroughSchema = z.looseObject({
|
|
41
|
+
harness: z.string().refine((value) => value !== undefined, { message: "Required" }),
|
|
42
|
+
reason: z.string().refine((value) => value !== undefined, { message: "Required" }),
|
|
43
|
+
});
|
|
44
|
+
export const FallbackReportSchema = z.looseObject({
|
|
45
|
+
fell_through: z
|
|
46
|
+
.array(z.lazy(() => FallThroughSchema))
|
|
47
|
+
.refine((value) => value !== undefined, { message: "Required" }),
|
|
48
|
+
ran: z.union([z.string(), z.null()]).refine((value) => value !== undefined, { message: "Required" }),
|
|
49
|
+
});
|
|
50
|
+
export const HarnessInfoSchema = z.looseObject({
|
|
51
|
+
default_bin: z.string().refine((value) => value !== undefined, { message: "Required" }),
|
|
52
|
+
display: z.string().refine((value) => value !== undefined, { message: "Required" }),
|
|
53
|
+
example_command: z.array(z.string()).refine((value) => value !== undefined, { message: "Required" }),
|
|
54
|
+
fork_reuses_cache: z.boolean().refine((value) => value !== undefined, { message: "Required" }),
|
|
55
|
+
id: z.string().refine((value) => value !== undefined, { message: "Required" }),
|
|
56
|
+
install_hint: z.string().refine((value) => value !== undefined, { message: "Required" }),
|
|
57
|
+
mock_rewrite: z.union([z.string(), z.null()]).refine((value) => value !== undefined, { message: "Required" }),
|
|
58
|
+
modes: z.array(z.lazy(() => ModeInfoSchema)).refine((value) => value !== undefined, { message: "Required" }),
|
|
59
|
+
output_format: z.lazy(() => OutputFormatSchema).refine((value) => value !== undefined, { message: "Required" }),
|
|
60
|
+
session_capable: z.boolean().refine((value) => value !== undefined, { message: "Required" }),
|
|
61
|
+
supports_allowed_tools: z.boolean().refine((value) => value !== undefined, { message: "Required" }),
|
|
62
|
+
supports_denied_tools: z.boolean().refine((value) => value !== undefined, { message: "Required" }),
|
|
63
|
+
supports_fork: z.boolean().refine((value) => value !== undefined, { message: "Required" }),
|
|
64
|
+
supports_hooks: z.boolean().refine((value) => value !== undefined, { message: "Required" }),
|
|
65
|
+
supports_mock_deny: z.boolean().refine((value) => value !== undefined, { message: "Required" }),
|
|
66
|
+
supports_native_schema: z.boolean().refine((value) => value !== undefined, { message: "Required" }),
|
|
67
|
+
supports_prompt_stdin: z.boolean().refine((value) => value !== undefined, { message: "Required" }),
|
|
68
|
+
supports_reasoning: z.boolean().refine((value) => value !== undefined, { message: "Required" }),
|
|
69
|
+
supports_resume: z.boolean().refine((value) => value !== undefined, { message: "Required" }),
|
|
70
|
+
supports_system_file: z.boolean().refine((value) => value !== undefined, { message: "Required" }),
|
|
71
|
+
sync_file: z.union([z.string(), z.null()]).refine((value) => value !== undefined, { message: "Required" }),
|
|
72
|
+
});
|
|
73
|
+
export const HistoryListSchema = z.array(z.lazy(() => HistorySessionSummarySchema));
|
|
74
|
+
export const HistoryListOptionsSchema = z.strictObject({
|
|
75
|
+
allProjects: z.boolean().optional(),
|
|
76
|
+
historyDir: z.string().optional(),
|
|
77
|
+
project: z.string().optional(),
|
|
78
|
+
});
|
|
79
|
+
export const HistoryLookupSchema = z.union([
|
|
80
|
+
z.lazy(() => HistoryLookupByLastSchema),
|
|
81
|
+
z.lazy(() => HistoryLookupBySessionSchema),
|
|
82
|
+
]);
|
|
83
|
+
export const HistoryLookupByLastSchema = z.strictObject({
|
|
84
|
+
allProjects: z.boolean().optional(),
|
|
85
|
+
historyDir: z.string().optional(),
|
|
86
|
+
last: z.literal(true).refine((value) => value !== undefined, { message: "Required" }),
|
|
87
|
+
project: z.string().optional(),
|
|
88
|
+
session: z.string().optional(),
|
|
89
|
+
});
|
|
90
|
+
export const HistoryLookupBySessionSchema = z.strictObject({
|
|
91
|
+
allProjects: z.boolean().optional(),
|
|
92
|
+
historyDir: z.string().optional(),
|
|
93
|
+
last: z.boolean().optional(),
|
|
94
|
+
project: z.string().optional(),
|
|
95
|
+
session: z
|
|
96
|
+
.string()
|
|
97
|
+
.min(1)
|
|
98
|
+
.refine((value) => value !== undefined, { message: "Required" }),
|
|
99
|
+
});
|
|
100
|
+
export const HistoryRecordSchema = z.looseObject({
|
|
101
|
+
duration_ms: z.union([z.int().gte(0), z.null()]).refine((value) => value !== undefined, { message: "Required" }),
|
|
102
|
+
events: z
|
|
103
|
+
.union([z.array(z.lazy(() => ActionEventSchema)), z.null()])
|
|
104
|
+
.refine((value) => value !== undefined, { message: "Required" }),
|
|
105
|
+
exit_code: z.union([z.int(), z.null()]).refine((value) => value !== undefined, { message: "Required" }),
|
|
106
|
+
failure_kind: z
|
|
107
|
+
.union([z.lazy(() => FailureKindSchema), z.null()])
|
|
108
|
+
.refine((value) => value !== undefined, { message: "Required" }),
|
|
109
|
+
harness: z.string().refine((value) => value !== undefined, { message: "Required" }),
|
|
110
|
+
model: z.union([z.string(), z.null()]).refine((value) => value !== undefined, { message: "Required" }),
|
|
111
|
+
name: z.string().refine((value) => value !== undefined, { message: "Required" }),
|
|
112
|
+
permission_mode: z.lazy(() => PermissionModeSchema).refine((value) => value !== undefined, { message: "Required" }),
|
|
113
|
+
project: z.string().refine((value) => value !== undefined, { message: "Required" }),
|
|
114
|
+
prompt: z.string().refine((value) => value !== undefined, { message: "Required" }),
|
|
115
|
+
schema_version: z.string().refine((value) => value !== undefined, { message: "Required" }),
|
|
116
|
+
session: z.string().refine((value) => value !== undefined, { message: "Required" }),
|
|
117
|
+
session_id: z.union([z.string(), z.null()]).refine((value) => value !== undefined, { message: "Required" }),
|
|
118
|
+
status: z.lazy(() => StatusSchema).refine((value) => value !== undefined, { message: "Required" }),
|
|
119
|
+
text: z.union([z.string(), z.null()]).refine((value) => value !== undefined, { message: "Required" }),
|
|
120
|
+
text_source: z.union([z.string(), z.null()]).refine((value) => value !== undefined, { message: "Required" }),
|
|
121
|
+
timestamp: z.string().refine((value) => value !== undefined, { message: "Required" }),
|
|
122
|
+
usage: z.lazy(() => UsageSchema).refine((value) => value !== undefined, { message: "Required" }),
|
|
123
|
+
});
|
|
124
|
+
export const HistoryRecordsSchema = z.array(z.lazy(() => HistoryRecordSchema));
|
|
125
|
+
export const HistorySessionSummarySchema = z.looseObject({
|
|
126
|
+
harnesses: z.array(z.string()).refine((value) => value !== undefined, { message: "Required" }),
|
|
127
|
+
id: z.string().refine((value) => value !== undefined, { message: "Required" }),
|
|
128
|
+
name: z.string().refine((value) => value !== undefined, { message: "Required" }),
|
|
129
|
+
path: z.string().refine((value) => value !== undefined, { message: "Required" }),
|
|
130
|
+
project: z.string().refine((value) => value !== undefined, { message: "Required" }),
|
|
131
|
+
record_count: z
|
|
132
|
+
.int()
|
|
133
|
+
.gte(0)
|
|
134
|
+
.refine((value) => value !== undefined, { message: "Required" }),
|
|
135
|
+
started: z.string().refine((value) => value !== undefined, { message: "Required" }),
|
|
136
|
+
});
|
|
137
|
+
export const ListReportSchema = z.looseObject({
|
|
138
|
+
harnesses: z.array(z.lazy(() => HarnessInfoSchema)).refine((value) => value !== undefined, { message: "Required" }),
|
|
139
|
+
schema_version: z.string().refine((value) => value !== undefined, { message: "Required" }),
|
|
140
|
+
});
|
|
141
|
+
export const ModeHeadlessSchema = z.union([z.literal("clean"), z.literal("hangs")]);
|
|
142
|
+
export const ModeInfoSchema = z.looseObject({
|
|
143
|
+
headless: z.lazy(() => ModeHeadlessSchema).refine((value) => value !== undefined, { message: "Required" }),
|
|
144
|
+
mode: z.lazy(() => PermissionModeSchema).refine((value) => value !== undefined, { message: "Required" }),
|
|
145
|
+
});
|
|
146
|
+
export const OutputFormatSchema = z.union([
|
|
147
|
+
z.literal("text"),
|
|
148
|
+
z.literal("json"),
|
|
149
|
+
z.literal("stream-json"),
|
|
150
|
+
]);
|
|
151
|
+
export const PermissionModeSchema = z.union([
|
|
152
|
+
z.literal("read-only"),
|
|
153
|
+
z.literal("plan"),
|
|
154
|
+
z.literal("default"),
|
|
155
|
+
z.literal("edit"),
|
|
156
|
+
z.literal("auto"),
|
|
157
|
+
z.literal("bypass"),
|
|
158
|
+
]);
|
|
159
|
+
export const RunOptionsSchema = z.strictObject({
|
|
160
|
+
bins: z.record(z.string(), z.string()).optional(),
|
|
161
|
+
cwd: z.string().optional(),
|
|
162
|
+
env: z.record(z.string(), z.string()).optional(),
|
|
163
|
+
events: z.boolean().optional(),
|
|
164
|
+
fork: z.boolean().optional(),
|
|
165
|
+
harnesses: z.array(z.string()).optional(),
|
|
166
|
+
history: z.boolean().optional(),
|
|
167
|
+
historyDir: z.string().optional(),
|
|
168
|
+
historyName: z.string().optional(),
|
|
169
|
+
mode: z.lazy(() => PermissionModeSchema).optional(),
|
|
170
|
+
models: z.array(z.string()).optional(),
|
|
171
|
+
prompt: z
|
|
172
|
+
.string()
|
|
173
|
+
.min(1)
|
|
174
|
+
.refine((value) => value !== undefined, { message: "Required" }),
|
|
175
|
+
reasoning: z.string().optional(),
|
|
176
|
+
resume: z.string().optional(),
|
|
177
|
+
session: z.string().optional(),
|
|
178
|
+
system: z.string().optional(),
|
|
179
|
+
timeoutSeconds: z.int().gte(0).optional(),
|
|
180
|
+
});
|
|
181
|
+
export const RunReportSchema = z.looseObject({
|
|
182
|
+
batch: z
|
|
183
|
+
.union([z.lazy(() => BatchReportSchema), z.null()])
|
|
184
|
+
.refine((value) => value !== undefined, { message: "Required" }),
|
|
185
|
+
bypass_permissions: z.boolean().refine((value) => value !== undefined, { message: "Required" }),
|
|
186
|
+
config_files: z.array(z.string()).refine((value) => value !== undefined, { message: "Required" }),
|
|
187
|
+
dry_run: z.boolean().refine((value) => value !== undefined, { message: "Required" }),
|
|
188
|
+
fallback: z
|
|
189
|
+
.union([z.lazy(() => FallbackReportSchema), z.null()])
|
|
190
|
+
.refine((value) => value !== undefined, { message: "Required" }),
|
|
191
|
+
fork: z.boolean().refine((value) => value !== undefined, { message: "Required" }),
|
|
192
|
+
history_file: z.union([z.string(), z.null()]).refine((value) => value !== undefined, { message: "Required" }),
|
|
193
|
+
mock_rules: z.unknown().refine((value) => value !== undefined, { message: "Required" }),
|
|
194
|
+
model: z.union([z.string(), z.null()]).refine((value) => value !== undefined, { message: "Required" }),
|
|
195
|
+
models: z.union([z.array(z.string()), z.null()]).refine((value) => value !== undefined, { message: "Required" }),
|
|
196
|
+
oneharness_version: z.string().refine((value) => value !== undefined, { message: "Required" }),
|
|
197
|
+
permission_mode: z.lazy(() => PermissionModeSchema).refine((value) => value !== undefined, { message: "Required" }),
|
|
198
|
+
prompt: z.string().refine((value) => value !== undefined, { message: "Required" }),
|
|
199
|
+
results: z.array(z.lazy(() => RunResultSchema)).refine((value) => value !== undefined, { message: "Required" }),
|
|
200
|
+
resume: z.union([z.string(), z.null()]).refine((value) => value !== undefined, { message: "Required" }),
|
|
201
|
+
schema: z.unknown().refine((value) => value !== undefined, { message: "Required" }),
|
|
202
|
+
schema_max_retries: z
|
|
203
|
+
.union([z.int().gte(0), z.null()])
|
|
204
|
+
.refine((value) => value !== undefined, { message: "Required" }),
|
|
205
|
+
schema_version: z.string().refine((value) => value !== undefined, { message: "Required" }),
|
|
206
|
+
session: z
|
|
207
|
+
.union([z.lazy(() => SessionReportSchema), z.null()])
|
|
208
|
+
.refine((value) => value !== undefined, { message: "Required" }),
|
|
209
|
+
spy_file: z.union([z.string(), z.null()]).refine((value) => value !== undefined, { message: "Required" }),
|
|
210
|
+
});
|
|
211
|
+
export const RunResultSchema = z.looseObject({
|
|
212
|
+
available: z.boolean().refine((value) => value !== undefined, { message: "Required" }),
|
|
213
|
+
bin: z.string().refine((value) => value !== undefined, { message: "Required" }),
|
|
214
|
+
command: z.array(z.string()).refine((value) => value !== undefined, { message: "Required" }),
|
|
215
|
+
duration_ms: z.union([z.int().gte(0), z.null()]).refine((value) => value !== undefined, { message: "Required" }),
|
|
216
|
+
error: z.union([z.string(), z.null()]).refine((value) => value !== undefined, { message: "Required" }),
|
|
217
|
+
events: z
|
|
218
|
+
.union([z.array(z.lazy(() => ActionEventSchema)), z.null()])
|
|
219
|
+
.refine((value) => value !== undefined, { message: "Required" }),
|
|
220
|
+
events_source: z.union([z.string(), z.null()]).refine((value) => value !== undefined, { message: "Required" }),
|
|
221
|
+
exit_code: z.union([z.int(), z.null()]).refine((value) => value !== undefined, { message: "Required" }),
|
|
222
|
+
failure_kind: z
|
|
223
|
+
.union([z.lazy(() => FailureKindSchema), z.null()])
|
|
224
|
+
.refine((value) => value !== undefined, { message: "Required" }),
|
|
225
|
+
failure_kind_source: z.union([z.string(), z.null()]).refine((value) => value !== undefined, { message: "Required" }),
|
|
226
|
+
harness: z.string().refine((value) => value !== undefined, { message: "Required" }),
|
|
227
|
+
model: z.union([z.string(), z.null()]).refine((value) => value !== undefined, { message: "Required" }),
|
|
228
|
+
output_format: z.lazy(() => OutputFormatSchema).refine((value) => value !== undefined, { message: "Required" }),
|
|
229
|
+
prompt: z.union([z.string(), z.null()]).refine((value) => value !== undefined, { message: "Required" }),
|
|
230
|
+
schema_attempts: z.union([z.int().gte(0), z.null()]).refine((value) => value !== undefined, { message: "Required" }),
|
|
231
|
+
schema_error: z.union([z.string(), z.null()]).refine((value) => value !== undefined, { message: "Required" }),
|
|
232
|
+
schema_valid: z.union([z.boolean(), z.null()]).refine((value) => value !== undefined, { message: "Required" }),
|
|
233
|
+
session_id: z.union([z.string(), z.null()]).refine((value) => value !== undefined, { message: "Required" }),
|
|
234
|
+
status: z.lazy(() => StatusSchema).refine((value) => value !== undefined, { message: "Required" }),
|
|
235
|
+
stderr: z.string().refine((value) => value !== undefined, { message: "Required" }),
|
|
236
|
+
stdout: z.string().refine((value) => value !== undefined, { message: "Required" }),
|
|
237
|
+
structured: z.unknown().refine((value) => value !== undefined, { message: "Required" }),
|
|
238
|
+
text: z.union([z.string(), z.null()]).refine((value) => value !== undefined, { message: "Required" }),
|
|
239
|
+
text_source: z.union([z.string(), z.null()]).refine((value) => value !== undefined, { message: "Required" }),
|
|
240
|
+
usage: z.lazy(() => UsageSchema).refine((value) => value !== undefined, { message: "Required" }),
|
|
241
|
+
usage_source: z.union([z.string(), z.null()]).refine((value) => value !== undefined, { message: "Required" }),
|
|
242
|
+
});
|
|
243
|
+
export const SessionPhaseSchema = z.union([z.literal("create"), z.literal("continue")]);
|
|
244
|
+
export const SessionReportSchema = z.looseObject({
|
|
245
|
+
name: z.string().refine((value) => value !== undefined, { message: "Required" }),
|
|
246
|
+
phase: z.lazy(() => SessionPhaseSchema).refine((value) => value !== undefined, { message: "Required" }),
|
|
247
|
+
store_file: z.union([z.string(), z.null()]).refine((value) => value !== undefined, { message: "Required" }),
|
|
248
|
+
token: z.union([z.string(), z.null()]).refine((value) => value !== undefined, { message: "Required" }),
|
|
249
|
+
});
|
|
250
|
+
export const StatusSchema = z.union([
|
|
251
|
+
z.literal("ok"),
|
|
252
|
+
z.literal("nonzero"),
|
|
253
|
+
z.literal("timeout"),
|
|
254
|
+
z.literal("spawn-error"),
|
|
255
|
+
z.literal("skipped"),
|
|
256
|
+
z.literal("planned"),
|
|
257
|
+
]);
|
|
258
|
+
export const UsageSchema = z.looseObject({
|
|
259
|
+
cache_read_tokens: z
|
|
260
|
+
.union([z.int().gte(0), z.null()])
|
|
261
|
+
.refine((value) => value !== undefined, { message: "Required" }),
|
|
262
|
+
cache_write_tokens: z
|
|
263
|
+
.union([z.int().gte(0), z.null()])
|
|
264
|
+
.refine((value) => value !== undefined, { message: "Required" }),
|
|
265
|
+
cost_usd: z.union([z.number(), z.null()]).refine((value) => value !== undefined, { message: "Required" }),
|
|
266
|
+
input_tokens: z.union([z.int().gte(0), z.null()]).refine((value) => value !== undefined, { message: "Required" }),
|
|
267
|
+
output_tokens: z.union([z.int().gte(0), z.null()]).refine((value) => value !== undefined, { message: "Required" }),
|
|
268
|
+
});
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import type { RunReport } from "./generated/contracts.js";
|
|
2
|
+
import type { DetectInfo } from "./generated/detection.js";
|
|
3
|
+
import type { HistoryRecord } from "./generated/history.js";
|
|
4
|
+
import type { HistorySessionSummary } from "./generated/history-list.js";
|
|
5
|
+
import type { HistoryListOptions } from "./generated/history-list-options.js";
|
|
6
|
+
import type { HistoryLookup } from "./generated/history-lookup.js";
|
|
7
|
+
import type { RunOptions } from "./generated/options.js";
|
|
8
|
+
import type { HarnessInfo } from "./generated/registry.js";
|
|
9
|
+
export type { ActionEvent, BatchReport, FailureKind, FallbackReport, FallThrough, OutputFormat, RunReport, RunResult, SessionReport, Status, Usage, } from "./generated/contracts.js";
|
|
10
|
+
export type { DetectInfo, DetectReport } from "./generated/detection.js";
|
|
11
|
+
export type { HistoryRecord } from "./generated/history.js";
|
|
12
|
+
export type { HistoryList, HistorySessionSummary, } from "./generated/history-list.js";
|
|
13
|
+
export type { HistoryListOptions } from "./generated/history-list-options.js";
|
|
14
|
+
export type { HistoryLookup, HistoryLookupByLast, HistoryLookupBySession, } from "./generated/history-lookup.js";
|
|
15
|
+
export type { HistoryRecords } from "./generated/history-records.js";
|
|
16
|
+
export type { PermissionMode, RunOptions } from "./generated/options.js";
|
|
17
|
+
export type Detection = DetectInfo;
|
|
18
|
+
export type { HarnessInfo, ListReport, ModeInfo, } from "./generated/registry.js";
|
|
19
|
+
export * from "./generated/zod.js";
|
|
20
|
+
export type OneHarnessOptions = {
|
|
21
|
+
executable?: string;
|
|
22
|
+
executableArgs?: readonly string[];
|
|
23
|
+
env?: Readonly<Record<string, string>>;
|
|
24
|
+
};
|
|
25
|
+
export declare class OneHarness {
|
|
26
|
+
private readonly options;
|
|
27
|
+
constructor(options?: OneHarnessOptions);
|
|
28
|
+
run(options: RunOptions): Promise<RunReport>;
|
|
29
|
+
list(): Promise<HarnessInfo[]>;
|
|
30
|
+
detect(harnesses?: readonly string[]): Promise<Detection[]>;
|
|
31
|
+
history(lookup: HistoryLookup): Promise<HistoryRecord[]>;
|
|
32
|
+
historyList(options?: HistoryListOptions): Promise<HistorySessionSummary[]>;
|
|
33
|
+
}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,146 @@
|
|
|
1
|
+
import { spawn } from "node:child_process";
|
|
2
|
+
import { createRequire } from "node:module";
|
|
3
|
+
import { DetectReportSchema, HistoryListOptionsSchema, HistoryListSchema, HistoryLookupSchema, HistoryRecordsSchema, ListReportSchema, RunOptionsSchema, RunReportSchema, } from "./generated/zod.js";
|
|
4
|
+
export * from "./generated/zod.js";
|
|
5
|
+
function parseContract(schema, value, label) {
|
|
6
|
+
const parsed = schema.safeParse(value);
|
|
7
|
+
if (parsed.success)
|
|
8
|
+
return parsed.data;
|
|
9
|
+
const details = parsed.error.issues
|
|
10
|
+
.map((issue) => `${issue.path.join(".") || "<root>"}: ${issue.message}`)
|
|
11
|
+
.join("; ");
|
|
12
|
+
throw new Error(`${label}: ${details}`);
|
|
13
|
+
}
|
|
14
|
+
function executable(options) {
|
|
15
|
+
if (options.executable)
|
|
16
|
+
return {
|
|
17
|
+
command: options.executable,
|
|
18
|
+
prefix: [...(options.executableArgs ?? [])],
|
|
19
|
+
};
|
|
20
|
+
if (process.env.ONEHARNESS_BIN)
|
|
21
|
+
return { command: process.env.ONEHARNESS_BIN, prefix: [] };
|
|
22
|
+
const require = createRequire(import.meta.url);
|
|
23
|
+
return {
|
|
24
|
+
command: process.execPath,
|
|
25
|
+
prefix: [require.resolve("oneharness-cli/bin/oneharness.js")],
|
|
26
|
+
};
|
|
27
|
+
}
|
|
28
|
+
async function invokeWith(options, args, cwd, acceptJsonOnNonzero = false) {
|
|
29
|
+
const bin = executable(options);
|
|
30
|
+
return await new Promise((resolve, reject) => {
|
|
31
|
+
const child = spawn(bin.command, [...bin.prefix, ...args], {
|
|
32
|
+
cwd,
|
|
33
|
+
env: { ...process.env, ...options.env },
|
|
34
|
+
windowsHide: true,
|
|
35
|
+
});
|
|
36
|
+
let stdout = "";
|
|
37
|
+
let stderr = "";
|
|
38
|
+
child.stdout
|
|
39
|
+
.setEncoding("utf8")
|
|
40
|
+
.on("data", (chunk) => (stdout += chunk));
|
|
41
|
+
child.stderr
|
|
42
|
+
.setEncoding("utf8")
|
|
43
|
+
.on("data", (chunk) => (stderr += chunk));
|
|
44
|
+
child.on("error", reject);
|
|
45
|
+
child.on("close", (code) => {
|
|
46
|
+
if (code !== 0 && !acceptJsonOnNonzero)
|
|
47
|
+
return reject(new Error(`oneharness exited ${code}: ${stderr.trim()}`));
|
|
48
|
+
try {
|
|
49
|
+
resolve(JSON.parse(stdout));
|
|
50
|
+
}
|
|
51
|
+
catch (error) {
|
|
52
|
+
if (code !== 0)
|
|
53
|
+
return reject(new Error(`oneharness exited ${code}: ${stderr.trim()}`));
|
|
54
|
+
reject(new Error(`oneharness returned invalid JSON: ${String(error)}`));
|
|
55
|
+
}
|
|
56
|
+
});
|
|
57
|
+
});
|
|
58
|
+
}
|
|
59
|
+
function pushMany(args, flag, values) {
|
|
60
|
+
for (const value of values ?? [])
|
|
61
|
+
args.push(flag, value);
|
|
62
|
+
}
|
|
63
|
+
export class OneHarness {
|
|
64
|
+
options;
|
|
65
|
+
constructor(options = {}) {
|
|
66
|
+
this.options = options;
|
|
67
|
+
}
|
|
68
|
+
async run(options) {
|
|
69
|
+
const input = parseContract(RunOptionsSchema, options, "invalid oneharness run options");
|
|
70
|
+
const args = ["run", "--prompt", input.prompt, "--compact"];
|
|
71
|
+
pushMany(args, "--harness", input.harnesses);
|
|
72
|
+
pushMany(args, "--model", input.models);
|
|
73
|
+
if (input.system !== undefined)
|
|
74
|
+
args.push("--system", input.system);
|
|
75
|
+
if (input.reasoning !== undefined)
|
|
76
|
+
args.push("--reasoning", input.reasoning);
|
|
77
|
+
if (input.resume !== undefined)
|
|
78
|
+
args.push("--resume", input.resume);
|
|
79
|
+
if (input.session !== undefined)
|
|
80
|
+
args.push("--session", input.session);
|
|
81
|
+
if (input.fork)
|
|
82
|
+
args.push("--fork");
|
|
83
|
+
if (input.mode)
|
|
84
|
+
args.push("--mode", input.mode);
|
|
85
|
+
if (input.timeoutSeconds !== undefined)
|
|
86
|
+
args.push("--timeout", String(input.timeoutSeconds));
|
|
87
|
+
if (input.events)
|
|
88
|
+
args.push("--events");
|
|
89
|
+
if (input.history)
|
|
90
|
+
args.push("--history");
|
|
91
|
+
if (input.historyName !== undefined)
|
|
92
|
+
args.push("--history-name", input.historyName);
|
|
93
|
+
if (input.historyDir !== undefined)
|
|
94
|
+
args.push("--history-dir", input.historyDir);
|
|
95
|
+
for (const [key, value] of Object.entries(input.env ?? {}))
|
|
96
|
+
args.push("--env", `${key}=${value}`);
|
|
97
|
+
for (const [key, value] of Object.entries(input.bins ?? {}))
|
|
98
|
+
args.push("--bin", `${key}=${value}`);
|
|
99
|
+
const value = await invokeWith(this.options, args, input.cwd, true);
|
|
100
|
+
return parseContract(RunReportSchema, value, "invalid oneharness run contract");
|
|
101
|
+
}
|
|
102
|
+
async list() {
|
|
103
|
+
const value = await invokeWith(this.options, ["list", "--compact"]);
|
|
104
|
+
return parseContract(ListReportSchema, value, "invalid oneharness list contract").harnesses;
|
|
105
|
+
}
|
|
106
|
+
async detect(harnesses = []) {
|
|
107
|
+
const args = ["detect", "--compact"];
|
|
108
|
+
pushMany(args, "--harness", harnesses);
|
|
109
|
+
const value = await invokeWith(this.options, args);
|
|
110
|
+
return parseContract(DetectReportSchema, value, "invalid oneharness detect contract").detected;
|
|
111
|
+
}
|
|
112
|
+
async history(lookup) {
|
|
113
|
+
const input = parseContract(HistoryLookupSchema, lookup, "invalid oneharness history options");
|
|
114
|
+
const args = ["history", "show", "--compact"];
|
|
115
|
+
// A lookup that selects no session is not a HistoryLookup, so only these
|
|
116
|
+
// two cases remain. The variants overlap on `{session, last: true}`, and
|
|
117
|
+
// `last: true` keeps its long-standing priority over a name — which is why
|
|
118
|
+
// the union tries the last-session variant first, in Rust and in the
|
|
119
|
+
// generated Zod alike. Ruling that case out here leaves the variant whose
|
|
120
|
+
// session the type guarantees is present.
|
|
121
|
+
if (input.last === true)
|
|
122
|
+
args.push("--last");
|
|
123
|
+
else
|
|
124
|
+
args.push(input.session);
|
|
125
|
+
if (input.project)
|
|
126
|
+
args.push("--project", input.project);
|
|
127
|
+
if (input.allProjects)
|
|
128
|
+
args.push("--all-projects");
|
|
129
|
+
if (input.historyDir)
|
|
130
|
+
args.push("--history-dir", input.historyDir);
|
|
131
|
+
const value = await invokeWith(this.options, args);
|
|
132
|
+
return parseContract(HistoryRecordsSchema, value, "invalid history contract");
|
|
133
|
+
}
|
|
134
|
+
async historyList(options = {}) {
|
|
135
|
+
const input = parseContract(HistoryListOptionsSchema, options, "invalid oneharness history list options");
|
|
136
|
+
const args = ["history", "list", "--compact"];
|
|
137
|
+
if (input.project)
|
|
138
|
+
args.push("--project", input.project);
|
|
139
|
+
if (input.allProjects)
|
|
140
|
+
args.push("--all-projects");
|
|
141
|
+
if (input.historyDir)
|
|
142
|
+
args.push("--history-dir", input.historyDir);
|
|
143
|
+
const value = await invokeWith(this.options, args);
|
|
144
|
+
return parseContract(HistoryListSchema, value, "invalid history list contract");
|
|
145
|
+
}
|
|
146
|
+
}
|
package/package.json
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@oneharness/sdk",
|
|
3
|
+
"version": "0.3.22",
|
|
4
|
+
"description": "Typed Node.js SDK for oneharness",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"main": "dist/index.js",
|
|
7
|
+
"types": "dist/index.d.ts",
|
|
8
|
+
"exports": {
|
|
9
|
+
".": {
|
|
10
|
+
"types": "./dist/index.d.ts",
|
|
11
|
+
"import": "./dist/index.js"
|
|
12
|
+
}
|
|
13
|
+
},
|
|
14
|
+
"files": [
|
|
15
|
+
"dist",
|
|
16
|
+
"README.md"
|
|
17
|
+
],
|
|
18
|
+
"engines": {
|
|
19
|
+
"node": ">=20"
|
|
20
|
+
},
|
|
21
|
+
"dependencies": {
|
|
22
|
+
"oneharness-cli": "0.3.22",
|
|
23
|
+
"zod": "^4.4.3"
|
|
24
|
+
}
|
|
25
|
+
}
|