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
|
@@ -484,7 +484,7 @@ def _enforce_schema(data: dict) -> dict | None:
|
|
|
484
484
|
# 구체버전 계열로 돌았는지" 가독성만 준다. CLI 가 실제 고른 버전과 다를 수
|
|
485
485
|
# 있으나 표시이므로 실행에는 무해하다. 새 버전이 나오면 여기만 갱신한다.
|
|
486
486
|
_DISPLAY_CONCRETE_CLAUDE = {
|
|
487
|
-
"fable": "claude-fable-5-
|
|
487
|
+
"fable": "claude-fable-5-2",
|
|
488
488
|
"opus": "claude-opus-5",
|
|
489
489
|
"sonnet": "claude-sonnet-5",
|
|
490
490
|
"haiku": "claude-haiku-5-5",
|
|
@@ -2455,7 +2455,7 @@ def recommended_role_models(
|
|
|
2455
2455
|
codex 이고 다른 provider 요청은 거부된다(`resolve_lead_provider`). 그래서
|
|
2456
2456
|
`lead_provider` 를 받아 그 provider 의 기본값으로 해소한다. 받지 않으면
|
|
2457
2457
|
role 별 레거시 기본값(claude 계열)으로 떨어지는데, 그 값을 codex 호스트
|
|
2458
|
-
화면에 그대로 쓰면 안내는 `opus` 인데 prepare 는 `gpt-6.
|
|
2458
|
+
화면에 그대로 쓰면 안내는 `opus` 인데 prepare 는 `gpt-6.2-sol` 을 배정한다.
|
|
2459
2459
|
"""
|
|
2460
2460
|
lead_provider_id = lead_provider or "claude"
|
|
2461
2461
|
report_writer_provider_id = report_writer_provider or "claude"
|
|
@@ -41,7 +41,23 @@ def latest_run_inputs(
|
|
|
41
41
|
phase_segment: str = "",
|
|
42
42
|
stage: Optional[int] = None,
|
|
43
43
|
) -> dict:
|
|
44
|
-
"""
|
|
44
|
+
"""The latest run's ``inputs`` (see `latest_run_inputs_document`); ``{}`` when absent."""
|
|
45
|
+
document = latest_run_inputs_document(
|
|
46
|
+
project_root, task_group, task_id, phase_segment=phase_segment, stage=stage,
|
|
47
|
+
)
|
|
48
|
+
inputs = document.get("inputs")
|
|
49
|
+
return inputs if isinstance(inputs, dict) else {}
|
|
50
|
+
|
|
51
|
+
|
|
52
|
+
def latest_run_inputs_document(
|
|
53
|
+
project_root: object,
|
|
54
|
+
task_group: str,
|
|
55
|
+
task_id: str,
|
|
56
|
+
*,
|
|
57
|
+
phase_segment: str = "",
|
|
58
|
+
stage: Optional[int] = None,
|
|
59
|
+
) -> dict:
|
|
60
|
+
"""Return the whole latest ``run-inputs-*.json`` record (``{}`` when absent).
|
|
45
61
|
|
|
46
62
|
``phase_segment`` 가 주어지면 그 phase 의 ``runs/<seg>/manifests/`` 와
|
|
47
63
|
``runs/<seg>/stage-*/manifests/`` 만 스캔한다 (resume 는 같은 phase 를 재실행하므로
|
|
@@ -78,8 +94,7 @@ def latest_run_inputs(
|
|
|
78
94
|
data = load_owned_object(candidates[0][1], artifact="run context")
|
|
79
95
|
except JsonBoundaryError:
|
|
80
96
|
return {}
|
|
81
|
-
|
|
82
|
-
return inputs if isinstance(inputs, dict) else {}
|
|
97
|
+
return data if isinstance(data, dict) else {}
|
|
83
98
|
|
|
84
99
|
|
|
85
100
|
def _now_iso() -> str:
|
|
@@ -52,6 +52,19 @@ def _refs_in(obj) -> set[str]:
|
|
|
52
52
|
return set(_REF_RE.findall(json.dumps(obj, ensure_ascii=False)))
|
|
53
53
|
|
|
54
54
|
|
|
55
|
+
def reachable_defs(defs: dict, start: object) -> set[str]:
|
|
56
|
+
"""Names of the ``$defs`` that *start* reaches through ``$ref``, transitively."""
|
|
57
|
+
reachable: set[str] = set()
|
|
58
|
+
work = list(_refs_in(start))
|
|
59
|
+
while work:
|
|
60
|
+
name = work.pop()
|
|
61
|
+
if name in reachable or name not in defs:
|
|
62
|
+
continue
|
|
63
|
+
reachable.add(name)
|
|
64
|
+
work.extend(_refs_in(defs[name]))
|
|
65
|
+
return reachable
|
|
66
|
+
|
|
67
|
+
|
|
55
68
|
def _conditional_applies(entry: dict, task_type: str) -> bool:
|
|
56
69
|
"""True when an ``allOf`` if/then entry is relevant to *task_type*.
|
|
57
70
|
|
|
@@ -219,16 +232,8 @@ def build_schema_excerpt(schema: dict, task_type: str, cut_from_version: str = "
|
|
|
219
232
|
}
|
|
220
233
|
all_of = [e for e in schema.get("allOf", []) if _conditional_applies(e, task_type)]
|
|
221
234
|
|
|
222
|
-
# Reachable $defs = transitive closure of $ref from kept props + allOf.
|
|
223
235
|
defs = schema.get("$defs", {})
|
|
224
|
-
reachable
|
|
225
|
-
work = list(_refs_in(props) | _refs_in(all_of))
|
|
226
|
-
while work:
|
|
227
|
-
name = work.pop()
|
|
228
|
-
if name in reachable or name not in defs:
|
|
229
|
-
continue
|
|
230
|
-
reachable.add(name)
|
|
231
|
-
work.extend(_refs_in(defs[name]))
|
|
236
|
+
reachable = reachable_defs(defs, [props, all_of])
|
|
232
237
|
|
|
233
238
|
excerpt = {
|
|
234
239
|
k: v
|
|
@@ -65,7 +65,7 @@ _ITEM_RE = re.compile(r"^###[ \t]+(?P<id>[^\s:]+)[ \t]*:?.*$", re.MULTILINE)
|
|
|
65
65
|
# `_field_match` enforces that an opening `**` is closed exactly once and that
|
|
66
66
|
# a label without bold carries a bullet.
|
|
67
67
|
_FIELD_KEYS = ("Verdict", "Fixability", "Note", "Explanation", "Prior dissent",
|
|
68
|
-
"Basis", "Your evidence", "Dependencies")
|
|
68
|
+
"Basis", "Your evidence", "Dependencies", "Opened")
|
|
69
69
|
_CANONICAL_KEYS = {key.lower(): key for key in _FIELD_KEYS}
|
|
70
70
|
_FIELD_RE = re.compile(
|
|
71
71
|
r"^(?P<bullet>[-*+][ \t]+)?(?P<open>\*\*)?"
|
|
@@ -105,6 +105,7 @@ class FindingVote:
|
|
|
105
105
|
verdict: str
|
|
106
106
|
disagree_basis: str | None
|
|
107
107
|
explanation: str
|
|
108
|
+
opened: tuple[str, ...] = ()
|
|
108
109
|
|
|
109
110
|
|
|
110
111
|
def _scan_blocks(text: str) -> dict[str, dict[str, str]]:
|
|
@@ -221,7 +222,11 @@ def _finding_vote(
|
|
|
221
222
|
f"finding `{finding_id}` has basis `{basis}` — expected one of "
|
|
222
223
|
f"{sorted(DISAGREE_BASES)}"
|
|
223
224
|
)
|
|
224
|
-
|
|
225
|
+
from .worker_audit_ledger import named_files
|
|
226
|
+
|
|
227
|
+
return FindingVote(
|
|
228
|
+
finding_id, verdict, basis, explanation, named_files(fields.get("Opened", "")),
|
|
229
|
+
)
|
|
225
230
|
|
|
226
231
|
|
|
227
232
|
@dataclass(frozen=True)
|
|
@@ -37,11 +37,12 @@ from .ids import (
|
|
|
37
37
|
_STEP_TO_GROUP,
|
|
38
38
|
)
|
|
39
39
|
from .state import Prompt, WizardError, WizardState, _is_role_selection_step
|
|
40
|
-
from .prompts import _domain_prompt
|
|
40
|
+
from .prompts import _domain_prompt, _msg
|
|
41
41
|
from .picker_navigation import (
|
|
42
42
|
is_split_picker,
|
|
43
43
|
merge_split_picker_answer,
|
|
44
44
|
present_picker,
|
|
45
|
+
split_by_vendor,
|
|
45
46
|
split_picker,
|
|
46
47
|
)
|
|
47
48
|
from .roles import _step_role, _submit_role_prompt, next_role_prompt
|
|
@@ -184,9 +185,19 @@ def next_prompt(state: WizardState) -> Prompt:
|
|
|
184
185
|
state.__dict__.update(attempt.__dict__)
|
|
185
186
|
|
|
186
187
|
|
|
188
|
+
def _is_model_pick(prompt: Prompt) -> bool:
|
|
189
|
+
return prompt.kind == "pick" and (
|
|
190
|
+
prompt.step.startswith(("role-models:", "role-model:"))
|
|
191
|
+
or prompt.step == "worker_settings_models"
|
|
192
|
+
)
|
|
193
|
+
|
|
194
|
+
|
|
187
195
|
def _native_picker_screen(state: WizardState, prompt: Prompt) -> Prompt:
|
|
188
196
|
"""호스트 네이티브 선택기 한도에 맞춘 화면.
|
|
189
197
|
|
|
198
|
+
모델 선택 화면은 후보 수와 상관없이 벤더별 탭으로 나눈다(`split_by_vendor`).
|
|
199
|
+
그 묶음이 호스트에 실리지 않을 때만 아래 규칙을 쓴다.
|
|
200
|
+
|
|
190
201
|
한도를 넘는 픽은 체크박스든 단일 선택이든 네이티브 질문 묶음에 실리는
|
|
191
202
|
크기(claude-code 4×4=16)까지 같은 화면의 체크박스 질문 여러 개로 자른다
|
|
192
203
|
(`split_picker`) — 사용자는 탭을 옮겨 다니며 한 번에 답한다. 단일 선택을
|
|
@@ -204,6 +215,16 @@ def _native_picker_screen(state: WizardState, prompt: Prompt) -> Prompt:
|
|
|
204
215
|
return prompt
|
|
205
216
|
prompt = prompt.questions[0]
|
|
206
217
|
port = default_host_registry().resolve(state.host_runtime).interaction()
|
|
218
|
+
if _is_model_pick(prompt):
|
|
219
|
+
by_vendor = split_by_vendor(
|
|
220
|
+
prompt,
|
|
221
|
+
max_options=port.native_option_limit,
|
|
222
|
+
max_questions=port.native_question_limit,
|
|
223
|
+
free_input_label=_msg(state.workspace_root, "model_tabs", "free_input", vendors="{vendors}"),
|
|
224
|
+
mixed_label=_msg(state.workspace_root, "model_tabs", "mixed", vendors="{vendors}"),
|
|
225
|
+
)
|
|
226
|
+
if by_vendor is not prompt and _interaction_plan(state, by_vendor).kind == "native-group":
|
|
227
|
+
return by_vendor
|
|
207
228
|
split = split_picker(
|
|
208
229
|
prompt,
|
|
209
230
|
max_options=port.native_option_limit,
|
|
@@ -276,6 +297,12 @@ def _sim_advance(state: WizardState, prompt: Prompt) -> None:
|
|
|
276
297
|
prompt = _next_prompt_screen(state)
|
|
277
298
|
try:
|
|
278
299
|
if _is_role_selection_step(prompt.step):
|
|
300
|
+
# A pending typed-model step has no default answer: count it and
|
|
301
|
+
# settle the role from its model screen's recommended set.
|
|
302
|
+
if prompt.kind == "text":
|
|
303
|
+
state.role_model_drafts.pop(_step_role(prompt.step), None)
|
|
304
|
+
state.answered.append(prompt.step)
|
|
305
|
+
prompt = next_role_prompt(state) or prompt
|
|
279
306
|
# 화면은 호스트 한도에 맞춰 쪽으로 잘린 사본일 수 있다 — 기본답은
|
|
280
307
|
# 잘리지 않은 원본(추천 집합)에서 낸다.
|
|
281
308
|
original = next_role_prompt(state) or prompt
|
|
@@ -348,8 +348,16 @@ _REUSE_FILLED_STEPS = (
|
|
|
348
348
|
S_CLARIFICATION_PICK, S_CLARIFICATION)
|
|
349
349
|
|
|
350
350
|
|
|
351
|
+
_INPUT_PREFIX = "role-model-input:"
|
|
351
352
|
_MODELS_PREFIX = "role-models:"
|
|
352
353
|
_SINGLE_PREFIX = "role-model:"
|
|
354
|
+
_ROLE_SELECTION_PREFIXES = (_INPUT_PREFIX, _MODELS_PREFIX, _SINGLE_PREFIX)
|
|
355
|
+
# A vendor tab's "type a model" row: the prefix plus the tab's providers joined by "+".
|
|
356
|
+
MODEL_FREE_INPUT_PREFIX = "__free_input__:"
|
|
357
|
+
|
|
358
|
+
|
|
359
|
+
def _role_model_input_prompt_id(role: str) -> str:
|
|
360
|
+
return f"{_INPUT_PREFIX}{role}"
|
|
353
361
|
|
|
354
362
|
|
|
355
363
|
def _role_models_prompt_id(role: str) -> str:
|
|
@@ -13,8 +13,8 @@ import json
|
|
|
13
13
|
import math
|
|
14
14
|
from dataclasses import replace
|
|
15
15
|
|
|
16
|
-
from .ids import PICK_TYPE_CUSTOM
|
|
17
|
-
from .state import Prompt, WizardError
|
|
16
|
+
from .ids import MODEL_FREE_INPUT_PREFIX, PICK_TYPE_CUSTOM
|
|
17
|
+
from .state import Option, Prompt, WizardError
|
|
18
18
|
|
|
19
19
|
_SPLIT_SEPARATOR = "#"
|
|
20
20
|
|
|
@@ -69,6 +69,68 @@ def split_picker(
|
|
|
69
69
|
)
|
|
70
70
|
|
|
71
71
|
|
|
72
|
+
def split_by_vendor(
|
|
73
|
+
prompt: Prompt,
|
|
74
|
+
*,
|
|
75
|
+
max_options: int,
|
|
76
|
+
max_questions: int,
|
|
77
|
+
free_input_label: str,
|
|
78
|
+
mixed_label: str,
|
|
79
|
+
) -> Prompt:
|
|
80
|
+
"""Show a model pick as one checkbox tab per vendor on one screen.
|
|
81
|
+
|
|
82
|
+
Each tab lists up to `max_options - 1` of a vendor's models, keeping the
|
|
83
|
+
recommended ones, and ends with a "type a model" row whose value names the tab's
|
|
84
|
+
providers. A vendor with that many models gets its own tab; the others
|
|
85
|
+
share one mixed tab. When the own tabs and the mixed tab exceed
|
|
86
|
+
`max_questions`, the last own tabs join the mixed one. Rows that are not
|
|
87
|
+
`provider/model` refs (a skip row) are left out: an empty answer means
|
|
88
|
+
nothing picked. Returns the prompt unchanged when it holds no model.
|
|
89
|
+
"""
|
|
90
|
+
models = [option for option in prompt.options if "/" in option.value]
|
|
91
|
+
if prompt.kind != "pick" or not models or max_options < 2:
|
|
92
|
+
return prompt
|
|
93
|
+
shown = max_options - 1
|
|
94
|
+
vendors: dict[str, list[Option]] = {}
|
|
95
|
+
for option in models:
|
|
96
|
+
vendors.setdefault(option.value.split("/", 1)[0], []).append(option)
|
|
97
|
+
own = [vendor for vendor, rows in vendors.items() if len(rows) >= shown]
|
|
98
|
+
mixed = [vendor for vendor in vendors if vendor not in own]
|
|
99
|
+
if len(own) + (1 if mixed else 0) > max_questions:
|
|
100
|
+
keep = max_questions - 1
|
|
101
|
+
mixed = [vendor for vendor in vendors if vendor in own[keep:] or vendor in mixed]
|
|
102
|
+
own = own[:keep]
|
|
103
|
+
groups = [[vendor] for vendor in own] + ([mixed] if mixed else [])
|
|
104
|
+
questions: list[Prompt] = []
|
|
105
|
+
for index, group in enumerate(groups, start=1):
|
|
106
|
+
rows = [option for vendor in group for option in vendors[vendor]]
|
|
107
|
+
picked = sorted(rows, key=lambda option: not option.recommended)[:shown]
|
|
108
|
+
rows = [option for option in rows if option in picked]
|
|
109
|
+
name = group[0] if len(group) == 1 else mixed_label.format(vendors="·".join(group))
|
|
110
|
+
questions.append(replace(
|
|
111
|
+
prompt,
|
|
112
|
+
step=f"{prompt.step}{_SPLIT_SEPARATOR}{index}",
|
|
113
|
+
label=f"{prompt.label} [{name}]",
|
|
114
|
+
options=[
|
|
115
|
+
*rows,
|
|
116
|
+
Option(
|
|
117
|
+
f"{MODEL_FREE_INPUT_PREFIX}{'+'.join(group)}",
|
|
118
|
+
free_input_label.format(vendors=name),
|
|
119
|
+
),
|
|
120
|
+
],
|
|
121
|
+
multi=True,
|
|
122
|
+
))
|
|
123
|
+
return Prompt(
|
|
124
|
+
step=prompt.step,
|
|
125
|
+
kind="pick_group",
|
|
126
|
+
label=prompt.label,
|
|
127
|
+
help=prompt.help,
|
|
128
|
+
echo_template=prompt.echo_template,
|
|
129
|
+
multi=prompt.multi,
|
|
130
|
+
questions=questions,
|
|
131
|
+
)
|
|
132
|
+
|
|
133
|
+
|
|
72
134
|
def is_split_picker(prompt: Prompt) -> bool:
|
|
73
135
|
return prompt.kind == "pick_group" and bool(prompt.questions) and all(
|
|
74
136
|
question.multi
|
|
@@ -8,7 +8,9 @@ verifier: `max > 1`)은 체크박스 한 장이고, 고른 모델 수가 곧 인
|
|
|
8
8
|
고정 단일 역할(`min = max = 1`, 예: report-writer·implementer)은 단일 선택 한 장이다.
|
|
9
9
|
|
|
10
10
|
모델 화면(`role-models:<role>`, `role-model:<role>:1`)은 실행 가능한 전체 후보를
|
|
11
|
-
|
|
11
|
+
제공자 순서로 싣는다. 호스트에 네이티브 질문 묶음이 있으면 엔진이 이 화면을
|
|
12
|
+
벤더별 탭으로 나눠 보인다(`picker_navigation.split_by_vendor`). 탭의 "직접 입력"
|
|
13
|
+
을 고르면 다음 화면(`role-model-input:<role>`)에서 모델 id 를 받는다. 기본 후보(프로젝트 `modelDefaults`, 없으면
|
|
12
14
|
카탈로그 기본값)에서 권장 수만큼 추천하고 제공자 안에서는 기본 후보가 앞이다.
|
|
13
15
|
호스트 네이티브 선택기의 옵션 한도
|
|
14
16
|
(claude-code 4, codex 3, grok 15)를 넘으면 체크박스든 단일 선택이든 네이티브
|
|
@@ -59,11 +61,14 @@ from .state import (
|
|
|
59
61
|
from .prompts import _msg, _opt, _p
|
|
60
62
|
from .ids import (
|
|
61
63
|
_MODELS_PREFIX,
|
|
62
|
-
|
|
64
|
+
_INPUT_PREFIX,
|
|
65
|
+
_ROLE_SELECTION_PREFIXES,
|
|
66
|
+
MODEL_FREE_INPUT_PREFIX,
|
|
63
67
|
_fixed_single,
|
|
64
68
|
_role_model_prompt_id,
|
|
65
69
|
_role_models_prompt_id,
|
|
66
70
|
_role_prompt_id,
|
|
71
|
+
_role_model_input_prompt_id,
|
|
67
72
|
)
|
|
68
73
|
|
|
69
74
|
# 선택 역할의 "추가 안 함" 값. 모델 참조는 `<provider>/<model>` 꼴이라 겹치지 않는다.
|
|
@@ -71,7 +76,7 @@ ROLE_SKIP_TOKEN = "0"
|
|
|
71
76
|
|
|
72
77
|
def _step_role(step_id: str) -> str:
|
|
73
78
|
"""역할 선택 step id 가 가리키는 역할. 역할 선택 step 이 아니면 빈 문자열."""
|
|
74
|
-
for prefix in
|
|
79
|
+
for prefix in _ROLE_SELECTION_PREFIXES:
|
|
75
80
|
if step_id.startswith(prefix):
|
|
76
81
|
return step_id[len(prefix):].split(":", 1)[0]
|
|
77
82
|
return ""
|
|
@@ -236,37 +241,73 @@ def _apply_configured_role_defaults(
|
|
|
236
241
|
options=[Option(value, value) for value in values],
|
|
237
242
|
auto_value=",".join(values),
|
|
238
243
|
)
|
|
239
|
-
prompt = (
|
|
240
|
-
_model_prompt(state, profile, requirement, context, scopes)
|
|
241
|
-
if _fixed_single(requirement)
|
|
242
|
-
else _role_models_prompt(state, profile, requirement, context, scopes)
|
|
243
|
-
)
|
|
244
|
+
prompt = _manual_role_prompt(state, profile, requirement, context, scopes)
|
|
244
245
|
if error:
|
|
245
246
|
prompt.label = _msg(state.workspace_root, "worker_settings", "run_invalid",
|
|
246
247
|
error=error, label=prompt.label)
|
|
247
248
|
return prompt
|
|
248
249
|
|
|
249
250
|
|
|
250
|
-
def
|
|
251
|
+
def _provider_of(model_ref: str) -> str:
|
|
252
|
+
return model_ref.split("/", 1)[0]
|
|
253
|
+
|
|
254
|
+
|
|
255
|
+
def _manual_role_prompt(
|
|
251
256
|
state: WizardState,
|
|
252
257
|
profile: RoleProfile,
|
|
253
258
|
requirement: RoleRequirement,
|
|
254
259
|
context: AssignmentContext,
|
|
255
260
|
scopes: ModelDefaultScopes,
|
|
256
261
|
) -> Prompt:
|
|
257
|
-
"""
|
|
262
|
+
"""The model screen a user answers for a role, every executable candidate on it."""
|
|
263
|
+
models = _role_model_options(state, profile, requirement, context, scopes)
|
|
264
|
+
if _fixed_single(requirement):
|
|
265
|
+
return _model_prompt(state, requirement, models)
|
|
266
|
+
return _role_models_prompt(state, requirement, models)
|
|
267
|
+
|
|
268
|
+
|
|
269
|
+
def _role_model_options(
|
|
270
|
+
state: WizardState,
|
|
271
|
+
profile: RoleProfile,
|
|
272
|
+
requirement: RoleRequirement,
|
|
273
|
+
context: AssignmentContext,
|
|
274
|
+
scopes: ModelDefaultScopes,
|
|
275
|
+
) -> list[Option]:
|
|
276
|
+
"""Every executable model for the role, in provider order.
|
|
258
277
|
|
|
259
|
-
|
|
260
|
-
|
|
278
|
+
The first `recommended_count` defaults (project `modelDefaults`, else the
|
|
279
|
+
catalog defaults) are recommended, ranked before the provider sort. A
|
|
280
|
+
fixed single role gets only the candidates that still complete the
|
|
281
|
+
assignment, with the first one recommended (`_single_model_options`).
|
|
261
282
|
"""
|
|
262
|
-
|
|
283
|
+
if _fixed_single(requirement):
|
|
284
|
+
return _single_model_options(state, profile, requirement.role, context, scopes)
|
|
263
285
|
pool = context.pool
|
|
264
286
|
_defaults, everything = _available_role_models(
|
|
265
287
|
state, profile, requirement, context, scopes,
|
|
266
288
|
)
|
|
267
289
|
if not everything:
|
|
268
290
|
_validate_role_selection_feasibility(state, profile, context, scopes)
|
|
269
|
-
raise WizardError(f"role {role!r} has no executable model candidates")
|
|
291
|
+
raise WizardError(f"role {requirement.role!r} has no executable model candidates")
|
|
292
|
+
t = _role_models_texts(state, "role_models", requirement)
|
|
293
|
+
options: list[Option] = []
|
|
294
|
+
for index, model_ref in enumerate(everything):
|
|
295
|
+
model = pool.resolve(model_ref)
|
|
296
|
+
options.append(_opt(
|
|
297
|
+
model_ref,
|
|
298
|
+
t["options"]["model"].format(model_ref=model_ref, display=model.display_name),
|
|
299
|
+
recommended=index < requirement.recommended_count,
|
|
300
|
+
))
|
|
301
|
+
options.sort(key=lambda option: provider_display_order(_provider_of(option.value)))
|
|
302
|
+
return options
|
|
303
|
+
|
|
304
|
+
|
|
305
|
+
def _role_models_prompt(
|
|
306
|
+
state: WizardState,
|
|
307
|
+
requirement: RoleRequirement,
|
|
308
|
+
options: list[Option],
|
|
309
|
+
) -> Prompt:
|
|
310
|
+
"""A role's model screen. An optional role's skip row joins the candidates."""
|
|
270
311
|
t = _role_models_texts(state, "role_models", requirement)
|
|
271
312
|
multi = requirement.max_count > 1
|
|
272
313
|
# "고른 만큼 인스턴스를 띄웁니다" 는 체크박스 문구다 — 최대 1개인 역할(critic)은
|
|
@@ -277,21 +318,13 @@ def _role_models_prompt(
|
|
|
277
318
|
)
|
|
278
319
|
optional = requirement.min_count == 0
|
|
279
320
|
skip_first = optional and requirement.recommended_count == 0
|
|
280
|
-
options
|
|
281
|
-
for index, model_ref in enumerate(everything):
|
|
282
|
-
model = pool.resolve(model_ref)
|
|
283
|
-
options.append(_opt(
|
|
284
|
-
model_ref,
|
|
285
|
-
t["options"]["model"].format(model_ref=model_ref, display=model.display_name),
|
|
286
|
-
recommended=index < requirement.recommended_count,
|
|
287
|
-
))
|
|
288
|
-
options.sort(key=lambda option: provider_display_order(option.value.split("/", 1)[0]))
|
|
321
|
+
options = list(options)
|
|
289
322
|
if skip_first:
|
|
290
323
|
options.insert(0, _skip_option(requirement, t, recommended=True))
|
|
291
324
|
if optional and not skip_first:
|
|
292
325
|
options.append(_skip_option(requirement, t, recommended=False))
|
|
293
326
|
return Prompt(
|
|
294
|
-
step=_role_models_prompt_id(role),
|
|
327
|
+
step=_role_models_prompt_id(requirement.role),
|
|
295
328
|
kind="pick",
|
|
296
329
|
multi=multi,
|
|
297
330
|
label=label,
|
|
@@ -336,21 +369,16 @@ def _single_model_options(
|
|
|
336
369
|
if not options:
|
|
337
370
|
_validate_role_selection_feasibility(state, profile, context, scopes)
|
|
338
371
|
raise WizardError(f"role {role!r} has no executable model candidates")
|
|
339
|
-
options.sort(key=lambda option: provider_display_order(option.value
|
|
372
|
+
options.sort(key=lambda option: provider_display_order(_provider_of(option.value)))
|
|
340
373
|
return options
|
|
341
374
|
|
|
342
375
|
|
|
343
376
|
def _model_prompt(
|
|
344
377
|
state: WizardState,
|
|
345
|
-
profile: RoleProfile,
|
|
346
378
|
requirement: RoleRequirement,
|
|
347
|
-
|
|
348
|
-
scopes: ModelDefaultScopes,
|
|
379
|
+
options: list[Option],
|
|
349
380
|
) -> Prompt:
|
|
350
381
|
prompt = _p(state.workspace_root, "role_model", role=requirement.role)
|
|
351
|
-
options = _single_model_options(
|
|
352
|
-
state, profile, requirement.role, context, scopes,
|
|
353
|
-
)
|
|
354
382
|
return Prompt(
|
|
355
383
|
step=_role_model_prompt_id(requirement.role, 1),
|
|
356
384
|
kind="pick",
|
|
@@ -365,6 +393,7 @@ def _drop_role_selection(state: WizardState, roles: set[str]) -> None:
|
|
|
365
393
|
for role in roles:
|
|
366
394
|
state.role_models.pop(role, None)
|
|
367
395
|
state.role_counts.pop(role, None)
|
|
396
|
+
state.role_model_drafts.pop(role, None)
|
|
368
397
|
state.role_sources.pop(role, None)
|
|
369
398
|
state.role_selection_order = [
|
|
370
399
|
step_id for step_id in state.role_selection_order
|
|
@@ -564,7 +593,7 @@ def _load_context(state: WizardState) -> tuple[AssignmentContext, ModelDefaultSc
|
|
|
564
593
|
|
|
565
594
|
|
|
566
595
|
def next_role_prompt(state: WizardState) -> Prompt | None:
|
|
567
|
-
"""프로필 순서대로
|
|
596
|
+
"""프로필 순서대로 답이 없는 첫 역할의 다음 화면(제공자, 그다음 모델)을 낸다."""
|
|
568
597
|
if not _identity_ready(state):
|
|
569
598
|
return None
|
|
570
599
|
profile = _load_role_profile_for_state(state)
|
|
@@ -573,6 +602,8 @@ def next_role_prompt(state: WizardState) -> Prompt | None:
|
|
|
573
602
|
_discard_invalid_previous_models(state, profile, requirements, context, scopes)
|
|
574
603
|
for requirement in requirements:
|
|
575
604
|
role = requirement.role
|
|
605
|
+
if role in state.role_model_drafts:
|
|
606
|
+
return _model_input_prompt(state, profile, requirement, context, scopes)
|
|
576
607
|
selected = state.role_models.get(role, [])
|
|
577
608
|
if _fixed_single(requirement):
|
|
578
609
|
if not selected:
|
|
@@ -594,7 +625,7 @@ def next_role_prompt(state: WizardState) -> Prompt | None:
|
|
|
594
625
|
state,
|
|
595
626
|
{later.role for later in requirements[requirements.index(requirement):]},
|
|
596
627
|
)
|
|
597
|
-
return
|
|
628
|
+
return _manual_role_prompt(state, profile, requirement, context, scopes)
|
|
598
629
|
_validate_role_selection_feasibility(state, profile, context, scopes)
|
|
599
630
|
return None
|
|
600
631
|
|
|
@@ -606,6 +637,113 @@ def _requirement_for(profile: RoleProfile, role: str) -> RoleRequirement:
|
|
|
606
637
|
return requirement
|
|
607
638
|
|
|
608
639
|
|
|
640
|
+
def _picked_values(t: dict, prompt: Prompt, value: str) -> list[str]:
|
|
641
|
+
# 같은 값이 두 번 오면(번호 목록에서 `1,1`) 한 번으로 센다 — 거절할 일이 아니다.
|
|
642
|
+
picked = list(dict.fromkeys(
|
|
643
|
+
item.strip() for item in (value or "").split(",") if item.strip()
|
|
644
|
+
))
|
|
645
|
+
allowed = {option.value for option in prompt.options}
|
|
646
|
+
unknown = [item for item in picked if item not in allowed]
|
|
647
|
+
if unknown:
|
|
648
|
+
raise WizardError(t["errors"]["unknown_option"].format(values=", ".join(unknown)))
|
|
649
|
+
return picked
|
|
650
|
+
|
|
651
|
+
|
|
652
|
+
def _skip_role(state: WizardState, role: str) -> None:
|
|
653
|
+
state.role_counts[role] = 0
|
|
654
|
+
state.role_models.pop(role, None)
|
|
655
|
+
|
|
656
|
+
|
|
657
|
+
def free_input_providers(values: list[str]) -> tuple[list[str], list[str]]:
|
|
658
|
+
"""Split a pick into its chosen values and the providers of ticked "type a model" rows."""
|
|
659
|
+
chosen: list[str] = []
|
|
660
|
+
providers: list[str] = []
|
|
661
|
+
for value in values:
|
|
662
|
+
if value.startswith(MODEL_FREE_INPUT_PREFIX):
|
|
663
|
+
providers.extend(value[len(MODEL_FREE_INPUT_PREFIX):].split("+"))
|
|
664
|
+
else:
|
|
665
|
+
chosen.append(value)
|
|
666
|
+
return chosen, list(dict.fromkeys(providers))
|
|
667
|
+
|
|
668
|
+
|
|
669
|
+
def resolve_typed_models(
|
|
670
|
+
typed: str, providers: list[str], candidates: list[str],
|
|
671
|
+
) -> list[str]:
|
|
672
|
+
"""Typed model ids as candidate refs of those providers.
|
|
673
|
+
|
|
674
|
+
An entry is a full `provider/model` ref or a model id that one provider's
|
|
675
|
+
candidate ends with. Anything else is refused with the refs it could be.
|
|
676
|
+
"""
|
|
677
|
+
allowed = [ref for ref in candidates if ref.split("/", 1)[0] in providers]
|
|
678
|
+
resolved: list[str] = []
|
|
679
|
+
for item in (part.strip() for part in typed.split(",")):
|
|
680
|
+
if not item:
|
|
681
|
+
continue
|
|
682
|
+
matches = [ref for ref in allowed if ref == item or ref.split("/", 1)[1] == item]
|
|
683
|
+
if len(matches) != 1:
|
|
684
|
+
raise WizardError(
|
|
685
|
+
f"{item!r} is not one model of {', '.join(providers)}; "
|
|
686
|
+
f"choose from {', '.join(allowed)}"
|
|
687
|
+
)
|
|
688
|
+
resolved.append(matches[0])
|
|
689
|
+
if not resolved:
|
|
690
|
+
raise WizardError(f"type at least one model of {', '.join(providers)}")
|
|
691
|
+
return list(dict.fromkeys(resolved))
|
|
692
|
+
|
|
693
|
+
|
|
694
|
+
def _model_input_prompt(
|
|
695
|
+
state: WizardState,
|
|
696
|
+
profile: RoleProfile,
|
|
697
|
+
requirement: RoleRequirement,
|
|
698
|
+
context: AssignmentContext,
|
|
699
|
+
scopes: ModelDefaultScopes,
|
|
700
|
+
) -> Prompt:
|
|
701
|
+
draft = state.role_model_drafts[requirement.role]
|
|
702
|
+
candidates = [
|
|
703
|
+
option.value
|
|
704
|
+
for option in _role_model_options(state, profile, requirement, context, scopes)
|
|
705
|
+
if _provider_of(option.value) in draft["providers"]
|
|
706
|
+
]
|
|
707
|
+
t = _p(
|
|
708
|
+
state.workspace_root, "role_model_input",
|
|
709
|
+
role=requirement.role,
|
|
710
|
+
providers=", ".join(draft["providers"]),
|
|
711
|
+
chosen=", ".join(draft["models"]) or "-",
|
|
712
|
+
candidates=", ".join(candidates),
|
|
713
|
+
)
|
|
714
|
+
return Prompt(
|
|
715
|
+
step=_role_model_input_prompt_id(requirement.role),
|
|
716
|
+
kind="text",
|
|
717
|
+
label=t["label"],
|
|
718
|
+
echo_template=t["echo_template"],
|
|
719
|
+
)
|
|
720
|
+
|
|
721
|
+
|
|
722
|
+
def _submit_model_input(
|
|
723
|
+
state: WizardState,
|
|
724
|
+
profile: RoleProfile,
|
|
725
|
+
requirement: RoleRequirement,
|
|
726
|
+
value: str,
|
|
727
|
+
) -> str:
|
|
728
|
+
"""Join the typed models to the ticked ones and submit them as the role's answer."""
|
|
729
|
+
role = requirement.role
|
|
730
|
+
draft = state.role_model_drafts[role]
|
|
731
|
+
context, scopes = _load_context(state)
|
|
732
|
+
original = _manual_role_prompt(state, profile, requirement, context, scopes)
|
|
733
|
+
typed = resolve_typed_models(
|
|
734
|
+
value, draft["providers"], [option.value for option in original.options],
|
|
735
|
+
)
|
|
736
|
+
del state.role_model_drafts[role]
|
|
737
|
+
try:
|
|
738
|
+
return _submit_role_answer(
|
|
739
|
+
state, profile, requirement, original,
|
|
740
|
+
",".join(dict.fromkeys([*draft["models"], *typed])),
|
|
741
|
+
)
|
|
742
|
+
except WizardError:
|
|
743
|
+
state.role_model_drafts[role] = draft
|
|
744
|
+
raise
|
|
745
|
+
|
|
746
|
+
|
|
609
747
|
def _submit_role_models(
|
|
610
748
|
state: WizardState,
|
|
611
749
|
profile: RoleProfile,
|
|
@@ -617,22 +755,14 @@ def _submit_role_models(
|
|
|
617
755
|
role = requirement.role
|
|
618
756
|
t = _role_models_texts(state, "role_models", requirement)
|
|
619
757
|
range_text = t["range"]
|
|
620
|
-
|
|
621
|
-
picked = list(dict.fromkeys(
|
|
622
|
-
item.strip() for item in (value or "").split(",") if item.strip()
|
|
623
|
-
))
|
|
624
|
-
allowed = {option.value for option in prompt.options}
|
|
625
|
-
unknown = [item for item in picked if item not in allowed]
|
|
626
|
-
if unknown:
|
|
627
|
-
raise WizardError(t["errors"]["unknown_option"].format(values=", ".join(unknown)))
|
|
758
|
+
picked = _picked_values(t, prompt, value)
|
|
628
759
|
models = [item for item in picked if item != ROLE_SKIP_TOKEN]
|
|
629
760
|
# "추가 안 함" 과 모델을 같이 고르면 모델을 고른 것이다.
|
|
761
|
+
# Vendor tabs carry no skip row: an optional role with nothing ticked is skipped.
|
|
630
762
|
if not models:
|
|
631
|
-
if ROLE_SKIP_TOKEN not in picked:
|
|
763
|
+
if ROLE_SKIP_TOKEN not in picked and requirement.min_count > 0:
|
|
632
764
|
raise WizardError(t["errors"]["min_one_required"].format(range=range_text))
|
|
633
|
-
|
|
634
|
-
state.role_counts[role] = 0
|
|
635
|
-
state.role_models.pop(role, None)
|
|
765
|
+
_skip_role(state, role)
|
|
636
766
|
return t["echo_variants"]["skipped"]
|
|
637
767
|
if not requirement.min_count <= len(models) <= requirement.max_count:
|
|
638
768
|
raise WizardError(t["errors"]["count_out_of_range"].format(
|
|
@@ -684,6 +814,24 @@ def _submit_role_prompt(state: WizardState, prompt: Prompt, value: str) -> str:
|
|
|
684
814
|
profile = _load_role_profile_for_state(state)
|
|
685
815
|
role = _step_role(prompt.step)
|
|
686
816
|
requirement = _requirement_for(profile, role)
|
|
817
|
+
if prompt.step.startswith(_INPUT_PREFIX):
|
|
818
|
+
return _submit_model_input(state, profile, requirement, value)
|
|
819
|
+
picked = [item.strip() for item in (value or "").split(",") if item.strip()]
|
|
820
|
+
chosen, typed_from = free_input_providers(picked)
|
|
821
|
+
if typed_from:
|
|
822
|
+
state.role_model_drafts[role] = {"models": chosen, "providers": typed_from}
|
|
823
|
+
return f"role-models: {role} (typed models next: {', '.join(typed_from)})"
|
|
824
|
+
return _submit_role_answer(state, profile, requirement, prompt, value)
|
|
825
|
+
|
|
826
|
+
|
|
827
|
+
def _submit_role_answer(
|
|
828
|
+
state: WizardState,
|
|
829
|
+
profile: RoleProfile,
|
|
830
|
+
requirement: RoleRequirement,
|
|
831
|
+
prompt: Prompt,
|
|
832
|
+
value: str,
|
|
833
|
+
) -> str:
|
|
834
|
+
role = requirement.role
|
|
687
835
|
if prompt.step.startswith(_MODELS_PREFIX):
|
|
688
836
|
if _fixed_single(requirement):
|
|
689
837
|
raise WizardError(f"role {role!r} takes exactly one model")
|
|
@@ -724,6 +872,7 @@ def _reset_role_selection_from(state: WizardState, target_step: str) -> None:
|
|
|
724
872
|
def _clear_role_selection(state: WizardState) -> None:
|
|
725
873
|
state.role_counts.clear()
|
|
726
874
|
state.role_models.clear()
|
|
875
|
+
state.role_model_drafts.clear()
|
|
727
876
|
state.role_selection_order.clear()
|
|
728
877
|
state.role_sources.clear()
|
|
729
878
|
state.manual_steps = [
|