@aviaratech/ai-delivery 0.3.35 → 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 (297) hide show
  1. package/CONTRIBUTING.md +12 -206
  2. package/README.md +57 -554
  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 +1651 -1590
  9. package/dist/boardReconcile.test.js.map +7 -1
  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 +402 -515
  15. package/dist/cli.js.map +7 -1
  16. package/dist/cliResult.d.ts +2 -2
  17. package/dist/cliResult.js +42 -45
  18. package/dist/cliResult.js.map +7 -1
  19. package/dist/cliResult.test.js +424 -369
  20. package/dist/cliResult.test.js.map +7 -1
  21. package/dist/config/deliveryConfig.d.ts +288 -14
  22. package/dist/config/deliveryConfig.js +472 -390
  23. package/dist/config/deliveryConfig.js.map +7 -1
  24. package/dist/config/deliveryConfig.test.js +773 -649
  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 -479
  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.js +649 -0
  53. package/dist/deliveryBoard.test.js.map +7 -0
  54. package/dist/deliveryHealth.test.js +179 -155
  55. package/dist/deliveryHealth.test.js.map +7 -1
  56. package/dist/dependencyCompatibility.test.js +154 -140
  57. package/dist/dependencyCompatibility.test.js.map +7 -1
  58. package/dist/directoryIndependent.test.js +417 -383
  59. package/dist/directoryIndependent.test.js.map +7 -1
  60. package/dist/dispatch.d.ts +16 -11
  61. package/dist/dispatch.js +329 -353
  62. package/dist/dispatch.js.map +7 -1
  63. package/dist/errors.d.ts +3 -3
  64. package/dist/errors.js +103 -96
  65. package/dist/errors.js.map +7 -1
  66. package/dist/fixtures/deliveryBoardReplay.d.ts +56 -0
  67. package/dist/fixtures/deliveryBoardReplay.js +617 -0
  68. package/dist/fixtures/deliveryBoardReplay.js.map +7 -0
  69. package/dist/fixtures/discovery.d.ts +59 -19
  70. package/dist/fixtures/discovery.js +96 -90
  71. package/dist/fixtures/discovery.js.map +7 -1
  72. package/dist/fixtures/inertEntrypointChild.js +57 -56
  73. package/dist/fixtures/inertEntrypointChild.js.map +7 -1
  74. package/dist/fixtures/inertEntrypoints.d.ts +1 -1
  75. package/dist/fixtures/inertEntrypoints.js +321 -276
  76. package/dist/fixtures/inertEntrypoints.js.map +7 -1
  77. package/dist/fixtures/inertTarget.d.ts +78 -7
  78. package/dist/fixtures/inertTarget.js +769 -691
  79. package/dist/fixtures/inertTarget.js.map +7 -1
  80. package/dist/fixtures/issue63.d.ts +4 -3
  81. package/dist/fixtures/issue63.js +260 -274
  82. package/dist/fixtures/issue63.js.map +7 -1
  83. package/dist/fixtures/issueProjectItems.d.ts +20 -0
  84. package/dist/fixtures/issueProjectItems.js +15 -0
  85. package/dist/fixtures/issueProjectItems.js.map +7 -0
  86. package/dist/fixtures/readView.d.ts +120 -0
  87. package/dist/fixtures/readView.js +172 -0
  88. package/dist/fixtures/readView.js.map +7 -0
  89. package/dist/fixtures/recordedGitHubFlows.d.ts +120 -0
  90. package/dist/fixtures/recordedGitHubFlows.js +109 -0
  91. package/dist/fixtures/recordedGitHubFlows.js.map +7 -0
  92. package/dist/genericCompatibility.test.js +64 -55
  93. package/dist/genericCompatibility.test.js.map +7 -1
  94. package/dist/git.js +73 -67
  95. package/dist/git.js.map +7 -1
  96. package/dist/gitProcess.d.ts +1 -1
  97. package/dist/gitProcess.js +58 -53
  98. package/dist/gitProcess.js.map +7 -1
  99. package/dist/github/client.d.ts +2 -2
  100. package/dist/github/client.js +484 -379
  101. package/dist/github/client.js.map +7 -1
  102. package/dist/github/commandIdentityPolicy.js +44 -52
  103. package/dist/github/commandIdentityPolicy.js.map +7 -1
  104. package/dist/github/discovery.d.ts +1 -0
  105. package/dist/github/discovery.js +197 -215
  106. package/dist/github/discovery.js.map +7 -1
  107. package/dist/github/discovery.test.js +223 -177
  108. package/dist/github/discovery.test.js.map +7 -1
  109. package/dist/github/issueHistory.d.ts +2 -2
  110. package/dist/github/issueHistory.js +117 -125
  111. package/dist/github/issueHistory.js.map +7 -1
  112. package/dist/github/machineAuth.d.ts +1 -1
  113. package/dist/github/machineAuth.js +126 -117
  114. package/dist/github/machineAuth.js.map +7 -1
  115. package/dist/github/machineAuth.test.js +755 -639
  116. package/dist/github/machineAuth.test.js.map +7 -1
  117. package/dist/github/nativeIssueMetadata.js +286 -273
  118. package/dist/github/nativeIssueMetadata.js.map +7 -1
  119. package/dist/github/projectDelivery.d.ts +18 -2
  120. package/dist/github/projectDelivery.js +615 -557
  121. package/dist/github/projectDelivery.js.map +7 -1
  122. package/dist/github/relationships.js +433 -389
  123. package/dist/github/relationships.js.map +7 -1
  124. package/dist/github/repo.d.ts +1 -0
  125. package/dist/github/repo.js +123 -96
  126. package/dist/github/repo.js.map +7 -1
  127. package/dist/index.js +3 -3
  128. package/dist/index.js.map +7 -1
  129. package/dist/issue.d.ts +40 -9
  130. package/dist/issue.js +2102 -1742
  131. package/dist/issue.js.map +7 -1
  132. package/dist/issue63History.test.js +40 -42
  133. package/dist/issue63History.test.js.map +7 -1
  134. package/dist/issue63Routes.test.js +154 -143
  135. package/dist/issue63Routes.test.js.map +7 -1
  136. package/dist/issueBatchUpdate.test.js +989 -885
  137. package/dist/issueBatchUpdate.test.js.map +7 -1
  138. package/dist/issueBlockerGuard.test.js +262 -226
  139. package/dist/issueBlockerGuard.test.js.map +7 -1
  140. package/dist/issueContract.d.ts +23 -4
  141. package/dist/issueContract.js +416 -395
  142. package/dist/issueContract.js.map +7 -1
  143. package/dist/issueContract.test.d.ts +4 -3
  144. package/dist/issueContract.test.js +358 -321
  145. package/dist/issueContract.test.js.map +7 -1
  146. package/dist/issueDates.test.js +235 -233
  147. package/dist/issueDates.test.js.map +7 -1
  148. package/dist/issueInfoReadback.test.js +304 -190
  149. package/dist/issueInfoReadback.test.js.map +7 -1
  150. package/dist/issueIntake.test.js +1945 -1732
  151. package/dist/issueIntake.test.js.map +7 -1
  152. package/dist/issueJournal.d.ts +40 -19
  153. package/dist/issueJournal.js +229 -138
  154. package/dist/issueJournal.js.map +7 -1
  155. package/dist/issueJournal.test.js +605 -422
  156. package/dist/issueJournal.test.js.map +7 -1
  157. package/dist/issueRollup.test.d.ts +1 -0
  158. package/dist/issueRollup.test.js +476 -0
  159. package/dist/issueRollup.test.js.map +7 -0
  160. package/dist/issueTracking.test.js +1059 -989
  161. package/dist/issueTracking.test.js.map +7 -1
  162. package/dist/issueWriteRecovery.test.d.ts +1 -0
  163. package/dist/issueWriteRecovery.test.js +260 -0
  164. package/dist/issueWriteRecovery.test.js.map +7 -0
  165. package/dist/lifecycle.test.js +112 -441
  166. package/dist/lifecycle.test.js.map +7 -1
  167. package/dist/logger.js +80 -74
  168. package/dist/logger.js.map +7 -1
  169. package/dist/mcp/index.js +116 -94
  170. package/dist/mcp/index.js.map +7 -1
  171. package/dist/mcp/tools.d.ts +264 -286
  172. package/dist/mcp/tools.js +267 -340
  173. package/dist/mcp/tools.js.map +7 -1
  174. package/dist/pluginAuthProbe.js +63 -52
  175. package/dist/pluginAuthProbe.js.map +7 -1
  176. package/dist/pluginAuthProbe.test.js +85 -62
  177. package/dist/pluginAuthProbe.test.js.map +7 -1
  178. package/dist/pluginCredentials.test.js +282 -259
  179. package/dist/pluginCredentials.test.js.map +7 -1
  180. package/dist/pluginDoctor.test.js +653 -588
  181. package/dist/pluginDoctor.test.js.map +7 -1
  182. package/dist/pluginInstaller.d.ts +7 -5
  183. package/dist/pluginInstaller.js +1173 -1229
  184. package/dist/pluginInstaller.js.map +7 -1
  185. package/dist/pluginInstaller.test.js +1842 -1423
  186. package/dist/pluginInstaller.test.js.map +7 -1
  187. package/dist/pluginPackaging.test.js +460 -409
  188. package/dist/pluginPackaging.test.js.map +7 -1
  189. package/dist/pr.d.ts +132 -94
  190. package/dist/pr.js +1521 -1323
  191. package/dist/pr.js.map +7 -1
  192. package/dist/pr.test.js +1678 -632
  193. package/dist/pr.test.js.map +7 -1
  194. package/dist/prAssociation.test.js +2419 -1788
  195. package/dist/prAssociation.test.js.map +7 -1
  196. package/dist/prDispatch.test.js +150 -89
  197. package/dist/prDispatch.test.js.map +7 -1
  198. package/dist/readView.d.ts +183 -0
  199. package/dist/readView.js +217 -0
  200. package/dist/readView.js.map +7 -0
  201. package/dist/readView.test.d.ts +1 -0
  202. package/dist/readView.test.js +119 -0
  203. package/dist/readView.test.js.map +7 -0
  204. package/dist/releaseReconciliation.test.js +267 -288
  205. package/dist/releaseReconciliation.test.js.map +7 -1
  206. package/dist/releaseWorkflow.test.js +2493 -422
  207. package/dist/releaseWorkflow.test.js.map +7 -1
  208. package/dist/review.d.ts +738 -2
  209. package/dist/review.js +601 -348
  210. package/dist/review.js.map +7 -1
  211. package/dist/review.test.js +1218 -812
  212. package/dist/review.test.js.map +7 -1
  213. package/dist/reviewSubmit.test.d.ts +1 -0
  214. package/dist/reviewSubmit.test.js +747 -0
  215. package/dist/reviewSubmit.test.js.map +7 -0
  216. package/dist/services/agentReadinessService.js +42 -37
  217. package/dist/services/agentReadinessService.js.map +7 -1
  218. package/dist/services/blockerGuardService.js +188 -188
  219. package/dist/services/blockerGuardService.js.map +7 -1
  220. package/dist/services/boardReconcileService.d.ts +125 -125
  221. package/dist/services/boardReconcileService.js +1295 -1421
  222. package/dist/services/boardReconcileService.js.map +7 -1
  223. package/dist/services/deliveryAdmission.js +131 -154
  224. package/dist/services/deliveryAdmission.js.map +7 -1
  225. package/dist/services/deliveryHealthService.js +197 -199
  226. package/dist/services/deliveryHealthService.js.map +7 -1
  227. package/dist/services/legacyIssueMigration.js +263 -277
  228. package/dist/services/legacyIssueMigration.js.map +7 -1
  229. package/dist/services/worktreeRegistry.d.ts +27 -119
  230. package/dist/services/worktreeRegistry.js +765 -1182
  231. package/dist/services/worktreeRegistry.js.map +7 -1
  232. package/dist/stagedChecks.test.js +396 -194
  233. package/dist/stagedChecks.test.js.map +7 -1
  234. package/dist/start.test.js +99 -95
  235. package/dist/start.test.js.map +7 -1
  236. package/dist/stdoutRegression.test.js +353 -352
  237. package/dist/stdoutRegression.test.js.map +7 -1
  238. package/dist/targetPolicyDiscovery.test.js +141 -143
  239. package/dist/targetPolicyDiscovery.test.js.map +7 -1
  240. package/dist/targetPolicyEntrypoints.test.js +308 -269
  241. package/dist/targetPolicyEntrypoints.test.js.map +7 -1
  242. package/dist/targetPolicyLocal.test.js +580 -1051
  243. package/dist/targetPolicyLocal.test.js.map +7 -1
  244. package/dist/targetPolicyRoutes.test.js +305 -281
  245. package/dist/targetPolicyRoutes.test.js.map +7 -1
  246. package/dist/targetRepositoryExecution.test.d.ts +1 -0
  247. package/dist/targetRepositoryExecution.test.js +463 -0
  248. package/dist/targetRepositoryExecution.test.js.map +7 -0
  249. package/dist/terminalMessages.js +41 -35
  250. package/dist/terminalMessages.js.map +7 -1
  251. package/dist/toolOutput.d.ts +2 -0
  252. package/dist/toolOutput.js +36 -0
  253. package/dist/toolOutput.js.map +7 -0
  254. package/dist/toolOutput.test.d.ts +1 -0
  255. package/dist/toolOutput.test.js +240 -0
  256. package/dist/toolOutput.test.js.map +7 -0
  257. package/dist/utils/atomicJson.js +84 -76
  258. package/dist/utils/atomicJson.js.map +7 -1
  259. package/dist/utils/filesystem.js +15 -18
  260. package/dist/utils/filesystem.js.map +7 -1
  261. package/dist/utils/lockfile.js +68 -71
  262. package/dist/utils/lockfile.js.map +7 -1
  263. package/dist/verification.d.ts +1 -19
  264. package/dist/verification.js +1020 -1939
  265. package/dist/verification.js.map +7 -1
  266. package/dist/verificationGate.test.js +127 -117
  267. package/dist/verificationGate.test.js.map +7 -1
  268. package/dist/version.js +23 -24
  269. package/dist/version.js.map +7 -1
  270. package/dist/worktree.d.ts +3 -15
  271. package/dist/worktree.js +97 -177
  272. package/dist/worktree.js.map +7 -1
  273. package/package.json +9 -8
  274. package/plugins/ai-delivery/.claude-plugin/plugin.json +2 -2
  275. package/plugins/ai-delivery/README.md +47 -156
  276. package/plugins/ai-delivery/plugin.json +1 -1
  277. package/plugins/ai-delivery/runtime/dist/THIRD-PARTY-NOTICES.md +238 -44
  278. package/plugins/ai-delivery/runtime/dist/cli.js +358 -115
  279. package/plugins/ai-delivery/runtime/package.json +1 -1
  280. package/plugins/ai-delivery/skills/intake-create/SKILL.md +14 -78
  281. package/plugins/ai-delivery/skills/pr-handoff/SKILL.md +35 -36
  282. package/plugins/ai-delivery/skills/worktree-lifecycle/SKILL.md +14 -15
  283. package/dist/investigationCompletion.test.js +0 -728
  284. package/dist/investigationCompletion.test.js.map +0 -1
  285. package/dist/setup.d.ts +0 -60
  286. package/dist/setup.js +0 -585
  287. package/dist/setup.js.map +0 -1
  288. package/dist/setup.test.js +0 -3329
  289. package/dist/setup.test.js.map +0 -1
  290. package/dist/worktreeTransition.d.ts +0 -211
  291. package/dist/worktreeTransition.js +0 -1037
  292. package/dist/worktreeTransition.js.map +0 -1
  293. package/dist/worktreeTransition.test.js +0 -1191
  294. package/dist/worktreeTransition.test.js.map +0 -1
  295. /package/dist/{investigationCompletion.test.d.ts → build.test.d.ts} +0 -0
  296. /package/dist/{setup.test.d.ts → callerErrors.test.d.ts} +0 -0
  297. /package/dist/{worktreeTransition.test.d.ts → deliveryBoard.test.d.ts} +0 -0
