@aviaratech/ai-delivery 0.3.34 → 0.3.36

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 (301) hide show
  1. package/CONTRIBUTING.md +12 -206
  2. package/README.md +57 -506
  3. package/dist/agent.d.ts +0 -2
  4. package/dist/agent.js +76 -16
  5. package/dist/agent.js.map +7 -1
  6. package/dist/agentReadiness.test.js +73 -67
  7. package/dist/agentReadiness.test.js.map +7 -1
  8. package/dist/boardReconcile.test.js +1746 -0
  9. package/dist/boardReconcile.test.js.map +7 -0
  10. package/dist/build.test.js +130 -0
  11. package/dist/build.test.js.map +7 -0
  12. package/dist/callerErrors.test.js +105 -0
  13. package/dist/callerErrors.test.js.map +7 -0
  14. package/dist/cli.js +406 -485
  15. package/dist/cli.js.map +7 -1
  16. package/dist/cliResult.d.ts +2 -2
  17. package/dist/cliResult.js +42 -25
  18. package/dist/cliResult.js.map +7 -1
  19. package/dist/cliResult.test.js +434 -297
  20. package/dist/cliResult.test.js.map +7 -1
  21. package/dist/config/deliveryConfig.d.ts +320 -14
  22. package/dist/config/deliveryConfig.js +472 -385
  23. package/dist/config/deliveryConfig.js.map +7 -1
  24. package/dist/config/deliveryConfig.test.js +775 -584
  25. package/dist/config/deliveryConfig.test.js.map +7 -1
  26. package/dist/contributorChecks.test.js +1694 -916
  27. package/dist/contributorChecks.test.js.map +7 -1
  28. package/dist/currentConsumer.test.js +819 -737
  29. package/dist/currentConsumer.test.js.map +7 -1
  30. package/dist/currentTrackingScenario.test.js +499 -477
  31. package/dist/currentTrackingScenario.test.js.map +7 -1
  32. package/dist/delivery/common.js +160 -172
  33. package/dist/delivery/common.js.map +7 -1
  34. package/dist/delivery/delivery.test.js +509 -431
  35. package/dist/delivery/delivery.test.js.map +7 -1
  36. package/dist/delivery/evidence.d.ts +2 -2
  37. package/dist/delivery/evidence.js +133 -120
  38. package/dist/delivery/evidence.js.map +7 -1
  39. package/dist/delivery/index.js +7 -2
  40. package/dist/delivery/index.js.map +7 -1
  41. package/dist/delivery/legacy.js +65 -5
  42. package/dist/delivery/legacy.js.map +7 -1
  43. package/dist/delivery/policy.d.ts +10 -10
  44. package/dist/delivery/policy.js +211 -238
  45. package/dist/delivery/policy.js.map +7 -1
  46. package/dist/delivery/stage.d.ts +18 -18
  47. package/dist/delivery/stage.js +220 -235
  48. package/dist/delivery/stage.js.map +7 -1
  49. package/dist/deliveryBoard.d.ts +74 -0
  50. package/dist/deliveryBoard.js +644 -0
  51. package/dist/deliveryBoard.js.map +7 -0
  52. package/dist/deliveryBoard.test.d.ts +1 -0
  53. package/dist/deliveryBoard.test.js +649 -0
  54. package/dist/deliveryBoard.test.js.map +7 -0
  55. package/dist/deliveryHealth.test.js +179 -155
  56. package/dist/deliveryHealth.test.js.map +7 -1
  57. package/dist/dependencyCompatibility.test.js +154 -140
  58. package/dist/dependencyCompatibility.test.js.map +7 -1
  59. package/dist/directoryIndependent.test.js +417 -383
  60. package/dist/directoryIndependent.test.js.map +7 -1
  61. package/dist/dispatch.d.ts +17 -12
  62. package/dist/dispatch.js +330 -322
  63. package/dist/dispatch.js.map +7 -1
  64. package/dist/errors.d.ts +16 -3
  65. package/dist/errors.js +104 -82
  66. package/dist/errors.js.map +7 -1
  67. package/dist/fixtures/deliveryBoardReplay.d.ts +56 -0
  68. package/dist/fixtures/deliveryBoardReplay.js +617 -0
  69. package/dist/fixtures/deliveryBoardReplay.js.map +7 -0
  70. package/dist/fixtures/discovery.d.ts +59 -19
  71. package/dist/fixtures/discovery.js +96 -90
  72. package/dist/fixtures/discovery.js.map +7 -1
  73. package/dist/fixtures/inertEntrypointChild.js +57 -56
  74. package/dist/fixtures/inertEntrypointChild.js.map +7 -1
  75. package/dist/fixtures/inertEntrypoints.d.ts +1 -1
  76. package/dist/fixtures/inertEntrypoints.js +321 -276
  77. package/dist/fixtures/inertEntrypoints.js.map +7 -1
  78. package/dist/fixtures/inertTarget.d.ts +78 -7
  79. package/dist/fixtures/inertTarget.js +769 -691
  80. package/dist/fixtures/inertTarget.js.map +7 -1
  81. package/dist/fixtures/issue63.d.ts +4 -3
  82. package/dist/fixtures/issue63.js +260 -274
  83. package/dist/fixtures/issue63.js.map +7 -1
  84. package/dist/fixtures/issueProjectItems.d.ts +20 -0
  85. package/dist/fixtures/issueProjectItems.js +15 -0
  86. package/dist/fixtures/issueProjectItems.js.map +7 -0
  87. package/dist/fixtures/readView.d.ts +120 -0
  88. package/dist/fixtures/readView.js +172 -0
  89. package/dist/fixtures/readView.js.map +7 -0
  90. package/dist/fixtures/recordedGitHubFlows.d.ts +120 -0
  91. package/dist/fixtures/recordedGitHubFlows.js +109 -0
  92. package/dist/fixtures/recordedGitHubFlows.js.map +7 -0
  93. package/dist/genericCompatibility.test.js +64 -55
  94. package/dist/genericCompatibility.test.js.map +7 -1
  95. package/dist/git.js +73 -67
  96. package/dist/git.js.map +7 -1
  97. package/dist/gitProcess.d.ts +1 -1
  98. package/dist/gitProcess.js +58 -53
  99. package/dist/gitProcess.js.map +7 -1
  100. package/dist/github/client.d.ts +2 -2
  101. package/dist/github/client.js +484 -379
  102. package/dist/github/client.js.map +7 -1
  103. package/dist/github/commandIdentityPolicy.js +44 -51
  104. package/dist/github/commandIdentityPolicy.js.map +7 -1
  105. package/dist/github/discovery.d.ts +3 -0
  106. package/dist/github/discovery.js +197 -201
  107. package/dist/github/discovery.js.map +7 -1
  108. package/dist/github/discovery.test.js +223 -177
  109. package/dist/github/discovery.test.js.map +7 -1
  110. package/dist/github/issueHistory.d.ts +2 -2
  111. package/dist/github/issueHistory.js +117 -125
  112. package/dist/github/issueHistory.js.map +7 -1
  113. package/dist/github/machineAuth.d.ts +1 -1
  114. package/dist/github/machineAuth.js +126 -117
  115. package/dist/github/machineAuth.js.map +7 -1
  116. package/dist/github/machineAuth.test.js +755 -639
  117. package/dist/github/machineAuth.test.js.map +7 -1
  118. package/dist/github/nativeIssueMetadata.js +286 -273
  119. package/dist/github/nativeIssueMetadata.js.map +7 -1
  120. package/dist/github/projectDelivery.d.ts +53 -1
  121. package/dist/github/projectDelivery.js +623 -460
  122. package/dist/github/projectDelivery.js.map +7 -1
  123. package/dist/github/relationships.d.ts +5 -2
  124. package/dist/github/relationships.js +434 -333
  125. package/dist/github/relationships.js.map +7 -1
  126. package/dist/github/repo.d.ts +1 -0
  127. package/dist/github/repo.js +123 -96
  128. package/dist/github/repo.js.map +7 -1
  129. package/dist/index.js +3 -3
  130. package/dist/index.js.map +7 -1
  131. package/dist/issue.d.ts +103 -7
  132. package/dist/issue.js +2104 -1547
  133. package/dist/issue.js.map +7 -1
  134. package/dist/issue63History.test.js +40 -42
  135. package/dist/issue63History.test.js.map +7 -1
  136. package/dist/issue63Routes.test.js +154 -143
  137. package/dist/issue63Routes.test.js.map +7 -1
  138. package/dist/issueBatchUpdate.test.js +1004 -683
  139. package/dist/issueBatchUpdate.test.js.map +7 -1
  140. package/dist/issueBlockerGuard.test.js +262 -226
  141. package/dist/issueBlockerGuard.test.js.map +7 -1
  142. package/dist/issueContract.d.ts +23 -4
  143. package/dist/issueContract.js +416 -395
  144. package/dist/issueContract.js.map +7 -1
  145. package/dist/issueContract.test.d.ts +4 -3
  146. package/dist/issueContract.test.js +358 -321
  147. package/dist/issueContract.test.js.map +7 -1
  148. package/dist/issueDates.test.js +235 -233
  149. package/dist/issueDates.test.js.map +7 -1
  150. package/dist/issueInfoReadback.test.js +304 -190
  151. package/dist/issueInfoReadback.test.js.map +7 -1
  152. package/dist/issueIntake.test.js +1945 -1732
  153. package/dist/issueIntake.test.js.map +7 -1
  154. package/dist/issueJournal.d.ts +40 -19
  155. package/dist/issueJournal.js +229 -138
  156. package/dist/issueJournal.js.map +7 -1
  157. package/dist/issueJournal.test.js +605 -422
  158. package/dist/issueJournal.test.js.map +7 -1
  159. package/dist/issueRollup.test.d.ts +1 -0
  160. package/dist/issueRollup.test.js +476 -0
  161. package/dist/issueRollup.test.js.map +7 -0
  162. package/dist/issueTracking.test.js +1088 -593
  163. package/dist/issueTracking.test.js.map +7 -1
  164. package/dist/issueWriteRecovery.test.d.ts +1 -0
  165. package/dist/issueWriteRecovery.test.js +260 -0
  166. package/dist/issueWriteRecovery.test.js.map +7 -0
  167. package/dist/lifecycle.test.js +112 -441
  168. package/dist/lifecycle.test.js.map +7 -1
  169. package/dist/logger.js +80 -74
  170. package/dist/logger.js.map +7 -1
  171. package/dist/mcp/index.js +116 -90
  172. package/dist/mcp/index.js.map +7 -1
  173. package/dist/mcp/tools.d.ts +790 -220
  174. package/dist/mcp/tools.js +267 -333
  175. package/dist/mcp/tools.js.map +7 -1
  176. package/dist/pluginAuthProbe.js +63 -52
  177. package/dist/pluginAuthProbe.js.map +7 -1
  178. package/dist/pluginAuthProbe.test.js +85 -62
  179. package/dist/pluginAuthProbe.test.js.map +7 -1
  180. package/dist/pluginCredentials.test.js +282 -259
  181. package/dist/pluginCredentials.test.js.map +7 -1
  182. package/dist/pluginDoctor.test.js +653 -588
  183. package/dist/pluginDoctor.test.js.map +7 -1
  184. package/dist/pluginInstaller.d.ts +7 -5
  185. package/dist/pluginInstaller.js +1173 -1231
  186. package/dist/pluginInstaller.js.map +7 -1
  187. package/dist/pluginInstaller.test.js +1822 -1283
  188. package/dist/pluginInstaller.test.js.map +7 -1
  189. package/dist/pluginPackaging.test.js +485 -305
  190. package/dist/pluginPackaging.test.js.map +7 -1
  191. package/dist/pr.d.ts +132 -94
  192. package/dist/pr.js +1521 -1323
  193. package/dist/pr.js.map +7 -1
  194. package/dist/pr.test.js +1678 -632
  195. package/dist/pr.test.js.map +7 -1
  196. package/dist/prAssociation.test.js +2419 -1788
  197. package/dist/prAssociation.test.js.map +7 -1
  198. package/dist/prDispatch.test.js +150 -89
  199. package/dist/prDispatch.test.js.map +7 -1
  200. package/dist/readView.d.ts +183 -0
  201. package/dist/readView.js +217 -0
  202. package/dist/readView.js.map +7 -0
  203. package/dist/readView.test.d.ts +1 -0
  204. package/dist/readView.test.js +119 -0
  205. package/dist/readView.test.js.map +7 -0
  206. package/dist/releaseReconciliation.test.js +267 -288
  207. package/dist/releaseReconciliation.test.js.map +7 -1
  208. package/dist/releaseWorkflow.test.js +2493 -422
  209. package/dist/releaseWorkflow.test.js.map +7 -1
  210. package/dist/review.d.ts +738 -2
  211. package/dist/review.js +601 -348
  212. package/dist/review.js.map +7 -1
  213. package/dist/review.test.js +1218 -812
  214. package/dist/review.test.js.map +7 -1
  215. package/dist/reviewSubmit.test.d.ts +1 -0
  216. package/dist/reviewSubmit.test.js +747 -0
  217. package/dist/reviewSubmit.test.js.map +7 -0
  218. package/dist/services/agentReadinessService.js +42 -37
  219. package/dist/services/agentReadinessService.js.map +7 -1
  220. package/dist/services/blockerGuardService.js +188 -188
  221. package/dist/services/blockerGuardService.js.map +7 -1
  222. package/dist/services/boardReconcileService.d.ts +1204 -0
  223. package/dist/services/boardReconcileService.js +1445 -0
  224. package/dist/services/boardReconcileService.js.map +7 -0
  225. package/dist/services/deliveryAdmission.d.ts +2 -0
  226. package/dist/services/deliveryAdmission.js +129 -152
  227. package/dist/services/deliveryAdmission.js.map +7 -1
  228. package/dist/services/deliveryHealthService.js +197 -199
  229. package/dist/services/deliveryHealthService.js.map +7 -1
  230. package/dist/services/legacyIssueMigration.js +263 -277
  231. package/dist/services/legacyIssueMigration.js.map +7 -1
  232. package/dist/services/worktreeRegistry.d.ts +27 -119
  233. package/dist/services/worktreeRegistry.js +765 -1182
  234. package/dist/services/worktreeRegistry.js.map +7 -1
  235. package/dist/stagedChecks.test.js +396 -194
  236. package/dist/stagedChecks.test.js.map +7 -1
  237. package/dist/start.test.js +99 -95
  238. package/dist/start.test.js.map +7 -1
  239. package/dist/stdoutRegression.test.js +354 -350
  240. package/dist/stdoutRegression.test.js.map +7 -1
  241. package/dist/targetPolicyDiscovery.test.js +141 -143
  242. package/dist/targetPolicyDiscovery.test.js.map +7 -1
  243. package/dist/targetPolicyEntrypoints.test.js +308 -269
  244. package/dist/targetPolicyEntrypoints.test.js.map +7 -1
  245. package/dist/targetPolicyLocal.test.js +580 -1051
  246. package/dist/targetPolicyLocal.test.js.map +7 -1
  247. package/dist/targetPolicyRoutes.test.js +305 -281
  248. package/dist/targetPolicyRoutes.test.js.map +7 -1
  249. package/dist/targetRepositoryExecution.test.d.ts +1 -0
  250. package/dist/targetRepositoryExecution.test.js +463 -0
  251. package/dist/targetRepositoryExecution.test.js.map +7 -0
  252. package/dist/terminalMessages.js +41 -35
  253. package/dist/terminalMessages.js.map +7 -1
  254. package/dist/toolOutput.d.ts +2 -0
  255. package/dist/toolOutput.js +36 -0
  256. package/dist/toolOutput.js.map +7 -0
  257. package/dist/toolOutput.test.d.ts +1 -0
  258. package/dist/toolOutput.test.js +240 -0
  259. package/dist/toolOutput.test.js.map +7 -0
  260. package/dist/utils/atomicJson.js +84 -76
  261. package/dist/utils/atomicJson.js.map +7 -1
  262. package/dist/utils/filesystem.js +15 -18
  263. package/dist/utils/filesystem.js.map +7 -1
  264. package/dist/utils/lockfile.js +68 -71
  265. package/dist/utils/lockfile.js.map +7 -1
  266. package/dist/verification.d.ts +1 -19
  267. package/dist/verification.js +1020 -1929
  268. package/dist/verification.js.map +7 -1
  269. package/dist/verificationGate.test.js +127 -117
  270. package/dist/verificationGate.test.js.map +7 -1
  271. package/dist/version.d.ts +6 -0
  272. package/dist/version.js +24 -10
  273. package/dist/version.js.map +7 -1
  274. package/dist/worktree.d.ts +3 -15
  275. package/dist/worktree.js +97 -177
  276. package/dist/worktree.js.map +7 -1
  277. package/package.json +10 -8
  278. package/plugins/ai-delivery/.claude-plugin/plugin.json +2 -2
  279. package/plugins/ai-delivery/README.md +47 -156
  280. package/plugins/ai-delivery/plugin.json +1 -1
  281. package/plugins/ai-delivery/runtime/dist/THIRD-PARTY-NOTICES.md +261 -43
  282. package/plugins/ai-delivery/runtime/dist/cli.js +369 -125
  283. package/plugins/ai-delivery/runtime/package.json +1 -1
  284. package/plugins/ai-delivery/skills/intake-create/SKILL.md +14 -78
  285. package/plugins/ai-delivery/skills/pr-handoff/SKILL.md +35 -36
  286. package/plugins/ai-delivery/skills/worktree-lifecycle/SKILL.md +14 -15
  287. package/dist/investigationCompletion.test.js +0 -728
  288. package/dist/investigationCompletion.test.js.map +0 -1
  289. package/dist/setup.d.ts +0 -60
  290. package/dist/setup.js +0 -585
  291. package/dist/setup.js.map +0 -1
  292. package/dist/setup.test.js +0 -3058
  293. package/dist/setup.test.js.map +0 -1
  294. package/dist/worktreeTransition.d.ts +0 -211
  295. package/dist/worktreeTransition.js +0 -1037
  296. package/dist/worktreeTransition.js.map +0 -1
  297. package/dist/worktreeTransition.test.js +0 -1191
  298. package/dist/worktreeTransition.test.js.map +0 -1
  299. /package/dist/{investigationCompletion.test.d.ts → boardReconcile.test.d.ts} +0 -0
  300. /package/dist/{setup.test.d.ts → build.test.d.ts} +0 -0
  301. /package/dist/{worktreeTransition.test.d.ts → callerErrors.test.d.ts} +0 -0
