issue-flow 0.12.0 → 0.13.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 (185) hide show
  1. package/README.md +79 -274
  2. package/dist/agent-BXRIEKVM.js +238 -0
  3. package/dist/agent-BXRIEKVM.js.map +1 -0
  4. package/dist/{analyze-OEET7KGE.js → analyze-WS47UYGN.js} +28 -16
  5. package/dist/analyze-WS47UYGN.js.map +1 -0
  6. package/dist/{apply-ZIA3C52S.js → apply-OS62UWRN.js} +15 -7
  7. package/dist/{apply-ZIA3C52S.js.map → apply-OS62UWRN.js.map} +1 -1
  8. package/dist/bench-SA3BOME5.js +906 -0
  9. package/dist/bench-SA3BOME5.js.map +1 -0
  10. package/dist/chunk-37N2RJW2.js +120 -0
  11. package/dist/chunk-37N2RJW2.js.map +1 -0
  12. package/dist/chunk-3XLCNVMD.js +180 -0
  13. package/dist/chunk-3XLCNVMD.js.map +1 -0
  14. package/dist/chunk-5TB6KLC2.js +72 -0
  15. package/dist/chunk-5TB6KLC2.js.map +1 -0
  16. package/dist/{chunk-MJULIKQU.js → chunk-664Y3NDX.js} +23 -47
  17. package/dist/chunk-664Y3NDX.js.map +1 -0
  18. package/dist/chunk-6FDFRNXZ.js +357 -0
  19. package/dist/chunk-6FDFRNXZ.js.map +1 -0
  20. package/dist/{chunk-56KS3TFQ.js → chunk-7KD66LIM.js} +115 -160
  21. package/dist/chunk-7KD66LIM.js.map +1 -0
  22. package/dist/chunk-7Z4Y3VKM.js +26 -0
  23. package/dist/chunk-7Z4Y3VKM.js.map +1 -0
  24. package/dist/chunk-ARFVHC2F.js +1111 -0
  25. package/dist/chunk-ARFVHC2F.js.map +1 -0
  26. package/dist/{chunk-NS6R37II.js → chunk-BHJCGWQX.js} +141 -12
  27. package/dist/chunk-BHJCGWQX.js.map +1 -0
  28. package/dist/chunk-BQDQTIM7.js +74 -0
  29. package/dist/chunk-BQDQTIM7.js.map +1 -0
  30. package/dist/chunk-CNBYCMSU.js +2709 -0
  31. package/dist/chunk-CNBYCMSU.js.map +1 -0
  32. package/dist/chunk-CRGIQFUQ.js +83 -0
  33. package/dist/chunk-CRGIQFUQ.js.map +1 -0
  34. package/dist/chunk-DIG5XKQQ.js +298 -0
  35. package/dist/chunk-DIG5XKQQ.js.map +1 -0
  36. package/dist/chunk-FZDR7CGH.js +71 -0
  37. package/dist/chunk-FZDR7CGH.js.map +1 -0
  38. package/dist/chunk-HEF2RMKN.js +413 -0
  39. package/dist/chunk-HEF2RMKN.js.map +1 -0
  40. package/dist/{chunk-M5UCXTIT.js → chunk-HJGGNLWI.js} +22 -18
  41. package/dist/chunk-HJGGNLWI.js.map +1 -0
  42. package/dist/chunk-HQAHNIAR.js +283 -0
  43. package/dist/chunk-HQAHNIAR.js.map +1 -0
  44. package/dist/{chunk-FJP3UQGD.js → chunk-IHIEXUTC.js} +39 -19
  45. package/dist/chunk-IHIEXUTC.js.map +1 -0
  46. package/dist/{chunk-Y5ZDJ4PJ.js → chunk-IV5SS4JN.js} +18 -10
  47. package/dist/chunk-IV5SS4JN.js.map +1 -0
  48. package/dist/{chunk-BYZDPR7N.js → chunk-IYV6KNVF.js} +146 -13
  49. package/dist/chunk-IYV6KNVF.js.map +1 -0
  50. package/dist/{chunk-TSOLWK7Y.js → chunk-J62QSVP6.js} +8 -8
  51. package/dist/chunk-KQHB7ZT3.js +559 -0
  52. package/dist/chunk-KQHB7ZT3.js.map +1 -0
  53. package/dist/chunk-L6HSKTQE.js +77 -0
  54. package/dist/chunk-L6HSKTQE.js.map +1 -0
  55. package/dist/{chunk-3QHK4YQA.js → chunk-LZ6GFQAG.js} +334 -117
  56. package/dist/chunk-LZ6GFQAG.js.map +1 -0
  57. package/dist/{chunk-LAFNLLQP.js → chunk-MIVHK5YI.js} +5 -5
  58. package/dist/chunk-NEZZ6KDR.js +1217 -0
  59. package/dist/chunk-NEZZ6KDR.js.map +1 -0
  60. package/dist/{chunk-NTMMF5UD.js → chunk-OPNGPUKJ.js} +436 -254
  61. package/dist/chunk-OPNGPUKJ.js.map +1 -0
  62. package/dist/chunk-P3LRUNC6.js +16 -0
  63. package/dist/chunk-P3LRUNC6.js.map +1 -0
  64. package/dist/{chunk-FADTCQGM.js → chunk-PIVGJM6K.js} +94 -32
  65. package/dist/chunk-PIVGJM6K.js.map +1 -0
  66. package/dist/{chunk-73ATPIYX.js → chunk-PV4OX5TC.js} +36 -71
  67. package/dist/chunk-PV4OX5TC.js.map +1 -0
  68. package/dist/chunk-QCXPNSEL.js +141 -0
  69. package/dist/chunk-QCXPNSEL.js.map +1 -0
  70. package/dist/{chunk-XQUSIEKA.js → chunk-QXDNBYQF.js} +52 -14
  71. package/dist/chunk-QXDNBYQF.js.map +1 -0
  72. package/dist/chunk-SNTTOQAD.js +30 -0
  73. package/dist/chunk-SNTTOQAD.js.map +1 -0
  74. package/dist/{chunk-QCPGHBSZ.js → chunk-TM67EHSV.js} +63 -21
  75. package/dist/chunk-TM67EHSV.js.map +1 -0
  76. package/dist/chunk-TVN2JVOF.js +77 -0
  77. package/dist/chunk-TVN2JVOF.js.map +1 -0
  78. package/dist/chunk-TX5WIVYP.js +129 -0
  79. package/dist/chunk-TX5WIVYP.js.map +1 -0
  80. package/dist/{chunk-A4SLHOW7.js → chunk-UJ7XWK7J.js} +24 -18
  81. package/dist/chunk-UJ7XWK7J.js.map +1 -0
  82. package/dist/{chunk-EZATO3DW.js → chunk-UOCPC2Y2.js} +594 -17
  83. package/dist/chunk-UOCPC2Y2.js.map +1 -0
  84. package/dist/chunk-XEYH6ZZI.js +289 -0
  85. package/dist/chunk-XEYH6ZZI.js.map +1 -0
  86. package/dist/cli.js +264 -44
  87. package/dist/cli.js.map +1 -1
  88. package/dist/{config-PRJGWW7J.js → config-MEM2IWWN.js} +28 -5
  89. package/dist/contract-JH2WBIO6.js +8 -0
  90. package/dist/conventions-WV4NDXGH.js +143 -0
  91. package/dist/conventions-WV4NDXGH.js.map +1 -0
  92. package/dist/execute-NITIHHCK.js +31 -0
  93. package/dist/{generate-EGB4KV2B.js → generate-MVQI7A45.js} +34 -20
  94. package/dist/{generate-EGB4KV2B.js.map → generate-MVQI7A45.js.map} +1 -1
  95. package/dist/git-YRVRUN3C.js +31 -0
  96. package/dist/init-OKWEC3EV.js +21 -0
  97. package/dist/{operations-BYT626KQ.js → operations-LU6JA3BX.js} +24 -15
  98. package/dist/{operations-BYT626KQ.js.map → operations-LU6JA3BX.js.map} +1 -1
  99. package/dist/permissions-7NMDFU27.js +18 -0
  100. package/dist/plan-LEJJF3DE.js +31 -0
  101. package/dist/{policy-6S4GFC76.js → policy-JSYEK5B2.js} +17 -6
  102. package/dist/policy-JSYEK5B2.js.map +1 -0
  103. package/dist/pr-HPVUZ7S3.js +36 -0
  104. package/dist/pr-review-R2QZBT3F.js +29 -0
  105. package/dist/prd-5O6GYCC6.js +30 -0
  106. package/dist/ps-TNE44R5V.js +90 -0
  107. package/dist/ps-TNE44R5V.js.map +1 -0
  108. package/dist/recorder-XGF55WXI.js +31 -0
  109. package/dist/recorder-XGF55WXI.js.map +1 -0
  110. package/dist/registry-LGPE53QD.js +15 -0
  111. package/dist/registry-LGPE53QD.js.map +1 -0
  112. package/dist/{resume-PPCNQVVV.js → resume-QMEPMSZW.js} +51 -34
  113. package/dist/{resume-PPCNQVVV.js.map → resume-QMEPMSZW.js.map} +1 -1
  114. package/dist/review-YKWD6SNN.js +32 -0
  115. package/dist/review-YKWD6SNN.js.map +1 -0
  116. package/dist/routing-2ZUMZPJB.js +91 -0
  117. package/dist/routing-2ZUMZPJB.js.map +1 -0
  118. package/dist/run-YU4TR62R.js +50 -0
  119. package/dist/run-YU4TR62R.js.map +1 -0
  120. package/dist/{state-manager-2EDVDBAR.js → state-manager-X3PT3FGT.js} +4 -2
  121. package/dist/state-manager-X3PT3FGT.js.map +1 -0
  122. package/dist/usage-VCFLDA5Y.js +174 -0
  123. package/dist/usage-VCFLDA5Y.js.map +1 -0
  124. package/dist/{web-EF5WIIGG.js → web-XVHLX62B.js} +41 -30
  125. package/dist/web-XVHLX62B.js.map +1 -0
  126. package/package.json +6 -2
  127. package/prompts/execute.md +7 -8
  128. package/prompts/plan.md +4 -5
  129. package/prompts/pr.md +2 -2
  130. package/web/AGENTS.md +3 -3
  131. package/web/public/app.css +38 -0
  132. package/web/public/app.js +121 -11
  133. package/web/public/index.html +24 -0
  134. package/dist/analyze-OEET7KGE.js.map +0 -1
  135. package/dist/chunk-3QHK4YQA.js.map +0 -1
  136. package/dist/chunk-42PJFMAR.js +0 -605
  137. package/dist/chunk-42PJFMAR.js.map +0 -1
  138. package/dist/chunk-4JSOYE4G.js +0 -368
  139. package/dist/chunk-4JSOYE4G.js.map +0 -1
  140. package/dist/chunk-56KS3TFQ.js.map +0 -1
  141. package/dist/chunk-73ATPIYX.js.map +0 -1
  142. package/dist/chunk-A4SLHOW7.js.map +0 -1
  143. package/dist/chunk-BAUPQXPE.js +0 -173
  144. package/dist/chunk-BAUPQXPE.js.map +0 -1
  145. package/dist/chunk-BYZDPR7N.js.map +0 -1
  146. package/dist/chunk-CD5ULRVC.js +0 -615
  147. package/dist/chunk-CD5ULRVC.js.map +0 -1
  148. package/dist/chunk-DIDUVL6O.js +0 -1365
  149. package/dist/chunk-DIDUVL6O.js.map +0 -1
  150. package/dist/chunk-EZATO3DW.js.map +0 -1
  151. package/dist/chunk-FADTCQGM.js.map +0 -1
  152. package/dist/chunk-FJP3UQGD.js.map +0 -1
  153. package/dist/chunk-LWRSMTTZ.js +0 -18
  154. package/dist/chunk-LWRSMTTZ.js.map +0 -1
  155. package/dist/chunk-M5UCXTIT.js.map +0 -1
  156. package/dist/chunk-M66SJHQQ.js +0 -206
  157. package/dist/chunk-M66SJHQQ.js.map +0 -1
  158. package/dist/chunk-MJULIKQU.js.map +0 -1
  159. package/dist/chunk-NS6R37II.js.map +0 -1
  160. package/dist/chunk-NTMMF5UD.js.map +0 -1
  161. package/dist/chunk-QCPGHBSZ.js.map +0 -1
  162. package/dist/chunk-XQUSIEKA.js.map +0 -1
  163. package/dist/chunk-Y5ZDJ4PJ.js.map +0 -1
  164. package/dist/execute-XBNVL753.js +0 -18
  165. package/dist/init-AJHCXJBP.js +0 -10
  166. package/dist/plan-QOZ3RIO6.js +0 -21
  167. package/dist/policy-6S4GFC76.js.map +0 -1
  168. package/dist/pr-EBBHD2ZX.js +0 -26
  169. package/dist/pr-review-VVMW5PO4.js +0 -20
  170. package/dist/prd-JQSZF7PR.js +0 -21
  171. package/dist/review-3F6MARWH.js +0 -19
  172. package/dist/run-RXE5GDQO.js +0 -36
  173. package/dist/web-EF5WIIGG.js.map +0 -1
  174. /package/dist/{chunk-TSOLWK7Y.js.map → chunk-J62QSVP6.js.map} +0 -0
  175. /package/dist/{chunk-LAFNLLQP.js.map → chunk-MIVHK5YI.js.map} +0 -0
  176. /package/dist/{config-PRJGWW7J.js.map → config-MEM2IWWN.js.map} +0 -0
  177. /package/dist/{execute-XBNVL753.js.map → contract-JH2WBIO6.js.map} +0 -0
  178. /package/dist/{init-AJHCXJBP.js.map → execute-NITIHHCK.js.map} +0 -0
  179. /package/dist/{plan-QOZ3RIO6.js.map → git-YRVRUN3C.js.map} +0 -0
  180. /package/dist/{pr-EBBHD2ZX.js.map → init-OKWEC3EV.js.map} +0 -0
  181. /package/dist/{pr-review-VVMW5PO4.js.map → permissions-7NMDFU27.js.map} +0 -0
  182. /package/dist/{prd-JQSZF7PR.js.map → plan-LEJJF3DE.js.map} +0 -0
  183. /package/dist/{review-3F6MARWH.js.map → pr-HPVUZ7S3.js.map} +0 -0
  184. /package/dist/{run-RXE5GDQO.js.map → pr-review-R2QZBT3F.js.map} +0 -0
  185. /package/dist/{state-manager-2EDVDBAR.js.map → prd-5O6GYCC6.js.map} +0 -0
