issue-flow 0.12.0 → 0.14.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 (197) hide show
  1. package/README.md +79 -274
  2. package/dist/agent-OX3KPHE4.js +30 -0
  3. package/dist/{analyze-OEET7KGE.js → analyze-WIND2SEB.js} +31 -16
  4. package/dist/analyze-WIND2SEB.js.map +1 -0
  5. package/dist/{apply-ZIA3C52S.js → apply-JNOI2LR4.js} +18 -7
  6. package/dist/{apply-ZIA3C52S.js.map → apply-JNOI2LR4.js.map} +1 -1
  7. package/dist/bench-B4VZON7E.js +910 -0
  8. package/dist/bench-B4VZON7E.js.map +1 -0
  9. package/dist/{chunk-FADTCQGM.js → chunk-2IQ6M4ZE.js} +94 -32
  10. package/dist/chunk-2IQ6M4ZE.js.map +1 -0
  11. package/dist/chunk-3BWZO4YI.js +141 -0
  12. package/dist/chunk-3BWZO4YI.js.map +1 -0
  13. package/dist/chunk-3WFZETIM.js +163 -0
  14. package/dist/chunk-3WFZETIM.js.map +1 -0
  15. package/dist/chunk-67YIU2VB.js +362 -0
  16. package/dist/chunk-67YIU2VB.js.map +1 -0
  17. package/dist/{chunk-QCPGHBSZ.js → chunk-6BENHR2I.js} +63 -21
  18. package/dist/chunk-6BENHR2I.js.map +1 -0
  19. package/dist/{chunk-BYZDPR7N.js → chunk-6QYMSNVA.js} +194 -235
  20. package/dist/chunk-6QYMSNVA.js.map +1 -0
  21. package/dist/{chunk-Y5ZDJ4PJ.js → chunk-76MMPJ53.js} +20 -10
  22. package/dist/chunk-76MMPJ53.js.map +1 -0
  23. package/dist/chunk-7Z4Y3VKM.js +26 -0
  24. package/dist/chunk-7Z4Y3VKM.js.map +1 -0
  25. package/dist/{chunk-3QHK4YQA.js → chunk-B72RQZBV.js} +346 -119
  26. package/dist/chunk-B72RQZBV.js.map +1 -0
  27. package/dist/chunk-BEZ5BA5U.js +625 -0
  28. package/dist/chunk-BEZ5BA5U.js.map +1 -0
  29. package/dist/chunk-BRCNQXYQ.js +74 -0
  30. package/dist/chunk-BRCNQXYQ.js.map +1 -0
  31. package/dist/chunk-CGKLE6WR.js +1203 -0
  32. package/dist/chunk-CGKLE6WR.js.map +1 -0
  33. package/dist/chunk-CRGIQFUQ.js +83 -0
  34. package/dist/chunk-CRGIQFUQ.js.map +1 -0
  35. package/dist/{chunk-NS6R37II.js → chunk-F6TOYSYY.js} +141 -12
  36. package/dist/chunk-F6TOYSYY.js.map +1 -0
  37. package/dist/chunk-G5EK2XRN.js +25 -0
  38. package/dist/chunk-G5EK2XRN.js.map +1 -0
  39. package/dist/chunk-HAKDLR6N.js +134 -0
  40. package/dist/chunk-HAKDLR6N.js.map +1 -0
  41. package/dist/chunk-J3SOTUVI.js +298 -0
  42. package/dist/chunk-J3SOTUVI.js.map +1 -0
  43. package/dist/chunk-JN6D3MY6.js +30 -0
  44. package/dist/chunk-JN6D3MY6.js.map +1 -0
  45. package/dist/{chunk-LAFNLLQP.js → chunk-KMRFRXIT.js} +5 -5
  46. package/dist/chunk-KT7JKOXB.js +72 -0
  47. package/dist/chunk-KT7JKOXB.js.map +1 -0
  48. package/dist/chunk-L6HSKTQE.js +77 -0
  49. package/dist/chunk-L6HSKTQE.js.map +1 -0
  50. package/dist/chunk-LBGHI4S2.js +1264 -0
  51. package/dist/chunk-LBGHI4S2.js.map +1 -0
  52. package/dist/chunk-LEW4QM74.js +180 -0
  53. package/dist/chunk-LEW4QM74.js.map +1 -0
  54. package/dist/{chunk-FJP3UQGD.js → chunk-LFEQIZLB.js} +115 -20
  55. package/dist/chunk-LFEQIZLB.js.map +1 -0
  56. package/dist/chunk-OOVG2KBY.js +77 -0
  57. package/dist/chunk-OOVG2KBY.js.map +1 -0
  58. package/dist/{chunk-56KS3TFQ.js → chunk-OR43364P.js} +115 -160
  59. package/dist/chunk-OR43364P.js.map +1 -0
  60. package/dist/chunk-P3LRUNC6.js +16 -0
  61. package/dist/chunk-P3LRUNC6.js.map +1 -0
  62. package/dist/{chunk-TSOLWK7Y.js → chunk-PBTA3QQX.js} +8 -7
  63. package/dist/{chunk-TSOLWK7Y.js.map → chunk-PBTA3QQX.js.map} +1 -1
  64. package/dist/{chunk-MJULIKQU.js → chunk-PHW2YV6N.js} +23 -47
  65. package/dist/chunk-PHW2YV6N.js.map +1 -0
  66. package/dist/{chunk-73ATPIYX.js → chunk-PZTWU277.js} +36 -71
  67. package/dist/chunk-PZTWU277.js.map +1 -0
  68. package/dist/{chunk-M5UCXTIT.js → chunk-QD4VOILZ.js} +22 -18
  69. package/dist/chunk-QD4VOILZ.js.map +1 -0
  70. package/dist/chunk-QJ5UZAH5.js +2718 -0
  71. package/dist/chunk-QJ5UZAH5.js.map +1 -0
  72. package/dist/chunk-QK7WUO7A.js +283 -0
  73. package/dist/chunk-QK7WUO7A.js.map +1 -0
  74. package/dist/{chunk-A4SLHOW7.js → chunk-QZVKRDJY.js} +27 -19
  75. package/dist/chunk-QZVKRDJY.js.map +1 -0
  76. package/dist/chunk-REO3PXXO.js +71 -0
  77. package/dist/chunk-REO3PXXO.js.map +1 -0
  78. package/dist/{chunk-EZATO3DW.js → chunk-RVO7L4FX.js} +594 -17
  79. package/dist/chunk-RVO7L4FX.js.map +1 -0
  80. package/dist/{chunk-XQUSIEKA.js → chunk-SZMHCEYV.js} +63 -14
  81. package/dist/chunk-SZMHCEYV.js.map +1 -0
  82. package/dist/chunk-TYRNTSPJ.js +243 -0
  83. package/dist/chunk-TYRNTSPJ.js.map +1 -0
  84. package/dist/chunk-UJ3L2MS7.js +238 -0
  85. package/dist/chunk-UJ3L2MS7.js.map +1 -0
  86. package/dist/chunk-V7MO5EDS.js +120 -0
  87. package/dist/chunk-V7MO5EDS.js.map +1 -0
  88. package/dist/chunk-WB2X37MO.js +415 -0
  89. package/dist/chunk-WB2X37MO.js.map +1 -0
  90. package/dist/{chunk-NTMMF5UD.js → chunk-X44FKNKP.js} +525 -252
  91. package/dist/chunk-X44FKNKP.js.map +1 -0
  92. package/dist/chunk-XEYH6ZZI.js +289 -0
  93. package/dist/chunk-XEYH6ZZI.js.map +1 -0
  94. package/dist/cli.js +267 -44
  95. package/dist/cli.js.map +1 -1
  96. package/dist/{config-PRJGWW7J.js → config-HMFMCY2M.js} +31 -5
  97. package/dist/contract-JH2WBIO6.js +8 -0
  98. package/dist/conventions-NJF2OPVQ.js +146 -0
  99. package/dist/conventions-NJF2OPVQ.js.map +1 -0
  100. package/dist/diagnostics-THH42ZMP.js +23 -0
  101. package/dist/execute-KFNNZZHI.js +35 -0
  102. package/dist/{generate-EGB4KV2B.js → generate-FW5C6NP7.js} +37 -20
  103. package/dist/{generate-EGB4KV2B.js.map → generate-FW5C6NP7.js.map} +1 -1
  104. package/dist/git-W72QQ6GT.js +33 -0
  105. package/dist/init-HTN4V67Q.js +24 -0
  106. package/dist/{operations-BYT626KQ.js → operations-BCFOBH42.js} +27 -15
  107. package/dist/{operations-BYT626KQ.js.map → operations-BCFOBH42.js.map} +1 -1
  108. package/dist/permissions-4AKNQZHK.js +18 -0
  109. package/dist/plan-SIZLGA4V.js +34 -0
  110. package/dist/{policy-6S4GFC76.js → policy-DT6Q6ZVM.js} +20 -6
  111. package/dist/policy-DT6Q6ZVM.js.map +1 -0
  112. package/dist/pr-OMWCGUOW.js +39 -0
  113. package/dist/pr-review-N24CZPKR.js +32 -0
  114. package/dist/pr-review-N24CZPKR.js.map +1 -0
  115. package/dist/prd-5OFTZAHJ.js +33 -0
  116. package/dist/prd-5OFTZAHJ.js.map +1 -0
  117. package/dist/ps-RFORTCUD.js +93 -0
  118. package/dist/ps-RFORTCUD.js.map +1 -0
  119. package/dist/recorder-KCCPMKQG.js +32 -0
  120. package/dist/recorder-KCCPMKQG.js.map +1 -0
  121. package/dist/registry-GLPXOMFG.js +15 -0
  122. package/dist/registry-GLPXOMFG.js.map +1 -0
  123. package/dist/{resume-PPCNQVVV.js → resume-M5RLKP4I.js} +55 -34
  124. package/dist/{resume-PPCNQVVV.js.map → resume-M5RLKP4I.js.map} +1 -1
  125. package/dist/review-YM4JAABY.js +35 -0
  126. package/dist/review-YM4JAABY.js.map +1 -0
  127. package/dist/routing-NNT5WKGX.js +94 -0
  128. package/dist/routing-NNT5WKGX.js.map +1 -0
  129. package/dist/run-PZUKHPQK.js +54 -0
  130. package/dist/run-PZUKHPQK.js.map +1 -0
  131. package/dist/session-publisher-T7EI3CIP.js +11 -0
  132. package/dist/session-publisher-T7EI3CIP.js.map +1 -0
  133. package/dist/{state-manager-2EDVDBAR.js → state-manager-GQH32C44.js} +4 -2
  134. package/dist/state-manager-GQH32C44.js.map +1 -0
  135. package/dist/usage-V2CHE5PY.js +177 -0
  136. package/dist/usage-V2CHE5PY.js.map +1 -0
  137. package/dist/{web-EF5WIIGG.js → web-EA3KGNFN.js} +45 -30
  138. package/dist/web-EA3KGNFN.js.map +1 -0
  139. package/package.json +6 -2
  140. package/prompts/execute.md +7 -8
  141. package/prompts/plan.md +4 -5
  142. package/prompts/pr.md +2 -2
  143. package/web/AGENTS.md +152 -13
  144. package/web/public/app.css +380 -109
  145. package/web/public/app.js +525 -25
  146. package/web/public/index.html +68 -1
  147. package/dist/analyze-OEET7KGE.js.map +0 -1
  148. package/dist/chunk-3QHK4YQA.js.map +0 -1
  149. package/dist/chunk-42PJFMAR.js +0 -605
  150. package/dist/chunk-42PJFMAR.js.map +0 -1
  151. package/dist/chunk-4JSOYE4G.js +0 -368
  152. package/dist/chunk-4JSOYE4G.js.map +0 -1
  153. package/dist/chunk-56KS3TFQ.js.map +0 -1
  154. package/dist/chunk-73ATPIYX.js.map +0 -1
  155. package/dist/chunk-A4SLHOW7.js.map +0 -1
  156. package/dist/chunk-BAUPQXPE.js +0 -173
  157. package/dist/chunk-BAUPQXPE.js.map +0 -1
  158. package/dist/chunk-BYZDPR7N.js.map +0 -1
  159. package/dist/chunk-CD5ULRVC.js +0 -615
  160. package/dist/chunk-CD5ULRVC.js.map +0 -1
  161. package/dist/chunk-DIDUVL6O.js +0 -1365
  162. package/dist/chunk-DIDUVL6O.js.map +0 -1
  163. package/dist/chunk-EZATO3DW.js.map +0 -1
  164. package/dist/chunk-FADTCQGM.js.map +0 -1
  165. package/dist/chunk-FJP3UQGD.js.map +0 -1
  166. package/dist/chunk-LWRSMTTZ.js +0 -18
  167. package/dist/chunk-LWRSMTTZ.js.map +0 -1
  168. package/dist/chunk-M5UCXTIT.js.map +0 -1
  169. package/dist/chunk-M66SJHQQ.js +0 -206
  170. package/dist/chunk-M66SJHQQ.js.map +0 -1
  171. package/dist/chunk-MJULIKQU.js.map +0 -1
  172. package/dist/chunk-NS6R37II.js.map +0 -1
  173. package/dist/chunk-NTMMF5UD.js.map +0 -1
  174. package/dist/chunk-QCPGHBSZ.js.map +0 -1
  175. package/dist/chunk-XQUSIEKA.js.map +0 -1
  176. package/dist/chunk-Y5ZDJ4PJ.js.map +0 -1
  177. package/dist/execute-XBNVL753.js +0 -18
  178. package/dist/init-AJHCXJBP.js +0 -10
  179. package/dist/plan-QOZ3RIO6.js +0 -21
  180. package/dist/policy-6S4GFC76.js.map +0 -1
  181. package/dist/pr-EBBHD2ZX.js +0 -26
  182. package/dist/pr-review-VVMW5PO4.js +0 -20
  183. package/dist/prd-JQSZF7PR.js +0 -21
  184. package/dist/review-3F6MARWH.js +0 -19
  185. package/dist/run-RXE5GDQO.js +0 -36
  186. package/dist/web-EF5WIIGG.js.map +0 -1
  187. /package/dist/{config-PRJGWW7J.js.map → agent-OX3KPHE4.js.map} +0 -0
  188. /package/dist/{chunk-LAFNLLQP.js.map → chunk-KMRFRXIT.js.map} +0 -0
  189. /package/dist/{execute-XBNVL753.js.map → config-HMFMCY2M.js.map} +0 -0
  190. /package/dist/{init-AJHCXJBP.js.map → contract-JH2WBIO6.js.map} +0 -0
  191. /package/dist/{plan-QOZ3RIO6.js.map → diagnostics-THH42ZMP.js.map} +0 -0
  192. /package/dist/{pr-EBBHD2ZX.js.map → execute-KFNNZZHI.js.map} +0 -0
  193. /package/dist/{pr-review-VVMW5PO4.js.map → git-W72QQ6GT.js.map} +0 -0
  194. /package/dist/{prd-JQSZF7PR.js.map → init-HTN4V67Q.js.map} +0 -0
  195. /package/dist/{review-3F6MARWH.js.map → permissions-4AKNQZHK.js.map} +0 -0
  196. /package/dist/{run-RXE5GDQO.js.map → plan-SIZLGA4V.js.map} +0 -0
  197. /package/dist/{state-manager-2EDVDBAR.js.map → pr-OMWCGUOW.js.map} +0 -0
