codex-workflow-v2 2.0.0-alpha.3 → 2.0.0-alpha.6

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.
Files changed (85) hide show
  1. package/README.md +104 -7
  2. package/dist/src/alpha6/adoption.d.ts +55 -0
  3. package/dist/src/alpha6/adoption.js +920 -0
  4. package/dist/src/alpha6/adoption.js.map +1 -0
  5. package/dist/src/alpha6/handoff.d.ts +39 -0
  6. package/dist/src/alpha6/handoff.js +975 -0
  7. package/dist/src/alpha6/handoff.js.map +1 -0
  8. package/dist/src/alpha6/journal.d.ts +30 -0
  9. package/dist/src/alpha6/journal.js +369 -0
  10. package/dist/src/alpha6/journal.js.map +1 -0
  11. package/dist/src/alpha6/milestone.d.ts +49 -0
  12. package/dist/src/alpha6/milestone.js +1049 -0
  13. package/dist/src/alpha6/milestone.js.map +1 -0
  14. package/dist/src/alpha6/plan-risk.d.ts +32 -0
  15. package/dist/src/alpha6/plan-risk.js +847 -0
  16. package/dist/src/alpha6/plan-risk.js.map +1 -0
  17. package/dist/src/alpha6/remediation.d.ts +20 -0
  18. package/dist/src/alpha6/remediation.js +748 -0
  19. package/dist/src/alpha6/remediation.js.map +1 -0
  20. package/dist/src/alpha6/review.d.ts +46 -0
  21. package/dist/src/alpha6/review.js +785 -0
  22. package/dist/src/alpha6/review.js.map +1 -0
  23. package/dist/src/alpha6/store-sidecars.d.ts +35 -0
  24. package/dist/src/alpha6/store-sidecars.js +281 -0
  25. package/dist/src/alpha6/store-sidecars.js.map +1 -0
  26. package/dist/src/cli.js +110 -23
  27. package/dist/src/cli.js.map +1 -1
  28. package/dist/src/contracts.d.ts +319 -1
  29. package/dist/src/delegation.d.ts +8 -0
  30. package/dist/src/delegation.js +155 -0
  31. package/dist/src/delegation.js.map +1 -0
  32. package/dist/src/git.js +2 -1
  33. package/dist/src/git.js.map +1 -1
  34. package/dist/src/index.d.ts +3 -0
  35. package/dist/src/index.js +1 -0
  36. package/dist/src/index.js.map +1 -1
  37. package/dist/src/reviewer.d.ts +6 -1
  38. package/dist/src/reviewer.js +145 -32
  39. package/dist/src/reviewer.js.map +1 -1
  40. package/dist/src/state/lock.d.ts +1 -0
  41. package/dist/src/state/lock.js +7 -1
  42. package/dist/src/state/lock.js.map +1 -1
  43. package/dist/src/state/store.d.ts +43 -1
  44. package/dist/src/state/store.js +140 -1
  45. package/dist/src/state/store.js.map +1 -1
  46. package/dist/src/ulid.d.ts +1 -1
  47. package/dist/src/ulid.js.map +1 -1
  48. package/dist/src/version.d.ts +1 -1
  49. package/dist/src/version.js +1 -1
  50. package/dist/src/workflow.d.ts +91 -13
  51. package/dist/src/workflow.js +1459 -76
  52. package/dist/src/workflow.js.map +1 -1
  53. package/docs/autonomy-guardrails.md +143 -0
  54. package/docs/decisions.md +30 -0
  55. package/docs/delegated-approval.md +189 -0
  56. package/docs/development-flow.md +53 -2
  57. package/docs/pdf/codex-workflow-v2-architecture-ru.pdf +426 -410
  58. package/docs/pdf/codex-workflow-v2-chat-only-guide-ru.pdf +778 -612
  59. package/docs/pdf/codex-workflow-v2-technical-reference-ru.pdf +526 -452
  60. package/docs/project-memory.md +7 -0
  61. package/docs/release.md +7 -0
  62. package/docs/updating-existing-project.md +141 -4
  63. package/docs/validation-report.md +47 -24
  64. package/package.json +1 -1
  65. package/plugins/codex-workflow-gateway/references/protocol.md +162 -5
  66. package/plugins/codex-workflow-gateway/skills/codex-workflow-gateway/SKILL.md +38 -3
  67. package/references/git-policy.md +5 -2
  68. package/references/state-machine.md +48 -0
  69. package/references/validation-and-review.md +28 -1
  70. package/roles/delivery-coordinator.md +11 -0
  71. package/roles/independent-reviewer.md +3 -0
  72. package/roles/technical-planner.md +7 -0
  73. package/roles/worker.md +4 -0
  74. package/schemas/adoption-posture-event.schema.json +129 -0
  75. package/schemas/authorization-event.schema.json +55 -0
  76. package/schemas/corrective-decision-event.schema.json +55 -0
  77. package/schemas/corrective-plan-audit.schema.json +20 -0
  78. package/schemas/delegation-grant.schema.json +69 -0
  79. package/schemas/milestone-scope-change-event.schema.json +68 -0
  80. package/schemas/milestone-transaction-journal.schema.json +95 -0
  81. package/schemas/plan-risk-audit-event.schema.json +90 -0
  82. package/schemas/remediation-event.schema.json +53 -0
  83. package/schemas/reviewer-attestation-event.schema.json +49 -0
  84. package/schemas/step-review-event.schema.json +74 -0
  85. package/schemas/task-handoff-event.schema.json +116 -0