package/dist/cli.js CHANGED
@@ -1,217 +1,186 @@
1
1
  #!/usr/bin/env node
2
- import { readFileSync, statSync } 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';
15
- import { DeliveryError } from './errors.js';
16
- import { parseBoardReconcileRequest } from './services/boardReconcileService.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";
17
29
  const program = new Command();
18
- program
19
- .name('ai-delivery')
20
- .description('Generic GitHub issue and pull request delivery')
21
- .version(PACKAGE_VERSION)
22
- .option('--identity <name>', 'Configured author or reviewer identity')
23
- .option('--personal-auth', 'Explicit legacy personal-token author override')
24
- .option('--repo <owner/name>', 'GitHub repository owner/name; works from any directory')
25
- .option('--repo-root <path>', 'Launch directory or explicit clone for local operations', process.cwd());
26
- // Only the plugin command group owns a local --version input. Skip global option
27
- // 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());
28
31
  for (let index = 2; index < process.argv.length; index++) {
29
- const argument = process.argv[index];
30
- const option = program.options.find((value) => value.long === argument.split('=')[0] || value.short === argument);
31
- if (option) {
32
- if (option.required && !argument.includes('='))
33
- index++;
34
- continue;
35
- }
36
- if (argument === 'plugin')
37
- program.enablePositionalOptions();
38
- 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;
39
40
  }
