@aviaratech/ai-delivery 0.3.43 → 0.3.45

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 (51) hide show
  1. package/README.md +1 -1
  2. package/dist/agentReadiness.test.js +12 -0
  3. package/dist/agentReadiness.test.js.map +2 -2
  4. package/dist/cli.js +2 -1
  5. package/dist/cli.js.map +2 -2
  6. package/dist/directoryIndependent.test.js +22 -3
  7. package/dist/directoryIndependent.test.js.map +3 -3
  8. package/dist/dispatch.js.map +2 -2
  9. package/dist/fixtures/builderReady.d.ts +4 -0
  10. package/dist/fixtures/builderReady.js +2 -0
  11. package/dist/fixtures/builderReady.js.map +2 -2
  12. package/dist/fixtures/inertTarget.d.ts +11 -0
  13. package/dist/fixtures/inertTarget.js +5 -0
  14. package/dist/fixtures/inertTarget.js.map +2 -2
  15. package/dist/fixtures/issue63.d.ts +7 -0
  16. package/dist/issue.d.ts +21 -1
  17. package/dist/issue.js +103 -12
  18. package/dist/issue.js.map +2 -2
  19. package/dist/issueBlockerGuard.test.js +11 -0
  20. package/dist/issueBlockerGuard.test.js.map +2 -2
  21. package/dist/issueContract.d.ts +23 -0
  22. package/dist/issueContract.js +77 -9
  23. package/dist/issueContract.js.map +2 -2
  24. package/dist/issueContract.test.d.ts +3 -0
  25. package/dist/issueContract.test.js +92 -5
  26. package/dist/issueContract.test.js.map +2 -2
  27. package/dist/issueIntake.test.js +37 -0
  28. package/dist/issueIntake.test.js.map +2 -2
  29. package/dist/issueJournal.d.ts +13 -9
  30. package/dist/issueJournal.js +14 -10
  31. package/dist/issueJournal.js.map +2 -2
  32. package/dist/issueJournal.test.js +11 -8
  33. package/dist/issueJournal.test.js.map +2 -2
  34. package/dist/issueTracking.test.js +135 -2
  35. package/dist/issueTracking.test.js.map +3 -3
  36. package/dist/mcp/index.js +10 -3
  37. package/dist/mcp/index.js.map +2 -2
  38. package/dist/mcp/tools.d.ts +49 -25
  39. package/dist/mcp/tools.js +23 -5
  40. package/dist/mcp/tools.js.map +2 -2
  41. package/dist/readView.d.ts +2 -0
  42. package/dist/readView.js +1 -1
  43. package/dist/readView.js.map +2 -2
  44. package/dist/releaseReconciliation.test.js +20 -6
  45. package/dist/releaseReconciliation.test.js.map +2 -2
  46. package/package.json +1 -1
  47. package/plugins/ai-delivery/.claude-plugin/plugin.json +2 -2
  48. package/plugins/ai-delivery/plugin.json +1 -1
  49. package/plugins/ai-delivery/runtime/dist/cli.js +139 -113
  50. package/plugins/ai-delivery/runtime/package.json +1 -1
  51. package/plugins/ai-delivery/skills/ticket-design/SKILL.md +11 -10
package/dist/issue.js CHANGED
@@ -37,6 +37,7 @@ import {
37
37
  } from "./github/projectNumbers.js";
