issue-flow 0.11.0 → 0.12.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 (118) hide show
  1. package/README.md +1 -1
  2. package/dist/{analyze-7B5TORNK.js → analyze-OEET7KGE.js} +17 -11
  3. package/dist/analyze-OEET7KGE.js.map +1 -0
  4. package/dist/{apply-WUJHDD7A.js → apply-ZIA3C52S.js} +6 -4
  5. package/dist/{apply-WUJHDD7A.js.map → apply-ZIA3C52S.js.map} +1 -1
  6. package/dist/{chunk-6N7LZZ5U.js → chunk-3QHK4YQA.js} +204 -107
  7. package/dist/chunk-3QHK4YQA.js.map +1 -0
  8. package/dist/chunk-42PJFMAR.js +605 -0
  9. package/dist/chunk-42PJFMAR.js.map +1 -0
  10. package/dist/{chunk-PL6CNMVS.js → chunk-4JSOYE4G.js} +105 -19
  11. package/dist/chunk-4JSOYE4G.js.map +1 -0
  12. package/dist/chunk-56KS3TFQ.js +703 -0
  13. package/dist/chunk-56KS3TFQ.js.map +1 -0
  14. package/dist/{chunk-AAY6KM7N.js → chunk-73ATPIYX.js} +160 -154
  15. package/dist/chunk-73ATPIYX.js.map +1 -0
  16. package/dist/{chunk-MKD2D7WE.js → chunk-A4SLHOW7.js} +70 -13
  17. package/dist/chunk-A4SLHOW7.js.map +1 -0
  18. package/dist/chunk-BAUPQXPE.js +173 -0
  19. package/dist/chunk-BAUPQXPE.js.map +1 -0
  20. package/dist/{chunk-HC2MT7BX.js → chunk-BYZDPR7N.js} +14 -581
  21. package/dist/chunk-BYZDPR7N.js.map +1 -0
  22. package/dist/chunk-CD5ULRVC.js +615 -0
  23. package/dist/chunk-CD5ULRVC.js.map +1 -0
  24. package/dist/chunk-DIDUVL6O.js +1365 -0
  25. package/dist/chunk-DIDUVL6O.js.map +1 -0
  26. package/dist/{chunk-47VIN33V.js → chunk-EZATO3DW.js} +7 -5
  27. package/dist/{chunk-47VIN33V.js.map → chunk-EZATO3DW.js.map} +1 -1
  28. package/dist/{chunk-JW7WLSZ6.js → chunk-FADTCQGM.js} +48 -12
  29. package/dist/chunk-FADTCQGM.js.map +1 -0
  30. package/dist/{chunk-GANSDJV7.js → chunk-FJP3UQGD.js} +15 -13
  31. package/dist/chunk-FJP3UQGD.js.map +1 -0
  32. package/dist/chunk-KMMASOA6.js +134 -0
  33. package/dist/chunk-KMMASOA6.js.map +1 -0
  34. package/dist/{chunk-HQYXVIH6.js → chunk-LAFNLLQP.js} +3 -3
  35. package/dist/chunk-LWRSMTTZ.js +18 -0
  36. package/dist/chunk-LWRSMTTZ.js.map +1 -0
  37. package/dist/{chunk-MSPUB635.js → chunk-M5UCXTIT.js} +15 -12
  38. package/dist/chunk-M5UCXTIT.js.map +1 -0
  39. package/dist/chunk-M66SJHQQ.js +206 -0
  40. package/dist/chunk-M66SJHQQ.js.map +1 -0
  41. package/dist/{chunk-OBLVLIUS.js → chunk-MJULIKQU.js} +42 -6
  42. package/dist/chunk-MJULIKQU.js.map +1 -0
  43. package/dist/{chunk-RKTEV6EG.js → chunk-NS6R37II.js} +4 -4
  44. package/dist/{run-H75MD5BQ.js → chunk-NTMMF5UD.js} +515 -544
  45. package/dist/chunk-NTMMF5UD.js.map +1 -0
  46. package/dist/{chunk-UBIQXCVE.js → chunk-QCPGHBSZ.js} +16 -13
  47. package/dist/chunk-QCPGHBSZ.js.map +1 -0
  48. package/dist/{chunk-LVKQ2AKT.js → chunk-TSOLWK7Y.js} +8 -6
  49. package/dist/chunk-TSOLWK7Y.js.map +1 -0
  50. package/dist/{chunk-VCKX262Z.js → chunk-XQUSIEKA.js} +13 -10
  51. package/dist/chunk-XQUSIEKA.js.map +1 -0
  52. package/dist/chunk-Y5ZDJ4PJ.js +76 -0
  53. package/dist/chunk-Y5ZDJ4PJ.js.map +1 -0
  54. package/dist/cli.js +156 -26
  55. package/dist/cli.js.map +1 -1
  56. package/dist/{config-4THHOXNN.js → config-PRJGWW7J.js} +15 -3
  57. package/dist/execute-XBNVL753.js +18 -0
  58. package/dist/{generate-6RA2MFJB.js → generate-EGB4KV2B.js} +18 -11
  59. package/dist/generate-EGB4KV2B.js.map +1 -0
  60. package/dist/init-AJHCXJBP.js +10 -0
  61. package/dist/operations-BYT626KQ.js +365 -0
  62. package/dist/operations-BYT626KQ.js.map +1 -0
  63. package/dist/plan-QOZ3RIO6.js +21 -0
  64. package/dist/{policy-XQW5NUIE.js → policy-6S4GFC76.js} +6 -4
  65. package/dist/{policy-XQW5NUIE.js.map → policy-6S4GFC76.js.map} +1 -1
  66. package/dist/pr-EBBHD2ZX.js +26 -0
  67. package/dist/pr-review-VVMW5PO4.js +20 -0
  68. package/dist/prd-JQSZF7PR.js +21 -0
  69. package/dist/resume-PPCNQVVV.js +221 -0
  70. package/dist/resume-PPCNQVVV.js.map +1 -0
  71. package/dist/review-3F6MARWH.js +19 -0
  72. package/dist/run-RXE5GDQO.js +36 -0
  73. package/dist/run-RXE5GDQO.js.map +1 -0
  74. package/dist/state-manager-2EDVDBAR.js +34 -0
  75. package/dist/state-manager-2EDVDBAR.js.map +1 -0
  76. package/dist/{web-ANQQTTRD.js → web-EF5WIIGG.js} +13 -8
  77. package/dist/{web-ANQQTTRD.js.map → web-EF5WIIGG.js.map} +1 -1
  78. package/package.json +1 -1
  79. package/prompts/pr.md +11 -4
  80. package/web/public/app.js +12 -0
  81. package/dist/analyze-7B5TORNK.js.map +0 -1
  82. package/dist/chunk-3BOHTH4V.js +0 -58
  83. package/dist/chunk-3BOHTH4V.js.map +0 -1
  84. package/dist/chunk-6N7LZZ5U.js.map +0 -1
  85. package/dist/chunk-AAY6KM7N.js.map +0 -1
  86. package/dist/chunk-GANSDJV7.js.map +0 -1
  87. package/dist/chunk-HC2MT7BX.js.map +0 -1
  88. package/dist/chunk-HDV3YDTG.js +0 -52
  89. package/dist/chunk-HDV3YDTG.js.map +0 -1
  90. package/dist/chunk-JW7WLSZ6.js.map +0 -1
  91. package/dist/chunk-LVKQ2AKT.js.map +0 -1
  92. package/dist/chunk-MKD2D7WE.js.map +0 -1
  93. package/dist/chunk-MSPUB635.js.map +0 -1
  94. package/dist/chunk-OBLVLIUS.js.map +0 -1
  95. package/dist/chunk-PL6CNMVS.js.map +0 -1
  96. package/dist/chunk-UBIQXCVE.js.map +0 -1
  97. package/dist/chunk-VCKX262Z.js.map +0 -1
  98. package/dist/chunk-VQ5VN7DF.js +0 -1018
  99. package/dist/chunk-VQ5VN7DF.js.map +0 -1
  100. package/dist/execute-5OEKLM5X.js +0 -15
  101. package/dist/generate-6RA2MFJB.js.map +0 -1
  102. package/dist/init-PRMOTQ7N.js +0 -9
  103. package/dist/plan-KENR6MJ3.js +0 -17
  104. package/dist/pr-KDGKG4BP.js +0 -21
  105. package/dist/pr-review-CAMAB7KO.js +0 -17
  106. package/dist/prd-V3MWDIHK.js +0 -17
  107. package/dist/review-7LN47SAN.js +0 -15
  108. package/dist/run-H75MD5BQ.js.map +0 -1
  109. /package/dist/{chunk-HQYXVIH6.js.map → chunk-LAFNLLQP.js.map} +0 -0
  110. /package/dist/{chunk-RKTEV6EG.js.map → chunk-NS6R37II.js.map} +0 -0
  111. /package/dist/{config-4THHOXNN.js.map → config-PRJGWW7J.js.map} +0 -0
  112. /package/dist/{execute-5OEKLM5X.js.map → execute-XBNVL753.js.map} +0 -0
  113. /package/dist/{init-PRMOTQ7N.js.map → init-AJHCXJBP.js.map} +0 -0
  114. /package/dist/{plan-KENR6MJ3.js.map → plan-QOZ3RIO6.js.map} +0 -0
  115. /package/dist/{pr-KDGKG4BP.js.map → pr-EBBHD2ZX.js.map} +0 -0
  116. /package/dist/{pr-review-CAMAB7KO.js.map → pr-review-VVMW5PO4.js.map} +0 -0
  117. /package/dist/{prd-V3MWDIHK.js.map → prd-JQSZF7PR.js.map} +0 -0
  118. /package/dist/{review-7LN47SAN.js.map → review-3F6MARWH.js.map} +0 -0
