@patchbay-nebius/agent 0.1.3 → 0.2.0
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 +1 -1
- package/dist/{scanner-HW5E6G7U.js → chunk-63LPPBLZ.js} +68 -51
- package/dist/chunk-63LPPBLZ.js.map +1 -0
- package/dist/{chunk-JVXVCXNZ.js → chunk-DZXK5OTN.js} +904 -78
- package/dist/chunk-DZXK5OTN.js.map +1 -0
- package/dist/cli.js +98 -25
- package/dist/cli.js.map +1 -1
- package/dist/fixtures-py.template.py +196 -0
- package/dist/index.d.ts +146 -38
- package/dist/index.js +35 -3
- package/dist/scanner-CEZ56J5N.js +11 -0
- package/dist/scanner-CEZ56J5N.js.map +1 -0
- package/package.json +3 -2
- package/dist/chunk-JVXVCXNZ.js.map +0 -1
- package/dist/scanner-HW5E6G7U.js.map +0 -1
package/README.md
CHANGED
|
@@ -61,7 +61,7 @@ Full breakdown and per-prompt stability in [bench/RESULTS-variance.md](https://g
|
|
|
61
61
|
## Also runs as
|
|
62
62
|
|
|
63
63
|
- **MCP server** for Claude Code / Codex / Cursor — see [@patchbay-nebius/mcp](https://www.npmjs.com/package/@patchbay-nebius/mcp)
|
|
64
|
-
- **Web app** — live at <https://patchbay-
|
|
64
|
+
- **Web app** — live at <https://patchbay-mcp.dev>
|
|
65
65
|
- **Slack slash command** — see [docs/slack-setup.md](https://github.com/GodSmasher/patchbay/blob/main/docs/slack-setup.md)
|
|
66
66
|
|
|
67
67
|
Built for the [Nebius × NVIDIA Global AI Hackathon](https://nebiusglobalaihackathon.devpost.com).
|
|
@@ -38,37 +38,42 @@ var VENDOR_HINTS = {
|
|
|
38
38
|
trello: "Trello",
|
|
39
39
|
freshdesk: "Freshdesk",
|
|
40
40
|
monday: "Monday",
|
|
41
|
-
pipeline: "Pipedrive",
|
|
42
41
|
quickbooks: "QuickBooks",
|
|
43
42
|
xero: "Xero",
|
|
44
43
|
paypal: "PayPal",
|
|
45
44
|
square: "Square"
|
|
46
45
|
};
|
|
47
46
|
var VENDOR_PATTERN = new RegExp(`\\b(${Object.keys(VENDOR_HINTS).join("|")})\\b`, "gi");
|
|
48
|
-
function
|
|
49
|
-
const files = walk(root);
|
|
47
|
+
function scanFiles(files) {
|
|
50
48
|
const opportunities = [];
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
content = readFileSync(file, "utf8");
|
|
57
|
-
} catch {
|
|
58
|
-
continue;
|
|
59
|
-
}
|
|
60
|
-
const rel = relative(root, file).replace(/\\/g, "/");
|
|
61
|
-
const name = basename(file).toLowerCase();
|
|
49
|
+
const contentByPath = /* @__PURE__ */ new Map();
|
|
50
|
+
for (const f of files) contentByPath.set(f.path, f.content);
|
|
51
|
+
for (const { path, content } of files) {
|
|
52
|
+
if (content.length > SCAN_MAX_BYTES) continue;
|
|
53
|
+
const name = basename(path).toLowerCase();
|
|
62
54
|
const lines = content.split("\n");
|
|
63
55
|
if (name.endsWith(".env") || name.endsWith(".env.example") || name === ".env.example" || name === ".env.sample") {
|
|
64
|
-
opportunities.push(...scanEnvFile(
|
|
56
|
+
opportunities.push(...scanEnvFile(path, lines));
|
|
65
57
|
}
|
|
66
|
-
opportunities.push(...scanTodos(
|
|
67
|
-
opportunities.push(...scanWebhookHandlers(
|
|
68
|
-
opportunities.push(...
|
|
58
|
+
opportunities.push(...scanTodos(path, lines));
|
|
59
|
+
opportunities.push(...scanWebhookHandlers(path, lines, content));
|
|
60
|
+
opportunities.push(...scanVendorImportsFromMemory(path, lines, contentByPath));
|
|
69
61
|
}
|
|
70
62
|
return rankAndDedupe(opportunities);
|
|
71
63
|
}
|
|
64
|
+
function scanRepo(root) {
|
|
65
|
+
const paths = walk(root);
|
|
66
|
+
const files = [];
|
|
67
|
+
for (const abs of paths) {
|
|
68
|
+
try {
|
|
69
|
+
const size = statSync(abs).size;
|
|
70
|
+
if (size > SCAN_MAX_BYTES) continue;
|
|
71
|
+
files.push({ path: relative(root, abs).replace(/\\/g, "/"), content: readFileSync(abs, "utf8") });
|
|
72
|
+
} catch {
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
return scanFiles(files);
|
|
76
|
+
}
|
|
72
77
|
function walk(dir, out = []) {
|
|
73
78
|
let entries;
|
|
74
79
|
try {
|
|
@@ -129,6 +134,11 @@ function scanTodos(file, lines) {
|
|
|
129
134
|
if (text.length < 15) continue;
|
|
130
135
|
if (!INTEGRATION_KEYWORDS.test(text) && !VENDOR_PATTERN.test(text)) continue;
|
|
131
136
|
const vendors = detectVendors(text);
|
|
137
|
+
if (vendors.length > 0 && !INTEGRATION_KEYWORDS.test(text)) {
|
|
138
|
+
const vendorText = vendors.join(" ").toLowerCase();
|
|
139
|
+
const AMBIGUOUS = /^(square|monday|discord|notion|linear|slack|resend|pipeline|hook|paypal)$/;
|
|
140
|
+
if (vendors.length === 1 && AMBIGUOUS.test(vendorText.split(" ")[0])) continue;
|
|
141
|
+
}
|
|
132
142
|
found.push({
|
|
133
143
|
score: 50 + vendors.length * 10 + (INTEGRATION_KEYWORDS.test(text) ? 10 : 0),
|
|
134
144
|
kind: "todo",
|
|
@@ -143,33 +153,45 @@ function scanTodos(file, lines) {
|
|
|
143
153
|
}
|
|
144
154
|
function scanWebhookHandlers(file, lines, content) {
|
|
145
155
|
const found = [];
|
|
146
|
-
const
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
156
|
+
const isPy = file.endsWith(".py");
|
|
157
|
+
const tsRouteRe = /@?(?:router|app|bp)\.(?:post|put|patch|get)\s*\(\s*['"`]([^'"`]*(?:webhook|hook|callback|notify|event)[^'"`]*)['"`]/gi;
|
|
158
|
+
const pyFlaskRouteRe = /@(?:app|bp)\.route\s*\(\s*['"]([^'"]*(?:webhook|hook|callback|notify|event)[^'"]*)['"]/gi;
|
|
159
|
+
const seen = /* @__PURE__ */ new Set();
|
|
160
|
+
const runRe = (re) => {
|
|
161
|
+
let m;
|
|
162
|
+
while (m = re.exec(content)) {
|
|
163
|
+
if (seen.has(m.index)) continue;
|
|
164
|
+
seen.add(m.index);
|
|
165
|
+
const path = m[1];
|
|
166
|
+
const upto = content.slice(0, m.index);
|
|
167
|
+
const lineNo = upto.split("\n").length;
|
|
168
|
+
const windowStart = Math.max(0, lineNo - 1);
|
|
169
|
+
const window = lines.slice(windowStart, Math.min(lines.length, windowStart + 20)).join("\n");
|
|
170
|
+
const stubby = /(TODO|FIXME|not\s+implemented|throw\s+new\s+Error|raise\s+NotImplementedError|raise\s+Exception\s*\(\s*['"]not\s+implemented)/i.test(window) || // TS: fewer than two matched braces means empty function body
|
|
171
|
+
!isPy && window.replace(/[^{}]/g, "").length < 4 || // Py: body is literally `pass` on its own line after the signature
|
|
172
|
+
isPy && /\bdef\s+\w+[^)]*\)[^:]*:\s*(?:#[^\n]*\n\s*)*pass\s*(?:\n|$)/.test(window);
|
|
173
|
+
if (!stubby) continue;
|
|
174
|
+
const vendors = detectVendors(path + " " + window);
|
|
175
|
+
found.push({
|
|
176
|
+
score: 70 + vendors.length * 10,
|
|
177
|
+
kind: "webhook-handler",
|
|
178
|
+
file,
|
|
179
|
+
line: lineNo,
|
|
180
|
+
evidence: `${path} \u2014 route body is empty / TODO / not-implemented`,
|
|
181
|
+
vendors,
|
|
182
|
+
prompt: vendors.length ? `When a ${vendors[0]} webhook hits ${path}, handle the payload and ${inferAction(vendors)}.` : `When an incoming webhook hits ${path}, verify the signature, parse the payload and forward the result to the configured target.`
|
|
183
|
+
});
|
|
184
|
+
}
|
|
185
|
+
};
|
|
186
|
+
runRe(tsRouteRe);
|
|
187
|
+
if (isPy) runRe(pyFlaskRouteRe);
|
|
167
188
|
return found;
|
|
168
189
|
}
|
|
169
190
|
var FRAMEWORK_IMPORT_HINTS = /\/(hydrogen|remix-oxygen|next|nuxt|express|fastify|koa|hono|svelte|solid|qwik|astro|react|vue|polaris|themes|plugin|cli)(\/|$)/i;
|
|
170
|
-
function
|
|
191
|
+
function scanVendorImportsFromMemory(file, lines, contentByPath) {
|
|
171
192
|
const found = [];
|
|
172
193
|
if (file.endsWith(".d.ts") || file.includes(".generated.") || file.includes("/generated/")) return found;
|
|
194
|
+
const fileContent = contentByPath.get(file) ?? "";
|
|
173
195
|
for (let i = 0; i < lines.length; i++) {
|
|
174
196
|
const line = lines[i];
|
|
175
197
|
const match = line.match(/(?:from\s+|require\(\s*)['"]([^'"\n]+)['"]/);
|
|
@@ -179,7 +201,7 @@ function scanVendorImports(file, lines) {
|
|
|
179
201
|
if (FRAMEWORK_IMPORT_HINTS.test(spec)) continue;
|
|
180
202
|
const vendor = detectVendor(spec.replace(/^@/, "").toLowerCase());
|
|
181
203
|
if (!vendor) continue;
|
|
182
|
-
const vendorUses = (
|
|
204
|
+
const vendorUses = (fileContent.match(new RegExp(`\\b${vendor}`, "gi")) || []).length;
|
|
183
205
|
if (vendorUses > 6) continue;
|
|
184
206
|
const title = VENDOR_HINTS[vendor];
|
|
185
207
|
found.push({
|
|
@@ -194,13 +216,6 @@ function scanVendorImports(file, lines) {
|
|
|
194
216
|
}
|
|
195
217
|
return found;
|
|
196
218
|
}
|
|
197
|
-
function readSafe(file) {
|
|
198
|
-
try {
|
|
199
|
-
return readFileSync(file, "utf8");
|
|
200
|
-
} catch {
|
|
201
|
-
return "";
|
|
202
|
-
}
|
|
203
|
-
}
|
|
204
219
|
function detectVendor(text) {
|
|
205
220
|
for (const key of Object.keys(VENDOR_HINTS)) if (text.includes(key)) return key;
|
|
206
221
|
return null;
|
|
@@ -259,8 +274,10 @@ Or let patchbay build the top N for you:
|
|
|
259
274
|
patchbay scan ${root} --build-top=1`;
|
|
260
275
|
return header + "\n" + body + footer;
|
|
261
276
|
}
|
|
277
|
+
|
|
262
278
|
export {
|
|
263
|
-
|
|
264
|
-
scanRepo
|
|
279
|
+
scanFiles,
|
|
280
|
+
scanRepo,
|
|
281
|
+
formatReport
|
|
265
282
|
};
|
|
266
|
-
//# sourceMappingURL=
|
|
283
|
+
//# sourceMappingURL=chunk-63LPPBLZ.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/scanner.ts"],"sourcesContent":["import { readFileSync, readdirSync, statSync } from 'node:fs'\nimport { join, relative, extname, basename } from 'node:path'\n\n/**\n * `patchbay scan <dir>` walks a repository looking for integration opportunities\n * patchbay could build. It reports a prioritised list with a concrete one-sentence\n * prompt per opportunity so the user can go straight to `patchbay build \"...\"`\n * (or `patchbay scan <dir> --build-top=N` for the hands-off path).\n *\n * The scanner is deliberately heuristic — regex + file-structure only, no LLM —\n * so it's instant, free, and the user can audit every signal we flagged.\n */\n\nexport interface Opportunity {\n score: number\n kind: 'todo' | 'env-var' | 'webhook-handler' | 'vendor-sdk-import'\n file: string\n line: number\n evidence: string\n prompt: string\n vendors: string[]\n}\n\nconst SKIP_DIRS = new Set(['node_modules', '.git', 'dist', '.next', 'out', 'build', '.turbo', '.vercel', 'coverage'])\nconst SCAN_EXTS = new Set(['.ts', '.tsx', '.js', '.jsx', '.mjs', '.cjs', '.py', '.go', '.rb', '.env', '.example'])\nconst SCAN_MAX_BYTES = 500_000\n\n/** Default cap on the formatted report so a template repo doesn't produce 100 lines. */\nconst DEFAULT_REPORT_LIMIT = 15\n\nconst INTEGRATION_KEYWORDS = /\\b(webhook|sync|notify|integrate|forward|post\\s+to|send\\s+to|push\\s+to|pull\\s+from|fetch\\s+from|subscribe|publish|route\\s+to|hook\\s+into)\\b/i\n\n/** Vendor name → canonical title case for the prompt. */\nconst VENDOR_HINTS: Record<string, string> = {\n stripe: 'Stripe', shopify: 'Shopify', mailchimp: 'Mailchimp', typeform: 'Typeform', pipedrive: 'Pipedrive',\n hubspot: 'HubSpot', salesforce: 'Salesforce', slack: 'Slack', discord: 'Discord', notion: 'Notion',\n airtable: 'Airtable', asana: 'Asana', jira: 'Jira', linear: 'Linear', github: 'GitHub', gitlab: 'GitLab',\n zendesk: 'Zendesk', intercom: 'Intercom', twilio: 'Twilio', sendgrid: 'SendGrid', brevo: 'Brevo',\n resend: 'Resend', postmark: 'Postmark', mailgun: 'Mailgun', calendly: 'Calendly', jotform: 'Jotform',\n pusher: 'Pusher', zoom: 'Zoom', trello: 'Trello', freshdesk: 'Freshdesk', monday: 'Monday',\n quickbooks: 'QuickBooks', xero: 'Xero', paypal: 'PayPal', square: 'Square',\n}\n\nconst VENDOR_PATTERN = new RegExp(`\\\\b(${Object.keys(VENDOR_HINTS).join('|')})\\\\b`, 'gi')\n\nexport interface ScanInputFile {\n /** Repo-relative path, forward slashes. */\n path: string\n content: string\n}\n\n/**\n * Scan a list of in-memory files. Used by both the CLI (which populates it by walking\n * disk) and the web scanner (which populates it from the GitHub REST API).\n */\nexport function scanFiles(files: ScanInputFile[]): Opportunity[] {\n const opportunities: Opportunity[] = []\n const contentByPath = new Map<string, string>()\n for (const f of files) contentByPath.set(f.path, f.content)\n for (const { path, content } of files) {\n if (content.length > SCAN_MAX_BYTES) continue\n const name = basename(path).toLowerCase()\n const lines = content.split('\\n')\n if (name.endsWith('.env') || name.endsWith('.env.example') || name === '.env.example' || name === '.env.sample') {\n opportunities.push(...scanEnvFile(path, lines))\n }\n opportunities.push(...scanTodos(path, lines))\n opportunities.push(...scanWebhookHandlers(path, lines, content))\n opportunities.push(...scanVendorImportsFromMemory(path, lines, contentByPath))\n }\n return rankAndDedupe(opportunities)\n}\n\nexport function scanRepo(root: string): Opportunity[] {\n const paths = walk(root)\n const files: ScanInputFile[] = []\n for (const abs of paths) {\n try {\n const size = statSync(abs).size\n if (size > SCAN_MAX_BYTES) continue\n files.push({ path: relative(root, abs).replace(/\\\\/g, '/'), content: readFileSync(abs, 'utf8') })\n } catch { /* skip */ }\n }\n return scanFiles(files)\n}\n\nfunction walk(dir: string, out: string[] = []): string[] {\n let entries: string[]\n try { entries = readdirSync(dir) } catch { return out }\n for (const entry of entries) {\n if (entry.startsWith('.') && !entry.startsWith('.env')) continue\n if (SKIP_DIRS.has(entry)) continue\n const full = join(dir, entry)\n let st\n try { st = statSync(full) } catch { continue }\n if (st.isDirectory()) walk(full, out)\n else if (SCAN_EXTS.has(extname(entry).toLowerCase()) || entry.startsWith('.env')) out.push(full)\n }\n return out\n}\n\nfunction scanEnvFile(file: string, lines: string[]): Opportunity[] {\n const found: Opportunity[] = []\n const grouped = new Map<string, { line: number; vars: string[] }>()\n for (let i = 0; i < lines.length; i++) {\n const line = lines[i]!\n const match = line.match(/^([A-Z][A-Z0-9_]+)=/)\n if (!match) continue\n const key = match[1]!\n const vendor = detectVendor(key.toLowerCase())\n if (!vendor) continue\n const bucket = grouped.get(vendor) ?? { line: i + 1, vars: [] }\n bucket.vars.push(key)\n grouped.set(vendor, bucket)\n }\n for (const [vendor, info] of grouped) {\n const title = VENDOR_HINTS[vendor]!\n found.push({\n score: 60 + info.vars.length * 5,\n kind: 'env-var',\n file,\n line: info.line,\n evidence: info.vars.join(', '),\n vendors: [title],\n prompt: `When something happens that needs ${title}, call ${title}'s API with the fields configured via ${info.vars.join(' / ')}.`,\n })\n }\n return found\n}\n\nfunction scanTodos(file: string, lines: string[]): Opportunity[] {\n const found: Opportunity[] = []\n for (let i = 0; i < lines.length; i++) {\n const line = lines[i]!\n // Only inline / block comments, not strings or type literals.\n const match = line.match(/(?:\\/\\/|\\/\\*|#|<!--|\\*)\\s*(?:TODO|FIXME|XXX|HACK)\\b[: ]*(.*)/i)\n if (!match) continue\n const text = match[1]!.replace(/\\*\\/\\s*$/, '').trim()\n if (text.length < 15) continue\n if (!INTEGRATION_KEYWORDS.test(text) && !VENDOR_PATTERN.test(text)) continue\n const vendors = detectVendors(text)\n // Guard against false positives like \"colored square like list\" where the\n // vendor pattern matches a plain English word. If the ONLY signal is a\n // vendor name AND that name is also a common English word AND there's no\n // integration keyword, skip it.\n if (vendors.length > 0 && !INTEGRATION_KEYWORDS.test(text)) {\n const vendorText = vendors.join(' ').toLowerCase()\n const AMBIGUOUS = /^(square|monday|discord|notion|linear|slack|resend|pipeline|hook|paypal)$/\n if (vendors.length === 1 && AMBIGUOUS.test(vendorText.split(' ')[0]!)) continue\n }\n found.push({\n score: 50 + vendors.length * 10 + (INTEGRATION_KEYWORDS.test(text) ? 10 : 0),\n kind: 'todo',\n file,\n line: i + 1,\n evidence: text.slice(0, 160),\n vendors,\n prompt: text.length < 180 && /^when|^on\\b/i.test(text) ? text : promptFromTodo(text, vendors),\n })\n }\n return found\n}\n\nfunction scanWebhookHandlers(file: string, lines: string[], content: string): Opportunity[] {\n const found: Opportunity[] = []\n const isPy = file.endsWith('.py')\n\n // Node/TS: Express / Next / FastAPI (same `app.post(...)` shape) route handlers.\n // We also catch FastAPI's decorator form `@app.post(\"/webhook\")` with the same regex.\n const tsRouteRe = /@?(?:router|app|bp)\\.(?:post|put|patch|get)\\s*\\(\\s*['\"`]([^'\"`]*(?:webhook|hook|callback|notify|event)[^'\"`]*)['\"`]/gi\n // Flask decorator: @app.route(\"/webhook\", methods=[\"POST\"]) — route goes through methods arg\n const pyFlaskRouteRe = /@(?:app|bp)\\.route\\s*\\(\\s*['\"]([^'\"]*(?:webhook|hook|callback|notify|event)[^'\"]*)['\"]/gi\n\n // Try both patterns; dedupe by starting offset so FastAPI decorator catches once.\n const seen = new Set<number>()\n const runRe = (re: RegExp) => {\n let m: RegExpExecArray | null\n while ((m = re.exec(content))) {\n if (seen.has(m.index)) continue\n seen.add(m.index)\n const path = m[1]!\n const upto = content.slice(0, m.index)\n const lineNo = upto.split('\\n').length\n const windowStart = Math.max(0, lineNo - 1)\n const window = lines.slice(windowStart, Math.min(lines.length, windowStart + 20)).join('\\n')\n // Stubby signals:\n // TS: TODO/FIXME, \"not implemented\", `throw new Error`, tiny brace body\n // Py: `raise NotImplementedError`, bare `pass`, body is just a docstring, empty def body\n const stubby =\n /(TODO|FIXME|not\\s+implemented|throw\\s+new\\s+Error|raise\\s+NotImplementedError|raise\\s+Exception\\s*\\(\\s*['\"]not\\s+implemented)/i.test(window) ||\n // TS: fewer than two matched braces means empty function body\n (!isPy && window.replace(/[^{}]/g, '').length < 4) ||\n // Py: body is literally `pass` on its own line after the signature\n (isPy && /\\bdef\\s+\\w+[^)]*\\)[^:]*:\\s*(?:#[^\\n]*\\n\\s*)*pass\\s*(?:\\n|$)/.test(window))\n if (!stubby) continue\n const vendors = detectVendors(path + ' ' + window)\n found.push({\n score: 70 + vendors.length * 10,\n kind: 'webhook-handler',\n file,\n line: lineNo,\n evidence: `${path} — route body is empty / TODO / not-implemented`,\n vendors,\n prompt: vendors.length\n ? `When a ${vendors[0]} webhook hits ${path}, handle the payload and ${inferAction(vendors)}.`\n : `When an incoming webhook hits ${path}, verify the signature, parse the payload and forward the result to the configured target.`,\n })\n }\n }\n runRe(tsRouteRe)\n if (isPy) runRe(pyFlaskRouteRe)\n return found\n}\n\n/** SDK import specifiers that are frameworks (not integrations) — skip entirely. */\nconst FRAMEWORK_IMPORT_HINTS = /\\/(hydrogen|remix-oxygen|next|nuxt|express|fastify|koa|hono|svelte|solid|qwik|astro|react|vue|polaris|themes|plugin|cli)(\\/|$)/i\n\nfunction scanVendorImports(file: string, lines: string[]): Opportunity[] {\n const found: Opportunity[] = []\n // Skip declaration files and generated code — these are types, not business logic.\n if (file.endsWith('.d.ts') || file.includes('.generated.') || file.includes('/generated/')) return found\n for (let i = 0; i < lines.length; i++) {\n const line = lines[i]!\n const match = line.match(/(?:from\\s+|require\\(\\s*)['\"]([^'\"\\n]+)['\"]/)\n if (!match) continue\n const spec = match[1]!\n // Only real npm packages: skip relative imports (./x, ../x) and node builtins (node:x).\n if (spec.startsWith('.') || spec.startsWith('/') || spec.startsWith('node:')) continue\n // Skip framework/toolkit imports that happen to contain a vendor name (e.g. @shopify/hydrogen is a framework not Shopify as an integration target).\n if (FRAMEWORK_IMPORT_HINTS.test(spec)) continue\n const vendor = detectVendor(spec.replace(/^@/, '').toLowerCase())\n if (!vendor) continue\n // Count how many times the vendor name shows up in the file to tell \"imported-and-used\" from \"imported-but-stubbed\".\n const vendorUses = (readSafe(file).match(new RegExp(`\\\\b${vendor}`, 'gi')) || []).length\n if (vendorUses > 6) continue // actively used; probably not an opportunity\n const title = VENDOR_HINTS[vendor]!\n found.push({\n score: 40 + (vendorUses < 3 ? 15 : 0),\n kind: 'vendor-sdk-import',\n file,\n line: i + 1,\n evidence: `imports '${spec}' but only uses \"${vendor}\" ${vendorUses}× in this file`,\n vendors: [title],\n prompt: `Write a ${title} integration — the ${title} SDK is already a dependency but there's no handler wired up.`,\n })\n }\n return found\n}\n\nfunction readSafe(file: string): string {\n try { return readFileSync(file, 'utf8') } catch { return '' }\n}\n\nfunction scanVendorImportsFromMemory(file: string, lines: string[], contentByPath: Map<string, string>): Opportunity[] {\n const found: Opportunity[] = []\n if (file.endsWith('.d.ts') || file.includes('.generated.') || file.includes('/generated/')) return found\n const fileContent = contentByPath.get(file) ?? ''\n for (let i = 0; i < lines.length; i++) {\n const line = lines[i]!\n const match = line.match(/(?:from\\s+|require\\(\\s*)['\"]([^'\"\\n]+)['\"]/)\n if (!match) continue\n const spec = match[1]!\n if (spec.startsWith('.') || spec.startsWith('/') || spec.startsWith('node:')) continue\n if (FRAMEWORK_IMPORT_HINTS.test(spec)) continue\n const vendor = detectVendor(spec.replace(/^@/, '').toLowerCase())\n if (!vendor) continue\n const vendorUses = (fileContent.match(new RegExp(`\\\\b${vendor}`, 'gi')) || []).length\n if (vendorUses > 6) continue\n const title = VENDOR_HINTS[vendor]!\n found.push({\n score: 40 + (vendorUses < 3 ? 15 : 0),\n kind: 'vendor-sdk-import',\n file,\n line: i + 1,\n evidence: `imports '${spec}' but only uses \"${vendor}\" ${vendorUses}× in this file`,\n vendors: [title],\n prompt: `Write a ${title} integration — the ${title} SDK is already a dependency but there's no handler wired up.`,\n })\n }\n return found\n}\n\nfunction detectVendor(text: string): string | null {\n for (const key of Object.keys(VENDOR_HINTS)) if (text.includes(key)) return key\n return null\n}\n\nfunction detectVendors(text: string): string[] {\n const set = new Set<string>()\n const lower = text.toLowerCase()\n for (const key of Object.keys(VENDOR_HINTS)) if (lower.includes(key)) set.add(VENDOR_HINTS[key]!)\n return [...set]\n}\n\nfunction promptFromTodo(text: string, vendors: string[]): string {\n if (vendors.length >= 2) return `When something happens in ${vendors[0]}, do the matching thing in ${vendors[1]}. (From TODO: \"${text.slice(0, 100)}\")`\n if (vendors.length === 1) return `Build the ${vendors[0]} integration this TODO describes: \"${text.slice(0, 160)}\"`\n return `Build the integration this TODO describes: \"${text.slice(0, 180)}\"`\n}\n\nfunction inferAction(vendors: string[]): string {\n if (vendors.length >= 2) return `forward the result to ${vendors[1]}`\n return 'persist the result and reply 200'\n}\n\nfunction rankAndDedupe(opportunities: Opportunity[]): Opportunity[] {\n // Collapse duplicates (same file + same first vendor + same kind) to the highest-scoring.\n const map = new Map<string, Opportunity>()\n for (const op of opportunities) {\n const key = `${op.file}::${op.kind}::${op.vendors.join(',')}`\n const existing = map.get(key)\n if (!existing || op.score > existing.score) map.set(key, op)\n }\n // Second pass: cap vendor-sdk-import to 3 per (vendor, kind) so one framework/template\n // repo can't flood the report with 90 Shopify entries. Keep the highest-scoring 3.\n const perVendorKind = new Map<string, number>()\n const all = [...map.values()].sort((a, b) => b.score - a.score)\n const kept: Opportunity[] = []\n for (const op of all) {\n if (op.kind !== 'vendor-sdk-import') { kept.push(op); continue }\n const key = `${op.vendors[0] ?? '?'}::${op.kind}`\n const seen = perVendorKind.get(key) ?? 0\n if (seen >= 3) continue\n perVendorKind.set(key, seen + 1)\n kept.push(op)\n }\n return kept\n}\n\nexport function formatReport(opportunities: Opportunity[], root: string, limit = DEFAULT_REPORT_LIMIT): string {\n if (!opportunities.length) return `No integration opportunities found under ${root}.`\n const total = opportunities.length\n const shown = opportunities.slice(0, limit)\n const header = `patchbay scan found ${total} integration opportunit${total === 1 ? 'y' : 'ies'} under ${root}` + (total > shown.length ? ` (showing top ${shown.length}; pass --all to see them all)` : '') + '\\n'\n const body = shown\n .map((op, i) => `#${i + 1} score ${op.score} ${op.kind} ${op.file}:${op.line}\\n ${op.evidence}\\n build: patchbay build \"${op.prompt}\"`)\n .join('\\n\\n')\n const footer = `\\n\\nRun one directly:\\n patchbay build \"${opportunities[0]!.prompt}\"\\nOr let patchbay build the top N for you:\\n patchbay scan ${root} --build-top=1`\n return header + '\\n' + body + footer\n}\n"],"mappings":";AAAA,SAAS,cAAc,aAAa,gBAAgB;AACpD,SAAS,MAAM,UAAU,SAAS,gBAAgB;AAsBlD,IAAM,YAAY,oBAAI,IAAI,CAAC,gBAAgB,QAAQ,QAAQ,SAAS,OAAO,SAAS,UAAU,WAAW,UAAU,CAAC;AACpH,IAAM,YAAY,oBAAI,IAAI,CAAC,OAAO,QAAQ,OAAO,QAAQ,QAAQ,QAAQ,OAAO,OAAO,OAAO,QAAQ,UAAU,CAAC;AACjH,IAAM,iBAAiB;AAGvB,IAAM,uBAAuB;AAE7B,IAAM,uBAAuB;AAG7B,IAAM,eAAuC;AAAA,EAC3C,QAAQ;AAAA,EAAU,SAAS;AAAA,EAAW,WAAW;AAAA,EAAa,UAAU;AAAA,EAAY,WAAW;AAAA,EAC/F,SAAS;AAAA,EAAW,YAAY;AAAA,EAAc,OAAO;AAAA,EAAS,SAAS;AAAA,EAAW,QAAQ;AAAA,EAC1F,UAAU;AAAA,EAAY,OAAO;AAAA,EAAS,MAAM;AAAA,EAAQ,QAAQ;AAAA,EAAU,QAAQ;AAAA,EAAU,QAAQ;AAAA,EAChG,SAAS;AAAA,EAAW,UAAU;AAAA,EAAY,QAAQ;AAAA,EAAU,UAAU;AAAA,EAAY,OAAO;AAAA,EACzF,QAAQ;AAAA,EAAU,UAAU;AAAA,EAAY,SAAS;AAAA,EAAW,UAAU;AAAA,EAAY,SAAS;AAAA,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