package/docs/decisions.md CHANGED
@@ -50,3 +50,33 @@ This document closes the requirement gaps identified during the V2 design review
50
50
  evidence, and base HEAD. The gateway must end the turn after showing it, and the CLI accepts
51
51
  only an explicit actor and exact code from a later user-confirmed turn. This is state-bound
52
52
  consent, not cryptographic proof of human identity.
53
+ 10. **Delegated approval.** Human approval stays the default, but a principal may issue a
54
+ project-bound, expiring grant to a distinct delegate after a separate confirmation-code
55
+ turn. Grants allow only enumerated Knowledge Map, Task, or Milestone approval transitions
56
+ and are scoped to the project, one Milestone, or one Task. Each use records
57
+ both actors and the policy hash; revocation blocks future uses. This is an additive schema
58
+ 2 entity and optional authorization metadata, so existing schema 2 projects require no
59
+ migration. It is local policy evidence, not a cryptographic identity signature.
60
+ 11. **Core-owned Step commit.** `task run` dispatches a Worker that leaves changes
61
+ uncommitted. For an active Step, `next` returns the exact `task step-complete` transition
62
+ and Step ID. That transition validates history and allowed paths, runs checks, creates
63
+ the atomic commit, and records evidence. A manual Worker commit is unrecorded history and
64
+ fails closed without changing persisted Task state. This changes navigation and
65
+ diagnostics only; state schema 2 and protocol 1 remain unchanged.
66
+ 12. **Autonomous correction guardrail.** The initial Plan must make migration,
67
+ concurrency, restart/replay, crash-window, and provider risks visible. After two failed
68
+ independent reviews, another corrective Plan requires a distinct Auditor covering every
69
+ latest finding. The audit is append-only artifact evidence; no Task state field or schema
70
+ change is required.
71
+ 13. **Content-only context refresh.** A delegate may compose reconcile, approval, knowledge
72
+ rebind, and execution reauthorization only when the approved source classification is
73
+ identical and only content hashes changed. Core validates both delegated transitions
74
+ before writing. Source-set, category, scope, authority, gap, or conflict changes stay on
75
+ the ordinary visible approval path. State schema 2 and protocol 1 remain unchanged.
76
+ 14. **Autonomous chat and closure boundary.** A Milestone coordinator owns orchestration and
77
+ final acceptance while each required Task uses a dedicated user-visible Task chat.
78
+ `next` exposes the Milestone completion contract, and delegated acceptance retains the
79
+ delegate actor and exact state-bound MSA code.
80
+ 15. **Safe update preflight.** Dependency updates begin with a read-only preflight requiring
81
+ a clean checkout, no running Step, and no active writer lease. It does not install,
82
+ migrate, or mutate project state.
@@ -0,0 +1,189 @@
1
+ # Delegated Approval
2
+
3
+ Delegated approval is an optional local authority grant. It lets a named agent actor cross
4
+ selected Project Knowledge Map, Task, and Milestone approval transitions without pretending
5
+ to be the user. Human approval remains the default.
6
+
7
+ ## Policy and issuance
8
+
9
+ A policy contains:
10
+
11
+ - `principal`: the user audit identity;
12
+ - `delegate`: a distinct agent audit identity;
13
+ - `scope`: the current project, one Milestone, or one Task;
14
+ - `transitions`: an allow-list of Knowledge Map, Task, and Milestone approvals;
15
+ - `expiresAt`: a required future UTC timestamp.
16
+
17
+ `delegation prepare` normalizes the policy, hashes it with the local project ID, and returns
18
+ a deterministic `DGA-*` confirmation code. The gateway displays the complete binding and
19
+ ends the turn. `delegation grant` is permitted only after a later user message confirms the
20
+ same code. Duplicate issuance of the same exact policy is rejected.
21
+
22
+ ## Storage and compatibility
23
+
24
+ Each grant is an independently revisioned schema 2 entity at:
25
+
26
+ ```text
27
+ $CODEX_HOME/workflow-state/v2/projects/<project-id>/delegations/<DGR-ID>/state.json
28
+ ```
29
+
30
+ Existing schema 2 project, Task, Milestone, Knowledge Map, graph, and authorization records
31
+ are not rewritten. The new directory and authorization metadata are additive, so an existing
32
+ project needs no state migration. After the first delegated transition, downgrading is not
33
+ recommended because an older package cannot enforce or fully explain the new audit metadata.
34
+
35
+ ## Use and audit
36
+
37
+ The core checks current status, expiry, actor equality, allowed transition, and scope before
38
+ writing the lifecycle change. A Milestone-scoped grant also covers linked Tasks in that
39
+ Milestone. Every delegated authorization event contains:
40
+
41
+ ```text
42
+ authorizationMode = delegated
43
+ actor = <delegate>
44
+ delegation.grantId
45
+ delegation.policyHash
46
+ delegation.principal
47
+ delegation.delegate
48
+ delegation.transition
49
+ ```
50
+
51
+ `next` exposes active matching grants as `delegatedApprovalOptions`. Milestone final
52
+ acceptance still requires the current `MSA-*` code, preserving the revision/hash/HEAD binding;
53
+ the pre-issued grant replaces only the later human-message requirement.
54
+
55
+ Alpha.6 does not widen this allow-list. Delegated approval does not authorize:
56
+
57
+ - `state adoption-apply`
58
+ - `milestone scope-change-prepare`
59
+ - `milestone scope-change-apply`
60
+ - any replacement human gate for Milestone membership repair or scope decisions
61
+
62
+ ## Starting a delegate chat
63
+
64
+ A grant does not start an agent and is not attached to a Codex chat automatically. Open a new
65
+ Local chat in the same Codex Project and give it both the exact `delegate` value and `DGR-ID`.
66
+ The chat must resolve the project-local package, run handshake/doctor/status/next, and read the
67
+ grant before doing work. The earlier `DGA-*` code is not needed again; it authorized issuance,
68
+ not use.
69
+
70
+ Before the first mutation, the delegate verifies:
71
+
72
+ - project identity matches the grant's project;
73
+ - `status` is `active` and `expiresAt` is still in the future;
74
+ - the exact chat actor equals `delegate`;
75
+ - scope covers the requested Milestone or Task;
76
+ - the needed transition is present;
77
+ - `next.delegatedApprovalOptions` contains this grant at the approval point.
78
+
79
+ The delegate must not create, renew, broaden, or replace its own grant. Product ambiguity and
80
+ scope changes are not approval transitions: the delegate stops and asks the user. Worker and
81
+ Independent Reviewer roles may implement or review work, but the coordinating delegate alone
82
+ uses the grant and passes `--delegation-grant` to the Core transition.
83
+
84
+ This matters more in alpha.6 because Milestone scope changes are explicitly journaled,
85
+ human-only lifecycle actions. A delegate may continue ordinary Milestone execution only inside
86
+ the already approved scope.
87
+
88
+ ### Milestone delegate prompt
89
+
90
+ Use project scope when the Milestone does not exist yet. An existing Milestone and its linked
91
+ Tasks may use Milestone scope.
92
+
93
+ ```text
94
+ Работай как delegate-координатор Workflow V2 для одного Milestone.
95
+ Delegate actor: agent:deputy
96
+ Delegation grant: <DGR-ID>
97
+ Milestone ID: <AUTO или MS-ID>
98
+ Требования пользователя: <вставить требования без пересказа lifecycle>
99
+
100
+ Все CLI-, Git-, test-команды и координацию Codex-чатов выполняешь ты.
101
+ Начни с AGENTS.md, project-local gateway handshake, doctor, status и next.
102
+ Выполни delegation show для указанного DGR-ID и до мутаций проверь:
103
+ project, status active, delegate, scope, transitions и expiresAt. Не создавай,
104
+ не продлевай и не расширяй grant.
105
+
106
+ Для AUTO проведи Discovery и не materialize Milestone при blocking unknowns.
107
+ Не принимай новые продуктовые решения и не расширяй scope: при смысловой
108
+ неопределённости остановись и спроси меня. Подготовь Milestone и связанные
109
+ тонкие Tasks. На approval-переходе используй grant только если текущий next
110
+ вернул exact delegatedApprovalOptions для этого DGR-ID и transition; actor
111
+ всегда agent:deputy, никогда user.
112
+
113
+ Required Tasks выполняй последовательно. Для каждой Task обязательно создай
114
+ отдельный пользовательский Codex-чат, передав ему Task delegate prompt, тот же actor и DGR-ID.
115
+ Milestone-чат не реализует Steps и не накапливает fix-loop всех Tasks;
116
+ не запускай два writer на одном checkout. Worker и Reviewer не используют
117
+ grant: approval-команды выполняет только delegate-координатор после их evidence.
118
+
119
+ После merge всех required Tasks выполни Milestone validation. Если next вернул
120
+ milestone.final_accept для этого grant, проверь Result/evidence/HEAD и примени
121
+ grant с текущим MSA-code в том же turn. Если exact option нет, остановись перед
122
+ human gate. В конце покажи Milestone status, authorization event, использованный
123
+ grant/transition и результаты проверок.
124
+ ```
125
+
126
+ ### Task delegate prompt
127
+
128
+ Use Task scope for one existing Task. A new standalone Task with `AUTO` requires project
129
+ scope; a Milestone-scoped grant covers Tasks linked to that Milestone.
130
+
131
+ ```text
132
+ Выполни или возобнови одну Task через Workflow V2 как delegate.
133
+ Delegate actor: agent:deputy
134
+ Delegation grant: <DGR-ID>
135
+ Milestone ID: <MS-ID или NONE>
136
+ Task ID: <TASK-ID или AUTO>
137
+ Цель standalone Task: <только если AUTO>
138
+
139
+ Все CLI-, Git- и test-команды выполняешь ты. Начни с AGENTS.md,
140
+ project-local gateway handshake, doctor, status и next. Выполни delegation
141
+ show для DGR-ID и до мутаций проверь project, active status, delegate,
142
+ scope, transitions и expiresAt. Не создавай и не меняй grant.
143
+
144
+ Не меняй пользовательские требования и scope. Для AUTO сначала проведи
145
+ Discovery; при blocking unknowns остановись. Подготовь проверяемый Plan.
146
+ Authorization выполняй только когда текущий next содержит exact
147
+ delegatedApprovalOptions для DGR-ID и task.execution_authorize; используй
148
+ actor agent:deputy и --delegation-grant, не записывай actor user.
149
+
150
+ Далее следуй штатному lifecycle: один Step - один writer lease. Worker меняет
151
+ только разрешённые файлы и оставляет их uncommitted; затем координатор вызывает
152
+ exact `task step-complete` из `next`, а core выполняет checks, создаёт commit и
153
+ записывает evidence. Worker не использует grant. При изменении Knowledge Map
154
+ выполни reconcile; approve разрешён только при exact project_memory.approve
155
+ option этого project-scoped grant. Затем knowledge-rebind и новая authorization.
156
+ Если next содержит exact `contextRefresh` для того же grant, можешь вместо четырёх
157
+ команд выполнить `task context-refresh`; при любом изменении source set,
158
+ category/authority, gaps или conflicts используй обычный видимый процесс.
159
+
160
+ После submit запусти отдельный Independent Reviewer; Reviewer не использует
161
+ grant и не исправляет код. После второго failed review не запускай очередной
162
+ патч: получи отдельный corrective Plan audit, охватывающий все последние findings,
163
+ и передай его через `--corrective-audit-file`. Продолжай только при
164
+ `decision=continue-fix`; остальные решения верни пользователю/координатору.
165
+ Final acceptance делай
166
+ только при exact task.final_accept option для DGR-ID, затем штатный merge.
167
+ Если option отсутствует, grant истёк, scope не совпал или требуется смысловое
168
+ решение пользователя - остановись. В конце покажи Task status, commits, checks,
169
+ review и delegated authorization event.
170
+ ```
171
+
172
+ Milestone coordinator waits for the dedicated Task chat to return its terminal Task status
173
+ and merge evidence before starting the next required Task. Internal subagents inside one
174
+ oversized Milestone chat are not a substitute for this user-visible Task boundary.
175
+
176
+ After autonomous work, inspect the recorded events and revoke a broad grant when it is no
177
+ longer needed. Revocation does not erase completed approvals.
178
+
179
+ ## Revocation and limits
180
+
181
+ `delegation revoke` requires the exact principal actor, current grant revision, and a reason.
182
+ It blocks future uses and preserves past events. Expiry is checked at every use and does not
183
+ need a state mutation.
184
+
185
+ This mechanism is policy evidence, not cryptographic process identity. The local CLI cannot
186
+ prove that a particular Codex process owns the delegate label. Keep project-wide grants
187
+ short-lived and use narrower scopes once entity IDs exist. External side effects such as
188
+ payments, secrets, production deployment, or live trading need their own provider-level
189
+ authorization and must not rely on this grant alone.
@@ -21,10 +21,25 @@ Materialization requires an observable outcome, scope, acceptance criteria, and
21
21
  blocking unknowns. No Task identifier or branch exists before this gate. Task authorization