@@ -1,332 +1,7 @@
1
1
  #!/usr/bin/env node
2
-
3
- // src/policy/schemas.ts
4
- import { z } from "zod";
5
- var policyDiscoveryConfigSchema = z.object({
6
- issueTemplates: z.boolean().default(true),
7
- pullRequestTemplate: z.boolean().default(true),
8
- docs: z.boolean().default(true),
9
- codeowners: z.boolean().default(true),
10
- labels: z.boolean().default(true),
11
- issueTypes: z.boolean().default(true)
12
- });
13
- var policyIssuesDeclarationSchema = z.object({
14
- titleConvention: z.string().min(1).optional(),
15
- /**
16
- * Whether Issue Flow may create a label the repository does not have.
17
- *
18
- * `.optional()` rather than `.default(false)`: the resolved declarations must
19
- * stay "only what was written", or the group would always look declared and
20
- * `sources` would report a provenance nobody asked for. The effective default
21
- * — false — lives at the call site.
22
- *
23
- * That default is a deliberate change of behaviour: creating taxonomy without
24
- * asking is the defect this exists to stop. A repository that wants the old
25
- * behaviour opts back into it.
26
- */
27
- allowLabelCreation: z.boolean().optional()
28
- });
29
- var policyPullRequestsDeclarationSchema = z.object({
30
- baseBranch: z.string().min(1).optional(),
31
- titleConvention: z.string().min(1).optional()
32
- });
33
- var policyGitDeclarationSchema = z.object({
34
- branchConvention: z.string().min(1).optional(),
35
- commitConvention: z.string().min(1).optional()
36
- });
37
- var policyConfigSchema = z.object({
38
- enabled: z.boolean().default(true),
39
- /**
40
- * Token budget for the `__REPO_POLICY__` projection. Sections above it are
41
- * replaced whole by a pointer rather than truncated — see
42
- * `policy/placeholders.ts`.
43
- */
44
- contextBudget: z.number().int().positive().default(1500),
45
- discovery: policyDiscoveryConfigSchema.prefault({}),
46
- issues: policyIssuesDeclarationSchema.prefault({}),
47
- pullRequests: policyPullRequestsDeclarationSchema.prefault({}),
48
- git: policyGitDeclarationSchema.prefault({})
49
- });
50
- var policyConfigInputSchema = z.object({
51
- enabled: z.boolean().optional(),
52
- contextBudget: z.number().int().positive().optional(),
53
- // Spelled out rather than `policyDiscoveryConfigSchema.partial()`: in zod 4
54
- // a `.default()` survives `.partial()`, so every toggle would come back
55
- // materialized and the input layer would stop meaning "what the user wrote".
56
- discovery: z.object({
57
- issueTemplates: z.boolean().optional(),
58
- pullRequestTemplate: z.boolean().optional(),
59
- docs: z.boolean().optional(),
60
- codeowners: z.boolean().optional(),
61
- labels: z.boolean().optional(),
62
- issueTypes: z.boolean().optional()
63
- }).optional(),
64
- issues: z.object({ titleConvention: z.string().nullish(), allowLabelCreation: z.boolean().optional() }).optional(),
65
- pullRequests: z.object({ baseBranch: z.string().nullish(), titleConvention: z.string().nullish() }).optional(),
66
- git: z.object({ branchConvention: z.string().nullish(), commitConvention: z.string().nullish() }).optional()
67
- });
68
-
69
- // src/schemas.ts
70
- import { z as z2 } from "zod";
71
- var claudeUsageSchema = z2.object({
72
- inputTokens: z2.number().optional(),
73
- outputTokens: z2.number().optional(),
74
- cacheReadTokens: z2.number().optional(),
75
- cacheCreationTokens: z2.number().optional(),
76
- costUsd: z2.number().optional()
77
- });
78
- var userStoryStatusSchema = z2.enum(["backlog", "in_progress", "in_review", "done"]);
79
- var storyStageSchema = z2.enum([
80
- "pending",
81
- "executing",
82
- "awaiting_review",
83
- "in_review",
84
- "in_correction",
85
- "done",
86
- "failed"
87
- ]);
88
- var userStorySchema = z2.object({
89
- id: z2.string(),
90
- title: z2.string(),
91
- description: z2.string(),
92
- acceptanceCriteria: z2.array(z2.string()),
93
- priority: z2.number().int().positive(),
94
- passes: z2.boolean(),
95
- notes: z2.string(),
96
- ...claudeUsageSchema.shape,
97
- durationSeconds: z2.number().optional(),
98
- status: userStoryStatusSchema.optional(),
99
- dependencies: z2.array(z2.string()).optional(),
100
- stage: storyStageSchema.optional(),
101
- stageSince: z2.string().optional(),
102
- stageDetail: z2.string().optional()
103
- });
104
- var pipelineStateSchema = z2.object({
105
- analyzeCompleted: z2.boolean().optional(),
106
- prdCompleted: z2.boolean(),
107
- jsonCompleted: z2.boolean(),
108
- executionCompleted: z2.boolean(),
109
- reviewCompleted: z2.boolean(),
110
- prCreated: z2.boolean(),
111
- prReviewCompleted: z2.boolean().optional()
112
- });
113
- var pullRequestRefSchema = z2.object({
114
- number: z2.number().int().positive(),
115
- url: z2.string(),
116
- headBranch: z2.string(),
117
- createdAt: z2.string()
118
- });
119
- var prReviewRecommendationSchema = z2.enum([
120
- "APPROVE",
121
- "APPROVE_WITH_SUGGESTIONS",
122
- "REQUEST_CHANGES"
123
- ]);
124
- var prReviewStateSchema = z2.object({
125
- enabled: z2.boolean().default(false),
126
- pullRequestNumber: z2.number().int().positive().optional(),
127
- rounds: z2.number().int().min(0).default(0),
128
- lastRecommendation: prReviewRecommendationSchema.optional(),
129
- lastReviewedAt: z2.string().optional()
130
- });
131
- var lastErrorSchema = z2.object({
132
- category: z2.string(),
133
- message: z2.string(),
134
- at: z2.string()
135
- });
136
- var issueMetadataSchema = z2.object({
137
- schemaVersion: z2.literal(1),
138
- id: z2.string().min(1),
139
- number: z2.number().int().positive().nullable(),
140
- source: z2.enum(["github", "local"]),
141
- title: z2.string(),
142
- labels: z2.array(z2.string()),
143
- state: z2.enum(["open", "closed"]),
144
- createdAt: z2.string(),
145
- updatedAt: z2.string(),
146
- contentHash: z2.string(),
147
- remote: z2.object({
148
- provider: z2.enum(["github", "local"]),
149
- ref: z2.string(),
150
- syncedAt: z2.string(),
151
- syncedContentHash: z2.string()
152
- }).optional()
153
- });
154
- var taskPlanSchema = z2.object({
155
- project: z2.string(),
156
- issueNumber: z2.union([z2.number().int().positive(), z2.string().min(1)]),
157
- issueUrl: z2.string().optional().default(""),
158
- branchName: z2.string(),
159
- noBranch: z2.boolean().optional().default(false),
160
- description: z2.string(),
161
- issueStatus: z2.enum(["pending", "in_progress", "completed"]),
162
- completedAt: z2.string().nullable(),
163
- lastAttemptAt: z2.string().nullable(),
164
- lastError: lastErrorSchema.nullable(),
165
- correctionCycle: z2.number().int().min(0),
166
- maxCorrectionCycles: z2.number().int().min(0),
167
- /**
168
- * Findings from the most recent failed review, verbatim. Non-null means the
169
- * issue has a pending correction even if every userStories[].passes is
170
- * already true — the execute phase must address these before the field is
171
- * cleared back to null. See core/engine.ts's early-return guards.
172
- */
173
- lastReviewFindings: z2.string().nullable().optional().default(null),
174
- pipeline: pipelineStateSchema,
175
- pullRequest: pullRequestRefSchema.optional(),
176
- prReview: prReviewStateSchema.optional(),
177
- userStories: z2.array(userStorySchema)
178
- });
179
- var headlessResultSchema = z2.object({
180
- success: z2.boolean(),
181
- result: z2.string(),
182
- cost: claudeUsageSchema.nullable(),
183
- error: z2.string().nullable()
184
- });
185
- var sessionLogEntrySchema = z2.object({
186
- at: z2.string(),
187
- level: z2.enum(["info", "warn", "error"]),
188
- message: z2.string()
189
- });
190
- var sessionUsageShape = {
191
- inputTokens: z2.number().nullable().default(null),
192
- outputTokens: z2.number().nullable().default(null),
193
- cacheReadTokens: z2.number().nullable().default(null),
194
- cacheCreationTokens: z2.number().nullable().default(null),
195
- costUsd: z2.number().nullable().default(null)
196
- };
197
- var sessionPhaseSchema = z2.object({
198
- name: z2.string(),
199
- status: z2.enum(["pending", "running", "completed", "failed"]),
200
- startedAt: z2.string().nullable(),
201
- endedAt: z2.string().nullable(),
202
- durationSeconds: z2.number().nullable(),
203
- error: z2.string().nullable(),
204
- ...sessionUsageShape
205
- });
206
- var sessionStorySchema = z2.object({
207
- id: z2.string(),
208
- title: z2.string(),
209
- priority: z2.number(),
210
- passes: z2.boolean(),
211
- completedAt: z2.string().nullable(),
212
- // Also introduced with the metrics, hence the same tolerant default.
213
- durationSeconds: z2.number().nullable().default(null),
214
- // Snapshot fields are always present on output and defaulted on input, so a
215
- // session.json written before they existed still parses. This is the mirror
216
- // image of userStorySchema, where the same two fields are plainly optional.
217
- status: userStoryStatusSchema.default("backlog"),
218
- dependencies: z2.array(z2.string()).default([]),
219
- // Published for the panel's story detail view. Same tolerant default as the
220
- // fields above: absent (older session.json) and empty resolve to the same
221
- // value, so the client never has to tell them apart.
222
- description: z2.string().default(""),
223
- acceptanceCriteria: z2.array(z2.string()).default([]),
224
- // Additive like the rest of this schema: a session.json written before
225
- // `stage` existed parses into 'pending'/null, the same values a fresh
226
- // snapshot starts a story at.
227
- stage: storyStageSchema.default("pending"),
228
- stageSince: z2.string().nullable().default(null),
229
- stageDetail: z2.string().nullable().default(null),
230
- ...sessionUsageShape
231
- });
232
- var sessionSnapshotSchema = z2.object({
233
- schemaVersion: z2.literal(1),
234
- sessionId: z2.string().nullable(),
235
- readOnly: z2.literal(true),
236
- capabilities: z2.array(z2.string()),
237
- issue: z2.object({
238
- number: z2.number().nullable(),
239
- url: z2.string().nullable(),
240
- // Additive: a session.json written before the Issue section was enriched
241
- // parses into the same "not reported" values createInitialSnapshot() uses.
242
- title: z2.string().nullable().default(null),
243
- description: z2.string().nullable().default(null),
244
- labels: z2.array(z2.string()).default([]),
245
- state: z2.string().nullable().default(null)
246
- }),
247
- status: z2.enum(["idle", "running", "completed", "failed"]),
248
- startedAt: z2.string().nullable(),
249
- updatedAt: z2.string().nullable(),
250
- endedAt: z2.string().nullable(),
251
- elapsedSeconds: z2.number().nullable(),
252
- estimatedRemainingSeconds: z2.number().nullable(),
253
- progress: z2.object({
254
- percent: z2.number(),
255
- phasesCompleted: z2.number(),
256
- phasesTotal: z2.number(),
257
- storiesCompleted: z2.number(),
258
- storiesTotal: z2.number()
259
- }),
260
- currentPhase: z2.string().nullable(),
261
- currentActivity: z2.object({
262
- story: z2.string().nullable(),
263
- tool: z2.string().nullable(),
264
- detail: z2.string().nullable(),
265
- since: z2.string()
266
- }).nullable(),
267
- phases: z2.array(sessionPhaseSchema),
268
- stories: z2.array(sessionStorySchema),
269
- // The whole aggregate is additive: a snapshot from before it existed parses
270
- // into the same "nothing reported" object the reducer starts from.
271
- metrics: z2.object({
272
- totalInputTokens: z2.number().nullable().default(null),
273
- totalOutputTokens: z2.number().nullable().default(null),
274
- totalCacheReadTokens: z2.number().nullable().default(null),
275
- totalCacheCreationTokens: z2.number().nullable().default(null),
276
- totalCostUsd: z2.number().nullable().default(null)
277
- }).default({
278
- totalInputTokens: null,
279
- totalOutputTokens: null,
280
- totalCacheReadTokens: null,
281
- totalCacheCreationTokens: null,
282
- totalCostUsd: null
283
- }),
284
- execution: z2.object({
285
- iteration: z2.number(),
286
- retries: z2.number(),
287
- correctionCycle: z2.number(),
288
- maxCorrectionCycles: z2.number().nullable()
289
- }),
290
- git: z2.object({
291
- branch: z2.string().nullable(),
292
- baseBranch: z2.string().nullable(),
293
- commits: z2.array(z2.object({ hash: z2.string(), subject: z2.string() }))
294
- }),
295
- // Additive like the metrics aggregate: a session.json written before the
296
- // repository section existed parses into the same all-null object
297
- // createInitialSnapshot() starts from.
298
- repository: z2.object({
299
- name: z2.string().nullable().default(null),
300
- remoteUrl: z2.string().nullable().default(null),
301
- branch: z2.string().nullable().default(null),
302
- headCommit: z2.string().nullable().default(null),
303
- root: z2.string().nullable().default(null)
304
- }).default({ name: null, remoteUrl: null, branch: null, headCommit: null, root: null }),
305
- pullRequests: z2.array(z2.object({ number: z2.number(), url: z2.string(), title: z2.string() })),
306
- logs: z2.array(sessionLogEntrySchema),
307
- errors: z2.array(sessionLogEntrySchema),
308
- warnings: z2.array(sessionLogEntrySchema),
309
- lastError: z2.object({ message: z2.string(), at: z2.string() }).nullable(),
310
- nextSteps: z2.array(z2.string()),
311
- environment: z2.object({ node: z2.string(), platform: z2.string() }).nullable()
312
- });
313
- var webConfigSchema = z2.object({
314
- enabled: z2.boolean().default(false),
315
- port: z2.number().int().min(1).max(65535).default(3737),
316
- host: z2.string().min(1).default("0.0.0.0"),
317
- refreshSeconds: z2.number().positive().default(5),
318
- logLimit: z2.number().int().positive().default(200),
319
- includeLogs: z2.boolean().default(true)
320
- });
321
- var issuesConfigSchema = z2.object({
322
- defaultGenerateTarget: z2.enum(["github", "local", "both"]).default("github"),
323
- preferredProvider: z2.enum(["github", "local"]).default("github"),
324
- conflictPolicy: z2.enum(["ask", "prefer-local", "prefer-github"]).default("ask"),
325
- requireConfirmation: z2.boolean().default(true)
326
- });
327
- var prReviewConfigSchema = z2.object({
328
- publisher: z2.enum(["local"]).default("local")
329
- });
2
+ import {
3
+ isoNow
4
+ } from "./chunk-CD5ULRVC.js";
330
5
 
