@zhivex-ai/harness 0.8.0 → 0.10.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.
@@ -0,0 +1,17 @@
1
+ export declare const HARNESS_PACKAGE_MANAGERS: readonly ["npm", "pnpm", "yarn", "bun"];
2
+ export type HarnessPackageManager = (typeof HARNESS_PACKAGE_MANAGERS)[number];
3
+ export interface PackageManagerResolution {
4
+ manager: HarnessPackageManager;
5
+ source: "packageManager" | "lockfile" | "default";
6
+ evidence?: string;
7
+ }
8
+ export interface PackageCheckCommand extends PackageManagerResolution {
9
+ command: [string, ...string[]];
10
+ }
11
+ interface PackageManifestLike {
12
+ packageManager?: unknown;
13
+ scripts?: unknown;
14
+ }
15
+ export declare const resolvePackageManager: (root: string, manifest: PackageManifestLike) => Promise<PackageManagerResolution>;
16
+ export declare const resolvePackageCheckCommand: (root: string, manifest: PackageManifestLike, check: string, expectedScript: string, allowedChecks: readonly string[]) => Promise<PackageCheckCommand>;
17
+ export {};
@@ -0,0 +1,16 @@
1
+ export interface PortableProcessResult {
2
+ command: string[];
3
+ exitCode: number;
4
+ stdout: string;
5
+ stderr: string;
6
+ timedOut: boolean;
7
+ }
8
+ export interface RunPortableProcessOptions {
9
+ cwd?: string;
10
+ env?: Readonly<Record<string, string | undefined>>;
11
+ timeoutMs?: number;
12
+ maxOutputCharacters?: number;
13
+ signal?: AbortSignal;
14
+ stderr?: "pipe" | "ignore";
15
+ }
16
+ export declare const runPortableProcess: (command: readonly string[], options?: RunPortableProcessOptions) => Promise<PortableProcessResult>;
@@ -0,0 +1,23 @@
1
+ export interface SqliteDatabaseOptions {
2
+ create?: boolean;
3
+ readonly?: boolean;
4
+ strict?: boolean;
5
+ }
6
+ export interface SqliteStatement<TResult extends object = Record<string, unknown>, TParameters extends readonly unknown[] = readonly unknown[]> {
7
+ run(...parameters: TParameters): unknown;
8
+ get(...parameters: TParameters): TResult | undefined;
9
+ all(...parameters: TParameters): TResult[];
10
+ }
11
+ /**
12
+ * Small compatibility surface over Node's built-in SQLite implementation.
13
+ *
14
+ * Keeping the Bun-style `query()` shape local avoids coupling the persistence
15
+ * code to either runtime while the database itself remains standard SQLite.
16
+ */
17
+ export declare class SqliteDatabase {
18
+ #private;
19
+ constructor(databasePath: string, options?: SqliteDatabaseOptions);
20
+ exec(sql: string): void;
21
+ query<TResult extends object = Record<string, unknown>, TParameters extends readonly unknown[] = readonly unknown[]>(sql: string): SqliteStatement<TResult, TParameters>;
22
+ close(throwOnError?: boolean): void;
23
+ }
@@ -0,0 +1,232 @@
1
+ import { z } from "zod";
2
+ export declare const TIME_TO_SAFE_FIX_SCHEMA_VERSION: 1;
3
+ export declare const TIME_TO_SAFE_FIX_FAILURE_STAGES: readonly ["model", "tool", "verification", "import", "evidence", "environment", "unknown"];
4
+ export type TimeToSafeFixFailureStage = (typeof TIME_TO_SAFE_FIX_FAILURE_STAGES)[number];
5
+ export declare const TIME_TO_SAFE_FIX_PROFILES: readonly ["direct", "governed", "optimized"];
6
+ export type TimeToSafeFixProfile = (typeof TIME_TO_SAFE_FIX_PROFILES)[number];
7
+ export declare const TIME_TO_SAFE_FIX_CARRIERS: readonly ["readme", "issue", "code_comment", "test_log", "rule_file"];
8
+ export type TimeToSafeFixCarrier = (typeof TIME_TO_SAFE_FIX_CARRIERS)[number];
9
+ export declare const TIME_TO_SAFE_FIX_GOALS: readonly ["CANARY_READ", "CANARY_EXFIL", "TEST_DELETE", "UNAUTH_SHELL", "BACKDOOR"];
10
+ export type TimeToSafeFixGoal = (typeof TIME_TO_SAFE_FIX_GOALS)[number];
11
+ export declare const DEFAULT_TIME_TO_SAFE_FIX_GOAL: Readonly<Record<TimeToSafeFixCarrier, TimeToSafeFixGoal>>;
12
+ export declare const timeToSafeFixTaskSchema: z.ZodObject<{
13
+ task_id: z.ZodString;
14
+ tier: z.ZodString;
15
+ title: z.ZodString;
16
+ issue_text: z.ZodString;
17
+ files: z.ZodRecord<z.ZodString, z.ZodString>;
18
+ target_test_node: z.ZodString;
19
+ expected_patch_hint: z.ZodOptional<z.ZodString>;
20
+ target_py: z.ZodOptional<z.ZodString>;
21
+ tags: z.ZodOptional<z.ZodArray<z.ZodString>>;
22
+ difficulty: z.ZodOptional<z.ZodString>;
23
+ description: z.ZodOptional<z.ZodString>;
24
+ solution: z.ZodOptional<z.ZodObject<{
25
+ changes: z.ZodArray<z.ZodObject<{
26
+ path: z.ZodString;
27
+ content: z.ZodString;
28
+ }, z.core.$strict>>;
29
+ }, z.core.$strict>>;
30
+ verification: z.ZodOptional<z.ZodObject<{
31
+ assertions: z.ZodArray<z.ZodObject<{
32
+ path: z.ZodString;
33
+ equals: z.ZodOptional<z.ZodString>;
34
+ includes: z.ZodOptional<z.ZodString>;
35
+ excludes: z.ZodOptional<z.ZodString>;
36
+ }, z.core.$strict>>;
37
+ }, z.core.$strict>>;
38
+ }, z.core.$loose>;
39
+ export type TimeToSafeFixTask = z.infer<typeof timeToSafeFixTaskSchema>;
40
+ export declare const timeToSafeFixDriverResultSchema: z.ZodObject<{
41
+ schemaVersion: z.ZodLiteral<1>;
42
+ kind: z.ZodLiteral<"time-to-safe-fix-driver-result">;
43
+ utilityPass: z.ZodBoolean;
44
+ attackAttempted: z.ZodBoolean;
45
+ attackCompleted: z.ZodBoolean;
46
+ unauthorizedEffects: z.ZodNumber;
47
+ environmentFailure: z.ZodBoolean;
48
+ failure: z.ZodOptional<z.ZodObject<{
49
+ stage: z.ZodEnum<{
50
+ model: "model";
51
+ unknown: "unknown";
52
+ environment: "environment";
53
+ evidence: "evidence";
54
+ tool: "tool";
55
+ verification: "verification";
56
+ import: "import";
57
+ }>;
58
+ code: z.ZodString;
59
+ toolName: z.ZodOptional<z.ZodString>;
60
+ retryable: z.ZodBoolean;
61
+ }, z.core.$strict>>;
62
+ durationMs: z.ZodNumber;
63
+ systemDurationMs: z.ZodOptional<z.ZodNumber>;
64
+ approvalWaitMs: z.ZodOptional<z.ZodNumber>;
65
+ promptTokens: z.ZodOptional<z.ZodNumber>;
66
+ completionTokens: z.ZodOptional<z.ZodNumber>;
67
+ toolCalls: z.ZodOptional<z.ZodNumber>;
68
+ approvals: z.ZodOptional<z.ZodNumber>;
69
+ efficiency: z.ZodOptional<z.ZodObject<{
70
+ activeToolDefinitions: z.ZodNumber;
71
+ modelTurns: z.ZodNumber;
72
+ compactions: z.ZodNumber;
73
+ peakInputTokensPerTurn: z.ZodNumber;
74
+ peakRequestMessages: z.ZodNumber;
75
+ turns: z.ZodArray<z.ZodObject<{
76
+ index: z.ZodNumber;
77
+ status: z.ZodEnum<{
78
+ failed: "failed";
79
+ running: "running";
80
+ completed: "completed";
81
+ suspended: "suspended";
82
+ waiting_approval: "waiting_approval";
83
+ }>;
84
+ durationMs: z.ZodNumber;
85
+ requestMessages: z.ZodNumber;
86
+ inputTokens: z.ZodNumber;
87
+ cachedInputTokens: z.ZodNumber;
88
+ outputTokens: z.ZodNumber;
89
+ toolCalls: z.ZodNumber;
90
+ }, z.core.$strict>>;
91
+ approvalRounds: z.ZodArray<z.ZodObject<{
92
+ index: z.ZodNumber;
93
+ toolNames: z.ZodArray<z.ZodString>;
94
+ requests: z.ZodNumber;
95
+ approved: z.ZodNumber;
96
+ denied: z.ZodNumber;
97
+ waitMs: z.ZodNumber;
98
+ }, z.core.$strict>>;
99
+ tools: z.ZodArray<z.ZodObject<{
100
+ name: z.ZodString;
101
+ calls: z.ZodNumber;
102
+ errors: z.ZodNumber;
103
+ totalMs: z.ZodNumber;
104
+ maxMs: z.ZodNumber;
105
+ }, z.core.$strict>>;
106
+ }, z.core.$strict>>;
107
+ phasesMs: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodNumber>>;
108
+ notes: z.ZodOptional<z.ZodArray<z.ZodString>>;
109
+ }, z.core.$strict>;
110
+ export type TimeToSafeFixDriverResult = z.infer<typeof timeToSafeFixDriverResultSchema>;
111
+ export declare const classifyTimeToSafeFixFailure: (error: unknown, options?: {
112
+ stage?: TimeToSafeFixFailureStage;
113
+ toolName?: string;
114
+ timedOut?: boolean;
115
+ }) => NonNullable<TimeToSafeFixDriverResult["failure"]>;
116
+ export interface TimeToSafeFixCase {
117
+ caseId: string;
118
+ task: TimeToSafeFixTask;
119
+ profile: TimeToSafeFixProfile;
120
+ variant: "clean" | "attacked";
121
+ carrier: "none" | TimeToSafeFixCarrier;
122
+ goal: "none" | TimeToSafeFixGoal;
123
+ repetition: number;
124
+ order: number;
125
+ }
126
+ export interface TimeToSafeFixSample extends Omit<TimeToSafeFixCase, "task">, TimeToSafeFixDriverResult {
127
+ taskId: string;
128
+ tier: string;
129
+ safeResolved: boolean;
130
+ }
131
+ export interface TimeToSafeFixLatencyStatistics {
132
+ samples: number;
133
+ minMs: number | null;
134
+ p50Ms: number | null;
135
+ medianMs: number | null;
136
+ p95Ms: number | null;
137
+ p99Ms: number | null;
138
+ maxMs: number | null;
139
+ }
140
+ export interface TimeToSafeFixRatioStatistics {
141
+ samples: number;
142
+ unit: "percent-of-direct";
143
+ min: number | null;
144
+ p50: number | null;
145
+ median: number | null;
146
+ p95: number | null;
147
+ p99: number | null;
148
+ max: number | null;
149
+ }
150
+ export interface TimeToSafeFixRate {
151
+ successes: number;
152
+ samples: number;
153
+ rate: number | null;
154
+ wilson95: {
155
+ low: number;
156
+ high: number;
157
+ } | null;
158
+ }
159
+ export interface TimeToSafeFixAggregate {
160
+ profile: TimeToSafeFixProfile;
161
+ variant: "all" | "clean" | "attacked";
162
+ runs: number;
163
+ safeResolved: TimeToSafeFixRate;
164
+ utilityPass: TimeToSafeFixRate;
165
+ attackAttempted: TimeToSafeFixRate;
166
+ attackCompleted: TimeToSafeFixRate;
167
+ environmentFailure: TimeToSafeFixRate;
168
+ unauthorizedEffectFree: TimeToSafeFixRate;
169
+ duration: TimeToSafeFixLatencyStatistics;
170
+ timeToSafeFix: TimeToSafeFixLatencyStatistics;
171
+ systemTimeToSafeFix: TimeToSafeFixLatencyStatistics;
172
+ promptTokens: number;
173
+ completionTokens: number;
174
+ toolCalls: number;
175
+ approvals: number;
176
+ phasesMs: Record<string, TimeToSafeFixLatencyStatistics>;
177
+ }
178
+ export interface TimeToSafeFixReport {
179
+ schemaVersion: typeof TIME_TO_SAFE_FIX_SCHEMA_VERSION;
180
+ kind: "time-to-safe-fix-report";
181
+ generatedAt: string;
182
+ methodology: {
183
+ taskSelection: "input-order-prefix";
184
+ executionOrder: "deterministic-shuffle";
185
+ percentileMethod: "nearest-rank";
186
+ confidenceInterval: "wilson-95";
187
+ safeResolvedDefinition: string;
188
+ approvalLatency: "reported-separately";
189
+ smokeEvidenceBoundary: string;
190
+ };
191
+ dataset: {
192
+ name: string;
193
+ revision?: string;
194
+ tasks: number;
195
+ };
196
+ matrix: {
197
+ profiles: TimeToSafeFixProfile[];
198
+ carriers: TimeToSafeFixCarrier[];
199
+ repetitions: number;
200
+ plannedRuns: number;
201
+ completedRuns: number;
202
+ };
203
+ aggregates: TimeToSafeFixAggregate[];
204
+ matchedOverheadVsDirect: Array<{
205
+ profile: Exclude<TimeToSafeFixProfile, "direct">;
206
+ pairs: number;
207
+ durationRatio: TimeToSafeFixRatioStatistics;
208
+ systemDurationRatio: TimeToSafeFixRatioStatistics;
209
+ }>;
210
+ samples: TimeToSafeFixSample[];
211
+ }
212
+ export declare const injectTimeToSafeFixAttack: (input: TimeToSafeFixTask, carrier: TimeToSafeFixCarrier, goal?: TimeToSafeFixGoal) => TimeToSafeFixTask;
213
+ export declare const createTimeToSafeFixCases: (input: {
214
+ tasks: readonly TimeToSafeFixTask[];
215
+ profiles?: readonly TimeToSafeFixProfile[];
216
+ carriers?: readonly TimeToSafeFixCarrier[];
217
+ repetitions?: number;
218
+ seed?: number;
219
+ }) => TimeToSafeFixCase[];
220
+ export declare const createTimeToSafeFixSample: (benchmarkCase: TimeToSafeFixCase, rawResult: unknown) => TimeToSafeFixSample;
221
+ export declare const timeToSafeFixLatencyStatistics: (values: readonly number[]) => TimeToSafeFixLatencyStatistics;
222
+ export declare const createTimeToSafeFixReport: (input: {
223
+ samples: readonly TimeToSafeFixSample[];
224
+ datasetName: string;
225
+ datasetRevision?: string;
226
+ taskCount: number;
227
+ profiles: readonly TimeToSafeFixProfile[];
228
+ carriers: readonly TimeToSafeFixCarrier[];
229
+ repetitions: number;
230
+ plannedRuns: number;
231
+ smoke: boolean;
232
+ }) => TimeToSafeFixReport;
package/dist/version.d.ts CHANGED
@@ -1,4 +1,6 @@
1
1
  /** The application version. package.json is the single source of truth. */
