okstra 0.235.0 → 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.
- package/dist/lib/host-registry-client.d.mts +9 -2
- package/dist/lib/host-registry-client.mjs +29 -3
- package/dist/lib/host-registry-client.mjs.map +1 -1
- package/dist/lib/runtime-payload.mjs +1 -0
- package/dist/lib/runtime-payload.mjs.map +1 -1
- package/docs/architecture.md +1 -1
- package/docs/cli.md +6 -0
- package/package.json +1 -1
- package/runtime/BUILD.json +2 -2
- package/runtime/bin/lib/okstra/usage.sh +8 -8
- package/runtime/bin/okstra-qwen-exec.sh +5 -0
- package/runtime/prompts/lead/convergence.md +4 -1
- package/runtime/prompts/lead/okstra-lead-contract.md +3 -3
- package/runtime/prompts/profiles/_common-contract.md +10 -1
- package/runtime/prompts/wizard/prompts.ko.json +16 -4
- package/runtime/python/okstra_ctl/adapters/providers/antigravity/adapter.py +10 -2
- package/runtime/python/okstra_ctl/adapters/providers/claude/adapter.py +16 -1
- package/runtime/python/okstra_ctl/adapters/providers/codex/adapter.py +20 -5
- package/runtime/python/okstra_ctl/adapters/providers/kimi/adapter.py +17 -9
- package/runtime/python/okstra_ctl/adapters/providers/qwen/adapter.py +88 -0
- package/runtime/python/okstra_ctl/adapters/providers/qwen/manifest.json +1 -0
- package/runtime/python/okstra_ctl/adapters/providers/qwen/settings.json +12 -0
- package/runtime/python/okstra_ctl/adapters/providers/zai/adapter.py +8 -2
- package/runtime/python/okstra_ctl/business_flow/contracts.py +11 -0
- package/runtime/python/okstra_ctl/business_flow/engine.py +90 -32
- package/runtime/python/okstra_ctl/business_flow/hooks.py +4 -2
- package/runtime/python/okstra_ctl/business_flow/source.py +39 -7
- package/runtime/python/okstra_ctl/business_flow/store.py +94 -28
- package/runtime/python/okstra_ctl/convergence.py +95 -5
- package/runtime/python/okstra_ctl/convergence_critic_verify_prompt.py +11 -10
- package/runtime/python/okstra_ctl/convergence_engine.py +30 -15
- package/runtime/python/okstra_ctl/convergence_reverify_prompt.py +9 -2
- package/runtime/python/okstra_ctl/coverage_census.py +75 -12
- package/runtime/python/okstra_ctl/entrypoints/hosts.py +1 -1
- package/runtime/python/okstra_ctl/lead_progress.py +1 -1
- package/runtime/python/okstra_ctl/model_discovery.py +1 -1
- package/runtime/python/okstra_ctl/models.py +2 -2
- package/runtime/python/okstra_ctl/phases/discussion/profile.md +2 -2
- package/runtime/python/okstra_ctl/phases/error_analysis/profile.md +1 -1
- package/runtime/python/okstra_ctl/phases/implementation_option_selection/profile.md +1 -1
- package/runtime/python/okstra_ctl/phases/implementation_planning/authoring.py +2 -1
- package/runtime/python/okstra_ctl/phases/implementation_planning/instructions/plan-body-verification.md +1 -1
- package/runtime/python/okstra_ctl/phases/implementation_planning/profile.md +3 -3
- package/runtime/python/okstra_ctl/phases/requirements_discovery/profile.md +5 -5
- package/runtime/python/okstra_ctl/registry/provider_registry.py +1 -1
- package/runtime/python/okstra_ctl/render_final_report.py +1 -1
- package/runtime/python/okstra_ctl/run.py +1 -1
- package/runtime/python/okstra_ctl/run_context.py +18 -3
- package/runtime/python/okstra_ctl/schema_excerpt.py +14 -9
- package/runtime/python/okstra_ctl/verdict_blocks.py +7 -2
- package/runtime/python/okstra_ctl/wizard/engine.py +28 -1
- package/runtime/python/okstra_ctl/wizard/ids.py +8 -0
- package/runtime/python/okstra_ctl/wizard/picker_navigation.py +64 -2
- package/runtime/python/okstra_ctl/wizard/roles.py +194 -45
- package/runtime/python/okstra_ctl/wizard/sources.py +10 -1
- package/runtime/python/okstra_ctl/wizard/state.py +67 -20
- package/runtime/python/okstra_ctl/wizard/steps_roles.py +6 -3
- package/runtime/python/okstra_ctl/wizard/worker_settings.py +129 -25
- package/runtime/python/okstra_ctl/worker_audit_ledger.py +44 -8
- package/runtime/python/okstra_ctl/worker_prompt_body.py +26 -2
- package/runtime/python/okstra_ctl/worker_prompt_headers.py +12 -9
- package/runtime/python/okstra_token_usage/claude.py +5 -1
- package/runtime/python/okstra_token_usage/collect.py +3 -3
- package/runtime/python/okstra_token_usage/pricing.py +1 -0
- package/runtime/skills/_fragments/wizard-relay-protocol.md +1 -1
- package/runtime/skills/okstra-discussion/SKILL.md +1 -1
- package/runtime/skills/okstra-run/SKILL.md +2 -2
- package/runtime/templates/worker-prompt-preamble.md +12 -2
|
@@ -30,7 +30,7 @@ from okstra_ctl import worktree_registry
|
|
|
30
30
|
from okstra_ctl.worktree import is_git_work_tree, main_worktree_path
|
|
31
31
|
from okstra_ctl.paths import RunRef, task_runs_dir
|
|
32
32
|
from okstra_ctl.phases.catalog import INPUT_DOCUMENT_TASK_TYPES
|
|
33
|
-
from okstra_ctl.run_context import latest_run_inputs
|
|
33
|
+
from okstra_ctl.run_context import latest_run_inputs, latest_run_inputs_document
|
|
34
34
|
from okstra_ctl.generated_input import names_generated_input_document
|
|
35
35
|
from okstra_project.state import (
|
|
36
36
|
StateError,
|
|
@@ -633,6 +633,15 @@ def _latest_run_inputs(
|
|
|
633
633
|
phase_segment=phase_segment, stage=stage)
|
|
634
634
|
|
|
635
635
|
|
|
636
|
+
def _latest_run_inputs_document(
|
|
637
|
+
state: WizardState, *, phase_segment: str = "", stage: Optional[int] = None
|
|
638
|
+
) -> dict:
|
|
639
|
+
"""The whole latest run-inputs record, including its static role executions."""
|
|
640
|
+
return latest_run_inputs_document(
|
|
641
|
+
state.project_root, state.task_group, state.task_id,
|
|
642
|
+
phase_segment=phase_segment, stage=stage)
|
|
643
|
+
|
|
644
|
+
|
|
636
645
|
def _clarification_pick_required(state: WizardState) -> bool:
|
|
637
646
|
if state.task_type == "release-handoff":
|
|
638
647
|
report = _suggest_latest_final_report(state)
|
|
@@ -3,7 +3,7 @@ from __future__ import annotations
|
|
|
3
3
|
|
|
4
4
|
from dataclasses import asdict, dataclass, field
|
|
5
5
|
from pathlib import Path
|
|
6
|
-
from typing import Any, Callable, Optional
|
|
6
|
+
from typing import Any, Callable, Optional, TypedDict
|
|
7
7
|
|
|
8
8
|
from okstra_ctl.registry.provider_registry import default_provider_registry
|
|
9
9
|
from okstra_ctl.model_pool import ModelPool
|
|
@@ -27,6 +27,7 @@ from .ids import (
|
|
|
27
27
|
S_HANDOFF_STAGE_PICK,
|
|
28
28
|
_ABORT_OPTION,
|
|
29
29
|
_SLUG_OK,
|
|
30
|
+
_ROLE_SELECTION_PREFIXES,
|
|
30
31
|
_STAGE_SCOPED_TASK_TYPES,
|
|
31
32
|
_role_model_prompt_id,
|
|
32
33
|
_role_models_prompt_id,
|
|
@@ -36,11 +37,20 @@ from .ids import (
|
|
|
36
37
|
|
|
37
38
|
# ---- Data types ----------------------------------------------------------
|
|
38
39
|
|
|
40
|
+
class ModelDraft(TypedDict):
|
|
41
|
+
"""Models ticked on a vendor-tab screen and the providers whose models are typed next."""
|
|
42
|
+
|
|
43
|
+
models: list[str]
|
|
44
|
+
providers: list[str]
|
|
45
|
+
|
|
46
|
+
|
|
39
47
|
@dataclass
|
|
40
48
|
class WizardState:
|
|
41
49
|
# role-first canonical model selections
|
|
42
50
|
role_counts: dict[str, int] = field(default_factory=dict)
|
|
43
51
|
role_models: dict[str, list[str]] = field(default_factory=dict)
|
|
52
|
+
# Models ticked on a role's model screen while its typed models are pending.
|
|
53
|
+
role_model_drafts: dict[str, ModelDraft] = field(default_factory=dict)
|
|
44
54
|
role_selection_order: list[str] = field(default_factory=list)
|
|
45
55
|
role_sources: dict[str, str] = field(default_factory=dict)
|
|
46
56
|
worker_defaults_snapshot: WorkerDefaultScopes | None = None
|
|
@@ -48,6 +58,8 @@ class WizardState:
|
|
|
48
58
|
worker_settings_scope: WorkerScope | None = None
|
|
49
59
|
worker_settings_updates: WorkerDefaultUpdates = field(default_factory=dict)
|
|
50
60
|
worker_settings_role: str = ""
|
|
61
|
+
worker_settings_choosing: bool = False
|
|
62
|
+
worker_settings_draft: ModelDraft | None = None
|
|
51
63
|
worker_settings_review: bool = False
|
|
52
64
|
worker_settings_saved: bool = False
|
|
53
65
|
worker_settings_answers: int = 0
|
|
@@ -239,7 +251,7 @@ class Prompt:
|
|
|
239
251
|
self._check_recommendations()
|
|
240
252
|
|
|
241
253
|
def _check_recommendations(self) -> None:
|
|
242
|
-
"""단일 추천은 하나다.
|
|
254
|
+
"""단일 추천은 하나다. 제공자·모델 선택은 제공자 순서, 그 외에는 추천이 앞이다.
|
|
243
255
|
|
|
244
256
|
실측(2026-09-09, task 선택 화면): 남은 task 세 줄이 전부 `(추천)` 을
|
|
245
257
|
달고 나왔고, 리드는 산문에서 2번을 권했다. 추천이 여럿이면 라벨은
|
|
@@ -251,7 +263,7 @@ class Prompt:
|
|
|
251
263
|
될 수 없다.
|
|
252
264
|
"""
|
|
253
265
|
flags = [option.recommended for option in self.options]
|
|
254
|
-
grouped_models = self.step.startswith((
|
|
266
|
+
grouped_models = self.step.startswith((*_ROLE_SELECTION_PREFIXES, "worker_settings_models"))
|
|
255
267
|
if any(flags):
|
|
256
268
|
if self.multi:
|
|
257
269
|
if not grouped_models and any(flags[index] for index in range(1, len(flags))
|
|
@@ -409,36 +421,49 @@ def _initial_cross_verification_requirement(
|
|
|
409
421
|
), None)
|
|
410
422
|
|
|
411
423
|
|
|
412
|
-
def
|
|
413
|
-
|
|
424
|
+
def _recorded_models_by_role(
|
|
425
|
+
rows: object, *, model_key: str, skip_roles: frozenset[str] = frozenset(),
|
|
426
|
+
) -> dict[str, list[tuple[str, str]]]:
|
|
427
|
+
"""Recorded rows as (provider, model) per role.
|
|
414
428
|
|
|
415
|
-
|
|
416
|
-
|
|
429
|
+
run-inputs `workerAssignments` carry the model as `model`, its
|
|
430
|
+
`staticRoleExecutions` as `modelId`. `workers` names worker ids
|
|
431
|
+
(`claude-planner`), not providers, so it cannot restore a model.
|
|
417
432
|
"""
|
|
418
|
-
|
|
419
|
-
assigned: dict[str, list[tuple[str, str]]] = {}
|
|
433
|
+
recorded: dict[str, list[tuple[str, str]]] = {}
|
|
420
434
|
for row in rows if isinstance(rows, list) else ():
|
|
421
435
|
if not isinstance(row, dict):
|
|
422
436
|
continue
|
|
423
|
-
role, provider, model = row.get("role"), row.get("provider"), row.get(
|
|
424
|
-
if isinstance(role, str) and isinstance(provider, str) and provider:
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
)
|
|
428
|
-
return assigned
|
|
437
|
+
role, provider, model = row.get("role"), row.get("provider"), row.get(model_key)
|
|
438
|
+
if isinstance(role, str) and role not in skip_roles and isinstance(provider, str) and provider:
|
|
439
|
+
recorded.setdefault(role, []).append((provider, model if isinstance(model, str) else ""))
|
|
440
|
+
return recorded
|
|
429
441
|
|
|
430
442
|
|
|
431
443
|
def _role_selections_from_run_inputs(
|
|
432
444
|
state: WizardState,
|
|
433
445
|
payload: dict[str, Any],
|
|
446
|
+
static_role_executions: object,
|
|
434
447
|
) -> None:
|
|
435
|
-
"""직전 run-inputs 의 provider·모델 기록을 역할별 모델 선택으로 옮긴다.
|
|
448
|
+
"""직전 run-inputs 의 provider·모델 기록을 역할별 모델 선택으로 옮긴다.
|
|
449
|
+
|
|
450
|
+
`static_role_executions` lists every static role prepare assigned. It is
|
|
451
|
+
complete, so a role it lacks was assigned nobody and restores as zero.
|
|
452
|
+
`workerAssignments` omits the critic, so without the complete record an
|
|
453
|
+
optional role it lacks is asked again rather than taken as zero.
|
|
454
|
+
"""
|
|
436
455
|
profile = _load_role_profile_for_state(state)
|
|
437
456
|
pool = ModelPool.from_registry(default_provider_registry())
|
|
438
457
|
cross_requirement = _initial_cross_verification_requirement(profile)
|
|
439
|
-
|
|
458
|
+
planned = _recorded_models_by_role(
|
|
459
|
+
static_role_executions, model_key="modelId", skip_roles=frozenset({"leader"}),
|
|
460
|
+
)
|
|
461
|
+
if planned:
|
|
462
|
+
_restore_recorded_role_selections(state, profile, pool, planned, complete=True)
|
|
463
|
+
return
|
|
464
|
+
assigned = _recorded_models_by_role(payload.get("workerAssignments"), model_key="model")
|
|
440
465
|
if assigned:
|
|
441
|
-
_restore_recorded_role_selections(state, profile, pool, assigned)
|
|
466
|
+
_restore_recorded_role_selections(state, profile, pool, assigned, complete=False)
|
|
442
467
|
return
|
|
443
468
|
providers = _legacy_worker_providers(payload)
|
|
444
469
|
if cross_requirement is not None:
|
|
@@ -504,6 +529,8 @@ def _restore_recorded_role_selections(
|
|
|
504
529
|
profile: RoleProfile,
|
|
505
530
|
pool: ModelPool,
|
|
506
531
|
assigned: dict[str, list[tuple[str, str]]],
|
|
532
|
+
*,
|
|
533
|
+
complete: bool,
|
|
507
534
|
) -> None:
|
|
508
535
|
for requirement in profile.roles:
|
|
509
536
|
if requirement.dynamic or requirement.role == "leader":
|
|
@@ -512,11 +539,14 @@ def _restore_recorded_role_selections(
|
|
|
512
539
|
rows = assigned.get(role, [])
|
|
513
540
|
if not rows and requirement.min_count > 0:
|
|
514
541
|
continue
|
|
542
|
+
step = _role_prompt_id(requirement)
|
|
543
|
+
if not rows and not complete:
|
|
544
|
+
state.manual_steps.append(step)
|
|
545
|
+
continue
|
|
515
546
|
models = [
|
|
516
547
|
model for provider, raw in rows
|
|
517
548
|
if (model := _legacy_model_ref(pool, provider, role, raw)) is not None
|
|
518
549
|
]
|
|
519
|
-
step = _role_prompt_id(requirement)
|
|
520
550
|
if len(models) != len(rows):
|
|
521
551
|
state.manual_steps.append(step)
|
|
522
552
|
continue
|
|
@@ -568,6 +598,23 @@ def _validate_v2_state_fields(data: dict[str, Any]) -> None:
|
|
|
568
598
|
for role, models in role_models.items()
|
|
569
599
|
):
|
|
570
600
|
raise WizardError("wizard state roleModels must map roles to modelRef arrays")
|
|
601
|
+
drafts = data.get("role_model_drafts", {})
|
|
602
|
+
if not isinstance(drafts, dict) or not all(
|
|
603
|
+
isinstance(role, str) and _is_model_draft(draft)
|
|
604
|
+
for role, draft in drafts.items()
|
|
605
|
+
):
|
|
606
|
+
raise WizardError("wizard state role_model_drafts must map roles to model drafts")
|
|
607
|
+
worker_draft = data.get("worker_settings_draft")
|
|
608
|
+
if worker_draft is not None and not _is_model_draft(worker_draft):
|
|
609
|
+
raise WizardError("wizard state worker_settings_draft must be a model draft")
|
|
610
|
+
|
|
611
|
+
|
|
612
|
+
def _is_model_draft(draft: object) -> bool:
|
|
613
|
+
return isinstance(draft, dict) and all(
|
|
614
|
+
isinstance(draft.get(key), list)
|
|
615
|
+
and all(isinstance(item, str) for item in draft[key])
|
|
616
|
+
for key in ("models", "providers")
|
|
617
|
+
)
|
|
571
618
|
if not isinstance(selection_order, list) or not all(
|
|
572
619
|
isinstance(step_id, str) for step_id in selection_order
|
|
573
620
|
):
|
|
@@ -575,7 +622,7 @@ def _validate_v2_state_fields(data: dict[str, Any]) -> None:
|
|
|
575
622
|
|
|
576
623
|
|
|
577
624
|
def _is_role_selection_step(step_id: str) -> bool:
|
|
578
|
-
return step_id.startswith(
|
|
625
|
+
return step_id.startswith(_ROLE_SELECTION_PREFIXES)
|
|
579
626
|
|
|
580
627
|
|
|
581
628
|
def _discard_implicit_leader_selection(state: WizardState) -> None:
|
|
@@ -17,7 +17,7 @@ from .state import (
|
|
|
17
17
|
_role_selections_from_run_inputs,
|
|
18
18
|
)
|
|
19
19
|
from .prompts import _opt, _p
|
|
20
|
-
from .sources import _latest_run_inputs, _suggest_latest_final_report
|
|
20
|
+
from .sources import _latest_run_inputs, _latest_run_inputs_document, _suggest_latest_final_report
|
|
21
21
|
from .steps_analysis import _restore_analysis_evidence_inputs
|
|
22
22
|
|
|
23
23
|
|
|
@@ -87,12 +87,15 @@ def _submit_reuse_previous(state: WizardState, value: str) -> Optional[str]:
|
|
|
87
87
|
return "reuse-previous: no (step-by-step re-entry)"
|
|
88
88
|
state.reuse_previous = True
|
|
89
89
|
seg = slugify_task_segment(state.task_type)
|
|
90
|
-
|
|
90
|
+
document = _latest_run_inputs_document(state, phase_segment=seg)
|
|
91
|
+
inputs = document.get("inputs") if isinstance(document.get("inputs"), dict) else {}
|
|
91
92
|
conversion_payload = dict(inputs)
|
|
92
93
|
conversion_payload.setdefault("grokModel", _assignment_model(inputs, "grok", "grok"))
|
|
93
94
|
conversion_payload.setdefault("kimiModel", _assignment_model(inputs, "kimi", "kimi"))
|
|
94
95
|
_clear_role_selection(state)
|
|
95
|
-
_role_selections_from_run_inputs(
|
|
96
|
+
_role_selections_from_run_inputs(
|
|
97
|
+
state, conversion_payload, document.get("staticRoleExecutions"),
|
|
98
|
+
)
|
|
96
99
|
state.role_sources = {
|
|
97
100
|
role: "previous" for role in state.role_models.keys() | state.role_counts.keys()
|
|
98
101
|
}
|
|
@@ -8,6 +8,7 @@ from okstra_project import project_json_path
|
|
|
8
8
|
from okstra_ctl.assignment_environment import load_assignment_context
|
|
9
9
|
from okstra_ctl.assignment_resolver import AssignmentContext
|
|
10
10
|
from okstra_ctl.dispatch_state import detect_terminal_backend
|
|
11
|
+
from okstra_ctl.registry.provider_registry import provider_display_order
|
|
11
12
|
from okstra_ctl.domain.worker_defaults import (
|
|
12
13
|
WorkerDefaultError,
|
|
13
14
|
WorkerDefaultsConflict,
|
|
@@ -22,13 +23,21 @@ from okstra_ctl.worker_defaults import (
|
|
|
22
23
|
)
|
|
23
24
|
|
|
24
25
|
from .prompts import _msg
|
|
25
|
-
from .roles import
|
|
26
|
+
from .roles import (
|
|
27
|
+
_executable_role_models,
|
|
28
|
+
_host_session_context,
|
|
29
|
+
_provider_of,
|
|
30
|
+
free_input_providers,
|
|
31
|
+
resolve_typed_models,
|
|
32
|
+
)
|
|
26
33
|
from .state import Option, Prompt, WizardError, WizardState
|
|
27
34
|
|
|
28
35
|
_INHERIT = "__inherit__"
|
|
29
36
|
_DISABLE = "__disable__"
|
|
30
37
|
_SCREENS_AFTER_SCOPE_PICK = 2
|
|
31
38
|
_SCREENS_AFTER_MODEL_EDIT = 2
|
|
39
|
+
_SCREENS_FOR_ACTION_PICK = 1
|
|
40
|
+
_CHOOSE_MODELS = "__choose_models__"
|
|
32
41
|
_SCREENS_AFTER_ROLE_MENU = 1
|
|
33
42
|
_SCREENS_AFTER_REVIEW = 0
|
|
34
43
|
|
|
@@ -66,7 +75,9 @@ def remaining_settings_screens(state: WizardState) -> int:
|
|
|
66
75
|
if state.worker_settings_scope is None:
|
|
67
76
|
return _SCREENS_AFTER_SCOPE_PICK
|
|
68
77
|
if state.worker_settings_role:
|
|
69
|
-
|
|
78
|
+
if state.worker_settings_choosing:
|
|
79
|
+
return _SCREENS_AFTER_MODEL_EDIT
|
|
80
|
+
return _SCREENS_AFTER_MODEL_EDIT + _SCREENS_FOR_ACTION_PICK
|
|
70
81
|
return _SCREENS_AFTER_ROLE_MENU
|
|
71
82
|
|
|
72
83
|
|
|
@@ -155,12 +166,14 @@ def worker_settings_summary(state: WizardState) -> str:
|
|
|
155
166
|
return "\n".join(lines)
|
|
156
167
|
|
|
157
168
|
|
|
158
|
-
def
|
|
159
|
-
|
|
169
|
+
def _settings_candidates(
|
|
170
|
+
state: WizardState,
|
|
171
|
+
) -> tuple[StaticRoleRequirement, list[str], list[str], bool]:
|
|
172
|
+
"""(requirement, candidates in provider order, preferred models, disabled now)."""
|
|
160
173
|
role = state.worker_settings_role
|
|
161
174
|
requirement = common_worker_requirements(Path(state.workspace_root))[role]
|
|
162
175
|
context = _settings_context(state)
|
|
163
|
-
|
|
176
|
+
executable = _executable_role_models(
|
|
164
177
|
state, RoleProfile((requirement,)), requirement, context
|
|
165
178
|
)
|
|
166
179
|
scopes = _draft_scopes(state)
|
|
@@ -168,43 +181,102 @@ def _settings_model_prompt(state: WizardState) -> Prompt:
|
|
|
168
181
|
role, scopes.get("project", {}), scopes.get("global", {})
|
|
169
182
|
)
|
|
170
183
|
current = selected[0] if selected and isinstance(selected[0], list) else []
|
|
171
|
-
preferred = list(dict.fromkeys(model for model in current if model in
|
|
184
|
+
preferred = list(dict.fromkeys(model for model in current if model in executable))
|
|
172
185
|
if not preferred:
|
|
173
|
-
preferred = list(
|
|
174
|
-
|
|
175
|
-
multi = requirement.max_count > 1
|
|
176
|
-
if not multi:
|
|
186
|
+
preferred = list(executable[: requirement.recommended_count])
|
|
187
|
+
if requirement.max_count <= 1:
|
|
177
188
|
preferred = preferred[:1]
|
|
189
|
+
disabled = requirement.min_count == 0 and (
|
|
190
|
+
not executable or (selected is not None and selected[0] == [])
|
|
191
|
+
)
|
|
192
|
+
candidates = sorted(
|
|
193
|
+
executable, key=lambda model: provider_display_order(_provider_of(model))
|
|
194
|
+
)
|
|
195
|
+
return requirement, candidates, preferred, disabled
|
|
196
|
+
|
|
197
|
+
|
|
198
|
+
def _settings_action_prompt(state: WizardState) -> Prompt:
|
|
199
|
+
"""First screen of a role edit: choose models, or end it without models."""
|
|
200
|
+
requirement, candidates, _preferred, disabled = _settings_candidates(state)
|
|
201
|
+
inherit = not candidates and not disabled
|
|
178
202
|
options = [
|
|
179
|
-
Option(
|
|
203
|
+
Option(
|
|
204
|
+
_CHOOSE_MODELS, _text(state, "choose_models"),
|
|
205
|
+
recommended=bool(candidates) and not disabled,
|
|
206
|
+
),
|
|
207
|
+
*_settings_without_models(state, requirement, disabled=disabled, inherit=inherit),
|
|
180
208
|
]
|
|
181
|
-
|
|
182
|
-
|
|
209
|
+
options.sort(key=lambda option: not option.recommended)
|
|
210
|
+
return Prompt(
|
|
211
|
+
step="worker_settings_action",
|
|
212
|
+
kind="pick",
|
|
213
|
+
options=options,
|
|
214
|
+
label=_text(
|
|
215
|
+
state,
|
|
216
|
+
"action_label",
|
|
217
|
+
role=_text(state, f"role_{state.worker_settings_role}"),
|
|
218
|
+
minimum=str(requirement.min_count),
|
|
219
|
+
maximum=str(requirement.max_count),
|
|
220
|
+
),
|
|
183
221
|
)
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
222
|
+
|
|
223
|
+
|
|
224
|
+
def _settings_without_models(
|
|
225
|
+
state: WizardState,
|
|
226
|
+
requirement: StaticRoleRequirement,
|
|
227
|
+
*,
|
|
228
|
+
disabled: bool,
|
|
229
|
+
inherit: bool,
|
|
230
|
+
) -> list[Option]:
|
|
231
|
+
"""Rows that end a role edit without models: disable, inherit or clear, cancel."""
|
|
232
|
+
rows = []
|
|
187
233
|
if requirement.min_count == 0:
|
|
188
|
-
|
|
189
|
-
inherited =
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
234
|
+
rows.append(Option(_DISABLE, _text(state, "disabled"), recommended=disabled))
|
|
235
|
+
inherited = "inherit" if state.worker_settings_scope == "project" else "clear"
|
|
236
|
+
rows.append(Option(_INHERIT, _text(state, inherited), recommended=inherit))
|
|
237
|
+
rows.append(Option("cancel", _text(state, "cancel")))
|
|
238
|
+
return rows
|
|
239
|
+
|
|
240
|
+
|
|
241
|
+
def _settings_model_prompt(state: WizardState) -> Prompt:
|
|
242
|
+
"""The role's models in provider order; the engine shows them as vendor tabs."""
|
|
243
|
+
text = partial(_text, state)
|
|
244
|
+
requirement, candidates, preferred, _disabled = _settings_candidates(state)
|
|
245
|
+
options = [Option(model, model, recommended=model in preferred) for model in candidates]
|
|
194
246
|
return Prompt(
|
|
195
247
|
step="worker_settings_models",
|
|
196
248
|
kind="pick",
|
|
197
|
-
multi=
|
|
249
|
+
multi=requirement.max_count > 1,
|
|
198
250
|
options=options,
|
|
199
251
|
label=text(
|
|
200
252
|
"models_label",
|
|
201
|
-
role=text(f"role_{
|
|
253
|
+
role=text(f"role_{state.worker_settings_role}"),
|
|
202
254
|
minimum=str(requirement.min_count),
|
|
203
255
|
maximum=str(requirement.max_count),
|
|
204
256
|
),
|
|
205
257
|
)
|
|
206
258
|
|
|
207
259
|
|
|
260
|
+
def _settings_model_input_prompt(state: WizardState) -> Prompt:
|
|
261
|
+
draft = state.worker_settings_draft
|
|
262
|
+
assert draft is not None
|
|
263
|
+
_requirement, candidates, _preferred, _disabled = _settings_candidates(state)
|
|
264
|
+
return Prompt(
|
|
265
|
+
step="worker_settings_model_input",
|
|
266
|
+
kind="text",
|
|
267
|
+
label=_text(
|
|
268
|
+
state,
|
|
269
|
+
"model_input_label",
|
|
270
|
+
role=_text(state, f"role_{state.worker_settings_role}"),
|
|
271
|
+
providers=", ".join(draft["providers"]),
|
|
272
|
+
chosen=", ".join(draft["models"]) or "-",
|
|
273
|
+
candidates=", ".join(
|
|
274
|
+
model for model in candidates if _provider_of(model) in draft["providers"]
|
|
275
|
+
),
|
|
276
|
+
),
|
|
277
|
+
)
|
|
278
|
+
|
|
279
|
+
|
|
208
280
|
def next_worker_settings_prompt(state: WizardState) -> Prompt:
|
|
209
281
|
if state.worker_settings_saved:
|
|
210
282
|
return Prompt(step="done", kind="done", label=worker_settings_summary(state))
|
|
@@ -235,6 +307,10 @@ def next_worker_settings_prompt(state: WizardState) -> Prompt:
|
|
|
235
307
|
],
|
|
236
308
|
)
|
|
237
309
|
if state.worker_settings_role:
|
|
310
|
+
if state.worker_settings_draft is not None:
|
|
311
|
+
return _settings_model_input_prompt(state)
|
|
312
|
+
if not state.worker_settings_choosing:
|
|
313
|
+
return _settings_action_prompt(state)
|
|
238
314
|
return _settings_model_prompt(state)
|
|
239
315
|
return Prompt(
|
|
240
316
|
step="worker_settings_roles",
|
|
@@ -265,6 +341,25 @@ def _stage_worker_models(state: WizardState, value: str) -> None:
|
|
|
265
341
|
_validate_staged_models(state, requirement, models, _settings_context(state))
|
|
266
342
|
state.worker_settings_updates[role] = models
|
|
267
343
|
state.worker_settings_role = ""
|
|
344
|
+
state.worker_settings_choosing = False
|
|
345
|
+
state.worker_settings_draft = None
|
|
346
|
+
|
|
347
|
+
|
|
348
|
+
def _stage_picked_worker_models(state: WizardState, value: str) -> None:
|
|
349
|
+
picked = [part.strip() for part in value.split(",") if part.strip()]
|
|
350
|
+
chosen, typed_from = free_input_providers(picked)
|
|
351
|
+
if typed_from:
|
|
352
|
+
state.worker_settings_draft = {"models": chosen, "providers": typed_from}
|
|
353
|
+
return
|
|
354
|
+
_stage_worker_models(state, value)
|
|
355
|
+
|
|
356
|
+
|
|
357
|
+
def _stage_typed_worker_models(state: WizardState, value: str) -> None:
|
|
358
|
+
draft = state.worker_settings_draft
|
|
359
|
+
assert draft is not None
|
|
360
|
+
_requirement, candidates, _preferred, _disabled = _settings_candidates(state)
|
|
361
|
+
typed = resolve_typed_models(value, draft["providers"], candidates)
|
|
362
|
+
_stage_worker_models(state, ",".join(dict.fromkeys([*draft["models"], *typed])))
|
|
268
363
|
|
|
269
364
|
|
|
270
365
|
def _save_worker_settings(state: WizardState) -> None:
|
|
@@ -321,8 +416,17 @@ def submit_worker_settings(state: WizardState, prompt: Prompt, value: str) -> st
|
|
|
321
416
|
state.worker_settings_role = value
|
|
322
417
|
else:
|
|
323
418
|
raise WizardError(_text(state, "choose_role"))
|
|
419
|
+
elif prompt.step == "worker_settings_action":
|
|
420
|
+
if value == _CHOOSE_MODELS:
|
|
421
|
+
state.worker_settings_choosing = True
|
|
422
|
+
elif value in (_INHERIT, _DISABLE):
|
|
423
|
+
_stage_worker_models(state, value)
|
|
424
|
+
else:
|
|
425
|
+
raise WizardError(_text(state, "choose_action"))
|
|
324
426
|
elif prompt.step == "worker_settings_models":
|
|
325
|
-
|
|
427
|
+
_stage_picked_worker_models(state, value)
|
|
428
|
+
elif prompt.step == "worker_settings_model_input":
|
|
429
|
+
_stage_typed_worker_models(state, value)
|
|
326
430
|
elif prompt.step == "worker_settings_save":
|
|
327
431
|
if value == "save":
|
|
328
432
|
_save_worker_settings(state)
|
|
@@ -104,7 +104,48 @@ def _cited_file_paths(content: str) -> set[str]:
|
|
|
104
104
|
return paths
|
|
105
105
|
|
|
106
106
|
|
|
107
|
-
|
|
107
|
+
# A file that a citation, an evidence note or an Opened list names:
|
|
108
|
+
# `src/a_b.ts:4-9`, **src/a.ts**, [packet](.okstra/x/p.md:3), /abs/src/a.ts.
|
|
109
|
+
# A name counts only with a directory or a line, so prose such as `e.g.` or a
|
|
110
|
+
# version number is not a file.
|
|
111
|
+
_NAMED_FILE_RE = re.compile(
|
|
112
|
+
r"(?<![\w./@-])(?P<path>[\w.@-]*(?:/[\w.@-]+)*\.[A-Za-z]\w*"
|
|
113
|
+
r"|(?:[\w.@-]+/)+(?:Dockerfile|Justfile|Makefile|Procfile|Rakefile))"
|
|
114
|
+
r"(?P<line>:\d+(?:-\d+)?)?"
|
|
115
|
+
)
|
|
116
|
+
|
|
117
|
+
|
|
118
|
+
def named_files(text: str) -> tuple[str, ...]:
|
|
119
|
+
"""The file paths *text* names, in order, without line suffixes."""
|
|
120
|
+
paths: dict[str, None] = {}
|
|
121
|
+
for match in _NAMED_FILE_RE.finditer(text):
|
|
122
|
+
path = match.group("path")
|
|
123
|
+
if match.group("line") or "/" in path:
|
|
124
|
+
paths.setdefault(path, None)
|
|
125
|
+
return tuple(paths)
|
|
126
|
+
|
|
127
|
+
|
|
128
|
+
def recorded_as_opened(path: str, ledger: frozenset[str] | set[str]) -> bool:
|
|
129
|
+
"""Whether a ledger row names *path*, project-relative or absolute on either side.
|
|
130
|
+
|
|
131
|
+
A bare filename matches only when exactly one row has that name.
|
|
132
|
+
"""
|
|
133
|
+
if path in ledger:
|
|
134
|
+
return True
|
|
135
|
+
if "/" not in path:
|
|
136
|
+
return len([row for row in ledger if row.rsplit("/", 1)[-1] == path]) == 1
|
|
137
|
+
return any(path.endswith("/" + row) or row.endswith("/" + path) for row in ledger)
|
|
138
|
+
|
|
139
|
+
|
|
140
|
+
def ledger_required(prompt_path: Path) -> bool:
|
|
141
|
+
"""Whether the prompt asked its worker for an Evidence read ledger."""
|
|
142
|
+
try:
|
|
143
|
+
return EVIDENCE_LEDGER_HEADER in prompt_path.read_text(encoding="utf-8").splitlines()
|
|
144
|
+
except OSError:
|
|
145
|
+
return False
|
|
146
|
+
|
|
147
|
+
|
|
148
|
+
def audit_evidence_read_paths(content: str) -> set[str]:
|
|
108
149
|
return {
|
|
109
150
|
match.group("path")
|
|
110
151
|
for match in _EVIDENCE_READ_RE.finditer(content)
|
|
@@ -230,19 +271,14 @@ def _evidence_read_ledger_failures(
|
|
|
230
271
|
) -> list[str]:
|
|
231
272
|
if worker_role == "report-writer-worker":
|
|
232
273
|
return []
|
|
233
|
-
|
|
234
|
-
try:
|
|
235
|
-
prompt_content = prompt_path.read_text(encoding="utf-8")
|
|
236
|
-
except OSError:
|
|
237
|
-
return []
|
|
238
|
-
if EVIDENCE_LEDGER_HEADER not in prompt_content.splitlines():
|
|
274
|
+
if not ledger_required(_worker_prompt_path(run_dir, worker_role, task_type, seq)):
|
|
239
275
|
return []
|
|
240
276
|
try:
|
|
241
277
|
audit_content = audit_path.read_text(encoding="utf-8")
|
|
242
278
|
except OSError as exc:
|
|
243
279
|
return [f"worker audit sidecar unreadable: {audit_path.name} ({exc})"]
|
|
244
280
|
|
|
245
|
-
read_paths =
|
|
281
|
+
read_paths = audit_evidence_read_paths(audit_content)
|
|
246
282
|
missing_paths = sorted(_cited_file_paths(result_content) - read_paths)
|
|
247
283
|
return [
|
|
248
284
|
f"worker `{worker_role}` result `{result_name}` cites "
|
|
@@ -3,7 +3,25 @@ from __future__ import annotations
|
|
|
3
3
|
|
|
4
4
|
from typing import Any, Mapping, Sequence
|
|
5
5
|
|
|
6
|
-
from .worker_prompt_policy import PromptPlan
|
|
6
|
+
from .worker_prompt_policy import ANALYSIS_DUTY_BY_TASK_TYPE, PromptPlan
|
|
7
|
+
|
|
8
|
+
# The duty contract ahead of this body is shared across task types and says what
|
|
9
|
+
# a result must be, not what to open in which order; a worker that follows only
|
|
10
|
+
# its wording reads the packet and writes. Requirements discovery is answered
|
|
11
|
+
# from code, so its analysers get the order of work in front of the inputs.
|
|
12
|
+
_INVESTIGATION_PROCEDURE: dict[str, tuple[str, ...]] = {
|
|
13
|
+
"requirements-discovery": (
|
|
14
|
+
"1. List every open question in the brief and every expected end-state "
|
|
15
|
+
"row (EB, PB, EO) the packet carries.",
|
|
16
|
+
"2. For each, open the code that answers it: the endpoint or handler, the "
|
|
17
|
+
"service, the repository or query, the model or type (installed dependency "
|
|
18
|
+
"packages included) and the existing tests or specs. Read the bodies, not "
|
|
19
|
+
"only the file names.",
|
|
20
|
+
"3. Record every file you open as an `Evidence read` row in the audit sidecar.",
|
|
21
|
+
"4. Judge every Coverage Census cell from what you opened.",
|
|
22
|
+
"5. Run the preamble's \"Before writing the result\" check, then write the result.",
|
|
23
|
+
),
|
|
24
|
+
}
|
|
7
25
|
|
|
8
26
|
|
|
9
27
|
def analysis_worker_label(worker_id: str) -> str:
|
|
@@ -28,6 +46,11 @@ def analysis_prompt_body(
|
|
|
28
46
|
) -> list[str]:
|
|
29
47
|
"""Render the provider-neutral body for an initial analysis audience."""
|
|
30
48
|
label = analysis_worker_label(worker_id)
|
|
49
|
+
task_type = _require_string(manifest, "taskType")
|
|
50
|
+
procedure = (
|
|
51
|
+
_INVESTIGATION_PROCEDURE.get(task_type, ())
|
|
52
|
+
if plan.duty_audience == ANALYSIS_DUTY_BY_TASK_TYPE.get(task_type) else ()
|
|
53
|
+
)
|
|
31
54
|
pane_role = {
|
|
32
55
|
"implementation-executor": "executor",
|
|
33
56
|
"implementation-verifier": "verifier",
|
|
@@ -40,8 +63,9 @@ def analysis_prompt_body(
|
|
|
40
63
|
"",
|
|
41
64
|
"## Task",
|
|
42
65
|
f"- Task key: `{_require_string(manifest, 'taskKey')}`",
|
|
43
|
-
f"- Task type: `{
|
|
66
|
+
f"- Task type: `{task_type}`",
|
|
44
67
|
"",
|
|
68
|
+
*(["## Investigation procedure", *procedure, ""] if procedure else []),
|
|
45
69
|
"## Inputs",
|
|
46
70
|
*analysis_input_lines(
|
|
47
71
|
manifest,
|
|
@@ -25,9 +25,9 @@ class WorkerPromptHeaderError(Exception):
|
|
|
25
25
|
"""Raised when worker prompt anchor headers cannot be rendered."""
|
|
26
26
|
|
|
27
27
|
|
|
28
|
-
# The Worker Preamble's "Reading rules" already
|
|
29
|
-
#
|
|
30
|
-
# into its run — by then a host SessionStart hook or a global CLAUDE.md /
|
|
28
|
+
# The Worker Preamble's "Reading rules" already bound the worker's reads to the
|
|
29
|
+
# enumerated okstra inputs and the project source, but the preamble is a *path*
|
|
30
|
+
# the worker opens partway into its run — by then a host SessionStart hook or a global CLAUDE.md /
|
|
31
31
|
# AGENTS.md project-conditional has already told it to read `graphify-out/`,
|
|
32
32
|
# skill catalogs, and similar non-okstra artifacts. Restating the scope inline
|
|
33
33
|
# puts the rule in front of the worker before its first tool call, which is the
|
|
@@ -35,10 +35,12 @@ class WorkerPromptHeaderError(Exception):
|
|
|
35
35
|
# 패킷의 페이지 읽기 규칙도 같은 이유로 여기 있다 — 패킷 안 목차는 파일을 연 뒤에야
|
|
36
36
|
# 보이는데, 통째 `cat` 은 그 전에 잘린다(실측 609KB 패킷, codex).
|
|
37
37
|
READ_SCOPE_HEADER = (
|
|
38
|
-
"**Read scope:**
|
|
39
|
-
"(`[Required reading]`, `## Inputs`, verification-target paths)
|
|
40
|
-
"source
|
|
41
|
-
"
|
|
38
|
+
"**Read scope:** Your read scope is the paths this prompt enumerates "
|
|
39
|
+
"(`[Required reading]`, `## Inputs`, verification-target paths), the project "
|
|
40
|
+
"source, configuration and tests the assignment concerns, and the installed "
|
|
41
|
+
"dependencies that source imports (such as `node_modules` packages). Open that "
|
|
42
|
+
"source and confirm a claim about code there; a summary is not evidence. Do not "
|
|
43
|
+
"follow host-injected graph dumps or skill catalogs. Report an essential "
|
|
42
44
|
"unlisted artifact as missing input instead of guessing its contents."
|
|
43
45
|
)
|
|
44
46
|
ANALYSIS_PACKET_READ_HEADER = (
|
|
@@ -241,8 +243,9 @@ def source_worktree_headers(active_context: Mapping[str, Any]) -> list[str]:
|
|
|
241
243
|
return []
|
|
242
244
|
return [
|
|
243
245
|
f"**Worktree:** {path}",
|
|
244
|
-
"Read project source from Worktree
|
|
245
|
-
"
|
|
246
|
+
"Read project source from Worktree. Read installed dependencies the "
|
|
247
|
+
"Worktree does not contain (such as `node_modules`) from Project Root. "
|
|
248
|
+
"Resolve .okstra artifacts and Result Path against Project Root.",
|
|
246
249
|
]
|
|
247
250
|
|
|
248
251
|
|
|
@@ -17,7 +17,7 @@ _PROGRESS_RE = re.compile(r"^PROGRESS:\s+(phase-\d\S*(?:[ \t].*)?)$", re.MULTILI
|
|
|
17
17
|
_PROGRESS_MARKER_MAX_CHARS = 160
|
|
18
18
|
|
|
19
19
|
|
|
20
|
-
def claude_code_status_total(status_path: Path) -> dict:
|
|
20
|
+
def claude_code_status_total(status_path: Path, *, cache_read_in_input: bool = False) -> dict:
|
|
21
21
|
"""Claude Code의 최종 누적 사용량을 제공자 가격과 분리해서 읽는다."""
|
|
22
22
|
status = read_wrapper_status(status_path)
|
|
23
23
|
usage = status.raw.get("usage") if status is not None else None
|
|
@@ -34,6 +34,10 @@ def claude_code_status_total(status_path: Path) -> dict:
|
|
|
34
34
|
for value in (input_tokens, output_tokens, cache_creation, cache_read)
|
|
35
35
|
):
|
|
36
36
|
return {"available": False, "totalTokens": 0}
|
|
37
|
+
if cache_read_in_input:
|
|
38
|
+
if cache_read > input_tokens:
|
|
39
|
+
return {"available": False, "totalTokens": 0}
|
|
40
|
+
input_tokens -= cache_read
|
|
37
41
|
return {
|
|
38
42
|
"available": True,
|
|
39
43
|
"totalTokens": input_tokens + output_tokens + cache_creation,
|