331
6
  // src/core/session-state.ts
332
7
  import { mkdir, rename, writeFile } from "fs/promises";
@@ -917,230 +592,6 @@ function getSessionPublisher() {
917
592
  return _publisher;
918
593
  }
919
594
 
920
- // src/core/state-manager.ts
921
- import { readFile } from "fs/promises";
922
- import { ZodError } from "zod";
923
-
924
- // src/utils/fs.ts
925
- import { copyFile, mkdtemp, rename as rename2, unlink, writeFile as writeFile2 } from "fs/promises";
926
- import { tmpdir } from "os";
927
- import { basename, join } from "path";
928
- async function writeFileAtomic(path, content) {
929
- const tmpDir = await mkdtemp(join(tmpdir(), "issue-flow-"));
930
- const tmpFile = join(tmpDir, basename(path));
931
- await writeFile2(tmpFile, content, "utf-8");
932
- try {
933
- await rename2(tmpFile, path);
934
- } catch (err) {
935
- if (err.code === "EXDEV") {
936
- await copyFile(tmpFile, path);
937
- await unlink(tmpFile);
938
- } else {
939
- throw err;
940
- }
941
- }
942
- }
943
-
944
- // src/core/metrics.ts
945
- var USAGE_FIELDS = [
946
- "inputTokens",
947
- "outputTokens",
948
- "cacheReadTokens",
949
- "cacheCreationTokens",
950
- "costUsd"
951
- ];
952
- function num(value) {
953
- return typeof value === "number" && Number.isFinite(value) ? value : void 0;
954
- }
955
- function isRecord(value) {
956
- return typeof value === "object" && value !== null;
957
- }
958
- function parseUsage(payload) {
959
- if (!isRecord(payload)) return null;
960
- const usageRaw = isRecord(payload.usage) ? payload.usage : void 0;
961
- const usage = {};
962
- const inputTokens = usageRaw ? num(usageRaw.input_tokens) : void 0;
963
- const outputTokens = usageRaw ? num(usageRaw.output_tokens) : void 0;
964
- const cacheReadTokens = usageRaw ? num(usageRaw.cache_read_input_tokens) : void 0;
965
- const cacheCreationTokens = usageRaw ? num(usageRaw.cache_creation_input_tokens) : void 0;
966
- const costUsd = num(payload.total_cost_usd);
967
- const legacyInput = num(payload.num_input_tokens);
968
- const legacyOutput = num(payload.num_output_tokens);
969
- const legacyCost = num(payload.cost_usd);
970
- const resolvedInput = inputTokens ?? legacyInput;
971
- const resolvedOutput = outputTokens ?? legacyOutput;
972
- const resolvedCost = costUsd ?? legacyCost;
973
- if (resolvedInput !== void 0) usage.inputTokens = resolvedInput;
974
- if (resolvedOutput !== void 0) usage.outputTokens = resolvedOutput;
975
- if (cacheReadTokens !== void 0) usage.cacheReadTokens = cacheReadTokens;
976
- if (cacheCreationTokens !== void 0) usage.cacheCreationTokens = cacheCreationTokens;
977
- if (resolvedCost !== void 0) usage.costUsd = resolvedCost;
978
- return Object.keys(usage).length > 0 ? usage : null;
979
- }
980
- function sumUsage(a, b) {
981
- const result = {};
982
- for (const field of USAGE_FIELDS) {
983
- const left = a?.[field];
984
- const right = b?.[field];
985
- if (left === void 0 && right === void 0) continue;
986
- result[field] = (left ?? 0) + (right ?? 0);
987
- }
988
- return result;
989
- }
990
- function divideUsage(usage, parts) {
991
- const result = {};
992
- if (!usage) return result;
993
- const divisor = Number.isFinite(parts) && parts > 1 ? parts : 1;
994
- for (const field of USAGE_FIELDS) {
995
- const value = usage[field];
996
- if (value === void 0) continue;
997
- result[field] = field === "costUsd" ? value / divisor : Math.round(value / divisor);
998
- }
999
- return result;
1000
- }
1001
- function compactTokens(value) {
1002
- const abs = Math.abs(value);
1003
- if (abs >= 1e6) return `${(value / 1e6).toFixed(1)}M`;
1004
- if (abs >= 1e3) return `${(value / 1e3).toFixed(1)}k`;
1005
- return String(Math.round(value));
1006
- }
1007
- function formatTokens(usage) {
1008
- if (!usage) return "";
1009
- const segments = [];
1010
- const io = [];
1011
- if (usage.inputTokens !== void 0) io.push(`${compactTokens(usage.inputTokens)} in`);
1012
- if (usage.outputTokens !== void 0) io.push(`${compactTokens(usage.outputTokens)} out`);
1013
- if (io.length > 0) segments.push(io.join(" / "));
1014
- const cache = usage.cacheReadTokens !== void 0 || usage.cacheCreationTokens !== void 0 ? (usage.cacheReadTokens ?? 0) + (usage.cacheCreationTokens ?? 0) : void 0;
1015
- if (cache !== void 0) segments.push(`${compactTokens(cache)} cache`);
1016
- if (usage.costUsd !== void 0) segments.push(`~$${usage.costUsd.toFixed(4)}`);
1017
- return segments.join(" \xB7 ");
1018
- }
1019
- function hasUsageData(usage) {
1020
- if (!usage) return false;
1021
- return USAGE_FIELDS.some((field) => usage[field] !== void 0);
1022
- }
1023
-
1024
- // src/core/state-manager.ts
1025
- function isoNow() {
1026
- return (/* @__PURE__ */ new Date()).toISOString().replace(/\.\d{3}Z$/, "Z");
1027
- }
1028
- async function loadTaskPlan(path) {
1029
- const content = await readFile(path, "utf-8");
1030
- const raw = JSON.parse(content);
1031
- try {
1032
- return taskPlanSchema.parse(raw);
1033
- } catch (err) {
1034
- if (err instanceof ZodError) {
1035
- const issues = err.issues.map((i) => ` - ${i.path.join(".")}: ${i.message}`).join("\n");
1036
- throw new Error(`Invalid tasks.json at ${path}:
1037
- ${issues}`);
1038
- }
1039
- throw err;
1040
- }
1041
- }
1042
- async function saveTaskPlan(path, plan) {
1043
- await writeFileAtomic(path, `${JSON.stringify(plan, null, 2)}
1044
- `);
1045
- }
1046
- function initializeState(plan) {
1047
- const defaultPipeline = {
1048
- prdCompleted: false,
1049
- jsonCompleted: false,
1050
- executionCompleted: false,
1051
- reviewCompleted: false,
1052
- prCreated: false
1053
- };
1054
- return {
1055
- ...plan,
1056
- issueStatus: plan.issueStatus ?? "pending",
1057
- completedAt: plan.completedAt ?? null,
1058
- lastAttemptAt: plan.lastAttemptAt ?? null,
1059
- lastError: plan.lastError ?? null,
1060
- correctionCycle: plan.correctionCycle ?? 0,
1061
- maxCorrectionCycles: plan.maxCorrectionCycles ?? 3,
1062
- lastReviewFindings: plan.lastReviewFindings ?? null,
1063
- pipeline: plan.pipeline ? { ...defaultPipeline, ...plan.pipeline } : defaultPipeline
1064
- };
1065
- }
1066
- function hasPendingCorrection(plan) {
1067
- return Boolean(plan.lastReviewFindings);
1068
- }
1069
- function allStoriesPass(plan) {
1070
- if (plan.userStories.length === 0) {
1071
- return false;
1072
- }
1073
- return plan.userStories.every((story) => story.passes === true);
1074
- }
1075
- function selectActiveStory(stories) {
1076
- return [...stories].filter((story) => !story.passes).sort((a, b) => a.priority - b.priority)[0];
1077
- }
1078
- function applyStoryMetrics(plan, storyIds, share, durationSeconds) {
1079
- if (storyIds.length === 0) return plan;
1080
- const targets = new Set(storyIds);
1081
- return {
1082
- ...plan,
1083
- userStories: plan.userStories.map((story) => {
1084
- if (!targets.has(story.id)) return story;
1085
- const updated = { ...story, ...sumUsage(story, share) };
1086
- if (story.durationSeconds !== void 0 || durationSeconds !== void 0) {
1087
- updated.durationSeconds = (story.durationSeconds ?? 0) + (durationSeconds ?? 0);
1088
- }
1089
- return updated;
1090
- })
1091
- };
1092
- }
1093
- function markIssueInProgress(plan, timestamp) {
1094
- const ts = timestamp ?? isoNow();
1095
- return {
1096
- ...plan,
1097
- issueStatus: "in_progress",
1098
- completedAt: null,
1099
- lastAttemptAt: ts
1100
- };
1101
- }
1102
- function markIssueCompleted(plan) {
1103
- const ts = isoNow();
1104
- return {
1105
- ...plan,
1106
- issueStatus: "completed",
1107
- completedAt: ts,
1108
- lastAttemptAt: ts,
1109
- lastError: null,
1110
- pipeline: plan.pipeline ? { ...plan.pipeline, executionCompleted: true } : plan.pipeline
1111
- };
1112
- }
1113
- function setLastError(plan, category, message) {
1114
- const ts = isoNow();
1115
- const error = {
1116
- category,
1117
- message,
1118
- at: ts
1119
- };
1120
- return {
1121
- ...plan,
1122
- lastAttemptAt: ts,
1123
- lastError: error
1124
- };
1125
- }
1126
- function clearLastError(plan, attemptStartedAt) {
1127
- const ts = isoNow();
1128
- if (plan.lastError && plan.lastError.at > attemptStartedAt) {
1129
- return {
1130
- ...plan,
1131
- lastAttemptAt: ts
1132
- };
1133
- }
1134
- return {
1135
- ...plan,
1136
- lastAttemptAt: ts,
1137
- lastError: null
1138
- };
1139
- }
1140
- function trimErrorMessage(message) {
1141
- return message.split("\n").filter((line) => line.trim().length > 0).slice(0, 8).join("\n");
1142
- }
1143
-
1144
595
  // src/core/verbose.ts