40
41
  function execution() {
41
- const options = program.opts();
42
- const identity = (options.identity ?? process.env.AI_DELIVERY_IDENTITY)?.trim() || undefined;
43
- return {
44
- repoRoot: options.repoRoot,
45
- ...(identity === undefined ? {} : { identity }),
46
- personalAuth: options.personalAuth === true,
47
- ...(options.repo === undefined ? {} : { repo: options.repo }),
48
- };
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
+ };
49
51
  }
50
52
  function int(value) {
51
- return value === undefined ? undefined : Number(value);
53
+ return value === void 0 ? void 0 : Number(value);
52
54
  }
53
55
  function list(value) {
54
- return value === undefined
55
- ? undefined
56
- : value
57
- .split(',')
58
- .map((part) => part.trim())
59
- .filter(Boolean);
56
+ return value === void 0 ? void 0 : value.split(",").map((part) => part.trim()).filter(Boolean);
60
57
  }
61
58
  function ints(value) {
62
- return list(value)?.map(Number);
59
+ return list(value)?.map(Number);
63
60
  }
64
61
  function body(value, file) {
65
- if (value !== undefined && file !== undefined)
66
- throw new Error('Pass either --body or --body-file.');
67
- 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");
68
64
  }
69
- function fields(file, overrides) {
70
- const value = file === undefined ? {} : JSON.parse(readFileSync(file, 'utf8'));
71
- return {
72
- ...IssueWriteSchema.extend({
73
- ...NativeIssueDateFields,
74
- ...IssueDeferralPatch,
75
- status: IssueStatusPatch.optional(),
76
- preserveHistory: z.boolean().optional(),
77
- }).parse(value),
78
- ...Object.fromEntries(Object.entries(overrides).filter(([, item]) => item !== undefined)),
79
- };
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
+ };
80
77
  }