38
38
  import {
39
39
  getNativeBlockerRelationships,
40
+ getNativeBlockingRelationships,
40
41
  hasNativeSubIssues,
41
42
  linkBlockedBy,
42
43
  replaceBlockedBy,
@@ -57,6 +58,7 @@ import {
57
58
  requireIssueStatus,
58
59
  parseIssueBody,
59
60
  requireIssue,
61
+ addedLocalPaths,
60
62
  renderIssueBody,
61
63
  issueWarnings,
62
64
  issueBodyDiff,
@@ -212,13 +214,15 @@ async function labels(context, input) {
212
214
  }
213
215
  throw new DeliveryError("Repository label listing exceeds the bounded readback window.");
214
216
  }
217
+ const BLOCKERS_DISAGREE = "status.blockers must name each blockedBy issue as #<n>, or start with None; or send only blockedBy.";
218
+ const blockersAgree = (blockedBy, text) => blockedBy.length === 0 ? /^None\b/u.test(text) : blockedBy.every((number) => new RegExp(`#${String(number)}(?!\\d)`, "u").test(text));
215
219
  function prepareIssueWrite(input, current, forIntent = false) {
216
220
  const patch = input.status === void 0 ? void 0 : requireIssueStatus(
217
221
  IssueStatusPatch,
218
222
  current === void 0 ? requireIssueStatus(CreateIssueStatus, input.status) : input.status
219
223
  );
220
- if (input.blockedBy !== void 0 && patch && "blockers" in patch)
221
- throw new DeliveryError("Choose native blockedBy or display-only status.blockers in one update, not both.");
224
+ if (input.blockedBy !== void 0 && patch?.blockers !== void 0 && !blockersAgree(input.blockedBy, patch.blockers))
225
+ throw new DeliveryError(BLOCKERS_DISAGREE);
222
226
  const statusOnly = patch !== void 0 && Object.entries(input).every(
223
227
  ([key, value]) => value === void 0 || ["repo", "issueNumber", "status", "projectStatus"].includes(key)
224
228
  );
@@ -266,6 +270,10 @@ function prepareIssueWrite(input, current, forIntent = false) {
266
270
  },
267
271
  requireBuilder ? { requireBuilder: true } : {}
268
272
  );
273
+ if (currentParsed !== void 0 && !currentParsed.issue.draft && !issue.draft) {
274
+ const added = addedLocalPaths(currentParsed.issue, issue);
275
+ if (added.length) throw new IssueValidationError(added);
276
+ }
269
277
  const unchangedContract = currentParsed !== void 0 && JSON.stringify(issue) === JSON.stringify(currentParsed.issue);
270
278
  const legacyFormatting = unchangedContract && parsed.legacyFormatting === true;
271
279
  const base = parsed.status ?? currentParsed?.status;
@@ -275,7 +283,7 @@ function prepareIssueWrite(input, current, forIntent = false) {
275
283
  nextMilestone: patch?.nextMilestone ?? base?.nextMilestone ?? "Not started",
276
284
  blockers: patch?.blockers ?? base?.blockers ?? "None",
277
285
  latestJournal: patch?.latestJournal ?? base?.latestJournal ?? "None yet",
278
- ...input.blockedBy === void 0 ? {} : {
286
+ ...input.blockedBy === void 0 || patch?.blockers !== void 0 ? {} : {
279
287
  blockers: input.blockedBy.length ? input.blockedBy.map((number) => "#" + String(number)).join(", ") : "None"
280
288
  }
281
289
  };
@@ -942,7 +950,7 @@ async function assertProjectTransition(context, plan, recordOverride = false, va
942
950
  }
943
951
  }
944
952
  const BODY_FREE_KEYS = /* @__PURE__ */ new Set([
945
- ..."repo issueNumber state closeReason supersededBy preserveHistory overrideReason".split(" "),
953
+ ..."repo issueNumber state closeReason closeout supersededBy preserveHistory overrideReason".split(" "),
946
954
  ..."projectStatus milestone labels priority startDate targetDate".split(" "),
947
955
  ..."expectedTradesPerDay measuredTradesPerDay".split(" ")
948
956
  ]);
@@ -983,7 +991,7 @@ function rebuildableWrite(input, current) {
983
991
  "draft",
984
992
  "openQuestions",
985
993
  "context",
986
- ...["builder", "extends", "decisions", "surface", "fences", "proof"].filter((key) => carried.has(key))
994
+ ...["builder", "extends", "priorWork", "decisions", "moneyPath", "ownerOk", "surface", "fences", "proof"].filter((key) => carried.has(key))
987
995
  ].filter((key) => input[key] === void 0);
988
996
  if (reset.length) {
989
997
  const message = `Rebuilt the hand-edited body (old one in the history comment); reset because not sent: ${reset.join(", ")}.`;
@@ -1014,7 +1022,7 @@ async function prepareIssueUpdate(context, input) {
1014
1022
  throw new DeliveryError("A superseding issue must be a different positive issue number.");
1015
1023
  const { clients, config, repo } = context;
1016
1024
  const preserveArchived = Object.keys(input).every(
1017
- (key) => ["issueNumber", "title", "state", "closeReason", "supersededBy", "preserveHistory"].includes(key)
1025
+ (key) => ["issueNumber", "title", "state", "closeReason", "closeout", "supersededBy", "preserveHistory"].includes(key)
1018
1026
  );
1019
1027
  const dateChanges = await prepareIssueDates(context, input);
1020
1028
  const currentContent = await issueInfo(context, input.issueNumber);
@@ -1102,6 +1110,9 @@ async function prepareIssueUpdate(context, input) {
1102
1110
  }
1103
1111
  }
1104
1112
  }
1113
+ const studyClose = await prepareStudyClose(context, input, closeReason, input.title ?? currentContent.title);
1114
+ const unblocks = closeReason === void 0 ? void 0 : await readUnblocks(context, input.issueNumber);
1115
+ if (unblocks?.warning !== void 0) prepared.warnings.push(unblocks.warning);
1105
1116
  let historyBody;
1106
1117
  let priorContent = input.status === void 0 ? void 0 : { title: currentContent.title, body: currentContent.body };
1107
1118
  if (input.preserveHistory === true && (input.title !== void 0 || input.body !== void 0)) {
@@ -1123,8 +1134,12 @@ async function prepareIssueUpdate(context, input) {
1123
1134
  historyBody = body;
1124
1135
  }
1125
1136
  }
1126
- const closureBody = closeReason === void 0 ? void 0 : `Requested closure reason: ${closeReason}.${input.supersededBy === void 0 ? "" : `
1127
- Superseded by ${repo.owner}/${repo.repo}#${String(input.supersededBy)}.`}`;
1137
+ const closureBody = closeReason === void 0 ? void 0 : [
1138
+ ...studyClose ?? [],
1139
+ `Requested closure reason: ${closeReason}.${input.supersededBy === void 0 ? "" : `
1140
+ Superseded by ${repo.owner}/${repo.repo}#${String(input.supersededBy)}.`}`,
1141
+ ...unblocks?.numbers.length ? [`**Unblocks:** ${unblocks.numbers.map((n) => `#${String(n)}`).join(", ")}`] : []
1142
+ ].join("\n\n");
1128
1143
  const target = (await clients.rest.issues.get({ ...repo, issue_number: input.issueNumber })).data;
1129
1144
  if (target.number !== input.issueNumber || "pull_request" in target || !target.node_id || target.html_url !== currentContent.url || new URL(target.html_url).pathname.toLowerCase() !== `/${repo.owner}/${repo.repo}/issues/${String(input.issueNumber)}`.toLowerCase())
1130
1145
  throw new DeliveryError("History target is not the requested issue.");
@@ -1151,9 +1166,77 @@ Superseded by ${repo.owner}/${repo.repo}#${String(input.supersededBy)}.`}`;
1151
1166
  dateChanges,
1152
1167
  priorContent,
1153
1168
  historyBody,
1154
- closureBody
1169
+ closureBody,
1170
+ unblocks: unblocks?.numbers
1155
1171
  };
1156
1172
  }
