@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
package/dist/cli.js CHANGED
@@ -1,205 +1,186 @@
1
1
  #!/usr/bin/env node
2
- import { readFileSync } from 'node:fs';
3
- import { Command } from 'commander';
4
- import { z } from 'zod';
5
- import { printCommandError, printCommandResult } from './cliResult.js';
6
- import { contextFor, executeTool } from './dispatch.js';
7
- import { listIssueSubissues } from './issue.js';
8
- import { listPrs, preflightReviewRoute, prChecks } from './pr.js';
9
- import { serveAiDeliveryMcp } from './mcp/index.js';
10
- import { planOfflineLegacyIssueMigration } from './services/legacyIssueMigration.js';
11
- import { PACKAGE_VERSION } from './version.js';
12
- import { managePlugin } from './pluginInstaller.js';
13
- import { IssueWriteSchema, IssueStatusPatch, IssueDeferralPatch } from './issueContract.js';
14
- import { NativeIssueDateFields } from './github/nativeIssueMetadata.js';
2
+ import { closeSync, constants, fstatSync, openSync, readFileSync, readSync, statSync } from "node:fs";
3
+ import { createHash } from "node:crypto";
4
+ import { createDeliveryGitHubClients } from "./github/client.js";
5
+ import { appCredentialSource, loadDeliverySettings } from "./config/deliveryConfig.js";
6
+ import { Command } from "commander";
7
+ import { z } from "zod";
8
+ import { printCommandError, printCommandResult } from "./cliResult.js";
9
+ import { contextFor, executeTool } from "./dispatch.js";
10
+ import { listIssueSubissues } from "./issue.js";
11
+ import { listPrs, preflightReviewRoute, prChecks, submitFormalReview } from "./pr.js";
12
+ import {
13
+ assertReviewVerdictTarget,
14
+ buildReviewArtifact,
15
+ parseReviewVerdict,
16
+ readGitHubReviewBase,
17
+ ReviewSubmissionError,
18
+ validateReviewTarget
19
+ } from "./review.js";
20
+ import { serveAiDeliveryMcp } from "./mcp/index.js";
21
+ import { planOfflineLegacyIssueMigration } from "./services/legacyIssueMigration.js";
22
+ import { PACKAGE_VERSION } from "./version.js";
23
+ import { managePlugin } from "./pluginInstaller.js";
24
+ import { IssueWriteSchema, IssueStatusPatch, IssueDeferralPatch, ProjectStatusPatch } from "./issueContract.js";
25
+ import { NativeIssueDateFields } from "./github/nativeIssueMetadata.js";
26
+ import { DeliveryError } from "./errors.js";
27
+ import { parseBoardReconcileRequest } from "./services/boardReconcileService.js";
28
+ import { renderDeliveryBoard } from "./deliveryBoard.js";
15
29
  const program = new Command();
16
- program
17
- .name('ai-delivery')
18
- .description('Generic GitHub issue and pull request delivery')
19
- .version(PACKAGE_VERSION)
20
- .option('--identity <name>', 'Configured author or reviewer identity')
21
- .option('--personal-auth', 'Explicit legacy personal-token author override')
22
- .option('--repo <owner/name>', 'GitHub repository owner/name; works from any directory')
23
- .option('--repo-root <path>', 'Launch directory or explicit clone for local operations', process.cwd());
24
- // Only the plugin command group owns a local --version input. Skip global option
25
- // values when selecting its parser so an unrelated argument named plugin has no effect.
30
+ program.name("ai-delivery").description("Generic GitHub issue and pull request delivery").version(PACKAGE_VERSION).option("--identity <name>", "Configured author or reviewer identity").option("--personal-auth", "Explicit legacy personal-token author override").option("--json", "Print JSON output").option("--verbose", "Include full bodies, diffs and routing with --json").option("--repo <owner/name>", "GitHub repository owner/name; works from any directory").option("--repo-root <path>", "Launch directory or explicit clone for local operations", process.cwd());
26
31
  for (let index = 2; index < process.argv.length; index++) {
27
- const argument = process.argv[index];
28
- const option = program.options.find((value) => value.long === argument.split('=')[0] || value.short === argument);
29
- if (option) {
30
- if (option.required && !argument.includes('='))
31
- index++;
32
- continue;
33
- }
34
- if (argument === 'plugin')
35
- program.enablePositionalOptions();
36
- break;
32
+ const argument = process.argv[index];
33
+ const option = program.options.find((value) => value.long === argument.split("=")[0] || value.short === argument);
34
+ if (option) {
35
+ if (option.required && !argument.includes("=")) index++;
36
+ continue;
37
+ }
38
+ if (argument === "plugin") program.enablePositionalOptions();
39
+ break;
37
40
  }
38
41
  function execution() {
39
- const options = program.opts();
40
- const identity = (options.identity ?? process.env.AI_DELIVERY_IDENTITY)?.trim() || undefined;
41
- return {
42
- repoRoot: options.repoRoot,
43
- ...(identity === undefined ? {} : { identity }),
44
- personalAuth: options.personalAuth === true,
45
- ...(options.repo === undefined ? {} : { repo: options.repo }),
46
- };
42
+ const options = program.opts();
43
+ const identity = (options.identity ?? process.env.AI_DELIVERY_IDENTITY)?.trim() || void 0;
44
+ return {
45
+ repoRoot: options.repoRoot,
46
+ ...options.verbose === true ? { verbose: true } : {},
47
+ ...identity === void 0 ? {} : { identity },
48
+ personalAuth: options.personalAuth === true,
49
+ ...options.repo === void 0 ? {} : { repo: options.repo }
50
+ };
47
51
  }
48
52
  function int(value) {
49
- return value === undefined ? undefined : Number(value);
53
+ return value === void 0 ? void 0 : Number(value);
50
54
  }
51
55
  function list(value) {
52
- return value === undefined
53
- ? undefined
54
- : value
55
- .split(',')
56
- .map((part) => part.trim())
57
- .filter(Boolean);
56
+ return value === void 0 ? void 0 : value.split(",").map((part) => part.trim()).filter(Boolean);
58
57
  }
59
58
  function ints(value) {
60
- return list(value)?.map(Number);
59
+ return list(value)?.map(Number);
61
60
  }
62
61
  function body(value, file) {
63
- if (value !== undefined && file !== undefined)
64
- throw new Error('Pass either --body or --body-file.');
65
- return file === undefined ? value : readFileSync(file, 'utf8');
62
+ if (value !== void 0 && file !== void 0) throw new Error("Pass either --body or --body-file.");
63
+ return file === void 0 ? value : readFileSync(file, "utf8");
66
64
  }