81
78
  function run(name, input) {
82
- 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
+ );
83
83
  }
84
84
  function print(value) {
85
- process.stdout.write(`${JSON.stringify(value, null, 2)}\n`);
85
+ process.stdout.write(`${JSON.stringify(value, null, 2)}
86
+ `);
86
87
  }
87
88
  function reconciliationFile(path) {
88
- const limit = 16 * 1024 * 1024;
89
- const stat = statSync(path);
90
- if (!stat.isFile() || stat.size > limit)
91
- throw new DeliveryError('Reconciliation files must be regular UTF-8 JSON files of at most 16 MiB.');
92
- const bytes = readFileSync(path);
93
- if (bytes.byteLength > limit)
94
- throw new DeliveryError('Reconciliation files exceed 16 MiB.');
95
- return JSON.parse(new TextDecoder('utf-8', { fatal: true }).decode(bytes));
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));
96
96
  }
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
100
- .command(action)
101
- .requiredOption('--host <host>', 'Native host: codex or claude-code')
102
- .option('--scope <scope>', 'Native scope: user, project, or local; Codex supports user', 'user')
103
- .option('--dry-run', 'Describe the selected target without changing files or contacting native tools')
104
- .option('--json', 'Print the result as JSON');
105
- if (action === 'install' || action === 'update')
106
- command.requiredOption('--version <version>', 'Explicit published package version');
107
- if (action === 'doctor')
108
- command.option('--check-auth', 'Read configured role identities and repository access; requires explicit --repo');
109
- command.action(async (options) => {
110
- const result = await managePlugin({
111
- action,
112
- host: options.host,
113
- scope: options.scope,
114
- ...(options.version === undefined ? {} : { version: options.version }),
115
- dryRun: options.dryRun === true,
116
- checkAuth: options.checkAuth === true,
117
- ...(options.checkAuth && execution().repo ? { repo: execution().repo } : {}),
118
- repoRoot: execution().repoRoot,
119
- });
120
- if (options.json) {
121
- print(result);
122
- return;
123
- }
124
- process.stdout.write(`${result.dryRun ? 'Dry run: ' : ''}${result.host} ${result.scope}: ${action}; version ${result.version ?? 'none'}; installed ${result.installed}; changed ${result.changed}\n`);
125
- if (result.mcp)
126
- process.stdout.write(`Bundled MCP startup: ${result.mcp.startup}${result.mcp.error ? ` (${result.mcp.error})` : ''}\n`);
127
- if (result.diagnostics) {
128
- process.stdout.write(`Registration observations: ${result.diagnostics.registrations.length}; completeness ${result.diagnostics.completeness}; migration ${result.diagnostics.migration}; planned changes ${result.diagnostics.plannedChanges.length}\n`);
129
- for (const entry of result.diagnostics.registrations)
130
- process.stdout.write(`${entry.kind} ${entry.scope}: ownership ${entry.ownership}; source ${entry.source}; version ${entry.version ?? 'unknown'}\n`);
131
- process.stdout.write(`Unverified conditions: ${result.diagnostics.findings.join(', ')}\n`);
132
- }
133
- if (result.activation)
134
- 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`);
135
- if (result.recoveryRequired)
136
- process.stdout.write('Resume the interrupted original plugin command to recover this target.\n');
137
- if (result.authProbe)
138
- 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`);
139
- });
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
+ );
140
157
  }
