@attalabs/vinaya 0.44.1 → 0.47.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (143) hide show
  1. package/README.md +6 -4
  2. package/dist/checks/bin/check-body-bare-digits.js +233 -195
  3. package/dist/checks/bin/check-branch-topology.js +70 -23
  4. package/dist/checks/bin/check-brief-shape.js +233 -195
  5. package/dist/checks/bin/check-changeset-coverage.js +94 -16
  6. package/dist/checks/bin/check-ci-shard-coverage.js +3 -0
  7. package/dist/checks/bin/check-closes-n.js +128 -34
  8. package/dist/checks/bin/check-coherence.js +336 -245
  9. package/dist/checks/bin/check-dispatch-readiness.js +3623 -463
  10. package/dist/checks/bin/check-doc-claims.js +233 -195
  11. package/dist/checks/bin/check-doc-coverage-push.js +243 -196
  12. package/dist/checks/bin/check-doc-coverage.js +243 -196
  13. package/dist/checks/bin/check-doctrine-no-procedures.js +233 -195
  14. package/dist/checks/bin/check-doctrine-portability.js +233 -195
  15. package/dist/checks/bin/check-evidence-fresh.js +9983 -1995
  16. package/dist/checks/bin/check-exec-bits.js +3 -0
  17. package/dist/checks/bin/check-first-push-dispatch.js +301 -224
  18. package/dist/checks/bin/check-issue-milestone-attach.js +65 -10
  19. package/dist/checks/bin/check-issue-objectives-numbering.js +233 -195
  20. package/dist/checks/bin/check-issue-parts-coverage.js +65 -10
  21. package/dist/checks/bin/check-issue-surface-globs.js +1032 -236
  22. package/dist/checks/bin/check-issue-title-grammar.js +5 -1
  23. package/dist/checks/bin/check-no-disk-state.js +5 -1
  24. package/dist/checks/bin/check-pr-premise-reassert.js +10 -1
  25. package/dist/checks/bin/check-pr-report-density.js +5 -1
  26. package/dist/checks/bin/check-principal-test-plan-wait.js +253 -201
  27. package/dist/checks/bin/check-quoted-command.js +233 -195
  28. package/dist/checks/bin/check-reader-resolvable-prose.js +233 -195
  29. package/dist/checks/bin/check-registry-gates.js +131 -34
  30. package/dist/checks/bin/check-retired-vocabulary.js +233 -195
  31. package/dist/checks/bin/check-review-gate.js +233 -195
  32. package/dist/checks/bin/check-single-plan-pr.js +5 -1
  33. package/dist/checks/bin/check-surface-scope.js +107 -32
  34. package/dist/checks/bin/check-test-plan.js +253 -201
  35. package/dist/checks/bin/check-token-collection-wired.js +3 -0
  36. package/dist/checks/bin/check-workspace-escape.js +3 -0
  37. package/dist/checks/bin/verify-coherence.js +237 -148
  38. package/dist/checks/bin/verify-dispatch.js +870 -66
  39. package/dist/checks/bin/verify-docs.js +13 -6
  40. package/dist/harness.js +57 -10
  41. package/dist/index.js +16617 -7187
  42. package/dist/lib/pre-push-cache-test-run.js +4487 -2170
  43. package/dist/lib/pre-push-changed-files.js +251 -12
  44. package/dist/lib/pre-push-mode.js +69 -19
  45. package/dist/lib/pre-push-progress-dir.js +10265 -2853
  46. package/dist/lib/pre-push-record-tests.js +67 -19
  47. package/dist/lib/pre-push-select-tests.js +520 -222
  48. package/dist/lib/push-progress-observer.js +9176 -1757
  49. package/dist/process.js +2 -0
  50. package/dist/programs/archive.js +8948 -1547
  51. package/dist/programs/audit.js +9176 -1772
  52. package/dist/programs/check.js +9248 -1845
  53. package/dist/programs/commit-msg.js +8984 -1583
  54. package/dist/programs/dev-review-loop.js +15612 -7634
  55. package/dist/programs/dispatch.js +9977 -2726
  56. package/dist/programs/log-emit.js +9011 -1660
  57. package/dist/programs/log-selftest.js +8908 -1507
  58. package/dist/programs/log-send.js +9081 -1594
  59. package/dist/programs/pr-report.js +9476 -1820
  60. package/dist/programs/pr-snapshot.js +8916 -1515
  61. package/dist/programs/pr-verify-evidence.js +9481 -1825
  62. package/dist/programs/pr.js +11709 -4033
  63. package/dist/programs/review-post.js +11140 -3496
  64. package/dist/programs/review-status.js +8996 -1533
  65. package/dist/programs/run-engine.js +22031 -18759
  66. package/dist/programs/sync.js +9030 -1629
  67. package/dist/programs/task-brief.js +10185 -1821
  68. package/dist/programs/task-sweep.js +9266 -1621
  69. package/dist/programs/task-tools-serve.js +77118 -16678
  70. package/dist/programs/tokens.js +8966 -1565
  71. package/dist/programs/waiver.js +8983 -1582
  72. package/dist/types/harness/kernel/dev-process-socket/loader/load-process.d.ts +1 -1
  73. package/dist/types/harness/processes/vinaya-strict/tools/legacy-markers.d.ts +8 -0
  74. package/dist/types/harness/processes/vinaya-strict/tools/task-contract/brief-validation.d.ts +3 -3
  75. package/dist/types/harness/processes/vinaya-strict/tools/task-contract/objectives.d.ts +5 -6
  76. package/dist/vinaya-strict/checks/registry.ts +2 -2
  77. package/dist/vinaya-strict/executing/developer/developer-doctrine-shape.test.ts +8 -0
  78. package/dist/vinaya-strict/executing/developer/developer-turn-result.ts +1 -1
  79. package/dist/vinaya-strict/executing/developer/evals/developer-capability-suite.test.ts +2 -2
  80. package/dist/vinaya-strict/executing/developer/evals/developer-capability-suite.ts +30 -20
  81. package/dist/vinaya-strict/executing/developer/reference.md +5 -3
  82. package/dist/vinaya-strict/integration/config/vinaya-config-section.ts +29 -7
  83. package/dist/vinaya-strict/integration/policies/vinaya-policies.ts +4 -4
  84. package/dist/vinaya-strict/integration/process/process-integration.ts +5 -1
  85. package/dist/vinaya-strict/process.yaml +6 -1
  86. package/dist/vinaya-strict/thinking/plan-reviewer/doctrine.md +68 -0
  87. package/dist/vinaya-strict/thinking/plan-reviewer/grants.yaml +19 -0
  88. package/dist/vinaya-strict/thinking/plan-reviewer/output.schema.json +388 -0
  89. package/dist/vinaya-strict/thinking/planner/doctrine.md +4 -1
  90. package/dist/vinaya-strict/thinking/planner/tools/amend-rationale-deps.test.ts +10 -2
  91. package/dist/vinaya-strict/thinking/planner/tools/amend-rationale-deps.ts +5 -1
  92. package/dist/vinaya-strict/thinking/planner/tools/open-issue.test.ts +198 -34
  93. package/dist/vinaya-strict/thinking/planner/tools/open-issue.ts +120 -193
  94. package/dist/vinaya-strict/thinking/planner/tools/planner-operations.test.ts +629 -15
  95. package/dist/vinaya-strict/thinking/planner/tools/planner-operations.ts +726 -62
  96. package/dist/vinaya-strict/thinking/planner/tools/planner-tools.test.ts +505 -5
  97. package/dist/vinaya-strict/thinking/planner/tools/planner-tools.ts +636 -21
  98. package/package.json +3 -2
  99. package/studio-standalone/apps/vinaya-studio/.next/BUILD_ID +1 -1
  100. package/studio-standalone/apps/vinaya-studio/.next/build-manifest.json +2 -2
  101. package/studio-standalone/apps/vinaya-studio/.next/prerender-manifest.json +3 -3
  102. package/studio-standalone/apps/vinaya-studio/.next/server/app/_global-error/page_client-reference-manifest.js +1 -1
  103. package/studio-standalone/apps/vinaya-studio/.next/server/app/_global-error.html +1 -1
  104. package/studio-standalone/apps/vinaya-studio/.next/server/app/_global-error.rsc +1 -1
  105. package/studio-standalone/apps/vinaya-studio/.next/server/app/_global-error.segments/_full.segment.rsc +1 -1
  106. package/studio-standalone/apps/vinaya-studio/.next/server/app/_global-error.segments/_global-error/__PAGE__.segment.rsc +1 -1
  107. package/studio-standalone/apps/vinaya-studio/.next/server/app/_global-error.segments/_tree.segment.rsc +1 -1
  108. package/studio-standalone/apps/vinaya-studio/.next/server/app/_not-found/page_client-reference-manifest.js +1 -1
  109. package/studio-standalone/apps/vinaya-studio/.next/server/app/milestones/page_client-reference-manifest.js +1 -1
  110. package/studio-standalone/apps/vinaya-studio/.next/server/app/page_client-reference-manifest.js +1 -1
  111. package/studio-standalone/apps/vinaya-studio/.next/server/app/tasks/page_client-reference-manifest.js +1 -1
  112. package/studio-standalone/apps/vinaya-studio/.next/server/chunks/209.js +2 -2
  113. package/studio-standalone/apps/vinaya-studio/.next/server/chunks/951.js +1 -1
  114. package/studio-standalone/apps/vinaya-studio/.next/server/middleware-build-manifest.js +1 -1
  115. package/studio-standalone/apps/vinaya-studio/.next/server/pages/500.html +1 -1
  116. package/studio-standalone/apps/vinaya-studio/.next/server/preview-props.json +3 -3
  117. package/studio-standalone/apps/vinaya-studio/.next/server/server-reference-manifest.json +1 -1
  118. package/studio-standalone/apps/vinaya-studio/.next/static/chunks/151-c365f0ef8268ad13.js +1 -0
  119. package/studio-standalone/apps/vinaya-studio/.next/static/chunks/19-aa314f13784dcc58.js +4 -0
  120. package/studio-standalone/apps/vinaya-studio/.next/static/chunks/app/{layout-dfa2186095e797bd.js → layout-f038e8deecb2bf5f.js} +1 -1
  121. package/studio-standalone/apps/vinaya-studio/.next/static/chunks/app/milestones/{page-2fffb49104860a15.js → page-12314f4deb06a414.js} +1 -1
  122. package/studio-standalone/apps/vinaya-studio/.next/static/chunks/app/{page-6ae258f663623b2a.js → page-7a06aa3cdd046fa8.js} +1 -1
  123. package/studio-standalone/apps/vinaya-studio/.next/static/chunks/app/tasks/{page-2fffb49104860a15.js → page-12314f4deb06a414.js} +1 -1
  124. package/studio-standalone/apps/vinaya-studio/.next/static/css/8eb5ed5b65b9692e.css +1 -0
  125. package/studio-standalone/apps/vinaya-studio/log-follow.mjs +708 -93
  126. package/studio-standalone/apps/vinaya-studio/log-sync-folder-source.mjs +699 -84
  127. package/studio-standalone/apps/vinaya-studio/studio-server.mjs +4692 -3116
  128. package/vinaya-strict/artifacts/templates/brief-template.md +4 -0
  129. package/vinaya-strict/artifacts/templates/issue-rationale-template.md +7 -3
  130. package/vinaya-strict/artifacts/templates/pr-report-template.md +1 -1
  131. package/vinaya-strict/doctrine/contracts/planner-developer.md +2 -1
  132. package/vinaya-strict/doctrine/enforcement.md +4 -4
  133. package/vinaya-strict/doctrine/roles/principal.md +1 -1
  134. package/vinaya-strict/doctrine/state-machine.md +7 -2
  135. package/vinaya-strict/executing/developer/reference.md +5 -3
  136. package/vinaya-strict/thinking/plan-reviewer/doctrine.md +68 -0
  137. package/vinaya-strict/thinking/planner/doctrine.md +4 -1
  138. package/vinaya-strict/thinking/planner/reference.md +29 -8
  139. package/studio-standalone/apps/vinaya-studio/.next/static/chunks/151-23bea4cac9687151.js +0 -1
  140. package/studio-standalone/apps/vinaya-studio/.next/static/chunks/853-1d5548ff3a55a75f.js +0 -4
  141. package/studio-standalone/apps/vinaya-studio/.next/static/css/fb16828fc3128d4c.css +0 -1
  142. /package/studio-standalone/apps/vinaya-studio/.next/static/{3URbt6IPajL5OOhijN1-x → bJrgAp9Kl4JsCUYkeAYez}/_buildManifest.js +0 -0
  143. /package/studio-standalone/apps/vinaya-studio/.next/static/{3URbt6IPajL5OOhijN1-x → bJrgAp9Kl4JsCUYkeAYez}/_ssgManifest.js +0 -0
