quirl-cli 0.1.0 → 0.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/dist/quirl.mjs +5 -4
  2. package/package.json +1 -1
package/dist/quirl.mjs CHANGED
@@ -177,8 +177,9 @@ if(!Array.isArray(r))throw Error(`ajv implementation error`);let a=n.name(`valid
177
177
  - Tag items only from their tag sets (listed under Tags in the briefing): capabilities by who they're for and their kind, features by kind of change, tasks by kind of work. Product areas aren't tags; group capabilities under a parent capability instead.
178
178
  - Flags are messages people send about a section (a capability, feature, task, doc or term). Approved ones are listed first in the briefing: act on them, then mark each done with resolve_flag. Only admins approve or remove flags (decide_flag); list_flags shows them.
179
179
  - Home shows everyone the product as a map built from Quirl: each top-level capability with its icon, arrows from what it relies on, and its parts listed under it. Give features and capabilities an icon (request_feature's icon, set_feature_icon, set_capability_icon), and propose what each capability relies on and which capability it's part of (propose_capability_details) once it's approved.
180
+ - Resources (databases, hosted services, external APIs) come from quirl sync. If the project runs on something sync can't see from the code, add it with add_resource, without secret values.
180
181
  - If the project has no capabilities yet, offer to read the codebase and draft them with propose_capability.
181
- - If the project briefing isn't already in your context, call quirl_context first.`}),r={p_project:e.project},i=()=>({tool:n.server.getClientVersion()?.name??`mcp`,model:process.env.QUIRL_AGENT_MODEL}),a=e=>async t=>{try{return Pb(await e(t))}catch(e){if(e instanceof Hr)return{...Pb(e.message),isError:!0};throw e}};n.registerTool(`quirl_context`,{title:`Project briefing`,description:`The project briefing: always-loaded docs in full, glossary, capabilities, your open tasks and the list of other docs. Usually already loaded at session start.`,inputSchema:{}},a(async()=>Nb(await t.context(e.project)))),n.registerTool(`search_docs`,{title:`Search docs`,description:`Full-text search across the project's docs (README, ADRs, guides, runbooks). Returns matching sections with their content. Use for anything not in the briefing.`,inputSchema:{query:V().describe(`Words to search for, e.g. 'refund approval limits'`),limit:H().int().min(1).max(20).optional()}},a(({query:e,limit:n})=>t.call(`search_docs`,{...r,p_query:e,p_limit:n??6}))),n.registerTool(`read_doc`,{title:`Read a doc`,description:`Read one doc in full, by id, title or source path.`,inputSchema:{doc:V().describe(`Doc id, title or path, e.g. 'docs/adr/004-queues.md'`)}},a(({doc:e})=>t.call(`read_doc`,{...r,p_doc:e}))),n.registerTool(`lookup`,{title:`Look up a term, capability or contract`,description:`Find glossary terms, capabilities, features and API/table contracts matching a name. Use it to check what a word means here, or the request/response shape of an endpoint or table.`,inputSchema:{query:V().describe(`A term, capability, endpoint or table name, e.g. 'Visit' or 'POST /login'`)}},a(({query:e})=>t.call(`lookup`,{...r,p_query:e})));let o=(e,t,r,i)=>{n.registerTool(e,r,i),n.registerTool(t,{...r,description:`Old name for ${e}; use ${e}. ${r.description}`},i)};o(`list_tasks`,`list_cards`,{title:`List tasks`,description:`List tasks on the board. Defaults to your own tasks that aren't done.`,inputSchema:{onlyMine:Qp().optional(),includeDone:Qp().optional()}},a(({onlyMine:e,includeDone:n})=>t.call(`list_cards`,{...r,p_only_mine:e??!0,p_include_done:n??!1})));let s=`Markdown: short paragraphs, and lists for steps or parts, not one long block.`,c=`Kind of work: e.g. Frontend, Backend, Database, Design, DevOps, Testing, Docs, Research. Only tags from the task set are accepted (see tagSets in quirl_context); propose a new value with propose_term (kind tag, tagSet task_work).`,l=V().describe(`Task number, e.g. 'K-104' or '104'`);return o(`get_task`,`get_card`,{title:`Get a task`,description:`A task with its feature, docs, dependencies and evidence.`,inputSchema:{task:l.optional(),card:l.optional()}},a(({task:e,card:n})=>t.call(`get_card`,{...r,p_card:e??n}))),o(`create_task`,`create_card`,{title:`Create a task`,description:`Add a task to the board (status: todo). Use it for work you discover that should be tracked. Put it under the feature it serves.`,inputSchema:{title:V(),description:V().optional().describe(`What to do and why. ${s}`),type:_m([`feature_work`,`bug`,`chore`,`research`]).optional(),feature:V().optional().describe(`Feature name or id (e.g. F-4) this task belongs to`),tags:U(V()).optional().describe(c)}},a(async({title:e,description:n,type:a,feature:o,tags:s})=>{let c=await t.call(`create_card`,{...r,p_title:e,p_description:n??``,p_type:a??`feature_work`,p_feature:o??null,p_agent:i()});return s?.length&&await t.call(`update_card`,{...r,p_card:c,p_patch:{tags:s},p_agent:i()}),c})),o(`update_task`,`update_card`,{title:`Update a task`,description:`Move a task, mark it blocked (with a reason) or unblocked, put it under a feature, set its tags, rewrite its title or description, and attach evidence: a branch, commit or pull request. Repos are referenced by name.`,inputSchema:{task:l.optional(),card:l.optional(),status:_m([`backlog`,`todo`,`in_progress`,`review`,`done`]).optional(),feature:V().optional().describe(`Feature name or id (e.g. F-4) to put the task under; an empty string takes it off its feature`),title:V().optional(),description:V().optional().describe(`Replaces the description. ${s}`),tags:U(V()).optional().describe(`${c} Replaces the current tags.`),blocked:Qp().optional(),blockedReason:V().optional(),addBranch:W({repo:V(),name:V()}).optional(),addCommit:W({repo:V(),sha:V(),message:V().optional()}).optional(),addPullRequest:W({repo:V(),number:H().int(),url:V(),state:_m([`open`,`merged`,`closed`]).optional()}).optional()}},a(({task:e,card:n,...a})=>t.call(`update_card`,{...r,p_card:e??n,p_patch:a,p_agent:i()}))),n.registerTool(`propose_term`,{title:`Propose a glossary term`,description:`Suggest a new glossary term. It shows up for approval; it isn't used until a person approves it.`,inputSchema:{term:V(),plain:V().describe(`What it means, for someone non-technical`),technical:V().describe(`What it means in the code`),kind:_m([`concept`,`tag`,`name`]).optional(),tagSet:V().optional().describe(`Required for kind 'tag': the set the value belongs to, e.g. feature_change, task_work, capability_audience, capability_kind (see tagSets in quirl_context)`),reason:V().optional()}},a(({term:e,plain:n,technical:a,kind:o,tagSet:s,reason:c})=>t.call(`propose_term`,{...r,p_term:e,p_plain:n,p_technical:a,p_kind:o??`concept`,p_tag_set:s??null,p_reason:c??null,p_agent:i()}))),n.registerTool(`propose_term_retire`,{title:`Retire a glossary term`,description:`Propose retiring a glossary term or tag that's no longer used or was a mistake. With replaceWith, the term stays as one not to say (agents are told the replacement); without it, it's removed. Either way it comes off every capability, task and feature that used it. A person approves it. Built-in tag values can't be retired.`,inputSchema:{term:V().describe(`The term or tag to retire`),replaceWith:V().optional().describe(`An approved term to say instead, if there is one`),reason:V().optional()}},a(({term:e,replaceWith:n,reason:a})=>t.call(`propose_term_retire`,{...r,p_term:e,p_replace_with:n??null,p_reason:a??null,p_agent:i()}))),n.registerTool(`list_flags`,{title:`List flags`,description:`Flags are messages people send about a section of the project: a capability, feature, task, doc or glossary term. Lists open (waiting for an admin) and approved (to act on) flags, or only those with the given status.`,inputSchema:{status:_m([`open`,`approved`,`removed`,`done`]).optional()}},a(({status:e})=>t.call(`list_flags`,{...r,p_status:e??null}))),n.registerTool(`decide_flag`,{title:`Approve or remove a flag`,description:`Admins only. Approve a flag so agents act on it at the start of their sessions, or remove it. An approved flag can still be removed. Only do this when the person you work for asks you to.`,inputSchema:{flag:V().describe(`The flag's id, from the briefing or list_flags`),decision:_m([`approve`,`remove`])}},a(({flag:e,decision:n})=>t.call(`decide_flag`,{...r,p_flag:e,p_approve:n===`approve`,p_agent:i()}))),n.registerTool(`resolve_flag`,{title:`Mark a flag done`,description:`Mark an approved flag done once you've handled it, so it leaves the briefing. Say briefly what you did.`,inputSchema:{flag:V().describe(`The flag's id, from the briefing or list_flags`),note:V().optional().describe(`What was done, e.g. 'Updated C-12 to mention SMS'`)}},a(({flag:e,note:n})=>t.call(`resolve_flag`,{...r,p_flag:e,p_note:n??null,p_agent:i()}))),n.registerTool(`set_capability_icon`,{title:`Set a capability's icon`,description:`Give a capability an icon that fits what it does; it's shown on the capability's card. Use the same icon a related feature has when one fits both.`,inputSchema:{capability:V().describe(`Capability name or id (e.g. C-12)`),icon:_m(jb)}},a(({capability:e,icon:n})=>t.call(`set_capability_icon`,{...r,p_capability:e,p_icon:n,p_agent:i()}))),n.registerTool(`list_features`,{title:`List features`,description:`List the project's features with their status, the capability each changes (or createsCapability when it has none), and task counts. Shipped ones are left out unless includeShipped. Check here before requesting a feature.`,inputSchema:{includeShipped:Qp().optional()}},a(({includeShipped:e})=>t.call(`list_features`,{...r,p_include_shipped:e??!1}))),n.registerTool(`get_feature`,{title:`Get a feature`,description:`A feature with its description, status, the capability it changes (and what that capability does) and its tasks.`,inputSchema:{feature:V().describe(`Feature name or id (e.g. F-4)`)}},a(({feature:e})=>t.call(`get_feature`,{...r,p_feature:e}))),n.registerTool(`request_feature`,{title:`Request a feature`,description:`Request a feature: a change to the product that stakeholders follow on the Features page, usually made of several tasks. Check list_features first so you don't request one twice. It shows as requested straight away and a person accepts or declines it. Put tasks under it with create_task or update_task.`,inputSchema:{name:V().describe(`Short name, e.g. 'Repeat appointments'`),description:V().describe(`What changes for the user, in plain words. Markdown: short paragraphs, and lists for parts`),capability:V().optional().describe(`Capability name or id (e.g. C-12) it changes. Leave it out when the feature creates a new capability`),tags:U(V()).optional().describe(`Kind of change: e.g. New, Improvement, Visual, Fix, Performance, Security, Removal, Internal (the feature_change set in quirl_context)`),reason:V().optional().describe(`Why it's worth doing`),icon:_m(jb).optional().describe(`An icon that fits the feature, shown on its card`)}},a(async({name:e,description:n,capability:a,tags:o,reason:s,icon:c})=>{let l=await t.call(`request_feature`,{...r,p_name:e,p_description:n,p_capability:a??null,p_tags:o??null,p_reason:s??null,p_agent:i()});return c&&l===`requested`&&await t.call(`set_feature_icon`,{...r,p_feature:e,p_icon:c,p_agent:i()}),l})),n.registerTool(`set_feature_icon`,{title:`Set a feature's icon`,description:`Give a feature an icon that fits what it does; it's shown on the feature's card. list_features shows which features have none.`,inputSchema:{feature:V().describe(`Feature name or id (e.g. F-4)`),icon:_m(jb)}},a(({feature:e,icon:n})=>t.call(`set_feature_icon`,{...r,p_feature:e,p_icon:n,p_agent:i()}))),n.registerTool(`tag_feature`,{title:`Tag a feature`,description:`Set a feature's kind-of-change tags (replaces the current ones). Only values from the feature_change tag set are accepted.`,inputSchema:{feature:V().describe(`Feature name or id (e.g. F-4)`),tags:U(V()).describe(`Kind of change: e.g. New, Improvement, Visual, Fix, Performance, Security, Removal, Internal`)}},a(({feature:e,tags:n})=>t.call(`tag_feature`,{...r,p_feature:e,p_tags:n,p_agent:i()}))),n.registerTool(`propose_capability`,{title:`Propose a capability`,description:"Draft a capability: one thing the product does today, described for a non-technical reader. Use it when the project has none yet (for example right after `quirl init`), when you find one that's missing, or when a feature that creates a new capability ships (pass it in features). Never for something not built yet: request a feature instead. A person approves it before it shows up.",inputSchema:{name:V().describe(`Short name, e.g. 'Online booking'`),whatItDoes:V().describe(`One or two plain sentences, no jargon`),technical:V().optional().describe(`Where it lives in the code and how it works. Markdown: short paragraphs, and lists for parts, not one long block`),features:U(V()).optional().describe(`Feature names or ids (e.g. F-4) that create or change this capability; they're linked to it once it's approved`),reason:V().optional()}},a(({name:e,whatItDoes:n,technical:a,features:o,reason:s})=>t.call(`propose_capability`,{...r,p_name:e,p_what_it_does:n,p_technical:a??``,p_features:o??null,p_reason:s??null,p_agent:i()}))),n.registerTool(`propose_capability_archive`,{title:`Propose archiving a capability`,description:`Suggest retiring a capability that no longer describes what the product does, or that was drafted for something not built yet. Unshipped features linked to it will create a new capability when they ship. A person approves it.`,inputSchema:{capability:V().describe(`Capability name or id (e.g. C-12)`),reason:V().describe(`Why it should go`)}},a(({capability:e,reason:n})=>t.call(`propose_capability_archive`,{...r,p_capability:e,p_reason:n,p_agent:i()}))),n.registerTool(`propose_capability_update`,{title:`Propose a capability correction`,description:`Suggest a corrected description for a capability when the code no longer matches it. A person approves it.`,inputSchema:{capability:V().describe(`Capability name or id (e.g. C-12)`),field:_m([`what_it_does`,`technical_description`]),after:V().describe(`The corrected text. Markdown: short paragraphs, and lists for parts, not one long block`),reason:V().optional()}},a(({capability:e,field:n,after:a,reason:o})=>t.call(`propose_capability_update`,{...r,p_capability:e,p_field:n,p_after:a,p_reason:o??null,p_agent:i()}))),n.registerTool(`propose_capability_details`,{title:`Propose how a capability works and its connections`,description:`Suggest a capability's 'How it works' steps, its tags (glossary terms of kind 'tag'), the capability it's part of, and its connections: capabilities it relies on, repos, resources it runs on, glossary terms and docs. Each part you pass replaces that part when a person approves it; parts you leave out are kept. Names are matched to existing, approved items. What it relies on draws the arrows on the Home map, so link the steps a user goes through (e.g. invoicing relies on booking).`,inputSchema:{capability:V().describe(`Capability name or id (e.g. C-12)`),howItWorks:U(V()).optional().describe(`3 to 5 plain-language steps, as the user experiences it`),reliesOn:U(W({capability:V().describe(`Capability name or id (e.g. C-12)`),label:V().describe(`How it relies on it, read before the name, e.g. 'extends'`)})).optional(),parent:V().optional().describe(`The capability this one is part of (name or id, e.g. C-2), or 'none' to make it top-level. Parts are listed under their parent instead of on their own`),repos:U(V()).optional().describe(`Repo names`),resources:U(V()).optional().describe(`Resource names it runs on`),terms:U(V()).optional().describe(`Glossary terms`),docs:U(V()).optional().describe(`Doc titles, or <repo>/<path> (e.g. quirl/AGENTS.md) when titles repeat`),tags:U(V()).optional().describe(`Who it's for (Customer, Admin, Developer, Agent) and its kind (Interface, Integration, Data, Automation, Infrastructure, Access and security, AI): the capability tag sets in quirl_context`),reason:V().optional()}},a(({capability:e,howItWorks:n,reliesOn:a,parent:o,repos:s,resources:c,terms:l,docs:u,tags:d,reason:f})=>t.call(`propose_capability_details`,{...r,p_capability:e,p_how_it_works:n??null,p_relies_on:a??null,p_parent:o??null,p_repos:s??null,p_resources:c??null,p_terms:l??null,p_docs:u??null,p_tags:d??null,p_reason:f??null,p_agent:i()}))),n}async function Ib(e){await Fb(e).connect(new Ab)}const Lb=`0.1.0`,Rb=process.env.QUIRL_SERVER===`local`?{apiUrl:`http://127.0.0.1:54321`,publishableKey:`sb_publishable_ACJWlzQHlZjBrEguHvfOxg_3BJgxAaH`,appUrl:`http://localhost:5173`}:{apiUrl:`https://dugevhzlzrdtasuibdzr.supabase.co`,publishableKey:`sb_publishable_45P7GyyZoJsN0AO3wfmqNA_CXbx1iCW`,appUrl:`https://app.quirl.io`};function zb(){return{apiUrl:process.env.QUIRL_API_URL??Rb.apiUrl,publishableKey:process.env.QUIRL_PUBLISHABLE_KEY??Rb.publishableKey,appUrl:process.env.QUIRL_APP_URL??Rb.appUrl}}const Bb=()=>x(process.env.XDG_CONFIG_HOME??x(h(),`.config`),`quirl`),Vb=()=>x(Bb(),`credentials.json`);async function Hb(){try{return JSON.parse(await u(Vb(),`utf8`))}catch{return{}}}async function Ub(){return process.env.QUIRL_KEY?{apiUrl:zb().apiUrl,key:process.env.QUIRL_KEY,email:``}:(await Hb())[zb().apiUrl]??null}async function Wb(e){let t=await Hb();t[e.apiUrl]=e,await l(Bb(),{recursive:!0,mode:448}),await m(Vb(),`${JSON.stringify(t,null,` `)}\n`,{mode:384}),await s(Vb(),384)}async function Gb(){let e=await Hb();delete e[zb().apiUrl],Object.keys(e).length?await m(Vb(),`${JSON.stringify(e,null,` `)}\n`,{mode:384}):await f(Vb(),{force:!0})}async function Kb(){let e=zb();return{apiUrl:e.apiUrl,publishableKey:e.publishableKey,key:(await Ub())?.key??``}}function qb(e=process.cwd()){try{return a(`git`,[`rev-parse`,`--show-toplevel`],{cwd:e,stdio:[`ignore`,`pipe`,`ignore`]}).toString().trim()}catch{return e}}const Jb=e=>x(e,`.quirl`,`project.json`);async function Yb(e=process.cwd()){let t=e;for(;;)try{return{root:t,link:JSON.parse(await u(Jb(t),`utf8`))}}catch{let e=y(t);if(e===t)return null;t=e}}async function Xb(e,t){await l(x(e,`.quirl`),{recursive:!0}),await m(Jb(e),`${JSON.stringify(t,null,` `)}\n`)}async function Zb({hook:e=!1}={}){let t=await Yb();if(!t){if(e)return;throw Error("This folder isn't linked to a Quirl project. Run `quirl init`.")}try{let n=await new Ur(await Kb()).context(t.link.projectId);process.stdout.write(`${Nb(n,e?9500:void 0)}\n`)}catch(n){if(!e)throw n;process.stdout.write(`Quirl project "${t.link.name}": couldn't load the briefing (${n.message}). The quirl MCP tools may still work.\n`)}}const Qb=/* @__PURE__ */ new Set([`.git`,`node_modules`,`dist`,`build`,`.next`,`vendor`,`.venv`,`venv`,`__pycache__`,`coverage`,`.turbo`,`.svelte-kit`,`.nuxt`,`.output`,`.cache`,`.vercel`,`.pnpm-store`,`fixtures`,`test-fixtures`,`__fixtures__`,`testdata`]),$b=2e5;async function ex(e){let t=[],n=await tx(e,t),r=new Map(n.map(e=>[e.path,e]));return{root:e,files:n,warnings:t,file:e=>r.get(e),async readText(e,n=1048576){if(e.size>n)return t.push(`${e.path}: skipped, ${cx(e.size)} is over the ${cx(n)} limit`),null;try{return await u(e.absolutePath,`utf8`)}catch(n){return t.push(`${e.path}: could not be read (${ox(n)})`),null}}}}async function tx(e,t){let n=[],r=[``];for(;r.length>0;){let i=r.pop(),a;try{a=await d(_.join(e,i),{withFileTypes:!0})}catch(e){t.push(`${i||`.`}: folder could not be read (${ox(e)})`);continue}for(let o of a){let a=i?`${i}/${o.name}`:o.name;if(o.isSymbolicLink())continue;if(o.isDirectory()){!Qb.has(o.name)&&!T(_.join(e,a,`.git`))&&r.push(a);continue}if(!o.isFile())continue;if(n.length>=$b)return t.push(`Stopped after ${$b} files; the rest of the tree was not scanned`),nx(n);let s=_.join(e,a);try{let e=await c(s);n.push({path:a,absolutePath:s,size:e.size})}catch(e){t.push(`${a}: could not be read (${ox(e)})`)}}}return nx(n)}function nx(e){return e.sort((e,t)=>e.path<t.path?-1:+(e.path>t.path))}function rx(e){let t=e.lastIndexOf(`/`);return t===-1?e:e.slice(t+1)}function ix(e){let t=e.lastIndexOf(`/`);return t===-1?``:e.slice(0,t)}function ax(e,t){return e?`${e}/${t}`:t}function ox(e){return e instanceof Error?e.message:String(e)}function Q(e){return typeof e==`object`&&!!e&&!Array.isArray(e)}function sx(e){return typeof e==`string`?e:void 0}function cx(e){return e>=1048576?`${(e/1048576).toFixed(1)} MB`:`${Math.ceil(e/1024)} KB`}async function lx(e,t=3){let n=[],r=async(e,i)=>{if(T(_.join(e,`.git`))&&n.push(e),i>=t)return;let a;try{a=await d(e,{withFileTypes:!0})}catch{return}for(let t of a)!t.isDirectory()||t.name.startsWith(`.`)||Qb.has(t.name)||await r(_.join(e,t.name),i+1)};return await r(_.resolve(e),0),n.sort((e,t)=>e.localeCompare(t))}const ux=process.stdout.isTTY&&!process.env.NO_COLOR,dx=e=>t=>ux?`\x1b[${e}m${t}\x1b[0m`:t,fx=dx(1),px=dx(2),mx=dx(32),hx=dx(31),gx=dx(36),_x=e=>console.log(`${mx(`✓`)} ${e}`),vx=e=>console.log(` ${e}`),yx=(e,t)=>console.log(`\n${e} ${t}`),bx=e=>console.log(` ${e}`);function xx(e){if(!ux)return bx(px(e)),{stop:()=>{}};let t=0,n=setInterval(()=>{process.stdout.write(`\r ${gx(`⠋⠙⠹⠸⠼⠴⠦⠧⠇⠏`[t++%10]??``)} ${px(e)}`)},80);return{stop:()=>{clearInterval(n),process.stdout.write(`\r\x1B[2K`)}}}var Sx=class extends Error{};async function Cx(e,t=``){if(!process.stdin.isTTY)return t;let n=E({input:process.stdin,output:process.stdout});try{return(await n.question(e)).trim()||t}finally{n.close()}}async function wx(e,t){let n=await Cx(`${e} ${px(t?`[Y/n]`:`[y/N]`)} `,t?`y`:`n`);return/^y/i.test(n)}function Tx(e){if(process.env.QUIRL_NO_BROWSER)return;let t=process.platform===`darwin`?`open`:process.platform===`win32`?`cmd`:`xdg-open`,n=process.platform===`win32`?[`/c`,`start`,``,e]:[e];try{o(t,n,{stdio:`ignore`,detached:!0}).on(`error`,()=>{}).unref()}catch{}}const Ex=`<!-- quirl:start -->`,Dx=`<!-- quirl:end -->`,Ox=`# quirl: keep the project in sync`;function kx(){try{let e=a(process.platform===`win32`?`where`:`which`,[`quirl`],{stdio:[`ignore`,`pipe`,`ignore`]}).toString();if(!/[\\/]_npx[\\/]/.test(e))return{command:`quirl`,args:[],shell:`quirl`,portable:!0}}catch{}return{command:`npx`,args:[`-y`,`quirl-cli`],shell:`npx -y quirl-cli`,portable:!0}}const Ax=[`QUIRL_SERVER`,`QUIRL_API_URL`,`QUIRL_PUBLISHABLE_KEY`,`QUIRL_APP_URL`];function jx(){return Object.fromEntries(Ax.flatMap(e=>process.env[e]?[[e,process.env[e]]]:[]))}function Mx(){return`${Object.entries(jx()).map(([e,t])=>`${e}="${t}" `).join(``)}${kx().shell}`}async function Nx(e){try{return JSON.parse(await u(e,`utf8`))}catch(t){if(t.code===`ENOENT`)return{};throw Error(`${e} isn't valid JSON; fix it and run \`quirl init\` again.`)}}const Px=async(e,t)=>{await l(y(e),{recursive:!0}),await m(e,`${JSON.stringify(t,null,2)}\n`)};async function Fx(e){let t=x(e,`.mcp.json`),n=await Nx(t),r=kx();n.mcpServers={...n.mcpServers,quirl:{command:r.command,args:[...r.args,`mcp`],...Object.keys(jx()).length?{env:jx()}:{}}},await Px(t,n)}async function Ix(e){let t=x(e,`.claude`,`settings.json`),n=await Nx(t),r=n.hooks??{},i=`${Mx()} context --hook`;r.SessionStart=[...(r.SessionStart??[]).map(e=>({...e,hooks:e.hooks.filter(e=>!/\bcontext --hook$/.test(e.command))})).filter(e=>e.hooks.length),{hooks:[{type:`command`,command:i,timeout:15}]}],n.hooks=r,await Px(t,n)}async function Lx(e,t,n=[]){let r=x(e,`CLAUDE.md`),i=``;try{i=await u(r,`utf8`)}catch{}let a=`${Ex}
182
+ - If the project briefing isn't already in your context, call quirl_context first.`}),r={p_project:e.project},i=()=>({tool:n.server.getClientVersion()?.name??`mcp`,model:process.env.QUIRL_AGENT_MODEL}),a=e=>async t=>{try{return Pb(await e(t))}catch(e){if(e instanceof Hr)return{...Pb(e.message),isError:!0};throw e}};n.registerTool(`quirl_context`,{title:`Project briefing`,description:`The project briefing: always-loaded docs in full, glossary, capabilities, your open tasks and the list of other docs. Usually already loaded at session start.`,inputSchema:{}},a(async()=>Nb(await t.context(e.project)))),n.registerTool(`search_docs`,{title:`Search docs`,description:`Full-text search across the project's docs (README, ADRs, guides, runbooks). Returns matching sections with their content. Use for anything not in the briefing.`,inputSchema:{query:V().describe(`Words to search for, e.g. 'refund approval limits'`),limit:H().int().min(1).max(20).optional()}},a(({query:e,limit:n})=>t.call(`search_docs`,{...r,p_query:e,p_limit:n??6}))),n.registerTool(`read_doc`,{title:`Read a doc`,description:`Read one doc in full, by id, title or source path.`,inputSchema:{doc:V().describe(`Doc id, title or path, e.g. 'docs/adr/004-queues.md'`)}},a(({doc:e})=>t.call(`read_doc`,{...r,p_doc:e}))),n.registerTool(`lookup`,{title:`Look up a term, capability or contract`,description:`Find glossary terms, capabilities, features and API/table contracts matching a name. Use it to check what a word means here, or the request/response shape of an endpoint or table.`,inputSchema:{query:V().describe(`A term, capability, endpoint or table name, e.g. 'Visit' or 'POST /login'`)}},a(({query:e})=>t.call(`lookup`,{...r,p_query:e})));let o=(e,t,r,i)=>{n.registerTool(e,r,i),n.registerTool(t,{...r,description:`Old name for ${e}; use ${e}. ${r.description}`},i)};o(`list_tasks`,`list_cards`,{title:`List tasks`,description:`List tasks on the board. Defaults to your own tasks that aren't done.`,inputSchema:{onlyMine:Qp().optional(),includeDone:Qp().optional()}},a(({onlyMine:e,includeDone:n})=>t.call(`list_cards`,{...r,p_only_mine:e??!0,p_include_done:n??!1})));let s=`Markdown: short paragraphs, and lists for steps or parts, not one long block.`,c=`Kind of work: e.g. Frontend, Backend, Database, Design, DevOps, Testing, Docs, Research. Only tags from the task set are accepted (see tagSets in quirl_context); propose a new value with propose_term (kind tag, tagSet task_work).`,l=V().describe(`Task number, e.g. 'K-104' or '104'`);return o(`get_task`,`get_card`,{title:`Get a task`,description:`A task with its feature, docs, dependencies and evidence.`,inputSchema:{task:l.optional(),card:l.optional()}},a(({task:e,card:n})=>t.call(`get_card`,{...r,p_card:e??n}))),o(`create_task`,`create_card`,{title:`Create a task`,description:`Add a task to the board (status: todo). Use it for work you discover that should be tracked. Put it under the feature it serves.`,inputSchema:{title:V(),description:V().optional().describe(`What to do and why. ${s}`),type:_m([`feature_work`,`bug`,`chore`,`research`]).optional(),feature:V().optional().describe(`Feature name or id (e.g. F-4) this task belongs to`),tags:U(V()).optional().describe(c)}},a(async({title:e,description:n,type:a,feature:o,tags:s})=>{let c=await t.call(`create_card`,{...r,p_title:e,p_description:n??``,p_type:a??`feature_work`,p_feature:o??null,p_agent:i()});return s?.length&&await t.call(`update_card`,{...r,p_card:c,p_patch:{tags:s},p_agent:i()}),c})),o(`update_task`,`update_card`,{title:`Update a task`,description:`Move a task, mark it blocked (with a reason) or unblocked, put it under a feature, set its tags, rewrite its title or description, and attach evidence: a branch, commit or pull request. Repos are referenced by name.`,inputSchema:{task:l.optional(),card:l.optional(),status:_m([`backlog`,`todo`,`in_progress`,`review`,`done`]).optional(),feature:V().optional().describe(`Feature name or id (e.g. F-4) to put the task under; an empty string takes it off its feature`),title:V().optional(),description:V().optional().describe(`Replaces the description. ${s}`),tags:U(V()).optional().describe(`${c} Replaces the current tags.`),blocked:Qp().optional(),blockedReason:V().optional(),addBranch:W({repo:V(),name:V()}).optional(),addCommit:W({repo:V(),sha:V(),message:V().optional()}).optional(),addPullRequest:W({repo:V(),number:H().int(),url:V(),state:_m([`open`,`merged`,`closed`]).optional()}).optional()}},a(({task:e,card:n,...a})=>t.call(`update_card`,{...r,p_card:e??n,p_patch:a,p_agent:i()}))),n.registerTool(`propose_term`,{title:`Propose a glossary term`,description:`Suggest a new glossary term. It shows up for approval; it isn't used until a person approves it.`,inputSchema:{term:V(),plain:V().describe(`What it means, for someone non-technical`),technical:V().describe(`What it means in the code`),kind:_m([`concept`,`tag`,`name`]).optional(),tagSet:V().optional().describe(`Required for kind 'tag': the set the value belongs to, e.g. feature_change, task_work, capability_audience, capability_kind (see tagSets in quirl_context)`),reason:V().optional()}},a(({term:e,plain:n,technical:a,kind:o,tagSet:s,reason:c})=>t.call(`propose_term`,{...r,p_term:e,p_plain:n,p_technical:a,p_kind:o??`concept`,p_tag_set:s??null,p_reason:c??null,p_agent:i()}))),n.registerTool(`propose_term_retire`,{title:`Retire a glossary term`,description:`Propose retiring a glossary term or tag that's no longer used or was a mistake. With replaceWith, the term stays as one not to say (agents are told the replacement); without it, it's removed. Either way it comes off every capability, task and feature that used it. A person approves it. Built-in tag values can't be retired.`,inputSchema:{term:V().describe(`The term or tag to retire`),replaceWith:V().optional().describe(`An approved term to say instead, if there is one`),reason:V().optional()}},a(({term:e,replaceWith:n,reason:a})=>t.call(`propose_term_retire`,{...r,p_term:e,p_replace_with:n??null,p_reason:a??null,p_agent:i()}))),n.registerTool(`list_flags`,{title:`List flags`,description:`Flags are messages people send about a section of the project: a capability, feature, task, doc or glossary term. Lists open (waiting for an admin) and approved (to act on) flags, or only those with the given status.`,inputSchema:{status:_m([`open`,`approved`,`removed`,`done`]).optional()}},a(({status:e})=>t.call(`list_flags`,{...r,p_status:e??null}))),n.registerTool(`decide_flag`,{title:`Approve or remove a flag`,description:`Admins only. Approve a flag so agents act on it at the start of their sessions, or remove it. An approved flag can still be removed. Only do this when the person you work for asks you to.`,inputSchema:{flag:V().describe(`The flag's id, from the briefing or list_flags`),decision:_m([`approve`,`remove`])}},a(({flag:e,decision:n})=>t.call(`decide_flag`,{...r,p_flag:e,p_approve:n===`approve`,p_agent:i()}))),n.registerTool(`resolve_flag`,{title:`Mark a flag done`,description:`Mark an approved flag done once you've handled it, so it leaves the briefing. Say briefly what you did.`,inputSchema:{flag:V().describe(`The flag's id, from the briefing or list_flags`),note:V().optional().describe(`What was done, e.g. 'Updated C-12 to mention SMS'`)}},a(({flag:e,note:n})=>t.call(`resolve_flag`,{...r,p_flag:e,p_note:n??null,p_agent:i()}))),n.registerTool(`set_capability_icon`,{title:`Set a capability's icon`,description:`Give a capability an icon that fits what it does; it's shown on the capability's card. Use the same icon a related feature has when one fits both.`,inputSchema:{capability:V().describe(`Capability name or id (e.g. C-12)`),icon:_m(jb)}},a(({capability:e,icon:n})=>t.call(`set_capability_icon`,{...r,p_capability:e,p_icon:n,p_agent:i()}))),n.registerTool(`add_resource`,{title:`Add or fill in a resource`,description:"Record a service the project runs on that `quirl sync` can't see from the code: a hosted database another team runs, a SaaS named only in docs or the console, a staging copy. Sync already finds most things from env templates, docker-compose and client packages, so check Stack first (lookup) and don't add what it found. A resource with the same provider and environment is filled in rather than duplicated: the fields you give are set, and repos and capabilities are added to its links. Never pass URLs with credentials, keys or other secret values.",inputSchema:{name:V().describe(`What the team calls it, e.g. "Postgres", "Stripe"`),type:_m([`database`,`storage`,`service`,`queue`,`auth`,`external_api`]),provider:V().optional().describe(`Who runs it, e.g. "Google Cloud SQL", "Stripe". Resources are matched on this. Defaults to the name.`),description:V().optional().describe(`One plain sentence on what the project uses it for`),technical:V().optional().describe(`Technical notes for developers: setup, access, limits`),environment:V().optional().describe(`Defaults to "production"; e.g. "staging"`),repos:U(V()).optional().describe(`Repos that use it, by name`),capabilities:U(V()).optional().describe(`Capabilities that run on it, by name or id (e.g. C-12)`)}},a(e=>t.call(`add_resource`,{...r,p_name:e.name,p_type:e.type,p_provider:e.provider??null,p_description:e.description??null,p_technical:e.technical??null,p_environment:e.environment??null,p_repos:e.repos??null,p_capabilities:e.capabilities??null,p_agent:i()}))),n.registerTool(`list_features`,{title:`List features`,description:`List the project's features with their status, the capability each changes (or createsCapability when it has none), and task counts. Shipped ones are left out unless includeShipped. Check here before requesting a feature.`,inputSchema:{includeShipped:Qp().optional()}},a(({includeShipped:e})=>t.call(`list_features`,{...r,p_include_shipped:e??!1}))),n.registerTool(`get_feature`,{title:`Get a feature`,description:`A feature with its description, status, the capability it changes (and what that capability does) and its tasks.`,inputSchema:{feature:V().describe(`Feature name or id (e.g. F-4)`)}},a(({feature:e})=>t.call(`get_feature`,{...r,p_feature:e}))),n.registerTool(`request_feature`,{title:`Request a feature`,description:`Request a feature: a change to the product that stakeholders follow on the Features page, usually made of several tasks. Check list_features first so you don't request one twice. It shows as requested straight away and a person accepts or declines it. Put tasks under it with create_task or update_task.`,inputSchema:{name:V().describe(`Short name, e.g. 'Repeat appointments'`),description:V().describe(`What changes for the user, in plain words. Markdown: short paragraphs, and lists for parts`),capability:V().optional().describe(`Capability name or id (e.g. C-12) it changes. Leave it out when the feature creates a new capability`),tags:U(V()).optional().describe(`Kind of change: e.g. New, Improvement, Visual, Fix, Performance, Security, Removal, Internal (the feature_change set in quirl_context)`),reason:V().optional().describe(`Why it's worth doing`),icon:_m(jb).optional().describe(`An icon that fits the feature, shown on its card`)}},a(async({name:e,description:n,capability:a,tags:o,reason:s,icon:c})=>{let l=await t.call(`request_feature`,{...r,p_name:e,p_description:n,p_capability:a??null,p_tags:o??null,p_reason:s??null,p_agent:i()});return c&&l===`requested`&&await t.call(`set_feature_icon`,{...r,p_feature:e,p_icon:c,p_agent:i()}),l})),n.registerTool(`set_feature_icon`,{title:`Set a feature's icon`,description:`Give a feature an icon that fits what it does; it's shown on the feature's card. list_features shows which features have none.`,inputSchema:{feature:V().describe(`Feature name or id (e.g. F-4)`),icon:_m(jb)}},a(({feature:e,icon:n})=>t.call(`set_feature_icon`,{...r,p_feature:e,p_icon:n,p_agent:i()}))),n.registerTool(`tag_feature`,{title:`Tag a feature`,description:`Set a feature's kind-of-change tags (replaces the current ones). Only values from the feature_change tag set are accepted.`,inputSchema:{feature:V().describe(`Feature name or id (e.g. F-4)`),tags:U(V()).describe(`Kind of change: e.g. New, Improvement, Visual, Fix, Performance, Security, Removal, Internal`)}},a(({feature:e,tags:n})=>t.call(`tag_feature`,{...r,p_feature:e,p_tags:n,p_agent:i()}))),n.registerTool(`propose_capability`,{title:`Propose a capability`,description:"Draft a capability: one thing the product does today, described for a non-technical reader. Use it when the project has none yet (for example right after `quirl init`), when you find one that's missing, or when a feature that creates a new capability ships (pass it in features). Never for something not built yet: request a feature instead. A person approves it before it shows up.",inputSchema:{name:V().describe(`Short name, e.g. 'Online booking'`),whatItDoes:V().describe(`One or two plain sentences, no jargon`),technical:V().optional().describe(`Where it lives in the code and how it works. Markdown: short paragraphs, and lists for parts, not one long block`),features:U(V()).optional().describe(`Feature names or ids (e.g. F-4) that create or change this capability; they're linked to it once it's approved`),reason:V().optional()}},a(({name:e,whatItDoes:n,technical:a,features:o,reason:s})=>t.call(`propose_capability`,{...r,p_name:e,p_what_it_does:n,p_technical:a??``,p_features:o??null,p_reason:s??null,p_agent:i()}))),n.registerTool(`propose_capability_archive`,{title:`Propose archiving a capability`,description:`Suggest retiring a capability that no longer describes what the product does, or that was drafted for something not built yet. Unshipped features linked to it will create a new capability when they ship. A person approves it.`,inputSchema:{capability:V().describe(`Capability name or id (e.g. C-12)`),reason:V().describe(`Why it should go`)}},a(({capability:e,reason:n})=>t.call(`propose_capability_archive`,{...r,p_capability:e,p_reason:n,p_agent:i()}))),n.registerTool(`propose_capability_update`,{title:`Propose a capability correction`,description:`Suggest a corrected description for a capability when the code no longer matches it. A person approves it.`,inputSchema:{capability:V().describe(`Capability name or id (e.g. C-12)`),field:_m([`what_it_does`,`technical_description`]),after:V().describe(`The corrected text. Markdown: short paragraphs, and lists for parts, not one long block`),reason:V().optional()}},a(({capability:e,field:n,after:a,reason:o})=>t.call(`propose_capability_update`,{...r,p_capability:e,p_field:n,p_after:a,p_reason:o??null,p_agent:i()}))),n.registerTool(`propose_capability_details`,{title:`Propose how a capability works and its connections`,description:`Suggest a capability's 'How it works' steps, its tags (glossary terms of kind 'tag'), the capability it's part of, and its connections: capabilities it relies on, repos, resources it runs on, glossary terms and docs. Each part you pass replaces that part when a person approves it; parts you leave out are kept. Names are matched to existing, approved items. What it relies on draws the arrows on the Home map, so link the steps a user goes through (e.g. invoicing relies on booking).`,inputSchema:{capability:V().describe(`Capability name or id (e.g. C-12)`),howItWorks:U(V()).optional().describe(`3 to 5 plain-language steps, as the user experiences it`),reliesOn:U(W({capability:V().describe(`Capability name or id (e.g. C-12)`),label:V().describe(`How it relies on it, read before the name, e.g. 'extends'`)})).optional(),parent:V().optional().describe(`The capability this one is part of (name or id, e.g. C-2), or 'none' to make it top-level. Parts are listed under their parent instead of on their own`),repos:U(V()).optional().describe(`Repo names`),resources:U(V()).optional().describe(`Resource names it runs on`),terms:U(V()).optional().describe(`Glossary terms`),docs:U(V()).optional().describe(`Doc titles, or <repo>/<path> (e.g. quirl/AGENTS.md) when titles repeat`),tags:U(V()).optional().describe(`Who it's for (Customer, Admin, Developer, Agent) and its kind (Interface, Integration, Data, Automation, Infrastructure, Access and security, AI): the capability tag sets in quirl_context`),reason:V().optional()}},a(({capability:e,howItWorks:n,reliesOn:a,parent:o,repos:s,resources:c,terms:l,docs:u,tags:d,reason:f})=>t.call(`propose_capability_details`,{...r,p_capability:e,p_how_it_works:n??null,p_relies_on:a??null,p_parent:o??null,p_repos:s??null,p_resources:c??null,p_terms:l??null,p_docs:u??null,p_tags:d??null,p_reason:f??null,p_agent:i()}))),n}async function Ib(e){await Fb(e).connect(new Ab)}const Lb=`0.1.1`,Rb=process.env.QUIRL_SERVER===`local`?{apiUrl:`http://127.0.0.1:54321`,publishableKey:`sb_publishable_ACJWlzQHlZjBrEguHvfOxg_3BJgxAaH`,appUrl:`http://localhost:5173`}:{apiUrl:`https://dugevhzlzrdtasuibdzr.supabase.co`,publishableKey:`sb_publishable_45P7GyyZoJsN0AO3wfmqNA_CXbx1iCW`,appUrl:`https://app.quirl.io`};function zb(){return{apiUrl:process.env.QUIRL_API_URL??Rb.apiUrl,publishableKey:process.env.QUIRL_PUBLISHABLE_KEY??Rb.publishableKey,appUrl:process.env.QUIRL_APP_URL??Rb.appUrl}}const Bb=()=>x(process.env.XDG_CONFIG_HOME??x(h(),`.config`),`quirl`),Vb=()=>x(Bb(),`credentials.json`);async function Hb(){try{return JSON.parse(await u(Vb(),`utf8`))}catch{return{}}}async function Ub(){return process.env.QUIRL_KEY?{apiUrl:zb().apiUrl,key:process.env.QUIRL_KEY,email:``}:(await Hb())[zb().apiUrl]??null}async function Wb(e){let t=await Hb();t[e.apiUrl]=e,await l(Bb(),{recursive:!0,mode:448}),await m(Vb(),`${JSON.stringify(t,null,` `)}\n`,{mode:384}),await s(Vb(),384)}async function Gb(){let e=await Hb();delete e[zb().apiUrl],Object.keys(e).length?await m(Vb(),`${JSON.stringify(e,null,` `)}\n`,{mode:384}):await f(Vb(),{force:!0})}async function Kb(){let e=zb();return{apiUrl:e.apiUrl,publishableKey:e.publishableKey,key:(await Ub())?.key??``}}function qb(e=process.cwd()){try{return a(`git`,[`rev-parse`,`--show-toplevel`],{cwd:e,stdio:[`ignore`,`pipe`,`ignore`]}).toString().trim()}catch{return e}}const Jb=e=>x(e,`.quirl`,`project.json`);async function Yb(e=process.cwd()){let t=e;for(;;)try{return{root:t,link:JSON.parse(await u(Jb(t),`utf8`))}}catch{let e=y(t);if(e===t)return null;t=e}}async function Xb(e,t){await l(x(e,`.quirl`),{recursive:!0}),await m(Jb(e),`${JSON.stringify(t,null,` `)}\n`)}async function Zb({hook:e=!1}={}){let t=await Yb();if(!t){if(e)return;throw Error("This folder isn't linked to a Quirl project. Run `quirl init`.")}try{let n=await new Ur(await Kb()).context(t.link.projectId);process.stdout.write(`${Nb(n,e?9500:void 0)}\n`)}catch(n){if(!e)throw n;process.stdout.write(`Quirl project "${t.link.name}": couldn't load the briefing (${n.message}). The quirl MCP tools may still work.\n`)}}const Qb=/* @__PURE__ */ new Set([`.git`,`node_modules`,`dist`,`build`,`.next`,`vendor`,`.venv`,`venv`,`__pycache__`,`coverage`,`.turbo`,`.svelte-kit`,`.nuxt`,`.output`,`.cache`,`.vercel`,`.pnpm-store`,`fixtures`,`test-fixtures`,`__fixtures__`,`testdata`]),$b=2e5;async function ex(e){let t=[],n=await tx(e,t),r=new Map(n.map(e=>[e.path,e]));return{root:e,files:n,warnings:t,file:e=>r.get(e),async readText(e,n=1048576){if(e.size>n)return t.push(`${e.path}: skipped, ${cx(e.size)} is over the ${cx(n)} limit`),null;try{return await u(e.absolutePath,`utf8`)}catch(n){return t.push(`${e.path}: could not be read (${ox(n)})`),null}}}}async function tx(e,t){let n=[],r=[``];for(;r.length>0;){let i=r.pop(),a;try{a=await d(_.join(e,i),{withFileTypes:!0})}catch(e){t.push(`${i||`.`}: folder could not be read (${ox(e)})`);continue}for(let o of a){let a=i?`${i}/${o.name}`:o.name;if(o.isSymbolicLink())continue;if(o.isDirectory()){!Qb.has(o.name)&&!T(_.join(e,a,`.git`))&&r.push(a);continue}if(!o.isFile())continue;if(n.length>=$b)return t.push(`Stopped after ${$b} files; the rest of the tree was not scanned`),nx(n);let s=_.join(e,a);try{let e=await c(s);n.push({path:a,absolutePath:s,size:e.size})}catch(e){t.push(`${a}: could not be read (${ox(e)})`)}}}return nx(n)}function nx(e){return e.sort((e,t)=>e.path<t.path?-1:+(e.path>t.path))}function rx(e){let t=e.lastIndexOf(`/`);return t===-1?e:e.slice(t+1)}function ix(e){let t=e.lastIndexOf(`/`);return t===-1?``:e.slice(0,t)}function ax(e,t){return e?`${e}/${t}`:t}function ox(e){return e instanceof Error?e.message:String(e)}function Q(e){return typeof e==`object`&&!!e&&!Array.isArray(e)}function sx(e){return typeof e==`string`?e:void 0}function cx(e){return e>=1048576?`${(e/1048576).toFixed(1)} MB`:`${Math.ceil(e/1024)} KB`}async function lx(e,t=3){let n=[],r=async(e,i)=>{if(T(_.join(e,`.git`))&&n.push(e),i>=t)return;let a;try{a=await d(e,{withFileTypes:!0})}catch{return}for(let t of a)!t.isDirectory()||t.name.startsWith(`.`)||Qb.has(t.name)||await r(_.join(e,t.name),i+1)};return await r(_.resolve(e),0),n.sort((e,t)=>e.localeCompare(t))}const ux=process.stdout.isTTY&&!process.env.NO_COLOR,dx=e=>t=>ux?`\x1b[${e}m${t}\x1b[0m`:t,fx=dx(1),px=dx(2),mx=dx(32),hx=dx(31),gx=dx(36),_x=e=>console.log(`${mx(`✓`)} ${e}`),vx=e=>console.log(` ${e}`),yx=(e,t)=>console.log(`\n${e} ${t}`),bx=e=>console.log(` ${e}`);function xx(e){if(!ux)return bx(px(e)),{stop:()=>{}};let t=0,n=setInterval(()=>{process.stdout.write(`\r ${gx(`⠋⠙⠹⠸⠼⠴⠦⠧⠇⠏`[t++%10]??``)} ${px(e)}`)},80);return{stop:()=>{clearInterval(n),process.stdout.write(`\r\x1B[2K`)}}}var Sx=class extends Error{};async function Cx(e,t=``){if(!process.stdin.isTTY)return t;let n=E({input:process.stdin,output:process.stdout});try{return(await n.question(e)).trim()||t}finally{n.close()}}async function wx(e,t){let n=await Cx(`${e} ${px(t?`[Y/n]`:`[y/N]`)} `,t?`y`:`n`);return/^y/i.test(n)}function Tx(e){if(process.env.QUIRL_NO_BROWSER)return;let t=process.platform===`darwin`?`open`:process.platform===`win32`?`cmd`:`xdg-open`,n=process.platform===`win32`?[`/c`,`start`,``,e]:[e];try{o(t,n,{stdio:`ignore`,detached:!0}).on(`error`,()=>{}).unref()}catch{}}const Ex=`<!-- quirl:start -->`,Dx=`<!-- quirl:end -->`,Ox=`# quirl: keep the project in sync`;function kx(){try{let e=a(process.platform===`win32`?`where`:`which`,[`quirl`],{stdio:[`ignore`,`pipe`,`ignore`]}).toString();if(!/[\\/]_npx[\\/]/.test(e))return{command:`quirl`,args:[],shell:`quirl`,portable:!0}}catch{}return{command:`npx`,args:[`-y`,`quirl-cli`],shell:`npx -y quirl-cli`,portable:!0}}const Ax=[`QUIRL_SERVER`,`QUIRL_API_URL`,`QUIRL_PUBLISHABLE_KEY`,`QUIRL_APP_URL`];function jx(){return Object.fromEntries(Ax.flatMap(e=>process.env[e]?[[e,process.env[e]]]:[]))}function Mx(){return`${Object.entries(jx()).map(([e,t])=>`${e}="${t}" `).join(``)}${kx().shell}`}async function Nx(e){try{return JSON.parse(await u(e,`utf8`))}catch(t){if(t.code===`ENOENT`)return{};throw Error(`${e} isn't valid JSON; fix it and run \`quirl init\` again.`)}}const Px=async(e,t)=>{await l(y(e),{recursive:!0}),await m(e,`${JSON.stringify(t,null,2)}\n`)};async function Fx(e){let t=x(e,`.mcp.json`),n=await Nx(t),r=kx();n.mcpServers={...n.mcpServers,quirl:{command:r.command,args:[...r.args,`mcp`],...Object.keys(jx()).length?{env:jx()}:{}}},await Px(t,n)}async function Ix(e){let t=x(e,`.claude`,`settings.json`),n=await Nx(t),r=n.hooks??{},i=`${Mx()} context --hook`;r.SessionStart=[...(r.SessionStart??[]).map(e=>({...e,hooks:e.hooks.filter(e=>!/\bcontext --hook$/.test(e.command))})).filter(e=>e.hooks.length),{hooks:[{type:`command`,command:i,timeout:15}]}],n.hooks=r,await Px(t,n)}async function Lx(e,t,n=[]){let r=x(e,`CLAUDE.md`),i=``;try{i=await u(r,`utf8`)}catch{}let a=`${Ex}
182
183
  ## Quirl
183
184
 
184
185
  ${n.length?`This folder holds the repos of the Quirl project **${t}** (${n.join(`, `)}). Quirl is`:`This repo is part of the Quirl project **${t}**,`} the team's source of truth for what the product does. The project briefing (always-loaded docs, glossary, capabilities, your tasks) is loaded at the start of each session. Use the \`quirl\` MCP tools:
@@ -334,10 +335,10 @@ default:yield*this.pop(),yield*this.step()}}*blockMap(e){let t=e.items[e.items.l
334
335
  /* istanbul ignore else should not happen */
335
336
  n?this.stack.push(n):(yield*this.pop(),yield*this.step())}else{let t=this.peek(2);if(t.type===`block-map`&&(this.type===`map-value-ind`&&t.indent===e.indent||this.type===`newline`&&!t.items[t.items.length-1].sep))yield*this.pop(),yield*this.step();else if(this.type===`map-value-ind`&&t.type!==`flow-collection`){let n=c(s(t));u(e);let r=e.end.splice(1,e.end.length);r.push(this.sourceToken);let i={type:`block-map`,offset:e.offset,indent:e.indent,items:[{start:n,key:e,sep:r}]};this.onKeyLine=!0,this.stack[this.stack.length-1]=i}else yield*this.lineEnd(e)}}flowScalar(e){if(this.onNewLine){let e=this.source.indexOf(`
336
337
  `)+1;for(;e!==0;)this.onNewLine(this.offset+e),e=this.source.indexOf(`
337
- `,e)+1}return{type:e,offset:this.offset,indent:this.indent,source:this.source}}startBlockValue(e){switch(this.type){case`alias`:case`scalar`:case`single-quoted-scalar`:case`double-quoted-scalar`:return this.flowScalar(this.type);case`block-scalar-header`:return{type:`block-scalar`,offset:this.offset,indent:this.indent,props:[this.sourceToken],source:``};case`flow-map-start`:case`flow-seq-start`:return{type:`flow-collection`,offset:this.offset,indent:this.indent,start:this.sourceToken,items:[],end:[]};case`seq-item-ind`:return{type:`block-seq`,offset:this.offset,indent:this.indent,items:[{start:[this.sourceToken]}]};case`explicit-key-ind`:{this.onKeyLine=!0;let t=c(s(e));return t.push(this.sourceToken),{type:`block-map`,offset:this.offset,indent:this.indent,items:[{start:t,explicitKey:!0}]}}case`map-value-ind`:{this.onKeyLine=!0;let t=c(s(e));return{type:`block-map`,offset:this.offset,indent:this.indent,items:[{start:t,key:null,sep:[this.sourceToken]}]}}}return null}atIndentedComment(e,t){return this.type!==`comment`||this.indent<=t?!1:e.every(e=>e.type===`newline`||e.type===`space`)}*documentEnd(e){this.type!==`doc-mode`&&(e.end?e.end.push(this.sourceToken):e.end=[this.sourceToken],this.type===`newline`&&(yield*this.pop()))}*lineEnd(e){switch(this.type){case`comma`:case`doc-start`:case`doc-end`:case`flow-seq-end`:case`flow-map-end`:case`map-value-ind`:yield*this.pop(),yield*this.step();break;case`newline`:this.onKeyLine=!1;default:e.end?e.end.push(this.sourceToken):e.end=[this.sourceToken],this.type===`newline`&&(yield*this.pop())}}}})),CC=/* @__PURE__ */ D((e=>{var t=hC(),n=QS(),r=$S(),i=CS(),a=$(),o=xC(),s=SC();function c(e){let t=e.prettyErrors!==!1;return{lineCounter:e.lineCounter||t&&new o.LineCounter||null,prettyErrors:t}}function l(e,n={}){let{lineCounter:i,prettyErrors:a}=c(n),o=new s.Parser(i?.addNewLine),l=new t.Composer(n),u=Array.from(l.compose(o.parse(e)));if(a&&i)for(let t of u)t.errors.forEach(r.prettifyError(e,i)),t.warnings.forEach(r.prettifyError(e,i));return u.length>0?u:Object.assign([],{empty:!0},l.streamInfo())}function u(e,n={}){let{lineCounter:i,prettyErrors:a}=c(n),o=new s.Parser(i?.addNewLine),l=new t.Composer(n),u=null;for(let t of l.compose(o.parse(e),!0,e.length))if(!u)u=t;else if(u.options.logLevel!==`silent`){u.errors.push(new r.YAMLParseError(t.range.slice(0,2),`MULTIPLE_DOCS`,`Source contains multiple documents; please use YAML.parseAllDocuments()`));break}return a&&i&&(u.errors.forEach(r.prettifyError(e,i)),u.warnings.forEach(r.prettifyError(e,i))),u}function d(e,t,n){let r;typeof t==`function`?r=t:n===void 0&&t&&typeof t==`object`&&(n=t);let a=u(e,n);if(!a)return null;if(a.warnings.forEach(e=>i.warn(a.options.logLevel,e)),a.errors.length>0){if(a.options.logLevel!==`silent`)throw a.errors[0];a.errors=[]}return a.toJS(Object.assign({reviver:r},n))}function f(e,t,r){let i=null;if(typeof t==`function`||Array.isArray(t)?i=t:r===void 0&&t&&(r=t),typeof r==`string`&&(r=r.length),typeof r==`number`){let e=Math.round(r);r=e<1?void 0:e>8?{indent:8}:{indent:e}}if(e===void 0){let{keepUndefined:e}=r??t??{};if(!e)return}return a.isDocument(e)&&!i?e.toString(r):new n.Document(e,i,r).toString(r)}e.parse=d,e.parseAllDocuments=l,e.parseDocument=u,e.stringify=f})),wC=(/* @__PURE__ */ D((e=>{var t=hC(),n=QS(),r=XS(),i=$S(),a=mS(),o=$(),s=ES(),c=hS(),l=OS(),u=AS();yC();var d=bC(),f=xC(),p=SC(),m=CC(),h=cS();e.Composer=t.Composer,e.Document=n.Document,e.Schema=r.Schema,e.YAMLError=i.YAMLError,e.YAMLParseError=i.YAMLParseError,e.YAMLWarning=i.YAMLWarning,e.Alias=a.Alias,e.isAlias=o.isAlias,e.isCollection=o.isCollection,e.isDocument=o.isDocument,e.isMap=o.isMap,e.isNode=o.isNode,e.isPair=o.isPair,e.isScalar=o.isScalar,e.isSeq=o.isSeq,e.Pair=s.Pair,e.Scalar=c.Scalar,e.YAMLMap=l.YAMLMap,e.YAMLSeq=u.YAMLSeq,e.Lexer=d.Lexer,e.LineCounter=f.LineCounter,e.Parser=p.Parser,e.parse=m.parse,e.parseAllDocuments=m.parseAllDocuments,e.parseDocument=m.parseDocument,e.stringify=m.stringify,e.visit=h.visit,e.visitAsync=h.visitAsync})))();function TC(e,t){let n=(0,wC.parse)(e,{uniqueKeys:!1});if(!Q(n))throw Error(`not a YAML mapping`);let r=new nS(`npm`,t),i=Q(n.importers)?n.importers:{".":n};for(let e of Object.values(i))if(Q(e))for(let t of[`dependencies`,`devDependencies`,`optionalDependencies`]){let n=e[t];if(Q(n))for(let[e,t]of Object.entries(n)){let n=Q(t)?t.version:t;if(typeof n!=`string`||EC(n))continue;let i=OC(n);i?r.add(i.name,i.version,!0):r.add(e,DC(n),!0)}}for(let e of[`packages`,`snapshots`]){let t=n[e];if(Q(t))for(let e of Object.keys(t)){let t=OC(e);t&&!EC(t.version)&&r.add(t.name,t.version,!1)}}return r.rows()}function EC(e){return/^(link|file|workspace):/.test(e)}function DC(e){return e.replace(/\(.*$/,``).replace(/_(?=[^/]*@).*$/,``)}function OC(e){let t=e.replace(/^\//,``).replace(/\(.*$/,``),n=t.indexOf(`@`,1);if(n>0)return{name:t.slice(0,n),version:DC(t.slice(n+1))};if(!e.startsWith(`/`))return null;let r=t.lastIndexOf(`/`);return r<=0?null:{name:t.slice(0,r),version:DC(t.slice(r+1))}}function kC(e,t){let n=aS(e);if(!Q(n))throw Error(`not a JSON object`);let r=new nS(`npm`,t);if(Q(n.packages)){let e=/* @__PURE__ */ new Set;for(let[t,r]of Object.entries(n.packages))if(!t.includes(`node_modules/`))for(let t of iS(r))e.add(t);for(let[t,i]of Object.entries(n.packages)){let n=t.lastIndexOf(`node_modules/`);if(n===-1||!Q(i)||i.link===!0)continue;let a=t.slice(n+13),o=typeof i.name==`string`?i.name:a;if(typeof i.version!=`string`)continue;let s=t===`node_modules/${a}`;r.add(o,i.version,s&&e.has(a))}return r.rows()}if(Q(n.dependencies)){let e=(t,n)=>{for(let[i,a]of Object.entries(t)){if(!Q(a))continue;let t=a.version;typeof t==`string`&&!EC(t)&&r.add(i,t,n===0&&a.dev!==!0),Q(a.dependencies)&&e(a.dependencies,n+1)}};e(n.dependencies,0)}return r.rows()}function AC(e,t,n){let r=new nS(`npm`,t),i=[],a=!1;for(let t of e.split(/\r?\n/)){if(t===``||t.startsWith(`#`))continue;if(!/^\s/.test(t)&&t.endsWith(`:`)){let e=t.slice(0,-1).split(`,`).map(e=>e.trim().replace(/^"|"$/g,``));a=e.some(e=>/@(workspace|link|file|portal):/.test(e)),i=[...new Set(e.map(jC).filter(e=>e!==null))];continue}let e=/^\s+version:?\s+"?([^"\s]+)"?/.exec(t)?.[1];if(e&&!a){for(let t of i)r.add(t,e,n.has(t));i=[]}}return r.rows()}function jC(e){if(e===`__metadata`)return null;let t=e.indexOf(`@`,1);return t>0?e.slice(0,t):null}async function MC(e,t){let n=ix(t),r=/* @__PURE__ */ new Set,i=await NC(e,ax(n,`package.json`));for(let e of iS(i))r.add(e);if(!Q(i))return r;let a=i.workspaces,o=(Array.isArray(a)?a:Q(a)&&Array.isArray(a.packages)?a.packages:[]).filter(e=>typeof e==`string`).map(e=>PC(ax(n,e.replace(/^\.\//,``).replace(/\/$/,``))));if(o.length===0)return r;for(let t of e.files){if(!t.path.endsWith(`package.json`))continue;let n=ix(t.path);if(o.some(e=>e.test(n)))for(let n of iS(await NC(e,t.path)))r.add(n)}return r}async function NC(e,t){let n=e.file(t);if(!n)return null;let r=await e.readText(n);if(r===null)return null;try{return aS(r)}catch{return e.warnings.push(`${t}: not valid JSON, skipped`),null}}function PC(e){let t=e.split(`/`).map(e=>e===`**`?`.*`:e.replace(/[.+^${}()|[\]\\]/g,`\\$&`).replace(/\*/g,`[^/]*`)).join(`/`);return RegExp(`^${t}$`)}function FC(e){return e.toLowerCase().replace(/[-_.]+/g,`-`)}function IC(e,t,n){let r=new nS(`pip`,t),i=!1,a=null,o=null,s=!1,c=()=>{a&&o&&!s&&r.add(a,o,n.has(FC(a))),a=null,o=null,s=!1};for(let t of e.split(/\r?\n/)){if(/^\s*\[{1,2}([^\]]+)\]{1,2}\s*$/.exec(t)){t.trim()===`[[package]]`?(c(),i=!0):i=!1;continue}if(!i)continue;let e=/^\s*(name|version|source)\s*=\s*(.+)$/.exec(t);if(!e)continue;let n=e[2]?.trim()??``;if(e[1]===`source`)s=/\b(editable|virtual)\s*=/.test(n);else{let t=/^"([^"]*)"/.exec(n)?.[1];e[1]===`name`&&t&&(a=t),e[1]===`version`&&t&&(o=t)}}return c(),r.rows()}function LC(e){let t=/* @__PURE__ */ new Set,n=``,r=null,i=``,a=e=>{let n=/^\s*([A-Za-z0-9][A-Za-z0-9._-]*)/.exec(e)?.[1];n&&t.add(FC(n))},o=()=>{for(let e of i.matchAll(/"([^"]*)"|'([^']*)'/g))a(e[1]??e[2]??``);r=null,i=``};for(let a of e.split(/\r?\n/)){let e=a.replace(/\s+#.*$/,``);if(r!==null){i+=` ${e}`,e.includes(`]`)&&o();continue}let s=/^\s*\[([^\]]+)\]\s*$/.exec(e);if(s){n=(s[1]??``).trim();continue}let c=/^\s*"?([A-Za-z0-9_.-]+)"?\s*=\s*(.*)$/.exec(e);if(!c)continue;let l=c[1]??``,u=c[2]??``;n===`tool.poetry.dependencies`||n===`tool.poetry.dev-dependencies`||/^tool\.poetry\.group\.[^.]+\.dependencies$/.test(n)?FC(l)!==`python`&&t.add(FC(l)):(n===`project`&&l===`dependencies`||n===`project.optional-dependencies`||n===`dependency-groups`)&&u.trimStart().startsWith(`[`)&&(r=l,i=u,u.includes(`]`)&&o())}return t}function RC(e,t){let n=new nS(`pip`,t),r=0;for(let t of e.split(/\r?\n/)){let e=t.replace(/(^|\s)#.*$/,``).trim();if(e===``||e.startsWith(`-`))continue;let i=/^([A-Za-z0-9][A-Za-z0-9._-]*)\s*(?:\[[^\]]*\])?\s*===?\s*([^\s;,\\]+)/.exec(e);i?.[1]&&i[2]?n.add(i[1],i[2],!0):r++}return{rows:n.rows(),unpinned:r}}async function zC(e){let t=[];for(let n of e.files)try{let r=await BC(e,n);r&&t.push(...r)}catch(t){e.warnings.push(`${n.path}: could not be parsed (${ox(t)})`)}return t}async function BC(e,t){let n=rx(t.path),r=ix(t.path),i=t=>t?e.readText(t,52428800):Promise.resolve(null),a=t=>e.file(ax(r,t));switch(n){case`pnpm-lock.yaml`:{let e=await i(t);return e===null?null:TC(e,t.path)}case`package-lock.json`:case`npm-shrinkwrap.json`:{let e=await i(t);return e===null?null:kC(e,t.path)}case`yarn.lock`:{let n=await i(t);return n===null?null:AC(n,t.path,await MC(e,t.path))}case`composer.lock`:{let e=await i(t);return e===null?null:oS(e,t.path,await i(a(`composer.json`)))}case`poetry.lock`:case`uv.lock`:{let e=await i(t);if(e===null)return null;let n=await i(a(`pyproject.toml`)),r=n?LC(n):/* @__PURE__ */ new Set;return IC(e,t.path,r)}case`go.sum`:case`go.mod`:return n===`go.mod`&&a(`go.sum`)?null:sS(await i(a(`go.mod`)),n===`go.sum`?await i(t):null,t.path)}if(/^requirements[\w.-]*\.txt$/i.test(n)||/(^|\/)requirements\/[^/]+\.txt$/.test(t.path)){let n=await i(t);if(n===null)return null;let{rows:r,unpinned:a}=RC(n,t.path);return a>0&&e.warnings.push(`${t.path}: ${a} requirement${a===1?``:`s`} without an exact == pin skipped`),r}return null}const VC=n(i);async function HC(e,t){try{let{stdout:n}=await VC(`git`,t,{cwd:e,timeout:1e4}),r=n.trim();return r===``?null:r}catch{return null}}async function UC(e,t){let n=_.basename(e);if(await HC(e,[`rev-parse`,`--is-inside-work-tree`])!==`true`)return t.push(`Not a git repository (or git is not installed): repo details are empty`),{name:n,provider:null,url:null,defaultBranch:null,headSha:null,lastCommitAt:null};let[r,i,a,o,s]=await Promise.all([HC(e,[`remote`,`get-url`,`origin`]),HC(e,[`rev-parse`,`--verify`,`--quiet`,`HEAD`]),HC(e,[`log`,`-1`,`--format=%cI`]),HC(e,[`symbolic-ref`,`--quiet`,`refs/remotes/origin/HEAD`]),HC(e,[`symbolic-ref`,`--quiet`,`--short`,`HEAD`])]);i===null&&t.push(`Git repository has no commits yet`),r===null&&t.push(`Git repository has no 'origin' remote`);let c=r?WC(r):null;return r&&!c&&t.push(`Could not read the 'origin' remote URL`),{name:c?.name??n,provider:c?.provider??null,url:c?.url??null,defaultBranch:o?.replace(/^refs\/remotes\/origin\//,``)??s,headSha:i,lastCommitAt:a?new Date(a).toISOString():null}}function WC(e){let t,n,r=/^(?:[^@/]+@)?([^:/]+):(?!\/)(.+)$/.exec(e);if(/^[a-z+]+:\/\//i.test(e)){let r;try{r=new URL(e)}catch{return null}if(r.protocol===`file:`)return null;t=r.hostname,n=r.pathname}else if(r?.[1]&&r[2])t=r[1],n=r[2];else return null;if(n=n.replace(/^\/+/,``).replace(/\/+$/,``).replace(/\.git$/,``),!t||!n)return null;let i=t.toLowerCase(),a=i.includes(`github`)?`github`:i.includes(`gitlab`)?`gitlab`:null;return{name:n.slice(n.lastIndexOf(`/`)+1),provider:a,url:`https://${i}/${n}`}}const GC={ts:`TypeScript`,tsx:`TypeScript`,mts:`TypeScript`,cts:`TypeScript`,js:`JavaScript`,jsx:`JavaScript`,mjs:`JavaScript`,cjs:`JavaScript`,py:`Python`,go:`Go`,rb:`Ruby`,php:`PHP`,java:`Java`,kt:`Kotlin`,kts:`Kotlin`,swift:`Swift`,rs:`Rust`,cs:`C#`,fs:`F#`,c:`C`,h:`C`,cc:`C++`,cpp:`C++`,cxx:`C++`,hpp:`C++`,m:`Objective-C`,mm:`Objective-C++`,scala:`Scala`,dart:`Dart`,ex:`Elixir`,exs:`Elixir`,erl:`Erlang`,clj:`Clojure`,hs:`Haskell`,ml:`OCaml`,lua:`Lua`,r:`R`,pl:`Perl`,groovy:`Groovy`,zig:`Zig`,sol:`Solidity`,sql:`SQL`,sh:`Shell`,bash:`Shell`,zsh:`Shell`,ps1:`PowerShell`,tf:`HCL`,vue:`Vue`,svelte:`Svelte`,astro:`Astro`,html:`HTML`,css:`CSS`,scss:`SCSS`,sass:`SCSS`,less:`Less`};function KC(e){let t=/* @__PURE__ */ new Map;for(let n of e){let e=n.path.lastIndexOf(`.`);if(e===-1||e<n.path.lastIndexOf(`/`))continue;let r=GC[n.path.slice(e+1).toLowerCase()];r&&t.set(r,(t.get(r)??0)+1)}return[...t.entries()].sort((e,t)=>t[1]-e[1]||e[0].localeCompare(t[0])).slice(0,5).map(([e])=>e)}const qC=/* @__PURE__ */ new Set([`auth`,`storage`,`realtime`,`_realtime`,`extensions`,`graphql`,`graphql_public`,`supabase_functions`,`supabase_migrations`,`pgsodium`,`pgsodium_masks`,`vault`,`net`,`cron`,`pgbouncer`,`pg_catalog`,`information_schema`]),JC=/^(not|null|default|primary|unique|references|check|constraint|generated|collate|deferrable|initially|identity)$/i;function YC(e){if(!/\.sql$/i.test(e))return!1;let t=e.toLowerCase();return/(^|\/)migrations\//.test(t)||/(^|\/)db\/migrate\//.test(t)}async function XC(e){let t=/* @__PURE__ */ new Map,n=e.files.filter(e=>YC(e.path));n.sort((e,t)=>{let n=e.path.slice(e.path.lastIndexOf(`/`)+1),r=t.path.slice(t.path.lastIndexOf(`/`)+1);return n<r?-1:n>r?1:e.path<t.path?-1:1});for(let r of n){let n=await e.readText(r);if(n!==null)for(let i of ZC(n))try{aw(i,r.path,t,e.warnings)}catch(t){e.warnings.push(`${r.path}: could not read statement "${hw(i)}" (${t instanceof Error?t.message:String(t)})`)}}return[...t.values()].filter(e=>!qC.has(e.schema)).map(e=>{let t=e.schema===`public`?e.table:`${e.schema}.${e.table}`;return{kind:`table`,name:t,sourcePath:e.sourcePath,table:t,columns:e.columns}})}function ZC(e){let t=[],n=``,r=0;for(;r<e.length;){let i=e[r],a=e[r+1];if(i===`-`&&a===`-`){let t=e.indexOf(`
338
+ `,e)+1}return{type:e,offset:this.offset,indent:this.indent,source:this.source}}startBlockValue(e){switch(this.type){case`alias`:case`scalar`:case`single-quoted-scalar`:case`double-quoted-scalar`:return this.flowScalar(this.type);case`block-scalar-header`:return{type:`block-scalar`,offset:this.offset,indent:this.indent,props:[this.sourceToken],source:``};case`flow-map-start`:case`flow-seq-start`:return{type:`flow-collection`,offset:this.offset,indent:this.indent,start:this.sourceToken,items:[],end:[]};case`seq-item-ind`:return{type:`block-seq`,offset:this.offset,indent:this.indent,items:[{start:[this.sourceToken]}]};case`explicit-key-ind`:{this.onKeyLine=!0;let t=c(s(e));return t.push(this.sourceToken),{type:`block-map`,offset:this.offset,indent:this.indent,items:[{start:t,explicitKey:!0}]}}case`map-value-ind`:{this.onKeyLine=!0;let t=c(s(e));return{type:`block-map`,offset:this.offset,indent:this.indent,items:[{start:t,key:null,sep:[this.sourceToken]}]}}}return null}atIndentedComment(e,t){return this.type!==`comment`||this.indent<=t?!1:e.every(e=>e.type===`newline`||e.type===`space`)}*documentEnd(e){this.type!==`doc-mode`&&(e.end?e.end.push(this.sourceToken):e.end=[this.sourceToken],this.type===`newline`&&(yield*this.pop()))}*lineEnd(e){switch(this.type){case`comma`:case`doc-start`:case`doc-end`:case`flow-seq-end`:case`flow-map-end`:case`map-value-ind`:yield*this.pop(),yield*this.step();break;case`newline`:this.onKeyLine=!1;default:e.end?e.end.push(this.sourceToken):e.end=[this.sourceToken],this.type===`newline`&&(yield*this.pop())}}}})),CC=/* @__PURE__ */ D((e=>{var t=hC(),n=QS(),r=$S(),i=CS(),a=$(),o=xC(),s=SC();function c(e){let t=e.prettyErrors!==!1;return{lineCounter:e.lineCounter||t&&new o.LineCounter||null,prettyErrors:t}}function l(e,n={}){let{lineCounter:i,prettyErrors:a}=c(n),o=new s.Parser(i?.addNewLine),l=new t.Composer(n),u=Array.from(l.compose(o.parse(e)));if(a&&i)for(let t of u)t.errors.forEach(r.prettifyError(e,i)),t.warnings.forEach(r.prettifyError(e,i));return u.length>0?u:Object.assign([],{empty:!0},l.streamInfo())}function u(e,n={}){let{lineCounter:i,prettyErrors:a}=c(n),o=new s.Parser(i?.addNewLine),l=new t.Composer(n),u=null;for(let t of l.compose(o.parse(e),!0,e.length))if(!u)u=t;else if(u.options.logLevel!==`silent`){u.errors.push(new r.YAMLParseError(t.range.slice(0,2),`MULTIPLE_DOCS`,`Source contains multiple documents; please use YAML.parseAllDocuments()`));break}return a&&i&&(u.errors.forEach(r.prettifyError(e,i)),u.warnings.forEach(r.prettifyError(e,i))),u}function d(e,t,n){let r;typeof t==`function`?r=t:n===void 0&&t&&typeof t==`object`&&(n=t);let a=u(e,n);if(!a)return null;if(a.warnings.forEach(e=>i.warn(a.options.logLevel,e)),a.errors.length>0){if(a.options.logLevel!==`silent`)throw a.errors[0];a.errors=[]}return a.toJS(Object.assign({reviver:r},n))}function f(e,t,r){let i=null;if(typeof t==`function`||Array.isArray(t)?i=t:r===void 0&&t&&(r=t),typeof r==`string`&&(r=r.length),typeof r==`number`){let e=Math.round(r);r=e<1?void 0:e>8?{indent:8}:{indent:e}}if(e===void 0){let{keepUndefined:e}=r??t??{};if(!e)return}return a.isDocument(e)&&!i?e.toString(r):new n.Document(e,i,r).toString(r)}e.parse=d,e.parseAllDocuments=l,e.parseDocument=u,e.stringify=f})),wC=(/* @__PURE__ */ D((e=>{var t=hC(),n=QS(),r=XS(),i=$S(),a=mS(),o=$(),s=ES(),c=hS(),l=OS(),u=AS();yC();var d=bC(),f=xC(),p=SC(),m=CC(),h=cS();e.Composer=t.Composer,e.Document=n.Document,e.Schema=r.Schema,e.YAMLError=i.YAMLError,e.YAMLParseError=i.YAMLParseError,e.YAMLWarning=i.YAMLWarning,e.Alias=a.Alias,e.isAlias=o.isAlias,e.isCollection=o.isCollection,e.isDocument=o.isDocument,e.isMap=o.isMap,e.isNode=o.isNode,e.isPair=o.isPair,e.isScalar=o.isScalar,e.isSeq=o.isSeq,e.Pair=s.Pair,e.Scalar=c.Scalar,e.YAMLMap=l.YAMLMap,e.YAMLSeq=u.YAMLSeq,e.Lexer=d.Lexer,e.LineCounter=f.LineCounter,e.Parser=p.Parser,e.parse=m.parse,e.parseAllDocuments=m.parseAllDocuments,e.parseDocument=m.parseDocument,e.stringify=m.stringify,e.visit=h.visit,e.visitAsync=h.visitAsync})))();function TC(e,t){let n=(0,wC.parse)(e,{uniqueKeys:!1});if(!Q(n))throw Error(`not a YAML mapping`);let r=new nS(`npm`,t),i=Q(n.importers)?n.importers:{".":n};for(let e of Object.values(i))if(Q(e))for(let t of[`dependencies`,`devDependencies`,`optionalDependencies`]){let n=e[t];if(Q(n))for(let[e,t]of Object.entries(n)){let n=Q(t)?t.version:t;if(typeof n!=`string`||EC(n))continue;let i=OC(n);i?r.add(i.name,i.version,!0):r.add(e,DC(n),!0)}}for(let e of[`packages`,`snapshots`]){let t=n[e];if(Q(t))for(let e of Object.keys(t)){let t=OC(e);t&&!EC(t.version)&&r.add(t.name,t.version,!1)}}return r.rows()}function EC(e){return/^(link|file|workspace):/.test(e)}function DC(e){return e.replace(/\(.*$/,``).replace(/_(?=[^/]*@).*$/,``)}function OC(e){let t=e.replace(/^\//,``).replace(/\(.*$/,``),n=t.indexOf(`@`,1);if(n>0)return{name:t.slice(0,n),version:DC(t.slice(n+1))};if(!e.startsWith(`/`))return null;let r=t.lastIndexOf(`/`);return r<=0?null:{name:t.slice(0,r),version:DC(t.slice(r+1))}}function kC(e,t){let n=aS(e);if(!Q(n))throw Error(`not a JSON object`);let r=new nS(`npm`,t);if(Q(n.packages)){let e=/* @__PURE__ */ new Set;for(let[t,r]of Object.entries(n.packages))if(!t.includes(`node_modules/`))for(let t of iS(r))e.add(t);for(let[t,i]of Object.entries(n.packages)){let n=t.lastIndexOf(`node_modules/`);if(n===-1||!Q(i)||i.link===!0)continue;let a=t.slice(n+13),o=typeof i.name==`string`?i.name:a;if(typeof i.version!=`string`)continue;let s=t===`node_modules/${a}`;r.add(o,i.version,s&&e.has(a))}return r.rows()}if(Q(n.dependencies)){let e=(t,n)=>{for(let[i,a]of Object.entries(t)){if(!Q(a))continue;let t=a.version;typeof t==`string`&&!EC(t)&&r.add(i,t,n===0&&a.dev!==!0),Q(a.dependencies)&&e(a.dependencies,n+1)}};e(n.dependencies,0)}return r.rows()}function AC(e,t,n){let r=new nS(`npm`,t),i=[],a=!1;for(let t of e.split(/\r?\n/)){if(t===``||t.startsWith(`#`))continue;if(!/^\s/.test(t)&&t.endsWith(`:`)){let e=t.slice(0,-1).split(`,`).map(e=>e.trim().replace(/^"|"$/g,``));a=e.some(e=>/@(workspace|link|file|portal):/.test(e)),i=[...new Set(e.map(jC).filter(e=>e!==null))];continue}let e=/^\s+version:?\s+"?([^"\s]+)"?/.exec(t)?.[1];if(e&&!a){for(let t of i)r.add(t,e,n.has(t));i=[]}}return r.rows()}function jC(e){if(e===`__metadata`)return null;let t=e.indexOf(`@`,1);return t>0?e.slice(0,t):null}async function MC(e,t){let n=ix(t),r=/* @__PURE__ */ new Set,i=await NC(e,ax(n,`package.json`));for(let e of iS(i))r.add(e);if(!Q(i))return r;let a=i.workspaces,o=(Array.isArray(a)?a:Q(a)&&Array.isArray(a.packages)?a.packages:[]).filter(e=>typeof e==`string`).map(e=>PC(ax(n,e.replace(/^\.\//,``).replace(/\/$/,``))));if(o.length===0)return r;for(let t of e.files){if(!t.path.endsWith(`package.json`))continue;let n=ix(t.path);if(o.some(e=>e.test(n)))for(let n of iS(await NC(e,t.path)))r.add(n)}return r}async function NC(e,t){let n=e.file(t);if(!n)return null;let r=await e.readText(n);if(r===null)return null;try{return aS(r)}catch{return e.warnings.push(`${t}: not valid JSON, skipped`),null}}function PC(e){let t=e.split(`/`).map(e=>e===`**`?`.*`:e.replace(/[.+^${}()|[\]\\]/g,`\\$&`).replace(/\*/g,`[^/]*`)).join(`/`);return RegExp(`^${t}$`)}function FC(e){return e.toLowerCase().replace(/[-_.]+/g,`-`)}function IC(e,t,n){let r=new nS(`pip`,t),i=!1,a=null,o=null,s=!1,c=()=>{a&&o&&!s&&r.add(a,o,n.has(FC(a))),a=null,o=null,s=!1};for(let t of e.split(/\r?\n/)){if(/^\s*\[{1,2}([^\]]+)\]{1,2}\s*$/.exec(t)){t.trim()===`[[package]]`?(c(),i=!0):i=!1;continue}if(!i)continue;let e=/^\s*(name|version|source)\s*=\s*(.+)$/.exec(t);if(!e)continue;let n=e[2]?.trim()??``;if(e[1]===`source`)s=/\b(editable|virtual)\s*=/.test(n);else{let t=/^"([^"]*)"/.exec(n)?.[1];e[1]===`name`&&t&&(a=t),e[1]===`version`&&t&&(o=t)}}return c(),r.rows()}function LC(e){let t=/* @__PURE__ */ new Set,n=``,r=null,i=``,a=e=>{let n=/^\s*([A-Za-z0-9][A-Za-z0-9._-]*)/.exec(e)?.[1];n&&t.add(FC(n))},o=()=>{for(let e of i.matchAll(/"([^"]*)"|'([^']*)'/g))a(e[1]??e[2]??``);r=null,i=``},s=e=>e.replace(/"[^"]*"|'[^']*'/g,``).includes(`]`);for(let a of e.split(/\r?\n/)){let e=a.replace(/\s+#.*$/,``);if(r!==null){i+=` ${e}`,s(e)&&o();continue}let c=/^\s*\[([^\]]+)\]\s*$/.exec(e);if(c){n=(c[1]??``).trim();continue}let l=/^\s*"?([A-Za-z0-9_.-]+)"?\s*=\s*(.*)$/.exec(e);if(!l)continue;let u=l[1]??``,d=l[2]??``;n===`tool.poetry.dependencies`||n===`tool.poetry.dev-dependencies`||/^tool\.poetry\.group\.[^.]+\.dependencies$/.test(n)?FC(u)!==`python`&&t.add(FC(u)):(n===`project`&&u===`dependencies`||n===`project.optional-dependencies`||n===`dependency-groups`)&&d.trimStart().startsWith(`[`)&&(r=u,i=d,s(d.trimStart().slice(1))&&o())}return t}function RC(e,t){let n=new nS(`pip`,t),r=0;for(let t of e.split(/\r?\n/)){let e=t.replace(/(^|\s)#.*$/,``).trim();if(e===``||e.startsWith(`-`))continue;let i=/^([A-Za-z0-9][A-Za-z0-9._-]*)\s*(?:\[[^\]]*\])?\s*===?\s*([^\s;,\\]+)/.exec(e);i?.[1]&&i[2]?n.add(i[1],i[2],!0):r++}return{rows:n.rows(),unpinned:r}}async function zC(e){let t=[];for(let n of e.files)try{let r=await BC(e,n);r&&t.push(...r)}catch(t){e.warnings.push(`${n.path}: could not be parsed (${ox(t)})`)}return t}async function BC(e,t){let n=rx(t.path),r=ix(t.path),i=t=>t?e.readText(t,52428800):Promise.resolve(null),a=t=>e.file(ax(r,t));switch(n){case`pnpm-lock.yaml`:{let e=await i(t);return e===null?null:TC(e,t.path)}case`package-lock.json`:case`npm-shrinkwrap.json`:{let e=await i(t);return e===null?null:kC(e,t.path)}case`yarn.lock`:{let n=await i(t);return n===null?null:AC(n,t.path,await MC(e,t.path))}case`composer.lock`:{let e=await i(t);return e===null?null:oS(e,t.path,await i(a(`composer.json`)))}case`poetry.lock`:case`uv.lock`:{let e=await i(t);if(e===null)return null;let n=await i(a(`pyproject.toml`)),r=n?LC(n):/* @__PURE__ */ new Set;return IC(e,t.path,r)}case`go.sum`:case`go.mod`:return n===`go.mod`&&a(`go.sum`)?null:sS(await i(a(`go.mod`)),n===`go.sum`?await i(t):null,t.path)}if(/^requirements[\w.-]*\.txt$/i.test(n)||/(^|\/)requirements\/[^/]+\.txt$/.test(t.path)){let n=await i(t);if(n===null)return null;let{rows:r,unpinned:a}=RC(n,t.path);return a>0&&e.warnings.push(`${t.path}: ${a} requirement${a===1?``:`s`} without an exact == pin skipped`),r}return null}const VC=n(i);async function HC(e,t){try{let{stdout:n}=await VC(`git`,t,{cwd:e,timeout:1e4}),r=n.trim();return r===``?null:r}catch{return null}}async function UC(e,t){let n=_.basename(e);if(await HC(e,[`rev-parse`,`--is-inside-work-tree`])!==`true`)return t.push(`Not a git repository (or git is not installed): repo details are empty`),{name:n,provider:null,url:null,defaultBranch:null,headSha:null,lastCommitAt:null};let[r,i,a,o,s]=await Promise.all([HC(e,[`remote`,`get-url`,`origin`]),HC(e,[`rev-parse`,`--verify`,`--quiet`,`HEAD`]),HC(e,[`log`,`-1`,`--format=%cI`]),HC(e,[`symbolic-ref`,`--quiet`,`refs/remotes/origin/HEAD`]),HC(e,[`symbolic-ref`,`--quiet`,`--short`,`HEAD`])]);i===null&&t.push(`Git repository has no commits yet`),r===null&&t.push(`Git repository has no 'origin' remote`);let c=r?WC(r):null;return r&&!c&&t.push(`Could not read the 'origin' remote URL`),{name:c?.name??n,provider:c?.provider??null,url:c?.url??null,defaultBranch:o?.replace(/^refs\/remotes\/origin\//,``)??s,headSha:i,lastCommitAt:a?new Date(a).toISOString():null}}function WC(e){let t,n,r=/^(?:[^@/]+@)?([^:/]+):(?!\/)(.+)$/.exec(e);if(/^[a-z+]+:\/\//i.test(e)){let r;try{r=new URL(e)}catch{return null}if(r.protocol===`file:`)return null;t=r.hostname,n=r.pathname}else if(r?.[1]&&r[2])t=r[1],n=r[2];else return null;if(n=n.replace(/^\/+/,``).replace(/\/+$/,``).replace(/\.git$/,``),!t||!n)return null;let i=t.toLowerCase(),a=i.includes(`github`)?`github`:i.includes(`gitlab`)?`gitlab`:null;return{name:n.slice(n.lastIndexOf(`/`)+1),provider:a,url:`https://${i}/${n}`}}const GC={ts:`TypeScript`,tsx:`TypeScript`,mts:`TypeScript`,cts:`TypeScript`,js:`JavaScript`,jsx:`JavaScript`,mjs:`JavaScript`,cjs:`JavaScript`,py:`Python`,go:`Go`,rb:`Ruby`,php:`PHP`,java:`Java`,kt:`Kotlin`,kts:`Kotlin`,swift:`Swift`,rs:`Rust`,cs:`C#`,fs:`F#`,c:`C`,h:`C`,cc:`C++`,cpp:`C++`,cxx:`C++`,hpp:`C++`,m:`Objective-C`,mm:`Objective-C++`,scala:`Scala`,dart:`Dart`,ex:`Elixir`,exs:`Elixir`,erl:`Erlang`,clj:`Clojure`,hs:`Haskell`,ml:`OCaml`,lua:`Lua`,r:`R`,pl:`Perl`,groovy:`Groovy`,zig:`Zig`,sol:`Solidity`,sql:`SQL`,sh:`Shell`,bash:`Shell`,zsh:`Shell`,ps1:`PowerShell`,tf:`HCL`,vue:`Vue`,svelte:`Svelte`,astro:`Astro`,html:`HTML`,css:`CSS`,scss:`SCSS`,sass:`SCSS`,less:`Less`};function KC(e){let t=/* @__PURE__ */ new Map;for(let n of e){let e=n.path.lastIndexOf(`.`);if(e===-1||e<n.path.lastIndexOf(`/`))continue;let r=GC[n.path.slice(e+1).toLowerCase()];r&&t.set(r,(t.get(r)??0)+1)}return[...t.entries()].sort((e,t)=>t[1]-e[1]||e[0].localeCompare(t[0])).slice(0,5).map(([e])=>e)}const qC=/* @__PURE__ */ new Set([`auth`,`storage`,`realtime`,`_realtime`,`extensions`,`graphql`,`graphql_public`,`supabase_functions`,`supabase_migrations`,`pgsodium`,`pgsodium_masks`,`vault`,`net`,`cron`,`pgbouncer`,`pg_catalog`,`information_schema`]),JC=/^(not|null|default|primary|unique|references|check|constraint|generated|collate|deferrable|initially|identity)$/i;function YC(e){if(!/\.sql$/i.test(e))return!1;let t=e.toLowerCase();return/(^|\/)migrations\//.test(t)||/(^|\/)db\/migrate\//.test(t)}async function XC(e){let t=/* @__PURE__ */ new Map,n=e.files.filter(e=>YC(e.path));n.sort((e,t)=>{let n=e.path.slice(e.path.lastIndexOf(`/`)+1),r=t.path.slice(t.path.lastIndexOf(`/`)+1);return n<r?-1:n>r?1:e.path<t.path?-1:1});for(let r of n){let n=await e.readText(r);if(n!==null)for(let i of ZC(n))try{aw(i,r.path,t,e.warnings)}catch(t){e.warnings.push(`${r.path}: could not read statement "${hw(i)}" (${t instanceof Error?t.message:String(t)})`)}}return[...t.values()].filter(e=>!qC.has(e.schema)).map(e=>{let t=e.schema===`public`?e.table:`${e.schema}.${e.table}`;return{kind:`table`,name:t,sourcePath:e.sourcePath,table:t,columns:e.columns}})}function ZC(e){let t=[],n=``,r=0;for(;r<e.length;){let i=e[r],a=e[r+1];if(i===`-`&&a===`-`){let t=e.indexOf(`
338
339
  `,r);r=t===-1?e.length:t,n+=` `}else if(i===`/`&&a===`*`){let t=1;for(r+=2;r<e.length&&t>0;)e.startsWith(`/*`,r)?(t++,r+=2):e.startsWith(`*/`,r)?(t--,r+=2):r++;n+=` `}else if(i===`'`||i===`"`){let t=r+1;for(;t<e.length;)if(e[t]===i){if(e[t+1]===i)t+=2;else break}else t++;n+=e.slice(r,t+1),r=t+1}else{if(i===`$`){let t=/^\$[A-Za-z_]?[A-Za-z0-9_]*\$/.exec(e.slice(r,r+64))?.[0];if(t){let i=e.indexOf(t,r+t.length),a=i===-1?e.length:i+t.length;n+=e.slice(r,a),r=a;continue}}i===`;`?(n.trim()&&t.push(n.trim()),n=``,r++):(n+=i,r++)}}return n.trim()&&t.push(n.trim()),t.map(e=>e.replace(/\s+/g,` `))}function QC(e){let t=[],n=0,r=null,i=0;for(let a=0;a<e.length;a++){let o=e[a];r?o===r&&(r=null):o===`'`||o===`"`?r=o:o===`(`?n++:o===`)`?n--:o===`,`&&n===0&&(t.push(e.slice(i,a).trim()),i=a+1)}return t.push(e.slice(i).trim()),t.filter(Boolean)}function $C(e){let t=[],n=0;for(;n<e.length;){let r=e[n];if(/\s/.test(r)){n++;continue}if(r===`(`){let r=0,i=n,a=null;for(;i<e.length;i++){let t=e[i];if(a)t===a&&(a=null);else if(t===`'`||t===`"`)a=t;else if(t===`(`)r++;else if(t===`)`&&--r===0)break}t.push(e.slice(n,i+1)),n=i+1;continue}let i=n,a=null;for(;i<e.length;i++){let t=e[i];if(a)t===a&&(a=null);else if(t===`'`||t===`"`)a=t;else if(/\s/.test(t)||t===`(`)break}t.push(e.slice(n,i)),n=i}return t}const ew=String.raw`(?:"(?:[^"]|"")+"|[A-Za-z_][\w$]*)`,tw=String.raw`(${ew}(?:\s*\.\s*${ew})?)`;function nw(e){let t=e.trim();return t.startsWith(`"`)?t.slice(1,-1).replace(/""/g,`"`):t.toLowerCase()}function rw(e){let t=e.match(new RegExp(ew,`g`))??[e];return t.length>=2?{schema:nw(t[0]??``),table:nw(t[1]??``)}:{schema:`public`,table:nw(t[0]??e)}}function iw(e,t){return`${e}.${t}`}function aw(e,t,n,r){if(/^create\s+(?:(?:global|local)\s+)?(?:temp(?:orary)?\s+|unlogged\s+)?table\b/i.test(e)){ow(e,t,n,r);return}let i=new RegExp(String.raw`^alter\s+table\s+(?:if\s+exists\s+)?(?:only\s+)?${tw}\s+(.+)$`,`i`).exec(e);if(i?.[1]&&i[2]){pw(rw(i[1]),i[2],t,n,r);return}let a=/^drop\s+table\s+(?:if\s+exists\s+)?(.+?)(?:\s+(?:cascade|restrict))?$/i.exec(e);if(a?.[1])for(let e of QC(a[1])){let{schema:t,table:r}=rw(e);n.delete(iw(t,r))}}function ow(e,t,n,r){let i=new RegExp(String.raw`^create\s+(?:(?:global|local)\s+)?(?:temp(?:orary)?\s+|unlogged\s+)?table\s+(?:if\s+not\s+exists\s+)?${tw}\s*\(`,`i`).exec(e);if(!i?.[1]){r.push(`${t}: skipped a create table statement it couldn't read: "${hw(e)}"`);return}let{schema:a,table:o}=rw(i[1]),s=i[0].length-1,c=sw(e,s);if(c===-1){r.push(`${t}: unbalanced parentheses in create table ${o}`);return}let l=iw(a,o);if(n.has(l)&&/\bif\s+not\s+exists\b/i.test(e.slice(0,s)))return;let u={schema:a,table:o,sourcePath:t,columns:[]};for(let i of QC(e.slice(s+1,c))){if(/^(constraint|primary\s+key|unique|foreign\s+key|check|exclude|like)\b/i.test(i)){fw(u,i,n);continue}let e=cw(i,n);e?u.columns.push(e):r.push(`${t}: skipped column definition "${hw(i)}" in ${o}`)}n.set(l,u)}function sw(e,t){let n=0,r=null;for(let i=t;i<e.length;i++){let t=e[i];if(r)t===r&&(r=null);else if(t===`'`||t===`"`)r=t;else if(t===`(`)n++;else if(t===`)`&&--n===0)return i}return-1}function cw(e,t){let n=$C(e),r=n[0];if(!r||n.length<2)return null;let i=1,a=[];for(;i<n.length&&!JC.test(n[i]??``);)a.push(n[i]),i++;if(a.length===0)return null;let o={name:nw(r),type:a.join(` `).replace(/\s+\(/g,`(`).toLowerCase(),required:!1};return lw(o,n.slice(i),t),o}function lw(e,t,n){for(let r=0;r<t.length;r++){let i=t[r]?.toLowerCase(),a=t[r+1]?.toLowerCase();if(i===`not`&&a===`null`)e.required=!0,r++;else if(i===`primary`&&a===`key`)e.primaryKey=!0,e.required=!0,r++;else if(i===`unique`)e.unique=!0;else if(i==="default"){let n=[];for(;r+1<t.length&&!JC.test(t[r+1]??``);)n.push(t[r+1]),r++;n.length>0&&(e.default=uw(n))}else if(i===`references`){let i=t[r+1];if(!i)continue;let a=t[r+2]?.startsWith(`(`)?t[r+2]:void 0;e.references=dw(i,a,n),r+=a?2:1}}}function uw(e){return e.join(` `).replace(/\s+\(/g,`(`)}function dw(e,t,n){let{schema:r,table:i}=rw(e),a=r===`public`?i:`${r}.${i}`,o=t?nw(t.slice(1,-1).split(`,`)[0]??``):null;return o||=n.get(iw(r,i))?.columns.find(e=>e.primaryKey)?.name??`id`,`${a}.${o}`}function fw(e,t,n){let r=t.replace(new RegExp(String.raw`^constraint\s+${ew}\s+`,`i`),``),i=e=>(e??``).split(`,`).map(e=>nw(e)).filter(Boolean),a=/^primary\s+key\s*\(([^)]*)\)/i.exec(r);if(a){for(let t of i(a[1])){let n=e.columns.find(e=>e.name===t);n&&(n.primaryKey=!0,n.required=!0)}return}let o=/^unique\s*(?:nulls\s+(?:not\s+)?distinct\s*)?\(([^)]*)\)/i.exec(r);if(o){let t=i(o[1]),n=t.length===1?e.columns.find(e=>e.name===t[0]):void 0;n&&(n.unique=!0);return}let s=new RegExp(String.raw`^foreign\s+key\s*\(([^)]*)\)\s*references\s+${tw}\s*(\([^)]*\))?`,`i`).exec(r);if(s?.[2]){let t=i(s[1]),r=s[3]?i(s[3].slice(1,-1)):[];t.forEach((t,i)=>{let a=e.columns.find(e=>e.name===t);if(!a)return;let o=r[i];a.references=dw(s[2],o?`(${o})`:void 0,n)})}}function pw(e,t,n,r,i){let a=r.get(iw(e.schema,e.table));if(!a){!qC.has(e.schema)&&/\b(add|drop|alter|rename)\s+column\b/i.test(t)&&i.push(`${n}: alter table ${e.table} before any create table for it, skipped`);return}let o=new RegExp(String.raw`^rename\s+to\s+(${ew})$`,`i`).exec(t);if(o?.[1]){r.delete(iw(a.schema,a.table)),a.table=nw(o[1]),r.set(iw(a.schema,a.table),a);return}let s=new RegExp(String.raw`^rename\s+(?:column\s+)?(${ew})\s+to\s+(${ew})$`,`i`).exec(t);if(s?.[1]&&s[2]){let e=a.columns.find(e=>e.name===nw(s[1]));e&&(e.name=nw(s[2]))}else for(let e of QC(t)){let t=/^add\s+(?:column\s+)?(?:if\s+not\s+exists\s+)?(.+)$/i.exec(e);if(t?.[1]&&!/^add\s+(constraint|primary|unique|foreign|check|exclude)\b/i.test(e)){let o=cw(t[1],r);if(!o){i.push(`${n}: skipped "${hw(e)}" on ${a.table}`);continue}a.columns.some(e=>e.name===o.name)||a.columns.push(o);continue}let o=/^add\s+(.+)$/i.exec(e);if(o?.[1]){fw(a,o[1],r);continue}let s=new RegExp(String.raw`^drop\s+(?:column\s+)?(?:if\s+exists\s+)?(${ew})`,`i`).exec(e);if(s?.[1]&&!/^drop\s+constraint\b/i.test(e)){let e=nw(s[1]);a.columns=a.columns.filter(t=>t.name!==e);continue}let c=new RegExp(String.raw`^alter\s+(?:column\s+)?(${ew})\s+(.+)$`,`i`).exec(e);if(c?.[1]&&c[2]){let e=a.columns.find(e=>e.name===nw(c[1]));e&&mw(e,c[2])}}}function mw(e,t){if(/^set\s+not\s+null$/i.test(t))e.required=!0;else if(/^drop\s+not\s+null$/i.test(t))e.required=!!e.primaryKey;else if(/^drop\s+default$/i.test(t))delete e.default;else{let n=/^set\s+default\s+(.+)$/i.exec(t);if(n?.[1]){e.default=uw($C(n[1]));return}let r=/^(?:set\s+data\s+)?type\s+(.+?)(?:\s+(?:using|collate)\s+.*)?$/i.exec(t);r?.[1]&&(e.type=r[1].replace(/\s+\(/g,`(`).toLowerCase())}}function hw(e){return e.length>60?`${e.slice(0,57)}...`:e}const gw=[`GET`,`POST`,`PUT`,`PATCH`,`DELETE`],_w=/^(openapi|swagger)([.-][\w.-]*)?\.(json|ya?ml)$/i,vw=/\.(json|ya?ml)$/i;async function yw(e){let t=[];for(let n of e.files){let r=_w.test(rx(n.path));if(!r&&!vw.test(n.path)||!r&&(n.size>1048576||/(^|\/)[^/]*lock[^/]*$/i.test(n.path)))continue;let i=await e.readText(n,r?10485760:void 0);if(i===null||!r&&!/^\s*["']?(openapi|swagger)["']?\s*:/m.test(i))continue;let a;try{a=/\.json$/i.test(n.path)?JSON.parse(i):(0,wC.parse)(i)}catch(t){e.warnings.push(`${n.path}: OpenAPI file could not be parsed (${ox(t)})`);continue}!Q(a)||typeof a.openapi!=`string`&&typeof a.swagger!=`string`?r&&e.warnings.push(`${n.path}: no top-level openapi or swagger version, skipped`):t.push(...bw(a,n.path,e.warnings))}return t}function bw(e,t,n){let r=typeof e.swagger==`string`,i=new xw(e,t,n),a=r?e.securityDefinitions:Cw(e.components)?.securitySchemes,o=Q(a)?a:{},s=Q(e.paths)?e.paths:{},c=[];for(let[n,a]of Object.entries(s)){let s=i.resolve(a);if(s)for(let a of gw){let l=Cw(s[a.toLowerCase()]);if(!l)continue;let u=[...Array.isArray(s.parameters)?s.parameters:[],...Array.isArray(l.parameters)?l.parameters:[]],d=l.security??e.security;c.push({kind:`endpoint`,name:sx(l.summary)?.trim()||sx(l.operationId)||`${a} ${n}`,sourcePath:t,method:a,path:n,auth:Lw(d,o,i),request:r?Ow(u,l,e,i):Tw(l.requestBody,i),responses:kw(l,e,r,i)})}}return c}var xw=class{#e;#t;#n;#r=/* @__PURE__ */ new Set;constructor(e,t,n){this.#e=e,this.#t=t,this.#n=n}resolve(e){let t=e;for(let e=0;e<8;e++){if(!Q(t))return null;let e=t.$ref;if(typeof e!=`string`)return t;t=this.#i(e)}return null}refName(e){if(!Q(e)||typeof e.$ref!=`string`)return null;let t=e.$ref.slice(e.$ref.lastIndexOf(`/`)+1);return t?Sw(t):null}#i(e){if(!e.startsWith(`#/`))return this.#r.has(e)||(this.#r.add(e),this.#n.push(`${this.#t}: external $ref "${e}" not followed`)),null;let t=this.#e;for(let n of e.slice(2).split(`/`)){if(!Q(t))break;t=t[Sw(n)]}return t===void 0&&!this.#r.has(e)&&(this.#r.add(e),this.#n.push(`${this.#t}: $ref "${e}" points at nothing`)),t}};function Sw(e){return decodeURIComponent(e).replace(/~1/g,`/`).replace(/~0/g,`~`)}function Cw(e){return Q(e)?e:null}function ww(e){if(!Q(e))return null;let t=Object.entries(e).filter(e=>Q(e[1]));return t.find(([e])=>e===`application/json`)??t.find(([e])=>/json/.test(e))??t[0]??null}function Tw(e,t){let n=t.resolve(e),r=n?ww(n.content):null;return r?Ew(r[0],r[1],t):null}function Ew(e,t,n){let r=t.schema;return{contentType:e,fields:Nw(r,n),example:Dw(t,n)??Iw(r,n,0)}}function Dw(e,t){if(e.example!==void 0)return e.example;if(Q(e.examples)){let n=t.resolve(Object.values(e.examples)[0]);if(n&&n.value!==void 0)return n.value}}function Ow(e,t,n,r){let i=e.map(e=>r.resolve(e)).filter(e=>e!==null),a=jw(t.consumes)??jw(n.consumes),o=i.find(e=>e.in===`body`);if(o)return{contentType:a??`application/json`,fields:Nw(o.schema,r),example:Iw(o.schema,r,0)};let s=i.filter(e=>e.in===`formData`);if(s.length===0)return null;let c=s.map(e=>({name:sx(e.name)??``,type:Fw(e,r),required:e.required===!0,...Pw(e)}));return{contentType:a??`application/x-www-form-urlencoded`,fields:c,example:Object.fromEntries(s.map(e=>[sx(e.name)??``,Iw(e,r,1)]))}}function kw(e,t,n,r){if(!Q(e.responses))return[];let i=jw(e.produces)??jw(t.produces)??`application/json`,a=[];for(let[t,o]of Object.entries(e.responses)){let e=r.resolve(o);if(!e)continue;let s=null;if(n){if(e.schema!==void 0){let t=Cw(e.examples);s={contentType:i,fields:Nw(e.schema,r),example:t?.[i]??Iw(e.schema,r,0)}}}else{let t=ww(e.content);t&&(s=Ew(t[0],t[1],r))}a.push({status:Aw(t),description:sx(e.description)??``,body:s})}return a}function Aw(e){let t=e.replace(/x/gi,`0`),n=Number.parseInt(t,10);return Number.isNaN(n)?0:n}function jw(e){return Array.isArray(e)&&typeof e[0]==`string`?e[0]:void 0}function Mw(e,t,n=0){let r=t.resolve(e);if(!r||n>8)return r;if(Array.isArray(r.allOf)){let e={},i=[];for(let a of r.allOf){let r=Mw(a,t,n+1);r&&(Q(r.properties)&&Object.assign(e,r.properties),Array.isArray(r.required)&&i.push(...r.required.filter(e=>typeof e==`string`)))}return Q(r.properties)&&Object.assign(e,r.properties),Array.isArray(r.required)&&i.push(...r.required.filter(e=>typeof e==`string`)),{...r,type:`object`,properties:e,required:i}}let i=Array.isArray(r.oneOf)?r.oneOf:Array.isArray(r.anyOf)?r.anyOf:null;return i&&i.length>0&&!r.properties?Mw(i[0],t,n+1):r}function Nw(e,t){let n=Mw(e,t);if(n?.type===`array`&&(n=Mw(n.items,t)),!n||!Q(n.properties))return[];let r=new Set(Array.isArray(n.required)?n.required:[]);return Object.entries(n.properties).map(([e,n])=>{let i=Mw(n,t)??{};return{name:e,type:Fw(n,t),required:r.has(e),...Pw(i)}})}function Pw(e){let t={},n=sx(e.description)?.trim();return n&&(t.description=n),Array.isArray(e.enum)&&(t.values=e.enum.map(e=>String(e))),t}function Fw(e,t,n=0){let r=t.refName(e),i=Mw(e,t);if(!i)return r??`unknown`;let a=Array.isArray(i.type)?i.type.filter(e=>e!==`null`).join(` | `):sx(i.type);return a===`array`?n>8?`array`:`${Fw(i.items,t,n+1)}[]`:r&&(a===`object`||a===void 0)?r:sx(i.format)??a??(i.properties?`object`:`unknown`)}function Iw(e,t,n){let r=Mw(e,t);if(!r||n>8)return null;if(r.example!==void 0)return r.example;if(Array.isArray(r.enum)&&r.enum.length>0)return r.enum[0];let i=Array.isArray(r.type)?r.type.find(e=>e!==`null`):r.type;if(i===`object`||i===void 0&&Q(r.properties)){let e=Q(r.properties)?r.properties:{};return Object.fromEntries(Object.entries(e).map(([e,r])=>[e,Iw(r,t,n+1)]))}switch(i){case`array`:return[Iw(r.items,t,n+1)];case`string`:return`string`;case`integer`:case`number`:return 0;case`boolean`:return!1;default:return null}}function Lw(e,t,n){if(!Array.isArray(e)||e.length===0)return null;let r=[];for(let i of e){if(!Q(i))continue;let e=Object.keys(i);e.length===0?r.push(`none`):r.push(e.map(e=>Rw(e,n.resolve(t[e]))).join(` + `))}let i=[...new Set(r)];return i.length===0||i.length===1&&i[0]===`none`?null:i.map(e=>e===`none`?`no auth`:e).join(` or `)}function Rw(e,t){if(!t)return e;switch(sx(t.type)?.toLowerCase()){case`http`:{let e=sx(t.scheme)?.toLowerCase();if(e===`bearer`){let e=sx(t.bearerFormat);return e?`Bearer token (${e})`:`Bearer token`}return e===`basic`?`Basic auth`:`HTTP ${e??`auth`}`}case`basic`:return`Basic auth`;case`apikey`:return`apikey ${sx(t.in)??`header`} ${sx(t.name)??e}`;case`oauth2`:return`OAuth2`;case`openidconnect`:return`OpenID Connect`;case`mutualtls`:return`Mutual TLS`;default:return e}}const zw=[`readme.md`,`readme.mdx`,`readme.markdown`,`readme.txt`,`readme`];async function Bw(e){let t=e.files.find(e=>!e.path.includes(`/`)&&zw.includes(e.path.toLowerCase()));if(!t)return null;let n=await e.readText(t);return{path:t.path,oneLiner:n===null?null:Vw(n)}}function Vw(e){let t=e.replace(/\r\n/g,`
339
340
  `).replace(/^---\n[\s\S]*?\n---\n/,``).replace(/<!--[\s\S]*?-->/g,``).replace(/^(```|~~~)[\s\S]*?^\1.*$/gm,``);for(let e of t.split(/\n\s*\n/)){let t=e.split(`
340
- `).map(e=>e.trim()).filter(Boolean),n=t[0];if(!n||/^(#|=+$|-+$|\||[-*+] |\d+\. |>|<|\[!\[|!\[)/.test(n)||/^ {4}|^\t/.test(e))continue;let r=Hw(t.join(` `));if(!(r.length<15||!/[a-z]/i.test(r)))return Uw(/^.+?[.!?](?=\s+["'([]?[A-Z]|\s*$)/.exec(r)?.[0]??r,200)}return null}function Hw(e){return e.replace(/!\[[^\]]*\]\([^)]*\)/g,``).replace(/\[([^\]]*)\]\([^)]*\)/g,`$1`).replace(/\[([^\]]*)\]\[[^\]]*\]/g,`$1`).replace(/<[^>]+>/g,``).replace(/`([^`]*)`/g,`$1`).replace(/(\*\*|__)(.*?)\1/g,`$2`).replace(/(^|\W)[*_](\S(?:.*?\S)?)[*_](?=\W|$)/g,`$1$2`).replace(/\s+/g,` `).trim()}function Uw(e,t){if(e.length<=t)return e;let n=e.slice(0,t-1),r=n.lastIndexOf(` `);return`${(r>t/2?n.slice(0,r):n).trimEnd()}…`}const Ww={name:`Supabase`,type:`database`,provider:`Supabase Postgres`},Gw={name:`Postgres`,type:`database`,provider:`Postgres`},Kw={name:`MySQL`,type:`database`,provider:`MySQL`},qw={name:`MongoDB`,type:`database`,provider:`MongoDB`},Jw={name:`Redis`,type:`database`,provider:`Redis`},Yw={name:`Elasticsearch`,type:`database`,provider:`Elasticsearch`},Xw={name:`AWS S3`,type:`storage`,provider:`AWS S3`},Zw={name:`AWS SQS`,type:`queue`,provider:`AWS SQS`},Qw={name:`AWS`,type:`service`,provider:`AWS`},$w={name:`MinIO`,type:`storage`,provider:`MinIO`},eT={name:`Cloudinary`,type:`storage`,provider:`Cloudinary`},tT={name:`RabbitMQ`,type:`queue`,provider:`RabbitMQ`},nT={name:`Kafka`,type:`queue`,provider:`Kafka`},rT={name:`Stripe`,type:`external_api`,provider:`Stripe`},iT={name:`Twilio`,type:`external_api`,provider:`Twilio`},aT={name:`SendGrid`,type:`service`,provider:`SendGrid`},oT={name:`Postmark`,type:`service`,provider:`Postmark`},sT={name:`Resend`,type:`service`,provider:`Resend`},cT={name:`Mailgun`,type:`service`,provider:`Mailgun`},lT={name:`Email (SMTP)`,type:`service`,provider:`SMTP`},uT={name:`Firebase`,type:`service`,provider:`Firebase`},dT={name:`OpenAI`,type:`external_api`,provider:`OpenAI`},fT={name:`Anthropic`,type:`external_api`,provider:`Anthropic`},pT={name:`Sentry`,type:`service`,provider:`Sentry`},mT={name:`Auth0`,type:`auth`,provider:`Auth0`},hT={name:`Clerk`,type:`auth`,provider:`Clerk`},gT={name:`Auth.js`,type:`auth`,provider:`Auth.js`},_T={name:`Algolia`,type:`external_api`,provider:`Algolia`},vT=[[/^SUPABASE_/,Ww],[/^(DATABASE_URL|POSTGRES_|PG(HOST|USER|PASSWORD|DATABASE|PORT)$)/,Gw],[/^MYSQL_/,Kw],[/^MONGO(DB)?_/,qw],[/^(REDIS_|UPSTASH_REDIS_)/,Jw],[/^(ELASTIC(SEARCH)?_)/,Yw],[/^(AWS_)?S3_|_S3_BUCKET$|^AWS_BUCKET/,Xw],[/^(AWS_)?SQS_/,Zw],[/^AWS_(ACCESS_KEY_ID|SECRET_ACCESS_KEY|REGION|DEFAULT_REGION)$/,Qw],[/^MINIO_/,$w],[/^CLOUDINARY_/,eT],[/^(RABBITMQ_|AMQP_URL)/,tT],[/^KAFKA_/,nT],[/^STRIPE_/,rT],[/^TWILIO_/,iT],[/^SENDGRID_/,aT],[/^POSTMARK_/,oT],[/^RESEND_/,sT],[/^MAILGUN_/,cT],[/^SMTP_/,lT],[/^FIREBASE_/,uT],[/^OPENAI_/,dT],[/^ANTHROPIC_/,fT],[/^SENTRY_/,pT],[/^AUTH0_/,mT],[/^CLERK_/,hT],[/^(NEXTAUTH_|AUTH_SECRET$)/,gT],[/^ALGOLIA_/,_T]],yT=[[[`@supabase/supabase-js`,`@supabase/ssr`,`supabase`,`github.com/supabase-community/*`,`supabase/supabase-php`],Ww],[[`pg`,`postgres`,`pg-promise`,`@neondatabase/serverless`,`@vercel/postgres`,`psycopg2`,`psycopg2-binary`,`psycopg`,`asyncpg`,`github.com/jackc/pgx*`,`github.com/lib/pq`],Gw],[[`mysql`,`mysql2`,`pymysql`,`mysqlclient`,`github.com/go-sql-driver/mysql`],Kw],[[`mongodb`,`mongoose`,`pymongo`,`motor`,`go.mongodb.org/mongo-driver*`,`mongodb/mongodb`],qw],[[`redis`,`ioredis`,`@upstash/redis`,`predis/predis`,`github.com/redis/go-redis*`,`github.com/go-redis/redis*`],Jw],[[`@elastic/elasticsearch`,`elasticsearch`,`elasticsearch/elasticsearch`],Yw],[[`@aws-sdk/client-s3`,`github.com/aws/aws-sdk-go-v2/service/s3`,`league/flysystem-aws-s3-v3`],Xw],[[`@aws-sdk/client-sqs`,`github.com/aws/aws-sdk-go-v2/service/sqs`],Zw],[[`aws-sdk`,`boto3`,`aws/aws-sdk-php`,`github.com/aws/aws-sdk-go`],Qw],[[`minio`],$w],[[`cloudinary`,`cloudinary/cloudinary_php`],eT],[[`amqplib`,`pika`,`php-amqplib/php-amqplib`,`github.com/rabbitmq/amqp091-go`],tT],[[`kafkajs`,`kafka-python`,`confluent-kafka`,`github.com/segmentio/kafka-go`],nT],[[`stripe`,`@stripe/stripe-js`,`@stripe/react-stripe-js`,`stripe/stripe-php`,`github.com/stripe/stripe-go*`],rT],[[`twilio`,`twilio/sdk`,`github.com/twilio/twilio-go`],iT],[[`@sendgrid/`,`sendgrid`,`sendgrid/sendgrid`],aT],[[`postmark`,`wildbit/postmark-php`],oT],[[`resend`,`resend/resend-php`],sT],[[`mailgun.js`,`mailgun/mailgun-php`],cT],[[`nodemailer`],lT],[[`firebase`,`firebase-admin`,`kreait/firebase-php`,`firebase.google.com/go*`],uT],[[`openai`,`openai-php/client`,`github.com/sashabaranov/go-openai`],dT],[[`@anthropic-ai/sdk`,`anthropic`,`github.com/anthropics/anthropic-sdk-go`],fT],[[`@sentry/`,`sentry-sdk`,`sentry/sentry`,`sentry/sentry-laravel`,`github.com/getsentry/sentry-go`],pT],[[`@auth0/`,`auth0`,`auth0/auth0-php`],mT],[[`@clerk/`],hT],[[`next-auth`,`@auth/`],gT],[[`algoliasearch`,`algolia/algoliasearch-client-php`],_T]],bT=[[/^supabase\//,Ww],[/(^|\/)(postgres|postgis|timescaledb)$/,Gw],[/(^|\/)(mysql|mariadb)$/,Kw],[/(^|\/)mongo(db)?$/,qw],[/(^|\/)(redis|redis-stack|valkey)$/,Jw],[/(^|\/)(elasticsearch|opensearch)$/,Yw],[/(^|\/)minio$/,$w],[/(^|\/)rabbitmq$/,tT],[/(^|\/)(kafka|cp-kafka)$/,nT],[/(^|\/)localstack$/,Qw]];function xT(e){return/^\.env(\.[\w-]+)*\.(example|sample|template|dist)$/i.test(e)||/^(example|sample)\.env$/i.test(e)}function ST(e){return/^(docker-)?compose([.-][\w.-]+)?\.ya?ml$/i.test(e)}var CT=class{#e=/* @__PURE__ */ new Map;add(e,t){let n=this.#e.get(e.provider);n?n.evidence.includes(t)||n.evidence.push(t):this.#e.set(e.provider,{...e,evidence:[t]})}list(){return[...this.#e.values()].sort((e,t)=>e.name.localeCompare(t.name))}};async function wT(e,t){let n=new CT;for(let t of e.files){let r=rx(t.path);if(xT(r)){let r=await e.readText(t);if(r===null)continue;for(let e of TT(r)){let r=e.replace(/^(NEXT_PUBLIC_|VITE_|PUBLIC_|REACT_APP_|EXPO_PUBLIC_|NUXT_PUBLIC_|NUXT_)/,``),i=vT.find(([e])=>e.test(r));i&&n.add(i[1],`env: ${e} (${t.path})`)}}else if(ST(r)){let r=await e.readText(t);if(r===null)continue;let i;try{i=(0,wC.parse)(r)}catch(n){e.warnings.push(`${t.path}: could not be parsed (${ox(n)})`);continue}let a=Q(i)&&Q(i.services)?i.services:{};for(let[e,r]of Object.entries(a)){if(!Q(r)||typeof r.image!=`string`)continue;let i=ET(r.image),a=bT.find(([e])=>e.test(i));a&&n.add(a[1],`docker-compose: service ${e} (${r.image}) in ${t.path}`)}}else(t.path===`supabase/config.toml`||t.path.endsWith(`/supabase/config.toml`))&&n.add(Ww,`file: ${t.path}`)}for(let e of t){if(!e.direct)continue;let t=yT.find(([t])=>t.some(t=>DT(t,e.package)));t&&n.add(t[1],`dependency: ${e.package} (${e.sourceLockfile})`)}return n.list()}function TT(e){let t=[];for(let n of e.split(/\r?\n/)){let e=/^\s*(?:export\s+)?([A-Za-z_][A-Za-z0-9_]*)\s*=/.exec(n);e?.[1]&&t.push(e[1])}return t}function ET(e){let t=e.toLowerCase().replace(/@.*$/,``),n=t.lastIndexOf(`/`),r=t.indexOf(`:`,n+1);r!==-1&&(t=t.slice(0,r));let i=t.split(`/`);return i.length>1&&/[.:]|^localhost$/.test(i[0]??``)&&i.shift(),i[0]===`library`&&i.shift(),i.join(`/`)}function DT(e,t){return e.endsWith(`*`)?t.startsWith(e.slice(0,-1)):e.endsWith(`/`)?t.startsWith(e):t===e}async function OT(e){let t=_.resolve(e);if(!(await p(t)).isDirectory())throw Error(`${t} is not a folder`);let n=(/* @__PURE__ */ new Date()).toISOString(),r=await ex(t),i=[],[a,o,s,c,l,u,d]=await Promise.all([UC(t,i),Bw(r),zC(r),Gx(r),Qx(r),yw(r),XC(r)]),f=await wT(r,s);return{scannedAt:n,root:t,repo:{...a,languages:KC(r.files),readme:o},dependencies:s,docs:c,agentInstructions:l,contracts:[...u,...d],resources:f,warnings:[...i,...r.warnings]}}function kT(e){let t=(e,t,n=`${t}s`)=>e?`${e} ${e===1?t:n}`:``;return[t(e.docs,`doc`)+(e.docsChanged&&e.docsChanged<e.docs?` (${e.docsChanged} changed)`:``),t(e.dependencies,`dependency`,`dependencies`),t(e.contracts,`contract`),t(e.resources,`service`)].filter(Boolean).join(` · `)||`nothing to import yet`}async function AT(e,t,{quiet:n=!1,source:r=`connector`}={}){let i=await OT(e),a=await new Ur(await Kb()).call(`sync_repo`,{p_project:t.projectId,p_snapshot:i,p_source:r});if(!n){_x(`Synced ${fx(i.repo.name)} to ${fx(t.name)}`),vx(px(kT(a)));for(let e of i.warnings)vx(px(`! ${e}`))}return{snapshot:i,result:a}}async function jT(e){return tS(await ex(e))}async function MT(e,t,{quiet:n=!1}={}){if(!t.folder)return;let{docs:r,unsupported:i}=await jT(e),a=await new Ur(await Kb()).call(`sync_folder`,{p_project:t.projectId,p_folder:t.folder,p_folder_name:v(e),p_docs:r});return n||(_x(`Synced the documents in ${fx(`${v(e)}/`)} outside the repos`),vx(px(`${a.docs} docs (${a.docsChanged} changed${a.archived?`, ${a.archived} removed`:``})`)),i.length&&vx(px(`! ${i.length} PDF/Office files skipped: only markdown and text are read for now`))),a}async function NT(e={}){let t=await Yb();if(!t)throw new Sx("This folder isn't linked to a Quirl project. Run `quirl init`.");let n=t.link.repos?.length?t.link.repos.map(e=>x(t.root,e)):[t.root],r=n.length+ +!!t.link.folder,i=0;for(let a of n)try{await AT(a,t.link,e)}catch(e){if(i++,r===1)throw e;let n=S(t.root,a)||`.`;console.error(`${hx(`✗`)} ${n}: ${e.message}`)}if(t.link.folder)try{await MT(t.root,t.link,e)}catch(e){i++,console.error(`${hx(`✗`)} documents in ${v(t.root)}/: ${e.message}`)}if(i)throw new Sx(`${i} of ${r} parts didn't sync.`)}async function PT(e){let t=qb(),n=await lx(t),r=n.length?n:[t],i=r.length>1||r[0]!==t,a=e=>S(t,e)||v(t),o=h(),s=t.startsWith(o)?`~${t.slice(o.length)}`:t;if(console.log(`\n🌀 ${fx(`Quirl`)} ${px(`·`)} connecting ${fx(s)}`),i&&(yx(`📁`,`Found ${r.length} ${r.length===1?`repo`:`repos`}`),bx(px(r.map(a).join(` · `))),!await wx(` Import all of them into one project?`,!0)))throw new Sx("Nothing imported. Run `quirl init` inside the repo you want instead.");let c=!1;if(i&&!n.includes(t)){let{docs:e,unsupported:n}=await jT(t);if(e.length){yx(`📄`,`Also found ${e.length} ${e.length===1?`document`:`documents`} outside the repos`);for(let t of e.slice(0,8))bx(px(t.path));e.length>8&&bx(px(`…and ${e.length-8} more`)),n.length&&bx(px(`(${n.length} PDF/Office files can't be read yet and are skipped)`)),c=await wx(` Import them too? Everyone on the project will be able to read them.`,!0)}}await Ub()||await zx({quiet:!0});let l=await IT((await new Ur(await Kb()).whoami()).projects,e.project??(await Yb(t))?.link.project);if(l.role===`stakeholder`)throw new Sx(`You're a stakeholder on ${l.name}; ask an admin or dev to run \`quirl init\`.`);let u={project:l.slug,projectId:l.id,name:l.name};yx(`🔗`,`Linked to ${fx(l.name)} ${px(`· ${l.organization}`)}`);let d=e.claude!==!1,f=e.hooks??await wx(` Sync with Quirl on every git push?`,!0);yx(`📦`,`Importing docs, dependencies and schemas`);let p=[];for(let e of r){let t=xx(`Reading ${a(e)}…`);try{await Xb(e,u);let{snapshot:n,result:r}=await AT(e,u,{quiet:!0});d&&await FT(e,l.name),f&&await Rx(e),t.stop(),bx(`${mx(`✓`)} ${fx(a(e))} ${px(kT(r))}`);for(let e of n.warnings)bx(px(` ! ${e}`));p.push(e)}catch(n){t.stop(),bx(`${hx(`✗`)} ${fx(a(e))} ${n.message}`)}}if(!p.length)throw new Sx(`No repo was imported.`);if(i){let e=p.map(a),n=await Yb(t),r={...u,repos:e,folder:c?n?.root===t&&n.link.folder||w():void 0};if(await Xb(t,r),c)try{let e=await MT(t,r,{quiet:!0});bx(`${mx(`✓`)} ${fx(`documents outside the repos`)} ${px(`${e?.docs??0} docs`)}`)}catch(e){bx(`${hx(`✗`)} ${fx(`documents outside the repos`)} ${e.message}`)}d&&!p.includes(t)&&await FT(t,l.name,e)}let m=kx().portable;d&&(yx(`🤖`,`Connected Claude Code`),bx(px(`.mcp.json the quirl tools`)),bx(px(`.claude/settings.json the briefing, loaded as each session starts`)),bx(px(`CLAUDE.md when to use Quirl`))),f&&yx(`🪝`,`Quirl syncs on every ${fx(`git push`)}`);let g=r.length-p.length,_=`.quirl .mcp.json .claude/settings.json CLAUDE.md`;yx(g?`⚠️ `:`🎉`,g?`Done, but ${g} of ${r.length} repos failed. Fix them and run ${fx(`quirl init`)} again.`:fx(`All set!`)),bx(d&&!m?px(`Don't commit ${_} yet: they point at this checkout until the CLI is installed.`):`${px(`1.`)} Commit what was added${i?` in each repo`:``}: ${gx(`git add ${_}`)}`),bx(`${px(d&&!m?`→`:`2.`)} Start Claude Code here and approve the ${fx(`quirl`)} server when it asks.`),i&&!p.includes(t)&&bx(px("Run `quirl sync` here to sync every repo at once.")),console.log(``)}async function FT(e,t,n=[]){await Fx(e),await Ix(e),await Lx(e,t,n)}async function IT(e,t){if(!e.length)throw new Sx(`You aren't on any Quirl project yet. Ask an admin to invite you.`);if(t){let n=e.find(e=>e.slug===t||e.id===t);if(!n)throw new Sx(`No project "${t}" among yours: ${e.map(e=>e.slug).join(`, `)}.`);return n}if(e.length===1)return e[0];yx(`🗂️ `,`Which project is this part of?`);for(let[t,n]of e.entries())bx(`${gx(String(t+1))} ${n.name} ${px(`· ${n.organization} · ${n.role}`)}`);let n=e[Number(await Cx(` Project [1-${e.length}]: `))-1];if(!n)throw new Sx("No project picked. Run `quirl init --project <slug>`.");return n}const LT=`${fx(`quirl`)} ${px(Lb)}: connect a repo to Quirl
341
+ `).map(e=>e.trim()).filter(Boolean),n=t[0];if(!n||/^(#|=+$|-+$|\||[-*+] |\d+\. |>|<|\[!\[|!\[)/.test(n)||/^ {4}|^\t/.test(e))continue;let r=Hw(t.join(` `));if(!(r.length<15||!/[a-z]/i.test(r)))return Uw(/^.+?[.!?](?=\s+["'([]?[A-Z]|\s*$)/.exec(r)?.[0]??r,200)}return null}function Hw(e){return e.replace(/!\[[^\]]*\]\([^)]*\)/g,``).replace(/\[([^\]]*)\]\([^)]*\)/g,`$1`).replace(/\[([^\]]*)\]\[[^\]]*\]/g,`$1`).replace(/<[^>]+>/g,``).replace(/`([^`]*)`/g,`$1`).replace(/(\*\*|__)(.*?)\1/g,`$2`).replace(/(^|\W)[*_](\S(?:.*?\S)?)[*_](?=\W|$)/g,`$1$2`).replace(/\s+/g,` `).trim()}function Uw(e,t){if(e.length<=t)return e;let n=e.slice(0,t-1),r=n.lastIndexOf(` `);return`${(r>t/2?n.slice(0,r):n).trimEnd()}…`}const Ww={name:`Supabase`,type:`database`,provider:`Supabase Postgres`},Gw={name:`Postgres`,type:`database`,provider:`Postgres`},Kw={name:`MySQL`,type:`database`,provider:`MySQL`},qw={name:`MongoDB`,type:`database`,provider:`MongoDB`},Jw={name:`Redis`,type:`database`,provider:`Redis`},Yw={name:`Elasticsearch`,type:`database`,provider:`Elasticsearch`},Xw={name:`AWS S3`,type:`storage`,provider:`AWS S3`},Zw={name:`AWS SQS`,type:`queue`,provider:`AWS SQS`},Qw={name:`AWS`,type:`service`,provider:`AWS`},$w={name:`MinIO`,type:`storage`,provider:`MinIO`},eT={name:`Cloudinary`,type:`storage`,provider:`Cloudinary`},tT={name:`RabbitMQ`,type:`queue`,provider:`RabbitMQ`},nT={name:`Kafka`,type:`queue`,provider:`Kafka`},rT={name:`Stripe`,type:`external_api`,provider:`Stripe`},iT={name:`Twilio`,type:`external_api`,provider:`Twilio`},aT={name:`SendGrid`,type:`service`,provider:`SendGrid`},oT={name:`Postmark`,type:`service`,provider:`Postmark`},sT={name:`Resend`,type:`service`,provider:`Resend`},cT={name:`Mailgun`,type:`service`,provider:`Mailgun`},lT={name:`Email (SMTP)`,type:`service`,provider:`SMTP`},uT={name:`Firebase`,type:`service`,provider:`Firebase`},dT={name:`OpenAI`,type:`external_api`,provider:`OpenAI`},fT={name:`Anthropic`,type:`external_api`,provider:`Anthropic`},pT={name:`Sentry`,type:`service`,provider:`Sentry`},mT={name:`Auth0`,type:`auth`,provider:`Auth0`},hT={name:`Clerk`,type:`auth`,provider:`Clerk`},gT={name:`Auth.js`,type:`auth`,provider:`Auth.js`},_T={name:`Algolia`,type:`external_api`,provider:`Algolia`},vT={name:`Google Cloud`,type:`service`,provider:`Google Cloud`},yT={name:`Cloud Storage`,type:`storage`,provider:`Google Cloud Storage`},bT={name:`Pub/Sub`,type:`queue`,provider:`Google Cloud Pub/Sub`},xT={name:`BigQuery`,type:`database`,provider:`Google BigQuery`},ST={name:`Firestore`,type:`database`,provider:`Google Firestore`},CT={name:`Secret Manager`,type:`service`,provider:`Google Secret Manager`},wT={name:`Gemini`,type:`external_api`,provider:`Google Gemini`},TT={name:`DuckDB`,type:`database`,provider:`DuckDB`},ET=[[/^SUPABASE_/,Ww],[/^(DATABASE_URL|POSTGRES_|PG(HOST|USER|PASSWORD|DATABASE|PORT)$)/,Gw],[/^MYSQL_/,Kw],[/^MONGO(DB)?_/,qw],[/^(REDIS_|UPSTASH_REDIS_)/,Jw],[/^(ELASTIC(SEARCH)?_)/,Yw],[/^(AWS_)?S3_|_S3_BUCKET$|^AWS_BUCKET/,Xw],[/^(AWS_)?SQS_/,Zw],[/^AWS_(ACCESS_KEY_ID|SECRET_ACCESS_KEY|REGION|DEFAULT_REGION)$/,Qw],[/^MINIO_/,$w],[/^CLOUDINARY_/,eT],[/^(RABBITMQ_|AMQP_URL)/,tT],[/^KAFKA_/,nT],[/^STRIPE_/,rT],[/^TWILIO_/,iT],[/^SENDGRID_/,aT],[/^POSTMARK_/,oT],[/^RESEND_/,sT],[/^MAILGUN_/,cT],[/^SMTP_/,lT],[/^FIREBASE_/,uT],[/^OPENAI_/,dT],[/^ANTHROPIC_/,fT],[/^SENTRY_/,pT],[/^AUTH0_/,mT],[/^CLERK_/,hT],[/^(NEXTAUTH_|AUTH_SECRET$)/,gT],[/^ALGOLIA_/,_T],[/^(GCS_BUCKET|GOOGLE_CLOUD_STORAGE_|GCS_)/,yT],[/^(PUBSUB_|GOOGLE_PUBSUB_)/,bT],[/^BIGQUERY_/,xT],[/^FIRESTORE_/,ST],[/^(GEMINI_|GOOGLE_GENAI_)/,wT],[/^(GOOGLE_CLOUD_PROJECT|GCP_PROJECT(_ID)?|GCLOUD_PROJECT|GOOGLE_APPLICATION_CREDENTIALS)$/,vT]],DT=[[[`@supabase/supabase-js`,`@supabase/ssr`,`supabase`,`github.com/supabase-community/*`,`supabase/supabase-php`],Ww],[[`pg`,`postgres`,`pg-promise`,`@neondatabase/serverless`,`@vercel/postgres`,`psycopg2`,`psycopg2-binary`,`psycopg`,`asyncpg`,`github.com/jackc/pgx*`,`github.com/lib/pq`],Gw],[[`mysql`,`mysql2`,`pymysql`,`mysqlclient`,`github.com/go-sql-driver/mysql`],Kw],[[`mongodb`,`mongoose`,`pymongo`,`motor`,`go.mongodb.org/mongo-driver*`,`mongodb/mongodb`],qw],[[`redis`,`ioredis`,`@upstash/redis`,`predis/predis`,`github.com/redis/go-redis*`,`github.com/go-redis/redis*`],Jw],[[`@elastic/elasticsearch`,`elasticsearch`,`elasticsearch/elasticsearch`],Yw],[[`@aws-sdk/client-s3`,`github.com/aws/aws-sdk-go-v2/service/s3`,`league/flysystem-aws-s3-v3`],Xw],[[`@aws-sdk/client-sqs`,`github.com/aws/aws-sdk-go-v2/service/sqs`],Zw],[[`aws-sdk`,`boto3`,`aws/aws-sdk-php`,`github.com/aws/aws-sdk-go`],Qw],[[`minio`],$w],[[`cloudinary`,`cloudinary/cloudinary_php`],eT],[[`amqplib`,`pika`,`php-amqplib/php-amqplib`,`github.com/rabbitmq/amqp091-go`],tT],[[`kafkajs`,`kafka-python`,`confluent-kafka`,`github.com/segmentio/kafka-go`],nT],[[`stripe`,`@stripe/stripe-js`,`@stripe/react-stripe-js`,`stripe/stripe-php`,`github.com/stripe/stripe-go*`],rT],[[`twilio`,`twilio/sdk`,`github.com/twilio/twilio-go`],iT],[[`@sendgrid/`,`sendgrid`,`sendgrid/sendgrid`],aT],[[`postmark`,`wildbit/postmark-php`],oT],[[`resend`,`resend/resend-php`],sT],[[`mailgun.js`,`mailgun/mailgun-php`],cT],[[`nodemailer`],lT],[[`firebase`,`firebase-admin`,`firebase-functions`,`kreait/firebase-php`,`firebase.google.com/go*`],uT],[[`openai`,`openai-php/client`,`github.com/sashabaranov/go-openai`],dT],[[`@anthropic-ai/sdk`,`anthropic`,`github.com/anthropics/anthropic-sdk-go`],fT],[[`@sentry/`,`sentry-sdk`,`sentry/sentry`,`sentry/sentry-laravel`,`github.com/getsentry/sentry-go`],pT],[[`@auth0/`,`auth0`,`auth0/auth0-php`],mT],[[`@clerk/`],hT],[[`next-auth`,`@auth/`],gT],[[`algoliasearch`,`algolia/algoliasearch-client-php`],_T],[[`@google-cloud/storage`,`google-cloud-storage`,`cloud.google.com/go/storage`],yT],[[`@google-cloud/pubsub`,`google-cloud-pubsub`,`cloud.google.com/go/pubsub*`],bT],[[`@google-cloud/bigquery`,`google-cloud-bigquery`,`cloud.google.com/go/bigquery`],xT],[[`@google-cloud/firestore`,`google-cloud-firestore`,`cloud.google.com/go/firestore`],ST],[[`@google-cloud/secret-manager`,`google-cloud-secret-manager`,`cloud.google.com/go/secretmanager`],CT],[[`@google/genai`,`@google/generative-ai`,`google-genai`,`google-generativeai`,`google-cloud-aiplatform`,`vertexai`],wT],[[`@google-cloud/`,`google-cloud-*`,`google-auth-library`,`google-auth`,`cloud.google.com/go*`],vT],[[`duckdb`,`@duckdb/`],TT]],OT=[[/^supabase\//,Ww],[/(^|\/)(postgres|postgis|timescaledb)$/,Gw],[/(^|\/)(mysql|mariadb)$/,Kw],[/(^|\/)mongo(db)?$/,qw],[/(^|\/)(redis|redis-stack|valkey)$/,Jw],[/(^|\/)(elasticsearch|opensearch)$/,Yw],[/(^|\/)minio$/,$w],[/(^|\/)rabbitmq$/,tT],[/(^|\/)(kafka|cp-kafka)$/,nT],[/(^|\/)localstack$/,Qw],[/(^|\/)(cloud-sdk|google-cloud-cli)$/,vT],[/(^|\/)(gcloud-pubsub-emulator|pubsub-emulator)$/,bT],[/(^|\/)fake-gcs-server$/,yT]];function kT(e){return/^\.env(\.[\w-]+)*\.(example|sample|template|dist)$/i.test(e)||/^(example|sample)\.env$/i.test(e)}function AT(e){return/^(docker-)?compose([.-][\w.-]+)?\.ya?ml$/i.test(e)}var jT=class{#e=/* @__PURE__ */ new Map;add(e,t){let n=this.#e.get(e.provider);n?n.evidence.includes(t)||n.evidence.push(t):this.#e.set(e.provider,{...e,evidence:[t]})}list(){return[...this.#e.values()].sort((e,t)=>e.name.localeCompare(t.name))}};async function MT(e,t){let n=new jT;for(let t of e.files){let r=rx(t.path);if(kT(r)){let r=await e.readText(t);if(r===null)continue;for(let e of NT(r)){let r=e.replace(/^(NEXT_PUBLIC_|VITE_|PUBLIC_|REACT_APP_|EXPO_PUBLIC_|NUXT_PUBLIC_|NUXT_)/,``),i=ET.find(([e])=>e.test(r));i&&n.add(i[1],`env: ${e} (${t.path})`)}}else if(AT(r)){let r=await e.readText(t);if(r===null)continue;let i;try{i=(0,wC.parse)(r)}catch(n){e.warnings.push(`${t.path}: could not be parsed (${ox(n)})`);continue}let a=Q(i)&&Q(i.services)?i.services:{};for(let[e,r]of Object.entries(a)){if(!Q(r)||typeof r.image!=`string`)continue;let i=PT(r.image),a=OT.find(([e])=>e.test(i));a&&n.add(a[1],`docker-compose: service ${e} (${r.image}) in ${t.path}`)}}else t.path===`supabase/config.toml`||t.path.endsWith(`/supabase/config.toml`)?n.add(Ww,`file: ${t.path}`):r===`firebase.json`?n.add(uT,`file: ${t.path}`):/^cloudbuild\.ya?ml$/.test(r)&&n.add(vT,`file: ${t.path}`)}for(let e of t){if(!e.direct)continue;let t=DT.find(([t])=>t.some(t=>FT(t,e.package)));t&&n.add(t[1],`dependency: ${e.package} (${e.sourceLockfile})`)}return n.list()}function NT(e){let t=[];for(let n of e.split(/\r?\n/)){let e=/^\s*(?:export\s+)?([A-Za-z_][A-Za-z0-9_]*)\s*=/.exec(n);e?.[1]&&t.push(e[1])}return t}function PT(e){let t=e.toLowerCase().replace(/@.*$/,``),n=t.lastIndexOf(`/`),r=t.indexOf(`:`,n+1);r!==-1&&(t=t.slice(0,r));let i=t.split(`/`);return i.length>1&&/[.:]|^localhost$/.test(i[0]??``)&&i.shift(),i[0]===`library`&&i.shift(),i.join(`/`)}function FT(e,t){return e.endsWith(`*`)?t.startsWith(e.slice(0,-1)):e.endsWith(`/`)?t.startsWith(e):t===e}async function IT(e){let t=_.resolve(e);if(!(await p(t)).isDirectory())throw Error(`${t} is not a folder`);let n=(/* @__PURE__ */ new Date()).toISOString(),r=await ex(t),i=[],[a,o,s,c,l,u,d]=await Promise.all([UC(t,i),Bw(r),zC(r),Gx(r),Qx(r),yw(r),XC(r)]),f=await MT(r,s);return{scannedAt:n,root:t,repo:{...a,languages:KC(r.files),readme:o},dependencies:s,docs:c,agentInstructions:l,contracts:[...u,...d],resources:f,warnings:[...i,...r.warnings]}}function LT(e){let t=(e,t,n=`${t}s`)=>e?`${e} ${e===1?t:n}`:``;return[t(e.docs,`doc`)+(e.docsChanged&&e.docsChanged<e.docs?` (${e.docsChanged} changed)`:``),t(e.dependencies,`dependency`,`dependencies`),t(e.contracts,`contract`),t(e.resources,`service`)].filter(Boolean).join(` · `)||`nothing to import yet`}async function RT(e,t,{quiet:n=!1,source:r=`connector`}={}){let i=await IT(e),a=await new Ur(await Kb()).call(`sync_repo`,{p_project:t.projectId,p_snapshot:i,p_source:r});if(!n){_x(`Synced ${fx(i.repo.name)} to ${fx(t.name)}`),vx(px(LT(a)));for(let e of i.warnings)vx(px(`! ${e}`))}return{snapshot:i,result:a}}async function zT(e){return tS(await ex(e))}async function BT(e,t,{quiet:n=!1}={}){if(!t.folder)return;let{docs:r,unsupported:i}=await zT(e),a=await new Ur(await Kb()).call(`sync_folder`,{p_project:t.projectId,p_folder:t.folder,p_folder_name:v(e),p_docs:r});return n||(_x(`Synced the documents in ${fx(`${v(e)}/`)} outside the repos`),vx(px(`${a.docs} docs (${a.docsChanged} changed${a.archived?`, ${a.archived} removed`:``})`)),i.length&&vx(px(`! ${i.length} PDF/Office files skipped: only markdown and text are read for now`))),a}async function VT(e={}){let t=await Yb();if(!t)throw new Sx("This folder isn't linked to a Quirl project. Run `quirl init`.");let n=t.link.repos?.length?t.link.repos.map(e=>x(t.root,e)):[t.root],r=n.length+ +!!t.link.folder,i=0;for(let a of n)try{await RT(a,t.link,e)}catch(e){if(i++,r===1)throw e;let n=S(t.root,a)||`.`;console.error(`${hx(`✗`)} ${n}: ${e.message}`)}if(t.link.folder)try{await BT(t.root,t.link,e)}catch(e){i++,console.error(`${hx(`✗`)} documents in ${v(t.root)}/: ${e.message}`)}if(i)throw new Sx(`${i} of ${r} parts didn't sync.`)}async function HT(e){let t=qb(),n=await lx(t),r=n.length?n:[t],i=r.length>1||r[0]!==t,a=e=>S(t,e)||v(t),o=h(),s=t.startsWith(o)?`~${t.slice(o.length)}`:t;if(console.log(`\n🌀 ${fx(`Quirl`)} ${px(`·`)} connecting ${fx(s)}`),i&&(yx(`📁`,`Found ${r.length} ${r.length===1?`repo`:`repos`}`),bx(px(r.map(a).join(` · `))),!await wx(` Import all of them into one project?`,!0)))throw new Sx("Nothing imported. Run `quirl init` inside the repo you want instead.");let c=!1;if(i&&!n.includes(t)){let{docs:e,unsupported:n}=await zT(t);if(e.length){yx(`📄`,`Also found ${e.length} ${e.length===1?`document`:`documents`} outside the repos`);for(let t of e.slice(0,8))bx(px(t.path));e.length>8&&bx(px(`…and ${e.length-8} more`)),n.length&&bx(px(`(${n.length} PDF/Office files can't be read yet and are skipped)`)),c=await wx(` Import them too? Everyone on the project will be able to read them.`,!0)}}await Ub()||await zx({quiet:!0});let l=await WT((await new Ur(await Kb()).whoami()).projects,e.project??(await Yb(t))?.link.project);if(l.role===`stakeholder`)throw new Sx(`You're a stakeholder on ${l.name}; ask an admin or dev to run \`quirl init\`.`);let u={project:l.slug,projectId:l.id,name:l.name};yx(`🔗`,`Linked to ${fx(l.name)} ${px(`· ${l.organization}`)}`);let d=e.claude!==!1,f=e.hooks??await wx(` Sync with Quirl on every git push?`,!0);yx(`📦`,`Importing docs, dependencies and schemas`);let p=[];for(let e of r){let t=xx(`Reading ${a(e)}…`);try{await Xb(e,u);let{snapshot:n,result:r}=await RT(e,u,{quiet:!0});d&&await UT(e,l.name),f&&await Rx(e),t.stop(),bx(`${mx(`✓`)} ${fx(a(e))} ${px(LT(r))}`);for(let e of n.warnings)bx(px(` ! ${e}`));p.push(e)}catch(n){t.stop(),bx(`${hx(`✗`)} ${fx(a(e))} ${n.message}`)}}if(!p.length)throw new Sx(`No repo was imported.`);if(i){let e=p.map(a),n=await Yb(t),r={...u,repos:e,folder:c?n?.root===t&&n.link.folder||w():void 0};if(await Xb(t,r),c)try{let e=await BT(t,r,{quiet:!0});bx(`${mx(`✓`)} ${fx(`documents outside the repos`)} ${px(`${e?.docs??0} docs`)}`)}catch(e){bx(`${hx(`✗`)} ${fx(`documents outside the repos`)} ${e.message}`)}d&&!p.includes(t)&&await UT(t,l.name,e)}let m=kx().portable;d&&(yx(`🤖`,`Connected Claude Code`),bx(px(`.mcp.json the quirl tools`)),bx(px(`.claude/settings.json the briefing, loaded as each session starts`)),bx(px(`CLAUDE.md when to use Quirl`))),f&&yx(`🪝`,`Quirl syncs on every ${fx(`git push`)}`);let g=r.length-p.length,_=`.quirl .mcp.json .claude/settings.json CLAUDE.md`;yx(g?`⚠️ `:`🎉`,g?`Done, but ${g} of ${r.length} repos failed. Fix them and run ${fx(`quirl init`)} again.`:fx(`All set!`)),bx(d&&!m?px(`Don't commit ${_} yet: they point at this checkout until the CLI is installed.`):`${px(`1.`)} Commit what was added${i?` in each repo`:``}: ${gx(`git add ${_}`)}`),bx(`${px(d&&!m?`→`:`2.`)} Start Claude Code here and approve the ${fx(`quirl`)} server when it asks.`),i&&!p.includes(t)&&bx(px("Run `quirl sync` here to sync every repo at once.")),console.log(``)}async function UT(e,t,n=[]){await Fx(e),await Ix(e),await Lx(e,t,n)}async function WT(e,t){if(!e.length)throw new Sx(`You aren't on any Quirl project yet. Ask an admin to invite you.`);if(t){let n=e.find(e=>e.slug===t||e.id===t);if(!n)throw new Sx(`No project "${t}" among yours: ${e.map(e=>e.slug).join(`, `)}.`);return n}if(e.length===1)return e[0];yx(`🗂️ `,`Which project is this part of?`);for(let[t,n]of e.entries())bx(`${gx(String(t+1))} ${n.name} ${px(`· ${n.organization} · ${n.role}`)}`);let n=e[Number(await Cx(` Project [1-${e.length}]: `))-1];if(!n)throw new Sx("No project picked. Run `quirl init --project <slug>`.");return n}const GT=`${fx(`quirl`)} ${px(Lb)}: connect a repo to Quirl
341
342
 
342
343
  quirl init [--project <slug>] [--hooks|--no-hooks] [--no-claude]
343
344
  Link this repo, import it, and connect Claude Code
@@ -347,4 +348,4 @@ n?this.stack.push(n):(yield*this.pop(),yield*this.step())}else{let t=this.peek(2
347
348
  quirl logout Forget this machine's key
348
349
  quirl whoami Show who you're signed in as
349
350
  quirl mcp Run the MCP server (used by Claude Code)
350
- `;async function RT(){let[e,...n]=process.argv.slice(2),{values:r}=t({args:n,allowNegative:!0,options:{project:{type:`string`},hooks:{type:`boolean`},claude:{type:`boolean`},quiet:{type:`boolean`},hook:{type:`boolean`},source:{type:`string`}}});switch(e){case`init`:return PT({project:r.project,hooks:r.hooks,claude:r.claude});case`sync`:return NT({quiet:r.quiet,source:r.source});case`context`:return Zb({hook:r.hook});case`login`:await zx();return;case`logout`:return await Gb(),_x(`Signed out on this machine.`),vx(px(`The key still exists until you revoke it under Organization > Access keys in Quirl (${zb().appUrl}).`));case`whoami`:{if(!await Ub())throw new Sx("Not signed in. Run `quirl login`.");let e=await new Ur(await Kb()).whoami();console.log(fx(e.email));for(let t of e.projects)vx(`${t.name} ${px(`${t.slug} · ${t.organization} · ${t.role}`)}`);let t=await Yb();t&&vx(px(`This folder: ${t.link.name}`));return}case`mcp`:{let e=await Yb();if(!e)throw new Sx("This folder isn't linked to a Quirl project. Run `quirl init`.");return Ib({...await Kb(),project:e.link.projectId,version:Lb})}case void 0:case`help`:case`--help`:case`-h`:process.stdout.write(LT);return;case`--version`:case`-v`:return console.log(Lb);default:throw new Sx(`Unknown command "${e}".\n\n${LT}`)}}RT().catch(e=>{let t=e instanceof Error?e.message:String(e);console.error(`${hx(`✗`)} ${t}`),process.exit(1)});export{};
351
+ `;async function KT(){let[e,...n]=process.argv.slice(2),{values:r}=t({args:n,allowNegative:!0,options:{project:{type:`string`},hooks:{type:`boolean`},claude:{type:`boolean`},quiet:{type:`boolean`},hook:{type:`boolean`},source:{type:`string`}}});switch(e){case`init`:return HT({project:r.project,hooks:r.hooks,claude:r.claude});case`sync`:return VT({quiet:r.quiet,source:r.source});case`context`:return Zb({hook:r.hook});case`login`:await zx();return;case`logout`:return await Gb(),_x(`Signed out on this machine.`),vx(px(`The key still exists until you revoke it under Organization > Access keys in Quirl (${zb().appUrl}).`));case`whoami`:{if(!await Ub())throw new Sx("Not signed in. Run `quirl login`.");let e=await new Ur(await Kb()).whoami();console.log(fx(e.email));for(let t of e.projects)vx(`${t.name} ${px(`${t.slug} · ${t.organization} · ${t.role}`)}`);let t=await Yb();t&&vx(px(`This folder: ${t.link.name}`));return}case`mcp`:{let e=await Yb();if(!e)throw new Sx("This folder isn't linked to a Quirl project. Run `quirl init`.");return Ib({...await Kb(),project:e.link.projectId,version:Lb})}case void 0:case`help`:case`--help`:case`-h`:process.stdout.write(GT);return;case`--version`:case`-v`:return console.log(Lb);default:throw new Sx(`Unknown command "${e}".\n\n${GT}`)}}KT().catch(e=>{let t=e instanceof Error?e.message:String(e);console.error(`${hx(`✗`)} ${t}`),process.exit(1)});export{};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "quirl-cli",
3
- "version": "0.1.0",
3
+ "version": "0.1.1",
4
4
  "description": "Connect a repo to Quirl, the team's source of truth for what the product does.",
5
5
  "license": "UNLICENSED",
6
6
  "homepage": "https://quirl.io",