141
- program
142
- .command('runtime:stage')
143
- .description('Stage a reviewed archive in a private directory; does not activate or admit it')
144
- .requiredOption('--archive <path>')
145
- .requiredOption('--archive-sha256 <digest>')
146
- .requiredOption('--package-version <version>')
147
- .requiredOption('--source-commit <sha>')
148
- .requiredOption('--config-digest <digest>')
149
- .requiredOption('--runtime-directory <path>')
150
- .option('--native-plugin-root <path>', 'Bind the exact reviewed native plugin root')
151
- .option('--max-aggregate-rss-bytes <bytes>', 'Sampled controller plus children RSS limit')
152
- .option('--max-new-output-bytes <bytes>', 'Owned stage and metadata output limit')
153
- .option('--min-free-disk-bytes <bytes>', 'Required free disk headroom')
154
- .option('--max-captured-output-bytes <bytes>', 'Retained command log cap; defaults to 1 MiB')
155
- .option('--authorize-stage', 'Explicit authority to stage this reviewed archive')
156
- .action(async (o) => run('runtime_stage', {
157
- authority: o.authorizeStage === true ? 'runtime:stage' : '',
158
- archivePath: o.archive,
159
- expectedArchiveSha256: o.archiveSha256,
160
- packageVersion: o.packageVersion,
161
- expectedSourceCommit: o.sourceCommit,
162
- expectedConfigDigest: o.configDigest,
163
- runtimeDirectory: o.runtimeDirectory,
164
- ...(o.nativePluginRoot === undefined ? {} : { nativePluginRoot: o.nativePluginRoot }),
165
- ...(['maxAggregateRssBytes', 'maxNewOutputBytes', 'minFreeDiskBytes', 'maxCapturedOutputBytes'].some((key) => o[key] !== undefined)
166
- ? {
167
- resourceBounds: {
168
- maxAggregateRssBytes: Number(o.maxAggregateRssBytes ?? 1024 ** 3),
169
- minFreeDiskBytes: Number(o.minFreeDiskBytes ?? 256 * 1024 ** 2),
170
- maxNewOutputBytes: Number(o.maxNewOutputBytes ?? 512 * 1024 ** 2),
171
- maxCapturedOutputBytes: Number(o.maxCapturedOutputBytes ?? 1024 ** 2),
172
- },
173
- }
174
- : {}),
175
- }));
176
- program
177
- .command('runtime:admit')
178
- .description('Explicitly publish the existing admission for an exact completed stage')
179
- .requiredOption('--stage-id <digest>')
180
- .requiredOption('--source-commit <sha>')
181
- .requiredOption('--config-digest <digest>')
182
- .requiredOption('--runtime-directory <path>')
183
- .option('--expected-prior <digest>', 'SHA-256 of the exact current private admission bytes')
184
- .option('--expected-absent', 'Explicitly require no current admission')
185
- .option('--authorize-admit', 'Explicit authority for the final admission write')
186
- .action(async (o) => {
187
- if ((o.expectedPrior === undefined) === (o.expectedAbsent !== true))
188
- throw new Error('Choose exactly one of --expected-prior or --expected-absent.');
189
- return run('runtime_admit', {
190
- authority: o.authorizeAdmit === true ? 'runtime:admit' : '',
191
- stageId: o.stageId,
192
- expectedSourceCommit: o.sourceCommit,
193
- expectedConfigDigest: o.configDigest,
194
- runtimeDirectory: o.runtimeDirectory,
195
- expectedPriorAdmissionSha256: o.expectedAbsent === true ? null : o.expectedPrior,
196
- });
197
- });
198
- program
199
- .command('create')
200
- .requiredOption('--title <title>')
201
- .option('--fields-file <path>', 'UTF-8 JSON typed fields; explicit CLI fields take precedence')
202
- .option('--draft', 'Explicitly write an incomplete parked draft')
203
- .option('--body <markdown>')
204
- .option('--body-file <path>')
205
- .option('--type <type>')
206
- .option('--points <number>')
207
- .option('--priority <priority>')
208
- .option('--labels <labels>')
209
- .option('--blocked-by <numbers>')
210
- .option('--blocks <numbers>', 'Add this issue as a blocker of these dependents')
211
- .option('--override-reason <reason>', 'Required explanation when adding a blocker to active work')
212
- .option('--milestone <number>')
213
- .option('--parent <number>')
214
- .action(async (o) => run('issue_create', fields(o.fieldsFile, {
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,
215
184
  title: o.title,
216
185
  body: body(o.body, o.bodyFile),
217
186
  issueType: o.type,
@@ -223,44 +192,34 @@ program
223
192
  overrideReason: o.overrideReason,
224
193
  milestone: int(o.milestone),
225
194
  parentIssueNumber: int(o.parent),
226
- ...(o.draft === true ? { draft: true } : {}),
227
- })));
228
- program
229
- .command('start')
230
- .option('--issue <number>')
231
- .option('--request <text>')
232
- .option('--request-id <id>', 'Stable retry identity for a new issue start')
233
- .option('--title <title>')
234
- .option('--body <markdown>')
235
- .option('--body-file <path>')
236
- .option('--type <type>')
237
- .option('--points <number>')
238
- .option('--priority <priority>')
239
- .option('--labels <labels>')
240
- .option('--blocked-by <numbers>')
241
- .option('--blocks <numbers>', 'Add this issue as a blocker of these dependents')
242
- .option('--override-reason <reason>', 'Capacity override reason, or explanation when adding a blocker to active work')
243
- .option('--milestone <number>')
244
- .option('--parent <number>')
245
- .option('--branch <branch>')
246
- .option('--resume-created')
247
- .option('--investigation-worktree <path>', 'Prospectively register an already linked host-created investigation')
248
- .option('--expected-head <sha>', 'Exact unchanged initial commit for investigation registration')
249
- .action(async (o) => {
250
- if (o.investigationWorktree !== undefined || o.expectedHead !== undefined) {
251
- if (Object.keys(o).some((key) => !['issue', 'investigationWorktree', 'expectedHead'].includes(key)))
252
- throw new Error('Investigation registration cannot create or change issue/branch metadata.');
253
- return run('issue_start', {
254
- issueNumber: int(o.issue),
255
- investigationWorktree: o.investigationWorktree,
256
- expectedHeadSha: o.expectedHead,
257
- });
258
- }
259
- 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
+ {
260
220
  issueNumber: int(o.issue),
261
- request: o.request,
262
- requestId: o.requestId,
263
221
  title: o.title,
222
+ ...o.draft === true ? { draft: true } : {},
264
223
  body: body(o.body, o.bodyFile),
265
224
  issueType: o.type,
266
225
  points: int(o.points),
@@ -271,317 +230,245 @@ program
271
230
  overrideReason: o.overrideReason,
272
231
  milestone: int(o.milestone),
273
232
  parentIssueNumber: int(o.parent),
274
- branch: o.branch,
275
- resumeCreated: o.resumeCreated === true,
276
- });
277
- });
278
- for (const name of ['list', 'search']) {
279
- program
280
- .command(name)
281
- .option('--query <text>', 'Literal text to search in the selected repository')
282
- .option('--state <state>')
283
- .option('--labels <labels>')
284
- .option('--parent <number>')
285
- .option('--type <type>')
286
- .option('--project-status <status>')
287
- .option('--updated-since <timestamp>')
288
- .option('--page <number>')
289
- .option('--per-page <number>')
290
- .action(async (o) => run(name === 'list' ? 'issue_list' : 'issue_search', {
291
- query: o.query,
292
233
  state: o.state,
293
- labels: list(o.labels),
294
- parentIssueNumber: int(o.parent),
295
- issueType: o.type,
296
- projectStatus: o.projectStatus,
297
- updatedSince: o.updatedSince,
298
- page: int(o.page),
299
- perPage: int(o.perPage),
300
- }));
301
- }
302
- program
303
- .command('update')
304
- .requiredOption('--issue <number>')
305
- .option('--fields-file <path>', 'UTF-8 JSON typed issue field patch')
306
- .option('--draft', 'Explicitly write an incomplete parked draft')
307
- .option('--title <title>')
308
- .option('--body <markdown>')
309
- .option('--body-file <path>')
310
- .option('--type <type>')
311
- .option('--points <number>')
312
- .option('--priority <priority>')
313
- .option('--labels <labels>')
314
- .option('--blocked-by <numbers>')
315
- .option('--blocks <numbers>', 'Add this issue as a blocker of these dependents')
316
- .option('--override-reason <reason>', 'Required explanation when adding a blocker to active work')
317
- .option('--milestone <number>')
318
- .option('--parent <number>')
319
- .option('--state <state>')
320
- .option('--preserve-history', 'Preserve the previous title and body before a rewrite')
321
- .option('--close-reason <reason>')
322
- .option('--superseded-by <number>')
323
- .option('--park', 'Park execution while retaining the issue worktree')
324
- .option('--defer', 'Defer until an explicit undefer')
325
- .option('--defer-until <date>', 'Record an ISO date condition without automatic undeferral')
326
- .option('--defer-trigger <text>', 'Record the condition for reconsidering deferred work')
327
- .option('--undefer', 'Explicitly clear deferral; draft and park remain unchanged')
328
- .action(async (o) => run('issue_update', fields(o.fieldsFile, {
329
- issueNumber: int(o.issue),
330
- title: o.title,
331
- ...(o.draft === true ? { draft: true } : {}),
332
- body: body(o.body, o.bodyFile),
333
- issueType: o.type,
334
- points: int(o.points),
335
- priority: o.priority,
336
- labels: list(o.labels),
337
- blockedBy: ints(o.blockedBy),
338
- blocks: ints(o.blocks),
339
- overrideReason: o.overrideReason,
340
- milestone: int(o.milestone),
341
- parentIssueNumber: int(o.parent),
342
- state: o.state,
343
- preserveHistory: o.preserveHistory === true ? true : undefined,
344
- closeReason: o.closeReason,
345
- supersededBy: int(o.supersededBy),
346
- park: o.park === true ? true : undefined,
347
- defer: o.defer === true || o.deferUntil !== undefined || o.deferTrigger !== undefined
348
- ? {
349
- ...(o.deferUntil === undefined ? {} : { until: o.deferUntil }),
350
- ...(o.deferTrigger === undefined ? {} : { trigger: o.deferTrigger }),
351
- }
352
- : undefined,
353
- undefer: o.undefer === true ? true : undefined,
354
- })));
355
- program
356
- .command('board:reconcile')
357
- .description('Plan or apply bounded Project reconciliation for explicit repositories')
358
- .requiredOption('--repositories <owner/repo...>', '1–10 explicit GitHub repositories')
359
- .option('--checkouts-file <path>', 'UTF-8 JSON checkout selectors for dry-run')
360
- .option('--dry-run', 'Collect a plan without writes (default)')
361
- .option('--apply', 'Apply the retained original plan')
362
- .option('--plan-file <path>', 'Original complete reconciliation plan JSON')
363
- .option('--prior-result-file <path>', 'Optional prior result JSON for the exact original plan')
364
- .action(async (options) => {
365
- if (options.dryRun && options.apply)
366
- throw new DeliveryError('Choose either --dry-run or --apply.');
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.");
367
262
  const request = parseBoardReconcileRequest({
368
- repositories: options.repositories,
369
- ...(execution().repo === undefined ? {} : { repo: execution().repo }),
370
- mode: options.apply ? 'apply' : 'dry-run',
371
- ...(options.checkoutsFile === undefined ? {} : { checkouts: reconciliationFile(options.checkoutsFile) }),
372
- ...(options.planFile === undefined ? {} : { plan: reconciliationFile(options.planFile) }),
373
- ...(options.priorResultFile === undefined ? {} : { priorResult: reconciliationFile(options.priorResultFile) }),
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) }
374
269
  });
