@zhivex-ai/harness 0.6.1 → 0.7.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.
@@ -7,13 +7,359 @@ import path8 from "path";
7
7
  import { createMockLanguageModel } from "@zhivex-ai/agents/testing";
8
8
 
9
9
  // src/config.ts
10
- import { createHash } from "crypto";
10
+ import { createHash as createHash2 } from "crypto";
11
11
  import { realpathSync } from "fs";
12
12
  import path from "path";
13
+
14
+ // src/providers.ts
15
+ import { createHash } from "crypto";
16
+ import { createGemini } from "@zhivex-ai/gemini";
13
17
  import { createMeta } from "@zhivex-ai/meta";
14
18
  import { createOpenAI } from "@zhivex-ai/openai";
15
19
  import { createQwen } from "@zhivex-ai/qwen";
16
- var PROVIDERS = ["meta", "qwen", "openai"];
20
+ var HARNESS_PROVIDER_CAPABILITIES = [
21
+ "streaming",
22
+ "tool-calling",
23
+ "approval-resume"
24
+ ];
25
+ var QWEN_REGIONS = [
26
+ "singapore",
27
+ "beijing",
28
+ "hong-kong",
29
+ "tokyo",
30
+ "frankfurt",
31
+ "virginia"
32
+ ];
33
+ var PROVIDER_ID = /^[a-z0-9][a-z0-9._-]{0,63}$/;
34
+ var ENVIRONMENT_VARIABLE = /^[A-Z_][A-Z0-9_]{0,127}$/;
35
+ var DIAGNOSTIC_KEY = /^[a-z][A-Za-z0-9]{0,63}$/;
36
+ var requiredText = (name, value) => {
37
+ const normalized = value.trim();
38
+ if (!normalized || /[\u0000-\u001f\u007f]/.test(normalized)) {
39
+ throw new Error(`${name} must be a non-empty printable string.`);
40
+ }
41
+ return normalized;
42
+ };
43
+ var environmentVariable = (name, value) => {
44
+ if (!ENVIRONMENT_VARIABLE.test(value)) {
45
+ throw new Error(`${name} must be a valid environment variable name.`);
46
+ }
47
+ return value;
48
+ };
49
+ var diagnosticKey = (value) => {
50
+ if (!DIAGNOSTIC_KEY.test(value)) {
51
+ throw new Error(`Invalid provider diagnostic key: ${value}.`);
52
+ }
53
+ return value;
54
+ };
55
+ var normalizedDescriptor = (descriptor) => {
56
+ const id = descriptor.id.trim().toLowerCase();
57
+ if (descriptor.id !== id || !PROVIDER_ID.test(id)) {
58
+ throw new Error(`Invalid provider id: ${descriptor.id}. Use 1-64 lowercase letters, digits, dot, underscore, or hyphen.`);
59
+ }
60
+ if (!(descriptor.support === "certified" || descriptor.support === "provisional")) {
61
+ throw new Error(`Invalid support level for provider ${id}.`);
62
+ }
63
+ const credentialNames = [...new Set(descriptor.credentialNames.map((name) => environmentVariable(`Credential for provider ${id}`, name)))];
64
+ const capabilities = [...new Set(descriptor.capabilities)];
65
+ const invalidCapability = capabilities.find((capability) => !HARNESS_PROVIDER_CAPABILITIES.includes(capability));
66
+ if (invalidCapability) {
67
+ throw new Error(`Invalid capability for provider ${id}: ${invalidCapability}.`);
68
+ }
69
+ return Object.freeze({
70
+ id,
71
+ name: requiredText(`Name for provider ${id}`, descriptor.name),
72
+ defaultModel: requiredText(`Default model for provider ${id}`, descriptor.defaultModel),
73
+ credentialNames: Object.freeze(credentialNames),
74
+ capabilities: Object.freeze(capabilities),
75
+ support: descriptor.support
76
+ });
77
+ };
78
+ var normalizedDiagnostics = (provider, diagnostics) => {
79
+ const endpointEnvironmentVariable = diagnostics?.endpointEnvironmentVariable === undefined ? undefined : environmentVariable(`Endpoint diagnostic for provider ${provider}`, diagnostics.endpointEnvironmentVariable);
80
+ const seenKeys = new Set;
81
+ const presence = (diagnostics?.presence ?? []).map((entry) => {
82
+ const key = diagnosticKey(entry.key);
83
+ if (seenKeys.has(key)) {
84
+ throw new Error(`Duplicate diagnostic key for provider ${provider}: ${key}.`);
85
+ }
86
+ seenKeys.add(key);
87
+ return Object.freeze({
88
+ key,
89
+ environmentVariable: environmentVariable(`Presence diagnostic for provider ${provider}`, entry.environmentVariable)
90
+ });
91
+ });
92
+ const enums = (diagnostics?.enums ?? []).map((entry) => {
93
+ const key = diagnosticKey(entry.key);
94
+ if (seenKeys.has(key)) {
95
+ throw new Error(`Duplicate diagnostic key for provider ${provider}: ${key}.`);
96
+ }
97
+ seenKeys.add(key);
98
+ const allowedValues = [...new Set(entry.allowedValues.map((value) => requiredText(`Allowed diagnostic value for provider ${provider}`, value)))];
99
+ if (allowedValues.length === 0) {
100
+ throw new Error(`Enum diagnostic ${key} for provider ${provider} needs allowed values.`);
101
+ }
102
+ return Object.freeze({
103
+ key,
104
+ environmentVariable: environmentVariable(`Enum diagnostic for provider ${provider}`, entry.environmentVariable),
105
+ allowedValues: Object.freeze(allowedValues)
106
+ });
107
+ });
108
+ return Object.freeze({
109
+ ...endpointEnvironmentVariable ? { endpointEnvironmentVariable } : {},
110
+ ...presence.length > 0 ? { presence: Object.freeze(presence) } : {},
111
+ ...enums.length > 0 ? { enums: Object.freeze(enums) } : {}
112
+ });
113
+ };
114
+ var endpointConfiguration = (value) => {
115
+ const configured = Boolean(value?.trim());
116
+ if (!configured) {
117
+ return {
118
+ customEndpoint: false,
119
+ endpointValid: true,
120
+ endpointSecure: true
121
+ };
122
+ }
123
+ try {
124
+ const endpoint = new URL(value.trim());
125
+ const supportedProtocol = endpoint.protocol === "https:" || endpoint.protocol === "http:";
126
+ return {
127
+ customEndpoint: true,
128
+ endpointValid: supportedProtocol && !endpoint.username && !endpoint.password && !endpoint.hash && !endpoint.search,
129
+ endpointSecure: endpoint.protocol === "https:"
130
+ };
131
+ } catch {
132
+ return {
133
+ customEndpoint: true,
134
+ endpointValid: false,
135
+ endpointSecure: false
136
+ };
137
+ }
138
+ };
139
+ var createCredentials = (env, provider, names) => Object.freeze({
140
+ names,
141
+ get: (name) => {
142
+ if (!names.includes(name)) {
143
+ throw new Error(`Credential ${name} is not declared for provider ${provider}.`);
144
+ }
145
+ return env[name]?.trim() || undefined;
146
+ },
147
+ first: () => {
148
+ for (const name of names) {
149
+ const value = env[name]?.trim();
150
+ if (value) {
151
+ return value;
152
+ }
153
+ }
154
+ return;
155
+ },
156
+ require: () => {
157
+ for (const name of names) {
158
+ const value = env[name]?.trim();
159
+ if (value) {
160
+ return value;
161
+ }
162
+ }
163
+ throw new Error(names.length === 0 ? `Provider ${provider} does not declare a credential.` : `Missing credentials for ${provider}. Set ${names.join(" or ")} in the environment.`);
164
+ }
165
+ });
166
+ var normalizeRegistration = (registration) => {
167
+ if (typeof registration.factory !== "function") {
168
+ throw new Error("Provider registration factory must be a function.");
169
+ }
170
+ const descriptor = normalizedDescriptor(registration.descriptor);
171
+ return Object.freeze({
172
+ descriptor,
173
+ factory: registration.factory,
174
+ diagnostics: normalizedDiagnostics(descriptor.id, registration.diagnostics)
175
+ });
176
+ };
177
+ var providerConfiguration = (diagnostics, env) => {
178
+ const configuration = endpointConfiguration(diagnostics.endpointEnvironmentVariable ? env[diagnostics.endpointEnvironmentVariable] : undefined);
179
+ for (const entry of diagnostics.presence ?? []) {
180
+ configuration[`${entry.key}Configured`] = Boolean(env[entry.environmentVariable]?.trim());
181
+ }
182
+ for (const entry of diagnostics.enums ?? []) {
183
+ const value = env[entry.environmentVariable]?.trim();
184
+ configuration[`${entry.key}Configured`] = Boolean(value);
185
+ configuration[`${entry.key}Valid`] = !value || entry.allowedValues.includes(value);
186
+ }
187
+ return Object.freeze(configuration);
188
+ };
189
+ var parseWithRegistrations = (value, registrations) => {
190
+ const defaultProvider = registrations.has("openai") ? "openai" : registrations.keys().next().value;
191
+ const normalized = (value ?? defaultProvider ?? "").trim().toLowerCase();
192
+ if (registrations.has(normalized)) {
193
+ return normalized;
194
+ }
195
+ throw new Error(`Unknown provider: ${value}. Use ${[...registrations.keys()].join(", ")}.`);
196
+ };
197
+ var createProviderRegistry = (registrations) => {
198
+ if (registrations.length === 0) {
199
+ throw new Error("Provider registry must contain at least one provider.");
200
+ }
201
+ const entries = new Map;
202
+ for (const registration of registrations) {
203
+ const normalized = normalizeRegistration(registration);
204
+ if (entries.has(normalized.descriptor.id)) {
205
+ throw new Error(`Duplicate provider registration: ${normalized.descriptor.id}.`);
206
+ }
207
+ entries.set(normalized.descriptor.id, normalized);
208
+ }
209
+ const frozenRegistrations = Object.freeze([...entries.values()]);
210
+ const descriptors = Object.freeze(frozenRegistrations.map((entry) => entry.descriptor));
211
+ const registry = Object.freeze({
212
+ descriptors,
213
+ has: (provider) => entries.has(provider.trim().toLowerCase()),
214
+ parse: (value) => parseWithRegistrations(value, entries),
215
+ descriptor: (provider) => {
216
+ const registration = entries.get(provider);
217
+ if (!registration) {
218
+ throw new Error(`No descriptor is available for provider ${provider}.`);
219
+ }
220
+ return registration.descriptor;
221
+ },
222
+ createModel: (config, env = process.env) => {
223
+ const registration = entries.get(config.provider);
224
+ if (!registration) {
225
+ throw new Error(`No factory is available for provider ${config.provider}.`);
226
+ }
227
+ return registration.factory(Object.freeze({
228
+ provider: config.provider,
229
+ model: config.model,
230
+ env,
231
+ credentials: createCredentials(env, config.provider, registration.descriptor.credentialNames)
232
+ }));
233
+ },
234
+ availability: (env = process.env) => Object.freeze(frozenRegistrations.map((registration) => {
235
+ const credentials = Object.freeze(registration.descriptor.credentialNames.map((name) => Object.freeze({ name, present: Boolean(env[name]?.trim()) })));
236
+ return Object.freeze({
237
+ ...registration.descriptor,
238
+ configured: credentials.length === 0 || credentials.some((credential) => credential.present),
239
+ credentials,
240
+ configuration: providerConfiguration(registration.diagnostics, env)
241
+ });
242
+ })),
243
+ transportFingerprint: (env = process.env) => {
244
+ const transport = frozenRegistrations.map((registration) => {
245
+ const names = [
246
+ registration.diagnostics.endpointEnvironmentVariable,
247
+ ...(registration.diagnostics.presence ?? []).map((entry) => entry.environmentVariable),
248
+ ...(registration.diagnostics.enums ?? []).map((entry) => entry.environmentVariable)
249
+ ].filter((name) => Boolean(name));
250
+ return {
251
+ provider: registration.descriptor.id,
252
+ values: names.map((name) => [name, env[name]?.trim() ?? ""])
253
+ };
254
+ });
255
+ return `sha256:${createHash("sha256").update(JSON.stringify(transport)).digest("hex")}`;
256
+ },
257
+ extend: (additional) => createProviderRegistry([
258
+ ...frozenRegistrations,
259
+ ...additional
260
+ ])
261
+ });
262
+ return registry;
263
+ };
264
+ var optionalQwenRegion = (value) => {
265
+ if (!value) {
266
+ return;
267
+ }
268
+ if (QWEN_REGIONS.includes(value)) {
269
+ return value;
270
+ }
271
+ throw new Error(`Invalid QWEN_REGION: ${value}.`);
272
+ };
273
+ var BUILTIN_PROVIDER_REGISTRATIONS = Object.freeze([
274
+ {
275
+ descriptor: {
276
+ id: "meta",
277
+ name: "Meta Model API",
278
+ defaultModel: "muse-spark-1.2",
279
+ credentialNames: ["MODEL_API_KEY"],
280
+ capabilities: HARNESS_PROVIDER_CAPABILITIES,
281
+ support: "certified"
282
+ },
283
+ diagnostics: { endpointEnvironmentVariable: "META_BASE_URL" },
284
+ factory: ({ model, env, credentials }) => {
285
+ const baseURL = env.META_BASE_URL?.trim();
286
+ return createMeta({
287
+ apiKey: credentials.require(),
288
+ ...baseURL ? { baseURL } : {}
289
+ })(model);
290
+ }
291
+ },
292
+ {
293
+ descriptor: {
294
+ id: "qwen",
295
+ name: "Qwen / Alibaba Cloud Model Studio",
296
+ defaultModel: "qwen3.8-max",
297
+ credentialNames: ["DASHSCOPE_API_KEY", "QWEN_API_KEY"],
298
+ capabilities: HARNESS_PROVIDER_CAPABILITIES,
299
+ support: "certified"
300
+ },
301
+ diagnostics: {
302
+ endpointEnvironmentVariable: "QWEN_BASE_URL",
303
+ presence: [{ key: "workspaceId", environmentVariable: "QWEN_WORKSPACE_ID" }],
304
+ enums: [{
305
+ key: "region",
306
+ environmentVariable: "QWEN_REGION",
307
+ allowedValues: QWEN_REGIONS
308
+ }]
309
+ },
310
+ factory: ({ model, env, credentials }) => {
311
+ const baseURL = env.QWEN_BASE_URL?.trim();
312
+ const workspaceId = env.QWEN_WORKSPACE_ID?.trim();
313
+ const region = optionalQwenRegion(env.QWEN_REGION?.trim());
314
+ return createQwen({
315
+ apiKey: credentials.require(),
316
+ ...baseURL ? { baseURL } : {},
317
+ ...workspaceId ? { workspaceId } : {},
318
+ ...region ? { region } : {}
319
+ })(model);
320
+ }
321
+ },
322
+ {
323
+ descriptor: {
324
+ id: "openai",
325
+ name: "OpenAI",
326
+ defaultModel: "gpt-5.4",
327
+ credentialNames: ["OPENAI_API_KEY"],
328
+ capabilities: HARNESS_PROVIDER_CAPABILITIES,
329
+ support: "certified"
330
+ },
331
+ diagnostics: { endpointEnvironmentVariable: "OPENAI_BASE_URL" },
332
+ factory: ({ model, env, credentials }) => {
333
+ const baseURL = env.OPENAI_BASE_URL?.trim();
334
+ return createOpenAI({
335
+ apiKey: credentials.require(),
336
+ ...baseURL ? { baseURL } : {}
337
+ })(model);
338
+ }
339
+ },
340
+ {
341
+ descriptor: {
342
+ id: "gemini",
343
+ name: "Google Gemini",
344
+ defaultModel: "gemini-3.6-flash",
345
+ credentialNames: ["GEMINI_API_KEY", "GOOGLE_GENERATIVE_AI_API_KEY"],
346
+ capabilities: HARNESS_PROVIDER_CAPABILITIES,
347
+ support: "provisional"
348
+ },
349
+ diagnostics: { endpointEnvironmentVariable: "GEMINI_BASE_URL" },
350
+ factory: ({ model, env, credentials }) => {
351
+ const baseURL = env.GEMINI_BASE_URL?.trim();
352
+ return createGemini({
353
+ apiKey: credentials.require(),
354
+ ...baseURL ? { baseURL } : {}
355
+ })(model);
356
+ }
357
+ }
358
+ ]);
359
+ var DEFAULT_PROVIDER_REGISTRY = createProviderRegistry(BUILTIN_PROVIDER_REGISTRATIONS);
360
+ var PROVIDER_DESCRIPTORS = DEFAULT_PROVIDER_REGISTRY.descriptors;
361
+
362
+ // src/config.ts
17
363
  var DEFAULT_ALLOWED_CHECKS = ["test", "typecheck", "lint", "build"];
