okstra 0.232.0 → 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 -283
- package/dist/cli-registry.mjs +8 -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/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.mjs +2 -17
- package/dist/lib/memory-auto-register.mjs.map +1 -1
- 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/docs/architecture/storage-model.md +36 -5
- package/docs/architecture.md +10 -4
- package/docs/cli.md +279 -2
- package/docs/contributor-change-matrix.md +1 -2
- package/docs/project-structure-overview.md +31 -41
- package/package.json +1 -1
- package/runtime/BUILD.json +2 -2
- package/runtime/agents/operations/trace-interface-review.json +6 -0
- package/runtime/agents/operations/trace-scope-review.json +6 -0
- package/runtime/prompts/coding-preflight/authoring-checks.md +1 -1
- package/runtime/prompts/coding-preflight/clean-code.md +18 -20
- package/runtime/prompts/coding-preflight/overview.md +1 -1
- package/runtime/prompts/duties/code-reviewer.json +1 -1
- 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 +2 -2
- package/runtime/prompts/profiles/_common-contract.md +1 -1
- package/runtime/python/okstra_ctl/agent/invocation.py +1 -0
- package/runtime/python/okstra_ctl/agent/prompt_cli/cli.py +66 -26
- package/runtime/python/okstra_ctl/agent/prompt_cli/corrections.py +23 -8
- package/runtime/python/okstra_ctl/agent/prompt_cli/materialize.py +28 -10
- package/runtime/python/okstra_ctl/agent/prompt_cli/results.py +8 -11
- package/runtime/python/okstra_ctl/agent/standalone.py +12 -0
- package/runtime/python/okstra_ctl/analysis_packet.py +22 -11
- package/runtime/python/okstra_ctl/code_review_census.py +93 -2
- 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 +13 -0
- package/runtime/python/okstra_ctl/code_review_supervisor.py +41 -0
- package/runtime/python/okstra_ctl/code_review_target.py +140 -15
- package/runtime/python/okstra_ctl/coverage_census.py +11 -2
- 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/domain/role.py +1 -0
- package/runtime/python/okstra_ctl/doyouknow/sources/manager.py +48 -9
- 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 +33 -6
- package/runtime/python/okstra_ctl/manager_cli.py +122 -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_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 +42 -3
- 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 +3 -0
- 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/implementation/host-rules.md +3 -3
- package/runtime/python/okstra_ctl/phases/implementation/instructions/_implementation-diff-review.md +8 -6
- package/runtime/python/okstra_ctl/phases/implementation/instructions/_implementation-self-check.md +1 -1
- 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 +12 -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 +5 -5
- 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 +38 -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 +179 -7
- package/runtime/python/okstra_ctl/report_projections.py +64 -18
- package/runtime/python/okstra_ctl/report_synthesis_packet.py +86 -36
- package/runtime/python/okstra_ctl/run.py +43 -35
- 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/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/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_project/state.py +20 -0
- 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/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 +58 -50
- package/runtime/skills/okstra-code-review/references/census-rules.md +6 -6
- package/runtime/skills/okstra-code-review/references/review-calibration.md +8 -12
- 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 +24 -0
- package/runtime/skills/okstra-memory/SKILL.md +1 -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/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/validators/checks/fixtures-02.py +25 -33
- package/runtime/validators/validate-run.py +93 -36
|
@@ -35,9 +35,9 @@ from ...report_corrections import (
|
|
|
35
35
|
load_corrections,
|
|
36
36
|
render_applied_narrative,
|
|
37
37
|
)
|
|
38
|
-
from ...report_inputs import report_narrative_path, uses_report_contract_v3
|
|
38
|
+
from ...report_inputs import report_authoring_format, report_narrative_path, uses_report_contract_v3
|
|
39
39
|
from ...paths import STAGE_VALIDATOR_RELATIVE, find_asset_root
|
|
40
|
-
from ...report_narrative import task_narrative_errors
|
|
40
|
+
from ...report_narrative import load_report_narrative, task_narrative_errors
|
|
41
41
|
from ...report_synthesis_packet import (
|
|
42
42
|
ReportSynthesisPacketError,
|
|
43
43
|
ReportSynthesisPacket,
|
|
@@ -68,13 +68,13 @@ def run_corrections_check(
|
|
|
68
68
|
if not uses_report_contract_v3(manifest):
|
|
69
69
|
return CorrectionsCheck(ledger, (), None, False, {}, (
|
|
70
70
|
"owner=lead correction=ledger path=- reason=corrections require report "
|
|
71
|
-
"contract 3.0
|
|
71
|
+
"contract 3.0; this run uses an older contract",
|
|
72
72
|
))
|
|
73
73
|
contract = manifest.get("agentContract")
|
|
74
74
|
authorized = contract.get("authorizedPaths") if isinstance(contract, Mapping) else None
|
|
75
75
|
authorized = authorized if isinstance(authorized, Mapping) else {}
|
|
76
76
|
try:
|
|
77
|
-
|
|
77
|
+
_authorized_path(
|
|
78
78
|
project_root,
|
|
79
79
|
str(ledger.get("baseNarrativePath") or ""),
|
|
80
80
|
authorized.get("resultRoots"),
|
|
@@ -85,6 +85,19 @@ def run_corrections_check(
|
|
|
85
85
|
return CorrectionsCheck(ledger, (), None, False, {}, (
|
|
86
86
|
f"owner=lead correction=ledger path={ledger.get('baseNarrativePath')} reason={exc}",
|
|
87
87
|
))
|
|
88
|
+
# Keep the original spelling so the JSON boundary can inspect symlink components.
|
|
89
|
+
base_path = Path(str(ledger["baseNarrativePath"]))
|
|
90
|
+
if not base_path.is_absolute():
|
|
91
|
+
base_path = project_root / base_path
|
|
92
|
+
try:
|
|
93
|
+
input_format = report_authoring_format(manifest)
|
|
94
|
+
load_report_narrative(project_root, manifest, load_schema_version("3.0"),
|
|
95
|
+
path=base_path, structure_only=True,
|
|
96
|
+
allow_preserved_attempt=True)
|
|
97
|
+
except (OSError, UnicodeError, ValueError) as exc:
|
|
98
|
+
return CorrectionsCheck(ledger, (), None, False, {}, (
|
|
99
|
+
f"owner=lead correction=ledger path={base_path} reason=base narrative does not parse: {exc}",
|
|
100
|
+
))
|
|
88
101
|
try:
|
|
89
102
|
packet = build_report_synthesis_packet(
|
|
90
103
|
project_root=project_root,
|
|
@@ -109,6 +122,7 @@ def run_corrections_check(
|
|
|
109
122
|
rewrite_results is None and any(item.get("kind") == "rewrite" for item in ledger["corrections"]),
|
|
110
123
|
),
|
|
111
124
|
rewrite_results=rewrite_results,
|
|
125
|
+
input_format=input_format,
|
|
112
126
|
)
|
|
113
127
|
|
|
114
128
|
|
|
@@ -195,8 +209,7 @@ def run_corrections_apply(
|
|
|
195
209
|
"""
|
|
196
210
|
if not uses_report_contract_v3(manifest):
|
|
197
211
|
raise AgentPromptCliError(
|
|
198
|
-
"apply-corrections requires report contract 3.0
|
|
199
|
-
"narrative); this run uses an older contract"
|
|
212
|
+
"apply-corrections requires report contract 3.0; this run uses an older contract"
|
|
200
213
|
)
|
|
201
214
|
narrative_path = report_narrative_path(project_root, manifest)
|
|
202
215
|
events_value = manifest.get("leadEventsPath")
|
|
@@ -225,12 +238,14 @@ def run_corrections_apply(
|
|
|
225
238
|
)
|
|
226
239
|
return _apply_checked_corrections(
|
|
227
240
|
project_root, manifest_path, narrative_path, corrections_path, check, rewrite_results_path,
|
|
241
|
+
input_format=report_authoring_format(manifest),
|
|
228
242
|
)
|
|
229
243
|
|
|
230
244
|
|
|
231
245
|
def _apply_checked_corrections(
|
|
232
246
|
project_root: Path, manifest_path: Path, narrative_path: Path,
|
|
233
247
|
corrections_path: Path, check: CorrectionsCheck, rewrite_results_path: Path | None,
|
|
248
|
+
*, input_format: str = "markdown-v1",
|
|
234
249
|
) -> dict[str, Any]:
|
|
235
250
|
corrections_rel = _relative(project_root, corrections_path)
|
|
236
251
|
if check.defects:
|
|
@@ -253,7 +268,7 @@ def _apply_checked_corrections(
|
|
|
253
268
|
"baseNarrativePath is the live narrative "
|
|
254
269
|
f"({_relative(project_root, narrative_path)}); applying would "
|
|
255
270
|
"overwrite the only copy of the attempt being corrected. Copy it "
|
|
256
|
-
"to worker-results/report-writer-narrative-a<N>-<task-type>-<seq
|
|
271
|
+
f"to worker-results/report-writer-narrative-a<N>-<task-type>-<seq>{narrative_path.suffix} "
|
|
257
272
|
"first and point the ledger at that copy"
|
|
258
273
|
)
|
|
259
274
|
previous = _already_applied(project_root, manifest_path, corrections_rel)
|
|
@@ -265,7 +280,7 @@ def _apply_checked_corrections(
|
|
|
265
280
|
)
|
|
266
281
|
applied_ids = [str(item.get("id")) for item in check.corrections]
|
|
267
282
|
narrative_rel = _relative(project_root, narrative_path)
|
|
268
|
-
rendered = render_applied_narrative(check, load_schema_version("3.0"))
|
|
283
|
+
rendered = render_applied_narrative(check, load_schema_version("3.0"), input_format=input_format)
|
|
269
284
|
if narrative_path.is_file() and narrative_path.read_text(encoding="utf-8") not in (
|
|
270
285
|
base_path.read_text(encoding="utf-8"), rendered,
|
|
271
286
|
):
|
|
@@ -34,6 +34,8 @@ from ...assignment_environment import load_assignment_context
|
|
|
34
34
|
from ..standalone import StandaloneInvocationRequest, prepare_standalone_invocation
|
|
35
35
|
from ...code_review_invocation import CodeReviewInputs
|
|
36
36
|
from ...path_hints import hydrate_active_run_context
|
|
37
|
+
from ...json_boundary import JsonBoundaryError, OUTSIDE_WORKER_RESULT_LANES
|
|
38
|
+
from ...phases.improvement_discovery.resolved_census import prepare_resolved_lens_census
|
|
37
39
|
from ...worker_prompt_headers import worker_prompt_headers
|
|
38
40
|
from ...worker_prompt_contract import (
|
|
39
41
|
complete_reverify_instruction,
|
|
@@ -44,6 +46,7 @@ from ...worker_prompt_policy import (
|
|
|
44
46
|
critic_assignment_ref,
|
|
45
47
|
is_critic_verification,
|
|
46
48
|
is_verification_dispatch_kind,
|
|
49
|
+
resolve_prompt_plan_for_manifest,
|
|
47
50
|
)
|
|
48
51
|
from ...paths import okstra_home
|
|
49
52
|
from ...contract_refreeze import (
|
|
@@ -58,8 +61,8 @@ from ...initial_prompt_materialization import (
|
|
|
58
61
|
)
|
|
59
62
|
from ...final_report_paths import final_report_data_path
|
|
60
63
|
from ...final_report_schema import load_schema_version
|
|
61
|
-
from ...report_inputs import report_narrative_path, uses_report_contract_v3
|
|
62
|
-
from ...report_narrative import NarrativeContractError,
|
|
64
|
+
from ...report_inputs import report_authoring_format, report_narrative_path, uses_report_contract_v3
|
|
65
|
+
from ...report_narrative import NarrativeContractError, load_report_narrative
|
|
63
66
|
from ...report_synthesis_packet import (
|
|
64
67
|
ReportSynthesisPacketError,
|
|
65
68
|
materialize_report_synthesis_packet,
|
|
@@ -314,6 +317,15 @@ def _materialize_run(
|
|
|
314
317
|
active_context = hydrate_active_run_context(
|
|
315
318
|
_read_json_object(active_context_path, "active run context")
|
|
316
319
|
)
|
|
320
|
+
if args.dispatch_kind == "initial" and manifest.get("taskType") == "improvement-discovery":
|
|
321
|
+
try:
|
|
322
|
+
plan = resolve_prompt_plan_for_manifest(
|
|
323
|
+
manifest=manifest, worker_id=args.worker_id, dispatch_kind="initial",
|
|
324
|
+
)
|
|
325
|
+
if plan.audience == "analysis":
|
|
326
|
+
prepare_resolved_lens_census(project_root, manifest)
|
|
327
|
+
except (ValueError, JsonBoundaryError, OSError, UnicodeError) as exc:
|
|
328
|
+
raise AgentPromptCliError(str(exc)) from exc
|
|
317
329
|
metadata_path = prompt_path.with_name(prompt_path.name + ".meta.json")
|
|
318
330
|
generation = _reuse_or_seal_verifier_generation(
|
|
319
331
|
args, project_root, manifest_path, manifest, active_context, metadata_path,
|
|
@@ -370,7 +382,7 @@ def _materialize_run(
|
|
|
370
382
|
f"audience {args.audience} has no corrections ledger"
|
|
371
383
|
)
|
|
372
384
|
raise AgentPromptCliError(
|
|
373
|
-
"--corrections requires report contract 3.0
|
|
385
|
+
"--corrections requires report contract 3.0; "
|
|
374
386
|
"this run uses an older contract"
|
|
375
387
|
)
|
|
376
388
|
if args.audience in _RESOURCE_AUDIENCES and not is_reverify:
|
|
@@ -597,19 +609,20 @@ def _with_report_writer_sections(
|
|
|
597
609
|
check,
|
|
598
610
|
base_narrative_rel=str(check.ledger.get("baseNarrativePath") or ""),
|
|
599
611
|
corrections_rel=_relative(project_root, corrections_path),
|
|
612
|
+
input_format=report_authoring_format(manifest),
|
|
600
613
|
))
|
|
601
614
|
body = "## Inputs\n\nCorrection-only task: use the checked field values and evidence below."
|
|
602
615
|
sections.extend(_render_correction_application(args, project_root, narrative_path, corrections_path, check))
|
|
603
616
|
sections.append("")
|
|
604
617
|
else:
|
|
605
|
-
_refuse_free_form_correction(project_root, narrative_path)
|
|
618
|
+
_refuse_free_form_correction(project_root, narrative_path, manifest)
|
|
606
619
|
preserved = _preserve_reauthored_narrative(
|
|
607
620
|
project_root, narrative_path, invocation_id=str(args.invocation_id),
|
|
608
621
|
)
|
|
609
622
|
if preserved is not None:
|
|
610
623
|
sections.extend(_render_previous_attempt_section(preserved))
|
|
611
624
|
sections.append("")
|
|
612
|
-
sections.extend(render_output_section())
|
|
625
|
+
sections.extend(render_output_section(input_format=report_authoring_format(manifest)))
|
|
613
626
|
return body.rstrip("\n") + "\n\n" + "\n".join(sections) + "\n"
|
|
614
627
|
|
|
615
628
|
|
|
@@ -677,7 +690,9 @@ def _render_previous_attempt_section(preserved_rel: str) -> list[str]:
|
|
|
677
690
|
]
|
|
678
691
|
|
|
679
692
|
|
|
680
|
-
def _refuse_free_form_correction(
|
|
693
|
+
def _refuse_free_form_correction(
|
|
694
|
+
project_root: Path, narrative_path: Path, manifest: Mapping[str, Any],
|
|
695
|
+
) -> None:
|
|
681
696
|
"""서사가 이미 있고 구조가 읽히면 이 디스패치는 교정이다 — 원장 없이는 거절한다.
|
|
682
697
|
|
|
683
698
|
구조가 읽히지 않는 서사(줄 문법·소유권 결함)는 교정 대상이 아니라 재저작
|
|
@@ -688,9 +703,12 @@ def _refuse_free_form_correction(project_root: Path, narrative_path: Path) -> No
|
|
|
688
703
|
if not narrative_path.is_file():
|
|
689
704
|
return
|
|
690
705
|
try:
|
|
691
|
-
|
|
692
|
-
|
|
693
|
-
|
|
706
|
+
load_report_narrative(project_root, manifest, load_schema_version("3.0"),
|
|
707
|
+
path=narrative_path, structure_only=True)
|
|
708
|
+
except JsonBoundaryError as exc:
|
|
709
|
+
if exc.reason == OUTSIDE_WORKER_RESULT_LANES:
|
|
710
|
+
raise AgentPromptCliError(str(exc)) from exc
|
|
711
|
+
return
|
|
694
712
|
except NarrativeContractError:
|
|
695
713
|
return
|
|
696
714
|
narrative_rel = _relative(project_root, narrative_path)
|
|
@@ -705,7 +723,7 @@ def _refuse_free_form_correction(project_root: Path, narrative_path: Path) -> No
|
|
|
705
723
|
"--corrections here. A ledger of only replace/remove/add/move entries needs no "
|
|
706
724
|
"writer round: `okstra agent-prompt apply-corrections` writes the "
|
|
707
725
|
"narrative and records the activity row. Only a narrative whose "
|
|
708
|
-
"structure does not parse (
|
|
726
|
+
"structure does not parse (declared syntax or writer ownership) is "
|
|
709
727
|
"re-authored without a ledger; value defects are what the ledger fixes"
|
|
710
728
|
)
|
|
711
729
|
|
|
@@ -12,6 +12,7 @@ from datetime import datetime, timezone
|
|
|
12
12
|
from pathlib import Path
|
|
13
13
|
|
|
14
14
|
from ..invocation import (
|
|
15
|
+
AgentInvocationError,
|
|
15
16
|
AgentModelAssignment,
|
|
16
17
|
agent_model_assignment_from_payload,
|
|
17
18
|
materialize_standalone_result,
|
|
@@ -28,7 +29,6 @@ from ...dispatch_state import (
|
|
|
28
29
|
from .emit import _emit
|
|
29
30
|
from .inputs import (
|
|
30
31
|
AgentPromptCliError,
|
|
31
|
-
_is_relative_to,
|
|
32
32
|
_mapping,
|
|
33
33
|
_project_input,
|
|
34
34
|
_project_root,
|
|
@@ -149,27 +149,24 @@ def _verify(args: argparse.Namespace) -> None:
|
|
|
149
149
|
|
|
150
150
|
|
|
151
151
|
def _materialize_result(args: argparse.Namespace) -> None:
|
|
152
|
+
from ..standalone import standalone_returned_body
|
|
153
|
+
|
|
152
154
|
project_root = _project_root(args.project_root)
|
|
153
155
|
metadata_path = _project_input(project_root, args.metadata, "metadata")
|
|
154
|
-
root = project_root / ".okstra" / "agent-invocations" / args.purpose
|
|
155
|
-
temporary_root = root / ".tmp"
|
|
156
156
|
returned_body_path = _project_input(
|
|
157
157
|
project_root,
|
|
158
158
|
args.returned_body_file,
|
|
159
159
|
"returned body",
|
|
160
160
|
)
|
|
161
|
-
|
|
162
|
-
returned_body_path
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
raise AgentPromptCliError(
|
|
166
|
-
"returned body file must be inside the standalone purpose .tmp directory"
|
|
167
|
-
)
|
|
161
|
+
try:
|
|
162
|
+
returned_body = standalone_returned_body(project_root, args.purpose, returned_body_path)
|
|
163
|
+
except AgentInvocationError as exc:
|
|
164
|
+
raise AgentPromptCliError(str(exc)) from exc
|
|
168
165
|
result = materialize_standalone_result(
|
|
169
166
|
project_root=project_root,
|
|
170
167
|
purpose=args.purpose,
|
|
171
168
|
metadata_path=metadata_path,
|
|
172
|
-
returned_body=
|
|
169
|
+
returned_body=returned_body,
|
|
173
170
|
)
|
|
174
171
|
_emit({
|
|
175
172
|
"ok": True,
|
|
@@ -21,6 +21,18 @@ from .invocation import (
|
|
|
21
21
|
)
|
|
22
22
|
|
|
23
23
|
|
|
24
|
+
def standalone_returned_body(project_root: Path, purpose: str, body_path: Path) -> bytes:
|
|
25
|
+
"""Read a raw return only from the purpose's `.tmp/` directory."""
|
|
26
|
+
temporary_root = project_root / ".okstra" / "agent-invocations" / purpose / ".tmp"
|
|
27
|
+
if not temporary_root.is_dir() or not body_path.resolve(strict=True).is_relative_to(
|
|
28
|
+
temporary_root.resolve(strict=True),
|
|
29
|
+
):
|
|
30
|
+
raise AgentInvocationError(
|
|
31
|
+
"returned body file must be inside the standalone purpose .tmp directory"
|
|
32
|
+
)
|
|
33
|
+
return body_path.read_bytes()
|
|
34
|
+
|
|
35
|
+
|
|
24
36
|
@dataclass(frozen=True)
|
|
25
37
|
class StandaloneInvocationRequest:
|
|
26
38
|
project_root: Path
|
|
@@ -241,17 +241,10 @@ def reference_source_extracts(
|
|
|
241
241
|
reference_text: str, clarification_text: str,
|
|
242
242
|
) -> str:
|
|
243
243
|
"""합성 입력 안에 원문이 함께 있을 때 일치하는 발췌만 참조로 바꾼다."""
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
end = start + _INDEX_PREAMBLE_LINES + len(headings) - 1
|
|
249
|
-
unindexed = "\n".join(lines[:start] + lines[end:]) + "\n"
|
|
250
|
-
# 생성기가 만든 목차임을 재구성으로 확인한다. 수정된 목차가 있으면
|
|
251
|
-
# 원문 전체를 유지해 내용 손실이나 잘못된 줄번호를 만들지 않는다.
|
|
252
|
-
if _with_section_index(unindexed) != packet_text:
|
|
253
|
-
return packet_text
|
|
254
|
-
lines = unindexed.splitlines()
|
|
244
|
+
unindexed = _without_generated_section_index(packet_text)
|
|
245
|
+
if unindexed is None:
|
|
246
|
+
return packet_text
|
|
247
|
+
lines = unindexed.splitlines()
|
|
255
248
|
blocks = (
|
|
256
249
|
("Task brief", brief_text, _brief_block(brief_text)),
|
|
257
250
|
("Analysis profile", profile_text, _profile_block(task_type, profile_text)),
|
|
@@ -277,6 +270,24 @@ def reference_source_extracts(
|
|
|
277
270
|
return "\n".join(lines).rstrip() + "\n" if changed else packet_text
|
|
278
271
|
|
|
279
272
|
|
|
273
|
+
def replace_analysis_packet_block(packet_text: str, expected: str, replacement: str) -> str:
|
|
274
|
+
unindexed = _without_generated_section_index(packet_text)
|
|
275
|
+
if unindexed is None or unindexed.count(expected) != 1:
|
|
276
|
+
raise ValueError("analysis packet has no matching pending resolved-lens census or valid section index")
|
|
277
|
+
return _with_section_index(unindexed.replace(expected, replacement))
|
|
278
|
+
|
|
279
|
+
|
|
280
|
+
def _without_generated_section_index(packet_text: str) -> str | None:
|
|
281
|
+
lines = packet_text.splitlines()
|
|
282
|
+
headings = _heading_lines(lines)
|
|
283
|
+
if not headings or headings[0][1] != "## Section Index":
|
|
284
|
+
return packet_text
|
|
285
|
+
start = headings[0][0] - 2
|
|
286
|
+
end = start + _INDEX_PREAMBLE_LINES + len(headings) - 1
|
|
287
|
+
unindexed = "\n".join(lines[:start] + lines[end:]) + "\n"
|
|
288
|
+
return unindexed if _with_section_index(unindexed) == packet_text else None
|
|
289
|
+
|
|
290
|
+
|
|
280
291
|
def _with_section_index(body: str) -> str:
|
|
281
292
|
"""Prefix the rendered packet with every section's line range.
|
|
282
293
|
|
|
@@ -7,9 +7,9 @@ import re
|
|
|
7
7
|
import subprocess
|
|
8
8
|
from dataclasses import dataclass
|
|
9
9
|
from pathlib import Path, PurePosixPath
|
|
10
|
-
from collections.abc import Mapping
|
|
10
|
+
from collections.abc import Mapping, Sequence
|
|
11
11
|
|
|
12
|
-
from .review_verdicts import read_review_census
|
|
12
|
+
from .review_verdicts import _table_fields, parse_review_census, read_review_census
|
|
13
13
|
|
|
14
14
|
_GROUPS = ("structural", "semantic", "state-and-tests", "general")
|
|
15
15
|
_FILE_GROUPS = {
|
|
@@ -256,3 +256,94 @@ def _render(
|
|
|
256
256
|
"- New: " + (", ".join(new) or "-"),
|
|
257
257
|
]
|
|
258
258
|
return "\n".join(rows) + "\n"
|
|
259
|
+
|
|
260
|
+
|
|
261
|
+
# Specialist order of the review workflow; each specialist owns one axis.
|
|
262
|
+
ASSIGNMENT_AXES = ("structural", "semantic", "general", "state-and-tests")
|
|
263
|
+
|
|
264
|
+
|
|
265
|
+
def split_review_census(text: str) -> dict[str, str]:
|
|
266
|
+
"""Split a full census into one assigned census per axis that has cells.
|
|
267
|
+
|
|
268
|
+
Every line outside the Cells table is kept verbatim, so each assignment
|
|
269
|
+
carries the same policy digest, resource selection and rule catalog.
|
|
270
|
+
"""
|
|
271
|
+
full = parse_review_census(text)
|
|
272
|
+
kept: dict[str, list[str]] = {axis: [] for axis in ASSIGNMENT_AXES}
|
|
273
|
+
section = ""
|
|
274
|
+
for line in text.splitlines(keepends=True):
|
|
275
|
+
if line.startswith("## "):
|
|
276
|
+
section = line.strip()
|
|
277
|
+
group = _cell_row_group(line) if section == "## Cells" else None
|
|
278
|
+
for axis, lines in kept.items():
|
|
279
|
+
if group is None or group == axis:
|
|
280
|
+
lines.append(line)
|
|
281
|
+
assigned: dict[str, str] = {}
|
|
282
|
+
for axis in ASSIGNMENT_AXES:
|
|
283
|
+
if not any(cell.group == axis for cell in full.cells.values()):
|
|
284
|
+
continue
|
|
285
|
+
assigned[axis] = "".join(kept[axis])
|
|
286
|
+
_check_partition(full, assigned)
|
|
287
|
+
return assigned
|
|
288
|
+
|
|
289
|
+
|
|
290
|
+
def _cell_row_group(line: str) -> str | None:
|
|
291
|
+
if not line.strip().startswith("|"):
|
|
292
|
+
return None
|
|
293
|
+
fields = _table_fields(line)
|
|
294
|
+
if len(fields) != 3 or fields[0] == "Cell" or all(re.fullmatch(r"[-:]+", f) for f in fields):
|
|
295
|
+
return None
|
|
296
|
+
return fields[2]
|
|
297
|
+
|
|
298
|
+
|
|
299
|
+
def _check_partition(full, assigned: Mapping[str, str]) -> None:
|
|
300
|
+
owners: dict[str, str] = {}
|
|
301
|
+
for axis, text in assigned.items():
|
|
302
|
+
part = parse_review_census(text)
|
|
303
|
+
if part.rules != full.rules or part.references != full.references:
|
|
304
|
+
raise ValueError(f"assigned {axis} census changes the rule catalog")
|
|
305
|
+
for identity, cell in part.cells.items():
|
|
306
|
+
if cell.group != axis or identity in owners or full.cells.get(identity) != cell:
|
|
307
|
+
raise ValueError(f"assigned {axis} census does not own cell {identity}")
|
|
308
|
+
owners[identity] = axis
|
|
309
|
+
if set(owners) != set(full.cells):
|
|
310
|
+
missing = sorted(set(full.cells) - set(owners))
|
|
311
|
+
raise ValueError("assigned censuses leave cells unowned: " + ", ".join(missing))
|
|
312
|
+
|
|
313
|
+
|
|
314
|
+
def write_review_assignments(project_root: Path, census: Path) -> dict[str, Path]:
|
|
315
|
+
"""Write `<review-id>.<axis>.census.md` beside a `<review-id>.census.md` in `.okstra/`."""
|
|
316
|
+
if not census.name.endswith(".census.md"):
|
|
317
|
+
raise ValueError("census file must be named <review-id>.census.md")
|
|
318
|
+
census.resolve(strict=True).relative_to((project_root / ".okstra").resolve())
|
|
319
|
+
stem = census.name.removesuffix(".census.md")
|
|
320
|
+
assigned = split_review_census(census.read_text(encoding="utf-8"))
|
|
321
|
+
outputs = {axis: census.with_name(f"{stem}.{axis}.census.md") for axis in assigned}
|
|
322
|
+
for axis, out in outputs.items():
|
|
323
|
+
if out.exists() and out.read_text(encoding="utf-8") != assigned[axis]:
|
|
324
|
+
raise ValueError(f"existing assignment differs; choose a new review id: {out}")
|
|
325
|
+
for axis, out in outputs.items():
|
|
326
|
+
out.write_text(assigned[axis], encoding="utf-8")
|
|
327
|
+
return outputs
|
|
328
|
+
|
|
329
|
+
|
|
330
|
+
def subset_review_census(text: str, cell_ids: Sequence[str]) -> str:
|
|
331
|
+
"""Keep only the named Cells rows; every other line stays verbatim."""
|
|
332
|
+
full = parse_review_census(text)
|
|
333
|
+
unknown = sorted(set(cell_ids) - set(full.cells))
|
|
334
|
+
if unknown or not cell_ids:
|
|
335
|
+
raise ValueError("cell subset names no cell or unknown cells: " + ", ".join(unknown))
|
|
336
|
+
wanted = set(cell_ids)
|
|
337
|
+
kept: list[str] = []
|
|
338
|
+
section = ""
|
|
339
|
+
for line in text.splitlines(keepends=True):
|
|
340
|
+
if line.startswith("## "):
|
|
341
|
+
section = line.strip()
|
|
342
|
+
if section == "## Cells" and _cell_row_group(line) is not None:
|
|
343
|
+
if _table_fields(line)[0] not in wanted:
|
|
344
|
+
continue
|
|
345
|
+
kept.append(line)
|
|
346
|
+
subset = "".join(kept)
|
|
347
|
+
if set(parse_review_census(subset).cells) != wanted:
|
|
348
|
+
raise ValueError("cell subset lost a requested cell")
|
|
349
|
+
return subset
|