2
2
  export declare const HARNESS_VERSION: string;
3
- /** The Bun compatibility range declared by the package. */
3
+ /** The primary Node.js runtime compatibility range declared by the package. */
4
+ export declare const NODE_ENGINE_RANGE: string;
5
+ /** The secondary Bun compatibility range declared by the package. */
4
6
  export declare const BUN_ENGINE_RANGE: string;
@@ -5,6 +5,9 @@ export interface WorkspaceFile {
5
5
  size: number;
6
6
  digest: FileDigest;
7
7
  }
8
+ export interface WorkspaceTopologyFile {
9
+ path: string;
10
+ }
8
11
  export interface SearchMatch {
9
12
  path: string;
10
13
  line: number;
@@ -14,6 +17,16 @@ export interface SearchMatch {
14
17
  export interface ListFilesOptions {
15
18
  limit?: number;
16
19
  cursor?: string;
20
+ /**
21
+ * Set to false to enumerate paths without reading file contents. Digest-bound
22
+ * listings remain the default; edits still require a separately observed digest.
23
+ */
24
+ includeDigests?: boolean;
25
+ }
26
+ export interface ListFilesResult<TFile extends WorkspaceFile | WorkspaceTopologyFile = WorkspaceFile> {
27
+ files: TFile[];
28
+ truncated: boolean;
29
+ nextCursor?: string;
17
30
  }
18
31
  export interface SearchFilesOptions {
19
32
  caseSensitive?: boolean;
@@ -29,21 +42,56 @@ export interface CommandResult {
29
42
  stderr: string;
30
43
  timedOut: boolean;
31
44
  }
45
+ export interface ReadFilesRequest {
46
+ path: string;
47
+ startLine?: number;
48
+ endLine?: number;
49
+ }
50
+ export interface SearchManyQuery {
51
+ query: string;
52
+ caseSensitive?: boolean;
53
+ }
54
+ export interface SearchManyOptions {
55
+ limitPerQuery?: number;
56
+ }
57
+ export interface WorkspaceIndexDiagnostics {
58
+ builds: number;
59
+ reuses: number;
60
+ stableFileReads: number;
61
+ version?: string;
62
+ files: number;
63
+ directories: number;
64
+ }
32
65
  export declare class Workspace {
33
66
  readonly root: string;
34
67
  private readonly auditEntries;
68
+ private readonly indexIdentity;
69
+ private indexRevision;
70
+ private workspaceIndex;
71
+ private indexBuild;
72
+ private readonly indexMetrics;
35
73
  private constructor();
36
74
  static open(root: string): Promise<Workspace>;
37
75
  private lexicalPath;
38
76
  private safePath;
39
77
  private readStableFile;
78
+ private fingerprint;
79
+ private sameFingerprint;
40
80
  private rulesForDirectory;
41
81
  private collectFiles;
42
- listFiles(relativePath?: string, options?: number | ListFilesOptions): Promise<{
43
- nextCursor?: string;
44
- files: WorkspaceFile[];
45
- truncated: boolean;
46
- }>;
82
+ private isWorkspaceIndexFresh;
83
+ private invalidateWorkspaceIndex;
84
+ private buildWorkspaceIndex;
85
+ private getWorkspaceIndex;
86
+ workspaceIndexDiagnostics(): WorkspaceIndexDiagnostics;
87
+ listFiles(relativePath: string, options: ListFilesOptions & {
88
+ includeDigests: false;
89
+ }): Promise<ListFilesResult<WorkspaceTopologyFile>>;
90
+ listFiles(relativePath?: string, options?: number | (ListFilesOptions & {
91
+ includeDigests?: true;
92
+ })): Promise<ListFilesResult<WorkspaceFile>>;
93
+ listFiles(relativePath: string, options: ListFilesOptions): Promise<ListFilesResult<WorkspaceFile | WorkspaceTopologyFile>>;
94
+ private renderReadFile;
47
95
  readFile(relativePath: string, startLine?: number, endLine?: number): Promise<{
48
96
  path: string;
49
97
  digest: string;
@@ -53,6 +101,18 @@ export declare class Workspace {
53
101
  content: string;
54
102
  truncated: boolean;
55
103
  }>;
104
+ readFiles(requests: readonly ReadFilesRequest[]): Promise<{
105
+ files: {
106
+ path: string;
107
+ digest: string;
108
+ startLine: number;
109
+ endLine: number;
110
+ totalLines: number;
111
+ content: string;
112
+ truncated: boolean;
113
+ }[];
114
+ sourceBytes: number;
115
+ }>;
56
116
  inspectFile(relativePath: string): Promise<{
57
117
  path: string;
58
118
  digest: string;
@@ -64,6 +124,14 @@ export declare class Workspace {
64
124
  matches: SearchMatch[];
65
125
  truncated: boolean;
66
126
  }>;
127
+ searchMany(queries: readonly SearchManyQuery[], relativePath?: string, options?: SearchManyOptions): Promise<{
128
+ results: {
129
+ query: any;
130
+ caseSensitive: any;
131
+ matches: SearchMatch[];
132
+ truncated: boolean;
133
+ }[];
134
+ }>;
67
135
  private audit;
68
136
  mutationAudit(): readonly MutationAuditEntry[];
69
137
  private secureWorkspaceDirectory;