22
22
  is hash-bound to Brief and Plan. Later Plan changes supersede it.
23
23
 
24
+ In alpha.6, execution authorization also requires a current Plan Risk Audit bound to the same
25
+ Brief, Plan, Knowledge Map, and exact Step set. For existing schema 2 projects upgraded into
26
+ alpha.6, execution additionally requires adoption posture first; remaining legacy scope then
27
+ uses a bootstrap audit over the preserved non-`completed`, non-`skipped` Steps only.
28
+ The audit names a Plan author and independent auditor, binds each guarded failure mode to
29
+ exact executable evidence, and blocks authorization on `split-required` or `stop-escalate`.
30
+
24
31
  Local execution creates `codex/task-<id>-<slug>` from a clean base only after authorization.
25
32
  An externally owned checkout must already use a dedicated non-base branch. The core never
26
33
  creates or removes external worktrees. Each Step declares allowed writes, dependencies, and
27
- checks; unexpected paths or failed checks block its atomic commit.
34
+ checks. `task run` dispatches exactly one Step and returns a writer lease. The Worker changes
35
+ only allowed files and leaves them uncommitted. Repository-level `next` then returns the exact
36
+ `task step-complete` transition for the active Step. That core transition runs checks, stages
37
+ the allowed changes, creates the atomic Step commit, and records evidence. Unexpected paths,
38
+ failed checks, or any manual/unrecorded Worker commit block completion.
39
+
40
+ If the current Plan Risk Audit marks the Step for strict review, the atomic commit is still
41
+ created by core, but the Step remains non-terminal and `next` routes to `task step-review`
42
+ until commit-bound strict review and reviewer attestation pass.
28
43
 
