okstra 0.174.0 → 0.175.1
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 +18 -9
- package/bin/okstra +8 -4
- package/dist/cli-registry.d.mts +16 -0
- package/dist/cli-registry.mjs +560 -0
- package/dist/cli-registry.mjs.map +1 -0
- package/dist/commands/execute/agent-prompt.d.mts +1 -0
- package/{src → dist}/commands/execute/agent-prompt.mjs +10 -11
- package/dist/commands/execute/agent-prompt.mjs.map +1 -0
- package/dist/commands/execute/codex-dispatch.d.mts +3 -0
- package/dist/commands/execute/codex-dispatch.mjs +6 -0
- package/dist/commands/execute/codex-dispatch.mjs.map +1 -0
- package/dist/commands/execute/codex-run.d.mts +3 -0
- package/{src → dist}/commands/execute/codex-run.mjs +30 -37
- package/dist/commands/execute/codex-run.mjs.map +1 -0
- package/dist/commands/execute/convergence.d.mts +1 -0
- package/{src → dist}/commands/execute/convergence.mjs +15 -16
- package/dist/commands/execute/convergence.mjs.map +1 -0
- package/dist/commands/execute/error-log.d.mts +1 -0
- package/{src → dist}/commands/execute/error-log.mjs +2 -3
- package/dist/commands/execute/error-log.mjs.map +1 -0
- package/dist/commands/execute/git-reconcile.d.mts +1 -0
- package/{src → dist}/commands/execute/git-reconcile.mjs +10 -11
- package/dist/commands/execute/git-reconcile.mjs.map +1 -0
- package/dist/commands/execute/handoff.d.mts +1 -0
- package/{src → dist}/commands/execute/handoff.mjs +10 -11
- package/dist/commands/execute/handoff.mjs.map +1 -0
- package/dist/commands/execute/incremental-carry.d.mts +1 -0
- package/{src → dist}/commands/execute/incremental-carry.mjs +2 -3
- package/dist/commands/execute/incremental-carry.mjs.map +1 -0
- package/dist/commands/execute/incremental-scope.d.mts +1 -0
- package/{src → dist}/commands/execute/incremental-scope.mjs +2 -3
- package/dist/commands/execute/incremental-scope.mjs.map +1 -0
- package/dist/commands/execute/integrate-stages.d.mts +1 -0
- package/{src → dist}/commands/execute/integrate-stages.mjs +10 -11
- package/dist/commands/execute/integrate-stages.mjs.map +1 -0
- package/dist/commands/execute/pane-title.d.mts +1 -0
- package/dist/commands/execute/pane-title.mjs +20 -0
- package/dist/commands/execute/pane-title.mjs.map +1 -0
- package/dist/commands/execute/plan-items.d.mts +1 -0
- package/dist/commands/execute/plan-items.mjs +9 -0
- package/dist/commands/execute/plan-items.mjs.map +1 -0
- package/dist/commands/execute/plan-validate.d.mts +1 -0
- package/dist/commands/execute/plan-validate.mjs +68 -0
- package/dist/commands/execute/plan-validate.mjs.map +1 -0
- package/dist/commands/execute/plan-verify.d.mts +1 -0
- package/{src → dist}/commands/execute/plan-verify.mjs +13 -16
- package/dist/commands/execute/plan-verify.mjs.map +1 -0
- package/dist/commands/execute/render-bundle.d.mts +3 -0
- package/{src → dist}/commands/execute/render-bundle.mjs +65 -61
- package/dist/commands/execute/render-bundle.mjs.map +1 -0
- package/dist/commands/execute/run.d.mts +24 -0
- package/dist/commands/execute/run.mjs +196 -0
- package/dist/commands/execute/run.mjs.map +1 -0
- package/dist/commands/execute/spawn-followups.d.mts +1 -0
- package/{src → dist}/commands/execute/spawn-followups.mjs +6 -7
- package/dist/commands/execute/spawn-followups.mjs.map +1 -0
- package/dist/commands/execute/team.d.mts +3 -0
- package/{src → dist}/commands/execute/team.mjs +29 -36
- package/dist/commands/execute/team.mjs.map +1 -0
- package/dist/commands/execute/token-usage.d.mts +1 -0
- package/{src → dist}/commands/execute/token-usage.mjs +2 -3
- package/dist/commands/execute/token-usage.mjs.map +1 -0
- package/dist/commands/execute/wizard.d.mts +8 -0
- package/dist/commands/execute/wizard.mjs +191 -0
- package/dist/commands/execute/wizard.mjs.map +1 -0
- package/dist/commands/execute/worker-audit-check.d.mts +1 -0
- package/{src → dist}/commands/execute/worker-audit-check.mjs +11 -12
- package/dist/commands/execute/worker-audit-check.mjs.map +1 -0
- package/dist/commands/execute/worker-dispatch.d.mts +7 -0
- package/{src → dist}/commands/execute/worker-dispatch.mjs +34 -46
- package/dist/commands/execute/worker-dispatch.mjs.map +1 -0
- package/dist/commands/execute/worker-state.d.mts +1 -0
- package/{src → dist}/commands/execute/worker-state.mjs +15 -16
- package/dist/commands/execute/worker-state.mjs.map +1 -0
- package/dist/commands/execute/worktree-lookup.d.mts +1 -0
- package/{src → dist}/commands/execute/worktree-lookup.mjs +38 -37
- package/dist/commands/execute/worktree-lookup.mjs.map +1 -0
- package/dist/commands/execute/worktree-status.d.mts +1 -0
- package/{src → dist}/commands/execute/worktree-status.mjs +52 -46
- package/dist/commands/execute/worktree-status.mjs.map +1 -0
- package/dist/commands/inspect/code-review.d.mts +1 -0
- package/{src → dist}/commands/inspect/code-review.mjs +16 -19
- package/dist/commands/inspect/code-review.mjs.map +1 -0
- package/dist/commands/inspect/container.d.mts +1 -0
- package/{src → dist}/commands/inspect/container.mjs +11 -13
- package/dist/commands/inspect/container.mjs.map +1 -0
- package/dist/commands/inspect/context-cost.d.mts +1 -0
- package/{src → dist}/commands/inspect/context-cost.mjs +11 -13
- package/dist/commands/inspect/context-cost.mjs.map +1 -0
- package/dist/commands/inspect/design-prep.d.mts +1 -0
- package/{src → dist}/commands/inspect/design-prep.mjs +10 -11
- package/dist/commands/inspect/design-prep.mjs.map +1 -0
- package/dist/commands/inspect/error-report.d.mts +1 -0
- package/{src → dist}/commands/inspect/error-report.mjs +11 -13
- package/dist/commands/inspect/error-report.mjs.map +1 -0
- package/dist/commands/inspect/error-zip.d.mts +1 -0
- package/{src → dist}/commands/inspect/error-zip.mjs +11 -12
- package/dist/commands/inspect/error-zip.mjs.map +1 -0
- package/dist/commands/inspect/log-report.d.mts +1 -0
- package/{src → dist}/commands/inspect/log-report.mjs +11 -13
- package/dist/commands/inspect/log-report.mjs.map +1 -0
- package/dist/commands/inspect/profile-show.d.mts +1 -0
- package/{src → dist}/commands/inspect/profile-show.mjs +10 -11
- package/dist/commands/inspect/profile-show.mjs.map +1 -0
- package/dist/commands/inspect/recap.d.mts +1 -0
- package/{src → dist}/commands/inspect/recap.mjs +11 -13
- package/dist/commands/inspect/recap.mjs.map +1 -0
- package/dist/commands/inspect/resolve-task-key.d.mts +1 -0
- package/{src → dist}/commands/inspect/resolve-task-key.mjs +11 -13
- package/dist/commands/inspect/resolve-task-key.mjs.map +1 -0
- package/dist/commands/inspect/rollup.d.mts +1 -0
- package/{src → dist}/commands/inspect/rollup.mjs +11 -13
- package/dist/commands/inspect/rollup.mjs.map +1 -0
- package/dist/commands/inspect/run-audit.d.mts +1 -0
- package/{src → dist}/commands/inspect/run-audit.mjs +11 -12
- package/dist/commands/inspect/run-audit.mjs.map +1 -0
- package/dist/commands/inspect/set-work-status.d.mts +1 -0
- package/{src → dist}/commands/inspect/set-work-status.mjs +11 -13
- package/dist/commands/inspect/set-work-status.mjs.map +1 -0
- package/dist/commands/inspect/stage-map.d.mts +1 -0
- package/dist/commands/inspect/stage-map.mjs +110 -0
- package/dist/commands/inspect/stage-map.mjs.map +1 -0
- package/dist/commands/inspect/task-list.d.mts +1 -0
- package/dist/commands/inspect/task-list.mjs +103 -0
- package/dist/commands/inspect/task-list.mjs.map +1 -0
- package/dist/commands/inspect/task-show.d.mts +1 -0
- package/dist/commands/inspect/task-show.mjs +108 -0
- package/dist/commands/inspect/task-show.mjs.map +1 -0
- package/dist/commands/inspect/time-report.d.mts +1 -0
- package/{src → dist}/commands/inspect/time-report.mjs +11 -13
- package/dist/commands/inspect/time-report.mjs.map +1 -0
- package/dist/commands/inspect/usage-report.d.mts +1 -0
- package/{src → dist}/commands/inspect/usage-report.mjs +11 -13
- package/dist/commands/inspect/usage-report.mjs.map +1 -0
- package/dist/commands/inspect/user-response.d.mts +1 -0
- package/{src → dist}/commands/inspect/user-response.mjs +10 -11
- package/dist/commands/inspect/user-response.mjs.map +1 -0
- package/dist/commands/inspect/worker-liveness.d.mts +1 -0
- package/{src → dist}/commands/inspect/worker-liveness.mjs +11 -13
- package/dist/commands/inspect/worker-liveness.mjs.map +1 -0
- package/dist/commands/lifecycle/check-project.d.mts +21 -0
- package/dist/commands/lifecycle/check-project.mjs +175 -0
- package/dist/commands/lifecycle/check-project.mjs.map +1 -0
- package/dist/commands/lifecycle/config.d.mts +1 -0
- package/dist/commands/lifecycle/config.mjs +369 -0
- package/dist/commands/lifecycle/config.mjs.map +1 -0
- package/dist/commands/lifecycle/doctor.d.mts +10 -0
- package/dist/commands/lifecycle/doctor.mjs +317 -0
- package/dist/commands/lifecycle/doctor.mjs.map +1 -0
- package/dist/commands/lifecycle/install.d.mts +17 -0
- package/dist/commands/lifecycle/install.mjs +1077 -0
- package/dist/commands/lifecycle/install.mjs.map +1 -0
- package/dist/commands/lifecycle/migrate.d.mts +1 -0
- package/{src → dist}/commands/lifecycle/migrate.mjs +10 -11
- package/dist/commands/lifecycle/migrate.mjs.map +1 -0
- package/dist/commands/lifecycle/model.d.mts +1 -0
- package/dist/commands/lifecycle/model.mjs +22 -0
- package/dist/commands/lifecycle/model.mjs.map +1 -0
- package/dist/commands/lifecycle/paths.d.mts +1 -0
- package/dist/commands/lifecycle/paths.mjs +102 -0
- package/dist/commands/lifecycle/paths.mjs.map +1 -0
- package/dist/commands/lifecycle/preflight.d.mts +1 -0
- package/dist/commands/lifecycle/preflight.mjs +124 -0
- package/dist/commands/lifecycle/preflight.mjs.map +1 -0
- package/dist/commands/lifecycle/setup.d.mts +1 -0
- package/dist/commands/lifecycle/setup.mjs +297 -0
- package/dist/commands/lifecycle/setup.mjs.map +1 -0
- package/dist/commands/lifecycle/uninstall.d.mts +4 -0
- package/dist/commands/lifecycle/uninstall.mjs +262 -0
- package/dist/commands/lifecycle/uninstall.mjs.map +1 -0
- package/dist/commands/manager.d.mts +3 -0
- package/{src → dist}/commands/manager.mjs +25 -32
- package/dist/commands/manager.mjs.map +1 -0
- package/dist/commands/memory/memory.d.mts +1 -0
- package/dist/commands/memory/memory.mjs +569 -0
- package/dist/commands/memory/memory.mjs.map +1 -0
- package/dist/commands/pr/pr.d.mts +33 -0
- package/dist/commands/pr/pr.mjs +296 -0
- package/dist/commands/pr/pr.mjs.map +1 -0
- package/dist/commands/report/agent-activity.d.mts +1 -0
- package/{src → dist}/commands/report/agent-activity.mjs +11 -12
- package/dist/commands/report/agent-activity.mjs.map +1 -0
- package/dist/commands/report/finalize.d.mts +4 -0
- package/{src → dist}/commands/report/finalize.mjs +25 -32
- package/dist/commands/report/finalize.mjs.map +1 -0
- package/dist/commands/report/inject-report-index.d.mts +1 -0
- package/{src → dist}/commands/report/inject-report-index.mjs +6 -7
- package/dist/commands/report/inject-report-index.mjs.map +1 -0
- package/dist/commands/report/render-final-report.d.mts +1 -0
- package/{src → dist}/commands/report/render-final-report.mjs +6 -7
- package/dist/commands/report/render-final-report.mjs.map +1 -0
- package/dist/commands/report/render-views.d.mts +1 -0
- package/{src → dist}/commands/report/render-views.mjs +6 -7
- package/dist/commands/report/render-views.mjs.map +1 -0
- package/dist/commands/report/translate.d.mts +1 -0
- package/{src → dist}/commands/report/translate.mjs +6 -7
- package/dist/commands/report/translate.mjs.map +1 -0
- package/dist/lib/helper-scripts.d.mts +3 -0
- package/{src → dist}/lib/helper-scripts.mjs +11 -14
- package/dist/lib/helper-scripts.mjs.map +1 -0
- package/dist/lib/host-registry-client.d.mts +25 -0
- package/dist/lib/host-registry-client.mjs +152 -0
- package/dist/lib/host-registry-client.mjs.map +1 -0
- package/dist/lib/install-assets.d.mts +8 -0
- package/{src → dist}/lib/install-assets.mjs +17 -20
- package/dist/lib/install-assets.mjs.map +1 -0
- package/dist/lib/okstra-dirs.d.mts +4 -0
- package/{src → dist}/lib/okstra-dirs.mjs +3 -6
- package/dist/lib/okstra-dirs.mjs.map +1 -0
- package/dist/lib/paths.d.mts +4 -0
- package/dist/lib/paths.mjs +78 -0
- package/dist/lib/paths.mjs.map +1 -0
- package/dist/lib/proc.d.mts +3 -0
- package/dist/lib/proc.mjs +31 -0
- package/dist/lib/proc.mjs.map +1 -0
- package/dist/lib/python-helper.d.mts +8 -0
- package/dist/lib/python-helper.mjs +123 -0
- package/dist/lib/python-helper.mjs.map +1 -0
- package/dist/lib/runtime-manifest.d.mts +7 -0
- package/dist/lib/runtime-manifest.mjs +73 -0
- package/dist/lib/runtime-manifest.mjs.map +1 -0
- package/dist/lib/skill-catalog.d.mts +4 -0
- package/dist/lib/skill-catalog.mjs +50 -0
- package/dist/lib/skill-catalog.mjs.map +1 -0
- package/dist/lib/types.d.mts +129 -0
- package/dist/lib/types.mjs +2 -0
- package/dist/lib/types.mjs.map +1 -0
- package/dist/lib/version.d.mts +2 -0
- package/dist/lib/version.mjs +27 -0
- package/dist/lib/version.mjs.map +1 -0
- package/docs/architecture/storage-model.md +4 -0
- package/docs/architecture.md +7 -1
- package/docs/cli.md +26 -6
- package/docs/contributor-change-matrix.md +2 -2
- package/docs/project-structure-overview.md +16 -7
- package/docs/task-process/README.md +2 -0
- package/docs/task-process/implementation-planning.md +1 -1
- package/docs/task-process/implementation.md +1 -1
- package/package.json +11 -5
- package/runtime/BUILD.json +2 -2
- package/runtime/agents/workers/claude-worker.md +2 -1
- package/runtime/agents/workers/report-writer-worker.md +3 -1
- package/runtime/agents/workers/translator-worker.md +3 -1
- package/runtime/bin/lib/okstra/cli.sh +12 -0
- package/runtime/bin/lib/okstra/globals.sh +3 -0
- package/runtime/bin/lib/okstra/usage.sh +4 -4
- package/runtime/bin/okstra-error-log.py +27 -0
- package/runtime/bin/okstra-provider-exec.py +217 -5
- package/runtime/bin/okstra.sh +10 -0
- package/runtime/prompts/lead/convergence.md +27 -18
- package/runtime/prompts/lead/okstra-lead-contract.md +3 -1
- package/runtime/prompts/lead/plan-body-verification.md +10 -3
- package/runtime/prompts/lead/team-contract.md +1 -1
- package/runtime/prompts/profiles/change-impact-analysis.md +16 -0
- package/runtime/prompts/profiles/error-analysis.md +20 -0
- package/runtime/prompts/profiles/feature-analysis.md +16 -0
- package/runtime/prompts/profiles/final-verification.md +16 -0
- package/runtime/prompts/profiles/implementation-option-selection.md +16 -0
- package/runtime/prompts/profiles/implementation-planning.md +20 -0
- package/runtime/prompts/profiles/implementation.md +15 -0
- package/runtime/prompts/profiles/improvement-discovery.md +16 -0
- package/runtime/prompts/profiles/project-analysis.md +16 -0
- package/runtime/prompts/profiles/release-handoff.md +4 -0
- package/runtime/prompts/profiles/requirements-discovery.md +20 -0
- package/runtime/prompts/wizard/prompts.ko.json +18 -0
- package/runtime/python/okstra_ctl/adapters/dispatch/cli_wrapper.py +8 -0
- package/runtime/python/okstra_ctl/adapters/dispatch/cmux.py +8 -0
- package/runtime/python/okstra_ctl/adapters/dispatch/native_team.py +13 -0
- package/runtime/python/okstra_ctl/adapters/hosts/antigravity/adapter.py +2 -2
- package/runtime/python/okstra_ctl/adapters/hosts/claude-code/adapter.py +25 -5
- package/runtime/python/okstra_ctl/adapters/hosts/codex/adapter.py +2 -2
- package/runtime/python/okstra_ctl/adapters/hosts/external/adapter.py +4 -1
- package/runtime/python/okstra_ctl/adapters/hosts/grok/adapter.py +2 -2
- package/runtime/python/okstra_ctl/adapters/hosts/kimi/adapter.py +2 -2
- package/runtime/python/okstra_ctl/adapters/providers/antigravity/adapter.py +79 -11
- package/runtime/python/okstra_ctl/adapters/providers/claude/adapter.py +95 -25
- package/runtime/python/okstra_ctl/adapters/providers/codex/adapter.py +59 -14
- package/runtime/python/okstra_ctl/adapters/providers/grok/adapter.py +55 -9
- package/runtime/python/okstra_ctl/adapters/providers/kimi/adapter.py +51 -12
- package/runtime/python/okstra_ctl/agent_activity.py +5 -1
- package/runtime/python/okstra_ctl/agent_invocation.py +608 -14
- package/runtime/python/okstra_ctl/agent_prompt_cli.py +249 -50
- package/runtime/python/okstra_ctl/application/resolve_assignment.py +53 -12
- package/runtime/python/okstra_ctl/assignment_environment.py +102 -0
- package/runtime/python/okstra_ctl/assignment_resolver.py +790 -0
- package/runtime/python/okstra_ctl/attempt_evidence.py +342 -0
- package/runtime/python/okstra_ctl/convergence.py +409 -3
- package/runtime/python/okstra_ctl/convergence_engine.py +248 -15
- package/runtime/python/okstra_ctl/convergence_store.py +170 -1
- package/runtime/python/okstra_ctl/dispatch_core.py +1092 -63
- package/runtime/python/okstra_ctl/dispatch_state.py +696 -11
- package/runtime/python/okstra_ctl/doctor.py +14 -0
- package/runtime/python/okstra_ctl/domain/host.py +32 -1
- package/runtime/python/okstra_ctl/domain/provider.py +212 -6
- package/runtime/python/okstra_ctl/domain/role.py +125 -0
- package/runtime/python/okstra_ctl/domain/wizard/interaction.py +13 -0
- package/runtime/python/okstra_ctl/domain/worker_exec.py +34 -1
- package/runtime/python/okstra_ctl/domain/worker_role.py +13 -3
- package/runtime/python/okstra_ctl/domain/worker_stream.py +24 -0
- package/runtime/python/okstra_ctl/error_log_write.py +9 -0
- package/runtime/python/okstra_ctl/error_report.py +21 -1
- package/runtime/python/okstra_ctl/execution_identity.py +529 -0
- package/runtime/python/okstra_ctl/execution_manifest.py +1281 -0
- package/runtime/python/okstra_ctl/execution_mutation_audit.py +619 -0
- package/runtime/python/okstra_ctl/index.py +6 -2
- package/runtime/python/okstra_ctl/initial_prompt_materialization.py +43 -3
- package/runtime/python/okstra_ctl/legacy_model_selection.py +490 -0
- package/runtime/python/okstra_ctl/model_cli.py +278 -0
- package/runtime/python/okstra_ctl/model_defaults.py +46 -0
- package/runtime/python/okstra_ctl/model_discovery.py +26 -7
- package/runtime/python/okstra_ctl/model_pool.py +501 -0
- package/runtime/python/okstra_ctl/models.py +47 -27
- package/runtime/python/okstra_ctl/mutation_recovery.py +293 -0
- package/runtime/python/okstra_ctl/pane_title.py +151 -0
- package/runtime/python/okstra_ctl/ports/host_model.py +48 -17
- package/runtime/python/okstra_ctl/ports/worker_dispatch.py +4 -0
- package/runtime/python/okstra_ctl/registry/provider_registry.py +8 -4
- package/runtime/python/okstra_ctl/render.py +78 -10
- package/runtime/python/okstra_ctl/render_final_report.py +19 -0
- package/runtime/python/okstra_ctl/report_contract.py +39 -0
- package/runtime/python/okstra_ctl/report_finalize.py +16 -0
- package/runtime/python/okstra_ctl/report_html/render.py +1 -0
- package/runtime/python/okstra_ctl/role_requirements.py +217 -0
- package/runtime/python/okstra_ctl/run.py +1207 -258
- package/runtime/python/okstra_ctl/run_index_row.py +7 -1
- package/runtime/python/okstra_ctl/time_report.py +38 -4
- package/runtime/python/okstra_ctl/usage_identity.py +86 -0
- package/runtime/python/okstra_ctl/usage_report.py +15 -3
- package/runtime/python/okstra_ctl/wizard.py +1253 -62
- package/runtime/python/okstra_ctl/worker_audit_ledger.py +68 -65
- package/runtime/python/okstra_ctl/worker_request.py +7 -1
- package/runtime/python/okstra_ctl/worker_runner.py +130 -5
- package/runtime/python/okstra_ctl/workers.py +7 -5
- package/runtime/python/okstra_ctl/write_policy.py +571 -0
- package/runtime/schemas/convergence-groups-v2.0.schema.json +128 -0
- package/runtime/schemas/execution-manifest-v2.schema.json +340 -0
- package/runtime/schemas/final-report-v2.0.schema.json +25 -0
- package/runtime/skills/okstra-run/SKILL.md +9 -9
- package/runtime/templates/report-writer-prompt-preamble.md +2 -0
- package/runtime/templates/reports/final-report-v2.template.md +7 -1
- package/runtime/templates/reports/html/base.template.html +21 -0
- package/runtime/templates/reports/html/i18n/en.json +4 -0
- package/runtime/templates/reports/html/i18n/ko.json +4 -0
- package/runtime/templates/worker-prompt-preamble.md +6 -2
- package/runtime/validators/lib/fixtures.sh +49 -16
- package/runtime/validators/validate-run.py +429 -35
- package/runtime/validators/validate_session_conformance.py +25 -7
- package/src/cli-registry.mjs +0 -539
- package/src/commands/execute/codex-dispatch.mjs +0 -10
- package/src/commands/execute/plan-items.mjs +0 -9
- package/src/commands/execute/plan-validate.mjs +0 -68
- package/src/commands/execute/run.mjs +0 -208
- package/src/commands/execute/wizard.mjs +0 -167
- package/src/commands/inspect/stage-map.mjs +0 -98
- package/src/commands/inspect/task-list.mjs +0 -97
- package/src/commands/inspect/task-show.mjs +0 -100
- package/src/commands/lifecycle/check-project.mjs +0 -187
- package/src/commands/lifecycle/config.mjs +0 -385
- package/src/commands/lifecycle/doctor.mjs +0 -308
- package/src/commands/lifecycle/install.mjs +0 -1170
- package/src/commands/lifecycle/paths.mjs +0 -104
- package/src/commands/lifecycle/preflight.mjs +0 -125
- package/src/commands/lifecycle/setup.mjs +0 -333
- package/src/commands/lifecycle/uninstall.mjs +0 -279
- package/src/commands/memory/memory.mjs +0 -524
- package/src/commands/pr/pr.mjs +0 -261
- package/src/lib/host-registry-client.mjs +0 -176
- package/src/lib/paths.mjs +0 -86
- package/src/lib/proc.mjs +0 -31
- package/src/lib/python-helper.mjs +0 -142
- package/src/lib/runtime-manifest.mjs +0 -70
- package/src/lib/skill-catalog.mjs +0 -53
- package/src/lib/version.mjs +0 -20
- /package/{src → dist}/commands/pr/default.md +0 -0
|
@@ -20,6 +20,7 @@ imports this module directly.
|
|
|
20
20
|
from __future__ import annotations
|
|
21
21
|
|
|
22
22
|
import copy
|
|
23
|
+
import hashlib
|
|
23
24
|
import json
|
|
24
25
|
import math
|
|
25
26
|
import re
|
|
@@ -31,7 +32,16 @@ from typing import Any, Callable, Optional
|
|
|
31
32
|
|
|
32
33
|
from okstra_ctl.application.advance_wizard import plan_prompt
|
|
33
34
|
from okstra_ctl.application.resolve_assignment import resolve_lead_provider
|
|
35
|
+
from okstra_ctl.assignment_environment import load_assignment_context
|
|
36
|
+
from okstra_ctl.assignment_resolver import (
|
|
37
|
+
AssignmentContext,
|
|
38
|
+
AssignmentResolutionError,
|
|
39
|
+
RoleInstance,
|
|
40
|
+
resolve_assignments,
|
|
41
|
+
resolve_model_assignment,
|
|
42
|
+
)
|
|
34
43
|
from okstra_ctl.domain.host import (
|
|
44
|
+
CurrentSessionModelAttestation,
|
|
35
45
|
HostCapabilityMismatch,
|
|
36
46
|
HostNotRegistered,
|
|
37
47
|
HostSessionContext,
|
|
@@ -44,8 +54,18 @@ from okstra_ctl.domain.wizard.interaction import (
|
|
|
44
54
|
WizardPrompt,
|
|
45
55
|
normalize_planned_answer,
|
|
46
56
|
)
|
|
57
|
+
from okstra_ctl.dispatch_state import detect_terminal_backend
|
|
47
58
|
from okstra_ctl.registry.host_registry import default_host_registry
|
|
48
59
|
from okstra_ctl.registry.provider_registry import default_provider_registry
|
|
60
|
+
from okstra_ctl.model_defaults import ModelDefaultScopes, default_candidates
|
|
61
|
+
from okstra_ctl.model_pool import ModelPool
|
|
62
|
+
from okstra_ctl.legacy_model_selection import serialize_host_session_context
|
|
63
|
+
from okstra_ctl.role_requirements import (
|
|
64
|
+
RoleProfile,
|
|
65
|
+
RoleProfileError,
|
|
66
|
+
RoleRequirement,
|
|
67
|
+
load_role_profile,
|
|
68
|
+
)
|
|
49
69
|
from okstra_ctl.ids import slugify_task_segment
|
|
50
70
|
from okstra_ctl.brief_frontmatter import read_brief_frontmatter
|
|
51
71
|
from okstra_ctl.analysis_inputs import (
|
|
@@ -72,6 +92,7 @@ from okstra_ctl.clarification_items import (
|
|
|
72
92
|
sidecar_answers,
|
|
73
93
|
user_response_sidecars,
|
|
74
94
|
)
|
|
95
|
+
from okstra_ctl.convergence_store import write_json_atomic
|
|
75
96
|
from okstra_ctl.incremental_scope import (
|
|
76
97
|
parse_stage_graph,
|
|
77
98
|
preview_link_availability_for_report,
|
|
@@ -96,8 +117,10 @@ from okstra_ctl.run import (
|
|
|
96
117
|
_apply_cli_implementation_option,
|
|
97
118
|
_extract_frontmatter_block,
|
|
98
119
|
_load_final_report_data_if_present,
|
|
120
|
+
_assignment_resolution_message,
|
|
99
121
|
_reject_blocking_plan_body_gate,
|
|
100
122
|
_set_data_json_approved_true_if_present,
|
|
123
|
+
_model_default_scopes,
|
|
101
124
|
recommended_role_models,
|
|
102
125
|
)
|
|
103
126
|
from okstra_ctl.stage_map import (
|
|
@@ -406,6 +429,12 @@ _STEP_TO_GROUP: dict[str, str] = {
|
|
|
406
429
|
|
|
407
430
|
@dataclass
|
|
408
431
|
class WizardState:
|
|
432
|
+
# execution identity v2: role-first canonical model selections
|
|
433
|
+
execution_identity_version: int = 1
|
|
434
|
+
role_counts: dict[str, int] = field(default_factory=dict)
|
|
435
|
+
role_models: dict[str, list[str]] = field(default_factory=dict)
|
|
436
|
+
role_selection_order: list[str] = field(default_factory=list)
|
|
437
|
+
|
|
409
438
|
# bootstrap
|
|
410
439
|
workspace_root: str = ""
|
|
411
440
|
project_root: str = ""
|
|
@@ -524,11 +553,19 @@ class WizardState:
|
|
|
524
553
|
answered: list[str] = field(default_factory=list)
|
|
525
554
|
|
|
526
555
|
def to_json(self) -> dict[str, Any]:
|
|
527
|
-
|
|
556
|
+
payload = asdict(self)
|
|
557
|
+
payload.pop("execution_identity_version")
|
|
558
|
+
payload["executionIdentityVersion"] = 2
|
|
559
|
+
payload["roleCounts"] = payload.pop("role_counts")
|
|
560
|
+
payload["roleModels"] = payload.pop("role_models")
|
|
561
|
+
payload["roleSelectionOrder"] = payload.pop("role_selection_order")
|
|
562
|
+
for field_name in _V1_PROVIDER_STATE_FIELDS:
|
|
563
|
+
payload.pop(field_name, None)
|
|
564
|
+
return payload
|
|
528
565
|
|
|
529
566
|
@classmethod
|
|
530
567
|
def from_json(cls, d: dict[str, Any]) -> "WizardState":
|
|
531
|
-
return
|
|
568
|
+
return _wizard_state_from_json(d)
|
|
532
569
|
|
|
533
570
|
|
|
534
571
|
@dataclass
|
|
@@ -550,8 +587,14 @@ class Prompt:
|
|
|
550
587
|
# only meaningful when kind == "pick_group": one entry per AskUserQuestion tab
|
|
551
588
|
questions: list["Prompt"] = field(default_factory=list)
|
|
552
589
|
|
|
590
|
+
@property
|
|
591
|
+
def id(self) -> str:
|
|
592
|
+
"""Stable public identifier shared by static and role-instance prompts."""
|
|
593
|
+
return self.step
|
|
594
|
+
|
|
553
595
|
def to_json(self) -> dict[str, Any]:
|
|
554
596
|
out = {
|
|
597
|
+
"id": self.step,
|
|
555
598
|
"step": self.step,
|
|
556
599
|
"kind": self.kind,
|
|
557
600
|
"label": self.label,
|
|
@@ -959,6 +1002,829 @@ def _profile_path(workspace_root: Path, task_type: str) -> Path:
|
|
|
959
1002
|
return workspace_root / "prompts" / "profiles" / f"{task_type}.md"
|
|
960
1003
|
|
|
961
1004
|
|
|
1005
|
+
_V2_STATE_FIELDS = (
|
|
1006
|
+
"roleCounts",
|
|
1007
|
+
"roleModels",
|
|
1008
|
+
"roleSelectionOrder",
|
|
1009
|
+
)
|
|
1010
|
+
_V1_PROVIDER_STATE_FIELDS = (
|
|
1011
|
+
"workers_override",
|
|
1012
|
+
"lead_provider",
|
|
1013
|
+
"lead_model",
|
|
1014
|
+
"claude_model",
|
|
1015
|
+
"codex_model",
|
|
1016
|
+
"antigravity_model",
|
|
1017
|
+
"grok_model",
|
|
1018
|
+
"kimi_model",
|
|
1019
|
+
"report_writer_provider",
|
|
1020
|
+
"report_writer_model",
|
|
1021
|
+
"executor",
|
|
1022
|
+
"critic",
|
|
1023
|
+
)
|
|
1024
|
+
_V1_PROVIDER_STATE_JSON_FIELDS = frozenset({
|
|
1025
|
+
*_V1_PROVIDER_STATE_FIELDS,
|
|
1026
|
+
"workers",
|
|
1027
|
+
"leadProvider",
|
|
1028
|
+
"leadModel",
|
|
1029
|
+
"claudeModel",
|
|
1030
|
+
"codexModel",
|
|
1031
|
+
"antigravityModel",
|
|
1032
|
+
"grokModel",
|
|
1033
|
+
"kimiModel",
|
|
1034
|
+
"reportWriterProvider",
|
|
1035
|
+
"reportWriterModel",
|
|
1036
|
+
})
|
|
1037
|
+
|
|
1038
|
+
|
|
1039
|
+
def _load_role_profile_for_state(state: WizardState) -> RoleProfile:
|
|
1040
|
+
try:
|
|
1041
|
+
return load_role_profile(
|
|
1042
|
+
_profile_path(Path(state.workspace_root), state.task_type)
|
|
1043
|
+
)
|
|
1044
|
+
except RoleProfileError as exc:
|
|
1045
|
+
raise WizardError(str(exc)) from exc
|
|
1046
|
+
|
|
1047
|
+
|
|
1048
|
+
def _role_selection_enabled(state: WizardState) -> bool:
|
|
1049
|
+
if (
|
|
1050
|
+
state.execution_identity_version != 2
|
|
1051
|
+
or not state.workspace_root
|
|
1052
|
+
or not state.task_type
|
|
1053
|
+
):
|
|
1054
|
+
return False
|
|
1055
|
+
try:
|
|
1056
|
+
load_role_profile(_profile_path(Path(state.workspace_root), state.task_type))
|
|
1057
|
+
except (OSError, RoleProfileError):
|
|
1058
|
+
return False
|
|
1059
|
+
return True
|
|
1060
|
+
|
|
1061
|
+
|
|
1062
|
+
def _legacy_value(payload: dict[str, Any], snake: str, camel: str) -> Any:
|
|
1063
|
+
return payload.get(snake, payload.get(camel, ""))
|
|
1064
|
+
|
|
1065
|
+
|
|
1066
|
+
def _legacy_model_ref(
|
|
1067
|
+
pool: ModelPool,
|
|
1068
|
+
provider: str,
|
|
1069
|
+
role: str,
|
|
1070
|
+
raw_model: Any,
|
|
1071
|
+
) -> str | None:
|
|
1072
|
+
provider_id = provider.strip().lower()
|
|
1073
|
+
if not provider_id:
|
|
1074
|
+
return None
|
|
1075
|
+
model_value = raw_model.strip() if isinstance(raw_model, str) else ""
|
|
1076
|
+
try:
|
|
1077
|
+
model = (
|
|
1078
|
+
pool.resolve_alias(provider_id, model_value)
|
|
1079
|
+
if model_value
|
|
1080
|
+
else pool.default_candidate(provider_id, role)
|
|
1081
|
+
)
|
|
1082
|
+
except (ValueError, RuntimeError):
|
|
1083
|
+
return None
|
|
1084
|
+
if model is None:
|
|
1085
|
+
return None
|
|
1086
|
+
availability = pool.availability(str(model.model_ref), role)
|
|
1087
|
+
return str(model.model_ref) if availability.available else None
|
|
1088
|
+
|
|
1089
|
+
|
|
1090
|
+
def _legacy_worker_providers(payload: dict[str, Any]) -> list[str]:
|
|
1091
|
+
raw = _legacy_value(payload, "workers_override", "workers")
|
|
1092
|
+
if isinstance(raw, list):
|
|
1093
|
+
values = raw
|
|
1094
|
+
elif isinstance(raw, str):
|
|
1095
|
+
values = raw.split(",")
|
|
1096
|
+
else:
|
|
1097
|
+
values = []
|
|
1098
|
+
return [
|
|
1099
|
+
value.strip().lower()
|
|
1100
|
+
for value in values
|
|
1101
|
+
if isinstance(value, str)
|
|
1102
|
+
and value.strip()
|
|
1103
|
+
and value.strip().lower() != "report-writer"
|
|
1104
|
+
]
|
|
1105
|
+
|
|
1106
|
+
|
|
1107
|
+
def _initial_cross_verification_requirement(
|
|
1108
|
+
profile: RoleProfile,
|
|
1109
|
+
) -> RoleRequirement | None:
|
|
1110
|
+
return next((
|
|
1111
|
+
requirement
|
|
1112
|
+
for requirement in profile.roles
|
|
1113
|
+
if not requirement.dynamic
|
|
1114
|
+
and requirement.role in {
|
|
1115
|
+
"analyser",
|
|
1116
|
+
"designer",
|
|
1117
|
+
"planner",
|
|
1118
|
+
"verifier",
|
|
1119
|
+
}
|
|
1120
|
+
), None)
|
|
1121
|
+
|
|
1122
|
+
|
|
1123
|
+
def _convert_v1_provider_selections(
|
|
1124
|
+
state: WizardState,
|
|
1125
|
+
payload: dict[str, Any],
|
|
1126
|
+
) -> None:
|
|
1127
|
+
if not _role_selection_enabled(state):
|
|
1128
|
+
return
|
|
1129
|
+
profile = _load_role_profile_for_state(state)
|
|
1130
|
+
pool = ModelPool.from_registry(default_provider_registry())
|
|
1131
|
+
cross_requirement = _initial_cross_verification_requirement(profile)
|
|
1132
|
+
providers = _legacy_worker_providers(payload)
|
|
1133
|
+
if cross_requirement is not None:
|
|
1134
|
+
selected_count = cross_requirement.count
|
|
1135
|
+
if providers and cross_requirement.optional_count > 0:
|
|
1136
|
+
maximum = cross_requirement.count + cross_requirement.optional_count
|
|
1137
|
+
selected_count = min(maximum, max(cross_requirement.count, len(providers)))
|
|
1138
|
+
if cross_requirement.optional_count > 0:
|
|
1139
|
+
state.role_counts[cross_requirement.role] = selected_count
|
|
1140
|
+
count_id = f"role-count:{cross_requirement.role}"
|
|
1141
|
+
state.role_selection_order.append(count_id)
|
|
1142
|
+
if not providers:
|
|
1143
|
+
providers = [
|
|
1144
|
+
model.provider_id
|
|
1145
|
+
for model in pool.default_candidates(cross_requirement.role)
|
|
1146
|
+
]
|
|
1147
|
+
for ordinal, provider in enumerate(providers[:selected_count], start=1):
|
|
1148
|
+
raw_model = _legacy_value(
|
|
1149
|
+
payload,
|
|
1150
|
+
f"{provider}_model",
|
|
1151
|
+
f"{provider}Model",
|
|
1152
|
+
)
|
|
1153
|
+
model_ref = _legacy_model_ref(
|
|
1154
|
+
pool,
|
|
1155
|
+
provider,
|
|
1156
|
+
cross_requirement.role,
|
|
1157
|
+
raw_model,
|
|
1158
|
+
)
|
|
1159
|
+
if model_ref is None:
|
|
1160
|
+
break
|
|
1161
|
+
state.role_models.setdefault(cross_requirement.role, []).append(model_ref)
|
|
1162
|
+
state.role_selection_order.append(
|
|
1163
|
+
f"role-model:{cross_requirement.role}:{ordinal}"
|
|
1164
|
+
)
|
|
1165
|
+
|
|
1166
|
+
provider_rows = (
|
|
1167
|
+
(
|
|
1168
|
+
"leader",
|
|
1169
|
+
_legacy_value(payload, "lead_provider", "leadProvider") or "claude",
|
|
1170
|
+
_legacy_value(payload, "lead_model", "leadModel"),
|
|
1171
|
+
),
|
|
1172
|
+
(
|
|
1173
|
+
"report-writer",
|
|
1174
|
+
_legacy_value(
|
|
1175
|
+
payload,
|
|
1176
|
+
"report_writer_provider",
|
|
1177
|
+
"reportWriterProvider",
|
|
1178
|
+
) or "claude",
|
|
1179
|
+
_legacy_value(
|
|
1180
|
+
payload,
|
|
1181
|
+
"report_writer_model",
|
|
1182
|
+
"reportWriterModel",
|
|
1183
|
+
),
|
|
1184
|
+
),
|
|
1185
|
+
(
|
|
1186
|
+
"implementer",
|
|
1187
|
+
_legacy_value(payload, "executor", "executor") or "claude",
|
|
1188
|
+
_legacy_value(
|
|
1189
|
+
payload,
|
|
1190
|
+
f"{_legacy_value(payload, 'executor', 'executor') or 'claude'}_model",
|
|
1191
|
+
f"{_legacy_value(payload, 'executor', 'executor') or 'claude'}Model",
|
|
1192
|
+
),
|
|
1193
|
+
),
|
|
1194
|
+
(
|
|
1195
|
+
"critic",
|
|
1196
|
+
_legacy_value(payload, "critic", "critic"),
|
|
1197
|
+
_legacy_value(
|
|
1198
|
+
payload,
|
|
1199
|
+
f"{_legacy_value(payload, 'critic', 'critic')}_model",
|
|
1200
|
+
f"{_legacy_value(payload, 'critic', 'critic')}Model",
|
|
1201
|
+
),
|
|
1202
|
+
),
|
|
1203
|
+
)
|
|
1204
|
+
static_roles = {
|
|
1205
|
+
requirement.role
|
|
1206
|
+
for requirement in profile.roles
|
|
1207
|
+
if not requirement.dynamic and requirement.count > 0
|
|
1208
|
+
}
|
|
1209
|
+
if state.host_entry_mode == "spawn-process":
|
|
1210
|
+
static_roles.add("leader")
|
|
1211
|
+
for role, provider, raw_model in provider_rows:
|
|
1212
|
+
if role not in static_roles or not isinstance(provider, str) or not provider:
|
|
1213
|
+
continue
|
|
1214
|
+
model_ref = _legacy_model_ref(pool, provider, role, raw_model)
|
|
1215
|
+
if model_ref is None:
|
|
1216
|
+
continue
|
|
1217
|
+
state.role_models[role] = [model_ref]
|
|
1218
|
+
state.role_selection_order.append(f"role-model:{role}:1")
|
|
1219
|
+
|
|
1220
|
+
|
|
1221
|
+
def _wizard_state_from_json(payload: dict[str, Any]) -> WizardState:
|
|
1222
|
+
if not isinstance(payload, dict):
|
|
1223
|
+
raise WizardError("wizard state must be a JSON object")
|
|
1224
|
+
data = dict(payload)
|
|
1225
|
+
version = data.pop("executionIdentityVersion", None)
|
|
1226
|
+
has_v2_fields = any(field_name in data for field_name in _V2_STATE_FIELDS)
|
|
1227
|
+
has_v1_fields = any(
|
|
1228
|
+
field_name in data for field_name in _V1_PROVIDER_STATE_JSON_FIELDS
|
|
1229
|
+
)
|
|
1230
|
+
if version == 2:
|
|
1231
|
+
if has_v1_fields or not all(field_name in data for field_name in _V2_STATE_FIELDS):
|
|
1232
|
+
raise WizardError("mixed wizard state versions are not allowed")
|
|
1233
|
+
data["role_counts"] = data.pop("roleCounts")
|
|
1234
|
+
data["role_models"] = data.pop("roleModels")
|
|
1235
|
+
data["role_selection_order"] = data.pop("roleSelectionOrder")
|
|
1236
|
+
data["execution_identity_version"] = 2
|
|
1237
|
+
_validate_v2_state_fields(data)
|
|
1238
|
+
elif version in (None, 1):
|
|
1239
|
+
if has_v2_fields:
|
|
1240
|
+
raise WizardError("mixed wizard state versions are not allowed")
|
|
1241
|
+
data.pop("execution_identity_version", None)
|
|
1242
|
+
else:
|
|
1243
|
+
raise WizardError(f"unsupported wizard state version: {version!r}")
|
|
1244
|
+
allowed = WizardState.__dataclass_fields__.keys()
|
|
1245
|
+
state = WizardState(**{key: value for key, value in data.items() if key in allowed})
|
|
1246
|
+
if version != 2:
|
|
1247
|
+
state.execution_identity_version = 2
|
|
1248
|
+
_convert_v1_provider_selections(state, payload)
|
|
1249
|
+
return state
|
|
1250
|
+
|
|
1251
|
+
|
|
1252
|
+
def _validate_v2_state_fields(data: dict[str, Any]) -> None:
|
|
1253
|
+
role_counts = data.get("role_counts")
|
|
1254
|
+
role_models = data.get("role_models")
|
|
1255
|
+
selection_order = data.get("role_selection_order")
|
|
1256
|
+
if not isinstance(role_counts, dict) or not all(
|
|
1257
|
+
isinstance(role, str)
|
|
1258
|
+
and isinstance(count, int)
|
|
1259
|
+
and not isinstance(count, bool)
|
|
1260
|
+
for role, count in role_counts.items()
|
|
1261
|
+
):
|
|
1262
|
+
raise WizardError("wizard state roleCounts must map roles to integers")
|
|
1263
|
+
if not isinstance(role_models, dict) or not all(
|
|
1264
|
+
isinstance(role, str)
|
|
1265
|
+
and isinstance(models, list)
|
|
1266
|
+
and all(isinstance(model_ref, str) for model_ref in models)
|
|
1267
|
+
for role, models in role_models.items()
|
|
1268
|
+
):
|
|
1269
|
+
raise WizardError("wizard state roleModels must map roles to modelRef arrays")
|
|
1270
|
+
if not isinstance(selection_order, list) or not all(
|
|
1271
|
+
isinstance(step_id, str) for step_id in selection_order
|
|
1272
|
+
):
|
|
1273
|
+
raise WizardError("wizard state roleSelectionOrder must be a string array")
|
|
1274
|
+
|
|
1275
|
+
|
|
1276
|
+
def _role_count_prompt_id(role: str) -> str:
|
|
1277
|
+
return f"role-count:{role}"
|
|
1278
|
+
|
|
1279
|
+
|
|
1280
|
+
def _role_model_prompt_id(role: str, ordinal: int) -> str:
|
|
1281
|
+
return f"role-model:{role}:{ordinal}"
|
|
1282
|
+
|
|
1283
|
+
|
|
1284
|
+
def _selected_role_count(
|
|
1285
|
+
state: WizardState,
|
|
1286
|
+
requirement: RoleRequirement,
|
|
1287
|
+
) -> int:
|
|
1288
|
+
if requirement.optional_count == 0:
|
|
1289
|
+
return requirement.count
|
|
1290
|
+
return state.role_counts.get(requirement.role, requirement.count)
|
|
1291
|
+
|
|
1292
|
+
|
|
1293
|
+
def _selectable_static_requirements(
|
|
1294
|
+
state: WizardState,
|
|
1295
|
+
profile: RoleProfile,
|
|
1296
|
+
) -> tuple[RoleRequirement, ...]:
|
|
1297
|
+
requirements: list[RoleRequirement] = []
|
|
1298
|
+
if state.host_entry_mode == "spawn-process":
|
|
1299
|
+
requirements.append(RoleRequirement("leader", 1, "lead"))
|
|
1300
|
+
requirements.extend(
|
|
1301
|
+
requirement
|
|
1302
|
+
for requirement in profile.roles
|
|
1303
|
+
if not requirement.dynamic
|
|
1304
|
+
and _selected_role_count(state, requirement) > 0
|
|
1305
|
+
)
|
|
1306
|
+
return tuple(requirements)
|
|
1307
|
+
|
|
1308
|
+
|
|
1309
|
+
def _count_prompt(
|
|
1310
|
+
state: WizardState,
|
|
1311
|
+
requirement: RoleRequirement,
|
|
1312
|
+
) -> Prompt:
|
|
1313
|
+
maximum = requirement.count + requirement.optional_count
|
|
1314
|
+
prompt = _p(
|
|
1315
|
+
state.workspace_root,
|
|
1316
|
+
"role_count",
|
|
1317
|
+
role=requirement.role,
|
|
1318
|
+
minimum=str(requirement.count),
|
|
1319
|
+
maximum=str(maximum),
|
|
1320
|
+
default=str(requirement.count),
|
|
1321
|
+
)
|
|
1322
|
+
return Prompt(
|
|
1323
|
+
step=_role_count_prompt_id(requirement.role),
|
|
1324
|
+
kind="pick",
|
|
1325
|
+
label=prompt["label"],
|
|
1326
|
+
options=[
|
|
1327
|
+
_opt(
|
|
1328
|
+
str(count),
|
|
1329
|
+
prompt["options"]["count"].format(
|
|
1330
|
+
count=count,
|
|
1331
|
+
default_suffix=(
|
|
1332
|
+
prompt["options"].get("default_suffix", "")
|
|
1333
|
+
if count == requirement.count
|
|
1334
|
+
else ""
|
|
1335
|
+
),
|
|
1336
|
+
),
|
|
1337
|
+
)
|
|
1338
|
+
for count in range(requirement.count, maximum + 1)
|
|
1339
|
+
],
|
|
1340
|
+
echo_template=prompt["echo_template"],
|
|
1341
|
+
)
|
|
1342
|
+
|
|
1343
|
+
|
|
1344
|
+
def _role_default_candidates(
|
|
1345
|
+
state: WizardState,
|
|
1346
|
+
role: str,
|
|
1347
|
+
pool: ModelPool,
|
|
1348
|
+
scopes: ModelDefaultScopes | None = None,
|
|
1349
|
+
) -> tuple[str, ...]:
|
|
1350
|
+
try:
|
|
1351
|
+
selected_scopes = scopes or _model_default_scopes(Path(state.project_root))
|
|
1352
|
+
scoped = default_candidates(role, selected_scopes)
|
|
1353
|
+
except (PrepareError, ValueError) as exc:
|
|
1354
|
+
raise WizardError(str(exc)) from exc
|
|
1355
|
+
if scoped:
|
|
1356
|
+
for model_ref in scoped:
|
|
1357
|
+
availability = pool.availability(
|
|
1358
|
+
model_ref,
|
|
1359
|
+
role,
|
|
1360
|
+
state.host_runtime,
|
|
1361
|
+
"new-session",
|
|
1362
|
+
)
|
|
1363
|
+
if not availability.available:
|
|
1364
|
+
raise WizardError(
|
|
1365
|
+
f"configured default model {model_ref!r} is unavailable for "
|
|
1366
|
+
f"role {role!r}: {availability.reason}"
|
|
1367
|
+
)
|
|
1368
|
+
return tuple(scoped)
|
|
1369
|
+
return tuple(
|
|
1370
|
+
str(model.model_ref) for model in pool.default_candidates(role)
|
|
1371
|
+
)
|
|
1372
|
+
|
|
1373
|
+
|
|
1374
|
+
def _role_model_options(
|
|
1375
|
+
state: WizardState,
|
|
1376
|
+
profile: RoleProfile,
|
|
1377
|
+
role: str,
|
|
1378
|
+
ordinal: int,
|
|
1379
|
+
context: AssignmentContext,
|
|
1380
|
+
scopes: ModelDefaultScopes,
|
|
1381
|
+
) -> list[Option]:
|
|
1382
|
+
pool = context.pool
|
|
1383
|
+
defaults = _role_default_candidates(state, role, pool, scopes)
|
|
1384
|
+
if defaults:
|
|
1385
|
+
offset = (ordinal - 1) % len(defaults)
|
|
1386
|
+
defaults = (*defaults[offset:], *defaults[:offset])
|
|
1387
|
+
candidate_refs = [
|
|
1388
|
+
*defaults,
|
|
1389
|
+
*(str(model.model_ref) for model in pool.list(role=role)),
|
|
1390
|
+
]
|
|
1391
|
+
ordered_refs = tuple(dict.fromkeys(candidate_refs))
|
|
1392
|
+
default_refs = frozenset(defaults)
|
|
1393
|
+
prompt = _p(
|
|
1394
|
+
state.workspace_root,
|
|
1395
|
+
"role_model",
|
|
1396
|
+
role=role,
|
|
1397
|
+
ordinal="1",
|
|
1398
|
+
count="1",
|
|
1399
|
+
)
|
|
1400
|
+
options: list[Option] = []
|
|
1401
|
+
for model_ref in ordered_refs:
|
|
1402
|
+
availability = pool.availability(
|
|
1403
|
+
model_ref,
|
|
1404
|
+
role,
|
|
1405
|
+
state.host_runtime,
|
|
1406
|
+
"new-session",
|
|
1407
|
+
)
|
|
1408
|
+
if not availability.available:
|
|
1409
|
+
continue
|
|
1410
|
+
candidate_models = {
|
|
1411
|
+
selected_role: tuple(models)
|
|
1412
|
+
for selected_role, models in state.role_models.items()
|
|
1413
|
+
}
|
|
1414
|
+
selected = list(candidate_models.get(role, ()))[: ordinal - 1]
|
|
1415
|
+
selected.append(model_ref)
|
|
1416
|
+
candidate_models[role] = tuple(selected)
|
|
1417
|
+
if not _role_selection_can_complete(
|
|
1418
|
+
state,
|
|
1419
|
+
profile,
|
|
1420
|
+
context,
|
|
1421
|
+
candidate_models,
|
|
1422
|
+
scopes,
|
|
1423
|
+
):
|
|
1424
|
+
continue
|
|
1425
|
+
model = pool.resolve(model_ref)
|
|
1426
|
+
options.append(_opt(
|
|
1427
|
+
model_ref,
|
|
1428
|
+
prompt["options"]["model"].format(
|
|
1429
|
+
model_ref=model_ref,
|
|
1430
|
+
display=model.display_name,
|
|
1431
|
+
default_suffix=(
|
|
1432
|
+
prompt["options"].get("default_suffix", "")
|
|
1433
|
+
if model_ref in default_refs
|
|
1434
|
+
else ""
|
|
1435
|
+
),
|
|
1436
|
+
),
|
|
1437
|
+
))
|
|
1438
|
+
if not options:
|
|
1439
|
+
_validate_role_selection_feasibility(state, profile, context, scopes)
|
|
1440
|
+
raise WizardError(f"role {role!r} has no executable model candidates")
|
|
1441
|
+
return options
|
|
1442
|
+
|
|
1443
|
+
|
|
1444
|
+
def _model_prompt(
|
|
1445
|
+
state: WizardState,
|
|
1446
|
+
profile: RoleProfile,
|
|
1447
|
+
requirement: RoleRequirement,
|
|
1448
|
+
ordinal: int,
|
|
1449
|
+
context: AssignmentContext,
|
|
1450
|
+
scopes: ModelDefaultScopes,
|
|
1451
|
+
) -> Prompt:
|
|
1452
|
+
prompt = _p(
|
|
1453
|
+
state.workspace_root,
|
|
1454
|
+
"role_model",
|
|
1455
|
+
role=requirement.role,
|
|
1456
|
+
ordinal=str(ordinal),
|
|
1457
|
+
count=str(_selected_role_count(state, requirement)),
|
|
1458
|
+
)
|
|
1459
|
+
return Prompt(
|
|
1460
|
+
step=_role_model_prompt_id(requirement.role, ordinal),
|
|
1461
|
+
kind="pick",
|
|
1462
|
+
label=prompt["label"],
|
|
1463
|
+
options=_role_model_options(
|
|
1464
|
+
state,
|
|
1465
|
+
profile,
|
|
1466
|
+
requirement.role,
|
|
1467
|
+
ordinal,
|
|
1468
|
+
context,
|
|
1469
|
+
scopes,
|
|
1470
|
+
),
|
|
1471
|
+
echo_template=prompt["echo_template"],
|
|
1472
|
+
)
|
|
1473
|
+
|
|
1474
|
+
|
|
1475
|
+
def _rewind_invalid_role_models(
|
|
1476
|
+
state: WizardState,
|
|
1477
|
+
requirements: tuple[RoleRequirement, ...],
|
|
1478
|
+
requirement_index: int,
|
|
1479
|
+
model_index: int,
|
|
1480
|
+
) -> None:
|
|
1481
|
+
requirement = requirements[requirement_index]
|
|
1482
|
+
del state.role_models[requirement.role][model_index:]
|
|
1483
|
+
invalid_ids: set[str] = set()
|
|
1484
|
+
for later_index, later_requirement in enumerate(
|
|
1485
|
+
requirements[requirement_index:],
|
|
1486
|
+
start=requirement_index,
|
|
1487
|
+
):
|
|
1488
|
+
first_ordinal = model_index + 1 if later_index == requirement_index else 1
|
|
1489
|
+
later_count = _selected_role_count(state, later_requirement)
|
|
1490
|
+
invalid_ids.update(
|
|
1491
|
+
_role_model_prompt_id(later_requirement.role, ordinal)
|
|
1492
|
+
for ordinal in range(first_ordinal, later_count + 1)
|
|
1493
|
+
)
|
|
1494
|
+
if later_index != requirement_index:
|
|
1495
|
+
state.role_models.pop(later_requirement.role, None)
|
|
1496
|
+
state.role_selection_order = [
|
|
1497
|
+
step_id for step_id in state.role_selection_order
|
|
1498
|
+
if step_id not in invalid_ids
|
|
1499
|
+
]
|
|
1500
|
+
state.answered = [
|
|
1501
|
+
step_id for step_id in state.answered if step_id not in invalid_ids
|
|
1502
|
+
]
|
|
1503
|
+
|
|
1504
|
+
|
|
1505
|
+
def _discard_invalid_previous_models(
|
|
1506
|
+
state: WizardState,
|
|
1507
|
+
profile: RoleProfile,
|
|
1508
|
+
requirements: tuple[RoleRequirement, ...],
|
|
1509
|
+
context: AssignmentContext,
|
|
1510
|
+
scopes: ModelDefaultScopes,
|
|
1511
|
+
) -> None:
|
|
1512
|
+
selected_models = {
|
|
1513
|
+
role: tuple(models) for role, models in state.role_models.items()
|
|
1514
|
+
}
|
|
1515
|
+
if _role_selection_error(
|
|
1516
|
+
state,
|
|
1517
|
+
profile,
|
|
1518
|
+
context,
|
|
1519
|
+
selected_models,
|
|
1520
|
+
scopes,
|
|
1521
|
+
) is None:
|
|
1522
|
+
return
|
|
1523
|
+
selected_prefix: dict[str, tuple[str, ...]] = {}
|
|
1524
|
+
for requirement_index, requirement in enumerate(requirements):
|
|
1525
|
+
count = _selected_role_count(state, requirement)
|
|
1526
|
+
selected = state.role_models.get(requirement.role, [])
|
|
1527
|
+
if len(selected) > count:
|
|
1528
|
+
raise WizardError(
|
|
1529
|
+
f"role {requirement.role!r} has {len(selected)} models for "
|
|
1530
|
+
f"{count} instances"
|
|
1531
|
+
)
|
|
1532
|
+
for index, model_ref in enumerate(selected):
|
|
1533
|
+
candidate_prefix = dict(selected_prefix)
|
|
1534
|
+
candidate_prefix[requirement.role] = tuple(selected[: index + 1])
|
|
1535
|
+
if _role_selection_can_complete(
|
|
1536
|
+
state,
|
|
1537
|
+
profile,
|
|
1538
|
+
context,
|
|
1539
|
+
candidate_prefix,
|
|
1540
|
+
scopes,
|
|
1541
|
+
):
|
|
1542
|
+
continue
|
|
1543
|
+
_rewind_invalid_role_models(
|
|
1544
|
+
state,
|
|
1545
|
+
requirements,
|
|
1546
|
+
requirement_index,
|
|
1547
|
+
index,
|
|
1548
|
+
)
|
|
1549
|
+
return
|
|
1550
|
+
if selected:
|
|
1551
|
+
selected_prefix[requirement.role] = tuple(selected)
|
|
1552
|
+
|
|
1553
|
+
|
|
1554
|
+
def _host_session_context(state: WizardState) -> HostSessionContext:
|
|
1555
|
+
native_provider = default_host_registry().resolve(
|
|
1556
|
+
state.host_runtime
|
|
1557
|
+
).descriptor.native_provider_id
|
|
1558
|
+
return HostSessionContext(
|
|
1559
|
+
host_id=state.host_runtime,
|
|
1560
|
+
entry_mode=state.host_entry_mode,
|
|
1561
|
+
available_functions=frozenset(state.available_functions),
|
|
1562
|
+
interaction_surface="wizard",
|
|
1563
|
+
current_model=CurrentSessionModelAttestation.unknown(native_provider),
|
|
1564
|
+
)
|
|
1565
|
+
|
|
1566
|
+
|
|
1567
|
+
def _role_selection_error(
|
|
1568
|
+
state: WizardState,
|
|
1569
|
+
profile: RoleProfile,
|
|
1570
|
+
context: AssignmentContext,
|
|
1571
|
+
role_models: dict[str, tuple[str, ...]],
|
|
1572
|
+
scopes: ModelDefaultScopes,
|
|
1573
|
+
) -> str | None:
|
|
1574
|
+
try:
|
|
1575
|
+
resolve_assignments(
|
|
1576
|
+
profile=profile,
|
|
1577
|
+
role_counts=dict(state.role_counts),
|
|
1578
|
+
role_models=role_models,
|
|
1579
|
+
scopes=scopes,
|
|
1580
|
+
pool=context.pool,
|
|
1581
|
+
host=_host_session_context(state),
|
|
1582
|
+
environment=context.environment,
|
|
1583
|
+
)
|
|
1584
|
+
except AssignmentResolutionError as exc:
|
|
1585
|
+
return _assignment_resolution_message(exc)
|
|
1586
|
+
except (PrepareError, ValueError, RuntimeError) as exc:
|
|
1587
|
+
return str(exc)
|
|
1588
|
+
return None
|
|
1589
|
+
|
|
1590
|
+
|
|
1591
|
+
def _executable_role_models(
|
|
1592
|
+
state: WizardState,
|
|
1593
|
+
profile: RoleProfile,
|
|
1594
|
+
requirement: RoleRequirement,
|
|
1595
|
+
context: AssignmentContext,
|
|
1596
|
+
) -> tuple[str, ...]:
|
|
1597
|
+
host = _host_session_context(state)
|
|
1598
|
+
candidates: list[str] = []
|
|
1599
|
+
instance = RoleInstance(requirement.role, requirement.duty, 1)
|
|
1600
|
+
for model in context.pool.list(role=requirement.role):
|
|
1601
|
+
model_ref = str(model.model_ref)
|
|
1602
|
+
try:
|
|
1603
|
+
resolve_model_assignment(
|
|
1604
|
+
instance=instance,
|
|
1605
|
+
model_ref=model_ref,
|
|
1606
|
+
pool=context.pool,
|
|
1607
|
+
host=host,
|
|
1608
|
+
environment=context.environment,
|
|
1609
|
+
)
|
|
1610
|
+
except (AssignmentResolutionError, ValueError, RuntimeError):
|
|
1611
|
+
continue
|
|
1612
|
+
candidates.append(model_ref)
|
|
1613
|
+
return tuple(candidates)
|
|
1614
|
+
|
|
1615
|
+
|
|
1616
|
+
def _completed_role_models(
|
|
1617
|
+
state: WizardState,
|
|
1618
|
+
profile: RoleProfile,
|
|
1619
|
+
context: AssignmentContext,
|
|
1620
|
+
role_models: dict[str, tuple[str, ...]],
|
|
1621
|
+
) -> dict[str, tuple[str, ...]] | None:
|
|
1622
|
+
completed = {role: list(models) for role, models in role_models.items()}
|
|
1623
|
+
for requirement in _selectable_static_requirements(state, profile):
|
|
1624
|
+
count = _selected_role_count(state, requirement)
|
|
1625
|
+
selected = completed.setdefault(requirement.role, [])
|
|
1626
|
+
if len(selected) > count:
|
|
1627
|
+
return None
|
|
1628
|
+
candidates = _executable_role_models(state, profile, requirement, context)
|
|
1629
|
+
if not candidates or any(model not in candidates for model in selected):
|
|
1630
|
+
return None
|
|
1631
|
+
providers = {
|
|
1632
|
+
context.pool.resolve(model).provider_id
|
|
1633
|
+
for model in selected[:requirement.count]
|
|
1634
|
+
}
|
|
1635
|
+
required = requirement.min_distinct_providers or 0
|
|
1636
|
+
available_providers = {
|
|
1637
|
+
context.pool.resolve(model).provider_id for model in candidates
|
|
1638
|
+
}
|
|
1639
|
+
required_slots = max(0, requirement.count - len(selected))
|
|
1640
|
+
possible = len(providers | available_providers)
|
|
1641
|
+
if min(possible, len(providers) + required_slots) < required:
|
|
1642
|
+
return None
|
|
1643
|
+
while len(selected) < count:
|
|
1644
|
+
ordinal = len(selected) + 1
|
|
1645
|
+
model_ref = candidates[0]
|
|
1646
|
+
if ordinal <= requirement.count and len(providers) < required:
|
|
1647
|
+
model_ref = next(
|
|
1648
|
+
model
|
|
1649
|
+
for model in candidates
|
|
1650
|
+
if context.pool.resolve(model).provider_id not in providers
|
|
1651
|
+
)
|
|
1652
|
+
selected.append(model_ref)
|
|
1653
|
+
if ordinal <= requirement.count:
|
|
1654
|
+
providers.add(context.pool.resolve(model_ref).provider_id)
|
|
1655
|
+
return {role: tuple(models) for role, models in completed.items()}
|
|
1656
|
+
|
|
1657
|
+
|
|
1658
|
+
def _role_selection_can_complete(
|
|
1659
|
+
state: WizardState,
|
|
1660
|
+
profile: RoleProfile,
|
|
1661
|
+
context: AssignmentContext,
|
|
1662
|
+
role_models: dict[str, tuple[str, ...]],
|
|
1663
|
+
scopes: ModelDefaultScopes,
|
|
1664
|
+
) -> bool:
|
|
1665
|
+
completed = _completed_role_models(state, profile, context, role_models)
|
|
1666
|
+
return completed is not None and _role_selection_error(
|
|
1667
|
+
state,
|
|
1668
|
+
profile,
|
|
1669
|
+
context,
|
|
1670
|
+
completed,
|
|
1671
|
+
scopes,
|
|
1672
|
+
) is None
|
|
1673
|
+
|
|
1674
|
+
|
|
1675
|
+
def _validate_role_selection_feasibility(
|
|
1676
|
+
state: WizardState,
|
|
1677
|
+
profile: RoleProfile,
|
|
1678
|
+
context: AssignmentContext | None = None,
|
|
1679
|
+
scopes: ModelDefaultScopes | None = None,
|
|
1680
|
+
) -> None:
|
|
1681
|
+
assignment_context = context or load_assignment_context(
|
|
1682
|
+
host_runtime=state.host_runtime,
|
|
1683
|
+
terminal_backend=detect_terminal_backend(),
|
|
1684
|
+
)
|
|
1685
|
+
selected_scopes = scopes or _model_default_scopes(Path(state.project_root))
|
|
1686
|
+
error = _role_selection_error(
|
|
1687
|
+
state,
|
|
1688
|
+
profile,
|
|
1689
|
+
assignment_context,
|
|
1690
|
+
{
|
|
1691
|
+
role: tuple(models) for role, models in state.role_models.items()
|
|
1692
|
+
},
|
|
1693
|
+
selected_scopes,
|
|
1694
|
+
)
|
|
1695
|
+
if error is not None:
|
|
1696
|
+
raise WizardError(error)
|
|
1697
|
+
|
|
1698
|
+
|
|
1699
|
+
def next_role_prompt(state: WizardState) -> Prompt | None:
|
|
1700
|
+
"""Ask every adjustable count before one model question per role instance."""
|
|
1701
|
+
if not _role_selection_enabled(state) or not _identity_ready(state):
|
|
1702
|
+
return None
|
|
1703
|
+
state.use_defaults = False
|
|
1704
|
+
profile = _load_role_profile_for_state(state)
|
|
1705
|
+
for requirement in profile.roles:
|
|
1706
|
+
if requirement.dynamic or requirement.optional_count == 0:
|
|
1707
|
+
continue
|
|
1708
|
+
if requirement.role not in state.role_counts:
|
|
1709
|
+
return _count_prompt(state, requirement)
|
|
1710
|
+
count = state.role_counts[requirement.role]
|
|
1711
|
+
maximum = requirement.count + requirement.optional_count
|
|
1712
|
+
if count < requirement.count or count > maximum:
|
|
1713
|
+
raise WizardError(
|
|
1714
|
+
f"role {requirement.role!r} count must be in "
|
|
1715
|
+
f"{requirement.count}..{maximum}: {count}"
|
|
1716
|
+
)
|
|
1717
|
+
requirements = _selectable_static_requirements(state, profile)
|
|
1718
|
+
try:
|
|
1719
|
+
scopes = _model_default_scopes(Path(state.project_root))
|
|
1720
|
+
except (PrepareError, ValueError) as exc:
|
|
1721
|
+
raise WizardError(str(exc)) from exc
|
|
1722
|
+
context = load_assignment_context(
|
|
1723
|
+
host_runtime=state.host_runtime,
|
|
1724
|
+
terminal_backend=detect_terminal_backend(),
|
|
1725
|
+
)
|
|
1726
|
+
_discard_invalid_previous_models(
|
|
1727
|
+
state,
|
|
1728
|
+
profile,
|
|
1729
|
+
requirements,
|
|
1730
|
+
context,
|
|
1731
|
+
scopes,
|
|
1732
|
+
)
|
|
1733
|
+
for requirement in requirements:
|
|
1734
|
+
count = _selected_role_count(state, requirement)
|
|
1735
|
+
selected = state.role_models.get(requirement.role, [])
|
|
1736
|
+
if len(selected) < count:
|
|
1737
|
+
return _model_prompt(
|
|
1738
|
+
state,
|
|
1739
|
+
profile,
|
|
1740
|
+
requirement,
|
|
1741
|
+
len(selected) + 1,
|
|
1742
|
+
context,
|
|
1743
|
+
scopes,
|
|
1744
|
+
)
|
|
1745
|
+
_validate_role_selection_feasibility(state, profile, context, scopes)
|
|
1746
|
+
return None
|
|
1747
|
+
|
|
1748
|
+
|
|
1749
|
+
def _validate_submitted_role_model(
|
|
1750
|
+
state: WizardState,
|
|
1751
|
+
profile: RoleProfile,
|
|
1752
|
+
) -> None:
|
|
1753
|
+
try:
|
|
1754
|
+
scopes = _model_default_scopes(Path(state.project_root))
|
|
1755
|
+
except (PrepareError, ValueError) as exc:
|
|
1756
|
+
raise WizardError(str(exc)) from exc
|
|
1757
|
+
context = load_assignment_context(
|
|
1758
|
+
host_runtime=state.host_runtime,
|
|
1759
|
+
terminal_backend=detect_terminal_backend(),
|
|
1760
|
+
)
|
|
1761
|
+
role_models = {
|
|
1762
|
+
role: tuple(models) for role, models in state.role_models.items()
|
|
1763
|
+
}
|
|
1764
|
+
requirements = _selectable_static_requirements(state, profile)
|
|
1765
|
+
complete = all(
|
|
1766
|
+
len(role_models.get(requirement.role, ()))
|
|
1767
|
+
== _selected_role_count(state, requirement)
|
|
1768
|
+
for requirement in requirements
|
|
1769
|
+
)
|
|
1770
|
+
if complete:
|
|
1771
|
+
_validate_role_selection_feasibility(state, profile, context, scopes)
|
|
1772
|
+
return
|
|
1773
|
+
if not _role_selection_can_complete(
|
|
1774
|
+
state,
|
|
1775
|
+
profile,
|
|
1776
|
+
context,
|
|
1777
|
+
role_models,
|
|
1778
|
+
scopes,
|
|
1779
|
+
):
|
|
1780
|
+
raise WizardError("selected role model leaves no complete role assignment")
|
|
1781
|
+
|
|
1782
|
+
|
|
1783
|
+
def _submit_role_prompt(state: WizardState, prompt: Prompt, value: str) -> str:
|
|
1784
|
+
if prompt.step.startswith("role-count:"):
|
|
1785
|
+
role = prompt.step.split(":", 1)[1]
|
|
1786
|
+
profile = _load_role_profile_for_state(state)
|
|
1787
|
+
requirement = next(
|
|
1788
|
+
(row for row in profile.roles if row.role == role),
|
|
1789
|
+
None,
|
|
1790
|
+
)
|
|
1791
|
+
if requirement is None or requirement.dynamic or requirement.optional_count == 0:
|
|
1792
|
+
raise WizardError(f"role {role!r} does not accept a count selection")
|
|
1793
|
+
try:
|
|
1794
|
+
count = int(value)
|
|
1795
|
+
except ValueError as exc:
|
|
1796
|
+
raise WizardError(f"role {role!r} count must be an integer") from exc
|
|
1797
|
+
maximum = requirement.count + requirement.optional_count
|
|
1798
|
+
if count < requirement.count or count > maximum:
|
|
1799
|
+
raise WizardError(
|
|
1800
|
+
f"role {role!r} count must be in "
|
|
1801
|
+
f"{requirement.count}..{maximum}: {count}"
|
|
1802
|
+
)
|
|
1803
|
+
state.role_counts[role] = count
|
|
1804
|
+
state.role_models.pop(role, None)
|
|
1805
|
+
return f"role-count: {role}={count}"
|
|
1806
|
+
_, role, ordinal_raw = prompt.step.split(":", 2)
|
|
1807
|
+
ordinal = int(ordinal_raw)
|
|
1808
|
+
allowed = {option.value for option in prompt.options}
|
|
1809
|
+
if value not in allowed:
|
|
1810
|
+
raise WizardError(
|
|
1811
|
+
f"model {value!r} is not a compatible candidate for role {role!r}"
|
|
1812
|
+
)
|
|
1813
|
+
selected = state.role_models.setdefault(role, [])
|
|
1814
|
+
if ordinal != len(selected) + 1:
|
|
1815
|
+
raise WizardError(
|
|
1816
|
+
f"role {role!r} model selection is out of order at ordinal {ordinal}"
|
|
1817
|
+
)
|
|
1818
|
+
selected.append(value)
|
|
1819
|
+
try:
|
|
1820
|
+
profile = _load_role_profile_for_state(state)
|
|
1821
|
+
_validate_submitted_role_model(state, profile)
|
|
1822
|
+
except WizardError:
|
|
1823
|
+
selected.pop()
|
|
1824
|
+
raise
|
|
1825
|
+
return f"role-model: {role}#{ordinal}={value}"
|
|
1826
|
+
|
|
1827
|
+
|
|
962
1828
|
def _load_profile_workers(workspace_root: Path, task_type: str) -> list[str]:
|
|
963
1829
|
return resolve_profile_workers(_profile_path(workspace_root, task_type))
|
|
964
1830
|
|
|
@@ -3534,6 +4400,14 @@ def _submit_reuse_previous(state: WizardState, value: str) -> Optional[str]:
|
|
|
3534
4400
|
report_writer_provider = state.report_writer_provider or "claude"
|
|
3535
4401
|
state.report_writer_model = _safe_model(
|
|
3536
4402
|
report_writer_provider, inputs.get("reportWriterModel"))
|
|
4403
|
+
if _role_selection_enabled(state):
|
|
4404
|
+
conversion_payload = dict(inputs)
|
|
4405
|
+
conversion_payload.setdefault("grokModel", state.grok_model)
|
|
4406
|
+
conversion_payload.setdefault("kimiModel", state.kimi_model)
|
|
4407
|
+
state.role_counts.clear()
|
|
4408
|
+
state.role_models.clear()
|
|
4409
|
+
state.role_selection_order.clear()
|
|
4410
|
+
_convert_v1_provider_selections(state, conversion_payload)
|
|
3537
4411
|
directive = inputs.get("directive")
|
|
3538
4412
|
state.directive = directive if isinstance(directive, str) else ""
|
|
3539
4413
|
related = inputs.get("relatedTasks")
|
|
@@ -3579,6 +4453,7 @@ def _role_model_lines(state: WizardState) -> str:
|
|
|
3579
4453
|
.resolve(state.host_runtime)
|
|
3580
4454
|
.descriptor.native_provider_id
|
|
3581
4455
|
or "",
|
|
4456
|
+
report_writer_provider=state.report_writer_provider or "claude",
|
|
3582
4457
|
)
|
|
3583
4458
|
roster = _resolved_roster(state)
|
|
3584
4459
|
impl = state.task_type == "implementation"
|
|
@@ -4116,7 +4991,15 @@ def _build_edit_target(state: WizardState) -> Prompt:
|
|
|
4116
4991
|
t = _p(state.workspace_root, "edit_target")
|
|
4117
4992
|
# offer every step that has been answered.
|
|
4118
4993
|
options: list[Option] = []
|
|
4119
|
-
|
|
4994
|
+
selection_ids = [
|
|
4995
|
+
*state.answered,
|
|
4996
|
+
*(
|
|
4997
|
+
step_id
|
|
4998
|
+
for step_id in state.role_selection_order
|
|
4999
|
+
if step_id not in state.answered
|
|
5000
|
+
),
|
|
5001
|
+
]
|
|
5002
|
+
for sid in selection_ids:
|
|
4120
5003
|
if sid in (S_CONFIRM, S_EDIT_TARGET):
|
|
4121
5004
|
continue
|
|
4122
5005
|
options.append(_opt(sid, sid))
|
|
@@ -4128,11 +5011,59 @@ def _build_edit_target(state: WizardState) -> Prompt:
|
|
|
4128
5011
|
)
|
|
4129
5012
|
|
|
4130
5013
|
|
|
5014
|
+
def _reset_role_selection_from(state: WizardState, target_step: str) -> None:
|
|
5015
|
+
try:
|
|
5016
|
+
target_index = state.role_selection_order.index(target_step)
|
|
5017
|
+
except ValueError as exc:
|
|
5018
|
+
raise WizardError(f"unknown role selection step: {target_step!r}") from exc
|
|
5019
|
+
kept_ids = state.role_selection_order[:target_index]
|
|
5020
|
+
kept_counts = {
|
|
5021
|
+
step_id.split(":", 1)[1]
|
|
5022
|
+
for step_id in kept_ids
|
|
5023
|
+
if step_id.startswith("role-count:")
|
|
5024
|
+
}
|
|
5025
|
+
kept_models: dict[str, int] = {}
|
|
5026
|
+
for step_id in kept_ids:
|
|
5027
|
+
if not step_id.startswith("role-model:"):
|
|
5028
|
+
continue
|
|
5029
|
+
_, role, _ = step_id.split(":", 2)
|
|
5030
|
+
kept_models[role] = kept_models.get(role, 0) + 1
|
|
5031
|
+
state.role_counts = {
|
|
5032
|
+
role: count
|
|
5033
|
+
for role, count in state.role_counts.items()
|
|
5034
|
+
if role in kept_counts
|
|
5035
|
+
}
|
|
5036
|
+
state.role_models = {
|
|
5037
|
+
role: models[:kept_models[role]]
|
|
5038
|
+
for role, models in state.role_models.items()
|
|
5039
|
+
if kept_models.get(role, 0) > 0
|
|
5040
|
+
}
|
|
5041
|
+
removed_ids = set(state.role_selection_order[target_index:])
|
|
5042
|
+
state.role_selection_order = kept_ids
|
|
5043
|
+
state.answered = [
|
|
5044
|
+
step_id for step_id in state.answered if step_id not in removed_ids
|
|
5045
|
+
]
|
|
5046
|
+
|
|
5047
|
+
|
|
5048
|
+
def _clear_role_selection(state: WizardState) -> None:
|
|
5049
|
+
state.role_counts.clear()
|
|
5050
|
+
state.role_models.clear()
|
|
5051
|
+
state.role_selection_order.clear()
|
|
5052
|
+
state.answered = [
|
|
5053
|
+
step_id
|
|
5054
|
+
for step_id in state.answered
|
|
5055
|
+
if not step_id.startswith(("role-count:", "role-model:"))
|
|
5056
|
+
]
|
|
5057
|
+
|
|
5058
|
+
|
|
4131
5059
|
def _submit_edit_target(state: WizardState, value: str) -> Optional[str]:
|
|
4132
|
-
if
|
|
5060
|
+
if value.startswith(("role-count:", "role-model:")):
|
|
5061
|
+
_reset_role_selection_from(state, value)
|
|
5062
|
+
elif any(s.id == value for s in STEPS):
|
|
5063
|
+
_reset_from(state, value)
|
|
5064
|
+
else:
|
|
4133
5065
|
raise WizardError(f"unknown step: {value!r}")
|
|
4134
5066
|
state.edit_target = value
|
|
4135
|
-
_reset_from(state, value)
|
|
4136
5067
|
state.confirmed = None
|
|
4137
5068
|
state.edit_target = ""
|
|
4138
5069
|
return f"edit-target: {value} (rewinding)"
|
|
@@ -4379,23 +5310,28 @@ STEPS: list[Step] = [
|
|
|
4379
5310
|
owns=("handoff_mode", "handoff_stages", "approved_plan_path")),
|
|
4380
5311
|
Step(S_EXECUTOR,
|
|
4381
5312
|
applies=lambda s: (s.task_type == "implementation"
|
|
5313
|
+
and not _role_selection_enabled(s)
|
|
4382
5314
|
and bool(s.approved_plan_path)
|
|
4383
5315
|
and not s.executor),
|
|
4384
5316
|
build=_build_executor, submit=_submit_executor,
|
|
4385
5317
|
owns=("executor",)),
|
|
4386
5318
|
Step(S_CRITIC_PICK,
|
|
4387
|
-
applies=lambda s: (
|
|
5319
|
+
applies=lambda s: (not _role_selection_enabled(s)
|
|
5320
|
+
and s.task_type in ("requirements-discovery", "error-analysis", "implementation-planning", "final-verification")
|
|
4388
5321
|
and not s.critic
|
|
4389
5322
|
and not s.critic_pending_text
|
|
4390
5323
|
and S_CRITIC_PICK not in s.answered),
|
|
4391
5324
|
build=_build_critic_pick, submit=_submit_critic_pick,
|
|
4392
5325
|
owns=("critic", "critic_pending_text")),
|
|
4393
5326
|
Step(S_CRITIC_TEXT,
|
|
4394
|
-
applies=lambda s: (
|
|
5327
|
+
applies=lambda s: (not _role_selection_enabled(s)
|
|
5328
|
+
and s.critic_pending_text
|
|
5329
|
+
and S_CRITIC_TEXT not in s.answered),
|
|
4395
5330
|
build=_build_critic_text, submit=_submit_critic_text,
|
|
4396
5331
|
owns=("critic", "critic_pending_text")),
|
|
4397
5332
|
Step(S_DEFAULTS_OR_CUSTOM,
|
|
4398
5333
|
applies=lambda s: (_identity_ready(s)
|
|
5334
|
+
and not _role_selection_enabled(s)
|
|
4399
5335
|
and s.use_defaults is None),
|
|
4400
5336
|
build=_build_defaults_or_custom, submit=_submit_defaults_or_custom,
|
|
4401
5337
|
owns=("use_defaults",)),
|
|
@@ -4408,6 +5344,7 @@ STEPS: list[Step] = [
|
|
|
4408
5344
|
# still skipped because it runs lead + executor only.
|
|
4409
5345
|
Step(S_WORKERS_OVERRIDE,
|
|
4410
5346
|
applies=lambda s: (s.task_type != "implementation"
|
|
5347
|
+
and not _role_selection_enabled(s)
|
|
4411
5348
|
and any(
|
|
4412
5349
|
w != "report-writer"
|
|
4413
5350
|
for w in (s.profile_workers
|
|
@@ -4419,23 +5356,27 @@ STEPS: list[Step] = [
|
|
|
4419
5356
|
# "직접 선택" 을 고른 run 에서만 등장한다 — 기본 로스터에서 워커를 빼는
|
|
4420
5357
|
# 축소가 가능한 유일한 화면.
|
|
4421
5358
|
Step(S_WORKERS_CUSTOM,
|
|
4422
|
-
applies=lambda s: (s
|
|
5359
|
+
applies=lambda s: (not _role_selection_enabled(s)
|
|
5360
|
+
and s.workers_custom_pending
|
|
4423
5361
|
and S_WORKERS_CUSTOM not in s.answered),
|
|
4424
5362
|
build=_build_workers_custom, submit=_submit_workers_custom,
|
|
4425
5363
|
owns=("workers_override", "workers_custom_pending")),
|
|
4426
5364
|
Step(S_LEAD_MODEL,
|
|
4427
5365
|
applies=lambda s: (s.use_defaults is False
|
|
5366
|
+
and not _role_selection_enabled(s)
|
|
4428
5367
|
and S_LEAD_MODEL not in s.answered),
|
|
4429
5368
|
build=_build_lead_model, submit=_submit_lead_model,
|
|
4430
5369
|
owns=("lead_provider", "lead_model")),
|
|
4431
5370
|
Step(S_EXECUTOR_MODEL,
|
|
4432
5371
|
applies=lambda s: (s.use_defaults is False
|
|
5372
|
+
and not _role_selection_enabled(s)
|
|
4433
5373
|
and s.task_type == "implementation"
|
|
4434
5374
|
and S_EXECUTOR_MODEL not in s.answered),
|
|
4435
5375
|
build=_build_executor_model, submit=_submit_executor_model,
|
|
4436
5376
|
owns=("claude_model", "codex_model", "antigravity_model")),
|
|
4437
5377
|
Step(S_CLAUDE_MODEL,
|
|
4438
5378
|
applies=lambda s: (s.use_defaults is False
|
|
5379
|
+
and not _role_selection_enabled(s)
|
|
4439
5380
|
and s.task_type != "implementation"
|
|
4440
5381
|
and "claude" in _resolved_roster(s)
|
|
4441
5382
|
and S_CLAUDE_MODEL not in s.answered),
|
|
@@ -4443,6 +5384,7 @@ STEPS: list[Step] = [
|
|
|
4443
5384
|
owns=("claude_model",)),
|
|
4444
5385
|
Step(S_CODEX_MODEL,
|
|
4445
5386
|
applies=lambda s: (s.use_defaults is False
|
|
5387
|
+
and not _role_selection_enabled(s)
|
|
4446
5388
|
and s.task_type != "implementation"
|
|
4447
5389
|
and "codex" in _resolved_roster(s)
|
|
4448
5390
|
and S_CODEX_MODEL not in s.answered),
|
|
@@ -4450,6 +5392,7 @@ STEPS: list[Step] = [
|
|
|
4450
5392
|
owns=("codex_model",)),
|
|
4451
5393
|
Step(S_ANTIGRAVITY_MODEL,
|
|
4452
5394
|
applies=lambda s: (s.use_defaults is False
|
|
5395
|
+
and not _role_selection_enabled(s)
|
|
4453
5396
|
and s.task_type != "implementation"
|
|
4454
5397
|
and "antigravity" in _resolved_roster(s)
|
|
4455
5398
|
and S_ANTIGRAVITY_MODEL not in s.answered),
|
|
@@ -4457,6 +5400,7 @@ STEPS: list[Step] = [
|
|
|
4457
5400
|
owns=("antigravity_model",)),
|
|
4458
5401
|
Step(S_GROK_MODEL,
|
|
4459
5402
|
applies=lambda s: (s.use_defaults is False
|
|
5403
|
+
and not _role_selection_enabled(s)
|
|
4460
5404
|
and s.task_type != "implementation"
|
|
4461
5405
|
and "grok" in _resolved_roster(s)
|
|
4462
5406
|
and S_GROK_MODEL not in s.answered),
|
|
@@ -4464,6 +5408,7 @@ STEPS: list[Step] = [
|
|
|
4464
5408
|
owns=("grok_model",)),
|
|
4465
5409
|
Step(S_KIMI_MODEL,
|
|
4466
5410
|
applies=lambda s: (s.use_defaults is False
|
|
5411
|
+
and not _role_selection_enabled(s)
|
|
4467
5412
|
and s.task_type != "implementation"
|
|
4468
5413
|
and "kimi" in _resolved_roster(s)
|
|
4469
5414
|
and S_KIMI_MODEL not in s.answered),
|
|
@@ -4471,6 +5416,7 @@ STEPS: list[Step] = [
|
|
|
4471
5416
|
owns=("kimi_model",)),
|
|
4472
5417
|
Step(S_REPORT_WRITER_MODEL,
|
|
4473
5418
|
applies=lambda s: (s.use_defaults is False
|
|
5419
|
+
and not _role_selection_enabled(s)
|
|
4474
5420
|
and (s.task_type == "implementation"
|
|
4475
5421
|
or "report-writer" in _resolved_roster(s))
|
|
4476
5422
|
and S_REPORT_WRITER_MODEL not in s.answered),
|
|
@@ -4590,7 +5536,7 @@ def _identity_ready(s: WizardState) -> bool:
|
|
|
4590
5536
|
if s.task_type in _STAGE_SCOPED_TASK_TYPES:
|
|
4591
5537
|
if not s.approved_plan_path:
|
|
4592
5538
|
return False
|
|
4593
|
-
if s.task_type == "implementation":
|
|
5539
|
+
if s.task_type == "implementation" and not _role_selection_enabled(s):
|
|
4594
5540
|
if not s.executor:
|
|
4595
5541
|
return False
|
|
4596
5542
|
if (s.task_type == "release-handoff"
|
|
@@ -4600,6 +5546,24 @@ def _identity_ready(s: WizardState) -> bool:
|
|
|
4600
5546
|
|
|
4601
5547
|
|
|
4602
5548
|
def _ready_for_confirm(s: WizardState) -> bool:
|
|
5549
|
+
if _role_selection_enabled(s):
|
|
5550
|
+
try:
|
|
5551
|
+
if next_role_prompt(s) is not None:
|
|
5552
|
+
return False
|
|
5553
|
+
except WizardError:
|
|
5554
|
+
return False
|
|
5555
|
+
followup_ids = [
|
|
5556
|
+
S_DIRECTIVE_PICK,
|
|
5557
|
+
S_DIRECTIVE,
|
|
5558
|
+
S_RELATED_TASKS_PICK,
|
|
5559
|
+
S_RELATED_TASKS,
|
|
5560
|
+
S_CLARIFICATION_PICK,
|
|
5561
|
+
S_CLARIFICATION,
|
|
5562
|
+
S_PR_TEMPLATE_PICK,
|
|
5563
|
+
S_PR_TEMPLATE,
|
|
5564
|
+
S_PR_TEMPLATE_SCOPE,
|
|
5565
|
+
]
|
|
5566
|
+
return not any(STEP_BY_ID[step_id].applies(s) for step_id in followup_ids)
|
|
4603
5567
|
if s.use_defaults is None:
|
|
4604
5568
|
return False
|
|
4605
5569
|
# Worker roster is required regardless of the defaults / customize
|
|
@@ -4631,6 +5595,12 @@ def _reset_from(state: WizardState, target_step: str) -> None:
|
|
|
4631
5595
|
idx = next((i for i, s in enumerate(STEPS) if s.id == target_step), -1)
|
|
4632
5596
|
if idx < 0:
|
|
4633
5597
|
return
|
|
5598
|
+
role_boundary = next(
|
|
5599
|
+
i for i, step in enumerate(STEPS)
|
|
5600
|
+
if step.id == S_DEFAULTS_OR_CUSTOM
|
|
5601
|
+
)
|
|
5602
|
+
if idx < role_boundary:
|
|
5603
|
+
_clear_role_selection(state)
|
|
4634
5604
|
# A later step may own a field an earlier answered step also owns —
|
|
4635
5605
|
# `handoff_stage_pick` owns `approved_plan_path` because it resolves the
|
|
4636
5606
|
# plan on its own. Clearing it while rewinding to a step in front of it
|
|
@@ -4687,6 +5657,8 @@ _FIELD_DEFAULTS: dict[str, Any] = {
|
|
|
4687
5657
|
"selected_stages": "",
|
|
4688
5658
|
"handoff_mode": "", "handoff_stages": "",
|
|
4689
5659
|
"executor": "", "critic": "", "critic_pending_text": False,
|
|
5660
|
+
"execution_identity_version": 1,
|
|
5661
|
+
"role_counts": {}, "role_models": {}, "role_selection_order": [],
|
|
4690
5662
|
"reuse_previous": None,
|
|
4691
5663
|
"use_defaults": None, "workers_override": "",
|
|
4692
5664
|
"workers_custom_pending": False,
|
|
@@ -4711,6 +5683,8 @@ def _reset_field(state: WizardState, fname: str) -> None:
|
|
|
4711
5683
|
# copy mutable defaults
|
|
4712
5684
|
if isinstance(default, list):
|
|
4713
5685
|
setattr(state, fname, [])
|
|
5686
|
+
elif isinstance(default, dict):
|
|
5687
|
+
setattr(state, fname, {})
|
|
4714
5688
|
else:
|
|
4715
5689
|
setattr(state, fname, default)
|
|
4716
5690
|
|
|
@@ -4725,6 +5699,7 @@ def init_state(
|
|
|
4725
5699
|
) -> WizardState:
|
|
4726
5700
|
"""Bootstrap a new wizard state."""
|
|
4727
5701
|
return WizardState(
|
|
5702
|
+
execution_identity_version=2,
|
|
4728
5703
|
workspace_root=workspace_root,
|
|
4729
5704
|
project_root=project_root,
|
|
4730
5705
|
project_id=project_id,
|
|
@@ -4764,6 +5739,10 @@ def next_prompt(state: WizardState) -> Prompt:
|
|
|
4764
5739
|
if state.confirmed:
|
|
4765
5740
|
return Prompt(step=S_DONE, kind="done")
|
|
4766
5741
|
for step in STEPS:
|
|
5742
|
+
if step.id == S_DEFAULTS_OR_CUSTOM:
|
|
5743
|
+
role_prompt = next_role_prompt(state)
|
|
5744
|
+
if role_prompt is not None:
|
|
5745
|
+
return role_prompt
|
|
4767
5746
|
if step.id in state.answered and not step.repeatable:
|
|
4768
5747
|
continue
|
|
4769
5748
|
if step.applies(state):
|
|
@@ -4800,6 +5779,13 @@ def _sim_advance(state: WizardState, prompt: Prompt) -> None:
|
|
|
4800
5779
|
"""기본답으로 한 화면 전진한다. progress 를 재계산하는 submit()/
|
|
4801
5780
|
_submit_group() 은 호출하지 않고 step.submit 만 직접 호출해 재귀를 막는다."""
|
|
4802
5781
|
try:
|
|
5782
|
+
if prompt.step.startswith(("role-count:", "role-model:")):
|
|
5783
|
+
_submit_role_prompt(state, prompt, _sim_answer(prompt))
|
|
5784
|
+
if prompt.step not in state.answered:
|
|
5785
|
+
state.answered.append(prompt.step)
|
|
5786
|
+
if prompt.step not in state.role_selection_order:
|
|
5787
|
+
state.role_selection_order.append(prompt.step)
|
|
5788
|
+
return
|
|
4803
5789
|
if prompt.kind == "pick_group":
|
|
4804
5790
|
for q in prompt.questions:
|
|
4805
5791
|
STEP_BY_ID[q.step].submit(state, _sim_answer(q))
|
|
@@ -4980,6 +5966,14 @@ def submit(state: WizardState, value: str) -> dict[str, Any]:
|
|
|
4980
5966
|
value = _normalize_interaction_answer(state, prompt, plan, value)
|
|
4981
5967
|
if prompt.kind == "pick_group":
|
|
4982
5968
|
return _submit_group(state, prompt, value)
|
|
5969
|
+
if prompt.step.startswith(("role-count:", "role-model:")):
|
|
5970
|
+
echo = _submit_role_prompt(state, prompt, value or "")
|
|
5971
|
+
if prompt.step not in state.answered:
|
|
5972
|
+
state.answered.append(prompt.step)
|
|
5973
|
+
if prompt.step not in state.role_selection_order:
|
|
5974
|
+
state.role_selection_order.append(prompt.step)
|
|
5975
|
+
nxt = next_prompt(state)
|
|
5976
|
+
return {"echo": echo, "next": prompt_payload(state, nxt)}
|
|
4983
5977
|
step = STEP_BY_ID[prompt.step]
|
|
4984
5978
|
echo = step.submit(state, value or "")
|
|
4985
5979
|
if prompt.step not in state.answered:
|
|
@@ -5005,15 +5999,39 @@ def _stage_intent(state: WizardState) -> WizardStageIntent:
|
|
|
5005
5999
|
raise WizardError(str(exc)) from exc
|
|
5006
6000
|
|
|
5007
6001
|
|
|
5008
|
-
def
|
|
6002
|
+
def render_role_args(state: WizardState) -> list[str]:
|
|
6003
|
+
"""Return ordered canonical role count/model CLI tokens."""
|
|
6004
|
+
role_argv: list[str] = []
|
|
6005
|
+
if _role_selection_enabled(state):
|
|
6006
|
+
profile = _load_role_profile_for_state(state)
|
|
6007
|
+
requirements = _selectable_static_requirements(state, profile)
|
|
6008
|
+
for requirement in profile.roles:
|
|
6009
|
+
if requirement.dynamic or requirement.optional_count == 0:
|
|
6010
|
+
continue
|
|
6011
|
+
if requirement.role not in state.role_counts:
|
|
6012
|
+
continue
|
|
6013
|
+
role_argv.extend([
|
|
6014
|
+
"--role-count",
|
|
6015
|
+
f"{requirement.role}={state.role_counts[requirement.role]}",
|
|
6016
|
+
])
|
|
6017
|
+
ordered_roles = [requirement.role for requirement in requirements]
|
|
6018
|
+
else:
|
|
6019
|
+
ordered_roles = []
|
|
6020
|
+
for role in state.role_models:
|
|
6021
|
+
if role not in ordered_roles:
|
|
6022
|
+
ordered_roles.append(role)
|
|
6023
|
+
for role in ordered_roles:
|
|
6024
|
+
for model_ref in state.role_models.get(role, []):
|
|
6025
|
+
role_argv.extend(["--role-model", f"{role}={model_ref}"])
|
|
6026
|
+
return role_argv
|
|
6027
|
+
|
|
6028
|
+
|
|
6029
|
+
def render_args(state: WizardState) -> dict[str, Any]:
|
|
5009
6030
|
"""Convert finalized state into ``okstra render-bundle`` argument map."""
|
|
5010
6031
|
if state.aborted:
|
|
5011
6032
|
raise WizardError(
|
|
5012
6033
|
"wizard was aborted by the user — render-args is unavailable"
|
|
5013
6034
|
)
|
|
5014
|
-
workers = state.workers_override.strip()
|
|
5015
|
-
if state.task_type == "implementation":
|
|
5016
|
-
workers = "" # profile-default roster is mandatory for impl
|
|
5017
6035
|
base_ref = (
|
|
5018
6036
|
""
|
|
5019
6037
|
if state.reuse_worktree or state.task_type == "final-verification"
|
|
@@ -5030,15 +6048,7 @@ def render_args(state: WizardState) -> dict[str, str]:
|
|
|
5030
6048
|
for path in (state.feature_evidence_path, state.project_evidence_path)
|
|
5031
6049
|
if path
|
|
5032
6050
|
]
|
|
5033
|
-
|
|
5034
|
-
f"{provider}={model}"
|
|
5035
|
-
for provider, model in (
|
|
5036
|
-
("grok", state.grok_model),
|
|
5037
|
-
("kimi", state.kimi_model),
|
|
5038
|
-
)
|
|
5039
|
-
if model
|
|
5040
|
-
)
|
|
5041
|
-
return {
|
|
6051
|
+
rendered: dict[str, Any] = {
|
|
5042
6052
|
"project-root": state.project_root,
|
|
5043
6053
|
"project-id": state.project_id,
|
|
5044
6054
|
"task-group": state.task_group,
|
|
@@ -5047,22 +6057,11 @@ def render_args(state: WizardState) -> dict[str, str]:
|
|
|
5047
6057
|
"task-brief": state.brief_path,
|
|
5048
6058
|
"analysis-target": state.analysis_target,
|
|
5049
6059
|
"evidence-inputs": ",".join(evidence_paths),
|
|
5050
|
-
"executor": state.executor,
|
|
5051
|
-
"critic": state.critic,
|
|
5052
6060
|
"approved-plan": state.approved_plan_path,
|
|
5053
6061
|
"stage": stage_intent.stage,
|
|
5054
6062
|
"stages": state.handoff_stages,
|
|
5055
6063
|
"base-ref": base_ref,
|
|
5056
|
-
"workers": workers,
|
|
5057
6064
|
"directive": state.directive,
|
|
5058
|
-
"lead-provider": state.lead_provider,
|
|
5059
|
-
"lead-model": state.lead_model,
|
|
5060
|
-
"claude-model": state.claude_model,
|
|
5061
|
-
"codex-model": state.codex_model,
|
|
5062
|
-
"antigravity-model": state.antigravity_model,
|
|
5063
|
-
"worker-model": worker_models,
|
|
5064
|
-
"report-writer-provider": state.report_writer_provider,
|
|
5065
|
-
"report-writer-model": state.report_writer_model,
|
|
5066
6065
|
"related-tasks": state.related_tasks_raw,
|
|
5067
6066
|
"clarification-response": state.clarification_response_path,
|
|
5068
6067
|
"selected-direction": state.selected_direction_path,
|
|
@@ -5072,7 +6071,36 @@ def render_args(state: WizardState) -> dict[str, str]:
|
|
|
5072
6071
|
),
|
|
5073
6072
|
"pr-template-path": pr_template,
|
|
5074
6073
|
"fix-cycle": state.fix_cycle,
|
|
6074
|
+
"host-session-context-json": serialize_host_session_context(
|
|
6075
|
+
_host_session_context(state)
|
|
6076
|
+
),
|
|
5075
6077
|
}
|
|
6078
|
+
role_argv = render_role_args(state)
|
|
6079
|
+
rendered["role-count"] = [
|
|
6080
|
+
role_argv[index + 1]
|
|
6081
|
+
for index, token in enumerate(role_argv)
|
|
6082
|
+
if token == "--role-count"
|
|
6083
|
+
]
|
|
6084
|
+
rendered["role-model"] = [
|
|
6085
|
+
role_argv[index + 1]
|
|
6086
|
+
for index, token in enumerate(role_argv)
|
|
6087
|
+
if token == "--role-model"
|
|
6088
|
+
]
|
|
6089
|
+
return rendered
|
|
6090
|
+
|
|
6091
|
+
|
|
6092
|
+
def _render_argv(rendered: dict[str, Any], *, host_runtime: str) -> list[str]:
|
|
6093
|
+
"""Flatten render arguments into the canonical render-bundle argv."""
|
|
6094
|
+
argv = ["--lead-runtime", host_runtime]
|
|
6095
|
+
for name, raw_value in rendered.items():
|
|
6096
|
+
values = raw_value if isinstance(raw_value, list) else [raw_value]
|
|
6097
|
+
for value in values:
|
|
6098
|
+
if not isinstance(value, str):
|
|
6099
|
+
raise WizardError(
|
|
6100
|
+
f"wizard render arg --{name} must be a string"
|
|
6101
|
+
)
|
|
6102
|
+
argv.extend([f"--{name}", value])
|
|
6103
|
+
return argv
|
|
5076
6104
|
|
|
5077
6105
|
|
|
5078
6106
|
def _clarification_sidecar_line(state: WizardState) -> Optional[str]:
|
|
@@ -5172,37 +6200,77 @@ def confirmation_block(state: WizardState) -> str:
|
|
|
5172
6200
|
worktree_line = _worktree_preview_line(state)
|
|
5173
6201
|
if worktree_line is not None:
|
|
5174
6202
|
lines.append(worktree_line)
|
|
5175
|
-
|
|
6203
|
+
role_selection = _role_selection_enabled(state)
|
|
6204
|
+
if state.task_type == "implementation" and not role_selection:
|
|
5176
6205
|
lines.append(f" executor : {state.executor or '(default)'}")
|
|
5177
6206
|
lines.append(
|
|
5178
6207
|
_msg(state.workspace_root, "confirmation", "workers_implementation_default")
|
|
5179
6208
|
)
|
|
5180
|
-
|
|
6209
|
+
elif not role_selection:
|
|
5181
6210
|
roster = state.workers_override or ",".join(state.profile_workers) or "(profile default)"
|
|
5182
6211
|
lines.append(f" workers : {roster}")
|
|
5183
|
-
|
|
5184
|
-
|
|
5185
|
-
|
|
5186
|
-
|
|
5187
|
-
|
|
5188
|
-
|
|
5189
|
-
|
|
5190
|
-
|
|
5191
|
-
|
|
5192
|
-
|
|
5193
|
-
|
|
5194
|
-
|
|
5195
|
-
|
|
5196
|
-
|
|
5197
|
-
|
|
6212
|
+
if role_selection:
|
|
6213
|
+
profile = _load_role_profile_for_state(state)
|
|
6214
|
+
if state.host_entry_mode == "current-session":
|
|
6215
|
+
lines.append(_msg(
|
|
6216
|
+
state.workspace_root,
|
|
6217
|
+
"confirmation",
|
|
6218
|
+
"static_role",
|
|
6219
|
+
role="leader",
|
|
6220
|
+
ordinal="1",
|
|
6221
|
+
model="current-session",
|
|
6222
|
+
))
|
|
6223
|
+
for requirement in _selectable_static_requirements(state, profile):
|
|
6224
|
+
count = _selected_role_count(state, requirement)
|
|
6225
|
+
selected = state.role_models.get(requirement.role, [])
|
|
6226
|
+
for ordinal in range(1, count + 1):
|
|
6227
|
+
model_ref = (
|
|
6228
|
+
selected[ordinal - 1]
|
|
6229
|
+
if ordinal <= len(selected)
|
|
6230
|
+
else "(selection required)"
|
|
6231
|
+
)
|
|
6232
|
+
lines.append(_msg(
|
|
6233
|
+
state.workspace_root,
|
|
6234
|
+
"confirmation",
|
|
6235
|
+
"static_role",
|
|
6236
|
+
role=requirement.role,
|
|
6237
|
+
ordinal=str(ordinal),
|
|
6238
|
+
model=model_ref,
|
|
6239
|
+
))
|
|
6240
|
+
for requirement in profile.roles:
|
|
6241
|
+
if not requirement.dynamic:
|
|
6242
|
+
continue
|
|
6243
|
+
lines.append(_msg(
|
|
6244
|
+
state.workspace_root,
|
|
6245
|
+
"confirmation",
|
|
6246
|
+
"dynamic_role",
|
|
6247
|
+
role=requirement.role,
|
|
6248
|
+
))
|
|
6249
|
+
else:
|
|
5198
6250
|
lines.append(
|
|
5199
|
-
f"
|
|
5200
|
-
f"{state.
|
|
6251
|
+
f" lead : {state.lead_provider or 'claude'} / "
|
|
6252
|
+
f"{state.lead_model or 'default'}"
|
|
5201
6253
|
)
|
|
6254
|
+
if state.claude_model:
|
|
6255
|
+
lines.append(f" claude-model : {state.claude_model}")
|
|
6256
|
+
if state.codex_model:
|
|
6257
|
+
lines.append(f" codex-model : {state.codex_model}")
|
|
6258
|
+
if state.antigravity_model:
|
|
6259
|
+
lines.append(f" antigravity-model : {state.antigravity_model}")
|
|
6260
|
+
if state.grok_model:
|
|
6261
|
+
lines.append(f" grok-model : {state.grok_model}")
|
|
6262
|
+
if state.kimi_model:
|
|
6263
|
+
lines.append(f" kimi-model : {state.kimi_model}")
|
|
6264
|
+
if state.report_writer_model or state.report_writer_provider:
|
|
6265
|
+
lines.append(
|
|
6266
|
+
f" report-writer : {state.report_writer_provider or 'claude'} / "
|
|
6267
|
+
f"{state.report_writer_model or 'default'}"
|
|
6268
|
+
)
|
|
5202
6269
|
lines.append(f" directive : {state.directive or '(none)'}")
|
|
5203
6270
|
if state.related_tasks_raw:
|
|
5204
6271
|
lines.append(f" related-tasks : {state.related_tasks_raw}")
|
|
5205
|
-
if
|
|
6272
|
+
if (not role_selection
|
|
6273
|
+
and state.task_type in ("requirements-discovery", "error-analysis", "implementation-planning", "final-verification")):
|
|
5206
6274
|
lines.append(f" critic : {state.critic or '(off)'}")
|
|
5207
6275
|
if state.task_type in _STAGE_SCOPED_TASK_TYPES:
|
|
5208
6276
|
lines.append(f" approved-plan : {state.approved_plan_path}")
|
|
@@ -5269,8 +6337,10 @@ def wizard_outcome(state: WizardState) -> dict[str, Any]:
|
|
|
5269
6337
|
raise WizardError("wizard was aborted by the user — outcome is unavailable")
|
|
5270
6338
|
if state.confirmed is not True:
|
|
5271
6339
|
raise WizardError("wizard is not complete — outcome is unavailable")
|
|
6340
|
+
rendered = render_args(state)
|
|
5272
6341
|
return {
|
|
5273
|
-
"renderArgs":
|
|
6342
|
+
"renderArgs": rendered,
|
|
6343
|
+
"renderArgv": _render_argv(rendered, host_runtime=state.host_runtime),
|
|
5274
6344
|
"orchestration": {"chainStages": _stage_intent(state).chain_stages},
|
|
5275
6345
|
"persistActions": _wizard_persist_actions(state),
|
|
5276
6346
|
"confirmationText": confirmation_block(state),
|
|
@@ -5279,16 +6349,136 @@ def wizard_outcome(state: WizardState) -> dict[str, Any]:
|
|
|
5279
6349
|
|
|
5280
6350
|
# ---- File I/O helpers (used by CLI) -------------------------------------
|
|
5281
6351
|
|
|
6352
|
+
_LEGACY_SOURCE_FIELD = "legacySource"
|
|
6353
|
+
|
|
6354
|
+
|
|
6355
|
+
def _legacy_v2_companion_path(path: Path) -> Path:
|
|
6356
|
+
return path.with_name(f"{path.name}.v2.json")
|
|
6357
|
+
|
|
6358
|
+
|
|
6359
|
+
def _content_addressed_v2_companion_path(
|
|
6360
|
+
path: Path,
|
|
6361
|
+
source_digest: str,
|
|
6362
|
+
suffix: int | None = None,
|
|
6363
|
+
) -> Path:
|
|
6364
|
+
numbered = f".{suffix}" if suffix is not None else ""
|
|
6365
|
+
return path.with_name(f"{path.name}.v2.{source_digest}{numbered}.json")
|
|
6366
|
+
|
|
6367
|
+
|
|
6368
|
+
def _content_addressed_v2_companion_paths(
|
|
6369
|
+
path: Path,
|
|
6370
|
+
source_digest: str,
|
|
6371
|
+
) -> tuple[Path, ...]:
|
|
6372
|
+
canonical = _content_addressed_v2_companion_path(path, source_digest)
|
|
6373
|
+
numbered_prefix = f"{path.name}.v2.{source_digest}."
|
|
6374
|
+
numbered = tuple(sorted(
|
|
6375
|
+
candidate
|
|
6376
|
+
for candidate in path.parent.iterdir()
|
|
6377
|
+
if candidate.is_file()
|
|
6378
|
+
and candidate.name.startswith(numbered_prefix)
|
|
6379
|
+
and candidate.name.endswith(".json")
|
|
6380
|
+
))
|
|
6381
|
+
return (canonical, *numbered)
|
|
6382
|
+
|
|
6383
|
+
|
|
6384
|
+
def _available_v2_companion_path(path: Path, source_digest: str) -> Path:
|
|
6385
|
+
candidate = _content_addressed_v2_companion_path(path, source_digest)
|
|
6386
|
+
suffix = 1
|
|
6387
|
+
while candidate.exists():
|
|
6388
|
+
candidate = _content_addressed_v2_companion_path(
|
|
6389
|
+
path,
|
|
6390
|
+
source_digest,
|
|
6391
|
+
suffix,
|
|
6392
|
+
)
|
|
6393
|
+
suffix += 1
|
|
6394
|
+
return candidate
|
|
6395
|
+
|
|
6396
|
+
|
|
6397
|
+
def _legacy_source_metadata(path: Path, source: bytes) -> dict[str, str]:
|
|
6398
|
+
return {
|
|
6399
|
+
"path": str(path.resolve()),
|
|
6400
|
+
"sha256": hashlib.sha256(source).hexdigest(),
|
|
6401
|
+
}
|
|
6402
|
+
|
|
6403
|
+
|
|
6404
|
+
def _matching_v2_companion(
|
|
6405
|
+
path: Path,
|
|
6406
|
+
source_metadata: dict[str, str],
|
|
6407
|
+
) -> dict[str, Any] | None:
|
|
6408
|
+
try:
|
|
6409
|
+
payload = json.loads(path.read_text(encoding="utf-8"))
|
|
6410
|
+
except (OSError, UnicodeError, json.JSONDecodeError):
|
|
6411
|
+
return None
|
|
6412
|
+
if not isinstance(payload, dict):
|
|
6413
|
+
return None
|
|
6414
|
+
if payload.get("executionIdentityVersion") != 2:
|
|
6415
|
+
return None
|
|
6416
|
+
if payload.get(_LEGACY_SOURCE_FIELD) != source_metadata:
|
|
6417
|
+
return None
|
|
6418
|
+
return payload
|
|
6419
|
+
|
|
6420
|
+
|
|
6421
|
+
def _load_matching_v2_state(
|
|
6422
|
+
paths: tuple[Path, ...],
|
|
6423
|
+
source_metadata: dict[str, str],
|
|
6424
|
+
) -> tuple[WizardState | None, Path | None]:
|
|
6425
|
+
for companion_path in paths:
|
|
6426
|
+
payload = _matching_v2_companion(companion_path, source_metadata)
|
|
6427
|
+
if payload is None:
|
|
6428
|
+
continue
|
|
6429
|
+
try:
|
|
6430
|
+
return WizardState.from_json(payload), companion_path
|
|
6431
|
+
except WizardError:
|
|
6432
|
+
continue
|
|
6433
|
+
return None, None
|
|
6434
|
+
|
|
6435
|
+
|
|
5282
6436
|
def load_state_file(path: Path) -> WizardState:
|
|
5283
|
-
|
|
5284
|
-
|
|
6437
|
+
source_path = Path(path)
|
|
6438
|
+
source = source_path.read_bytes()
|
|
6439
|
+
data = json.loads(source)
|
|
6440
|
+
source_version = data.get("executionIdentityVersion", 1)
|
|
6441
|
+
source_metadata = _legacy_source_metadata(source_path, source)
|
|
6442
|
+
source_digest = source_metadata["sha256"]
|
|
6443
|
+
resumed_state = None
|
|
6444
|
+
companion_path = None
|
|
6445
|
+
if source_version in (None, 1):
|
|
6446
|
+
content_paths = _content_addressed_v2_companion_paths(
|
|
6447
|
+
source_path,
|
|
6448
|
+
source_digest,
|
|
6449
|
+
)
|
|
6450
|
+
resumed_state, companion_path = _load_matching_v2_state(
|
|
6451
|
+
content_paths,
|
|
6452
|
+
source_metadata,
|
|
6453
|
+
)
|
|
6454
|
+
if resumed_state is None:
|
|
6455
|
+
resumed_state, _ = _load_matching_v2_state(
|
|
6456
|
+
(_legacy_v2_companion_path(source_path),),
|
|
6457
|
+
source_metadata,
|
|
6458
|
+
)
|
|
6459
|
+
state = resumed_state or WizardState.from_json(data)
|
|
6460
|
+
state._source_execution_identity_version = source_version
|
|
6461
|
+
if source_version in (None, 1):
|
|
6462
|
+
state._legacy_source_metadata = source_metadata
|
|
6463
|
+
state._v2_companion_path = companion_path or _available_v2_companion_path(
|
|
6464
|
+
source_path,
|
|
6465
|
+
source_digest,
|
|
6466
|
+
)
|
|
6467
|
+
return state
|
|
6468
|
+
|
|
6469
|
+
|
|
6470
|
+
def _save_resumed_state_file(path: Path, state: WizardState) -> None:
|
|
6471
|
+
"""Persist native v2 state while keeping legacy resume sources read-only."""
|
|
6472
|
+
if getattr(state, "_source_execution_identity_version", 2) in (None, 1):
|
|
6473
|
+
payload = state.to_json()
|
|
6474
|
+
payload[_LEGACY_SOURCE_FIELD] = state._legacy_source_metadata
|
|
6475
|
+
write_json_atomic(state._v2_companion_path, payload)
|
|
6476
|
+
return
|
|
6477
|
+
save_state_file(path, state)
|
|
5285
6478
|
|
|
5286
6479
|
|
|
5287
6480
|
def save_state_file(path: Path, state: WizardState) -> None:
|
|
5288
|
-
Path(path).
|
|
5289
|
-
json.dumps(state.to_json(), indent=2, ensure_ascii=False),
|
|
5290
|
-
encoding="utf-8",
|
|
5291
|
-
)
|
|
6481
|
+
write_json_atomic(Path(path), state.to_json())
|
|
5292
6482
|
|
|
5293
6483
|
|
|
5294
6484
|
# ---- CLI entrypoint -----------------------------------------------------
|
|
@@ -5366,6 +6556,7 @@ def _cli(argv: list[str]) -> int:
|
|
|
5366
6556
|
|
|
5367
6557
|
if args.cmd == "step":
|
|
5368
6558
|
state = load_state_file(state_path)
|
|
6559
|
+
persisted_state = copy.deepcopy(state)
|
|
5369
6560
|
if args.no_submit and args.answer is not None:
|
|
5370
6561
|
print(json.dumps(
|
|
5371
6562
|
{"ok": False, "error": "--no-submit and --answer are mutually exclusive"},
|
|
@@ -5390,7 +6581,7 @@ def _cli(argv: list[str]) -> int:
|
|
|
5390
6581
|
else:
|
|
5391
6582
|
result = submit(state, args.answer)
|
|
5392
6583
|
except WizardError as exc:
|
|
5393
|
-
|
|
6584
|
+
_save_resumed_state_file(state_path, persisted_state)
|
|
5394
6585
|
try:
|
|
5395
6586
|
current = prompt_payload(state, next_prompt(state))
|
|
5396
6587
|
except WizardError:
|
|
@@ -5402,7 +6593,7 @@ def _cli(argv: list[str]) -> int:
|
|
|
5402
6593
|
print(json.dumps({"ok": False, "error": str(exc), "current": current},
|
|
5403
6594
|
ensure_ascii=False, indent=2))
|
|
5404
6595
|
return 0
|
|
5405
|
-
|
|
6596
|
+
_save_resumed_state_file(state_path, state)
|
|
5406
6597
|
print(json.dumps({"ok": True, **result}, ensure_ascii=False, indent=2))
|
|
5407
6598
|
return 0
|
|
5408
6599
|
|