@mushi-mushi/mcp-ci 0.6.4 → 0.6.6
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/README.md +9 -9
- package/dist/{api-contract-5PFMVTHT.js → api-contract-RGYYDA62.js} +1 -2
- package/dist/api-contract-RGYYDA62.js.map +1 -0
- package/dist/cli.js +2 -2
- package/dist/{spec-drift-SGNI6UBK.js → spec-drift-AHA6YMEE.js} +3 -2
- package/dist/spec-drift-AHA6YMEE.js.map +1 -0
- package/package.json +1 -1
- package/dist/api-contract-5PFMVTHT.js.map +0 -1
- package/dist/spec-drift-SGNI6UBK.js.map +0 -1
package/README.md
CHANGED
|
@@ -53,13 +53,13 @@ jobs:
|
|
|
53
53
|
classify:
|
|
54
54
|
runs-on: ubuntu-latest
|
|
55
55
|
steps:
|
|
56
|
-
- uses:
|
|
56
|
+
- uses: kensaurus/mushi-mushi/packages/mcp-ci@master
|
|
57
57
|
with:
|
|
58
58
|
api-key: ${{ secrets.MUSHI_API_KEY }}
|
|
59
59
|
project-id: ${{ secrets.MUSHI_PROJECT_ID }}
|
|
60
60
|
command: trigger-judge
|
|
61
61
|
|
|
62
|
-
- uses:
|
|
62
|
+
- uses: kensaurus/mushi-mushi/packages/mcp-ci@master
|
|
63
63
|
with:
|
|
64
64
|
api-key: ${{ secrets.MUSHI_API_KEY }}
|
|
65
65
|
project-id: ${{ secrets.MUSHI_PROJECT_ID }}
|
|
@@ -79,7 +79,7 @@ jobs:
|
|
|
79
79
|
if: github.event.label.name == 'mushi:auto-fix'
|
|
80
80
|
runs-on: ubuntu-latest
|
|
81
81
|
steps:
|
|
82
|
-
- uses:
|
|
82
|
+
- uses: kensaurus/mushi-mushi/packages/mcp-ci@master
|
|
83
83
|
with:
|
|
84
84
|
api-key: ${{ secrets.MUSHI_API_KEY }}
|
|
85
85
|
project-id: ${{ secrets.MUSHI_PROJECT_ID }}
|
|
@@ -101,7 +101,7 @@ jobs:
|
|
|
101
101
|
- uses: actions/checkout@v4
|
|
102
102
|
|
|
103
103
|
# Refresh the crawler cookie so Gate 4 can hit auth-gated routes.
|
|
104
|
-
- uses:
|
|
104
|
+
- uses: kensaurus/mushi-mushi/packages/mcp-ci@master
|
|
105
105
|
with:
|
|
106
106
|
api-key: ${{ secrets.MUSHI_API_KEY }}
|
|
107
107
|
project-id: ${{ secrets.MUSHI_PROJECT_ID }}
|
|
@@ -111,14 +111,14 @@ jobs:
|
|
|
111
111
|
TEST_USER_PASSWORD: ${{ secrets.MUSHI_TEST_USER_PASSWORD }}
|
|
112
112
|
|
|
113
113
|
# Feed Gate 3 (api_contract) the current commit's API surface.
|
|
114
|
-
- uses:
|
|
114
|
+
- uses: kensaurus/mushi-mushi/packages/mcp-ci@master
|
|
115
115
|
with:
|
|
116
116
|
api-key: ${{ secrets.MUSHI_API_KEY }}
|
|
117
117
|
project-id: ${{ secrets.MUSHI_PROJECT_ID }}
|
|
118
118
|
command: discover-api
|
|
119
119
|
|
|
120
120
|
# Run Gates 1–5 server-side and gate the PR on the composite status.
|
|
121
|
-
- uses:
|
|
121
|
+
- uses: kensaurus/mushi-mushi/packages/mcp-ci@master
|
|
122
122
|
with:
|
|
123
123
|
api-key: ${{ secrets.MUSHI_API_KEY }}
|
|
124
124
|
project-id: ${{ secrets.MUSHI_PROJECT_ID }}
|
|
@@ -139,14 +139,14 @@ jobs:
|
|
|
139
139
|
runs-on: ubuntu-latest
|
|
140
140
|
steps:
|
|
141
141
|
- id: status
|
|
142
|
-
uses:
|
|
142
|
+
uses: kensaurus/mushi-mushi/packages/mcp-ci@master
|
|
143
143
|
with:
|
|
144
144
|
api-key: ${{ secrets.MUSHI_API_KEY }}
|
|
145
145
|
project-id: ${{ secrets.MUSHI_PROJECT_ID }}
|
|
146
146
|
command: discovery-status
|
|
147
147
|
|
|
148
148
|
- if: steps.status.outputs.ready_to_propose == 'true'
|
|
149
|
-
uses:
|
|
149
|
+
uses: kensaurus/mushi-mushi/packages/mcp-ci@master
|
|
150
150
|
with:
|
|
151
151
|
api-key: ${{ secrets.MUSHI_API_KEY }}
|
|
152
152
|
project-id: ${{ secrets.MUSHI_PROJECT_ID }}
|
|
@@ -192,4 +192,4 @@ MIT
|
|
|
192
192
|
<!-- mushi-readme-stats-footer -->
|
|
193
193
|
---
|
|
194
194
|
|
|
195
|
-
<sub>Monorepo scale (July 2026):
|
|
195
|
+
<sub>Monorepo scale (July 2026): 65 edge functions · 471 SQL migrations · 13 outbound plugins · 11 inbound adapters · 19 pipeline agents. Canonical counts: <a href="https://github.com/kensaurus/mushi-mushi/blob/master/docs/stats.md">docs/stats.md</a> · <code>pnpm docs-stats</code></sub>
|
|
@@ -123,8 +123,7 @@ async function walk(dir, onFile) {
|
|
|
123
123
|
}
|
|
124
124
|
export {
|
|
125
125
|
discoverRoutes,
|
|
126
|
-
fetchSupabaseOpenApi,
|
|
127
126
|
parseOpenApiFile,
|
|
128
127
|
walkNextAppRouter
|
|
129
128
|
};
|
|
130
|
-
//# sourceMappingURL=api-contract-
|
|
129
|
+
//# sourceMappingURL=api-contract-RGYYDA62.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/api-contract.ts"],"sourcesContent":["/**\n * API Contract adapter (whitepaper §5 Gate 3).\n *\n * Walks a customer repo for the THREE most common API surface\n * declarations and returns a normalised `${METHOD}:${path}` set:\n *\n * 1. Next.js App Router — `app/**\\/route.ts` exports (GET / POST / …).\n * 2. OpenAPI document — `openapi.yaml` / `openapi.json` paths.\n * 3. Supabase introspection — server URL hand-supplied; we GET\n * `/rest/v1/?apikey=` and pull the OpenAPI Postgrest exposes.\n *\n * The function is intentionally pure-Node + zero-dep so the GitHub\n * Action that wraps it stays tiny. It POSTs the discovered set into\n * the same `inventory-gates` endpoint via a `discovered_apis` payload\n * which Gate 3 already knows how to consume (it currently reads from\n * the crawl summary; this adapter widens the source).\n */\n\nimport { promises as fs } from 'node:fs'\nimport path from 'node:path'\n\ntype DiscoveredRoute = string // \"METHOD:path\"\n\nconst HTTP_METHODS = ['GET', 'POST', 'PUT', 'PATCH', 'DELETE'] as const\n\n/**\n * Walk Next.js App Router route handlers — `app/**\\/route.{ts,js,tsx,jsx}`\n * exports.\n *\n * Heuristic: scan each `route.*` file for `export async function GET|POST|…`.\n * We don't full-AST parse: a string match keeps the script dependency-free\n * and false positives are low (the file name is the safety net). The path\n * is derived from the directory structure relative to `app/`.\n */\nexport async function walkNextAppRouter(rootDir: string): Promise<DiscoveredRoute[]> {\n const out = new Set<DiscoveredRoute>()\n const appDir = path.join(rootDir, 'app')\n try {\n await walk(appDir, async (filePath) => {\n const base = path.basename(filePath)\n if (!/^route\\.(ts|tsx|js|jsx)$/.test(base)) return\n const content = await fs.readFile(filePath, 'utf-8').catch(() => '')\n const relative = path.relative(appDir, path.dirname(filePath)).split(path.sep).join('/')\n // Strip Next.js App Router URL-invisible segments before deriving\n // the route. Without this filter the discovery output leaks\n // file-system organisation into the API contract:\n // - `(group)` → route groups (URL-invisible bucket)\n // - `@slot` → parallel-route slots (rendered into a slot, no URL)\n // - `_private` → private/co-located files (never routable)\n // Leaving these in produces phony entries like `GET:/(marketing)/api/foo`\n // that never exist as real URLs and create false API-contract failures\n // for repos that use these standard conventions.\n const segments = relative === '' ? [] : relative.split('/').filter((seg) => {\n if (!seg) return false\n if (seg.startsWith('(') && seg.endsWith(')')) return false\n if (seg.startsWith('@')) return false\n if (seg.startsWith('_')) return false\n return true\n })\n // Convert `[id]` and `[...slug]` → `{id}` / `{slug}` and prefix with `/`.\n const routePath = '/' + segments.join('/').replace(/\\[(\\.{3})?([^\\]]+)\\]/g, '{$2}')\n for (const method of HTTP_METHODS) {\n const re = new RegExp(`export\\\\s+(?:async\\\\s+)?function\\\\s+${method}\\\\b`)\n if (re.test(content)) out.add(`${method}:${routePath || '/'}`)\n }\n })\n } catch {\n // app/ doesn't exist or is unreadable — caller falls back to OpenAPI\n }\n return Array.from(out)\n}\n\n/**\n * Parse an OpenAPI document (`openapi.yaml` / `.json`) and emit one\n * route per (method, path) entry. We use a lightweight Yaml fallback —\n * if `yaml` isn't installed in the consumer repo we just JSON.parse.\n */\nexport async function parseOpenApiFile(filePath: string): Promise<DiscoveredRoute[]> {\n const out: DiscoveredRoute[] = []\n try {\n const content = await fs.readFile(filePath, 'utf-8')\n let doc: unknown\n if (filePath.endsWith('.json')) {\n doc = JSON.parse(content)\n } else {\n try {\n // `yaml` is an optional peer-dep here — the consumer repo may or may\n // not have it installed. Cast to `any` so TS doesn't require us to\n // declare it as a hard dep just for the dynamic-import fallback path.\n const yaml = (await import('yaml' as string)) as { parse: (s: string) => unknown }\n doc = yaml.parse(content)\n } catch {\n return []\n }\n }\n const paths = (doc as { paths?: Record<string, Record<string, unknown>> }).paths ?? {}\n for (const [p, ops] of Object.entries(paths)) {\n for (const m of Object.keys(ops)) {\n const upper = m.toUpperCase()\n if ((HTTP_METHODS as readonly string[]).includes(upper)) {\n out.push(`${upper}:${p}`)\n }\n }\n }\n } catch {\n return []\n }\n return out\n}\n\n/**\n * Fetch the Supabase Postgrest OpenAPI doc — every Supabase project\n * exposes one at `/rest/v1/?apikey=…`.\n */\nasync function fetchSupabaseOpenApi(\n supabaseUrl: string,\n apiKey: string,\n): Promise<DiscoveredRoute[]> {\n try {\n const res = await fetch(`${supabaseUrl.replace(/\\/$/, '')}/rest/v1/?apikey=${apiKey}`, {\n headers: { Accept: 'application/json' },\n })\n if (!res.ok) return []\n const doc = await res.json()\n const paths = (doc as { paths?: Record<string, Record<string, unknown>> }).paths ?? {}\n const out: DiscoveredRoute[] = []\n for (const [p, ops] of Object.entries(paths)) {\n for (const m of Object.keys(ops)) {\n const upper = m.toUpperCase()\n if ((HTTP_METHODS as readonly string[]).includes(upper)) {\n out.push(`${upper}:/rest/v1${p}`)\n }\n }\n }\n return out\n } catch {\n return []\n }\n}\n\n/**\n * Aggregate every adapter for a single repo + optional Supabase target\n * and return a deduplicated, sorted list.\n */\nexport async function discoverRoutes(opts: {\n repoRoot: string\n openapiFile?: string\n supabaseUrl?: string\n supabaseAnonKey?: string\n}): Promise<DiscoveredRoute[]> {\n const all = new Set<DiscoveredRoute>()\n\n const next = await walkNextAppRouter(opts.repoRoot)\n for (const r of next) all.add(r)\n\n if (opts.openapiFile) {\n const oas = await parseOpenApiFile(opts.openapiFile)\n for (const r of oas) all.add(r)\n } else {\n // Convention: `openapi.yaml` at repo root.\n for (const candidate of ['openapi.yaml', 'openapi.json', 'openapi.yml']) {\n const full = path.join(opts.repoRoot, candidate)\n try {\n await fs.access(full)\n const oas = await parseOpenApiFile(full)\n for (const r of oas) all.add(r)\n break\n } catch {\n // not present\n }\n }\n }\n\n if (opts.supabaseUrl && opts.supabaseAnonKey) {\n const supa = await fetchSupabaseOpenApi(opts.supabaseUrl, opts.supabaseAnonKey)\n for (const r of supa) all.add(r)\n }\n\n return Array.from(all).sort()\n}\n\nasync function walk(dir: string, onFile: (p: string) => Promise<void>): Promise<void> {\n let entries\n try {\n entries = await fs.readdir(dir, { withFileTypes: true })\n } catch {\n return\n }\n for (const entry of entries) {\n if (entry.name === 'node_modules' || entry.name === '.next' || entry.name.startsWith('.')) continue\n const full = path.join(dir, entry.name)\n if (entry.isDirectory()) {\n await walk(full, onFile)\n } else if (entry.isFile()) {\n await onFile(full)\n }\n }\n}\n"],"mappings":";AAkBA,SAAS,YAAY,UAAU;AAC/B,OAAO,UAAU;AAIjB,IAAM,eAAe,CAAC,OAAO,QAAQ,OAAO,SAAS,QAAQ;AAW7D,eAAsB,kBAAkB,SAA6C;AACnF,QAAM,MAAM,oBAAI,IAAqB;AACrC,QAAM,SAAS,KAAK,KAAK,SAAS,KAAK;AACvC,MAAI;AACF,UAAM,KAAK,QAAQ,OAAO,aAAa;AACrC,YAAM,OAAO,KAAK,SAAS,QAAQ;AACnC,UAAI,CAAC,2BAA2B,KAAK,IAAI,EAAG;AAC5C,YAAM,UAAU,MAAM,GAAG,SAAS,UAAU,OAAO,EAAE,MAAM,MAAM,EAAE;AACnE,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;AACF,cAAM,GAAG,OAAO,IAAI;AACpB,cAAM,MAAM,MAAM,iBAAiB,IAAI;AACvC,mBAAW,KAAK,IAAK,KAAI,IAAI,CAAC;AAC9B;AAAA,MACF,QAAQ;AAAA,MAER;AAAA,IACF;AAAA,EACF;AAEA,MAAI,KAAK,eAAe,KAAK,iBAAiB;AAC5C,UAAM,OAAO,MAAM,qBAAqB,KAAK,aAAa,KAAK,eAAe;AAC9E,eAAW,KAAK,KAAM,KAAI,IAAI,CAAC;AAAA,EACjC;AAEA,SAAO,MAAM,KAAK,GAAG,EAAE,KAAK;AAC9B;AAEA,eAAe,KAAK,KAAa,QAAqD;AACpF,MAAI;AACJ,MAAI;AACF,cAAU,MAAM,GAAG,QAAQ,KAAK,EAAE,eAAe,KAAK,CAAC;AAAA,EACzD,QAAQ;AACN;AAAA,EACF;AACA,aAAW,SAAS,SAAS;AAC3B,QAAI,MAAM,SAAS,kBAAkB,MAAM,SAAS,WAAW,MAAM,KAAK,WAAW,GAAG,EAAG;AAC3F,UAAM,OAAO,KAAK,KAAK,KAAK,MAAM,IAAI;AACtC,QAAI,MAAM,YAAY,GAAG;AACvB,YAAM,KAAK,MAAM,MAAM;AAAA,IACzB,WAAW,MAAM,OAAO,GAAG;AACzB,YAAM,OAAO,IAAI;AAAA,IACnB;AAAA,EACF;AACF;","names":[]}
|
package/dist/cli.js
CHANGED
|
@@ -86,7 +86,7 @@ async function main() {
|
|
|
86
86
|
break;
|
|
87
87
|
}
|
|
88
88
|
case "discover-api": {
|
|
89
|
-
const { discoverRoutes } = await import("./api-contract-
|
|
89
|
+
const { discoverRoutes } = await import("./api-contract-RGYYDA62.js");
|
|
90
90
|
const repoRoot = core.getInput("repo-root") || process.cwd();
|
|
91
91
|
const openapiFile = core.getInput("openapi-file") || void 0;
|
|
92
92
|
const supabaseUrl = core.getInput("supabase-url") || void 0;
|
|
@@ -123,7 +123,7 @@ async function main() {
|
|
|
123
123
|
const failOnBreaking = core.getInput("fail-on-breaking") !== "false";
|
|
124
124
|
const commitSha = core.getInput("commit-sha") || process.env.GITHUB_SHA || void 0;
|
|
125
125
|
const prNumber = core.getInput("pr-number") ? Number(core.getInput("pr-number")) : void 0;
|
|
126
|
-
const { runSpecDrift } = await import("./spec-drift-
|
|
126
|
+
const { runSpecDrift } = await import("./spec-drift-AHA6YMEE.js");
|
|
127
127
|
const diffFindings = await runSpecDrift({ baseSpec, headSpec });
|
|
128
128
|
core.info(`oasdiff found ${diffFindings.length} change(s)`);
|
|
129
129
|
core.setOutput("findings", JSON.stringify(diffFindings));
|
|
@@ -21,7 +21,8 @@ function getOasdiffUrl() {
|
|
|
21
21
|
}
|
|
22
22
|
async function downloadOasdiff() {
|
|
23
23
|
const cacheDir = join(homedir(), ".mushi", "tools");
|
|
24
|
-
mkdirSync(cacheDir, { recursive: true });
|
|
24
|
+
mkdirSync(cacheDir, { recursive: true, mode: 448 });
|
|
25
|
+
if (process.platform !== "win32") chmodSync(cacheDir, 448);
|
|
25
26
|
const ext = process.platform === "win32" ? ".exe" : "";
|
|
26
27
|
const binPath = join(cacheDir, `oasdiff-${OASDIFF_VERSION}${ext}`);
|
|
27
28
|
if (existsSync(binPath)) return binPath;
|
|
@@ -98,4 +99,4 @@ async function runSpecDrift(opts) {
|
|
|
98
99
|
export {
|
|
99
100
|
runSpecDrift
|
|
100
101
|
};
|
|
101
|
-
//# sourceMappingURL=spec-drift-
|
|
102
|
+
//# sourceMappingURL=spec-drift-AHA6YMEE.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/spec-drift.ts"],"sourcesContent":["/**\n * spec-drift.ts — Gate 6 oasdiff-based OpenAPI spec drift detection.\n *\n * Downloads the oasdiff Go binary (static, no runtime deps) and runs\n * `oasdiff breaking <base> <head>` to find breaking API changes between\n * two OpenAPI spec versions.\n *\n * The binary is cached under ~/.mushi/tools/oasdiff-<version> after first download.\n * Version can be pinned via the OASDIFF_VERSION env var; defaults to latest.\n */\n\nimport { execFileSync } from 'node:child_process'\nimport { existsSync, mkdirSync, chmodSync, writeFileSync, mkdtempSync, rmSync } from 'node:fs'\nimport { homedir } from 'node:os'\nimport { join } from 'node:path'\nimport { createHash } from 'node:crypto'\n\nconst OASDIFF_VERSION = process.env.OASDIFF_VERSION ?? '1.10.18'\n\nconst PLATFORM_MAP: Record<string, string> = {\n 'linux-x64': 'linux-amd64',\n 'linux-arm64': 'linux-arm64',\n 'darwin-x64': 'darwin-amd64',\n 'darwin-arm64': 'darwin-arm64',\n 'win32-x64': 'windows-amd64',\n}\n\nfunction getOasdiffUrl(): string {\n const platformKey = `${process.platform}-${process.arch}`\n const platform = PLATFORM_MAP[platformKey]\n if (!platform) throw new Error(`Unsupported platform for oasdiff: ${platformKey}`)\n const ext = process.platform === 'win32' ? '.exe' : ''\n return (\n `https://github.com/Tufin/oasdiff/releases/download/v${OASDIFF_VERSION}/` +\n `oasdiff_${OASDIFF_VERSION}_${platform}${ext}.tar.gz`\n )\n}\n\nasync function downloadOasdiff(): Promise<string> {\n const cacheDir = join(homedir(), '.mushi', 'tools')\n // 0700: the download and extract dir stay private to this user. `mode` only\n // applies to directories mkdir creates, so tighten an existing one too.\n mkdirSync(cacheDir, { recursive: true, mode: 0o700 })\n if (process.platform !== 'win32') chmodSync(cacheDir, 0o700)\n const ext = process.platform === 'win32' ? '.exe' : ''\n const binPath = join(cacheDir, `oasdiff-${OASDIFF_VERSION}${ext}`)\n if (existsSync(binPath)) return binPath\n\n const url = getOasdiffUrl()\n const res = await fetch(url)\n if (!res.ok) throw new Error(`Failed to download oasdiff: HTTP ${res.status} from ${url}`)\n\n const buf = Buffer.from(await res.arrayBuffer())\n const maxBytes = 64 * 1024 * 1024\n if (buf.length > maxBytes) {\n throw new Error(`oasdiff download too large (${buf.length} bytes) — aborting`)\n }\n\n // Store under ~/.mushi/tools (mode 0700 dir) instead of the world-readable\n // system temp dir — avoids CodeQL insecure-temp-file + keeps cache reusable.\n const tgzPath = join(cacheDir, `oasdiff-${createHash('md5').update(url).digest('hex')}.tar.gz`)\n writeFileSync(tgzPath, buf)\n\n const extractDir = mkdtempSync(join(cacheDir, 'oasdiff-extract-'))\n try {\n execFileSync('tar', ['-xzf', tgzPath, '-C', extractDir])\n\n const { readdirSync, copyFileSync } = await import('node:fs')\n const files = readdirSync(extractDir)\n const binName = process.platform === 'win32' ? 'oasdiff.exe' : 'oasdiff'\n const found = files.find((f) => f === binName || f.startsWith('oasdiff'))\n if (!found) throw new Error(`oasdiff binary not found in archive. Files: ${files.join(', ')}`)\n copyFileSync(join(extractDir, found), binPath)\n if (process.platform !== 'win32') chmodSync(binPath, 0o755)\n } finally {\n rmSync(extractDir, { recursive: true, force: true })\n rmSync(tgzPath, { force: true })\n }\n return binPath\n}\n\nexport interface SpecDriftFinding {\n severity: 'error' | 'warn' | 'info'\n rule_id: string\n message: string\n path?: string\n method?: string\n}\n\nexport async function runSpecDrift(opts: {\n baseSpec: string\n headSpec: string\n}): Promise<SpecDriftFinding[]> {\n let binPath: string\n try {\n binPath = await downloadOasdiff()\n } catch (err) {\n throw new Error(`oasdiff download failed: ${err instanceof Error ? err.message : String(err)}`)\n }\n\n let output = ''\n try {\n output = execFileSync(binPath, ['breaking', opts.baseSpec, opts.headSpec, '--format', 'json'], {\n encoding: 'utf-8',\n timeout: 30_000,\n // oasdiff exits 1 when breaking changes are found — that's expected.\n // We catch the error and still parse stdout.\n })\n } catch (err) {\n // execFileSync throws on non-zero exit. Capture stdout from the error object.\n const execErr = err as { stdout?: string; stderr?: string; status?: number }\n output = execErr.stdout ?? ''\n // If no stdout and non-zero exit, it's a real failure (e.g. binary crash).\n if (!output && execErr.status !== 1) {\n throw new Error(\n `oasdiff failed: ${execErr.stderr ?? String(err)}`,\n )\n }\n }\n\n if (!output.trim()) return []\n\n let parsed: unknown\n try {\n parsed = JSON.parse(output)\n } catch {\n // oasdiff may output plain text in some versions — wrap as a single warning.\n return [{ severity: 'warn', rule_id: 'spec-drift-parse-error', message: output.slice(0, 500) }]\n }\n\n // oasdiff JSON output: array of { id, text, level, operation, operationId, path, source }\n const items = Array.isArray(parsed) ? parsed : []\n return items.map((item: Record<string, unknown>) => {\n const level = String(item.level ?? 'error').toLowerCase()\n const severity: SpecDriftFinding['severity'] =\n level === 'error' || level === 'breaking' ? 'error'\n : level === 'warn' || level === 'warning' ? 'warn'\n : 'info'\n return {\n severity,\n rule_id: String(item.id ?? 'spec-drift'),\n message: String(item.text ?? item.message ?? JSON.stringify(item)),\n path: item.path ? String(item.path) : undefined,\n method: item.operation ? String(item.operation) : undefined,\n }\n })\n}\n"],"mappings":";AAWA,SAAS,oBAAoB;AAC7B,SAAS,YAAY,WAAW,WAAW,eAAe,aAAa,cAAc;AACrF,SAAS,eAAe;AACxB,SAAS,YAAY;AACrB,SAAS,kBAAkB;AAE3B,IAAM,kBAAkB,QAAQ,IAAI,mBAAmB;AAEvD,IAAM,eAAuC;AAAA,EAC3C,aAAa;AAAA,EACb,eAAe;AAAA,EACf,cAAc;AAAA,EACd,gBAAgB;AAAA,EAChB,aAAa;AACf;AAEA,SAAS,gBAAwB;AAC/B,QAAM,cAAc,GAAG,QAAQ,QAAQ,IAAI,QAAQ,IAAI;AACvD,QAAM,WAAW,aAAa,WAAW;AACzC,MAAI,CAAC,SAAU,OAAM,IAAI,MAAM,qCAAqC,WAAW,EAAE;AACjF,QAAM,MAAM,QAAQ,aAAa,UAAU,SAAS;AACpD,SACE,uDAAuD,eAAe,YAC3D,eAAe,IAAI,QAAQ,GAAG,GAAG;AAEhD;AAEA,eAAe,kBAAmC;AAChD,QAAM,WAAW,KAAK,QAAQ,GAAG,UAAU,OAAO;AAGlD,YAAU,UAAU,EAAE,WAAW,MAAM,MAAM,IAAM,CAAC;AACpD,MAAI,QAAQ,aAAa,QAAS,WAAU,UAAU,GAAK;AAC3D,QAAM,MAAM,QAAQ,aAAa,UAAU,SAAS;AACpD,QAAM,UAAU,KAAK,UAAU,WAAW,eAAe,GAAG,GAAG,EAAE;AACjE,MAAI,WAAW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ANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mushi-mushi/mcp-ci",
|
|
3
|
-
"version": "0.6.
|
|
3
|
+
"version": "0.6.6",
|
|
4
4
|
"description": "GitHub Action entrypoint for running Mushi Mushi MCP tools in CI — trigger judge, dispatch fixes, gate merges on classification coverage.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"type": "module",
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/api-contract.ts"],"sourcesContent":["/**\n * API Contract adapter (whitepaper §5 Gate 3).\n *\n * Walks a customer repo for the THREE most common API surface\n * declarations and returns a normalised `${METHOD}:${path}` set:\n *\n * 1. Next.js App Router — `app/**\\/route.ts` exports (GET / POST / …).\n * 2. OpenAPI document — `openapi.yaml` / `openapi.json` paths.\n * 3. Supabase introspection — server URL hand-supplied; we GET\n * `/rest/v1/?apikey=` and pull the OpenAPI Postgrest exposes.\n *\n * The function is intentionally pure-Node + zero-dep so the GitHub\n * Action that wraps it stays tiny. It POSTs the discovered set into\n * the same `inventory-gates` endpoint via a `discovered_apis` payload\n * which Gate 3 already knows how to consume (it currently reads from\n * the crawl summary; this adapter widens the source).\n */\n\nimport { promises as fs } from 'node:fs'\nimport path from 'node:path'\n\ntype DiscoveredRoute = string // \"METHOD:path\"\n\nconst HTTP_METHODS = ['GET', 'POST', 'PUT', 'PATCH', 'DELETE'] as const\n\n/**\n * Walk Next.js App Router route handlers — `app/**\\/route.{ts,js,tsx,jsx}`\n * exports.\n *\n * Heuristic: scan each `route.*` file for `export async function GET|POST|…`.\n * We don't full-AST parse: a string match keeps the script dependency-free\n * and false positives are low (the file name is the safety net). The path\n * is derived from the directory structure relative to `app/`.\n */\nexport async function walkNextAppRouter(rootDir: string): Promise<DiscoveredRoute[]> {\n const out = new Set<DiscoveredRoute>()\n const appDir = path.join(rootDir, 'app')\n try {\n await walk(appDir, async (filePath) => {\n const base = path.basename(filePath)\n if (!/^route\\.(ts|tsx|js|jsx)$/.test(base)) return\n const content = await fs.readFile(filePath, 'utf-8').catch(() => '')\n const relative = path.relative(appDir, path.dirname(filePath)).split(path.sep).join('/')\n // Strip Next.js App Router URL-invisible segments before deriving\n // the route. Without this filter the discovery output leaks\n // file-system organisation into the API contract:\n // - `(group)` → route groups (URL-invisible bucket)\n // - `@slot` → parallel-route slots (rendered into a slot, no URL)\n // - `_private` → private/co-located files (never routable)\n // Leaving these in produces phony entries like `GET:/(marketing)/api/foo`\n // that never exist as real URLs and create false API-contract failures\n // for repos that use these standard conventions.\n const segments = relative === '' ? [] : relative.split('/').filter((seg) => {\n if (!seg) return false\n if (seg.startsWith('(') && seg.endsWith(')')) return false\n if (seg.startsWith('@')) return false\n if (seg.startsWith('_')) return false\n return true\n })\n // Convert `[id]` and `[...slug]` → `{id}` / `{slug}` and prefix with `/`.\n const routePath = '/' + segments.join('/').replace(/\\[(\\.{3})?([^\\]]+)\\]/g, '{$2}')\n for (const method of HTTP_METHODS) {\n const re = new RegExp(`export\\\\s+(?:async\\\\s+)?function\\\\s+${method}\\\\b`)\n if (re.test(content)) out.add(`${method}:${routePath || '/'}`)\n }\n })\n } catch {\n // app/ doesn't exist or is unreadable — caller falls back to OpenAPI\n }\n return Array.from(out)\n}\n\n/**\n * Parse an OpenAPI document (`openapi.yaml` / `.json`) and emit one\n * route per (method, path) entry. We use a lightweight Yaml fallback —\n * if `yaml` isn't installed in the consumer repo we just JSON.parse.\n */\nexport async function parseOpenApiFile(filePath: string): Promise<DiscoveredRoute[]> {\n const out: DiscoveredRoute[] = []\n try {\n const content = await fs.readFile(filePath, 'utf-8')\n let doc: unknown\n if (filePath.endsWith('.json')) {\n doc = JSON.parse(content)\n } else {\n try {\n // `yaml` is an optional peer-dep here — the consumer repo may or may\n // not have it installed. Cast to `any` so TS doesn't require us to\n // declare it as a hard dep just for the dynamic-import fallback path.\n const yaml = (await import('yaml' as string)) as { parse: (s: string) => unknown }\n doc = yaml.parse(content)\n } catch {\n return []\n }\n }\n const paths = (doc as { paths?: Record<string, Record<string, unknown>> }).paths ?? {}\n for (const [p, ops] of Object.entries(paths)) {\n for (const m of Object.keys(ops)) {\n const upper = m.toUpperCase()\n if ((HTTP_METHODS as readonly string[]).includes(upper)) {\n out.push(`${upper}:${p}`)\n }\n }\n }\n } catch {\n return []\n }\n return out\n}\n\n/**\n * Fetch the Supabase Postgrest OpenAPI doc — every Supabase project\n * exposes one at `/rest/v1/?apikey=…`.\n */\nexport async function fetchSupabaseOpenApi(\n supabaseUrl: string,\n apiKey: string,\n): Promise<DiscoveredRoute[]> {\n try {\n const res = await fetch(`${supabaseUrl.replace(/\\/$/, '')}/rest/v1/?apikey=${apiKey}`, {\n headers: { Accept: 'application/json' },\n })\n if (!res.ok) return []\n const doc = await res.json()\n const paths = (doc as { paths?: Record<string, Record<string, unknown>> }).paths ?? {}\n const out: DiscoveredRoute[] = []\n for (const [p, ops] of Object.entries(paths)) {\n for (const m of Object.keys(ops)) {\n const upper = m.toUpperCase()\n if ((HTTP_METHODS as readonly string[]).includes(upper)) {\n out.push(`${upper}:/rest/v1${p}`)\n }\n }\n }\n return out\n } catch {\n return []\n }\n}\n\n/**\n * Aggregate every adapter for a single repo + optional Supabase target\n * and return a deduplicated, sorted list.\n */\nexport async function discoverRoutes(opts: {\n repoRoot: string\n openapiFile?: string\n supabaseUrl?: string\n supabaseAnonKey?: string\n}): Promise<DiscoveredRoute[]> {\n const all = new Set<DiscoveredRoute>()\n\n const next = await walkNextAppRouter(opts.repoRoot)\n for (const r of next) all.add(r)\n\n if (opts.openapiFile) {\n const oas = await parseOpenApiFile(opts.openapiFile)\n for (const r of oas) all.add(r)\n } else {\n // Convention: `openapi.yaml` at repo root.\n for (const candidate of ['openapi.yaml', 'openapi.json', 'openapi.yml']) {\n const full = path.join(opts.repoRoot, candidate)\n try {\n await fs.access(full)\n const oas = await parseOpenApiFile(full)\n for (const r of oas) all.add(r)\n break\n } catch {\n // not present\n }\n }\n }\n\n if (opts.supabaseUrl && opts.supabaseAnonKey) {\n const supa = await fetchSupabaseOpenApi(opts.supabaseUrl, opts.supabaseAnonKey)\n for (const r of supa) all.add(r)\n }\n\n return Array.from(all).sort()\n}\n\nasync function walk(dir: string, onFile: (p: string) => Promise<void>): Promise<void> {\n let entries\n try {\n entries = await fs.readdir(dir, { withFileTypes: true })\n } catch {\n return\n }\n for (const entry of entries) {\n if (entry.name === 'node_modules' || entry.name === '.next' || entry.name.startsWith('.')) continue\n const full = path.join(dir, entry.name)\n if (entry.isDirectory()) {\n await walk(full, onFile)\n } else if (entry.isFile()) {\n await onFile(full)\n }\n }\n}\n"],"mappings":";AAkBA,SAAS,YAAY,UAAU;AAC/B,OAAO,UAAU;AAIjB,IAAM,eAAe,CAAC,OAAO,QAAQ,OAAO,SAAS,QAAQ;AAW7D,eAAsB,kBAAkB,SAA6C;AACnF,QAAM,MAAM,oBAAI,IAAqB;AACrC,QAAM,SAAS,KAAK,KAAK,SAAS,KAAK;AACvC,MAAI;AACF,UAAM,KAAK,QAAQ,OAAO,aAAa;AACrC,YAAM,OAAO,KAAK,SAAS,QAAQ;AACnC,UAAI,CAAC,2BAA2B,KAAK,IAAI,EAAG;AAC5C,YAAM,UAAU,MAAM,GAAG,SAAS,UAAU,OAAO,EAAE,MAAM,MAAM,EAAE;AACnE,YAAM,WAAW,KAAK,SAAS,QAAQ,KAAK,QAAQ,QAAQ,CAAC,EAAE,MAAM,KAAK,GAAG,EAAE,KAAK,GAAG;AAUvF,YAAM,WAAW,aAAa,KAAK,CAAC,IAAI,SAAS,MAAM,GAAG,EAAE,OAAO,CAAC,QAAQ;AAC1E,YAAI,CAAC,IAAK,QAAO;AACjB,YAAI,IAAI,WAAW,GAAG,KAAK,IAAI,SAAS,GAAG,EAAG,QAAO;AACrD,YAAI,IAAI,WAAW,GAAG,EAAG,QAAO;AAChC,YAAI,IAAI,WAAW,GAAG,EAAG,QAAO;AAChC,eAAO;AAAA,MACT,CAAC;AAED,YAAM,YAAY,MAAM,SAAS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AI;AACF,cAAU,MAAM,GAAG,QAAQ,KAAK,EAAE,eAAe,KAAK,CAAC;AAAA,EACzD,QAAQ;AACN;AAAA,EACF;AACA,aAAW,SAAS,SAAS;AAC3B,QAAI,MAAM,SAAS,kBAAkB,MAAM,SAAS,WAAW,MAAM,KAAK,WAAW,GAAG,EAAG;AAC3F,UAAM,OAAO,KAAK,KAAK,KAAK,MAAM,IAAI;AACtC,QAAI,MAAM,YAAY,GAAG;AACvB,YAAM,KAAK,MAAM,MAAM;AAAA,IACzB,WAAW,MAAM,OAAO,GAAG;AACzB,YAAM,OAAO,IAAI;AAAA,IACnB;AAAA,EACF;AACF;","names":[]}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/spec-drift.ts"],"sourcesContent":["/**\n * spec-drift.ts — Gate 6 oasdiff-based OpenAPI spec drift detection.\n *\n * Downloads the oasdiff Go binary (static, no runtime deps) and runs\n * `oasdiff breaking <base> <head>` to find breaking API changes between\n * two OpenAPI spec versions.\n *\n * The binary is cached under ~/.mushi/oasdiff-<version> after first download.\n * Version can be pinned via the OASDIFF_VERSION env var; defaults to latest.\n */\n\nimport { execFileSync } from 'node:child_process'\nimport { existsSync, mkdirSync, chmodSync, writeFileSync, mkdtempSync, rmSync } from 'node:fs'\nimport { homedir } from 'node:os'\nimport { join } from 'node:path'\nimport { createHash } from 'node:crypto'\n\nconst OASDIFF_VERSION = process.env.OASDIFF_VERSION ?? '1.10.18'\n\nconst PLATFORM_MAP: Record<string, string> = {\n 'linux-x64': 'linux-amd64',\n 'linux-arm64': 'linux-arm64',\n 'darwin-x64': 'darwin-amd64',\n 'darwin-arm64': 'darwin-arm64',\n 'win32-x64': 'windows-amd64',\n}\n\nfunction getOasdiffUrl(): string {\n const platformKey = `${process.platform}-${process.arch}`\n const platform = PLATFORM_MAP[platformKey]\n if (!platform) throw new Error(`Unsupported platform for oasdiff: ${platformKey}`)\n const ext = process.platform === 'win32' ? '.exe' : ''\n return (\n `https://github.com/Tufin/oasdiff/releases/download/v${OASDIFF_VERSION}/` +\n `oasdiff_${OASDIFF_VERSION}_${platform}${ext}.tar.gz`\n )\n}\n\nasync function downloadOasdiff(): Promise<string> {\n const cacheDir = join(homedir(), '.mushi', 'tools')\n mkdirSync(cacheDir, { recursive: true })\n const ext = process.platform === 'win32' ? '.exe' : ''\n const binPath = join(cacheDir, `oasdiff-${OASDIFF_VERSION}${ext}`)\n if (existsSync(binPath)) return binPath\n\n const url = getOasdiffUrl()\n const res = await fetch(url)\n if (!res.ok) throw new Error(`Failed to download oasdiff: HTTP ${res.status} from ${url}`)\n\n const buf = Buffer.from(await res.arrayBuffer())\n const maxBytes = 64 * 1024 * 1024\n if (buf.length > maxBytes) {\n throw new Error(`oasdiff download too large (${buf.length} bytes) — aborting`)\n }\n\n // Store under ~/.mushi/tools (mode 0700 dir) instead of the world-readable\n // system temp dir — avoids CodeQL insecure-temp-file + keeps cache reusable.\n const tgzPath = join(cacheDir, `oasdiff-${createHash('md5').update(url).digest('hex')}.tar.gz`)\n writeFileSync(tgzPath, buf)\n\n const extractDir = mkdtempSync(join(cacheDir, 'oasdiff-extract-'))\n try {\n execFileSync('tar', ['-xzf', tgzPath, '-C', extractDir])\n\n const { readdirSync, copyFileSync } = await import('node:fs')\n const files = readdirSync(extractDir)\n const binName = process.platform === 'win32' ? 'oasdiff.exe' : 'oasdiff'\n const found = files.find((f) => f === binName || f.startsWith('oasdiff'))\n if (!found) throw new Error(`oasdiff binary not found in archive. Files: ${files.join(', ')}`)\n copyFileSync(join(extractDir, found), binPath)\n if (process.platform !== 'win32') chmodSync(binPath, 0o755)\n } finally {\n rmSync(extractDir, { recursive: true, force: true })\n rmSync(tgzPath, { force: true })\n }\n return binPath\n}\n\nexport interface SpecDriftFinding {\n severity: 'error' | 'warn' | 'info'\n rule_id: string\n message: string\n path?: string\n method?: string\n}\n\nexport async function runSpecDrift(opts: {\n baseSpec: string\n headSpec: string\n}): Promise<SpecDriftFinding[]> {\n let binPath: string\n try {\n binPath = await downloadOasdiff()\n } catch (err) {\n throw new Error(`oasdiff download failed: ${err instanceof Error ? err.message : String(err)}`)\n }\n\n let output = ''\n try {\n output = execFileSync(binPath, ['breaking', opts.baseSpec, opts.headSpec, '--format', 'json'], {\n encoding: 'utf-8',\n timeout: 30_000,\n // oasdiff exits 1 when breaking changes are found — that's expected.\n // We catch the error and still parse stdout.\n })\n } catch (err) {\n // execFileSync throws on non-zero exit. Capture stdout from the error object.\n const execErr = err as { stdout?: string; stderr?: string; status?: number }\n output = execErr.stdout ?? ''\n // If no stdout and non-zero exit, it's a real failure (e.g. binary crash).\n if (!output && execErr.status !== 1) {\n throw new Error(\n `oasdiff failed: ${execErr.stderr ?? String(err)}`,\n )\n }\n }\n\n if (!output.trim()) return []\n\n let parsed: unknown\n try {\n parsed = JSON.parse(output)\n } catch {\n // oasdiff may output plain text in some versions — wrap as a single warning.\n return [{ severity: 'warn', rule_id: 'spec-drift-parse-error', message: output.slice(0, 500) }]\n }\n\n // oasdiff JSON output: array of { id, text, level, operation, operationId, path, source }\n const items = Array.isArray(parsed) ? parsed : []\n return items.map((item: Record<string, unknown>) => {\n const level = String(item.level ?? 'error').toLowerCase()\n const severity: SpecDriftFinding['severity'] =\n level === 'error' || level === 'breaking' ? 'error'\n : level === 'warn' || level === 'warning' ? 'warn'\n : 'info'\n return {\n severity,\n rule_id: String(item.id ?? 'spec-drift'),\n message: String(item.text ?? item.message ?? JSON.stringify(item)),\n path: item.path ? String(item.path) : undefined,\n method: item.operation ? String(item.operation) : undefined,\n }\n })\n}\n"],"mappings":";AAWA,SAAS,oBAAoB;AAC7B,SAAS,YAAY,WAAW,WAAW,eAAe,aAAa,cAAc;AACrF,SAAS,eAAe;AACxB,SAAS,YAAY;AACrB,SAAS,kBAAkB;AAE3B,IAAM,kBAAkB,QAAQ,IAAI,mBAAmB;AAEvD,IAAM,eAAuC;AAAA,EAC3C,aAAa;AAAA,EACb,eAAe;AAAA,EACf,cAAc;AAAA,EACd,g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