29
44
  After a Step changes approved project knowledge, the Delivery Coordinator reconciles and
30
45
  reapproves the Project Knowledge Map, then runs `task knowledge-rebind` between Steps. The
@@ -35,12 +50,33 @@ active Worker Step, a no-op binding, an invalid knowledge target, or a modified
35
50
  artifact. After the user authorizes the rebound Plan, execution resumes in the existing
36
51
  workspace; if all Steps are complete, the next action is submission.
37
52
 
53
+ When `next.contextRefresh` exposes an eligible project-scoped grant and content-only mode,
54
+ `task context-refresh` may compose reconcile, delegated map approval, rebind, and delegated
55
+ execution reauthorization. Core validates both approval transitions before writing and
56
+ rejects any source-set, category, scope, authority, gap, or conflict change.
57
+
38
58
  Submission requires a clean, auditable Task history and records evidence for the exact
39
59
  Task head. `task review-launch` starts a separate read-only reviewer. A passing fresh review
40
60
  permits Result creation. Human final acceptance binds Brief, Plan, Result, evidence, and
41
61
  the accepted head. Base advancement forces synchronization, checks, review, and acceptance
42
62
  to be repeated before merge.
43
63
 
64
+ The Technical Planner performs a risk review before authorization. Migration work includes a
65
+ populated forward-upgrade check; concurrent state includes deterministic races; restart,
66
+ replay, and crash claims include restart/crash-window evidence; provider work includes
67
+ failure injection and hidden-default verification. After two failed independent reviews,
68
+ another Plan requires a distinct corrective Auditor and `--corrective-audit-file`. Only a
69
+ `continue-fix` audit may continue; replan, split, and stop decisions return to coordination.
70
+ For guarded alpha.6 remediation, a third ordinary retry is blocked until a current
71
+ `task corrective-decision` exists for the same Step and Plan binding. If that corrective
72
+ attempt fails review, the third failure is a hard stop and no fourth run is permitted.
73
+
74
+ Execution authorization and final acceptance use the human path by default. If the user has
75
+ previously issued an active delegation grant for the exact transition and scope, the named
76
+ delegate may perform that transition with `--delegation-grant`. The event keeps the delegate
77
+ as actor and separately records the principal and policy hash. Expired, revoked, wrong-scope,
78
+ wrong-transition, and wrong-actor grants are rejected before the lifecycle state changes.
79
+
44
80
  ## Milestone lifecycle