375
- return run('board_reconcile', request);
376
- });
377
- program
378
- .command('batch:update')
379
- .description('Plan or apply 1–50 current-repository issue updates with ordered readback')
380
- .requiredOption('--items-file <path>', 'UTF-8 JSON array of complete issue_update inputs')
381
- .option('--dry-run', 'Return plans and readback without any native writes')
382
- .action(async (o) => run('issue_batch_update', {
383
- items: JSON.parse(readFileSync(o.itemsFile, 'utf8')),
384
- dryRun: o.dryRun === true,
385
- }));
386
- program
387
- .command('health')
388
- .requiredOption('--from <utc>', 'Inclusive UTC ISO timestamp')
389
- .requiredOption('--to <utc>', 'Exclusive UTC ISO timestamp')
390
- .option('--max-issues <number>')
391
- .option('--max-timeline-pages <number>')
392
- .option('--max-project-pages <number>')
393
- .option('--oldest-limit <number>')
394
- .action(async (o) => run('delivery_health', {
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", {
395
281
  repo: execution().repo,
396
282
  from: o.from,
397
283
  to: o.to,
398
284
  maxIssues: int(o.maxIssues),
399
285
  maxTimelinePages: int(o.maxTimelinePages),
400
286
  maxProjectPages: int(o.maxProjectPages),
401
- oldestLimit: int(o.oldestLimit),
402
- }));
403
- program
404
- .command('info')
405
- .requiredOption('--issue <number>')
406
- .action(async (o) => run('issue_info', { issueNumber: int(o.issue) }));
407
- program
408
- .command('ready:check')
409
- .requiredOption('--issue <number>')
410
- .action(async (o) => run('issue_ready_check', { issueNumber: int(o.issue) }));
411
- for (const field of ['parent', 'blockers']) {
412
- program
413
- .command(field)
414
- .requiredOption('--issue <number>')
415
- .action(async (o) => {
416
- const info = (await executeTool('issue_info', { issueNumber: int(o.issue) }, execution()));
417
- print(field === 'parent'
418
- ? { issueNumber: int(o.issue), parentIssueNumber: info.parentIssueNumber }
419
- : { issueNumber: int(o.issue), blockedBy: info.blockedBy });
420
- });
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
+ });
421
299
  }
