okstra 0.227.0 → 0.228.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 +1 -1
- package/dist/cli-registry.mjs +6 -0
- package/dist/cli-registry.mjs.map +1 -1
- package/docs/architecture/storage-model.md +77 -0
- package/docs/cli.md +15 -3
- package/docs/project-structure-overview.md +12 -2
- package/package.json +1 -1
- package/runtime/BUILD.json +2 -2
- package/runtime/prompts/duties/code-reviewer.json +1 -0
- package/runtime/prompts/lead/convergence.md +5 -19
- package/runtime/prompts/lead/okstra-lead-contract.md +1 -1
- package/runtime/prompts/profiles/_coding-conventions-preflight.md +1 -1
- package/runtime/python/okstra_ctl/adapters/verification_inputs.py +22 -0
- package/runtime/python/okstra_ctl/adapters/worker_defaults.py +2 -2
- package/runtime/python/okstra_ctl/analysis_packet.py +52 -21
- package/runtime/python/okstra_ctl/approval_decisions.py +30 -1
- package/runtime/python/okstra_ctl/approved_plan_stage_extract.py +100 -66
- package/runtime/python/okstra_ctl/brief_sources.py +162 -44
- package/runtime/python/okstra_ctl/code_review_coverage.py +11 -1
- package/runtime/python/okstra_ctl/code_review_scope.py +157 -0
- package/runtime/python/okstra_ctl/code_review_target.py +46 -10
- package/runtime/python/okstra_ctl/conformance.py +9 -3
- package/runtime/python/okstra_ctl/design_surfaces.py +51 -19
- package/runtime/python/okstra_ctl/final_report_schema.py +37 -30
- package/runtime/python/okstra_ctl/fixed_text.py +31 -9
- package/runtime/python/okstra_ctl/implementation_direction.py +18 -0
- package/runtime/python/okstra_ctl/initial_prompt_materialization.py +59 -21
- package/runtime/python/okstra_ctl/json_registry.py +3 -18
- package/runtime/python/okstra_ctl/manager_split.py +201 -84
- package/runtime/python/okstra_ctl/model_io/references.py +31 -1
- package/runtime/python/okstra_ctl/model_io/renderers.py +30 -1
- package/runtime/python/okstra_ctl/model_io_cli.py +9 -0
- package/runtime/python/okstra_ctl/path_hints.py +13 -1
- package/runtime/python/okstra_ctl/paths.py +4 -0
- package/runtime/python/okstra_ctl/phases/final_verification/prior_blockers.py +87 -45
- package/runtime/python/okstra_ctl/phases/final_verification/profile.md +2 -2
- package/runtime/python/okstra_ctl/phases/final_verification/spec.md +10 -2
- package/runtime/python/okstra_ctl/phases/final_verification/validation.py +19 -11
- package/runtime/python/okstra_ctl/phases/implementation/instructions/_implementation-executor.md +3 -1
- package/runtime/python/okstra_ctl/phases/implementation/instructions/_implementation-verifier.md +3 -1
- package/runtime/python/okstra_ctl/phases/implementation/spec.md +14 -0
- package/runtime/python/okstra_ctl/phases/implementation_option_selection/authoring.py +2 -1
- package/runtime/python/okstra_ctl/phases/implementation_option_selection/profile.md +1 -1
- package/runtime/python/okstra_ctl/phases/implementation_option_selection/validation.py +53 -37
- package/runtime/python/okstra_ctl/phases/implementation_planning/profile.md +1 -1
- package/runtime/python/okstra_ctl/plan_items.py +9 -11
- package/runtime/python/okstra_ctl/ports/verification_inputs.py +17 -0
- package/runtime/python/okstra_ctl/prior_planning.py +6 -17
- package/runtime/python/okstra_ctl/prior_run_summary.py +35 -0
- package/runtime/python/okstra_ctl/qa_commands.py +66 -1
- package/runtime/python/okstra_ctl/qa_commands_cli.py +67 -0
- package/runtime/python/okstra_ctl/qa_procedures.py +235 -0
- package/runtime/python/okstra_ctl/registry/verification_inputs_store.py +8 -0
- package/runtime/python/okstra_ctl/render.py +10 -0
- package/runtime/python/okstra_ctl/report_assembly.py +12 -12
- package/runtime/python/okstra_ctl/run.py +108 -5
- package/runtime/python/okstra_ctl/verification_input_ref.py +80 -0
- package/runtime/python/okstra_ctl/verification_input_types.py +32 -0
- package/runtime/python/okstra_ctl/verification_inputs.py +162 -0
- package/runtime/python/okstra_ctl/verification_plan.py +116 -0
- package/runtime/python/okstra_ctl/worker_prompt_body.py +12 -6
- package/runtime/python/okstra_ctl/worker_prompt_contract.py +5 -1
- package/runtime/python/okstra_ctl/worker_prompt_headers.py +50 -1
- package/runtime/python/okstra_project/dirs.py +22 -0
- package/runtime/python/okstra_project/resolver.py +10 -0
- package/runtime/schemas/final-report-v3.0.schema.json +5 -1
- package/runtime/skills/okstra-brief-gen/SKILL.md +10 -4
- package/runtime/skills/okstra-code-review/SKILL.md +39 -45
- package/runtime/skills/okstra-code-review/references/census-rules.md +14 -2
- package/runtime/skills/okstra-code-review/references/review-calibration.md +31 -8
- package/runtime/skills/okstra-manager/SKILL.md +2 -2
- package/runtime/skills/okstra-setup/SKILL.md +2 -0
- package/runtime/skills/okstra-setup/references/project-config.md +2 -0
- package/runtime/validators/validate-brief.py +21 -5
|
@@ -22,6 +22,7 @@ class ReviewCell:
|
|
|
22
22
|
class ReviewCensus:
|
|
23
23
|
rules: dict[str, tuple[str, ...]]
|
|
24
24
|
cells: dict[str, ReviewCell]
|
|
25
|
+
references: dict[str, str]
|
|
25
26
|
|
|
26
27
|
|
|
27
28
|
def _table_fields(line: str) -> list[str]:
|
|
@@ -34,6 +35,7 @@ def read_review_census(path: Path) -> ReviewCensus:
|
|
|
34
35
|
rule_ids: set[str] = set()
|
|
35
36
|
pairs: set[tuple[str, str]] = set()
|
|
36
37
|
references: set[tuple[str, str]] = set()
|
|
38
|
+
rule_references: dict[str, str] = {}
|
|
37
39
|
section = ""
|
|
38
40
|
for line in path.read_text(encoding="utf-8").splitlines():
|
|
39
41
|
if line.startswith("## "):
|
|
@@ -56,6 +58,7 @@ def read_review_census(path: Path) -> ReviewCensus:
|
|
|
56
58
|
raise ValueError("unknown rule group")
|
|
57
59
|
rule_ids.add(identity)
|
|
58
60
|
references.add((value, reference))
|
|
61
|
+
rule_references[identity] = reference
|
|
59
62
|
rules.setdefault(value, []).append(identity)
|
|
60
63
|
else:
|
|
61
64
|
if not re.fullmatch(r"C-CR-[0-9]+", identity) or identity in cells:
|
|
@@ -71,7 +74,9 @@ def read_review_census(path: Path) -> ReviewCensus:
|
|
|
71
74
|
raise ValueError("census needs Rules and Cells tables")
|
|
72
75
|
if any(cell.group not in rules for cell in cells.values()):
|
|
73
76
|
raise ValueError("cell names an unknown rule group")
|
|
74
|
-
return ReviewCensus(
|
|
77
|
+
return ReviewCensus(
|
|
78
|
+
{group: tuple(ids) for group, ids in rules.items()}, cells, rule_references,
|
|
79
|
+
)
|
|
75
80
|
|
|
76
81
|
|
|
77
82
|
def _keyed_values(text: str) -> dict[str, str]:
|
|
@@ -272,6 +277,11 @@ def check_review_coverage(
|
|
|
272
277
|
if assignment is not None and current != assignment:
|
|
273
278
|
raise AgentInvocationError("coverage cannot mix reviewer model assignments")
|
|
274
279
|
assignment = current
|
|
280
|
+
heads = [line.removeprefix("Review head: ")
|
|
281
|
+
for line in verified.returned_body.splitlines()
|
|
282
|
+
if line.startswith("Review head: ")]
|
|
283
|
+
if heads and heads != [tree.commit]:
|
|
284
|
+
raise ValueError("completion review head differs from --head")
|
|
275
285
|
bodies.append(verified.returned_body)
|
|
276
286
|
verdicts: dict[str, tuple[str, str]] = {}
|
|
277
287
|
missing: dict[str, str] = {}
|
|
@@ -0,0 +1,157 @@
|
|
|
1
|
+
"""Conservative carry candidates; current reviewers still attest the impact boundary."""
|
|
2
|
+
from __future__ import annotations
|
|
3
|
+
|
|
4
|
+
import hashlib
|
|
5
|
+
import re
|
|
6
|
+
from dataclasses import dataclass
|
|
7
|
+
from pathlib import Path, PurePosixPath
|
|
8
|
+
|
|
9
|
+
from .agent.invocation import verify_standalone_completion
|
|
10
|
+
from .fixed_text import scalar
|
|
11
|
+
from .code_review_coverage import (
|
|
12
|
+
ReviewCensus, _HeadTree, _head_tree, _table_fields, check_review_coverage,
|
|
13
|
+
read_review_census,
|
|
14
|
+
)
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
@dataclass(frozen=True)
|
|
18
|
+
class ReviewScope:
|
|
19
|
+
baseline: str
|
|
20
|
+
recheck: tuple[str, ...]
|
|
21
|
+
carry: tuple[str, ...]
|
|
22
|
+
reason: str
|
|
23
|
+
|
|
24
|
+
def render(self) -> str:
|
|
25
|
+
mode = "incremental" if self.carry else "full"
|
|
26
|
+
return (
|
|
27
|
+
f"Scope: {mode}\nReason: {scalar(self.reason)}\n{self.baseline}"
|
|
28
|
+
f"Recheck: {', '.join(self.recheck) or '-'}\n"
|
|
29
|
+
f"Carry candidates: {', '.join(self.carry) or '-'}\n"
|
|
30
|
+
)
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
def _rule_digest(census: ReviewCensus, policies: list[Path]) -> str:
|
|
34
|
+
digest = hashlib.sha256()
|
|
35
|
+
values = [repr(census.rules), repr(census.references)]
|
|
36
|
+
for reference in census.references.values():
|
|
37
|
+
for location in reference.split(";"):
|
|
38
|
+
name = re.sub(r":\d+(?:-\d+)?$", "", location.strip().partition("#")[0])
|
|
39
|
+
values.append(
|
|
40
|
+
hashlib.sha256(Path(name).expanduser().read_bytes()).hexdigest()
|
|
41
|
+
)
|
|
42
|
+
values.extend(hashlib.sha256(path.read_bytes()).hexdigest() for path in policies)
|
|
43
|
+
for value in values:
|
|
44
|
+
digest.update(value.encode() + b"\0")
|
|
45
|
+
return digest.hexdigest()
|
|
46
|
+
|
|
47
|
+
|
|
48
|
+
def _dependencies(body: str, census: ReviewCensus) -> dict[str, set[str]]:
|
|
49
|
+
dependencies: dict[str, set[str]] = {}
|
|
50
|
+
section = ""
|
|
51
|
+
for line in body.splitlines():
|
|
52
|
+
if line.startswith("## "):
|
|
53
|
+
section = line.strip()
|
|
54
|
+
if section != "## Review Dependencies" or not line.startswith("|"):
|
|
55
|
+
continue
|
|
56
|
+
fields = _table_fields(line)
|
|
57
|
+
if fields[0] == "Cell" or all(re.fullmatch(r"[-:]+", f) for f in fields):
|
|
58
|
+
continue
|
|
59
|
+
if len(fields) != 2 or fields[0] not in census.cells or fields[0] in dependencies:
|
|
60
|
+
raise ValueError("invalid or duplicate dependency cell")
|
|
61
|
+
paths = {part.strip() for part in fields[1].split(";")}
|
|
62
|
+
if any(not p or PurePosixPath(p).is_absolute() or ".." in PurePosixPath(p).parts
|
|
63
|
+
for p in paths):
|
|
64
|
+
raise ValueError("dependencies must be literal repository-relative paths")
|
|
65
|
+
dependencies[fields[0]] = paths
|
|
66
|
+
return dependencies
|
|
67
|
+
|
|
68
|
+
|
|
69
|
+
def _prior_inputs(
|
|
70
|
+
root: Path, completions: list[Path], census: ReviewCensus, baseline: str,
|
|
71
|
+
) -> dict[str, set[str]]:
|
|
72
|
+
dependencies: dict[str, set[str]] = {}
|
|
73
|
+
for completion in completions:
|
|
74
|
+
body = verify_standalone_completion(
|
|
75
|
+
completion, project_root=root, expected_purpose="code-review",
|
|
76
|
+
).returned_body
|
|
77
|
+
for line in baseline.splitlines():
|
|
78
|
+
if body.splitlines().count(line) != 1:
|
|
79
|
+
raise ValueError("previous baseline missing or different")
|
|
80
|
+
for cell, sources in _dependencies(body, census).items():
|
|
81
|
+
dependencies.setdefault(cell, set()).update(sources)
|
|
82
|
+
return dependencies
|
|
83
|
+
|
|
84
|
+
|
|
85
|
+
def review_scope(
|
|
86
|
+
root: Path, census_path: Path, base: str, head: str, policies: list[Path], *,
|
|
87
|
+
previous_head: str = "", previous_census: Path | None = None,
|
|
88
|
+
completions: list[Path] | None = None,
|
|
89
|
+
) -> ReviewScope:
|
|
90
|
+
census = read_review_census(census_path)
|
|
91
|
+
current = _head_tree(root, head)
|
|
92
|
+
base_commit = _head_tree(root, base).commit
|
|
93
|
+
if current._git("merge-base", "--is-ancestor", base_commit, current.commit).returncode:
|
|
94
|
+
raise ValueError("review base is not an ancestor of head")
|
|
95
|
+
rules = _rule_digest(census, policies)
|
|
96
|
+
baseline = (
|
|
97
|
+
f"Review base: {base_commit}\nReview head: {current.commit}\n"
|
|
98
|
+
f"Review rules: {rules}\n"
|
|
99
|
+
)
|
|
100
|
+
def full(reason: str) -> ReviewScope:
|
|
101
|
+
return ReviewScope(baseline, tuple(census.cells), (), reason)
|
|
102
|
+
|
|
103
|
+
if not previous_head or previous_census is None or not completions:
|
|
104
|
+
return full("no complete previous review inputs")
|
|
105
|
+
prior = _head_tree(root, previous_head)
|
|
106
|
+
ancestry = current._git("merge-base", "--is-ancestor", prior.commit, current.commit)
|
|
107
|
+
if ancestry.returncode != 0:
|
|
108
|
+
return full("previous head is not an ancestor")
|
|
109
|
+
old = read_review_census(previous_census)
|
|
110
|
+
if old.rules != census.rules or old.references != census.references:
|
|
111
|
+
return full("rule catalog changed")
|
|
112
|
+
verdicts = check_review_coverage(root, previous_census, completions, prior.commit)
|
|
113
|
+
if verdicts.missing or verdicts.unknown:
|
|
114
|
+
return full("previous review coverage is incomplete")
|
|
115
|
+
try:
|
|
116
|
+
dependencies = _prior_inputs(
|
|
117
|
+
root, completions, old,
|
|
118
|
+
baseline.replace(f"Review head: {current.commit}", f"Review head: {prior.commit}"),
|
|
119
|
+
)
|
|
120
|
+
for sources in dependencies.values():
|
|
121
|
+
for source in sources:
|
|
122
|
+
prior.line_count(source)
|
|
123
|
+
except ValueError as exc:
|
|
124
|
+
return full(str(exc))
|
|
125
|
+
return _partition(current, prior.commit, census, old, verdicts.verdicts,
|
|
126
|
+
dependencies, baseline)
|
|
127
|
+
|
|
128
|
+
|
|
129
|
+
def _partition(
|
|
130
|
+
current: _HeadTree, previous: str, census: ReviewCensus, old: ReviewCensus,
|
|
131
|
+
verdicts: dict[str, tuple[str, str]], dependencies: dict[str, set[str]], baseline: str,
|
|
132
|
+
) -> ReviewScope:
|
|
133
|
+
delta = current._git("diff", "--no-ext-diff", "--no-renames", "--name-only", "-z",
|
|
134
|
+
previous, current.commit, "--")
|
|
135
|
+
if delta.returncode != 0:
|
|
136
|
+
raise ValueError("cannot read review delta")
|
|
137
|
+
changed = {p.decode("utf-8", "surrogateescape") for p in delta.stdout.split(b"\0") if p}
|
|
138
|
+
known = set().union(*dependencies.values()) if dependencies else set()
|
|
139
|
+
unknown = changed - known
|
|
140
|
+
carry = []
|
|
141
|
+
for identity, cell in census.cells.items():
|
|
142
|
+
sources = dependencies.get(identity, set())
|
|
143
|
+
target = cell.target.partition(":")[0]
|
|
144
|
+
if (not unknown and old.cells.get(identity) == cell and target in sources
|
|
145
|
+
and not changed.intersection(sources)
|
|
146
|
+
and verdicts.get(identity, ("missing", ""))[0] in ("clean", "n/a")):
|
|
147
|
+
carry.append(identity)
|
|
148
|
+
reason = ("unmapped changed inputs: " + ", ".join(sorted(unknown))) if unknown else (
|
|
149
|
+
"review changed dependencies and prior findings; attest carry boundaries"
|
|
150
|
+
)
|
|
151
|
+
carry_ids = set(carry)
|
|
152
|
+
return ReviewScope(
|
|
153
|
+
baseline,
|
|
154
|
+
tuple(key for key in census.cells if key not in carry_ids),
|
|
155
|
+
tuple(carry),
|
|
156
|
+
reason,
|
|
157
|
+
)
|
|
@@ -58,6 +58,16 @@ def _review_date(raw: str) -> str:
|
|
|
58
58
|
return raw
|
|
59
59
|
|
|
60
60
|
|
|
61
|
+
def _resolve_base_commit(repo: Path, base: str) -> str:
|
|
62
|
+
base_commit = _git_out(
|
|
63
|
+
repo, "rev-parse", "--verify", "--quiet", "--end-of-options",
|
|
64
|
+
f"{base}^{{commit}}",
|
|
65
|
+
)
|
|
66
|
+
if not base_commit:
|
|
67
|
+
raise StateError(f"base {base!r} is not a commit", stage="base_missing")
|
|
68
|
+
return base_commit
|
|
69
|
+
|
|
70
|
+
|
|
61
71
|
def _branch_snapshot(repo: Path, branch: str, base: str, review_date: str) -> dict:
|
|
62
72
|
head = _git_out(repo, "rev-parse", branch)
|
|
63
73
|
if not head:
|
|
@@ -66,12 +76,7 @@ def _branch_snapshot(repo: Path, branch: str, base: str, review_date: str) -> di
|
|
|
66
76
|
raise StateError(
|
|
67
77
|
"branch reviews require --base <branch-or-commit>", stage="args"
|
|
68
78
|
)
|
|
69
|
-
base_commit =
|
|
70
|
-
repo, "rev-parse", "--verify", "--quiet", "--end-of-options",
|
|
71
|
-
f"{base}^{{commit}}",
|
|
72
|
-
)
|
|
73
|
-
if not base_commit:
|
|
74
|
-
raise StateError(f"base {base!r} is not a commit", stage="base_missing")
|
|
79
|
+
base_commit = _resolve_base_commit(repo, base)
|
|
75
80
|
review_path, seq = next_branch_review(branch_review_dir(repo, branch), review_date)
|
|
76
81
|
return {
|
|
77
82
|
"mode": "branch",
|
|
@@ -88,14 +93,15 @@ _CLI_EPILOG = r"""Usage:
|
|
|
88
93
|
okstra code-review target --task-key <k> --stage <N> [--base <ref>] [--project-root <dir>] [--cwd <dir>] --json
|
|
89
94
|
okstra code-review target --branch <name> --base <ref> [--date <YYYY-MM-DD>] [--project-root <dir>] --json
|
|
90
95
|
okstra code-review check-coverage --head <ref> --census <table-path> --completion <completion-path> [--completion ...] [--project-root <dir>]
|
|
96
|
+
okstra code-review scope --base <ref> --head <ref> --census <path> --policy <path> [--previous-head <ref> --previous-census <path> --completion <path> ...]
|
|
91
97
|
okstra code-review check-lines --base <ref> --head <ref> --cite <path:line> [--cite ...] [--project-root <dir>]
|
|
92
98
|
|
|
93
99
|
Output: JSON { ok, mode, worktreePath, branch, baseCommit, headCommit,
|
|
94
100
|
reviewPath, round, reportLanguage }. `check-lines` prints `ok`, `not-changed`
|
|
95
101
|
(with the file's changed lines) or `not-in-diff` per citation and exits 1 when
|
|
96
102
|
any citation is not a line the range changed. `--base` sets the base in either mode. Without it, stage
|
|
97
|
-
mode
|
|
98
|
-
|
|
103
|
+
mode selects the base from the stage registry row. Both modes resolve the
|
|
104
|
+
selected base to a fixed commit; branch mode requires an explicit base. An empty
|
|
99
105
|
worktreePath means the review reads the branch ref
|
|
100
106
|
instead of a checked-out tree. This is read-only — it never creates
|
|
101
107
|
directories or files. `check-coverage` reads each evidence file at `--head`, not
|
|
@@ -111,7 +117,7 @@ def _build_parser() -> argparse.ArgumentParser:
|
|
|
111
117
|
prog="okstra code-review",
|
|
112
118
|
description="Resolve a code review's diff range and result file path, or check finding citations."
|
|
113
119
|
)
|
|
114
|
-
parser.add_argument("command", choices=("target", "check-lines", "check-coverage"))
|
|
120
|
+
parser.add_argument("command", choices=("target", "check-lines", "check-coverage", "scope"))
|
|
115
121
|
parser.add_argument("--task-key", default="", help="project-id:task-group:task-id")
|
|
116
122
|
parser.add_argument("--stage", type=int, default=0, help="stage number to review")
|
|
117
123
|
parser.add_argument("--branch", default="", help="branch to review")
|
|
@@ -131,6 +137,10 @@ def _build_parser() -> argparse.ArgumentParser:
|
|
|
131
137
|
parser.add_argument("--census", default="", help="check-coverage: shared Rules and grouped Cells tables")
|
|
132
138
|
parser.add_argument("--completion", action="append", default=[],
|
|
133
139
|
help="check-coverage: verified reviewer completion (repeat for gap-fills)")
|
|
140
|
+
parser.add_argument("--previous-head", default="", help="scope: previous reviewed commit")
|
|
141
|
+
parser.add_argument("--previous-census", default="", help="scope: previous full census")
|
|
142
|
+
parser.add_argument("--policy", action="append", default=[],
|
|
143
|
+
help="scope: policy/calibration source to fingerprint (repeatable)")
|
|
134
144
|
parser.add_argument("--date", default="", help="YYYY-MM-DD for branch result naming")
|
|
135
145
|
parser.add_argument("--project-root", default="", help="explicit project root")
|
|
136
146
|
parser.add_argument("--cwd", default=".", help="cwd for project root resolution")
|
|
@@ -311,6 +321,8 @@ def main(argv: list[str] | None = None) -> int:
|
|
|
311
321
|
print(render_code_review_target_text(payload) if args.text else json.dumps(payload))
|
|
312
322
|
return 2
|
|
313
323
|
|
|
324
|
+
if args.command == "scope":
|
|
325
|
+
return _scope(args, Path(project_root))
|
|
314
326
|
if args.command == "check-coverage":
|
|
315
327
|
return _check_coverage(args, Path(project_root))
|
|
316
328
|
if args.command == "check-lines":
|
|
@@ -340,6 +352,28 @@ def main(argv: list[str] | None = None) -> int:
|
|
|
340
352
|
return 0
|
|
341
353
|
|
|
342
354
|
|
|
355
|
+
def _scope(args: argparse.Namespace, project_root: Path) -> int:
|
|
356
|
+
from .agent.invocation import AgentInvocationError
|
|
357
|
+
from .code_review_scope import review_scope
|
|
358
|
+
|
|
359
|
+
if not (args.base and args.head and args.census and args.policy):
|
|
360
|
+
print("scope: pass --base, --head, --census and --policy", file=sys.stderr)
|
|
361
|
+
return 2
|
|
362
|
+
try:
|
|
363
|
+
result = review_scope(
|
|
364
|
+
project_root, Path(args.census), args.base, args.head,
|
|
365
|
+
[Path(path).expanduser() for path in args.policy],
|
|
366
|
+
previous_head=args.previous_head,
|
|
367
|
+
previous_census=Path(args.previous_census) if args.previous_census else None,
|
|
368
|
+
completions=[Path(path) for path in args.completion],
|
|
369
|
+
)
|
|
370
|
+
except (OSError, ValueError, AgentInvocationError) as exc:
|
|
371
|
+
print(f"scope: {exc}", file=sys.stderr)
|
|
372
|
+
return 2
|
|
373
|
+
print(result.render(), end="")
|
|
374
|
+
return 0
|
|
375
|
+
|
|
376
|
+
|
|
343
377
|
# ---- stage 모드 해소 -------------------------------------------------------
|
|
344
378
|
# 모듈 도크스트링이 "stage 규칙은 code_review_target_snapshot 이 소유한다" 고
|
|
345
379
|
# 적어 두었지만 실제 함수는 okstra_project.state 에 있었고, 거기서 okstra_ctl 을
|
|
@@ -388,9 +422,11 @@ def code_review_target_snapshot(
|
|
|
388
422
|
coords = (identity["projectId"], identity["taskGroup"], identity["taskId"])
|
|
389
423
|
stage_row = worktree_registry.get_stage_row(*coords, stage) or {}
|
|
390
424
|
worktree_view = _stage_worktree_view(project_root, stage_row, stage)
|
|
391
|
-
|
|
425
|
+
base_ref = base or stage_row.get("base_ref") or _legacy_stage_base_commit(
|
|
392
426
|
identity, stages, selected
|
|
393
427
|
)
|
|
428
|
+
git_root = Path(worktree_view["worktreePath"] or project_root)
|
|
429
|
+
base_commit = _resolve_base_commit(git_root, base_ref)
|
|
394
430
|
review_path, round_no = code_review_paths.next_stage_review(
|
|
395
431
|
code_review_paths.stage_review_dir(
|
|
396
432
|
project_root, identity["taskGroup"], identity["taskId"]
|
|
@@ -56,9 +56,15 @@ def normalize_conformance_script(
|
|
|
56
56
|
호출부가 있다.
|
|
57
57
|
"""
|
|
58
58
|
prefix = "<task_root>/"
|
|
59
|
-
|
|
60
|
-
while
|
|
61
|
-
|
|
59
|
+
start = 0
|
|
60
|
+
while True:
|
|
61
|
+
if script.startswith(prefix, start):
|
|
62
|
+
start += len(prefix)
|
|
63
|
+
elif script.startswith("./", start):
|
|
64
|
+
start += 2
|
|
65
|
+
else:
|
|
66
|
+
break
|
|
67
|
+
value = script[start:]
|
|
62
68
|
if task_root is not None and value.startswith(".okstra/"):
|
|
63
69
|
for parent in task_root.resolve().parents:
|
|
64
70
|
if parent.name == ".okstra" and task_root.resolve().is_relative_to(
|
|
@@ -272,8 +272,12 @@ def _files_cell_tokens(cell: str) -> list[str]:
|
|
|
272
272
|
return tokens
|
|
273
273
|
|
|
274
274
|
|
|
275
|
+
# Characters that continue a path: a path is named only where neither side has one.
|
|
276
|
+
PATH_CHARS = r"\w./@-"
|
|
277
|
+
|
|
278
|
+
|
|
275
279
|
def _cell_covers_path(cell: str, path: str) -> bool:
|
|
276
|
-
path_pattern = rf"(?<![
|
|
280
|
+
path_pattern = rf"(?<![{PATH_CHARS}]){re.escape(path)}(?![{PATH_CHARS}])"
|
|
277
281
|
if re.search(path_pattern, cell) is not None:
|
|
278
282
|
return True
|
|
279
283
|
for token in _files_cell_tokens(cell):
|
|
@@ -301,6 +305,27 @@ def _stages_touching_path(
|
|
|
301
305
|
return hits
|
|
302
306
|
|
|
303
307
|
|
|
308
|
+
def _declared_parts(path: str) -> list[str]:
|
|
309
|
+
parts = [
|
|
310
|
+
_LINE_RANGE_SUFFIX.sub("", _normalise(part))
|
|
311
|
+
for part in (_split_declared_paths(path) or [path])
|
|
312
|
+
]
|
|
313
|
+
return [part for part in parts if part]
|
|
314
|
+
|
|
315
|
+
|
|
316
|
+
def stages_touching_declared_path(
|
|
317
|
+
path: str,
|
|
318
|
+
stages: Mapping[int, Mapping[str, Any]],
|
|
319
|
+
) -> list[int]:
|
|
320
|
+
"""Every stage whose step cells touch a part of a ``fileStructure`` path."""
|
|
321
|
+
matched: list[int] = []
|
|
322
|
+
for part in _declared_parts(path):
|
|
323
|
+
for stage_number in _stages_touching_path(part, stages):
|
|
324
|
+
if stage_number not in matched:
|
|
325
|
+
matched.append(stage_number)
|
|
326
|
+
return matched
|
|
327
|
+
|
|
328
|
+
|
|
304
329
|
def _stages_for_selected_path(
|
|
305
330
|
path: str,
|
|
306
331
|
stages: Mapping[int, Mapping[str, Any]],
|
|
@@ -318,32 +343,22 @@ def _stages_for_selected_path(
|
|
|
318
343
|
Zero stages is still an error: the recommended option declares a file that
|
|
319
344
|
no step creates or edits.
|
|
320
345
|
"""
|
|
321
|
-
declared =
|
|
322
|
-
_LINE_RANGE_SUFFIX.sub("", _normalise(part))
|
|
323
|
-
for part in (_split_declared_paths(path) or [path])
|
|
324
|
-
]
|
|
325
|
-
declared = [part for part in declared if part]
|
|
346
|
+
declared = _declared_parts(path)
|
|
326
347
|
if not declared:
|
|
327
348
|
raise DesignSurfaceError(
|
|
328
349
|
f"selected option path {path!r} is not mapped to a stage"
|
|
329
350
|
)
|
|
330
|
-
matched: list[int] = []
|
|
331
|
-
seen: set[int] = set()
|
|
332
351
|
for part in declared:
|
|
333
|
-
|
|
334
|
-
|
|
352
|
+
if _stages_touching_path(part, stages):
|
|
353
|
+
continue
|
|
354
|
+
if "qa/scripts/" in part:
|
|
335
355
|
# 적합성 스크립트는 executor 가 역할 권한으로 쓴다(write_policy
|
|
336
356
|
# `_role_qa_artifact_paths`). 계획 step 의 files·plannedPaths 칸에는 원래 없다.
|
|
337
357
|
continue
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
for stage_number in hits:
|
|
343
|
-
if stage_number not in seen:
|
|
344
|
-
seen.add(stage_number)
|
|
345
|
-
matched.append(stage_number)
|
|
346
|
-
return matched
|
|
358
|
+
raise DesignSurfaceError(
|
|
359
|
+
f"selected option path {part!r} is not mapped to a stage"
|
|
360
|
+
)
|
|
361
|
+
return stages_touching_declared_path(path, stages)
|
|
347
362
|
|
|
348
363
|
|
|
349
364
|
def detect_design_surfaces(
|
|
@@ -385,3 +400,20 @@ def detect_design_surfaces(
|
|
|
385
400
|
key=lambda key: (key[0], rule_order[key[1]]),
|
|
386
401
|
)
|
|
387
402
|
]
|
|
403
|
+
|
|
404
|
+
|
|
405
|
+
def detect_design_surfaces_in_unvalidated_plan(
|
|
406
|
+
planning: object,
|
|
407
|
+
) -> list[DesignSurfaceTrigger]:
|
|
408
|
+
"""Detect design surfaces of an unvalidated plan; a plan without stages has none.
|
|
409
|
+
|
|
410
|
+
Every detection failure, including a malformed row the detector trips over,
|
|
411
|
+
becomes one `DesignSurfaceError`, so the draft check and `plan-items prepare`
|
|
412
|
+
reach the same verdict on the same plan.
|
|
413
|
+
"""
|
|
414
|
+
if not isinstance(planning, Mapping) or not planning.get("stages"):
|
|
415
|
+
return []
|
|
416
|
+
try:
|
|
417
|
+
return detect_design_surfaces(planning)
|
|
418
|
+
except (DesignSurfaceError, TypeError, AttributeError) as exc:
|
|
419
|
+
raise DesignSurfaceError(f"design-surface detection failed: {exc}") from exc
|
|
@@ -62,30 +62,38 @@ def _check_type(value: Any, expected: str) -> bool:
|
|
|
62
62
|
return isinstance(value, _TYPE_PYTHON.get(expected, ()))
|
|
63
63
|
|
|
64
64
|
|
|
65
|
-
def
|
|
66
|
-
if isinstance(
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
65
|
+
def json_schema_number_key(value: int | float) -> str:
|
|
66
|
+
if isinstance(value, float) and value.is_integer():
|
|
67
|
+
value = int(value)
|
|
68
|
+
return str(value)
|
|
69
|
+
|
|
70
|
+
|
|
71
|
+
def _intern_json_schema_value(
|
|
72
|
+
value: Any, identities: dict[tuple[type, Any], int],
|
|
73
|
+
) -> int:
|
|
74
|
+
pending = [(value, False)]
|
|
75
|
+
completed: list[int] = []
|
|
76
|
+
while pending:
|
|
77
|
+
item, expanded = pending.pop()
|
|
78
|
+
if isinstance(item, (dict, list)):
|
|
79
|
+
if not expanded:
|
|
80
|
+
pending.append((item, True))
|
|
81
|
+
values = tuple(item.values()) if isinstance(item, dict) else item
|
|
82
|
+
pending.extend((child, False) for child in reversed(values))
|
|
83
|
+
continue
|
|
84
|
+
start = len(completed) - len(item)
|
|
85
|
+
children = tuple(completed[start:])
|
|
86
|
+
del completed[start:]
|
|
87
|
+
key = ((dict, frozenset(zip(item, children)))
|
|
88
|
+
if isinstance(item, dict) else (list, children))
|
|
89
|
+
elif isinstance(item, bool):
|
|
90
|
+
key = (bool, item)
|
|
91
|
+
elif isinstance(item, (int, float)):
|
|
92
|
+
key = (int, json_schema_number_key(item))
|
|
93
|
+
else:
|
|
94
|
+
key = (type(item), item)
|
|
95
|
+
completed.append(identities.setdefault(key, len(identities)))
|
|
96
|
+
return completed[0]
|
|
89
97
|
|
|
90
98
|
|
|
91
99
|
def _resolve_ref(ref: str, root: dict) -> dict:
|
|
@@ -263,12 +271,11 @@ class _Validator:
|
|
|
263
271
|
max_items = schema.get("maxItems")
|
|
264
272
|
if max_items is not None and len(instance) > max_items:
|
|
265
273
|
self._err(path, f"array length {len(instance)} > maxItems {max_items}")
|
|
266
|
-
if schema.get("uniqueItems") is True
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
self._err(path, "array items are not unique")
|
|
274
|
+
if schema.get("uniqueItems") is True:
|
|
275
|
+
identities: dict[tuple[type, Any], int] = {}
|
|
276
|
+
if len({_intern_json_schema_value(item, identities)
|
|
277
|
+
for item in instance}) != len(instance):
|
|
278
|
+
self._err(path, "array items are not unique")
|
|
272
279
|
prefix_items = schema.get("prefixItems") or []
|
|
273
280
|
for i, item_schema in enumerate(prefix_items[: len(instance)]):
|
|
274
281
|
self.validate(instance[i], item_schema, path + (i,))
|
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
"""모델용 고정 텍스트 투영의 scalar 줄 형식을 공유한다."""
|
|
2
2
|
from __future__ import annotations
|
|
3
3
|
|
|
4
|
+
import json
|
|
4
5
|
import re
|
|
6
|
+
from typing import Callable
|
|
5
7
|
|
|
6
8
|
|
|
7
9
|
_CONTROL = re.compile(r"[\x00-\x09\x0b\x0c\x0e-\x1f\x7f-\x9f\u2028\u2029]")
|
|
@@ -34,24 +36,44 @@ def block(text: str) -> str:
|
|
|
34
36
|
return _one_line(text)
|
|
35
37
|
|
|
36
38
|
|
|
37
|
-
def
|
|
38
|
-
"""한 scalar를 Markdown 목록 한 줄로 렌더한다."""
|
|
39
|
+
def _line_prefix(label: str) -> str:
|
|
39
40
|
if not re.fullmatch(r"[A-Za-z][A-Za-z0-9 ()/.-]*", label):
|
|
40
41
|
raise ValueError("fixed text label must be a static single-line label")
|
|
41
|
-
return f"- {label}:
|
|
42
|
+
return f"- {label}: "
|
|
43
|
+
|
|
44
|
+
|
|
45
|
+
def line(label: str, value: object) -> str:
|
|
46
|
+
"""한 scalar를 Markdown 목록 한 줄로 렌더한다."""
|
|
47
|
+
return f"{_line_prefix(label)}`{scalar(value)}`\n"
|
|
42
48
|
|
|
43
49
|
|
|
44
50
|
def value_lines(label: str, value: object) -> list[str]:
|
|
45
51
|
"""JSON 모양의 복합 값을 이름/순서/값 고정 줄로 손실 없이 펼친다."""
|
|
52
|
+
return _value_lines(label, value, line)
|
|
53
|
+
|
|
54
|
+
|
|
55
|
+
def _quoted_scalar_line(label: str, value: object) -> str:
|
|
56
|
+
return _line_prefix(label) + json.dumps(value, ensure_ascii=True) + "\n"
|
|
57
|
+
|
|
58
|
+
|
|
59
|
+
def quoted_value_lines(label: str, value: object) -> list[str]:
|
|
60
|
+
return _value_lines(label, value, _quoted_scalar_line)
|
|
61
|
+
|
|
62
|
+
|
|
63
|
+
def _value_lines(
|
|
64
|
+
label: str, value: object, render_line: Callable[[str, object], str],
|
|
65
|
+
) -> list[str]:
|
|
46
66
|
if isinstance(value, dict):
|
|
47
|
-
rows = [
|
|
67
|
+
rows = [render_line(f"{label} field count", len(value))]
|
|
48
68
|
for index, (name, child) in enumerate(value.items(), 1):
|
|
49
|
-
rows.append(
|
|
50
|
-
rows.extend(
|
|
69
|
+
rows.append(render_line(f"{label} field {index} name", name))
|
|
70
|
+
rows.extend(_value_lines(
|
|
71
|
+
f"{label} field {index} value", child, render_line,
|
|
72
|
+
))
|
|
51
73
|
return rows
|
|
52
74
|
if isinstance(value, list):
|
|
53
|
-
rows = [
|
|
75
|
+
rows = [render_line(f"{label} item count", len(value))]
|
|
54
76
|
for index, child in enumerate(value, 1):
|
|
55
|
-
rows.extend(
|
|
77
|
+
rows.extend(_value_lines(f"{label} item {index}", child, render_line))
|
|
56
78
|
return rows
|
|
57
|
-
return [
|
|
79
|
+
return [render_line(label, value)]
|
|
@@ -31,6 +31,10 @@ from .report_views import (
|
|
|
31
31
|
direction_candidate_ineligibility,
|
|
32
32
|
normalize_direction_selection_identity,
|
|
33
33
|
)
|
|
34
|
+
from .phases.implementation_option_selection.validation import (
|
|
35
|
+
selection_candidates,
|
|
36
|
+
validate_split_acceptance,
|
|
37
|
+
)
|
|
34
38
|
from .qa_commands import find_denied_tokens
|
|
35
39
|
from .user_response import UserResponseError, parse_direction_selection
|
|
36
40
|
|
|
@@ -302,6 +306,11 @@ def _selected_option(
|
|
|
302
306
|
)
|
|
303
307
|
if option is None:
|
|
304
308
|
raise DirectionSelectionError("selected option is not a ranked candidate")
|
|
309
|
+
# The gate does not run the option-selection validator, which owns id
|
|
310
|
+
# uniqueness; a repeated id would leave which direction was accepted ambiguous.
|
|
311
|
+
same_id = [row for row in selection_candidates(selection) if row.get("id") == option_id]
|
|
312
|
+
if len(same_id) > 1:
|
|
313
|
+
raise DirectionSelectionError("selected option id names more than one candidate")
|
|
305
314
|
try:
|
|
306
315
|
report_option_id, report_option_name = normalize_direction_selection_identity(
|
|
307
316
|
str(option.get("id") or ""), str(option.get("name") or "")
|
|
@@ -326,6 +335,14 @@ def _validate_no_blockers(data: Mapping[str, Any]) -> None:
|
|
|
326
335
|
)
|
|
327
336
|
|
|
328
337
|
|
|
338
|
+
def _validate_split_acceptance(data: Mapping[str, Any]) -> None:
|
|
339
|
+
# `blocking_feasibility_facts` trusts any `splitAcceptance` ref, so the gate
|
|
340
|
+
# re-checks the cited answer before it trusts the candidate's validity.
|
|
341
|
+
errors = validate_split_acceptance(data)
|
|
342
|
+
if errors:
|
|
343
|
+
raise DirectionSelectionError("; ".join(errors))
|
|
344
|
+
|
|
345
|
+
|
|
329
346
|
def _direction_payload(option: Mapping[str, Any]) -> dict[str, Any]:
|
|
330
347
|
fields = (
|
|
331
348
|
"goal",
|
|
@@ -387,6 +404,7 @@ def resolve_selected_direction(
|
|
|
387
404
|
evidence, option_id, note, constraints = _preselected_selection(selection)
|
|
388
405
|
else:
|
|
389
406
|
raise DirectionSelectionError(f"unsupported selection mode: {mode}")
|
|
407
|
+
_validate_split_acceptance(data)
|
|
390
408
|
option, normalized_option_name = _selected_option(selection, option_id)
|
|
391
409
|
_validate_no_blockers(data)
|
|
392
410
|
return SelectedDirection(
|