45
81
 
46
82
  ```text
@@ -57,6 +93,11 @@ and prevents new linked Tasks from starting. A Task that has started cannot be r
57
93
  it can be retained as waived/cancelled with history and reason. Tasks already in progress
58
94
  may finish while an amendment awaits authorization.
59
95
 
96
+ After the initial empty planning posture, alpha.6 does not use ordinary `milestone plan-set`
97
+ for scope changes. It uses human-only `milestone scope-change-prepare` and
98
+ `milestone scope-change-apply`, with journaled recovery across `state.json`, `plan.json`, and
99
+ `scope-change-events.jsonl`.
100
+
60
101
  A Milestone has no integration branch. Validation requires all required Tasks to be
61
102
  `merged`, checks the current clean base branch, and writes evidence plus Result. Final
62
103
  acceptance binds those artifacts to the unchanged base HEAD. Cancellation records a reason
@@ -76,11 +117,21 @@ explicit user response containing that code permits `milestone accept --actor ..
76
117
  that the recorded confirmation matches the displayed state; identity still depends on the
77
118
  trusted Codex/user interaction boundary rather than on the local npm package alone.
78
119
 
120
+ With an eligible `milestone.final_accept` grant, `next` additionally returns
121
+ `delegatedApprovalOptions`. The delegate may then use the current `MSA-*` code in the same
122
+ turn because the earlier grant-issuance turn is the controlling user decision. Without such
123
+ an option, the ordinary later-message human gate remains mandatory.
124
+
125
+ The Milestone coordinator keeps implementation out of its long-lived context: every required
126
+ Task runs in a dedicated user-visible Task chat. The Milestone chat owns ordering, exact
127
+ delegated transitions, merge observation, cross-Task validation, and final acceptance.
128
+
79
129
  ## Responsibility boundaries
80
130
 
81
131
  | Participant | Responsible for | Cannot decide |
82
132
  | --- | --- | --- |
83
- | User | map classifications, execution authorization, final acceptance, scope changes | implementation evidence |
133
+ | User / principal | map classifications, direct approvals, delegation policy and revocation, scope changes | implementation evidence |
134
+ | Delegate | only transitions explicitly allowed by an active grant | grant creation, expansion, impersonating the principal |
84
135
  | Scope Lead | discovery, facts, unknowns, Task/Milestone recommendation | production edits |
85
136
  | Technical Planner | requirements mapping, Steps, checks, knowledge impact | authorization |
86
137
  | Delivery Coordinator | valid transitions, dispatch, evidence collection | scope expansion |