@aviaratech/ai-delivery 0.3.46 → 0.3.48

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 (36) 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/issue.js +7 -5
  7. package/dist/issue.js.map +2 -2
  8. package/dist/issueBatchUpdate.test.js +9 -1
  9. package/dist/issueBatchUpdate.test.js.map +2 -2
  10. package/dist/issueBlockerGuard.test.js +27 -0
  11. package/dist/issueBlockerGuard.test.js.map +2 -2
  12. package/dist/issueContract.d.ts +2 -0
  13. package/dist/issueContract.js +23 -2
  14. package/dist/issueContract.js.map +2 -2
  15. package/dist/issueContract.test.js +54 -0
  16. package/dist/issueContract.test.js.map +2 -2
  17. package/dist/issueTracking.test.js +2 -1
  18. package/dist/issueTracking.test.js.map +2 -2
  19. package/dist/mcp/index.js +20 -19
  20. package/dist/mcp/index.js.map +2 -2
  21. package/dist/services/agentReadinessService.js +6 -2
  22. package/dist/services/agentReadinessService.js.map +2 -2
  23. package/dist/services/blockerGuardService.js +8 -5
  24. package/dist/services/blockerGuardService.js.map +2 -2
  25. package/dist/staleServer.test.d.ts +1 -0
  26. package/dist/staleServer.test.js +110 -0
  27. package/dist/staleServer.test.js.map +7 -0
  28. package/dist/version.d.ts +2 -0
  29. package/dist/version.js +15 -1
  30. package/dist/version.js.map +2 -2
  31. package/package.json +1 -1
  32. package/plugins/ai-delivery/.claude-plugin/plugin.json +2 -2
  33. package/plugins/ai-delivery/plugin.json +1 -1
  34. package/plugins/ai-delivery/runtime/dist/cli.js +100 -100
  35. package/plugins/ai-delivery/runtime/package.json +1 -1
  36. package/plugins/ai-delivery/skills/intake-create/SKILL.md +1 -1
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../src/services/agentReadinessService.ts"],
4
- "sourcesContent": ["import type { NativePointValue } from '../github/nativeIssueMetadata.js';\nimport {\n parseIssueBody,\n validateIssue,\n issueWarnings,\n IssueValidationError,\n type IssueDiagnostic,\n} from '../issueContract.js';\n\nexport interface AgentReadinessResult {\n failures: IssueDiagnostic[];\n warnings: IssueDiagnostic[];\n ready: boolean;\n}\n/** Content validation is repository-independent; GitHub owns live eligibility. */\nexport function evaluateAgentReadiness(input: {\n blockedBy?: readonly number[];\n body: string;\n points?: NativePointValue | undefined;\n priority?: string | undefined;\n repoRoot?: string | undefined;\n title: string;\n issueType?: string | undefined;\n trackingParent?: boolean;\n}): AgentReadinessResult {\n const failures: IssueDiagnostic[] = [];\n const add = (code: string, field: string, message: string): void => {\n failures.push({ code, field, message, fixHint: message });\n };\n let warnings: IssueDiagnostic[] = [];\n let epic = false;\n try {\n const parsed = parseIssueBody(input.body, {\n title: input.title,\n ...(input.issueType === undefined ? {} : { issueType: input.issueType }),\n ...(input.points === undefined ? {} : { points: input.points }),\n });\n const result = validateIssue(parsed.issue);\n if (parsed.issue.deferral !== undefined)\n add('deferred', 'defer', 'Issue is deferred; explicitly undefer it before starting work.');\n epic = parsed.issue.epic === true;\n failures.push(...result.failures);\n warnings = issueWarnings(parsed.issue);\n if (!parsed.legacy && input.points !== undefined && parsed.issue.points !== input.points)\n add('points.sync', 'points', 'Reconcile canonical Points with the live native Points field.');\n if (!parsed.legacy && input.issueType !== undefined && parsed.issue.issueType !== input.issueType)\n add('type.sync', 'issueType', 'Reconcile the canonical Issue Type with the live native Issue Type.');\n } catch (error) {\n if (!(error instanceof IssueValidationError)) throw error;\n failures.push(...error.failures);\n }\n if (input.points === undefined)\n add('points', 'points', 'Set configured native Points before autonomous development.');\n if (input.priority === undefined && !epic)\n add('priority', 'priority', 'Set native Priority with issue_update before autonomous development.');\n if (input.issueType === undefined)\n add('issue-type', 'issueType', 'Set native Issue Type with issue_update before autonomous development.');\n if ((input.blockedBy?.length ?? 0) > 0)\n add('blocked', 'blockedBy', 'Resolve open native blockers before autonomous development.');\n if (input.trackingParent)\n add('tracking-parent', 'parent', 'Dispatch an executable sub-issue instead of the tracking parent.');\n return { failures, warnings, ready: failures.length === 0 };\n}\n"],
5
- "mappings": "AACA;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OAEK;AAQA,SAAS,uBAAuB,OASd;AACvB,QAAM,WAA8B,CAAC;AACrC,QAAM,MAAM,CAAC,MAAc,OAAe,YAA0B;AAClE,aAAS,KAAK,EAAE,MAAM,OAAO,SAAS,SAAS,QAAQ,CAAC;AAAA,EAC1D;AACA,MAAI,WAA8B,CAAC;AACnC,MAAI,OAAO;AACX,MAAI;AACF,UAAM,SAAS,eAAe,MAAM,MAAM;AAAA,MACxC,OAAO,MAAM;AAAA,MACb,GAAI,MAAM,cAAc,SAAY,CAAC,IAAI,EAAE,WAAW,MAAM,UAAU;AAAA,MACtE,GAAI,MAAM,WAAW,SAAY,CAAC,IAAI,EAAE,QAAQ,MAAM,OAAO;AAAA,IAC/D,CAAC;AACD,UAAM,SAAS,cAAc,OAAO,KAAK;AACzC,QAAI,OAAO,MAAM,aAAa;AAC5B,UAAI,YAAY,SAAS,gEAAgE;AAC3F,WAAO,OAAO,MAAM,SAAS;AAC7B,aAAS,KAAK,GAAG,OAAO,QAAQ;AAChC,eAAW,cAAc,OAAO,KAAK;AACrC,QAAI,CAAC,OAAO,UAAU,MAAM,WAAW,UAAa,OAAO,MAAM,WAAW,MAAM;AAChF,UAAI,eAAe,UAAU,+DAA+D;AAC9F,QAAI,CAAC,OAAO,UAAU,MAAM,cAAc,UAAa,OAAO,MAAM,cAAc,MAAM;AACtF,UAAI,aAAa,aAAa,qEAAqE;AAAA,EACvG,SAAS,OAAO;AACd,QAAI,EAAE,iBAAiB,sBAAuB,OAAM;AACpD,aAAS,KAAK,GAAG,MAAM,QAAQ;AAAA,EACjC;AACA,MAAI,MAAM,WAAW;AACnB,QAAI,UAAU,UAAU,6DAA6D;AACvF,MAAI,MAAM,aAAa,UAAa,CAAC;AACnC,QAAI,YAAY,YAAY,sEAAsE;AACpG,MAAI,MAAM,cAAc;AACtB,QAAI,cAAc,aAAa,wEAAwE;AACzG,OAAK,MAAM,WAAW,UAAU,KAAK;AACnC,QAAI,WAAW,aAAa,6DAA6D;AAC3F,MAAI,MAAM;AACR,QAAI,mBAAmB,UAAU,kEAAkE;AACrG,SAAO,EAAE,UAAU,UAAU,OAAO,SAAS,WAAW,EAAE;AAC5D;",
4
+ "sourcesContent": ["import type { NativePointValue } from '../github/nativeIssueMetadata.js';\nimport {\n parseIssueBody,\n validateIssue,\n issueWarnings,\n IssueValidationError,\n type IssueDiagnostic,\n} from '../issueContract.js';\n\nexport interface AgentReadinessResult {\n failures: IssueDiagnostic[];\n warnings: IssueDiagnostic[];\n ready: boolean;\n}\n/** Content validation is repository-independent; GitHub owns live eligibility. */\nexport function evaluateAgentReadiness(input: {\n blockedBy?: readonly number[];\n body: string;\n points?: NativePointValue | undefined;\n priority?: string | undefined;\n repoRoot?: string | undefined;\n title: string;\n issueType?: string | undefined;\n trackingParent?: boolean;\n}): AgentReadinessResult {\n const failures: IssueDiagnostic[] = [];\n const add = (code: string, field: string, message: string): void => {\n failures.push({ code, field, message, fixHint: message });\n };\n let warnings: IssueDiagnostic[] = [];\n let epic = false;\n try {\n const parsed = parseIssueBody(input.body, {\n title: input.title,\n ...(input.issueType === undefined ? {} : { issueType: input.issueType }),\n ...(input.points === undefined ? {} : { points: input.points }),\n });\n const result = validateIssue(parsed.issue);\n if (parsed.issue.deferral !== undefined)\n add('deferred', 'defer', 'Issue is deferred; explicitly undefer it before starting work.');\n epic = parsed.issue.epic === true;\n failures.push(...result.failures);\n warnings = issueWarnings(parsed.issue);\n if (!parsed.legacy && input.points !== undefined && parsed.issue.points !== input.points)\n add('points.sync', 'points', 'Reconcile canonical Points with the live native Points field.');\n if (!parsed.legacy && input.issueType !== undefined && parsed.issue.issueType !== input.issueType)\n add('type.sync', 'issueType', 'Reconcile the canonical Issue Type with the live native Issue Type.');\n } catch (error) {\n if (!(error instanceof IssueValidationError)) throw error;\n failures.push(...error.failures);\n }\n if (input.points === undefined)\n add('points', 'points', 'Set configured native Points before autonomous development.');\n if (input.priority === undefined && !epic)\n add('priority', 'priority', 'Set native Priority with issue_update before autonomous development.');\n if (input.issueType === undefined)\n add('issue-type', 'issueType', 'Set native Issue Type with issue_update before autonomous development.');\n if (input.blockedBy && input.blockedBy.length > 0)\n add(\n 'blocked',\n 'blockedBy',\n `Resolve open native blockers ${input.blockedBy.map((n) => '#' + String(n)).join(', ')} before autonomous development.`,\n );\n if (input.trackingParent)\n add('tracking-parent', 'parent', 'Dispatch an executable sub-issue instead of the tracking parent.');\n return { failures, warnings, ready: failures.length === 0 };\n}\n"],
5
+ "mappings": "AACA;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OAEK;AAQA,SAAS,uBAAuB,OASd;AACvB,QAAM,WAA8B,CAAC;AACrC,QAAM,MAAM,CAAC,MAAc,OAAe,YAA0B;AAClE,aAAS,KAAK,EAAE,MAAM,OAAO,SAAS,SAAS,QAAQ,CAAC;AAAA,EAC1D;AACA,MAAI,WAA8B,CAAC;AACnC,MAAI,OAAO;AACX,MAAI;AACF,UAAM,SAAS,eAAe,MAAM,MAAM;AAAA,MACxC,OAAO,MAAM;AAAA,MACb,GAAI,MAAM,cAAc,SAAY,CAAC,IAAI,EAAE,WAAW,MAAM,UAAU;AAAA,MACtE,GAAI,MAAM,WAAW,SAAY,CAAC,IAAI,EAAE,QAAQ,MAAM,OAAO;AAAA,IAC/D,CAAC;AACD,UAAM,SAAS,cAAc,OAAO,KAAK;AACzC,QAAI,OAAO,MAAM,aAAa;AAC5B,UAAI,YAAY,SAAS,gEAAgE;AAC3F,WAAO,OAAO,MAAM,SAAS;AAC7B,aAAS,KAAK,GAAG,OAAO,QAAQ;AAChC,eAAW,cAAc,OAAO,KAAK;AACrC,QAAI,CAAC,OAAO,UAAU,MAAM,WAAW,UAAa,OAAO,MAAM,WAAW,MAAM;AAChF,UAAI,eAAe,UAAU,+DAA+D;AAC9F,QAAI,CAAC,OAAO,UAAU,MAAM,cAAc,UAAa,OAAO,MAAM,cAAc,MAAM;AACtF,UAAI,aAAa,aAAa,qEAAqE;AAAA,EACvG,SAAS,OAAO;AACd,QAAI,EAAE,iBAAiB,sBAAuB,OAAM;AACpD,aAAS,KAAK,GAAG,MAAM,QAAQ;AAAA,EACjC;AACA,MAAI,MAAM,WAAW;AACnB,QAAI,UAAU,UAAU,6DAA6D;AACvF,MAAI,MAAM,aAAa,UAAa,CAAC;AACnC,QAAI,YAAY,YAAY,sEAAsE;AACpG,MAAI,MAAM,cAAc;AACtB,QAAI,cAAc,aAAa,wEAAwE;AACzG,MAAI,MAAM,aAAa,MAAM,UAAU,SAAS;AAC9C;AAAA,MACE;AAAA,MACA;AAAA,MACA,gCAAgC,MAAM,UAAU,IAAI,CAAC,MAAM,MAAM,OAAO,CAAC,CAAC,EAAE,KAAK,IAAI,CAAC;AAAA,IACxF;AACF,MAAI,MAAM;AACR,QAAI,mBAAmB,UAAU,kEAAkE;AACrG,SAAO,EAAE,UAAU,UAAU,OAAO,SAAS,WAAW,EAAE;AAC5D;",
6
6
  "names": []