@@ -0,0 +1,1217 @@
1
+ #!/usr/bin/env node
2
+
3
+ // src/agents/types.ts
4
+ var AGENT_PHASES = [
5
+ "analyze",
6
+ "generate",
7
+ "prd",
8
+ "plan",
9
+ "execute",
10
+ "review",
11
+ "pr",
12
+ "pr-review"
13
+ ];
14
+ function isAgentPhase(value) {
15
+ return AGENT_PHASES.includes(value);
16
+ }
17
+ function isAgentProviderId(value) {
18
+ return value === "claude" || value === "codex" || value === "cursor" || value === "antigravity";
19
+ }
20
+ var CLAUDE_CAPABILITIES = {
21
+ extraDirectories: "flag",
22
+ addDirs: true,
23
+ toolAllowlist: true,
24
+ maxTurns: true,
25
+ osSandbox: false,
26
+ modelSelection: true,
27
+ modelDiscovery: false,
28
+ usage: "tokens-and-cost",
29
+ reportsUsage: true,
30
+ reportsCost: true,
31
+ sessionResume: false,
32
+ authProbe: "none",
33
+ bareModelAliases: true,
34
+ promptChannel: "both",
35
+ nativeTimeout: false,
36
+ contextFileName: "CLAUDE.md",
37
+ contextFileMaxBytes: null,
38
+ toolNameCase: "CamelCase",
39
+ readOnlyMode: "native"
40
+ };
41
+ var CODEX_CAPABILITIES = {
42
+ extraDirectories: "flag",
43
+ addDirs: true,
44
+ toolAllowlist: false,
45
+ maxTurns: false,
46
+ osSandbox: true,
47
+ modelSelection: true,
48
+ modelDiscovery: false,
49
+ usage: "tokens-only",
50
+ reportsUsage: true,
51
+ reportsCost: false,
52
+ sessionResume: true,
53
+ authProbe: "exit-code",
54
+ bareModelAliases: false,
55
+ promptChannel: "both",
56
+ nativeTimeout: false,
57
+ contextFileName: "AGENTS.md",
58
+ contextFileMaxBytes: 32 * 1024,
59
+ toolNameCase: "none",
60
+ readOnlyMode: "sandbox"
61
+ };
62
+ var CURSOR_CAPABILITIES = {
63
+ extraDirectories: "permission-file",
64
+ addDirs: false,
65
+ toolAllowlist: false,
66
+ maxTurns: false,
67
+ osSandbox: true,
68
+ modelSelection: true,
69
+ modelDiscovery: true,
70
+ usage: "none",
71
+ reportsUsage: false,
72
+ reportsCost: false,
73
+ sessionResume: true,
74
+ authProbe: "text",
75
+ bareModelAliases: false,
76
+ promptChannel: "argv",
77
+ nativeTimeout: false,
78
+ contextFileName: "AGENTS.md",
79
+ contextFileMaxBytes: null,
80
+ toolNameCase: "lowercase",
81
+ readOnlyMode: "native"
82
+ };
83
+ var ANTIGRAVITY_CAPABILITIES = {
84
+ extraDirectories: "flag",
85
+ addDirs: true,
86
+ toolAllowlist: false,
87
+ maxTurns: false,
88
+ osSandbox: true,
89
+ modelSelection: true,
90
+ modelDiscovery: true,
91
+ usage: "tokens-only",
92
+ reportsUsage: true,
93
+ reportsCost: false,
94
+ sessionResume: true,
95
+ authProbe: "none",
96
+ bareModelAliases: false,
97
+ promptChannel: "argv",
98
+ nativeTimeout: true,
99
+ contextFileName: "AGENTS.md",
100
+ contextFileMaxBytes: null,
101
+ toolNameCase: "CamelCase",
102
+ readOnlyMode: "native"
103
+ };
104
+ var AGENT_SCHEMA_VERSION = 1;
105
+
106
+ // src/policy/schemas.ts
107
+ import { z } from "zod";
108
+ var policyDiscoveryConfigSchema = z.object({
109
+ issueTemplates: z.boolean().default(true),
110
+ pullRequestTemplate: z.boolean().default(true),
111
+ docs: z.boolean().default(true),
112
+ codeowners: z.boolean().default(true),
113
+ labels: z.boolean().default(true),
114
+ issueTypes: z.boolean().default(true)
115
+ });
116
+ var policyIssuesDeclarationSchema = z.object({
117
+ titleConvention: z.string().min(1).optional(),
118
+ /**
119
+ * Whether Issue Flow may create a label the repository does not have.
120
+ *
121
+ * `.optional()` rather than `.default(false)`: the resolved declarations must
122
+ * stay "only what was written", or the group would always look declared and
123
+ * `sources` would report a provenance nobody asked for. The effective default
124
+ * — false — lives at the call site.
125
+ *
126
+ * That default is a deliberate change of behaviour: creating taxonomy without
127
+ * asking is the defect this exists to stop. A repository that wants the old
128
+ * behaviour opts back into it.
129
+ */
130
+ allowLabelCreation: z.boolean().optional()
131
+ });
132
+ var policyPullRequestsDeclarationSchema = z.object({
133
+ baseBranch: z.string().min(1).optional(),
134
+ titleConvention: z.string().min(1).optional()
135
+ });
136
+ var policyGitDeclarationSchema = z.object({
137
+ branchConvention: z.string().min(1).optional(),
138
+ commitConvention: z.string().min(1).optional(),
139
+ pullRequestTitleConvention: z.string().min(1).optional(),
140
+ issueReference: z.enum(["closes", "refs"]).optional(),
141
+ typeMap: z.record(z.string(), z.string().min(1)).optional()
142
+ });
143
+ var policyConfigSchema = z.object({
144
+ enabled: z.boolean().default(true),
145
+ /**
146
+ * Token budget for the `__REPO_POLICY__` projection. Sections above it are
147
+ * replaced whole by a pointer rather than truncated — see
148
+ * `policy/placeholders.ts`.
149
+ */
150
+ contextBudget: z.number().int().positive().default(1500),
151
+ discovery: policyDiscoveryConfigSchema.prefault({}),
152
+ issues: policyIssuesDeclarationSchema.prefault({}),
153
+ pullRequests: policyPullRequestsDeclarationSchema.prefault({}),
154
+ git: policyGitDeclarationSchema.prefault({})
155
+ });
156
+ var policyConfigInputSchema = z.object({
157
+ enabled: z.boolean().optional(),
158
+ contextBudget: z.number().int().positive().optional(),
159
+ // Spelled out rather than `policyDiscoveryConfigSchema.partial()`: in zod 4
160
+ // a `.default()` survives `.partial()`, so every toggle would come back
161
+ // materialized and the input layer would stop meaning "what the user wrote".
162
+ discovery: z.object({
163
+ issueTemplates: z.boolean().optional(),
164
+ pullRequestTemplate: z.boolean().optional(),
165
+ docs: z.boolean().optional(),
166
+ codeowners: z.boolean().optional(),
167
+ labels: z.boolean().optional(),
168
+ issueTypes: z.boolean().optional()
169
+ }).optional(),
170
+ issues: z.object({ titleConvention: z.string().nullish(), allowLabelCreation: z.boolean().optional() }).optional(),
171
+ pullRequests: z.object({ baseBranch: z.string().nullish(), titleConvention: z.string().nullish() }).optional(),
172
+ git: z.object({
173
+ branchConvention: z.string().nullish(),
174
+ commitConvention: z.string().nullish(),
175
+ pullRequestTitleConvention: z.string().nullish(),
176
+ issueReference: z.enum(["closes", "refs"]).nullish(),
177
+ typeMap: z.record(z.string(), z.string().min(1)).nullish()
178
+ }).optional()
179
+ });
180
+
181
+ // src/schemas.ts
182
+ import { z as z2 } from "zod";
183
+ var claudeUsageSchema = z2.object({
184
+ inputTokens: z2.number().optional(),
185
+ outputTokens: z2.number().optional(),
186
+ cacheReadTokens: z2.number().optional(),
187
+ cacheCreationTokens: z2.number().optional(),
188
+ costUsd: z2.number().optional()
189
+ });
190
+ var userStoryStatusSchema = z2.enum(["backlog", "in_progress", "in_review", "done"]);
191
+ var storyStageSchema = z2.enum([
192
+ "pending",
193
+ "executing",
194
+ "awaiting_review",
195
+ "in_review",
196
+ "in_correction",
197
+ "done",
198
+ "failed"
199
+ ]);
200
+ var userStorySchema = z2.object({
201
+ id: z2.string(),
202
+ title: z2.string(),
203
+ description: z2.string(),
204
+ acceptanceCriteria: z2.array(z2.string()),
205
+ priority: z2.number().int().positive(),
206
+ passes: z2.boolean(),
207
+ notes: z2.string(),
208
+ ...claudeUsageSchema.shape,
209
+ durationSeconds: z2.number().optional(),
210
+ status: userStoryStatusSchema.optional(),
211
+ dependencies: z2.array(z2.string()).optional(),
212
+ stage: storyStageSchema.optional(),
213
+ stageSince: z2.string().optional(),
214
+ stageDetail: z2.string().optional()
215
+ });
216
+ var pipelineStateSchema = z2.object({
217
+ analyzeCompleted: z2.boolean().optional(),
218
+ prdCompleted: z2.boolean(),
219
+ jsonCompleted: z2.boolean(),
220
+ executionCompleted: z2.boolean(),
221
+ reviewCompleted: z2.boolean(),
222
+ prCreated: z2.boolean(),
223
+ prReviewCompleted: z2.boolean().optional()
224
+ });
225
+ var pullRequestRefSchema = z2.object({
226
+ number: z2.number().int().positive(),
227
+ url: z2.string(),
228
+ headBranch: z2.string(),
229
+ createdAt: z2.string()
230
+ });
231
+ var prReviewRecommendationSchema = z2.enum([
232
+ "APPROVE",
233
+ "APPROVE_WITH_SUGGESTIONS",
234
+ "REQUEST_CHANGES"
235
+ ]);
236
+ var prReviewStateSchema = z2.object({
237
+ enabled: z2.boolean().default(false),
238
+ pullRequestNumber: z2.number().int().positive().optional(),
239
+ rounds: z2.number().int().min(0).default(0),
240
+ lastRecommendation: prReviewRecommendationSchema.optional(),
241
+ lastReviewedAt: z2.string().optional()
242
+ });
243
+ var lastErrorSchema = z2.object({
244
+ category: z2.string(),
245
+ message: z2.string(),
246
+ at: z2.string()
247
+ });
248
+ var issueMetadataSchema = z2.object({
249
+ schemaVersion: z2.literal(1),
250
+ id: z2.string().min(1),
251
+ number: z2.number().int().positive().nullable(),
252
+ source: z2.enum(["github", "local"]),
253
+ title: z2.string(),
254
+ labels: z2.array(z2.string()),
255
+ state: z2.enum(["open", "closed"]),
256
+ createdAt: z2.string(),
257
+ updatedAt: z2.string(),
258
+ contentHash: z2.string(),
259
+ remote: z2.object({
260
+ provider: z2.enum(["github", "local"]),
261
+ ref: z2.string(),
262
+ syncedAt: z2.string(),
263
+ syncedContentHash: z2.string()
264
+ }).optional()
265
+ });
266
+ var runOwnerSchema = z2.object({
267
+ pid: z2.number().int().positive(),
268
+ host: z2.string(),
269
+ startedAt: z2.string()
270
+ });
271
+ var issueRunStateSchema = z2.object({
272
+ status: z2.enum(["idle", "running", "waiting", "retrying", "paused", "blocked", "failed"]).default("idle"),
273
+ currentPhase: z2.string().nullable().default(null),
274
+ attempt: z2.number().int().min(0).default(0),
275
+ lastHeartbeatAt: z2.string().nullable().default(null),
276
+ blockedReason: z2.string().nullable().default(null),
277
+ owner: runOwnerSchema.nullable().default(null)
278
+ });
279
+ var failureKindSchema = z2.enum([
280
+ "network",
281
+ "timeout",
282
+ "stalled",
283
+ "rate_limit",
284
+ "provider_down",
285
+ "provider_crash",
286
+ "authentication",
287
+ "configuration",
288
+ "repository_state",
289
+ "task_execution",
290
+ "internal",
291
+ "unknown"
292
+ ]);
293
+ var normalizedUsageSchema = z2.object({
294
+ inputTokens: z2.number().optional(),
295
+ outputTokens: z2.number().optional(),
296
+ cacheReadTokens: z2.number().optional(),
297
+ cacheCreationTokens: z2.number().optional(),
298
+ reasoningTokens: z2.number().optional(),
299
+ details: z2.record(z2.string(), z2.number()).optional(),
300
+ source: z2.enum(["provider", "unavailable"])
301
+ });
302
+ var pricingSnapshotSchema = z2.object({
303
+ tableVersion: z2.string(),
304
+ modelKey: z2.string(),
305
+ inputPerMillion: z2.number(),
306
+ outputPerMillion: z2.number(),
307
+ cacheReadPerMillion: z2.number().optional(),
308
+ cacheWritePerMillion: z2.number().optional(),
309
+ capturedAt: z2.string()
310
+ });
311
+ var costRecordSchema = z2.discriminatedUnion("status", [
312
+ z2.object({ status: z2.literal("reported"), amount: z2.number(), currency: z2.literal("USD") }),
313
+ z2.object({
314
+ status: z2.literal("estimated"),
315
+ amount: z2.number(),
316
+ currency: z2.literal("USD"),
317
+ pricing: pricingSnapshotSchema
318
+ }),
319
+ z2.object({
320
+ status: z2.literal("unknown"),
321
+ reason: z2.enum(["not_reported", "no_pricing", "unknown_model", "subscription", "zero_rated"])
322
+ })
323
+ ]);
324
+ var executionRecordSchema = z2.object({
325
+ id: z2.string(),
326
+ sessionId: z2.string().nullable(),
327
+ purpose: z2.enum([
328
+ "analyze",
329
+ "generate",
330
+ "prd",
331
+ "plan",
332
+ "execute",
333
+ "review",
334
+ "pr",
335
+ "pr-review",
336
+ "verify"
337
+ ]),
338
+ attempt: z2.number().int().positive(),
339
+ trigger: z2.enum(["initial", "retry", "fallback", "correction", "escalation"]),
340
+ triggerReason: failureKindSchema.nullable(),
341
+ agent: z2.object({
342
+ harness: z2.string(),
343
+ provider: z2.string().nullable(),
344
+ harnessVersion: z2.string().nullable().optional(),
345
+ model: z2.object({
346
+ requested: z2.string().nullable(),
347
+ resolved: z2.string().nullable(),
348
+ source: z2.enum(["provider", "config", "unavailable"])
349
+ }),
350
+ providerSessionId: z2.string().nullable()
351
+ }),
352
+ startedAt: z2.string(),
353
+ finishedAt: z2.string().nullable(),
354
+ durationMs: z2.number().nullable(),
355
+ cliDurationMs: z2.number().nullable().optional(),
356
+ harnessStartupMs: z2.number().nullable().optional(),
357
+ apiDurationMs: z2.number().nullable().optional(),
358
+ ttftMs: z2.number().nullable().optional(),
359
+ numTurns: z2.number().nullable().optional(),
360
+ usage: normalizedUsageSchema.nullable(),
361
+ cost: costRecordSchema,
362
+ status: z2.enum(["running", "completed", "failed", "timeout", "cancelled", "interrupted"]),
363
+ failure: z2.object({
364
+ kind: failureKindSchema,
365
+ message: z2.string(),
366
+ exitCode: z2.number().nullable()
367
+ }).nullable(),
368
+ stopReason: z2.enum([
369
+ "completed",
370
+ "failed",
371
+ "timeout",
372
+ "cancelled",
373
+ "max_attempts",
374
+ "max_cost",
375
+ "max_duration"
376
+ ]).nullable().optional(),
377
+ iteration: z2.number().int().optional(),
378
+ storyIds: z2.array(z2.string()).optional(),
379
+ owner: z2.object({ pid: z2.number().int(), host: z2.string() }).nullable().optional(),
380
+ routingDecision: z2.object({
381
+ selected: z2.string(),
382
+ actual: z2.string().optional(),
383
+ candidates: z2.array(z2.unknown()).optional(),
384
+ reasonCodes: z2.array(z2.string()).optional()
385
+ }).passthrough().nullable().optional(),
386
+ verdict: z2.object({
387
+ status: z2.enum(["passed", "failed", "unverified"]),
388
+ level: z2.string().nullable().optional(),
389
+ independence: z2.string().nullable().optional()
390
+ }).nullable().optional()
391
+ });
392
+ var taskPlanSchema = z2.object({
393
+ project: z2.string(),
394
+ issueNumber: z2.union([z2.number().int().positive(), z2.string().min(1)]),
395
+ issueUrl: z2.string().optional().default(""),
396
+ branchName: z2.string(),
397
+ noBranch: z2.boolean().optional().default(false),
398
+ description: z2.string(),
399
+ issueStatus: z2.enum(["pending", "in_progress", "completed"]),
400
+ completedAt: z2.string().nullable(),
401
+ lastAttemptAt: z2.string().nullable(),
402
+ lastError: lastErrorSchema.nullable(),
403
+ correctionCycle: z2.number().int().min(0),
404
+ maxCorrectionCycles: z2.number().int().min(0),
405
+ /**
406
+ * Findings from the most recent failed review, verbatim. Non-null means the
407
+ * issue has a pending correction even if every userStories[].passes is
408
+ * already true — the execute phase must address these before the field is
409
+ * cleared back to null. See core/engine.ts's early-return guards.
410
+ */
411
+ lastReviewFindings: z2.string().nullable().optional().default(null),
412
+ pipeline: pipelineStateSchema,
413
+ /**
414
+ * Where the run stands right now. Purely additive: absent in every plan
415
+ * written before it, and absent is not the same as `idle` — it means the
416
+ * plan predates the field, which is why there is no `.default()` here.
417
+ */
418
+ runState: issueRunStateSchema.optional(),
419
+ pullRequest: pullRequestRefSchema.optional(),
420
+ prReview: prReviewStateSchema.optional(),
421
+ userStories: z2.array(userStorySchema),
422
+ /**
423
+ * Per-invocation history. `.optional()` and no `.default([])`: a plan that
424
+ * predates the field must not grow an empty array just because it was saved.
425
+ */
426
+ executions: z2.array(executionRecordSchema).optional()
427
+ });
428
+ var headlessResultSchema = z2.object({
429
+ success: z2.boolean(),
430
+ result: z2.string(),
431
+ cost: claudeUsageSchema.nullable(),
432
+ error: z2.string().nullable()
433
+ });
434
+ var sessionLogEntrySchema = z2.object({
435
+ at: z2.string(),
436
+ level: z2.enum(["info", "warn", "error"]),
437
+ message: z2.string()
438
+ });
439
+ var sessionUsageShape = {
440
+ inputTokens: z2.number().nullable().default(null),
441
+ outputTokens: z2.number().nullable().default(null),
442
+ cacheReadTokens: z2.number().nullable().default(null),
443
+ cacheCreationTokens: z2.number().nullable().default(null),
444
+ costUsd: z2.number().nullable().default(null)
445
+ };
446
+ var sessionPhaseSchema = z2.object({
447
+ name: z2.string(),
448
+ status: z2.enum(["pending", "running", "completed", "failed"]),
449
+ startedAt: z2.string().nullable(),
450
+ endedAt: z2.string().nullable(),
451
+ durationSeconds: z2.number().nullable(),
452
+ error: z2.string().nullable(),
453
+ harnessExecutionMs: z2.number().nullable().default(null),
454
+ orchestrationOverheadMs: z2.number().nullable().default(null),
455
+ harnessStartupMs: z2.number().nullable().default(null),
456
+ ttftMs: z2.number().nullable().default(null),
457
+ attemptCount: z2.number().nullable().default(null),
458
+ retryDurationMs: z2.number().nullable().default(null),
459
+ ...sessionUsageShape
460
+ });
461
+ var sessionStorySchema = z2.object({
462
+ id: z2.string(),
463
+ title: z2.string(),
464
+ priority: z2.number(),
465
+ passes: z2.boolean(),
466
+ completedAt: z2.string().nullable(),
467
+ // Also introduced with the metrics, hence the same tolerant default.
468
+ durationSeconds: z2.number().nullable().default(null),
469
+ // Snapshot fields are always present on output and defaulted on input, so a
470
+ // session.json written before they existed still parses. This is the mirror
471
+ // image of userStorySchema, where the same two fields are plainly optional.
472
+ status: userStoryStatusSchema.default("backlog"),
473
+ dependencies: z2.array(z2.string()).default([]),
474
+ // Published for the panel's story detail view. Same tolerant default as the
475
+ // fields above: absent (older session.json) and empty resolve to the same
476
+ // value, so the client never has to tell them apart.
477
+ description: z2.string().default(""),
478
+ acceptanceCriteria: z2.array(z2.string()).default([]),
479
+ // Additive like the rest of this schema: a session.json written before
480
+ // `stage` existed parses into 'pending'/null, the same values a fresh
481
+ // snapshot starts a story at.
482
+ stage: storyStageSchema.default("pending"),
483
+ stageSince: z2.string().nullable().default(null),
484
+ stageDetail: z2.string().nullable().default(null),
485
+ ...sessionUsageShape
486
+ });
487
+ var sessionSnapshotSchema = z2.object({
488
+ schemaVersion: z2.literal(1),
489
+ sessionId: z2.string().nullable(),
490
+ readOnly: z2.literal(true),
491
+ capabilities: z2.array(z2.string()),
492
+ issue: z2.object({
493
+ number: z2.number().nullable(),
494
+ url: z2.string().nullable(),
495
+ // Additive: a session.json written before the Issue section was enriched
496
+ // parses into the same "not reported" values createInitialSnapshot() uses.
497
+ title: z2.string().nullable().default(null),
498
+ description: z2.string().nullable().default(null),
499
+ labels: z2.array(z2.string()).default([]),
500
+ state: z2.string().nullable().default(null)
501
+ }),
502
+ status: z2.enum(["idle", "running", "completed", "failed"]),
503
+ startedAt: z2.string().nullable(),
504
+ updatedAt: z2.string().nullable(),
505
+ endedAt: z2.string().nullable(),
506
+ elapsedSeconds: z2.number().nullable(),
507
+ estimatedRemainingSeconds: z2.number().nullable(),
508
+ progress: z2.object({
509
+ percent: z2.number(),
510
+ phasesCompleted: z2.number(),
511
+ phasesTotal: z2.number(),
512
+ storiesCompleted: z2.number(),
513
+ storiesTotal: z2.number()
514
+ }),
515
+ currentPhase: z2.string().nullable(),
516
+ currentActivity: z2.object({
517
+ story: z2.string().nullable(),
518
+ tool: z2.string().nullable(),
519
+ detail: z2.string().nullable(),
520
+ since: z2.string()
521
+ }).nullable(),
522
+ phases: z2.array(sessionPhaseSchema),
523
+ stories: z2.array(sessionStorySchema),
524
+ // The whole aggregate is additive: a snapshot from before it existed parses
525
+ // into the same "nothing reported" object the reducer starts from.
526
+ metrics: z2.object({
527
+ totalInputTokens: z2.number().nullable().default(null),
528
+ totalOutputTokens: z2.number().nullable().default(null),
529
+ totalCacheReadTokens: z2.number().nullable().default(null),
530
+ totalCacheCreationTokens: z2.number().nullable().default(null),
531
+ totalCostUsd: z2.number().nullable().default(null)
532
+ }).default({
533
+ totalInputTokens: null,
534
+ totalOutputTokens: null,
535
+ totalCacheReadTokens: null,
536
+ totalCacheCreationTokens: null,
537
+ totalCostUsd: null
538
+ }),
539
+ execution: z2.object({
540
+ iteration: z2.number(),
541
+ retries: z2.number(),
542
+ correctionCycle: z2.number(),
543
+ maxCorrectionCycles: z2.number().nullable()
544
+ }),
545
+ // Additive resilience projection. Every field defaults so session.json from
546
+ // before provider failover/observability remains readable without a schema
547
+ // version bump.
548
+ resilience: z2.object({
549
+ attempt: z2.number().int().nonnegative().default(0),
550
+ provider: z2.string().nullable().default(null),
551
+ model: z2.string().nullable().default(null),
552
+ lastFailureKind: z2.enum([
553
+ "network",
554
+ "timeout",
555
+ "stalled",
556
+ "rate_limit",
557
+ "provider_down",
558
+ "provider_crash",
559
+ "authentication",
560
+ "configuration",
561
+ "repository_state",
562
+ "task_execution",
563
+ "internal",
564
+ "unknown"
565
+ ]).nullable().default(null),
566
+ cooldownUntil: z2.string().nullable().default(null),
567
+ lastActivityAt: z2.string().nullable().default(null)
568
+ }).default({
569
+ attempt: 0,
570
+ provider: null,
571
+ model: null,
572
+ lastFailureKind: null,
573
+ cooldownUntil: null,
574
+ lastActivityAt: null
575
+ }),
576
+ git: z2.object({
577
+ branch: z2.string().nullable(),
578
+ baseBranch: z2.string().nullable(),
579
+ commits: z2.array(z2.object({ hash: z2.string(), subject: z2.string() }))
580
+ }),
581
+ // Additive like the metrics aggregate: a session.json written before the
582
+ // repository section existed parses into the same all-null object
583
+ // createInitialSnapshot() starts from.
584
+ repository: z2.object({
585
+ name: z2.string().nullable().default(null),
586
+ remoteUrl: z2.string().nullable().default(null),
587
+ branch: z2.string().nullable().default(null),
588
+ headCommit: z2.string().nullable().default(null),
589
+ root: z2.string().nullable().default(null)
590
+ }).default({ name: null, remoteUrl: null, branch: null, headCommit: null, root: null }),
591
+ pullRequests: z2.array(z2.object({ number: z2.number(), url: z2.string(), title: z2.string() })),
592
+ logs: z2.array(sessionLogEntrySchema),
593
+ errors: z2.array(sessionLogEntrySchema),
594
+ warnings: z2.array(sessionLogEntrySchema),
595
+ lastError: z2.object({ message: z2.string(), at: z2.string() }).nullable(),
596
+ nextSteps: z2.array(z2.string()),
597
+ environment: z2.object({
598
+ node: z2.string(),
599
+ platform: z2.string(),
600
+ agent: z2.string().nullable().default(null),
601
+ model: z2.string().nullable().default(null)
602
+ }).nullable(),
603
+ // Additive: a session.json written before the acceptance contract existed
604
+ // parses as "not reported". schemaVersion stays 1.
605
+ verification: z2.object({
606
+ verdict: z2.enum(["passed", "failed", "unverified"]).nullable(),
607
+ level: z2.string().nullable(),
608
+ independence: z2.string().nullable()
609
+ }).nullable().default(null)
610
+ });
611
+ var webConfigSchema = z2.object({
612
+ enabled: z2.boolean().default(false),
613
+ port: z2.number().int().min(1).max(65535).default(3737),
614
+ host: z2.string().min(1).default("0.0.0.0"),
615
+ refreshSeconds: z2.number().positive().default(5),
616
+ logLimit: z2.number().int().positive().default(200),
617
+ includeLogs: z2.boolean().default(true)
618
+ });
619
+ var issuesConfigSchema = z2.object({
620
+ defaultGenerateTarget: z2.enum(["github", "local", "both"]).default("github"),
621
+ preferredProvider: z2.enum(["github", "local"]).default("github"),
622
+ conflictPolicy: z2.enum(["ask", "prefer-local", "prefer-github"]).default("ask"),
623
+ requireConfirmation: z2.boolean().default(true)
624
+ });
625
+ var prReviewConfigSchema = z2.object({
626
+ publisher: z2.enum(["local", "github"]).default("local")
627
+ });
628
+ var verifyCheckSchema = z2.object({
629
+ id: z2.string().min(1),
630
+ run: z2.string().optional(),
631
+ expectFiles: z2.array(z2.string()).optional(),
632
+ fatal: z2.boolean().optional()
633
+ });
634
+ var verifyConfigSchema = z2.object({
635
+ level: z2.enum(["L0", "L1", "L2", "L3", "L5"]).default("L1"),
636
+ triggers: z2.array(z2.string()).default([]),
637
+ pairings: z2.record(z2.string(), z2.string()).default({}),
638
+ contract: z2.array(verifyCheckSchema).optional(),
639
+ crossVerify: z2.boolean().default(true)
640
+ });
641
+ var routingConfigSchema = z2.object({
642
+ mode: z2.enum(["off", "shadow", "recommend", "active"]).default("shadow"),
643
+ profile: z2.enum(["economy", "balanced", "quality", "speed"]).default("balanced"),
644
+ escalation: z2.object({
645
+ enabled: z2.boolean().default(false),
646
+ minAttemptsBeforeEscalation: z2.number().int().positive().default(2),
647
+ maxEscalations: z2.number().int().nonnegative().default(2),
648
+ maxRungs: z2.array(z2.enum(["effort", "model", "harness", "review", "decompose"])).default(["effort", "model", "harness"])
649
+ }).default({
650
+ enabled: false,
651
+ minAttemptsBeforeEscalation: 2,
652
+ maxEscalations: 2,
653
+ maxRungs: ["effort", "model", "harness"]
654
+ }),
655
+ ceilings: z2.object({
656
+ maxCostUsdPerIssue: z2.number().nonnegative().nullable().default(null),
657
+ maxDurationMsPerIssue: z2.number().nonnegative().nullable().default(null),
658
+ maxExecutionsPerIssue: z2.number().int().nonnegative().nullable().default(null),
659
+ onCeiling: z2.literal("block").default("block")
660
+ }).default({
661
+ maxCostUsdPerIssue: null,
662
+ maxDurationMsPerIssue: null,
663
+ maxExecutionsPerIssue: null,
664
+ onCeiling: "block"
665
+ })
666
+ });
667
+
668
+ // src/agents/schemas.ts
669
+ import { z as z3 } from "zod";
670
+ var agentProviderIdSchema = z3.enum(["claude", "codex", "cursor", "antigravity"]);
671
+ var codexSandboxSchema = z3.enum(["read-only", "workspace-write", "danger-full-access"]);
672
+ var codexReasoningEffortSchema = z3.enum(["minimal", "low", "medium", "high", "xhigh"]);
673
+ var claudeSettingsSchema = z3.object({
674
+ ignoreUserConfig: z3.boolean(),
675
+ strictMcpConfig: z3.boolean()
676
+ }).partial();
677
+ var codexSettingsSchema = z3.object({
678
+ reasoningEffort: codexReasoningEffortSchema,
679
+ sandbox: codexSandboxSchema,
680
+ ignoreUserConfig: z3.boolean(),
681
+ skipGitRepoCheck: z3.boolean(),
682
+ configOverrides: z3.record(z3.string(), z3.union([z3.string(), z3.number(), z3.boolean()]))
683
+ }).partial();
684
+ var cursorSandboxSchema = z3.enum(["enabled", "disabled"]);
685
+ var cursorPermissionsFileSchema = z3.enum(["global", "project", "none"]);
686
+ var cursorSettingsSchema = z3.object({
687
+ sandbox: cursorSandboxSchema,
688
+ approveMcps: z3.boolean(),
689
+ permissionsFile: cursorPermissionsFileSchema,
690
+ minVersion: z3.string().min(1),
691
+ force: z3.boolean().refine((value) => value !== false, {
692
+ message: "agent.cursor.force cannot be false: without --force, Cursor finishes with exit 0 and writes nothing."
693
+ })
694
+ }).partial();
695
+ var antigravityEffortSchema = z3.enum(["low", "medium", "high"]);
696
+ var antigravitySettingsSchema = z3.object({
697
+ effort: antigravityEffortSchema,
698
+ sandbox: z3.boolean(),
699
+ executeTimeout: z3.union([z3.number().int(), z3.string().min(1), z3.null()]),
700
+ maxPromptBytes: z3.number().int().positive(),
701
+ minVersion: z3.string().min(1),
702
+ skipPermissions: z3.boolean().refine((value) => value !== false, {
703
+ message: "agent.antigravity.skipPermissions cannot be false: without --dangerously-skip-permissions, Antigravity finishes SUCCESS and writes nothing."
704
+ })
705
+ }).partial();
706
+ var agentBlockSchema = z3.object({
707
+ provider: agentProviderIdSchema,
708
+ model: z3.string().min(1).nullable(),
709
+ claude: claudeSettingsSchema,
710
+ codex: codexSettingsSchema,
711
+ cursor: cursorSettingsSchema,
712
+ antigravity: antigravitySettingsSchema
713
+ }).partial();
714
+ var agentPhasesSchema = z3.object({
715
+ analyze: agentBlockSchema,
716
+ generate: agentBlockSchema,
717
+ prd: agentBlockSchema,
718
+ plan: agentBlockSchema,
719
+ execute: agentBlockSchema,
720
+ review: agentBlockSchema,
721
+ pr: agentBlockSchema,
722
+ "pr-review": agentBlockSchema
723
+ }).partial();
724
+ var agentConfigInputSchema = z3.object({
725
+ provider: agentProviderIdSchema,
726
+ model: z3.string().min(1).nullable(),
727
+ claude: claudeSettingsSchema,
728
+ codex: codexSettingsSchema,
729
+ cursor: cursorSettingsSchema,
730
+ antigravity: antigravitySettingsSchema,
731
+ phases: agentPhasesSchema
732
+ }).partial();
733
+ function parsePhasesInput(value, warn) {
734
+ if (value === void 0 || value === null) return {};
735
+ if (typeof value !== "object" || Array.isArray(value)) {
736
+ warn('Ignoring "agent.phases": expected an object.');
737
+ return {};
738
+ }
739
+ const result = {};
740
+ for (const [key, raw] of Object.entries(value)) {
741
+ if (!AGENT_PHASES.includes(key)) {
742
+ warn(`Ignoring unknown agent phase "${key}".`);
743
+ continue;
744
+ }
745
+ const parsed = agentBlockSchema.safeParse(raw);
746
+ if (!parsed.success) {
747
+ warn(`Ignoring agent.phases.${key}: ${parsed.error.issues[0]?.message ?? "invalid value"}.`);
748
+ continue;
749
+ }
750
+ result[key] = parsed.data;
751
+ }
752
+ return result;
753
+ }
754
+
755
+ // src/storage/schemas.ts
756
+ import { z as z4 } from "zod";
757
+ var STORAGE_SCHEMA_VERSION = 1;
758
+ var userStoryNumberingSourceSchema = z4.enum(["history", "start-us", "none"]);
759
+ var userStoryNumberingDecisionSchema = z4.object({
760
+ /** The `US-NNN` number the `plan` prompt was told to continue from. */
761
+ nextNumber: z4.number().int().positive(),
762
+ source: userStoryNumberingSourceSchema,
763
+ /** Issue the decision was made for. */
764
+ issueNumber: z4.string().min(1),
765
+ decidedAt: z4.string().min(1),
766
+ /** Human-readable origin, e.g. the previous story id and issue it came from. */
767
+ detail: z4.string().optional()
768
+ });
769
+ var projectMetadataSchema = z4.object({
770
+ schemaVersion: z4.number().int().positive(),
771
+ projectId: z4.string().min(1),
772
+ root: z4.string().min(1),
773
+ /** Normalized remote (`host/org/repo`), or null when the project has none. */
774
+ remoteUrl: z4.string().nullable(),
775
+ createdAt: z4.string().min(1),
776
+ updatedAt: z4.string().min(1),
777
+ /** Null until the project is used by a pipeline run. */
778
+ lastAttemptAt: z4.string().nullable(),
779
+ /**
780
+ * Most recent User Story numbering decision made by `plan` (issue #36).
781
+ * Absent on a project whose `plan` never ran through the numbering
782
+ * resolver, or on a `metadata.json` written before the feature existed.
783
+ */
784
+ userStoryNumbering: userStoryNumberingDecisionSchema.optional()
785
+ });
786
+ var webShape = webConfigSchema.shape;
787
+ var globalWebConfigSchema = z4.object({
788
+ port: webShape.port.unwrap(),
789
+ host: webShape.host.unwrap(),
790
+ refreshSeconds: webShape.refreshSeconds.unwrap(),
791
+ logLimit: webShape.logLimit.unwrap()
792
+ }).partial();
793
+ var globalRetryConfigSchema = z4.object({
794
+ retryLimit: z4.number().int().nonnegative(),
795
+ retryForever: z4.boolean(),
796
+ backoffBaseSeconds: z4.number().nonnegative(),
797
+ backoffMaxSeconds: z4.number().nonnegative()
798
+ }).partial();
799
+ var resilienceProfileSchema = z4.enum([
800
+ "default",
801
+ "continuous"
802
+ ]);
803
+ var jitterSchema = z4.enum(["none", "full"]);
804
+ var failoverModeSchema = z4.enum([
805
+ "never",
806
+ "after_attempts",
807
+ "immediate"
808
+ ]);
809
+ var exhaustedActionSchema = z4.enum(["fail", "block"]);
810
+ var retryPolicyOverrideSchema = z4.object({
811
+ maxAttempts: z4.number().int().nonnegative(),
812
+ initialDelayMs: z4.number().nonnegative(),
813
+ maxDelayMs: z4.number().nonnegative(),
814
+ backoffFactor: z4.number().min(1),
815
+ jitter: jitterSchema,
816
+ retryForever: z4.boolean(),
817
+ failover: failoverModeSchema,
818
+ failoverAfterAttempts: z4.number().int().positive(),
819
+ onExhausted: exhaustedActionSchema
820
+ }).partial();
821
+ var retryOverridesByKind = {
822
+ network: retryPolicyOverrideSchema,
823
+ timeout: retryPolicyOverrideSchema,
824
+ stalled: retryPolicyOverrideSchema,
825
+ rateLimit: retryPolicyOverrideSchema,
826
+ providerDown: retryPolicyOverrideSchema,
827
+ providerCrash: retryPolicyOverrideSchema,
828
+ authentication: retryPolicyOverrideSchema,
829
+ configuration: retryPolicyOverrideSchema,
830
+ repositoryState: retryPolicyOverrideSchema,
831
+ taskExecution: retryPolicyOverrideSchema,
832
+ internal: retryPolicyOverrideSchema,
833
+ unknown: retryPolicyOverrideSchema
834
+ };
835
+ var resilienceRetryConfigSchema = z4.object(retryOverridesByKind).partial();
836
+ var resilienceProvidersConfigSchema = z4.object({
837
+ failover: z4.boolean(),
838
+ chain: z4.array(z4.string().min(1)),
839
+ cooldownMs: z4.number().nonnegative(),
840
+ maxCooldownMs: z4.number().nonnegative(),
841
+ failureWindowMs: z4.number().positive(),
842
+ failuresToTrip: z4.number().int().positive()
843
+ }).partial();
844
+ var providerHealthStatusSchema = z4.enum([
845
+ "healthy",
846
+ "degraded",
847
+ "unavailable",
848
+ "rate_limited",
849
+ "auth_failed",
850
+ "half_open"
851
+ ]);
852
+ var providerHealthRecordSchema = z4.object({
853
+ status: providerHealthStatusSchema.default("healthy"),
854
+ failures: z4.array(
855
+ z4.object({
856
+ at: z4.string(),
857
+ kind: z4.enum([
858
+ "network",
859
+ "timeout",
860
+ "stalled",
861
+ "rate_limit",
862
+ "provider_down",
863
+ "provider_crash",
864
+ "authentication",
865
+ "configuration",
866
+ "repository_state",
867
+ "task_execution",
868
+ "internal",
869
+ "unknown"
870
+ ])
871
+ })
872
+ ).default([]),
873
+ consecutiveFailures: z4.number().int().nonnegative().default(0),
874
+ cooldownLevel: z4.number().int().nonnegative().default(0),
875
+ cooldownUntil: z4.string().nullable().default(null),
876
+ lastFailureKind: z4.enum([
877
+ "network",
878
+ "timeout",
879
+ "stalled",
880
+ "rate_limit",
881
+ "provider_down",
882
+ "provider_crash",
883
+ "authentication",
884
+ "configuration",
885
+ "repository_state",
886
+ "task_execution",
887
+ "internal",
888
+ "unknown"
889
+ ]).nullable().default(null),
890
+ lastFailureAt: z4.string().nullable().default(null),
891
+ lastSuccessAt: z4.string().nullable().default(null),
892
+ probeInFlight: z4.boolean().default(false),
893
+ probeStartedAt: z4.string().nullable().default(null)
894
+ });
895
+ var providersHealthSchema = z4.object({
896
+ schemaVersion: z4.literal(1).default(1),
897
+ providers: z4.record(z4.string(), providerHealthRecordSchema).default({})
898
+ });
899
+ var resilienceQueueConfigSchema = z4.object({
900
+ onIssueFailure: z4.enum(["stop", "skip", "block"]),
901
+ maxIssueAttempts: z4.number().int().positive()
902
+ }).partial();
903
+ var resilienceWatchdogConfigSchema = z4.object({
904
+ inactivityTimeoutMs: z4.number().int().nonnegative()
905
+ }).partial();
906
+ var resilienceJournalConfigSchema = z4.object({
907
+ enabled: z4.boolean(),
908
+ maxFileBytes: z4.number().int().positive()
909
+ }).partial();
910
+ var resilienceDecomposeConfigSchema = z4.object({
911
+ auto: z4.boolean()
912
+ }).partial();
913
+ var resilienceConfigSchema = z4.object({
914
+ profile: resilienceProfileSchema,
915
+ /** Whether a credential failure may migrate to another provider. */
916
+ failoverOnAuth: z4.boolean(),
917
+ retry: resilienceRetryConfigSchema,
918
+ providers: resilienceProvidersConfigSchema,
919
+ queue: resilienceQueueConfigSchema,
920
+ watchdog: resilienceWatchdogConfigSchema,
921
+ journal: resilienceJournalConfigSchema,
922
+ decompose: resilienceDecomposeConfigSchema
923
+ }).partial();
924
+ var telemetryPricingOverrideSchema = z4.object({
925
+ inputPerMillion: z4.number(),
926
+ outputPerMillion: z4.number(),
927
+ cacheReadPerMillion: z4.number(),
928
+ cacheWritePerMillion: z4.number()
929
+ }).partial();
930
+ var telemetryConfigInputSchema = z4.object({
931
+ enabled: z4.boolean(),
932
+ maxExecutions: z4.number().int().positive(),
933
+ pricing: z4.object({
934
+ estimate: z4.boolean(),
935
+ overrides: z4.record(z4.string(), telemetryPricingOverrideSchema)
936
+ }).partial()
937
+ }).partial();
938
+ var globalCommitConfigSchema = z4.object({
939
+ signoff: z4.boolean(),
940
+ conventional: z4.boolean()
941
+ }).partial();
942
+ var globalConfigSchema = z4.object({
943
+ schemaVersion: z4.number().int().positive(),
944
+ /** Override for the directory holding `projects/`. */
945
+ storageDir: z4.string().min(1),
946
+ web: globalWebConfigSchema,
947
+ retry: globalRetryConfigSchema,
948
+ commit: globalCommitConfigSchema,
949
+ resilience: resilienceConfigSchema,
950
+ agent: agentConfigInputSchema,
951
+ telemetry: telemetryConfigInputSchema
952
+ }).partial();
953
+ var webLockSchema = z4.object({
954
+ pid: z4.number().int().positive(),
955
+ port: z4.number().int().positive(),
956
+ host: z4.string().min(1),
957
+ startedAt: z4.string().min(1)
958
+ });
959
+ var runLockSchema = z4.object({
960
+ pid: z4.number().int().positive(),
961
+ /** `os.hostname()`. A pid only means something on the host that wrote it. */
962
+ host: z4.string().min(1),
963
+ /** The issue (or queue) identifier the owner is running. */
964
+ target: z4.string().min(1),
965
+ startedAt: z4.string().min(1),
966
+ lastHeartbeatAt: z4.string().min(1),
967
+ /** Absent on a foreground run written before this field existed. */
968
+ detached: z4.boolean().optional()
969
+ });
970
+ var executionPlanIssueSchema = z4.object({
971
+ id: z4.string().min(1),
972
+ number: z4.number().int().positive().nullable(),
973
+ title: z4.string(),
974
+ url: z4.string().nullable(),
975
+ source: z4.string().min(1),
976
+ position: z4.number().int().positive(),
977
+ // `blocked` and `skipped` are additive: no plan written before them can
978
+ // carry one, and a reader that does not know them was never given one.
979
+ status: z4.enum(["pending", "in_progress", "completed", "failed", "blocked", "skipped"]),
980
+ origin: z4.enum(["requested", "discovered"]),
981
+ role: z4.enum(["executable", "container"]).default("executable"),
982
+ externalDependencies: z4.array(z4.string()).default([]),
983
+ dependsOn: z4.array(z4.string()).default([]),
984
+ parent: z4.string().nullable().default(null),
985
+ priority: z4.enum(["high", "medium", "low"]).nullable().default(null),
986
+ heuristic: z4.boolean().default(false),
987
+ failedPhase: z4.string().nullable().default(null),
988
+ lastError: z4.object({ category: z4.string(), message: z4.string(), at: z4.string() }).nullable().default(null),
989
+ startedAt: z4.string().nullable().default(null),
990
+ completedAt: z4.string().nullable().default(null),
991
+ // Both default, so an execution-plan.json written by an earlier release
992
+ // parses unchanged and reads as "never attempted, not blocked".
993
+ attempts: z4.number().int().min(0).default(0),
994
+ blockedReason: z4.string().nullable().default(null)
995
+ });
996
+ var executionPlanSchema = z4.object({
997
+ schemaVersion: z4.literal(1),
998
+ id: z4.string().min(1),
999
+ project: z4.string().min(1),
1000
+ requested: z4.array(z4.string().min(1)),
1001
+ branchName: z4.string().nullable().default(null),
1002
+ noBranch: z4.boolean().default(false),
1003
+ prReview: z4.boolean().default(false),
1004
+ status: z4.enum(["pending", "in_progress", "completed", "failed"]),
1005
+ createdAt: z4.string().min(1),
1006
+ updatedAt: z4.string().min(1),
1007
+ truncated: z4.boolean().default(false),
1008
+ issues: z4.array(executionPlanIssueSchema),
1009
+ excluded: z4.array(
1010
+ z4.object({
1011
+ id: z4.string().min(1),
1012
+ number: z4.number().int().positive().nullable(),
1013
+ title: z4.string(),
1014
+ url: z4.string().nullable(),
1015
+ reason: z4.string()
1016
+ })
1017
+ ).default([]),
1018
+ pullRequest: pullRequestRefSchema.optional()
1019
+ });
1020
+
1021
+ // src/storage/lock.ts
1022
+ import { mkdir, readFile, rm, writeFile } from "fs/promises";
1023
+ import { hostname } from "os";
1024
+ import { dirname } from "path";
1025
+ var RUN_LOCK_HEARTBEAT_MS = 1e4;
1026
+ var RUN_LOCK_STALE_INTERVALS = 3;
1027
+ var CLAIM_RETRIES = 3;
1028
+ function isProcessAlive(pid) {
1029
+ try {
1030
+ process.kill(pid, 0);
1031
+ return true;
1032
+ } catch (err) {
1033
+ return err.code === "EPERM";
1034
+ }
1035
+ }
1036
+ async function readRunLock(lockFile) {
1037
+ let raw;
1038
+ try {
1039
+ raw = await readFile(lockFile, "utf-8");
1040
+ } catch {
1041
+ return null;
1042
+ }
1043
+ try {
1044
+ const result = runLockSchema.safeParse(JSON.parse(raw));
1045
+ return result.success ? result.data : null;
1046
+ } catch {
1047
+ return null;
1048
+ }
1049
+ }
1050
+ async function removeRunLock(lockFile) {
1051
+ try {
1052
+ await rm(lockFile, { force: true });
1053
+ } catch {
1054
+ }
1055
+ }
1056
+ function isRunLockStale(lock, options = {}) {
1057
+ const heartbeatMs = options.heartbeatMs ?? RUN_LOCK_HEARTBEAT_MS;
1058
+ const staleIntervals = options.staleIntervals ?? RUN_LOCK_STALE_INTERVALS;
1059
+ const now = (options.clock ?? Date.now)();
1060
+ const host = options.host ?? hostname();
1061
+ const beat = Date.parse(lock.lastHeartbeatAt);
1062
+ const silent = Number.isNaN(beat) || now - beat > heartbeatMs * staleIntervals;
1063
+ if (lock.host !== host) return silent;
1064
+ return silent || !isProcessAlive(lock.pid);
1065
+ }
1066
+ function isSelf(lock, pid, host) {
1067
+ return lock.pid === pid && lock.host === host;
1068
+ }
1069
+ function describeRunLockOwner(lock) {
1070
+ return `pid ${lock.pid} on ${lock.host} (issue ${lock.target}, started ${lock.startedAt}, last heartbeat ${lock.lastHeartbeatAt})`;
1071
+ }
1072
+ async function touchRunLock(lockFile, lock, at) {
1073
+ const next = { ...lock, lastHeartbeatAt: at };
1074
+ try {
1075
+ await writeFile(lockFile, `${JSON.stringify(next, null, 2)}
1076
+ `, "utf-8");
1077
+ } catch {
1078
+ }
1079
+ return next;
1080
+ }
1081
+ async function claim(lockFile, lock) {
1082
+ try {
1083
+ await mkdir(dirname(lockFile), { recursive: true });
1084
+ await writeFile(lockFile, `${JSON.stringify(lock, null, 2)}
1085
+ `, {
1086
+ encoding: "utf-8",
1087
+ flag: "wx"
1088
+ });
1089
+ return true;
1090
+ } catch (err) {
1091
+ if (err.code === "EEXIST") return false;
1092
+ throw err;
1093
+ }
1094
+ }
1095
+ async function acquireRunLock(lockFile, options) {
1096
+ const pid = options.pid ?? process.pid;
1097
+ const host = options.host ?? hostname();
1098
+ const heartbeatMs = options.heartbeatMs ?? RUN_LOCK_HEARTBEAT_MS;
1099
+ const clock = options.clock ?? Date.now;
1100
+ const staleness = {
1101
+ heartbeatMs,
1102
+ ...options.staleIntervals === void 0 ? {} : { staleIntervals: options.staleIntervals },
1103
+ clock,
1104
+ pid,
1105
+ host
1106
+ };
1107
+ let reclaimedFrom = null;
1108
+ for (let attempt = 0; attempt <= CLAIM_RETRIES; attempt++) {
1109
+ const at = new Date(clock()).toISOString();
1110
+ const mine = {
1111
+ pid,
1112
+ host,
1113
+ target: options.target,
1114
+ startedAt: at,
1115
+ lastHeartbeatAt: at,
1116
+ ...options.detached === true ? { detached: true } : {}
1117
+ };
1118
+ if (await claim(lockFile, mine)) {
1119
+ return { ok: true, handle: startHandle(lockFile, mine, reclaimedFrom, options) };
1120
+ }
1121
+ const existing = await readRunLock(lockFile);
1122
+ if (existing === null) {
1123
+ await removeRunLock(lockFile);
1124
+ continue;
1125
+ }
1126
+ if (isSelf(existing, pid, host)) {
1127
+ return { ok: true, handle: nestedHandle(existing) };
1128
+ }
1129
+ if (!isRunLockStale(existing, staleness)) {
1130
+ return { ok: false, owner: existing };
1131
+ }
1132
+ reclaimedFrom = existing;
1133
+ try {
1134
+ options.onTakeover?.(existing);
1135
+ } catch {
1136
+ }
1137
+ await removeRunLock(lockFile);
1138
+ }
1139
+ const owner = await readRunLock(lockFile);
1140
+ if (owner !== null) return { ok: false, owner };
1141
+ return {
1142
+ ok: false,
1143
+ owner: {
1144
+ pid: 0,
1145
+ host,
1146
+ target: options.target,
1147
+ startedAt: new Date(clock()).toISOString(),
1148
+ lastHeartbeatAt: new Date(clock()).toISOString()
1149
+ }
1150
+ };
1151
+ }
1152
+ function startHandle(lockFile, lock, reclaimedFrom, options) {
1153
+ const heartbeatMs = options.heartbeatMs ?? RUN_LOCK_HEARTBEAT_MS;
1154
+ const clock = options.clock ?? Date.now;
1155
+ let current = lock;
1156
+ let timer = null;
1157
+ if (options.heartbeat !== false) {
1158
+ timer = setInterval(() => {
1159
+ void touchRunLock(lockFile, current, new Date(clock()).toISOString()).then((next) => {
1160
+ current = next;
1161
+ });
1162
+ }, heartbeatMs);
1163
+ timer.unref();
1164
+ }
1165
+ return {
1166
+ lock,
1167
+ reclaimedFrom,
1168
+ release: async () => {
1169
+ if (timer !== null) {
1170
+ clearInterval(timer);
1171
+ timer = null;
1172
+ }
1173
+ await removeRunLock(lockFile);
1174
+ }
1175
+ };
1176
+ }
1177
+ function nestedHandle(lock) {
1178
+ return { lock, reclaimedFrom: null, release: async () => {
1179
+ } };
1180
+ }
1181
+
1182
+ export {
1183
+ AGENT_PHASES,
1184
+ isAgentPhase,
1185
+ isAgentProviderId,
1186
+ CLAUDE_CAPABILITIES,
1187
+ CODEX_CAPABILITIES,
1188
+ CURSOR_CAPABILITIES,
1189
+ ANTIGRAVITY_CAPABILITIES,
1190
+ AGENT_SCHEMA_VERSION,
1191
+ policyConfigSchema,
1192
+ policyConfigInputSchema,
1193
+ issueMetadataSchema,
1194
+ taskPlanSchema,
1195
+ sessionSnapshotSchema,
1196
+ webConfigSchema,
1197
+ issuesConfigSchema,
1198
+ prReviewConfigSchema,
1199
+ verifyConfigSchema,
1200
+ routingConfigSchema,
1201
+ agentConfigInputSchema,
1202
+ parsePhasesInput,
1203
+ STORAGE_SCHEMA_VERSION,
1204
+ projectMetadataSchema,
1205
+ providersHealthSchema,
1206
+ resilienceConfigSchema,
1207
+ telemetryConfigInputSchema,
1208
+ globalConfigSchema,
1209
+ webLockSchema,
1210
+ executionPlanSchema,
1211
+ isProcessAlive,
1212
+ readRunLock,
1213
+ isRunLockStale,
1214
+ describeRunLockOwner,
1215
+ acquireRunLock
1216
+ };
1217
+ //# sourceMappingURL=chunk-NEZZ6KDR.js.map