popeye-cli 1.10.0 → 2.1.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 (326) hide show
  1. package/CHANGELOG.md +114 -0
  2. package/CONTRIBUTING.md +38 -3
  3. package/README.md +104 -18
  4. package/dist/adapters/gemini.js +3 -3
  5. package/dist/adapters/openai.js +2 -2
  6. package/dist/adapters/openai.js.map +1 -1
  7. package/dist/auth/gemini.js +1 -1
  8. package/dist/cli/commands/create.d.ts.map +1 -1
  9. package/dist/cli/commands/create.js +11 -5
  10. package/dist/cli/commands/create.js.map +1 -1
  11. package/dist/cli/commands/resume.d.ts.map +1 -1
  12. package/dist/cli/commands/resume.js +9 -1
  13. package/dist/cli/commands/resume.js.map +1 -1
  14. package/dist/cli/interactive.d.ts.map +1 -1
  15. package/dist/cli/interactive.js +29 -3
  16. package/dist/cli/interactive.js.map +1 -1
  17. package/dist/config/defaults.d.ts.map +1 -1
  18. package/dist/config/defaults.js +7 -2
  19. package/dist/config/defaults.js.map +1 -1
  20. package/dist/config/index.d.ts +1 -7
  21. package/dist/config/index.d.ts.map +1 -1
  22. package/dist/config/popeye-md.d.ts +32 -0
  23. package/dist/config/popeye-md.d.ts.map +1 -0
  24. package/dist/config/popeye-md.js +111 -0
  25. package/dist/config/popeye-md.js.map +1 -0
  26. package/dist/config/schema.d.ts +3 -21
  27. package/dist/config/schema.d.ts.map +1 -1
  28. package/dist/config/schema.js +21 -8
  29. package/dist/config/schema.js.map +1 -1
  30. package/dist/pipeline/artifact-manager.d.ts +47 -0
  31. package/dist/pipeline/artifact-manager.d.ts.map +1 -0
  32. package/dist/pipeline/artifact-manager.js +251 -0
  33. package/dist/pipeline/artifact-manager.js.map +1 -0
  34. package/dist/pipeline/artifact-validators.d.ts +29 -0
  35. package/dist/pipeline/artifact-validators.d.ts.map +1 -0
  36. package/dist/pipeline/artifact-validators.js +173 -0
  37. package/dist/pipeline/artifact-validators.js.map +1 -0
  38. package/dist/pipeline/bridges/review-bridge.d.ts +70 -0
  39. package/dist/pipeline/bridges/review-bridge.d.ts.map +1 -0
  40. package/dist/pipeline/bridges/review-bridge.js +266 -0
  41. package/dist/pipeline/bridges/review-bridge.js.map +1 -0
  42. package/dist/pipeline/change-request.d.ts +47 -0
  43. package/dist/pipeline/change-request.d.ts.map +1 -0
  44. package/dist/pipeline/change-request.js +91 -0
  45. package/dist/pipeline/change-request.js.map +1 -0
  46. package/dist/pipeline/check-runner.d.ts +47 -0
  47. package/dist/pipeline/check-runner.d.ts.map +1 -0
  48. package/dist/pipeline/check-runner.js +417 -0
  49. package/dist/pipeline/check-runner.js.map +1 -0
  50. package/dist/pipeline/command-resolver.d.ts +9 -0
  51. package/dist/pipeline/command-resolver.d.ts.map +1 -0
  52. package/dist/pipeline/command-resolver.js +140 -0
  53. package/dist/pipeline/command-resolver.js.map +1 -0
  54. package/dist/pipeline/consensus/consensus-runner.d.ts +44 -0
  55. package/dist/pipeline/consensus/consensus-runner.d.ts.map +1 -0
  56. package/dist/pipeline/consensus/consensus-runner.js +212 -0
  57. package/dist/pipeline/consensus/consensus-runner.js.map +1 -0
  58. package/dist/pipeline/constitution.d.ts +45 -0
  59. package/dist/pipeline/constitution.d.ts.map +1 -0
  60. package/dist/pipeline/constitution.js +82 -0
  61. package/dist/pipeline/constitution.js.map +1 -0
  62. package/dist/pipeline/gate-engine.d.ts +55 -0
  63. package/dist/pipeline/gate-engine.d.ts.map +1 -0
  64. package/dist/pipeline/gate-engine.js +270 -0
  65. package/dist/pipeline/gate-engine.js.map +1 -0
  66. package/dist/pipeline/index.d.ts +26 -0
  67. package/dist/pipeline/index.d.ts.map +1 -0
  68. package/dist/pipeline/index.js +35 -0
  69. package/dist/pipeline/index.js.map +1 -0
  70. package/dist/pipeline/migration.d.ts +15 -0
  71. package/dist/pipeline/migration.d.ts.map +1 -0
  72. package/dist/pipeline/migration.js +76 -0
  73. package/dist/pipeline/migration.js.map +1 -0
  74. package/dist/pipeline/orchestrator.d.ts +30 -0
  75. package/dist/pipeline/orchestrator.d.ts.map +1 -0
  76. package/dist/pipeline/orchestrator.js +242 -0
  77. package/dist/pipeline/orchestrator.js.map +1 -0
  78. package/dist/pipeline/packets/audit-report-builder.d.ts +11 -0
  79. package/dist/pipeline/packets/audit-report-builder.d.ts.map +1 -0
  80. package/dist/pipeline/packets/audit-report-builder.js +32 -0
  81. package/dist/pipeline/packets/audit-report-builder.js.map +1 -0
  82. package/dist/pipeline/packets/consensus-packet-builder.d.ts +35 -0
  83. package/dist/pipeline/packets/consensus-packet-builder.d.ts.map +1 -0
  84. package/dist/pipeline/packets/consensus-packet-builder.js +80 -0
  85. package/dist/pipeline/packets/consensus-packet-builder.js.map +1 -0
  86. package/dist/pipeline/packets/index.d.ts +12 -0
  87. package/dist/pipeline/packets/index.d.ts.map +1 -0
  88. package/dist/pipeline/packets/index.js +8 -0
  89. package/dist/pipeline/packets/index.js.map +1 -0
  90. package/dist/pipeline/packets/plan-packet-builder.d.ts +21 -0
  91. package/dist/pipeline/packets/plan-packet-builder.d.ts.map +1 -0
  92. package/dist/pipeline/packets/plan-packet-builder.js +27 -0
  93. package/dist/pipeline/packets/plan-packet-builder.js.map +1 -0
  94. package/dist/pipeline/packets/rca-packet-builder.d.ts +19 -0
  95. package/dist/pipeline/packets/rca-packet-builder.d.ts.map +1 -0
  96. package/dist/pipeline/packets/rca-packet-builder.js +22 -0
  97. package/dist/pipeline/packets/rca-packet-builder.js.map +1 -0
  98. package/dist/pipeline/phases/architecture.d.ts +7 -0
  99. package/dist/pipeline/phases/architecture.d.ts.map +1 -0
  100. package/dist/pipeline/phases/architecture.js +60 -0
  101. package/dist/pipeline/phases/architecture.js.map +1 -0
  102. package/dist/pipeline/phases/audit.d.ts +8 -0
  103. package/dist/pipeline/phases/audit.d.ts.map +1 -0
  104. package/dist/pipeline/phases/audit.js +144 -0
  105. package/dist/pipeline/phases/audit.js.map +1 -0
  106. package/dist/pipeline/phases/consensus-architecture.d.ts +7 -0
  107. package/dist/pipeline/phases/consensus-architecture.d.ts.map +1 -0
  108. package/dist/pipeline/phases/consensus-architecture.js +84 -0
  109. package/dist/pipeline/phases/consensus-architecture.js.map +1 -0
  110. package/dist/pipeline/phases/consensus-master-plan.d.ts +7 -0
  111. package/dist/pipeline/phases/consensus-master-plan.d.ts.map +1 -0
  112. package/dist/pipeline/phases/consensus-master-plan.js +81 -0
  113. package/dist/pipeline/phases/consensus-master-plan.js.map +1 -0
  114. package/dist/pipeline/phases/consensus-role-plans.d.ts +7 -0
  115. package/dist/pipeline/phases/consensus-role-plans.d.ts.map +1 -0
  116. package/dist/pipeline/phases/consensus-role-plans.js +85 -0
  117. package/dist/pipeline/phases/consensus-role-plans.js.map +1 -0
  118. package/dist/pipeline/phases/done.d.ts +7 -0
  119. package/dist/pipeline/phases/done.d.ts.map +1 -0
  120. package/dist/pipeline/phases/done.js +45 -0
  121. package/dist/pipeline/phases/done.js.map +1 -0
  122. package/dist/pipeline/phases/implementation.d.ts +8 -0
  123. package/dist/pipeline/phases/implementation.d.ts.map +1 -0
  124. package/dist/pipeline/phases/implementation.js +45 -0
  125. package/dist/pipeline/phases/implementation.js.map +1 -0
  126. package/dist/pipeline/phases/index.d.ts +20 -0
  127. package/dist/pipeline/phases/index.d.ts.map +1 -0
  128. package/dist/pipeline/phases/index.js +19 -0
  129. package/dist/pipeline/phases/index.js.map +1 -0
  130. package/dist/pipeline/phases/intake.d.ts +8 -0
  131. package/dist/pipeline/phases/intake.d.ts.map +1 -0
  132. package/dist/pipeline/phases/intake.js +49 -0
  133. package/dist/pipeline/phases/intake.js.map +1 -0
  134. package/dist/pipeline/phases/phase-context.d.ts +30 -0
  135. package/dist/pipeline/phases/phase-context.d.ts.map +1 -0
  136. package/dist/pipeline/phases/phase-context.js +33 -0
  137. package/dist/pipeline/phases/phase-context.js.map +1 -0
  138. package/dist/pipeline/phases/production-gate.d.ts +8 -0
  139. package/dist/pipeline/phases/production-gate.d.ts.map +1 -0
  140. package/dist/pipeline/phases/production-gate.js +84 -0
  141. package/dist/pipeline/phases/production-gate.js.map +1 -0
  142. package/dist/pipeline/phases/qa-validation.d.ts +7 -0
  143. package/dist/pipeline/phases/qa-validation.d.ts.map +1 -0
  144. package/dist/pipeline/phases/qa-validation.js +50 -0
  145. package/dist/pipeline/phases/qa-validation.js.map +1 -0
  146. package/dist/pipeline/phases/recovery-loop.d.ts +7 -0
  147. package/dist/pipeline/phases/recovery-loop.d.ts.map +1 -0
  148. package/dist/pipeline/phases/recovery-loop.js +93 -0
  149. package/dist/pipeline/phases/recovery-loop.js.map +1 -0
  150. package/dist/pipeline/phases/review.d.ts +8 -0
  151. package/dist/pipeline/phases/review.d.ts.map +1 -0
  152. package/dist/pipeline/phases/review.js +127 -0
  153. package/dist/pipeline/phases/review.js.map +1 -0
  154. package/dist/pipeline/phases/role-planning.d.ts +7 -0
  155. package/dist/pipeline/phases/role-planning.d.ts.map +1 -0
  156. package/dist/pipeline/phases/role-planning.js +75 -0
  157. package/dist/pipeline/phases/role-planning.js.map +1 -0
  158. package/dist/pipeline/phases/stuck.d.ts +7 -0
  159. package/dist/pipeline/phases/stuck.d.ts.map +1 -0
  160. package/dist/pipeline/phases/stuck.js +51 -0
  161. package/dist/pipeline/phases/stuck.js.map +1 -0
  162. package/dist/pipeline/repo-snapshot.d.ts +24 -0
  163. package/dist/pipeline/repo-snapshot.d.ts.map +1 -0
  164. package/dist/pipeline/repo-snapshot.js +343 -0
  165. package/dist/pipeline/repo-snapshot.js.map +1 -0
  166. package/dist/pipeline/role-execution-adapter.d.ts +59 -0
  167. package/dist/pipeline/role-execution-adapter.d.ts.map +1 -0
  168. package/dist/pipeline/role-execution-adapter.js +159 -0
  169. package/dist/pipeline/role-execution-adapter.js.map +1 -0
  170. package/dist/pipeline/skill-loader.d.ts +34 -0
  171. package/dist/pipeline/skill-loader.d.ts.map +1 -0
  172. package/dist/pipeline/skill-loader.js +156 -0
  173. package/dist/pipeline/skill-loader.js.map +1 -0
  174. package/dist/pipeline/skills/defaults.d.ts +16 -0
  175. package/dist/pipeline/skills/defaults.d.ts.map +1 -0
  176. package/dist/pipeline/skills/defaults.js +189 -0
  177. package/dist/pipeline/skills/defaults.js.map +1 -0
  178. package/dist/pipeline/type-defs/artifacts.d.ts +207 -0
  179. package/dist/pipeline/type-defs/artifacts.d.ts.map +1 -0
  180. package/dist/pipeline/type-defs/artifacts.js +67 -0
  181. package/dist/pipeline/type-defs/artifacts.js.map +1 -0
  182. package/dist/pipeline/type-defs/audit.d.ts +259 -0
  183. package/dist/pipeline/type-defs/audit.d.ts.map +1 -0
  184. package/dist/pipeline/type-defs/audit.js +54 -0
  185. package/dist/pipeline/type-defs/audit.js.map +1 -0
  186. package/dist/pipeline/type-defs/checks.d.ts +82 -0
  187. package/dist/pipeline/type-defs/checks.d.ts.map +1 -0
  188. package/dist/pipeline/type-defs/checks.js +38 -0
  189. package/dist/pipeline/type-defs/checks.js.map +1 -0
  190. package/dist/pipeline/type-defs/enums.d.ts +43 -0
  191. package/dist/pipeline/type-defs/enums.d.ts.map +1 -0
  192. package/dist/pipeline/type-defs/enums.js +55 -0
  193. package/dist/pipeline/type-defs/enums.js.map +1 -0
  194. package/dist/pipeline/type-defs/index.d.ts +12 -0
  195. package/dist/pipeline/type-defs/index.d.ts.map +1 -0
  196. package/dist/pipeline/type-defs/index.js +12 -0
  197. package/dist/pipeline/type-defs/index.js.map +1 -0
  198. package/dist/pipeline/type-defs/packets.d.ts +821 -0
  199. package/dist/pipeline/type-defs/packets.d.ts.map +1 -0
  200. package/dist/pipeline/type-defs/packets.js +109 -0
  201. package/dist/pipeline/type-defs/packets.js.map +1 -0
  202. package/dist/pipeline/type-defs/snapshot.d.ts +52 -0
  203. package/dist/pipeline/type-defs/snapshot.d.ts.map +1 -0
  204. package/dist/pipeline/type-defs/snapshot.js +35 -0
  205. package/dist/pipeline/type-defs/snapshot.js.map +1 -0
  206. package/dist/pipeline/type-defs/state.d.ts +455 -0
  207. package/dist/pipeline/type-defs/state.d.ts.map +1 -0
  208. package/dist/pipeline/type-defs/state.js +90 -0
  209. package/dist/pipeline/type-defs/state.js.map +1 -0
  210. package/dist/pipeline/types.d.ts +16 -0
  211. package/dist/pipeline/types.d.ts.map +1 -0
  212. package/dist/pipeline/types.js +16 -0
  213. package/dist/pipeline/types.js.map +1 -0
  214. package/dist/types/audit.d.ts +6 -6
  215. package/dist/types/consensus.d.ts +5 -1
  216. package/dist/types/consensus.d.ts.map +1 -1
  217. package/dist/types/consensus.js +15 -4
  218. package/dist/types/consensus.js.map +1 -1
  219. package/dist/types/index.d.ts +1 -1
  220. package/dist/types/index.d.ts.map +1 -1
  221. package/dist/types/index.js +1 -1
  222. package/dist/types/index.js.map +1 -1
  223. package/dist/types/project.d.ts +1 -1
  224. package/dist/types/project.d.ts.map +1 -1
  225. package/dist/types/project.js +39 -10
  226. package/dist/types/project.js.map +1 -1
  227. package/dist/types/workflow.d.ts +1 -7
  228. package/dist/types/workflow.d.ts.map +1 -1
  229. package/dist/types/workflow.js +1 -1
  230. package/dist/types/workflow.js.map +1 -1
  231. package/dist/upgrade/handlers.js +5 -5
  232. package/dist/upgrade/handlers.js.map +1 -1
  233. package/dist/workflow/index.d.ts.map +1 -1
  234. package/dist/workflow/index.js +52 -0
  235. package/dist/workflow/index.js.map +1 -1
  236. package/dist/workflow/website-strategy.js +1 -1
  237. package/dist/workflow/website-strategy.js.map +1 -1
  238. package/package.json +1 -1
  239. package/skills/PHASE_GATE_ENGINE_SPEC.md +113 -20
  240. package/skills/POPEYE_FULL_AUTONOMY_PIPELINE.md +66 -13
  241. package/src/adapters/gemini.ts +3 -3
  242. package/src/adapters/openai.ts +2 -2
  243. package/src/auth/gemini.ts +1 -1
  244. package/src/cli/commands/create.ts +12 -6
  245. package/src/cli/commands/resume.ts +9 -1
  246. package/src/cli/interactive.ts +32 -3
  247. package/src/config/defaults.ts +7 -2
  248. package/src/config/popeye-md.ts +139 -0
  249. package/src/config/schema.ts +21 -8
  250. package/src/pipeline/artifact-manager.ts +339 -0
  251. package/src/pipeline/artifact-validators.ts +224 -0
  252. package/src/pipeline/bridges/review-bridge.ts +371 -0
  253. package/src/pipeline/change-request.ts +119 -0
  254. package/src/pipeline/check-runner.ts +504 -0
  255. package/src/pipeline/command-resolver.ts +168 -0
  256. package/src/pipeline/consensus/consensus-runner.ts +317 -0
  257. package/src/pipeline/constitution.ts +109 -0
  258. package/src/pipeline/gate-engine.ts +347 -0
  259. package/src/pipeline/index.ts +82 -0
  260. package/src/pipeline/migration.ts +91 -0
  261. package/src/pipeline/orchestrator.ts +322 -0
  262. package/src/pipeline/packets/audit-report-builder.ts +47 -0
  263. package/src/pipeline/packets/consensus-packet-builder.ts +112 -0
  264. package/src/pipeline/packets/index.ts +15 -0
  265. package/src/pipeline/packets/plan-packet-builder.ts +52 -0
  266. package/src/pipeline/packets/rca-packet-builder.ts +38 -0
  267. package/src/pipeline/phases/architecture.ts +73 -0
  268. package/src/pipeline/phases/audit.ts +193 -0
  269. package/src/pipeline/phases/consensus-architecture.ts +104 -0
  270. package/src/pipeline/phases/consensus-master-plan.ts +100 -0
  271. package/src/pipeline/phases/consensus-role-plans.ts +105 -0
  272. package/src/pipeline/phases/done.ts +68 -0
  273. package/src/pipeline/phases/implementation.ts +52 -0
  274. package/src/pipeline/phases/index.ts +21 -0
  275. package/src/pipeline/phases/intake.ts +68 -0
  276. package/src/pipeline/phases/phase-context.ts +86 -0
  277. package/src/pipeline/phases/production-gate.ts +113 -0
  278. package/src/pipeline/phases/qa-validation.ts +63 -0
  279. package/src/pipeline/phases/recovery-loop.ts +120 -0
  280. package/src/pipeline/phases/review.ts +149 -0
  281. package/src/pipeline/phases/role-planning.ts +92 -0
  282. package/src/pipeline/phases/stuck.ts +62 -0
  283. package/src/pipeline/repo-snapshot.ts +395 -0
  284. package/src/pipeline/role-execution-adapter.ts +238 -0
  285. package/src/pipeline/skill-loader.ts +192 -0
  286. package/src/pipeline/skills/defaults.ts +215 -0
  287. package/src/pipeline/type-defs/artifacts.ts +82 -0
  288. package/src/pipeline/type-defs/audit.ts +67 -0
  289. package/src/pipeline/type-defs/checks.ts +47 -0
  290. package/src/pipeline/type-defs/enums.ts +62 -0
  291. package/src/pipeline/type-defs/index.ts +12 -0
  292. package/src/pipeline/type-defs/packets.ts +131 -0
  293. package/src/pipeline/type-defs/snapshot.ts +55 -0
  294. package/src/pipeline/type-defs/state.ts +167 -0
  295. package/src/pipeline/types.ts +16 -0
  296. package/src/types/consensus.ts +16 -4
  297. package/src/types/index.ts +1 -0
  298. package/src/types/project.ts +39 -10
  299. package/src/types/workflow.ts +1 -1
  300. package/src/upgrade/handlers.ts +5 -5
  301. package/src/workflow/index.ts +52 -0
  302. package/src/workflow/website-strategy.ts +1 -1
  303. package/tests/cli/model-command.test.ts +19 -9
  304. package/tests/config/config.test.ts +3 -3
  305. package/tests/config/popeye-md.test.ts +168 -0
  306. package/tests/pipeline/artifact-manager.test.ts +183 -0
  307. package/tests/pipeline/artifact-validators.test.ts +207 -0
  308. package/tests/pipeline/bridges/review-bridge.test.ts +243 -0
  309. package/tests/pipeline/change-request.test.ts +180 -0
  310. package/tests/pipeline/check-runner.test.ts +157 -0
  311. package/tests/pipeline/command-resolver.test.ts +159 -0
  312. package/tests/pipeline/consensus-runner.test.ts +206 -0
  313. package/tests/pipeline/consensus-scoring.test.ts +163 -0
  314. package/tests/pipeline/constitution.test.ts +122 -0
  315. package/tests/pipeline/gate-engine.test.ts +195 -0
  316. package/tests/pipeline/migration.test.ts +133 -0
  317. package/tests/pipeline/orchestrator.test.ts +614 -0
  318. package/tests/pipeline/packets/builders.test.ts +347 -0
  319. package/tests/pipeline/repo-snapshot.test.ts +189 -0
  320. package/tests/pipeline/role-execution-adapter.test.ts +299 -0
  321. package/tests/pipeline/session-guidance.test.ts +205 -0
  322. package/tests/pipeline/skill-loader.test.ts +186 -0
  323. package/tests/pipeline/start-env-checks.test.ts +123 -0
  324. package/tests/pipeline/types.test.ts +156 -0
  325. package/tests/types/consensus.test.ts +1 -1
  326. package/tests/workflow/pipeline-bootstrap.test.ts +162 -0