18
364
  var HARNESS_CONFIG_SCHEMA_VERSION = 4;
19
365
  var HARNESS_STORE_BACKENDS = ["sqlite", "file"];
@@ -69,45 +415,6 @@ var DEFAULT_SUBAGENT_BUDGET = {
69
415
  maxTotalTokens: 36000,
70
416
  includeChildRuns: false
71
417
  };
72
- var HARNESS_PROVIDER_CAPABILITIES = [
73
- "streaming",
74
- "tool-calling",
75
- "approval-resume"
76
- ];
77
- var PROVIDER_DESCRIPTORS = [
78
- {
79
- id: "meta",
80
- name: "Meta Model API",
81
- defaultModel: "muse-spark-1.2",
82
- credentialNames: ["MODEL_API_KEY"],
83
- capabilities: HARNESS_PROVIDER_CAPABILITIES,
84
- support: "certified"
85
- },
86
- {
87
- id: "qwen",
88
- name: "Qwen / Alibaba Cloud Model Studio",
89
- defaultModel: "qwen3.8-max",
90
- credentialNames: ["DASHSCOPE_API_KEY", "QWEN_API_KEY"],
91
- capabilities: HARNESS_PROVIDER_CAPABILITIES,
92
- support: "certified"
93
- },
94
- {
95
- id: "openai",
96
- name: "OpenAI",
97
- defaultModel: "gpt-5.4",
98
- credentialNames: ["OPENAI_API_KEY"],
99
- capabilities: HARNESS_PROVIDER_CAPABILITIES,
100
- support: "certified"
101
- }
102
- ];
103
- var QWEN_REGIONS = [
104
- "singapore",
105
- "beijing",
106
- "hong-kong",
107
- "tokyo",
108
- "frankfurt",
109
- "virginia"
110
- ];
111
418
  var integerOption = (name, input, envValue, fallback, minimum, maximum) => {
112
419
  const value = input ?? (envValue === undefined ? fallback : Number(envValue));
113
420
  if (!Number.isSafeInteger(value) || value < minimum || value > maximum) {
@@ -136,7 +443,7 @@ var nonNegativeNumberOption = (name, input, envValue) => {
136
443
  }
137
444
  return value;
138
445
  };
139
- var defaultHarnessNamespace = (workspace) => `workspace-${createHash("sha256").update(workspace).digest("hex").slice(0, 16)}`;
446
+ var defaultHarnessNamespace = (workspace) => `workspace-${createHash2("sha256").update(workspace).digest("hex").slice(0, 16)}`;
140
447
  var canonicalStateDirectory = (requestedWorkspace, canonicalWorkspace, configured) => {
141
448
  if (!configured) {
142
449
  return path.join(canonicalWorkspace, ".zhivex-harness", "runs");
@@ -238,26 +545,14 @@ var canonicalWorkspaceFile = (requestedWorkspace, canonicalWorkspace, configured
238
545
  const insideRequestedWorkspace = relative === "" || relative !== ".." && !relative.startsWith(`..${path.sep}`) && !path.isAbsolute(relative);
239
546
  return insideRequestedWorkspace ? path.resolve(canonicalWorkspace, relative) : requestedPath;
240
547
  };
241
- var parseProvider = (value) => {
242
- const normalized = (value ?? "openai").trim().toLowerCase();
243
- if (PROVIDERS.includes(normalized)) {
244
- return normalized;
245
- }
246
- throw new Error(`Unknown provider: ${value}. Use meta, qwen, or openai.`);
247
- };
248
- var providerDescriptor = (provider) => {
249
- const descriptor = PROVIDER_DESCRIPTORS.find((entry) => entry.id === provider);
250
- if (!descriptor) {
251
- throw new Error(`No descriptor is available for provider ${provider}.`);
252
- }
253
- return descriptor;
254
- };
255
- var resolveHarnessConfig = (input = {}) => {
548
+ var parseProvider = (value, registry = DEFAULT_PROVIDER_REGISTRY) => registry.parse(value);
549
+ var providerDescriptor = (provider, registry = DEFAULT_PROVIDER_REGISTRY) => registry.descriptor(provider);
550
+ var resolveHarnessConfig = (input = {}, registry = DEFAULT_PROVIDER_REGISTRY) => {
256
551
  if (input.schemaVersion !== undefined && input.schemaVersion !== HARNESS_CONFIG_SCHEMA_VERSION) {
257
552
  throw new Error(`Unsupported config schema version: ${input.schemaVersion}. Expected ${HARNESS_CONFIG_SCHEMA_VERSION}.`);
258
553
  }
259
- const provider = parseProvider(input.provider ?? process.env.ZHIVEX_HARNESS_PROVIDER);
260
- const descriptor = providerDescriptor(provider);
554
+ const provider = parseProvider(input.provider ?? process.env.ZHIVEX_HARNESS_PROVIDER, registry);
555
+ const descriptor = providerDescriptor(provider, registry);
261
556
  const requestedWorkspace = path.resolve(input.workspace ?? process.cwd());
262
557
  let workspace = requestedWorkspace;
263
558
  try {
@@ -351,59 +646,10 @@ var resolveHarnessConfig = (input = {}) => {
351
646
  ...mcpConfigPath ? { mcpConfigPath } : {}
352
647
  };
353
648
  };
354
- var requiredCredential = (env, provider, names) => {
355
- for (const name of names) {
356
- const value = env[name]?.trim();
357
- if (value) {
358
- return value;
359
- }
360
- }
361
- throw new Error(`Missing credentials for ${provider}. Set ${names.join(" or ")} in the environment.`);
362
- };
363
- var optionalQwenRegion = (value) => {
364
- if (!value) {
365
- return;
366
- }
367
- if (QWEN_REGIONS.includes(value)) {
368
- return value;
369
- }
370
- throw new Error(`Invalid QWEN_REGION: ${value}.`);
371
- };
372
- var createProviderModel = (config, env = process.env) => {
373
- switch (config.provider) {
374
- case "meta": {
375
- const baseURL = env.META_BASE_URL?.trim();
376
- const provider = createMeta({
377
- apiKey: requiredCredential(env, "meta", ["MODEL_API_KEY"]),
378
- ...baseURL ? { baseURL } : {}
379
- });
380
- return provider(config.model);
381
- }
382
- case "qwen": {
383
- const baseURL = env.QWEN_BASE_URL?.trim();
384
- const workspaceId = env.QWEN_WORKSPACE_ID?.trim();
385
- const region = optionalQwenRegion(env.QWEN_REGION?.trim());
386
- const provider = createQwen({
387
- apiKey: requiredCredential(env, "qwen", ["DASHSCOPE_API_KEY", "QWEN_API_KEY"]),
388
- ...baseURL ? { baseURL } : {},
389
- ...workspaceId ? { workspaceId } : {},
390
- ...region ? { region } : {}
391
- });
392
- return provider(config.model);
393
- }
394
- case "openai": {
395
- const baseURL = env.OPENAI_BASE_URL?.trim();
396
- const provider = createOpenAI({
397
- apiKey: requiredCredential(env, "openai", ["OPENAI_API_KEY"]),
398
- ...baseURL ? { baseURL } : {}
399
- });
400
- return provider(config.model);
401
- }
402
- }
403
- };
649
+ var createProviderModel = (config, env = process.env, registry = DEFAULT_PROVIDER_REGISTRY) => registry.createModel(config, env);
404
650
 
405
651
  // src/execution-environment.ts
406
- import { createHash as createHash4, randomUUID as randomUUID2 } from "crypto";
652
+ import { createHash as createHash5, randomUUID as randomUUID2 } from "crypto";
407
653
  import {
408
654
  chmod,
409
655
  lstat as lstat2,
@@ -419,7 +665,7 @@ import path4 from "path";
419
665
  import { createAgentExecutionEnvironmentBinding } from "@zhivex-ai/agents/beta";
420
666
 
421
667
  // src/edit-contracts.ts
422
- import { createHash as createHash2 } from "crypto";
668
+ import { createHash as createHash3 } from "crypto";
423
669
  import path2 from "path";
424
670
  import { z } from "zod";
425
671
  var EDIT_CONTRACT_SCHEMA_VERSION = 1;
@@ -519,7 +765,7 @@ var mutationAuditEntrySchema = z.strictObject({
519
765
  timestamp: z.iso.datetime(),
520
766
  quarantineId: z.string().min(1).max(200).optional()
521
767
  });
522
- var digest = (value) => `sha256:${createHash2("sha256").update(value).digest("hex")}`;
768
+ var digest = (value) => `sha256:${createHash3("sha256").update(value).digest("hex")}`;
523
769
  var canonicalProposalPayload = (changes) => ({
524
770
  schemaVersion: EDIT_CONTRACT_SCHEMA_VERSION,
525
771
  kind: "edit-proposal",
@@ -554,7 +800,7 @@ var editContractDocument = (kind, result) => ({
554
800
  });
555
801
 
556
802
  // src/workspace.ts
557
- import { createHash as createHash3, randomUUID } from "crypto";
803
+ import { createHash as createHash4, randomUUID } from "crypto";
558
804
  import { link, lstat, mkdir, open, readFile, readdir, realpath, rename, stat, unlink } from "fs/promises";
559
805
  import path3 from "path";
560
806
  var HARD_IGNORES = new Set([".git", ".next", ".turbo", ".zhivex-harness", "coverage", "dist", "node_modules"]);
@@ -572,7 +818,7 @@ var isInside = (root, candidate) => {
572
818
  return relative === "" || !relative.startsWith(`..${path3.sep}`) && relative !== ".." && !path3.isAbsolute(relative);
573
819
  };
574
820
  var wirePath = (value) => value.split(path3.sep).join("/");
575
- var digestBytes = (value) => `sha256:${createHash3("sha256").update(value).digest("hex")}`;
821
+ var digestBytes = (value) => `sha256:${createHash4("sha256").update(value).digest("hex")}`;
576
822
  var truncate = (value, maxLength = MAX_TOOL_OUTPUT) => value.length <= maxLength ? value : `${value.slice(0, maxLength)}
577
823
  \u2026 output truncated (${value.length - maxLength} characters omitted)`;
578
824
  var cursorEncode = (value) => Buffer.from(JSON.stringify(value)).toString("base64url");
@@ -1339,8 +1585,8 @@ var BUILT_IN_TOOL_NAMES = new Set([
1339
1585
  "apply_environment_patch",
1340
1586
  "environment_status"
1341
1587
  ]);
1342
- var digest2 = (value) => `sha256:${createHash4("sha256").update(value).digest("hex")}`;
1343
- var runHash = (runId) => createHash4("sha256").update(runId).digest("hex").slice(0, 24);
1588
+ var digest2 = (value) => `sha256:${createHash5("sha256").update(value).digest("hex")}`;
1589
+ var runHash = (runId) => createHash5("sha256").update(runId).digest("hex").slice(0, 24);
1344
1590
  var isInside2 = (root, candidate) => {
1345
1591
  const relative = path4.relative(root, candidate);
1346
1592
  return relative === "" || relative !== ".." && !relative.startsWith(`..${path4.sep}`) && !path4.isAbsolute(relative);
@@ -2308,7 +2554,7 @@ var executionFingerprintInput = (execution, environment) => execution.backend ==
2308
2554
  };
2309
2555
 
2310
2556
  // src/harness.ts
2311
- import { createHash as createHash6 } from "crypto";
2557
+ import { createHash as createHash7 } from "crypto";
2312
2558
  import {
2313
2559
  Agent,
2314
2560
  applySafetyPolicyToAgent as applySafetyPolicyToAgent2,
@@ -3052,7 +3298,7 @@ var createHarnessMcpTools = async (configuration, options = {}) => {
3052
3298
  var mcpConfigurationFingerprintInput = (configuration) => serializeJsonValue(configuration);
3053
3299
 
3054
3300
  // src/orchestration.ts
3055
- import { createHash as createHash5, randomUUID as randomUUID3 } from "crypto";
3301
+ import { createHash as createHash6, randomUUID as randomUUID3 } from "crypto";
3056
3302
  import {
3057
3303
  applySafetyPolicyToAgent,
3058
3304
  createBudgetGuard,
@@ -3099,7 +3345,7 @@ var childHarnessBinding = (parent, profile, model, toolNames, config) => ({
3099
3345
  schemaVersion: 1,
3100
3346
  id: `${parent.id}-${profile}`,
3101
3347
  version: parent.version,
3102
- fingerprint: `sha256:${createHash5("sha256").update(JSON.stringify({
3348
+ fingerprint: `sha256:${createHash6("sha256").update(JSON.stringify({
3103
3349
  parent: parent.fingerprint,
3104
3350
  profile,
3105
3351
  model: {
@@ -3184,11 +3430,11 @@ var createHarnessSubagents = (options) => {
3184
3430
  // src/harness.ts
3185
3431
  var APPROVAL_VERSION = "2026-08-17-v5";
3186
3432
  var TOOL_CONTRACT_VERSION = "enforced-execution-v1";
3187
- var createHarnessBinding = (config, mcpConfiguration, model, subagentModels, executionEnvironment) => ({
3433
+ var createHarnessBinding = (config, mcpConfiguration, model, subagentModels, providerTransportFingerprint, executionEnvironment) => ({
3188
3434
  schemaVersion: 1,
3189
3435
  id: "zhivex-harness",
3190
3436
  version: HARNESS_VERSION,
3191
- fingerprint: `sha256:${createHash6("sha256").update(JSON.stringify({
3437
+ fingerprint: `sha256:${createHash7("sha256").update(JSON.stringify({
3192
3438
  configSchemaVersion: HARNESS_CONFIG_SCHEMA_VERSION,
3193
3439
  approvalVersion: APPROVAL_VERSION,
3194
3440
  toolContractVersion: TOOL_CONTRACT_VERSION,
@@ -3196,6 +3442,7 @@ var createHarnessBinding = (config, mcpConfiguration, model, subagentModels, exe
3196
3442
  provider: config.provider,
3197
3443
  model: config.model,
3198
3444
  runtimeModel: inspectHarnessModelCapabilities(model),
3445
+ providerTransportFingerprint,
3199
3446
  subagentModels: Object.fromEntries(config.orchestration.profiles.map((profile) => [
3200
3447
  profile,
3201
3448
  inspectHarnessModelCapabilities(subagentModels?.[profile] ?? model)
@@ -3418,32 +3665,35 @@ var createExecutionEnvironmentTools = (workspace) => ({
3418
3665
  })
3419
3666
  });
3420
3667
  var estimateMessageTokens = (messages) => Math.max(1, Math.ceil(JSON.stringify(messages).length / 4));
3421
- var createHarnessCompactor = () => {
3668
+ var summarizeHarnessMessages = (messages) => {
3422
3669
  const redaction = createRedactionPolicy2({ includeEmails: true });
3423
- return async ({ messages }) => {
3424
- const summaries = messages.map((message, index) => {
3425
- const record = message;
3426
- const parts = (record.parts ?? []).map((part) => {
3427
- if (part.type === "text" && typeof part.text === "string") {
3428
- const text = redaction.redactText(part.text).replace(/\s+/g, " ").trim();
3429
- return text.length > 160 ? `${text.slice(0, 160)}\u2026` : text;
3430
- }
3431
- if (part.type === "tool-call") {
3432
- const call = part.toolCall;
3433
- return `tool-call:${typeof call?.name === "string" ? call.name : "unknown"}`;
3434
- }
3435
- if (part.type === "tool-result") {
3436
- const result = part.toolResult;
3437
- return `tool-result:${typeof result?.toolName === "string" ? result.toolName : "unknown"}`;
3438
- }
3439
- return typeof part.type === "string" ? part.type : "part";
3440
- });
3441
- return `${index + 1}. ${record.role ?? "message"}: ${parts.join(" | ")}`;
3670
+ const summaries = messages.map((message, index) => {
3671
+ const record = message;
3672
+ const parts = (record.parts ?? []).map((part) => {
3673
+ if (part.type === "text" && typeof part.text === "string") {
3674
+ const text = redaction.redactText(part.text).replace(/\bBearer\s+\S+/gi, "Bearer [REDACTED]").replace(/\b([A-Z][A-Z0-9_]*(?:KEY|TOKEN|SECRET|PASSWORD)|api[_-]?key|access[_-]?token|password)\s*([=:])\s*(?:"[^"]*"|'[^']*'|\S+)/gi, "$1$2[REDACTED]").replace(/\b(?:sk|ghp|gho|github_pat)-[A-Za-z0-9_-]{8,}\b/g, "[REDACTED]").replace(/\s+/g, " ").trim();
3675
+ return text.length > 160 ? `${text.slice(0, 160)}\u2026` : text;
3676
+ }
3677
+ if (part.type === "tool-call") {
3678
+ const call = part.toolCall;
3679
+ return `tool-call:${typeof call?.name === "string" ? call.name : "unknown"}`;
3680
+ }
3681
+ if (part.type === "tool-result") {
3682
+ const result = part.toolResult;
3683
+ return `tool-result:${typeof result?.toolName === "string" ? result.toolName : "unknown"}`;
3684
+ }
3685
+ return typeof part.type === "string" ? part.type : "part";
3442
3686
  });
3443
- const summary = summaries.join(`
3687
+ return `${index + 1}. ${record.role ?? "message"}: ${parts.join(" | ")}`;
3688
+ });
3689
+ const summary = summaries.join(`
3444
3690
  `);
3691
+ return summary.length > 4000 ? `${summary.slice(0, 4000)}\u2026` : summary;
3692
+ };
3693
+ var createHarnessCompactor = () => {
3694
+ return async ({ messages }) => {
3445
3695
  return {
3446
- summary: summary.length > 4000 ? `${summary.slice(0, 4000)}\u2026` : summary,
3696
+ summary: summarizeHarnessMessages(messages),
3447
3697
  metadata: {
3448
3698
  strategy: "deterministic-redacted-transcript",
3449
3699
  sourceMessages: messages.length
@@ -3506,7 +3756,7 @@ var createProviderCompatibleBudget = (config) => {
3506
3756
  };
3507
3757
  };
3508
3758
  var createHarness = async (options = {}) => {
3509
- const config = resolveHarnessConfig(options);
3759
+ const config = resolveHarnessConfig(options, options.providerRegistry);
3510
3760
  const workspace = await Workspace.open(config.workspace);
3511
3761
  await validateStateDirectory(config.workspace, config.stateDirectory);
3512
3762
  const executionEnvironment = config.execution.backend === "oci" ? await createHarnessOciExecutionEnvironment({
@@ -3515,7 +3765,7 @@ var createHarness = async (options = {}) => {
3515
3765
  stateDirectory: config.stateDirectory,
3516
3766
  ...options.ociRuntimeAdapter ? { runtime: options.ociRuntimeAdapter } : {}
3517
3767
  }) : undefined;
3518
- const model = options.modelInstance ?? createProviderModel(config, options.env ?? process.env);
3768
+ const model = options.modelInstance ?? createProviderModel(config, options.env ?? process.env, options.providerRegistry);
3519
3769
  const capabilityRequirements = [...new Set([
3520
3770
  ...config.requiredCapabilities,
3521
3771
  ...config.orchestration.profiles.length > 0 || config.mcpConfigPath || options.mcpConfiguration ? ["tools", "streaming"] : []
@@ -3557,7 +3807,7 @@ var createHarness = async (options = {}) => {
3557
3807
  await options.onTelemetryEvent?.(event);
3558
3808
  };
3559
3809
  const costGuardrails = createCostGuardrails(config);
3560
- const binding = createHarnessBinding(config, mcpConfiguration, model, options.subagentModels, executionEnvironment);
3810
+ const binding = createHarnessBinding(config, mcpConfiguration, model, options.subagentModels, (options.providerRegistry ?? DEFAULT_PROVIDER_REGISTRY).transportFingerprint(options.env ?? process.env), executionEnvironment);
3561
3811
  const subagentRuntime = createHarnessSubagents({
3562
3812
  config,
3563
3813
  parentBinding: binding,