7
7
  }
@@ -8,6 +8,7 @@ import {
8
8
  } from "../github/projectDelivery.js";
9
9
  import { getNativeBlockerRelationships } from "../github/relationships.js";
10
10
  import { readIssueHistory } from "../github/issueHistory.js";
11
+ import { isDesignTitle } from "../issueContract.js";
11
12
  const OverrideReason = z.string().trim().min(1).max(2e3);
12
13
  async function endpoint(context, number) {
13
14
  if (!Number.isSafeInteger(number) || number <= 0)
@@ -16,7 +17,7 @@ async function endpoint(context, number) {
16
17
  const url = new URL(issue.html_url);
17
18
  if (issue.number !== number || "pull_request" in issue || !issue.node_id || url.protocol !== "https:" || url.hostname !== "github.com" || url.pathname.toLowerCase() !== `/${context.repo.owner}/${context.repo.repo}/issues/${number}`.toLowerCase())
18
19
  throw new DeliveryError("Dependency endpoint is not the requested repository issue.");
19
- return issue.node_id;
20
+ return { nodeId: issue.node_id, design: isDesignTitle(issue.title) };
20
21
  }
21
22
  async function prepareBlockerGuard(context, intents, overrideReason, forwardBlockers = []) {
22
23
  if (context.clients.role !== "author" || !context.clients.authenticatedAuthor)
@@ -127,7 +128,7 @@ ${JSON.stringify(evidence, null, 2)}
127
128
  return { id: matches[0]?.id, body };
128
129
  };
129
130
  for (const intent of intents) {
130
- const id = await endpoint(context, intent.dependent);
131
+ const { nodeId: id } = await endpoint(context, intent.dependent);
131
132
  const existing = await getNativeBlockerRelationships({
132
133
  graphql: context.clients.graphql,
133
134
  repo: context.repo,
@@ -136,8 +137,8 @@ ${JSON.stringify(evidence, null, 2)}
136
137
  const candidates = [];
137
138
  for (const blocker of new Set(intent.blockers)) {
138
139
  if (blocker === intent.dependent) throw new DeliveryError("An issue cannot block itself.");
139
- const blockerNodeId = await endpoint(context, blocker);
140
- if (!existing.blockers.some((value) => value.number === blocker))
140
+ const { nodeId: blockerNodeId, design } = await endpoint(context, blocker);
141
+ if (!design && !existing.blockers.some((value) => value.number === blocker))
141
142
  candidates.push({ issueNumber: intent.dependent, issueNodeId: id, blocker, blockerNodeId });
142
143
  }
143
144
  if (!intent.pendingBlocker && !candidates.length) continue;
@@ -157,9 +158,11 @@ ${JSON.stringify(evidence, null, 2)}
157
158
  }
158
159
  }
159
160
  return async (edge) => {
160
- const dependentId = await endpoint(context, edge.issueNumber), blockerId = await endpoint(context, edge.blocker);
161
+ const { nodeId: dependentId } = await endpoint(context, edge.issueNumber);
162
+ const { nodeId: blockerId, design } = await endpoint(context, edge.blocker);
161
163
  if (dependentId !== edge.issueNodeId || blockerId !== edge.blockerNodeId || dependentId === blockerId)
162
164
  throw new DeliveryError("Dependency endpoint identity changed.");
165
+ if (design) return;
163
166
  if (await currentStatus(edge.issueNumber, dependentId) === "In Progress" && !required.has(edge.issueNumber))
164
167
  required.set(edge.issueNumber, (/* @__PURE__ */ new Date()).toISOString());
165
168
  if (!required.has(edge.issueNumber)) return;
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../src/services/blockerGuardService.ts"],
4
- "sourcesContent": ["import { z } from 'zod';\nimport type { DeliveryContext } from '../issue.js';\nimport { DeliveryError } from '../errors.js';\nimport { digestValue } from '../delivery/common.js';\nimport {\n getIssueProjectStatus,\n getProjectDeliveryConfiguration,\n projectSettingsFromDeliveryConfig,\n} from '../github/projectDelivery.js';\nimport { getNativeBlockerRelationships } from '../github/relationships.js';\nimport { readIssueHistory } from '../github/issueHistory.js';\n\nexport const OverrideReason = z.string().trim().min(1).max(2000);\nexport interface BlockerIntent {\n dependent: number;\n blockers: number[];\n pendingBlocker?: boolean;\n}\ntype Edge = { issueNumber: number; issueNodeId: string; blocker: number; blockerNodeId: string };\n\nasync function endpoint(context: DeliveryContext, number: number): Promise<string> {\n if (!Number.isSafeInteger(number) || number <= 0)\n throw new DeliveryError('Dependency endpoint must be a positive issue number.');\n const issue = (await context.clients.rest.issues.get({ ...context.repo, issue_number: number })).data;\n const url = new URL(issue.html_url);\n if (\n issue.number !== number ||\n 'pull_request' in issue ||\n !issue.node_id ||\n url.protocol !== 'https:' ||\n url.hostname !== 'github.com' ||\n url.pathname.toLowerCase() !== `/${context.repo.owner}/${context.repo.repo}/issues/${number}`.toLowerCase()\n )\n throw new DeliveryError('Dependency endpoint is not the requested repository issue.');\n return issue.node_id;\n}\n\n/** Read-only preflight plus a reconciled callback for every actual native addition. */\nexport async function prepareBlockerGuard(\n context: DeliveryContext,\n intents: BlockerIntent[],\n overrideReason?: string,\n forwardBlockers: number[] = [],\n) {\n if (context.clients.role !== 'author' || !context.clients.authenticatedAuthor)\n throw new DeliveryError('Dependency writes require configured author authority.');\n const authority = await context.clients.authenticatedAuthor();\n if (!authority.actorLogin.trim()) throw new DeliveryError('Dependency author identity is unavailable.');\n const reason = overrideReason === undefined ? undefined : OverrideReason.parse(overrideReason);\n for (const blocker of forwardBlockers) await endpoint(context, blocker);\n const configuration =\n context.projectConfiguration ??\n (await getProjectDeliveryConfiguration({\n graphql: context.clients.graphql,\n org: context.config.native.organization,\n settings: projectSettingsFromDeliveryConfig(context.config),\n }));\n const required = new Map<number, string>();\n const currentStatus = async (number: number, id: string) => {\n const status = await getIssueProjectStatus({\n graphql: context.clients.graphql,\n issueNodeId: id,\n org: context.config.native.organization,\n configuration,\n maxPages: 20,\n });\n if (status === null)\n throw new DeliveryError(\n `Project status for dependent #${number} is unresolved; dependency additions were refused.`,\n );\n return status.status;\n };\n const requireReason = (number: number) => {\n if (reason === undefined)\n throw new DeliveryError(`Adding a blocker to active issue #${number} requires overrideReason.`);\n };\n const episodeFor = async (edge: Edge) => {\n const history = await readIssueHistory(context, edge.issueNumber, 20, edge.issueNodeId);\n if (!history.complete)\n throw new DeliveryError(\n `Complete dependency history is required for an active blocker override: ${history.reason ?? 'Incomplete timeline'}.`,\n );\n const removals = history.events\n .filter(\n (value) =>\n value.__typename === 'BlockedByRemovedEvent' &&\n value.blockingIssue?.id === edge.blockerNodeId &&\n value.blockingIssue.repository.nameWithOwner.toLowerCase() === context.config.repository.toLowerCase(),\n )\n .sort((a, b) => Date.parse(b.createdAt) - Date.parse(a.createdAt));\n if (removals[0] && removals[1] && Date.parse(removals[1].createdAt) === Date.parse(removals[0].createdAt))\n throw new DeliveryError('Dependency removal episode is ambiguous.');\n return removals[0]?.id ?? 'complete-history:no-removal';\n };\n const verifyComment = async (id: number, body: string, number: number) => {\n const value = (await context.clients.rest.issues.getComment({ ...context.repo, comment_id: id })).data;\n if (\n value.id !== id ||\n value.body !== body ||\n value.user?.login.toLowerCase() !== authority.actorLogin.toLowerCase() ||\n value.issue_url !== `https://api.github.com/repos/${context.repo.owner}/${context.repo.repo}/issues/${number}`\n )\n throw new DeliveryError(\n 'Override comment author, body or issue readback disagrees; native dependency was not added.',\n );\n };\n const commentFor = async (edge: Edge, episode: string, observedAt: string) => {\n const identity = {\n schema: 'ai-delivery.blocker-override@1',\n repository: context.config.repository,\n projectId: configuration.projectId,\n dependent: { number: edge.issueNumber, id: edge.issueNodeId },\n blocker: { number: edge.blocker, id: edge.blockerNodeId },\n episode,\n reason,\n observedStatus: 'In Progress',\n };\n const marker = `<!-- ai-delivery:blocker-override@1:${digestValue({ repository: context.config.repository.toLowerCase(), projectId: configuration.projectId, dependentId: edge.issueNodeId, blockerId: edge.blockerNodeId, episode })} -->`;\n const matches: { id: number; body?: string | null }[] = [];\n let complete = false;\n for (let page = 1; page <= 20; page++) {\n const comments = (\n await context.clients.rest.issues.listComments({\n ...context.repo,\n issue_number: edge.issueNumber,\n per_page: 100,\n page,\n })\n ).data;\n matches.push(\n ...comments.filter(\n (value) =>\n value.body?.includes(marker) && value.user?.login.toLowerCase() === authority.actorLogin.toLowerCase(),\n ),\n );\n if (comments.length < 100) {\n complete = true;\n break;\n }\n }\n if (!complete || matches.length > 1)\n throw new DeliveryError('Override comment search is incomplete or has duplicate authoritative markers.');\n const render = (evidence: typeof identity & { observedAt: string }) =>\n `Blocker override requested for ${context.config.repository}#${edge.issueNumber} blocked by #${edge.blocker}.\\n\\n${marker}\\n\\n\\`\\`\\`json\\n${JSON.stringify(evidence, null, 2)}\\n\\`\\`\\``;\n let body = render({ ...identity, observedAt });\n if (matches[0]) {\n body = matches[0].body ?? '';\n const raw = body.match(/```json\\n([\\s\\S]+)\\n```$/u)?.[1];\n let saved: Record<string, unknown>;\n try {\n saved = JSON.parse(raw ?? '') as Record<string, unknown>;\n } catch {\n throw new DeliveryError('Override comment evidence is malformed.');\n }\n const { observedAt: prior, ...fields } = saved;\n if (\n typeof prior !== 'string' ||\n !z.iso.datetime().safeParse(prior).success ||\n JSON.stringify(fields) !== JSON.stringify(identity) ||\n body !== render(saved as typeof identity & { observedAt: string })\n )\n throw new DeliveryError('Existing override comment conflicts with the requested reason or endpoint evidence.');\n await verifyComment(matches[0].id, body, edge.issueNumber);\n }\n return { id: matches[0]?.id, body };\n };\n for (const intent of intents) {\n const id = await endpoint(context, intent.dependent);\n const existing = await getNativeBlockerRelationships({\n graphql: context.clients.graphql,\n repo: context.repo,\n issueNumber: intent.dependent,\n });\n const candidates: Edge[] = [];\n for (const blocker of new Set(intent.blockers)) {\n if (blocker === intent.dependent) throw new DeliveryError('An issue cannot block itself.');\n const blockerNodeId = await endpoint(context, blocker);\n if (!existing.blockers.some((value) => value.number === blocker))\n candidates.push({ issueNumber: intent.dependent, issueNodeId: id, blocker, blockerNodeId });\n }\n if (!intent.pendingBlocker && !candidates.length) continue;\n if ((await currentStatus(intent.dependent, id)) === 'In Progress') {\n const observedAt = new Date().toISOString();\n required.set(intent.dependent, observedAt);\n requireReason(intent.dependent);\n // Pending creation has no blocker node yet, but its dependent history must already be complete.\n if (intent.pendingBlocker) {\n const history = await readIssueHistory(context, intent.dependent, 20, id);\n if (!history.complete)\n throw new DeliveryError('Complete dependency history is required for an active blocker override.');\n }\n for (const edge of candidates) {\n const episode = await episodeFor(edge);\n await commentFor(edge, episode, observedAt);\n }\n }\n }\n return async (edge: Edge): Promise<void | boolean> => {\n const dependentId = await endpoint(context, edge.issueNumber),\n blockerId = await endpoint(context, edge.blocker);\n if (dependentId !== edge.issueNodeId || blockerId !== edge.blockerNodeId || dependentId === blockerId)\n throw new DeliveryError('Dependency endpoint identity changed.');\n if ((await currentStatus(edge.issueNumber, dependentId)) === 'In Progress' && !required.has(edge.issueNumber))\n required.set(edge.issueNumber, new Date().toISOString());\n if (!required.has(edge.issueNumber)) return;\n requireReason(edge.issueNumber);\n const actor = await context.clients.authenticatedAuthor!();\n if (\n actor.actorLogin.toLowerCase() !== authority.actorLogin.toLowerCase() ||\n actor.credentialIdentity !== authority.credentialIdentity\n )\n throw new DeliveryError('Dependency override author authority changed.');\n const episode = await episodeFor(edge);\n const comment = await commentFor(edge, episode, required.get(edge.issueNumber)!);\n const id =\n comment.id ??\n (\n await context.clients.rest.issues.createComment({\n ...context.repo,\n issue_number: edge.issueNumber,\n body: comment.body,\n })\n ).data.id;\n await verifyComment(id, comment.body, edge.issueNumber);\n // Enumeration and comment writes are not atomic with dependencies. Reconcile the exact episode again.\n if ((await episodeFor(edge)) !== episode)\n throw new DeliveryError(\n 'Dependency removal episode changed after override verification; inspect native state and resume this issue.',\n );\n const final = await getNativeBlockerRelationships({\n graphql: context.clients.graphql,\n repo: context.repo,\n issueNumber: edge.issueNumber,\n });\n if (final.blockers.some((value) => value.id === edge.blockerNodeId)) return false;\n };\n}\n"],
5
- "mappings": "AAAA,SAAS,SAAS;AAElB,SAAS,qBAAqB;AAC9B,SAAS,mBAAmB;AAC5B;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,OACK;AACP,SAAS,qCAAqC;AAC9C,SAAS,wBAAwB;AAE1B,MAAM,iBAAiB,EAAE,OAAO,EAAE,KAAK,EAAE,IAAI,CAAC,EAAE,IAAI,GAAI;AAQ/D,eAAe,SAAS,SAA0B,QAAiC;AACjF,MAAI,CAAC,OAAO,cAAc,MAAM,KAAK,UAAU;AAC7C,UAAM,IAAI,cAAc,sDAAsD;AAChF,QAAM,SAAS,MAAM,QAAQ,QAAQ,KAAK,OAAO,IAAI,EAAE,GAAG,QAAQ,MAAM,cAAc,OAAO,CAAC,GAAG;AACjG,QAAM,MAAM,IAAI,IAAI,MAAM,QAAQ;AAClC,MACE,MAAM,WAAW,UACjB,kBAAkB,SAClB,CAAC,MAAM,WACP,IAAI,aAAa,YACjB,IAAI,aAAa,gBACjB,IAAI,SAAS,YAAY,MAAM,IAAI,QAAQ,KAAK,KAAK,IAAI,QAAQ,KAAK,IAAI,WAAW,MAAM,GAAG,YAAY;AAE1G,UAAM,IAAI,cAAc,4DAA4D;AACtF,SAAO,MAAM;AACf;AAGA,eAAsB,oBACpB,SACA,SACA,gBACA,kBAA4B,CAAC,GAC7B;AACA,MAAI,QAAQ,QAAQ,SAAS,YAAY,CAAC,QAAQ,QAAQ;AACxD,UAAM,IAAI,cAAc,wDAAwD;AAClF,QAAM,YAAY,MAAM,QAA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iBAAiB,gBAAgB;AAC1F,YAAM,IAAI,cAAc,uCAAuC;AACjE,QAAK,MAAM,cAAc,KAAK,aAAa,WAAW,MAAO,iBAAiB,CAAC,SAAS,IAAI,KAAK,WAAW;AAC1G,eAAS,IAAI,KAAK,cAAa,oBAAI,KAAK,GAAE,YAAY,CAAC;AACzD,QAAI,CAAC,SAAS,IAAI,KAAK,WAAW,EAAG;AACrC,kBAAc,KAAK,WAAW;AAC9B,UAAM,QAAQ,MAAM,QAAQ,QAAQ,oBAAqB;AACzD,QACE,MAAM,WAAW,YAAY,MAAM,UAAU,WAAW,YAAY,KACpE,MAAM,uBAAuB,UAAU;AAEvC,YAAM,IAAI,cAAc,+CAA+C;AACzE,UAAM,UAAU,MAAM,WAAW,IAAI;AACrC,UAAM,UAAU,MAAM,WAAW,MAAM,SAAS,SAAS,IAAI,KAAK,WAAW,CAAE;AAC/E,UAAM,KACJ,QAAQ,OAEN,MAAM,QAAQ,QAAQ,KAAK,OAAO,cAAc;AAAA,MAC9C,GAAG,QAAQ;AAAA,MACX,cAAc,KAAK;AAAA,MACnB,MAAM,QAAQ;AAAA,IAChB,CAAC,GACD,KAAK;AACT,UAAM,cAAc,IAAI,QAAQ,MAAM,KAAK,WAAW;AAEtD,QAAK,MAAM,WAAW,IAAI,MAAO;AAC/B,YAAM,IAAI;AAAA,QACR;AAAA,MACF;AACF,UAAM,QAAQ,MAAM,8BAA8B;AAAA,MAChD,SAAS,QAAQ,QAAQ;AAAA,MACzB,MAAM,QAAQ;AAAA,MACd,aAAa,KAAK;AAAA,IACpB,CAAC;AACD,QAAI,MAAM,SAAS,KAAK,CAAC,UAAU,MAAM,OAAO,KAAK,aAAa,EAAG,QAAO;AAAA,EAC9E;AACF;",
4
+ "sourcesContent": ["import { z } from 'zod';\nimport type { DeliveryContext } from '../issue.js';\nimport { DeliveryError } from '../errors.js';\nimport { digestValue } from '../delivery/common.js';\nimport {\n getIssueProjectStatus,\n getProjectDeliveryConfiguration,\n projectSettingsFromDeliveryConfig,\n} from '../github/projectDelivery.js';\nimport { getNativeBlockerRelationships } from '../github/relationships.js';\nimport { readIssueHistory } from '../github/issueHistory.js';\nimport { isDesignTitle } from '../issueContract.js';\n\nexport const OverrideReason = z.string().trim().min(1).max(2000);\nexport interface BlockerIntent {\n dependent: number;\n blockers: number[];\n pendingBlocker?: boolean;\n}\ntype Edge = { issueNumber: number; issueNodeId: string; blocker: number; blockerNodeId: string };\n\nasync function endpoint(context: DeliveryContext, number: number): Promise<{ nodeId: string; design: boolean }> {\n if (!Number.isSafeInteger(number) || number <= 0)\n throw new DeliveryError('Dependency endpoint must be a positive issue number.');\n const issue = (await context.clients.rest.issues.get({ ...context.repo, issue_number: number })).data;\n const url = new URL(issue.html_url);\n if (\n issue.number !== number ||\n 'pull_request' in issue ||\n !issue.node_id ||\n url.protocol !== 'https:' ||\n url.hostname !== 'github.com' ||\n url.pathname.toLowerCase() !== `/${context.repo.owner}/${context.repo.repo}/issues/${number}`.toLowerCase()\n )\n throw new DeliveryError('Dependency endpoint is not the requested repository issue.');\n return { nodeId: issue.node_id, design: isDesignTitle(issue.title) };\n}\n\n/** Read-only preflight plus a reconciled callback for every actual native addition. */\nexport async function prepareBlockerGuard(\n context: DeliveryContext,\n intents: BlockerIntent[],\n overrideReason?: string,\n forwardBlockers: number[] = [],\n) {\n if (context.clients.role !== 'author' || !context.clients.authenticatedAuthor)\n throw new DeliveryError('Dependency writes require configured author authority.');\n const authority = await context.clients.authenticatedAuthor();\n if (!authority.actorLogin.trim()) throw new DeliveryError('Dependency author identity is unavailable.');\n const reason = overrideReason === undefined ? undefined : OverrideReason.parse(overrideReason);\n for (const blocker of forwardBlockers) await endpoint(context, blocker);\n const configuration =\n context.projectConfiguration ??\n (await getProjectDeliveryConfiguration({\n graphql: context.clients.graphql,\n org: context.config.native.organization,\n settings: projectSettingsFromDeliveryConfig(context.config),\n }));\n const required = new Map<number, string>();\n const currentStatus = async (number: number, id: string) => {\n const status = await getIssueProjectStatus({\n graphql: context.clients.graphql,\n issueNodeId: id,\n org: context.config.native.organization,\n configuration,\n maxPages: 20,\n });\n if (status === null)\n throw new DeliveryError(\n `Project status for dependent #${number} is unresolved; dependency additions were refused.`,\n );\n return status.status;\n };\n const requireReason = (number: number) => {\n if (reason === undefined)\n throw new DeliveryError(`Adding a blocker to active issue #${number} requires overrideReason.`);\n };\n const episodeFor = async (edge: Edge) => {\n const history = await readIssueHistory(context, edge.issueNumber, 20, edge.issueNodeId);\n if (!history.complete)\n throw new DeliveryError(\n `Complete dependency history is required for an active blocker override: ${history.reason ?? 'Incomplete timeline'}.`,\n );\n const removals = history.events\n .filter(\n (value) =>\n value.__typename === 'BlockedByRemovedEvent' &&\n value.blockingIssue?.id === edge.blockerNodeId &&\n value.blockingIssue.repository.nameWithOwner.toLowerCase() === context.config.repository.toLowerCase(),\n )\n .sort((a, b) => Date.parse(b.createdAt) - Date.parse(a.createdAt));\n if (removals[0] && removals[1] && Date.parse(removals[1].createdAt) === Date.parse(removals[0].createdAt))\n throw new DeliveryError('Dependency removal episode is ambiguous.');\n return removals[0]?.id ?? 'complete-history:no-removal';\n };\n const verifyComment = async (id: number, body: string, number: number) => {\n const value = (await context.clients.rest.issues.getComment({ ...context.repo, comment_id: id })).data;\n if (\n value.id !== id ||\n value.body !== body ||\n value.user?.login.toLowerCase() !== authority.actorLogin.toLowerCase() ||\n value.issue_url !== `https://api.github.com/repos/${context.repo.owner}/${context.repo.repo}/issues/${number}`\n )\n throw new DeliveryError(\n 'Override comment author, body or issue readback disagrees; native dependency was not added.',\n );\n };\n const commentFor = async (edge: Edge, episode: string, observedAt: string) => {\n const identity = {\n schema: 'ai-delivery.blocker-override@1',\n repository: context.config.repository,\n projectId: configuration.projectId,\n dependent: { number: edge.issueNumber, id: edge.issueNodeId },\n blocker: { number: edge.blocker, id: edge.blockerNodeId },\n episode,\n reason,\n observedStatus: 'In Progress',\n };\n const marker = `<!-- ai-delivery:blocker-override@1:${digestValue({ repository: context.config.repository.toLowerCase(), projectId: configuration.projectId, dependentId: edge.issueNodeId, blockerId: edge.blockerNodeId, episode })} -->`;\n const matches: { id: number; body?: string | null }[] = [];\n let complete = false;\n for (let page = 1; page <= 20; page++) {\n const comments = (\n await context.clients.rest.issues.listComments({\n ...context.repo,\n issue_number: edge.issueNumber,\n per_page: 100,\n page,\n })\n ).data;\n matches.push(\n ...comments.filter(\n (value) =>\n value.body?.includes(marker) && value.user?.login.toLowerCase() === authority.actorLogin.toLowerCase(),\n ),\n );\n if (comments.length < 100) {\n complete = true;\n break;\n }\n }\n if (!complete || matches.length > 1)\n throw new DeliveryError('Override comment search is incomplete or has duplicate authoritative markers.');\n const render = (evidence: typeof identity & { observedAt: string }) =>\n `Blocker override requested for ${context.config.repository}#${edge.issueNumber} blocked by #${edge.blocker}.\\n\\n${marker}\\n\\n\\`\\`\\`json\\n${JSON.stringify(evidence, null, 2)}\\n\\`\\`\\``;\n let body = render({ ...identity, observedAt });\n if (matches[0]) {\n body = matches[0].body ?? '';\n const raw = body.match(/```json\\n([\\s\\S]+)\\n```$/u)?.[1];\n let saved: Record<string, unknown>;\n try {\n saved = JSON.parse(raw ?? '') as Record<string, unknown>;\n } catch {\n throw new DeliveryError('Override comment evidence is malformed.');\n }\n const { observedAt: prior, ...fields } = saved;\n if (\n typeof prior !== 'string' ||\n !z.iso.datetime().safeParse(prior).success ||\n JSON.stringify(fields) !== JSON.stringify(identity) ||\n body !== render(saved as typeof identity & { observedAt: string })\n )\n throw new DeliveryError('Existing override comment conflicts with the requested reason or endpoint evidence.');\n await verifyComment(matches[0].id, body, edge.issueNumber);\n }\n return { id: matches[0]?.id, body };\n };\n for (const intent of intents) {\n const { nodeId: id } = await endpoint(context, intent.dependent);\n const existing = await getNativeBlockerRelationships({\n graphql: context.clients.graphql,\n repo: context.repo,\n issueNumber: intent.dependent,\n });\n const candidates: Edge[] = [];\n for (const blocker of new Set(intent.blockers)) {\n if (blocker === intent.dependent) throw new DeliveryError('An issue cannot block itself.');\n const { nodeId: blockerNodeId, design } = await endpoint(context, blocker);\n // A Design ticket writes no code, so it may block an active issue without an override (Paul, Dec 4).\n if (!design && !existing.blockers.some((value) => value.number === blocker))\n candidates.push({ issueNumber: intent.dependent, issueNodeId: id, blocker, blockerNodeId });\n }\n if (!intent.pendingBlocker && !candidates.length) continue;\n if ((await currentStatus(intent.dependent, id)) === 'In Progress') {\n const observedAt = new Date().toISOString();\n required.set(intent.dependent, observedAt);\n requireReason(intent.dependent);\n // Pending creation has no blocker node yet, but its dependent history must already be complete.\n if (intent.pendingBlocker) {\n const history = await readIssueHistory(context, intent.dependent, 20, id);\n if (!history.complete)\n throw new DeliveryError('Complete dependency history is required for an active blocker override.');\n }\n for (const edge of candidates) {\n const episode = await episodeFor(edge);\n await commentFor(edge, episode, observedAt);\n }\n }\n }\n return async (edge: Edge): Promise<void | boolean> => {\n const { nodeId: dependentId } = await endpoint(context, edge.issueNumber);\n const { nodeId: blockerId, design } = await endpoint(context, edge.blocker);\n if (dependentId !== edge.issueNodeId || blockerId !== edge.blockerNodeId || dependentId === blockerId)\n throw new DeliveryError('Dependency endpoint identity changed.');\n if (design) return;\n if ((await currentStatus(edge.issueNumber, dependentId)) === 'In Progress' && !required.has(edge.issueNumber))\n required.set(edge.issueNumber, new Date().toISOString());\n if (!required.has(edge.issueNumber)) return;\n requireReason(edge.issueNumber);\n const actor = await context.clients.authenticatedAuthor!();\n if (\n actor.actorLogin.toLowerCase() !== authority.actorLogin.toLowerCase() ||\n actor.credentialIdentity !== authority.credentialIdentity\n )\n throw new DeliveryError('Dependency override author authority changed.');\n const episode = await episodeFor(edge);\n const comment = await commentFor(edge, episode, required.get(edge.issueNumber)!);\n const id =\n comment.id ??\n (\n await context.clients.rest.issues.createComment({\n ...context.repo,\n issue_number: edge.issueNumber,\n body: comment.body,\n })\n ).data.id;\n await verifyComment(id, comment.body, edge.issueNumber);\n // Enumeration and comment writes are not atomic with dependencies. Reconcile the exact episode again.\n if ((await episodeFor(edge)) !== episode)\n throw new DeliveryError(\n 'Dependency removal episode changed after override verification; inspect native state and resume this issue.',\n );\n const final = await getNativeBlockerRelationships({\n graphql: context.clients.graphql,\n repo: context.repo,\n issueNumber: edge.issueNumber,\n });\n if (final.blockers.some((value) => value.id === edge.blockerNodeId)) return false;\n };\n}\n"],
5
+ "mappings": "AAAA,SAAS,SAAS;AAElB,SAAS,qBAAqB;AAC9B,SAAS,mBAAmB;AAC5B;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,OACK;AACP,SAAS,qCAAqC;AAC9C,SAAS,wBAAwB;AACjC,SAAS,qBAAqB;AAEvB,MAAM,iBAAiB,EAAE,OAAO,EAAE,KAAK,EAAE,IAAI,CAAC,EAAE,IAAI,GAAI;AAQ/D,eAAe,SAAS,SAA0B,QAA8D;AAC9G,MAAI,CAAC,OAAO,cAAc,MAAM,KAAK,UAAU;AAC7C,UAAM,IAAI,cAAc,sDAAsD;AAChF,QAAM,SAAS,MAAM,QAAQ,QAAQ,KAAK,OAAO,IAAI,EAAE,GAAG,QAAQ,MAAM,cAAc,OAAO,CAAC,GAAG;AACjG,QAAM,MAAM,IAAI,IAAI,MAAM,QAAQ;AAClC,MACE,MAAM,WAAW,UACjB,kBAAkB,SAClB,CAAC,MAAM,WACP,IAAI,aAAa,YACjB,IAAI,aAAa,gBACjB,IAAI,SAAS,YAAY,MAAM,IAAI,QAAQ,KAAK,KAAK,IAAI,QAAQ,KAAK,IAAI,WAAW,MAAM,GAAG,YAAY;AAE1G,UAAM,IAAI,cAAc,4DAA4D;AACtF,SAAO,EAAE,QAAQ,MAAM,SAAS,QAAQ,cAAc,MAAM,KAAK,EAAE;AACrE;AAGA,eAAsB,oBACpB,SACA,SACA,gBACA,kBAA4B,CAAC,GAC7B;AACA,MAAI,QAAQ,QAAQ,SAAS,YAAY,CAAC,QAAQ,QAAQ;AACxD,UAAM,IAAI,cAAc,wDAAwD;AAClF,QAAM,YAAY,MAAM,QAAQ,QAAQ,oBAAoB;AAC5D,MAAI,CAA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 import assert from "node:assert/strict";
2
+ import { cpSync, mkdirSync, mkdtempSync, rmSync, writeFileSync } from "node:fs";
3
+ import { tmpdir } from "node:os";
4
+ import { join } from "node:path";
5
+ import { fileURLToPath } from "node:url";
6
+ import { Client } from "@modelcontextprotocol/sdk/client/index.js";
7
+ import { InMemoryTransport } from "@modelcontextprotocol/sdk/inMemory.js";
8
+ import { StdioClientTransport } from "@modelcontextprotocol/sdk/client/stdio.js";
9
+ import { afterEach, beforeEach, test, vi } from "vitest";
10
+ import * as dispatch from "./dispatch.js";
11
+ import { createAiDeliveryMcpServer } from "./mcp/index.js";
12
+ import { PACKAGE_VERSION } from "./version.js";
13
+ const OWNER = "@aviaratech/ai-delivery.plugin@1";
14
+ let root;
15
+ beforeEach(() => {
16
+ root = mkdtempSync(join(tmpdir(), "stale-server-"));
17
+ });
18
+ afterEach(() => {
19
+ vi.restoreAllMocks();
20
+ rmSync(root, { recursive: true, force: true });
21
+ });
22
+ function layout(state2) {
23
+ const plugin = join(root, "marketplace", "versions", PACKAGE_VERSION, "plugins", "ai-delivery");
24
+ mkdirSync(join(plugin, "runtime", "dist"), { recursive: true });
25
+ if (state2 !== void 0) writeFileSync(join(root, "state.json"), state2);
26
+ return { entry: join(plugin, "runtime", "dist", "cli.js"), plugin };
27
+ }
28
+ const state = (extra = {}, currentVersion = "9.9.9") => JSON.stringify({ owner: OWNER, currentVersion, ...extra });
29
+ async function call(runtimeEntryPath, name, args) {
30
+ const server = createAiDeliveryMcpServer({
31
+ repoRoot: "/unrelated",
32
+ repo: "example/widget",
33
+ ...runtimeEntryPath === void 0 ? {} : { runtimeEntryPath }
34
+ });
35
+ const client = new Client({ name: "stale-server", version: "1" });
36
+ const [clientTransport, serverTransport] = InMemoryTransport.createLinkedPair();
37
+ try {
38
+ await server.connect(serverTransport);
39
+ await client.connect(clientTransport);
40
+ return await client.callTool({ name, arguments: args });
41
+ } finally {
42
+ await client.close();
43
+ await server.close();
44
+ }
45
+ }
46
+ const NOTICE = `This session's ai-delivery MCP server is ${PACKAGE_VERSION} but 9.9.9 is installed, so its rules may differ. Start a new session to load 9.9.9; /clear and /reload-plugins keep this server.`;
47
+ test("a stale managed server appends the notice to invalid-argument and thrown-error replies", async () => {
48
+ const { entry } = layout(state());
49
+ const invalid = await call(entry, "issue_comment", { issueNumber: 1 });
50
+ assert.equal(invalid.isError, true);
51
+ assert.equal(invalid.content.at(-1)?.text, NOTICE);
52
+ vi.spyOn(dispatch, "executeTool").mockRejectedValue(new Error("boom"));
53
+ const thrown = await call(entry, "issue_info", { issueNumber: 1 });
54
+ assert.equal(thrown.isError, true);
55
+ assert.deepEqual(
56
+ thrown.content.map(({ text }) => text),
57
+ ["boom", NOTICE]
58
+ );
59
+ });
60
+ test("a stale managed server appends the notice after an unchanged success result", async () => {
61
+ const { entry } = layout(state());
62
+ vi.spyOn(dispatch, "executeTool").mockResolvedValue({ ok: true });
63
+ const reply = await call(entry, "issue_info", { issueNumber: 1 });
64
+ assert.notEqual(reply.isError, true);
65
+ assert.equal(reply.content.length, 2);
66
+ assert.deepEqual(JSON.parse(reply.content[0].text), { ok: true });
67
+ assert.equal(reply.content[1]?.text, NOTICE);
68
+ });
69
+ test("a matching, pending, unmanaged or unreadable install leaves replies unchanged", async () => {
70
+ const plain = async (entry) => {
71
+ const reply = await call(entry, "issue_comment", { issueNumber: 1 });
72
+ assert.equal(reply.isError, true);
73
+ assert.equal(reply.content.length, 1);
74
+ };
75
+ await plain(layout(state({}, PACKAGE_VERSION)).entry);
76
+ await plain(layout(state({ pending: {} })).entry);
77
+ await plain(layout(JSON.stringify({ owner: "someone-else", currentVersion: "9.9.9" })).entry);
78
+ await plain(layout("{").entry);
79
+ await plain(void 0);
80
+ await plain("/unrelated/dist/cli.js");
81
+ rmSync(join(root, "state.json"));
82
+ await plain(layout(void 0).entry);
83
+ });
84
+ test("the built plugin reports a stale install end to end", async () => {
85
+ const { plugin } = layout(state());
86
+ cpSync(fileURLToPath(new URL("../plugins/ai-delivery", import.meta.url)), plugin, { recursive: true });
87
+ const client = new Client({ name: "stale-server", version: "1" });
88
+ const transport = new StdioClientTransport({
89
+ command: process.execPath,
90
+ args: [join(plugin, "dist", "mcp-launcher.js")]
91
+ });
92
+ try {
93
+ await client.connect(transport);
94
+ const reply = await client.callTool({ name: "issue_comment", arguments: { issueNumber: 1 } });
95
+ assert.equal(reply.isError, true);
96
+ assert.equal(reply.content.at(-1)?.text, NOTICE);
97
+ } finally {
98
+ await client.close();
99
+ }
100
+ }, 3e4);
101
+ test("an unreadable state.json never refuses a call that would succeed", async () => {
102
+ vi.spyOn(dispatch, "executeTool").mockResolvedValue({ ok: true });
103
+ const reply = await call(layout("{").entry, "issue_info", { issueNumber: 1 });
104
+ assert.notEqual(reply.isError, true);
105
+ assert.deepEqual(
106
+ reply.content.map(({ text }) => JSON.parse(text)),
107
+ [{ ok: true }]
108
+ );
109
+ });
110
+ //# sourceMappingURL=staleServer.test.js.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../src/staleServer.test.ts"],
4
+ "sourcesContent": ["import assert from 'node:assert/strict';\nimport { cpSync, mkdirSync, mkdtempSync, rmSync, writeFileSync } from 'node:fs';\nimport { tmpdir } from 'node:os';\nimport { join } from 'node:path';\nimport { fileURLToPath } from 'node:url';\nimport { Client } from '@modelcontextprotocol/sdk/client/index.js';\nimport { InMemoryTransport } from '@modelcontextprotocol/sdk/inMemory.js';\nimport { StdioClientTransport } from '@modelcontextprotocol/sdk/client/stdio.js';\nimport { afterEach, beforeEach, test, vi } from 'vitest';\nimport * as dispatch from './dispatch.js';\nimport { createAiDeliveryMcpServer } from './mcp/index.js';\nimport { PACKAGE_VERSION } from './version.js';\n\nconst OWNER = '@aviaratech/ai-delivery.plugin@1';\nlet root: string;\nbeforeEach(() => {\n root = mkdtempSync(join(tmpdir(), 'stale-server-'));\n});\nafterEach(() => {\n vi.restoreAllMocks();\n rmSync(root, { recursive: true, force: true });\n});\n\n/** A managed install layout: <root>/marketplace/versions/<running>/plugins/ai-delivery/runtime/dist/cli.js. */\nfunction layout(state: string | undefined): { entry: string; plugin: string } {\n const plugin = join(root, 'marketplace', 'versions', PACKAGE_VERSION, 'plugins', 'ai-delivery');\n mkdirSync(join(plugin, 'runtime', 'dist'), { recursive: true });\n if (state !== undefined) writeFileSync(join(root, 'state.json'), state);\n return { entry: join(plugin, 'runtime', 'dist', 'cli.js'), plugin };\n}\nconst state = (extra: Record<string, unknown> = {}, currentVersion = '9.9.9') =>\n JSON.stringify({ owner: OWNER, currentVersion, ...extra });\n\nasync function call(\n runtimeEntryPath: string | undefined,\n name: string,\n args: Record<string, unknown>,\n): Promise<{ isError?: boolean; content: { type: string; text: string }[] }> {\n const server = createAiDeliveryMcpServer({\n repoRoot: '/unrelated',\n repo: 'example/widget',\n ...(runtimeEntryPath === undefined ? {} : { runtimeEntryPath }),\n });\n const client = new Client({ name: 'stale-server', version: '1' });\n const [clientTransport, serverTransport] = InMemoryTransport.createLinkedPair();\n try {\n await server.connect(serverTransport);\n await client.connect(clientTransport);\n return (await client.callTool({ name, arguments: args })) as Awaited<ReturnType<typeof call>>;\n } finally {\n await client.close();\n await server.close();\n }\n}\nconst NOTICE = `This session's ai-delivery MCP server is ${PACKAGE_VERSION} but 9.9.9 is installed, so its rules may differ. Start a new session to load 9.9.9; /clear and /reload-plugins keep this server.`;\n\ntest('a stale managed server appends the notice to invalid-argument and thrown-error replies', async () => {\n const { entry } = layout(state());\n // issue_comment's registered schema is loose, so its refusal comes from the handler; the SDK rejects other bad arguments before the handler runs.\n const invalid = await call(entry, 'issue_comment', { issueNumber: 1 });\n assert.equal(invalid.isError, true);\n assert.equal(invalid.content.at(-1)?.text, NOTICE);\n\n vi.spyOn(dispatch, 'executeTool').mockRejectedValue(new Error('boom'));\n const thrown = await call(entry, 'issue_info', { issueNumber: 1 });\n assert.equal(thrown.isError, true);\n assert.deepEqual(\n thrown.content.map(({ text }) => text),\n ['boom', NOTICE],\n );\n});\n\ntest('a stale managed server appends the notice after an unchanged success result', async () => {\n const { entry } = layout(state());\n vi.spyOn(dispatch, 'executeTool').mockResolvedValue({ ok: true });\n const reply = await call(entry, 'issue_info', { issueNumber: 1 });\n assert.notEqual(reply.isError, true);\n assert.equal(reply.content.length, 2);\n assert.deepEqual(JSON.parse(reply.content[0]!.text), { ok: true });\n assert.equal(reply.content[1]?.text, NOTICE);\n});\n\ntest('a matching, pending, unmanaged or unreadable install leaves replies unchanged', async () => {\n const plain = async (entry: string | undefined) => {\n const reply = await call(entry, 'issue_comment', { issueNumber: 1 });\n assert.equal(reply.isError, true);\n assert.equal(reply.content.length, 1);\n };\n await plain(layout(state({}, PACKAGE_VERSION)).entry);\n await plain(layout(state({ pending: {} })).entry);\n await plain(layout(JSON.stringify({ owner: 'someone-else', currentVersion: '9.9.9' })).entry);\n await plain(layout('{').entry);\n await plain(undefined);\n await plain('/unrelated/dist/cli.js');\n rmSync(join(root, 'state.json'));\n await plain(layout(undefined).entry);\n});\n\ntest('the built plugin reports a stale install end to end', async () => {\n const { plugin } = layout(state());\n cpSync(fileURLToPath(new URL('../plugins/ai-delivery', import.meta.url)), plugin, { recursive: true });\n const client = new Client({ name: 'stale-server', version: '1' });\n const transport = new StdioClientTransport({\n command: process.execPath,\n args: [join(plugin, 'dist', 'mcp-launcher.js')],\n });\n try {\n await client.connect(transport);\n const reply = (await client.callTool({ name: 'issue_comment', arguments: { issueNumber: 1 } })) as Awaited<\n ReturnType<typeof call>\n >;\n assert.equal(reply.isError, true);\n assert.equal(reply.content.at(-1)?.text, NOTICE);\n } finally {\n await client.close();\n }\n}, 30_000);\n\ntest('an unreadable state.json never refuses a call that would succeed', async () => {\n vi.spyOn(dispatch, 'executeTool').mockResolvedValue({ ok: true });\n const reply = await call(layout('{').entry, 'issue_info', { issueNumber: 1 });\n assert.notEqual(reply.isError, true);\n assert.deepEqual(\n reply.content.map(({ text }) => JSON.parse(text) as unknown),\n [{ ok: true }],\n );\n});\n"],
5
+ "mappings": "AAAA,OA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jD,UAAE;AACA,UAAM,OAAO,MAAM;AAAA,EACrB;AACF,GAAG,GAAM;AAET,KAAK,oEAAoE,YAAY;AACnF,KAAG,MAAM,UAAU,aAAa,EAAE,kBAAkB,EAAE,IAAI,KAAK,CAAC;AAChE,QAAM,QAAQ,MAAM,KAAK,OAAO,GAAG,EAAE,OAAO,cAAc,EAAE,aAAa,EAAE,CAAC;AAC5E,SAAO,SAAS,MAAM,SAAS,IAAI;AACnC,SAAO;AAAA,IACL,MAAM,QAAQ,IAAI,CAAC,EAAE,KAAK,MAAM,KAAK,MAAM,IAAI,CAAY;AAAA,IAC3D,CAAC,EAAE,IAAI,KAAK,CAAC;AAAA,EACf;AACF,CAAC;",
6
+ "names": ["state"]
7
+ }
package/dist/version.d.ts CHANGED
@@ -1 +1,3 @@
1
1
  export declare const PACKAGE_VERSION: string;
2
+ /** The version the installer says is current, for a runtime running from a managed install; undefined when unknown. */
3
+ export declare function installedPluginVersion(runtimeEntryPath: string): string | undefined;
package/dist/version.js CHANGED
@@ -1,9 +1,23 @@
1
1
  import { readFileSync } from "node:fs";
2
+ import { join } from "node:path";
2
3
  const packageMetadata = JSON.parse(readFileSync(new URL("../package.json", import.meta.url), "utf8"));
3
4
  if (typeof packageMetadata !== "object" || packageMetadata === null || !("version" in packageMetadata) || typeof packageMetadata.version !== "string" || !/^(0|[1-9]\d*)\.(0|[1-9]\d*)\.(0|[1-9]\d*)$/u.test(packageMetadata.version))
4
5
  throw new Error("The adjacent ai-delivery package identity must contain a stable version.");
5
6
  const PACKAGE_VERSION = packageMetadata.version;
7
+ const MANAGED_RUNTIME = /^(.+)[\\/]marketplace[\\/]versions[\\/][^\\/]+[\\/]plugins[\\/]ai-delivery[\\/]runtime[\\/]dist[\\/]cli\.js$/u;
8
+ function installedPluginVersion(runtimeEntryPath) {
9
+ const root = MANAGED_RUNTIME.exec(runtimeEntryPath)?.[1];
10
+ if (root === void 0) return void 0;
11
+ try {
12
+ const state = JSON.parse(readFileSync(join(root, "state.json"), "utf8"));
13
+ if (typeof state !== "object" || state === null || "pending" in state) return void 0;
14
+ return "owner" in state && state.owner === "@aviaratech/ai-delivery.plugin@1" && "currentVersion" in state && typeof state.currentVersion === "string" ? state.currentVersion : void 0;
15
+ } catch {
16
+ return void 0;
17
+ }
18
+ }
6
19
  export {
7
- PACKAGE_VERSION
20
+ PACKAGE_VERSION,
21
+ installedPluginVersion
8
22
  };
9
23
  //# sourceMappingURL=version.js.map
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../src/version.ts"],
4
- "sourcesContent": ["import { readFileSync } from 'node:fs';\n\nconst packageMetadata: unknown = JSON.parse(readFileSync(new URL('../package.json', import.meta.url), 'utf8'));\nif (\n typeof packageMetadata !== 'object' ||\n packageMetadata === null ||\n !('version' in packageMetadata) ||\n typeof packageMetadata.version !== 'string' ||\n !/^(0|[1-9]\\d*)\\.(0|[1-9]\\d*)\\.(0|[1-9]\\d*)$/u.test(packageMetadata.version)\n)\n throw new Error('The adjacent ai-delivery package identity must contain a stable version.');\n\nexport const PACKAGE_VERSION = packageMetadata.version;\n"],
5
- "mappings": "AAAA,SAAS,oBAAoB;AAE7B,MAAM,kBAA2B,KAAK,MAAM,aAAa,IAAI,IAAI,mBAAmB,YAAY,GAAG,GAAG,MAAM,CAAC;AAC7G,IACE,OAAO,oBAAoB,YAC3B,oBAAoB,QACpB,EAAE,aAAa,oBACf,OAAO,gBAAgB,YAAY,YACnC,CAAC,8CAA8C,KAAK,gBAAgB,OAAO;AAE3E,QAAM,IAAI,MAAM,0EAA0E;AAErF,MAAM,kBAAkB,gBAAgB;",
4
+ "sourcesContent": ["import { readFileSync } from 'node:fs';\nimport { join } from 'node:path';\n\nconst packageMetadata: unknown = JSON.parse(readFileSync(new URL('../package.json', import.meta.url), 'utf8'));\nif (\n typeof packageMetadata !== 'object' ||\n packageMetadata === null ||\n !('version' in packageMetadata) ||\n typeof packageMetadata.version !== 'string' ||\n !/^(0|[1-9]\\d*)\\.(0|[1-9]\\d*)\\.(0|[1-9]\\d*)$/u.test(packageMetadata.version)\n)\n throw new Error('The adjacent ai-delivery package identity must contain a stable version.');\n\nexport const PACKAGE_VERSION = packageMetadata.version;\n\nconst MANAGED_RUNTIME =\n /^(.+)[\\\\/]marketplace[\\\\/]versions[\\\\/][^\\\\/]+[\\\\/]plugins[\\\\/]ai-delivery[\\\\/]runtime[\\\\/]dist[\\\\/]cli\\.js$/u;\n\n/** The version the installer says is current, for a runtime running from a managed install; undefined when unknown. */\nexport function installedPluginVersion(runtimeEntryPath: string): string | undefined {\n const root = MANAGED_RUNTIME.exec(runtimeEntryPath)?.[1];\n if (root === undefined) return undefined;\n try {\n const state: unknown = JSON.parse(readFileSync(join(root, 'state.json'), 'utf8'));\n if (typeof state !== 'object' || state === null || 'pending' in state) return undefined;\n return 'owner' in state &&\n state.owner === '@aviaratech/ai-delivery.plugin@1' &&\n 'currentVersion' in state &&\n typeof state.currentVersion === 'string'\n ? state.currentVersion\n : undefined;\n } catch {\n return undefined;\n }\n}\n"],
5
+ "mappings": "AAAA,SAAS,oBAAoB;AAC7B,SAAS,YAAY;AAErB,MAAM,kBAA2B,KAAK,MAAM,aAAa,IAAI,IAAI,mBAAmB,YAAY,GAAG,GAAG,MAAM,CAAC;AAC7G,IACE,OAAO,oBAAoB,YAC3B,oBAAoB,QACpB,EAAE,aAAa,oBACf,OAAO,gBAAgB,YAAY,YACnC,CAAC,8CAA8C,KAAK,gBAAgB,OAAO;AAE3E,QAAM,IAAI,MAAM,0EAA0E;AAErF,MAAM,kBAAkB,gBAAgB;AAE/C,MAAM,kBACJ;AAGK,SAAS,uBAAuB,kBAA8C;AACnF,QAAM,OAAO,gBAAgB,KAAK,gBAAgB,IAAI,CAAC;AACvD,MAAI,SAAS,OAAW,QAAO;AAC/B,MAAI;AACF,UAAM,QAAiB,KAAK,MAAM,aAAa,KAAK,MAAM,YAAY,GAAG,MAAM,CAAC;AAChF,QAAI,OAAO,UAAU,YAAY,UAAU,QAAQ,aAAa,MAAO,QAAO;AAC9E,WAAO,WAAW,SAChB,MAAM,UAAU,sCAChB,oBAAoB,SACpB,OAAO,MAAM,mBAAmB,WAC9B,MAAM,iBACN;AAAA,EACN,QAAQ;AACN,WAAO;AAAA,EACT;AACF;",
6
6
  "names": []
7
7
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@aviaratech/ai-delivery",
3
- "version": "0.3.46",
3
+ "version": "0.3.48",
4
4
  "private": false,
5
5
  "description": "Generic GitHub issue and pull request delivery CLI and MCP server",
6
6
  "homepage": "https://github.com/aviaratech/ai-delivery#readme",
@@ -1,11 +1,11 @@
1
1
  {
2
2
  "name": "ai-delivery",
3
- "version": "0.3.46",
3
+ "version": "0.3.48",
4
4
  "description": "GitHub issue and pull request delivery tools for prepared worktrees and evidence-based handoff.",
5
5
  "author": { "name": "AviaraTech", "url": "https://github.com/aviaratech" },
6
6
  "homepage": "https://github.com/aviaratech/ai-delivery#readme",
7
7
  "repository": "https://github.com/aviaratech/ai-delivery",
8
8
  "license": "MIT",
9
9
  "deliveryCapabilityVersion": 2,
10
- "packageVersion": "0.3.46"
10
+ "packageVersion": "0.3.48"
11
11
  }
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "$schema": "https://agent-plugins.org/schemas/1.0.0/plugin.schema.json",
3
3
  "name": "ai-delivery",
4
- "version": "0.3.46",
4
+ "version": "0.3.48",
5
5
  "description": "GitHub issue and pull request delivery tools for prepared worktrees and evidence-based handoff.",
6
6
  "author": { "name": "AviaraTech", "url": "https://github.com/aviaratech" },
7
7
  "homepage": "https://github.com/aviaratech/ai-delivery#readme",