@@ -1,615 +0,0 @@
1
- #!/usr/bin/env node
2
-
3
- // src/core/state-manager.ts
4
- import { readFile } from "fs/promises";
5
- import { ZodError } from "zod";
6
-
7
- // src/schemas.ts
8
- import { z as z2 } from "zod";
9
-
10
- // src/policy/schemas.ts
11
- import { z } from "zod";
12
- var policyDiscoveryConfigSchema = z.object({
13
- issueTemplates: z.boolean().default(true),
14
- pullRequestTemplate: z.boolean().default(true),
15
- docs: z.boolean().default(true),
16
- codeowners: z.boolean().default(true),
17
- labels: z.boolean().default(true),
18
- issueTypes: z.boolean().default(true)
19
- });
20
- var policyIssuesDeclarationSchema = z.object({
21
- titleConvention: z.string().min(1).optional(),
22
- /**
23
- * Whether Issue Flow may create a label the repository does not have.
24
- *
25
- * `.optional()` rather than `.default(false)`: the resolved declarations must
26
- * stay "only what was written", or the group would always look declared and
27
- * `sources` would report a provenance nobody asked for. The effective default
28
- * — false — lives at the call site.
29
- *
30
- * That default is a deliberate change of behaviour: creating taxonomy without
31
- * asking is the defect this exists to stop. A repository that wants the old
32
- * behaviour opts back into it.
33
- */
34
- allowLabelCreation: z.boolean().optional()
35
- });
36
- var policyPullRequestsDeclarationSchema = z.object({
37
- baseBranch: z.string().min(1).optional(),
38
- titleConvention: z.string().min(1).optional()
39
- });
40
- var policyGitDeclarationSchema = z.object({
41
- branchConvention: z.string().min(1).optional(),
42
- commitConvention: z.string().min(1).optional()
43
- });
44
- var policyConfigSchema = z.object({
45
- enabled: z.boolean().default(true),
46
- /**
47
- * Token budget for the `__REPO_POLICY__` projection. Sections above it are
48
- * replaced whole by a pointer rather than truncated — see
49
- * `policy/placeholders.ts`.
50
- */
51
- contextBudget: z.number().int().positive().default(1500),
52
- discovery: policyDiscoveryConfigSchema.prefault({}),
53
- issues: policyIssuesDeclarationSchema.prefault({}),
54
- pullRequests: policyPullRequestsDeclarationSchema.prefault({}),
55
- git: policyGitDeclarationSchema.prefault({})
56
- });
57
- var policyConfigInputSchema = z.object({
58
- enabled: z.boolean().optional(),
59
- contextBudget: z.number().int().positive().optional(),
60
- // Spelled out rather than `policyDiscoveryConfigSchema.partial()`: in zod 4
61
- // a `.default()` survives `.partial()`, so every toggle would come back
62
- // materialized and the input layer would stop meaning "what the user wrote".
63
- discovery: z.object({
64
- issueTemplates: z.boolean().optional(),
65
- pullRequestTemplate: z.boolean().optional(),
66
- docs: z.boolean().optional(),
67
- codeowners: z.boolean().optional(),
68
- labels: z.boolean().optional(),
69
- issueTypes: z.boolean().optional()
70
- }).optional(),
71
- issues: z.object({ titleConvention: z.string().nullish(), allowLabelCreation: z.boolean().optional() }).optional(),
72
- pullRequests: z.object({ baseBranch: z.string().nullish(), titleConvention: z.string().nullish() }).optional(),
73
- git: z.object({ branchConvention: z.string().nullish(), commitConvention: z.string().nullish() }).optional()
74
- });
75
-
76
- // src/schemas.ts
77
- var claudeUsageSchema = z2.object({
78
- inputTokens: z2.number().optional(),
79
- outputTokens: z2.number().optional(),
80
- cacheReadTokens: z2.number().optional(),
81
- cacheCreationTokens: z2.number().optional(),
82
- costUsd: z2.number().optional()
83
- });
84
- var userStoryStatusSchema = z2.enum(["backlog", "in_progress", "in_review", "done"]);
85
- var storyStageSchema = z2.enum([
86
- "pending",
87
- "executing",
88
- "awaiting_review",
89
- "in_review",
90
- "in_correction",
91
- "done",
92
- "failed"
93
- ]);
94
- var userStorySchema = z2.object({
95
- id: z2.string(),
96
- title: z2.string(),
97
- description: z2.string(),
98
- acceptanceCriteria: z2.array(z2.string()),
99
- priority: z2.number().int().positive(),
100
- passes: z2.boolean(),
101
- notes: z2.string(),
102
- ...claudeUsageSchema.shape,
103
- durationSeconds: z2.number().optional(),
104
- status: userStoryStatusSchema.optional(),
105
- dependencies: z2.array(z2.string()).optional(),
106
- stage: storyStageSchema.optional(),
107
- stageSince: z2.string().optional(),
108
- stageDetail: z2.string().optional()
109
- });
110
- var pipelineStateSchema = z2.object({
111
- analyzeCompleted: z2.boolean().optional(),
112
- prdCompleted: z2.boolean(),
113
- jsonCompleted: z2.boolean(),
114
- executionCompleted: z2.boolean(),
115
- reviewCompleted: z2.boolean(),
116
- prCreated: z2.boolean(),
117
- prReviewCompleted: z2.boolean().optional()
118
- });
119
- var pullRequestRefSchema = z2.object({
120
- number: z2.number().int().positive(),
121
- url: z2.string(),
122
- headBranch: z2.string(),
123
- createdAt: z2.string()
124
- });
125
- var prReviewRecommendationSchema = z2.enum([
126
- "APPROVE",
127
- "APPROVE_WITH_SUGGESTIONS",
128
- "REQUEST_CHANGES"
129
- ]);
130
- var prReviewStateSchema = z2.object({
131
- enabled: z2.boolean().default(false),
132
- pullRequestNumber: z2.number().int().positive().optional(),
133
- rounds: z2.number().int().min(0).default(0),
134
- lastRecommendation: prReviewRecommendationSchema.optional(),
135
- lastReviewedAt: z2.string().optional()
136
- });
137
- var lastErrorSchema = z2.object({
138
- category: z2.string(),
139
- message: z2.string(),
140
- at: z2.string()
141
- });
142
- var issueMetadataSchema = z2.object({
143
- schemaVersion: z2.literal(1),
144
- id: z2.string().min(1),
145
- number: z2.number().int().positive().nullable(),
146
- source: z2.enum(["github", "local"]),
147
- title: z2.string(),
148
- labels: z2.array(z2.string()),
149
- state: z2.enum(["open", "closed"]),
150
- createdAt: z2.string(),
151
- updatedAt: z2.string(),
152
- contentHash: z2.string(),
153
- remote: z2.object({
154
- provider: z2.enum(["github", "local"]),
155
- ref: z2.string(),
156
- syncedAt: z2.string(),
157
- syncedContentHash: z2.string()
158
- }).optional()
159
- });
160
- var runOwnerSchema = z2.object({
161
- pid: z2.number().int().positive(),
162
- host: z2.string(),
163
- startedAt: z2.string()
164
- });
165
- var issueRunStateSchema = z2.object({
166
- status: z2.enum(["idle", "running", "waiting", "retrying", "paused", "blocked", "failed"]).default("idle"),
167
- currentPhase: z2.string().nullable().default(null),
168
- attempt: z2.number().int().min(0).default(0),
169
- lastHeartbeatAt: z2.string().nullable().default(null),
170
- blockedReason: z2.string().nullable().default(null),
171
- owner: runOwnerSchema.nullable().default(null)
172
- });
173
- var taskPlanSchema = z2.object({
174
- project: z2.string(),
175
- issueNumber: z2.union([z2.number().int().positive(), z2.string().min(1)]),
176
- issueUrl: z2.string().optional().default(""),
177
- branchName: z2.string(),
178
- noBranch: z2.boolean().optional().default(false),
179
- description: z2.string(),
180
- issueStatus: z2.enum(["pending", "in_progress", "completed"]),
181
- completedAt: z2.string().nullable(),
182
- lastAttemptAt: z2.string().nullable(),
183
- lastError: lastErrorSchema.nullable(),
184
- correctionCycle: z2.number().int().min(0),
185
- maxCorrectionCycles: z2.number().int().min(0),
186
- /**
187
- * Findings from the most recent failed review, verbatim. Non-null means the
188
- * issue has a pending correction even if every userStories[].passes is
189
- * already true — the execute phase must address these before the field is
190
- * cleared back to null. See core/engine.ts's early-return guards.
191
- */
192
- lastReviewFindings: z2.string().nullable().optional().default(null),
193
- pipeline: pipelineStateSchema,
194
- /**
195
- * Where the run stands right now. Purely additive: absent in every plan
196
- * written before it, and absent is not the same as `idle` — it means the
197
- * plan predates the field, which is why there is no `.default()` here.
198
- */
199
- runState: issueRunStateSchema.optional(),
200
- pullRequest: pullRequestRefSchema.optional(),
201
- prReview: prReviewStateSchema.optional(),
202
- userStories: z2.array(userStorySchema)
203
- });
204
- var headlessResultSchema = z2.object({
205
- success: z2.boolean(),
206
- result: z2.string(),
207
- cost: claudeUsageSchema.nullable(),
208
- error: z2.string().nullable()
209
- });
210
- var sessionLogEntrySchema = z2.object({
211
- at: z2.string(),
212
- level: z2.enum(["info", "warn", "error"]),
213
- message: z2.string()
214
- });
215
- var sessionUsageShape = {
216
- inputTokens: z2.number().nullable().default(null),
217
- outputTokens: z2.number().nullable().default(null),
218
- cacheReadTokens: z2.number().nullable().default(null),
219
- cacheCreationTokens: z2.number().nullable().default(null),
220
- costUsd: z2.number().nullable().default(null)
221
- };
222
- var sessionPhaseSchema = z2.object({
223
- name: z2.string(),
224
- status: z2.enum(["pending", "running", "completed", "failed"]),
225
- startedAt: z2.string().nullable(),
226
- endedAt: z2.string().nullable(),
227
- durationSeconds: z2.number().nullable(),
228
- error: z2.string().nullable(),
229
- ...sessionUsageShape
230
- });
231
- var sessionStorySchema = z2.object({
232
- id: z2.string(),
233
- title: z2.string(),
234
- priority: z2.number(),
235
- passes: z2.boolean(),
236
- completedAt: z2.string().nullable(),
237
- // Also introduced with the metrics, hence the same tolerant default.
238
- durationSeconds: z2.number().nullable().default(null),
239
- // Snapshot fields are always present on output and defaulted on input, so a
240
- // session.json written before they existed still parses. This is the mirror
241
- // image of userStorySchema, where the same two fields are plainly optional.
242
- status: userStoryStatusSchema.default("backlog"),
243
- dependencies: z2.array(z2.string()).default([]),
244
- // Published for the panel's story detail view. Same tolerant default as the
245
- // fields above: absent (older session.json) and empty resolve to the same
246
- // value, so the client never has to tell them apart.
247
- description: z2.string().default(""),
248
- acceptanceCriteria: z2.array(z2.string()).default([]),
249
- // Additive like the rest of this schema: a session.json written before
250
- // `stage` existed parses into 'pending'/null, the same values a fresh
251
- // snapshot starts a story at.
252
- stage: storyStageSchema.default("pending"),
253
- stageSince: z2.string().nullable().default(null),
254
- stageDetail: z2.string().nullable().default(null),
255
- ...sessionUsageShape
256
- });
257
- var sessionSnapshotSchema = z2.object({
258
- schemaVersion: z2.literal(1),
259
- sessionId: z2.string().nullable(),
260
- readOnly: z2.literal(true),
261
- capabilities: z2.array(z2.string()),
262
- issue: z2.object({
263
- number: z2.number().nullable(),
264
- url: z2.string().nullable(),
265
- // Additive: a session.json written before the Issue section was enriched
266
- // parses into the same "not reported" values createInitialSnapshot() uses.
267
- title: z2.string().nullable().default(null),
268
- description: z2.string().nullable().default(null),
269
- labels: z2.array(z2.string()).default([]),
270
- state: z2.string().nullable().default(null)
271
- }),
272
- status: z2.enum(["idle", "running", "completed", "failed"]),
273
- startedAt: z2.string().nullable(),
274
- updatedAt: z2.string().nullable(),
275
- endedAt: z2.string().nullable(),
276
- elapsedSeconds: z2.number().nullable(),
277
- estimatedRemainingSeconds: z2.number().nullable(),
278
- progress: z2.object({
279
- percent: z2.number(),
280
- phasesCompleted: z2.number(),
281
- phasesTotal: z2.number(),
282
- storiesCompleted: z2.number(),
283
- storiesTotal: z2.number()
284
- }),
285
- currentPhase: z2.string().nullable(),
286
- currentActivity: z2.object({
287
- story: z2.string().nullable(),
288
- tool: z2.string().nullable(),
289
- detail: z2.string().nullable(),
290
- since: z2.string()
291
- }).nullable(),
292
- phases: z2.array(sessionPhaseSchema),
293
- stories: z2.array(sessionStorySchema),
294
- // The whole aggregate is additive: a snapshot from before it existed parses
295
- // into the same "nothing reported" object the reducer starts from.
296
- metrics: z2.object({
297
- totalInputTokens: z2.number().nullable().default(null),
298
- totalOutputTokens: z2.number().nullable().default(null),
299
- totalCacheReadTokens: z2.number().nullable().default(null),
300
- totalCacheCreationTokens: z2.number().nullable().default(null),
301
- totalCostUsd: z2.number().nullable().default(null)
302
- }).default({
303
- totalInputTokens: null,
304
- totalOutputTokens: null,
305
- totalCacheReadTokens: null,
306
- totalCacheCreationTokens: null,
307
- totalCostUsd: null
308
- }),
309
- execution: z2.object({
310
- iteration: z2.number(),
311
- retries: z2.number(),
312
- correctionCycle: z2.number(),
313
- maxCorrectionCycles: z2.number().nullable()
314
- }),
315
- git: z2.object({
316
- branch: z2.string().nullable(),
317
- baseBranch: z2.string().nullable(),
318
- commits: z2.array(z2.object({ hash: z2.string(), subject: z2.string() }))
319
- }),
320
- // Additive like the metrics aggregate: a session.json written before the
321
- // repository section existed parses into the same all-null object
322
- // createInitialSnapshot() starts from.
323
- repository: z2.object({
324
- name: z2.string().nullable().default(null),
325
- remoteUrl: z2.string().nullable().default(null),
326
- branch: z2.string().nullable().default(null),
327
- headCommit: z2.string().nullable().default(null),
328
- root: z2.string().nullable().default(null)
329
- }).default({ name: null, remoteUrl: null, branch: null, headCommit: null, root: null }),
330
- pullRequests: z2.array(z2.object({ number: z2.number(), url: z2.string(), title: z2.string() })),
331
- logs: z2.array(sessionLogEntrySchema),
332
- errors: z2.array(sessionLogEntrySchema),
333
- warnings: z2.array(sessionLogEntrySchema),
334
- lastError: z2.object({ message: z2.string(), at: z2.string() }).nullable(),
335
- nextSteps: z2.array(z2.string()),
336
- environment: z2.object({ node: z2.string(), platform: z2.string() }).nullable()
337
- });
338
- var webConfigSchema = z2.object({
339
- enabled: z2.boolean().default(false),
340
- port: z2.number().int().min(1).max(65535).default(3737),
341
- host: z2.string().min(1).default("0.0.0.0"),
342
- refreshSeconds: z2.number().positive().default(5),
343
- logLimit: z2.number().int().positive().default(200),
344
- includeLogs: z2.boolean().default(true)
345
- });
346
- var issuesConfigSchema = z2.object({
347
- defaultGenerateTarget: z2.enum(["github", "local", "both"]).default("github"),
348
- preferredProvider: z2.enum(["github", "local"]).default("github"),
349
- conflictPolicy: z2.enum(["ask", "prefer-local", "prefer-github"]).default("ask"),
350
- requireConfirmation: z2.boolean().default(true)
351
- });
352
- var prReviewConfigSchema = z2.object({
353
- publisher: z2.enum(["local", "github"]).default("local")
354
- });
355
-
356
- // src/utils/fs.ts
357
- import { copyFile, mkdtemp, rename, unlink, writeFile } from "fs/promises";
358
- import { tmpdir } from "os";
359
- import { basename, join } from "path";
360
- async function writeFileAtomic(path, content) {
361
- const tmpDir = await mkdtemp(join(tmpdir(), "issue-flow-"));
362
- const tmpFile = join(tmpDir, basename(path));
363
- await writeFile(tmpFile, content, "utf-8");
364
- try {
365
- await rename(tmpFile, path);
366
- } catch (err) {
367
- if (err.code === "EXDEV") {
368
- await copyFile(tmpFile, path);
369
- await unlink(tmpFile);
370
- } else {
371
- throw err;
372
- }
373
- }
374
- }
375
-
376
- // src/core/metrics.ts
377
- var USAGE_FIELDS = [
378
- "inputTokens",
379
- "outputTokens",
380
- "cacheReadTokens",
381
- "cacheCreationTokens",
382
- "costUsd"
383
- ];
384
- function num(value) {
385
- return typeof value === "number" && Number.isFinite(value) ? value : void 0;
386
- }
387
- function isRecord(value) {
388
- return typeof value === "object" && value !== null;
389
- }
390
- function parseUsage(payload) {
391
- if (!isRecord(payload)) return null;
392
- const usageRaw = isRecord(payload.usage) ? payload.usage : void 0;
393
- const usage = {};
394
- const inputTokens = usageRaw ? num(usageRaw.input_tokens) : void 0;
395
- const outputTokens = usageRaw ? num(usageRaw.output_tokens) : void 0;
396
- const cacheReadTokens = usageRaw ? num(usageRaw.cache_read_input_tokens) : void 0;
397
- const cacheCreationTokens = usageRaw ? num(usageRaw.cache_creation_input_tokens) : void 0;
398
- const costUsd = num(payload.total_cost_usd);
399
- const legacyInput = num(payload.num_input_tokens);
400
- const legacyOutput = num(payload.num_output_tokens);
401
- const legacyCost = num(payload.cost_usd);
402
- const resolvedInput = inputTokens ?? legacyInput;
403
- const resolvedOutput = outputTokens ?? legacyOutput;
404
- const resolvedCost = costUsd ?? legacyCost;
405
- if (resolvedInput !== void 0) usage.inputTokens = resolvedInput;
406
- if (resolvedOutput !== void 0) usage.outputTokens = resolvedOutput;
407
- if (cacheReadTokens !== void 0) usage.cacheReadTokens = cacheReadTokens;
408
- if (cacheCreationTokens !== void 0) usage.cacheCreationTokens = cacheCreationTokens;
409
- if (resolvedCost !== void 0) usage.costUsd = resolvedCost;
410
- return Object.keys(usage).length > 0 ? usage : null;
411
- }
412
- function sumUsage(a, b) {
413
- const result = {};
414
- for (const field of USAGE_FIELDS) {
415
- const left = a?.[field];
416
- const right = b?.[field];
417
- if (left === void 0 && right === void 0) continue;
418
- result[field] = (left ?? 0) + (right ?? 0);
419
- }
420
- return result;
421
- }
422
- function divideUsage(usage, parts) {
423
- const result = {};
424
- if (!usage) return result;
425
- const divisor = Number.isFinite(parts) && parts > 1 ? parts : 1;
426
- for (const field of USAGE_FIELDS) {
427
- const value = usage[field];
428
- if (value === void 0) continue;
429
- result[field] = field === "costUsd" ? value / divisor : Math.round(value / divisor);
430
- }
431
- return result;
432
- }
433
- function compactTokens(value) {
434
- const abs = Math.abs(value);
435
- if (abs >= 1e6) return `${(value / 1e6).toFixed(1)}M`;
436
- if (abs >= 1e3) return `${(value / 1e3).toFixed(1)}k`;
437
- return String(Math.round(value));
438
- }
439
- function formatTokens(usage) {
440
- if (!usage) return "";
441
- const segments = [];
442
- const io = [];
443
- if (usage.inputTokens !== void 0) io.push(`${compactTokens(usage.inputTokens)} in`);
444
- if (usage.outputTokens !== void 0) io.push(`${compactTokens(usage.outputTokens)} out`);
445
- if (io.length > 0) segments.push(io.join(" / "));
446
- const cache = usage.cacheReadTokens !== void 0 || usage.cacheCreationTokens !== void 0 ? (usage.cacheReadTokens ?? 0) + (usage.cacheCreationTokens ?? 0) : void 0;
447
- if (cache !== void 0) segments.push(`${compactTokens(cache)} cache`);
448
- if (usage.costUsd !== void 0) segments.push(`~$${usage.costUsd.toFixed(4)}`);
449
- return segments.join(" \xB7 ");
450
- }
451
- function hasUsageData(usage) {
452
- if (!usage) return false;
453
- return USAGE_FIELDS.some((field) => usage[field] !== void 0);
454
- }
455
-
456
- // src/core/state-manager.ts
457
- function isoNow() {
458
- return (/* @__PURE__ */ new Date()).toISOString().replace(/\.\d{3}Z$/, "Z");
459
- }
460
- async function loadTaskPlan(path) {
461
- const content = await readFile(path, "utf-8");
462
- const raw = JSON.parse(content);
463
- try {
464
- return taskPlanSchema.parse(raw);
465
- } catch (err) {
466
- if (err instanceof ZodError) {
467
- const issues = err.issues.map((i) => ` - ${i.path.join(".")}: ${i.message}`).join("\n");
468
- throw new Error(`Invalid tasks.json at ${path}:
469
- ${issues}`);
470
- }
471
- throw err;
472
- }
473
- }
474
- async function saveTaskPlan(path, plan) {
475
- await writeFileAtomic(path, `${JSON.stringify(plan, null, 2)}
476
- `);
477
- }
478
- function initializeState(plan) {
479
- const defaultPipeline = {
480
- prdCompleted: false,
481
- jsonCompleted: false,
482
- executionCompleted: false,
483
- reviewCompleted: false,
484
- prCreated: false
485
- };
486
- return {
487
- ...plan,
488
- issueStatus: plan.issueStatus ?? "pending",
489
- completedAt: plan.completedAt ?? null,
490
- lastAttemptAt: plan.lastAttemptAt ?? null,
491
- lastError: plan.lastError ?? null,
492
- correctionCycle: plan.correctionCycle ?? 0,
493
- maxCorrectionCycles: plan.maxCorrectionCycles ?? 3,
494
- lastReviewFindings: plan.lastReviewFindings ?? null,
495
- pipeline: plan.pipeline ? { ...defaultPipeline, ...plan.pipeline } : defaultPipeline
496
- };
497
- }
498
- function hasPendingCorrection(plan) {
499
- return Boolean(plan.lastReviewFindings);
500
- }
501
- function allStoriesPass(plan) {
502
- if (plan.userStories.length === 0) {
503
- return false;
504
- }
505
- return plan.userStories.every((story) => story.passes === true);
506
- }
507
- function selectActiveStory(stories) {
508
- return [...stories].filter((story) => !story.passes).sort((a, b) => a.priority - b.priority)[0];
509
- }
510
- function markStoryPassing(plan, storyId) {
511
- return {
512
- ...plan,
513
- userStories: plan.userStories.map(
514
- (story) => story.id === storyId ? { ...story, passes: true } : story
515
- )
516
- };
517
- }
518
- function applyStoryMetrics(plan, storyIds, share, durationSeconds) {
519
- if (storyIds.length === 0) return plan;
520
- const targets = new Set(storyIds);
521
- return {
522
- ...plan,
523
- userStories: plan.userStories.map((story) => {
524
- if (!targets.has(story.id)) return story;
525
- const updated = { ...story, ...sumUsage(story, share) };
526
- if (story.durationSeconds !== void 0 || durationSeconds !== void 0) {
527
- updated.durationSeconds = (story.durationSeconds ?? 0) + (durationSeconds ?? 0);
528
- }
529
- return updated;
530
- })
531
- };
532
- }
533
- function markIssueInProgress(plan, timestamp) {
534
- const ts = timestamp ?? isoNow();
535
- return {
536
- ...plan,
537
- issueStatus: "in_progress",
538
- completedAt: null,
539
- lastAttemptAt: ts
540
- };
541
- }
542
- function markIssueCompleted(plan) {
543
- const ts = isoNow();
544
- return {
545
- ...plan,
546
- issueStatus: "completed",
547
- completedAt: ts,
548
- lastAttemptAt: ts,
549
- lastError: null,
550
- pipeline: plan.pipeline ? { ...plan.pipeline, executionCompleted: true } : plan.pipeline
551
- };
552
- }
553
- function setLastError(plan, category, message) {
554
- const ts = isoNow();
555
- const error = {
556
- category,
557
- message,
558
- at: ts
559
- };
560
- return {
561
- ...plan,
562
- lastAttemptAt: ts,
563
- lastError: error
564
- };
565
- }
566
- function clearLastError(plan, attemptStartedAt) {
567
- const ts = isoNow();
568
- if (plan.lastError && plan.lastError.at > attemptStartedAt) {
569
- return {
570
- ...plan,
571
- lastAttemptAt: ts
572
- };
573
- }
574
- return {
575
- ...plan,
576
- lastAttemptAt: ts,
577
- lastError: null
578
- };
579
- }
580
- function trimErrorMessage(message) {
581
- return message.split("\n").filter((line) => line.trim().length > 0).slice(0, 8).join("\n");
582
- }
583
-
584
- export {
585
- policyConfigSchema,
586
- policyConfigInputSchema,
587
- pullRequestRefSchema,
588
- issueMetadataSchema,
589
- taskPlanSchema,
590
- sessionSnapshotSchema,
591
- webConfigSchema,
592
- issuesConfigSchema,
593
- prReviewConfigSchema,
594
- writeFileAtomic,
595
- parseUsage,
596
- sumUsage,
597
- divideUsage,
598
- formatTokens,
599
- hasUsageData,
600
- isoNow,
601
- loadTaskPlan,
602
- saveTaskPlan,
603
- initializeState,
604
- hasPendingCorrection,
605
- allStoriesPass,
606
- selectActiveStory,
607
- markStoryPassing,
608
- applyStoryMetrics,
609
- markIssueInProgress,
610
- markIssueCompleted,
611
- setLastError,
612
- clearLastError,
613
- trimErrorMessage
614
- };
615
- //# sourceMappingURL=chunk-CD5ULRVC.js.map