harnessix 0.10.0b3__py3-none-any.whl
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.
- harnessix/__init__.py +3 -0
- harnessix/__main__.py +5 -0
- harnessix/agent/__init__.py +1 -0
- harnessix/agent/approvals.py +365 -0
- harnessix/agent/argument_normalization.py +143 -0
- harnessix/agent/attempt_accounting.py +60 -0
- harnessix/agent/batch_patching.py +191 -0
- harnessix/agent/billing.py +47 -0
- harnessix/agent/call_repair.py +212 -0
- harnessix/agent/cancellation.py +63 -0
- harnessix/agent/compaction_input_budget.py +130 -0
- harnessix/agent/compaction_reducer.py +275 -0
- harnessix/agent/completion_guard.py +177 -0
- harnessix/agent/errors.py +116 -0
- harnessix/agent/event_compatibility.py +200 -0
- harnessix/agent/execution.py +47 -0
- harnessix/agent/ids.py +13 -0
- harnessix/agent/input_publication.py +28 -0
- harnessix/agent/item_reducer.py +442 -0
- harnessix/agent/lifecycle.py +224 -0
- harnessix/agent/model_history_runtime.py +373 -0
- harnessix/agent/model_input_budget.py +275 -0
- harnessix/agent/model_text.py +151 -0
- harnessix/agent/models.py +900 -0
- harnessix/agent/patching.py +103 -0
- harnessix/agent/planning.py +289 -0
- harnessix/agent/ports.py +211 -0
- harnessix/agent/provider_stop.py +51 -0
- harnessix/agent/publication.py +225 -0
- harnessix/agent/question_events.py +43 -0
- harnessix/agent/reducer.py +225 -0
- harnessix/agent/reducer_support.py +196 -0
- harnessix/agent/runtime.py +3473 -0
- harnessix/agent/runtime_configuration.py +86 -0
- harnessix/agent/runtime_recovery.py +225 -0
- harnessix/agent/runtime_thread_lock.py +61 -0
- harnessix/agent/telemetry.py +318 -0
- harnessix/agent/tool_call_groups.py +41 -0
- harnessix/agent/tool_rejections.py +100 -0
- harnessix/agent/truncation_recovery.py +79 -0
- harnessix/agent/trusted_action_contracts.py +83 -0
- harnessix/agent/trusted_action_reducer.py +46 -0
- harnessix/agent/trusted_action_runtime.py +250 -0
- harnessix/agent/trusted_action_session.py +307 -0
- harnessix/agent/turn_budget_compaction.py +252 -0
- harnessix/agent/turn_budget_hint.py +27 -0
- harnessix/agent/turn_reducer.py +384 -0
- harnessix/agent/usage.py +150 -0
- harnessix/agent_cli.py +497 -0
- harnessix/app_server/__init__.py +13 -0
- harnessix/app_server/artifacts.py +68 -0
- harnessix/app_server/command_runtime.py +110 -0
- harnessix/app_server/frame_publication.py +118 -0
- harnessix/app_server/handshake.py +96 -0
- harnessix/app_server/query_runtime.py +118 -0
- harnessix/app_server/server.py +299 -0
- harnessix/app_server/service.py +487 -0
- harnessix/app_server/stdio.py +268 -0
- harnessix/artifacts/__init__.py +1 -0
- harnessix/artifacts/action_output_store.py +413 -0
- harnessix/artifacts/action_review_store.py +202 -0
- harnessix/artifacts/batch_diff.py +255 -0
- harnessix/artifacts/batch_verify.py +178 -0
- harnessix/artifacts/binary_projection.py +28 -0
- harnessix/artifacts/contracts.py +137 -0
- harnessix/artifacts/persistence.py +73 -0
- harnessix/artifacts/ports.py +69 -0
- harnessix/artifacts/publication.py +131 -0
- harnessix/artifacts/reference.py +145 -0
- harnessix/artifacts/sqlite.py +552 -0
- harnessix/candidates/__init__.py +1 -0
- harnessix/candidates/judge.py +94 -0
- harnessix/candidates/selection.py +146 -0
- harnessix/candidates/verification.py +208 -0
- harnessix/cli.py +126 -0
- harnessix/context/__init__.py +78 -0
- harnessix/context/compaction.py +459 -0
- harnessix/context/compaction_contracts.py +115 -0
- harnessix/context/compaction_ledger_contracts.py +163 -0
- harnessix/context/compaction_projection.py +45 -0
- harnessix/context/compaction_runtime_contracts.py +25 -0
- harnessix/context/compaction_window.py +175 -0
- harnessix/context/contracts.py +401 -0
- harnessix/context/engine.py +234 -0
- harnessix/context/ports.py +18 -0
- harnessix/context/read_workspace.py +84 -0
- harnessix/context/sources.py +839 -0
- harnessix/context/tool_result_contracts.py +214 -0
- harnessix/context/tool_result_view.py +488 -0
- harnessix/context/working_set_view.py +143 -0
- harnessix/delivery/__init__.py +1 -0
- harnessix/delivery/action_transaction_planning.py +53 -0
- harnessix/delivery/contracts.py +314 -0
- harnessix/delivery/diff.py +41 -0
- harnessix/delivery/diff_content.py +231 -0
- harnessix/delivery/file_modes.py +18 -0
- harnessix/delivery/filesystem.py +528 -0
- harnessix/delivery/git.py +902 -0
- harnessix/delivery/git_authentication_control.py +201 -0
- harnessix/delivery/git_checkpoint.py +132 -0
- harnessix/delivery/git_command.py +222 -0
- harnessix/delivery/git_contracts.py +497 -0
- harnessix/delivery/git_identity.py +58 -0
- harnessix/delivery/git_inventory_contracts.py +576 -0
- harnessix/delivery/git_inventory_materials.py +199 -0
- harnessix/delivery/git_inventory_wire.py +323 -0
- harnessix/delivery/git_material_cas.py +158 -0
- harnessix/delivery/git_material_failure.py +262 -0
- harnessix/delivery/git_material_input_contracts.py +459 -0
- harnessix/delivery/git_material_native.py +435 -0
- harnessix/delivery/git_material_native_windows.py +404 -0
- harnessix/delivery/git_material_trace2_profile.py +374 -0
- harnessix/delivery/git_material_worker.py +354 -0
- harnessix/delivery/git_object_material.py +147 -0
- harnessix/delivery/git_object_references.py +189 -0
- harnessix/delivery/git_push.py +609 -0
- harnessix/delivery/git_repository_recipe.py +246 -0
- harnessix/delivery/git_source.py +56 -0
- harnessix/delivery/git_store.py +438 -0
- harnessix/delivery/git_store_genesis.py +103 -0
- harnessix/delivery/git_store_schema.py +98 -0
- harnessix/delivery/git_store_schema_v2.py +239 -0
- harnessix/delivery/git_tree_closure.py +220 -0
- harnessix/delivery/git_tree_diff.py +93 -0
- harnessix/delivery/git_tree_projection.py +450 -0
- harnessix/delivery/git_workspace_snapshot.py +27 -0
- harnessix/delivery/path_case.py +156 -0
- harnessix/delivery/planner.py +316 -0
- harnessix/delivery/planner_v2.py +93 -0
- harnessix/delivery/preserved_mode_contracts.py +182 -0
- harnessix/delivery/review_jsonl.py +37 -0
- harnessix/delivery/rollback_action.py +296 -0
- harnessix/delivery/store.py +526 -0
- harnessix/delivery/transaction_action_executor.py +153 -0
- harnessix/delivery/trusted_action.py +614 -0
- harnessix/delivery/trusted_action_contracts.py +379 -0
- harnessix/delivery/windows_filesystem.py +244 -0
- harnessix/delivery/windows_io.py +29 -0
- harnessix/delivery/windows_metadata.py +95 -0
- harnessix/delivery/workspace_cas_io.py +80 -0
- harnessix/delivery/workspace_patch_compact.py +75 -0
- harnessix/delivery/workspace_patch_errors.py +81 -0
- harnessix/delivery/workspace_record_codec.py +334 -0
- harnessix/delivery/workspace_record_contracts.py +46 -0
- harnessix/delivery/workspace_record_v3_contracts.py +18 -0
- harnessix/delivery/workspace_store_schema.py +104 -0
- harnessix/delivery/workspace_v2_contracts.py +82 -0
- harnessix/domain/__init__.py +1 -0
- harnessix/domain/artifact_pagination.py +25 -0
- harnessix/domain/errors.py +15 -0
- harnessix/domain/file_lock.py +31 -0
- harnessix/domain/models.py +161 -0
- harnessix/domain/public_output_schema.py +255 -0
- harnessix/domain/review_text.py +90 -0
- harnessix/evals/__init__.py +318 -0
- harnessix/evals/_historical_check.py +131 -0
- harnessix/evals/campaign.py +177 -0
- harnessix/evals/campaign_cli.py +84 -0
- harnessix/evals/campaign_contracts.py +260 -0
- harnessix/evals/campaign_execution.py +425 -0
- harnessix/evals/campaign_execution_contracts.py +161 -0
- harnessix/evals/catalog.py +142 -0
- harnessix/evals/checks.py +210 -0
- harnessix/evals/cli_config.py +33 -0
- harnessix/evals/compaction.py +86 -0
- harnessix/evals/compaction_contracts.py +131 -0
- harnessix/evals/contracts.py +464 -0
- harnessix/evals/delivery.py +937 -0
- harnessix/evals/delivery_contracts.py +241 -0
- harnessix/evals/execution_fs.py +67 -0
- harnessix/evals/git_evidence.py +66 -0
- harnessix/evals/grader.py +511 -0
- harnessix/evals/materializer.py +391 -0
- harnessix/evals/provider_suite_cli.py +149 -0
- harnessix/evals/provider_suite_contracts.py +197 -0
- harnessix/evals/provider_suite_evidence.py +199 -0
- harnessix/evals/provider_suite_execution.py +222 -0
- harnessix/evals/report.py +383 -0
- harnessix/evals/run_state.py +97 -0
- harnessix/evals/runner.py +669 -0
- harnessix/evals/suite.py +231 -0
- harnessix/evals/suite_contracts.py +398 -0
- harnessix/evals/suite_execution.py +578 -0
- harnessix/evals/suite_execution_contracts.py +178 -0
- harnessix/evals/task_pack.py +229 -0
- harnessix/evals/task_pack_contracts.py +418 -0
- harnessix/evals/task_pack_execution.py +473 -0
- harnessix/evals/task_pack_materializer.py +510 -0
- harnessix/evals/task_pack_observations.py +125 -0
- harnessix/evals/task_pack_publication.py +264 -0
- harnessix/evals/task_pack_suite.py +179 -0
- harnessix/evals/task_pack_trial.py +631 -0
- harnessix/evals/taskpacks/engineering-v1/archives/agents-utils-benchmark.tar +0 -0
- harnessix/evals/taskpacks/engineering-v1/archives/langchain-utils-benchmark.tar +0 -0
- harnessix/evals/taskpacks/engineering-v1/archives/opencode-utils-benchmark.tar +0 -0
- harnessix/evals/taskpacks/engineering-v1/manifest.json +715 -0
- harnessix/evals/taskpacks/engineering-v2/archives/agents-utils-benchmark.tar +0 -0
- harnessix/evals/taskpacks/engineering-v2/archives/langchain-utils-benchmark.tar +0 -0
- harnessix/evals/taskpacks/engineering-v2/archives/opencode-utils-benchmark.tar +0 -0
- harnessix/evals/taskpacks/engineering-v2/manifest.json +715 -0
- harnessix/evals/taskpacks/v1/archives/javascript-slug.tar +0 -0
- harnessix/evals/taskpacks/v1/archives/python-mathbox.tar +0 -0
- harnessix/evals/taskpacks/v1/manifest.json +187 -0
- harnessix/exec_cli.py +476 -0
- harnessix/execution/__init__.py +1 -0
- harnessix/execution/contracts.py +242 -0
- harnessix/execution/planner.py +346 -0
- harnessix/execution/public_tool_contracts.py +176 -0
- harnessix/execution/store.py +281 -0
- harnessix/execution/versioned_contracts.py +13 -0
- harnessix/file_lock.py +7 -0
- harnessix/hooks/__init__.py +39 -0
- harnessix/hooks/contracts.py +497 -0
- harnessix/hooks/runtime.py +330 -0
- harnessix/hooks/store.py +406 -0
- harnessix/licensing.py +20 -0
- harnessix/mcp/__init__.py +49 -0
- harnessix/mcp/actions.py +267 -0
- harnessix/mcp/contracts.py +173 -0
- harnessix/mcp/host_target.py +87 -0
- harnessix/mcp/runtime.py +619 -0
- harnessix/mcp/schema.py +181 -0
- harnessix/mcp/server.py +258 -0
- harnessix/mcp/startup.py +59 -0
- harnessix/mcp/store.py +384 -0
- harnessix/mcp/target_protocol.py +35 -0
- harnessix/models/__init__.py +1 -0
- harnessix/models/_anthropic_http.py +72 -0
- harnessix/models/_anthropic_mapping.py +127 -0
- harnessix/models/_anthropic_stream.py +285 -0
- harnessix/models/_billing.py +27 -0
- harnessix/models/_bounded_http.py +136 -0
- harnessix/models/_chat_errors.py +123 -0
- harnessix/models/_chat_input_anchor.py +83 -0
- harnessix/models/_chat_mapping.py +180 -0
- harnessix/models/_chat_stream.py +325 -0
- harnessix/models/_history.py +196 -0
- harnessix/models/_json.py +69 -0
- harnessix/models/_provider_io.py +80 -0
- harnessix/models/_tool_schema.py +63 -0
- harnessix/models/anthropic.py +233 -0
- harnessix/models/billing.py +40 -0
- harnessix/models/config.py +199 -0
- harnessix/models/contracts.py +175 -0
- harnessix/models/costs.py +480 -0
- harnessix/models/openai_chat.py +347 -0
- harnessix/models/pricing.py +114 -0
- harnessix/models/proxy.py +78 -0
- harnessix/models/scripted.py +60 -0
- harnessix/models/tool_result_text.py +264 -0
- harnessix/observability/__init__.py +43 -0
- harnessix/observability/core.py +130 -0
- harnessix/observability/logging.py +78 -0
- harnessix/observability/opentelemetry.py +171 -0
- harnessix/patches/__init__.py +1 -0
- harnessix/patches/agent_bridge.py +355 -0
- harnessix/patches/batch_agent_bridge.py +468 -0
- harnessix/patches/batch_approval_contracts.py +88 -0
- harnessix/patches/batch_bridge_contracts.py +101 -0
- harnessix/patches/batch_contracts.py +60 -0
- harnessix/patches/batch_execution.py +159 -0
- harnessix/patches/batch_ledger.py +169 -0
- harnessix/patches/batch_run_contracts.py +94 -0
- harnessix/patches/batch_run_migrations.py +21 -0
- harnessix/patches/batch_runs.py +94 -0
- harnessix/patches/batches.py +82 -0
- harnessix/patches/bridge_contracts.py +57 -0
- harnessix/patches/contracts.py +107 -0
- harnessix/patches/diff.py +82 -0
- harnessix/patches/diff_contracts.py +92 -0
- harnessix/patches/diff_document.py +122 -0
- harnessix/patches/diff_document_contracts.py +164 -0
- harnessix/patches/ledger.py +218 -0
- harnessix/patches/ledger_migrations.py +26 -0
- harnessix/patches/managed.py +599 -0
- harnessix/patches/managed_batches.py +155 -0
- harnessix/patches/managed_contracts.py +66 -0
- harnessix/patches/managed_io.py +160 -0
- harnessix/patches/planner.py +229 -0
- harnessix/processes/__init__.py +1 -0
- harnessix/processes/bridge_contracts.py +125 -0
- harnessix/processes/capture.py +84 -0
- harnessix/processes/contracts.py +92 -0
- harnessix/processes/git_observation.py +79 -0
- harnessix/processes/git_read_windows.py +372 -0
- harnessix/processes/output_artifact.py +200 -0
- harnessix/processes/owner_output.py +167 -0
- harnessix/processes/owner_protocol.py +213 -0
- harnessix/processes/owner_receipt.py +415 -0
- harnessix/processes/posix_owner.py +548 -0
- harnessix/processes/public_output.py +219 -0
- harnessix/processes/receipt_projection.py +88 -0
- harnessix/processes/runtime.py +335 -0
- harnessix/processes/state_directory.py +41 -0
- harnessix/processes/supervision_contracts.py +264 -0
- harnessix/processes/supervision_planner.py +264 -0
- harnessix/processes/supervision_store.py +250 -0
- harnessix/processes/supervisor.py +728 -0
- harnessix/processes/supervisor_capabilities.py +116 -0
- harnessix/processes/test_contracts.py +44 -0
- harnessix/processes/trusted_output.py +514 -0
- harnessix/processes/windows_conpty.py +432 -0
- harnessix/processes/windows_job.py +177 -0
- harnessix/processes/windows_owner.py +474 -0
- harnessix/processes/windows_owner_observation.py +21 -0
- harnessix/processes/windows_receipt.py +101 -0
- harnessix/product_config/__init__.py +56 -0
- harnessix/product_config/action_catalog.py +146 -0
- harnessix/product_config/action_codec.py +122 -0
- harnessix/product_config/action_composition.py +628 -0
- harnessix/product_config/action_contracts.py +610 -0
- harnessix/product_config/action_diagnostics.py +173 -0
- harnessix/product_config/action_owner.py +40 -0
- harnessix/product_config/action_recovery.py +148 -0
- harnessix/product_config/action_runtime.py +502 -0
- harnessix/product_config/action_runtime_types.py +16 -0
- harnessix/product_config/action_store.py +522 -0
- harnessix/product_config/agent_context.py +557 -0
- harnessix/product_config/cli.py +126 -0
- harnessix/product_config/codec.py +181 -0
- harnessix/product_config/coding_closure_budget.py +48 -0
- harnessix/product_config/coding_scratch.py +18 -0
- harnessix/product_config/coding_test_outcomes.py +72 -0
- harnessix/product_config/coding_tool_view.py +895 -0
- harnessix/product_config/context_budget.py +106 -0
- harnessix/product_config/contracts.py +602 -0
- harnessix/product_config/endpoint_probe.py +155 -0
- harnessix/product_config/errors.py +5 -0
- harnessix/product_config/eval_action.py +210 -0
- harnessix/product_config/eval_process.py +331 -0
- harnessix/product_config/extension_composition.py +69 -0
- harnessix/product_config/git_approval_history_projection.py +472 -0
- harnessix/product_config/git_approval_history_proof.py +201 -0
- harnessix/product_config/git_baseline.py +355 -0
- harnessix/product_config/git_baseline_contracts.py +70 -0
- harnessix/product_config/git_business_associations.py +310 -0
- harnessix/product_config/git_business_snapshot.py +48 -0
- harnessix/product_config/git_business_snapshot_contracts.py +102 -0
- harnessix/product_config/git_business_snapshot_wire.py +211 -0
- harnessix/product_config/git_checkpoint_materials.py +287 -0
- harnessix/product_config/git_checkpoint_preparation.py +599 -0
- harnessix/product_config/git_checkpoint_scope.py +355 -0
- harnessix/product_config/git_decision_link_contracts.py +200 -0
- harnessix/product_config/git_decision_link_ledger.py +188 -0
- harnessix/product_config/git_decision_link_rows.py +138 -0
- harnessix/product_config/git_decision_link_sources.py +184 -0
- harnessix/product_config/git_decision_link_wire.py +78 -0
- harnessix/product_config/git_decision_recovery.py +252 -0
- harnessix/product_config/git_delivery_core_store.py +222 -0
- harnessix/product_config/git_delivery_observed_contracts.py +137 -0
- harnessix/product_config/git_delivery_observed_wire.py +41 -0
- harnessix/product_config/git_delivery_plan_contracts.py +293 -0
- harnessix/product_config/git_delivery_plan_materials.py +142 -0
- harnessix/product_config/git_delivery_plan_snapshot.py +180 -0
- harnessix/product_config/git_delivery_plan_validation.py +106 -0
- harnessix/product_config/git_delivery_plan_wire.py +188 -0
- harnessix/product_config/git_delivery_process.py +595 -0
- harnessix/product_config/git_delivery_review.py +330 -0
- harnessix/product_config/git_delivery_review_codec.py +209 -0
- harnessix/product_config/git_delivery_review_contracts.py +80 -0
- harnessix/product_config/git_delivery_review_host.py +275 -0
- harnessix/product_config/git_delivery_route_core.py +81 -0
- harnessix/product_config/git_delivery_source.py +464 -0
- harnessix/product_config/git_material_process.py +481 -0
- harnessix/product_config/git_native_control.py +114 -0
- harnessix/product_config/git_parent_contracts.py +25 -0
- harnessix/product_config/git_prefix_catalog.py +103 -0
- harnessix/product_config/git_prefix_reader.py +120 -0
- harnessix/product_config/git_prefix_records.py +154 -0
- harnessix/product_config/git_prefix_rows.py +113 -0
- harnessix/product_config/git_prefix_sql.py +290 -0
- harnessix/product_config/git_prefix_writer.py +319 -0
- harnessix/product_config/git_prepared_approval_history.py +364 -0
- harnessix/product_config/git_prepared_link_connection.py +274 -0
- harnessix/product_config/git_prepared_link_contracts.py +73 -0
- harnessix/product_config/git_prepared_link_ledger.py +424 -0
- harnessix/product_config/git_prepared_link_observation.py +175 -0
- harnessix/product_config/git_prepared_link_proof.py +326 -0
- harnessix/product_config/git_prepared_link_rows.py +99 -0
- harnessix/product_config/git_prepared_link_wire.py +76 -0
- harnessix/product_config/git_prepared_native_identity.py +151 -0
- harnessix/product_config/git_prepared_runtime_thread.py +274 -0
- harnessix/product_config/git_process_host.py +170 -0
- harnessix/product_config/git_repository_observation.py +128 -0
- harnessix/product_config/git_review_identity.py +182 -0
- harnessix/product_config/git_user_authority.py +136 -0
- harnessix/product_config/git_user_observation.py +591 -0
- harnessix/product_config/git_user_observation_contracts.py +83 -0
- harnessix/product_config/git_user_observation_paths.py +141 -0
- harnessix/product_config/git_user_source_files.py +350 -0
- harnessix/product_config/git_user_source_scope.py +90 -0
- harnessix/product_config/host_process_action.py +254 -0
- harnessix/product_config/mcp_composition.py +163 -0
- harnessix/product_config/mcp_config.py +216 -0
- harnessix/product_config/mcp_status.py +108 -0
- harnessix/product_config/mcp_trust.py +60 -0
- harnessix/product_config/migration.py +200 -0
- harnessix/product_config/native_process.py +608 -0
- harnessix/product_config/native_sandbox.py +269 -0
- harnessix/product_config/native_shells.py +65 -0
- harnessix/product_config/preflight.py +123 -0
- harnessix/product_config/preflight_actions.py +218 -0
- harnessix/product_config/preflight_configuration.py +337 -0
- harnessix/product_config/preflight_environment.py +316 -0
- harnessix/product_config/preflight_support.py +83 -0
- harnessix/product_config/private_json.py +22 -0
- harnessix/product_config/process_action.py +766 -0
- harnessix/product_config/process_command.py +137 -0
- harnessix/product_config/process_profile.py +382 -0
- harnessix/product_config/product_contracts.py +197 -0
- harnessix/product_config/runtime.py +457 -0
- harnessix/product_config/sandbox_approval.py +46 -0
- harnessix/product_config/server.py +524 -0
- harnessix/product_config/session_key.py +55 -0
- harnessix/product_config/session_key_codec.py +40 -0
- harnessix/product_config/session_key_dpapi.py +64 -0
- harnessix/product_config/session_key_posix.py +221 -0
- harnessix/product_config/session_key_store.py +27 -0
- harnessix/product_config/session_key_windows.py +104 -0
- harnessix/product_config/session_key_windows_files.py +185 -0
- harnessix/product_config/session_key_windows_security.py +29 -0
- harnessix/product_config/skill_composition.py +120 -0
- harnessix/product_config/skill_diagnostics.py +62 -0
- harnessix/product_config/state_backup.py +420 -0
- harnessix/product_config/state_backup_cli.py +99 -0
- harnessix/product_config/state_backup_contracts.py +122 -0
- harnessix/product_config/state_backup_files.py +494 -0
- harnessix/product_config/state_backup_records.py +328 -0
- harnessix/product_config/state_backup_v2_contracts.py +125 -0
- harnessix/product_config/state_backup_v2_validation.py +179 -0
- harnessix/product_config/state_backup_validation.py +291 -0
- harnessix/product_config/state_backup_windows.py +54 -0
- harnessix/product_config/state_owner.py +154 -0
- harnessix/product_config/state_owner_posix.py +67 -0
- harnessix/product_config/state_owner_windows.py +71 -0
- harnessix/product_config/state_restore.py +145 -0
- harnessix/product_config/state_restore_contracts.py +84 -0
- harnessix/product_config/state_restore_flow.py +174 -0
- harnessix/product_config/state_restore_journal.py +160 -0
- harnessix/product_config/state_restore_prepare.py +130 -0
- harnessix/product_config/store.py +502 -0
- harnessix/product_config/task_dependencies.py +238 -0
- harnessix/product_config/wizard.py +481 -0
- harnessix/product_config/workspace_patch_review.py +163 -0
- harnessix/product_config/workspace_patch_source.py +138 -0
- harnessix/product_config/workspace_patch_source_contracts.py +80 -0
- harnessix/product_config/workspace_rollback.py +89 -0
- harnessix/product_config/zero_config.py +115 -0
- harnessix/product_ui/__init__.py +122 -0
- harnessix/product_ui/app.py +240 -0
- harnessix/product_ui/approval_automation.py +75 -0
- harnessix/product_ui/cli.py +600 -0
- harnessix/product_ui/contracts.py +134 -0
- harnessix/product_ui/controller.py +591 -0
- harnessix/product_ui/cost_estimate.py +93 -0
- harnessix/product_ui/data_cli.py +275 -0
- harnessix/product_ui/diff_view.py +45 -0
- harnessix/product_ui/error_help.py +147 -0
- harnessix/product_ui/errors.py +13 -0
- harnessix/product_ui/git_detection.py +36 -0
- harnessix/product_ui/interaction_presenter.py +85 -0
- harnessix/product_ui/interaction_screens.py +287 -0
- harnessix/product_ui/interaction_service.py +316 -0
- harnessix/product_ui/interactions.py +395 -0
- harnessix/product_ui/main_view.py +164 -0
- harnessix/product_ui/mcp_cli.py +94 -0
- harnessix/product_ui/preflight_text.py +95 -0
- harnessix/product_ui/projection.py +267 -0
- harnessix/product_ui/rendering.py +124 -0
- harnessix/product_ui/session.py +345 -0
- harnessix/product_ui/skills_cli.py +22 -0
- harnessix/product_ui/state_file.py +226 -0
- harnessix/product_ui/state_store.py +180 -0
- harnessix/product_ui/thread_selection.py +55 -0
- harnessix/product_ui/tool_summary.py +105 -0
- harnessix/product_ui/turn_budget.py +36 -0
- harnessix/product_ui/workspace_trust.py +95 -0
- harnessix/protocol/__init__.py +94 -0
- harnessix/protocol/artifact_limits.py +11 -0
- harnessix/protocol/codec.py +94 -0
- harnessix/protocol/compatibility.py +30 -0
- harnessix/protocol/contracts.py +656 -0
- harnessix/protocol/projection.py +352 -0
- harnessix/protocol/requests.py +253 -0
- harnessix/sandbox/__init__.py +1 -0
- harnessix/sandbox/bubblewrap.py +222 -0
- harnessix/sandbox/capabilities.py +346 -0
- harnessix/sandbox/container.py +629 -0
- harnessix/sandbox/contracts.py +305 -0
- harnessix/sandbox/egress.py +297 -0
- harnessix/sandbox/native_contracts.py +199 -0
- harnessix/sandbox/native_policy.py +415 -0
- harnessix/sandbox/native_probe.py +187 -0
- harnessix/sandbox/network.py +149 -0
- harnessix/sandbox/network_isolation.py +82 -0
- harnessix/sandbox/planner.py +102 -0
- harnessix/sandbox/process_runtime.py +289 -0
- harnessix/sandbox/seatbelt.py +106 -0
- harnessix/sandbox/store.py +108 -0
- harnessix/sandbox/workspace_snapshot.py +51 -0
- harnessix/sdk/__init__.py +17 -0
- harnessix/sdk/agent_client.py +406 -0
- harnessix/sdk/errors.py +22 -0
- harnessix/sdk/request.py +82 -0
- harnessix/sdk/response.py +119 -0
- harnessix/sdk/subprocess.py +349 -0
- harnessix/secrets/__init__.py +1 -0
- harnessix/secrets/guard.py +79 -0
- harnessix/secrets/provider.py +160 -0
- harnessix/secrets/publication.py +364 -0
- harnessix/secrets/redaction.py +92 -0
- harnessix/secrets/text_publication.py +70 -0
- harnessix/session/__init__.py +1 -0
- harnessix/session/capacity.py +277 -0
- harnessix/session/errors.py +31 -0
- harnessix/session/event_body_refs.py +16 -0
- harnessix/session/git_prefix_contracts.py +82 -0
- harnessix/session/git_prefix_publication.py +97 -0
- harnessix/session/git_publication_contracts.py +81 -0
- harnessix/session/maintenance.py +231 -0
- harnessix/session/maintenance_backup.py +209 -0
- harnessix/session/maintenance_contracts.py +154 -0
- harnessix/session/maintenance_execution.py +235 -0
- harnessix/session/maintenance_io.py +64 -0
- harnessix/session/maintenance_planning.py +222 -0
- harnessix/session/maintenance_records.py +248 -0
- harnessix/session/maintenance_restore.py +77 -0
- harnessix/session/migrations/0001_initial.sql +13 -0
- harnessix/session/migrations/0002_projection_version.sql +1 -0
- harnessix/session/migrations/0003_semantic_contract.sql +2 -0
- harnessix/session/migrations/0004_model_attempts.sql +2 -0
- harnessix/session/migrations/0005_response_billing.sql +2 -0
- harnessix/session/migrations/0006_artifacts.sql +16 -0
- harnessix/session/migrations/0007_managed_patch.sql +3 -0
- harnessix/session/migrations/0008_managed_patch_batch.sql +3 -0
- harnessix/session/migrations/0009_batch_diff_artifacts.sql +24 -0
- harnessix/session/migrations/0010_agent_process_projection.sql +2 -0
- harnessix/session/migrations/0011_process_output_artifacts.sql +23 -0
- harnessix/session/migrations/0012_context_inspection.sql +2 -0
- harnessix/session/migrations/0013_context_sources.sql +2 -0
- harnessix/session/migrations/0014_context_source_consistency.sql +2 -0
- harnessix/session/migrations/0015_tool_result_model_view.sql +2 -0
- harnessix/session/migrations/0016_compaction_attempt_ledger.sql +2 -0
- harnessix/session/migrations/0017_compaction_window.sql +2 -0
- harnessix/session/migrations/0018_thread_lifecycle.sql +2 -0
- harnessix/session/migrations/0019_turn_retry.sql +2 -0
- harnessix/session/migrations/0020_protocol_requests.sql +15 -0
- harnessix/session/migrations/0021_deferred_turn_execution.sql +2 -0
- harnessix/session/migrations/0022_interactive_turns.sql +2 -0
- harnessix/session/migrations/0023_trusted_action_gateway.sql +2 -0
- harnessix/session/migrations/0024_trusted_action_review_artifacts.sql +25 -0
- harnessix/session/migrations/0025_trusted_action_output_artifacts.sql +26 -0
- harnessix/session/migrations/0026_store_maintenance.sql +30 -0
- harnessix/session/migrations/0027_thread_list_lookup.sql +4 -0
- harnessix/session/migrations/0028_artifact_publication_proof.sql +7 -0
- harnessix/session/migrations/0029_authenticated_session_history.sql +14 -0
- harnessix/session/migrations/0030_authenticated_artifact_body.sql +3 -0
- harnessix/session/migrations/0031_unknown_tool_rejection.sql +2 -0
- harnessix/session/migrations/0032_tool_result_working_set.sql +2 -0
- harnessix/session/migrations/__init__.py +1 -0
- harnessix/session/ports.py +45 -0
- harnessix/session/publication_seal.py +254 -0
- harnessix/session/sqlite.py +622 -0
- harnessix/session/sqlite_append.py +95 -0
- harnessix/session/sqlite_history.py +173 -0
- harnessix/session/sqlite_publication.py +373 -0
- harnessix/session/store_publication.py +438 -0
- harnessix/session/verified_prefix_cache.py +60 -0
- harnessix/skills/__init__.py +42 -0
- harnessix/skills/actions.py +386 -0
- harnessix/skills/contracts.py +253 -0
- harnessix/skills/prompt.py +38 -0
- harnessix/skills/runtime.py +644 -0
- harnessix/skills/store.py +276 -0
- harnessix/smoke/__init__.py +1 -0
- harnessix/smoke/cli.py +72 -0
- harnessix/smoke/contracts.py +133 -0
- harnessix/smoke/runner.py +237 -0
- harnessix/sqlite_readonly.py +18 -0
- harnessix/tools/__init__.py +1 -0
- harnessix/tools/argument_feedback.py +420 -0
- harnessix/tools/argument_repair.py +214 -0
- harnessix/tools/contracts.py +289 -0
- harnessix/tools/definition_view.py +275 -0
- harnessix/tools/files.py +318 -0
- harnessix/tools/git.py +533 -0
- harnessix/tools/git_contracts.py +98 -0
- harnessix/tools/grep_matcher.py +93 -0
- harnessix/tools/patterns.py +46 -0
- harnessix/tools/read_backend.py +65 -0
- harnessix/tools/read_catalog.py +358 -0
- harnessix/tools/runtime.py +504 -0
- harnessix/tools/search.py +582 -0
- harnessix/tools/search_contracts.py +279 -0
- harnessix/tools/windows_file_read.py +215 -0
- harnessix/tools/windows_read.py +92 -0
- harnessix/tools/windows_read_port.py +174 -0
- harnessix/tools/windows_search.py +425 -0
- harnessix/tools/workspace.py +295 -0
- harnessix/trusted_actions/__init__.py +37 -0
- harnessix/trusted_actions/agent_gateway.py +135 -0
- harnessix/trusted_actions/agent_gateway_invocation.py +63 -0
- harnessix/trusted_actions/agent_gateway_output.py +437 -0
- harnessix/trusted_actions/agent_gateway_support.py +608 -0
- harnessix/trusted_actions/agent_preplanning.py +119 -0
- harnessix/trusted_actions/builtin_success.py +125 -0
- harnessix/trusted_actions/composite_gateway.py +93 -0
- harnessix/trusted_actions/contracts.py +336 -0
- harnessix/trusted_actions/legacy_projection.py +103 -0
- harnessix/trusted_actions/operation_router.py +243 -0
- harnessix/trusted_actions/operation_store.py +322 -0
- harnessix/trusted_actions/outcome_validation.py +99 -0
- harnessix/trusted_actions/output_budget.py +129 -0
- harnessix/trusted_actions/ownership_store.py +150 -0
- harnessix/trusted_actions/planning.py +400 -0
- harnessix/trusted_actions/policy.py +135 -0
- harnessix/trusted_actions/preparation_rejection.py +177 -0
- harnessix/trusted_actions/prepared_resolution.py +115 -0
- harnessix/trusted_actions/public_errors.py +198 -0
- harnessix/trusted_actions/public_outcomes.py +484 -0
- harnessix/trusted_actions/recovery_contracts.py +101 -0
- harnessix/trusted_actions/router.py +496 -0
- harnessix/trusted_actions/store.py +490 -0
- harnessix/trusted_actions/transition_store.py +143 -0
- harnessix/trusted_actions/versioned_contracts.py +20 -0
- harnessix/workspace/__init__.py +1 -0
- harnessix/workspace/blob_read_control.py +55 -0
- harnessix/workspace/contracts.py +104 -0
- harnessix/workspace/git_windows_binding.py +98 -0
- harnessix/workspace/leases.py +160 -0
- harnessix/workspace/native_observation_io.py +71 -0
- harnessix/workspace/parent_closure_codec.py +286 -0
- harnessix/workspace/parent_closure_contracts.py +93 -0
- harnessix/workspace/parent_closure_paths.py +106 -0
- harnessix/workspace/parent_closure_wire.py +41 -0
- harnessix/workspace/paths.py +59 -0
- harnessix/workspace/snapshot.py +455 -0
- harnessix/workspace/snapshot_capture.py +267 -0
- harnessix/workspace/snapshot_contracts.py +73 -0
- harnessix/workspace/snapshot_fields.py +80 -0
- harnessix/workspace/snapshot_ports.py +73 -0
- harnessix/workspace/snapshot_v2.py +134 -0
- harnessix/workspace/snapshot_verification.py +45 -0
- harnessix/workspace/terminal_read_control.py +112 -0
- harnessix/workspace/windows.py +478 -0
- harnessix/workspace/windows_file_io.py +223 -0
- harnessix/workspace/windows_private_directory.py +55 -0
- harnessix/workspace/windows_private_security.py +217 -0
- harnessix-0.10.0b3.dist-info/METADATA +117 -0
- harnessix-0.10.0b3.dist-info/RECORD +653 -0
- harnessix-0.10.0b3.dist-info/WHEEL +4 -0
- harnessix-0.10.0b3.dist-info/entry_points.txt +2 -0
- harnessix-0.10.0b3.dist-info/licenses/LICENSE +235 -0
harnessix/__init__.py
ADDED
harnessix/__main__.py
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"""供应商无关的 Agent Runtime Kernel。"""
|
|
@@ -0,0 +1,365 @@
|
|
|
1
|
+
"""持久Agent状态机:校验审批请求指纹、有效期与决策绑定。"""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
import hashlib
|
|
6
|
+
import json
|
|
7
|
+
from datetime import timedelta
|
|
8
|
+
from uuid import UUID, uuid5
|
|
9
|
+
|
|
10
|
+
from pydantic import ValidationError
|
|
11
|
+
|
|
12
|
+
from harnessix.agent.errors import KernelError
|
|
13
|
+
from harnessix.agent.models import (
|
|
14
|
+
ApprovalContent,
|
|
15
|
+
ApprovalRequestContent,
|
|
16
|
+
Item,
|
|
17
|
+
PatchApprovalRequestContent,
|
|
18
|
+
PatchBatchApprovalRequestContent,
|
|
19
|
+
ProcessApprovalRequestContent,
|
|
20
|
+
Thread,
|
|
21
|
+
ToolCallContent,
|
|
22
|
+
ToolResultContent,
|
|
23
|
+
TrustedActionApprovalRequestContent,
|
|
24
|
+
Turn,
|
|
25
|
+
)
|
|
26
|
+
from harnessix.domain.models import (
|
|
27
|
+
ApprovalDecision,
|
|
28
|
+
ApprovalOutcome,
|
|
29
|
+
EffectClass,
|
|
30
|
+
ToolDescriptor,
|
|
31
|
+
utc_now,
|
|
32
|
+
)
|
|
33
|
+
from harnessix.patches.batch_bridge_contracts import ManagedPatchBatchCallPlan
|
|
34
|
+
from harnessix.patches.batch_contracts import PatchBatchProposal
|
|
35
|
+
from harnessix.patches.bridge_contracts import ManagedPatchCallPlan
|
|
36
|
+
from harnessix.patches.contracts import PatchProposal
|
|
37
|
+
from harnessix.processes.bridge_contracts import PROCESS_AGENT_FRONTENDS, AgentProcessCallPlan
|
|
38
|
+
from harnessix.processes.contracts import ProcessRequest
|
|
39
|
+
from harnessix.processes.test_contracts import RunTestsInput
|
|
40
|
+
from harnessix.tools.workspace import digest
|
|
41
|
+
|
|
42
|
+
READ_ONLY_POLICY_VERSION = "kernel-read-only/v1"
|
|
43
|
+
_TRUSTED_ACTION_NAMESPACE = UUID("f5cc2cc0-5b13-4f37-bd6e-7b3111b10c03")
|
|
44
|
+
|
|
45
|
+
|
|
46
|
+
def _fingerprint(value: object) -> str:
|
|
47
|
+
return hashlib.sha256(
|
|
48
|
+
json.dumps(
|
|
49
|
+
value, sort_keys=True, separators=(",", ":"), ensure_ascii=False, allow_nan=False
|
|
50
|
+
).encode()
|
|
51
|
+
).hexdigest()
|
|
52
|
+
|
|
53
|
+
|
|
54
|
+
def tool_fingerprint(definition: ToolDescriptor) -> str:
|
|
55
|
+
return _fingerprint(definition.model_dump(mode="json"))
|
|
56
|
+
|
|
57
|
+
|
|
58
|
+
def request_fingerprint(
|
|
59
|
+
thread: Thread,
|
|
60
|
+
turn: Turn,
|
|
61
|
+
call: ToolCallContent,
|
|
62
|
+
*,
|
|
63
|
+
policy_version: str = READ_ONLY_POLICY_VERSION,
|
|
64
|
+
) -> str:
|
|
65
|
+
"""绑定当前只读契约;不是 Workspace 内容哈希或未来的 OS 授权凭证。"""
|
|
66
|
+
return execution_fingerprint(
|
|
67
|
+
thread.thread_id, turn.turn_id, thread.workspace, call, policy_version=policy_version
|
|
68
|
+
)
|
|
69
|
+
|
|
70
|
+
|
|
71
|
+
def execution_fingerprint(
|
|
72
|
+
thread_id: UUID,
|
|
73
|
+
turn_id: UUID,
|
|
74
|
+
workspace: str,
|
|
75
|
+
call: ToolCallContent,
|
|
76
|
+
*,
|
|
77
|
+
policy_version: str = READ_ONLY_POLICY_VERSION,
|
|
78
|
+
) -> str:
|
|
79
|
+
"""审批和进程内作用域共享同一摘要格式,不引入第二套权限。"""
|
|
80
|
+
return _fingerprint(
|
|
81
|
+
{
|
|
82
|
+
"policy": policy_version,
|
|
83
|
+
"thread_id": str(thread_id),
|
|
84
|
+
"turn_id": str(turn_id),
|
|
85
|
+
"workspace": workspace,
|
|
86
|
+
"call": call.model_dump(mode="json"),
|
|
87
|
+
}
|
|
88
|
+
)
|
|
89
|
+
|
|
90
|
+
|
|
91
|
+
def trusted_action_invocation_id(
|
|
92
|
+
thread_id: UUID,
|
|
93
|
+
turn_id: UUID,
|
|
94
|
+
call: ToolCallContent,
|
|
95
|
+
) -> UUID:
|
|
96
|
+
"""从持久调用身份导出稳定Plan ID,重启不得产生第二个副作用计划。"""
|
|
97
|
+
|
|
98
|
+
if call.tool_fingerprint is None:
|
|
99
|
+
raise ValueError("Trusted Action调用缺少Tool Fingerprint")
|
|
100
|
+
return uuid5(
|
|
101
|
+
_TRUSTED_ACTION_NAMESPACE,
|
|
102
|
+
f"{thread_id}:{turn_id}:{call.call_id}:{call.tool_fingerprint}",
|
|
103
|
+
)
|
|
104
|
+
|
|
105
|
+
|
|
106
|
+
def trusted_action_request_fingerprint(
|
|
107
|
+
thread: Thread,
|
|
108
|
+
turn: Turn,
|
|
109
|
+
call: ToolCallContent,
|
|
110
|
+
*,
|
|
111
|
+
plan_id: UUID,
|
|
112
|
+
plan_fingerprint: str,
|
|
113
|
+
execution_fingerprint: str,
|
|
114
|
+
policy_id: str,
|
|
115
|
+
policy_version: str,
|
|
116
|
+
presentation: str,
|
|
117
|
+
diff_sha256: str | None,
|
|
118
|
+
) -> str:
|
|
119
|
+
"""绑定Session归属、完整调用、Router计划及可见Review证据。"""
|
|
120
|
+
|
|
121
|
+
return _fingerprint(
|
|
122
|
+
{
|
|
123
|
+
"spec_version": "harnessix.agent-trusted-action-approval/v1",
|
|
124
|
+
"thread_id": str(thread.thread_id),
|
|
125
|
+
"turn_id": str(turn.turn_id),
|
|
126
|
+
"workspace": thread.workspace,
|
|
127
|
+
"call": call.model_dump(mode="json"),
|
|
128
|
+
"plan_id": str(plan_id),
|
|
129
|
+
"plan_fingerprint": plan_fingerprint,
|
|
130
|
+
"execution_fingerprint": execution_fingerprint,
|
|
131
|
+
"policy_id": policy_id,
|
|
132
|
+
"policy_version": policy_version,
|
|
133
|
+
"presentation": presentation,
|
|
134
|
+
"diff_sha256": diff_sha256,
|
|
135
|
+
}
|
|
136
|
+
)
|
|
137
|
+
|
|
138
|
+
|
|
139
|
+
def approval_for(turn: Turn, call: ToolCallContent) -> Item | None:
|
|
140
|
+
return next(
|
|
141
|
+
(
|
|
142
|
+
item
|
|
143
|
+
for item in turn.items
|
|
144
|
+
if isinstance(item.content, ApprovalContent) and item.content.call_id == call.call_id
|
|
145
|
+
),
|
|
146
|
+
None,
|
|
147
|
+
)
|
|
148
|
+
|
|
149
|
+
|
|
150
|
+
def approval_action_id(turn: Turn, call: ToolCallContent) -> UUID | None:
|
|
151
|
+
"""返回统一Action或旧Process审批绑定的稳定执行身份。"""
|
|
152
|
+
|
|
153
|
+
item = approval_for(turn, call)
|
|
154
|
+
if item is None:
|
|
155
|
+
return None
|
|
156
|
+
if isinstance(item.content, TrustedActionApprovalRequestContent):
|
|
157
|
+
return item.content.plan_id
|
|
158
|
+
if isinstance(item.content, ProcessApprovalRequestContent):
|
|
159
|
+
return item.content.plan.action_id
|
|
160
|
+
return None
|
|
161
|
+
|
|
162
|
+
|
|
163
|
+
# 宿主以系统身份作出的决定(如本机沙箱内命令的自动批准,ADR 0113)使用该前缀。
|
|
164
|
+
SYSTEM_APPROVAL_ACTOR_PREFIX = "harnessix:"
|
|
165
|
+
|
|
166
|
+
|
|
167
|
+
def approval_was_decided(content: ApprovalContent, decision: ApprovalDecision) -> bool:
|
|
168
|
+
"""同语义决定幂等返回;冲突重放失败关闭。
|
|
169
|
+
|
|
170
|
+
系统身份已作出决定后,客户端可能在看到审批请求的瞬间再回复一次(自动批准模式或人工)。
|
|
171
|
+
结论相同时视为同一决定幂等返回;结论相反仍失败关闭。
|
|
172
|
+
"""
|
|
173
|
+
|
|
174
|
+
recorded = content.decision
|
|
175
|
+
if recorded is None:
|
|
176
|
+
return False
|
|
177
|
+
if recorded.actor.startswith(SYSTEM_APPROVAL_ACTOR_PREFIX) and (
|
|
178
|
+
recorded.outcome == decision.outcome
|
|
179
|
+
):
|
|
180
|
+
return True
|
|
181
|
+
if (recorded.outcome, recorded.actor, recorded.reason) != (
|
|
182
|
+
decision.outcome,
|
|
183
|
+
decision.actor,
|
|
184
|
+
decision.reason,
|
|
185
|
+
):
|
|
186
|
+
raise KernelError("approval_conflict", "审批已绑定其他决定")
|
|
187
|
+
return True
|
|
188
|
+
|
|
189
|
+
|
|
190
|
+
def approval_type_matches(call: ToolCallContent, content: ApprovalContent) -> bool:
|
|
191
|
+
"""校验审批投影是否适用于当前Tool前端及效果类别。"""
|
|
192
|
+
|
|
193
|
+
if not call.requires_approval:
|
|
194
|
+
return False
|
|
195
|
+
if isinstance(content, TrustedActionApprovalRequestContent):
|
|
196
|
+
return True
|
|
197
|
+
if isinstance(content, ApprovalRequestContent):
|
|
198
|
+
return call.effect_class is EffectClass.READ_ONLY
|
|
199
|
+
if call.effect_class is not EffectClass.NON_IDEMPOTENT_WRITE:
|
|
200
|
+
return False
|
|
201
|
+
if isinstance(content, ProcessApprovalRequestContent):
|
|
202
|
+
return call.tool in PROCESS_AGENT_FRONTENDS
|
|
203
|
+
expected_tool = (
|
|
204
|
+
"apply_patch_batch"
|
|
205
|
+
if isinstance(content, PatchBatchApprovalRequestContent)
|
|
206
|
+
else "apply_patch"
|
|
207
|
+
)
|
|
208
|
+
return call.tool == expected_tool
|
|
209
|
+
|
|
210
|
+
|
|
211
|
+
def validate_patch_plan(
|
|
212
|
+
thread: Thread, turn: Turn, call: ToolCallContent, plan: ManagedPatchCallPlan
|
|
213
|
+
) -> bool:
|
|
214
|
+
"""只校验事件归属和提案一致性;磁盘事实由受管桥接核对。"""
|
|
215
|
+
try:
|
|
216
|
+
checked = ManagedPatchCallPlan.model_validate_json(plan.model_dump_json())
|
|
217
|
+
proposal = PatchProposal.model_validate_json(json.dumps(call.arguments, allow_nan=False))
|
|
218
|
+
except (ValidationError, ValueError, TypeError):
|
|
219
|
+
return False
|
|
220
|
+
return (
|
|
221
|
+
call.tool == "apply_patch"
|
|
222
|
+
and call.effect_class == EffectClass.NON_IDEMPOTENT_WRITE
|
|
223
|
+
and call.requires_approval
|
|
224
|
+
and call.tool_fingerprint is not None
|
|
225
|
+
and (checked.thread_id, checked.turn_id, checked.call_id)
|
|
226
|
+
== (thread.thread_id, turn.turn_id, call.call_id)
|
|
227
|
+
and checked.call_fingerprint == request_fingerprint(thread, turn, call)
|
|
228
|
+
and checked.manifest.proposal_sha256 == _fingerprint(proposal.model_dump(mode="json"))
|
|
229
|
+
)
|
|
230
|
+
|
|
231
|
+
|
|
232
|
+
def validate_batch_plan(
|
|
233
|
+
thread: Thread, turn: Turn, call: ToolCallContent, plan: ManagedPatchBatchCallPlan
|
|
234
|
+
) -> bool:
|
|
235
|
+
try:
|
|
236
|
+
checked = ManagedPatchBatchCallPlan.model_validate_json(plan.model_dump_json())
|
|
237
|
+
proposal = PatchBatchProposal.model_validate_json(
|
|
238
|
+
json.dumps(call.arguments, allow_nan=False)
|
|
239
|
+
)
|
|
240
|
+
except (ValidationError, ValueError, TypeError):
|
|
241
|
+
return False
|
|
242
|
+
return (
|
|
243
|
+
call.tool == "apply_patch_batch"
|
|
244
|
+
and call.effect_class == EffectClass.NON_IDEMPOTENT_WRITE
|
|
245
|
+
and call.requires_approval
|
|
246
|
+
and call.tool_fingerprint is not None
|
|
247
|
+
and (checked.thread_id, checked.turn_id, checked.call_id)
|
|
248
|
+
== (thread.thread_id, turn.turn_id, call.call_id)
|
|
249
|
+
and checked.call_fingerprint == request_fingerprint(thread, turn, call)
|
|
250
|
+
and checked.backend.manifest.proposal_sha256
|
|
251
|
+
== _fingerprint(proposal.model_dump(mode="json"))
|
|
252
|
+
)
|
|
253
|
+
|
|
254
|
+
|
|
255
|
+
def validate_process_plan(
|
|
256
|
+
thread: Thread, turn: Turn, call: ToolCallContent, plan: AgentProcessCallPlan
|
|
257
|
+
) -> bool:
|
|
258
|
+
"""校验Session调用归属和公开命令摘要;Action事实由宿主桥接另行核对。"""
|
|
259
|
+
try:
|
|
260
|
+
checked = AgentProcessCallPlan.model_validate_json(plan.model_dump_json())
|
|
261
|
+
except (ValidationError, ValueError, TypeError):
|
|
262
|
+
return False
|
|
263
|
+
common = (
|
|
264
|
+
call.tool in PROCESS_AGENT_FRONTENDS
|
|
265
|
+
and call.effect_class == EffectClass.NON_IDEMPOTENT_WRITE
|
|
266
|
+
and call.requires_approval
|
|
267
|
+
and call.tool_fingerprint is not None
|
|
268
|
+
and (checked.thread_id, checked.turn_id, checked.call_id)
|
|
269
|
+
== (thread.thread_id, turn.turn_id, call.call_id)
|
|
270
|
+
and checked.workspace == thread.workspace
|
|
271
|
+
and checked.call_fingerprint == request_fingerprint(thread, turn, call)
|
|
272
|
+
)
|
|
273
|
+
if not common:
|
|
274
|
+
return False
|
|
275
|
+
if call.tool == "run_tests":
|
|
276
|
+
try:
|
|
277
|
+
RunTestsInput.model_validate_json(json.dumps(call.arguments, allow_nan=False))
|
|
278
|
+
except (ValidationError, ValueError, TypeError):
|
|
279
|
+
return False
|
|
280
|
+
return True
|
|
281
|
+
try:
|
|
282
|
+
process = ProcessRequest.model_validate_json(json.dumps(call.arguments, allow_nan=False))
|
|
283
|
+
except (ValidationError, ValueError, TypeError):
|
|
284
|
+
return False
|
|
285
|
+
return (
|
|
286
|
+
checked.action_tool_version == call.tool_version
|
|
287
|
+
and checked.program == process.program
|
|
288
|
+
and checked.arguments_sha256 == digest(process.arguments)
|
|
289
|
+
and checked.timeout_seconds == process.timeout_seconds
|
|
290
|
+
)
|
|
291
|
+
|
|
292
|
+
|
|
293
|
+
def approval_matches(
|
|
294
|
+
thread: Thread,
|
|
295
|
+
turn: Turn,
|
|
296
|
+
call: ToolCallContent,
|
|
297
|
+
content: ApprovalContent,
|
|
298
|
+
) -> bool:
|
|
299
|
+
if isinstance(content, TrustedActionApprovalRequestContent):
|
|
300
|
+
try:
|
|
301
|
+
expected_plan_id = trusted_action_invocation_id(thread.thread_id, turn.turn_id, call)
|
|
302
|
+
except ValueError:
|
|
303
|
+
return False
|
|
304
|
+
return (
|
|
305
|
+
call.requires_approval
|
|
306
|
+
and content.plan_id == expected_plan_id
|
|
307
|
+
and content.request_fingerprint
|
|
308
|
+
== trusted_action_request_fingerprint(
|
|
309
|
+
thread,
|
|
310
|
+
turn,
|
|
311
|
+
call,
|
|
312
|
+
plan_id=content.plan_id,
|
|
313
|
+
plan_fingerprint=content.plan_fingerprint,
|
|
314
|
+
execution_fingerprint=content.execution_fingerprint,
|
|
315
|
+
policy_id=content.policy_id,
|
|
316
|
+
policy_version=content.policy_version,
|
|
317
|
+
presentation=content.presentation,
|
|
318
|
+
diff_sha256=(
|
|
319
|
+
content.diff_artifact.sha256 if content.diff_artifact is not None else None
|
|
320
|
+
),
|
|
321
|
+
)
|
|
322
|
+
)
|
|
323
|
+
if isinstance(content, ProcessApprovalRequestContent):
|
|
324
|
+
return (
|
|
325
|
+
validate_process_plan(thread, turn, call, content.plan)
|
|
326
|
+
and content.request_fingerprint == content.plan.approval_fingerprint
|
|
327
|
+
)
|
|
328
|
+
if isinstance(content, PatchBatchApprovalRequestContent):
|
|
329
|
+
return (
|
|
330
|
+
validate_batch_plan(thread, turn, call, content.plan)
|
|
331
|
+
and content.request_fingerprint == content.plan.approval_fingerprint
|
|
332
|
+
)
|
|
333
|
+
if isinstance(content, PatchApprovalRequestContent):
|
|
334
|
+
return (
|
|
335
|
+
validate_patch_plan(thread, turn, call, content.plan)
|
|
336
|
+
and content.request_fingerprint == content.plan.approval_fingerprint
|
|
337
|
+
)
|
|
338
|
+
return content.request_fingerprint == request_fingerprint(
|
|
339
|
+
thread, turn, call, policy_version=content.policy_version
|
|
340
|
+
)
|
|
341
|
+
|
|
342
|
+
|
|
343
|
+
def remaining_seconds(turn: Turn) -> float:
|
|
344
|
+
# 持久墙钟截止时间:暂停、离线和重启均不刷新原 Turn 的预算。
|
|
345
|
+
return (
|
|
346
|
+
turn.created_at + timedelta(seconds=turn.budget.timeout_seconds) - utc_now()
|
|
347
|
+
).total_seconds()
|
|
348
|
+
|
|
349
|
+
|
|
350
|
+
def with_rejection_reason[ResultT](result: ResultT, approval: Item | None) -> ResultT:
|
|
351
|
+
"""用户拒绝并填写原因时附在错误信息后,模型据此调整做法,而不是只知道被拒绝。"""
|
|
352
|
+
|
|
353
|
+
if not isinstance(result, ToolResultContent) or approval is None:
|
|
354
|
+
return result
|
|
355
|
+
assert isinstance(approval.content, ApprovalContent)
|
|
356
|
+
decision, error = approval.content.decision, result.error
|
|
357
|
+
if (
|
|
358
|
+
decision is None
|
|
359
|
+
or decision.outcome != ApprovalOutcome.REJECTED
|
|
360
|
+
or not decision.reason
|
|
361
|
+
or error is None
|
|
362
|
+
):
|
|
363
|
+
return result
|
|
364
|
+
message = f"{error.message}。用户说明:{decision.reason}"[:2000]
|
|
365
|
+
return result.model_copy(update={"error": error.model_copy(update={"message": message})})
|
|
@@ -0,0 +1,143 @@
|
|
|
1
|
+
"""按已公布input_schema还原被模型字符串化的JSON容器参数;不放宽任何校验。
|
|
2
|
+
|
|
3
|
+
部分模型会把数组/对象参数序列化为JSON字符串(如``"files": "[...]"``),偶尔还遗漏末尾的
|
|
4
|
+
闭合括号。仅当Schema在该位置明确声明为array或object、且字符串可严格解析(必要时仅补齐末尾
|
|
5
|
+
缺失的闭合括号)为同类型容器时才还原;其余值原样保留,由工具原有的严格校验照旧拒绝。
|
|
6
|
+
还原后的规范参数才进入审批、审计与执行。还原先于提案阶段的结构修复(call_repair):
|
|
7
|
+
修复只认真实的数组与对象,字符串化的``files``会让它看不到外层字段与默认mode。
|
|
8
|
+
"""
|
|
9
|
+
|
|
10
|
+
from __future__ import annotations
|
|
11
|
+
|
|
12
|
+
from collections.abc import Mapping
|
|
13
|
+
from typing import Any
|
|
14
|
+
|
|
15
|
+
from pydantic import JsonValue
|
|
16
|
+
|
|
17
|
+
from harnessix.domain.models import ToolDescriptor
|
|
18
|
+
from harnessix.models._json import strict_json
|
|
19
|
+
from harnessix.models.contracts import ToolCallCompleted, ToolCallRejected
|
|
20
|
+
|
|
21
|
+
_MAX_DEPTH = 16
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
def normalize_proposal(
|
|
25
|
+
proposal: ToolCallCompleted | ToolCallRejected, definitions: Mapping[str, ToolDescriptor]
|
|
26
|
+
) -> ToolCallCompleted | ToolCallRejected:
|
|
27
|
+
"""按提案所调工具的公布Schema还原参数;未注册工具与拒绝提案原样返回。"""
|
|
28
|
+
if not isinstance(proposal, ToolCallCompleted):
|
|
29
|
+
return proposal
|
|
30
|
+
definition = definitions.get(proposal.tool)
|
|
31
|
+
if definition is None:
|
|
32
|
+
return proposal
|
|
33
|
+
normalized = normalize_stringified_containers(proposal.arguments, definition.input_schema)
|
|
34
|
+
if normalized == proposal.arguments:
|
|
35
|
+
return proposal
|
|
36
|
+
return proposal.model_copy(update={"arguments": normalized})
|
|
37
|
+
|
|
38
|
+
|
|
39
|
+
def normalize_stringified_containers(
|
|
40
|
+
arguments: dict[str, JsonValue], schema: Mapping[str, Any]
|
|
41
|
+
) -> dict[str, JsonValue]:
|
|
42
|
+
normalized = _normalize(arguments, schema, schema, 0)
|
|
43
|
+
assert isinstance(normalized, dict)
|
|
44
|
+
return normalized
|
|
45
|
+
|
|
46
|
+
|
|
47
|
+
def _normalize(
|
|
48
|
+
value: JsonValue, schema: Mapping[str, Any], root: Mapping[str, Any], depth: int
|
|
49
|
+
) -> JsonValue:
|
|
50
|
+
node = _resolve(schema, root)
|
|
51
|
+
if depth > _MAX_DEPTH or node is None:
|
|
52
|
+
return value
|
|
53
|
+
expected = _container_type(node)
|
|
54
|
+
if isinstance(value, str) and expected is not None:
|
|
55
|
+
value = _decoded(value, expected)
|
|
56
|
+
if isinstance(value, dict):
|
|
57
|
+
properties = node.get("properties")
|
|
58
|
+
if not isinstance(properties, Mapping):
|
|
59
|
+
return value
|
|
60
|
+
return {
|
|
61
|
+
key: _normalize(item, properties[key], root, depth + 1)
|
|
62
|
+
if isinstance(properties.get(key), Mapping)
|
|
63
|
+
else item
|
|
64
|
+
for key, item in value.items()
|
|
65
|
+
}
|
|
66
|
+
if isinstance(value, list):
|
|
67
|
+
items = node.get("items")
|
|
68
|
+
if not isinstance(items, Mapping):
|
|
69
|
+
return value
|
|
70
|
+
return [_normalize(item, items, root, depth + 1) for item in value]
|
|
71
|
+
return value
|
|
72
|
+
|
|
73
|
+
|
|
74
|
+
def _resolve(node: Mapping[str, Any], root: Mapping[str, Any]) -> Mapping[str, Any] | None:
|
|
75
|
+
for _ in range(_MAX_DEPTH):
|
|
76
|
+
reference = node.get("$ref")
|
|
77
|
+
if reference is None:
|
|
78
|
+
return node
|
|
79
|
+
if not isinstance(reference, str) or not reference.startswith("#/$defs/"):
|
|
80
|
+
return None
|
|
81
|
+
definitions = root.get("$defs")
|
|
82
|
+
target = (
|
|
83
|
+
definitions.get(reference.removeprefix("#/$defs/"))
|
|
84
|
+
if isinstance(definitions, Mapping)
|
|
85
|
+
else None
|
|
86
|
+
)
|
|
87
|
+
if not isinstance(target, Mapping):
|
|
88
|
+
return None
|
|
89
|
+
node = target
|
|
90
|
+
return None
|
|
91
|
+
|
|
92
|
+
|
|
93
|
+
def _container_type(node: Mapping[str, Any]) -> type | None:
|
|
94
|
+
declared = node.get("type")
|
|
95
|
+
if declared == "array":
|
|
96
|
+
return list
|
|
97
|
+
if declared == "object":
|
|
98
|
+
return dict
|
|
99
|
+
return None
|
|
100
|
+
|
|
101
|
+
|
|
102
|
+
def _decoded(text: str, expected: type) -> JsonValue:
|
|
103
|
+
candidate = text.strip()
|
|
104
|
+
for attempt in (candidate, _with_missing_closers(candidate)):
|
|
105
|
+
if attempt is None:
|
|
106
|
+
continue
|
|
107
|
+
try:
|
|
108
|
+
parsed = strict_json(attempt)
|
|
109
|
+
except ValueError:
|
|
110
|
+
continue
|
|
111
|
+
if isinstance(parsed, expected):
|
|
112
|
+
return parsed
|
|
113
|
+
return text
|
|
114
|
+
|
|
115
|
+
|
|
116
|
+
def _with_missing_closers(text: str) -> str | None:
|
|
117
|
+
"""只补齐末尾缺失的外层闭合括号:文本须以已闭合的内层容器结尾(`]`或`}`)。
|
|
118
|
+
|
|
119
|
+
不改写任何已有字符;值中途截断、未闭合字符串、多余闭合或其他语法错误一律放弃,
|
|
120
|
+
交由严格校验拒绝。
|
|
121
|
+
"""
|
|
122
|
+
if not text.endswith(("]", "}")):
|
|
123
|
+
return None
|
|
124
|
+
stack: list[str] = []
|
|
125
|
+
in_string = escaped = False
|
|
126
|
+
for character in text:
|
|
127
|
+
if in_string:
|
|
128
|
+
if escaped:
|
|
129
|
+
escaped = False
|
|
130
|
+
elif character == "\\":
|
|
131
|
+
escaped = True
|
|
132
|
+
elif character == '"':
|
|
133
|
+
in_string = False
|
|
134
|
+
elif character == '"':
|
|
135
|
+
in_string = True
|
|
136
|
+
elif character in "[{":
|
|
137
|
+
stack.append("]" if character == "[" else "}")
|
|
138
|
+
elif character in "]}":
|
|
139
|
+
if not stack or stack.pop() != character:
|
|
140
|
+
return None
|
|
141
|
+
if in_string or not stack:
|
|
142
|
+
return None
|
|
143
|
+
return text + "".join(reversed(stack))
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
"""持久Agent状态机:根据Provider观测事实结算模型尝试用量。"""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
from datetime import datetime
|
|
6
|
+
|
|
7
|
+
from harnessix.agent.errors import KernelError
|
|
8
|
+
from harnessix.agent.usage import ModelAttempt, ModelAttemptFinished, ModelUsageObserved
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
def settle_observation(
|
|
12
|
+
attempt: ModelAttempt,
|
|
13
|
+
payload: ModelUsageObserved | ModelAttemptFinished,
|
|
14
|
+
occurred_at: datetime,
|
|
15
|
+
) -> tuple[ModelAttempt, int, int]:
|
|
16
|
+
"""共享累计差额规则;用途、状态阶段、预算和身份唯一性由调用方守卫。"""
|
|
17
|
+
if attempt.attempt_id != payload.attempt_id or attempt.status != "running":
|
|
18
|
+
raise KernelError("invalid_event", "模型尝试尚未开始或已结算")
|
|
19
|
+
if isinstance(payload, ModelUsageObserved):
|
|
20
|
+
try:
|
|
21
|
+
payload.usage.validate_successor(attempt.usage)
|
|
22
|
+
billing = payload.billing if payload.billing is not None else attempt.billing
|
|
23
|
+
billing.validate_successor(attempt.billing)
|
|
24
|
+
billing.validate_usage(payload.usage)
|
|
25
|
+
except ValueError:
|
|
26
|
+
raise KernelError("invalid_event", "模型用量或计费元数据冲突") from None
|
|
27
|
+
for field in ("actual_model", "response_id"):
|
|
28
|
+
before, after = getattr(attempt, field), getattr(payload, field)
|
|
29
|
+
if before is not None and after is not None and before != after:
|
|
30
|
+
raise KernelError("invalid_event", "尝试响应身份发生变化")
|
|
31
|
+
input_delta = (payload.usage.input_tokens or 0) - (attempt.usage.input_tokens or 0)
|
|
32
|
+
output_delta = (payload.usage.output_tokens or 0) - (attempt.usage.output_tokens or 0)
|
|
33
|
+
return (
|
|
34
|
+
attempt.model_copy(
|
|
35
|
+
update={
|
|
36
|
+
"usage": payload.usage,
|
|
37
|
+
"billing": billing,
|
|
38
|
+
"actual_model": payload.actual_model or attempt.actual_model,
|
|
39
|
+
"response_id": payload.response_id or attempt.response_id,
|
|
40
|
+
}
|
|
41
|
+
),
|
|
42
|
+
input_delta,
|
|
43
|
+
output_delta,
|
|
44
|
+
)
|
|
45
|
+
if payload.outcome == "completed":
|
|
46
|
+
if attempt.usage.completeness != "complete":
|
|
47
|
+
raise KernelError("invalid_event", "成功尝试需要完整用量")
|
|
48
|
+
if attempt.actual_model is None or attempt.response_id is None:
|
|
49
|
+
raise KernelError("invalid_event", "成功尝试缺少响应身份")
|
|
50
|
+
return (
|
|
51
|
+
attempt.model_copy(
|
|
52
|
+
update={
|
|
53
|
+
"status": payload.outcome,
|
|
54
|
+
"error": payload.error,
|
|
55
|
+
"finished_at": occurred_at,
|
|
56
|
+
}
|
|
57
|
+
),
|
|
58
|
+
0,
|
|
59
|
+
0,
|
|
60
|
+
)
|