@attalabs/vinaya 0.42.1 → 0.43.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 (88) hide show
  1. package/dist/checks/bin/check-evidence-fresh.js +177 -152
  2. package/dist/checks/bin/check-registry-gates.js +10 -3
  3. package/dist/index.js +300 -173
  4. package/dist/lib/pre-push-cache-test-run.js +145 -144
  5. package/dist/lib/pre-push-changed-files.js +10 -3
  6. package/dist/lib/pre-push-progress-dir.js +169 -147
  7. package/dist/lib/pre-push-select-tests.js +16 -4
  8. package/dist/lib/push-progress-observer.js +169 -147
  9. package/dist/programs/archive.js +172 -148
  10. package/dist/programs/audit.js +169 -147
  11. package/dist/programs/check.js +172 -148
  12. package/dist/programs/commit-msg.js +172 -148
  13. package/dist/programs/dev-review-loop.js +300 -176
  14. package/dist/programs/dispatch.js +1905 -1877
  15. package/dist/programs/log-emit.js +172 -148
  16. package/dist/programs/log-selftest.js +172 -148
  17. package/dist/programs/log-send.js +172 -148
  18. package/dist/programs/pr-report.js +177 -152
  19. package/dist/programs/pr-snapshot.js +172 -148
  20. package/dist/programs/pr-verify-evidence.js +177 -152
  21. package/dist/programs/pr.js +172 -148
  22. package/dist/programs/review-post.js +172 -148
  23. package/dist/programs/review-status.js +180 -148
  24. package/dist/programs/run-engine.js +110594 -0
  25. package/dist/programs/supervised-command.js +67 -0
  26. package/dist/programs/sync.js +63 -39
  27. package/dist/programs/task-brief.js +174 -150
  28. package/dist/programs/task-sweep.js +244 -151
  29. package/dist/programs/task-tools-serve.js +260 -163
  30. package/dist/programs/tokens.js +172 -148
  31. package/dist/programs/waiver.js +172 -148
  32. package/dist/vinaya-strict/checks/registry.ts +1085 -0
  33. package/dist/vinaya-strict/executing/code-reviewer/README.md +3 -0
  34. package/dist/vinaya-strict/executing/code-reviewer/doctrine.md +185 -0
  35. package/dist/vinaya-strict/executing/code-reviewer/evals/README.md +1 -0
  36. package/dist/vinaya-strict/executing/code-reviewer/evals/code-reviewer-cases.json +280 -0
  37. package/dist/vinaya-strict/executing/code-reviewer/grants.yaml +22 -0
  38. package/dist/vinaya-strict/executing/code-reviewer/output.schema.json +93 -0
  39. package/dist/vinaya-strict/executing/code-reviewer/review-result.ts +347 -0
  40. package/dist/vinaya-strict/executing/dev-review.flow.yaml +103 -0
  41. package/dist/vinaya-strict/executing/developer/README.md +3 -0
  42. package/dist/vinaya-strict/executing/developer/developer-doctrine-shape.test.ts +69 -0
  43. package/dist/vinaya-strict/executing/developer/developer-turn-result.ts +286 -0
  44. package/dist/vinaya-strict/executing/developer/doctrine.md +111 -0
  45. package/dist/vinaya-strict/executing/developer/evals/README.md +1 -0
  46. package/dist/vinaya-strict/executing/developer/evals/developer-capability-cases.json +6275 -0
  47. package/dist/vinaya-strict/executing/developer/evals/developer-capability-held-out.json +11526 -0
  48. package/dist/vinaya-strict/executing/developer/evals/developer-capability-suite.test.ts +498 -0
  49. package/dist/vinaya-strict/executing/developer/evals/developer-capability-suite.ts +1407 -0
  50. package/dist/vinaya-strict/executing/developer/grants.yaml +25 -0
  51. package/dist/vinaya-strict/executing/developer/output.schema.json +148 -0
  52. package/dist/vinaya-strict/executing/developer/reference.md +376 -0
  53. package/dist/vinaya-strict/executing/operator/doctrine.md +209 -0
  54. package/dist/vinaya-strict/executing/security-reviewer/README.md +3 -0
  55. package/dist/vinaya-strict/executing/security-reviewer/doctrine.md +171 -0
  56. package/dist/vinaya-strict/executing/security-reviewer/evals/README.md +1 -0
  57. package/dist/vinaya-strict/executing/security-reviewer/evals/security-reviewer-cases.json +141 -0
  58. package/dist/vinaya-strict/executing/security-reviewer/grants.yaml +22 -0
  59. package/dist/vinaya-strict/executing/security-reviewer/output.schema.json +93 -0
  60. package/dist/vinaya-strict/integration/config/vinaya-config-section.ts +1278 -0
  61. package/dist/vinaya-strict/integration/policies/vinaya-policies.ts +52 -0
  62. package/dist/vinaya-strict/integration/process/process-integration.ts +57 -0
  63. package/dist/vinaya-strict/loops/dev-review/v2/dev-review-v2.flow.yaml +136 -0
  64. package/dist/vinaya-strict/process.yaml +43 -0
  65. package/dist/vinaya-strict/retrospecting/archivist/doctrine.md +174 -0
  66. package/dist/vinaya-strict/retrospecting/tranche-archivist/doctrine.md +270 -0
  67. package/dist/vinaya-strict/thinking/architect/doctrine.md +110 -0
  68. package/dist/vinaya-strict/thinking/planner/doctrine.md +105 -0
  69. package/dist/vinaya-strict/thinking/planner/tools/amend-rationale-deps.test.ts +128 -0
  70. package/dist/vinaya-strict/thinking/planner/tools/amend-rationale-deps.ts +169 -0
  71. package/dist/vinaya-strict/thinking/planner/tools/open-issue.test.ts +701 -0
  72. package/dist/vinaya-strict/thinking/planner/tools/open-issue.ts +1035 -0
  73. package/dist/vinaya-strict/thinking/planner/tools/planner-operations.test.ts +359 -0
  74. package/dist/vinaya-strict/thinking/planner/tools/planner-operations.ts +815 -0
  75. package/dist/vinaya-strict/thinking/planner/tools/planner-tools.test.ts +200 -0
  76. package/dist/vinaya-strict/thinking/planner/tools/planner-tools.ts +458 -0
  77. package/package.json +4 -2
  78. package/studio-standalone/apps/vinaya-studio/.next/BUILD_ID +1 -1
  79. package/studio-standalone/apps/vinaya-studio/.next/build-manifest.json +2 -2
  80. package/studio-standalone/apps/vinaya-studio/.next/server/app/_global-error.html +1 -1
  81. package/studio-standalone/apps/vinaya-studio/.next/server/app/_global-error.rsc +1 -1
  82. package/studio-standalone/apps/vinaya-studio/.next/server/app/_global-error.segments/_full.segment.rsc +1 -1
  83. package/studio-standalone/apps/vinaya-studio/.next/server/app/_global-error.segments/_global-error/__PAGE__.segment.rsc +1 -1
  84. package/studio-standalone/apps/vinaya-studio/.next/server/app/_global-error.segments/_tree.segment.rsc +1 -1
  85. package/studio-standalone/apps/vinaya-studio/.next/server/middleware-build-manifest.js +1 -1
  86. package/studio-standalone/apps/vinaya-studio/.next/server/pages/500.html +1 -1
  87. /package/studio-standalone/apps/vinaya-studio/.next/static/{yFfoujElgbwPk-7KNS-kw → x2q88XfwsihlevulRhIvs}/_buildManifest.js +0 -0
  88. /package/studio-standalone/apps/vinaya-studio/.next/static/{yFfoujElgbwPk-7KNS-kw → x2q88XfwsihlevulRhIvs}/_ssgManifest.js +0 -0
