okstra 0.234.1 → 0.236.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.
Files changed (171) hide show
  1. package/dist/cli-registry.mjs +7 -0
  2. package/dist/cli-registry.mjs.map +1 -1
  3. package/dist/commands/implementation-report/implementation-report.d.mts +1 -0
  4. package/dist/commands/implementation-report/implementation-report.mjs +73 -0
  5. package/dist/commands/implementation-report/implementation-report.mjs.map +1 -0
  6. package/dist/commands/trace/comparison.d.mts +39 -0
  7. package/dist/commands/trace/comparison.mjs +138 -0
  8. package/dist/commands/trace/comparison.mjs.map +1 -0
  9. package/dist/commands/trace/document.d.mts +8 -0
  10. package/dist/commands/trace/document.mjs +37 -0
  11. package/dist/commands/trace/document.mjs.map +1 -0
  12. package/dist/commands/trace/line-counts.d.mts +15 -0
  13. package/dist/commands/trace/line-counts.mjs +107 -0
  14. package/dist/commands/trace/line-counts.mjs.map +1 -0
  15. package/dist/commands/trace/model.d.mts +2 -1
  16. package/dist/commands/trace/model.mjs +13 -1
  17. package/dist/commands/trace/model.mjs.map +1 -1
  18. package/dist/commands/trace/progression.mjs +7 -3
  19. package/dist/commands/trace/progression.mjs.map +1 -1
  20. package/dist/commands/trace/task-link.d.mts +3 -0
  21. package/dist/commands/trace/task-link.mjs.map +1 -1
  22. package/dist/commands/trace/trace.mjs +64 -44
  23. package/dist/commands/trace/trace.mjs.map +1 -1
  24. package/dist/lib/host-registry-client.d.mts +9 -2
  25. package/dist/lib/host-registry-client.mjs +29 -3
  26. package/dist/lib/host-registry-client.mjs.map +1 -1
  27. package/dist/lib/python-helper.d.mts +1 -1
  28. package/dist/lib/python-helper.mjs +11 -5
  29. package/dist/lib/python-helper.mjs.map +1 -1
  30. package/dist/lib/runtime-payload.mjs +1 -0
  31. package/dist/lib/runtime-payload.mjs.map +1 -1
  32. package/dist/lib/types.d.mts +1 -0
  33. package/docs/architecture/storage-model.md +50 -0
  34. package/docs/architecture.md +1 -1
  35. package/docs/cli.md +37 -15
  36. package/docs/project-structure-overview.md +6 -1
  37. package/package.json +1 -1
  38. package/runtime/BUILD.json +2 -2
  39. package/runtime/agents/operations/trace-tests-review.json +6 -0
  40. package/runtime/bin/lib/okstra/usage.sh +8 -8
  41. package/runtime/bin/okstra-qwen-exec.sh +5 -0
  42. package/runtime/prompts/duties/test-reviewer.json +32 -0
  43. package/runtime/prompts/lead/convergence.md +4 -1
  44. package/runtime/prompts/lead/okstra-lead-contract.md +3 -3
  45. package/runtime/prompts/lead/report-writer.md +13 -1
  46. package/runtime/prompts/profiles/_common-contract.md +10 -1
  47. package/runtime/prompts/wizard/prompts.ko.json +16 -4
  48. package/runtime/python/okstra_ctl/adapters/providers/antigravity/adapter.py +10 -2
  49. package/runtime/python/okstra_ctl/adapters/providers/claude/adapter.py +16 -1
  50. package/runtime/python/okstra_ctl/adapters/providers/codex/adapter.py +20 -5
  51. package/runtime/python/okstra_ctl/adapters/providers/kimi/adapter.py +17 -9
  52. package/runtime/python/okstra_ctl/adapters/providers/qwen/adapter.py +88 -0
  53. package/runtime/python/okstra_ctl/adapters/providers/qwen/manifest.json +1 -0
  54. package/runtime/python/okstra_ctl/adapters/providers/qwen/settings.json +12 -0
  55. package/runtime/python/okstra_ctl/adapters/providers/zai/adapter.py +8 -2
  56. package/runtime/python/okstra_ctl/agent/invocation.py +109 -56
  57. package/runtime/python/okstra_ctl/agent/prompt_cli/materialize.py +17 -0
  58. package/runtime/python/okstra_ctl/attempt_evidence.py +5 -2
  59. package/runtime/python/okstra_ctl/business_flow/contracts.py +11 -0
  60. package/runtime/python/okstra_ctl/business_flow/engine.py +90 -32
  61. package/runtime/python/okstra_ctl/business_flow/hooks.py +4 -2
  62. package/runtime/python/okstra_ctl/business_flow/source.py +39 -7
  63. package/runtime/python/okstra_ctl/business_flow/store.py +94 -28
  64. package/runtime/python/okstra_ctl/code_review_census.py +38 -0
  65. package/runtime/python/okstra_ctl/code_review_coverage.py +15 -4
  66. package/runtime/python/okstra_ctl/code_review_prepare.py +15 -3
  67. package/runtime/python/okstra_ctl/code_review_scope.py +3 -2
  68. package/runtime/python/okstra_ctl/code_review_target.py +16 -6
  69. package/runtime/python/okstra_ctl/conformance_evidence.py +44 -21
  70. package/runtime/python/okstra_ctl/consumers.py +6 -1
  71. package/runtime/python/okstra_ctl/convergence.py +95 -5
  72. package/runtime/python/okstra_ctl/convergence_critic_verify_prompt.py +11 -10
  73. package/runtime/python/okstra_ctl/convergence_engine.py +30 -15
  74. package/runtime/python/okstra_ctl/convergence_reverify_prompt.py +9 -2
  75. package/runtime/python/okstra_ctl/coverage_census.py +75 -12
  76. package/runtime/python/okstra_ctl/design_review.py +6 -26
  77. package/runtime/python/okstra_ctl/design_review_evidence.py +6 -26
  78. package/runtime/python/okstra_ctl/dispatch_core.py +9 -2
  79. package/runtime/python/okstra_ctl/dispatch_state.py +5 -0
  80. package/runtime/python/okstra_ctl/domain/role.py +1 -0
  81. package/runtime/python/okstra_ctl/entrypoints/hosts.py +1 -1
  82. package/runtime/python/okstra_ctl/execution_manifest.py +8 -0
  83. package/runtime/python/okstra_ctl/implementation_comparison/__init__.py +12 -0
  84. package/runtime/python/okstra_ctl/implementation_comparison/__main__.py +129 -0
  85. package/runtime/python/okstra_ctl/implementation_comparison/assembly.py +340 -0
  86. package/runtime/python/okstra_ctl/implementation_comparison/baseline.py +254 -0
  87. package/runtime/python/okstra_ctl/implementation_comparison/business_reuse.py +118 -0
  88. package/runtime/python/okstra_ctl/implementation_comparison/commit_source.py +113 -0
  89. package/runtime/python/okstra_ctl/implementation_comparison/html.py +49 -0
  90. package/runtime/python/okstra_ctl/implementation_comparison/inputs.py +348 -0
  91. package/runtime/python/okstra_ctl/implementation_comparison/model.py +47 -0
  92. package/runtime/python/okstra_ctl/implementation_comparison/preparation.py +195 -0
  93. package/runtime/python/okstra_ctl/implementation_comparison/publication.py +317 -0
  94. package/runtime/python/okstra_ctl/implementation_comparison/run_evidence.py +208 -0
  95. package/runtime/python/okstra_ctl/implementation_comparison/run_integration.py +198 -0
  96. package/runtime/python/okstra_ctl/implementation_comparison/source.py +342 -0
  97. package/runtime/python/okstra_ctl/implementation_comparison/target.py +144 -0
  98. package/runtime/python/okstra_ctl/implementation_comparison/task_assembly.py +333 -0
  99. package/runtime/python/okstra_ctl/implementation_comparison/task_selection.py +309 -0
  100. package/runtime/python/okstra_ctl/implementation_generation_evidence.py +134 -0
  101. package/runtime/python/okstra_ctl/implementation_outcome.py +2 -2
  102. package/runtime/python/okstra_ctl/initial_prompt_materialization.py +1 -0
  103. package/runtime/python/okstra_ctl/json_boundary.py +28 -8
  104. package/runtime/python/okstra_ctl/lead_progress.py +1 -1
  105. package/runtime/python/okstra_ctl/model_discovery.py +1 -1
  106. package/runtime/python/okstra_ctl/models.py +2 -2
  107. package/runtime/python/okstra_ctl/paths.py +7 -4
  108. package/runtime/python/okstra_ctl/phases/discussion/profile.md +2 -2
  109. package/runtime/python/okstra_ctl/phases/error_analysis/profile.md +1 -1
  110. package/runtime/python/okstra_ctl/phases/implementation_option_selection/profile.md +1 -1
  111. package/runtime/python/okstra_ctl/phases/implementation_planning/authoring.py +2 -1
  112. package/runtime/python/okstra_ctl/phases/implementation_planning/instructions/plan-body-verification.md +1 -1
  113. package/runtime/python/okstra_ctl/phases/implementation_planning/profile.md +3 -3
  114. package/runtime/python/okstra_ctl/phases/requirements_discovery/profile.md +5 -5
  115. package/runtime/python/okstra_ctl/plan_run_root.py +8 -4
  116. package/runtime/python/okstra_ctl/qa_procedures.py +33 -2
  117. package/runtime/python/okstra_ctl/registry/provider_registry.py +1 -1
  118. package/runtime/python/okstra_ctl/render.py +4 -0
  119. package/runtime/python/okstra_ctl/render_final_report.py +1 -1
  120. package/runtime/python/okstra_ctl/report_execution_evidence.py +88 -15
  121. package/runtime/python/okstra_ctl/report_finalize.py +18 -4
  122. package/runtime/python/okstra_ctl/report_html/render.py +46 -7
  123. package/runtime/python/okstra_ctl/report_html/validation.py +32 -0
  124. package/runtime/python/okstra_ctl/report_synthesis_packet.py +37 -3
  125. package/runtime/python/okstra_ctl/report_view_artifacts.py +12 -0
  126. package/runtime/python/okstra_ctl/review_verdicts.py +9 -0
  127. package/runtime/python/okstra_ctl/run.py +17 -1
  128. package/runtime/python/okstra_ctl/run_context.py +18 -3
  129. package/runtime/python/okstra_ctl/schema_excerpt.py +14 -9
  130. package/runtime/python/okstra_ctl/stage_done.py +11 -3
  131. package/runtime/python/okstra_ctl/stage_ledger.py +2 -2
  132. package/runtime/python/okstra_ctl/stage_map.py +3 -3
  133. package/runtime/python/okstra_ctl/trace_review.py +1 -0
  134. package/runtime/python/okstra_ctl/trace_tasks.py +22 -7
  135. package/runtime/python/okstra_ctl/verdict_blocks.py +7 -2
  136. package/runtime/python/okstra_ctl/verification_dispatch.py +32 -0
  137. package/runtime/python/okstra_ctl/verification_evidence.py +23 -3
  138. package/runtime/python/okstra_ctl/verification_generation.py +3 -2
  139. package/runtime/python/okstra_ctl/verification_inputs.py +3 -2
  140. package/runtime/python/okstra_ctl/verification_invocation.py +7 -3
  141. package/runtime/python/okstra_ctl/wizard/engine.py +28 -1
  142. package/runtime/python/okstra_ctl/wizard/ids.py +8 -0
  143. package/runtime/python/okstra_ctl/wizard/picker_navigation.py +64 -2
  144. package/runtime/python/okstra_ctl/wizard/roles.py +194 -45
  145. package/runtime/python/okstra_ctl/wizard/sources.py +10 -1
  146. package/runtime/python/okstra_ctl/wizard/state.py +67 -20
  147. package/runtime/python/okstra_ctl/wizard/steps_roles.py +6 -3
  148. package/runtime/python/okstra_ctl/wizard/worker_settings.py +129 -25
  149. package/runtime/python/okstra_ctl/worker_audit_ledger.py +44 -8
  150. package/runtime/python/okstra_ctl/worker_prompt_body.py +26 -2
  151. package/runtime/python/okstra_ctl/worker_prompt_headers.py +12 -9
  152. package/runtime/python/okstra_token_usage/claude.py +5 -1
  153. package/runtime/python/okstra_token_usage/collect.py +3 -3
  154. package/runtime/python/okstra_token_usage/pricing.py +1 -0
  155. package/runtime/schemas/report-synthesis-packet-v1.0.schema.json +17 -0
  156. package/runtime/skills/_fragments/wizard-relay-protocol.md +1 -1
  157. package/runtime/skills/okstra-code-review/SKILL.md +1 -1
  158. package/runtime/skills/okstra-code-review/references/census-rules.md +1 -1
  159. package/runtime/skills/okstra-code-review/references/review-calibration.md +1 -1
  160. package/runtime/skills/okstra-discussion/SKILL.md +1 -1
  161. package/runtime/skills/okstra-run/SKILL.md +33 -2
  162. package/runtime/skills/okstra-tdd/SKILL.md +74 -13
  163. package/runtime/templates/reports/html/assets/implementation-comparison.css +39 -0
  164. package/runtime/templates/reports/html/assets/implementation-comparison.js +55 -0
  165. package/runtime/templates/reports/html/i18n/en.json +113 -0
  166. package/runtime/templates/reports/html/i18n/ko.json +113 -0
  167. package/runtime/templates/reports/html/implementation-comparison.template.html +77 -0
  168. package/runtime/templates/reports/implementation-comparison-notes.md +72 -0
  169. package/runtime/templates/trace/trace.template.md +2 -0
  170. package/runtime/templates/worker-prompt-preamble.md +12 -2
  171. package/runtime/validators/validate-report-views.py +4 -36