1173
+ const STUDY_TITLE = /^study\b/iu;
1174
+ async function prepareStudyClose(context, input, closeReason, title) {
1175
+ const study = STUDY_TITLE.test(title);
1176
+ if (study && input.state === "closed" && closeReason === void 0)
1177
+ throw new DeliveryError("Pass closeReason to close a study: 'completed' with closeout, or 'not_planned'.");
1178
+ if (!study || closeReason !== "completed") {
1179
+ if (input.closeout !== void 0)
1180
+ throw new DeliveryError('closeout applies only when closing a study (title starts with "Study") as completed.');
1181
+ return void 0;
1182
+ }
1183
+ const verdict = input.closeout?.verdict.trim() ?? "";
1184
+ const result = input.closeout?.result ?? "";
1185
+ if (!verdict || verdict.split("\n").length > 3 || verdict.length > 600)
1186
+ throw new DeliveryError("Pass closeout.verdict (1\u20133 lines) to close a study.");
1187
+ if (!result.trim() || result.length > 4e3)
1188
+ throw new DeliveryError(
1189
+ "Pass closeout.result (the READOUT's Result section); GitHub search doesn't read artifacts."
1190
+ );
1191
+ const artifacts = await readIssueArtifacts(context, input.issueNumber);
1192
+ if (!artifacts.some((artifact) => /^readout\b/iu.test(artifact.name)))
1193
+ throw new DeliveryError(
1194
+ `Attach the READOUT with gh issue artifact create ${String(input.issueNumber)} READOUT.md, then close again.`
1195
+ );
1196
+ return [
1197
+ `**Verdict:** ${verdict}`,
1198
+ `**Result:**
1199
+
1200
+ ${result}`,
1201
+ `**Artifacts:**
1202
+ ${artifacts.map((artifact) => `- [${artifact.name}](${artifact.url})`).join("\n")}`
1203
+ ];
1204
+ }
1205
+ const IssueArtifactRows = z.array(
1206
+ z.object({ number: z.number().int().positive(), name: z.string(), type: z.string(), html_url: z.url() })
1207
+ );
1208
+ async function readIssueArtifacts(context, issueNumber) {
1209
+ let status;
1210
+ let data;
1211
+ try {
1212
+ const response = await context.clients.rest.request(
1213
+ "GET /repos/{owner}/{repo}/issues/{issue_number}/artifacts",
1214
+ { ...context.repo, issue_number: issueNumber, per_page: 100 }
1215
+ );
1216
+ ({ status, data } = response);
1217
+ } catch (error) {
1218
+ status = error.status ?? "unavailable";
1219
+ }
1220
+ const rows = status === 200 ? IssueArtifactRows.safeParse(data) : void 0;
1221
+ if (!rows?.success)
1222
+ throw new DeliveryError(
1223
+ `Can't read this issue's artifacts (HTTP ${String(status)}); attach the READOUT with gh issue artifact create and retry.`
1224
+ );
1225
+ return rows.data.map((row) => ({ number: row.number, name: row.name, type: row.type, url: row.html_url }));
1226
+ }
1227
+ async function readUnblocks(context, issueNumber) {
1228
+ try {
1229
+ const dependents = await getNativeBlockingRelationships({
1230
+ graphql: context.clients.graphql,
1231
+ issueNumber,
1232
+ repo: context.repo
1233
+ });
1234
+ return { numbers: dependents.filter((issue) => issue.state === "OPEN").map((issue) => issue.number) };
1235
+ } catch (error) {
1236
+ const message = `Couldn't read the issues #${String(issueNumber)} blocks (${error instanceof Error ? error.message : String(error)}); the close has no Unblocks line, so tell their owners yourself.`;
1237
+ return { numbers: [], warning: { code: "close.unblocks", field: "blocking", message, fixHint: message } };
1238
+ }
1239
+ }
1157
1240
  async function updateIssue(context, input) {
1158
1241
  const { expectedTradesPerDay, measuredTradesPerDay, ...fields } = input;
1159
1242
  const patch = projectTradePatch({ expectedTradesPerDay, measuredTradesPerDay });
@@ -1443,7 +1526,8 @@ async function applyIssueUpdate(context, plan, changes) {
1443
1526
  ...prepared.conversion === void 0 ? {} : { conversion: prepared.conversion },
1444
1527
  ...projectStatusComment === void 0 ? {} : { projectStatusComment },
1445
1528
  ...historyComment === void 0 ? {} : { historyComment },
1446
- ...closure === void 0 || closureComment === void 0 ? {} : { closure: { ...closure, supersededBy: input.supersededBy ?? null, comment: closureComment } }
1529
+ ...closure === void 0 || closureComment === void 0 ? {} : { closure: { ...closure, supersededBy: input.supersededBy ?? null, comment: closureComment } },
1530
+ ...plan.unblocks === void 0 ? {} : { unblocks: plan.unblocks }
1447
1531
  };
1448
1532
  }
