@aviaratech/ai-delivery 0.3.43 → 0.3.44

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 +2 -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 +7 -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 +3 -0
  16. package/dist/issue.d.ts +21 -1
  17. package/dist/issue.js +100 -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 +7 -0
  22. package/dist/issueContract.js +56 -9
  23. package/dist/issueContract.js.map +2 -2
  24. package/dist/issueContract.test.d.ts +1 -0
  25. package/dist/issueContract.test.js +66 -4
  26. package/dist/issueContract.test.js.map +2 -2
  27. package/dist/issueIntake.test.js +17 -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 +39 -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 +138 -112
  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,
@@ -212,13 +213,15 @@ async function labels(context, input) {
212
213
  }
213
214
  throw new DeliveryError("Repository label listing exceeds the bounded readback window.");
214
215
  }
216
+ const BLOCKERS_DISAGREE = "status.blockers must name each blockedBy issue as #<n>, or start with None; or send only blockedBy.";
217
+ const blockersAgree = (blockedBy, text) => blockedBy.length === 0 ? /^None\b/u.test(text) : blockedBy.every((number) => new RegExp(`#${String(number)}(?!\\d)`, "u").test(text));
215
218
  function prepareIssueWrite(input, current, forIntent = false) {
216
219
  const patch = input.status === void 0 ? void 0 : requireIssueStatus(
217
220
  IssueStatusPatch,
218
221
  current === void 0 ? requireIssueStatus(CreateIssueStatus, input.status) : input.status
219
222
  );
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.");
223
+ if (input.blockedBy !== void 0 && patch?.blockers !== void 0 && !blockersAgree(input.blockedBy, patch.blockers))
224
+ throw new DeliveryError(BLOCKERS_DISAGREE);
222
225
  const statusOnly = patch !== void 0 && Object.entries(input).every(
223
226
  ([key, value]) => value === void 0 || ["repo", "issueNumber", "status", "projectStatus"].includes(key)
224
227
  );
@@ -275,7 +278,7 @@ function prepareIssueWrite(input, current, forIntent = false) {
275
278
  nextMilestone: patch?.nextMilestone ?? base?.nextMilestone ?? "Not started",
276
279
  blockers: patch?.blockers ?? base?.blockers ?? "None",
277
280
  latestJournal: patch?.latestJournal ?? base?.latestJournal ?? "None yet",
278
- ...input.blockedBy === void 0 ? {} : {
281
+ ...input.blockedBy === void 0 || patch?.blockers !== void 0 ? {} : {
279
282
  blockers: input.blockedBy.length ? input.blockedBy.map((number) => "#" + String(number)).join(", ") : "None"
280
283
  }
281
284
  };
@@ -942,7 +945,7 @@ async function assertProjectTransition(context, plan, recordOverride = false, va
942
945
  }
943
946
  }
944
947
  const BODY_FREE_KEYS = /* @__PURE__ */ new Set([
945
- ..."repo issueNumber state closeReason supersededBy preserveHistory overrideReason".split(" "),
948
+ ..."repo issueNumber state closeReason closeout supersededBy preserveHistory overrideReason".split(" "),
946
949
  ..."projectStatus milestone labels priority startDate targetDate".split(" "),
947
950
  ..."expectedTradesPerDay measuredTradesPerDay".split(" ")
948
951
  ]);
@@ -983,7 +986,9 @@ function rebuildableWrite(input, current) {
983
986
  "draft",
984
987
  "openQuestions",
985
988
  "context",
986
- ...["builder", "extends", "decisions", "surface", "fences", "proof"].filter((key) => carried.has(key))
989
+ ...["builder", "extends", "priorWork", "decisions", "surface", "fences", "proof"].filter(
990
+ (key) => carried.has(key)
991
+ )
987
992
  ].filter((key) => input[key] === void 0);
988
993
  if (reset.length) {
989
994
  const message = `Rebuilt the hand-edited body (old one in the history comment); reset because not sent: ${reset.join(", ")}.`;
@@ -1014,7 +1019,7 @@ async function prepareIssueUpdate(context, input) {
1014
1019
  throw new DeliveryError("A superseding issue must be a different positive issue number.");
1015
1020
  const { clients, config, repo } = context;
1016
1021
  const preserveArchived = Object.keys(input).every(
1017
- (key) => ["issueNumber", "title", "state", "closeReason", "supersededBy", "preserveHistory"].includes(key)
1022
+ (key) => ["issueNumber", "title", "state", "closeReason", "closeout", "supersededBy", "preserveHistory"].includes(key)
1018
1023
  );
1019
1024
  const dateChanges = await prepareIssueDates(context, input);
1020
1025
  const currentContent = await issueInfo(context, input.issueNumber);
@@ -1102,6 +1107,9 @@ async function prepareIssueUpdate(context, input) {
1102
1107
  }
1103
1108
  }
1104
1109
  }
1110
+ const studyClose = await prepareStudyClose(context, input, closeReason, input.title ?? currentContent.title);
1111
+ const unblocks = closeReason === void 0 ? void 0 : await readUnblocks(context, input.issueNumber);
1112
+ if (unblocks?.warning !== void 0) prepared.warnings.push(unblocks.warning);
1105
1113
  let historyBody;
1106
1114
  let priorContent = input.status === void 0 ? void 0 : { title: currentContent.title, body: currentContent.body };
1107
1115
  if (input.preserveHistory === true && (input.title !== void 0 || input.body !== void 0)) {
@@ -1123,8 +1131,12 @@ async function prepareIssueUpdate(context, input) {
1123
1131
  historyBody = body;
1124
1132
  }
1125
1133
  }
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)}.`}`;
1134
+ const closureBody = closeReason === void 0 ? void 0 : [
1135
+ ...studyClose ?? [],
1136
+ `Requested closure reason: ${closeReason}.${input.supersededBy === void 0 ? "" : `
1137
+ Superseded by ${repo.owner}/${repo.repo}#${String(input.supersededBy)}.`}`,
1138
+ ...unblocks?.numbers.length ? [`**Unblocks:** ${unblocks.numbers.map((n) => `#${String(n)}`).join(", ")}`] : []
1139
+ ].join("\n\n");
1128
1140
  const target = (await clients.rest.issues.get({ ...repo, issue_number: input.issueNumber })).data;
1129
1141
  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
1142
  throw new DeliveryError("History target is not the requested issue.");
@@ -1151,9 +1163,77 @@ Superseded by ${repo.owner}/${repo.repo}#${String(input.supersededBy)}.`}`;
1151
1163
  dateChanges,
1152
1164
  priorContent,
1153
1165
  historyBody,
1154
- closureBody
1166
+ closureBody,
1167
+ unblocks: unblocks?.numbers
1155
1168
  };