422
- program
423
- .command('subissues')
424
- .requiredOption('--issue <number>')
425
- .action(async (o) => {
426
- const context = await contextFor(execution(), 'subissues');
427
- 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)) });
428
303
  });
429
- program
430
- .command('pr:create')
431
- .description('Create a PR from a linked issue branch, or promote an existing associated PR with --head and --ready.')
432
- .requiredOption('--issue <number>')
433
- .option('--pr <number>', 'Exact existing PR selector; never creates a replacement')
434
- .option('--non-closing', 'Retain the issue OPEN using native non-closing reference proof')
435
- .option('--title <title>')
436
- .option('--body-file <path>')
437
- .option('--head <branch>', 'Explicit remote head; existing PR promotion verifies its native issue association')
438
- .option('--ready', 'Publish ready, or promote the author-owned PR selected by --head')
439
- .option('--dry-run')
440
- .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", {
441
309
  issueNumber: int(o.issue),
442
310
  prNumber: int(o.pr),
443
311
  nonClosing: o.nonClosing,
312
+ reconcileNonClosingReference: o.reconcileNonClosingReference,
313
+ expectedHeadSha: o.expectedHead,
314
+ expectedBaseSha: o.expectedBase,
444
315
  title: o.title,
445
- body: body(undefined, o.bodyFile),
316
+ body: body(void 0, o.bodyFile),
446
317
  headBranch: o.head,
318
+ base: o.base,
447
319
  draft: o.ready !== true,
448
- dryRun: o.dryRun === true,
449
- }));
450
- program
451
- .command('pr:info')
452
- .description('Inspect an exact PR; combine --issue and --pr to verify its native closing-issue association.')
453
- .option('--non-closing', 'Verify an exact native non-closing PR-to-issue reference')
454
- .option('--issue <number>', 'Issue to verify; issue-only lookup requires a GitHub-linked branch')
455
- .option('--pr <number>', 'Exact PR number; include --issue after issue branch links are replaced on publication')
456
- .action(async (o) => run('issue_pr_info', { issueNumber: int(o.issue), prNumber: int(o.pr), nonClosing: o.nonClosing }));
457
- program
458
- .command('pr:list')
459
- .option('--state <state>', 'open, closed or all', 'open')
460
- .action(async (o) => {
461
- if (!['open', 'closed', 'all'].includes(o.state))
462
- throw new Error('Invalid PR state.');
463
- const context = await contextFor(execution(), 'pr:list');
464
- 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));
465
330
  });
466
- program
467
- .command('pr:checks')
468
- .requiredOption('--pr <number>')
469
- .action(async (o) => {
470
- const context = await contextFor(execution(), 'pr:checks');
471
- 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)));
472
334
  });
473
- program
474
- .command('pr:review')
475
- .requiredOption('--issue <number>')
476
- .requiredOption('--pr <number>')
477
- .requiredOption('--artifact <path>', 'Path to a UTF-8 JSON review artifact file (not inline JSON)')
478
- .option('--non-closing', 'Retain the referenced issue OPEN; finish refuses this mode')
479
- .option('--dry-run')
480
- .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", {
481
337
  issueNumber: int(o.issue),