1449
1533
  async function findUpdateComment(context, issueNumber, body) {
@@ -1647,7 +1731,7 @@ function localBatchFailureReason(error) {
1647
1731
  if ([
1648
1732
  "Choose a valid defer condition or explicit undefer, never both.",
1649
1733
  "Use defer or undefer to change deferral state.",
1650
- "Choose native blockedBy or display-only status.blockers in one update, not both.",
1734
+ BLOCKERS_DISAGREE,
1651
1735
  "Convert the legacy contract explicitly before a status-only update.",
1652
1736
  "Issue labels must be non-empty and unique.",
1653
1737
  "Repository label listing exceeds the bounded readback window.",
@@ -1878,7 +1962,14 @@ async function readIssueInfo(context, issueNumber, includeProject = true, expect
1878
1962
  return { info, issueNodeId: issue.node_id, issueNumber: issue.number };
1879
1963
  }
1880
1964
  async function issueInfo(context, issueNumber, options = {}) {
1881
- return (await readIssueInfo(context, issueNumber, true, void 0, options.childDetail)).info;
1965
+ const info = (await readIssueInfo(context, issueNumber, true, void 0, options.childDetail)).info;
1966
+ if (options.artifacts !== true) return info;
1967
+ try {
1968
+ return { ...info, artifacts: await readIssueArtifacts(context, issueNumber) };
1969
+ } catch (error) {
1970
+ const message = error instanceof Error ? error.message : String(error);
1971
+ return { ...info, warnings: [{ code: "artifacts.unread", field: "artifacts", message, fixHint: message }] };
1972
+ }
1882
1973
  }
1883
1974
  function childCounts(children) {
1884
1975
  const closedChildCount = children.filter((child) => child.state === "closed").length;