quirl-cli 0.1.15 → 0.1.16
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/quirl.mjs +1 -1
- package/package.json +1 -1
package/dist/quirl.mjs
CHANGED
|
@@ -211,7 +211,7 @@ if(!Array.isArray(r))throw Error(`ajv implementation error`);let a=n.name(`valid
|
|
|
211
211
|
- domain: pointsTo, record
|
|
212
212
|
- event (webhook received or event sent): direction (receives|sends), counterpart, fields, example
|
|
213
213
|
- role: permissions (list, one line each), assignedTo
|
|
214
|
-
- model (AI): modelId*, usedFor, settings, calledFrom (file paths)`,Qb=H(U({relation:W(Xb),to:B().describe(`"endpoint:GET /domains", "variable:STRIPE_KEY", "resource:<name>" or "repo:<name>"`)})).describe(`Links, as [{relation, to}]. relation: runs (deployment → repo), serves (deployment → API resource or endpoint), calls (job/function/deployment → endpoint, function or model), uses (→ variable, model or resource), protects (role → table, endpoint or function), triggers (event → endpoint, job or function), sends_to (→ queue or resource). to: a contract as kind:name ("endpoint:GET /domains", "variable:STRIPE_KEY"), "resource:<name>" or "repo:<name>".`),$b={resource:B().describe(`The resource's name, provider or id (from list_resources)`),inEnvironment:B().optional().describe(`Its current environment, when the same resource exists in several`)};function ex(e){let t=new Wr(e),n=new yb({name:`quirl`,version:e.version},{instructions:e.notice?`${e.notice}\n\n${Kb}`:Kb}),r={p_project:e.project},i=()=>({tool:n.server.getClientVersion()?.name??`mcp`,model:process.env.QUIRL_AGENT_MODEL}),a=e=>async t=>{try{return qb(await e(t))}catch(e){if(e instanceof Ur)return{...qb(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()=>zb(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:B().describe(`Words to search for, e.g. 'refund approval limits'`),limit:V().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. source says where it lives: 'quirl' for docs written in Quirl (editable with edit_doc), otherwise the repo or folder it's synced from.`,inputSchema:{doc:B().describe(`Doc id, title or path, e.g. 'docs/adr/004-queues.md'`)}},a(({doc:e})=>t.call(`read_doc`,{...r,p_doc:e})));let o=[`product`,`guideline`,`architecture`,`decision`,`how_to`,`reference`];n.registerTool(`create_doc`,{title:`Write a new doc`,description:`Write a doc in Quirl itself: a PRD, spec or product note with no file behind it. Docs about code that tests or builds rely on belong in their repo, where sync picks them up. Use product for PRDs and specs. Never include secret values.`,inputSchema:{title:B(),body:B().describe(`Markdown. Headings (##, ###) split it into sections edit_doc can change one at a time.`),type:W(o).optional().describe(`Defaults to reference`)}},a(({title:e,body:n,type:a})=>t.call(`create_doc`,{...r,p_title:e,p_body:n,p_type:a??`reference`,p_agent:i()}))),n.registerTool(`edit_doc`,{title:`Edit a doc written in Quirl`,description:`Change one section of a doc written in Quirl, or the whole doc, without rewriting the rest. A section is named by its heading, or by its path when a heading repeats ('Billing > Refunds'). replace swaps the section's text (keeping its heading, unless the new text starts with one); append adds to the end of it. Without a section, replace rewrites the doc and append adds to its end. Docs synced from a repo or folder are changed there instead. The edit fails if the doc changed since it was read, rather than overwriting that change.`,inputSchema:{doc:B().describe(`Doc id or title`),section:B().optional().describe(`Heading text or path, e.g. 'Scope' or 'Billing > Refunds'`),content:B().describe(`Markdown`),mode:W([`replace`,`append`]).optional().describe(`Defaults to replace`),title:B().optional().describe(`A new title for the doc`),type:W(o).optional()}},a(async({doc:e,section:n,content:a,mode:o,title:s,type:c})=>{let l=await t.call(`read_doc`,{...r,p_doc:e});if(!l.editable)throw new Ur(`"${l.title}" comes from ${l.source}. Change it there; sync brings it into Quirl.`);let u;try{u=Gb(l.body,n,a,o??`replace`)}catch(e){throw new Ur(e.message)}return{...await t.call(`update_doc`,{...r,p_doc:l.id,p_title:s??null,p_body:u,p_type:c??null,p_expected_hash:l.contentHash,p_agent:i()}),edited:n??`the whole doc`,sections:Hb(u)}})),n.registerTool(`doc_history`,{title:`A doc's history`,description:`Who changed a doc and when, newest first, with lines added and removed. Pass a version to see what it changed (a diff against the version before), or full to get that version's whole text, e.g. to bring back wording with edit_doc.`,inputSchema:{doc:B().describe(`Doc id or title`),version:V().int().optional(),full:em().optional().describe(`With version: its whole text instead of the diff`)}},a(async({doc:e,version:n,full:i})=>{let a=await t.call(`doc_history`,{...r,p_doc:e,p_limit:n?200:21}),o=a.versions,s=e=>o.find(t=>t.version===e-1);if(n){let e=o.find(e=>e.version===n);if(!e)throw new Ur(`"${a.title}" has no version ${n}; the latest is ${o[0]?.version??0}.`);if(i)return{version:n,title:e.title,body:e.body};let t=s(n);return{version:n,author:e.author??`unknown`,at:e.createdAt,...t&&t.title!==e.title?{renamed:`${t.title} → ${e.title}`}:{},diff:t?Ib(t.body,e.body)||`(no text changes)`:`(first version)`}}return{title:a.title,source:a.source,versions:o.slice(0,20).map(e=>{let t=s(e.version);return{version:e.version,author:e.author??`unknown`,at:e.createdAt,change:t?Pb(Nb(t.body,e.body)):`first version`}})}})),n.registerTool(`archive_doc`,{title:`Archive a doc written in Quirl`,description:`Remove a doc written in Quirl that's no longer true or was a mistake. It's archived and stays in history. Docs synced from a repo or folder are deleted there instead.`,inputSchema:{doc:B().describe(`Doc id or title`),reason:B().optional().describe(`Why, for history`)}},a(({doc:e,reason:n})=>t.call(`archive_doc`,{...r,p_doc:e,p_reason:n??null,p_agent:i()}))),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:B().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 s=(e,t,r,i)=>{n.registerTool(e,r,i),n.registerTool(t,{...r,description:`Old name for ${e}; use ${e}. ${r.description}`},i)};s(`list_tasks`,`list_cards`,{title:`List tasks`,description:`List tasks on the board. Defaults to your own tasks that aren't done.`,inputSchema:{onlyMine:em().optional(),includeDone:em().optional()}},a(({onlyMine:e,includeDone:n})=>t.call(`list_cards`,{...r,p_only_mine:e??!0,p_include_done:n??!1})));let c=`Markdown: short paragraphs, and lists for steps or parts, not one long block.`,l=`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).`,u=B().describe(`Task number, e.g. 'K-104' or '104'`),d=B().optional().describe(`Who does it: "me", a member's email or name (only people on the project), or "none"`);return s(`get_task`,`get_card`,{title:`Get a task`,description:`A task with its feature, docs, dependencies and evidence.`,inputSchema:{task:u.optional(),card:u.optional()}},a(({task:e,card:n})=>t.call(`get_card`,{...r,p_card:e??n}))),s(`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:B(),description:B().optional().describe(`What to do and why. ${c}`),type:W([`feature_work`,`bug`,`chore`,`research`]).optional(),feature:B().optional().describe(`Feature name or id (e.g. F-4) this task belongs to`),tags:H(B()).optional().describe(l),assignee:d.describe(`Who does it: "me" (the default), a member's email or name, or "none"`)}},a(async({title:e,description:n,type:a,feature:o,tags:s,assignee:c})=>{let l=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||c)&&await t.call(`update_card`,{...r,p_card:l,p_patch:{...s?.length?{tags:s}:{},...c?{assignee:c}:{}},p_agent:i()}),l})),s(`update_task`,`update_card`,{title:`Update a task`,description:`Move a task, mark it blocked (with a reason) or unblocked, assign it, 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:u.optional(),card:u.optional(),assignee:d,status:W([`backlog`,`todo`,`in_progress`,`review`,`done`]).optional(),feature:B().optional().describe(`Feature name or id (e.g. F-4) to put the task under; an empty string takes it off its feature`),title:B().optional(),description:B().optional().describe(`Replaces the description. ${c}`),tags:H(B()).optional().describe(`${l} Replaces the current tags.`),blocked:em().optional(),blockedReason:B().optional(),addBranch:U({repo:B(),name:B()}).optional(),addCommit:U({repo:B(),sha:B(),message:B().optional()}).optional(),addPullRequest:U({repo:B(),number:V().int(),url:B(),state:W([`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(`archive_task`,{title:`Archive a task`,description:`Remove a task that shouldn't be there: a duplicate or a mistake. It's archived and stays in history, and its feature's status is worked out without it. For work that's finished, move it to done instead.`,inputSchema:{task:u,reason:B().optional().describe(`Why, for history`)}},a(({task:e,reason:n})=>t.call(`archive_card`,{...r,p_card:e,p_reason:n??null,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:B(),plain:B().describe(`What it means, for someone non-technical`),technical:B().describe(`What it means in the code`),kind:W([`concept`,`tag`,`name`]).optional(),aliases:H(B()).optional().describe(`Other names people use for it, e.g. "Strategy Lab", "DSL". None may already name another term.`),tagSet:B().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:B().optional()}},a(({term:e,plain:n,technical:a,kind:o,tagSet:s,aliases:c,reason:l})=>t.call(`propose_term`,{...r,p_term:e,p_plain:n,p_technical:a,p_kind:o??`concept`,p_tag_set:s??null,p_aliases:c??null,p_reason:l??null,p_agent:i()}))),n.registerTool(`propose_term_update`,{title:`Propose a glossary term correction`,description:`Suggest a corrected name, plain definition or technical definition for an existing glossary term, when it's wrong or the code no longer matches it. A renamed term keeps its old name as an alias. For other names people use, use propose_term_aliases; to stop using a term, propose_term_retire. A person approves it.`,inputSchema:{term:B().describe(`The term, by its name or one of its aliases`),field:W([`term`,`plain`,`technical`]).describe(`term: its name; plain: what it means for someone non-technical; technical: what it means in the code`),after:B().describe(`The new name, or the corrected definition`),reason:B().optional()}},a(e=>t.call(`propose_term_update`,{...r,p_term:e.term,p_field:e.field,p_after:e.after,p_reason:e.reason??null,p_agent:i()}))),n.registerTool(`propose_term_aliases`,{title:`Propose other names for a term`,description:`Add or remove the other names people use for a glossary term ("Strategy Lab" and "DSL" for Domain Strategy Lab). Agents then understand them, while code and titles keep the term itself. A name can't already belong to another term: then the terms clash, and a person sorts it out. A person approves the change.`,inputSchema:{term:B().describe(`The term, by its name or one of its aliases`),add:H(B()).optional(),remove:H(B()).optional(),reason:B().optional().describe(`Where it's used, e.g. "the ticket and the standup notes say Strategy Lab"`)}},a(e=>t.call(`propose_term_aliases`,{...r,p_term:e.term,p_add:e.add??null,p_remove:e.remove??null,p_reason:e.reason??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:B().describe(`The term or tag to retire`),replaceWith:B().optional().describe(`An approved term to say instead, if there is one`),reason:B().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:W([`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:B().describe(`The flag's id, from the briefing or list_flags`),decision:W([`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:B().describe(`The flag's id, from the briefing or list_flags`),note:B().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:B().describe(`Capability name or id (e.g. C-12)`),icon:W(Lb)}},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:B().describe(`What the team calls it, e.g. "Postgres", "Stripe"`),type:W(Jb),provider:B().optional().describe(`Who runs it, e.g. "Google Cloud SQL", "Stripe". Resources are matched on this. Defaults to the name.`),description:B().optional().describe(`One plain sentence on what the project uses it for`),technical:B().optional().describe(`Technical notes for developers: setup, access, limits`),environment:B().optional().describe(`Defaults to "production"; e.g. "staging"`),repos:H(B()).optional().describe(`Repos that use it, by name`),capabilities:H(B()).optional().describe(`Capabilities that run on it, by name or id (e.g. C-12)`),account:B().optional().describe(`The cloud project, account or team it lives in, e.g. GCP project "domainarium-staging". Sync files deployments, jobs and secrets by it. Never a key.`)}},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_account:e.account??null,p_agent:i()}))),n.registerTool(`list_resources`,{title:`List the project's resources`,description:`Every resource on Stack: name, type, provider, environment, whether sync found it or someone added it, the repos that use it, the capabilities that run on it, and the tables and endpoints filed under it (per repo, with a few names). Tables in the wrong database or endpoints under the wrong API: fix with move_contracts.`,inputSchema:{}},a(()=>t.call(`list_resources`,r))),n.registerTool(`update_resource`,{title:`Change a resource`,description:`Correct a resource: rename it, relabel its environment (a scanned one that's really the local docker database becomes 'local'), or change its type, provider, descriptions or links. Only the fields you pass change. repos and capabilities replace its links; use add_resource to add to them. A repo you take off stays off: sync won't link it again until a person adds it back. Sync keeps updating a relabelled resource instead of adding it again. Never pass secret values.`,inputSchema:{...$b,name:B().optional(),type:W(Jb).optional(),provider:B().optional(),environment:B().optional().describe(`e.g. "production", "staging", "dev", "local"`),description:B().optional().describe(`One plain sentence on what the project uses it for`),technical:B().optional().describe(`Notes for developers`),repos:H(B()).optional().describe(`Replaces the repos that use it. Ones left out stay off through later syncs.`),capabilities:H(B()).optional().describe(`Replaces the capabilities that run on it (names or C-12)`),account:B().optional().describe(`The cloud project, account or team it lives in, e.g. GCP project "domainarium-staging". Sync files deployments, jobs and secrets by it. Never a key. Empty clears it.`)}},a(e=>t.call(`update_resource`,{...r,p_resource:e.resource,p_in_environment:e.inEnvironment??null,p_name:e.name??null,p_type:e.type??null,p_provider:e.provider??null,p_environment:e.environment??null,p_description:e.description??null,p_technical:e.technical??null,p_repos:e.repos??null,p_capabilities:e.capabilities??null,p_account:e.account??null,p_agent:i()}))),n.registerTool(`remove_resource`,{title:`Remove a wrong resource`,description:`Remove a resource that isn't one: a false match from sync, a duplicate, something no longer used. It's archived, stays in history, and sync won't add it again. A resource holding endpoints or tables from sync can't be removed; relabel it instead.`,inputSchema:{...$b,reason:B().optional().describe(`Why it's wrong, for history`)}},a(e=>t.call(`remove_resource`,{...r,p_resource:e.resource,p_in_environment:e.inEnvironment??null,p_reason:e.reason??null,p_agent:i()}))),n.registerTool(`get_resource`,{title:`Get a resource and what it holds`,description:`One resource with everything it holds: endpoints, tables, functions, deployments, variables (names only), jobs, domains, events, roles, models. Each with its fields (spec), whether sync found it or someone added it, and its links (what it runs, calls, uses or protects, and what points at it). Use before adding or changing what a resource holds.`,inputSchema:$b},a(e=>t.call(`get_resource`,{...r,p_resource:e.resource,p_in_environment:e.inEnvironment??null}))),n.registerTool(`add_contract`,{title:`Add something a resource holds`,description:`Record what the code doesn't show: a Cloud Scheduler job set up in the console, the variables Secret Manager holds (names, never values), a Cloud Run service, the roles the product has, the AI models it calls, a webhook it receives, a domain. Sync finds endpoints and tables from OpenAPI files and migrations, so check get_resource first. What you add stays until someone removes it; if sync later finds the same thing in code, it takes it over. Never pass secret values, keys or URLs with credentials.\n\n${Zb}`,inputSchema:{...$b,kind:W(Yb),name:B().optional().describe(`e.g. "nightly-invoices", "STRIPE_SECRET_KEY", "admin", "claude-opus-5-5". Endpoints default to "METHOD /path".`),description:B().optional().describe(`One plain sentence: what it is or does`),spec:_m(B(),im()).optional().describe(`The kind's fields; see the list above`),repo:B().optional().describe(`The repo it belongs to, if any`),links:Qb.optional()}},a(e=>t.call(`add_contract`,{...r,p_resource:e.resource,p_in_environment:e.inEnvironment??null,p_kind:e.kind,p_name:e.name??null,p_description:e.description??null,p_spec:e.spec??null,p_repo:e.repo??null,p_links:e.links??null,p_agent:i()}))),n.registerTool(`update_contract`,{title:`Change something a resource holds`,description:`Correct or fill in a contract: its description, its fields, its links. spec is merged: given fields are set, a field set to null is removed. links, when given, replace the links people added (sync's stay). On something sync found (an endpoint from OpenAPI, a table from migrations) only the description and links change here; the rest follows the code. To file it under another resource, use move_contracts.\n\n${Zb}`,inputSchema:{contract:B().describe(`kind:name ("job:nightly-invoices", "endpoint:GET /domains"), a unique name, or its id (from get_resource)`),resource:B().optional().describe(`Its resource, when the name is in several`),inEnvironment:B().optional(),name:B().optional(),description:B().optional(),spec:_m(B(),im()).optional(),links:Qb.optional()}},a(e=>t.call(`update_contract`,{...r,p_contract:e.contract,p_resource:e.resource??null,p_in_environment:e.inEnvironment??null,p_name:e.name??null,p_description:e.description??null,p_spec:e.spec??null,p_links:e.links??null,p_agent:i()}))),n.registerTool(`remove_contract`,{title:`Remove something added to a resource`,description:`Remove a contract someone added that's wrong or gone: a deleted job, a retired variable. It's archived and stays in history. What sync found from code can't be removed here: change the code, or move it with move_contracts if it's filed in the wrong place.`,inputSchema:{contract:B().describe(`kind:name ("variable:OLD_KEY"), a unique name, or its id`),resource:B().optional(),inEnvironment:B().optional(),reason:B().optional().describe(`Why, for history`)}},a(e=>t.call(`remove_contract`,{...r,p_contract:e.contract,p_resource:e.resource??null,p_in_environment:e.inEnvironment??null,p_reason:e.reason??null,p_agent:i()}))),n.registerTool(`move_contracts`,{title:`Move what sync filed to another resource`,description:`Correct where sync filed a repo's tables (which database), endpoints (which API), deployments (which Cloud Run project), jobs, variables, functions, roles or models. Without names, all of the repo's ones of that kind move and later syncs put new ones there too. With names, only those move and sync leaves them there. list_resources shows what's filed where. For deployments in the wrong environment, setting the resource's account (update_resource) also fixes later syncs. With also, they're filed under this resource as well as where they are: the same endpoints served by the dev and the prod API.`,inputSchema:{repo:B().describe(`The repo they come from: name, URL or id`),kind:W([...Yb,`tables`,`endpoints`]),to:B().describe(`The resource they belong to: name, provider or id`),toEnvironment:B().optional().describe(`Its environment, when it exists in several`),names:H(B()).optional().describe(`Only these, e.g. ["bookings"] or ["GET /bookings"]; leave out to move all`),also:em().optional().describe(`Keep them where they are and file them here too, e.g. endpoints served in dev and in prod`)}},a(e=>t.call(`move_contracts`,{...r,p_repo:e.repo,p_kind:e.kind,p_to:e.to,p_in_environment:e.toEnvironment??null,p_names:e.names??null,p_also:e.also??!1,p_agent:i()}))),n.registerTool(`remove_repo`,{title:`Remove a repo`,description:"Remove a repo from the project, for admins: one that's retired, or was imported by mistake. Its dependencies, endpoints, tables and synced docs are archived with it, and it's unlinked from capabilities, tasks and resources. Sync skips it from then on; running `quirl init` in it adds it back. Only on the person's request: confirm with them first. To rename a repo instead, set its name in .quirl/project.json and sync.",inputSchema:{repo:B().describe(`The repo's name, URL or id`),reason:B().optional().describe(`Why it's removed, for history`)}},a(e=>t.call(`remove_repo`,{...r,p_repo:e.repo,p_reason:e.reason??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:em().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:B().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:B().describe(`Short name, e.g. 'Repeat appointments'`),description:B().describe(`What changes for the user, in plain words. Markdown: short paragraphs, and lists for parts`),capability:B().optional().describe(`Capability name or id (e.g. C-12) it changes. Leave it out when the feature creates a new capability`),tags:H(B()).optional().describe(`Kind of change: e.g. New, Improvement, Visual, Fix, Performance, Security, Removal, Internal (the feature_change set in quirl_context)`),reason:B().optional().describe(`Why it's worth doing`),icon:W(Lb).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:B().describe(`Feature name or id (e.g. F-4)`),icon:W(Lb)}},a(({feature:e,icon:n})=>t.call(`set_feature_icon`,{...r,p_feature:e,p_icon:n,p_agent:i()}))),n.registerTool(`update_feature`,{title:`Correct a feature`,description:`Fix a feature's name, description or the capability it changes, e.g. after requesting it with the wrong one. Only the fields you pass change; it shows in the feature's history. Tags: tag_feature; icon: set_feature_icon.`,inputSchema:{feature:B().describe(`Feature name or id (e.g. F-4)`),name:B().optional(),description:B().optional().describe(`What changes for the user, in plain words. Markdown: short paragraphs, and lists for parts`),capability:B().optional().describe(`The capability it changes (name or C-12), or "none" when it creates a new one`)}},a(({feature:e,name:n,description:a,capability:o})=>t.call(`update_feature`,{...r,p_feature:e,p_name:n??null,p_description:a??null,p_capability:o??null,p_agent:i()}))),n.registerTool(`withdraw_feature`,{title:`Withdraw a feature`,description:`Remove a feature that shouldn't be there: a duplicate, a mistake, or an idea dropped before any work. It's archived and stays in history. One that shipped can't be withdrawn; move or archive its tasks first (update_task, archive_task).`,inputSchema:{feature:B().describe(`Feature name or id (e.g. F-4)`),reason:B().optional().describe(`Why, for history`)}},a(({feature:e,reason:n})=>t.call(`withdraw_feature`,{...r,p_feature:e,p_reason:n??null,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:B().describe(`Feature name or id (e.g. F-4)`),tags:H(B()).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(`list_capabilities`,{title:`List the capabilities`,description:`Every capability as data: id (C-12), name, status, icon, the capability it's part of, what it does, what it relies on, its tags and the features changing it. Retired ones only with includeRetired.`,inputSchema:{includeRetired:em().optional()}},a(({includeRetired:e})=>t.call(`list_capabilities`,{...r,p_include_retired:e??!1}))),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:B().describe(`Short name, e.g. 'Online booking'`),whatItDoes:B().describe(`One or two plain sentences, no jargon`),technical:B().optional().describe(`Where it lives in the code and how it works. Markdown: short paragraphs, and lists for parts, not one long block`),features:H(B()).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:B().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:B().describe(`Capability name or id (e.g. C-12)`),reason:B().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 name or description for a capability when the code no longer matches it. A person approves it.`,inputSchema:{capability:B().describe(`Capability name or id (e.g. C-12)`),field:W([`name`,`what_it_does`,`technical_description`]),after:B().describe(`The new name, or the corrected text. Markdown: short paragraphs, and lists for parts, not one long block`),reason:B().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:B().describe(`Capability name or id (e.g. C-12)`),howItWorks:H(B()).optional().describe(`3 to 5 plain-language steps, as the user experiences it`),reliesOn:H(U({capability:B().describe(`Capability name or id (e.g. C-12)`),label:B().describe(`How it relies on it, read before the name, e.g. 'extends'`)})).optional(),parent:B().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:H(B()).optional().describe(`Repo names`),resources:H(B()).optional().describe(`Resource names it runs on`),terms:H(B()).optional().describe(`Glossary terms`),docs:H(B()).optional().describe(`Doc titles, or <repo>/<path> (e.g. quirl/AGENTS.md) when titles repeat`),tags:H(B()).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:B().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 tx(e){await ex(e).connect(new Mb)}const nx=`0.1.15`,rx=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 ix(){return{apiUrl:process.env.QUIRL_API_URL??rx.apiUrl,publishableKey:process.env.QUIRL_PUBLISHABLE_KEY??rx.publishableKey,appUrl:process.env.QUIRL_APP_URL??rx.appUrl}}const ax=()=>x(process.env.XDG_CONFIG_HOME??x(h(),`.config`),`quirl`),ox=()=>x(ax(),`credentials.json`);async function sx(){try{return JSON.parse(await u(ox(),`utf8`))}catch{return{}}}async function cx(){return process.env.QUIRL_KEY?{apiUrl:ix().apiUrl,key:process.env.QUIRL_KEY,email:``}:(await sx())[ix().apiUrl]??null}async function lx(e){let t=await sx();t[e.apiUrl]=e,await l(ax(),{recursive:!0,mode:448}),await m(ox(),`${JSON.stringify(t,null,` `)}\n`,{mode:384}),await s(ox(),384)}async function ux(){let e=await sx();delete e[ix().apiUrl],Object.keys(e).length?await m(ox(),`${JSON.stringify(e,null,` `)}\n`,{mode:384}):await f(ox(),{force:!0})}async function dx(){let e=ix();return{apiUrl:e.apiUrl,publishableKey:e.publishableKey,key:(await cx())?.key??``}}function fx(e){return(e.repos??[]).map(e=>typeof e==`string`?{path:e}:e)}function px(e=process.cwd()){try{return a(`git`,[`rev-parse`,`--show-toplevel`],{cwd:e,stdio:[`ignore`,`pipe`,`ignore`]}).toString().trim()}catch{return e}}const mx=e=>x(e,`.quirl`,`project.json`);async function hx(e=process.cwd()){let t=e;for(;;)try{return{root:t,link:JSON.parse(await u(mx(t),`utf8`))}}catch{let e=y(t);if(e===t)return null;t=e}}async function gx(e,t){await l(x(e,`.quirl`),{recursive:!0}),await m(mx(e),`${JSON.stringify(t,null,` `)}\n`)}function _x(e){let t=``;for(let n=0;n<e.length;n++){let r=e[n];r===`*`?e[n+1]===`*`?(t+=e[n+2]===`/`?`(?:.*/)?`:`.*`,n+=e[n+2]===`/`?2:1):t+=`[^/]*`:t+=r===`?`?`[^/]`:r.replace(/[.+^${}()|[\]\\]/g,`\\$&`)}return RegExp(`^${t}$`)}function vx(e){let t=[];for(let n of e.split(/\r?\n/)){let e=n.replace(/\s+$/,``);if(!e||e.startsWith(`#`))continue;let r=e.startsWith(`!`);r&&(e=e.slice(1));let i=e.endsWith(`/`);i&&(e=e.slice(0,-1));let a=e.includes(`/`);e=e.replace(/^\//,``);let o=_x(e).source.slice(1,-1);t.push({regex:RegExp(a?`^${o}$`:`^(?:.*/)?${o}$`),negate:r,dirOnly:i})}return t}function yx(e,t){if(!e.length)return!1;let n=t.split(`/`);for(let t=1;t<=n.length;t++){let r=n.slice(0,t).join(`/`),i=t<n.length,a=!1;for(let t of e)(!t.dirOnly||i)&&t.regex.test(r)&&(a=!t.negate);if(a)return!0}return!1}async function bx(e){try{return vx(await u(_.join(e,`.quirlignore`),`utf8`))}catch{return[]}}function xx(e,t){return new Promise(n=>{if(!t.length)return n(/* @__PURE__ */ new Set);i(`git`,[`check-ignore`,`--stdin`,`-z`],{cwd:e,maxBuffer:268435456,timeout:6e4},(e,t)=>n(new Set(String(t??``).split(`\0`).filter(Boolean)))).stdin?.end(`${t.join(`\0`)}\0`)})}const Sx=n(i),Cx=/* @__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`]),wx=1048576,Tx=2e5;async function Ex(e){let t=[],n=await bx(e),r=(await Ox(e,t)).filter(e=>!yx(n,e.path)),i=await xx(e,r.map(e=>e.path)),a=r.filter(e=>!i.has(e.path)),o=new Map(a.map(e=>[e.path,e]));return{root:e,files:a,warnings:t,file:e=>o.get(e),async readText(e,n=wx){if(e.size>n)return t.push(`${e.path}: skipped, ${Fx(e.size)} is over the ${Fx(n)} limit`),null;try{return await u(e.absolutePath,`utf8`)}catch(n){return t.push(`${e.path}: could not be read (${Nx(n)})`),null}}}}async function Dx(e,t){let n=[],r=await bx(e),{stdout:i}=await Sx(`git`,[`ls-tree`,`-r`,`-l`,`-z`,`--full-tree`,t],{cwd:e,maxBuffer:268435456,timeout:6e4}),a=[];for(let e of i.split(`\0`)){let t=e.indexOf(` `);if(t===-1)continue;let[i,o,s,c]=e.slice(0,t).trim().split(/\s+/),l=e.slice(t+1);if(o===`blob`&&i!==`120000`&&s&&!l.split(`/`).some(e=>Cx.has(e))&&!yx(r,l)){if(a.length>=Tx){n.push(`Stopped after ${Tx} files; the rest of the tree was not scanned`);break}a.push({path:l,absolutePath:s,size:Number(c)||0})}}kx(a);let o=new Map(a.map(e=>[e.path,e]));return{root:e,files:a,warnings:n,file:e=>o.get(e),async readText(t,r=wx){if(t.size>r)return n.push(`${t.path}: skipped, ${Fx(t.size)} is over the ${Fx(r)} limit`),null;try{let{stdout:n}=await Sx(`git`,[`cat-file`,`blob`,t.absolutePath],{cwd:e,maxBuffer:r+1024,timeout:3e4});return n}catch(e){return n.push(`${t.path}: could not be read (${Nx(e)})`),null}}}}async function Ox(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 (${Nx(e)})`);continue}for(let o of a){let a=i?`${i}/${o.name}`:o.name;if(o.isSymbolicLink())continue;if(o.isDirectory()){!Cx.has(o.name)&&!C(_.join(e,a,`.git`))&&r.push(a);continue}if(!o.isFile())continue;if(n.length>=Tx)return t.push(`Stopped after ${Tx} files; the rest of the tree was not scanned`),kx(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 (${Nx(e)})`)}}}return kx(n)}function kx(e){return e.sort((e,t)=>e.path<t.path?-1:+(e.path>t.path))}function Ax(e){let t=e.lastIndexOf(`/`);return t===-1?e:e.slice(t+1)}function jx(e){let t=e.lastIndexOf(`/`);return t===-1?``:e.slice(0,t)}function Mx(e,t){return e?`${e}/${t}`:t}function Nx(e){return Kr(e instanceof Error?e.message:String(e))}function Z(e){return typeof e==`object`&&!!e&&!Array.isArray(e)}function Px(e){return typeof e==`string`?e:void 0}function Fx(e){return e>=1048576?`${(e/1048576).toFixed(1)} MB`:`${Math.ceil(e/1024)} KB`}const Ix=(e,t)=>{let n=e.split(`.`).map(Number),r=t.split(`.`).map(Number);for(let e=0;e<3;e++)if((n[e]??0)!==(r[e]??0))return(n[e]??0)>(r[e]??0);return!1};async function Lx(){try{let e=await fetch(`https://registry.npmjs.org/quirl-cli/latest`,{signal:AbortSignal.timeout(1500)});if(!e.ok)return null;let{version:t}=await e.json();return t&&Ix(t,`0.1.15`)?t:null}catch{return null}}const Rx=e=>`These Quirl tools are version ${nx}; ${e} is out, so some tools or options may be missing (for example resource types, or kinds move_contracts takes). Tell the person: run \`npx quirl-cli@latest init\` in this repo, then restart Claude Code.`;async function zx({hook:e=!1}={}){let t=await hx();if(!t){if(e)return;throw Error("This folder isn't linked to a Quirl project. Run `quirl init`.")}try{let[n,r]=await Promise.all([new Wr(await dx()).context(t.link.projectId),Lx()]),i=r?`${Rx(r)}\n\n`:``;process.stdout.write(`${i}${zb(n,e?9500-i.length:void 0)}\n`)}catch(n){if(!e)throw n;process.stdout.write(`Quirl project "${t.link.name}": couldn't load the briefing (${Nx(n)}). The quirl MCP tools may still work.\n`)}}const Bx=process.stdout.isTTY&&!process.env.NO_COLOR,Vx=e=>t=>Bx?`\x1b[${e}m${t}\x1b[0m`:t,Hx=Vx(1),Q=Vx(2),Ux=Vx(32),Wx=Vx(31),Gx=Vx(36),Kx=e=>console.log(`${Ux(`✓`)} ${e}`),qx=e=>console.log(` ${e}`),Jx=(e,t)=>console.log(`\n${e} ${t}`),Yx=e=>console.log(` ${e}`);function Xx(e){if(!Bx)return Yx(Q(e)),{stop:()=>{}};let t=0,n=setInterval(()=>{process.stdout.write(`\r ${Gx(`⠋⠙⠹⠸⠼⠴⠦⠧⠇⠏`[t++%10]??``)} ${Q(e)}`)},80);return{stop:()=>{clearInterval(n),process.stdout.write(`\r\x1B[2K`)}}}var Zx=class extends Error{};async function Qx(e,t=``){if(!process.stdin.isTTY)return t;let n=w({input:process.stdin,output:process.stdout});try{return(await n.question(e)).trim()||t}finally{n.close()}}async function $x(e,t){let n=await Qx(`${e} ${Q(t?`[Y/n]`:`[y/N]`)} `,t?`y`:`n`);return/^y/i.test(n)}function eS(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 tS=`.quirl-export.json`,nS=e=>e.toLowerCase().normalize(`NFKD`).replace(/[̀-ͯ]/g,``).replace(/[^a-z0-9]+/g,`-`).replace(/^-+|-+$/g,``).slice(0,80)||`untitled`;function rS(e){return`---\n${[[`title`,e.title],[`type`,e.type],[`status`,e.status],[`source`,e.source],[`alwaysLoad`,e.alwaysLoad],[`id`,e.id],[`created`,e.createdAt],[`updated`,e.updatedAt]].map(([e,t])=>`${e}: ${JSON.stringify(t)}`).join(`
|
|
214
|
+
- model (AI): modelId*, usedFor, settings, calledFrom (file paths)`,Qb=H(U({relation:W(Xb),to:B().describe(`"endpoint:GET /domains", "variable:STRIPE_KEY", "resource:<name>" or "repo:<name>"`)})).describe(`Links, as [{relation, to}]. relation: runs (deployment → repo), serves (deployment → API resource or endpoint), calls (job/function/deployment → endpoint, function or model), uses (→ variable, model or resource), protects (role → table, endpoint or function), triggers (event → endpoint, job or function), sends_to (→ queue or resource). to: a contract as kind:name ("endpoint:GET /domains", "variable:STRIPE_KEY"), "resource:<name>" or "repo:<name>".`),$b={resource:B().describe(`The resource's name, provider or id (from list_resources)`),inEnvironment:B().optional().describe(`Its current environment, when the same resource exists in several`)};function ex(e){let t=new Wr(e),n=new yb({name:`quirl`,version:e.version},{instructions:e.notice?`${e.notice}\n\n${Kb}`:Kb}),r={p_project:e.project},i=()=>({tool:n.server.getClientVersion()?.name??`mcp`,model:process.env.QUIRL_AGENT_MODEL}),a=e=>async t=>{try{return qb(await e(t))}catch(e){if(e instanceof Ur)return{...qb(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()=>zb(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:B().describe(`Words to search for, e.g. 'refund approval limits'`),limit:V().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. source says where it lives: 'quirl' for docs written in Quirl (editable with edit_doc), otherwise the repo or folder it's synced from.`,inputSchema:{doc:B().describe(`Doc id, title or path, e.g. 'docs/adr/004-queues.md'`)}},a(({doc:e})=>t.call(`read_doc`,{...r,p_doc:e})));let o=[`product`,`guideline`,`architecture`,`decision`,`how_to`,`reference`];n.registerTool(`create_doc`,{title:`Write a new doc`,description:`Write a doc in Quirl itself: a PRD, spec or product note with no file behind it. Docs about code that tests or builds rely on belong in their repo, where sync picks them up. Use product for PRDs and specs. Never include secret values.`,inputSchema:{title:B(),body:B().describe(`Markdown. Headings (##, ###) split it into sections edit_doc can change one at a time.`),type:W(o).optional().describe(`Defaults to reference`)}},a(({title:e,body:n,type:a})=>t.call(`create_doc`,{...r,p_title:e,p_body:n,p_type:a??`reference`,p_agent:i()}))),n.registerTool(`edit_doc`,{title:`Edit a doc written in Quirl`,description:`Change one section of a doc written in Quirl, or the whole doc, without rewriting the rest. A section is named by its heading, or by its path when a heading repeats ('Billing > Refunds'). replace swaps the section's text (keeping its heading, unless the new text starts with one); append adds to the end of it. Without a section, replace rewrites the doc and append adds to its end. Docs synced from a repo or folder are changed there instead. The edit fails if the doc changed since it was read, rather than overwriting that change.`,inputSchema:{doc:B().describe(`Doc id or title`),section:B().optional().describe(`Heading text or path, e.g. 'Scope' or 'Billing > Refunds'`),content:B().describe(`Markdown`),mode:W([`replace`,`append`]).optional().describe(`Defaults to replace`),title:B().optional().describe(`A new title for the doc`),type:W(o).optional()}},a(async({doc:e,section:n,content:a,mode:o,title:s,type:c})=>{let l=await t.call(`read_doc`,{...r,p_doc:e});if(!l.editable)throw new Ur(`"${l.title}" comes from ${l.source}. Change it there; sync brings it into Quirl.`);let u;try{u=Gb(l.body,n,a,o??`replace`)}catch(e){throw new Ur(e.message)}return{...await t.call(`update_doc`,{...r,p_doc:l.id,p_title:s??null,p_body:u,p_type:c??null,p_expected_hash:l.contentHash,p_agent:i()}),edited:n??`the whole doc`,sections:Hb(u)}})),n.registerTool(`doc_history`,{title:`A doc's history`,description:`Who changed a doc and when, newest first, with lines added and removed. Pass a version to see what it changed (a diff against the version before), or full to get that version's whole text, e.g. to bring back wording with edit_doc.`,inputSchema:{doc:B().describe(`Doc id or title`),version:V().int().optional(),full:em().optional().describe(`With version: its whole text instead of the diff`)}},a(async({doc:e,version:n,full:i})=>{let a=await t.call(`doc_history`,{...r,p_doc:e,p_limit:n?200:21}),o=a.versions,s=e=>o.find(t=>t.version===e-1);if(n){let e=o.find(e=>e.version===n);if(!e)throw new Ur(`"${a.title}" has no version ${n}; the latest is ${o[0]?.version??0}.`);if(i)return{version:n,title:e.title,body:e.body};let t=s(n);return{version:n,author:e.author??`unknown`,at:e.createdAt,...t&&t.title!==e.title?{renamed:`${t.title} → ${e.title}`}:{},diff:t?Ib(t.body,e.body)||`(no text changes)`:`(first version)`}}return{title:a.title,source:a.source,versions:o.slice(0,20).map(e=>{let t=s(e.version);return{version:e.version,author:e.author??`unknown`,at:e.createdAt,change:t?Pb(Nb(t.body,e.body)):`first version`}})}})),n.registerTool(`archive_doc`,{title:`Archive a doc written in Quirl`,description:`Remove a doc written in Quirl that's no longer true or was a mistake. It's archived and stays in history. Docs synced from a repo or folder are deleted there instead.`,inputSchema:{doc:B().describe(`Doc id or title`),reason:B().optional().describe(`Why, for history`)}},a(({doc:e,reason:n})=>t.call(`archive_doc`,{...r,p_doc:e,p_reason:n??null,p_agent:i()}))),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:B().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 s=(e,t,r,i)=>{n.registerTool(e,r,i),n.registerTool(t,{...r,description:`Old name for ${e}; use ${e}. ${r.description}`},i)};s(`list_tasks`,`list_cards`,{title:`List tasks`,description:`List tasks on the board. Defaults to your own tasks that aren't done.`,inputSchema:{onlyMine:em().optional(),includeDone:em().optional()}},a(({onlyMine:e,includeDone:n})=>t.call(`list_cards`,{...r,p_only_mine:e??!0,p_include_done:n??!1})));let c=`Markdown: short paragraphs, and lists for steps or parts, not one long block.`,l=`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).`,u=B().describe(`Task number, e.g. 'K-104' or '104'`),d=B().optional().describe(`Who does it: "me", a member's email or name (only people on the project), or "none"`);return s(`get_task`,`get_card`,{title:`Get a task`,description:`A task with its feature, docs, dependencies and evidence.`,inputSchema:{task:u.optional(),card:u.optional()}},a(({task:e,card:n})=>t.call(`get_card`,{...r,p_card:e??n}))),s(`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:B(),description:B().optional().describe(`What to do and why. ${c}`),type:W([`feature_work`,`bug`,`chore`,`research`]).optional(),feature:B().optional().describe(`Feature name or id (e.g. F-4) this task belongs to`),tags:H(B()).optional().describe(l),assignee:d.describe(`Who does it: "me" (the default), a member's email or name, or "none"`)}},a(async({title:e,description:n,type:a,feature:o,tags:s,assignee:c})=>{let l=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||c)&&await t.call(`update_card`,{...r,p_card:l,p_patch:{...s?.length?{tags:s}:{},...c?{assignee:c}:{}},p_agent:i()}),l})),s(`update_task`,`update_card`,{title:`Update a task`,description:`Move a task, mark it blocked (with a reason) or unblocked, assign it, 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:u.optional(),card:u.optional(),assignee:d,status:W([`backlog`,`todo`,`in_progress`,`review`,`done`]).optional(),feature:B().optional().describe(`Feature name or id (e.g. F-4) to put the task under; an empty string takes it off its feature`),title:B().optional(),description:B().optional().describe(`Replaces the description. ${c}`),tags:H(B()).optional().describe(`${l} Replaces the current tags.`),blocked:em().optional(),blockedReason:B().optional(),addBranch:U({repo:B(),name:B()}).optional(),addCommit:U({repo:B(),sha:B(),message:B().optional()}).optional(),addPullRequest:U({repo:B(),number:V().int(),url:B(),state:W([`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(`archive_task`,{title:`Archive a task`,description:`Remove a task that shouldn't be there: a duplicate or a mistake. It's archived and stays in history, and its feature's status is worked out without it. For work that's finished, move it to done instead.`,inputSchema:{task:u,reason:B().optional().describe(`Why, for history`)}},a(({task:e,reason:n})=>t.call(`archive_card`,{...r,p_card:e,p_reason:n??null,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:B(),plain:B().describe(`What it means, for someone non-technical`),technical:B().describe(`What it means in the code`),kind:W([`concept`,`tag`,`name`]).optional(),aliases:H(B()).optional().describe(`Other names people use for it, e.g. "Strategy Lab", "DSL". None may already name another term.`),tagSet:B().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:B().optional()}},a(({term:e,plain:n,technical:a,kind:o,tagSet:s,aliases:c,reason:l})=>t.call(`propose_term`,{...r,p_term:e,p_plain:n,p_technical:a,p_kind:o??`concept`,p_tag_set:s??null,p_aliases:c??null,p_reason:l??null,p_agent:i()}))),n.registerTool(`propose_term_update`,{title:`Propose a glossary term correction`,description:`Suggest a corrected name, plain definition or technical definition for an existing glossary term, when it's wrong or the code no longer matches it. A renamed term keeps its old name as an alias. For other names people use, use propose_term_aliases; to stop using a term, propose_term_retire. A person approves it.`,inputSchema:{term:B().describe(`The term, by its name or one of its aliases`),field:W([`term`,`plain`,`technical`]).describe(`term: its name; plain: what it means for someone non-technical; technical: what it means in the code`),after:B().describe(`The new name, or the corrected definition`),reason:B().optional()}},a(e=>t.call(`propose_term_update`,{...r,p_term:e.term,p_field:e.field,p_after:e.after,p_reason:e.reason??null,p_agent:i()}))),n.registerTool(`propose_term_aliases`,{title:`Propose other names for a term`,description:`Add or remove the other names people use for a glossary term ("Strategy Lab" and "DSL" for Domain Strategy Lab). Agents then understand them, while code and titles keep the term itself. A name can't already belong to another term: then the terms clash, and a person sorts it out. A person approves the change.`,inputSchema:{term:B().describe(`The term, by its name or one of its aliases`),add:H(B()).optional(),remove:H(B()).optional(),reason:B().optional().describe(`Where it's used, e.g. "the ticket and the standup notes say Strategy Lab"`)}},a(e=>t.call(`propose_term_aliases`,{...r,p_term:e.term,p_add:e.add??null,p_remove:e.remove??null,p_reason:e.reason??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:B().describe(`The term or tag to retire`),replaceWith:B().optional().describe(`An approved term to say instead, if there is one`),reason:B().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:W([`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:B().describe(`The flag's id, from the briefing or list_flags`),decision:W([`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:B().describe(`The flag's id, from the briefing or list_flags`),note:B().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:B().describe(`Capability name or id (e.g. C-12)`),icon:W(Lb)}},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:B().describe(`What the team calls it, e.g. "Postgres", "Stripe"`),type:W(Jb),provider:B().optional().describe(`Who runs it, e.g. "Google Cloud SQL", "Stripe". Resources are matched on this. Defaults to the name.`),description:B().optional().describe(`One plain sentence on what the project uses it for`),technical:B().optional().describe(`Technical notes for developers: setup, access, limits`),environment:B().optional().describe(`Defaults to "production"; e.g. "staging"`),repos:H(B()).optional().describe(`Repos that use it, by name`),capabilities:H(B()).optional().describe(`Capabilities that run on it, by name or id (e.g. C-12)`),account:B().optional().describe(`The cloud project, account or team it lives in, e.g. GCP project "domainarium-staging". Sync files deployments, jobs and secrets by it. Never a key.`)}},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_account:e.account??null,p_agent:i()}))),n.registerTool(`list_resources`,{title:`List the project's resources`,description:`Every resource on Stack: name, type, provider, environment, whether sync found it or someone added it, the repos that use it, the capabilities that run on it, and the tables and endpoints filed under it (per repo, with a few names). Tables in the wrong database or endpoints under the wrong API: fix with move_contracts.`,inputSchema:{}},a(()=>t.call(`list_resources`,r))),n.registerTool(`update_resource`,{title:`Change a resource`,description:`Correct a resource: rename it, relabel its environment (a scanned one that's really the local docker database becomes 'local'), or change its type, provider, descriptions or links. Only the fields you pass change. repos and capabilities replace its links; use add_resource to add to them. A repo you take off stays off: sync won't link it again until a person adds it back. Sync keeps updating a relabelled resource instead of adding it again. Never pass secret values.`,inputSchema:{...$b,name:B().optional(),type:W(Jb).optional(),provider:B().optional(),environment:B().optional().describe(`e.g. "production", "staging", "dev", "local"`),description:B().optional().describe(`One plain sentence on what the project uses it for`),technical:B().optional().describe(`Notes for developers`),repos:H(B()).optional().describe(`Replaces the repos that use it. Ones left out stay off through later syncs.`),capabilities:H(B()).optional().describe(`Replaces the capabilities that run on it (names or C-12)`),account:B().optional().describe(`The cloud project, account or team it lives in, e.g. GCP project "domainarium-staging". Sync files deployments, jobs and secrets by it. Never a key. Empty clears it.`)}},a(e=>t.call(`update_resource`,{...r,p_resource:e.resource,p_in_environment:e.inEnvironment??null,p_name:e.name??null,p_type:e.type??null,p_provider:e.provider??null,p_environment:e.environment??null,p_description:e.description??null,p_technical:e.technical??null,p_repos:e.repos??null,p_capabilities:e.capabilities??null,p_account:e.account??null,p_agent:i()}))),n.registerTool(`remove_resource`,{title:`Remove a wrong resource`,description:`Remove a resource that isn't one: a false match from sync, a duplicate, something no longer used. It's archived, stays in history, and sync won't add it again. A resource holding endpoints or tables from sync can't be removed; relabel it instead.`,inputSchema:{...$b,reason:B().optional().describe(`Why it's wrong, for history`)}},a(e=>t.call(`remove_resource`,{...r,p_resource:e.resource,p_in_environment:e.inEnvironment??null,p_reason:e.reason??null,p_agent:i()}))),n.registerTool(`get_resource`,{title:`Get a resource and what it holds`,description:`One resource with everything it holds: endpoints, tables, functions, deployments, variables (names only), jobs, domains, events, roles, models. Each with its fields (spec), whether sync found it or someone added it, and its links (what it runs, calls, uses or protects, and what points at it). Use before adding or changing what a resource holds.`,inputSchema:$b},a(e=>t.call(`get_resource`,{...r,p_resource:e.resource,p_in_environment:e.inEnvironment??null}))),n.registerTool(`add_contract`,{title:`Add something a resource holds`,description:`Record what the code doesn't show: a Cloud Scheduler job set up in the console, the variables Secret Manager holds (names, never values), a Cloud Run service, the roles the product has, the AI models it calls, a webhook it receives, a domain. Sync finds endpoints and tables from OpenAPI files and migrations, so check get_resource first. What you add stays until someone removes it; if sync later finds the same thing in code, it takes it over. Never pass secret values, keys or URLs with credentials.\n\n${Zb}`,inputSchema:{...$b,kind:W(Yb),name:B().optional().describe(`e.g. "nightly-invoices", "STRIPE_SECRET_KEY", "admin", "claude-opus-5-5". Endpoints default to "METHOD /path".`),description:B().optional().describe(`One plain sentence: what it is or does`),spec:_m(B(),im()).optional().describe(`The kind's fields; see the list above`),repo:B().optional().describe(`The repo it belongs to, if any`),links:Qb.optional()}},a(e=>t.call(`add_contract`,{...r,p_resource:e.resource,p_in_environment:e.inEnvironment??null,p_kind:e.kind,p_name:e.name??null,p_description:e.description??null,p_spec:e.spec??null,p_repo:e.repo??null,p_links:e.links??null,p_agent:i()}))),n.registerTool(`update_contract`,{title:`Change something a resource holds`,description:`Correct or fill in a contract: its description, its fields, its links. spec is merged: given fields are set, a field set to null is removed. links, when given, replace the links people added (sync's stay). On something sync found (an endpoint from OpenAPI, a table from migrations) only the description and links change here; the rest follows the code. To file it under another resource, use move_contracts.\n\n${Zb}`,inputSchema:{contract:B().describe(`kind:name ("job:nightly-invoices", "endpoint:GET /domains"), a unique name, or its id (from get_resource)`),resource:B().optional().describe(`Its resource, when the name is in several`),inEnvironment:B().optional(),name:B().optional(),description:B().optional(),spec:_m(B(),im()).optional(),links:Qb.optional()}},a(e=>t.call(`update_contract`,{...r,p_contract:e.contract,p_resource:e.resource??null,p_in_environment:e.inEnvironment??null,p_name:e.name??null,p_description:e.description??null,p_spec:e.spec??null,p_links:e.links??null,p_agent:i()}))),n.registerTool(`remove_contract`,{title:`Remove something added to a resource`,description:`Remove a contract someone added that's wrong or gone: a deleted job, a retired variable. It's archived and stays in history. What sync found from code can't be removed here: change the code, or move it with move_contracts if it's filed in the wrong place.`,inputSchema:{contract:B().describe(`kind:name ("variable:OLD_KEY"), a unique name, or its id`),resource:B().optional(),inEnvironment:B().optional(),reason:B().optional().describe(`Why, for history`)}},a(e=>t.call(`remove_contract`,{...r,p_contract:e.contract,p_resource:e.resource??null,p_in_environment:e.inEnvironment??null,p_reason:e.reason??null,p_agent:i()}))),n.registerTool(`move_contracts`,{title:`Move what sync filed to another resource`,description:`Correct where sync filed a repo's tables (which database), endpoints (which API), deployments (which Cloud Run project), jobs, variables, functions, roles or models. Without names, all of the repo's ones of that kind move and later syncs put new ones there too. With names, only those move and sync leaves them there. list_resources shows what's filed where. For deployments in the wrong environment, setting the resource's account (update_resource) also fixes later syncs. With also, they're filed under this resource as well as where they are: the same endpoints served by the dev and the prod API.`,inputSchema:{repo:B().describe(`The repo they come from: name, URL or id`),kind:W([...Yb,`tables`,`endpoints`]),to:B().describe(`The resource they belong to: name, provider or id`),toEnvironment:B().optional().describe(`Its environment, when it exists in several`),names:H(B()).optional().describe(`Only these, e.g. ["bookings"] or ["GET /bookings"]; leave out to move all`),also:em().optional().describe(`Keep them where they are and file them here too, e.g. endpoints served in dev and in prod`)}},a(e=>t.call(`move_contracts`,{...r,p_repo:e.repo,p_kind:e.kind,p_to:e.to,p_in_environment:e.toEnvironment??null,p_names:e.names??null,p_also:e.also??!1,p_agent:i()}))),n.registerTool(`remove_repo`,{title:`Remove a repo`,description:"Remove a repo from the project, for admins: one that's retired, or was imported by mistake. Its dependencies, endpoints, tables and synced docs are archived with it, and it's unlinked from capabilities, tasks and resources. Sync skips it from then on; running `quirl init` in it adds it back. Only on the person's request: confirm with them first. To rename a repo instead, set its name in .quirl/project.json and sync.",inputSchema:{repo:B().describe(`The repo's name, URL or id`),reason:B().optional().describe(`Why it's removed, for history`)}},a(e=>t.call(`remove_repo`,{...r,p_repo:e.repo,p_reason:e.reason??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:em().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:B().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:B().describe(`Short name, e.g. 'Repeat appointments'`),description:B().describe(`What changes for the user, in plain words. Markdown: short paragraphs, and lists for parts`),capability:B().optional().describe(`Capability name or id (e.g. C-12) it changes. Leave it out when the feature creates a new capability`),tags:H(B()).optional().describe(`Kind of change: e.g. New, Improvement, Visual, Fix, Performance, Security, Removal, Internal (the feature_change set in quirl_context)`),reason:B().optional().describe(`Why it's worth doing`),icon:W(Lb).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:B().describe(`Feature name or id (e.g. F-4)`),icon:W(Lb)}},a(({feature:e,icon:n})=>t.call(`set_feature_icon`,{...r,p_feature:e,p_icon:n,p_agent:i()}))),n.registerTool(`update_feature`,{title:`Correct a feature`,description:`Fix a feature's name, description or the capability it changes, e.g. after requesting it with the wrong one. Only the fields you pass change; it shows in the feature's history. Tags: tag_feature; icon: set_feature_icon.`,inputSchema:{feature:B().describe(`Feature name or id (e.g. F-4)`),name:B().optional(),description:B().optional().describe(`What changes for the user, in plain words. Markdown: short paragraphs, and lists for parts`),capability:B().optional().describe(`The capability it changes (name or C-12), or "none" when it creates a new one`)}},a(({feature:e,name:n,description:a,capability:o})=>t.call(`update_feature`,{...r,p_feature:e,p_name:n??null,p_description:a??null,p_capability:o??null,p_agent:i()}))),n.registerTool(`withdraw_feature`,{title:`Withdraw a feature`,description:`Remove a feature that shouldn't be there: a duplicate, a mistake, or an idea dropped before any work. It's archived and stays in history. One that shipped can't be withdrawn; move or archive its tasks first (update_task, archive_task).`,inputSchema:{feature:B().describe(`Feature name or id (e.g. F-4)`),reason:B().optional().describe(`Why, for history`)}},a(({feature:e,reason:n})=>t.call(`withdraw_feature`,{...r,p_feature:e,p_reason:n??null,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:B().describe(`Feature name or id (e.g. F-4)`),tags:H(B()).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(`list_capabilities`,{title:`List the capabilities`,description:`Every capability as data: id (C-12), name, status, icon, the capability it's part of, what it does, what it relies on, its tags and the features changing it. Retired ones only with includeRetired.`,inputSchema:{includeRetired:em().optional()}},a(({includeRetired:e})=>t.call(`list_capabilities`,{...r,p_include_retired:e??!1}))),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:B().describe(`Short name, e.g. 'Online booking'`),whatItDoes:B().describe(`One or two plain sentences, no jargon`),technical:B().optional().describe(`Where it lives in the code and how it works. Markdown: short paragraphs, and lists for parts, not one long block`),features:H(B()).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:B().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:B().describe(`Capability name or id (e.g. C-12)`),reason:B().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 name or description for a capability when the code no longer matches it. A person approves it.`,inputSchema:{capability:B().describe(`Capability name or id (e.g. C-12)`),field:W([`name`,`what_it_does`,`technical_description`]),after:B().describe(`The new name, or the corrected text. Markdown: short paragraphs, and lists for parts, not one long block`),reason:B().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:B().describe(`Capability name or id (e.g. C-12)`),howItWorks:H(B()).optional().describe(`3 to 5 plain-language steps, as the user experiences it`),reliesOn:H(U({capability:B().describe(`Capability name or id (e.g. C-12)`),label:B().describe(`How it relies on it, read before the name, e.g. 'extends'`)})).optional(),parent:B().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:H(B()).optional().describe(`Repo names`),resources:H(B()).optional().describe(`Resource names it runs on`),terms:H(B()).optional().describe(`Glossary terms`),docs:H(B()).optional().describe(`Doc titles, or <repo>/<path> (e.g. quirl/AGENTS.md) when titles repeat`),tags:H(B()).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:B().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 tx(e){await ex(e).connect(new Mb)}const nx=`0.1.16`,rx=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 ix(){return{apiUrl:process.env.QUIRL_API_URL??rx.apiUrl,publishableKey:process.env.QUIRL_PUBLISHABLE_KEY??rx.publishableKey,appUrl:process.env.QUIRL_APP_URL??rx.appUrl}}const ax=()=>x(process.env.XDG_CONFIG_HOME??x(h(),`.config`),`quirl`),ox=()=>x(ax(),`credentials.json`);async function sx(){try{return JSON.parse(await u(ox(),`utf8`))}catch{return{}}}async function cx(){return process.env.QUIRL_KEY?{apiUrl:ix().apiUrl,key:process.env.QUIRL_KEY,email:``}:(await sx())[ix().apiUrl]??null}async function lx(e){let t=await sx();t[e.apiUrl]=e,await l(ax(),{recursive:!0,mode:448}),await m(ox(),`${JSON.stringify(t,null,` `)}\n`,{mode:384}),await s(ox(),384)}async function ux(){let e=await sx();delete e[ix().apiUrl],Object.keys(e).length?await m(ox(),`${JSON.stringify(e,null,` `)}\n`,{mode:384}):await f(ox(),{force:!0})}async function dx(){let e=ix();return{apiUrl:e.apiUrl,publishableKey:e.publishableKey,key:(await cx())?.key??``}}function fx(e){return(e.repos??[]).map(e=>typeof e==`string`?{path:e}:e)}function px(e=process.cwd()){try{return a(`git`,[`rev-parse`,`--show-toplevel`],{cwd:e,stdio:[`ignore`,`pipe`,`ignore`]}).toString().trim()}catch{return e}}const mx=e=>x(e,`.quirl`,`project.json`);async function hx(e=process.cwd()){let t=e;for(;;)try{return{root:t,link:JSON.parse(await u(mx(t),`utf8`))}}catch{let e=y(t);if(e===t)return null;t=e}}async function gx(e,t){await l(x(e,`.quirl`),{recursive:!0}),await m(mx(e),`${JSON.stringify(t,null,` `)}\n`)}function _x(e){let t=``;for(let n=0;n<e.length;n++){let r=e[n];r===`*`?e[n+1]===`*`?(t+=e[n+2]===`/`?`(?:.*/)?`:`.*`,n+=e[n+2]===`/`?2:1):t+=`[^/]*`:t+=r===`?`?`[^/]`:r.replace(/[.+^${}()|[\]\\]/g,`\\$&`)}return RegExp(`^${t}$`)}function vx(e){let t=[];for(let n of e.split(/\r?\n/)){let e=n.replace(/\s+$/,``);if(!e||e.startsWith(`#`))continue;let r=e.startsWith(`!`);r&&(e=e.slice(1));let i=e.endsWith(`/`);i&&(e=e.slice(0,-1));let a=e.includes(`/`);e=e.replace(/^\//,``);let o=_x(e).source.slice(1,-1);t.push({regex:RegExp(a?`^${o}$`:`^(?:.*/)?${o}$`),negate:r,dirOnly:i})}return t}function yx(e,t){if(!e.length)return!1;let n=t.split(`/`);for(let t=1;t<=n.length;t++){let r=n.slice(0,t).join(`/`),i=t<n.length,a=!1;for(let t of e)(!t.dirOnly||i)&&t.regex.test(r)&&(a=!t.negate);if(a)return!0}return!1}async function bx(e){try{return vx(await u(_.join(e,`.quirlignore`),`utf8`))}catch{return[]}}function xx(e,t){return new Promise(n=>{if(!t.length)return n(/* @__PURE__ */ new Set);i(`git`,[`check-ignore`,`--stdin`,`-z`],{cwd:e,maxBuffer:268435456,timeout:6e4},(e,t)=>n(new Set(String(t??``).split(`\0`).filter(Boolean)))).stdin?.end(`${t.join(`\0`)}\0`)})}const Sx=n(i),Cx=/* @__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`]),wx=1048576,Tx=2e5;async function Ex(e){let t=[],n=await bx(e),r=(await Ox(e,t)).filter(e=>!yx(n,e.path)),i=await xx(e,r.map(e=>e.path)),a=r.filter(e=>!i.has(e.path)),o=new Map(a.map(e=>[e.path,e]));return{root:e,files:a,warnings:t,file:e=>o.get(e),async readText(e,n=wx){if(e.size>n)return t.push(`${e.path}: skipped, ${Fx(e.size)} is over the ${Fx(n)} limit`),null;try{return await u(e.absolutePath,`utf8`)}catch(n){return t.push(`${e.path}: could not be read (${Nx(n)})`),null}}}}async function Dx(e,t){let n=[],r=await bx(e),{stdout:i}=await Sx(`git`,[`ls-tree`,`-r`,`-l`,`-z`,`--full-tree`,t],{cwd:e,maxBuffer:268435456,timeout:6e4}),a=[];for(let e of i.split(`\0`)){let t=e.indexOf(` `);if(t===-1)continue;let[i,o,s,c]=e.slice(0,t).trim().split(/\s+/),l=e.slice(t+1);if(o===`blob`&&i!==`120000`&&s&&!l.split(`/`).some(e=>Cx.has(e))&&!yx(r,l)){if(a.length>=Tx){n.push(`Stopped after ${Tx} files; the rest of the tree was not scanned`);break}a.push({path:l,absolutePath:s,size:Number(c)||0})}}kx(a);let o=new Map(a.map(e=>[e.path,e]));return{root:e,files:a,warnings:n,file:e=>o.get(e),async readText(t,r=wx){if(t.size>r)return n.push(`${t.path}: skipped, ${Fx(t.size)} is over the ${Fx(r)} limit`),null;try{let{stdout:n}=await Sx(`git`,[`cat-file`,`blob`,t.absolutePath],{cwd:e,maxBuffer:r+1024,timeout:3e4});return n}catch(e){return n.push(`${t.path}: could not be read (${Nx(e)})`),null}}}}async function Ox(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 (${Nx(e)})`);continue}for(let o of a){let a=i?`${i}/${o.name}`:o.name;if(o.isSymbolicLink())continue;if(o.isDirectory()){!Cx.has(o.name)&&!C(_.join(e,a,`.git`))&&r.push(a);continue}if(!o.isFile())continue;if(n.length>=Tx)return t.push(`Stopped after ${Tx} files; the rest of the tree was not scanned`),kx(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 (${Nx(e)})`)}}}return kx(n)}function kx(e){return e.sort((e,t)=>e.path<t.path?-1:+(e.path>t.path))}function Ax(e){let t=e.lastIndexOf(`/`);return t===-1?e:e.slice(t+1)}function jx(e){let t=e.lastIndexOf(`/`);return t===-1?``:e.slice(0,t)}function Mx(e,t){return e?`${e}/${t}`:t}function Nx(e){return Kr(e instanceof Error?e.message:String(e))}function Z(e){return typeof e==`object`&&!!e&&!Array.isArray(e)}function Px(e){return typeof e==`string`?e:void 0}function Fx(e){return e>=1048576?`${(e/1048576).toFixed(1)} MB`:`${Math.ceil(e/1024)} KB`}const Ix=(e,t)=>{let n=e.split(`.`).map(Number),r=t.split(`.`).map(Number);for(let e=0;e<3;e++)if((n[e]??0)!==(r[e]??0))return(n[e]??0)>(r[e]??0);return!1};async function Lx(){try{let e=await fetch(`https://registry.npmjs.org/quirl-cli/latest`,{signal:AbortSignal.timeout(1500)});if(!e.ok)return null;let{version:t}=await e.json();return t&&Ix(t,`0.1.16`)?t:null}catch{return null}}const Rx=e=>`These Quirl tools are version ${nx}; ${e} is out, so some tools or options may be missing (for example resource types, or kinds move_contracts takes). Tell the person: run \`npx quirl-cli@latest init\` in this repo, then restart Claude Code.`;async function zx({hook:e=!1}={}){let t=await hx();if(!t){if(e)return;throw Error("This folder isn't linked to a Quirl project. Run `quirl init`.")}try{let[n,r]=await Promise.all([new Wr(await dx()).context(t.link.projectId),Lx()]),i=r?`${Rx(r)}\n\n`:``;process.stdout.write(`${i}${zb(n,e?9500-i.length:void 0)}\n`)}catch(n){if(!e)throw n;process.stdout.write(`Quirl project "${t.link.name}": couldn't load the briefing (${Nx(n)}). The quirl MCP tools may still work.\n`)}}const Bx=process.stdout.isTTY&&!process.env.NO_COLOR,Vx=e=>t=>Bx?`\x1b[${e}m${t}\x1b[0m`:t,Hx=Vx(1),Q=Vx(2),Ux=Vx(32),Wx=Vx(31),Gx=Vx(36),Kx=e=>console.log(`${Ux(`✓`)} ${e}`),qx=e=>console.log(` ${e}`),Jx=(e,t)=>console.log(`\n${e} ${t}`),Yx=e=>console.log(` ${e}`);function Xx(e){if(!Bx)return Yx(Q(e)),{stop:()=>{}};let t=0,n=setInterval(()=>{process.stdout.write(`\r ${Gx(`⠋⠙⠹⠸⠼⠴⠦⠧⠇⠏`[t++%10]??``)} ${Q(e)}`)},80);return{stop:()=>{clearInterval(n),process.stdout.write(`\r\x1B[2K`)}}}var Zx=class extends Error{};async function Qx(e,t=``){if(!process.stdin.isTTY)return t;let n=w({input:process.stdin,output:process.stdout});try{return(await n.question(e)).trim()||t}finally{n.close()}}async function $x(e,t){let n=await Qx(`${e} ${Q(t?`[Y/n]`:`[y/N]`)} `,t?`y`:`n`);return/^y/i.test(n)}function eS(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 tS=`.quirl-export.json`,nS=e=>e.toLowerCase().normalize(`NFKD`).replace(/[̀-ͯ]/g,``).replace(/[^a-z0-9]+/g,`-`).replace(/^-+|-+$/g,``).slice(0,80)||`untitled`;function rS(e){return`---\n${[[`title`,e.title],[`type`,e.type],[`status`,e.status],[`source`,e.source],[`alwaysLoad`,e.alwaysLoad],[`id`,e.id],[`created`,e.createdAt],[`updated`,e.updatedAt]].map(([e,t])=>`${e}: ${JSON.stringify(t)}`).join(`
|
|
215
215
|
`)}\n---\n\n`}async function iS({dir:e=`quirl-docs`,all:t=!1}){let n=await hx();if(!n)throw new Zx("This folder isn't linked to a Quirl project. Run `quirl init`.");let r=new Wr(await dx()),i=_.resolve(e);Jx(`📤`,`Exporting ${t?`all`:`Quirl-written`} docs from ${Hx(n.link.name)}`);let a=[];for(let e=0;;e+=100){let i=await r.call(`export_docs`,{p_project:n.link.projectId,p_only_quirl:!t,p_offset:e,p_limit:100});if(a.push(...i),i.length<100)break}let o=[],s=/* @__PURE__ */ new Set;await l(i,{recursive:!0});for(let e of a){let t=`${e.type}/${nS(e.title)}.md`;for(let n=2;s.has(t);n++)t=`${e.type}/${nS(e.title)}-${n}.md`;s.add(t),await l(_.join(i,e.type),{recursive:!0}),await m(_.join(i,t),rS(e)+e.body.replace(/\n*$/,`
|
|
216
216
|
`)),o.push(t)}let c=0;try{let e=JSON.parse(await u(_.join(i,tS),`utf8`));for(let t of e.files??[])s.has(t)||t.includes(`..`)||(await f(_.join(i,t),{force:!0}),c++)}catch{}await m(_.join(i,tS),`${JSON.stringify({project:n.link.project,exportedAt:(/* @__PURE__ */ new Date()).toISOString(),all:t,files:o},null,` `)}\n`),Yx(`${Ux(`✓`)} ${a.length} ${a.length===1?`doc`:`docs`} written to ${Gx(_.relative(process.cwd(),i)||`.`)}${c?Q(` · ${c} removed`):``}`),t||Yx(Q(`Docs synced from repos are left out; add --all to include them.`)),console.log(``)}async function aS(e,t=3){let n=[],r=async(e,i)=>{if(C(_.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(`.`)||Cx.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 oS=`<!-- quirl:start -->`,sS=`<!-- quirl:end -->`,cS=`# quirl: keep the project in sync`;function lS(){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@latest`],shell:`npx -y quirl-cli@latest`,portable:!0}}const uS=[`QUIRL_SERVER`,`QUIRL_API_URL`,`QUIRL_PUBLISHABLE_KEY`,`QUIRL_APP_URL`];function dS(){return Object.fromEntries(uS.flatMap(e=>process.env[e]?[[e,process.env[e]]]:[]))}function fS(){return`${Object.entries(dS()).map(([e,t])=>`${e}="${t}" `).join(``)}${lS().shell}`}async function pS(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 mS=async(e,t)=>{await l(y(e),{recursive:!0}),await m(e,`${JSON.stringify(t,null,2)}\n`)};async function hS(e){let t=x(e,`.mcp.json`),n=await pS(t),r=lS();n.mcpServers={...n.mcpServers,quirl:{command:r.command,args:[...r.args,`mcp`],...Object.keys(dS()).length?{env:dS()}:{}}},await mS(t,n)}async function gS(e){let t=x(e,`.claude`,`settings.json`),n=await pS(t),r=n.hooks??{},i=`${fS()} 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 mS(t,n)}async function _S(e,t,n=[]){let r=x(e,`CLAUDE.md`),i=``;try{i=await u(r,`utf8`)}catch{}let a=`${oS}
|
|
217
217
|
## Quirl
|