okstra 0.231.1 → 0.233.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/README.md +19 -271
- package/dist/cli-registry.mjs +14 -1
- package/dist/cli-registry.mjs.map +1 -1
- package/dist/commands/execute/render-bundle.d.mts +6 -1
- package/dist/commands/execute/render-bundle.mjs +139 -32
- package/dist/commands/execute/render-bundle.mjs.map +1 -1
- package/dist/commands/lifecycle/config.mjs +6 -74
- package/dist/commands/lifecycle/config.mjs.map +1 -1
- package/dist/commands/memory/memory.mjs +9 -55
- package/dist/commands/memory/memory.mjs.map +1 -1
- package/dist/commands/trace/capacity.d.mts +12 -0
- package/dist/commands/trace/capacity.mjs +21 -0
- package/dist/commands/trace/capacity.mjs.map +1 -0
- package/dist/commands/trace/model.d.mts +89 -0
- package/dist/commands/trace/model.mjs +251 -0
- package/dist/commands/trace/model.mjs.map +1 -0
- package/dist/commands/trace/progression.d.mts +11 -0
- package/dist/commands/trace/progression.mjs +194 -0
- package/dist/commands/trace/progression.mjs.map +1 -0
- package/dist/commands/trace/review.d.mts +7 -0
- package/dist/commands/trace/review.mjs +51 -0
- package/dist/commands/trace/review.mjs.map +1 -0
- package/dist/commands/trace/task-link.d.mts +18 -0
- package/dist/commands/trace/task-link.mjs +72 -0
- package/dist/commands/trace/task-link.mjs.map +1 -0
- package/dist/commands/trace/trace.d.mts +1 -0
- package/dist/commands/trace/trace.mjs +293 -0
- package/dist/commands/trace/trace.mjs.map +1 -0
- package/dist/lib/bounded-file.d.mts +1 -0
- package/dist/lib/bounded-file.mjs +36 -0
- package/dist/lib/bounded-file.mjs.map +1 -0
- package/dist/lib/config-store.d.mts +34 -0
- package/dist/lib/config-store.mjs +70 -0
- package/dist/lib/config-store.mjs.map +1 -0
- package/dist/lib/file-lock.mjs +4 -5
- package/dist/lib/file-lock.mjs.map +1 -1
- package/dist/lib/input-limit.d.mts +4 -0
- package/dist/lib/input-limit.mjs +8 -0
- package/dist/lib/input-limit.mjs.map +1 -0
- package/dist/lib/memory-auto-register.d.mts +1 -0
- package/dist/lib/memory-auto-register.mjs +98 -0
- package/dist/lib/memory-auto-register.mjs.map +1 -0
- package/dist/lib/memory-entry-contract.d.mts +12 -0
- package/dist/lib/memory-entry-contract.mjs +46 -0
- package/dist/lib/memory-entry-contract.mjs.map +1 -0
- package/dist/lib/python-helper.d.mts +1 -1
- package/dist/lib/python-helper.mjs +3 -2
- package/dist/lib/python-helper.mjs.map +1 -1
- package/dist/lib/record-secrets.d.mts +1 -0
- package/dist/lib/record-secrets.mjs +28 -0
- package/dist/lib/record-secrets.mjs.map +1 -0
- package/dist/lib/report-language-tag.d.mts +1 -0
- package/dist/lib/report-language-tag.mjs +4 -0
- package/dist/lib/report-language-tag.mjs.map +1 -0
- package/dist/lib/report-language.d.mts +1 -0
- package/dist/lib/report-language.mjs +50 -0
- package/dist/lib/report-language.mjs.map +1 -0
- package/dist/lib/skill-catalog.mjs +3 -0
- package/dist/lib/skill-catalog.mjs.map +1 -1
- package/dist/lib/types.d.mts +2 -1
- package/docs/architecture/storage-model.md +163 -5
- package/docs/architecture.md +17 -4
- package/docs/cli.md +511 -0
- package/docs/contributor-change-matrix.md +1 -2
- package/docs/project-structure-overview.md +33 -42
- package/package.json +1 -1
- package/runtime/BUILD.json +2 -2
- package/runtime/agents/common.json +8 -8
- package/runtime/agents/operations/trace-interface-review.json +6 -0
- package/runtime/agents/operations/trace-scope-review.json +6 -0
- package/runtime/agents/roles/verifier.json +2 -4
- package/runtime/bin/okstra-provider-exec.py +10 -4
- package/runtime/prompts/coding-preflight/architectures/hexagonal.md +23 -30
- package/runtime/prompts/coding-preflight/authoring-checks.md +17 -0
- package/runtime/prompts/coding-preflight/clean-code.md +88 -286
- package/runtime/prompts/coding-preflight/frameworks/node-server.md +2 -3
- package/runtime/prompts/coding-preflight/languages/java.md +3 -5
- package/runtime/prompts/coding-preflight/languages/javascript-typescript.md +5 -12
- package/runtime/prompts/coding-preflight/languages/kotlin.md +2 -4
- package/runtime/prompts/coding-preflight/languages/python.md +2 -7
- package/runtime/prompts/coding-preflight/languages/rust.md +2 -8
- package/runtime/prompts/coding-preflight/languages/sql.md +2 -4
- package/runtime/prompts/coding-preflight/overview.md +25 -38
- package/runtime/prompts/coding-preflight/review-rules.json +30 -0
- package/runtime/prompts/duties/code-reviewer.json +15 -18
- package/runtime/prompts/duties/implementation-verifier.json +1 -0
- package/runtime/prompts/duties/interface-reviewer.json +32 -0
- package/runtime/prompts/host-orchestration/README.md +18 -9
- package/runtime/prompts/launch.template.md +3 -2
- package/runtime/prompts/lead/context-loader.md +2 -0
- package/runtime/prompts/lead/okstra-lead-contract.md +7 -7
- package/runtime/prompts/lead/report-writer.md +6 -6
- package/runtime/prompts/profiles/_coding-conventions-preflight.md +41 -6
- package/runtime/prompts/profiles/_common-contract.md +1 -1
- package/runtime/python/okstra_ctl/agent/invocation.py +122 -36
- package/runtime/python/okstra_ctl/agent/prompt_cli/cli.py +72 -26
- package/runtime/python/okstra_ctl/agent/prompt_cli/corrections.py +23 -8
- package/runtime/python/okstra_ctl/agent/prompt_cli/materialize.py +58 -14
- package/runtime/python/okstra_ctl/agent/prompt_cli/results.py +8 -11
- package/runtime/python/okstra_ctl/agent/standalone.py +15 -0
- package/runtime/python/okstra_ctl/analysis_packet.py +24 -30
- package/runtime/python/okstra_ctl/attempt_evidence.py +10 -0
- package/runtime/python/okstra_ctl/code_review_census.py +162 -7
- package/runtime/python/okstra_ctl/code_review_coverage.py +4 -274
- package/runtime/python/okstra_ctl/code_review_integrity.py +154 -0
- package/runtime/python/okstra_ctl/code_review_invocation.py +212 -0
- package/runtime/python/okstra_ctl/code_review_prepare.py +381 -0
- package/runtime/python/okstra_ctl/code_review_run.py +384 -0
- package/runtime/python/okstra_ctl/code_review_scope.py +49 -9
- package/runtime/python/okstra_ctl/code_review_supervisor.py +41 -0
- package/runtime/python/okstra_ctl/code_review_target.py +212 -13
- package/runtime/python/okstra_ctl/consumers.py +12 -9
- package/runtime/python/okstra_ctl/coverage_census.py +11 -2
- package/runtime/python/okstra_ctl/design_review.py +207 -0
- package/runtime/python/okstra_ctl/design_review_evidence.py +297 -0
- package/runtime/python/okstra_ctl/design_snapshot.py +16 -9
- package/runtime/python/okstra_ctl/direct_work.py +45 -3
- package/runtime/python/okstra_ctl/dispatch_core.py +31 -15
- package/runtime/python/okstra_ctl/dispatch_state.py +9 -2
- package/runtime/python/okstra_ctl/doctor.py +8 -25
- package/runtime/python/okstra_ctl/domain/role.py +1 -0
- package/runtime/python/okstra_ctl/doyouknow/__init__.py +9 -0
- package/runtime/python/okstra_ctl/doyouknow/cli.py +91 -0
- package/runtime/python/okstra_ctl/doyouknow/config.py +58 -0
- package/runtime/python/okstra_ctl/doyouknow/contracts.py +184 -0
- package/runtime/python/okstra_ctl/doyouknow/identity.py +22 -0
- package/runtime/python/okstra_ctl/doyouknow/paths.py +22 -0
- package/runtime/python/okstra_ctl/doyouknow/pending.py +72 -0
- package/runtime/python/okstra_ctl/doyouknow/registration.py +260 -0
- package/runtime/python/okstra_ctl/doyouknow/source_contracts.py +128 -0
- package/runtime/python/okstra_ctl/doyouknow/source_store.py +172 -0
- package/runtime/python/okstra_ctl/doyouknow/sources/io.py +36 -0
- package/runtime/python/okstra_ctl/doyouknow/sources/manager.py +300 -0
- package/runtime/python/okstra_ctl/doyouknow/sources/memory.py +179 -0
- package/runtime/python/okstra_ctl/doyouknow/sources/task.py +95 -0
- package/runtime/python/okstra_ctl/doyouknow/store.py +260 -0
- package/runtime/python/okstra_ctl/doyouknow/sync.py +58 -0
- package/runtime/python/okstra_ctl/execution_mutation_audit.py +18 -2
- package/runtime/python/okstra_ctl/file_size_cap.py +3 -4
- package/runtime/python/okstra_ctl/final_report_schema.py +37 -34
- package/runtime/python/okstra_ctl/incremental_carry.py +6 -7
- package/runtime/python/okstra_ctl/initial_prompt_materialization.py +9 -2
- package/runtime/python/okstra_ctl/json_boundary.py +51 -5
- package/runtime/python/okstra_ctl/jsonl.py +21 -0
- package/runtime/python/okstra_ctl/manager_cli.py +148 -1
- package/runtime/python/okstra_ctl/manager_journal.py +126 -0
- package/runtime/python/okstra_ctl/manager_launch.py +3 -3
- package/runtime/python/okstra_ctl/manager_log.py +221 -0
- package/runtime/python/okstra_ctl/manager_paths.py +8 -0
- package/runtime/python/okstra_ctl/manager_registration.py +29 -0
- package/runtime/python/okstra_ctl/manager_resume.py +59 -0
- package/runtime/python/okstra_ctl/manager_split.py +2 -2
- package/runtime/python/okstra_ctl/manager_store.py +116 -17
- package/runtime/python/okstra_ctl/manager_sync.py +45 -25
- package/runtime/python/okstra_ctl/manager_view.py +35 -2
- package/runtime/python/okstra_ctl/material.py +2 -0
- package/runtime/python/okstra_ctl/model_cli.py +64 -14
- package/runtime/python/okstra_ctl/model_defaults.py +22 -0
- package/runtime/python/okstra_ctl/model_io/renderers.py +16 -2
- package/runtime/python/okstra_ctl/model_io_cli.py +7 -1
- package/runtime/python/okstra_ctl/operation_invocation.py +207 -28
- package/runtime/python/okstra_ctl/path_hints.py +14 -3
- package/runtime/python/okstra_ctl/paths.py +6 -1
- package/runtime/python/okstra_ctl/phases/catalog.py +24 -7
- package/runtime/python/okstra_ctl/phases/final_verification/validation.py +20 -0
- package/runtime/python/okstra_ctl/phases/implementation/host-rules.md +3 -3
- package/runtime/python/okstra_ctl/phases/implementation/instructions/_implementation-deliverable.md +10 -0
- package/runtime/python/okstra_ctl/phases/implementation/instructions/_implementation-diff-review.md +23 -8
- package/runtime/python/okstra_ctl/phases/implementation/instructions/_implementation-self-check.md +6 -4
- package/runtime/python/okstra_ctl/phases/implementation/instructions/_implementation-verifier.md +38 -10
- package/runtime/python/okstra_ctl/phases/implementation/report_assets/implementation.template.html +13 -0
- package/runtime/python/okstra_ctl/phases/implementation/spec.md +25 -0
- package/runtime/python/okstra_ctl/phases/implementation/validation.py +6 -0
- package/runtime/python/okstra_ctl/phases/implementation_option_selection/profile.md +1 -1
- package/runtime/python/okstra_ctl/phases/implementation_option_selection/votes.py +11 -11
- package/runtime/python/okstra_ctl/phases/implementation_planning/authoring.py +16 -9
- package/runtime/python/okstra_ctl/phases/implementation_planning/host-rules.md +3 -6
- package/runtime/python/okstra_ctl/phases/implementation_planning/instructions/plan-body-verification.md +12 -10
- package/runtime/python/okstra_ctl/phases/implementation_planning/profile.md +6 -6
- package/runtime/python/okstra_ctl/phases/improvement_discovery/lenses.py +12 -0
- package/runtime/python/okstra_ctl/phases/improvement_discovery/profile.md +7 -6
- package/runtime/python/okstra_ctl/phases/improvement_discovery/resolved_census.py +159 -0
- package/runtime/python/okstra_ctl/phases/improvement_discovery/spec.md +5 -2
- package/runtime/python/okstra_ctl/phases/improvement_discovery/validation.py +21 -7
- package/runtime/python/okstra_ctl/phases/release_handoff/boundary.json +1 -1
- package/runtime/python/okstra_ctl/phases/release_handoff/profile.md +4 -1
- package/runtime/python/okstra_ctl/plan_verify_cli.py +6 -4
- package/runtime/python/okstra_ctl/render.py +28 -2
- package/runtime/python/okstra_ctl/report_assembly.py +53 -11
- package/runtime/python/okstra_ctl/report_contract.py +26 -0
- package/runtime/python/okstra_ctl/report_corrections.py +36 -20
- package/runtime/python/okstra_ctl/report_inputs.py +1 -0
- package/runtime/python/okstra_ctl/report_language.py +4 -1
- package/runtime/python/okstra_ctl/report_narrative.py +182 -7
- package/runtime/python/okstra_ctl/report_projections.py +64 -18
- package/runtime/python/okstra_ctl/report_synthesis_packet.py +97 -38
- package/runtime/python/okstra_ctl/review_policy.py +359 -0
- package/runtime/python/okstra_ctl/review_verdicts.py +291 -0
- package/runtime/python/okstra_ctl/run.py +67 -36
- package/runtime/python/okstra_ctl/run_context.py +10 -1
- package/runtime/python/okstra_ctl/set_work_status.py +4 -15
- package/runtime/python/okstra_ctl/stage_done.py +11 -0
- package/runtime/python/okstra_ctl/standalone_review_audit.py +28 -0
- package/runtime/python/okstra_ctl/task_list_cli.py +34 -8
- package/runtime/python/okstra_ctl/task_query.py +239 -0
- package/runtime/python/okstra_ctl/trace_review.py +264 -0
- package/runtime/python/okstra_ctl/trace_tasks.py +197 -0
- package/runtime/python/okstra_ctl/user_authorization.py +14 -0
- package/runtime/python/okstra_ctl/verification_generation.py +23 -1
- package/runtime/python/okstra_ctl/verification_input_types.py +15 -1
- package/runtime/python/okstra_ctl/verification_inputs.py +28 -6
- package/runtime/python/okstra_ctl/verification_invocation.py +7 -1
- package/runtime/python/okstra_ctl/verification_target.py +2 -0
- package/runtime/python/okstra_ctl/wizard/confirmation.py +7 -3
- package/runtime/python/okstra_ctl/wizard/launch.py +52 -0
- package/runtime/python/okstra_ctl/wizard/launch_cli.py +39 -0
- package/runtime/python/okstra_ctl/wizard/outcome.py +17 -16
- package/runtime/python/okstra_ctl/wizard/registry.py +1 -1
- package/runtime/python/okstra_ctl/wizard/render.py +8 -0
- package/runtime/python/okstra_ctl/wizard/state.py +2 -1
- package/runtime/python/okstra_ctl/worker_prompt_headers.py +24 -9
- package/runtime/python/okstra_ctl/worker_runner.py +66 -10
- package/runtime/python/okstra_ctl/write_policy.py +34 -1
- package/runtime/python/okstra_project/__init__.py +2 -0
- package/runtime/python/okstra_project/dirs.py +18 -0
- package/runtime/python/okstra_project/state.py +45 -20
- package/runtime/python/okstra_token_usage/blocks.py +74 -0
- package/runtime/python/okstra_token_usage/cli.py +23 -10
- package/runtime/python/okstra_token_usage/collect.py +25 -22
- package/runtime/python/okstra_token_usage/policy.py +193 -0
- package/runtime/schemas/doyouknow-config-v1.schema.json +20 -0
- package/runtime/schemas/doyouknow-v1.schema.json +65 -0
- package/runtime/schemas/final-report-v2.0.schema.json +157 -0
- package/runtime/schemas/final-report-v3.0.schema.json +157 -0
- package/runtime/schemas/memory-entry-contract-v1.json +11 -0
- package/runtime/schemas/record-secret-patterns.json +41 -0
- package/runtime/schemas/report-synthesis-packet-v1.0.schema.json +1 -1
- package/runtime/skills/_fragments/wizard-confirm-step.md +1 -1
- package/runtime/skills/_fragments/wizard-preflight.md +1 -1
- package/runtime/skills/_fragments/wizard-prompt-loop.md +3 -5
- package/runtime/skills/_fragments/wizard-relay-protocol.md +1 -1
- package/runtime/skills/_fragments/wizard-render-bundle.md +15 -29
- package/runtime/skills/okstra-brief-gen/SKILL.md +7 -7
- package/runtime/skills/okstra-brief-gen/references/tracker-recursion.md +1 -1
- package/runtime/skills/okstra-code-review/SKILL.md +92 -136
- package/runtime/skills/okstra-code-review/references/census-rules.md +29 -105
- package/runtime/skills/okstra-code-review/references/review-calibration.md +37 -61
- package/runtime/skills/okstra-discussion/SKILL.md +22 -38
- package/runtime/skills/okstra-explain-flow/SKILL.md +6 -2
- package/runtime/skills/okstra-manager/SKILL.md +31 -0
- package/runtime/skills/okstra-memory/SKILL.md +8 -1
- package/runtime/skills/okstra-pr-gen/SKILL.md +1 -1
- package/runtime/skills/okstra-run/SKILL.md +55 -183
- package/runtime/skills/okstra-schedule-gen/SKILL.md +9 -13
- package/runtime/skills/okstra-setup/SKILL.md +3 -2
- package/runtime/skills/okstra-setup/references/project-config.md +2 -4
- package/runtime/skills/okstra-tdd/SKILL.md +187 -0
- package/runtime/skills/okstra-user-response/SKILL.md +4 -2
- package/runtime/templates/implementation-worker-preamble.md +4 -9
- package/runtime/templates/manager/view.template.html +4 -0
- package/runtime/templates/report-writer-prompt-preamble.md +15 -3
- package/runtime/templates/trace/trace.template.md +42 -0
- package/runtime/templates/worker-prompt-preamble.md +4 -12
- package/runtime/validators/checks/fixtures-02.py +25 -33
- package/runtime/validators/validate-run.py +107 -38
|
@@ -0,0 +1,264 @@
|
|
|
1
|
+
"""Independent reviewer selection and verdict verification for implementation traces.
|
|
2
|
+
|
|
3
|
+
The TypeScript `okstra trace` command owns trace state. This module owns the two
|
|
4
|
+
facts it cannot check itself: which registered models may review a step, and
|
|
5
|
+
whether a reviewer's standalone completion is authentic, bound to the reviewed
|
|
6
|
+
section and carries a verdict.
|
|
7
|
+
"""
|
|
8
|
+
from __future__ import annotations
|
|
9
|
+
|
|
10
|
+
import argparse
|
|
11
|
+
import json
|
|
12
|
+
import re
|
|
13
|
+
import sys
|
|
14
|
+
from collections.abc import Sequence
|
|
15
|
+
from dataclasses import dataclass
|
|
16
|
+
from pathlib import Path
|
|
17
|
+
|
|
18
|
+
from .agent.invocation import AgentInvocationError, verify_standalone_completion
|
|
19
|
+
from .domain.host import HostNotRegistered
|
|
20
|
+
from .json_boundary import load_owned_object
|
|
21
|
+
from .model_pool import ModelPool
|
|
22
|
+
from .operation_invocation import (
|
|
23
|
+
OperationPreparationError,
|
|
24
|
+
operation_ceiling,
|
|
25
|
+
operation_contract_root,
|
|
26
|
+
resolve_operation_slots,
|
|
27
|
+
slot_payload,
|
|
28
|
+
)
|
|
29
|
+
from .registry.host_registry import default_host_registry
|
|
30
|
+
from .registry.provider_registry import default_provider_registry
|
|
31
|
+
|
|
32
|
+
PURPOSE = "trace-review"
|
|
33
|
+
STEP_OPERATIONS = {
|
|
34
|
+
"analysis-review": "trace-scope-review",
|
|
35
|
+
"spec-review": "trace-scope-review",
|
|
36
|
+
"interface-review": "trace-interface-review",
|
|
37
|
+
}
|
|
38
|
+
_DIGEST_RE = re.compile(r"^sha256:[0-9a-f]{64}$")
|
|
39
|
+
_VERDICT_RE = re.compile(r"^Trace review verdict: (pass|fail)[ \t]*$", re.MULTILINE)
|
|
40
|
+
_ANY_VERDICT_RE = re.compile(r"^Trace review verdict:", re.MULTILINE)
|
|
41
|
+
|
|
42
|
+
|
|
43
|
+
class TraceReviewError(ValueError):
|
|
44
|
+
def __init__(self, code: str, message: str) -> None:
|
|
45
|
+
super().__init__(message)
|
|
46
|
+
self.code = code
|
|
47
|
+
|
|
48
|
+
|
|
49
|
+
@dataclass(frozen=True)
|
|
50
|
+
class ReviewTarget:
|
|
51
|
+
project_root: Path
|
|
52
|
+
trace_path: str
|
|
53
|
+
step: str
|
|
54
|
+
round: int
|
|
55
|
+
section_digest: str
|
|
56
|
+
host_runtime: str
|
|
57
|
+
|
|
58
|
+
|
|
59
|
+
@dataclass(frozen=True)
|
|
60
|
+
class ReviewerRecord:
|
|
61
|
+
invocation_id: str
|
|
62
|
+
provider: str
|
|
63
|
+
model: str
|
|
64
|
+
runner: str
|
|
65
|
+
duty_id: str
|
|
66
|
+
verdict: str
|
|
67
|
+
|
|
68
|
+
def to_payload(self) -> dict[str, str]:
|
|
69
|
+
"""The `TraceReviewer` shape `okstra trace` validates and stores."""
|
|
70
|
+
return {
|
|
71
|
+
"invocationId": self.invocation_id, "provider": self.provider, "model": self.model,
|
|
72
|
+
"runner": self.runner, "dutyId": self.duty_id, "verdict": self.verdict,
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
|
|
76
|
+
def binding_text(target: ReviewTarget) -> str:
|
|
77
|
+
return "\n".join((
|
|
78
|
+
"Trace review binding",
|
|
79
|
+
f"- Trace: {target.trace_path}",
|
|
80
|
+
f"- Step: {target.step}",
|
|
81
|
+
f"- Round: {target.round}",
|
|
82
|
+
f"- Section digest: {target.section_digest}",
|
|
83
|
+
f"- Host runtime: {target.host_runtime}",
|
|
84
|
+
))
|
|
85
|
+
|
|
86
|
+
|
|
87
|
+
def _operation(step: str) -> str:
|
|
88
|
+
operation = STEP_OPERATIONS.get(step)
|
|
89
|
+
if operation is None:
|
|
90
|
+
raise TraceReviewError("STEP_MISMATCH", f"Not a review step: {step}")
|
|
91
|
+
return operation
|
|
92
|
+
|
|
93
|
+
|
|
94
|
+
def _contract_root() -> Path:
|
|
95
|
+
try:
|
|
96
|
+
return operation_contract_root()
|
|
97
|
+
except OperationPreparationError as exc:
|
|
98
|
+
raise TraceReviewError("REVIEW_UNAVAILABLE", "operation contracts not found") from exc
|
|
99
|
+
|
|
100
|
+
|
|
101
|
+
def _native_provider(host_runtime: str) -> str:
|
|
102
|
+
try:
|
|
103
|
+
return default_host_registry().resolve(host_runtime).descriptor.native_provider_id
|
|
104
|
+
except HostNotRegistered as exc:
|
|
105
|
+
raise TraceReviewError("INVALID_ARGUMENT", f"unknown host runtime {host_runtime!r}: {exc}") from exc
|
|
106
|
+
|
|
107
|
+
|
|
108
|
+
def _ceiling(operation: str) -> int:
|
|
109
|
+
try:
|
|
110
|
+
return operation_ceiling(operation, contract_root=_contract_root())
|
|
111
|
+
except OperationPreparationError as exc:
|
|
112
|
+
raise TraceReviewError("REVIEW_UNAVAILABLE", str(exc)) from exc
|
|
113
|
+
|
|
114
|
+
|
|
115
|
+
def _independence(native: str, providers: Sequence[str]) -> str:
|
|
116
|
+
return "cross-provider" if any(provider != native for provider in providers) else "same-provider"
|
|
117
|
+
|
|
118
|
+
|
|
119
|
+
def plan_reviewers(target: ReviewTarget, count: int) -> dict[str, object]:
|
|
120
|
+
"""Resolve reviewer slots, placing models from the host's own provider last."""
|
|
121
|
+
operation = _operation(target.step)
|
|
122
|
+
ceiling = _ceiling(operation)
|
|
123
|
+
if not 1 <= count <= ceiling:
|
|
124
|
+
raise TraceReviewError("INVALID_ARGUMENT", f"--count must be from 1 to {ceiling}, got {count}")
|
|
125
|
+
native = _native_provider(target.host_runtime)
|
|
126
|
+
try:
|
|
127
|
+
slots = resolve_operation_slots(
|
|
128
|
+
operation, contract_root=_contract_root(), pool=ModelPool.from_registry(default_provider_registry()),
|
|
129
|
+
count=count, deprioritized_provider=native,
|
|
130
|
+
)
|
|
131
|
+
except OperationPreparationError as exc:
|
|
132
|
+
raise TraceReviewError("REVIEW_UNAVAILABLE", str(exc)) from exc
|
|
133
|
+
return {
|
|
134
|
+
"operation": operation,
|
|
135
|
+
"dutyId": slots[0].duty_id,
|
|
136
|
+
"roleId": slots[0].role_id,
|
|
137
|
+
"binding": binding_text(target),
|
|
138
|
+
"independence": _independence(native, [slot.provider_id for slot in slots]),
|
|
139
|
+
"slots": [slot_payload(slot) for slot in slots],
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
|
|
143
|
+
def _verdict(body: str, invocation_id: str) -> str:
|
|
144
|
+
matches = _VERDICT_RE.findall(body)
|
|
145
|
+
if len(matches) != 1 or len(_ANY_VERDICT_RE.findall(body)) != 1:
|
|
146
|
+
raise TraceReviewError(
|
|
147
|
+
"REVIEW_REJECTED",
|
|
148
|
+
f"{invocation_id}: the returned body needs exactly one 'Trace review verdict: pass|fail' line",
|
|
149
|
+
)
|
|
150
|
+
return matches[0]
|
|
151
|
+
|
|
152
|
+
|
|
153
|
+
def _verify_completion(target: ReviewTarget, completion: Path, duty_id: str) -> ReviewerRecord:
|
|
154
|
+
try:
|
|
155
|
+
verified = verify_standalone_completion(completion, project_root=target.project_root, expected_purpose=PURPOSE)
|
|
156
|
+
metadata = load_owned_object(verified.prompt_metadata_path, artifact="agent invocation metadata")
|
|
157
|
+
except (AgentInvocationError, OSError, ValueError) as exc:
|
|
158
|
+
raise TraceReviewError("REVIEW_REJECTED", f"{completion}: {exc}") from exc
|
|
159
|
+
invocation_id = verified.invocation_id
|
|
160
|
+
if metadata.get("audience") != duty_id:
|
|
161
|
+
raise TraceReviewError(
|
|
162
|
+
"REVIEW_REJECTED",
|
|
163
|
+
f"{invocation_id}: reviewer duty {metadata.get('audience')!r} does not review {target.step} ({duty_id})",
|
|
164
|
+
)
|
|
165
|
+
assignment = metadata.get("modelAssignment")
|
|
166
|
+
if not isinstance(assignment, dict):
|
|
167
|
+
raise TraceReviewError("REVIEW_REJECTED", f"{invocation_id}: model assignment is missing")
|
|
168
|
+
if assignment.get("hostRuntime") != target.host_runtime:
|
|
169
|
+
raise TraceReviewError(
|
|
170
|
+
"REVIEW_REJECTED",
|
|
171
|
+
f"{invocation_id}: reviewer host runtime {assignment.get('hostRuntime')!r} differs from {target.host_runtime!r}",
|
|
172
|
+
)
|
|
173
|
+
prompt = verified.prompt_metadata_path.with_name(f"{invocation_id}.prompt.md").read_text(encoding="utf-8")
|
|
174
|
+
if binding_text(target) not in prompt:
|
|
175
|
+
raise TraceReviewError(
|
|
176
|
+
"REVIEW_STALE",
|
|
177
|
+
f"{invocation_id}: the prompt lacks the current binding; the trace, step, round, section content or host differs, or the binding was not copied verbatim",
|
|
178
|
+
)
|
|
179
|
+
return ReviewerRecord(
|
|
180
|
+
invocation_id=invocation_id,
|
|
181
|
+
provider=str(assignment.get("provider", "")),
|
|
182
|
+
model=str(assignment.get("model", "")),
|
|
183
|
+
runner=str(assignment.get("runner", "")),
|
|
184
|
+
duty_id=duty_id,
|
|
185
|
+
verdict=_verdict(verified.returned_body, invocation_id),
|
|
186
|
+
)
|
|
187
|
+
|
|
188
|
+
|
|
189
|
+
def _require_independent(native: str, role_id: str, reviewers: Sequence[ReviewerRecord]) -> None:
|
|
190
|
+
pool = ModelPool.from_registry(default_provider_registry())
|
|
191
|
+
if _independence(native, [row.provider for row in reviewers]) == "same-provider" and any(
|
|
192
|
+
model.provider_id != native for model in pool.default_candidates(role_id)
|
|
193
|
+
):
|
|
194
|
+
raise TraceReviewError(
|
|
195
|
+
"REVIEWER_NOT_INDEPENDENT",
|
|
196
|
+
f"a model outside provider {native!r} is registered for role {role_id!r}; at least one reviewer must use it",
|
|
197
|
+
)
|
|
198
|
+
|
|
199
|
+
|
|
200
|
+
def verify_reviews(target: ReviewTarget, completions: Sequence[Path]) -> dict[str, object]:
|
|
201
|
+
"""Authenticate each completion and derive the combined verdict."""
|
|
202
|
+
operation = _operation(target.step)
|
|
203
|
+
if not _DIGEST_RE.fullmatch(target.section_digest) or target.round < 1:
|
|
204
|
+
raise TraceReviewError("INVALID_ARGUMENT", "section digest or round is invalid")
|
|
205
|
+
if not completions:
|
|
206
|
+
raise TraceReviewError("REVIEW_REQUIRED", "supply at least one reviewer completion")
|
|
207
|
+
ceiling = _ceiling(operation)
|
|
208
|
+
if len(completions) > ceiling:
|
|
209
|
+
raise TraceReviewError("INVALID_ARGUMENT", f"{operation} allows at most {ceiling} reviewer completions")
|
|
210
|
+
native = _native_provider(target.host_runtime)
|
|
211
|
+
try:
|
|
212
|
+
slot = resolve_operation_slots(
|
|
213
|
+
operation, contract_root=_contract_root(), pool=ModelPool.from_registry(default_provider_registry()), count=1,
|
|
214
|
+
)[0]
|
|
215
|
+
except OperationPreparationError as exc:
|
|
216
|
+
raise TraceReviewError("REVIEW_UNAVAILABLE", str(exc)) from exc
|
|
217
|
+
reviewers: list[ReviewerRecord] = []
|
|
218
|
+
for completion in completions:
|
|
219
|
+
record = _verify_completion(target, completion, slot.duty_id)
|
|
220
|
+
if any(row.invocation_id == record.invocation_id for row in reviewers):
|
|
221
|
+
raise TraceReviewError("REVIEW_REJECTED", f"{record.invocation_id}: completion supplied twice")
|
|
222
|
+
reviewers.append(record)
|
|
223
|
+
_require_independent(native, slot.role_id, reviewers)
|
|
224
|
+
return {
|
|
225
|
+
"verdict": "pass" if all(row.verdict == "pass" for row in reviewers) else "fail",
|
|
226
|
+
"independence": _independence(native, [row.provider for row in reviewers]),
|
|
227
|
+
"reviewers": [row.to_payload() for row in reviewers],
|
|
228
|
+
}
|
|
229
|
+
|
|
230
|
+
|
|
231
|
+
def _target(args: argparse.Namespace) -> ReviewTarget:
|
|
232
|
+
return ReviewTarget(
|
|
233
|
+
Path(args.project_root).resolve(), args.trace_path, args.step, args.round, args.section_digest, args.host_runtime,
|
|
234
|
+
)
|
|
235
|
+
|
|
236
|
+
|
|
237
|
+
def main(argv: Sequence[str] | None = None) -> int:
|
|
238
|
+
parser = argparse.ArgumentParser(prog="okstra_ctl.trace_review")
|
|
239
|
+
commands = parser.add_subparsers(dest="command", required=True)
|
|
240
|
+
for name in ("plan", "verify"):
|
|
241
|
+
command = commands.add_parser(name)
|
|
242
|
+
command.add_argument("--project-root", required=True)
|
|
243
|
+
command.add_argument("--trace-path", required=True)
|
|
244
|
+
command.add_argument("--step", required=True)
|
|
245
|
+
command.add_argument("--round", required=True, type=int)
|
|
246
|
+
command.add_argument("--section-digest", required=True)
|
|
247
|
+
command.add_argument("--host-runtime", required=True)
|
|
248
|
+
commands.choices["plan"].add_argument("--count", type=int, default=1)
|
|
249
|
+
commands.choices["verify"].add_argument("--completion", action="append", default=[])
|
|
250
|
+
args = parser.parse_args(argv)
|
|
251
|
+
try:
|
|
252
|
+
if args.command == "plan":
|
|
253
|
+
result = plan_reviewers(_target(args), args.count)
|
|
254
|
+
else:
|
|
255
|
+
result = verify_reviews(_target(args), [Path(path) for path in args.completion])
|
|
256
|
+
except TraceReviewError as exc:
|
|
257
|
+
print(json.dumps({"error": {"code": exc.code, "message": str(exc)}}))
|
|
258
|
+
return 1
|
|
259
|
+
print(json.dumps(result))
|
|
260
|
+
return 0
|
|
261
|
+
|
|
262
|
+
|
|
263
|
+
if __name__ == "__main__":
|
|
264
|
+
sys.exit(main())
|
|
@@ -0,0 +1,197 @@
|
|
|
1
|
+
"""Project task projection for TypeScript-owned implementation traces."""
|
|
2
|
+
from __future__ import annotations
|
|
3
|
+
|
|
4
|
+
import argparse
|
|
5
|
+
import hashlib
|
|
6
|
+
import json
|
|
7
|
+
import math
|
|
8
|
+
import re
|
|
9
|
+
from dataclasses import dataclass
|
|
10
|
+
from datetime import datetime, timezone
|
|
11
|
+
from pathlib import Path
|
|
12
|
+
|
|
13
|
+
from okstra_project import StateError, parse_task_key, project_json_path, resolve_task_root_read_only
|
|
14
|
+
from okstra_project.dirs import OKSTRA_RELATIVE, contained_relative_path
|
|
15
|
+
|
|
16
|
+
from .direct_work import TASK_MANIFEST_MAX_BYTES, load_direct_task, publish_direct_work, record_direct_work
|
|
17
|
+
from .json_boundary import ReadBudget, load_owned_object, read_bounded_bytes, write_owned_object_atomic
|
|
18
|
+
from .run_context import task_mutex
|
|
19
|
+
|
|
20
|
+
TRACE_ATTEMPT_LIMIT = 128
|
|
21
|
+
TRACE_REQUEST_MAX_BYTES = 16 * 1024
|
|
22
|
+
TRACE_METADATA_LIST_LIMITS = {"tags": (20, 64), "changedFiles": (100, 512), "references": (20, 512), "relatedTasks": (50, 384)}
|
|
23
|
+
TRACE_METADATA_TEXT_LIMITS = {"title": 200, "summary": 2000}
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
@dataclass(frozen=True)
|
|
27
|
+
class TraceSource:
|
|
28
|
+
frontmatter: dict
|
|
29
|
+
text: str
|
|
30
|
+
digest: str
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
def read_task_trace(project_root: Path, trace_path: str, task_key: str, *, budget: ReadBudget | None = None) -> TraceSource:
|
|
34
|
+
root = project_root.resolve()
|
|
35
|
+
relative = Path(trace_path)
|
|
36
|
+
if relative.is_absolute() or len(relative.parts) != 4 or relative.parts[:2] != (*OKSTRA_RELATIVE.parts, "traces"):
|
|
37
|
+
raise ValueError("Trace path is outside project traces")
|
|
38
|
+
if trace_path != relative.as_posix() or contained_relative_path(trace_path, root) != trace_path or relative.suffix != ".md":
|
|
39
|
+
raise ValueError("Trace path is not canonical or contained")
|
|
40
|
+
content = read_bounded_bytes(root / relative, max_bytes=TASK_MANIFEST_MAX_BYTES, artifact="implementation trace", budget=budget)
|
|
41
|
+
text = content.decode("utf-8")
|
|
42
|
+
match = re.match(r"^---\r?\n([\s\S]*?)\r?\n---(?:\r?\n|$)", text)
|
|
43
|
+
header = json.loads(match[1]) if match else None
|
|
44
|
+
if not isinstance(header, dict) or not isinstance(header.get("task"), dict) or header["task"].get("key") != task_key:
|
|
45
|
+
raise ValueError("Trace owner does not match the task")
|
|
46
|
+
return TraceSource(header, text, hashlib.sha256(content).hexdigest())
|
|
47
|
+
|
|
48
|
+
|
|
49
|
+
def _validate_request(project_root: Path, request: dict) -> dict:
|
|
50
|
+
if not isinstance(request, dict) or len(json.dumps(request, ensure_ascii=False).encode()) > TRACE_REQUEST_MAX_BYTES:
|
|
51
|
+
raise ValueError("Trace request exceeds its input limit")
|
|
52
|
+
identity = request.get("task")
|
|
53
|
+
if (not isinstance(identity, dict) or set(identity) != {"key"}
|
|
54
|
+
or not isinstance(identity.get("key"), str) or len(identity["key"]) > 384):
|
|
55
|
+
raise ValueError("Trace task identity is invalid")
|
|
56
|
+
project_id, _, _ = parse_task_key(identity["key"])
|
|
57
|
+
project = load_owned_object(project_json_path(project_root), artifact="project config", max_bytes=TASK_MANIFEST_MAX_BYTES)
|
|
58
|
+
if project.get("projectId") != project_id:
|
|
59
|
+
raise ValueError("Trace task belongs to another project")
|
|
60
|
+
created = request.get("createdAt")
|
|
61
|
+
if isinstance(created, bool) or not isinstance(created, (int, float)) or not math.isfinite(created) or created < 0:
|
|
62
|
+
raise ValueError("Trace creation timestamp is invalid")
|
|
63
|
+
if (type(request.get("completed")) is not bool or not isinstance(request.get("currentStep"), str)
|
|
64
|
+
or len(request["currentStep"]) > 64):
|
|
65
|
+
raise ValueError("Trace projection state is invalid")
|
|
66
|
+
if not isinstance(request.get("tracePath"), str) or len(request["tracePath"]) > 1024:
|
|
67
|
+
raise ValueError("Trace path is invalid")
|
|
68
|
+
source = read_task_trace(project_root, request["tracePath"], identity["key"])
|
|
69
|
+
source_created = datetime.fromisoformat(source.frontmatter.get("createdAt", ""))
|
|
70
|
+
if source_created.tzinfo is None or round(source_created.timestamp() * 1000) != created:
|
|
71
|
+
raise ValueError("Trace creation timestamp does not match its source")
|
|
72
|
+
if source.digest != request.get("digest") or source.frontmatter.get("currentStep") != request["currentStep"]:
|
|
73
|
+
raise ValueError("Trace projection does not match its saved source")
|
|
74
|
+
steps = source.frontmatter.get("steps", {})
|
|
75
|
+
integration = steps.get("integration", {}) if isinstance(steps, dict) else {}
|
|
76
|
+
completed = isinstance(integration, dict) and integration.get("status") == "done"
|
|
77
|
+
if request["completed"] != completed:
|
|
78
|
+
raise ValueError("Trace completion projection does not match its source")
|
|
79
|
+
task = source.frontmatter["task"]
|
|
80
|
+
if set(task) != {"key", *TRACE_METADATA_LIST_LIMITS, *TRACE_METADATA_TEXT_LIMITS}:
|
|
81
|
+
raise ValueError("Trace metadata fields are invalid")
|
|
82
|
+
for field, limit in TRACE_METADATA_TEXT_LIMITS.items():
|
|
83
|
+
if not isinstance(task.get(field), str) or len(task[field]) > limit:
|
|
84
|
+
raise ValueError("Trace text metadata is invalid")
|
|
85
|
+
for field, (count, size) in TRACE_METADATA_LIST_LIMITS.items():
|
|
86
|
+
values = task.get(field)
|
|
87
|
+
if not isinstance(values, list) or len(values) > count or any(not isinstance(value, str) or not value.strip() or len(value) > size for value in values):
|
|
88
|
+
raise ValueError("Trace list metadata is invalid")
|
|
89
|
+
if request["completed"] and not task["summary"].strip():
|
|
90
|
+
raise ValueError("Completed traces require a feature summary")
|
|
91
|
+
return {**request, "task": task}
|
|
92
|
+
|
|
93
|
+
|
|
94
|
+
def _attempts(manifest: dict) -> list[dict]:
|
|
95
|
+
attempts = manifest.get("implementationTraces", [])
|
|
96
|
+
if not isinstance(attempts, list) or len(attempts) > TRACE_ATTEMPT_LIMIT or any(not isinstance(item, dict) for item in attempts):
|
|
97
|
+
raise ValueError("Trace attempt history is invalid")
|
|
98
|
+
for item in attempts:
|
|
99
|
+
created = item.get("createdAt")
|
|
100
|
+
if (not isinstance(item.get("path"), str) or not isinstance(item.get("digest"), str)
|
|
101
|
+
or not isinstance(item.get("currentStep"), str) or type(item.get("completed")) is not bool
|
|
102
|
+
or isinstance(created, bool) or not isinstance(created, (int, float)) or not math.isfinite(created)):
|
|
103
|
+
raise ValueError("Trace attempt record is invalid")
|
|
104
|
+
return attempts
|
|
105
|
+
|
|
106
|
+
|
|
107
|
+
def _is_synced(manifest: dict, request: dict) -> bool:
|
|
108
|
+
return any(item.get("path") == request["tracePath"] and item.get("digest") == request["digest"]
|
|
109
|
+
and item.get("syncedDigest") == request["digest"] for item in _attempts(manifest))
|
|
110
|
+
|
|
111
|
+
|
|
112
|
+
def _save_projection(path: Path, manifest: dict) -> None:
|
|
113
|
+
if len((json.dumps(manifest, indent=2, ensure_ascii=False) + "\n").encode()) > TASK_MANIFEST_MAX_BYTES:
|
|
114
|
+
raise ValueError("Task manifest exceeds its input limit")
|
|
115
|
+
write_owned_object_atomic(path, manifest, artifact="task manifest")
|
|
116
|
+
|
|
117
|
+
|
|
118
|
+
def _record_attempt(manifest: dict, request: dict) -> bool:
|
|
119
|
+
path = request["tracePath"]
|
|
120
|
+
attempts = _attempts(manifest)
|
|
121
|
+
previous = next((item for item in attempts if item.get("path") == path), {})
|
|
122
|
+
others = [item for item in attempts if item.get("path") != path]
|
|
123
|
+
if len(others) >= TRACE_ATTEMPT_LIMIT:
|
|
124
|
+
raise ValueError("Trace attempt history is full")
|
|
125
|
+
attempt = {"path": path, "digest": request["digest"], "createdAt": request["createdAt"],
|
|
126
|
+
"currentStep": request["currentStep"], "completed": request["completed"]}
|
|
127
|
+
if previous.get("digest") == request["digest"] and previous.get("syncedDigest"):
|
|
128
|
+
attempt["syncedDigest"] = previous["syncedDigest"]
|
|
129
|
+
attempts = sorted([*others, attempt], key=lambda item: (item["createdAt"], item["path"]))
|
|
130
|
+
manifest["implementationTraces"] = attempts
|
|
131
|
+
if attempts[-1]["path"] != path:
|
|
132
|
+
return False
|
|
133
|
+
manifest.update({"executionKind": "implementation-trace", "implementationTracePath": path,
|
|
134
|
+
"traceDigest": request["digest"], "traceMetadata": {key: value for key, value in request["task"].items() if key != "key"}})
|
|
135
|
+
metadata = manifest["traceMetadata"]
|
|
136
|
+
manifest["relatedTasks"] = list(dict.fromkeys([*manifest.get("relatedTasks", []), *metadata["relatedTasks"]]))
|
|
137
|
+
status = "done" if request["completed"] else "in-progress"
|
|
138
|
+
if previous.get("digest") != request["digest"] or manifest.get("workStatus") != status:
|
|
139
|
+
manifest["workStatusUpdatedAt"] = datetime.now(timezone.utc).isoformat().replace("+00:00", "Z")
|
|
140
|
+
manifest["updatedAt"] = manifest["workStatusUpdatedAt"]
|
|
141
|
+
manifest["workStatus"] = status
|
|
142
|
+
manifest["workStatusNote"] = metadata["summary"]
|
|
143
|
+
return True
|
|
144
|
+
|
|
145
|
+
|
|
146
|
+
def trace_task_sync_status(project_root: Path, request: dict) -> dict:
|
|
147
|
+
_validate_request(project_root, request)
|
|
148
|
+
key = request["task"]["key"]
|
|
149
|
+
if resolve_task_root_read_only(project_root, key) is None:
|
|
150
|
+
return {"taskKey": key, "taskSync": "pending"}
|
|
151
|
+
_, manifest = load_direct_task(project_root, {"taskKey": key}, allow_create=False)
|
|
152
|
+
synced = _is_synced(manifest, request)
|
|
153
|
+
return {"taskKey": key, "taskSync": "synced" if synced else "pending"}
|
|
154
|
+
|
|
155
|
+
|
|
156
|
+
def synchronize_trace_task(project_root: Path, request: dict) -> dict:
|
|
157
|
+
_validate_request(project_root, request)
|
|
158
|
+
key = request["task"]["key"]
|
|
159
|
+
with task_mutex(key):
|
|
160
|
+
request = _validate_request(project_root, request)
|
|
161
|
+
path, manifest = load_direct_task(project_root, {"taskKey": key}, allow_create=True)
|
|
162
|
+
if _is_synced(manifest, request):
|
|
163
|
+
return {"taskKey": key, "taskSync": "synced"}
|
|
164
|
+
latest = _record_attempt(manifest, request)
|
|
165
|
+
_save_projection(path, manifest)
|
|
166
|
+
if latest and request["completed"]:
|
|
167
|
+
record_direct_work(project_root, path, manifest)
|
|
168
|
+
_save_projection(path, manifest)
|
|
169
|
+
publish_direct_work(project_root, manifest)
|
|
170
|
+
for attempt in manifest["implementationTraces"]:
|
|
171
|
+
if attempt["path"] == request["tracePath"]:
|
|
172
|
+
attempt["syncedDigest"] = request["digest"]
|
|
173
|
+
_save_projection(path, manifest)
|
|
174
|
+
return {"taskKey": key, "taskSync": "synced"}
|
|
175
|
+
|
|
176
|
+
|
|
177
|
+
def main(argv: list[str] | None = None) -> int:
|
|
178
|
+
parser = argparse.ArgumentParser(prog="trace task projection")
|
|
179
|
+
parser.add_argument("operation", choices=("sync", "status"))
|
|
180
|
+
parser.add_argument("--project-root", required=True, type=Path)
|
|
181
|
+
parser.add_argument("--request", required=True)
|
|
182
|
+
args = parser.parse_args(argv)
|
|
183
|
+
try:
|
|
184
|
+
if len(args.request.encode()) > TRACE_REQUEST_MAX_BYTES:
|
|
185
|
+
raise ValueError("Trace request exceeds its input limit")
|
|
186
|
+
request = json.loads(args.request)
|
|
187
|
+
operation = synchronize_trace_task if args.operation == "sync" else trace_task_sync_status
|
|
188
|
+
result = operation(args.project_root.resolve(), request)
|
|
189
|
+
except (OSError, ValueError, TypeError, KeyError, RecursionError, StateError):
|
|
190
|
+
print(json.dumps({"error": {"code": "TASK_SYNC_FAILED", "message": "Trace task projection failed; retry synchronization after checking its source and project."}}))
|
|
191
|
+
return 1
|
|
192
|
+
print(json.dumps(result))
|
|
193
|
+
return 0
|
|
194
|
+
|
|
195
|
+
|
|
196
|
+
if __name__ == "__main__":
|
|
197
|
+
raise SystemExit(main())
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
"""Shared shape validation for a displayed wizard confirmation receipt."""
|
|
2
|
+
from __future__ import annotations
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
def validate_wizard_authorization(record: object) -> None:
|
|
6
|
+
if not isinstance(record, dict) or (
|
|
7
|
+
record.get("schemaVersion") != "1.0"
|
|
8
|
+
or record.get("source") != "wizard-confirmation"
|
|
9
|
+
or record.get("response") != "proceed"
|
|
10
|
+
or not isinstance(record.get("prompt"), str)
|
|
11
|
+
or not record["prompt"].strip()
|
|
12
|
+
or not isinstance(record.get("scope"), dict)
|
|
13
|
+
):
|
|
14
|
+
raise ValueError("user authorization requires the displayed prompt, proceed response, and scope")
|
|
@@ -24,6 +24,10 @@ from .verification_inputs import (
|
|
|
24
24
|
canonical_run_ref, publish_verification_snapshot, read_verification_inputs,
|
|
25
25
|
)
|
|
26
26
|
from .verification_target import read_verification_head
|
|
27
|
+
from .verification_input_types import DESIGN_REVIEW_INPUT_SCHEMA_VERSION
|
|
28
|
+
from .design_review import (
|
|
29
|
+
DesignReviewSnapshot, DESIGN_REVIEW_SCHEMA, capture_design_review,
|
|
30
|
+
)
|
|
27
31
|
|
|
28
32
|
|
|
29
33
|
class _OptionalFrozenVerificationSource(TypedDict, total=False):
|
|
@@ -40,6 +44,7 @@ class FrozenVerificationSource(_OptionalFrozenVerificationSource):
|
|
|
40
44
|
|
|
41
45
|
class _OptionalGenerationConformance(TypedDict, total=False):
|
|
42
46
|
conformanceStages: list[int]
|
|
47
|
+
designReview: DesignReviewSnapshot
|
|
43
48
|
|
|
44
49
|
|
|
45
50
|
class VerificationGenerationRecord(_OptionalGenerationConformance):
|
|
@@ -85,12 +90,23 @@ _SCHEMA = {
|
|
|
85
90
|
"sourceRoot": _PATH, "source": _SOURCE, "artifactInputs": _FILES,
|
|
86
91
|
"conformanceStages": {"type": "array",
|
|
87
92
|
"items": {"type": "integer", "minimum": 1}},
|
|
93
|
+
"designReview": DESIGN_REVIEW_SCHEMA,
|
|
88
94
|
},
|
|
89
95
|
}
|
|
90
96
|
_ARTIFACT = "verification generation"
|
|
91
97
|
|
|
92
98
|
|
|
93
99
|
def _generation_errors(payload: dict[str, Any]) -> list[str]:
|
|
100
|
+
if "designReview" in payload:
|
|
101
|
+
from .review_verdicts import parse_review_census
|
|
102
|
+
|
|
103
|
+
review = payload["designReview"]
|
|
104
|
+
if payload["taskType"] != "implementation" or review["head"] != payload["head"]:
|
|
105
|
+
return ["design review must name this implementation head"]
|
|
106
|
+
try:
|
|
107
|
+
parse_review_census(review["census"], allow_empty=True)
|
|
108
|
+
except ValueError as exc:
|
|
109
|
+
return [f"invalid design review census: {exc}"]
|
|
94
110
|
stages = payload.get("conformanceStages", [])
|
|
95
111
|
if any(left >= right for left, right in pairwise(stages)):
|
|
96
112
|
return ["generation conformance stages must be strictly increasing"]
|
|
@@ -177,7 +193,7 @@ def _capture_generation(
|
|
|
177
193
|
if artifacts[relative] != digest:
|
|
178
194
|
raise ValueError("verification conformance manifest changed during capture")
|
|
179
195
|
read_verification_head(source_root, head)
|
|
180
|
-
|
|
196
|
+
result: VerificationGenerationRecord = {
|
|
181
197
|
"schemaVersion": "1.0", "kind": "verification-generation",
|
|
182
198
|
"generation": generation, "taskType": ref.task_type,
|
|
183
199
|
"runManifestPath": ref.manifest.relative_to(project).as_posix(),
|
|
@@ -196,6 +212,12 @@ def _capture_generation(
|
|
|
196
212
|
**({"conformanceStages": list(conformance.stages)}
|
|
197
213
|
if conformance is not None else {}),
|
|
198
214
|
}
|
|
215
|
+
if ref.task_type == "implementation" and inputs["schemaVersion"] == DESIGN_REVIEW_INPUT_SCHEMA_VERSION:
|
|
216
|
+
result["designReview"] = capture_design_review(
|
|
217
|
+
source_root, inputs["reviewBase"], head, inputs["reviewPolicy"],
|
|
218
|
+
ref.verification_generation(generation).with_suffix(".functions.json"),
|
|
219
|
+
)
|
|
220
|
+
return result
|
|
199
221
|
|
|
200
222
|
|
|
201
223
|
def prepare_verification_generation(
|
|
@@ -5,6 +5,8 @@ from typing import Any, Literal, TypedDict
|
|
|
5
5
|
INPUT_SCHEMA_VERSION: Literal["1.0"] = "1.0"
|
|
6
6
|
INPUT_KIND: Literal["verification-inputs"] = "verification-inputs"
|
|
7
7
|
PLAN_INPUT_SCHEMA_VERSION: Literal["2.0"] = "2.0"
|
|
8
|
+
REVIEW_INPUT_SCHEMA_VERSION: Literal["3.0"] = "3.0"
|
|
9
|
+
DESIGN_REVIEW_INPUT_SCHEMA_VERSION: Literal["4.0"] = "4.0"
|
|
8
10
|
|
|
9
11
|
|
|
10
12
|
class FrozenProcedure(TypedDict):
|
|
@@ -12,6 +14,16 @@ class FrozenProcedure(TypedDict):
|
|
|
12
14
|
digest: str
|
|
13
15
|
|
|
14
16
|
|
|
17
|
+
class _OptionalFrozenReviewPolicy(TypedDict, total=False):
|
|
18
|
+
authorPolicyDigest: str
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
class FrozenReviewPolicy(_OptionalFrozenReviewPolicy):
|
|
22
|
+
schemaVersion: str
|
|
23
|
+
architecture: str
|
|
24
|
+
sources: dict[str, FrozenProcedure]
|
|
25
|
+
|
|
26
|
+
|
|
15
27
|
QaSourceStatus = Literal[
|
|
16
28
|
"not-declared", "not-queried", "no-baseline", "unchanged", "changed",
|
|
17
29
|
]
|
|
@@ -39,6 +51,8 @@ class FrozenVerificationPlan(TypedDict):
|
|
|
39
51
|
|
|
40
52
|
|
|
41
53
|
class _OptionalVerificationInputs(TypedDict, total=False):
|
|
54
|
+
reviewBase: str
|
|
55
|
+
reviewPolicy: FrozenReviewPolicy
|
|
42
56
|
approvedPlan: FrozenVerificationPlan
|
|
43
57
|
qaSourceObservations: dict[str, list[FrozenQaSourceObservation]]
|
|
44
58
|
conformanceBaseline: dict[str, str]
|
|
@@ -46,7 +60,7 @@ class _OptionalVerificationInputs(TypedDict, total=False):
|
|
|
46
60
|
|
|
47
61
|
|
|
48
62
|
class VerificationInputs(_OptionalVerificationInputs):
|
|
49
|
-
schemaVersion: Literal["1.0", "2.0"]
|
|
63
|
+
schemaVersion: Literal["1.0", "2.0", "3.0", "4.0"]
|
|
50
64
|
kind: Literal["verification-inputs"]
|
|
51
65
|
sourceRoot: str
|
|
52
66
|
qaCommands: dict[str, list[dict[str, Any]]]
|