@@ -1,7 +1,7 @@
1
1
  import { describe, expect, it } from 'bun:test'
2
2
  import { readFileSync } from 'node:fs'
3
- import { TaskToolErrorSchema } from '../../../../../kernel/tools/catalog/task-tools'
4
- import { makeCheckError } from '../../../tools/task-contract/forge/forge-write'
3
+ import { TaskToolErrorSchema } from '@harness/kernel/tools/catalog/task-tools'
4
+ import { makeCheckError } from '@harness/workflow/tools/task-contract/forge/forge-write'
5
5
  import { PLANNER_TOOL_ENTRIES, PLANNER_TOOL_NAMES, plannerToolHandlers, type PlannerOperations } from './planner-tools'
6
6
 
7
7
  const finding = (check: string) => makeCheckError(check, `${check} message`, `${check} recovery`)
@@ -40,13 +40,71 @@ function stubOps(
40
40
  calls.push({ op: 'objectives', arg: args })
41
41
  return { ok: true, version: 'v2', url: 'https://example.test/issues/9#c', supersedeUrl: null }
42
42
  },
43
+ editDocumentation: async (input) => {
44
+ calls.push({ op: 'documentation', arg: input })
45
+ return { ok: true, briefUrl: 'https://example.test/issues/9#brief', recordUrl: 'https://example.test/issues/9#r' }
46
+ },
43
47
  printIssueSurface: (args) => {
44
48
  calls.push({ op: 'surface', arg: args, body: bodyOf(args) })
45
49
  return { ok: true, set: { forced: [] } as never, json: false, text: 'surface text' }
46
50
  },
