@zhivex-ai/harness 1.3.0-rc.3 → 1.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +53 -0
- package/README.md +12 -10
- package/SECURITY.md +1 -1
- package/SUPPORT.md +4 -4
- package/contracts/engine-api.json +334 -0
- package/contracts/public-api.json +267 -1
- package/contracts/stable-api-signatures.json +43 -43
- package/dist/acp-cli.js +54 -18
- package/dist/approvals/approval-history.d.ts +22 -0
- package/dist/approvals/explicit-review.d.ts +24 -0
- package/dist/approvals/host-policy-identity.d.ts +3 -0
- package/dist/cli/arguments.d.ts +6 -2
- package/dist/cli/checkpoints.d.ts +230 -0
- package/dist/cli/cli-profiles.d.ts +4 -2
- package/dist/cli/governance-report.d.ts +5 -0
- package/dist/cli/policy-decisions.d.ts +9 -0
- package/dist/cli/policy.d.ts +5 -0
- package/dist/cli/presentation.d.ts +3 -1
- package/dist/cli/terminal/terminal-ui.d.ts +4 -0
- package/dist/{cli-entry-xmf48p6a.js → cli-entry-1gfg3brj.js} +14921 -10692
- package/dist/cli-entry-bx3vjw7h.js +656 -0
- package/dist/{index-fvca1xea.js → cli-entry-d5788aay.js} +339 -58
- package/dist/{cli-qgwvtk0w.js → cli-etsmtst3.js} +918 -2222
- package/dist/cli.js +3 -5
- package/dist/client/acp-mcp-admission.d.ts +32 -0
- package/dist/client/acp-mcp-host.d.ts +19 -0
- package/dist/client/acp-mcp-session.d.ts +14 -0
- package/dist/client/acp-stdio.d.ts +2 -0
- package/dist/client/acp.d.ts +4 -1
- package/dist/client/adapter.d.ts +13 -1
- package/dist/client/json-contracts.d.ts +107 -4
- package/dist/client/local-service.d.ts +2 -0
- package/dist/client/protocol.d.ts +127 -1
- package/dist/client/service-events.d.ts +4 -0
- package/dist/compat/cli-options.d.ts +13 -1
- package/dist/compat/code-support.js +23 -87
- package/dist/{config-q32jm1e6.js → config-c002f06f.js} +1 -1
- package/dist/{config-6gtpxvjv.js → config-j3jga5wh.js} +3 -1
- package/dist/context/adaptive-compaction.d.ts +1 -0
- package/dist/context/compaction.d.ts +1 -1
- package/dist/context/request-measurements.d.ts +17 -0
- package/dist/context/request-projection.d.ts +10 -0
- package/dist/context/task-memory.d.ts +1 -0
- package/dist/engine/acp.d.ts +2 -0
- package/dist/engine/acp.js +197 -1
- package/dist/engine/client.js +11 -4
- package/dist/engine/desktop-providers-v1.d.ts +4 -0
- package/dist/engine/desktop-providers-v1.js +18 -0
- package/dist/engine/desktop-state-v1.d.ts +10 -0
- package/dist/engine/desktop-state-v1.js +168 -0
- package/dist/engine/index.d.ts +12 -0
- package/dist/engine/index.js +571 -71
- package/dist/engine/mcp-stdio-v1.d.ts +11 -0
- package/dist/engine/mcp-stdio-v1.js +108 -0
- package/dist/engine/models.d.ts +3 -0
- package/dist/engine/models.js +894 -0
- package/dist/engine/protocol.d.ts +1 -0
- package/dist/engine/protocol.js +24 -0
- package/dist/engine/service.js +12 -5
- package/dist/execution/acceptance-snapshot.d.ts +2 -0
- package/dist/execution/execution-environment.d.ts +10 -0
- package/dist/execution/mcp-oci-channel.d.ts +11 -0
- package/dist/execution/mcp-oci-server.d.ts +38 -0
- package/dist/execution/mcp-oci-workspace.d.ts +23 -0
- package/dist/execution/mcp-resource-recovery.d.ts +19 -0
- package/dist/execution/mcp-workspace-snapshot.d.ts +20 -0
- package/dist/hostile-repository-demo.js +3169 -1163
- package/dist/{index-f4sb0e2q.js → index-2jrdcj6b.js} +17 -2
- package/dist/{index-77h9qr5h.js → index-3ah1f369.js} +40 -10
- package/dist/{index-pgqz45fj.js → index-42gp2hy8.js} +197 -1091
- package/dist/{index-41fkzt91.js → index-4jw3tvy8.js} +10 -2
- package/dist/index-6m08wvab.js +1768 -0
- package/dist/index-8705zxpr.js +145 -0
- package/dist/{index-d0wrghff.js → index-8vm2m34s.js} +225 -1416
- package/dist/index-8zzhggxv.js +477 -0
- package/dist/index-a97bezbz.js +1073 -0
- package/dist/index-azmwjp95.js +1004 -0
- package/dist/{cli-entry-0mmeag20.js → index-gq9xagx2.js} +122 -836
- package/dist/index-h0mqx2ed.js +1373 -0
- package/dist/index-hnaxfpb5.js +5589 -0
- package/dist/{index-2aymdsqc.js → index-qfpz5y2v.js} +24 -0
- package/dist/{index-kfgt9yqq.js → index-w2sj0wkw.js} +33 -10
- package/dist/index-wg1sd3at.js +80 -0
- package/dist/index-xqxeypt5.js +888 -0
- package/dist/index-yb239ghk.js +961 -0
- package/dist/index-z0qxmkm2.js +3389 -0
- package/dist/index.js +85 -72
- package/dist/integrations/mcp-host-session.d.ts +26 -0
- package/dist/integrations/mcp-stdio-admission.d.ts +54 -0
- package/dist/integrations/mcp-stdio-client.d.ts +44 -0
- package/dist/integrations/mcp-stdio-framing.d.ts +18 -0
- package/dist/integrations/mcp-stdio-launch.d.ts +20 -0
- package/dist/integrations/mcp-stdio-session.d.ts +7 -0
- package/dist/integrations/mcp-stdio-tools.d.ts +12 -0
- package/dist/internal/desktop/catalog.d.ts +2 -0
- package/dist/internal/desktop/persistence.d.ts +2 -3
- package/dist/internal/desktop/providers.d.ts +1 -0
- package/dist/models/catalog.d.ts +2 -0
- package/dist/persistence/governance-context.d.ts +126 -0
- package/dist/persistence/governance-report.d.ts +299 -0
- package/dist/persistence/host-database-backup.d.ts +28 -0
- package/dist/persistence/mcp-execution-journal.d.ts +19 -0
- package/dist/persistence/mcp-reconciliation.d.ts +33 -0
- package/dist/persistence/mcp-resource-journal.d.ts +54 -0
- package/dist/persistence/workspace-checkpoints.d.ts +138 -0
- package/dist/providers/anthropic-continuation.d.ts +5 -0
- package/dist/providers/providers.d.ts +1 -1
- package/dist/providers/vertex-auth.d.ts +27 -0
- package/dist/runtime/delegation-contracts.d.ts +9 -0
- package/dist/runtime/delegation-correction.d.ts +9 -0
- package/dist/runtime/delegation-result.d.ts +73 -0
- package/dist/runtime/error-diagnostics.d.ts +86 -0
- package/dist/runtime/harness.d.ts +11 -1
- package/dist/runtime/policy-decisions.d.ts +66 -0
- package/dist/runtime/policy-inspection.d.ts +52 -0
- package/dist/runtime/provider-diagnostics.d.ts +1 -0
- package/dist/runtime/runtime-instructions.d.ts +8 -0
- package/dist/runtime/task-acceptance-checks.d.ts +103 -0
- package/dist/runtime/task-acceptance-delivery.d.ts +107 -0
- package/dist/runtime/task-acceptance-host.d.ts +20 -0
- package/dist/runtime/task-acceptance-record.d.ts +107 -0
- package/dist/runtime/task-acceptance-validation.d.ts +25 -0
- package/dist/runtime/task-acceptance.d.ts +47 -0
- package/dist/runtime/time-to-safe-fix.d.ts +83 -0
- package/dist/runtime/tool-policy-file.d.ts +23 -0
- package/dist/runtime/tool-policy-paths.d.ts +5 -0
- package/dist/runtime/tool-policy.d.ts +6 -0
- package/dist/service-cli.js +14 -7
- package/dist/{service-client-cli-gs78wrxe.js → service-client-cli-3365rfav.js} +307 -248
- package/dist/verify-historical-migrations.js +3134 -1129
- package/dist/workspace/path-policy.d.ts +4 -0
- package/dist/zhx.js +3 -5
- package/docs/ACP.md +14 -2
- package/docs/ANTHROPIC.md +33 -0
- package/docs/CLI.md +132 -0
- package/docs/CLIENT_PROTOCOL.md +45 -0
- package/docs/CODE_RELEASE.md +35 -18
- package/docs/ENGINE_API.md +216 -7
- package/docs/EXTENSIBILITY.md +46 -3
- package/docs/FIRST_USE.md +6 -6
- package/docs/LOCAL_SERVICE.md +13 -0
- package/docs/MCP_STDIO.md +20 -0
- package/docs/README.md +1 -0
- package/docs/STABILITY.md +4 -2
- package/docs/SUPPORT_MATRIX.md +1 -1
- package/docs/TOOL_POLICY.md +81 -0
- package/docs/VERTEX.md +50 -0
- package/docs/adr/0002-isolated-mcp-stdio.md +135 -0
- package/docs/fixtures/mcp-stdio-contract-v1.json +189 -0
- package/docs/support-matrix.json +2 -0
- package/evaluations/representative-assembly-matrix.json +46 -1
- package/evaluations/task-acceptance-routes.json +7 -0
- package/examples/README.md +3 -3
- package/package.json +43 -12
- package/dist/cli-entry-64pdp3k5.js +0 -17
- package/dist/cli-entry-7h9savv5.js +0 -375
- package/dist/index-5wjwe91x.js +0 -9434
package/dist/engine/index.js
CHANGED
|
@@ -2,8 +2,6 @@ import {
|
|
|
2
2
|
CHANGE_ENVELOPE_DIGEST_ALGORITHM,
|
|
3
3
|
CHANGE_ENVELOPE_SCHEMA_VERSION,
|
|
4
4
|
DEFAULT_TIME_TO_SAFE_FIX_GOAL,
|
|
5
|
-
HARNESS_STATE_BACKUP_MAX_BYTES,
|
|
6
|
-
HARNESS_STATE_BACKUP_SCHEMA_VERSION,
|
|
7
5
|
MAX_CHANGE_ENVELOPE_APPROVALS,
|
|
8
6
|
MAX_CHANGE_ENVELOPE_APPROVAL_SCOPES,
|
|
9
7
|
MAX_CHANGE_ENVELOPE_ATTESTATIONS,
|
|
@@ -51,28 +49,31 @@ import {
|
|
|
51
49
|
computeChangeEnvelopeDigest,
|
|
52
50
|
computeChangeEnvelopeEvidenceDigest,
|
|
53
51
|
createChangeEnvelope,
|
|
54
|
-
createHarnessStateBackup,
|
|
55
52
|
createTimeToSafeFixCases,
|
|
56
53
|
createTimeToSafeFixReport,
|
|
57
54
|
createTimeToSafeFixSample,
|
|
58
55
|
digestChangeEnvelopeArtifact,
|
|
59
|
-
exportHarnessStateBackup,
|
|
60
56
|
externalAttestationReferenceSchema,
|
|
61
|
-
importHarnessStateBackup,
|
|
62
|
-
importHarnessStateBackupFile,
|
|
63
57
|
injectTimeToSafeFixAttack,
|
|
64
|
-
inspectHarnessState,
|
|
65
|
-
openWorkspaceCheckpointStore,
|
|
66
58
|
parseCliJsonDocument,
|
|
67
59
|
parseCliJsonLineDocument,
|
|
68
|
-
readHarnessStateBackup,
|
|
69
60
|
recommendCompactionModels,
|
|
70
|
-
stateBackupBundleSchema,
|
|
71
61
|
timeToSafeFixDriverResultSchema,
|
|
72
62
|
timeToSafeFixLatencyStatistics,
|
|
73
63
|
timeToSafeFixTaskSchema,
|
|
74
64
|
verifyChangeEnvelope
|
|
75
|
-
} from "../index-
|
|
65
|
+
} from "../index-8vm2m34s.js";
|
|
66
|
+
import {
|
|
67
|
+
HARNESS_STATE_BACKUP_MAX_BYTES,
|
|
68
|
+
HARNESS_STATE_BACKUP_SCHEMA_VERSION,
|
|
69
|
+
createHarnessStateBackup,
|
|
70
|
+
exportHarnessStateBackup,
|
|
71
|
+
importHarnessStateBackup,
|
|
72
|
+
importHarnessStateBackupFile,
|
|
73
|
+
inspectHarnessState,
|
|
74
|
+
readHarnessStateBackup,
|
|
75
|
+
stateBackupBundleSchema
|
|
76
|
+
} from "../index-a97bezbz.js";
|
|
76
77
|
import {
|
|
77
78
|
CLI_COMMAND_OPTION_CONTRACTS,
|
|
78
79
|
CLI_OPTION_DEFINITIONS,
|
|
@@ -82,7 +83,7 @@ import {
|
|
|
82
83
|
resolveHarnessModelRoutes,
|
|
83
84
|
serializeHarnessModelRoutes,
|
|
84
85
|
validateCliCommandOptions
|
|
85
|
-
} from "../index-
|
|
86
|
+
} from "../index-2jrdcj6b.js";
|
|
86
87
|
import {
|
|
87
88
|
harnessLocalCredentialsSchema,
|
|
88
89
|
openHarnessActivityStore,
|
|
@@ -90,108 +91,136 @@ import {
|
|
|
90
91
|
recoverHarnessLocalService,
|
|
91
92
|
requestHarnessLocalService,
|
|
92
93
|
startHarnessLocalService
|
|
93
|
-
} from "../index-
|
|
94
|
+
} from "../index-w2sj0wkw.js";
|
|
94
95
|
import {
|
|
95
|
-
|
|
96
|
-
|
|
96
|
+
createAcpConnection,
|
|
97
|
+
serveAcpStdio
|
|
98
|
+
} from "../index-3ah1f369.js";
|
|
99
|
+
import {
|
|
100
|
+
APPROVAL_HISTORY_KEY,
|
|
97
101
|
DEFAULT_HARNESS_CONTEXT_MANIFEST,
|
|
98
102
|
DEFAULT_HARNESS_PROJECT_INSTRUCTIONS,
|
|
99
|
-
EDIT_CONTRACT_SCHEMA_VERSION,
|
|
100
|
-
EDIT_DIGEST_ALGORITHM,
|
|
101
103
|
HARNESS_CONTEXT_BUNDLE_SCHEMA_VERSION,
|
|
102
104
|
HARNESS_CONTEXT_CONFIG_SCHEMA_VERSION,
|
|
103
|
-
HARNESS_EXECUTION_ARTIFACT_SCHEMA_VERSION,
|
|
104
105
|
HARNESS_INSTRUCTIONS,
|
|
105
106
|
HARNESS_LIFECYCLE_EVENTS,
|
|
106
|
-
HARNESS_MCP_CONFIG_SCHEMA_VERSION,
|
|
107
|
-
HARNESS_MCP_PERMISSIONS,
|
|
108
|
-
HARNESS_OCI_LABEL,
|
|
109
|
-
HARNESS_OCI_LABEL_VALUE,
|
|
110
|
-
HARNESS_OPERATIONS_SCHEMA_VERSION,
|
|
111
|
-
HARNESS_SQLITE_FILE,
|
|
112
107
|
HARNESS_SUBAGENT_PROFILE_DESCRIPTORS,
|
|
113
|
-
HARNESS_VERSION,
|
|
114
|
-
MAX_EDIT_CHANGES,
|
|
115
|
-
MAX_EDIT_FILE_BYTES,
|
|
116
|
-
MAX_EDIT_PROPOSAL_BYTES,
|
|
117
108
|
MAX_HARNESS_CONTEXT_FILES,
|
|
118
109
|
MAX_HARNESS_CONTEXT_FILE_BYTES,
|
|
119
110
|
MAX_HARNESS_CONTEXT_TOTAL_BYTES,
|
|
120
111
|
MAX_HARNESS_SKILLS,
|
|
121
112
|
MAX_HARNESS_SKILL_DIRECTORIES,
|
|
122
113
|
MAX_HARNESS_SKILL_FILE_BYTES,
|
|
123
|
-
NODE_ENGINE_RANGE,
|
|
124
114
|
SEMANTIC_COMPACTION_VERSION,
|
|
125
|
-
TERMINAL_RUN_STATUSES,
|
|
126
|
-
Workspace,
|
|
127
115
|
appendUserMessage,
|
|
128
|
-
applyEditProposalInputSchema,
|
|
129
116
|
applyHarnessToolPolicy,
|
|
117
|
+
approvalDecisionViews,
|
|
130
118
|
assertHarnessModelCapabilities,
|
|
131
|
-
cancelHarnessRun,
|
|
132
|
-
cleanupHarnessExecutionArtifacts,
|
|
133
|
-
cleanupHarnessRuns,
|
|
134
119
|
compactHarnessMessages,
|
|
135
|
-
createEditProposal,
|
|
136
120
|
createEmptyHarnessContextBundle,
|
|
137
121
|
createExecutionEnvironmentTools,
|
|
138
122
|
createHarness,
|
|
139
123
|
createHarnessClientAdapter,
|
|
140
124
|
createHarnessLifecycleDispatcher,
|
|
141
|
-
createHarnessMcpTools,
|
|
142
|
-
createHarnessOciExecutionEnvironment,
|
|
143
125
|
createHarnessSubagents,
|
|
144
126
|
createHarnessToolPolicy,
|
|
145
|
-
createHttpMcpClient,
|
|
146
127
|
createProgressMonitor,
|
|
147
128
|
createSemanticCompactor,
|
|
148
|
-
describeOciCommand,
|
|
149
|
-
editChangeSchema,
|
|
150
|
-
editChangesSchema,
|
|
151
|
-
editContractDocument,
|
|
152
|
-
editProposalChangeSchema,
|
|
153
|
-
editProposalInputSchema,
|
|
154
|
-
editProposalSchema,
|
|
155
129
|
estimateMessageTokens,
|
|
156
|
-
executionFingerprintInput,
|
|
157
|
-
fileDigestSchema,
|
|
158
130
|
harnessContextConfigurationSchema,
|
|
159
131
|
harnessContextFingerprintInput,
|
|
160
|
-
harnessExecutionSession,
|
|
161
132
|
harnessLifecycleFingerprintInput,
|
|
133
|
+
harnessPolicyDecisionEventSchema,
|
|
162
134
|
harnessSkillLoadInputSchema,
|
|
163
135
|
harnessToolPolicySchema,
|
|
164
136
|
inspectHarnessModelCapabilities,
|
|
165
|
-
|
|
137
|
+
inspectHarnessPolicy,
|
|
138
|
+
inspectHarnessTaskAcceptance,
|
|
166
139
|
isHarnessContextDigest,
|
|
167
|
-
listHarnessRuns,
|
|
168
|
-
loadHarnessMcpConfiguration,
|
|
169
140
|
loadHarnessProjectContext,
|
|
170
141
|
loadHarnessSkill,
|
|
171
|
-
migrateLegacyFileRuns,
|
|
172
|
-
moveFileInputSchema,
|
|
173
|
-
mutationAuditEntrySchema,
|
|
174
|
-
mutationOperationSchema,
|
|
175
|
-
normalizeHarnessMcpConfiguration,
|
|
176
|
-
openHarnessPersistence,
|
|
177
|
-
quarantineFileInputSchema,
|
|
178
142
|
renderHarnessContextInstructions,
|
|
179
|
-
|
|
143
|
+
reviseHarnessTaskAcceptance,
|
|
180
144
|
runHarness,
|
|
181
145
|
runHarnessReviewGroup,
|
|
182
|
-
selectHarnessModel
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
146
|
+
selectHarnessModel
|
|
147
|
+
} from "../index-hnaxfpb5.js";
|
|
148
|
+
import {
|
|
149
|
+
HARNESS_OPERATIONS_SCHEMA_VERSION,
|
|
150
|
+
HARNESS_SQLITE_FILE,
|
|
151
|
+
TERMINAL_RUN_STATUSES,
|
|
152
|
+
cancelHarnessRun,
|
|
153
|
+
cleanupHarnessRuns,
|
|
154
|
+
inspectHarnessRun,
|
|
155
|
+
listHarnessRuns,
|
|
156
|
+
migrateLegacyFileRuns,
|
|
157
|
+
openHarnessPersistence,
|
|
158
|
+
openWorkspaceCheckpointStore
|
|
159
|
+
} from "../index-h0mqx2ed.js";
|
|
160
|
+
import"../index-8zzhggxv.js";
|
|
186
161
|
import {
|
|
187
162
|
HARNESS_SESSION_INDEX_FILE,
|
|
188
163
|
HARNESS_SESSION_SCHEMA_VERSION,
|
|
189
164
|
SESSION_RUN_STATUSES,
|
|
165
|
+
TASK_ACCEPTANCE_EVIDENCE_KEY,
|
|
190
166
|
TERMINAL_SESSION_RUN_STATUSES,
|
|
167
|
+
USAGE_LEDGER_KEY,
|
|
168
|
+
compileTaskAcceptanceContract,
|
|
169
|
+
inspectRuntimeManifest,
|
|
170
|
+
inspectUsageLedger,
|
|
191
171
|
openCliSessionStore,
|
|
192
172
|
openSessionStore,
|
|
173
|
+
readTaskAcceptanceLedger,
|
|
174
|
+
taskAcceptanceContractSchema,
|
|
193
175
|
validateStateDirectory
|
|
194
|
-
} from "../index-
|
|
176
|
+
} from "../index-42gp2hy8.js";
|
|
177
|
+
import {
|
|
178
|
+
BUN_ENGINE_RANGE,
|
|
179
|
+
HARNESS_MCP_CONFIG_SCHEMA_VERSION,
|
|
180
|
+
HARNESS_MCP_PERMISSIONS,
|
|
181
|
+
HARNESS_VERSION,
|
|
182
|
+
NODE_ENGINE_RANGE,
|
|
183
|
+
createHarnessMcpTools,
|
|
184
|
+
createHttpMcpClient,
|
|
185
|
+
loadHarnessMcpConfiguration,
|
|
186
|
+
normalizeHarnessMcpConfiguration
|
|
187
|
+
} from "../index-azmwjp95.js";
|
|
188
|
+
import {
|
|
189
|
+
CliOciRuntimeAdapter,
|
|
190
|
+
HARNESS_EXECUTION_ARTIFACT_SCHEMA_VERSION,
|
|
191
|
+
HARNESS_OCI_LABEL,
|
|
192
|
+
HARNESS_OCI_LABEL_VALUE,
|
|
193
|
+
Workspace,
|
|
194
|
+
cleanupHarnessExecutionArtifacts,
|
|
195
|
+
createHarnessOciExecutionEnvironment,
|
|
196
|
+
describeOciCommand,
|
|
197
|
+
executionFingerprintInput,
|
|
198
|
+
harnessExecutionSession
|
|
199
|
+
} from "../index-z0qxmkm2.js";
|
|
200
|
+
import {
|
|
201
|
+
EDIT_CONTRACT_SCHEMA_VERSION,
|
|
202
|
+
EDIT_DIGEST_ALGORITHM,
|
|
203
|
+
MAX_EDIT_CHANGES,
|
|
204
|
+
MAX_EDIT_FILE_BYTES,
|
|
205
|
+
MAX_EDIT_PROPOSAL_BYTES,
|
|
206
|
+
applyEditProposalInputSchema,
|
|
207
|
+
createEditProposal,
|
|
208
|
+
editChangeSchema,
|
|
209
|
+
editChangesSchema,
|
|
210
|
+
editContractDocument,
|
|
211
|
+
editProposalChangeSchema,
|
|
212
|
+
editProposalInputSchema,
|
|
213
|
+
editProposalSchema,
|
|
214
|
+
fileDigestSchema,
|
|
215
|
+
moveFileInputSchema,
|
|
216
|
+
mutationAuditEntrySchema,
|
|
217
|
+
mutationOperationSchema,
|
|
218
|
+
quarantineFileInputSchema,
|
|
219
|
+
restoreFileInputSchema,
|
|
220
|
+
taskCheckReceiptSchema,
|
|
221
|
+
validateEditProposal,
|
|
222
|
+
workspaceFilePathSchema
|
|
223
|
+
} from "../index-yb239ghk.js";
|
|
195
224
|
import {
|
|
196
225
|
BUILTIN_PROVIDER_REGISTRATIONS,
|
|
197
226
|
DEFAULT_ALLOWED_CHECKS,
|
|
@@ -227,7 +256,9 @@ import {
|
|
|
227
256
|
providerAvailability,
|
|
228
257
|
providerDescriptor,
|
|
229
258
|
resolveHarnessConfig
|
|
230
|
-
} from "../index-
|
|
259
|
+
} from "../index-gq9xagx2.js";
|
|
260
|
+
import"../index-8705zxpr.js";
|
|
261
|
+
import"../index-xqxeypt5.js";
|
|
231
262
|
import {
|
|
232
263
|
CLI_EVENT_SCHEMA_VERSION,
|
|
233
264
|
CLI_JSON_SCHEMA_VERSION,
|
|
@@ -238,12 +269,473 @@ import {
|
|
|
238
269
|
serializeStreamResult,
|
|
239
270
|
streamEventDocument,
|
|
240
271
|
streamResultDocument
|
|
241
|
-
} from "../index-
|
|
242
|
-
import {
|
|
243
|
-
createAcpConnection,
|
|
244
|
-
serveAcpStdio
|
|
245
|
-
} from "../index-77h9qr5h.js";
|
|
272
|
+
} from "../index-qfpz5y2v.js";
|
|
246
273
|
import"../index-1bx83sw4.js";
|
|
274
|
+
// src/persistence/governance-report.ts
|
|
275
|
+
import { createHash as createHash2 } from "node:crypto";
|
|
276
|
+
import { z as z2 } from "zod";
|
|
277
|
+
|
|
278
|
+
// src/persistence/governance-context.ts
|
|
279
|
+
import { createHash } from "node:crypto";
|
|
280
|
+
import { z } from "zod";
|
|
281
|
+
var digest = z.string().regex(/^sha256:[a-f0-9]{64}$/);
|
|
282
|
+
var count = z.number().int().nonnegative().safe();
|
|
283
|
+
var governanceReference = (kind, value) => "sha256:" + createHash("sha256").update(JSON.stringify([kind, value])).digest("hex");
|
|
284
|
+
var governanceSessionSchema = z.strictObject({ availability: z.enum(["recorded", "unavailable"]), reference: digest.nullable(), revision: count.nullable() });
|
|
285
|
+
var governanceHistorySchema = z.strictObject({
|
|
286
|
+
availability: z.enum(["recorded", "unavailable"]),
|
|
287
|
+
retention: z.enum(["unknown", "retained", "expired"]),
|
|
288
|
+
incomplete: z.boolean(),
|
|
289
|
+
policyDecisions: z.array(z.strictObject({
|
|
290
|
+
runReference: digest,
|
|
291
|
+
sequence: count,
|
|
292
|
+
toolReference: digest,
|
|
293
|
+
phase: z.enum(["approval-request", "tool-entry"]),
|
|
294
|
+
decision: z.enum(["allow", "ask_user", "deny"]),
|
|
295
|
+
policyDigest: digest.nullable(),
|
|
296
|
+
source: z.enum(["operator-file", "application", "baseline"]),
|
|
297
|
+
ruleReferences: z.array(digest).max(128),
|
|
298
|
+
explicitReviewRequired: z.boolean()
|
|
299
|
+
})).max(512)
|
|
300
|
+
});
|
|
301
|
+
var governanceEnvelopeSchema = z.strictObject({
|
|
302
|
+
source: z.literal("caller-supplied"),
|
|
303
|
+
envelopeId: digest.nullable(),
|
|
304
|
+
patchReference: digest.nullable(),
|
|
305
|
+
patchDigest: digest.nullable(),
|
|
306
|
+
linkedRunReferences: z.array(digest).max(64),
|
|
307
|
+
schemaValid: z.boolean(),
|
|
308
|
+
integrity: z.enum(["valid", "invalid"]),
|
|
309
|
+
expiration: z.enum(["unknown", "current", "expired", "not-yet-valid"]),
|
|
310
|
+
checkedAt: z.iso.datetime(),
|
|
311
|
+
expiredApprovals: count,
|
|
312
|
+
authenticity: z.literal("not-verified"),
|
|
313
|
+
patchBytes: z.literal("not-verified")
|
|
314
|
+
});
|
|
315
|
+
async function readGovernanceSession(source, rootRunId, runIds) {
|
|
316
|
+
const session = { availability: "unavailable", reference: null, revision: null };
|
|
317
|
+
const history = { availability: "unavailable", retention: "unknown", incomplete: true, policyDecisions: [] };
|
|
318
|
+
if (!source)
|
|
319
|
+
return { session, history, verify: async () => {} };
|
|
320
|
+
const initial = await source.index.get(source.id);
|
|
321
|
+
if (!initial || initial.sessionId !== source.id || !initial.runs.some((run) => run.runId === rootRunId))
|
|
322
|
+
throw new Error("GOVERNANCE_SESSION_MISMATCH");
|
|
323
|
+
const captured = JSON.stringify(initial);
|
|
324
|
+
session.availability = "recorded";
|
|
325
|
+
session.reference = governanceReference("session", initial.sessionId);
|
|
326
|
+
session.revision = initial.revision;
|
|
327
|
+
const pages = [];
|
|
328
|
+
if (source.history) {
|
|
329
|
+
let cursor = 0;
|
|
330
|
+
history.availability = "recorded";
|
|
331
|
+
history.retention = "retained";
|
|
332
|
+
history.incomplete = false;
|
|
333
|
+
for (let pageIndex = 0;pageIndex < 50; pageIndex++) {
|
|
334
|
+
const page = source.history.replay(source.id, cursor);
|
|
335
|
+
pages.push({ cursor, digest: governanceReference("history-page", JSON.stringify(page)) });
|
|
336
|
+
if (page.schemaVersion !== 1 || !Number.isSafeInteger(page.nextCursor) || page.nextCursor < cursor || page.events.length > 200)
|
|
337
|
+
throw new Error("GOVERNANCE_HISTORY_INVALID");
|
|
338
|
+
if (page.cursorExpired || page.policyEvidenceIncomplete) {
|
|
339
|
+
history.retention = "expired";
|
|
340
|
+
history.incomplete = true;
|
|
341
|
+
}
|
|
342
|
+
let lastSequence = cursor;
|
|
343
|
+
for (const event of page.events) {
|
|
344
|
+
if (event.sessionId !== source.id || !Number.isSafeInteger(event.sequence) || event.sequence <= lastSequence || event.sequence > page.nextCursor)
|
|
345
|
+
throw new Error("GOVERNANCE_HISTORY_INVALID");
|
|
346
|
+
lastSequence = event.sequence;
|
|
347
|
+
if (!runIds.has(event.runId) || event.activity.type !== "policy-decision")
|
|
348
|
+
continue;
|
|
349
|
+
const parsed = harnessPolicyDecisionEventSchema.safeParse(event.activity);
|
|
350
|
+
if (!parsed.success) {
|
|
351
|
+
history.incomplete = true;
|
|
352
|
+
continue;
|
|
353
|
+
}
|
|
354
|
+
if (history.policyDecisions.length === 512) {
|
|
355
|
+
history.incomplete = true;
|
|
356
|
+
continue;
|
|
357
|
+
}
|
|
358
|
+
const value = parsed.data;
|
|
359
|
+
history.policyDecisions.push({
|
|
360
|
+
runReference: governanceReference("run", event.runId),
|
|
361
|
+
sequence: event.sequence,
|
|
362
|
+
toolReference: governanceReference("tool", value.toolName),
|
|
363
|
+
phase: value.phase,
|
|
364
|
+
decision: value.decision,
|
|
365
|
+
policyDigest: value.policyDigest,
|
|
366
|
+
source: value.source,
|
|
367
|
+
ruleReferences: value.ruleIds.map((rule) => governanceReference("rule", rule)),
|
|
368
|
+
explicitReviewRequired: value.explicitReviewRequired
|
|
369
|
+
});
|
|
370
|
+
}
|
|
371
|
+
if (page.cursorExpired || !page.hasMore)
|
|
372
|
+
break;
|
|
373
|
+
if (page.nextCursor === cursor)
|
|
374
|
+
throw new Error("GOVERNANCE_HISTORY_INVALID");
|
|
375
|
+
cursor = page.nextCursor;
|
|
376
|
+
if (pageIndex === 49)
|
|
377
|
+
history.incomplete = true;
|
|
378
|
+
}
|
|
379
|
+
}
|
|
380
|
+
return { session, history, verify: async () => {
|
|
381
|
+
for (const page of pages)
|
|
382
|
+
if (governanceReference("history-page", JSON.stringify(source.history.replay(source.id, page.cursor))) !== page.digest)
|
|
383
|
+
throw new Error("GOVERNANCE_STATE_CHANGED");
|
|
384
|
+
if (JSON.stringify(await source.index.get(source.id)) !== captured)
|
|
385
|
+
throw new Error("GOVERNANCE_STATE_CHANGED");
|
|
386
|
+
} };
|
|
387
|
+
}
|
|
388
|
+
function projectGovernanceEnvelopes(envelopes, patches, now) {
|
|
389
|
+
if (envelopes.length > 32)
|
|
390
|
+
throw new Error("GOVERNANCE_ENVELOPE_LIMIT");
|
|
391
|
+
return envelopes.map((input) => {
|
|
392
|
+
if (Buffer.byteLength(JSON.stringify(input) ?? "") > 256 * 1024)
|
|
393
|
+
throw new Error("GOVERNANCE_ENVELOPE_LIMIT");
|
|
394
|
+
const parsed = changeEnvelopeSchema.safeParse(input);
|
|
395
|
+
const proof = verifyChangeEnvelope(input, { now });
|
|
396
|
+
const envelope = parsed.success ? parsed.data : undefined;
|
|
397
|
+
return governanceEnvelopeSchema.parse({
|
|
398
|
+
source: "caller-supplied",
|
|
399
|
+
envelopeId: envelope?.envelopeId ?? null,
|
|
400
|
+
patchReference: envelope ? governanceReference("patch", envelope.patch.patchId) : null,
|
|
401
|
+
patchDigest: envelope?.patch.patchDigest ?? null,
|
|
402
|
+
linkedRunReferences: envelope ? [...patches.get(envelope.patch.patchId) ?? []] : [],
|
|
403
|
+
schemaValid: parsed.success,
|
|
404
|
+
integrity: proof.integrity.envelopeDigestValid && proof.integrity.evidenceDigestValid ? "valid" : "invalid",
|
|
405
|
+
expiration: !envelope ? "unknown" : proof.expiration.envelopeNotYetValid ? "not-yet-valid" : proof.expiration.envelopeExpired ? "expired" : "current",
|
|
406
|
+
checkedAt: proof.expiration.checkedAt,
|
|
407
|
+
expiredApprovals: proof.expiration.expiredApprovalIds.length,
|
|
408
|
+
authenticity: "not-verified",
|
|
409
|
+
patchBytes: "not-verified"
|
|
410
|
+
});
|
|
411
|
+
});
|
|
412
|
+
}
|
|
413
|
+
|
|
414
|
+
// src/persistence/governance-report.ts
|
|
415
|
+
var digest2 = z2.string().regex(/^sha256:[a-f0-9]{64}$/);
|
|
416
|
+
var version = z2.string().regex(/^\d+\.\d+\.\d+(?:[-+][a-zA-Z0-9.-]+)?$/);
|
|
417
|
+
var bindingSchema = z2.object({ schemaVersion: z2.literal(1), id: z2.literal("zhivex-harness"), version, fingerprint: digest2, algorithm: z2.literal("sha256") });
|
|
418
|
+
var count2 = z2.number().int().nonnegative().safe();
|
|
419
|
+
var status = z2.enum(["created", "running", "waiting_approval", "cancel_requested", "completed", "failed", "cancelled", "timed_out", "unknown"]);
|
|
420
|
+
var availability = z2.enum(["recorded", "unavailable", "invalid"]);
|
|
421
|
+
var providerReason = z2.enum(["empty_arguments", "invalid_json", "arguments_too_large", "incomplete_arguments", "inconsistent_metadata", "response_failed", "response_incomplete", "stream_truncated"]);
|
|
422
|
+
var deliveryReason = z2.enum(["TASK_ACCEPTANCE_NO_DELIVERY_EVIDENCE", "TASK_ACCEPTANCE_SCOPE_VIOLATION", "TASK_ACCEPTANCE_RUN_NOT_COMPLETED", "TASK_ACCEPTANCE_RUN_NOT_FINISHED", "TASK_ACCEPTANCE_IMPORT_UNCONFIRMED", "TASK_ACCEPTANCE_CHECKS_MISSING", "TASK_ACCEPTANCE_DELIVERY_DRIFT", "TASK_ACCEPTANCE_DELIVERY_INSPECTION_FAILED", "TASK_ACCEPTANCE_HUMAN_REVIEW_REQUIRED", "TASK_ACCEPTANCE_VERIFIED"]);
|
|
423
|
+
var deliveryStatus = z2.enum(["pending", "incomplete", "failed", "pending_review", "verified", "unknown"]);
|
|
424
|
+
var checkSchema = z2.strictObject({
|
|
425
|
+
reference: digest2,
|
|
426
|
+
argvDigest: digest2,
|
|
427
|
+
patchId: digest2,
|
|
428
|
+
snapshotDigest: digest2,
|
|
429
|
+
exitCode: z2.number().int(),
|
|
430
|
+
timedOut: z2.boolean(),
|
|
431
|
+
unchanged: z2.boolean()
|
|
432
|
+
});
|
|
433
|
+
var deliverySchema = z2.object({
|
|
434
|
+
schemaVersion: z2.literal(1),
|
|
435
|
+
contractRevision: count2,
|
|
436
|
+
contractDigest: digest2,
|
|
437
|
+
status: deliveryStatus,
|
|
438
|
+
checks: z2.array(taskCheckReceiptSchema).max(32),
|
|
439
|
+
delivery: z2.object({ runId: z2.string().max(512), executionIdentity: z2.string().max(512), patchId: digest2, snapshotDigest: digest2 }).optional()
|
|
440
|
+
});
|
|
441
|
+
var approvalSchema = z2.strictObject({
|
|
442
|
+
reference: digest2,
|
|
443
|
+
toolReference: digest2,
|
|
444
|
+
approved: z2.boolean(),
|
|
445
|
+
origin: z2.enum(["interactive", "automatic", "application", "unknown"]),
|
|
446
|
+
channelReference: digest2,
|
|
447
|
+
policyDigest: digest2.nullable(),
|
|
448
|
+
status: z2.enum(["rejected", "approved", "applied", "succeeded", "failed", "unknown"]),
|
|
449
|
+
proposalId: digest2.nullable(),
|
|
450
|
+
exitCode: z2.number().int().nullable(),
|
|
451
|
+
timedOut: z2.boolean().nullable(),
|
|
452
|
+
effects: z2.array(z2.strictObject({ pathReference: digest2, beforeDigest: digest2.nullable(), afterDigest: digest2.nullable() })).max(50)
|
|
453
|
+
});
|
|
454
|
+
var delegationReason = z2.enum(["valid", "invalid_json", "invalid_schema", "task_mismatch", "incomplete", "duplicate_claim", "path_denied", "evidence_missing", "coverage_missing", "missing_child", "child_identity_unavailable"]);
|
|
455
|
+
var delegationSchema = z2.strictObject({
|
|
456
|
+
taskReference: digest2,
|
|
457
|
+
childReference: digest2.nullable(),
|
|
458
|
+
recordedAcceptance: z2.boolean(),
|
|
459
|
+
reason: delegationReason,
|
|
460
|
+
semanticReview: z2.enum(["pending", "not_requested"]),
|
|
461
|
+
correctionsUsed: count2.nullable()
|
|
462
|
+
});
|
|
463
|
+
var delegationInput = z2.object({ schemaVersion: z2.literal(1), evaluations: z2.array(z2.object({
|
|
464
|
+
taskId: z2.string().max(128),
|
|
465
|
+
childRunId: z2.string().max(512).nullable(),
|
|
466
|
+
childStatus: z2.string().max(32),
|
|
467
|
+
accepted: z2.boolean(),
|
|
468
|
+
reason: delegationReason,
|
|
469
|
+
semanticReview: z2.enum(["pending", "not_requested"]),
|
|
470
|
+
correctionsUsed: count2.optional()
|
|
471
|
+
})).max(64) });
|
|
472
|
+
var runSchema = z2.strictObject({
|
|
473
|
+
reference: digest2,
|
|
474
|
+
parentReference: digest2.nullable(),
|
|
475
|
+
revision: count2.nullable(),
|
|
476
|
+
status,
|
|
477
|
+
finalized: z2.boolean(),
|
|
478
|
+
failure: z2.enum(["run_failed", "cancelled", "timed_out", "not_reported"]).nullable(),
|
|
479
|
+
failureDetails: z2.strictObject({ providerToolReason: providerReason.nullable(), diagnosticReference: digest2.nullable(), deliveryReason: deliveryReason.nullable() }),
|
|
480
|
+
identity: z2.literal("not-verified"),
|
|
481
|
+
runtimePolicy: z2.enum(["assistant-v3-durable-closure"]).nullable(),
|
|
482
|
+
contract: z2.strictObject({
|
|
483
|
+
availability,
|
|
484
|
+
digest: digest2.nullable(),
|
|
485
|
+
revision: count2.nullable(),
|
|
486
|
+
requiredChecks: count2.nullable(),
|
|
487
|
+
humanReviewsPending: count2.nullable(),
|
|
488
|
+
allowedWritePathReferences: z2.array(digest2).max(256),
|
|
489
|
+
protectedPathReferences: z2.array(digest2).max(256),
|
|
490
|
+
checks: z2.array(z2.strictObject({ reference: digest2, argvDigest: digest2, kind: z2.enum(["argv", "package-script"]), backend: z2.enum(["none", "oci"]), approval: z2.literal("required") })).max(32),
|
|
491
|
+
humanReviewReferences: z2.array(digest2).max(32)
|
|
492
|
+
}),
|
|
493
|
+
delivery: z2.strictObject({
|
|
494
|
+
availability,
|
|
495
|
+
status: deliveryStatus,
|
|
496
|
+
patchId: digest2.nullable(),
|
|
497
|
+
snapshotDigest: digest2.nullable(),
|
|
498
|
+
interpretation: z2.literal("recorded-checkpoint-not-current-workspace-verification"),
|
|
499
|
+
checks: z2.array(checkSchema).max(32)
|
|
500
|
+
}),
|
|
501
|
+
approvals: z2.strictObject({ availability, items: z2.array(approvalSchema).max(512) }),
|
|
502
|
+
usage: z2.strictObject({
|
|
503
|
+
availability: z2.enum(["recorded", "unavailable"]),
|
|
504
|
+
calls: count2.nullable(),
|
|
505
|
+
inputTokens: count2.nullable(),
|
|
506
|
+
outputTokens: count2.nullable(),
|
|
507
|
+
complete: z2.boolean().nullable(),
|
|
508
|
+
estimatedUsd: z2.number().finite().nonnegative().nullable(),
|
|
509
|
+
costKind: z2.literal("estimate-not-invoice")
|
|
510
|
+
}),
|
|
511
|
+
journal: z2.strictObject({ availability: z2.enum(["recorded", "unavailable"]), entries: count2, failed: count2, unfinished: count2 }),
|
|
512
|
+
delegations: z2.strictObject({ availability, interpretation: z2.literal("recorded-checkpoint-not-semantic-review"), items: z2.array(delegationSchema).max(64) }),
|
|
513
|
+
children: z2.array(digest2).max(64)
|
|
514
|
+
});
|
|
515
|
+
var harnessGovernanceReportSchema = z2.strictObject({
|
|
516
|
+
schemaVersion: z2.literal(1),
|
|
517
|
+
kind: z2.literal("harness-governance-report"),
|
|
518
|
+
exporterVersion: z2.string().regex(/^\d+\.\d+\.\d+(?:[-+][a-zA-Z0-9.-]+)?$/),
|
|
519
|
+
executionArtifact: z2.strictObject({ version: version.nullable(), digest: z2.null(), availability: z2.enum(["recorded-version", "unavailable"]), configurationFingerprint: digest2.nullable(), authenticity: z2.literal("not-verified") }),
|
|
520
|
+
rootReference: digest2,
|
|
521
|
+
identity: z2.literal("not-verified"),
|
|
522
|
+
referencePolicy: z2.literal("sha256-domain-separated-pseudonyms-not-anonymity"),
|
|
523
|
+
session: governanceSessionSchema,
|
|
524
|
+
eventHistory: governanceHistorySchema,
|
|
525
|
+
changeEnvelopes: z2.array(governanceEnvelopeSchema).max(32),
|
|
526
|
+
runs: z2.array(runSchema).max(64),
|
|
527
|
+
missingChildren: z2.array(digest2).max(64),
|
|
528
|
+
limitations: z2.array(z2.enum(["tree_limit", "missing_child", "invalid_contract", "invalid_delivery", "invalid_approvals", "journal_unavailable"])).max(6)
|
|
529
|
+
});
|
|
530
|
+
var MAX_JOURNAL = 2048;
|
|
531
|
+
var MAX_REPORT_BYTES = 2 * 1024 * 1024;
|
|
532
|
+
var sameScope = (state, scope) => !state.scope || state.scope.tenantId === scope?.tenantId && state.scope.userId === scope?.userId && state.scope.namespace === scope?.namespace;
|
|
533
|
+
function projectRun(state, journal, limitations) {
|
|
534
|
+
const runStatus = status.safeParse(state.status);
|
|
535
|
+
const stateStatus = runStatus.success ? runStatus.data : "unknown";
|
|
536
|
+
let ledger;
|
|
537
|
+
let contractAvailability = "unavailable";
|
|
538
|
+
try {
|
|
539
|
+
ledger = readTaskAcceptanceLedger(state);
|
|
540
|
+
if (ledger)
|
|
541
|
+
contractAvailability = "recorded";
|
|
542
|
+
} catch {
|
|
543
|
+
contractAvailability = "invalid";
|
|
544
|
+
limitations.add("invalid_contract");
|
|
545
|
+
}
|
|
546
|
+
const contract = ledger?.revisions.at(-1);
|
|
547
|
+
const rawDelivery = state.metadata?.[TASK_ACCEPTANCE_EVIDENCE_KEY];
|
|
548
|
+
const parsedDelivery = deliverySchema.safeParse(rawDelivery);
|
|
549
|
+
const bound = parsedDelivery.success && contract && parsedDelivery.data.contractDigest === contract.digest && parsedDelivery.data.contractRevision === contract.revision && (!parsedDelivery.data.delivery || parsedDelivery.data.delivery.runId === state.runId);
|
|
550
|
+
const candidate = bound ? parsedDelivery.data : undefined;
|
|
551
|
+
const verified = candidate?.status === "verified" || candidate?.status === "pending_review";
|
|
552
|
+
const validSuccess = !verified || stateStatus === "completed" && candidate.delivery && contract && contract.contract.requiredChecks.every((required) => candidate.checks.some((check) => check.checkId === required.id && check.runId === state.runId && check.argvDigest === "sha256:" + createHash2("sha256").update(JSON.stringify([required.command, ...required.args])).digest("hex") && check.contractDigest === contract.digest && check.contractRevision === contract.revision && check.exitCode === 0 && !check.timedOut && check.unchanged && check.patchId === candidate.delivery.patchId && check.snapshotDigest === candidate.delivery.snapshotDigest && check.executionIdentity === candidate.delivery.executionIdentity)) && candidate.status === "pending_review" === contract.contract.humanReview.length > 0;
|
|
553
|
+
const delivery = validSuccess ? candidate : undefined;
|
|
554
|
+
if (rawDelivery !== undefined && !delivery)
|
|
555
|
+
limitations.add("invalid_delivery");
|
|
556
|
+
const approvals = { availability: state.metadata?.[APPROVAL_HISTORY_KEY] === undefined ? "unavailable" : "recorded", items: [] };
|
|
557
|
+
try {
|
|
558
|
+
for (let offset = 0;offset < 512; offset += 25) {
|
|
559
|
+
const rows = approvalDecisionViews(state, journal ?? [], offset);
|
|
560
|
+
for (const row of rows)
|
|
561
|
+
approvals.items.push({
|
|
562
|
+
reference: governanceReference("approval", row.approvalId),
|
|
563
|
+
toolReference: governanceReference("tool", row.name),
|
|
564
|
+
approved: row.approved,
|
|
565
|
+
origin: row.provenance?.origin ?? "unknown",
|
|
566
|
+
channelReference: governanceReference("channel", row.provenance?.channel ?? "unknown"),
|
|
567
|
+
policyDigest: row.provenance?.policyDigest ?? null,
|
|
568
|
+
status: row.status,
|
|
569
|
+
proposalId: row.evidence?.proposalId ?? null,
|
|
570
|
+
exitCode: row.evidence?.exitCode ?? null,
|
|
571
|
+
timedOut: row.evidence?.timedOut ?? null,
|
|
572
|
+
effects: (row.evidence?.effects ?? []).map((effect) => ({ pathReference: governanceReference("path", effect.path), beforeDigest: effect.beforeDigest, afterDigest: effect.afterDigest }))
|
|
573
|
+
});
|
|
574
|
+
if (rows.length < 25)
|
|
575
|
+
break;
|
|
576
|
+
}
|
|
577
|
+
} catch {
|
|
578
|
+
approvals.availability = "invalid";
|
|
579
|
+
approvals.items = [];
|
|
580
|
+
limitations.add("invalid_approvals");
|
|
581
|
+
}
|
|
582
|
+
const parsedUsage = inspectUsageLedger(state.metadata?.[USAGE_LEDGER_KEY]);
|
|
583
|
+
const usage = parsedUsage?.runId === state.runId ? parsedUsage : null;
|
|
584
|
+
const rawDelegations = state.metadata?.zhivexDelegationAcceptanceV1;
|
|
585
|
+
const delegations = delegationInput.safeParse(rawDelegations);
|
|
586
|
+
const manifest = inspectRuntimeManifest(state.metadata?.effectiveRuntime);
|
|
587
|
+
return {
|
|
588
|
+
reference: governanceReference("run", state.runId),
|
|
589
|
+
parentReference: state.parentRunId ? governanceReference("run", state.parentRunId) : null,
|
|
590
|
+
revision: count2.safeParse(state.revision).success ? state.revision : null,
|
|
591
|
+
status: stateStatus,
|
|
592
|
+
finalized: ["completed", "failed", "cancelled", "timed_out"].includes(stateStatus),
|
|
593
|
+
failure: stateStatus === "failed" ? "run_failed" : stateStatus === "cancelled" ? "cancelled" : stateStatus === "timed_out" ? "timed_out" : state.error ? "not_reported" : null,
|
|
594
|
+
failureDetails: {
|
|
595
|
+
providerToolReason: providerReason.safeParse(state.error?.reason).success ? state.error.reason : null,
|
|
596
|
+
diagnosticReference: state.error?.diagnosticCode ? governanceReference("diagnostic", state.error.diagnosticCode) : null,
|
|
597
|
+
deliveryReason: deliveryReason.safeParse(rawDelivery && typeof rawDelivery === "object" && !Array.isArray(rawDelivery) ? rawDelivery.reason : undefined).success ? rawDelivery.reason : null
|
|
598
|
+
},
|
|
599
|
+
identity: "not-verified",
|
|
600
|
+
runtimePolicy: manifest?.policyVersion ?? null,
|
|
601
|
+
contract: {
|
|
602
|
+
availability: contractAvailability,
|
|
603
|
+
digest: contract?.digest ?? null,
|
|
604
|
+
revision: contract?.revision ?? null,
|
|
605
|
+
requiredChecks: contract?.contract.requiredChecks.length ?? null,
|
|
606
|
+
humanReviewsPending: contract?.contract.humanReview.length ?? null,
|
|
607
|
+
allowedWritePathReferences: contract?.contract.allowedWritePaths.map((file) => governanceReference("path", file)) ?? [],
|
|
608
|
+
protectedPathReferences: contract?.contract.protectedFiles.map((file) => governanceReference("path", file)) ?? [],
|
|
609
|
+
checks: contract?.contract.requiredChecks.map((check) => ({ reference: governanceReference("check", check.id), argvDigest: "sha256:" + createHash2("sha256").update(JSON.stringify([check.command, ...check.args])).digest("hex"), kind: check.kind, backend: check.execution.backend, approval: check.execution.approval })) ?? [],
|
|
610
|
+
humanReviewReferences: contract?.contract.humanReview.map((review) => governanceReference("review", review.id)) ?? []
|
|
611
|
+
},
|
|
612
|
+
delivery: {
|
|
613
|
+
availability: delivery ? "recorded" : rawDelivery === undefined ? "unavailable" : "invalid",
|
|
614
|
+
status: delivery?.status ?? "unknown",
|
|
615
|
+
patchId: delivery?.delivery?.patchId ?? null,
|
|
616
|
+
snapshotDigest: delivery?.delivery?.snapshotDigest ?? null,
|
|
617
|
+
interpretation: "recorded-checkpoint-not-current-workspace-verification",
|
|
618
|
+
checks: (delivery?.checks ?? []).filter((check) => check.runId === state.runId && check.contractDigest === contract?.digest && check.contractRevision === contract?.revision).map((check) => ({ reference: governanceReference("check", check.checkId), argvDigest: check.argvDigest, patchId: check.patchId, snapshotDigest: check.snapshotDigest, exitCode: check.exitCode, timedOut: check.timedOut, unchanged: check.unchanged }))
|
|
619
|
+
},
|
|
620
|
+
approvals,
|
|
621
|
+
usage: {
|
|
622
|
+
availability: usage ? "recorded" : "unavailable",
|
|
623
|
+
calls: usage?.calls ?? null,
|
|
624
|
+
inputTokens: usage?.inputTokens ?? null,
|
|
625
|
+
outputTokens: usage?.outputTokens ?? null,
|
|
626
|
+
complete: usage?.usageComplete ?? null,
|
|
627
|
+
estimatedUsd: usage?.estimatedUsd ?? null,
|
|
628
|
+
costKind: "estimate-not-invoice"
|
|
629
|
+
},
|
|
630
|
+
journal: {
|
|
631
|
+
availability: journal ? "recorded" : "unavailable",
|
|
632
|
+
entries: journal?.length ?? 0,
|
|
633
|
+
failed: journal?.filter((entry) => entry.status === "failed").length ?? 0,
|
|
634
|
+
unfinished: journal?.filter((entry) => entry.status !== "completed" && entry.status !== "failed").length ?? 0
|
|
635
|
+
},
|
|
636
|
+
delegations: {
|
|
637
|
+
availability: rawDelegations === undefined ? "unavailable" : delegations.success ? "recorded" : "invalid",
|
|
638
|
+
interpretation: "recorded-checkpoint-not-semantic-review",
|
|
639
|
+
items: delegations.success ? delegations.data.evaluations.map((item) => ({
|
|
640
|
+
taskReference: governanceReference("task", item.taskId),
|
|
641
|
+
childReference: item.childRunId ? governanceReference("run", item.childRunId) : null,
|
|
642
|
+
recordedAcceptance: item.accepted,
|
|
643
|
+
reason: item.reason,
|
|
644
|
+
semanticReview: item.semanticReview,
|
|
645
|
+
correctionsUsed: item.correctionsUsed ?? null
|
|
646
|
+
})) : []
|
|
647
|
+
},
|
|
648
|
+
children: (state.childRuns ?? []).slice(0, 64).map((child) => governanceReference("run", child.runId))
|
|
649
|
+
};
|
|
650
|
+
}
|
|
651
|
+
async function exportHarnessGovernanceReport(store, scope, runId, options = {}) {
|
|
652
|
+
const limitations = new Set;
|
|
653
|
+
const runs = [], missingChildren = [];
|
|
654
|
+
const observed = [];
|
|
655
|
+
const queue = [{ id: runId }], seen = new Set;
|
|
656
|
+
while (queue.length && runs.length + missingChildren.length < 64) {
|
|
657
|
+
const item = queue.shift();
|
|
658
|
+
if (seen.has(item.id))
|
|
659
|
+
continue;
|
|
660
|
+
seen.add(item.id);
|
|
661
|
+
const loaded = await store.load(item.id, scope);
|
|
662
|
+
const state = loaded ? structuredClone(loaded) : undefined;
|
|
663
|
+
if (!state || state.runId !== item.id || !sameScope(state, scope) || item.parent !== undefined && state.parentRunId !== item.parent) {
|
|
664
|
+
if (item.parent === undefined)
|
|
665
|
+
throw new Error("GOVERNANCE_RUN_UNAVAILABLE");
|
|
666
|
+
missingChildren.push(governanceReference("run", item.id));
|
|
667
|
+
limitations.add("missing_child");
|
|
668
|
+
continue;
|
|
669
|
+
}
|
|
670
|
+
const loadedJournal = await store.listToolCalls?.(state.runId, scope);
|
|
671
|
+
const journal = loadedJournal ? structuredClone(loadedJournal) : undefined;
|
|
672
|
+
if (journal && journal.length > MAX_JOURNAL)
|
|
673
|
+
throw new Error("GOVERNANCE_JOURNAL_LIMIT");
|
|
674
|
+
if (journal?.some((entry) => entry.runId !== state.runId))
|
|
675
|
+
throw new Error("GOVERNANCE_JOURNAL_SCOPE");
|
|
676
|
+
if (!journal)
|
|
677
|
+
limitations.add("journal_unavailable");
|
|
678
|
+
observed.push({ state, journal });
|
|
679
|
+
runs.push(projectRun(state, journal, limitations));
|
|
680
|
+
if ((state.childRuns?.length ?? 0) > 64)
|
|
681
|
+
limitations.add("tree_limit");
|
|
682
|
+
for (const child of (state.childRuns ?? []).slice(0, 64))
|
|
683
|
+
queue.push({ id: child.runId, parent: state.runId });
|
|
684
|
+
}
|
|
685
|
+
if (queue.length)
|
|
686
|
+
limitations.add("tree_limit");
|
|
687
|
+
const context = await readGovernanceSession(options.session, runId, new Set(observed.map((item) => item.state.runId)));
|
|
688
|
+
for (const { state, journal } of observed) {
|
|
689
|
+
const current = await store.load(state.runId, scope);
|
|
690
|
+
const currentJournal = await store.listToolCalls?.(state.runId, scope);
|
|
691
|
+
if (!current || JSON.stringify(current) !== JSON.stringify(state) || JSON.stringify(currentJournal) !== JSON.stringify(journal))
|
|
692
|
+
throw new Error("GOVERNANCE_STATE_CHANGED");
|
|
693
|
+
}
|
|
694
|
+
await context.verify();
|
|
695
|
+
const patches = new Map;
|
|
696
|
+
for (const run of runs)
|
|
697
|
+
for (const patch of new Set([run.delivery.patchId, ...run.approvals.items.map((row) => row.proposalId)].filter((id) => id !== null)))
|
|
698
|
+
patches.set(patch, [...patches.get(patch) ?? [], run.reference]);
|
|
699
|
+
const binding = bindingSchema.safeParse(observed[0]?.state.harness);
|
|
700
|
+
const report = harnessGovernanceReportSchema.parse({
|
|
701
|
+
schemaVersion: 1,
|
|
702
|
+
kind: "harness-governance-report",
|
|
703
|
+
exporterVersion: HARNESS_VERSION,
|
|
704
|
+
executionArtifact: { version: binding.success ? binding.data.version : null, digest: null, availability: binding.success ? "recorded-version" : "unavailable", configurationFingerprint: binding.success ? binding.data.fingerprint : null, authenticity: "not-verified" },
|
|
705
|
+
rootReference: governanceReference("run", runId),
|
|
706
|
+
identity: "not-verified",
|
|
707
|
+
referencePolicy: "sha256-domain-separated-pseudonyms-not-anonymity",
|
|
708
|
+
session: context.session,
|
|
709
|
+
eventHistory: context.history,
|
|
710
|
+
changeEnvelopes: projectGovernanceEnvelopes(options.changeEnvelopes ?? [], patches, options.now ?? Date.now()),
|
|
711
|
+
runs,
|
|
712
|
+
missingChildren,
|
|
713
|
+
limitations: [...limitations].sort()
|
|
714
|
+
});
|
|
715
|
+
if (Buffer.byteLength(JSON.stringify(report)) > MAX_REPORT_BYTES)
|
|
716
|
+
throw new Error("GOVERNANCE_REPORT_LIMIT");
|
|
717
|
+
return report;
|
|
718
|
+
}
|
|
719
|
+
function renderHarnessGovernanceMarkdown(input) {
|
|
720
|
+
const report = harnessGovernanceReportSchema.parse(input);
|
|
721
|
+
return [
|
|
722
|
+
"# Execution and governance report",
|
|
723
|
+
"",
|
|
724
|
+
`Schema: ${report.schemaVersion}. Exporter: ${report.exporterVersion}.`,
|
|
725
|
+
`Identity: not verified. Recorded execution version: ${report.executionArtifact.version ?? "unavailable"}. Artifact digest: unavailable. Hash references are pseudonyms, not signatures.`,
|
|
726
|
+
"Delivery describes a recorded checkpoint; export does not recheck the workspace.",
|
|
727
|
+
"",
|
|
728
|
+
"| Run reference | Execution | Recorded delivery | Usage |",
|
|
729
|
+
"| --- | --- | --- | --- |",
|
|
730
|
+
...report.runs.map((run) => `| ${run.reference} | ${run.status} | ${run.delivery.status} | ${run.usage.availability === "unavailable" ? "unavailable" : `${run.usage.inputTokens} input / ${run.usage.outputTokens} output (${run.usage.complete ? "complete" : "incomplete"})`} |`),
|
|
731
|
+
"",
|
|
732
|
+
`Missing children: ${report.missingChildren.length}. Limitations: ${report.limitations.join(", ") || "none detected"}.`,
|
|
733
|
+
`Session: ${report.session.availability}. Event history: ${report.eventHistory.availability}. Retention: ${report.eventHistory.retention}. Incomplete: ${report.eventHistory.incomplete}.`,
|
|
734
|
+
`Change envelopes: ${report.changeEnvelopes.length}. Envelope integrity does not verify patch bytes or authenticity. Estimates are not invoices.`,
|
|
735
|
+
""
|
|
736
|
+
].join(`
|
|
737
|
+
`);
|
|
738
|
+
}
|
|
247
739
|
export {
|
|
248
740
|
BUILTIN_PROVIDER_REGISTRATIONS,
|
|
249
741
|
BUN_ENGINE_RANGE,
|
|
@@ -368,6 +860,7 @@ export {
|
|
|
368
860
|
cliStreamErrorDocumentSchema,
|
|
369
861
|
cliStreamResultDocumentSchema,
|
|
370
862
|
compactHarnessMessages,
|
|
863
|
+
compileTaskAcceptanceContract,
|
|
371
864
|
computeChangeEnvelopeDigest,
|
|
372
865
|
computeChangeEnvelopeEvidenceDigest,
|
|
373
866
|
createAcpConnection,
|
|
@@ -403,6 +896,7 @@ export {
|
|
|
403
896
|
editProposalSchema,
|
|
404
897
|
estimateMessageTokens,
|
|
405
898
|
executionFingerprintInput,
|
|
899
|
+
exportHarnessGovernanceReport,
|
|
406
900
|
exportHarnessStateBackup,
|
|
407
901
|
externalAttestationReferenceSchema,
|
|
408
902
|
fileDigestSchema,
|
|
@@ -412,6 +906,7 @@ export {
|
|
|
412
906
|
harnessContextFingerprintInput,
|
|
413
907
|
harnessErrorDocument,
|
|
414
908
|
harnessExecutionSession,
|
|
909
|
+
harnessGovernanceReportSchema,
|
|
415
910
|
harnessLifecycleFingerprintInput,
|
|
416
911
|
harnessLocalCredentialsSchema,
|
|
417
912
|
harnessSkillLoadInputSchema,
|
|
@@ -420,8 +915,10 @@ export {
|
|
|
420
915
|
importHarnessStateBackupFile,
|
|
421
916
|
injectTimeToSafeFixAttack,
|
|
422
917
|
inspectHarnessModelCapabilities,
|
|
918
|
+
inspectHarnessPolicy,
|
|
423
919
|
inspectHarnessRun,
|
|
424
920
|
inspectHarnessState,
|
|
921
|
+
inspectHarnessTaskAcceptance,
|
|
425
922
|
isHarnessContextDigest,
|
|
426
923
|
listHarnessRuns,
|
|
427
924
|
loadHarnessMcpConfiguration,
|
|
@@ -451,10 +948,12 @@ export {
|
|
|
451
948
|
recommendCompactionModels,
|
|
452
949
|
recoverHarnessLocalService,
|
|
453
950
|
renderHarnessContextInstructions,
|
|
951
|
+
renderHarnessGovernanceMarkdown,
|
|
454
952
|
requestHarnessLocalService,
|
|
455
953
|
resolveHarnessConfig,
|
|
456
954
|
resolveHarnessModelRoutes,
|
|
457
955
|
restoreFileInputSchema,
|
|
956
|
+
reviseHarnessTaskAcceptance,
|
|
458
957
|
runHarness,
|
|
459
958
|
runHarnessReviewGroup,
|
|
460
959
|
selectHarnessModel,
|
|
@@ -466,6 +965,7 @@ export {
|
|
|
466
965
|
stateBackupBundleSchema,
|
|
467
966
|
streamEventDocument,
|
|
468
967
|
streamResultDocument,
|
|
968
|
+
taskAcceptanceContractSchema,
|
|
469
969
|
timeToSafeFixDriverResultSchema,
|
|
470
970
|
timeToSafeFixLatencyStatistics,
|
|
471
971
|
timeToSafeFixTaskSchema,
|