@@ -0,0 +1,333 @@
1
+ """Compose whole-task views from the selected stages' preserved comparisons."""
2
+ from __future__ import annotations
3
+
4
+ from copy import deepcopy
5
+ import json
6
+ from pathlib import Path
7
+ import time
8
+ from typing import Any
9
+
10
+ from ..final_report_paths import final_report_data_path
11
+ from ..json_boundary import PageBudgetExhausted, ReadBudget, parse_owned_snapshot
12
+ from .assembly import (
13
+ Assembly, CLAIM_FIELDS, MAX_ASSEMBLY_BYTES, MAX_CHANGES, _capture_inputs,
14
+ _file_changes, assemble_comparison,
15
+ )
16
+ from .baseline import ComparisonError, ComparisonOwner, _owner_and_directory, _read_capture
17
+ from .commit_source import read_recorded_commit_source, recorded_commit_is_ancestor
18
+ from .inputs import (
19
+ _ChangedInput, _artifact_bytes, _validate_source, read_run_comparison_source,
20
+ run_comparison_scope,
21
+ )
22
+ from .model import ComparisonSource, MAX_RECORDS, TaskEvidenceSelection
23
+ from .source import GIT_TIMEOUT_SECONDS, MAX_PATHS, GitCollector, digest_bytes
24
+ from .task_selection import SelectedTaskStage, TaskComparisonSelection
25
+
26
+
27
+ def _merge_fingerprints(target: dict[str, str | None], observed: dict[str, str | None]) -> None:
28
+ for path, digest in observed.items():
29
+ if path in target and target[path] != digest:
30
+ raise _ChangedInput(f"Task comparison input changed during assembly: {path}")
31
+ target[path] = digest
32
+
33
+
34
+ def _evidence_rows(stage: int, rows: list[dict[str, Any]]) -> list[dict[str, Any]]:
35
+ prefix = f"stage{stage}:"
36
+ evidence = []
37
+ for row in rows:
38
+ output = {**row, "id": prefix + row["id"], "stage": stage}
39
+ if "recordId" in row:
40
+ output["recordId"] = prefix + row["recordId"]
41
+ evidence.append(output)
42
+ return evidence
43
+
44
+
45
+ def _stage_rows(stage: int, data: dict[str, Any]) -> tuple[list[dict[str, Any]], list[dict[str, Any]]]:
46
+ prefix = f"stage{stage}:"
47
+ evidence = _evidence_rows(stage, data["evidence"])
48
+ changes = []
49
+ for change in data["changes"]:
50
+ output = deepcopy(change)
51
+ output.update(id=prefix + change["id"], stage=stage)
52
+ for field in CLAIM_FIELDS:
53
+ output[field]["evidence"] = [prefix + identifier for identifier in change[field]["evidence"]]
54
+ changes.append(output)
55
+ return changes, evidence
56
+
57
+
58
+ def _coverage_union(stages: dict[int, Assembly]) -> dict[str, Any]:
59
+ files: dict[str, dict[str, Any]] = {}
60
+ unexplained: set[str] = set()
61
+ unobserved: list[str] = []
62
+ excluded: set[str] = set()
63
+ for stage, assembled in stages.items():
64
+ coverage = assembled.data["coverage"]
65
+ unexplained.update(coverage["unexplained"])
66
+ unobserved.extend(f"stage{stage}:{identifier}" for identifier in coverage["unobserved"])
67
+ excluded.update(coverage["excluded"])
68
+ for row in coverage["files"]:
69
+ path = row["path"]
70
+ if path not in files and len(files) >= MAX_PATHS:
71
+ raise ComparisonError("Whole-task coverage path limit reached")
72
+ observation = {"stage": stage, **{key: row[key] for key in ("change", "beforeDigest", "afterDigest")}}
73
+ if path not in files:
74
+ files[path] = {**row, "stageObservations": [observation]}
75
+ else:
76
+ previous = files[path]
77
+ if any(previous[key] != row[key] for key in ("change", "beforeDigest", "afterDigest")):
78
+ previous.update(change="unknown", beforeDigest=None, afterDigest=None)
79
+ previous["stageObservations"].append(observation)
80
+ return {"files": [files[path] for path in sorted(files)], "unexplained": sorted(unexplained),
81
+ "unobserved": unobserved, "excluded": sorted(excluded)}
82
+
83
+
84
+ def _same_source(left: dict[str, Any], right: dict[str, Any]) -> bool:
85
+ if not all(record.get("completeInventory") is True for record in (left, right)):
86
+ return False
87
+ if set(left.get("excludedParts", [])) != set(right.get("excludedParts", [])):
88
+ return False
89
+ tracked = [{row["path"] for row in record["files"] if row.get("tracked")} for record in (left, right)]
90
+ return tracked[0] == tracked[1] and all(row["change"] == "unchanged" for row in _file_changes(left, right))
91
+
92
+
93
+ def _preserved_index_identity(record: dict[str, Any]) -> tuple[str, int] | None:
94
+ identities = []
95
+ outputs = record.get("git", {})
96
+ for name in ("index-before", "index-after"):
97
+ output = outputs.get(name)
98
+ if not isinstance(output, dict) or output.get("complete") is not True or output.get("returncode") != 0:
99
+ return None
100
+ stdout = output.get("stdout")
101
+ if not isinstance(stdout, dict) or not isinstance(stdout.get("storedDigest"), str) or type(stdout.get("bytes")) is not int or stdout["bytes"] < 0:
102
+ return None
103
+ identities.append((stdout["storedDigest"], stdout["bytes"]))
104
+ return identities[0] if identities[0] == identities[1] else None
105
+
106
+
107
+ def _integrated_target(
108
+ root: Path, before: dict[str, Any] | None, stages: dict[int, Assembly],
109
+ selected_heads: dict[int, str], *, git: GitCollector,
110
+ ) -> tuple[dict[str, Any], dict[str, Any] | None, list[str]]:
111
+ proof: dict[str, Any] = {"status": "unproven"}
112
+ targets = {stage: result.captures["after"][1] for stage, result in stages.items() if result.captures}
113
+ if before is None or before.get("status") != "complete" or before.get("completeInventory") is not True or not before.get("head"):
114
+ return proof, None, ["A complete original task baseline is required for cumulative source comparison"]
115
+ if not stages or set(targets) != set(selected_heads) or any(
116
+ target is None or target.get("status") != "complete" or target.get("completeInventory") is not True or not target.get("head")
117
+ for target in targets.values()
118
+ ):
119
+ return proof, None, ["Selected stages do not all have complete preserved targets"]
120
+ if any(target["head"] != selected_heads[stage] for stage, target in targets.items()):
121
+ return proof, None, ["Preserved target HEAD differs from the selected completed stage head"]
122
+ heads = list(dict.fromkeys(target["head"] for target in targets.values()))
123
+ ancestors: dict[tuple[str, str], bool | None] = {}
124
+
125
+ def is_ancestor(ancestor: str, descendant: str) -> bool | None:
126
+ pair = (ancestor, descendant)
127
+ if pair not in ancestors:
128
+ ancestors[pair] = recorded_commit_is_ancestor(root, ancestor, descendant, git=git)
129
+ return ancestors[pair]
130
+
131
+ candidate = heads[0]
132
+ for head in heads[1:]:
133
+ if is_ancestor(candidate, head) is True:
134
+ candidate = head
135
+ if any(is_ancestor(head, candidate) is not True for head in [before["head"], *heads]):
136
+ return proof, None, ["Git ancestry does not establish one target containing the task baseline and every selected stage"]
137
+ representatives = [stage for stage, target in targets.items() if target["head"] == candidate]
138
+ representative = representatives[0]
139
+ target = targets[representative]
140
+ if any(not _same_source(target, targets[stage]) for stage in representatives):
141
+ return proof, None, ["Selected targets at the same HEAD do not establish identical preserved working-tree states"]
142
+ index = _preserved_index_identity(target)
143
+ if index is None or any(_preserved_index_identity(targets[stage]) != index for stage in representatives):
144
+ return proof, None, ["Selected targets at the same HEAD do not establish identical preserved Git indexes"]
145
+ commits = {}
146
+ for stage, other in targets.items():
147
+ if other["head"] == candidate:
148
+ continue
149
+ if other["head"] not in commits:
150
+ commits[other["head"]] = read_recorded_commit_source(root, other["head"], git=git).record
151
+ if not _same_source(commits[other["head"]], other) or _preserved_index_identity(other) != (digest_bytes(b""), 0):
152
+ return proof, None, [f"Stage {stage} has uncommitted or unobserved source that Git ancestry does not include"]
153
+ proof.update(status="proven", head=candidate, representativeStage=representative, equivalentStages=representatives,
154
+ targetRef=stages[representative].data["target"].get("ref"))
155
+ return proof, target, []
156
+
157
+
158
+ def _task_baseline(
159
+ root: Path, directory: Path, owner: ComparisonOwner, manifests: list[dict[str, Any]],
160
+ fingerprints: dict[str, str | None], budget: ReadBudget,
161
+ ) -> tuple[dict[str, Any], dict[str, Any] | None]:
162
+ _artifact_bytes(root, (directory / "baseline.json").relative_to(root).as_posix(), fingerprints, budget)
163
+ response, record = _read_capture(root, directory, owner, budget=budget)
164
+ _capture_inputs(root, directory, record, fingerprints)
165
+ declared = []
166
+ for manifest in manifests:
167
+ comparison = manifest.get("implementationComparison")
168
+ scope = comparison.get("taskBaseline") if isinstance(comparison, dict) else None
169
+ if not isinstance(scope, dict):
170
+ continue
171
+ baseline = scope.get("baseline")
172
+ if scope.get("owner") != owner or scope.get("comparisonDirectory") != directory.relative_to(root).as_posix() or not isinstance(baseline, dict):
173
+ raise ComparisonError("Declared task baseline does not belong to this task")
174
+ declared.append(baseline.get("baselineRef"))
175
+ reference = response.get("baselineRef")
176
+ if reference is not None and (not declared or any(value != reference for value in declared)):
177
+ return {"status": "unavailable", "ref": None,
178
+ "limitations": ["Preserved task baseline does not match the selected runs' original task baseline references"]}, None
179
+ fields = ("status", "capturedAt", "head", "baselineCommit", "limitations", "scope", "completeInventory")
180
+ view = {**{key: record[key] for key in fields if record and key in record}, "ref": reference,
181
+ "status": response["status"], "limitations": response["limitations"]}
182
+ return view, record
183
+
184
+
185
+ def _read_stage_comparison(
186
+ root: Path, row: SelectedTaskStage, card: dict[str, Any],
187
+ fingerprints: dict[str, str | None], budget: ReadBudget, *, git: GitCollector,
188
+ ) -> tuple[Assembly | None, dict[str, Any] | None]:
189
+ manifest = None
190
+ try:
191
+ manifest_path = root / row.run_manifest
192
+ raw = _artifact_bytes(root, row.run_manifest, fingerprints, budget)
193
+ if raw is None:
194
+ raise ComparisonError("Selected stage manifest is missing")
195
+ candidate = parse_owned_snapshot(manifest_path, raw, artifact="selected stage manifest").value
196
+ stage_owner, stage_directory, report = run_comparison_scope(root, manifest_path, candidate)
197
+ if stage_owner.get("stage") != str(row.stage) or final_report_data_path(report) != final_report_data_path(root / row.report):
198
+ raise ComparisonError("Selected stage report identity changed")
199
+ manifest = candidate
200
+ stage_source = read_run_comparison_source(root, stage_owner, budget=budget, fingerprints=fingerprints)
201
+ assembled = assemble_comparison(root, stage_directory, stage_owner, stage_source, budget=budget, git=git)
202
+ _merge_fingerprints(fingerprints, assembled.fingerprints)
203
+ card.update(status=assembled.data["status"], source=assembled.data["source"],
204
+ baseline=assembled.data["baseline"], target=assembled.data["target"],
205
+ limitations=assembled.data["limitations"])
206
+ card["coverage"] = {**assembled.data["coverage"],
207
+ "unobserved": [f"stage{row.stage}:{identifier}" for identifier in assembled.data["coverage"]["unobserved"]]}
208
+ card["source"] = {**card["source"], "evidence": _evidence_rows(row.stage, card["source"].get("evidence", []))}
209
+ return assembled, manifest
210
+ except _ChangedInput:
211
+ raise
212
+ except (OSError, ValueError) as exc:
213
+ card["status"] = "partial"
214
+ card["limitations"].append(str(exc))
215
+ return None, manifest
216
+
217
+
218
+ def _cumulative_view(
219
+ root: Path, before: dict[str, Any] | None, stages: dict[int, Assembly],
220
+ selected_heads: dict[int, str], data: dict[str, Any], chosen: TaskEvidenceSelection, *, git: GitCollector,
221
+ ) -> dict[str, Any]:
222
+ coverage = _coverage_union(stages)
223
+ proof, target, limitations = _integrated_target(root, before, stages, selected_heads, git=git)
224
+ chosen["integrated"] = proof
225
+ data["integration"] = proof
226
+ data["limitations"].extend(limitations)
227
+ if target is not None:
228
+ representative = proof["representativeStage"]
229
+ data["target"] = dict(stages[representative].data["target"])
230
+ if len({row["path"] for record in (before, target) for row in record["files"]}) > MAX_PATHS:
231
+ raise ComparisonError("Whole-task cumulative coverage path limit reached")
232
+ files = _file_changes(before, target)
233
+ observations = {row["path"]: row["stageObservations"] for row in coverage["files"]}
234
+ for row in files:
235
+ row["stageObservations"] = observations.get(row["path"], [])
236
+ coverage["files"] = files
237
+ observed = {row["path"] for row in files if row["change"] in {"added", "removed", "modified"}}
238
+ coverage["unexplained"] = sorted(set(coverage["unexplained"]) & observed)
239
+ else:
240
+ data["target"]["limitations"] = limitations
241
+ change_ids = {change["id"] for change in data["changes"]}
242
+ coverage["unobserved"] = [identifier for identifier in coverage["unobserved"] if identifier in change_ids]
243
+ data["coverage"] = coverage
244
+ return proof
245
+
246
+
247
+ def assemble_task_comparison(
248
+ project_root: Path, comparison_dir: Path | None, owner: ComparisonOwner, source: ComparisonSource, *,
249
+ selection: TaskComparisonSelection, budget: ReadBudget,
250
+ ) -> Assembly:
251
+ root, directory, identity = _owner_and_directory(project_root, comparison_dir, owner)
252
+ if identity.get("kind") != "task" or selection.owner != identity:
253
+ raise ComparisonError("Whole-task comparison selection belongs to another owner")
254
+ fingerprints = dict(selection.fingerprints)
255
+ chosen: TaskEvidenceSelection = {"task": selection.selection,
256
+ "stages": {str(row.stage): None for row in selection.selected_stages}, "integrated": {"status": "unproven"}}
257
+ data: dict[str, Any] = {"schemaVersion": "1.0", "status": "partial", "source": dict(source),
258
+ "baseline": {"status": "unavailable", "ref": None, "limitations": ["Original task baseline is unavailable"]},
259
+ "target": {"status": "unavailable", "ref": None, "limitations": ["A cumulative target has not been established"]},
260
+ "changes": [], "evidence": [], "stageCards": [], "requiredStages": list(selection.required_stages), "integration": {"status": "unproven"},
261
+ "coverage": {"files": [], "unexplained": [], "unobserved": [], "excluded": []},
262
+ "limitations": list(selection.limitations)}
263
+ stages: dict[int, Assembly] = {}
264
+ manifests = []
265
+ required_inputs_inspected = False
266
+ git = GitCollector(shared_budget=budget, deadline=time.monotonic() + GIT_TIMEOUT_SECONDS)
267
+ try:
268
+ if not _validate_source(root, identity, source, fingerprints, budget):
269
+ data["status"] = "stale"
270
+ data["limitations"].append("Normalized task source does not match the saved original")
271
+ return Assembly(data, fingerprints, chosen)
272
+ _artifact_bytes(root, (directory / "baseline.json").relative_to(root).as_posix(), fingerprints, budget)
273
+ if len(selection.required_stages) > MAX_RECORDS:
274
+ data["limitations"].append("Whole-task stage card limit reached; additional stages were not assembled")
275
+ selected = {row.stage: row for row in selection.selected_stages}
276
+ for stage in selection.required_stages[:MAX_RECORDS]:
277
+ row = selected.get(stage)
278
+ card: dict[str, Any] = {"stage": stage, "status": "not-generated", "lifecycle": selection.lifecycle.get(stage, "unknown"),
279
+ "source": None, "baseline": {}, "target": {}, "reportPath": row.report if row else None,
280
+ "runManifestPath": row.run_manifest if row else None, "head": row.head if row else None,
281
+ "changeIds": [], "evidenceIds": [],
282
+ "coverage": {"files": [], "unexplained": [], "unobserved": [], "excluded": []}, "limitations": []}
283
+ data["stageCards"].append(card)
284
+ if row is None:
285
+ card["limitations"].append("Stage has not been selected as complete")
286
+ data["limitations"].append(f"Stage {stage} has not been selected as complete")
287
+ continue
288
+ assembled, manifest = _read_stage_comparison(root, row, card, fingerprints, budget, git=git)
289
+ if manifest is not None:
290
+ manifests.append(manifest)
291
+ if assembled is None:
292
+ data["limitations"].append(f"Stage {stage} could not be assembled: {card['limitations'][-1]}")
293
+ continue
294
+ stages[stage] = assembled
295
+ chosen["stages"][str(stage)] = assembled.selection
296
+ if len(data["changes"]) + len(assembled.data["changes"]) > MAX_CHANGES or len(data["evidence"]) + len(assembled.data["evidence"]) > MAX_RECORDS:
297
+ card["limitations"] = [*card["limitations"], "Stage details were omitted at the whole-task row limit"]
298
+ card["status"] = "partial"
299
+ continue
300
+ changes, evidence = _stage_rows(stage, assembled.data)
301
+ data["changes"].extend(changes)
302
+ data["evidence"].extend(evidence)
303
+ card["changeIds"] = [change["id"] for change in changes]
304
+ card["evidenceIds"] = [item["id"] for item in evidence]
305
+ data["baseline"], before = _task_baseline(root, directory, identity, manifests, fingerprints, budget)
306
+ required_inputs_inspected = True
307
+ proof = _cumulative_view(root, before, stages, {row.stage: row.head for row in selection.selected_stages},
308
+ data, chosen, git=git)
309
+ data["limitations"].extend(data["baseline"]["limitations"])
310
+ ready = (selection.required_stages and len(stages) == len(selection.required_stages)
311
+ and all(card["status"] == "ready" for card in data["stageCards"])
312
+ and before is not None and before.get("status") == "complete"
313
+ and proof["status"] == "proven" and not selection.limitations)
314
+ data["status"] = "ready" if ready else "partial"
315
+ except _ChangedInput as exc:
316
+ data["status"] = "stale"
317
+ data["limitations"].append(str(exc))
318
+ except PageBudgetExhausted as exc:
319
+ data["status"] = "partial" if required_inputs_inspected else "stale"
320
+ data["limitations"].append(f"Whole-task comparison is incomplete: {exc}")
321
+ except (OSError, ValueError) as exc:
322
+ data["limitations"].append(f"Whole-task comparison is incomplete: {exc}")
323
+ if len(json.dumps(data, ensure_ascii=True).encode()) > MAX_ASSEMBLY_BYTES:
324
+ data["changes"], data["evidence"] = [], []
325
+ data["coverage"] = {"files": [], "unexplained": [], "unobserved": [], "excluded": []}
326
+ for card in data["stageCards"]:
327
+ card.update(changeIds=[], evidenceIds=[], source=None, status="partial")
328
+ if data["status"] != "stale":
329
+ data["status"] = "partial"
330
+ data["limitations"].append("Whole-task details exceeded the serialized data byte limit")
331
+ if len(json.dumps(data, ensure_ascii=True).encode()) > MAX_ASSEMBLY_BYTES:
332
+ raise ComparisonError("Whole-task metadata exceeds its serialized byte limit")
333
+ return Assembly(data, fingerprints, chosen)
@@ -0,0 +1,309 @@
1
+ """Select stored task stages for whole-task comparison assembly and publication."""
2
+ from __future__ import annotations
3
+
4
+ from collections.abc import Iterator
5
+ from dataclasses import asdict, dataclass, field, replace
6
+ import json
7
+ import os
8
+ from pathlib import Path
9
+ from typing import Any
10
+
11
+ from ..consumers import carry_head_commit, stage_consumer_state_from_rows
12
+ from ..final_report_paths import final_report_data_path, is_report_record_path
13
+ from ..implementation_outcome import carry_is_pass_grade
14
+ from ..json_boundary import PageBudgetExhausted, ReadBudget, parse_owned_snapshot
15
+ from ..jsonl import parse_jsonl_snapshot
16
+ from ..paths import RunRef, task_manifest_file
17
+ from ..plan_run_root import list_implementation_planning_reports
18
+ from ..qa_procedures import project_artifact_relative_path, safe_qa_path
19
+ from ..stage_ledger import renumbering_divergence
20
+ from ..stage_map import (
21
+ StageMapError, StageMapSnapshot, active_stage_records, parse_stage_map_data,
22
+ parse_stage_map_text, stage_map_records,
23
+ )
24
+ from ..stage_targets import stage_lifecycle_snapshot_from_state
25
+ from .baseline import MAX_BASELINE_BYTES, ComparisonError, ComparisonOwner
26
+ from .inputs import _ChangedInput, _artifact_bytes, run_comparison_scope, task_comparison_owner
27
+ from .model import MAX_COMPARISON_INPUT_BYTES, MAX_COMPARISON_READ_BYTES
28
+ from .source import MAX_PATHS
29
+
30
+
31
+ class _TaskInputReadError(ComparisonError):
32
+ pass
33
+
34
+
35
+ @dataclass(frozen=True)
36
+ class SelectedTaskStage:
37
+ stage: int
38
+ report: str
39
+ run_manifest: str
40
+ head: str
41
+ carry: str
42
+
43
+
44
+ @dataclass(frozen=True)
45
+ class TaskComparisonSelection:
46
+ owner: ComparisonOwner
47
+ plan_path: str | None
48
+ required_stages: tuple[int, ...]
49
+ selected_stages: tuple[SelectedTaskStage, ...]
50
+ phase_outcome: dict[str, Any] | None
51
+ lifecycle: dict[int, str]
52
+ selection: dict[str, Any]
53
+ fingerprints: dict[str, str | None]
54
+ limitations: tuple[str, ...]
55
+
56
+
57
+ @dataclass
58
+ class _TaskSelectionInputs:
59
+ root: Path
60
+ budget: ReadBudget
61
+ fingerprints: dict[str, str | None]
62
+ paths: set[str] = field(default_factory=set)
63
+ entry_count: int = 0
64
+
65
+ def relative(self, path: Path) -> str:
66
+ path = path if path.is_absolute() else self.root / path
67
+ return project_artifact_relative_path(self.root, path)
68
+
69
+ def read(self, path: Path) -> bytes:
70
+ relative = self.relative(path)
71
+ if relative not in self.paths and len(self.paths) >= MAX_PATHS:
72
+ raise _TaskInputReadError("Task comparison artifact path limit reached")
73
+ self.paths.add(relative)
74
+ try:
75
+ raw = _artifact_bytes(self.root, relative, self.fingerprints, self.budget, limit=MAX_BASELINE_BYTES)
76
+ except _ChangedInput:
77
+ raise
78
+ except (OSError, ComparisonError, PageBudgetExhausted) as exc:
79
+ raise _TaskInputReadError(str(exc)) from exc
80
+ if raw is None:
81
+ raise FileNotFoundError(f"Task comparison input is missing: {relative}")
82
+ return raw
83
+
84
+ def object(self, path: Path) -> dict[str, Any]:
85
+ return parse_owned_snapshot(path, self.read(path), artifact="task comparison input").value
86
+
87
+ def plan(self, path: Path) -> StageMapSnapshot:
88
+ raw = self.read(path)
89
+ relative = self.relative(path)
90
+ if is_report_record_path(path):
91
+ data = parse_owned_snapshot(path, raw, artifact="task comparison plan").value
92
+ planning = data.get("implementationPlanning")
93
+ rows = planning.get("stageMap") if isinstance(planning, dict) else None
94
+ if isinstance(rows, list) and len(rows) > MAX_PATHS:
95
+ raise _TaskInputReadError("Task comparison plan stage limit reached")
96
+ stages = parse_stage_map_data(data, source_plan_path=relative)
97
+ else:
98
+ if raw.count(b"\n") + bool(raw and not raw.endswith(b"\n")) > MAX_PATHS:
99
+ raise _TaskInputReadError("Task comparison plan line limit reached")
100
+ stages = parse_stage_map_text(raw.decode("utf-8"), source_plan_path=relative)
101
+ return StageMapSnapshot("ready", relative, stage_map_records(stages))
102
+
103
+ def entries(self, path: Path) -> Iterator[Path]:
104
+ directory = safe_qa_path(self.root, self.relative(path))
105
+ if not directory.exists():
106
+ return
107
+ with os.scandir(directory) as entries:
108
+ for entry in entries:
109
+ self.entry_count += 1
110
+ if self.entry_count > MAX_PATHS:
111
+ raise ComparisonError("Task comparison directory entry limit reached")
112
+ yield directory / entry.name
113
+
114
+
115
+ def _task_path(inputs: _TaskSelectionInputs, task: Path, value: str) -> Path:
116
+ if not isinstance(value, str) or not value:
117
+ raise ComparisonError("Task comparison reference is missing")
118
+ path = Path(value)
119
+ if not path.parts:
120
+ raise ComparisonError("Task comparison reference has no path components")
121
+ if not path.is_absolute():
122
+ path = inputs.root / path if path.parts[0] == ".okstra" else task / path
123
+ return safe_qa_path(inputs.root, inputs.relative(path))
124
+
125
+
126
+ def _select_stage(
127
+ inputs: _TaskSelectionInputs, task: Path, task_key: str, stage: int,
128
+ done: dict[str, Any], latest: StageMapSnapshot, candidates: list[Path],
129
+ ) -> SelectedTaskStage:
130
+ if done.get("impl_task_key") != task_key:
131
+ raise ComparisonError("Done row belongs to a different task")
132
+ ref = RunRef.from_task_root(task, "implementation", stage=stage)
133
+ carry_path = ref.carry(stage)
134
+ if done.get("carry_path") and _task_path(inputs, task, done["carry_path"]) != carry_path:
135
+ raise ComparisonError("Done row does not name the stage's canonical carry")
136
+ carry = inputs.object(carry_path)
137
+ recorded_stage = carry.get("stage", carry.get("stageNumber", stage))
138
+ if type(recorded_stage) is not int or recorded_stage != stage:
139
+ raise ComparisonError("Carry belongs to a different stage")
140
+ head = carry_head_commit(carry)
141
+ if not head:
142
+ raise ComparisonError("Carry has no head commit")
143
+ if head != done.get("head_commit"):
144
+ raise ComparisonError(f"Carry head {head} differs from the selected done head {done.get('head_commit')}")
145
+ if not carry_is_pass_grade(carry):
146
+ raise ComparisonError("Carry is not pass-grade at the selected done head")
147
+ source_plan = _task_path(inputs, task, carry.get("sourcePlanPath"))
148
+ if source_plan.parent != RunRef.from_task_root(task, "implementation-planning").reports_dir:
149
+ raise ComparisonError("Carry plan does not belong to this task's planning reports")
150
+ if not is_report_record_path(source_plan):
151
+ record = final_report_data_path(source_plan)
152
+ try:
153
+ built_from = inputs.plan(record)
154
+ except FileNotFoundError:
155
+ built_from = inputs.plan(source_plan)
156
+ else:
157
+ built_from = inputs.plan(source_plan)
158
+ divergence = renumbering_divergence(latest, built_from, {stage})
159
+ if divergence or not any(row["stage_number"] == stage for row in built_from.stages):
160
+ raise ComparisonError("; ".join(divergence) or "Carry plan does not declare the completed stage")
161
+ report_path = _task_path(inputs, ref.run_dir, done.get("report_path"))
162
+ if report_path.parent != ref.reports_dir:
163
+ raise ComparisonError("Done report does not belong to the selected stage")
164
+ record_path = final_report_data_path(report_path)
165
+ try:
166
+ report = inputs.object(record_path)
167
+ report_path = record_path
168
+ except FileNotFoundError:
169
+ if is_report_record_path(report_path):
170
+ raise
171
+ inputs.read(report_path).decode("utf-8")
172
+ report = {}
173
+ header = report.get("header")
174
+ if isinstance(header, dict) and (header.get("taskType", "implementation") != "implementation" or header.get("taskKey", task_key) != task_key):
175
+ raise ComparisonError("Selected report belongs to a different task or phase")
176
+ matched = []
177
+ for path in candidates:
178
+ manifest = inputs.object(path)
179
+ _, _, declared_report = run_comparison_scope(inputs.root, path, manifest)
180
+ if final_report_data_path(declared_report) != record_path:
181
+ continue
182
+ if manifest.get("taskKey") != task_key:
183
+ raise ComparisonError("Selected run manifest belongs to a different task")
184
+ if manifest.get("approvedPlanPath"):
185
+ approved = _task_path(inputs, task, manifest["approvedPlanPath"])
186
+ if final_report_data_path(approved) != final_report_data_path(source_plan):
187
+ raise ComparisonError("Selected run manifest and carry name different approved plans")
188
+ matched.append(path)
189
+ if len(matched) != 1:
190
+ raise ComparisonError(f"Completed report requires exactly one matching run manifest; found {len(matched)}")
191
+ return SelectedTaskStage(stage, inputs.relative(report_path), inputs.relative(matched[0]), head, inputs.relative(carry_path))
192
+
193
+
194
+ def _outcome_limitations(
195
+ outcome: dict[str, Any] | None, required: tuple[int, ...],
196
+ selected: list[SelectedTaskStage], inputs: _TaskSelectionInputs, task: Path,
197
+ ) -> list[str]:
198
+ if outcome is None or outcome.get("state") != "completed":
199
+ return []
200
+ if outcome.get("stages") != list(required) or {row.stage for row in selected} != set(required):
201
+ return ["Stored implementation outcome does not match the current required and selected stages"]
202
+ if not selected:
203
+ return ["Stored implementation outcome has no selected completed stages"]
204
+ latest = max(selected, key=lambda row: row.stage)
205
+ try:
206
+ report = _task_path(inputs, task, outcome.get("reportPath"))
207
+ except (OSError, ValueError) as exc:
208
+ return [f"Stored implementation outcome report is unavailable: {exc}"]
209
+ if outcome.get("headCommit") != latest.head or final_report_data_path(report) != final_report_data_path(inputs.root / latest.report):
210
+ return ["Stored implementation outcome does not match the selected final stage head and report"]
211
+ return []
212
+
213
+
214
+ def read_task_comparison_selection(
215
+ project_root: Path, task_root: Path, *, budget: ReadBudget | None = None,
216
+ fingerprints: dict[str, str | None] | None = None,
217
+ ) -> TaskComparisonSelection:
218
+ """Selection completeness describes read coverage, not task completion."""
219
+ root = Path(project_root).resolve(strict=True)
220
+ task = Path(task_root)
221
+ task = task if task.is_absolute() else root / task
222
+ task = safe_qa_path(root, project_artifact_relative_path(root, task))
223
+ inputs = _TaskSelectionInputs(root, ReadBudget(MAX_COMPARISON_READ_BYTES) if budget is None else budget,
224
+ {} if fingerprints is None else fingerprints)
225
+ manifest_path = task_manifest_file(task)
226
+ owner = task_comparison_owner(root, task)
227
+ plan_path = None
228
+ required: tuple[int, ...] = ()
229
+ selected: list[SelectedTaskStage] = []
230
+ outcome = None
231
+ lifecycle: dict[int, str] = {}
232
+ selection: dict[str, Any] = {"complete": False, "plans": [], "manifests": {}}
233
+ limitations: list[str] = []
234
+ try:
235
+ manifest = inputs.object(manifest_path)
236
+ task_key = manifest.get("taskKey")
237
+ if not isinstance(task_key, str) or not task_key:
238
+ raise ComparisonError("Task manifest has no task key")
239
+ owner["taskKey"] = task_key
240
+ phase_outcomes = manifest.get("phaseOutcome")
241
+ outcome = phase_outcomes.get("implementation") if isinstance(phase_outcomes, dict) else None
242
+ if outcome is not None and not isinstance(outcome, dict):
243
+ outcome = None
244
+ raise ComparisonError("Stored implementation outcome must be an object")
245
+ planning = RunRef.from_task_root(task, "implementation-planning")
246
+ plans = list_implementation_planning_reports(planning.reports_dir, directory_entries=inputs.entries)
247
+ selection["plans"] = [inputs.relative(path) for path in plans]
248
+ if not plans:
249
+ raise ComparisonError("Task comparison has no implementation plan")
250
+ plan_path = inputs.relative(plans[0])
251
+ latest = inputs.plan(plans[0])
252
+ active = active_stage_records(latest.stages)
253
+ required = tuple(row["stage_number"] for row in active)
254
+ ledger = planning.run_dir / "consumers.jsonl"
255
+ try:
256
+ raw = inputs.read(ledger)
257
+ except FileNotFoundError:
258
+ raw = b""
259
+ if raw.count(b"\n") + bool(raw and not raw.endswith(b"\n")) > MAX_PATHS:
260
+ raise ComparisonError("Task comparison consumer row limit reached")
261
+ rows, invalid = parse_jsonl_snapshot(raw.decode("utf-8"))
262
+ if invalid:
263
+ raise ComparisonError(f"Task comparison consumer ledger has invalid rows: {invalid[:10]}")
264
+ if any("stage" in row and (type(row["stage"]) is not int or row["stage"] < 1) for row in rows):
265
+ raise ComparisonError("Task comparison consumer ledger has invalid stage identities")
266
+ for row in rows:
267
+ if row.get("status") == "pr" and row.get("stages") is not None and not isinstance(row["stages"], list):
268
+ raise ComparisonError("Task comparison consumer ledger has an invalid PR stages field")
269
+ if row.get("status") == "verified" and row.get("final_verdict") is not None and not isinstance(row["final_verdict"], dict):
270
+ raise ComparisonError("Task comparison consumer ledger has an invalid verified final_verdict field")
271
+ state = stage_consumer_state_from_rows(rows)
272
+ snapshot = stage_lifecycle_snapshot_from_state(latest.stages, state)
273
+ lifecycle = {row.stage: row.status for row in snapshot.lifecycles}
274
+ for stage in required:
275
+ ref = RunRef.from_task_root(task, "implementation", stage=stage)
276
+ candidates = []
277
+ for path in inputs.entries(ref.run_dir / "manifests"):
278
+ sequence = path.stem.removeprefix("run-manifest-implementation-")
279
+ if not sequence.isascii() or not sequence.isdecimal():
280
+ continue
281
+ number = int(sequence)
282
+ if path == replace(ref, seq=number).manifest:
283
+ candidates.append(path)
284
+ candidates.sort()
285
+ selection["manifests"][str(stage)] = [inputs.relative(path) for path in candidates]
286
+ if stage not in snapshot.done_by_stage:
287
+ continue
288
+ try:
289
+ selected.append(_select_stage(inputs, task, task_key, stage, snapshot.done_by_stage[stage], latest, candidates))
290
+ except (_ChangedInput, _TaskInputReadError):
291
+ raise
292
+ except (OSError, ValueError, StageMapError, RecursionError) as exc:
293
+ limitations.append(f"Stage {stage} was not selected: {exc}")
294
+ limitations.extend(_outcome_limitations(outcome, required, selected, inputs, task))
295
+ selection.update(complete=True, plan=plan_path, requiredStages=list(required),
296
+ lifecycle={str(stage): status for stage, status in lifecycle.items()},
297
+ stages=[asdict(row) for row in selected], phaseOutcome=outcome)
298
+ except _ChangedInput:
299
+ raise
300
+ except (OSError, ValueError, StageMapError, RecursionError) as exc:
301
+ selected = []
302
+ selection["complete"] = False
303
+ limitations.append(str(exc))
304
+ if len(json.dumps(selection, ensure_ascii=True, separators=(",", ":")).encode()) > MAX_COMPARISON_INPUT_BYTES:
305
+ selected = []
306
+ selection = {"complete": False}
307
+ limitations.append("Task comparison selection exceeds its byte limit")
308
+ return TaskComparisonSelection(owner, plan_path, required, tuple(selected), outcome, lifecycle,
309
+ selection, inputs.fingerprints, tuple(limitations))