47
51
  renderBrief: async (input) => {
48
52
  calls.push({ op: 'brief', arg: input })
49
- return { ok: true, brief: '# brief' }
53
+ return { ok: true, brief: '# brief', waiting: [] }
54
+ },
55
+ submitPlanDraft: (input) => {
56
+ calls.push({ op: 'draft-submit', arg: input })
57
+ return { ok: true, tranche: 'sample-plan', fingerprint: 'sha256:abc', tasks: 1 }
58
+ },
59
+ readPlanDraft: (tranche) => {
60
+ calls.push({ op: 'draft-read', arg: tranche })
61
+ return { ok: false, message: `no draft is stored for tranche "${tranche}" on this machine` }
62
+ },
63
+ checkPlanDraft: async (tranche) => {
64
+ calls.push({ op: 'draft-check', arg: tranche })
65
+ return { ok: false, message: `no draft is stored for tranche "${tranche}" on this machine` }
66
+ },
67
+ previewPlanDraft: async (tranche, task) => {
68
+ calls.push({ op: 'draft-preview', arg: { tranche, task } })
69
+ return { ok: false, message: `no draft is stored for tranche "${tranche}" on this machine` }
70
+ },
71
+ startPlanReview: async (tranche) => {
72
+ calls.push({ op: 'review-start', arg: tranche })
73
+ return {
74
+ ok: false,
75
+ reason: 'no_draft',
76
+ findings: [{ check: 'plan-review', message: 'no draft is stored', recovery: 'Submit the draft first.' }]
77
+ }
78
+ },
79
+ planReviewStatus: (tranche) => {
80
+ calls.push({ op: 'review-status', arg: tranche })
81
+ return {
82
+ ok: false,
83
+ findings: [{ check: 'plan-review', message: 'no draft is stored', recovery: 'Submit the draft first.' }]
84
+ }
85
+ },
86
+ decidePlanReview: (input) => {
87
+ calls.push({ op: 'review-decide', arg: input })
88
+ return {
89
+ ok: false,
90
+ findings: [{ check: 'plan-review', message: 'the round limit is not reached', recovery: 'Start a round.' }]
91
+ }
92
+ },
93
+ approvePlanReview: (input) => {
94
+ calls.push({ op: 'review-approve', arg: input })
95
+ return {
96
+ ok: false,
97
+ findings: [{ check: 'plan-review', message: 'the latest review round did not approve', recovery: 'Review.' }]
98
+ }
99
+ },
100
+ publishPlan: async (input) => {
101
+ calls.push({ op: 'publish', arg: input })
102
+ return {
103
+ ok: false,
104
+ findings: [makeCheckError('plan-publish', 'the draft is not approved', 'Review it first.')],
105
+ warnings: [],
106
+ published: []
107
+ }
50
108
  },