@@ -1,433 +1,454 @@
1
- import { z } from 'zod';
2
- import { DeliveryError } from './errors.js';
3
- export const ISSUE_CONTRACT_VERSION = 'ai-delivery.issue@1';
4
- export const ISSUE_BODY_MARKER = '<!-- ai-delivery:issue@1 -->';
5
- const DATA_PREFIX = '<!-- ai-delivery:issue-data@1 ';
1
+ import { z } from "zod";
2
+ import { DeliveryError } from "./errors.js";
3
+ const ISSUE_CONTRACT_VERSION = "ai-delivery.issue@1";
4
+ const ISSUE_BODY_MARKER = "<!-- ai-delivery:issue@1 -->";
5
+ const DATA_PREFIX = "<!-- ai-delivery:issue-data@1 ";
6
6
  const START_FOOTER = /\n\n<!-- ai-delivery-start-intent: sha256:[a-f0-9]{64} -->\n<!-- ai-delivery-start: sha256:[a-f0-9]{64} -->$/u;
7
- export function issueStartFooter(body) {
8
- return START_FOOTER.exec(body)?.[0] ?? '';
7
+ function issueStartFooter(body) {
8
+ return START_FOOTER.exec(body)?.[0] ?? "";
9
+ }
10
+ const CREATE_FOOTER = /\n\n<!-- ai-delivery-create: sha256:[a-f0-9]{64} intent: sha256:[a-f0-9]{64} -->$/u;
11
+ function issueTrackingFooter(body) {
12
+ return CREATE_FOOTER.exec(body)?.[0] ?? issueStartFooter(body);
9
13
  }
10
14
  const Text = z.string();
11
15
  const Strings = z.array(Text);
12
16
  const AcceptanceCriterion = z.strictObject({ behavior: Text, verifiedBy: Text });
13
- export const IssueDeferral = z.strictObject({
14
- until: z.iso.date().optional(),
15
- trigger: z.string().trim().min(1).max(2000).optional(),
17
+ const IssueDeferral = z.strictObject({
18
+ until: z.iso.date().optional(),
19
+ trigger: z.string().trim().min(1).max(2e3).optional()
16
20
  });
17
- export const IssueDeferralPatch = {
18
- defer: IssueDeferral.optional(),
19
- undefer: z.literal(true).optional(),
21
+ const IssueDeferralPatch = {
22
+ defer: IssueDeferral.optional(),
23
+ undefer: z.literal(true).optional()
20
24
  };
21
- export function requireDeferralPatch(value) {
22
- const parsed = z.strictObject(IssueDeferralPatch).safeParse(value);
23
- if (!parsed.success || (value.defer !== undefined && value.undefer !== undefined))
24
- throw new DeliveryError('Choose a valid defer condition or explicit undefer, never both.');
25
+ function requireDeferralPatch(value) {
26
+ const parsed = z.strictObject(IssueDeferralPatch).safeParse(value);
27
+ if (!parsed.success || value.defer !== void 0 && value.undefer !== void 0)
28
+ throw new DeliveryError("Choose a valid defer condition or explicit undefer, never both.");
25
29
  }
26
- /** Drafts permit incomplete requirements, but never secret-bearing public content. */
27
- export const IssueFields = z.strictObject({
28
- title: Text,
29
- issueType: Text.optional(),
30
- points: z.number().int().optional(),
31
- problem: Text.default(''),
32
- outcome: Text.default(''),
33
- acceptanceCriteria: z.array(AcceptanceCriterion).default([]),
34
- outOfScope: Strings.default([]),
35
- openQuestions: Strings.default([]),
36
- context: z
37
- .strictObject({ components: Strings.default([]), files: Strings.default([]), evidence: Strings.default([]) })
38
- .default({ components: [], files: [], evidence: [] }),
39
- bug: z
40
- .strictObject({ steps: Strings, expected: Text, actual: Text, reproducibility: Text, environment: Text })
41
- .optional(),
42
- draft: z.boolean().default(false),
43
- deferral: IssueDeferral.optional(),
44
- legacyBody: Text.optional(),
45
- retainLegacyBody: z.boolean().optional(),
30
+ const IssueFields = z.strictObject({
31
+ title: Text.describe(
32
+ 'Ready issues need 10\u201380 characters naming the specific change, with no "Bug:" or "[Task]" prefix.'
33
+ ),
34
+ issueType: Text.optional(),
35
+ points: z.number().int().optional().describe("Ready non-epic issues need Points 1\u20138 from the Points field's options (usually 1, 2, 3, 5 or 8)."),
36
+ epic: z.literal(true).optional(),
37
+ problem: Text.default(""),
38
+ outcome: Text.default(""),
39
+ acceptanceCriteria: z.array(AcceptanceCriterion).default([]),
40
+ outOfScope: Strings.default([]),
41
+ openQuestions: Strings.default([]),
42
+ context: z.strictObject({ components: Strings.default([]), files: Strings.default([]), evidence: Strings.default([]) }).default({ components: [], files: [], evidence: [] }),
43
+ bug: z.strictObject({ steps: Strings, expected: Text, actual: Text, reproducibility: Text, environment: Text }).optional().describe("Ready Bug issues need non-empty steps, expected, actual, reproducibility and environment."),
44
+ draft: z.boolean().default(false),
45
+ deferral: IssueDeferral.optional(),
46
+ legacyBody: Text.optional(),
47
+ retainLegacyBody: z.boolean().optional()
46
48
  });
47
- const StatusText = z
48
- .string()
49
- .trim()
50
- .min(1)
51
- .refine((value) => !/[\r\n]/u.test(value), 'Use one status line.');
52
- export const CreateIssueStatus = z.strictObject({ nextMilestone: StatusText.optional() });
53
- export const IssueStatusPatch = CreateIssueStatus.extend({
54
- blockers: StatusText.optional(),
55
- latestJournal: StatusText.optional(),
49
+ const StatusText = z.string().trim().min(1).refine((value) => !/[\r\n]/u.test(value), "Use one status line.");
50
+ const CreateIssueStatus = z.strictObject({ nextMilestone: StatusText.optional() });
51
+ const IssueStatusPatch = CreateIssueStatus.extend({
52
+ blockers: StatusText.optional(),
53
+ latestJournal: StatusText.optional()
54
+ });
55
+ const ISSUE_COMMENT_BODY_LIMIT = 65536;
56
+ const ProjectStatusPatch = z.strictObject({
57
+ status: z.enum(["Todo", "In Progress", "Blocked", "Done"]),
58
+ reason: z.string().trim().min(1)
59
+ }).superRefine((value, ctx) => {
60
+ if (`Requested Project Status: ${value.status}.
61
+
62
+ ${value.reason}`.length > ISSUE_COMMENT_BODY_LIMIT)
63
+ ctx.addIssue({
64
+ code: "custom",
65
+ path: ["reason"],
66
+ message: "Shorten the public reason to fit the issue comment limit."
67
+ });
68
+ if (secrets(value))
69
+ ctx.addIssue({
70
+ code: "custom",
71
+ path: ["reason"],
72
+ message: "Remove credentials and private keys from the public reason."
73
+ });
56
74
  });
57
75
  const IssueStatus = z.strictObject({
58
- state: z.enum(['Ready', 'Draft']),
59
- lastUpdated: z.iso.datetime(),
60
- nextMilestone: StatusText,
61
- blockers: StatusText,
62
- latestJournal: StatusText,
76
+ state: z.enum(["Ready", "Draft"]),
77
+ lastUpdated: z.iso.datetime(),
78
+ nextMilestone: StatusText,
79
+ blockers: StatusText,
80
+ latestJournal: StatusText
63
81
  });
64
- export function requireIssueStatus(schema, value) {
65
- const result = schema.safeParse(value);
66
- if (!result.success)
67
- throw new IssueValidationError(issueDiagnostics(result.error.issues));
68
- if (secrets(result.data))
69
- throw new IssueValidationError([
70
- hint('secrets', 'status', 'Remove credentials and private keys from public status fields.'),
71
- ]);
72
- return result.data;
82
+ function requireIssueStatus(schema, value) {
83
+ const result = schema.safeParse(value);
84
+ if (!result.success) throw new IssueValidationError(issueDiagnostics(result.error.issues));
85
+ if (secrets(result.data))
86
+ throw new IssueValidationError([
87
+ hint("secrets", "status", "Remove credentials and private keys from public status fields.")
88
+ ]);
89
+ return result.data;
73
90
  }
74
91
  const hint = (code, field, fixHint) => ({
75
- code,
76
- field,
77
- fixHint,
78
- message: fixHint,
92
+ code,
93
+ field,
94
+ fixHint,
95
+ message: fixHint
79
96
  });
80
97
  function secrets(value) {
81
- const strings = (item) => typeof item === 'string'
82
- ? [item]
83
- : Array.isArray(item)
84
- ? item.flatMap(strings)
85
- : item !== null && typeof item === 'object'
86
- ? Object.values(item).flatMap(strings)
87
- : [];
88
- const text = strings(value).join('\n');
89
- return /(?:-----BEGIN (?:RSA |EC |OPENSSH )?PRIVATE KEY-----|\b(?:gh[pousr]_[A-Za-z0-9]{20,}|github_pat_[A-Za-z0-9_]{20,}|sk-(?:proj-)?[A-Za-z0-9_-]{20,}|AKIA[A-Z0-9]{16})\b|\b(?:password|secret|api[_-]?key|access[_-]?token)\s*[=:]\s*["']?(?!<|\$|redacted\b|placeholder\b)[A-Za-z0-9_+/-]{8,})/iu.test(text);
98
+ const strings = (item) => typeof item === "string" ? [item] : Array.isArray(item) ? item.flatMap(strings) : item !== null && typeof item === "object" ? Object.values(item).flatMap(strings) : [];
99
+ const text = strings(value).join("\n");
100
+ return /(?:-----BEGIN (?:RSA |EC |OPENSSH )?PRIVATE KEY-----|\b(?:gh[pousr]_[A-Za-z0-9]{20,}|github_pat_[A-Za-z0-9_]{20,}|sk-(?:proj-)?[A-Za-z0-9_-]{20,}|AKIA[A-Z0-9]{16})\b|\b(?:password|secret|api[_-]?key|access[_-]?token)\s*[=:]\s*["']?(?!<|\$|redacted\b|placeholder\b)[A-Za-z0-9_+/-]{8,})/iu.test(
101
+ text
102
+ );
90
103
  }
91
104
  function secretRule(value, ctx) {
92
- if (secrets(value))
93
- ctx.addIssue({
94
- code: 'custom',
95
- path: ['body'],
96
- message: 'Remove credentials and private keys from public issue fields.',
97
- params: { issueCode: 'secrets' },
98
- });
105
+ if (secrets(value))
106
+ ctx.addIssue({
107
+ code: "custom",
108
+ path: ["body"],
109
+ message: "Remove credentials and private keys from public issue fields.",
110
+ params: { issueCode: "secrets" }
111
+ });
99
112
  }
100
- export const DraftIssue = IssueFields.superRefine(secretRule);
113
+ const DraftIssue = IssueFields.superRefine(secretRule);
101
114
  function readyRules(value, ctx) {
102
- const add = (code, field, fixHint) => ctx.addIssue({ code: 'custom', path: field, message: fixHint, params: { issueCode: code } });
103
- if (value.draft)
104
- add('draft', ['draft'], 'Resolve the draft fields and set draft to false before starting work.');
105
- if (value.points === undefined || value.points < 1 || value.points > 8)
106
- add('points', ['points'], 'Choose Points from 1 through 8; split a 13-point issue into sub-issues.');
107
- if (value.title.trim().length < 10 ||
108
- !/[\p{L}]/u.test(value.title) ||
109
- /^(?:fix|bug|task|feature|update|improve|test|issue|work)(?:\s+(?:it|this|stuff|things|issue))?[.!]?$/iu.test(value.title.trim()))
110
- add('title.specific', ['title'], 'Name the specific behavior or component that changes.');
111
- if (value.title.length > 80)
112
- add('title.length', ['title'], 'Shorten the title to at most 80 characters.');
113
- if (/^\s*(?:\[\s*(?:bug|feature|task)\s*\]|(?:bug|feature|task)\s*:)/iu.test(value.title))
114
- add('title.prefix', ['title'], 'Remove the issue-type prefix; use the native Issue Type field.');
115
- for (const field of ['problem', 'outcome'])
116
- if (!value[field].trim())
117
- add(field, [field], `Describe the ${field} in concrete terms.`);
118
- if (!value.acceptanceCriteria.length)
119
- add('acceptance-criteria', ['acceptanceCriteria'], 'Add an observable behavior and how it will be verified.');
120
- value.acceptanceCriteria.forEach((ac, index) => {
121
- if (!ac.behavior.trim() || !ac.verifiedBy.trim())
122
- add('acceptance-criteria.fields', ['acceptanceCriteria', index], 'Provide both behavior and verifiedBy for this criterion.');
123
- if (/^(?:.{1,100}\s)?(?:works(?:\s+(?:correctly|as expected|well|properly))?|(?:is|are)\s+(?:done|verified|reviewed|robust|seamless|appropriate|user[- ]friendly))[\s.!]*$/iu.test(ac.behavior) ||
124
- ac.behavior.trim().length < 12)
125
- add('acceptance-criteria.vague', ['acceptanceCriteria', index, 'behavior'], 'Replace vague wording with an observable input and result.');
126
- });
127
- if (!value.outOfScope.some((item) => item.trim()))
128
- add('out-of-scope', ['outOfScope'], 'Name at least one explicit non-goal.');
129
- if (value.openQuestions.length)
130
- add('open-questions', ['openQuestions'], 'Resolve each open question before marking the issue Ready.');
131
- if (value.issueType?.toLowerCase() === 'bug') {
132
- if (!value.bug)
133
- add('bug', ['bug'], 'Include steps, expected and actual results, reproducibility, and environment.');
134
- else {
135
- if (!value.bug.steps.length || value.bug.steps.some((step) => !step.trim()))
136
- add('bug.steps', ['bug', 'steps'], 'Provide nonempty ordered reproduction steps.');
137
- for (const field of ['expected', 'actual', 'reproducibility', 'environment'])
138
- if (!value.bug[field].trim())
139
- add(`bug.${field}`, ['bug', field], `Describe the bug's ${field}.`);
140
- }
115
+ const add = (code, field, fixHint) => ctx.addIssue({ code: "custom", path: field, message: fixHint, params: { issueCode: code } });
116
+ if (value.draft) add("draft", ["draft"], "Resolve the draft fields and set draft to false before starting work.");
117
+ if (!value.epic && (value.points === void 0 || value.points < 1 || value.points > 8))
118
+ add("points", ["points"], "Choose Points from 1 through 8; split a 13-point issue into sub-issues.");
119
+ if (value.title.trim().length < 10 || !/[\p{L}]/u.test(value.title) || /^(?:fix|bug|task|feature|update|improve|test|issue|work)(?:\s+(?:it|this|stuff|things|issue))?[.!]?$/iu.test(
120
+ value.title.trim()
121
+ ))
122
+ add("title.specific", ["title"], "Name the specific behavior or component that changes.");
123
+ if (value.title.length > 80) add("title.length", ["title"], "Shorten the title to at most 80 characters.");
124
+ if (/^\s*(?:\[\s*(?:bug|feature|task)\s*\]|(?:bug|feature|task)\s*:)/iu.test(value.title))
125
+ add("title.prefix", ["title"], "Remove the issue-type prefix; use the native Issue Type field.");
126
+ for (const field of ["problem", "outcome"])
127
+ if (!value[field].trim()) add(field, [field], `Describe the ${field} in concrete terms.`);
128
+ if (!value.acceptanceCriteria.length)
129
+ add("acceptance-criteria", ["acceptanceCriteria"], "Add an observable behavior and how it will be verified.");
130
+ value.acceptanceCriteria.forEach((ac, index) => {
131
+ if (!ac.behavior.trim() || !ac.verifiedBy.trim())
132
+ add(
133
+ "acceptance-criteria.fields",
134
+ ["acceptanceCriteria", index],
135
+ "Provide both behavior and verifiedBy for this criterion."
136
+ );
137
+ if (/^(?:.{1,100}\s)?(?:works(?:\s+(?:correctly|as expected|well|properly))?|(?:is|are)\s+(?:done|verified|reviewed|robust|seamless|appropriate|user[- ]friendly))[\s.!]*$/iu.test(
138
+ ac.behavior
139
+ ) || ac.behavior.trim().length < 12)
140
+ add(
141
+ "acceptance-criteria.vague",
142
+ ["acceptanceCriteria", index, "behavior"],
143
+ "Replace vague wording with an observable input and result."
144
+ );
145
+ });
146
+ if (!value.outOfScope.some((item) => item.trim()))
147
+ add("out-of-scope", ["outOfScope"], "Name at least one explicit non-goal.");
148
+ if (value.openQuestions.length)
149
+ add("open-questions", ["openQuestions"], "Resolve each open question before marking the issue Ready.");
150
+ if (value.issueType?.toLowerCase() === "bug") {
151
+ if (!value.bug)
152
+ add("bug", ["bug"], "Include steps, expected and actual results, reproducibility, and environment.");
153
+ else {
154
+ if (!value.bug.steps.length || value.bug.steps.some((step) => !step.trim()))
155
+ add("bug.steps", ["bug", "steps"], "Provide nonempty ordered reproduction steps.");
156
+ for (const field of ["expected", "actual", "reproducibility", "environment"])
157
+ if (!value.bug[field].trim()) add(`bug.${field}`, ["bug", field], `Describe the bug's ${field}.`);
141
158
  }
159
+ }
142
160
  }
143
- export const ReadyIssue = IssueFields.extend({
144
- title: Text.min(10).max(80),
145
- points: z.number().int().min(1).max(8),
146
- problem: Text.min(1),
147
- outcome: Text.min(1),
148
- acceptanceCriteria: z.array(AcceptanceCriterion).min(1),
149
- outOfScope: Strings.min(1),
150
- openQuestions: Strings.max(0).default([]),
151
- draft: z.literal(false).default(false),
152
- })
153
- .superRefine(secretRule)
154
- .superRefine(readyRules);
161
+ const ReadyIssue = IssueFields.extend({
162
+ title: Text.min(10).max(80),
163
+ points: z.number().int().min(1).max(8).optional(),
164
+ problem: Text.min(1),
165
+ outcome: Text.min(1),
166
+ acceptanceCriteria: z.array(AcceptanceCriterion).min(1),
167
+ outOfScope: Strings.min(1),
168
+ openQuestions: Strings.max(0).default([]),
169
+ draft: z.literal(false).default(false)
170
+ }).superRefine(secretRule).superRefine(readyRules).meta({ anyOf: [{ properties: { epic: { const: true } }, required: ["epic"] }, { required: ["points"] }] });
155
171
  const ReadySemantics = IssueFields.superRefine(secretRule).superRefine(readyRules);
156
- /** Portable structural schemas; semantic refinements are enforced by the write/readiness boundary. */
157
- export const ISSUE_JSON_SCHEMAS = {
158
- version: ISSUE_CONTRACT_VERSION,
159
- draft: z.toJSONSchema(DraftIssue),
160
- ready: z.toJSONSchema(ReadyIssue),
172
+ const ISSUE_JSON_SCHEMAS = {
173
+ version: ISSUE_CONTRACT_VERSION,
174
+ draft: z.toJSONSchema(DraftIssue),
175
+ ready: z.toJSONSchema(ReadyIssue)
161
176
  };
162
- /** Patch fields share the canonical validators but deliberately have no defaults. */
163
- export const IssueWriteFields = {
164
- title: IssueFields.shape.title.optional(),
165
- issueType: IssueFields.shape.issueType,
166
- points: IssueFields.shape.points,
167
- problem: IssueFields.shape.problem.removeDefault().optional(),
168
- outcome: IssueFields.shape.outcome.removeDefault().optional(),
169
- acceptanceCriteria: IssueFields.shape.acceptanceCriteria.removeDefault().optional(),
170
- outOfScope: IssueFields.shape.outOfScope.removeDefault().optional(),
171
- openQuestions: IssueFields.shape.openQuestions.removeDefault().optional(),
172
- context: IssueFields.shape.context.removeDefault().optional(),
173
- bug: IssueFields.shape.bug,
174
- draft: IssueFields.shape.draft.removeDefault().optional(),
175
- retainLegacyBody: IssueFields.shape.retainLegacyBody,
177
+ const IssueWriteFields = {
178
+ title: IssueFields.shape.title.optional(),
179
+ issueType: IssueFields.shape.issueType,
180
+ points: IssueFields.shape.points,
181
+ epic: IssueFields.shape.epic,
182
+ problem: IssueFields.shape.problem.removeDefault().optional(),
183
+ outcome: IssueFields.shape.outcome.removeDefault().optional(),
184
+ acceptanceCriteria: IssueFields.shape.acceptanceCriteria.removeDefault().optional(),
185
+ outOfScope: IssueFields.shape.outOfScope.removeDefault().optional(),
186
+ openQuestions: IssueFields.shape.openQuestions.removeDefault().optional(),
187
+ context: IssueFields.shape.context.removeDefault().optional(),
188
+ bug: IssueFields.shape.bug,
189
+ draft: IssueFields.shape.draft.removeDefault().optional(),
190
+ retainLegacyBody: IssueFields.shape.retainLegacyBody
176
191
  };
177
- export const IssueWriteSchema = z.strictObject(IssueWriteFields);
178
- /** Keep advertised structural schemas while returning domain diagnostics before SDK error wrapping. */
179
- export function issueInputSchema(schema) {
180
- return schema.refine(() => true, {
181
- when: ({ issues }) => {
182
- // Parsed values have already lost unknown keys. Preserve the original structural failures.
183
- if (issues.length)
184
- throw new IssueValidationError(issueDiagnostics(issues));
185
- return true;
186
- },
187
- });
192
+ const IssueWriteSchema = z.strictObject(IssueWriteFields);
193
+ function issueInputSchema(schema) {
194
+ return schema.refine(() => true, {
195
+ when: ({ issues }) => {
196
+ if (issues.length) throw new IssueValidationError(issueDiagnostics(issues));
197
+ return true;
198
+ }
199
+ });
188
200
  }
189
201
  function issueDiagnostics(issues) {
190
- const seen = new Set();
191
- return issues
192
- .map((issue) => {
193
- const field = (issue.path ?? []).map(String).join('.') || 'issue';
194
- const code = issue.code === 'custom' && typeof issue.params?.issueCode === 'string'
195
- ? issue.params.issueCode
196
- : field === 'points'
197
- ? 'points'
198
- : field === 'title'
199
- ? 'title.length'
200
- : field === 'outOfScope'
201
- ? 'out-of-scope'
202
- : field === 'openQuestions'
203
- ? 'open-questions'
204
- : field === 'acceptanceCriteria'
205
- ? 'acceptance-criteria'
206
- : field === 'draft'
207
- ? 'draft'
208
- : issue.code === 'unrecognized_keys'
209
- ? 'field.unknown'
210
- : 'field.type';
211
- return hint(code, field, code === 'points'
212
- ? 'Choose Points from 1 through 8; split a 13-point issue into sub-issues.'
213
- : issue.code === 'unrecognized_keys'
214
- ? 'Remove unrecognized fields from ' + field + '.'
215
- : (issue.message ??
216
- (issue.code === 'invalid_type'
217
- ? 'Provide a valid ' + issue.expected + ' value.'
218
- : 'Provide a value satisfying the declared issue field schema.')));
219
- })
220
- .filter((issue) => {
221
- const key = issue.code + ':' + issue.field;
222
- if (seen.has(key))
223
- return false;
224
- seen.add(key);
225
- return true;
226
- });
202
+ const seen = /* @__PURE__ */ new Set();
203
+ return issues.map((issue) => {
204
+ const field = (issue.path ?? []).map(String).join(".") || "issue";
205
+ const code = issue.code === "custom" && typeof issue.params?.issueCode === "string" ? issue.params.issueCode : field === "points" ? "points" : field === "title" ? "title.length" : field === "outOfScope" ? "out-of-scope" : field === "openQuestions" ? "open-questions" : field === "acceptanceCriteria" ? "acceptance-criteria" : field === "draft" ? "draft" : issue.code === "unrecognized_keys" ? "field.unknown" : "field.type";
206
+ return hint(
207
+ code,
208
+ field,
209
+ code === "points" ? "Choose Points from 1 through 8; split a 13-point issue into sub-issues." : issue.code === "unrecognized_keys" ? "Remove unrecognized fields from " + field + "." : issue.message ?? (issue.code === "invalid_type" ? "Provide a valid " + issue.expected + " value." : "Provide a value satisfying the declared issue field schema.")
210
+ );
211
+ }).filter((issue) => {
212
+ const key = issue.code + ":" + issue.field;
213
+ if (seen.has(key)) return false;
214
+ seen.add(key);
215
+ return true;
216
+ });
227
217
  }
228
- export function validateIssue(value, ready = true) {
229
- const parsed = (ready ? ReadyIssue : DraftIssue).safeParse(value);
230
- if (parsed.success)
231
- return { issue: parsed.data, failures: [] };
232
- const semantic = ready ? ReadySemantics.safeParse(value) : undefined;
233
- const issues = [...(semantic?.success === false ? semantic.error.issues : []), ...parsed.error.issues];
234
- return { failures: issueDiagnostics(issues) };
218
+ function validateIssue(value, ready = true) {
219
+ const parsed = (ready ? ReadyIssue : DraftIssue).safeParse(value);
220
+ if (parsed.success) return { issue: parsed.data, failures: [] };
221
+ const semantic = ready ? ReadySemantics.safeParse(value) : void 0;
222
+ const issues = [...semantic?.success === false ? semantic.error.issues : [], ...parsed.error.issues];
223
+ return { failures: issueDiagnostics(issues) };
235
224
  }
236
- export class IssueValidationError extends DeliveryError {
237
- failures;
238
- constructor(failures) {
239
- super(JSON.stringify({ contract: ISSUE_CONTRACT_VERSION, failures }));
240
- this.failures = failures;
241
- }
225
+ class IssueValidationError extends DeliveryError {
226
+ constructor(failures) {
227
+ super(JSON.stringify({ contract: ISSUE_CONTRACT_VERSION, failures }));
228
+ this.failures = failures;
229
+ }
230
+ failures;
242
231
  }
243
- export function requireIssue(value) {
244
- const structural = IssueFields.safeParse(value);
245
- const result = validateIssue(value, !structural.success || !structural.data.draft);
246
- if (!result.issue)
247
- throw new IssueValidationError(result.failures);
248
- return result.issue;
232
+ function requireIssue(value) {
233
+ const structural = IssueFields.safeParse(value);
234
+ const result = validateIssue(value, !structural.success || !structural.data.draft);
235
+ if (!result.issue) throw new IssueValidationError(result.failures);
236
+ return result.issue;
249
237
  }
250
- const escapeStatus = (value) => value
251
- .replaceAll('&', '&amp;')
252
- .replaceAll('<', '&lt;')
253
- .replaceAll('>', '&gt;')
254
- .replace(/[\\`*_[\]]/gu, '\\$&');
255
- const unescapeStatus = (value) => value
256
- .replace(/\\([\\`*_[\]])/gu, '$1')
257
- .replaceAll('&lt;', '<')
258
- .replaceAll('&gt;', '>')
259
- .replaceAll('&amp;', '&');
260
- export function renderIssueBody(value, status, legacyFormatting = false) {
261
- const item = DraftIssue.parse(value);
262
- if (status !== undefined)
263
- requireIssueStatus(IssueStatus, status);
264
- const list = (values) => (values.length ? values.map((v) => `- ${v}`).join('\n') : '(none)');
265
- const parts = [
266
- ISSUE_BODY_MARKER,
267
- '## Status',
268
- status === undefined
269
- ? item.draft
270
- ? 'Draft — parked; not ready to work.'
271
- : 'Ready'
272
- : `- **State:** ${status.state}\n- **Last updated:** ${status.lastUpdated} UTC\n- **Next milestone:** ${escapeStatus(status.nextMilestone)}\n- **Blockers:** ${escapeStatus(status.blockers)}\n- **Latest journal:** ${escapeStatus(status.latestJournal)}`,
273
- '## Problem',
274
- item.problem,
275
- '## Outcome',
276
- item.outcome,
277
- ...(item.deferral === undefined ? [] : ['## Deferral', `Deferred: ${JSON.stringify(item.deferral)}`]),
278
- '## Acceptance criteria',
279
- item.acceptanceCriteria
280
- .map((ac) => legacyFormatting
281
- ? `- [ ] ${ac.behavior}\n Verified by: ${ac.verifiedBy}`
282
- : `- [ ] ${ac.behavior.replace(/\n/gu, '\n ')}${ac.behavior.includes('\n') ? '\n' : ''}\n Verified by: ${ac.verifiedBy.replace(/\n/gu, '\n ')}`)
283
- .join('\n'),
284
- '## Out of scope',
285
- list(item.outOfScope),
286
- '## Open questions',
287
- list(item.openQuestions),
288
- '## Context',
289
- `Components:\n${list(item.context.components)}\n\nFiles:\n${list(item.context.files)}\n\nEvidence:\n${list(item.context.evidence)}`,
290
- ];
291
- if (item.bug)
292
- parts.push('## Bug', `Steps:\n${list(item.bug.steps)}\n\nExpected: ${item.bug.expected}\n\nActual: ${item.bug.actual}\n\nReproducibility: ${item.bug.reproducibility}\n\nEnvironment: ${item.bug.environment}`);
293
- if (item.legacyBody !== undefined && item.retainLegacyBody !== false)
294
- parts.push('## Preserved legacy body', item.legacyBody);
295
- // Escape comment delimiters without altering decoded data. Exact render equality detects human/payload divergence.
296
- parts.push(`${DATA_PREFIX}${JSON.stringify(item).replaceAll('<', '\\u003c').replaceAll('>', '\\u003e')} -->`);
297
- return parts.join('\n\n') + '\n';
238
+ const escapeStatus = (value) => value.replaceAll("&", "&amp;").replaceAll("<", "&lt;").replaceAll(">", "&gt;").replace(/[\\`*_[\]]/gu, "\\$&");
239
+ const unescapeStatus = (value) => value.replace(/\\([\\`*_[\]])/gu, "$1").replaceAll("&lt;", "<").replaceAll("&gt;", ">").replaceAll("&amp;", "&");
240
+ function renderIssueBody(value, status, legacyFormatting = false) {
241
+ const item = DraftIssue.parse(value);
242
+ if (status !== void 0) requireIssueStatus(IssueStatus, status);
243
+ const list = (values) => values.length ? values.map((v) => `- ${v}`).join("\n") : "(none)";
244
+ const parts = [
245
+ ISSUE_BODY_MARKER,
246
+ "## Status",
247
+ status === void 0 ? item.draft ? "Draft \u2014 parked; not ready to work." : "Ready" : `- **State:** ${status.state}
248
+ - **Last updated:** ${status.lastUpdated} UTC
249
+ - **Next milestone:** ${escapeStatus(status.nextMilestone)}
250
+ - **Blockers:** ${escapeStatus(status.blockers)}
251
+ - **Latest journal:** ${escapeStatus(status.latestJournal)}`,
252
+ "## Problem",
253
+ item.problem,
254
+ "## Outcome",
255
+ item.outcome,
256
+ ...item.deferral === void 0 ? [] : ["## Deferral", `Deferred: ${JSON.stringify(item.deferral)}`],
257
+ "## Acceptance criteria",
258
+ item.acceptanceCriteria.map(
259
+ (ac) => legacyFormatting ? `- [ ] ${ac.behavior}
260
+ Verified by: ${ac.verifiedBy}` : `- [ ] ${ac.behavior.replace(/\n/gu, "\n ")}${ac.behavior.includes("\n") ? "\n" : ""}
261
+ Verified by: ${ac.verifiedBy.replace(/\n/gu, "\n ")}`
262
+ ).join("\n"),
263
+ "## Out of scope",
264
+ list(item.outOfScope),
265
+ "## Open questions",
266
+ list(item.openQuestions),
267
+ "## Context",
268
+ `Components:
269
+ ${list(item.context.components)}
270
+
271
+ Files:
272
+ ${list(item.context.files)}
273
+
274
+ Evidence:
275
+ ${list(item.context.evidence)}`
276
+ ];
277
+ if (item.bug)
278
+ parts.push(
279
+ "## Bug",
280
+ `Steps:
281
+ ${list(item.bug.steps)}
282
+
283
+ Expected: ${item.bug.expected}
284
+
285
+ Actual: ${item.bug.actual}
286
+
287
+ Reproducibility: ${item.bug.reproducibility}
288
+
289
+ Environment: ${item.bug.environment}`
290
+ );
291
+ if (item.legacyBody !== void 0 && item.retainLegacyBody !== false)
292
+ parts.push("## Preserved legacy body", item.legacyBody);
293
+ parts.push(`${DATA_PREFIX}${JSON.stringify(item).replaceAll("<", "\\u003c").replaceAll(">", "\\u003e")} -->`);
294
+ return parts.join("\n\n") + "\n";
298
295
  }
299
296
  function section(body, names) {
300
- const lines = body.split(/\r?\n/u);
301
- const start = lines.findIndex((line) => names.includes(line
302
- .replace(/^#{1,6}\s+/u, '')
303
- .trim()
304
- .toLowerCase()));
305
- if (start < 0)
306
- return '';
307
- const end = lines.findIndex((line, index) => index > start && /^#{1,6}\s/u.test(line));
308
- return lines
309
- .slice(start + 1, end < 0 ? undefined : end)
310
- .join('\n')
311
- .trim();
297
+ const lines = body.split(/\r?\n/u);
298
+ const start = lines.findIndex(
299
+ (line) => names.includes(
300
+ line.replace(/^#{1,6}\s+/u, "").trim().toLowerCase()
301
+ )
302
+ );
303
+ if (start < 0) return "";
304
+ const end = lines.findIndex((line, index) => index > start && /^#{1,6}\s/u.test(line));
305
+ return lines.slice(start + 1, end < 0 ? void 0 : end).join("\n").trim();
312
306
  }
313
- /** Lenient conversion retains every legacy byte, and never invents verification or bug evidence. */
314
- export function parseIssueBody(body, metadata) {
315
- if (body.trimStart().startsWith(ISSUE_BODY_MARKER)) {
316
- const start = body.lastIndexOf(DATA_PREFIX);
317
- const end = body.indexOf(' -->', start);
318
- if (start < 0 || end < 0)
319
- throw new IssueValidationError([
320
- hint('body.canonical', 'body', 'Restore the complete canonical issue data and generated body.'),
321
- ]);
322
- let decoded;
323
- try {
324
- decoded = JSON.parse(body.slice(start + DATA_PREFIX.length, end));
325
- }
326
- catch {
327
- throw new IssueValidationError([hint('body.canonical', 'body', 'Restore valid canonical issue data.')]);
328
- }
329
- const result = validateIssue(decoded, false);
330
- if (!result.issue)
331
- throw new IssueValidationError(result.failures);
332
- const displayed = body.slice((ISSUE_BODY_MARKER + '\n\n## Status\n\n').length, body.indexOf('\n\n## Problem\n\n'));
333
- let status;
334
- if (displayed !== 'Ready' && displayed !== 'Draft — parked; not ready to work.') {
335
- const match = /^- \*\*State:\*\* (Ready|Draft)\n- \*\*Last updated:\*\* (\S+) UTC\n- \*\*Next milestone:\*\* ([^\r\n]+)\n- \*\*Blockers:\*\* ([^\r\n]+)\n- \*\*Latest journal:\*\* ([^\r\n]+)$/u.exec(displayed);
336
- if (!match)
337
- throw new IssueValidationError([
338
- hint('body.canonical', 'status', 'Restore the complete unambiguous status block.'),
339
- ]);
340
- status = requireIssueStatus(IssueStatus, {
341
- state: match[1],
342
- lastUpdated: match[2],
343
- nextMilestone: unescapeStatus(match[3]),
344
- blockers: unescapeStatus(match[4]),
345
- latestJournal: unescapeStatus(match[5]),
346
- });
347
- if (status.state !== (result.issue.draft ? 'Draft' : 'Ready'))
348
- throw new IssueValidationError([
349
- hint('body.canonical', 'status', 'Status state must agree with the typed draft field.'),
350
- ]);
351
- }
352
- const footer = issueStartFooter(body);
353
- const canonical = footer ? body.slice(0, -footer.length) : body;
354
- const legacyFormatting = renderIssueBody(result.issue, status) !== canonical;
355
- if ((legacyFormatting && renderIssueBody(result.issue, status, true) !== canonical) ||
356
- result.issue.title !== metadata.title)
357
- throw new IssueValidationError([
358
- hint('body.canonical', 'body', 'Update typed fields instead of editing only one copy of canonical content.'),
359
- ]);
360
- return {
361
- issue: result.issue,
362
- legacy: false,
363
- ...(status === undefined ? {} : { status }),
364
- ...(legacyFormatting ? { legacyFormatting: true } : {}),
365
- };
307
+ function parseIssueBody(body, metadata) {
308
+ if (body.trimStart().startsWith(ISSUE_BODY_MARKER)) {
309
+ const start = body.lastIndexOf(DATA_PREFIX);
310
+ const end = body.indexOf(" -->", start);
311
+ if (start < 0 || end < 0)
312
+ throw new IssueValidationError([
313
+ hint("body.canonical", "body", "Restore the complete canonical issue data and generated body.")
314
+ ]);
315
+ let decoded;
316
+ try {
317
+ decoded = JSON.parse(body.slice(start + DATA_PREFIX.length, end));
318
+ } catch {
319
+ throw new IssueValidationError([hint("body.canonical", "body", "Restore valid canonical issue data.")]);
366
320
  }
367
- const verification = section(body, ['verification', 'validation', 'tests']);
368
- const acText = section(body, ['acceptance criteria', 'acceptance']);
369
- const acceptanceCriteria = acText.split(/\n(?=\s*[-*+]\s+\[[ xX]\])/u).flatMap((block) => {
370
- const match = /^\s*[-*+]\s+\[[ xX]\]\s+([\s\S]+)/u.exec(block);
371
- if (!match)
372
- return [];
373
- const [behavior = '', verifiedBy = verification] = match[1].split(/\n\s*(?:Verified by:|Verified by)\s*/iu);
374
- return [{ behavior: behavior.trim(), verifiedBy: verifiedBy.trim() }];
375
- });
376
- const items = (s) => s
377
- .split(/\r?\n/u)
378
- .map((line) => line.replace(/^\s*[-*+]\s+/u, '').trim())
379
- .filter(Boolean);
380
- const scope = section(body, ['scope', 'context']);
381
- const bug = metadata.issueType?.toLowerCase() === 'bug'
382
- ? {
383
- steps: items(section(body, ['steps', 'steps to reproduce'])),
384
- expected: section(body, ['expected', 'expected results']),
385
- actual: section(body, ['actual', 'actual results']),
386
- reproducibility: section(body, ['reproducibility']),
387
- environment: section(body, ['environment']),
388
- }
389
- : undefined;
390
- const converted = validateIssue({
391
- ...metadata,
392
- problem: section(body, ['problem']),
393
- outcome: section(body, ['outcome']),
394
- acceptanceCriteria,
395
- outOfScope: items(section(body, ['out of scope', 'non-goals'])),
396
- openQuestions: items(section(body, ['open questions'])),
397
- context: { components: [], files: scope ? [scope] : [], evidence: verification ? [verification] : [] },
398
- ...(bug === undefined ? {} : { bug }),
399
- draft: /^draft\b/iu.test(section(body, ['status'])),
400
- legacyBody: body,
401
- }, false);
402
- if (!converted.issue)
403
- throw new IssueValidationError(converted.failures);
404
- return { issue: converted.issue, legacy: true };
321
+ const result = validateIssue(decoded, false);
322
+ if (!result.issue) throw new IssueValidationError(result.failures);
323
+ const displayed = body.slice((ISSUE_BODY_MARKER + "\n\n## Status\n\n").length, body.indexOf("\n\n## Problem\n\n"));
324
+ let status;
325
+ if (displayed !== "Ready" && displayed !== "Draft \u2014 parked; not ready to work.") {
326
+ const match = /^- \*\*State:\*\* (Ready|Draft)\n- \*\*Last updated:\*\* (\S+) UTC\n- \*\*Next milestone:\*\* ([^\r\n]+)\n- \*\*Blockers:\*\* ([^\r\n]+)\n- \*\*Latest journal:\*\* ([^\r\n]+)$/u.exec(
327
+ displayed
328
+ );
329
+ if (!match)
330
+ throw new IssueValidationError([
331
+ hint("body.canonical", "status", "Restore the complete unambiguous status block.")
332
+ ]);
333
+ status = requireIssueStatus(IssueStatus, {
334
+ state: match[1],
335
+ lastUpdated: match[2],
336
+ nextMilestone: unescapeStatus(match[3]),
337
+ blockers: unescapeStatus(match[4]),
338
+ latestJournal: unescapeStatus(match[5])
339
+ });
340
+ if (status.state !== (result.issue.draft ? "Draft" : "Ready"))
341
+ throw new IssueValidationError([
342
+ hint("body.canonical", "status", "Status state must agree with the typed draft field.")
343
+ ]);
344
+ }
345
+ const footer = issueTrackingFooter(body);
346
+ const canonical = footer ? body.slice(0, -footer.length) : body;
347
+ const legacyFormatting = renderIssueBody(result.issue, status) !== canonical;
348
+ if (legacyFormatting && renderIssueBody(result.issue, status, true) !== canonical || result.issue.title !== metadata.title)
349
+ throw new IssueValidationError([
350
+ hint("body.canonical", "body", "Update typed fields instead of editing only one copy of canonical content.")
351
+ ]);
352
+ return {
353
+ issue: result.issue,
354
+ legacy: false,
355
+ ...status === void 0 ? {} : { status },
356
+ ...legacyFormatting ? { legacyFormatting: true } : {}
357
+ };
358
+ }
359
+ const verification = section(body, ["verification", "validation", "tests"]);
360
+ const acText = section(body, ["acceptance criteria", "acceptance"]);
361
+ const acceptanceCriteria = acText.split(/\n(?=\s*[-*+]\s+\[[ xX]\])/u).flatMap((block) => {
362
+ const match = /^\s*[-*+]\s+\[[ xX]\]\s+([\s\S]+)/u.exec(block);
363
+ if (!match) return [];
364
+ const [behavior = "", verifiedBy = verification] = match[1].split(/\n\s*(?:Verified by:|Verified by)\s*/iu);
365
+ return [{ behavior: behavior.trim(), verifiedBy: verifiedBy.trim() }];
366
+ });
367
+ const items = (s) => s.split(/\r?\n/u).map((line) => line.replace(/^\s*[-*+]\s+/u, "").trim()).filter(Boolean);
368
+ const scope = section(body, ["scope", "context"]);
369
+ const bug = metadata.issueType?.toLowerCase() === "bug" ? {
370
+ steps: items(section(body, ["steps", "steps to reproduce"])),
371
+ expected: section(body, ["expected", "expected results"]),
372
+ actual: section(body, ["actual", "actual results"]),
373
+ reproducibility: section(body, ["reproducibility"]),
374
+ environment: section(body, ["environment"])
375
+ } : void 0;
376
+ const converted = validateIssue(
377
+ {
378
+ ...metadata,
379
+ problem: section(body, ["problem"]),
380
+ outcome: section(body, ["outcome"]),
381
+ acceptanceCriteria,
382
+ outOfScope: items(section(body, ["out of scope", "non-goals"])),
383
+ openQuestions: items(section(body, ["open questions"])),
384
+ context: { components: [], files: scope ? [scope] : [], evidence: verification ? [verification] : [] },
385
+ ...bug === void 0 ? {} : { bug },
386
+ draft: /^draft\b/iu.test(section(body, ["status"])),
387
+ legacyBody: body
388
+ },
389
+ false
390
+ );
391
+ if (!converted.issue) throw new IssueValidationError(converted.failures);
392
+ return { issue: converted.issue, legacy: true };
405
393
  }
406
- export function issueWarnings(issue, status, legacyFormatting = false) {
407
- const warnings = [];
408
- if (issue.acceptanceCriteria.length > 7)
409
- warnings.push(hint('many-criteria', 'acceptanceCriteria', 'Consider slicing more than seven criteria into smaller issues.'));
410
- if (!issue.acceptanceCriteria.some((ac) => /\b(?:edge|failure|fail|error|invalid|reject|refus|empty|missing|interrupt|timeout|boundary)/iu.test(ac.behavior)))
411
- warnings.push(hint('edge-case', 'acceptanceCriteria', 'Describe an edge or failure case.'));
412
- if (issue.issueType?.toLowerCase() === 'bug' &&
413
- !issue.acceptanceCriteria.some((ac) => /regression/iu.test(ac.behavior + ' ' + ac.verifiedBy)))
414
- warnings.push(hint('bug.regression', 'acceptanceCriteria', 'Add a regression test criterion for the bug.'));
415
- if (![...issue.context.files, ...issue.context.components].some((item) => item.trim()))
416
- warnings.push(hint('context', 'context', 'Name relevant components or files.'));
417
- const proofs = [...issue.context.evidence, ...issue.acceptanceCriteria.map((ac) => ac.verifiedBy)];
418
- if (proofs.length && proofs.every((proof) => /^(?:\/|[A-Za-z]:\\|~\/)/u.test(proof.trim())))
419
- warnings.push(hint('local-evidence', 'context.evidence', 'Use portable evidence in addition to machine-local paths.'));
420
- const body = renderIssueBody(issue, status, legacyFormatting);
421
- if (body.slice(0, body.lastIndexOf(DATA_PREFIX)).length > 4000)
422
- warnings.push(hint('body.length', 'body', 'Consider reducing a readable body over 4,000 characters.'));
423
- return warnings;
394
+ function issueWarnings(issue, status, legacyFormatting = false) {
395
+ const warnings = [];
396
+ if (issue.acceptanceCriteria.length > 7)
397
+ warnings.push(
398
+ hint("many-criteria", "acceptanceCriteria", "Consider slicing more than seven criteria into smaller issues.")
399
+ );
400
+ if (!issue.acceptanceCriteria.some(
401
+ (ac) => /\b(?:edge|failure|fail|error|invalid|reject|refus|empty|missing|interrupt|timeout|boundary)/iu.test(ac.behavior)
402
+ ))
403
+ warnings.push(hint("edge-case", "acceptanceCriteria", "Describe an edge or failure case."));
404
+ if (issue.issueType?.toLowerCase() === "bug" && !issue.acceptanceCriteria.some((ac) => /regression/iu.test(ac.behavior + " " + ac.verifiedBy)))
405
+ warnings.push(hint("bug.regression", "acceptanceCriteria", "Add a regression test criterion for the bug."));
406
+ if (![...issue.context.files, ...issue.context.components].some((item) => item.trim()))
407
+ warnings.push(hint("context", "context", "Name relevant components or files."));
408
+ const proofs = [...issue.context.evidence, ...issue.acceptanceCriteria.map((ac) => ac.verifiedBy)];
409
+ if (proofs.length && proofs.every((proof) => /^(?:\/|[A-Za-z]:\\|~\/)/u.test(proof.trim())))
410
+ warnings.push(
411
+ hint("local-evidence", "context.evidence", "Use portable evidence in addition to machine-local paths.")
412
+ );
413
+ const body = renderIssueBody(issue, status, legacyFormatting);
414
+ if (body.slice(0, body.lastIndexOf(DATA_PREFIX)).length > 4e3)
415
+ warnings.push(hint("body.length", "body", "Consider reducing a readable body over 4,000 characters."));
416
+ return warnings;
424
417
  }
425
- export function issueBodyDiff(before, after) {
426
- return [
427
- '--- prior body',
428
- '+++ canonical body',
429
- ...before.split('\n').map((line) => '-' + line),
430
- ...after.split('\n').map((line) => '+' + line),
431
- ].join('\n');
418
+ function issueBodyDiff(before, after) {
419
+ return [
420
+ "--- prior body",
421
+ "+++ canonical body",
422
+ ...before.split("\n").map((line) => "-" + line),
423
+ ...after.split("\n").map((line) => "+" + line)
424
+ ].join("\n");
432
425
  }
433
- //# sourceMappingURL=issueContract.js.map
426
+ export {
427
+ CreateIssueStatus,
428
+ DraftIssue,
429
+ ISSUE_BODY_MARKER,
430
+ ISSUE_COMMENT_BODY_LIMIT,
431
+ ISSUE_CONTRACT_VERSION,
432
+ ISSUE_JSON_SCHEMAS,
433
+ IssueDeferral,
434
+ IssueDeferralPatch,
435
+ IssueFields,
436
+ IssueStatusPatch,
437
+ IssueValidationError,
438
+ IssueWriteFields,
439
+ IssueWriteSchema,
440
+ ProjectStatusPatch,
441
+ ReadyIssue,
442
+ issueBodyDiff,
443
+ issueInputSchema,
444
+ issueStartFooter,
445
+ issueTrackingFooter,
446
+ issueWarnings,
447
+ parseIssueBody,
448
+ renderIssueBody,
449
+ requireDeferralPatch,
450
+ requireIssue,
451
+ requireIssueStatus,
452
+ validateIssue
453
+ };
454
+ //# sourceMappingURL=issueContract.js.map