1156
1169
  }
1170
+ const STUDY_TITLE = /^study\b/iu;
1171
+ async function prepareStudyClose(context, input, closeReason, title) {
1172
+ const study = STUDY_TITLE.test(title);
1173
+ if (study && input.state === "closed" && closeReason === void 0)
1174
+ throw new DeliveryError("Pass closeReason to close a study: 'completed' with closeout, or 'not_planned'.");
1175
+ if (!study || closeReason !== "completed") {
1176
+ if (input.closeout !== void 0)
1177
+ throw new DeliveryError('closeout applies only when closing a study (title starts with "Study") as completed.');
1178
+ return void 0;
1179
+ }
1180
+ const verdict = input.closeout?.verdict.trim() ?? "";
1181
+ const result = input.closeout?.result ?? "";
1182
+ if (!verdict || verdict.split("\n").length > 3 || verdict.length > 600)
1183
+ throw new DeliveryError("Pass closeout.verdict (1\u20133 lines) to close a study.");
1184
+ if (!result.trim() || result.length > 4e3)
1185
+ throw new DeliveryError(
1186
+ "Pass closeout.result (the READOUT's Result section); GitHub search doesn't read artifacts."
1187
+ );
1188
+ const artifacts = await readIssueArtifacts(context, input.issueNumber);
1189
+ if (!artifacts.some((artifact) => /^readout\b/iu.test(artifact.name)))
1190
+ throw new DeliveryError(
1191
+ `Attach the READOUT with gh issue artifact create ${String(input.issueNumber)} READOUT.md, then close again.`
1192
+ );
1193
+ return [
1194
+ `**Verdict:** ${verdict}`,
1195
+ `**Result:**
1196
+
1197
+ ${result}`,
1198
+ `**Artifacts:**
1199
+ ${artifacts.map((artifact) => `- [${artifact.name}](${artifact.url})`).join("\n")}`
1200
+ ];
1201
+ }
1202
+ const IssueArtifactRows = z.array(
1203
+ z.object({ number: z.number().int().positive(), name: z.string(), type: z.string(), html_url: z.url() })
1204
+ );
1205
+ async function readIssueArtifacts(context, issueNumber) {
1206
+ let status;
1207
+ let data;
1208
+ try {
1209
+ const response = await context.clients.rest.request(
1210
+ "GET /repos/{owner}/{repo}/issues/{issue_number}/artifacts",
1211
+ { ...context.repo, issue_number: issueNumber, per_page: 100 }
1212
+ );
1213
+ ({ status, data } = response);
1214
+ } catch (error) {
1215
+ status = error.status ?? "unavailable";
1216
+ }
1217
+ const rows = status === 200 ? IssueArtifactRows.safeParse(data) : void 0;
1218
+ if (!rows?.success)
1219
+ throw new DeliveryError(
1220
+ `Can't read this issue's artifacts (HTTP ${String(status)}); attach the READOUT with gh issue artifact create and retry.`
1221
+ );
1222
+ return rows.data.map((row) => ({ number: row.number, name: row.name, type: row.type, url: row.html_url }));
1223
+ }
1224
+ async function readUnblocks(context, issueNumber) {
1225
+ try {
1226
+ const dependents = await getNativeBlockingRelationships({
1227
+ graphql: context.clients.graphql,
1228
+ issueNumber,
1229
+ repo: context.repo
1230
+ });
1231
+ return { numbers: dependents.filter((issue) => issue.state === "OPEN").map((issue) => issue.number) };
1232
+ } catch (error) {
1233
+ 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.`;
1234
+ return { numbers: [], warning: { code: "close.unblocks", field: "blocking", message, fixHint: message } };
1235
+ }
1236
+ }
1157
1237
  async function updateIssue(context, input) {
1158
1238
  const { expectedTradesPerDay, measuredTradesPerDay, ...fields } = input;
1159
1239
  const patch = projectTradePatch({ expectedTradesPerDay, measuredTradesPerDay });
@@ -1443,7 +1523,8 @@ async function applyIssueUpdate(context, plan, changes) {
1443
1523
  ...prepared.conversion === void 0 ? {} : { conversion: prepared.conversion },
1444
1524
  ...projectStatusComment === void 0 ? {} : { projectStatusComment },
1445
1525
  ...historyComment === void 0 ? {} : { historyComment },
1446
- ...closure === void 0 || closureComment === void 0 ? {} : { closure: { ...closure, supersededBy: input.supersededBy ?? null, comment: closureComment } }
1526
+ ...closure === void 0 || closureComment === void 0 ? {} : { closure: { ...closure, supersededBy: input.supersededBy ?? null, comment: closureComment } },
1527
+ ...plan.unblocks === void 0 ? {} : { unblocks: plan.unblocks }
1447
1528
  };
1448
1529
  }
1449
1530
  async function findUpdateComment(context, issueNumber, body) {
@@ -1647,7 +1728,7 @@ function localBatchFailureReason(error) {
1647
1728
  if ([
1648
1729
  "Choose a valid defer condition or explicit undefer, never both.",
1649
1730
  "Use defer or undefer to change deferral state.",
1650
- "Choose native blockedBy or display-only status.blockers in one update, not both.",
1731
+ BLOCKERS_DISAGREE,
1651
1732
  "Convert the legacy contract explicitly before a status-only update.",
1652
1733
  "Issue labels must be non-empty and unique.",
1653
1734
  "Repository label listing exceeds the bounded readback window.",
@@ -1878,7 +1959,14 @@ async function readIssueInfo(context, issueNumber, includeProject = true, expect
1878
1959
  return { info, issueNodeId: issue.node_id, issueNumber: issue.number };
1879
1960
  }
1880
1961
  async function issueInfo(context, issueNumber, options = {}) {
1881
- return (await readIssueInfo(context, issueNumber, true, void 0, options.childDetail)).info;
1962
+ const info = (await readIssueInfo(context, issueNumber, true, void 0, options.childDetail)).info;
1963
+ if (options.artifacts !== true) return info;
1964
+ try {
1965
+ return { ...info, artifacts: await readIssueArtifacts(context, issueNumber) };
1966
+ } catch (error) {
1967
+ const message = error instanceof Error ? error.message : String(error);
1968
+ return { ...info, warnings: [{ code: "artifacts.unread", field: "artifacts", message, fixHint: message }] };
1969
+ }
1882
1970
  }
1883
1971
  function childCounts(children) {
1884
1972
  const closedChildCount = children.filter((child) => child.state === "closed").length;