51
109
  ...over
52
110
  }
@@ -63,8 +121,387 @@ const refusalFindings = (r: Awaited<ReturnType<typeof call>>) => {
63
121
  return JSON.parse(r.error.detail as string) as { check: string; message: string; recovery: string }[]
64
122
  }
65
123
 
124
+ const DRAFT = {
125
+ schemaVersion: 1,
126
+ tranche: 'sample-plan',
127
+ revision: 'a'.repeat(40),
128
+ reviewQuestionVersion: 'q1',
129
+ tasks: [{ number: 1, issue: null, title: 'First', body: 'Body', labels: ['vinaya/tranche:sample-plan'] }],
130
+ scope: [{ item: 'Everything', disposition: { kind: 'delivered', task: 1 } }]
131
+ }
132
+
133
+ describe('the plan draft tools', () => {
134
+ it('plan_draft_submit hands a whole draft to the store and returns its fingerprint', async () => {
135
+ const ops = stubOps()
136
+ const r = await call(ops, 'plan_draft_submit', DRAFT)
137
+ expect(r.ok).toBe(true)
138
+ if (r.ok) expect(r.result).toEqual({ tranche: 'sample-plan', fingerprint: 'sha256:abc', tasks: 1 })
139
+ expect(ops.calls.map((c) => c.op)).toEqual(['draft-submit'])
140
+ })
141
+
142
+ it('plan_draft_submit refuses a malformed draft before it reaches the store', async () => {
143
+ const ops = stubOps()
144
+ const r = await call(ops, 'plan_draft_submit', { ...DRAFT, revision: 'main' })
145
+ expect(r.ok).toBe(false)
146
+ expect(refusalFindings(r)[0]?.check).toBe('tool-input')
147
+ expect(ops.calls).toEqual([])
148
+ })
149
+
150
+ it('plan_draft_submit refuses a scope item delivered by a task the draft lacks', async () => {
151
+ const r = await call(stubOps(), 'plan_draft_submit', {
152
+ ...DRAFT,
153
+ scope: [{ item: 'X', disposition: { kind: 'delivered', task: 9 } }]
154
+ })
155
+ expect(r.ok).toBe(false)
156
+ })
157
+
158
+ it('plan_draft_read returns the stored draft and its fingerprint, and refuses an absent one', async () => {
159
+ const present = await call(
160
+ stubOps({ readPlanDraft: () => ({ ok: true, draft: DRAFT as never, fingerprint: 'sha256:abc' }) }),
161
+ 'plan_draft_read',
162
+ { tranche: 'sample-plan' }
163
+ )
164
+ expect(present.ok).toBe(true)
165
+ if (present.ok) expect(present.result).toEqual({ draft: DRAFT, fingerprint: 'sha256:abc' })
166
+ const absent = await call(stubOps(), 'plan_draft_read', { tranche: 'sample-plan' })
167
+ expect(absent.ok).toBe(false)
168
+ expect(refusalFindings(absent)[0]?.check).toBe('plan-draft')
169
+ })
170
+ })
171
+
172
+ describe('the plan draft check and preview tools', () => {
173
+ const blocking = finding('plan-draft-collision')
174
+ const warning = makeCheckError('plan-draft-collision', 'only a warning', 'no action', 'warning')
175
+
176
+ it('are on the Planner seat', () => {
177
+ expect(PLANNER_TOOL_NAMES).toContain('plan_draft_check')
178
+ expect(PLANNER_TOOL_NAMES).toContain('plan_draft_preview')
179
+ expect(PLANNER_TOOL_ENTRIES.map((e) => e.name)).toContain('plan_draft_check')
180
+ expect(PLANNER_TOOL_ENTRIES.map((e) => e.name)).toContain('plan_draft_preview')
181
+ })
182
+
183
+ it('plan_draft_check refuses a blocking finding as validation errors carrying check, message and recovery', async () => {
184
+ const r = await call(
185
+ stubOps({
186
+ checkPlanDraft: async () => ({
187
+ ok: true,
188
+ report: {
189
+ fingerprint: 'sha256:abc',
190
+ tasks: [{ task: 2, findings: [blocking] }],
191
+ cross: [finding('plan-draft-cycle')],
192
+ coverage: [finding('plan-draft-scope')],
193
+ blocking: true
194
+ }
195
+ })
196
+ }),
197
+ 'plan_draft_check',
198
+ { tranche: 'sample-plan' }
199
+ )
200
+ const findings = refusalFindings(r)
201
+ expect(findings.map((f) => f.check)).toEqual(['plan-draft-collision', 'plan-draft-cycle', 'plan-draft-scope'])
202
+ expect(findings[0]?.message).toBe('task 2: plan-draft-collision message')
203
+ expect(findings.every((f) => f.recovery.length > 0)).toBe(true)
204
+ })
205
+
206
+ it('plan_draft_check succeeds with the warnings when nothing blocks', async () => {
207
+ const r = await call(
208
+ stubOps({
209
+ checkPlanDraft: async () => ({
210
+ ok: true,
211
+ report: {
212
+ fingerprint: 'sha256:abc',
213
+ tasks: [{ task: 1, findings: [warning] }],
214
+ cross: [],
215
+ coverage: [],
216
+ blocking: false
217
+ }
218
+ })
219
+ }),
220
+ 'plan_draft_check',
221
+ { tranche: 'sample-plan' }
222
+ )
223
+ expect(r.ok).toBe(true)
224
+ if (r.ok) {
225
+ expect((r.result as { fingerprint: string }).fingerprint).toBe('sha256:abc')
226
+ expect((r.result as { warnings: unknown[] }).warnings).toHaveLength(1)
227
+ }
228
+ })
229
+
230
+ it('plan_draft_check refuses an absent draft, naming the check and the fix', async () => {
231
+ const f = refusalFindings(await call(stubOps(), 'plan_draft_check', { tranche: 'sample-plan' }))
232
+ expect(f[0]?.check).toBe('plan-draft')
233
+ expect(f[0]?.recovery).toContain('plan_draft_submit')
234
+ })
235
+
236
+ it('plan_draft_preview returns each task’s exact Issue and brief with its waiting reasons', async () => {
237
+ const ops = stubOps({
238
+ previewPlanDraft: async () => ({
239
+ ok: true,
240
+ preview: {
241
+ fingerprint: 'sha256:abc',
242
+ revision: 'a'.repeat(40),
243
+ findings: [],
244
+ ok: true,
245
+ tasks: [
246
+ {
247
+ task: 2,
248
+ issue: { title: '[sample-plan] 2 — Second', body: 'Body', labels: ['vinaya/tranche:sample-plan'] },
249
+ brief: '# brief',
250
+ waiting: ['dependency 1 has not merged'],
251
+ findings: []
252
+ }
253
+ ]
254
+ }
255
+ })
256
+ })
257
+ const r = await call(ops, 'plan_draft_preview', { tranche: 'sample-plan', task: 2 })
258
+ expect(r.ok).toBe(true)
259
+ if (r.ok) {
260
+ const result = r.result as { tasks: { task: number; brief: string; waiting: string[] }[] }
261
+ expect(result.tasks[0]).toMatchObject({ task: 2, brief: '# brief', waiting: ['dependency 1 has not merged'] })
262
+ }
263
+ })
264
+
265
+ it('plan_draft_preview refuses a task that cannot render as validation errors', async () => {
266
+ const r = await call(
267
+ stubOps({
268
+ previewPlanDraft: async () => ({
269
+ ok: true,
270
+ preview: {
271
+ fingerprint: 'sha256:abc',
272
+ revision: 'a'.repeat(40),
273
+ findings: [],
274
+ ok: false,
275
+ tasks: [
276
+ {
277
+ task: 1,
278
+ issue: { title: 't', body: 'b', labels: [] },
279
+ brief: null,
280
+ waiting: [],
281
+ findings: [finding('plan-draft-preview')]
282
+ }
283
+ ]
284
+ }
285
+ })
286
+ }),
287
+ 'plan_draft_preview',
288
+ { tranche: 'sample-plan' }
289
+ )
290
+ expect(refusalFindings(r)[0]).toEqual({
291
+ check: 'plan-draft-preview',
292
+ message: 'plan-draft-preview message',
293
+ recovery: 'plan-draft-preview recovery'
294
+ })
295
+ })
296
+
297
+ it('refuse input that names no tranche', async () => {
298
+ expect(refusalFindings(await call(stubOps(), 'plan_draft_preview', { task: 1 }))[0]?.check).toBe('tool-input')
299
+ expect(refusalFindings(await call(stubOps(), 'plan_draft_check', {}))[0]?.check).toBe('tool-input')
300
+ })
301
+ })
302
+
303
+ describe('the plan review tools', () => {
304
+ const STATUS = {
305
+ tranche: 'sample-plan',
306
+ fingerprint: 'sha256:abc',
307
+ roundsSpent: 2,
308
+ roundsAllowed: 2,
309
+ roundLimit: 2,
310
+ approved: false,
311
+ principalApproved: false,
312
+ principalApprovalStale: false,
313
+ stale: false,
314
+ lastVerdict: 'not_approved',
315
+ approvedTasks: [],
316
+ openFindings: [],
317
+ notes: [],
318
+ resolvedFindings: [],
319
+ stopped: false,
320
+ limitReached: true,
321
+ nextScope: null,
322
+ decisions: []
323
+ }
324
+
325
+ it('are on the Planner seat', () => {
326
+ for (const name of ['plan_review_start', 'plan_review_status', 'plan_review_decide', 'plan_approve'] as const) {
327
+ expect(PLANNER_TOOL_NAMES).toContain(name)
328
+ }
329
+ })
330
+
331
+ it('list and serve plan_publish, which returns each task’s number, Issue and link', async () => {
332
+ expect(PLANNER_TOOL_NAMES).toContain('plan_publish')
333
+ expect(PLANNER_TOOL_ENTRIES.map((e) => e.name)).toContain('plan_publish')
334
+ const ops = stubOps({
335
+ publishPlan: async () => ({
336
+ ok: true,
337
+ tasks: [{ task: 1, issue: 41, url: 'https://example.test/issues/41', alreadyPublished: false }],
338
+ warnings: []
339
+ })
340
+ })
341
+ const r = await call(ops, 'plan_publish', { tranche: 'sample-plan', tasks: [1] })
342
+ expect(r.ok).toBe(true)
343
+ if (r.ok) {
344
+ expect(r.result).toEqual({
345
+ tasks: [{ task: 1, issue: 41, url: 'https://example.test/issues/41', alreadyPublished: false }],
346
+ warnings: []
347
+ })
348
+ }
349
+ })
350
+
351
+ it('plan_publish refuses with the findings, and names the Issues written before a refusal', async () => {
352
+ expect(refusalFindings(await call(stubOps(), 'plan_publish', { tranche: 'sample-plan' }))[0]?.check).toBe(
353
+ 'plan-publish'
354
+ )
355
+ const half = stubOps({
356
+ publishPlan: async () => ({
357
+ ok: false,
358
+ findings: [finding('brief-shape')],
359
+ warnings: [],
360
+ published: [{ task: 1, issue: 41, url: 'https://example.test/issues/41', alreadyPublished: false }]
361
+ })
362
+ })
363
+ const findings = refusalFindings(await call(half, 'plan_publish', { tranche: 'sample-plan' }))
364
+ expect(findings.map((f) => f.check)).toEqual(['brief-shape', 'plan-publish'])
365
+ expect(findings[1]?.message).toContain('task 1 as Issue #41')
366
+ expect(refusalFindings(await call(stubOps(), 'plan_publish', { tasks: [1] }))[0]?.check).toBe('tool-input')
367
+ })
368
+
369
+ it('plan_review_start returns the round, its verdict and its findings', async () => {
370
+ const ops = stubOps({
371
+ startPlanReview: async () => ({
372
+ ok: true,
373
+ round: 1,
374
+ fingerprint: 'sha256:abc',
375
+ agent: 'codex',
376
+ verdict: 'not_approved',
377
+ findings: [],
378
+ openFindings: [],
379
+ resolved: [],
380
+ roundsSpent: 1,
381
+ roundsAllowed: 2,
382
+ scope: null
383
+ })
384
+ })
385
+ const r = await call(ops, 'plan_review_start', { tranche: 'sample-plan' })
386
+ expect(r.ok).toBe(true)
387
+ if (r.ok) expect((r.result as { verdict: string; round: number }).verdict).toBe('not_approved')
388
+ })
389
+
390
+ it('plan_review_start refuses as validation errors, one finding each', async () => {
391
+ const r = await call(stubOps(), 'plan_review_start', { tranche: 'sample-plan' })
392
+ expect(r.ok).toBe(false)
393
+ expect(refusalFindings(r)[0]?.check).toBe('plan-review')
394
+ })
395
+
396
+ it('plan_review_status returns the drift of the published tasks, and a status without it stays valid', async () => {
397
+ const drift = {
398
+ matching: [1],
399
+ drifted: [{ task: 2, issue: 12, differs: 'both' }],
400
+ unread: [{ task: 3, issue: 13, reason: 'unreadable' }]
401
+ }
402
+ const withDrift = await call(
403
+ stubOps({ planReviewStatus: () => ({ ok: true, status: { ...STATUS, drift } as never }) }),
404
+ 'plan_review_status',
405
+ { tranche: 'sample-plan' }
406
+ )
407
+ expect(withDrift.ok).toBe(true)
408
+ if (withDrift.ok) expect(withDrift.result).toEqual({ status: { ...STATUS, drift } })
409
+ const decided = await call(
410
+ stubOps({
411
+ decidePlanReview: () => ({ ok: true, status: STATUS as never, decision: { choice: 'stop' } as never })
412
+ }),
413
+ 'plan_review_decide',
414
+ { tranche: 'sample-plan', fingerprint: 'sha256:abc', choice: 'stop' }
415
+ )
416
+ expect(decided.ok).toBe(true)
417
+ })
418
+
419
+ it('plan_review_status returns the status and refuses an absent draft', async () => {
420
+ const present = await call(
421
+ stubOps({ planReviewStatus: () => ({ ok: true, status: STATUS as never }) }),
422
+ 'plan_review_status',
423
+ { tranche: 'sample-plan' }
424
+ )
425
+ expect(present.ok).toBe(true)
426
+ if (present.ok) expect(present.result).toEqual({ status: STATUS })
427
+ expect(refusalFindings(await call(stubOps(), 'plan_review_status', { tranche: 'sample-plan' }))[0]?.check).toBe(
428
+ 'plan-review'
429
+ )
430
+ })
431
+
432
+ it('plan_review_decide records a decision against the fingerprint it names', async () => {
433
+ const ops = stubOps({
434
+ decidePlanReview: (input) => ({
435
+ ok: true,
436
+ status: STATUS as never,
437
+ decision: { fingerprint: input.fingerprint, choice: input.choice, afterRounds: 2 }
438
+ })
439
+ })
440
+ const r = await call(ops, 'plan_review_decide', {
441
+ tranche: 'sample-plan',
442
+ fingerprint: 'sha256:abc',
443
+ choice: 'allow_one_more'
444
+ })
445
+ expect(r.ok).toBe(true)
446
+ if (r.ok) {
447
+ expect((r.result as { decision: unknown }).decision).toEqual({
448
+ fingerprint: 'sha256:abc',
449
+ choice: 'allow_one_more',
450
+ afterRounds: 2
451
+ })
452
+ }
453
+ })
454
+
455
+ it('list and serve plan_approve, which records the approval and refuses what the review did not approve', async () => {
456
+ expect(PLANNER_TOOL_NAMES).toContain('plan_approve')
457
+ expect(PLANNER_TOOL_ENTRIES.map((e) => e.name)).toContain('plan_approve')
458
+ const ok = await call(
459
+ stubOps({
460
+ approvePlanReview: (input) => ({
461
+ ok: true,
462
+ status: STATUS as never,
463
+ approval: { fingerprint: input.fingerprint, afterRounds: 1 }
464
+ })
465
+ }),
466
+ 'plan_approve',
467
+ { tranche: 'sample-plan', fingerprint: 'sha256:abc' }
468
+ )
469
+ expect(ok.ok).toBe(true)
470
+ if (ok.ok)
471
+ expect((ok.result as { approval: unknown }).approval).toEqual({ fingerprint: 'sha256:abc', afterRounds: 1 })
472
+ const refused = await call(stubOps(), 'plan_approve', { tranche: 'sample-plan', fingerprint: 'sha256:abc' })
473
+ expect(refusalFindings(refused)[0]?.message).toContain('did not approve')
474
+ expect(refusalFindings(await call(stubOps(), 'plan_approve', { tranche: 'sample-plan' }))[0]?.check).toBe(
475
+ 'tool-input'
476
+ )
477
+ })
478
+
479
+ it('plan_review_decide refuses, as a validation error, a decision the limit does not call for', async () => {
480
+ const ops = stubOps()
481
+ const r = await call(ops, 'plan_review_decide', {
482
+ tranche: 'sample-plan',
483
+ fingerprint: 'sha256:abc',
484
+ choice: 'stop'
485
+ })
486
+ expect(refusalFindings(r)[0]?.message).toContain('not reached')
487
+ expect(ops.calls.map((c) => c.op)).toEqual(['review-decide'])
488
+ })
489
+
490
+ it('refuse input without a tranche, a fingerprint or a known choice', async () => {
491
+ expect(refusalFindings(await call(stubOps(), 'plan_review_start', {}))[0]?.check).toBe('tool-input')
492
+ expect(
493
+ refusalFindings(await call(stubOps(), 'plan_review_decide', { tranche: 'sample-plan', choice: 'stop' }))[0]?.check
494
+ ).toBe('tool-input')
495
+ expect(
496
+ refusalFindings(
497
+ await call(stubOps(), 'plan_review_decide', { tranche: 'a', fingerprint: 'sha256:abc', choice: 'approve' })
498
+ )[0]?.check
499
+ ).toBe('tool-input')
500
+ })
501
+ })
502
+
66
503
  describe('the Planner tool entries', () => {
67
- it('are the six tools, each with an input and an output schema', () => {
504
+ it('are each tool of the seat, each with an input and an output schema', () => {
68
505
  expect(PLANNER_TOOL_ENTRIES.map((e) => e.name)).toEqual([...PLANNER_TOOL_NAMES])
69
506
  for (const entry of PLANNER_TOOL_ENTRIES) {
70
507
  expect(entry.inputSchema.type).toBe('object')
@@ -72,6 +509,14 @@ describe('the Planner tool entries', () => {
72
509
  }
73
510
  })
74
511
 
512
+ it('list the Documentation correction with a description and its schemas', () => {
513
+ const entry = PLANNER_TOOL_ENTRIES.find((e) => e.name === 'task_documentation_edit')
514
+ expect(entry?.description).toContain('Principal only')
515
+ expect(entry?.description).toContain('`## Documentation`')
516
+ expect(entry?.inputSchema.required).toEqual(['issue', 'documentation', 'reason'])
517
+ expect(entry?.outputSchema?.required).toEqual(['briefUrl', 'recordUrl'])
518
+ })
519
+
75
520
  it('describe the Issue writers without a retired command word', () => {
76
521
  for (const name of ['task_issue_create', 'task_issue_edit']) {
77
522
  const description = PLANNER_TOOL_ENTRIES.find((e) => e.name === name)?.description ?? ''
@@ -129,14 +574,69 @@ describe('success returns the library’s outcome', () => {
129
574
  await call(ops, 'task_objectives_edit', { op: 'add', issue: 9, sentence: 'S', reason: 'why', part: 'P' })
130
575
  expect(ops.calls[1]?.arg).toEqual(['9', '--add', 'S', '--part', 'P', '--reason', 'why'])
131
576
  })
577
+ it('task_documentation_edit passes the Issue, the section and the reason, and returns both comments', async () => {
578
+ const ops = stubOps()
579
+ const r = await call(ops, 'task_documentation_edit', {
580
+ issue: 9,
581
+ documentation: '- `a/one.md` — what it governs (O1)',
582
+ reason: 'the source moved'
583
+ })
584
+ expect(r).toEqual({
585
+ ok: true,
586
+ result: { briefUrl: 'https://example.test/issues/9#brief', recordUrl: 'https://example.test/issues/9#r' }
587
+ })
588
+ expect(ops.calls).toEqual([
589
+ {
590
+ op: 'documentation',
591
+ arg: { issue: 9, documentation: '- `a/one.md` — what it governs (O1)', reason: 'the source moved' }
592
+ }
593
+ ])
594
+ })
595
+ it('task_documentation_edit refuses an input with no reason before the operation runs', async () => {
596
+ const ops = stubOps()
597
+ const r = await call(ops, 'task_documentation_edit', { issue: 9, documentation: 'None' })
598
+ expect(refusalFindings(r)[0]?.check).toBe('tool-input')
599
+ expect(ops.calls).toEqual([])
600
+ })
601
+ it('task_documentation_edit returns the operation’s refusal with every finding', async () => {
602
+ const ops = stubOps({
603
+ editDocumentation: async () => ({ ok: false, findings: [finding('first-check'), finding('second-check')] })
604
+ })
605
+ const r = await call(ops, 'task_documentation_edit', { issue: 9, documentation: 'None', reason: 'r' })
606
+ expect(refusalFindings(r).map((f) => f.check)).toEqual(['first-check', 'second-check'])
607
+ })
132
608
  it('brief_render returns the rendered text', async () => {
133
609
  const ops = stubOps()
134
610
  expect(await call(ops, 'brief_render', { tranche: 't', id: '3' })).toEqual({
135
611
  ok: true,
136
- result: { brief: '# brief' }
612
+ result: { brief: '# brief', waiting: [] }
137
613
  })
138
614
  expect(ops.calls[0]?.arg).toEqual({ trancheSlug: 't', taskId: '3' })
139
615
  })
616
+ it('brief_render returns the brief with the reasons the task cannot start yet', async () => {
617
+ const ops = stubOps({
618
+ renderBrief: async () => ({ ok: true, brief: '# brief', waiting: ['depends on task 1'] })
619
+ })
620
+ expect(await call(ops, 'brief_render', { tranche: 't', id: '3' })).toEqual({
621
+ ok: true,
622
+ result: { brief: '# brief', waiting: ['depends on task 1'] }
623
+ })
624
+ })
625
+ it('brief_render with an Issue number alone returns that Issue’s brief', async () => {
626
+ const ops = stubOps()
627
+ expect(await call(ops, 'brief_render', { issue: 12 })).toEqual({
628
+ ok: true,
629
+ result: { brief: '# brief', waiting: [] }
630
+ })
631
+ expect(ops.calls[0]?.arg).toEqual({ issue: 12 })
632
+ })
633
+ it('brief_render refuses an Issue number given with a tranche and task id, and an address with neither', async () => {
634
+ const ops = stubOps()
635
+ expect((await call(ops, 'brief_render', { issue: 12, tranche: 't', id: '3' })).ok).toBe(false)
636
+ expect((await call(ops, 'brief_render', { tranche: 't' })).ok).toBe(false)
637
+ expect((await call(ops, 'brief_render', {})).ok).toBe(false)
638
+ expect(ops.calls).toEqual([])
639
+ })
140
640
  })
141
641
 
142
642
  describe('refusal keeps every finding’s check name and recovery text', () => {