@@ -0,0 +1,200 @@
1
+ import { describe, expect, it } from 'bun:test'
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'
5
+ import { PLANNER_TOOL_ENTRIES, PLANNER_TOOL_NAMES, plannerToolHandlers, type PlannerOperations } from './planner-tools'
6
+
7
+ const finding = (check: string) => makeCheckError(check, `${check} message`, `${check} recovery`)
8
+
9
+ /** Operations that record what they were called with and answer what a test says. */
10
+ function stubOps(
11
+ over: Partial<PlannerOperations> = {}
12
+ ): PlannerOperations & { calls: { op: string; arg: unknown; body?: string }[] } {
13
+ const calls: { op: string; arg: unknown; body?: string }[] = []
14
+ const bodyOf = (args: string[]) => {
15
+ const i = args.indexOf('--body-file')
16
+ return i >= 0 ? readFileSync(args[i + 1] as string, 'utf8') : undefined
17
+ }
18
+ const ops: PlannerOperations = {
19
+ createIssue: async (input) => {
20
+ calls.push({ op: 'create', arg: input, body: bodyOf(input.ghArgs) })
21
+ return {
22
+ ok: true,
23
+ written: !input.validateOnly,
24
+ url: input.validateOnly ? '' : 'https://example.test/issues/7',
25
+ renderSkipped: null,
26
+ warnings: []
27
+ }
28
+ },
29
+ editIssue: async (input) => {
30
+ calls.push({ op: 'edit', arg: input, body: bodyOf(input.args) })
31
+ return {
32
+ ok: true,
33
+ written: !input.validateOnly,
34
+ url: input.validateOnly ? '' : 'https://example.test/issues/9',
35
+ renderSkipped: null,
36
+ warnings: []
37
+ }
38
+ },
39
+ editObjectives: async (args) => {
40
+ calls.push({ op: 'objectives', arg: args })
41
+ return { ok: true, version: 'v2', url: 'https://example.test/issues/9#c', supersedeUrl: null }
42
+ },
43
+ printIssueSurface: (args) => {
44
+ calls.push({ op: 'surface', arg: args, body: bodyOf(args) })
45
+ return { ok: true, set: { forced: [] } as never, json: false, text: 'surface text' }
46
+ },
47
+ renderBrief: async (input) => {
48
+ calls.push({ op: 'brief', arg: input })
49
+ return { ok: true, brief: '# brief' }
50
+ },
51
+ ...over
52
+ }
53
+ return Object.assign(ops, { calls })
54
+ }
55
+
56
+ const call = (ops: PlannerOperations, name: (typeof PLANNER_TOOL_NAMES)[number], input: unknown) =>
57
+ plannerToolHandlers(ops)[name](input, { caller: null })
58
+
59
+ const refusalFindings = (r: Awaited<ReturnType<typeof call>>) => {
60
+ if (r.ok) throw new Error('expected a refusal')
61
+ expect(TaskToolErrorSchema.safeParse(r.error).success).toBe(true)
62
+ expect(r.error.kind).toBe('validation')
63
+ return JSON.parse(r.error.detail as string) as { check: string; message: string; recovery: string }[]
64
+ }
65
+
66
+ describe('the Planner tool entries', () => {
67
+ it('are the six tools, each with an input and an output schema', () => {
68
+ expect(PLANNER_TOOL_ENTRIES.map((e) => e.name)).toEqual([...PLANNER_TOOL_NAMES])
69
+ for (const entry of PLANNER_TOOL_ENTRIES) {
70
+ expect(entry.inputSchema.type).toBe('object')
71
+ expect(entry.outputSchema?.type).toBe('object')
72
+ }
73
+ })
74
+
75
+ it('describe the Issue writers without a retired command word', () => {
76
+ for (const name of ['task_issue_create', 'task_issue_edit']) {
77
+ const description = PLANNER_TOOL_ENTRIES.find((e) => e.name === name)?.description ?? ''
78
+ expect(description).not.toBe('')
79
+ for (const word of ['issue', 'brief', 'milestone']) expect(description).not.toContain(`vinaya ${word}`)
80
+ }
81
+ })
82
+ })
83
+
84
+ describe('success returns the library’s outcome', () => {
85
+ it('task_issue_create returns the written Issue’s link and hands the library the body as a file', async () => {
86
+ const ops = stubOps()
87
+ const r = await call(ops, 'task_issue_create', { title: 'T', body: '## Objectives\nO1.', labels: ['a', 'b'] })
88
+ expect(r).toEqual({
89
+ ok: true,
90
+ result: { written: true, url: 'https://example.test/issues/7', renderSkipped: null, warnings: [] }
91
+ })
92
+ expect(ops.calls[0]?.body).toBe('## Objectives\nO1.')
93
+ const ghArgs = ((ops.calls[0] as { arg: unknown }).arg as { ghArgs: string[] }).ghArgs
94
+ expect(ghArgs).toContain('--title')
95
+ expect(ghArgs.filter((a) => a === '--label')).toHaveLength(2)
96
+ })
97
+ it('task_issue_edit passes the Issue first and returns the link', async () => {
98
+ const ops = stubOps()
99
+ const r = await call(ops, 'task_issue_edit', { issue: 9, body: 'B', addLabels: ['x'] })
100
+ expect(r).toMatchObject({ ok: true, result: { written: true, url: 'https://example.test/issues/9' } })
101
+ expect(((ops.calls[0] as { arg: unknown }).arg as { args: string[] }).args[0]).toBe('9')
102
+ expect(ops.calls[0]?.body).toBe('B')
103
+ })
104
+ it('task_issue_validate runs validate-only for create and for edit and writes nothing', async () => {
105
+ const ops = stubOps()
106
+ const c = await call(ops, 'task_issue_validate', { mode: 'create', body: 'B' })
107
+ const e = await call(ops, 'task_issue_validate', { mode: 'edit', issue: 9, body: 'B' })
108
+ expect(c).toMatchObject({ ok: true, result: { written: false, url: '' } })
109
+ expect(e).toMatchObject({ ok: true, result: { written: false, url: '' } })
110
+ expect(ops.calls.map((x) => (x.arg as { validateOnly?: boolean }).validateOnly)).toEqual([true, true])
111
+ })
112
+ it('task_issue_surface returns the library’s text', async () => {
113
+ expect(await call(stubOps(), 'task_issue_surface', { body: 'B' })).toMatchObject({
114
+ ok: true,
115
+ result: { text: 'surface text' }
116
+ })
117
+ })
118
+ it('task_objectives_edit builds the library’s arguments from the operation', async () => {
119
+ const ops = stubOps()
120
+ const r = await call(ops, 'task_objectives_edit', {
121
+ op: 'replace',
122
+ issue: 9,
123
+ id: 'O2',
124
+ sentence: 'S',
125
+ reason: 'why'
126
+ })
127
+ expect(r).toMatchObject({ ok: true, result: { version: 'v2', supersedeUrl: null } })
128
+ expect(ops.calls[0]?.arg).toEqual(['9', '--replace', 'O2', 'S', '--reason', 'why'])
129
+ await call(ops, 'task_objectives_edit', { op: 'add', issue: 9, sentence: 'S', reason: 'why', part: 'P' })
130
+ expect(ops.calls[1]?.arg).toEqual(['9', '--add', 'S', '--part', 'P', '--reason', 'why'])
131
+ })
132
+ it('brief_render returns the rendered text', async () => {
133
+ const ops = stubOps()
134
+ expect(await call(ops, 'brief_render', { tranche: 't', id: '3' })).toEqual({
135
+ ok: true,
136
+ result: { brief: '# brief' }
137
+ })
138
+ expect(ops.calls[0]?.arg).toEqual({ trancheSlug: 't', taskId: '3' })
139
+ })
140
+ })
141
+
142
+ describe('refusal keeps every finding’s check name and recovery text', () => {
143
+ const findings = [finding('first-check'), finding('second-check')]
144
+
145
+ it('an Issue write refusal: message is the first finding, detail is every finding', async () => {
146
+ const ops = stubOps({ createIssue: async () => ({ ok: false, findings, warnings: [] }) })
147
+ const r = await call(ops, 'task_issue_create', { title: 'T', body: 'B' })
148
+ expect(!r.ok && r.error.message).toBe('first-check message')
149
+ expect(refusalFindings(r)).toEqual([
150
+ { check: 'first-check', message: 'first-check message', recovery: 'first-check recovery' },
151
+ { check: 'second-check', message: 'second-check message', recovery: 'second-check recovery' }
152
+ ])
153
+ })
154
+ it('the edit, validate and objectives tools refuse the same way', async () => {
155
+ const ops = stubOps({
156
+ editIssue: async () => ({ ok: false, findings, warnings: [] }),
157
+ createIssue: async () => ({ ok: false, findings, warnings: [] }),
158
+ editObjectives: async () => ({ ok: false, findings })
159
+ })
160
+ const results = [
161
+ await call(ops, 'task_issue_edit', { issue: 1, title: 'T' }),
162
+ await call(ops, 'task_issue_validate', { mode: 'create', body: 'B' }),
163
+ await call(ops, 'task_issue_validate', { mode: 'edit', issue: 1, body: 'B' }),
164
+ await call(ops, 'task_objectives_edit', { op: 'drop', issue: 1, id: 'O1', reason: 'r' })
165
+ ]
166
+ for (const r of results) expect(refusalFindings(r).map((f) => f.check)).toEqual(['first-check', 'second-check'])
167
+ })
168
+ it('a surface refusal and a brief refusal carry a check name and recovery text', async () => {
169
+ const ops = stubOps({
170
+ printIssueSurface: () => ({ ok: false, exitCode: 2, message: 'issue surface: no parse\n' }),
171
+ renderBrief: async () => ({ ok: false, missing: ['Boundary', 'Parts'] })
172
+ })
173
+ const s = refusalFindings(await call(ops, 'task_issue_surface', { body: 'B' }))
174
+ expect(s[0]).toMatchObject({ check: 'issue-surface', message: 'issue surface: no parse' })
175
+ expect(s[0]?.recovery.length).toBeGreaterThan(0)
176
+ const b = refusalFindings(await call(ops, 'brief_render', { tranche: 't', id: '3' }))
177
+ expect(b.map((f) => f.check)).toEqual(['brief-render', 'brief-render'])
178
+ expect(b[1]?.message).toContain('Parts')
179
+ })
180
+ it('a malformed input is refused in the same encoding, before any library call', async () => {
181
+ const ops = stubOps()
182
+ const r = await call(ops, 'task_issue_create', { title: '' })
183
+ expect(refusalFindings(r)[0]?.check).toBe('tool-input')
184
+ expect((await call(ops, 'task_issue_edit', { issue: 3 })).ok).toBe(false)
185
+ expect((await call(ops, 'task_issue_validate', { mode: 'edit', body: 'B' })).ok).toBe(false)
186
+ expect(ops.calls).toEqual([])
187
+ })
188
+ })
189
+
190
+ describe('no tool ends the server', () => {
191
+ it('a library that throws is an infrastructure error, not an escape', async () => {
192
+ const ops = stubOps({
193
+ createIssue: async () => {
194
+ throw new Error('boom')
195
+ }
196
+ })
197
+ const r = await call(ops, 'task_issue_create', { title: 'T', body: 'B' })
198
+ expect(r).toEqual({ ok: false, error: { kind: 'infrastructure', message: 'boom' } })
199
+ })
200
+ })
@@ -0,0 +1,458 @@
1
+ /**
2
+ * The Planner's role tools — the six operations the Planner writes a task
3
+ * Issue with, served on the Planner's own seat of the tool host. Each tool
4
+ * validates its input, calls ONE operation of the Planner library
5
+ * (`planner-operations.ts`, which returns an outcome and never ends the
6
+ * process — never a command function, which parses argv and exits) and returns
7
+ * that outcome: the written Issue's link or the rendered text on success; on
8
+ * refusal a `validation` error in the task tools' typed shape whose `message`
9
+ * is the first finding and whose string `detail` is the JSON text of EVERY
10
+ * finding as `{check, message, recovery}`, so no finding loses its check name
11
+ * or its recovery text. A handler never throws past its boundary: an
12
+ * unexpected failure is an `infrastructure` error, so no call ends the server.
13
+ *
14
+ * The catalog entries (name, description, input and output JSON Schema) and
15
+ * the handlers are defined here; the seat table (`integration/server.ts`)
16
+ * binds them to the Planner seat and its grant (`integration/policies/roles.ts`).
17
+ */
18
+
19
+ import { mkdtempSync, rmSync, writeFileSync } from 'node:fs'
20
+ import { tmpdir } from 'node:os'
21
+ import { join } from 'node:path'
22
+ import { z } from 'zod'
23
+ import { taskToolError, type TaskToolError } from '../../../../../kernel/tools/catalog/task-tools'
24
+ import type { SeatCallResult, SeatHandler } from '../../../../../kernel/tools/host/seat-host.js'
25
+ import type { McpToolListEntry } from '../../../../../kernel/tools/mcp-protocol.js'
26
+ import type { CheckError } from '../../../../../kernel/gates/checks/contract'
27
+ import {
28
+ createIssue,
29
+ editIssue,
30
+ editObjectives,
31
+ printIssueSurface,
32
+ renderBrief,
33
+ type BriefOutcome,
34
+ type IssueWriteOutcome,
35
+ type ObjectivesOutcome,
36
+ type SurfaceOutcome
37
+ } from './planner-operations'
38
+
39
+ // --- names ------------------------------------------------------------------
40
+
41
+ /** The six tools the Planner's seat is granted, in the order the seat lists them. */
42
+ export const PLANNER_TOOL_NAMES = [
43
+ 'task_issue_create',
44
+ 'task_issue_edit',
45
+ 'task_issue_surface',
46
+ 'task_objectives_edit',
47
+ 'brief_render',
48
+ 'task_issue_validate'
49
+ ] as const
50
+
51
+ export type PlannerToolName = (typeof PLANNER_TOOL_NAMES)[number]
52
+
53
+ // --- findings and the typed refusal -----------------------------------------
54
+
55
+ /** One finding as a refusal's detail carries it. */
56
+ export type PlannerFinding = { check: string; message: string; recovery: string }
57
+
58
+ const finding = (check: string, message: string, recovery: string): PlannerFinding => ({ check, message, recovery })
59
+
60
+ const fromCheckError = (e: CheckError): PlannerFinding => ({
61
+ check: e.check,
62
+ message: e.message,
63
+ recovery: e.agent_recovery_prompt
64
+ })
65
+
66
+ /** The refusal every tool returns: `message` is the first finding, `detail` the JSON text of all of them. */
67
+ export function findingsRefusal(findings: readonly PlannerFinding[]): TaskToolError {
68
+ const first = findings[0]
69
+ return taskToolError(
70
+ 'validation',
71
+ first ? first.message : 'the operation was refused without a finding',
72
+ JSON.stringify(findings)
73
+ )
74
+ }
75
+
76
+ const refused = (findings: readonly PlannerFinding[]): SeatCallResult => ({
77
+ ok: false,
78
+ error: findingsRefusal(findings)
79
+ })
80
+ const succeeded = (result: unknown): SeatCallResult => ({ ok: true, result })
81
+
82
+ // --- input schemas ------------------------------------------------------------
83
+
84
+ const label = z
85
+ .string()
86
+ .min(1)
87
+ .refine((l) => !l.includes(','), 'a label carries no comma')
88
+ const issueNumber = z.number().int().min(1)
89
+
90
+ const CreateInput = z
91
+ .object({
92
+ title: z.string().min(1),
93
+ body: z.string().min(1),
94
+ labels: z.array(label).optional(),
95
+ milestone: z.string().min(1).optional()
96
+ })
97
+ .strict()
98
+
99
+ const EditInput = z
100
+ .object({
101
+ issue: issueNumber,
102
+ title: z.string().min(1).optional(),
103
+ body: z.string().min(1).optional(),
104
+ addLabels: z.array(label).optional()
105
+ })
106
+ .strict()
107
+ .refine((v) => v.title !== undefined || v.body !== undefined || (v.addLabels?.length ?? 0) > 0, {
108
+ message: 'an edit changes at least one of title, body, addLabels'
109
+ })
110
+
111
+ const ValidateInput = z
112
+ .object({
113
+ mode: z.enum(['create', 'edit']),
114
+ issue: issueNumber.optional(),
115
+ title: z.string().min(1).optional(),
116
+ body: z.string().min(1),
117
+ labels: z.array(label).optional()
118
+ })
119
+ .strict()
120
+ .refine((v) => (v.mode === 'edit') === (v.issue !== undefined), {
121
+ message: 'issue is given for mode "edit" and for no other mode'
122
+ })
123
+
124
+ const SurfaceInput = z.object({ body: z.string().min(1) }).strict()
125
+
126
+ const ObjectivesInput = z.discriminatedUnion('op', [
127
+ z
128
+ .object({
129
+ op: z.literal('add'),
130
+ issue: issueNumber,
131
+ sentence: z.string().min(1),
132
+ reason: z.string().min(1),
133
+ part: z.string().min(1).optional()
134
+ })
135
+ .strict(),
136
+ z.object({ op: z.literal('drop'), issue: issueNumber, id: z.string().min(1), reason: z.string().min(1) }).strict(),
137
+ z
138
+ .object({
139
+ op: z.literal('replace'),
140
+ issue: issueNumber,
141
+ id: z.string().min(1),
142
+ sentence: z.string().min(1),
143
+ reason: z.string().min(1)
144
+ })
145
+ .strict()
146
+ ])
147
+
148
+ const BriefInput = z
149
+ .object({ tranche: z.string().min(1), id: z.string().min(1), globs: z.array(z.string().min(1)).optional() })
150
+ .strict()
151
+
152
+ // --- JSON Schemas (the wire needs them; Zod 3 ships no exporter) ---------------
153
+
154
+ const str = { type: 'string', minLength: 1 } as const
155
+ const labelsSchema = { type: 'array', items: { type: 'string', minLength: 1, pattern: '^[^,]+$' } } as const
156
+ const issueSchema = { type: 'integer', minimum: 1 } as const
157
+
158
+ const FINDING_JSON_SCHEMA = {
159
+ type: 'object',
160
+ properties: { check: { type: 'string' }, message: { type: 'string' }, recovery: { type: 'string' } },
161
+ required: ['check', 'message', 'recovery'],
162
+ additionalProperties: false
163
+ } as const
164
+ const FINDINGS_ARRAY = { type: 'array', items: FINDING_JSON_SCHEMA } as const
165
+
166
+ const WRITTEN_OUTPUT = {
167
+ type: 'object',
168
+ properties: {
169
+ written: { type: 'boolean' },
170
+ url: { type: 'string', description: "The written Issue's link; empty when nothing was written." },
171
+ renderSkipped: { type: ['string', 'null'] },
172
+ warnings: FINDINGS_ARRAY
173
+ },
174
+ required: ['written', 'url', 'renderSkipped', 'warnings'],
175
+ additionalProperties: false
176
+ } as const
177
+
178
+ /** The input JSON Schema of each tool. */
179
+ export const PLANNER_TOOL_INPUT_JSON_SCHEMAS: Record<PlannerToolName, Record<string, unknown>> = {
180
+ task_issue_create: {
181
+ type: 'object',
182
+ properties: { title: str, body: str, labels: labelsSchema, milestone: str },
183
+ required: ['title', 'body'],
184
+ additionalProperties: false
185
+ },
186
+ task_issue_edit: {
187
+ type: 'object',
188
+ properties: { issue: issueSchema, title: str, body: str, addLabels: labelsSchema },
189
+ required: ['issue'],
190
+ additionalProperties: false
191
+ },
192
+ task_issue_surface: {
193
+ type: 'object',
194
+ properties: { body: str },
195
+ required: ['body'],
196
+ additionalProperties: false
197
+ },
198
+ task_objectives_edit: {
199
+ type: 'object',
200
+ properties: {
201
+ op: { enum: ['add', 'drop', 'replace'] },
202
+ issue: issueSchema,
203
+ sentence: { ...str, description: 'The objective sentence, for add and replace.' },
204
+ id: { ...str, description: 'The objective id (O<k>), for drop and replace.' },
205
+ reason: str,
206
+ part: { ...str, description: 'The Parts line written with an added objective.' }
207
+ },
208
+ required: ['op', 'issue', 'reason'],
209
+ additionalProperties: false
210
+ },
211
+ brief_render: {
212
+ type: 'object',
213
+ properties: { tranche: str, id: str, globs: { type: 'array', items: str } },
214
+ required: ['tranche', 'id'],
215
+ additionalProperties: false
216
+ },
217
+ task_issue_validate: {
218
+ type: 'object',
219
+ properties: {
220
+ mode: {
221
+ enum: ['create', 'edit'],
222
+ description: 'Which write gate to run: the one create or the one edit passes.'
223
+ },
224
+ issue: { ...issueSchema, description: 'The Issue number, for mode "edit" only.' },
225
+ title: str,
226
+ body: str,
227
+ labels: labelsSchema
228
+ },
229
+ required: ['mode', 'body'],
230
+ additionalProperties: false
231
+ }
232
+ }
233
+
234
+ /** The output JSON Schema of each tool, as a success returns it. */
235
+ export const PLANNER_TOOL_OUTPUT_JSON_SCHEMAS: Record<PlannerToolName, Record<string, unknown>> = {
236
+ task_issue_create: WRITTEN_OUTPUT,
237
+ task_issue_edit: WRITTEN_OUTPUT,
238
+ task_issue_validate: WRITTEN_OUTPUT,
239
+ task_issue_surface: {
240
+ type: 'object',
241
+ properties: { text: { type: 'string' }, set: { type: 'object' } },
242
+ required: ['text', 'set'],
243
+ additionalProperties: false
244
+ },
245
+ task_objectives_edit: {
246
+ type: 'object',
247
+ properties: { version: { type: 'string' }, url: { type: 'string' }, supersedeUrl: { type: ['string', 'null'] } },
248
+ required: ['version', 'url', 'supersedeUrl'],
249
+ additionalProperties: false
250
+ },
251
+ brief_render: {
252
+ type: 'object',
253
+ properties: { brief: { type: 'string' } },
254
+ required: ['brief'],
255
+ additionalProperties: false
256
+ }
257
+ }
258
+
259
+ const REFUSAL_NOTE =
260
+ 'A refusal is a `validation` error: `message` is the first finding, `detail` is the JSON text of every finding as {check, message, recovery}.'
261
+
262
+ const DESCRIPTIONS: Record<PlannerToolName, string> = {
263
+ task_issue_create: `Create a task Issue from a title, a body and labels through the Issue write gate (the same gates \`task_issue_validate\` dry-runs for a create), then write it. Returns the written Issue's link. ${REFUSAL_NOTE}`,
264
+ task_issue_edit: `Edit a task Issue's title, body or labels through the Issue write gate (the same gates \`task_issue_validate\` dry-runs for an edit). Returns the Issue's link. ${REFUSAL_NOTE}`,
265
+ task_issue_surface: `Report what a draft Issue body's Boundary pins force on its Surface. Writes nothing. ${REFUSAL_NOTE}`,
266
+ task_objectives_edit: `Add, drop or replace one objective of an Issue's \`## Objectives\` (Principal only); supersedes a frozen brief when one exists. Returns the new objectives version. ${REFUSAL_NOTE}`,
267
+ brief_render: `Render a task's brief from its Issue; a refusal lists the facts it could not find. Writes nothing. ${REFUSAL_NOTE}`,
268
+ task_issue_validate: `Dry-run the Issue write gate for a create or an edit: runs exactly the gates create and edit run, writes nothing, and returns the findings in the same encoding as the other tools. ${REFUSAL_NOTE}`
269
+ }
270
+
271
+ /** The Planner seat's catalog entries, in the order the seat lists them. */
272
+ export const PLANNER_TOOL_ENTRIES: readonly McpToolListEntry[] = PLANNER_TOOL_NAMES.map((name) => ({
273
+ name,
274
+ description: DESCRIPTIONS[name],
275
+ inputSchema: PLANNER_TOOL_INPUT_JSON_SCHEMAS[name],
276
+ outputSchema: PLANNER_TOOL_OUTPUT_JSON_SCHEMAS[name]
277
+ }))
278
+
279
+ // --- handlers -------------------------------------------------------------------
280
+
281
+ /** The library operations each tool calls, replaceable so a test stubs the forge. */
282
+ export type PlannerOperations = {
283
+ createIssue: (input: { ghArgs: string[]; validateOnly?: boolean }) => Promise<IssueWriteOutcome>
284
+ editIssue: (input: { args: string[]; validateOnly?: boolean }) => Promise<IssueWriteOutcome>
285
+ editObjectives: (args: string[]) => Promise<ObjectivesOutcome>
286
+ printIssueSurface: (args: string[]) => SurfaceOutcome
287
+ renderBrief: (input: { trancheSlug: string; taskId: string; globs?: string[] }) => Promise<BriefOutcome>
288
+ }
289
+
290
+ export const realPlannerOperations: PlannerOperations = {
291
+ createIssue: (input) => createIssue(input),
292
+ editIssue: (input) => editIssue(input),
293
+ editObjectives: (args) => editObjectives(args),
294
+ printIssueSurface,
295
+ renderBrief: (input) => renderBrief(input)
296
+ }
297
+
298
+ /** Writes a body to a scratch file the library reads (`--body-file`), and removes it when the operation is over. */
299
+ async function withBodyFile<T>(body: string | undefined, run: (bodyFile: string | null) => Promise<T> | T): Promise<T> {
300
+ if (body === undefined) return run(null)
301
+ const dir = mkdtempSync(join(tmpdir(), 'planner-tool-'))
302
+ try {
303
+ const file = join(dir, 'body.md')
304
+ writeFileSync(file, body, 'utf8')
305
+ return await run(file)
306
+ } finally {
307
+ rmSync(dir, { recursive: true, force: true })
308
+ }
309
+ }
310
+
311
+ const labelArgs = (flag: string, labels: readonly string[] | undefined) => (labels ?? []).flatMap((l) => [flag, l])
312
+
313
+ function issueOutcomeResult(outcome: IssueWriteOutcome): SeatCallResult {
314
+ if (!outcome.ok) return refused(outcome.findings.map(fromCheckError))
315
+ return succeeded({
316
+ written: outcome.written,
317
+ url: outcome.url,
318
+ renderSkipped: outcome.renderSkipped,
319
+ warnings: outcome.warnings.map(fromCheckError)
320
+ })
321
+ }
322
+
323
+ /** Parses the caller's input; a malformed one is a refusal in the same encoding as any other. */
324
+ function parse<S extends z.ZodTypeAny>(
325
+ schema: S,
326
+ input: unknown
327
+ ): { ok: true; value: z.infer<S> } | { ok: false; refusal: SeatCallResult } {
328
+ const r = schema.safeParse(input ?? {})
329
+ if (r.success) return { ok: true, value: r.data }
330
+ return {
331
+ ok: false,
332
+ refusal: refused(
333
+ r.error.issues.map((issue) =>
334
+ finding(
335
+ 'tool-input',
336
+ `${issue.path.length > 0 ? `${issue.path.join('.')}: ` : ''}${issue.message}`,
337
+ 'Correct the tool input to match its input schema, then call the tool again.'
338
+ )
339
+ )
340
+ )
341
+ }
342
+ }
343
+
344
+ /** Wraps a handler so nothing it throws ends the server: an unexpected failure is an `infrastructure` error. */
345
+ function guarded<S extends z.ZodTypeAny>(
346
+ schema: S,
347
+ run: (input: z.infer<S>) => Promise<SeatCallResult> | SeatCallResult
348
+ ): SeatHandler<unknown> {
349
+ return async (input) => {
350
+ const parsed = parse(schema, input)
351
+ if (!parsed.ok) return parsed.refusal
352
+ try {
353
+ return await run(parsed.value)
354
+ } catch (e) {
355
+ return { ok: false, error: taskToolError('infrastructure', e instanceof Error ? e.message : String(e)) }
356
+ }
357
+ }
358
+ }
359
+
360
+ /** The handler of each Planner tool, over the library operations given. */
361
+ export function plannerToolHandlers(
362
+ ops: PlannerOperations = realPlannerOperations
363
+ ): Record<PlannerToolName, SeatHandler<unknown>> {
364
+ return {
365
+ task_issue_create: guarded(CreateInput, (v) =>
366
+ withBodyFile(v.body, async (file) =>
367
+ issueOutcomeResult(
368
+ await ops.createIssue({
369
+ ghArgs: [
370
+ '--title',
371
+ v.title,
372
+ '--body-file',
373
+ file as string,
374
+ ...labelArgs('--label', v.labels),
375
+ ...(v.milestone ? ['--milestone', v.milestone] : [])
376
+ ]
377
+ })
378
+ )
379
+ )
380
+ ),
381
+ task_issue_edit: guarded(EditInput, (v) =>
382
+ withBodyFile(v.body, async (file) =>
383
+ issueOutcomeResult(
384
+ await ops.editIssue({
385
+ args: [
386
+ String(v.issue),
387
+ ...(v.title !== undefined ? ['--title', v.title] : []),
388
+ ...(file !== null ? ['--body-file', file] : []),
389
+ ...labelArgs('--add-label', v.addLabels)
390
+ ]
391
+ })
392
+ )
393
+ )
394
+ ),
395
+ task_issue_validate: guarded(ValidateInput, (v) =>
396
+ withBodyFile(v.body, async (file) => {
397
+ const common = [
398
+ ...(v.title !== undefined ? ['--title', v.title] : []),
399
+ '--body-file',
400
+ file as string,
401
+ ...labelArgs(v.mode === 'create' ? '--label' : '--add-label', v.labels)
402
+ ]
403
+ const outcome =
404
+ v.mode === 'create'
405
+ ? await ops.createIssue({ ghArgs: common, validateOnly: true })
406
+ : await ops.editIssue({ args: [String(v.issue), ...common], validateOnly: true })
407
+ return issueOutcomeResult(outcome)
408
+ })
409
+ ),
410
+ task_issue_surface: guarded(SurfaceInput, (v) =>
411
+ withBodyFile(v.body, (file) => {
412
+ const outcome = ops.printIssueSurface(['--body-file', file as string])
413
+ if (!outcome.ok) {
414
+ return refused([
415
+ finding(
416
+ 'issue-surface',
417
+ outcome.message.trim(),
418
+ "Fix the draft body's `## Surface` and Boundary pins, then call the tool again."
419
+ )
420
+ ])
421
+ }
422
+ return succeeded({ text: outcome.text, set: outcome.set })
423
+ })
424
+ ),
425
+ task_objectives_edit: guarded(ObjectivesInput, async (v) => {
426
+ const flags =
427
+ v.op === 'add'
428
+ ? ['--add', v.sentence, ...(v.part ? ['--part', v.part] : [])]
429
+ : v.op === 'drop'
430
+ ? ['--drop', v.id]
431
+ : ['--replace', v.id, v.sentence]
432
+ const outcome = await ops.editObjectives([String(v.issue), ...flags, '--reason', v.reason])
433
+ if (!outcome.ok) return refused(outcome.findings.map(fromCheckError))
434
+ return succeeded({ version: outcome.version, url: outcome.url, supersedeUrl: outcome.supersedeUrl })
435
+ }),
436
+ brief_render: guarded(BriefInput, async (v) => {
437
+ const outcome = await ops.renderBrief({
438
+ trancheSlug: v.tranche,
439
+ taskId: v.id,
440
+ ...(v.globs ? { globs: v.globs } : {})
441
+ })
442
+ if (!outcome.ok) {
443
+ return refused(
444
+ outcome.missing.length > 0
445
+ ? outcome.missing.map((m) =>
446
+ finding(
447
+ 'brief-render',
448
+ `the brief cannot be rendered: ${m}`,
449
+ 'Supply the missing fact in the task Issue, then render again.'
450
+ )
451
+ )
452
+ : [finding('brief-render', 'the brief cannot be rendered', 'Check the task Issue, then render again.')]
453
+ )
454
+ }
455
+ return succeeded({ brief: outcome.brief })
456
+ })
457
+ }
458
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@attalabs/vinaya",
3
- "version": "0.42.1",
3
+ "version": "0.43.0",
4
4
  "description": "Vinaya \u2014 deterministic checks every AI coding agent must satisfy before merge.",
5
5
  "type": "module",
6
6
  "license": "FSL-1.1-ALv2",
@@ -35,7 +35,9 @@
35
35
  "vinaya-log-send": "dist/programs/log-send.js",
36
36
  "vinaya-log-emit": "dist/programs/log-emit.js",
37
37
  "vinaya-log-selftest": "dist/programs/log-selftest.js",
38
- "vinaya-sync": "dist/programs/sync.js"
38
+ "vinaya-sync": "dist/programs/sync.js",
39
+ "vinaya-run-engine": "dist/programs/run-engine.js",
40
+ "vinaya-supervised-command": "dist/programs/supervised-command.js"
39
41
  },
40
42
  "exports": {
41
43
  "./harness": {
@@ -1 +1 @@
1
- yFfoujElgbwPk-7KNS-kw
1
+ x2q88XfwsihlevulRhIvs