1145
596
  var _verbose = false;
1146
597
  function setVerbose(enabled) {
@@ -1177,6 +628,13 @@ function setGlobalTimeout(ms) {
1177
628
  function getGlobalTimeout() {
1178
629
  return _globalTimeout;
1179
630
  }
631
+ var _inactivityTimeout;
632
+ function setInactivityTimeout(ms) {
633
+ _inactivityTimeout = ms;
634
+ }
635
+ function getInactivityTimeout() {
636
+ return _inactivityTimeout;
637
+ }
1180
638
 
1181
639
  // src/ui/logger.ts
1182
640
  import chalk from "chalk";
@@ -1325,38 +783,11 @@ var ElapsedTimer = class {
1325
783
  };
1326
784
 
1327
785
  export {
1328
- policyConfigSchema,
1329
- policyConfigInputSchema,
1330
- pullRequestRefSchema,
1331
- issueMetadataSchema,
1332
- taskPlanSchema,
1333
- sessionSnapshotSchema,
1334
- webConfigSchema,
1335
- issuesConfigSchema,
1336
- prReviewConfigSchema,
1337
786
  NullPublisher,
787
+ MemoryPublisher,
1338
788
  FilePublisher,
1339
789
  setSessionPublisher,
1340
790
  getSessionPublisher,
1341
- writeFileAtomic,
1342
- parseUsage,
1343
- sumUsage,
1344
- divideUsage,
1345
- formatTokens,
1346
- hasUsageData,
1347
- isoNow,
1348
- loadTaskPlan,
1349
- saveTaskPlan,
1350
- initializeState,
1351
- hasPendingCorrection,
1352
- allStoriesPass,
1353
- selectActiveStory,
1354
- applyStoryMetrics,
1355
- markIssueInProgress,
1356
- markIssueCompleted,
1357
- setLastError,
1358
- clearLastError,
1359
- trimErrorMessage,
1360
791
  setVerbose,
1361
792
  isVerbose,
1362
793
  setOutputCallback,
@@ -1367,6 +798,8 @@ export {
1367
798
  getStoryStageCallback,
1368
799
  setGlobalTimeout,
1369
800
  getGlobalTimeout,
801
+ setInactivityTimeout,
802
+ getInactivityTimeout,
1370
803
  useUnicode,
1371
804
  useColor,
1372
805
  getIcons,
@@ -1380,4 +813,4 @@ export {
1380
813
  formatDuration,
1381
814
  ElapsedTimer
1382
815
  };
1383
- //# sourceMappingURL=chunk-HC2MT7BX.js.map
816
+ //# sourceMappingURL=chunk-BYZDPR7N.js.map