67
- function fields(file, overrides) {
68
- const value = file === undefined ? {} : JSON.parse(readFileSync(file, 'utf8'));
69
- return {
70
- ...IssueWriteSchema.extend({
71
- ...NativeIssueDateFields,
72
- ...IssueDeferralPatch,
73
- status: IssueStatusPatch.optional(),
74
- preserveHistory: z.boolean().optional(),
75
- }).parse(value),
76
- ...Object.fromEntries(Object.entries(overrides).filter(([, item]) => item !== undefined)),
77
- };
65
+ function fields(file, overrides, update = false) {
66
+ const value = file === void 0 ? {} : JSON.parse(readFileSync(file, "utf8"));
67
+ return {
68
+ ...IssueWriteSchema.extend({
69
+ ...NativeIssueDateFields,
70
+ ...IssueDeferralPatch,
71
+ status: IssueStatusPatch.optional(),
72
+ ...update ? { projectStatus: ProjectStatusPatch.optional() } : {},
73
+ preserveHistory: z.boolean().optional()
74
+ }).parse(value),
75
+ ...Object.fromEntries(Object.entries(overrides).filter(([, item]) => item !== void 0))
76
+ };
78
77
  }
79
78
  function run(name, input) {
80
- return executeTool(name, input, execution()).then((value) => printCommandResult(name, value));
79
+ const options = program.opts();
80
+ return executeTool(name, input, execution()).then(
81
+ (value) => printCommandResult(name, value, options.json === true && options.verbose === true)
82
+ );
81
83
  }
82
84
  function print(value) {
83
- process.stdout.write(`${JSON.stringify(value, null, 2)}\n`);
85
+ process.stdout.write(`${JSON.stringify(value, null, 2)}
86
+ `);
84
87
  }
85
- const plugin = program.command('plugin').description('Manage the ai-delivery native plugin');
86
- for (const action of ['install', 'doctor', 'preview', 'update', 'rollback', 'remove']) {
87
- const command = plugin
88
- .command(action)
89
- .requiredOption('--host <host>', 'Native host: codex or claude-code')
90
- .option('--scope <scope>', 'Native scope: user, project, or local; Codex supports user', 'user')
91
- .option('--dry-run', 'Describe the selected target without changing files or contacting native tools')
92
- .option('--json', 'Print the result as JSON');
93
- if (action === 'install' || action === 'update')
94
- command.requiredOption('--version <version>', 'Explicit published package version');
95
- if (action === 'doctor')
96
- command.option('--check-auth', 'Read configured role identities and repository access; requires explicit --repo');
97
- command.action(async (options) => {
98
- const result = await managePlugin({
99
- action,
100
- host: options.host,
101
- scope: options.scope,
102
- ...(options.version === undefined ? {} : { version: options.version }),
103
- dryRun: options.dryRun === true,
104
- checkAuth: options.checkAuth === true,
105
- ...(options.checkAuth && execution().repo ? { repo: execution().repo } : {}),
106
- repoRoot: execution().repoRoot,
107
- });
108
- if (options.json) {
109
- print(result);
110
- return;
111
- }
112
- process.stdout.write(`${result.dryRun ? 'Dry run: ' : ''}${result.host} ${result.scope}: ${action}; version ${result.version ?? 'none'}; installed ${result.installed}; changed ${result.changed}\n`);
113
- if (result.mcp)
114
- process.stdout.write(`Bundled MCP startup: ${result.mcp.startup}${result.mcp.error ? ` (${result.mcp.error})` : ''}\n`);
115
- if (result.diagnostics) {
116
- process.stdout.write(`Registration observations: ${result.diagnostics.registrations.length}; completeness ${result.diagnostics.completeness}; migration ${result.diagnostics.migration}; planned changes ${result.diagnostics.plannedChanges.length}\n`);
117
- for (const entry of result.diagnostics.registrations)
118
- process.stdout.write(`${entry.kind} ${entry.scope}: ownership ${entry.ownership}; source ${entry.source}; version ${entry.version ?? 'unknown'}\n`);
119
- process.stdout.write(`Unverified conditions: ${result.diagnostics.findings.join(', ')}\n`);
120
- }
121
- if (result.activation)
122
- process.stdout.write(`Native session loaded version: unverified. Installed observation: ${result.activation.installedVersion ?? 'unknown'}; separate startup: ${result.activation.startupVersion ?? 'not checked'}. Use the host's surface-specific activation guidance.\n`);
123
- if (result.recoveryRequired)
124
- process.stdout.write('Resume the interrupted original plugin command to recover this target.\n');
125
- if (result.authProbe)
126
- process.stdout.write(`Selected-runtime CLI auth probe: ${result.authProbe.outcome}; settings ${result.authProbe.settings}; process references ${result.authProbe.processReferences.status}; authentication ${result.authProbe.authentication.status}; repository access ${result.authProbe.repositoryAccess.status}${result.authProbe.reason ? ` (${result.authProbe.reason})` : ''}\nNative GUI credential propagation and counted exact-head approval remain unverified.\n`);
127
- });
88
+ function reconciliationFile(path) {
89
+ const limit = 16 * 1024 * 1024;
90
+ const stat = statSync(path);
91
+ if (!stat.isFile() || stat.size > limit)
92
+ throw new DeliveryError("Reconciliation files must be regular UTF-8 JSON files of at most 16 MiB.");
93
+ const bytes = readFileSync(path);
94
+ if (bytes.byteLength > limit) throw new DeliveryError("Reconciliation files exceed 16 MiB.");
95
+ return JSON.parse(new TextDecoder("utf-8", { fatal: true }).decode(bytes));
128
96
  }
129
- program
130
- .command('runtime:stage')
131
- .description('Stage a reviewed archive in a private directory; does not activate or admit it')
132
- .requiredOption('--archive <path>')
133
- .requiredOption('--archive-sha256 <digest>')
134
- .requiredOption('--package-version <version>')
135
- .requiredOption('--source-commit <sha>')
136
- .requiredOption('--config-digest <digest>')
137
- .requiredOption('--runtime-directory <path>')
138
- .option('--native-plugin-root <path>', 'Bind the exact reviewed native plugin root')
139
- .option('--max-aggregate-rss-bytes <bytes>', 'Sampled controller plus children RSS limit')
140
- .option('--max-new-output-bytes <bytes>', 'Owned stage and metadata output limit')
141
- .option('--min-free-disk-bytes <bytes>', 'Required free disk headroom')
142
- .option('--max-captured-output-bytes <bytes>', 'Retained command log cap; defaults to 1 MiB')
143
- .option('--authorize-stage', 'Explicit authority to stage this reviewed archive')
144
- .action(async (o) => run('runtime_stage', {
145
- authority: o.authorizeStage === true ? 'runtime:stage' : '',
146
- archivePath: o.archive,
147
- expectedArchiveSha256: o.archiveSha256,
148
- packageVersion: o.packageVersion,
149
- expectedSourceCommit: o.sourceCommit,
150
- expectedConfigDigest: o.configDigest,
151
- runtimeDirectory: o.runtimeDirectory,
152
- ...(o.nativePluginRoot === undefined ? {} : { nativePluginRoot: o.nativePluginRoot }),
153
- ...(['maxAggregateRssBytes', 'maxNewOutputBytes', 'minFreeDiskBytes', 'maxCapturedOutputBytes'].some((key) => o[key] !== undefined)
154
- ? {
155
- resourceBounds: {
156
- maxAggregateRssBytes: Number(o.maxAggregateRssBytes ?? 1024 ** 3),
157
- minFreeDiskBytes: Number(o.minFreeDiskBytes ?? 256 * 1024 ** 2),
158
- maxNewOutputBytes: Number(o.maxNewOutputBytes ?? 512 * 1024 ** 2),
159
- maxCapturedOutputBytes: Number(o.maxCapturedOutputBytes ?? 1024 ** 2),
160
- },
161
- }
162
- : {}),
163
- }));
164
- program
165
- .command('runtime:admit')
166
- .description('Explicitly publish the existing admission for an exact completed stage')
167
- .requiredOption('--stage-id <digest>')
168
- .requiredOption('--source-commit <sha>')
169
- .requiredOption('--config-digest <digest>')
170
- .requiredOption('--runtime-directory <path>')
171
- .option('--expected-prior <digest>', 'SHA-256 of the exact current private admission bytes')
172
- .option('--expected-absent', 'Explicitly require no current admission')
173
- .option('--authorize-admit', 'Explicit authority for the final admission write')
174
- .action(async (o) => {
175
- if ((o.expectedPrior === undefined) === (o.expectedAbsent !== true))
176
- throw new Error('Choose exactly one of --expected-prior or --expected-absent.');
177
- return run('runtime_admit', {
178
- authority: o.authorizeAdmit === true ? 'runtime:admit' : '',
179
- stageId: o.stageId,
180
- expectedSourceCommit: o.sourceCommit,
181
- expectedConfigDigest: o.configDigest,
182
- runtimeDirectory: o.runtimeDirectory,
183
- expectedPriorAdmissionSha256: o.expectedAbsent === true ? null : o.expectedPrior,
184
- });
185
- });
186
- program
187
- .command('create')
188
- .requiredOption('--title <title>')
189
- .option('--fields-file <path>', 'UTF-8 JSON typed fields; explicit CLI fields take precedence')
190
- .option('--draft', 'Explicitly write an incomplete parked draft')
191
- .option('--body <markdown>')
192
- .option('--body-file <path>')
193
- .option('--type <type>')
194
- .option('--points <number>')
195
- .option('--priority <priority>')
196
- .option('--labels <labels>')
197
- .option('--blocked-by <numbers>')
198
- .option('--blocks <numbers>', 'Add this issue as a blocker of these dependents')
199
- .option('--override-reason <reason>', 'Required explanation when adding a blocker to active work')
200
- .option('--milestone <number>')
201
- .option('--parent <number>')
202
- .action(async (o) => run('issue_create', fields(o.fieldsFile, {
97
+ const plugin = program.command("plugin").description("Manage the ai-delivery native plugin");
98
+ for (const action of ["install", "doctor", "preview", "update", "rollback", "remove"]) {
99
+ const command = plugin.command(action).requiredOption("--host <host>", "Native host: codex or claude-code").option("--scope <scope>", "Native scope: user, project, or local; Codex supports user", "user").option("--dry-run", "Describe the selected target without changing files or contacting native tools").option("--json", "Print the result as JSON");
100
+ if (action === "install" || action === "update")
101
+ command.requiredOption("--version <version>", "Explicit published package version");
102
+ if (action === "doctor")
103
+ command.option("--check-auth", "Read configured role identities and repository access; requires explicit --repo");
104
+ command.action(
105
+ async (options) => {
106
+ const result = await managePlugin({
107
+ action,
108
+ host: options.host,
109
+ scope: options.scope,
110
+ ...options.version === void 0 ? {} : { version: options.version },
111
+ dryRun: options.dryRun === true,
112
+ checkAuth: options.checkAuth === true,
113
+ ...options.checkAuth && execution().repo ? { repo: execution().repo } : {},
114
+ repoRoot: execution().repoRoot
115
+ });
116
+ if (options.json) {
117
+ print(result);
118
+ return;
119
+ }
120
+ process.stdout.write(
121
+ `${result.dryRun ? "Dry run: " : ""}${result.host} ${result.scope}: ${action}; version ${result.version ?? "none"}; installed ${result.installed}; changed ${result.changed}
122
+ `
123
+ );
124
+ if (result.mcp)
125
+ process.stdout.write(
126
+ `Bundled MCP startup: ${result.mcp.startup}${result.mcp.error ? ` (${result.mcp.error})` : ""}
127
+ `
128
+ );
129
+ if (result.diagnostics) {
130
+ process.stdout.write(
131
+ `Registration observations: ${result.diagnostics.registrations.length}; completeness ${result.diagnostics.completeness}; migration ${result.diagnostics.migration}; planned changes ${result.diagnostics.plannedChanges.length}
132
+ `
133
+ );
134
+ for (const entry of result.diagnostics.registrations)
135
+ process.stdout.write(
136
+ `${entry.kind} ${entry.scope}: ownership ${entry.ownership}; source ${entry.source}; version ${entry.version ?? "unknown"}
137
+ `
138
+ );
139
+ process.stdout.write(`Unverified conditions: ${result.diagnostics.findings.join(", ")}
140
+ `);
141
+ }
142
+ if (result.activation)
143
+ process.stdout.write(
144
+ `Native session loaded version: unverified. Installed observation: ${result.activation.installedVersion ?? "unknown"}; separate startup: ${result.activation.startupVersion ?? "not checked"}. Use the host's surface-specific activation guidance.
145
+ `
146
+ );
147
+ if (result.recoveryRequired)
148
+ process.stdout.write("Resume the interrupted original plugin command to recover this target.\n");
149
+ if (result.authProbe)
150
+ process.stdout.write(
151
+ `Selected-runtime CLI auth probe: ${result.authProbe.outcome}; settings ${result.authProbe.settings}; process references ${result.authProbe.processReferences.status}; authentication ${result.authProbe.authentication.status}; repository access ${result.authProbe.repositoryAccess.status}${result.authProbe.reason ? ` (${result.authProbe.reason})` : ""}
152
+ Native GUI credential propagation and counted exact-head approval remain unverified.
153
+ `
154
+ );
155
+ }
156
+ );
157
+ }
158
+ program.command("create").requiredOption("--title <title>").option("--fields-file <path>", "UTF-8 JSON typed fields; explicit CLI fields take precedence").option("--epic", "Create an active unsized parent issue").option("--op-id <id>", "Stable identity for retrying the same create").option("--draft", "Explicitly write an incomplete parked draft").option("--body <markdown>").option("--body-file <path>").option("--type <type>").option("--points <number>").option("--priority <priority>").option("--labels <labels>").option("--blocked-by <numbers>").option("--blocks <numbers>", "Add this issue as a blocker of these dependents").option("--override-reason <reason>", "Required explanation when adding a blocker to active work").option("--milestone <number>").option("--parent <number>").action(
159
+ async (o) => run(
160
+ "issue_create",
161
+ fields(o.fieldsFile, {
162
+ title: o.title,
163
+ epic: o.epic,
164
+ opId: o.opId,
165
+ body: body(o.body, o.bodyFile),
166
+ issueType: o.type,
167
+ points: int(o.points),
168
+ priority: o.priority,
169
+ labels: list(o.labels),
170
+ blockedBy: ints(o.blockedBy),
171
+ blocks: ints(o.blocks),
172
+ overrideReason: o.overrideReason,
173
+ milestone: int(o.milestone),
174
+ parentIssueNumber: int(o.parent),
175
+ ...o.draft === true ? { draft: true } : {}
176
+ })
177
+ )
178
+ );
179
+ program.command("start").option("--issue <number>").option("--request <text>").option("--request-id <id>", "Stable retry identity for a new issue start").option("--title <title>").option("--body <markdown>").option("--body-file <path>").option("--type <type>").option("--points <number>").option("--priority <priority>").option("--labels <labels>").option("--blocked-by <numbers>").option("--blocks <numbers>", "Add this issue as a blocker of these dependents").option("--override-reason <reason>", "Capacity override reason, or explanation when adding a blocker to active work").option("--milestone <number>").option("--parent <number>").option("--branch <branch>").option("--resume-created").action(
180
+ async (o) => run("issue_start", {
181
+ issueNumber: int(o.issue),
182
+ request: o.request,
183
+ requestId: o.requestId,
203
184
  title: o.title,
204
185
  body: body(o.body, o.bodyFile),
205
186
  issueType: o.type,
@@ -211,44 +192,34 @@ program
211
192
  overrideReason: o.overrideReason,
212
193
  milestone: int(o.milestone),
213
194
  parentIssueNumber: int(o.parent),
214
- ...(o.draft === true ? { draft: true } : {}),
215
- })));
216
- program
217
- .command('start')
218
- .option('--issue <number>')
219
- .option('--request <text>')
220
- .option('--request-id <id>', 'Stable retry identity for a new issue start')
221
- .option('--title <title>')
222
- .option('--body <markdown>')
223
- .option('--body-file <path>')
224
- .option('--type <type>')
225
- .option('--points <number>')
226
- .option('--priority <priority>')
227
- .option('--labels <labels>')
228
- .option('--blocked-by <numbers>')
229
- .option('--blocks <numbers>', 'Add this issue as a blocker of these dependents')
230
- .option('--override-reason <reason>', 'Capacity override reason, or explanation when adding a blocker to active work')
231
- .option('--milestone <number>')
232
- .option('--parent <number>')
233
- .option('--branch <branch>')
234
- .option('--resume-created')
235
- .option('--investigation-worktree <path>', 'Prospectively register an already linked host-created investigation')
236
- .option('--expected-head <sha>', 'Exact unchanged initial commit for investigation registration')
237
- .action(async (o) => {
238
- if (o.investigationWorktree !== undefined || o.expectedHead !== undefined) {
239
- if (Object.keys(o).some((key) => !['issue', 'investigationWorktree', 'expectedHead'].includes(key)))
240
- throw new Error('Investigation registration cannot create or change issue/branch metadata.');
241
- return run('issue_start', {
242
- issueNumber: int(o.issue),
243
- investigationWorktree: o.investigationWorktree,
244
- expectedHeadSha: o.expectedHead,
245
- });
246
- }
247
- return run('issue_start', {
195
+ branch: o.branch,
196
+ resumeCreated: o.resumeCreated === true
197
+ })
198
+ );
199
+ for (const name of ["list", "search"]) {
200
+ program.command(name).option("--query <text>", "Literal text to search in the selected repository").option("--state <state>").option("--labels <labels>").option("--parent <number>").option("--type <type>").option("--project-status <status>").option("--updated-since <timestamp>").option("--page <number>").option("--per-page <number>").action(
201
+ async (o) => run(name === "list" ? "issue_list" : "issue_search", {
202
+ query: o.query,
203
+ state: o.state,
204
+ labels: list(o.labels),
205
+ parentIssueNumber: int(o.parent),
206
+ issueType: o.type,
207
+ projectStatus: o.projectStatus,
208
+ updatedSince: o.updatedSince,
209
+ page: int(o.page),
210
+ perPage: int(o.perPage)
211
+ })
212
+ );
213
+ }
214
+ program.command("update").requiredOption("--issue <number>").option("--fields-file <path>", "UTF-8 JSON typed issue field patch").option("--draft", "Explicitly write an incomplete parked draft").option("--title <title>").option("--body <markdown>").option("--body-file <path>").option("--type <type>").option("--points <number>").option("--priority <priority>").option("--labels <labels>").option("--blocked-by <numbers>").option("--blocks <numbers>", "Add this issue as a blocker of these dependents").option("--override-reason <reason>", "Required explanation when adding a blocker to active work").option("--milestone <number>").option("--parent <number>").option("--state <state>").option("--project-status <status>", "Set Todo, In Progress, Blocked or Done with a public reason").option("--project-status-reason <reason>", "Required public reason for an explicit Project Status").option("--preserve-history", "Preserve the previous title and body before a rewrite").option("--close-reason <reason>").option("--superseded-by <number>").option("--park", "Park execution while retaining the issue worktree").option("--defer", "Defer until an explicit undefer").option("--defer-until <date>", "Record an ISO date condition without automatic undeferral").option("--defer-trigger <text>", "Record the condition for reconsidering deferred work").option("--undefer", "Explicitly clear deferral; draft and park remain unchanged").action(
215
+ async (o) => run(
216
+ "issue_update",
217
+ fields(
218
+ o.fieldsFile,
219
+ {
248
220
  issueNumber: int(o.issue),
249
- request: o.request,
250
- requestId: o.requestId,
251
221
  title: o.title,
222
+ ...o.draft === true ? { draft: true } : {},
252
223
  body: body(o.body, o.bodyFile),
253
224
  issueType: o.type,
254
225
  points: int(o.points),
@@ -259,295 +230,245 @@ program
259
230
  overrideReason: o.overrideReason,
260
231
  milestone: int(o.milestone),
261
232
  parentIssueNumber: int(o.parent),
262
- branch: o.branch,
263
- resumeCreated: o.resumeCreated === true,
264
- });
265
- });
266
- for (const name of ['list', 'search']) {
267
- program
268
- .command(name)
269
- .option('--query <text>', 'Literal text to search in the selected repository')
270
- .option('--state <state>')
271
- .option('--labels <labels>')
272
- .option('--parent <number>')
273
- .option('--type <type>')
274
- .option('--project-status <status>')
275
- .option('--updated-since <timestamp>')
276
- .option('--page <number>')
277
- .option('--per-page <number>')
278
- .action(async (o) => run(name === 'list' ? 'issue_list' : 'issue_search', {
279
- query: o.query,
280
233
  state: o.state,
281
- labels: list(o.labels),
282
- parentIssueNumber: int(o.parent),
283
- issueType: o.type,
284
- projectStatus: o.projectStatus,
285
- updatedSince: o.updatedSince,
286
- page: int(o.page),
287
- perPage: int(o.perPage),
288
- }));
289
- }
290
- program
291
- .command('update')
292
- .requiredOption('--issue <number>')
293
- .option('--fields-file <path>', 'UTF-8 JSON typed issue field patch')
294
- .option('--draft', 'Explicitly write an incomplete parked draft')
295
- .option('--title <title>')
296
- .option('--body <markdown>')
297
- .option('--body-file <path>')
298
- .option('--type <type>')
299
- .option('--points <number>')
300
- .option('--priority <priority>')
301
- .option('--labels <labels>')
302
- .option('--blocked-by <numbers>')
303
- .option('--blocks <numbers>', 'Add this issue as a blocker of these dependents')
304
- .option('--override-reason <reason>', 'Required explanation when adding a blocker to active work')
305
- .option('--milestone <number>')
306
- .option('--parent <number>')
307
- .option('--state <state>')
308
- .option('--preserve-history', 'Preserve the previous title and body before a rewrite')
309
- .option('--close-reason <reason>')
310
- .option('--superseded-by <number>')
311
- .option('--park', 'Park execution while retaining the issue worktree')
312
- .option('--defer', 'Defer until an explicit undefer')
313
- .option('--defer-until <date>', 'Record an ISO date condition without automatic undeferral')
314
- .option('--defer-trigger <text>', 'Record the condition for reconsidering deferred work')
315
- .option('--undefer', 'Explicitly clear deferral; draft and park remain unchanged')
316
- .action(async (o) => run('issue_update', fields(o.fieldsFile, {
317
- issueNumber: int(o.issue),
318
- title: o.title,
319
- ...(o.draft === true ? { draft: true } : {}),
320
- body: body(o.body, o.bodyFile),
321
- issueType: o.type,
322
- points: int(o.points),
323
- priority: o.priority,
324
- labels: list(o.labels),
325
- blockedBy: ints(o.blockedBy),
326
- blocks: ints(o.blocks),
327
- overrideReason: o.overrideReason,
328
- milestone: int(o.milestone),
329
- parentIssueNumber: int(o.parent),
330
- state: o.state,
331
- preserveHistory: o.preserveHistory === true ? true : undefined,
332
- closeReason: o.closeReason,
333
- supersededBy: int(o.supersededBy),
334
- park: o.park === true ? true : undefined,
335
- defer: o.defer === true || o.deferUntil !== undefined || o.deferTrigger !== undefined
336
- ? {
337
- ...(o.deferUntil === undefined ? {} : { until: o.deferUntil }),
338
- ...(o.deferTrigger === undefined ? {} : { trigger: o.deferTrigger }),
339
- }
340
- : undefined,
341
- undefer: o.undefer === true ? true : undefined,
342
- })));
343
- program
344
- .command('batch:update')
345
- .description('Plan or apply 1–50 current-repository issue updates with ordered readback')
346
- .requiredOption('--items-file <path>', 'UTF-8 JSON array of complete issue_update inputs')
347
- .option('--dry-run', 'Return plans and readback without any native writes')
348
- .action(async (o) => run('issue_batch_update', {
349
- items: JSON.parse(readFileSync(o.itemsFile, 'utf8')),
350
- dryRun: o.dryRun === true,
351
- }));
352
- program
353
- .command('health')
354
- .requiredOption('--from <utc>', 'Inclusive UTC ISO timestamp')
355
- .requiredOption('--to <utc>', 'Exclusive UTC ISO timestamp')
356
- .option('--max-issues <number>')
357
- .option('--max-timeline-pages <number>')
358
- .option('--max-project-pages <number>')
359
- .option('--oldest-limit <number>')
360
- .action(async (o) => run('delivery_health', {
234
+ projectStatus: o.projectStatus === void 0 && o.projectStatusReason === void 0 ? void 0 : ProjectStatusPatch.parse({ status: o.projectStatus, reason: o.projectStatusReason }),
235
+ preserveHistory: o.preserveHistory === true ? true : void 0,
236
+ closeReason: o.closeReason,
237
+ supersededBy: int(o.supersededBy),
238
+ park: o.park === true ? true : void 0,
239
+ defer: o.defer === true || o.deferUntil !== void 0 || o.deferTrigger !== void 0 ? {
240
+ ...o.deferUntil === void 0 ? {} : { until: o.deferUntil },
241
+ ...o.deferTrigger === void 0 ? {} : { trigger: o.deferTrigger }
242
+ } : void 0,
243
+ undefer: o.undefer === true ? true : void 0
244
+ },
245
+ true
246
+ )
247
+ )
248
+ );
249
+ program.command("board").description("Read delivery attention and readiness for explicit repositories").requiredOption("--repos <owner/repo,...>", "Explicit GitHub repositories, separated by commas").option("--decision-labels <label,...>", "Additional labels that signal human attention").option("--json", "Print the complete board as JSON").action(async (options) => {
250
+ const result = await executeTool(
251
+ "delivery_board",
252
+ { repos: options.repos.split(","), decisionLabels: options.decisionLabels?.split(",") },
253
+ execution()
254
+ );
255
+ if (options.json || program.opts().json) print(result);
256
+ else process.stdout.write(`${renderDeliveryBoard(result)}
257
+ `);
258
+ });
259
+ program.command("board:reconcile").description("Plan or apply bounded Project reconciliation for explicit repositories").requiredOption("--repositories <owner/repo...>", "1\u201310 explicit GitHub repositories").option("--checkouts-file <path>", "UTF-8 JSON checkout selectors for dry-run").option("--dry-run", "Collect a plan without writes (default)").option("--apply", "Apply the retained original plan").option("--plan-file <path>", "Original complete reconciliation plan JSON").option("--prior-result-file <path>", "Optional prior result JSON for the exact original plan").action(
260
+ async (options) => {
261
+ if (options.dryRun && options.apply) throw new DeliveryError("Choose either --dry-run or --apply.");
262
+ const request = parseBoardReconcileRequest({
263
+ repositories: options.repositories,
264
+ ...execution().repo === void 0 ? {} : { repo: execution().repo },
265
+ mode: options.apply ? "apply" : "dry-run",
266
+ ...options.checkoutsFile === void 0 ? {} : { checkouts: reconciliationFile(options.checkoutsFile) },
267
+ ...options.planFile === void 0 ? {} : { plan: reconciliationFile(options.planFile) },
268
+ ...options.priorResultFile === void 0 ? {} : { priorResult: reconciliationFile(options.priorResultFile) }
269
+ });
270
+ return run("board_reconcile", request);
271
+ }
272
+ );
273
+ program.command("batch:update").description("Plan or apply 1\u201350 current-repository issue updates with ordered readback").requiredOption("--items-file <path>", "UTF-8 JSON array of complete issue_update inputs").option("--dry-run", "Return plans and readback without any native writes").action(
274
+ async (o) => run("issue_batch_update", {
275
+ items: JSON.parse(readFileSync(o.itemsFile, "utf8")),
276
+ dryRun: o.dryRun === true
277
+ })
278
+ );
279
+ program.command("health").requiredOption("--from <utc>", "Inclusive UTC ISO timestamp").requiredOption("--to <utc>", "Exclusive UTC ISO timestamp").option("--max-issues <number>").option("--max-timeline-pages <number>").option("--max-project-pages <number>").option("--oldest-limit <number>").action(
280
+ async (o) => run("delivery_health", {
361
281
  repo: execution().repo,
362
282
  from: o.from,
363
283
  to: o.to,
364
284
  maxIssues: int(o.maxIssues),
365
285
  maxTimelinePages: int(o.maxTimelinePages),
366
286
  maxProjectPages: int(o.maxProjectPages),
367
- oldestLimit: int(o.oldestLimit),
368
- }));
369
- program
370
- .command('info')
371
- .requiredOption('--issue <number>')
372
- .action(async (o) => run('issue_info', { issueNumber: int(o.issue) }));
373
- program
374
- .command('ready:check')
375
- .requiredOption('--issue <number>')
376
- .action(async (o) => run('issue_ready_check', { issueNumber: int(o.issue) }));
377
- for (const field of ['parent', 'blockers']) {
378
- program
379
- .command(field)
380
- .requiredOption('--issue <number>')
381
- .action(async (o) => {
382
- const info = (await executeTool('issue_info', { issueNumber: int(o.issue) }, execution()));
383
- print(field === 'parent'
384
- ? { issueNumber: int(o.issue), parentIssueNumber: info.parentIssueNumber }
385
- : { issueNumber: int(o.issue), blockedBy: info.blockedBy });
386
- });
287
+ oldestLimit: int(o.oldestLimit)
288
+ })
289
+ );
290
+ program.command("info").requiredOption("--issue <number>").action(async (o) => run("issue_info", { issueNumber: int(o.issue) }));
291
+ program.command("ready:check").requiredOption("--issue <number>").action(async (o) => run("issue_ready_check", { issueNumber: int(o.issue) }));
292
+ for (const field of ["parent", "blockers"]) {
293
+ program.command(field).requiredOption("--issue <number>").action(async (o) => {
294
+ const info = await executeTool("issue_info", { issueNumber: int(o.issue) }, execution());
295
+ print(
296
+ field === "parent" ? { issueNumber: int(o.issue), parentIssueNumber: info.parentIssueNumber } : { issueNumber: int(o.issue), blockedBy: info.blockedBy }
297
+ );
298
+ });
387
299
  }
388
- program
389
- .command('subissues')
390
- .requiredOption('--issue <number>')
391
- .action(async (o) => {
392
- const context = await contextFor(execution(), 'subissues');
393
- print({ issueNumber: int(o.issue), subissues: await listIssueSubissues(context, Number(o.issue)) });
300
+ program.command("subissues").requiredOption("--issue <number>").action(async (o) => {
301
+ const context = await contextFor(execution(), "subissues");
302
+ print({ issueNumber: int(o.issue), subissues: await listIssueSubissues(context, Number(o.issue)) });
394
303
  });
395
- program
396
- .command('pr:create')
397
- .description('Create a PR from a linked issue branch, or promote an existing associated PR with --head and --ready.')
398
- .requiredOption('--issue <number>')
399
- .option('--pr <number>', 'Exact existing PR selector; never creates a replacement')
400
- .option('--non-closing', 'Retain the issue OPEN using native non-closing reference proof')
401
- .option('--title <title>')
402
- .option('--body-file <path>')
403
- .option('--head <branch>', 'Explicit remote head; existing PR promotion verifies its native issue association')
404
- .option('--ready', 'Publish ready, or promote the author-owned PR selected by --head')
405
- .option('--dry-run')
406
- .action(async (o) => run('issue_pr_create', {
304
+ program.command("pr:create").description("Create or reuse an issue-closing PR from a pushed --head, from any directory.").requiredOption("--issue <number>").option("--pr <number>", "Exact existing PR selector; never creates a replacement").option("--non-closing", "Retain the issue OPEN using native non-closing reference proof").option(
305
+ "--reconcile-non-closing-reference",
306
+ "Explicit native closing-pair removal request; caller must hold exact authority and reconcile prior attempts"
307
+ ).option("--expected-head <sha>", "Exact source SHA for the explicit reference action").option("--expected-base <sha>", "Exact default-base SHA for the explicit reference action").option("--title <title>").option("--body-file <path>").option("--head <branch>", "Pushed remote head; no ai-delivery branch or worktree setup required").option("--base <branch>", "Repository default branch (inferred when omitted)").option("--ready", "Publish ready, or promote the author-owned PR selected by --head").option("--dry-run").action(
308
+ async (o) => run("issue_pr_create", {
407
309
  issueNumber: int(o.issue),
408
310
  prNumber: int(o.pr),
409
311
  nonClosing: o.nonClosing,
312
+ reconcileNonClosingReference: o.reconcileNonClosingReference,
313
+ expectedHeadSha: o.expectedHead,
314
+ expectedBaseSha: o.expectedBase,
410
315
  title: o.title,
411
- body: body(undefined, o.bodyFile),
316
+ body: body(void 0, o.bodyFile),
412
317
  headBranch: o.head,
318
+ base: o.base,
413
319
  draft: o.ready !== true,
414
- dryRun: o.dryRun === true,
415
- }));
416
- program
417
- .command('pr:info')
418
- .description('Inspect an exact PR; combine --issue and --pr to verify its native closing-issue association.')
419
- .option('--non-closing', 'Verify an exact native non-closing PR-to-issue reference')
420
- .option('--issue <number>', 'Issue to verify; issue-only lookup requires a GitHub-linked branch')
421
- .option('--pr <number>', 'Exact PR number; include --issue after issue branch links are replaced on publication')
422
- .action(async (o) => run('issue_pr_info', { issueNumber: int(o.issue), prNumber: int(o.pr), nonClosing: o.nonClosing }));
423
- program
424
- .command('pr:list')
425
- .option('--state <state>', 'open, closed or all', 'open')
426
- .action(async (o) => {
427
- if (!['open', 'closed', 'all'].includes(o.state))
428
- throw new Error('Invalid PR state.');
429
- const context = await contextFor(execution(), 'pr:list');
430
- print(await listPrs(context, o.state));
320
+ dryRun: o.dryRun === true
321
+ })
322
+ );
323
+ program.command("pr:info").description("Inspect an exact PR; combine --issue and --pr to verify its native closing-issue association.").option("--non-closing", "Verify an exact native non-closing PR-to-issue reference").option("--issue <number>", "Issue to verify; issue-only lookup requires a GitHub-linked branch").option("--pr <number>", "Exact PR number; include --issue after issue branch links are replaced on publication").action(
324
+ async (o) => run("issue_pr_info", { issueNumber: int(o.issue), prNumber: int(o.pr), nonClosing: o.nonClosing })
325
+ );
326
+ program.command("pr:list").option("--state <state>", "open, closed or all", "open").action(async (o) => {
327
+ if (!["open", "closed", "all"].includes(o.state)) throw new Error("Invalid PR state.");
328
+ const context = await contextFor(execution(), "pr:list");
329
+ print(await listPrs(context, o.state));
431
330
  });
432
- program
433
- .command('pr:checks')
434
- .requiredOption('--pr <number>')
435
- .action(async (o) => {
436
- const context = await contextFor(execution(), 'pr:checks');
437
- print(await prChecks(context, Number(o.pr)));
331
+ program.command("pr:checks").requiredOption("--pr <number>").action(async (o) => {
332
+ const context = await contextFor(execution(), "pr:checks");
333
+ print(await prChecks(context, Number(o.pr)));
438
334
  });
439
- program
440
- .command('pr:review')
441
- .requiredOption('--issue <number>')
442
- .requiredOption('--pr <number>')
443
- .requiredOption('--artifact <path>', 'Path to a UTF-8 JSON review artifact file (not inline JSON)')
444
- .option('--non-closing', 'Retain the referenced issue OPEN; finish refuses this mode')
445
- .option('--dry-run')
446
- .action(async (o) => run('issue_pr_review', {
335
+ program.command("pr:review").requiredOption("--issue <number>").requiredOption("--pr <number>").requiredOption("--artifact <path>", "Path to a UTF-8 JSON review artifact file (not inline JSON)").option("--non-closing", "Retain the referenced issue OPEN; finish refuses this mode").option("--dry-run").action(
336
+ async (o) => run("issue_pr_review", {
447
337
  issueNumber: int(o.issue),
448
338
  prNumber: int(o.pr),
449
- artifact: readFileSync(o.artifact, 'utf8'),
339
+ artifact: readFileSync(o.artifact, "utf8"),
450
340
  dryRun: o.dryRun === true,
451
- nonClosing: o.nonClosing,
452
- }));
341
+ nonClosing: o.nonClosing
342
+ })
343
+ );
344
+ program.command("review").argument("<action>", "submit or doctor").description("Submit an independent verdict or check its configured App").option("--pr <number>", "Required for submit").option("--head <sha>", "Required exact head for submit").option("--identity <name>", "Required configured reviewer profile").option("--verdict <path>", "Required for submit: UTF-8 JSON verdict, at most 64 KiB").action(async (action, o) => {
345
+ if (!["submit", "doctor"].includes(action)) throw new DeliveryError("review action must be submit or doctor.");
346
+ const identity = o.identity ?? execution().identity ?? "";
347
+ const settings = await loadDeliverySettings(void 0, { reviewerIdentity: identity, prepareEnvironment: true });
348
+ const profile = settings.roles.reviewer;
349
+ if (!("appId" in profile))
350
+ throw new DeliveryError("identity: Select a reviewer profile with explicit App/provider binding.");
351
+ if (action === "doctor") {
352
+ if (o.pr !== void 0 || o.head !== void 0 || o.verdict !== void 0)
353
+ throw new DeliveryError("review doctor does not accept submission inputs.");
354
+ const clients2 = await createDeliveryGitHubClients({
355
+ config: settings,
356
+ identity,
357
+ role: "reviewer",
358
+ env: settings.environment
359
+ });
360
+ const actorLogin = await clients2.appActorLogin();
361
+ printCommandResult("review:doctor", {
362
+ status: "authenticated",
363
+ identity,
364
+ provider: profile.provider,
365
+ appId: profile.appId,
366
+ installationId: profile.installationId,
367
+ actorLogin,
368
+ source: appCredentialSource(profile).type
369
+ });
370
+ return;
371
+ }
372
+ if (o.pr === void 0 || o.head === void 0 || o.verdict === void 0)
373
+ throw new DeliveryError("review submit requires --pr, --head and --verdict.");
374
+ const fd = openSync(o.verdict, constants.O_RDONLY | constants.O_NOFOLLOW | constants.O_NONBLOCK);
375
+ let raw;
376
+ let verdictFileSha256;
377
+ try {
378
+ if (!fstatSync(fd).isFile()) throw new DeliveryError("verdict: Expected a regular file.");
379
+ const bytes = Buffer.alloc(64 * 1024 + 1);
380
+ let size = 0;
381
+ while (size < bytes.length) {
382
+ const count = readSync(fd, bytes, size, bytes.length - size, null);
383
+ if (count === 0) break;
384
+ size += count;
385
+ }
386
+ if (size > 64 * 1024) throw new DeliveryError("verdict: File exceeds 64 KiB.");
387
+ const content = bytes.subarray(0, size);
388
+ raw = content.toString("utf8");
389
+ if (!Buffer.from(raw, "utf8").equals(content)) throw new DeliveryError("verdict: Expected valid UTF-8.");
390
+ verdictFileSha256 = `sha256:${createHash("sha256").update(content).digest("hex")}`;
391
+ } finally {
392
+ closeSync(fd);
393
+ }
394
+ const verdict = parseReviewVerdict(raw);
395
+ assertReviewVerdictTarget(verdict, profile.provider, o.head);
396
+ const prNumber = z.number().int().positive().parse(Number(o.pr));
397
+ const authorContext = await contextFor(
398
+ { ...execution(), settings, identity, reviewSubmission: true },
399
+ "pr:info",
400
+ "author"
401
+ );
402
+ const reviewBase = await readGitHubReviewBase(authorContext, prNumber, o.head);
403
+ const artifact = buildReviewArtifact({
404
+ verdict,
405
+ verdictFileSha256,
406
+ identity,
407
+ provider: profile.provider,
408
+ expectedHead: o.head,
409
+ prNumber,
410
+ authorIdentity: settings.roles.author.identity,
411
+ reviewBase
412
+ });
413
+ await validateReviewTarget(authorContext, artifact, prNumber);
414
+ const clients = await createDeliveryGitHubClients({
415
+ config: authorContext.config,
416
+ identity,
417
+ role: "reviewer",
418
+ selectedAuthor: authorContext.clients,
419
+ ...authorContext.credentialEnvironment === void 0 ? {} : { env: authorContext.credentialEnvironment }
420
+ });
421
+ const context = { ...authorContext, clients };
422
+ try {
423
+ printCommandResult(
424
+ "review:submit",
425
+ await submitFormalReview(context, {
426
+ artifact: JSON.stringify(artifact),
427
+ issueNumber: verdict.issueNumber,
428
+ prNumber,
429
+ ...verdict.nonClosing === void 0 ? {} : { nonClosing: verdict.nonClosing }
430
+ })
431
+ );
432
+ } catch (error) {
433
+ if (!(error instanceof ReviewSubmissionError)) throw error;
434
+ process.stdout.write(
435
+ `${JSON.stringify({ status: "submission-unverified", submission: error.submission, nextAction: error.message })}
436
+ `
437
+ );
438
+ process.exitCode = 1;
439
+ }
440
+ });
453
441
  for (const [command, tool] of [
454
- ['pr:merge', 'issue_pr_merge'],
455
- ['finish', 'issue_finish'],
442
+ ["pr:merge", "issue_pr_merge"],
443
+ ["finish", "issue_finish"]
456
444
  ]) {
457
- const mergeCommand = program.command(command).requiredOption('--issue <number>');
458
- if (command === 'pr:merge')
459
- mergeCommand.requiredOption('--pr <number>');
460
- else
461
- mergeCommand.option('--pr <number>');
462
- mergeCommand
463
- .option('--strategy <method>')
464
- .option('--reviewed-head <sha>')
465
- .option('--non-closing', 'Retain the referenced issue OPEN; finish refuses this mode')
466
- .option('--dry-run');
467
- if (command === 'finish')
468
- mergeCommand
469
- .option('--investigation', 'Complete an unchanged prospectively registered investigation')
470
- .option('--result <path>', 'Durable independently reviewed result outside the removable worktree')
471
- .option('--authority-comment <number>', 'Exact native operator removal authority comment')
472
- .option('--acceptance-comment <number>', 'Exact configured-App result acceptance comment');
473
- mergeCommand.action(async (o) => {
474
- if (o.investigation === true) {
475
- if (o.pr !== undefined ||
476
- o.strategy !== undefined ||
477
- o.reviewedHead !== undefined ||
478
- o.nonClosing !== undefined)
479
- throw new Error('Investigation completion cannot accept PR or merge options.');
480
- return run(tool, {
481
- issueNumber: int(o.issue),
482
- investigation: true,
483
- resultPath: o.result,
484
- authorityCommentId: int(o.authorityComment),
485
- acceptanceCommentId: int(o.acceptanceComment),
486
- dryRun: o.dryRun === true,
487
- });
488
- }
489
- if (o.result !== undefined || o.authorityComment !== undefined || o.acceptanceComment !== undefined)
490
- throw new Error('Investigation evidence requires --investigation.');
491
- return run(tool, {
492
- issueNumber: int(o.issue),
493
- prNumber: int(o.pr),
494
- strategy: o.strategy,
495
- reviewedHeadSha: o.reviewedHead,
496
- dryRun: o.dryRun === true,
497
- nonClosing: o.nonClosing,
498
- });
499
- });
445
+ program.command(command).requiredOption("--issue <number>").requiredOption("--pr <number>").option("--strategy <method>").option("--reviewed-head <sha>").option("--non-closing", "Retain the referenced issue OPEN; finish refuses this mode").option("--dry-run").action(
446
+ async (o) => run(tool, {
447
+ issueNumber: int(o.issue),
448
+ prNumber: int(o.pr),
449
+ strategy: o.strategy,
450
+ reviewedHeadSha: o.reviewedHead,
451
+ dryRun: o.dryRun === true,
452
+ nonClosing: o.nonClosing
453
+ })
454
+ );
500
455
  }
501
- program
502
- .command('worktree:transition:inspect')
503
- .requiredOption('--issue <number>')
504
- .requiredOption('--purpose <purpose>', 'active-resume or merged-cleanup')
505
- .option('--disposition <disposition>', 'retain (default) or explicitly unheld remove')
506
- .option('--terminal-pr <number>')
507
- .option('--retained-holds <comment-ids>', 'Comma-separated native retained-hold comment IDs')
508
- .option('--retained-admission <path>')
509
- .option('--retained-archive <path>')
510
- .action(async (o) => run('issue_worktree_transition_inspect', {
511
- issueNumber: int(o.issue),
512
- purpose: o.purpose,
513
- ...(o.disposition === undefined ? {} : { disposition: o.disposition }),
514
- ...(o.terminalPr === undefined ? {} : { terminalPrNumber: int(o.terminalPr) }),
515
- ...(o.retainedHolds === undefined ? {} : { retainedHoldCommentIds: ints(o.retainedHolds) }),
516
- ...(o.retainedAdmission === undefined ? {} : { retainedAdmissionPath: o.retainedAdmission }),
517
- ...(o.retainedArchive === undefined ? {} : { retainedArchivePath: o.retainedArchive }),
518
- }));
519
- program
520
- .command('worktree:transition:apply')
521
- .requiredOption('--plan <path>')
522
- .requiredOption('--plan-id <digest>')
523
- .requiredOption('--relinquishment-comment <id>')
524
- .requiredOption('--acceptance-comment <id>')
525
- .option('--authorize-transition', 'Explicit authority for this exact independently accepted plan')
526
- .action(async (o) => run('issue_worktree_transition_apply', {
527
- authority: o.authorizeTransition === true ? 'worktree:transition' : '',
528
- planPath: o.plan,
529
- expectedPlanId: o.planId,
530
- relinquishmentCommentId: Number(o.relinquishmentComment),
531
- acceptanceCommentId: Number(o.acceptanceComment),
532
- }));
533
- program
534
- .command('migrate:legacy-issues')
535
- .requiredOption('--input-file <path>', 'Offline legacy issue inventory JSON')
536
- .action((o) => {
537
- const report = planOfflineLegacyIssueMigration(JSON.parse(readFileSync(o.inputFile, 'utf8')));
538
- process.stdout.write(`${JSON.stringify(report, null, 2)}\n`);
456
+ program.command("migrate:legacy-issues").requiredOption("--input-file <path>", "Offline legacy issue inventory JSON").action((o) => {
457
+ const report = planOfflineLegacyIssueMigration(JSON.parse(readFileSync(o.inputFile, "utf8")));
458
+ process.stdout.write(`${JSON.stringify(report, null, 2)}
459
+ `);
539
460
  });
540
- program
541
- .command('config:resolve')
542
- .description('Read the effective GitHub destination and admission digest')
543
- .action(async () => {
544
- const context = await contextFor(execution(), 'config:resolve');
545
- print({
546
- configDigest: context.configuration?.configDigest,
547
- routing: context.configuration?.routing,
548
- reviewRoute: await preflightReviewRoute(context, undefined, undefined, 'development'),
549
- });
461
+ program.command("config:resolve").description("Read the effective GitHub destination and admission digest").action(async () => {
462
+ const context = await contextFor(execution(), "config:resolve");
463
+ print({
464
+ configDigest: context.configuration?.configDigest,
465
+ routing: context.configuration?.routing,
466
+ reviewRoute: await preflightReviewRoute(context, void 0, void 0, "development")
467
+ });
468
+ });
469
+ program.command("mcp:serve").action(async () => serveAiDeliveryMcp(execution()));
470
+ program.parseAsync(process.argv).catch((error) => {
471
+ const options = program.opts();
472
+ printCommandError(error, options.json === true && options.verbose === true);
550
473
  });
551
- program.command('mcp:serve').action(async () => serveAiDeliveryMcp(execution()));
552
- program.parseAsync(process.argv).catch(printCommandError);
553
- //# sourceMappingURL=cli.js.map
474
+ //# sourceMappingURL=cli.js.map