@aviaratech/ai-delivery 0.3.47 → 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.
package/dist/mcp/index.js CHANGED
@@ -3,7 +3,7 @@ import { StdioServerTransport } from "@modelcontextprotocol/sdk/server/stdio.js"
3
3
  import { z } from "zod";
4
4
  import { executeTool } from "../dispatch.js";
5
5
  import { setLogsSuppressed } from "../logger.js";
6
- import { PACKAGE_VERSION } from "../version.js";
6
+ import { PACKAGE_VERSION, installedPluginVersion } from "../version.js";
7
7
  import { acceptedKeysError } from "../issueContract.js";
8
8
  import {
9
9
  JOURNAL_SCHEMA_METADATA,
@@ -16,7 +16,18 @@ import { projectToolOutput } from "../toolOutput.js";
16
16
  import { AI_DELIVERY_MCP_TOOLS } from "./tools.js";
17
17
  import { AI_DELIVERY_MCP_CONTRACT_VERSION, AI_DELIVERY_MCP_TOOLS as AI_DELIVERY_MCP_TOOLS2 } from "./tools.js";
18
18
  const SERVER_INSTRUCTIONS = "Use issue_info with an explicit repo; follow repository policy for checks and authorization, and respect requested providers and read-only intent.";
19
+ function staleServerNotice(runtimeEntryPath) {
20
+ const installed = runtimeEntryPath === void 0 ? void 0 : installedPluginVersion(runtimeEntryPath);
21
+ return installed === void 0 || installed === PACKAGE_VERSION ? void 0 : `This session's ai-delivery MCP server is ${PACKAGE_VERSION} but ${installed} is installed, so its rules may differ. Start a new session to load ${installed}; /clear and /reload-plugins keep this server.`;
22
+ }
19
23
  function createAiDeliveryMcpServer(context, activeCalls) {
24
+ const withNotice = (text) => {
25
+ const notice = staleServerNotice(context.runtimeEntryPath);
26
+ return [
27
+ { type: "text", text },
28
+ ...notice === void 0 ? [] : [{ type: "text", text: notice }]
29
+ ];
30
+ };
20
31
  const server = new McpServer(
21
32
  { name: "ai-delivery", version: PACKAGE_VERSION },
22
33
  { instructions: SERVER_INSTRUCTIONS }
@@ -40,12 +51,9 @@ function createAiDeliveryMcpServer(context, activeCalls) {
40
51
  const missing = journal && args.body === void 0 ? missingJournalFields(args) : [];
41
52
  const stated = journal ? parsed.error.issues.map((issue) => issue.message).filter((m) => [NEXT_DATE_REFUSAL, PLAIN_COMMENT_REFUSAL].includes(m)) : [];
42
53
  return {
43
- content: [
44
- {
45
- type: "text",
46
- text: `Invalid arguments for ${tool.name}.${missing.length ? ` Missing required fields: ${missing.join(", ")}. Provide every missing field.` : stated.length ? ` ${stated.join(" ")}` : journal ? ` ${tool.description}` : ""}`
47
- }
48
- ],
54
+ content: withNotice(
55
+ `Invalid arguments for ${tool.name}.${missing.length ? ` Missing required fields: ${missing.join(", ")}. Provide every missing field.` : stated.length ? ` ${stated.join(" ")}` : journal ? ` ${tool.description}` : ""}`
56
+ ),
49
57
  isError: true
50
58
  };
51
59
  }
@@ -65,26 +73,19 @@ function createAiDeliveryMcpServer(context, activeCalls) {
65
73
  activeCalls?.delete(pending);
66
74
  }
67
75
  return {
68
- content: [
69
- { type: "text", text: JSON.stringify(projectToolOutput(tool.name, value, verbose === true)) }
70
- ]
76
+ content: withNotice(JSON.stringify(projectToolOutput(tool.name, value, verbose === true)))
71
77
  };
72
78
  } catch (error) {
73
79
  const incomplete = getIncompleteIssueUpdate(error);
74
80
  if (incomplete !== void 0)
75
81
  return {
76
- content: [
77
- {
78
- type: "text",
79
- text: JSON.stringify(
80
- projectToolOutput(tool.name, incomplete, "verbose" in args && args.verbose === true)
81
- )
82
- }
83
- ],
82
+ content: withNotice(
83
+ JSON.stringify(projectToolOutput(tool.name, incomplete, "verbose" in args && args.verbose === true))
84
+ ),
84
85
  isError: true
85
86
  };
86
87
  const message = error instanceof Error ? error.message : String(error);
87
- return { content: [{ type: "text", text: message }], isError: true };
88
+ return { content: withNotice(message), isError: true };
88
89
  }
89
90
  }
90
91
  );
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../src/mcp/index.ts"],
4
- "sourcesContent": ["import { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js';\nimport { StdioServerTransport } from '@modelcontextprotocol/sdk/server/stdio.js';\nimport { z } from 'zod';\n\nimport { executeTool, type ExecutionContext } from '../dispatch.js';\nimport { setLogsSuppressed } from '../logger.js';\nimport { PACKAGE_VERSION } from '../version.js';\nimport { acceptedKeysError } from '../issueContract.js';\nimport {\n JOURNAL_SCHEMA_METADATA,\n NEXT_DATE_REFUSAL,\n PLAIN_COMMENT_REFUSAL,\n missingJournalFields,\n} from '../issueJournal.js';\nimport { getIncompleteIssueUpdate } from '../issue.js';\nimport { projectToolOutput } from '../toolOutput.js';\nimport { AI_DELIVERY_MCP_TOOLS, type AiDeliveryMcpToolName } from './tools.js';\n\nexport { AI_DELIVERY_MCP_CONTRACT_VERSION, AI_DELIVERY_MCP_TOOLS } from './tools.js';\n\nconst SERVER_INSTRUCTIONS =\n 'Use issue_info with an explicit repo; follow repository policy for checks and authorization, and respect requested providers and read-only intent.';\n\nexport function createAiDeliveryMcpServer(context: ExecutionContext, activeCalls?: Set<Promise<unknown>>): McpServer {\n const server = new McpServer(\n { name: 'ai-delivery', version: PACKAGE_VERSION },\n { instructions: SERVER_INSTRUCTIONS },\n );\n const tools: readonly {\n name: string;\n description: string;\n inputSchema: z.ZodObject<z.ZodRawShape>;\n readOnly?: true;\n }[] = AI_DELIVERY_MCP_TOOLS;\n for (const tool of tools) {\n server.registerTool(\n tool.name,\n {\n description: tool.description,\n ...(tool.readOnly ? { annotations: { readOnlyHint: true } } : {}),\n // The SDK must leave journal kind refinements to the handler so missing\n // conditional fields receive a safe, actionable contract refusal. Unknown\n // property names stay private through a schema-local error message.\n inputSchema:\n tool.name === 'issue_comment'\n ? z\n .strictObject(tool.inputSchema.shape, { error: acceptedKeysError })\n .partial()\n .meta(JOURNAL_SCHEMA_METADATA)\n : tool.inputSchema,\n },\n async (args, extra) => {\n const parsed = tool.inputSchema.safeParse(args);\n if (!parsed.success) {\n const journal = tool.name === 'issue_comment';\n const missing = journal && args.body === undefined ? missingJournalFields(args) : [];\n // A missing-field list comes first; these refusals already say what to send, so they replace the generic text.\n const stated = journal\n ? parsed.error.issues\n .map((issue) => issue.message)\n .filter((m) => [NEXT_DATE_REFUSAL, PLAIN_COMMENT_REFUSAL].includes(m))\n : [];\n return {\n content: [\n {\n type: 'text' as const,\n text: `Invalid arguments for ${tool.name}.${missing.length ? ` Missing required fields: ${missing.join(', ')}. Provide every missing field.` : stated.length ? ` ${stated.join(' ')}` : journal ? ` ${tool.description}` : ''}`,\n },\n ],\n isError: true,\n };\n }\n try {\n const signal = context.signal === undefined ? extra.signal : AbortSignal.any([context.signal, extra.signal]);\n const { verbose, ...input } = parsed.data;\n const pending = executeTool(tool.name as AiDeliveryMcpToolName, input, {\n ...context,\n signal,\n ...(verbose === true ? { verbose } : {}),\n });\n activeCalls?.add(pending);\n let value: unknown;\n try {\n value = await pending;\n } finally {\n activeCalls?.delete(pending);\n }\n return {\n content: [\n { type: 'text' as const, text: JSON.stringify(projectToolOutput(tool.name, value, verbose === true)) },\n ],\n };\n } catch (error) {\n const incomplete = getIncompleteIssueUpdate(error);\n if (incomplete !== undefined)\n return {\n content: [\n {\n type: 'text' as const,\n text: JSON.stringify(\n projectToolOutput(tool.name, incomplete, 'verbose' in args && args.verbose === true),\n ),\n },\n ],\n isError: true,\n };\n const message = error instanceof Error ? error.message : String(error);\n return { content: [{ type: 'text' as const, text: message }], isError: true };\n }\n },\n );\n }\n return server;\n}\n\nexport async function serveAiDeliveryMcp(context: ExecutionContext): Promise<void> {\n setLogsSuppressed(true);\n const shutdown = new AbortController();\n const activeCalls = new Set<Promise<unknown>>();\n const server = createAiDeliveryMcpServer({ ...context, signal: shutdown.signal }, activeCalls);\n let closing: Promise<void> | undefined;\n const close = (): Promise<void> => {\n closing ??= (async () => {\n shutdown.abort();\n await Promise.allSettled(activeCalls);\n await server.close();\n process.exit(0);\n })();\n return closing;\n };\n process.once('SIGINT', () => {\n void close();\n });\n process.once('SIGTERM', () => {\n void close();\n });\n await server.connect(new StdioServerTransport());\n process.stderr.write('ai-delivery MCP server started\\n');\n await new Promise<void>(() => {});\n}\n"],
5
- "mappings": "AAAA,SAAS,iBAAiB;AAC1B,SAAS,4BAA4B;AACrC,SAAS,SAAS;AAElB,SAAS,mBAA0C;AACnD,SAAS,yBAAyB;AAClC,SAAS,uBAAuB;AAChC,SAAS,yBAAyB;AAClC;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACK;AACP,SAAS,gCAAgC;AACzC,SAAS,yBAAyB;AAClC,SAAS,6BAAyD;AAElE,SAAS,kCAAkC,yBAAAA,8BAA6B;AAExE,MAAM,sBACJ;AAEK,SAAS,0BAA0B,SAA2B,aAAgD;AACnH,QAAM,SAAS,IAAI;AAAA,IACjB,EAAE,MAAM,eAAe,SAAS,gBAAgB;AAAA,IAChD,EAAE,cAAc,oBAAoB;AAAA,EACtC;AACA,QAAM,QAKA;AACN,aAAW,QAAQ,OAAO;AACxB,WAAO;AAAA,MACL,KAAK;AAAA,MACL;AAAA,QACE,aAAa,KAAK;AAAA,QAClB,GAAI,KAAK,WAAW,EAAE,aAAa,EAAE,cAAc,KAAK,EAAE,IAAI,CAAC;AAAA;AAAA;AAAA;AAAA,QAI/D,aACE,KAAK,SAAS,kBACV,EACG,aAAa,KAAK,YAAY,OAAO,EAAE,OAAO,kBAAkB,CAAC,EACjE,QAAQ,EACR,KAAK,uBAAuB,IAC/B,KAAK;AAAA,MACb;AAAA,MACA,OAAO,MAAM,UAAU;AACrB,cAAM,SAAS,KAAK,YAAY,UAAU,IAAI;AAC9C,YAAI,CAAC,OAAO,SAAS;AACnB,gBAAM,UAAU,KAAK,SAAS;AAC9B,gBAAM,UAAU,WAAW,KAAK,SAAS,SAAY,qBAAqB,IAAI,IAAI,CAAC;AAEnF,gBAAM,SAAS,UACX,OAAO,MAAM,OACV,IAAI,CAAC,UAAU,MAAM,OAAO,EAC5B,OAAO,CAAC,MAAM,CAAC,mBAAmB,qBAAqB,EAAE,SAAS,CAAC,CAAC,I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OAAO,KAAK;AACrE,iBAAO,EAAE,SAAS,CAAC,EAAE,MAAM,QAAiB,MAAM,QAAQ,CAAC,GAAG,SAAS,KAAK;AAAA,QAC9E;AAAA,MACF;AAAA,IACF;AAAA,EACF;AACA,SAAO;AACT;AAEA,eAAsB,mBAAmB,SAA0C;AACjF,oBAAkB,IAAI;AACtB,QAAM,WAAW,IAAI,gBAAgB;AACrC,QAAM,cAAc,oBAAI,IAAsB;AAC9C,QAAM,SAAS,0BAA0B,EAAE,GAAG,SAAS,QAAQ,SAAS,OAAO,GAAG,WAAW;AAC7F,MAAI;AACJ,QAAM,QAAQ,MAAqB;AACjC,iBAAa,YAAY;AACvB,eAAS,MAAM;AACf,YAAM,QAAQ,WAAW,WAAW;AACpC,YAAM,OAAO,MAAM;AACnB,cAAQ,KAAK,CAAC;AAAA,IAChB,GAAG;AACH,WAAO;AAAA,EACT;AACA,UAAQ,KAAK,UAAU,MAAM;AAC3B,SAAK,MAAM;AAAA,EACb,CAAC;AACD,UAAQ,KAAK,WAAW,MAAM;AAC5B,SAAK,MAAM;AAAA,EACb,CAAC;AACD,QAAM,OAAO,QAAQ,IAAI,qBAAqB,CAAC;AAC/C,UAAQ,OAAO,MAAM,kCAAkC;AACvD,QAAM,IAAI,QAAc,MAAM;AAAA,EAAC,CAAC;AAClC;",
4
+ "sourcesContent": ["import { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js';\nimport { StdioServerTransport } from '@modelcontextprotocol/sdk/server/stdio.js';\nimport { z } from 'zod';\n\nimport { executeTool, type ExecutionContext } from '../dispatch.js';\nimport { setLogsSuppressed } from '../logger.js';\nimport { PACKAGE_VERSION, installedPluginVersion } from '../version.js';\nimport { acceptedKeysError } from '../issueContract.js';\nimport {\n JOURNAL_SCHEMA_METADATA,\n NEXT_DATE_REFUSAL,\n PLAIN_COMMENT_REFUSAL,\n missingJournalFields,\n} from '../issueJournal.js';\nimport { getIncompleteIssueUpdate } from '../issue.js';\nimport { projectToolOutput } from '../toolOutput.js';\nimport { AI_DELIVERY_MCP_TOOLS, type AiDeliveryMcpToolName } from './tools.js';\n\nexport { AI_DELIVERY_MCP_CONTRACT_VERSION, AI_DELIVERY_MCP_TOOLS } from './tools.js';\n\nconst SERVER_INSTRUCTIONS =\n 'Use issue_info with an explicit repo; follow repository policy for checks and authorization, and respect requested providers and read-only intent.';\n\n/** Set when this server runs from a managed install whose current version has since changed. */\nfunction staleServerNotice(runtimeEntryPath: string | undefined): string | undefined {\n const installed = runtimeEntryPath === undefined ? undefined : installedPluginVersion(runtimeEntryPath);\n return installed === undefined || installed === PACKAGE_VERSION\n ? undefined\n : `This session's ai-delivery MCP server is ${PACKAGE_VERSION} but ${installed} is installed, so its rules may differ. Start a new session to load ${installed}; /clear and /reload-plugins keep this server.`;\n}\n\nexport function createAiDeliveryMcpServer(context: ExecutionContext, activeCalls?: Set<Promise<unknown>>): McpServer {\n const withNotice = (text: string) => {\n const notice = staleServerNotice(context.runtimeEntryPath);\n return [\n { type: 'text' as const, text },\n ...(notice === undefined ? [] : [{ type: 'text' as const, text: notice }]),\n ];\n };\n const server = new McpServer(\n { name: 'ai-delivery', version: PACKAGE_VERSION },\n { instructions: SERVER_INSTRUCTIONS },\n );\n const tools: readonly {\n name: string;\n description: string;\n inputSchema: z.ZodObject<z.ZodRawShape>;\n readOnly?: true;\n }[] = AI_DELIVERY_MCP_TOOLS;\n for (const tool of tools) {\n server.registerTool(\n tool.name,\n {\n description: tool.description,\n ...(tool.readOnly ? { annotations: { readOnlyHint: true } } : {}),\n // The SDK must leave journal kind refinements to the handler so missing\n // conditional fields receive a safe, actionable contract refusal. Unknown\n // property names stay private through a schema-local error message.\n inputSchema:\n tool.name === 'issue_comment'\n ? z\n .strictObject(tool.inputSchema.shape, { error: acceptedKeysError })\n .partial()\n .meta(JOURNAL_SCHEMA_METADATA)\n : tool.inputSchema,\n },\n async (args, extra) => {\n const parsed = tool.inputSchema.safeParse(args);\n if (!parsed.success) {\n const journal = tool.name === 'issue_comment';\n const missing = journal && args.body === undefined ? missingJournalFields(args) : [];\n // A missing-field list comes first; these refusals already say what to send, so they replace the generic text.\n const stated = journal\n ? parsed.error.issues\n .map((issue) => issue.message)\n .filter((m) => [NEXT_DATE_REFUSAL, PLAIN_COMMENT_REFUSAL].includes(m))\n : [];\n return {\n content: withNotice(\n `Invalid arguments for ${tool.name}.${missing.length ? ` Missing required fields: ${missing.join(', ')}. Provide every missing field.` : stated.length ? ` ${stated.join(' ')}` : journal ? ` ${tool.description}` : ''}`,\n ),\n isError: true,\n };\n }\n try {\n const signal = context.signal === undefined ? extra.signal : AbortSignal.any([context.signal, extra.signal]);\n const { verbose, ...input } = parsed.data;\n const pending = executeTool(tool.name as AiDeliveryMcpToolName, input, {\n ...context,\n signal,\n ...(verbose === true ? { verbose } : {}),\n });\n activeCalls?.add(pending);\n let value: unknown;\n try {\n value = await pending;\n } finally {\n activeCalls?.delete(pending);\n }\n return {\n content: withNotice(JSON.stringify(projectToolOutput(tool.name, value, verbose === true))),\n };\n } catch (error) {\n const incomplete = getIncompleteIssueUpdate(error);\n if (incomplete !== undefined)\n return {\n content: withNotice(\n JSON.stringify(projectToolOutput(tool.name, incomplete, 'verbose' in args && args.verbose === true)),\n ),\n isError: true,\n };\n const message = error instanceof Error ? error.message : String(error);\n return { content: withNotice(message), isError: true };\n }\n },\n );\n }\n return server;\n}\n\nexport async function serveAiDeliveryMcp(context: ExecutionContext): Promise<void> {\n setLogsSuppressed(true);\n const shutdown = new AbortController();\n const activeCalls = new Set<Promise<unknown>>();\n const server = createAiDeliveryMcpServer({ ...context, signal: shutdown.signal }, activeCalls);\n let closing: Promise<void> | undefined;\n const close = (): Promise<void> => {\n closing ??= (async () => {\n shutdown.abort();\n await Promise.allSettled(activeCalls);\n await server.close();\n process.exit(0);\n })();\n return closing;\n };\n process.once('SIGINT', () => {\n void close();\n });\n process.once('SIGTERM', () => {\n void close();\n });\n await server.connect(new StdioServerTransport());\n process.stderr.write('ai-delivery MCP server started\\n');\n await new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BAAyB,KAAK;AACjD,cAAI,eAAe;AACjB,mBAAO;AAAA,cACL,SAAS;AAAA,gBACP,KAAK,UAAU,kBAAkB,KAAK,MAAM,YAAY,aAAa,QAAQ,KAAK,YAAY,IAAI,CAAC;AAAA,cACrG;AAAA,cACA,SAAS;AAAA,YACX;AACF,gBAAM,UAAU,iBAAiB,QAAQ,MAAM,UAAU,OAAO,KAAK;AACrE,iBAAO,EAAE,SAAS,WAAW,OAAO,GAAG,SAAS,KAAK;AAAA,QACvD;AAAA,MACF;AAAA,IACF;AAAA,EACF;AACA,SAAO;AACT;AAEA,eAAsB,mBAAmB,SAA0C;AACjF,oBAAkB,IAAI;AACtB,QAAM,WAAW,IAAI,gBAAgB;AACrC,QAAM,cAAc,oBAAI,IAAsB;AAC9C,QAAM,SAAS,0BAA0B,EAAE,GAAG,SAAS,QAAQ,SAAS,OAAO,GAAG,WAAW;AAC7F,MAAI;AACJ,QAAM,QAAQ,MAAqB;AACjC,iBAAa,YAAY;AACvB,eAAS,MAAM;AACf,YAAM,QAAQ,WAAW,WAAW;AACpC,YAAM,OAAO,MAAM;AACnB,cAAQ,KAAK,CAAC;AAAA,IAChB,GAAG;AACH,WAAO;AAAA,EACT;AACA,UAAQ,KAAK,UAAU,MAAM;AAC3B,SAAK,MAAM;AAAA,EACb,CAAC;AACD,UAAQ,KAAK,WAAW,MAAM;AAC5B,SAAK,MAAM;AAAA,EACb,CAAC;AACD,QAAM,OAAO,QAAQ,IAAI,qBAAqB,CAAC;AAC/C,UAAQ,OAAO,MAAM,kCAAkC;AACvD,QAAM,IAAI,QAAc,MAAM;AAAA,EAAC,CAAC;AAClC;",
6
6
  "names": ["AI_DELIVERY_MCP_TOOLS"]
7
7
  }
@@ -37,8 +37,12 @@ function evaluateAgentReadiness(input) {
37
37
  add("priority", "priority", "Set native Priority with issue_update before autonomous development.");
38
38
  if (input.issueType === void 0)
39
39
  add("issue-type", "issueType", "Set native Issue Type with issue_update before autonomous development.");
40
- if ((input.blockedBy?.length ?? 0) > 0)
41
- add("blocked", "blockedBy", "Resolve open native blockers before autonomous development.");
40
+ if (input.blockedBy && input.blockedBy.length > 0)
41
+ add(
42
+ "blocked",
43
+ "blockedBy",
44
+ `Resolve open native blockers ${input.blockedBy.map((n) => "#" + String(n)).join(", ")} before autonomous development.`
45
+ );
42
46
  if (input.trackingParent)
43
47
  add("tracking-parent", "parent", "Dispatch an executable sub-issue instead of the tracking parent.");
44
48
  return { failures, warnings, ready: failures.length === 0 };
@@ -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,c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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,OAAO,YAAY;AACnB,SAAS,QAA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,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.47",
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.47",
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.47"
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.47",
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",