codex-workflow-v2 2.0.0-beta.13.1 → 2.0.0-beta.13.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -1
- package/dist/reviewer-runtime-build.json +17 -13
- package/dist/src/alpha6/remediation.d.ts +1 -0
- package/dist/src/alpha6/remediation.js +12 -3
- package/dist/src/alpha6/remediation.js.map +1 -1
- package/dist/src/cli-actions.d.ts +1 -1
- package/dist/src/cli-actions.js +3 -0
- package/dist/src/cli-actions.js.map +1 -1
- package/dist/src/cli.js +15 -0
- package/dist/src/cli.js.map +1 -1
- package/dist/src/gateway-handshake.js +1 -0
- package/dist/src/gateway-handshake.js.map +1 -1
- package/dist/src/observed-routes.js +1 -0
- package/dist/src/observed-routes.js.map +1 -1
- package/dist/src/pending-review-update.d.ts +49 -0
- package/dist/src/pending-review-update.js +132 -0
- package/dist/src/pending-review-update.js.map +1 -0
- package/dist/src/repository.js +16 -4
- package/dist/src/repository.js.map +1 -1
- package/dist/src/reviewer.js +4 -1
- package/dist/src/reviewer.js.map +1 -1
- package/dist/src/state/corrective-yield-executor.js +10 -1
- package/dist/src/state/corrective-yield-executor.js.map +1 -1
- package/dist/src/version.d.ts +1 -1
- package/dist/src/version.js +1 -1
- package/dist/src/workflow.d.ts +10 -0
- package/dist/src/workflow.js +161 -8
- package/dist/src/workflow.js.map +1 -1
- package/docs/beta13.2-signal-review-recovery.md +38 -0
- package/docs/pdf/codex-workflow-v2-architecture-ru.pdf +0 -0
- package/docs/pdf/codex-workflow-v2-chat-only-guide-ru.pdf +0 -0
- package/docs/pdf/codex-workflow-v2-technical-reference-ru.pdf +0 -0
- package/docs/pdf/sources/codex-workflow-v2-architecture-ru.md +1 -1
- package/docs/pdf/sources/codex-workflow-v2-chat-only-guide-ru.md +2 -2
- package/docs/pdf/sources/codex-workflow-v2-technical-reference-ru.md +3 -3
- package/docs/pending-review-update.md +15 -0
- package/docs/release.md +27 -2
- package/docs/updating-existing-project.md +10 -2
- package/package.json +1 -1
- package/plugins/codex-workflow-gateway/references/chat-dispatch.md +128 -0
- package/plugins/codex-workflow-gateway/references/protocol.md +11 -0
- package/plugins/codex-workflow-gateway/scripts/chat-dispatch.mjs +185 -0
- package/plugins/codex-workflow-gateway/scripts/chat-model-policy.mjs +43 -0
- package/plugins/codex-workflow-gateway/scripts/chat-registry.mjs +50 -3
- package/plugins/codex-workflow-gateway/skills/codex-workflow-gateway/SKILL.md +64 -17
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
# beta.13.2: pending-review recovery
|
|
2
|
+
|
|
3
|
+
## Confirmed failure
|
|
4
|
+
|
|
5
|
+
Signal M04 T01 completed the product changes for STEP-002 on beta.13.1, but its
|
|
6
|
+
required independent Step review could not be prepared. The cumulative Task diff
|
|
7
|
+
was 2,236,058 bytes, exceeding the default synchronous Git output buffer. The
|
|
8
|
+
checkout remained clean and the completion commit remained recorded; review had
|
|
9
|
+
not passed.
|
|
10
|
+
|
|
11
|
+
After the writer lease expired, repository navigation preferred delegated
|
|
12
|
+
Knowledge context refresh over the pending review's credential recovery. The
|
|
13
|
+
context-refresh executor correctly rejected the still-in-progress Step. Thus
|
|
14
|
+
navigation advertised an action its executor could not perform. Ordinary package
|
|
15
|
+
update was also blocked by the in-progress Step.
|
|
16
|
+
|
|
17
|
+
## Required recovery guarantees
|
|
18
|
+
|
|
19
|
+
- Large Step and final Task review inputs are complete or fail explicitly; Git
|
|
20
|
+
errors have bounded diagnostics rather than dumping the input corpus.
|
|
21
|
+
- Pending review and its exact writer credential recovery remain ahead of
|
|
22
|
+
Knowledge refresh. Refresh during a running Step stays forbidden.
|
|
23
|
+
- Installation recovery validates the source version, exact Task/Plan/Step and
|
|
24
|
+
completion commit, clean checkout, recorded Git history, review journal, and
|
|
25
|
+
absence of active ownership or transactions.
|
|
26
|
+
- Dependency transport preserves product bytes and the original reviewed commit.
|
|
27
|
+
Pending review never establishes passed-review provenance.
|
|
28
|
+
- The original required review, delegated context refresh, Task acceptance and
|
|
29
|
+
merge remain mandatory after recovery. Grants are not broadened or renewed.
|
|
30
|
+
|
|
31
|
+
## Release acceptance
|
|
32
|
+
|
|
33
|
+
The package regression suite must cover oversized review inputs and the combined
|
|
34
|
+
pending-review, expired-lease and stale-Knowledge state, including rejection of
|
|
35
|
+
unsafe recovery candidates. Release validation also requires the ordinary package
|
|
36
|
+
and external-review lifecycle gates. Actual Signal recovery must pass the blocked
|
|
37
|
+
Step review and reach a subsequent executable lifecycle boundary; green fixture
|
|
38
|
+
tests alone do not establish that the production Milestone has resumed.
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
@@ -463,7 +463,7 @@ Restart Docker Desktop требует отдельного разрешения
|
|
|
463
463
|
# 10. Operational checklist
|
|
464
464
|
|
|
465
465
|
- exact package version установлен, bundled gateway соответствует release и переустановлен;
|
|
466
|
-
- handshake подтверждает `packageVersion=2.0.0-beta.13.
|
|
466
|
+
- handshake подтверждает `packageVersion=2.0.0-beta.13.3`, protocol 2, state schema 2 и beta.13
|
|
467
467
|
capabilities;
|
|
468
468
|
- routine observation начинается с компактного `status`; `status --full` запрашивается только для
|
|
469
469
|
расследования, которому действительно нужна полная historical projection;
|
|
@@ -57,7 +57,7 @@ AGENTS.md
|
|
|
57
57
|
-> doctor только как дополнительная диагностика
|
|
58
58
|
```
|
|
59
59
|
|
|
60
|
-
Handshake beta.13.1 должен сообщать `packageVersion=2.0.0-beta.13.
|
|
60
|
+
Handshake beta.13.1 должен сообщать `packageVersion=2.0.0-beta.13.3`, `protocolVersion=2`,
|
|
61
61
|
`stateSchemaVersion=2`, dependency DAG, initial Plan transaction, mechanical feasibility,
|
|
62
62
|
Milestone autonomy, host-safe credential reference, failed-Step continuation transaction,
|
|
63
63
|
cause-bound rolling refinement, structural production edge, compact status, reviewer runtime preflight,
|
|
@@ -482,7 +482,7 @@ Task/project DGR. `dependencyBinding` для standalone handoff равен null.
|
|
|
482
482
|
# 14. Итоговый checklist пользователя
|
|
483
483
|
|
|
484
484
|
- beta.13.1 exact package и новый bundled gateway установлены; handshake показывает
|
|
485
|
-
`packageVersion=2.0.0-beta.13.
|
|
485
|
+
`packageVersion=2.0.0-beta.13.3`, protocol/state schema `2/2` и beta.13 capabilities;
|
|
486
486
|
- новый Coordinator chat не является fork старого Milestone;
|
|
487
487
|
- bootstrap DGR, если нужен, выдан отдельным exact human confirmation;
|
|
488
488
|
- Discovery не materialized при blocking unknowns;
|
|
@@ -15,7 +15,7 @@ authority сами: mutating permission определяется runtime state
|
|
|
15
15
|
|
|
16
16
|
| Параметр beta.13 | Значение |
|
|
17
17
|
|---|---|
|
|
18
|
-
| npm package | `codex-workflow-v2@2.0.0-beta.13.
|
|
18
|
+
| npm package | `codex-workflow-v2@2.0.0-beta.13.3` |
|
|
19
19
|
| protocolVersion | 2 |
|
|
20
20
|
| stateSchemaVersion | 2 |
|
|
21
21
|
| lifecycle epoch | 2 |
|
|
@@ -333,7 +333,7 @@ local reviewer внутри Codex App sandbox.
|
|
|
333
333
|
| Повтор stable reviewer `causeId` с `planConflict=true` | Root-cause replan той же Task обязателен |
|
|
334
334
|
| Похожий prose, номер попытки или reviewer cause без Plan conflict | Не создаёт replan authority |
|
|
335
335
|
| Finding `route=fix` или route отсутствует | Продолжить ту же Task/Step независимо от attempt count |
|
|
336
|
-
| Finding `route=replan` с exact Plan conflict |
|
|
336
|
+
| Finding `route=replan` с exact Plan conflict, включая первый провал | Штатный corrective yield/replan; повторный run запрещён, меняются только implementation Steps |
|
|
337
337
|
| `route=replan` без exact conflict | Невалидный review result, state не меняется |
|
|
338
338
|
| Explicit `split-required` | Structural replacement stop |
|
|
339
339
|
| Exact beta.11 attempt-four `stop-escalate` | Append-only Human-confirmed compatibility override |
|
|
@@ -767,7 +767,7 @@ dirty update.
|
|
|
767
767
|
observed-route matrix/compact-status/reviewer-runtime tests, legacy compatibility regressions,
|
|
768
768
|
`npm run test:signal-t10-check-support-e2e`, `npm run test:signal-remediation-e2e`,
|
|
769
769
|
`npm run pack:check`, `npm run smoke:downstream`, `npm run plugin:check`, official plugin/skill validators,
|
|
770
|
-
`npm run docs:pdf:check` и `npm run release:check` с exact `v2.0.0-beta.13.
|
|
770
|
+
`npm run docs:pdf:check` и `npm run release:check` с exact `v2.0.0-beta.13.3` tag binding и append-only
|
|
771
771
|
real-agent lifecycle log. Candidate проверяется из clean source checkout; missing built module не должен
|
|
772
772
|
превращаться в stack trace, а обязан быть детерминированно собран или диагностирован release gate.
|
|
773
773
|
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
# Updating while a strict Step review is pending
|
|
2
|
+
|
|
3
|
+
This narrow bridge supports source `codex-workflow-v2@2.0.0-beta.13.1` and the exact executing target package. It preserves the original completion commit, pending review chain, Plan and Knowledge authorization. It does not mark a review passed or bypass the following Knowledge refresh.
|
|
4
|
+
|
|
5
|
+
Use only a verified, exact target package runner with capability `pending-strict-review-dependency-bridge-v1`. The source preflight checks its package/build manifest and runtime file hashes. Never use a mutable version range or a global runner. The target runner exception before installation permits only the read-only source preflight below. Use the installed source runner for an explicitly returned stale lease repair.
|
|
6
|
+
|
|
7
|
+
1. Run the external target runner: `update pending-review-source-preflight --repo <repo> --id <Task> --json`. Save the complete JSON response outside the repository. If `staleLeaseRepair` names exactly this Task, use the **installed source** `locks repair --id <Task>` and rerun source preflight. The lock manager rechecks expiry; a live or unrelated lease is not repairable through this bridge. Do not transport until the fresh result has `eligible=true` and no blockers.
|
|
8
|
+
2. Retain the exact source receipt. Create one dependency transport commit on its `baseBranch` at `baseHead`, using a separate temporary worktree. Create one on `taskBranch` at `completionCommit`. Each commit must have one parent, change exactly `package.json` and `package-lock.json`, and change only the exact Workflow dependency entries from source to target. Preserve all product-owned manifest/lock fields independently on each branch. Do not merge, amend, reset, rebase, copy the base manifest over Task changes, or transport product work.
|
|
9
|
+
3. Install the exact target package in the Task repository. Use its repository-local runner for all remaining commands. Run `status`, then `next`; it must advertise `update pending-review-dependency-recover`. Run `update pending-review-dependency-preflight --id <Task> --file <source-receipt.json>`. Require `eligible=true` and no blockers.
|
|
10
|
+
4. Run `update pending-review-dependency-recover --id <Task> --expected-revision <source-task-revision> --file <source-receipt.json> --actor <coordinator> --reason <substantive-reason>`. Both plain preflight results and CLI `{ok:true,value:...}` receipts are accepted. The receipt is not authority: recovery reconstructs every source binding from canonical Task, artifacts, strict-review sidecars and Git parent commits. It checks clean checkout, all target version surfaces, exact base transport, and absence of any writer lease or pending transaction/Core operation again.
|
|
11
|
+
5. Recovery atomically registers the Task dependency commit in existing dependency provenance and writes the hash-chained `pending-review-updates.jsonl` sidecar. Task schema 2 is unchanged. It increments the Task revision but preserves the original pending event, product completion SHA and Step evidence. Repeating recovery is rejected rather than creating duplicate authority.
|
|
12
|
+
6. Run `status`, then `next`. Recover the exact advertised C1 writer credential if necessary. Generate a fresh `task step-review-packet`; use an independent external sealed reviewer and record the unchanged result with `task step-review-record`. The packet binds the original product commit and includes revalidated transport evidence; its repository seal binds the current dependency HEAD. Any later HEAD, base, Plan, evidence, packet, or seal change fails closed. Local nested review retains its original HEAD guard.
|
|
13
|
+
7. Follow fresh `status` and `next` after review. Under the original eligible Milestone Autonomy Grant, execute the advertised `task context-refresh` for predeclared supporting-source additions and dependency manifest drift. Then continue to the next normal Step or final Task boundary. Do not substitute standalone approval or manually edit state.
|
|
14
|
+
|
|
15
|
+
A failed preflight is a stop for this bridge. Repair only a specifically documented obstruction, then rerun the read-only assessment; never edit the receipt to hide a blocker. A pending or corrupt transaction must be recovered through its ordinary exact route before retrying.
|
package/docs/release.md
CHANGED
|
@@ -4,6 +4,31 @@ The npm package is `codex-workflow-v2` with public visibility. Consumers must pi
|
|
|
4
4
|
an exact version. Stable compatibility covers the latest minor release of the current
|
|
5
5
|
major only; older minors are unsupported unless a release note explicitly says otherwise.
|
|
6
6
|
|
|
7
|
+
## beta.13.3 explicit Plan conflict recovery
|
|
8
|
+
|
|
9
|
+
A first independently recorded reviewer `route=replan` with a validated Plan conflict
|
|
10
|
+
blocks current execution immediately and exposes corrective replan. Historical
|
|
11
|
+
rolling-cause classification remains unchanged; valid older histories are not
|
|
12
|
+
reclassified as corrupt. Ordinary new fix findings still continue in the same Task.
|
|
13
|
+
The failure transaction yields C1 and releases the exact writer lease. An older
|
|
14
|
+
failed Task with a retained C1 claim follows credential recovery and
|
|
15
|
+
`task corrective-yield` before planning; it cannot run or change its Plan while
|
|
16
|
+
the claim remains. Recovery binds the validated remediation event and preserves
|
|
17
|
+
the Task, review evidence, and existing worker identity.
|
|
18
|
+
The release also includes durable App dispatch and explicit role/phase model selection;
|
|
19
|
+
see the packaged `references/chat-dispatch.md`.
|
|
20
|
+
|
|
21
|
+
## beta.13.2 review recovery gate
|
|
22
|
+
|
|
23
|
+
The patch preserves protocol 2 and canonical entity schema 2. In addition to the
|
|
24
|
+
ordinary release gates, `release:check` executes the large-diff, pending-review
|
|
25
|
+
update, supporting-source refresh and Task guard regressions. Acceptance requires
|
|
26
|
+
complete external-sealed Step and Task packets above 2 MiB, explicit bounded
|
|
27
|
+
failure above the Git output limit, exact credential recovery before Knowledge
|
|
28
|
+
refresh, and a Signal-shaped delegated update followed by actual review,
|
|
29
|
+
context refresh and the next ordinary Step. A source preflight alone is not
|
|
30
|
+
recovery completion. See `beta13.2-signal-review-recovery.md`.
|
|
31
|
+
|
|
7
32
|
## Release gate
|
|
8
33
|
|
|
9
34
|
Before tagging a release:
|
|
@@ -52,8 +77,8 @@ surface and fails unless all of these release contracts remain present:
|
|
|
52
77
|
adds C1 yield before root-cause replan; the Signal-shaped E2E continues through recovery, the next
|
|
53
78
|
ordinary Step, Task completion, and next-Task dispatch;
|
|
54
79
|
- five distinct or unclassified review findings continue in the same Task without a numeric cap,
|
|
55
|
-
while
|
|
56
|
-
|
|
80
|
+
while repeated normalized mechanical failures still require root-cause replan; a current
|
|
81
|
+
explicit external reviewer Plan conflict requires replan immediately, without a synthetic retry;
|
|
57
82
|
- a transitive same-component check owner may refine the same Task only under the unchanged semantic
|
|
58
83
|
boundary; for a multi-Step `runtime-composition` consumer the independent PRA classification,
|
|
59
84
|
not a planner opt-in, requires an edge from a transitive owner to an exact executable consumer
|
|
@@ -636,8 +636,16 @@ title в registry readback и применяйте только возвращё
|
|
|
636
636
|
быть уникален и содержать exact `#NNN`, membership ordinal и ID. Input должен состоять из
|
|
637
637
|
TaskContextPacket; допустима только добавленная Codex App служебная `codex_delegation`-обёртка с
|
|
638
638
|
`source_thread_id`, но не parent turns или transcript. Если title отсутствует или нормализован
|
|
639
|
-
неверно, переименуйте и перепроверьте.
|
|
640
|
-
|
|
639
|
+
неверно, переименуйте и перепроверьте. Pending `clientThreadId`, тайм-аут или отсутствие в
|
|
640
|
+
`list_threads` не доказывают, что создание не состоялось, и не разрешают повторный `create_thread`.
|
|
641
|
+
До первого вызова сохраните `dispatch-begin`; после него используйте `dispatch-result/status`,
|
|
642
|
+
поиск коррелированного сеанса и `dispatch-observe` с фактическим `read_thread`. На одну
|
|
643
|
+
резервацию выдаётся только одно разрешение создания. Не обходите его новой резервацией или fork.
|
|
644
|
+
Полный контракт восстановления, сохранения supervisor/cursor и явного выбора `model`/`thinking`
|
|
645
|
+
по роли, фазе и сложности находится в
|
|
646
|
+
`plugins/codex-workflow-gateway/references/chat-dispatch.md`. Выбор модели требует соответствующего
|
|
647
|
+
поручения пользователя и актуального списка поддерживаемых пар на целевом host; нельзя молча
|
|
648
|
+
наследовать дорогую конфигурацию координатора или снижать уровень независимого аудита.
|
|
641
649
|
Создавайте или переиспользуйте Task-чат непосредственно перед dispatch этой Task, а не как пустой
|
|
642
650
|
placeholder для всего membership; `T<NN>` берите только из утверждённого membership order.
|
|
643
651
|
|
package/package.json
CHANGED
|
@@ -0,0 +1,128 @@
|
|
|
1
|
+
# Durable App dispatch and explicit model selection
|
|
2
|
+
|
|
3
|
+
This is an App orchestration journal, not Workflow authority. It does not call the App, approve
|
|
4
|
+
Git writes, renew grants, mint credentials, or replace Core status/next. All commands below use
|
|
5
|
+
`node <exact-package>/plugins/codex-workflow-gateway/scripts/chat-registry.mjs` and the existing
|
|
6
|
+
24-hex Workflow `--project-id`. The App project ID is a separate field.
|
|
7
|
+
|
|
8
|
+
## One reservation, one creation attempt
|
|
9
|
+
|
|
10
|
+
`allocate` reuses the same non-abandoned role/entity/membership/attempt reservation. Task and
|
|
11
|
+
Coordinator allocations also reuse it when a caller changes the attempt number. Review attempts
|
|
12
|
+
advance only after the actual Workflow review cycle advances. Never invent a new attempt or
|
|
13
|
+
reservation to bypass unresolved creation. Existing v1 registries remain readable; legacy bound
|
|
14
|
+
threads remain usable with explicit model/thinking arguments from the same policy; `model-select`
|
|
15
|
+
and `supervision-record` currently require a tracked dispatch and do not retrofit legacy evidence.
|
|
16
|
+
Legacy unbound reservations may have already created a chat: reconcile
|
|
17
|
+
those using real App/source evidence before using the new dispatch flow.
|
|
18
|
+
|
|
19
|
+
1. Save the closed context packet to a private local file. Do not include bearer credentials,
|
|
20
|
+
parent transcript, or approval narratives. Prepare a private dispatch request JSON:
|
|
21
|
+
|
|
22
|
+
```json
|
|
23
|
+
{
|
|
24
|
+
"repositoryRoot": "/absolute/canonical/repository",
|
|
25
|
+
"appProjectId": "project-id-from-list-projects",
|
|
26
|
+
"hostId": "local",
|
|
27
|
+
"promptFile": "/private/tmp/task-context.txt",
|
|
28
|
+
"modelRequest": {
|
|
29
|
+
"phase": "planning",
|
|
30
|
+
"complexity": "standard",
|
|
31
|
+
"highRisk": false,
|
|
32
|
+
"rationale": "New multi-file implementation plan with established requirements.",
|
|
33
|
+
"availableModels": [
|
|
34
|
+
{"id": "gpt-5.6-sol", "reasoningEfforts": ["low", "medium", "high", "xhigh", "max", "ultra"]}
|
|
35
|
+
]
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
Populate `availableModels` from the destination App tool's actual model/effort contract, not
|
|
41
|
+
this example, the parent's settings, API pricing pages, or a guessed alias. Explicit user
|
|
42
|
+
authorization to select models is required; journal input is not user authorization.
|
|
43
|
+
2. Run `dispatch-begin --reservation-id ID --file request.json` **before** `create_thread`.
|
|
44
|
+
Save its complete output to a mode-600 file. It atomically persists a creation marker, packet
|
|
45
|
+
hashes, repository binding and requested model selection, then returns `createAllowed:true`
|
|
46
|
+
and exact `createArgs` including `model` and App field `thinking`.
|
|
47
|
+
3. Only the process receiving that one permission may make **one** `create_thread(createArgs)`
|
|
48
|
+
call. A second begin, even after restart or timeout, returns `createAllowed:false` and no
|
|
49
|
+
create arguments. Do not reissue the external call after a lost/ambiguous response. The marker
|
|
50
|
+
prepended to the packet is routing provenance, not parent history.
|
|
51
|
+
4. Save the full App result locally, normalize its successful tool text JSON to
|
|
52
|
+
`{"result":{"clientThreadId":"client-new-thread:...","hostId":"local"}}` or
|
|
53
|
+
`{"result":{"threadId":"actual-uuid","hostId":"local"}}`, and run `dispatch-result`.
|
|
54
|
+
Preserve raw evidence separately. Never parse truncated displayed stdout as the full receipt.
|
|
55
|
+
Invalid JSON cannot change the journal. A pending client ID is never a usable thread ID.
|
|
56
|
+
5. Use `dispatch-status` to resume. Missing `list_threads` results are not proof of failure.
|
|
57
|
+
If the actual ID is unavailable, identify candidate rollout files from creation-time/worktree
|
|
58
|
+
evidence and run `dispatch-discover --file candidates.json`, where the file is
|
|
59
|
+
`{"sessionFiles":["/absolute/rollout.jsonl"]}`. The helper reads only supplied files, checks
|
|
60
|
+
actual session metadata, exact original dispatched prompt (including the App's routing XML),
|
|
61
|
+
and the Git common directory. It ignores guardian/subagent sessions and unrelated prompts.
|
|
62
|
+
It prints candidate IDs/paths only, never transcripts or reasoning. Use bounded candidate
|
|
63
|
+
lists, not vault searches. Malformed, oversized or partially written files need a later fresh
|
|
64
|
+
read; they never authorize another creation.
|
|
65
|
+
6. Confirm a correlated candidate using `read_thread`. Save its full response as
|
|
66
|
+
`{"observation": <parsed read_thread JSON>}` and run `dispatch-observe`. It checks actual UUID,
|
|
67
|
+
host, repository/worktree and App project when supplied. One candidate still requires App
|
|
68
|
+
readback; several candidates produce a duplicate conflict and require explicit disposition,
|
|
69
|
+
not arbitrary selection. After confirming one canonical child, inspect every other candidate,
|
|
70
|
+
reconcile any work it performed, and archive only idle duplicates. Record
|
|
71
|
+
`dispatch-resolve-duplicates` with `canonicalThreadId` and `dispositions`, one object per duplicate:
|
|
72
|
+
`{threadId, observation: <read_thread JSON>, archiveResult: {threadId, archived: true}}`.
|
|
73
|
+
Preserve the actual archive tool receipt; never fabricate it. Repeat canonical readback and bind.
|
|
74
|
+
Candidate history is retained and no creation permit is restored. This is a local evidence
|
|
75
|
+
check, not independent App attestation.
|
|
76
|
+
7. Run ordinary title `readback`/rename until exact match. After any rename, repeat
|
|
77
|
+
`dispatch-observe` with fresh App readback, then `readback` and `bind`. Binding a tracked
|
|
78
|
+
dispatch requires the same actual ID, host and observed title. Rebinding it to another child,
|
|
79
|
+
binding a client ID or sharing one child between reservations is rejected.
|
|
80
|
+
8. Run `supervision-record --file report.json` with `threadId`, `ownerThreadId`, `state`
|
|
81
|
+
(`active|attention|completed`), `cursor` and `nextAction`. Persist significant wait boundaries;
|
|
82
|
+
only that supervisor waits for this child. The journal stores routing state, not a Workflow
|
|
83
|
+
verdict. Do not put secrets, CREFs or confirmation codes in it. On restart, read the child and
|
|
84
|
+
fresh Core status/next before continuing. Worker reports stay local; the coordinator pulls.
|
|
85
|
+
|
|
86
|
+
A crash between durable begin and actual submission is deliberately ambiguous. There is no
|
|
87
|
+
App idempotency-key API here, so this provides **at most one create permit per reservation**,
|
|
88
|
+
not an exactly-once guarantee. Never clear the marker, abandon it, or expire it by time to retry.
|
|
89
|
+
If no positive creation evidence can be found, report that exact unresolved App operation. A
|
|
90
|
+
permission denial is a separate real gate; do not reroute it through another chat. Fresh user
|
|
91
|
+
approval does not establish that an ambiguous prior creation never happened.
|
|
92
|
+
|
|
93
|
+
## Model matrix
|
|
94
|
+
|
|
95
|
+
The versioned policy is `scripts/chat-model-policy.mjs`. It expresses a conservative relative
|
|
96
|
+
cost/latency preference, not measured savings or guaranteed account availability:
|
|
97
|
+
|
|
98
|
+
| Work | Preferred model | App thinking | Compatible fallback |
|
|
99
|
+
| --- | --- | --- | --- |
|
|
100
|
+
| Routine mechanical transitions, formatting, retrieval | gpt-5.4-mini | low | gpt-5.6-luna / low |
|
|
101
|
+
| Coordinator supervision; small implementation | gpt-5.6-luna | medium | gpt-5.6-terra / medium |
|
|
102
|
+
| Standard implementation | gpt-5.6-terra | medium | gpt-5.6-sol / medium |
|
|
103
|
+
| Task planning | gpt-5.6-sol | medium | gpt-6-astra / medium |
|
|
104
|
+
| Routine Step review | gpt-5.6-terra | medium | gpt-5.6-sol / medium |
|
|
105
|
+
| Standard Step review, final review, plan/corrective audit | gpt-5.6-sol | high | gpt-6-astra / high |
|
|
106
|
+
| Complex work or high risk, any role | gpt-6-astra | high | gpt-5.6-sol / high |
|
|
107
|
+
|
|
108
|
+
`routine` means a small, well-specified change or mechanical action with an existing check;
|
|
109
|
+
`standard` is ordinary multi-file work; `complex` covers new architecture, unresolved concurrency,
|
|
110
|
+
recovery/provenance or distributed state. Mark `highRisk` for authorization, security-sensitive
|
|
111
|
+
paths, data-loss exposure or irreversible migrations. The coordinator records the concrete
|
|
112
|
+
rationale; classification is a human/agent judgment, not an automatic risk detector. Unknown
|
|
113
|
+
complexity is not routine. Review/audit role floors override a falsely mechanical phase. No
|
|
114
|
+
automatic xhigh/max/ultra, and no escalation merely because a review failed or a tool timed out.
|
|
115
|
+
|
|
116
|
+
The policy chooses only a listed supported pair. If neither preferred nor fallback pair is
|
|
117
|
+
available, stop selection rather than silently inheriting the coordinator or lowering the review
|
|
118
|
+
floor. API docs explain the reasoning/latency tradeoff, while App availability and accepted field
|
|
119
|
+
names come from the live App tool contract:
|
|
120
|
+
https://developers.openai.com/api/docs/guides/latest-model
|
|
121
|
+
|
|
122
|
+
For a phase change in an existing bound chat, call `model-select` with its same `threadId` and
|
|
123
|
+
fresh `modelRequest`; copy the returned `followUpArgs` into `send_message_to_thread` with the
|
|
124
|
+
closed follow-up prompt. For example, planning uses Sol/medium, implementation Terra/medium,
|
|
125
|
+
then mechanical lifecycle work Mini/low. Do not create another Task just to switch model.
|
|
126
|
+
Keep the previous selection unless the phase/risk/scope changes materially. The journal records
|
|
127
|
+
requested settings; tool acceptance/runtime readback, when available, is required to claim the
|
|
128
|
+
actual model used. A model change never changes role, scope, credentials or approval authority.
|
|
@@ -56,10 +56,21 @@
|
|
|
56
56
|
A provenance recovery recorded after the final context-refresh audit may explain exactly one
|
|
57
57
|
additional Task revision only when it belongs to that verified Git chain. Any unexplained
|
|
58
58
|
revision remains a `doctor` boundary.
|
|
59
|
+
- Before a credential-consuming mutation, check the public `writerCredentialReference.expiresAt`
|
|
60
|
+
against the current time and its actor/action binding. Lease heartbeat or renewal does not
|
|
61
|
+
extend that reference's expiry. An expired, missing, consumed or unverifiable reference requires
|
|
62
|
+
the simultaneously advertised `next.writerCredentialRecovery` action with its exact Task,
|
|
63
|
+
revision and `requiredActor`, followed by fresh `status` and `next`; use the new reference.
|
|
64
|
+
If no recovery is advertised, stop before mutation. Never read or patch the vault, extend expiry
|
|
65
|
+
manually, or reuse the old reference. This check also applies after independent reviews and pauses.
|
|
59
66
|
- `milestone progress --id <MS-ID>` is a read-only projection and the sole source for Coordinator
|
|
60
67
|
progress tables. It preserves cancelled/replacement Tasks as distinct membership rows.
|
|
61
68
|
- `scripts/chat-registry.mjs` atomically allocates project-monotonic `#NNN`, builds all six title
|
|
62
69
|
families, verifies exact readback, supplies deterministic fallbacks, and binds the verified chat.
|
|
70
|
+
It also journals a single creation permit, pending/actual IDs, evidence-based resolution and
|
|
71
|
+
supervision cursors. Missing App listings never permit a retry. See `chat-dispatch.md` for
|
|
72
|
+
dispatch commands and the explicit role/phase model + thinking policy. These are App routing
|
|
73
|
+
helpers; they do not change Workflow protocol/state schema or grant approval authority.
|
|
63
74
|
|
|
64
75
|
## Handshake
|
|
65
76
|
|
|
@@ -0,0 +1,185 @@
|
|
|
1
|
+
import { createHash, randomUUID } from 'node:crypto';
|
|
2
|
+
import { readFileSync, realpathSync, statSync } from 'node:fs';
|
|
3
|
+
import { execFileSync } from 'node:child_process';
|
|
4
|
+
import path from 'node:path';
|
|
5
|
+
import { selectChatModel } from './chat-model-policy.mjs';
|
|
6
|
+
|
|
7
|
+
const hash = text => createHash('sha256').update(text).digest('hex');
|
|
8
|
+
const text = (value, name) => {
|
|
9
|
+
if (typeof value !== 'string' || !value.trim()) throw new Error(`${name} is required.`);
|
|
10
|
+
return value.trim();
|
|
11
|
+
};
|
|
12
|
+
const actualId = value => {
|
|
13
|
+
const id = text(value, 'actual threadId');
|
|
14
|
+
if (!/^[0-9a-f]{8}(?:-[0-9a-f]{4}){3}-[0-9a-f]{12}$/i.test(id)) throw new Error('Expected actual thread UUID, not clientThreadId.');
|
|
15
|
+
return id;
|
|
16
|
+
};
|
|
17
|
+
function jsonFile(file) {
|
|
18
|
+
if (statSync(file).size > 16 * 1024 * 1024) throw new Error('Input file exceeds 16 MiB.');
|
|
19
|
+
return JSON.parse(readFileSync(file, 'utf8'));
|
|
20
|
+
}
|
|
21
|
+
function commonGitDir(cwd) {
|
|
22
|
+
return realpathSync(execFileSync('git', ['rev-parse', '--path-format=absolute', '--git-common-dir'], {
|
|
23
|
+
cwd, encoding: 'utf8', timeout: 5000, maxBuffer: 1024 * 1024,
|
|
24
|
+
}).trim());
|
|
25
|
+
}
|
|
26
|
+
function promptMatches(value, digest) {
|
|
27
|
+
if (typeof value !== 'string') return false;
|
|
28
|
+
if (hash(value) === digest) return true;
|
|
29
|
+
const wrapped = /^<codex_delegation>\s*<source_thread_id>[^<]+<\/source_thread_id>\s*<input>([\s\S]*)<\/input>\s*<\/codex_delegation>$/.exec(value);
|
|
30
|
+
return wrapped !== null && hash(wrapped[1]) === digest;
|
|
31
|
+
}
|
|
32
|
+
function view(entry) {
|
|
33
|
+
const d = entry.dispatch;
|
|
34
|
+
return {
|
|
35
|
+
reservationId: entry.reservationId, state: d?.state ?? (entry.threadId ? 'legacy-bound' : 'untracked'),
|
|
36
|
+
createAllowed: false, dispatchId: d?.id ?? null, clientThreadId: d?.clientThreadId ?? null,
|
|
37
|
+
threadId: entry.threadId ?? d?.candidateThreadId ?? null, hostId: d?.hostId ?? entry.hostId ?? null,
|
|
38
|
+
selection: d?.selection ?? null, supervision: d?.supervision ?? null,
|
|
39
|
+
candidates: d?.candidates ?? [],
|
|
40
|
+
nextAction: entry.threadId ? 'supervise-existing' : d?.state === 'resolved' ? 'title-readback-and-bind'
|
|
41
|
+
: d ? 'resolve-existing-creation' : 'dispatch-begin',
|
|
42
|
+
};
|
|
43
|
+
}
|
|
44
|
+
export function dispatchAction(action, entry, input = {}) {
|
|
45
|
+
if (action === 'dispatch-status') return view(entry);
|
|
46
|
+
if (action === 'dispatch-begin') {
|
|
47
|
+
// A durable marker is committed BEFORE the external call. Even a lost response never permits another call.
|
|
48
|
+
if (entry.dispatch || entry.threadId) return view(entry);
|
|
49
|
+
if (entry.status === 'abandoned' || entry.status === 'blocked') throw new Error('Reservation is not dispatchable.');
|
|
50
|
+
const repositoryRoot = realpathSync(text(input.repositoryRoot, 'repositoryRoot'));
|
|
51
|
+
const gitDir = commonGitDir(repositoryRoot);
|
|
52
|
+
const appProjectId = text(input.appProjectId, 'appProjectId');
|
|
53
|
+
const hostId = text(input.hostId, 'hostId');
|
|
54
|
+
const promptPath = realpathSync(text(input.promptFile, 'promptFile'));
|
|
55
|
+
if (statSync(promptPath).size > 1024 * 1024) throw new Error('TaskContextPacket exceeds 1 MiB.');
|
|
56
|
+
const prompt = readFileSync(promptPath, 'utf8');
|
|
57
|
+
if (!prompt.trim() || !prompt.includes(entry.entityId)) throw new Error('Prompt must include the exact entity ID.');
|
|
58
|
+
const selection = selectChatModel(entry.type, input.modelRequest);
|
|
59
|
+
const id = randomUUID();
|
|
60
|
+
const marker = `[workflow-dispatch:${id}:${hash(prompt)}]`;
|
|
61
|
+
const dispatchedPrompt = `${marker}\n${prompt}`;
|
|
62
|
+
entry.dispatch = {
|
|
63
|
+
version: 1, id, state: 'creating', appProjectId, hostId, repositoryRoot, gitDir,
|
|
64
|
+
promptPath, promptHash: hash(prompt), dispatchedPromptHash: hash(dispatchedPrompt), marker,
|
|
65
|
+
selection, selectionHistory: [selection], clientThreadId: null, candidateThreadId: null,
|
|
66
|
+
candidates: [], observations: [], createdAt: new Date().toISOString(),
|
|
67
|
+
};
|
|
68
|
+
return { ...view(entry), createAllowed: true, nextAction: 'create-thread-once', createArgs: {
|
|
69
|
+
target: { type: 'project', projectId: appProjectId, environment: { type: 'worktree' } },
|
|
70
|
+
title: entry.requestedTitle, prompt: dispatchedPrompt, model: selection.model, thinking: selection.thinking,
|
|
71
|
+
} };
|
|
72
|
+
}
|
|
73
|
+
const d = entry.dispatch;
|
|
74
|
+
if (!d) throw new Error('No tracked dispatch; reconcile legacy chats manually, never assume creation failed.');
|
|
75
|
+
if (action === 'dispatch-result') {
|
|
76
|
+
const result = input.result;
|
|
77
|
+
if (!result || result.hostId !== d.hostId) throw new Error('Create result host mismatch.');
|
|
78
|
+
if (result.threadId && result.clientThreadId) throw new Error('Ambiguous create result.');
|
|
79
|
+
if (result.threadId) {
|
|
80
|
+
const id = actualId(result.threadId);
|
|
81
|
+
if (d.candidateThreadId && d.candidateThreadId !== id) throw new Error('Conflicting actual thread IDs.');
|
|
82
|
+
d.candidateThreadId = id;
|
|
83
|
+
} else {
|
|
84
|
+
const id = text(result.clientThreadId, 'clientThreadId');
|
|
85
|
+
if (!id.startsWith('client-new-thread:')) throw new Error('Invalid pending clientThreadId.');
|
|
86
|
+
if (d.clientThreadId && d.clientThreadId !== id) throw new Error('Conflicting creation attempts; reconcile duplicates.');
|
|
87
|
+
d.clientThreadId = id;
|
|
88
|
+
}
|
|
89
|
+
if (d.state === 'creating') d.state = 'pending';
|
|
90
|
+
return view(entry);
|
|
91
|
+
}
|
|
92
|
+
if (action === 'dispatch-discover') {
|
|
93
|
+
// Read only specifically supplied session files; never scan credential stores or print transcripts/reasoning.
|
|
94
|
+
if (!Array.isArray(input.sessionFiles) || input.sessionFiles.length > 200) throw new Error('Supply at most 200 candidate session files.');
|
|
95
|
+
const found = new Map(d.candidates.map(c => [c.threadId, c]));
|
|
96
|
+
for (const file of input.sessionFiles) {
|
|
97
|
+
if (statSync(file).size > 16 * 1024 * 1024) throw new Error('Session exceeds 16 MiB; narrow evidence required.');
|
|
98
|
+
const lines = readFileSync(file, 'utf8').split('\n');
|
|
99
|
+
const meta = JSON.parse(lines[0]).payload;
|
|
100
|
+
if (!meta || !['vscode', 'cli'].includes(meta.source) || typeof meta.cwd !== 'string') continue;
|
|
101
|
+
const rows = lines.slice(1).filter(Boolean).map(line => JSON.parse(line));
|
|
102
|
+
const bound = rows.some(row => {
|
|
103
|
+
if (row.type !== 'response_item') return false;
|
|
104
|
+
const p = row.payload;
|
|
105
|
+
// Actual App rollout format: a create_thread function output containing routing-only XML.
|
|
106
|
+
if (p?.type === 'function_call_output' && p.name === 'create_thread' && p.namespace === 'codex_app') {
|
|
107
|
+
return promptMatches(p.output, d.dispatchedPromptHash);
|
|
108
|
+
}
|
|
109
|
+
return p?.type === 'message' && p.role === 'user' && p.content?.some(c =>
|
|
110
|
+
['input_text', 'text'].includes(c.type) && promptMatches(c.text, d.dispatchedPromptHash));
|
|
111
|
+
});
|
|
112
|
+
if (!bound) continue;
|
|
113
|
+
if (commonGitDir(meta.cwd) !== d.gitDir) throw new Error('Session belongs to another repository.');
|
|
114
|
+
const id = actualId(meta.id);
|
|
115
|
+
found.set(id, { threadId: id, cwd: realpathSync(meta.cwd), sourceFile: realpathSync(file) });
|
|
116
|
+
}
|
|
117
|
+
d.candidates = [...found.values()];
|
|
118
|
+
if (d.candidates.length > 1) d.state = 'duplicate-conflict';
|
|
119
|
+
return view(entry);
|
|
120
|
+
}
|
|
121
|
+
if (action === 'dispatch-resolve-duplicates') {
|
|
122
|
+
const canonical = actualId(input.canonicalThreadId);
|
|
123
|
+
if (entry.threadId && entry.threadId !== canonical) throw new Error('Cannot replace a bound child.');
|
|
124
|
+
if (d.candidateThreadId && d.candidateThreadId !== canonical) throw new Error('Cannot replace the correlated create result.');
|
|
125
|
+
if (!d.candidates.some(c => c.threadId === canonical)) throw new Error('Canonical child must be a discovered candidate.');
|
|
126
|
+
const others = d.candidates.filter(c => c.threadId !== canonical);
|
|
127
|
+
if (!others.length || !Array.isArray(input.dispositions) || input.dispositions.length !== others.length) {
|
|
128
|
+
throw new Error('Require one idle readback and archive receipt for every duplicate.');
|
|
129
|
+
}
|
|
130
|
+
const receipts = others.map(candidate => {
|
|
131
|
+
const matching = input.dispositions.filter(x => x?.threadId === candidate.threadId);
|
|
132
|
+
if (matching.length !== 1) throw new Error('Duplicate disposition missing or repeated.');
|
|
133
|
+
const item = matching[0];
|
|
134
|
+
const t = item.observation?.thread;
|
|
135
|
+
if (t?.id !== candidate.threadId || t.kind !== 'codex' || t.hostId !== d.hostId
|
|
136
|
+
|| t.status?.type !== 'idle' || realpathSync(text(t.cwd, 'duplicate cwd')) !== candidate.cwd
|
|
137
|
+
|| commonGitDir(t.cwd) !== d.gitDir || item.archiveResult?.threadId !== candidate.threadId
|
|
138
|
+
|| item.archiveResult?.archived !== true) throw new Error('Duplicate requires matching idle readback and successful archive receipt.');
|
|
139
|
+
return { threadId: candidate.threadId, archived: true, recordedAt: new Date().toISOString() };
|
|
140
|
+
});
|
|
141
|
+
d.duplicateDisposition = { canonicalThreadId: canonical, archived: receipts };
|
|
142
|
+
d.state = 'pending';
|
|
143
|
+
return view(entry);
|
|
144
|
+
}
|
|
145
|
+
if (action === 'dispatch-observe') {
|
|
146
|
+
const observation = input.observation;
|
|
147
|
+
const t = observation?.thread;
|
|
148
|
+
if (!t || t.kind !== 'codex' || t.hostId !== d.hostId) throw new Error('Require actual Codex read_thread observation on the bound host.');
|
|
149
|
+
const id = actualId(t.id);
|
|
150
|
+
if (d.candidates.length > 1 && (d.duplicateDisposition?.canonicalThreadId !== id
|
|
151
|
+
|| d.candidates.some(c => c.threadId !== id && !d.duplicateDisposition.archived.some(a => a.threadId === c.threadId)))) {
|
|
152
|
+
throw new Error('Multiple candidates: explicit duplicate disposition required before binding.');
|
|
153
|
+
}
|
|
154
|
+
const candidate = d.candidates.find(c => c.threadId === id);
|
|
155
|
+
if (id !== d.candidateThreadId && !candidate) throw new Error('Uncorrelated thread; require create result or exact session prompt evidence.');
|
|
156
|
+
if (commonGitDir(text(t.cwd, 'thread cwd')) !== d.gitDir
|
|
157
|
+
|| (candidate && realpathSync(t.cwd) !== candidate.cwd)) throw new Error('Readback repository/cwd mismatch.');
|
|
158
|
+
if (t.projectId !== undefined && t.projectId !== d.appProjectId) throw new Error('Readback App project mismatch.');
|
|
159
|
+
if (d.candidateThreadId && d.candidateThreadId !== id) throw new Error('Readback differs from create result.');
|
|
160
|
+
d.candidateThreadId = id;
|
|
161
|
+
d.state = 'resolved';
|
|
162
|
+
d.observations.push({ threadId: id, hostId: t.hostId, cwd: realpathSync(t.cwd),
|
|
163
|
+
title: text(t.title, 'observed title'), observedAt: new Date().toISOString() });
|
|
164
|
+
return view(entry);
|
|
165
|
+
}
|
|
166
|
+
if (action === 'supervision-record') {
|
|
167
|
+
if (!entry.threadId || input.threadId !== entry.threadId || input.ownerThreadId === entry.threadId) throw new Error('Require bound child and separate supervisor.');
|
|
168
|
+
const owner = actualId(input.ownerThreadId);
|
|
169
|
+
if (d.supervision && d.supervision.ownerThreadId !== owner) throw new Error('Supervisor already assigned; no parallel wait owner.');
|
|
170
|
+
if (!['active', 'attention', 'completed'].includes(input.state)) throw new Error('Invalid supervision state.');
|
|
171
|
+
d.supervision = { ownerThreadId: owner, state: input.state, cursor: input.cursor == null ? null : text(input.cursor, 'cursor'),
|
|
172
|
+
nextAction: text(input.nextAction, 'nextAction'), updatedAt: new Date().toISOString() };
|
|
173
|
+
return view(entry);
|
|
174
|
+
}
|
|
175
|
+
if (action === 'model-select') {
|
|
176
|
+
if (!entry.threadId || input.threadId !== entry.threadId) throw new Error('Phase changes require the same bound thread.');
|
|
177
|
+
const selection = selectChatModel(entry.type, input.modelRequest);
|
|
178
|
+
d.selection = selection;
|
|
179
|
+
d.selectionHistory.push(selection);
|
|
180
|
+
return { ...view(entry), followUpArgs: { threadId: entry.threadId, hostId: entry.hostId,
|
|
181
|
+
model: selection.model, thinking: selection.thinking } };
|
|
182
|
+
}
|
|
183
|
+
throw new Error(`Unknown dispatch action: ${action}`);
|
|
184
|
+
}
|
|
185
|
+
export function dispatchInput(file) { return jsonFile(file); }
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
// Relative cost/latency policy, not a price list or an availability oracle.
|
|
2
|
+
export const MODEL_POLICY_VERSION = 'chat-model-policy-v1';
|
|
3
|
+
const PROFILES = {
|
|
4
|
+
mechanical: [['gpt-5.4-mini', 'low'], ['gpt-5.6-luna', 'low']],
|
|
5
|
+
scoped: [['gpt-5.6-luna', 'medium'], ['gpt-5.6-terra', 'medium']],
|
|
6
|
+
implementation: [['gpt-5.6-terra', 'medium'], ['gpt-5.6-sol', 'medium']],
|
|
7
|
+
planning: [['gpt-5.6-sol', 'medium'], ['gpt-6-astra', 'medium']],
|
|
8
|
+
review: [['gpt-5.6-sol', 'high'], ['gpt-6-astra', 'high']],
|
|
9
|
+
'scoped-review': [['gpt-5.6-terra', 'medium'], ['gpt-5.6-sol', 'medium']],
|
|
10
|
+
complex: [['gpt-6-astra', 'high'], ['gpt-5.6-sol', 'high']],
|
|
11
|
+
};
|
|
12
|
+
const TYPES = ['coordinator', 'task', 'step-review', 'final-review', 'corrective-audit', 'plan-audit'];
|
|
13
|
+
export function selectChatModel(type, request) {
|
|
14
|
+
if (!TYPES.includes(type)) throw new Error('Unknown chat type.');
|
|
15
|
+
if (!request || !['routine', 'standard', 'complex'].includes(request.complexity)
|
|
16
|
+
|| !['planning', 'implementation', 'mechanical', 'review', 'coordination'].includes(request.phase)
|
|
17
|
+
|| typeof request.rationale !== 'string' || !request.rationale.trim()
|
|
18
|
+
|| typeof request.highRisk !== 'boolean') throw new Error('Explicit phase, complexity, highRisk and rationale are required.');
|
|
19
|
+
if (!Array.isArray(request.availableModels) || request.availableModels.length === 0
|
|
20
|
+
|| request.availableModels.some(m => !m || typeof m.id !== 'string' || !Array.isArray(m.reasoningEfforts)
|
|
21
|
+
|| m.reasoningEfforts.some(e => typeof e !== 'string'))
|
|
22
|
+
|| new Set(request.availableModels.map(m => m.id)).size !== request.availableModels.length) {
|
|
23
|
+
throw new Error('Provide the destination host model/effort catalog; never infer availability.');
|
|
24
|
+
}
|
|
25
|
+
const reviewRole = type.endsWith('review') || type.endsWith('audit');
|
|
26
|
+
let profile;
|
|
27
|
+
if (request.highRisk || request.complexity === 'complex') profile = 'complex';
|
|
28
|
+
else if (type === 'step-review' && request.complexity === 'routine') profile = 'scoped-review';
|
|
29
|
+
else if (reviewRole || request.phase === 'review') profile = 'review';
|
|
30
|
+
else if (request.phase === 'planning') profile = 'planning';
|
|
31
|
+
else if (request.phase === 'mechanical') {
|
|
32
|
+
if (request.complexity !== 'routine') throw new Error('Mechanical phase requires routine complexity.');
|
|
33
|
+
profile = 'mechanical';
|
|
34
|
+
} else if (type === 'coordinator' || request.phase === 'coordination' || request.complexity === 'routine') profile = 'scoped';
|
|
35
|
+
else profile = 'implementation';
|
|
36
|
+
const selected = PROFILES[profile].find(([id, effort]) => request.availableModels.some(m => m.id === id && m.reasoningEfforts.includes(effort)));
|
|
37
|
+
if (!selected) throw new Error(`No supported model/effort for ${profile}; explicit policy revision required, never inherit coordinator settings.`);
|
|
38
|
+
return {
|
|
39
|
+
policyVersion: MODEL_POLICY_VERSION, profile, model: selected[0], thinking: selected[1],
|
|
40
|
+
phase: request.phase, complexity: request.complexity, highRisk: request.highRisk,
|
|
41
|
+
rationale: request.rationale.trim(), fallback: selected !== PROFILES[profile][0],
|
|
42
|
+
};
|
|
43
|
+
}
|