482
338
  prNumber: int(o.pr),
483
- artifact: readFileSync(o.artifact, 'utf8'),
339
+ artifact: readFileSync(o.artifact, "utf8"),
484
340
  dryRun: o.dryRun === true,
485
- nonClosing: o.nonClosing,
486
- }));
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
+ });
487
441
  for (const [command, tool] of [
488
- ['pr:merge', 'issue_pr_merge'],
489
- ['finish', 'issue_finish'],
442
+ ["pr:merge", "issue_pr_merge"],
443
+ ["finish", "issue_finish"]
490
444
  ]) {
491
- const mergeCommand = program.command(command).requiredOption('--issue <number>');
492
- if (command === 'pr:merge')
493
- mergeCommand.requiredOption('--pr <number>');
494
- else
495
- mergeCommand.option('--pr <number>');
496
- mergeCommand
497
- .option('--strategy <method>')
498
- .option('--reviewed-head <sha>')
499
- .option('--non-closing', 'Retain the referenced issue OPEN; finish refuses this mode')
500
- .option('--dry-run');
501
- if (command === 'finish')
502
- mergeCommand
503
- .option('--investigation', 'Complete an unchanged prospectively registered investigation')
504
- .option('--result <path>', 'Durable independently reviewed result outside the removable worktree')
505
- .option('--authority-comment <number>', 'Exact native operator removal authority comment')
506
- .option('--acceptance-comment <number>', 'Exact configured-App result acceptance comment');
507
- mergeCommand.action(async (o) => {
508
- if (o.investigation === true) {
509
- if (o.pr !== undefined ||
510
- o.strategy !== undefined ||
511
- o.reviewedHead !== undefined ||
512
- o.nonClosing !== undefined)
513
- throw new Error('Investigation completion cannot accept PR or merge options.');
514
- return run(tool, {
515
- issueNumber: int(o.issue),
516
- investigation: true,
517
- resultPath: o.result,
518
- authorityCommentId: int(o.authorityComment),
519
- acceptanceCommentId: int(o.acceptanceComment),
520
- dryRun: o.dryRun === true,
521
- });
522
- }
523
- if (o.result !== undefined || o.authorityComment !== undefined || o.acceptanceComment !== undefined)
524
- throw new Error('Investigation evidence requires --investigation.');
525
- return run(tool, {
526
- issueNumber: int(o.issue),
527
- prNumber: int(o.pr),
528
- strategy: o.strategy,
529
- reviewedHeadSha: o.reviewedHead,
530
- dryRun: o.dryRun === true,
531
- nonClosing: o.nonClosing,
532
- });
533
- });
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
+ );
534
455
  }
535
- program
536
- .command('worktree:transition:inspect')
537
- .requiredOption('--issue <number>')
538
- .requiredOption('--purpose <purpose>', 'active-resume or merged-cleanup')
539
- .option('--disposition <disposition>', 'retain (default) or explicitly unheld remove')
540
- .option('--terminal-pr <number>')
541
- .option('--retained-holds <comment-ids>', 'Comma-separated native retained-hold comment IDs')
542
- .option('--retained-admission <path>')
543
- .option('--retained-archive <path>')
544
- .action(async (o) => run('issue_worktree_transition_inspect', {
545
- issueNumber: int(o.issue),
546
- purpose: o.purpose,
547
- ...(o.disposition === undefined ? {} : { disposition: o.disposition }),
548
- ...(o.terminalPr === undefined ? {} : { terminalPrNumber: int(o.terminalPr) }),
549
- ...(o.retainedHolds === undefined ? {} : { retainedHoldCommentIds: ints(o.retainedHolds) }),
550
- ...(o.retainedAdmission === undefined ? {} : { retainedAdmissionPath: o.retainedAdmission }),
551
- ...(o.retainedArchive === undefined ? {} : { retainedArchivePath: o.retainedArchive }),
552
- }));
553
- program
554
- .command('worktree:transition:apply')
555
- .requiredOption('--plan <path>')
556
- .requiredOption('--plan-id <digest>')
557
- .requiredOption('--relinquishment-comment <id>')
558
- .requiredOption('--acceptance-comment <id>')
559
- .option('--authorize-transition', 'Explicit authority for this exact independently accepted plan')
560
- .action(async (o) => run('issue_worktree_transition_apply', {
561
- authority: o.authorizeTransition === true ? 'worktree:transition' : '',
562
- planPath: o.plan,
563
- expectedPlanId: o.planId,
564
- relinquishmentCommentId: Number(o.relinquishmentComment),
565
- acceptanceCommentId: Number(o.acceptanceComment),
566
- }));
567
- program
568
- .command('migrate:legacy-issues')
569
- .requiredOption('--input-file <path>', 'Offline legacy issue inventory JSON')
570
- .action((o) => {
571
- const report = planOfflineLegacyIssueMigration(JSON.parse(readFileSync(o.inputFile, 'utf8')));
572
- 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
+ `);
573
460
  });
574
- program
575
- .command('config:resolve')
576
- .description('Read the effective GitHub destination and admission digest')
577
- .action(async () => {
578
- const context = await contextFor(execution(), 'config:resolve');
579
- print({
580
- configDigest: context.configuration?.configDigest,
581
- routing: context.configuration?.routing,
582
- reviewRoute: await preflightReviewRoute(context, undefined, undefined, 'development'),
583
- });
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);
584
473
  });
585
- program.command('mcp:serve').action(async () => serveAiDeliveryMcp(execution()));
586
- program.parseAsync(process.argv).catch(printCommandError);
587
- //# sourceMappingURL=cli.js.map
474
+ //# sourceMappingURL=cli.js.map