@@ -0,0 +1,212 @@
1
+ /**
2
+ * Consensus Runner — adapter layer between structured packets
3
+ * and existing consensus machinery.
4
+ *
5
+ * Two modes (P1-D):
6
+ * 1. Independent Review (DEFAULT): N reviewers review simultaneously,
7
+ * no reviewer sees other reviewers' output.
8
+ * 2. Iterative Consensus (optional): for recovery plan iteration.
9
+ */
10
+ import { createHash } from 'node:crypto';
11
+ import { buildConsensusPacket } from '../packets/consensus-packet-builder.js';
12
+ // Re-use existing consensus infrastructure
13
+ import { iterateUntilConsensus } from '../../workflow/consensus.js';
14
+ const DEFAULT_PROVIDERS = [
15
+ { provider: 'openai', model: 'gpt-4.1', temperature: 0.3 },
16
+ { provider: 'gemini', model: 'gemini-2.5-flash', temperature: 0.3 },
17
+ ];
18
+ // ─── Consensus Runner ────────────────────────────────────
19
+ export class ConsensusRunner {
20
+ config;
21
+ constructor(config) {
22
+ this.config = config;
23
+ }
24
+ /** Run structured consensus on a plan packet */
25
+ async runStructuredConsensus(planPacket, gateDefinition) {
26
+ const rules = {
27
+ threshold: gateDefinition.consensusThreshold ?? this.config.threshold,
28
+ quorum: this.config.quorum,
29
+ min_reviewers: gateDefinition.minReviewers ?? this.config.minReviewers,
30
+ };
31
+ let votes;
32
+ if (this.config.mode === 'independent') {
33
+ votes = await this.runIndependentReview(planPacket);
34
+ }
35
+ else {
36
+ votes = await this.runIterativeReview(planPacket);
37
+ }
38
+ // Build consensus packet from votes
39
+ const packet = buildConsensusPacket({
40
+ planPacketRef: {
41
+ artifact_id: planPacket.metadata.packet_id,
42
+ path: '',
43
+ sha256: '',
44
+ version: planPacket.metadata.version,
45
+ type: 'consensus',
46
+ },
47
+ votes,
48
+ rules,
49
+ });
50
+ return packet;
51
+ }
52
+ /** Independent review: spawn N reviewers, each reviews independently */
53
+ async runIndependentReview(planPacket) {
54
+ const providers = this.config.reviewerProviders ?? DEFAULT_PROVIDERS;
55
+ const numReviewers = Math.max(this.config.minReviewers, providers.length);
56
+ // Build the review prompt from the plan packet
57
+ const prompt = buildReviewPrompt(planPacket);
58
+ const promptHash = createHash('sha256').update(prompt).digest('hex');
59
+ // Spawn reviewers in parallel
60
+ const reviewPromises = [];
61
+ for (let i = 0; i < numReviewers; i++) {
62
+ const provider = providers[i % providers.length];
63
+ reviewPromises.push(this.spawnSingleReviewer(prompt, promptHash, provider, `reviewer-${provider.provider}-${i}`));
64
+ }
65
+ return Promise.all(reviewPromises);
66
+ }
67
+ /** Iterative review: wraps existing iterateUntilConsensus */
68
+ async runIterativeReview(planPacket) {
69
+ const prompt = buildReviewPrompt(planPacket);
70
+ try {
71
+ const result = await iterateUntilConsensus(prompt, `Phase: ${planPacket.metadata.phase}`, {
72
+ projectDir: this.config.projectDir,
73
+ config: this.config.consensusConfig,
74
+ });
75
+ // Convert legacy result to ReviewerVote format
76
+ const vote = {
77
+ reviewer_id: 'iterative-reviewer',
78
+ provider: 'openai',
79
+ model: this.config.consensusConfig?.openaiModel ?? 'gpt-4.1',
80
+ temperature: this.config.consensusConfig?.temperature ?? 0.3,
81
+ prompt_hash: createHash('sha256').update(prompt).digest('hex'),
82
+ vote: result.approved ? 'APPROVE' : 'REJECT',
83
+ confidence: result.finalScore ?? 0.5,
84
+ blocking_issues: result.finalConcerns ?? [],
85
+ suggestions: result.finalRecommendations ?? [],
86
+ evidence_refs: [],
87
+ };
88
+ return [vote];
89
+ }
90
+ catch {
91
+ return [{
92
+ reviewer_id: 'iterative-reviewer-error',
93
+ provider: 'openai',
94
+ model: 'unknown',
95
+ temperature: 0,
96
+ prompt_hash: '',
97
+ vote: 'REJECT',
98
+ confidence: 0,
99
+ blocking_issues: ['Iterative consensus failed'],
100
+ suggestions: [],
101
+ evidence_refs: [],
102
+ }];
103
+ }
104
+ }
105
+ /** Spawn a single independent reviewer */
106
+ async spawnSingleReviewer(prompt, promptHash, provider, reviewerId) {
107
+ try {
108
+ const result = await this.callProviderForReview(prompt, provider);
109
+ return {
110
+ reviewer_id: reviewerId,
111
+ provider: provider.provider,
112
+ model: provider.model,
113
+ temperature: provider.temperature,
114
+ prompt_hash: promptHash,
115
+ vote: result.approved ? 'APPROVE' : 'REJECT',
116
+ confidence: result.confidence,
117
+ blocking_issues: result.blockingIssues,
118
+ suggestions: result.suggestions,
119
+ evidence_refs: [],
120
+ };
121
+ }
122
+ catch {
123
+ return {
124
+ reviewer_id: reviewerId,
125
+ provider: provider.provider,
126
+ model: provider.model,
127
+ temperature: provider.temperature,
128
+ prompt_hash: promptHash,
129
+ vote: 'REJECT',
130
+ confidence: 0,
131
+ blocking_issues: [`Review failed for ${provider.provider}`],
132
+ suggestions: [],
133
+ evidence_refs: [],
134
+ };
135
+ }
136
+ }
137
+ /** Call the appropriate provider adapter for a review */
138
+ async callProviderForReview(prompt, provider) {
139
+ switch (provider.provider) {
140
+ case 'openai': {
141
+ const { requestConsensus } = await import('../../adapters/openai.js');
142
+ const result = await requestConsensus(prompt, '', {
143
+ openaiModel: provider.model,
144
+ temperature: provider.temperature,
145
+ });
146
+ return parseConsensusResult(result);
147
+ }
148
+ case 'gemini': {
149
+ const { requestConsensus } = await import('../../adapters/gemini.js');
150
+ const result = await requestConsensus(prompt, '', {
151
+ model: provider.model,
152
+ temperature: provider.temperature,
153
+ });
154
+ return parseConsensusResult(result);
155
+ }
156
+ case 'grok': {
157
+ const { requestConsensus } = await import('../../adapters/grok.js');
158
+ const result = await requestConsensus(prompt, '', {
159
+ model: provider.model,
160
+ temperature: provider.temperature,
161
+ });
162
+ return parseConsensusResult(result);
163
+ }
164
+ default:
165
+ throw new Error(`Unknown provider: ${provider.provider}`);
166
+ }
167
+ }
168
+ }
169
+ function parseConsensusResult(result) {
170
+ return {
171
+ approved: result.approved,
172
+ confidence: result.score / 100, // score is 0-100, confidence is 0-1
173
+ blockingIssues: result.concerns ?? [],
174
+ suggestions: result.recommendations ?? [],
175
+ };
176
+ }
177
+ // ─── Prompt Builder ──────────────────────────────────────
178
+ export function buildReviewPrompt(planPacket) {
179
+ const lines = [
180
+ `# Independent Plan Review`,
181
+ ``,
182
+ `## Phase: ${planPacket.metadata.phase}`,
183
+ `## Submitted by: ${planPacket.metadata.submitted_by}`,
184
+ `## Version: ${planPacket.metadata.version}`,
185
+ ``,
186
+ `## Acceptance Criteria`,
187
+ ...planPacket.acceptance_criteria.map((c) => `- ${c}`),
188
+ ``,
189
+ `## Constraints`,
190
+ ...planPacket.constraints.map((c) => `- [${c.type}] ${c.description}`),
191
+ ``,
192
+ ];
193
+ if (planPacket.open_questions?.length) {
194
+ lines.push(`## Open Questions`);
195
+ lines.push(...planPacket.open_questions.map((q) => `- ${q}`));
196
+ lines.push('');
197
+ }
198
+ lines.push(`## Review Instructions`, ``, `You are an independent reviewer. Evaluate this plan for:`, `1. Completeness — are all required artifacts defined?`, `2. Consistency — do acceptance criteria match constraints?`, `3. Feasibility — can this be implemented as described?`, `4. Constitution compliance — does it follow governance rules?`, ``, `Respond with:`, `- APPROVE, REJECT, or CONDITIONAL`, `- Confidence score (0-1)`, `- Blocking issues (if any)`, `- Suggestions for improvement`);
199
+ return lines.join('\n');
200
+ }
201
+ // ─── Factory ─────────────────────────────────────────────
202
+ export function createConsensusRunner(projectDir, consensusConfig) {
203
+ return new ConsensusRunner({
204
+ mode: 'independent',
205
+ minReviewers: 2,
206
+ threshold: 0.95,
207
+ quorum: 2,
208
+ projectDir,
209
+ consensusConfig,
210
+ });
211
+ }
212
+ //# sourceMappingURL=consensus-runner.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"consensus-runner.js","sourceRoot":"","sources":["../../../src/pipeline/consensus/consensus-runner.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AAQzC,OAAO,EAAE,oBAAoB,EAAE,MAAM,wCAAwC,CAAC;AAG9E,2CAA2C;AAC3C,OAAO,EAAE,qBAAqB,EAAE,MAAM,6BAA6B,CAAC;AAsBpE,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eAAe;KAChB,CAAC,CAAC;AACL,CAAC"}
@@ -0,0 +1,45 @@
1
+ /**
2
+ * Constitution management — artifact creation, hashing, and verification.
3
+ * The constitution (skills/POPEYE_CONSTITUTION.md) is the immutable governance
4
+ * document for the pipeline. This module ensures it is tracked as an artifact
5
+ * and its integrity is verified at every gate.
6
+ */
7
+ import type { ArtifactEntry, PipelineState } from './types.js';
8
+ import type { ArtifactManager } from './artifact-manager.js';
9
+ /**
10
+ * Compute SHA-256 hash of constitution file content.
11
+ *
12
+ * Args:
13
+ * projectDir: Root project directory containing skills/ folder.
14
+ *
15
+ * Returns:
16
+ * Hex-encoded SHA-256 hash, or empty string if file not found.
17
+ */
18
+ export declare function computeConstitutionHash(projectDir: string): string;
19
+ /**
20
+ * Create a constitution artifact from the skills/POPEYE_CONSTITUTION.md file.
21
+ *
22
+ * Args:
23
+ * projectDir: Root project directory.
24
+ * artifactManager: The artifact manager instance.
25
+ *
26
+ * Returns:
27
+ * The created ArtifactEntry, or null if constitution file not found.
28
+ */
29
+ export declare function createConstitutionArtifact(projectDir: string, artifactManager: ArtifactManager): ArtifactEntry | null;
30
+ /**
31
+ * Verify the constitution file has not been modified since pipeline start.
32
+ * Compares current file hash against the hash stored in pipeline state.
33
+ *
34
+ * Args:
35
+ * pipeline: Current pipeline state (contains constitutionHash).
36
+ * projectDir: Root project directory.
37
+ *
38
+ * Returns:
39
+ * Object with valid=true if hash matches, or valid=false with reason.
40
+ */
41
+ export declare function verifyConstitution(pipeline: PipelineState, projectDir: string): {
42
+ valid: boolean;
43
+ reason?: string;
44
+ };
45
+ //# sourceMappingURL=constitution.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"constitution.d.ts","sourceRoot":"","sources":["../../src/pipeline/constitution.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAMH,OAAO,KAAK,EAAE,aAAa,EAAE,aAAa,EAAE,MAAM,YAAY,CAAC;AAC/D,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,uBAAuB,CAAC;AAS7D;;;;;;;;GAQG;AACH,wBAAgB,uBAAuB,CAAC,UAAU,EAAE,MAAM,GAAG,MAAM,CAQlE;AAID;;;;;;;;;GASG;AACH,wBAAgB,0BAA0B,CACxC,UAAU,EAAE,MAAM,EAClB,eAAe,EAAE,eAAe,GAC/B,aAAa,GAAG,IAAI,CAYtB;AAID;;;;;;;;;;GAUG;AACH,wBAAgB,kBAAkB,CAChC,QAAQ,EAAE,aAAa,EACvB,UAAU,EAAE,MAAM,GACjB;IAAE,KAAK,EAAE,OAAO,CAAC;IAAC,MAAM,CAAC,EAAE,MAAM,CAAA;CAAE,CAuBrC"}
@@ -0,0 +1,82 @@
1
+ /**
2
+ * Constitution management — artifact creation, hashing, and verification.
3
+ * The constitution (skills/POPEYE_CONSTITUTION.md) is the immutable governance
4
+ * document for the pipeline. This module ensures it is tracked as an artifact
5
+ * and its integrity is verified at every gate.
6
+ */
7
+ import { createHash } from 'node:crypto';
8
+ import { existsSync, readFileSync } from 'node:fs';
9
+ import { join } from 'node:path';
10
+ // ─── Constants ───────────────────────────────────────────
11
+ const CONSTITUTION_FILENAME = 'POPEYE_CONSTITUTION.md';
12
+ const SKILLS_DIR = 'skills';
13
+ // ─── Hash Computation ────────────────────────────────────
14
+ /**
15
+ * Compute SHA-256 hash of constitution file content.
16
+ *
17
+ * Args:
18
+ * projectDir: Root project directory containing skills/ folder.
19
+ *
20
+ * Returns:
21
+ * Hex-encoded SHA-256 hash, or empty string if file not found.
22
+ */
23
+ export function computeConstitutionHash(projectDir) {
24
+ const constitutionPath = join(projectDir, SKILLS_DIR, CONSTITUTION_FILENAME);
25
+ if (!existsSync(constitutionPath)) {
26
+ return '';
27
+ }
28
+ const content = readFileSync(constitutionPath, 'utf-8');
29
+ return createHash('sha256').update(content, 'utf-8').digest('hex');
30
+ }
31
+ // ─── Artifact Creation ───────────────────────────────────
32
+ /**
33
+ * Create a constitution artifact from the skills/POPEYE_CONSTITUTION.md file.
34
+ *
35
+ * Args:
36
+ * projectDir: Root project directory.
37
+ * artifactManager: The artifact manager instance.
38
+ *
39
+ * Returns:
40
+ * The created ArtifactEntry, or null if constitution file not found.
41
+ */
42
+ export function createConstitutionArtifact(projectDir, artifactManager) {
43
+ const constitutionPath = join(projectDir, SKILLS_DIR, CONSTITUTION_FILENAME);
44
+ if (!existsSync(constitutionPath)) {
45
+ return null;
46
+ }
47
+ const content = readFileSync(constitutionPath, 'utf-8');
48
+ return artifactManager.createAndStoreText('constitution', content, 'INTAKE');
49
+ }
50
+ // ─── Verification ────────────────────────────────────────
51
+ /**
52
+ * Verify the constitution file has not been modified since pipeline start.
53
+ * Compares current file hash against the hash stored in pipeline state.
54
+ *
55
+ * Args:
56
+ * pipeline: Current pipeline state (contains constitutionHash).
57
+ * projectDir: Root project directory.
58
+ *
59
+ * Returns:
60
+ * Object with valid=true if hash matches, or valid=false with reason.
61
+ */
62
+ export function verifyConstitution(pipeline, projectDir) {
63
+ // If no hash stored yet (pre-INTAKE), skip verification
64
+ if (!pipeline.constitutionHash) {
65
+ return { valid: true };
66
+ }
67
+ const currentHash = computeConstitutionHash(projectDir);
68
+ if (!currentHash) {
69
+ return {
70
+ valid: false,
71
+ reason: 'Constitution file not found — may have been deleted',
72
+ };
73
+ }
74
+ if (currentHash !== pipeline.constitutionHash) {
75
+ return {
76
+ valid: false,
77
+ reason: 'Constitution has been modified since pipeline start',
78
+ };
79
+ }
80
+ return { valid: true };
81
+ }
82
+ //# sourceMappingURL=constitution.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"constitution.js","sourceRoot":"","sources":["../../src/pipeline/constitution.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AACzC,OAAO,EAAE,UAAU,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AACnD,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AAKjC,4DAA4D;AAE5D,MAAM,qBAAqB,GAAG,w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,OAAO;YACL,KAAK,EAAE,KAAK;YACZ,MAAM,EAAE,qDAAqD;SAC9D,CAAC;IACJ,CAAC;IAED,IAAI,WAAW,KAAK,QAAQ,CAAC,gBAAgB,EAAE,CAAC;QAC9C,OAAO;YACL,KAAK,EAAE,KAAK;YACZ,MAAM,EAAE,qDAAqD;SAC9D,CAAC;IACJ,CAAC;IAED,OAAO,EAAE,KAAK,EAAE,IAAI,EAAE,CAAC;AACzB,CAAC"}
@@ -0,0 +1,55 @@
1
+ /**
2
+ * Gate Engine — pure deterministic state machine for the pipeline.
3
+ * No side effects. Reads artifacts and check results, never executes anything.
4
+ * All 14 phases with specific required artifacts and checks per phase.
5
+ */
6
+ import type { PipelinePhase, PipelineState, ArtifactType, GateCheckType } from './types.js';
7
+ export interface GateDefinition {
8
+ phase: PipelinePhase;
9
+ requiredArtifacts: ArtifactType[];
10
+ requiredChecks: GateCheckType[];
11
+ consensusThreshold?: number;
12
+ minReviewers?: number;
13
+ allowedTransitions: PipelinePhase[];
14
+ failTransition: PipelinePhase;
15
+ }
16
+ export interface GateResult {
17
+ phase: PipelinePhase;
18
+ pass: boolean;
19
+ score?: number;
20
+ blockers: string[];
21
+ missingArtifacts: ArtifactType[];
22
+ failedChecks: GateCheckType[];
23
+ consensusScore?: number;
24
+ timestamp: string;
25
+ }
26
+ export declare class GateEngine {
27
+ /** Get gate definition for a specific phase */
28
+ getGateDefinition(phase: PipelinePhase): GateDefinition;
29
+ /**
30
+ * Evaluate whether a phase's gate passes.
31
+ *
32
+ * Args:
33
+ * phase: The phase to evaluate.
34
+ * pipeline: Current pipeline state.
35
+ * options: Optional checks like constitution verification.
36
+ */
37
+ evaluateGate(phase: PipelinePhase, pipeline: PipelineState, options?: {
38
+ constitutionValid?: boolean;
39
+ constitutionReason?: string;
40
+ }): GateResult;
41
+ /** Get the next phase after a successful gate */
42
+ getNextPhase(current: PipelinePhase, _gateResult: GateResult): PipelinePhase;
43
+ /** Check if a transition between two phases is allowed */
44
+ canTransition(from: PipelinePhase, to: PipelinePhase, pipeline: PipelineState): {
45
+ allowed: boolean;
46
+ blockers: string[];
47
+ };
48
+ /** Get the ordered phase sequence */
49
+ getPhaseSequence(): PipelinePhase[];
50
+ /** Get phase index in the sequence (for progress tracking) */
51
+ getPhaseIndex(phase: PipelinePhase): number;
52
+ }
53
+ /** Factory function */
54
+ export declare function createGateEngine(): GateEngine;
55
+ //# sourceMappingURL=gate-engine.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"gate-engine.d.ts","sourceRoot":"","sources":["../../src/pipeline/gate-engine.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,KAAK,EACV,aAAa,EACb,aAAa,EACb,YAAY,EAEZ,aAAa,EACd,MAAM,YAAY,CAAC;AAIpB,MAAM,WAAW,cAAc;IAC7B,KAAK,EAAE,aAAa,CAAC;IACrB,iBAAiB,EAAE,YAAY,EAAE,CAAC;IAClC,cAAc,EAAE,aAAa,EAAE,CAAC;IAChC,kBAAkB,CAAC,EAAE,MAAM,CAAC;IAC5B,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,kBAAkB,EAAE,aAAa,EAAE,CAAC;IACpC,cAAc,EAAE,aAAa,CAAC;CAC/B;AAED,MAAM,WAAW,UAAU;IACzB,KAAK,EAAE,aAAa,CAAC;IACrB,IAAI,EAAE,OAAO,CAAC;IACd,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,QAAQ,EAAE,MAAM,EAAE,CAAC;IACnB,gBAAgB,EAAE,YAAY,EAAE,CAAC;IACjC,YAAY,EAAE,aAAa,EAAE,CAAC;IAC9B,cAAc,CAAC,EAAE,MAAM,CAAC;IACxB,SAAS,EAAE,MAAM,CAAC;CACnB;AAsID,qBAAa,UAAU;IACrB,+CAA+C;IAC/C,iBAAiB,CAAC,KAAK,EAAE,aAAa,GAAG,cAAc;IAIvD;;;;;;;OAOG;IACH,YAAY,CACV,KAAK,EAAE,aAAa,EACpB,QAAQ,EAAE,aAAa,EACvB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