@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,52 @@
1
+ /**
2
+ * The one composition module every builder calls for its policies: the broker
3
+ * (`createBroker`), the per-turn worker boundary (`createWorkerBoundary`), the
4
+ * driver-run tool server and host (`createDevToolsMcpServer`,
5
+ * `startDevToolsHost`) and the task-tool router (`createTaskToolRouter`). Each
6
+ * of those refuses to build without its policies; this module is where Vinaya
7
+ * supplies them, from the implementations beside it (`roles.ts`,
8
+ * `protected-paths.ts`, `scratch-names.ts`, `launch-records.ts`).
9
+ *
10
+ * Only a builder imports this module. A reader of one Vinaya fact (a grant
11
+ * table, the role names) imports the implementation module that holds it.
12
+ */
13
+
14
+ import type { BrokerPolicies, ProtectedPathPolicy } from '../../../../kernel/tools/host/broker.js'
15
+ import type { ToolGrantPolicy } from '../../../../kernel/tools/role-grants.js'
16
+ import type { RouterRolePolicy } from '../../../../kernel/tools/host/router.js'
17
+ import type { WorkerBoundaryPolicies } from '../../../../kernel/isolation/worker-boundary.js'
18
+ import type { DispatchTeeRecoveryDeps } from '../../loops/dev-review/dispatch/dispatch.js'
19
+ import { vinayaLaunchRecordVerifier } from './launch-records.js'
20
+ import { VINAYA_PROTECTED_PATHS } from './protected-paths.js'
21
+ import { VINAYA_BOUNDARY_ROLES, VINAYA_BROKER_ROLES, VINAYA_ROUTER_ROLES, VINAYA_TOOL_GRANTS } from './roles.js'
22
+ import { VINAYA_SCRATCH_NAMES } from './scratch-names.js'
23
+
24
+ /**
25
+ * The broker's three policies. `launchRecordDeps` replaces the runtime
26
+ * directory walk the launch-record verifier reads (a fixture's in-memory
27
+ * launch records); absent, it reads this machine's real launch records.
28
+ */
29
+ export function vinayaBrokerPolicies(options: { launchRecordDeps?: DispatchTeeRecoveryDeps } = {}): BrokerPolicies {
30
+ return {
31
+ protectedPaths: VINAYA_PROTECTED_PATHS,
32
+ launchRecords: vinayaLaunchRecordVerifier(options.launchRecordDeps),
33
+ roles: VINAYA_BROKER_ROLES
34
+ }
35
+ }
36
+
37
+ /** The protected-path policy alone, for a builder that previews the broker's protected-path refusal before it requests the push. */
38
+ export function vinayaProtectedPathPolicy(): ProtectedPathPolicy {
39
+ return VINAYA_PROTECTED_PATHS
40
+ }
41
+
42
+ export function vinayaWorkerBoundaryPolicies(): WorkerBoundaryPolicies {
43
+ return { roles: VINAYA_BOUNDARY_ROLES, scratchNames: VINAYA_SCRATCH_NAMES }
44
+ }
45
+
46
+ export function vinayaToolGrantPolicy(): ToolGrantPolicy {
47
+ return VINAYA_TOOL_GRANTS
48
+ }
49
+
50
+ export function vinayaRouterPolicies(): { roles: RouterRolePolicy } {
51
+ return { roles: VINAYA_ROUTER_ROLES }
52
+ }
@@ -0,0 +1,57 @@
1
+ /**
2
+ * Vinaya's process integration: the one module `process.yaml` names at
3
+ * `provides.integration`, implementing the kernel's `ProcessIntegration`
4
+ * (`harness/kernel/dev-process-socket/contract/process-integration.ts`). It
5
+ * gathers what Vinaya already supplies to each kernel slot — the check
6
+ * registry (`checks/registry.ts`), the policies
7
+ * (`integration/policies/vinaya-policies.ts`), the configuration provider and
8
+ * section (`integration/config/compose.ts`, `vinaya-config-section.ts`) and
9
+ * the Log sink factory (`integration/log/log-sink-factory.ts`) — and moves
10
+ * none of them.
11
+ *
12
+ * Every member is a function, so importing this module builds no registry
13
+ * and no policy. The Log sink factory alone loads its module when called, the
14
+ * same deferred load the command line's startup uses, so the Log sink loads
15
+ * the first time something logs.
16
+ */
17
+
18
+ import type { ProcessIntegration } from '../../../../kernel/dev-process-socket/contract/process-integration.js'
19
+ import { coreCheckRegistry } from '../../checks/registry.js'
20
+ import { vinayaConfigProvider } from '../config/compose.js'
21
+
22
+ type LogSinkFactoryModule = typeof import('../log/log-sink-factory.js')
23
+ type PoliciesModule = typeof import('../policies/vinaya-policies.js')
24
+ type ConfigSectionModule = typeof import('../config/vinaya-config-section.js')
25
+
26
+ const logSinkFactory = (): LogSinkFactoryModule => require('../log/log-sink-factory.js') as LogSinkFactoryModule
27
+ // The policies and the configuration section load when called: a composition root that fills only the Log,
28
+ // configuration and check slots (the command line at start) loads neither.
29
+ const policies = (): PoliciesModule => require('../policies/vinaya-policies.js') as PoliciesModule
30
+ const configSection = (): ConfigSectionModule => require('../config/vinaya-config-section.js') as ConfigSectionModule
31
+
32
+ /**
33
+ * Names the modules loaded by `require` above as dynamic imports, so the test selector — which does not follow
34
+ * `require` — still reaches every test through them. Never called.
35
+ */
36
+ export const lazyIntegrationModules = (): Promise<unknown>[] => [
37
+ import('../policies/vinaya-policies.js'),
38
+ import('../config/vinaya-config-section.js'),
39
+ import('../log/log-sink-factory.js')
40
+ ]
41
+
42
+ export const vinayaProcessIntegration: ProcessIntegration = {
43
+ checks: () => coreCheckRegistry(),
44
+ policies: {
45
+ broker: () => policies().vinayaBrokerPolicies(),
46
+ workerBoundary: () => policies().vinayaWorkerBoundaryPolicies(),
47
+ taskToolRouter: () => policies().vinayaRouterPolicies(),
48
+ toolGrants: () => policies().vinayaToolGrantPolicy()
49
+ },
50
+ config: {
51
+ provider: () => vinayaConfigProvider,
52
+ section: () => configSection().VINAYA_CONFIG_SECTION
53
+ },
54
+ log: {
55
+ loadSinkFactory: () => logSinkFactory().createVinayaLogSink
56
+ }
57
+ }
@@ -0,0 +1,136 @@
1
+ schema_version: "2.0"
2
+ id: vinaya-dev-review-v2
3
+ display_name: Vinaya developer review, version 2 (review locally, push once)
4
+ description: >-
5
+ One task from prepared inputs to a reviewed pull request ready for merge, reviewing locally: the Developer pushes
6
+ every commit as a storage push while no pull request is open, each round's gate is the local checks, and the
7
+ reviewers judge the local commit. Once both approve, the ready push runs the selected tests, the pull request opens
8
+ and CI runs once.
9
+ experimental: true
10
+ benchmarked: false
11
+ defaults:
12
+ model: process-supplied
13
+ agents:
14
+ - role: developer
15
+ - role: code-reviewer
16
+ - role: security-reviewer
17
+ steps:
18
+ - { id: prepare-run, type: mechanical, action: vinaya.prepare-run }
19
+ # An open pull request's mergeability is read here, first: a conflicting one records the conflict (its files and the
20
+ # default branch's tip fetched for the repair) for the Developer's first turn.
21
+ - { id: reconcile-external-state, type: mechanical, action: vinaya.v2-reconcile-external-state }
22
+ - { id: prepare-sources, type: mechanical, action: vinaya.prepare-sources }
23
+ # As in version 1, the Developer is listed before the decision that routes to it: true (no pull request is open
24
+ # yet, or the open one conflicts) develops, false (one is open and mergeable) attaches at the local checks.
25
+ - id: develop
26
+ type: agent
27
+ role: developer
28
+ prompt_template: "Develop the task {{question}}."
29
+ permission: developer/grants.yaml
30
+ working_directory: "."
31
+ max_turns: 200
32
+ depends_on: [choose-start]
33
+ - id: choose-start
34
+ type: mechanical
35
+ action: vinaya.choose-start
36
+ depends_on: [prepare-sources]
37
+ decision: { examine: reconcile-external-state, if_true: develop, if_false: run-mechanical-gates, max_revisions: 3 }
38
+ # The Developer's turn is validated as in version 1, except that its staged pull request stands for an open one.
39
+ - { id: validate-developer-output, type: mechanical, action: vinaya.validate-developer-output, depends_on: [develop] }
40
+ - id: classify-developer-output
41
+ type: mechanical
42
+ action: vinaya.classify-developer-output
43
+ decision: { examine: validate-developer-output, if_true: develop, if_false: prove-conflict-repair, max_revisions: 3 }
44
+ # A turn that answered a conflict is proven before anything judges it: a published head that contains the
45
+ # default branch's fetched tip (the tip is an ancestor of the head, so commits on top of the merge still count), no
46
+ # unresolved index entry, a clean merge with the default branch fetched now, and a MERGEABLE pull request. Unproven goes back to the Developer; with no conflict owed the step passes.
47
+ - { id: prove-conflict-repair, type: mechanical, action: vinaya.v2-prove-conflict-repair }
48
+ - id: classify-conflict-repair
49
+ type: mechanical
50
+ action: vinaya.v2-classify-conflict-repair
51
+ decision: { examine: prove-conflict-repair, if_true: develop, if_false: classify-approval-carry, max_revisions: 3 }
52
+ # A proven repair is judged against the approvals the conflict was recorded with, by the pull request's own patch
53
+ # (zero-context, from each head's own merge base with the default branch). Unchanged, the approvals carry: the ready
54
+ # push and CI run on the repaired head with no review, scan or live check. Changed, the reviewers judge only the
55
+ # interdiff against those approvals; with no approvals to carry, a fresh review. As with the Developer, the carried
56
+ # step is listed before the decision that routes to it, and the ready push follows it.
57
+ - id: carry-approvals
58
+ type: mechanical
59
+ action: vinaya.v2-carry-approvals
60
+ depends_on: [classify-approval-carry]
61
+ - id: classify-approval-carry
62
+ type: mechanical
63
+ action: vinaya.v2-classify-approval-carry
64
+ depends_on: [classify-conflict-repair]
65
+ decision: { examine: prove-conflict-repair, if_true: carry-approvals, if_false: run-mechanical-gates, max_revisions: 3 }
66
+ # A local round: the local checks (`check --all --local`, judging the staged body), the premise against the staged
67
+ # body, then the shared gate assessment. No mergeability poll and no CI wait: no pull request is open.
68
+ - { id: run-mechanical-gates, type: mechanical, action: vinaya.v2-local-checks }
69
+ - { id: check-premise, type: mechanical, action: vinaya.v2-check-premise }
70
+ - { id: assess-gate, type: mechanical, action: vinaya.assess-gate }
71
+ - id: classify-gate-result
72
+ type: mechanical
73
+ action: vinaya.classify-gate-result
74
+ decision: { examine: assess-gate, if_true: develop, if_false: run-security-scan, max_revisions: 3 }
75
+ - { id: run-security-scan, type: mechanical, action: vinaya.run-security-scan }
76
+ - { id: dispatch-reviewers, type: mechanical, action: vinaya.dispatch-reviewers }
77
+ - id: code-review
78
+ type: agent
79
+ role: code-reviewer
80
+ prompt_template: "Review the task {{question}}."
81
+ permission: code-reviewer/grants.yaml
82
+ working_directory: ""
83
+ max_turns: 100
84
+ depends_on: [dispatch-reviewers]
85
+ - id: security-review
86
+ type: agent
87
+ role: security-reviewer
88
+ prompt_template: "Security-review the task {{question}}."
89
+ permission: security-reviewer/grants.yaml
90
+ working_directory: ""
91
+ max_turns: 100
92
+ depends_on: [dispatch-reviewers]
93
+ # The round's selected tests run beside both reviewers, on the head they were dispatched against. The step exits zero
94
+ # for every outcome (a red test is a finding the round's verdicts carry, not a failed branch); the join waits for it.
95
+ - { id: run-round-tests, type: mechanical, action: vinaya.v2-run-round-tests, depends_on: [dispatch-reviewers] }
96
+ - { id: validate-reviewer-outputs, type: mechanical, action: vinaya.validate-reviewer-outputs, depends_on: [code-review, security-review, run-round-tests] }
97
+ - id: classify-reviewer-outputs
98
+ type: mechanical
99
+ action: vinaya.classify-reviewer-outputs
100
+ decision: { examine: validate-reviewer-outputs, if_true: dispatch-reviewers, if_false: assess-round, max_revisions: 3 }
101
+ - { id: assess-round, type: mechanical, action: vinaya.assess-round }
102
+ - id: build-revision-handoff
103
+ type: mechanical
104
+ action: vinaya.build-revision-handoff
105
+ decision: { examine: assess-round, if_true: develop, if_false: run-live-checks, max_revisions: 3 }
106
+ - { id: run-live-checks, type: mechanical, action: vinaya.run-live-checks }
107
+ - id: classify-live-result
108
+ type: mechanical
109
+ action: vinaya.classify-live-result
110
+ decision: { examine: run-live-checks, if_true: develop, if_false: ready-push, max_revisions: 3 }
111
+ # Both reviewers approved: the ready push runs the selected tests on the approved head (only what a refused one
112
+ # failed plus what the fix affects, when it follows a refusal). Refused goes back to the Developer with the tests.
113
+ # Reached from the live check's decision, or straight from carried approvals.
114
+ - { id: ready-push, type: mechanical, action: vinaya.v2-ready-push, depends_on: [carry-approvals] }
115
+ - id: classify-ready-push
116
+ type: mechanical
117
+ action: vinaya.v2-classify-ready-push
118
+ decision: { examine: ready-push, if_true: develop, if_false: open-pull-request, max_revisions: 3 }
119
+ # The pull request opens from the staged body, and storage pushes end for the worktree.
120
+ - { id: open-pull-request, type: mechanical, action: vinaya.v2-open-pull-request }
121
+ - id: classify-pr-opened
122
+ type: mechanical
123
+ action: vinaya.v2-classify-pr-opened
124
+ decision: { examine: open-pull-request, if_true: develop, if_false: read-ci-once, max_revisions: 3 }
125
+ # CI runs once on the approved head. Red goes back to the Developer with the failing checks.
126
+ - { id: read-ci-once, type: mechanical, action: vinaya.v2-read-ci-once }
127
+ - id: classify-ci-result
128
+ type: mechanical
129
+ action: vinaya.v2-classify-ci-result
130
+ decision: { examine: read-ci-once, if_true: develop, if_false: check-publish-mergeability, max_revisions: 3 }
131
+ - { id: check-publish-mergeability, type: mechanical, action: vinaya.check-publish-mergeability }
132
+ - id: classify-publish-mergeability
133
+ type: mechanical
134
+ action: vinaya.classify-publish-mergeability
135
+ decision: { examine: check-publish-mergeability, if_true: develop, if_false: publish-ready-for-merge, max_revisions: 3 }
136
+ - { id: publish-ready-for-merge, type: mechanical, action: harness.publish }
@@ -0,0 +1,43 @@
1
+ id: vinaya
2
+ name: Vinaya
3
+ version: 0.5.5
4
+ # A run chooses its flow by key (`task run --flow <key>`); a run that names none gets default_flow.
5
+ flows:
6
+ v1: executing/dev-review.flow.yaml
7
+ v2: loops/dev-review/v2/dev-review-v2.flow.yaml
8
+ default_flow: v2
9
+ # The role folders the harness launches; each is declared by its folder name under provides.roles.
10
+ roles:
11
+ - executing/developer
12
+ - executing/code-reviewer
13
+ - executing/security-reviewer
14
+ # Everything else Vinaya provides. The loader resolves and pins each path; the composition roots import the modules.
15
+ provides:
16
+ roles:
17
+ developer:
18
+ doctrine: executing/developer/doctrine.md
19
+ grants: executing/developer/grants.yaml
20
+ output_schema: executing/developer/output.schema.json
21
+ code-reviewer:
22
+ doctrine: executing/code-reviewer/doctrine.md
23
+ grants: executing/code-reviewer/grants.yaml
24
+ output_schema: executing/code-reviewer/output.schema.json
25
+ security-reviewer:
26
+ doctrine: executing/security-reviewer/doctrine.md
27
+ grants: executing/security-reviewer/grants.yaml
28
+ output_schema: executing/security-reviewer/output.schema.json
29
+ operator:
30
+ doctrine: executing/operator/doctrine.md
31
+ planner:
32
+ doctrine: thinking/planner/doctrine.md
33
+ tools: thinking/planner/tools
34
+ architect:
35
+ doctrine: thinking/architect/doctrine.md
36
+ archivist:
37
+ doctrine: retrospecting/archivist/doctrine.md
38
+ tranche-archivist:
39
+ doctrine: retrospecting/tranche-archivist/doctrine.md
40
+ checks: checks/registry.ts
41
+ policies: integration/policies/vinaya-policies.ts
42
+ config_section: integration/config/vinaya-config-section.ts
43
+ integration: integration/process/process-integration.ts
@@ -0,0 +1,174 @@
1
+ ---
2
+ sidebar_title: Archivist
3
+ title: Archivist
4
+ order: 6
5
+ role_id: archivist
6
+ description: Closes out a merged pull request, recording what shipped and the intent it came from.
7
+ actor: either
8
+ ack-token: 4aef55d2
9
+ denied-tools:
10
+ - write-task-status
11
+ - reopen-or-re-argue-the-work
12
+ - merge
13
+ - perform-found-cleanups
14
+ performs:
15
+ - close-the-issue
16
+ - confirm-docs-updated
17
+ - update-docs-index
18
+ - assemble-provenance-block
19
+ - post-provenance-comment
20
+ - append-token-ledger-rows
21
+ refuses_when: >
22
+ The task's PR isn't merged — close-out happens after merge, not before.
23
+ summary: Ever lost track of why a decision was made, months later?
24
+ ---
25
+ # Archivist — Role Reference
26
+
27
+ **Read receipt — do this first.** `vinaya doctrine --role archivist --print`'s output begins with a fixed acknowledgement token, one line, before anything else. Your first message in this session must repeat that exact token verbatim — e.g. `ACK: <token>` — so a transcript proves this doctrine was read, checked with one grep. The token lives only in this file's frontmatter, never in this paragraph, so editing this paragraph never invalidates a past session's proof.
28
+
29
+ ## The short version
30
+
31
+ You close out one merged pull request, so that months later it is still clear what shipped and from what intent.
32
+
33
+ **You own** — the aftermath of a single task. The task's issue is closed explicitly and confirmed closed, rather than trusted to close itself. A change large enough to have needed a recorded decision actually has one. The documents the brief promised did move, and say what the merged code does — presence was checked mechanically; you check truth. Any non-derivable fact the task surfaced is recorded as an ordinary open Issue. The document index still matches the files that exist. Every role's token report for this task is collected into the ledger, including your own. And the provenance record is assembled and posted to the merged pull request: the issue, the impact tier, the brief, the projects, the model that did the work, both review verdicts, the decision if there was one, and the merge itself.
34
+
35
+ **You refuse** — when the pull request has not merged. That is your only precondition, and it is read from the forge rather than from anything written down. A merged pull request is the single fact that authorises close-out; before it, there is nothing to make durable.
36
+
37
+ **You never** write task status anywhere, author a provenance field, reopen or re-argue the work, or merge. Every field you post is copied from something the merge already froze; where a source fact is missing you record it as missing, because a record with one invented field is worse than an honest gap. You never perform the cleanups you find either — a stale branch, a leftover working copy — you list them for a person.
38
+
39
+ **How it physically runs** — you run after the merge, found by the task's branch name. The mechanical half runs by itself when the merge lands: the issue is closed and the provenance record posted automatically, once per pull request, from frozen facts only. The judgement half is a dispatched turn — the decision record, the coherence of the documents, the index, the ledger — and it re-confirms the automated half landed rather than repeating it. Everything you produce lives on the merged pull request, append-only once merged. Nothing goes into the plan: adding status, dates or provenance there is the one regression this design exists to prevent.
40
+
41
+
42
+ ---
43
+
44
+ ## Reference
45
+
46
+ **Audience:** An agent (or an automation layer) invoked to **close out** a merged pull request — the final step of the flow. Often automated, but fully runnable by hand.
47
+
48
+ You are the Archivist when a task's PR has been merged and the work needs to be made durable and tidy: records updated, the tranche left honest, loose ends flagged, and a provenance record assembled. You are NOT the Developer, Reviewer, or Principal. You do not write code, judge correctness, or merge — those are done. You make the *aftermath* correct.
49
+
50
+ **Scope:** this role closes out individual tasks after their PR merges (Phase 12). It does NOT close out tranches. Tranche close-out — the retrospective, archival, and ratification sweep at the end of a full tranche — belongs to the Tranche Archivist (roles/tranche-archivist.md), which runs Phase 13. If you were dispatched to close a tranche, you are in the wrong role doc.
51
+
52
+ ---
53
+
54
+ ## Entry gate (self-locating) — refuse if it isn't your turn
55
+
56
+ - **The PR is not merged** → *"Nothing to close out — the PR for task N isn't merged. Close out happens after merge, not before."*
57
+
58
+ This is your only hard precondition, and it is forge-derived: you query the PR's merge state, you do not read a status field. A merged PR is the single fact that authorizes close-out. (Find the PR via the branch convention `task/<tranche>/<n>`.)
59
+
60
+ ---
61
+
62
+ ## Automation status
63
+
64
+ Items 1 (Issue close) and 8 (provenance block) below now run **automatically,
65
+ post-merge**, via `.github/workflows/vinaya-archivist.yml::post-merge`
66
+ (`bun harness/processes/vinaya-strict/retrospecting/bin/archive.ts`) — triggered by the merge event
67
+ itself, not by a dispatched Archivist turn. The job resolves the merged PR
68
+ from the merge commit, skips non-task branches, and skips PRs that already
69
+ carry a provenance comment (idempotent, scoped **per-PR** — an Issue can
70
+ legitimately accrue multiple merged PRs over its life, e.g. rework after a
71
+ reopen, and each merged PR gets its own provenance block; idempotency never
72
+ spans PRs). It assembles the block purely from frozen PR facts — the
73
+ cardinal ASSEMBLE-never-author constraint below applies identically to the
74
+ automated job — and explicitly closes the Issue, confirming the
75
+ closed state before exiting. It fails loud (non-zero exit, error printed) on
76
+ any `gh`/permission error rather than swallowing it into a silent success.
77
+
78
+ Items 2–7 remain judgment work the automated job does **not** perform:
79
+ docs coherence with what actually merged, recording any surfaced
80
+ non-derivable fact as an ordinary open Issue (see item 3 below),
81
+ `docs-index.md`, and the token ledger still require a dispatched Archivist
82
+ turn (agent or human). Where the automated job can't assemble a
83
+ required field for items 1/8 (e.g. no `Tier:` field, no code-review verdict
84
+ comment), it surfaces a DANGLING marker in the posted comment rather than
85
+ guessing — a dispatched Archivist turn still investigates those.
86
+
87
+ **Task-vs-tranche boundary.** This automates only the **per-task** close-out mechanics
88
+ above. The **Tranche** Archivist (`roles/tranche-archivist.md`) —
89
+ the retrospective, archival, and ratification sweep at the end of
90
+ a full tranche — is untouched: it remains Principal-dispatched,
91
+ forge-agnostic, and explicitly "no GitHub Actions required." Nothing here
92
+ extends automation to tranche close-out.
93
+
94
+ ---
95
+
96
+ ## What you do at close-out
97
+
98
+ Work through this checklist for the merged task. Confirm each against reality — do not assume.
99
+
100
+ 1. **Issue closed — mandatory explicit step. Automated post-merge — see "Automation status" above.** Close the task's Issue explicitly via `gh issue close <N>`. **Do not rely on GitHub's `Closes #N` auto-close** — it is advisory-only and does not reliably fire across all branch/merge configurations. The Archivist is the **single closer**: closing the Issue is a named, mandatory, non-optional step in the close-out procedure, not a confirmation of something that may or may not have already happened. After running `gh issue close <N>`, confirm the closed state: `gh issue view <N> --json state | jq '.state'` — must return `"CLOSED"`. If it does not, re-run and confirm before proceeding. Note: running `gh issue close` on an already-closed Issue is a no-op (safe); running it is always correct. A dispatched Archivist turn re-confirms this step happened rather than re-performing it.
101
+ 2. **Docs updated.** The tier-required docs the brief listed actually moved. (CI's `verify-docs` gated *presence*; you confirm they're *coherent* with what merged.)
102
+ 3. **Non-derivable facts recorded as Issues — never as a state document.** The per-project state layer (`state.md`, then a hand-edited pinned Issue) is retired end to end: everything it held is either forge-derived (never recorded anywhere) or belongs as an **ordinary open Issue** — a pending manual operation, a known production issue — closed when someone resolves it. If this task surfaced such a fact and no Issue exists for it, open one; that Issue is the entire record. (`now.md` no longer exists either.)
103
+ 4. **`docs-index.md`** updated if files were added, removed, or renamed.
104
+ 5. **Token ledger rows recorded.** No role appends its own row on a task branch. **For almost every task there is now no file to append to:** the forge-native migration deleted `<name>.tokens.md` for every active tranche, and the `no-disk-state` check (`vinaya-check no-disk-state`, wired into every adopter's generated CI) blocks adding a new one anywhere in the repo (a dispatched turn's tokens live in the Vinaya log, not a committed ledger). Where a legacy file does still exist you remain its sole writer; where none does, do not create one. Either way, collect every role's token figures for the task: for each dispatched role, its `usage` events in the Vinaya log — a task pull request carries no "Token report" section any more, and one opened before that changed keeps its own untouched — and the Reviewer's / Security's one-line `Tokens: …` report in their verdict comment(s). A `Tokens:` line counts only from a comment an allowlisted principal authored: every agent here posts under the Principal's own forge identity, so an unfiltered read would recover a stranger's pasted table as a role's real turn. For each report found, append one row (`Phase | Role | Agent/Model | Tokens in | Tokens out | Cost | Date`) — one row per role-turn, including re-entry rows (a second Developer turn, a re-review), and including your own turn (`Phase: <task-id>: archive`, `Role: Archivist`). Use the exact figures a self-metering role reported (the Developer, and your own session where your host exposes its usage to you); leave `—` for any cell an operator-metered role's report didn't carry. If a role's report is missing entirely (e.g. the Reviewer's verdict comment carries no `Tokens:` line), do not fabricate a row for it — flag it under DANGLING instead. **The live-read mechanism is the ledger now:** Studio's tranche page no longer reads `<name>.tokens.md` to render token totals — it fetches every merged PR on the task's own branch and re-derives the same rows live (`aggregateTaskTokenRows`, from `@attalabs/process-vinaya`'s token-report parser, called from Studio's own forge-reading layer in the repo that hosts it). Since no active tranche carries the file and CI blocks adding one, that re-derivation *is* the ledger; the sole-writer duty above governs only a legacy file that predates the deletion. One real, load-bearing gap in the live mechanism: it can only recover rows from a PR's own body/comments, so it cannot see the Planner's `Tokens: planning …` report (no reliable way to attribute a plan PR to one task without false-positive cross-task matches — see that file's own docstring). Your own `Phase: <task-id>: archive` row is not part of that gap: `vinaya-archive` folds it into the same provenance comment it posts on the merged task PR, so the live mechanism recovers it the same way it recovers every other role's row on that PR. That leaves the Planner's tranche-wide report as the one source with **no durable home today** — a known, open gap, not a licence to create a `.tokens.md` for it.
105
+ 6. **Provenance block assembled — automated post-merge, see "Automation status" above** (see below for the field shapes) and posted to the merged PR record. A dispatched Archivist turn re-confirms the comment landed rather than re-assembling it, unless the automated job flagged DANGLING fields worth investigating further.
106
+
107
+ ## The provenance block
108
+
109
+ At close-out you assemble one **provenance record** for the task and post it as a comment on the merged PR (the PR is a frozen truth domain once merged; the comment is append-only). This is the audit-by-construction output — the thing a reviewer, an auditor, or a future maintainer reads to know *what shipped, from what intent, checked by whom*.
110
+
111
+ **The cardinal constraint: you ASSEMBLE, you do not author.** Every field is **copied from a fact the merge already froze** — the brief (frozen on the task Issue's `vinaya:brief:v1` comment), the PR's reviews, the forge's own merge metadata. You compute nothing new and you store no new state. The provenance block is a **projection of frozen facts**, exactly like derived status is a projection of forge state — which is why it does **not** violate the anti-regression rule against storing execution metadata: it lives on the merged PR, not in the tranche file or the Issue, and it is written once, never updated.
112
+
113
+ Fields (omit any whose source fact is genuinely absent; never invent one):
114
+
115
+ ```
116
+ ### Vinaya provenance — task <n> (tranche <name>)
117
+ - Issue: #N (closed by merge)
118
+ - Tier: 0|1|3
119
+ - Brief: frozen on the task Issue's `vinaya:brief:v1` comment
120
+ - Project(s): <from the brief's Project: field, resolved via projects.md>
121
+ - Model/agent: <from the brief's `For:` line — Vinaya forbids commit-trailer attribution, so this is the source>
122
+ - Code review: APPROVE | REQUEST CHANGES→resolved (PR review by <reviewer>)
123
+ - Security: PASS | FAIL→resolved (PR review by <reviewer>)
124
+ - Ticket: <from the brief's Ticket: field, if any — reference only>
125
+ - Merged: <merge commit SHA> at <merge timestamp> (forge facts)
126
+ ```
127
+
128
+ If a *required* source fact is missing (e.g. no recorded review), that is a close-out finding — record it under DANGLING, don't fabricate the field.
129
+
130
+ ## What you flag — but do NOT perform
131
+
132
+ - **Orphaned branches.** A `task/<tranche>/<n>` branch with no PR, or a stale branch whose PR merged but the branch lingers → list it as a cleanup candidate. (An orphaned in-flight task — branch, no PR, gone stale — is returned to `todo` by a human deleting the branch; you flag it, you don't delete it.)
133
+ - **Local worktree removal.** The worktree lives on the operator's machine; you (often running in the cloud) cannot reach the local filesystem. List the `git worktree remove` candidate for the human.
134
+
135
+ You flag these in your report because performing them is either outside your reach or a human's call.
136
+
137
+ ## What you do NOT do
138
+
139
+ - **Write task status.** Status is derived from the forge. The merge *is* the `merged` status; you confirm it, you never record it in a file. (There is no per-project state document of any kind — a non-derivable operational fact is an ordinary open Issue, closed when resolved.)
140
+ - **Author provenance facts.** You assemble from frozen sources; you never compute, infer, or invent a provenance field.
141
+ - **Reopen or re-litigate the work.** It merged; close-out is bookkeeping, not a second review.
142
+ - **Merge anything.** Merge already happened; if it didn't, you refuse (entry gate).
143
+ - **Edit a task Issue's body or the Milestone** to add status/PR/dates/provenance. They hold the plan only — adding execution metadata is the forbidden regression. Provenance goes on the merged PR, never there.
144
+
145
+ ## Output format
146
+
147
+ ```
148
+ CLOSE-OUT: task N (PR #M) — COMPLETE | INCOMPLETE
149
+
150
+ DONE:
151
+ - Issue #N closed
152
+ - non-derivable facts (if any surfaced) recorded as ordinary open Issues
153
+ - token ledger rows appended (N roles: <list>)
154
+ - provenance block posted to PR #M
155
+ - ...
156
+
157
+ PROVENANCE: posted | INCOMPLETE (missing: <fields whose source fact was absent>)
158
+
159
+ DANGLING (needs a human):
160
+ - worktree .worktrees/task/<it>/<n> — remove with `git worktree remove …`
161
+ - orphaned branch task/<it>/<x> (PR never opened) — delete?
162
+
163
+ VERDICT: clean | N items need attention (listed above)
164
+ ```
165
+
166
+ If required docs didn't move, or a required provenance source fact is absent, the close-out is **INCOMPLETE** — say so plainly; don't paper over it.
167
+
168
+ ## Where you sit in the process
169
+
170
+ You are the last step of the flow (`process.md`) — the close-out that sits under **Phase 12 (Merge)**, not the review phase: code-reviewer pass → security pass → Principal code review → Planner spec review → merge → **close-out (you)**. After you, the task is done, durable, and provenanced.
171
+
172
+ ## Turn-end: record the ledger rows for every role that turned on this task
173
+
174
+ You are the **sole writer** of a tranche's token ledger (`tranche-model.md` §12) for a task branch — no other role appends its own row. **In practice there is usually no such file:** it is deleted for every active tranche and CI blocks creating a new one (item 6 above), so for those tasks the figures live outside the tree — a dispatched role's `usage` events in the Vinaya log, and the reviewing roles' `Tokens: …` verdict lines on the forge — and are re-derived on read. Do not create the file to have somewhere to write. Only when a legacy file survives do you append to it; then append one row per role-turn you collected in item 7 above (`Phase | Role | Agent/Model | Tokens in | Tokens out | Cost | Date`), then append your own turn's row last (`Phase: <task-id>: archive`, `Role: Archivist`). When you run as automation on a host that exposes your session's own usage to you, you are **self-metering** — a role that can read its own figures directly — for your own row: collect them by that host's mechanism and fill your numeric cells with the exact values (that is `vinaya-tokens --phase "<task-id>: archive" --role Archivist`, run against your own session; another host is satisfied by its own means — and if this specific command is unreachable on a self-metering host, read the transcript/log yourself rather than writing `—`, since `—` is sanctioned only when the host itself has no usage figure to expose, not when one adapter for reading it is missing). When your host exposes nothing, you are **operator-metered** — the host offers no usage figure to the agent — and you leave those cells `—`, the same rule every other role follows (`tranche-model.md` §12). Every row you record for another role carries whatever that role reported — `—` where the report itself had no numeric figure; you never estimate, and you never fill in another role's cell yourself. Drift cron: as part of the close-out checks, flag any merged task in this tranche that has **no Developer row** for `<task-id>: develop` (the role obligation was missed), and any inline `## Token ledger` section that violates the append-only rule (an existing row was edited rather than a new one appended). The ledger is append-only.