cherry-works 0.6.1 → 0.6.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -305,6 +305,8 @@ To put a price on it, ask your agent what last week cost: the built-in
305
305
  type or the provider's published ones, and answers per session and per day,
306
306
  naming the prices it used.
307
307
 
308
+ Both limits are set in `.cw/settings.json`; leave one out to keep its default:
309
+
308
310
  ```json
309
311
  {
310
312
  "agents": ["claude"],
@@ -313,6 +315,14 @@ naming the prices it used.
313
315
  }
314
316
  ```
315
317
 
318
+ - `mainContextCeiling` — the tokens a session may open with before `cw doctor`
319
+ warns. Raise it when your charter is meant to be large.
320
+ - `sessionContextMark` — every how many tokens a running session tells you what
321
+ it has used so far.
322
+
323
+ Each is a whole number above 0. Run `cw build` after changing either, then
324
+ `cw doctor` to check.
325
+
316
326
  ## Vendor sources
317
327
 
318
328
  ```bash
@@ -362,13 +372,16 @@ the environment variable its `tokenEnv` names. Any primitive points the agent
362
372
  at an mcp origin by naming it in its body as `[[mfbs/billing]]`.
363
373
 
364
374
  ```bash
365
- cw build # adds one entry, cw mcp serve, to your agent's .mcp.json
366
- cw mcp auth # sign in to every mcp origin you are not signed in to yet
375
+ cw mcp auth # sign in to every mcp origin the charter declares that you are not signed in to yet
376
+ cw build # asks each mcp origin for its tools; adds one entry, cw mcp serve, to your agent's .mcp.json
367
377
  cw mcp auth --status
368
378
  ```
369
379
 
370
- Every developer signs in as themselves, by browser where the mcp origin offers OAuth
371
- or with a token typed at a hidden prompt. Credentials are kept in the operating
380
+ Sign in before you build: the build reaches each mcp origin under your
381
+ credential, and stops on one you are not signed in to. Every developer signs in
382
+ as themselves, by browser where the mcp origin offers OAuth or with a token
383
+ typed at a hidden prompt. GitHub's MCP server does not let `cw` register for
384
+ OAuth, so sign in there with a personal access token. Credentials are kept in the operating
372
385
  system's credential store, never in the repository, and renewed without asking
373
386
  where the mcp origin allows it. `cw mcp serve` is the one MCP server your agent is
374
387
  given: it serves the tools each mcp origin declares and forwards every call under
package/dist/cw.js CHANGED
@@ -3,7 +3,7 @@
3
3
  // package.json
4
4
  var package_default = {
5
5
  name: "cherry-works",
6
- version: "0.6.1",
6
+ version: "0.6.2",
7
7
  description: "The charter engine: resolves a charter and compiles it into what a coding agent reads.",
8
8
  keywords: [
9
9
  "claude-code",
package/dist/main.js CHANGED
@@ -21898,7 +21898,7 @@ import { pathToFileURL as pathToFileURL2 } from "url";
21898
21898
  // package.json
21899
21899
  var package_default = {
21900
21900
  name: "cherry-works",
21901
- version: "0.6.1",
21901
+ version: "0.6.2",
21902
21902
  description: "The charter engine: resolves a charter and compiles it into what a coding agent reads.",
21903
21903
  keywords: [
21904
21904
  "claude-code",
@@ -27649,7 +27649,7 @@ function parseKVParams(typed, paramName) {
27649
27649
  }
27650
27650
  return params;
27651
27651
  }
27652
- function toText({ data: { files } }) {
27652
+ function printFaultsByFile({ data: { files } }) {
27653
27653
  return Object.keys(files).sort().map((file2) => [file2, ...(files[file2] ?? []).flatMap(lines), ""].join("\n")).join("");
27654
27654
  }
27655
27655
  function lines({ data: { severity, message, fix } }) {
@@ -27778,8 +27778,8 @@ var BuildCommand = class {
27778
27778
  return {
27779
27779
  code: EXIT_FAILURE,
27780
27780
  problem: `Nothing was previewed: ${noOfFiles} file${noOfFiles === 1 ? " has" : "s have"} errors.
27781
- Run "cw doctor" to see what is wrong with them.
27782
- `
27781
+
27782
+ ${printFaultsByFile(planSummaryDTO3)}`
27783
27783
  };
27784
27784
  }
27785
27785
  const { added: added2, edited: edited2, deleted: deleted2, unchanged } = planSummaryDTO3.data;
@@ -27804,8 +27804,8 @@ Run "cw doctor" to see what is wrong with them.
27804
27804
  return {
27805
27805
  code: EXIT_FAILURE,
27806
27806
  problem: `Nothing was built: ${noOfFiles} file${noOfFiles === 1 ? " has" : "s have"} errors.
27807
- Run "cw doctor" to see what is wrong with them.
27808
- `
27807
+
27808
+ ${printFaultsByFile(planSummaryDTO2)}`
27809
27809
  };
27810
27810
  }
27811
27811
  const { added, edited, deleted } = planSummaryDTO2.data;
@@ -27882,6 +27882,12 @@ var DoctorCommand = class {
27882
27882
  mainContexts,
27883
27883
  mainContextCeiling
27884
27884
  } = (await charterAuthoringApp2.doctor()).data;
27885
+ const isColoured = process.stdout.isTTY === true && process.env.NO_COLOR === void 0;
27886
+ const markByStanding = {
27887
+ good: isColoured ? "\x1B[32m\u2714\x1B[0m" : "\u2714",
27888
+ todo: isColoured ? "\x1B[33m\u26A0\x1B[0m" : "\u26A0",
27889
+ fault: isColoured ? "\x1B[31m\u2718\x1B[0m" : "\u2718"
27890
+ };
27885
27891
  return {
27886
27892
  code: problemCount === 0 ? EXIT_OK : EXIT_FAILURE,
27887
27893
  result: [
@@ -27890,19 +27896,19 @@ var DoctorCommand = class {
27890
27896
  `cw ${version2}`,
27891
27897
  // A repository that compiles for none is set up and building: the
27892
27898
  // neutral surface is compiled for everybody (FR-019).
27893
- agents.length === 0 ? "Agents: none chosen, so only the neutral surface is compiled." : `Agents: ${agents.join(", ")}.`,
27894
- errors > 0 ? `Charter: ${errors} error${errors === 1 ? "" : "s"}.` : warnings === 0 ? "Charter: holds." : `Charter: holds, with ${warnings} warning${warnings === 1 ? "" : "s"}.`,
27895
- driftedVendors2.length === 0 ? "Vendors: none edited here." : `Vendors: edited here: ${driftedVendors2.join(", ")}. Run "git checkout" under .cw/vendor/ to undo, or commit what you meant.`,
27896
- pending === null ? "Built: not known, since the charter does not hold." : pending === 0 ? "Built: up to date." : `Built: ${pending} file${pending === 1 ? "" : "s"} out of date. Run "cw build".`,
27899
+ agents.length === 0 ? `${markByStanding.good} Agents: none chosen, so only the neutral surface is compiled.` : `${markByStanding.good} Agents: ${agents.join(", ")}.`,
27900
+ errors > 0 ? `${markByStanding.fault} Charter: ${errors} error${errors === 1 ? "" : "s"}.` : warnings === 0 ? `${markByStanding.good} Charter: good.` : `${markByStanding.todo} Charter: good, with ${warnings} warning${warnings === 1 ? "" : "s"}.`,
27901
+ driftedVendors2.length === 0 ? `${markByStanding.good} Vendors: good.` : `${markByStanding.fault} Vendors: edited here: ${driftedVendors2.join(", ")}. Run "git checkout" under .cw/vendor/ to undo, or commit what you meant.`,
27902
+ pending === null ? `${markByStanding.fault} Built: Fix the charter's errors, then run "cw build".` : pending === 0 ? `${markByStanding.good} Built: up to date.` : `${markByStanding.todo} Built: ${pending} file${pending === 1 ? "" : "s"} out of date. Run "cw build".`,
27897
27903
  // What each agent opens a session with, held to the ceiling: past it is
27898
27904
  // a warning, and fails nothing (EVAL-FR-006).
27899
27905
  ...mainContexts.map(
27900
- ({ agent, totalTokens }) => `Context: ${agent} opens a session with about ${totalTokens.toLocaleString("en-US")} tokens, ${totalTokens > mainContextCeiling ? `past the ceiling of ${mainContextCeiling.toLocaleString("en-US")}. Run "cw context" to see what takes the most.` : `within the ceiling of ${mainContextCeiling.toLocaleString("en-US")}.`}`
27906
+ ({ agent, totalTokens }) => totalTokens > mainContextCeiling ? `${markByStanding.todo} Context: ${agent} opens a session with about ${totalTokens.toLocaleString("en-US")} tokens, past the ceiling of ${mainContextCeiling.toLocaleString("en-US")}. Run "cw context" to see what takes the most.` : `${markByStanding.good} Context: good (${agent} opens a session with about ${totalTokens.toLocaleString("en-US")} tokens, within the ceiling of ${mainContextCeiling.toLocaleString("en-US")}).`
27901
27907
  ),
27902
27908
  // Every fault under the file that has to change, below the four lines
27903
27909
  // rather than inside them: a line says how many, and this says which
27904
27910
  // (FR-009).
27905
- ...Object.keys(faultsByFile.data.files).length === 0 ? [] : ["", toText(faultsByFile)],
27911
+ ...Object.keys(faultsByFile.data.files).length === 0 ? [] : ["", printFaultsByFile(faultsByFile)],
27906
27912
  problemCount === 0 ? "Nothing to fix." : `${problemCount} thing${problemCount === 1 ? "" : "s"} to fix.`,
27907
27913
  ""
27908
27914
  ].join("\n")
@@ -27945,7 +27951,7 @@ var EvalCommand = class {
27945
27951
  const evalRunReportDTO2 = await charterEvaluatingApp2.evaluate();
27946
27952
  if (evalRunReportDTO2.type === "FaultsByFile") return { code: EXIT_FAILURE, problem: `No case was run.
27947
27953
 
27948
- ${toText(evalRunReportDTO2)}` };
27954
+ ${printFaultsByFile(evalRunReportDTO2)}` };
27949
27955
  const { evalCaseReports, totalTokens } = evalRunReportDTO2.data;
27950
27956
  if (evalCaseReports.length === 0)
27951
27957
  return {
@@ -28052,8 +28058,8 @@ var InitCommand = class {
28052
28058
  code: EXIT_FAILURE,
28053
28059
  result: [...setUp, ""].join("\n"),
28054
28060
  problem: `Nothing was built: ${noOfFiles} file${noOfFiles === 1 ? " has" : "s have"} errors.
28055
- Run "cw doctor" to see what is wrong with them.
28056
- `
28061
+
28062
+ ${printFaultsByFile(planSummaryDTO2)}`
28057
28063
  };
28058
28064
  }
28059
28065
  const { added, edited } = planSummaryDTO2.data;
@@ -28217,7 +28223,7 @@ var McpAuthCommand = class {
28217
28223
  if (status)
28218
28224
  return {
28219
28225
  code: EXIT_OK,
28220
- result: signInStatuses.length === 0 ? "No mcp origin the last build listed takes a sign-in.\n" : signInStatuses.map(
28226
+ result: signInStatuses.length === 0 ? "No mcp in the charter takes a sign-in.\n" : signInStatuses.map(
28221
28227
  ({ address, ids, signedIn, method }) => [address, ` ${ids.join(", ")}`, ` ${signedIn ? `signed in by ${method}` : "not signed in"}`, ""].join("\n")
28222
28228
  ).join("")
28223
28229
  };
@@ -28227,15 +28233,15 @@ var McpAuthCommand = class {
28227
28233
  const signInStatus = signInStatuses.find((one) => one.ids.includes(id));
28228
28234
  if (signInStatus === void 0)
28229
28235
  throw new DomainFault(
28230
- `No mcp origin the last build listed is declared by ${id}.`,
28231
- 'Run "cw mcp auth --status" to see every mcp, or "cw build" if the charter changed.'
28236
+ `No mcp in the charter that takes a sign-in is ${id}.`,
28237
+ 'Run "cw mcp auth --status" to see every mcp that does.'
28232
28238
  );
28233
28239
  unsignedStatuses = [signInStatus];
28234
28240
  }
28235
28241
  if (unsignedStatuses.length === 0)
28236
28242
  return {
28237
28243
  code: EXIT_OK,
28238
- result: signInStatuses.length === 0 ? "No mcp origin the last build listed takes a sign-in.\n" : `You are signed in at every address: ${signInStatuses.length}.
28244
+ result: signInStatuses.length === 0 ? "No mcp in the charter takes a sign-in.\n" : `You are signed in at every address: ${signInStatuses.length}.
28239
28245
  `
28240
28246
  };
28241
28247
  if (!process.stdin.isTTY)
@@ -58630,7 +58636,7 @@ var TestCommand = class {
58630
58636
  if (testRunReportDTO2.type === "FaultsByFile")
58631
58637
  return { code: EXIT_FAILURE, problem: `Nothing was resolved.
58632
58638
 
58633
- ${toText(testRunReportDTO2)}` };
58639
+ ${printFaultsByFile(testRunReportDTO2)}` };
58634
58640
  const cases = testRunReportDTO2.data.testCaseReports;
58635
58641
  if (cases.length === 0) {
58636
58642
  return {
@@ -61732,15 +61738,21 @@ var McpConnecting = class {
61732
61738
  * §19.5): one address is one account at one service, whatever path each
61733
61739
  * mcp origin there names. A local command taking no token signs in to nothing and
61734
61740
  * is left out.
61741
+ *
61742
+ * Read off the charter rather than the last build (FR-148): a build stops on
61743
+ * an mcp origin it is not signed in to (EVAL-FR-031), so an mcp added since
61744
+ * would never be listed for the sign-in that lets it build.
61735
61745
  */
61736
61746
  async #signInAddresses() {
61737
- const { origins } = await loadMcpOrigins(this.#repoPath, this.#fileReader);
61747
+ const charter = await loadCharterRoot(this.#repoPath, this.#fileReader, this.#yamlParser);
61738
61748
  const addresses = /* @__PURE__ */ new Map();
61739
- for (const { address, endpoint, ids, auth: auth2 } of origins.filter((one) => one.auth.length > 0)) {
61740
- const signInAddress = addresses.get(address) ?? { ...endpoint !== void 0 && { endpoint }, ids: /* @__PURE__ */ new Set(), auth: /* @__PURE__ */ new Set() };
61741
- ids.forEach((id) => signInAddress.ids.add(id));
61749
+ for (const mcpPrimitive of charter.primitives) {
61750
+ if (!(mcpPrimitive instanceof McpPrimitive) || mcpPrimitive.headers.auth === void 0) continue;
61751
+ const { id, endpoint, auth: auth2 } = mcpPrimitive.headers;
61752
+ const signInAddress = addresses.get(mcpPrimitive.address) ?? { ...endpoint !== void 0 && { endpoint }, ids: /* @__PURE__ */ new Set(), auth: /* @__PURE__ */ new Set() };
61753
+ signInAddress.ids.add(id);
61742
61754
  auth2.forEach((method) => signInAddress.auth.add(method));
61743
- addresses.set(address, signInAddress);
61755
+ addresses.set(mcpPrimitive.address, signInAddress);
61744
61756
  }
61745
61757
  return [...addresses].sort(([one], [other]) => one.localeCompare(other)).map(([address, { endpoint, ids, auth: auth2 }]) => ({
61746
61758
  address,
@@ -61757,7 +61769,7 @@ var McpConnecting = class {
61757
61769
  async #addressTaking(address, method) {
61758
61770
  const signInAddress = (await this.#signInAddresses()).find((one) => one.address === address);
61759
61771
  if (signInAddress === void 0)
61760
- throw new DomainFault(`No mcp origin the last build listed is at ${address}.`, 'Run "cw mcp auth --status" to see every address, or "cw build" if the charter changed.');
61772
+ throw new DomainFault(`No mcp in the charter is at ${address}.`, 'Run "cw mcp auth --status" to see every address.');
61761
61773
  if (signInAddress.endpoint !== void 0 && !isSecureEndpoint(signInAddress.endpoint))
61762
61774
  throw new DomainFault(
61763
61775
  `${address} is plain http to another machine, so no credential is sent there.`,
@@ -136,7 +136,7 @@ ${this.parser.parse(t)}</blockquote>
136
136
  ${t}</tr>
137
137
  `}tablecell(t){let e=this.parser.parseInline(t.tokens),a=t.header?"th":"td";return(t.align?`<${a} align="${t.align}">`:`<${a}>`)+e+`</${a}>
138
138
  `}strong({tokens:t}){return`<strong>${this.parser.parseInline(t)}</strong>`}em({tokens:t}){return`<em>${this.parser.parseInline(t)}</em>`}codespan({text:t}){return`<code>${Rr(t,!0)}</code>`}br(t){return"<br>"}del({tokens:t}){return`<del>${this.parser.parseInline(t)}</del>`}link({href:t,title:e,text:a,tokens:r,autolink:n}){let i=n?Rr(a,!0):this.parser.parseInline(r),o=Y5(t);if(o===null)return i;t=Rr(o,n);let s='<a href="'+t+'"';return e&&(s+=' title="'+Rr(e)+'"'),s+=">"+i+"</a>",s}image({href:t,title:e,text:a,tokens:r}){r&&(a=this.parser.parseInline(r,this.parser.textRenderer));let n=Y5(t);if(n===null)return Rr(a);t=n;let i=`<img src="${Rr(t)}" alt="${Rr(a)}"`;return e&&(i+=` title="${Rr(e)}"`),i+=">",i}text(t){return"tokens"in t&&t.tokens?this.parser.parseInline(t.tokens):"escaped"in t&&t.escaped?t.text:Rr(t.text)}},wC=class{strong({text:t}){return t}em({text:t}){return t}codespan({text:t}){return t}del({text:t}){return t}html({text:t}){return t}text({text:t}){return t}link({text:t}){return""+t}image({text:t}){return""+t}br(){return""}checkbox({raw:t}){return t}},_n=class mC{options;renderer;textRenderer;constructor(e){this.options=e||eu,this.options.renderer=this.options.renderer||new l0,this.renderer=this.options.renderer,this.renderer.options=this.options,this.renderer.parser=this,this.textRenderer=new wC}static parse(e,a){return new mC(a).parse(e)}static parseInline(e,a){return new mC(a).parseInline(e)}parse(e){this.renderer.parser=this;let a="";for(let r=0;r<e.length;r++){let n=e[r];if(this.options.extensions?.renderers?.[n.type]){let o=n,s=this.options.extensions.renderers[o.type].call({parser:this},o);if(s!==!1||!["space","hr","heading","code","table","blockquote","list","checkbox","html","def","paragraph","text"].includes(o.type)){a+=s||"";continue}}let i=n;switch(i.type){case"space":{a+=this.renderer.space(i);break}case"hr":{a+=this.renderer.hr(i);break}case"heading":{a+=this.renderer.heading(i);break}case"code":{a+=this.renderer.code(i);break}case"table":{a+=this.renderer.table(i);break}case"blockquote":{a+=this.renderer.blockquote(i);break}case"list":{a+=this.renderer.list(i);break}case"checkbox":{a+=this.renderer.checkbox(i);break}case"html":{a+=this.renderer.html(i);break}case"def":{a+=this.renderer.def(i);break}case"paragraph":{a+=this.renderer.paragraph(i);break}case"text":{a+=this.renderer.text(i);break}default:{let o='Token with "'+i.type+'" type was not found.';if(this.options.silent)return console.error(o),"";throw new Error(o)}}}return a}parseInline(e,a=this.renderer){this.renderer.parser=this;let r="";for(let n=0;n<e.length;n++){let i=e[n];if(this.options.extensions?.renderers?.[i.type]){let s=this.options.extensions.renderers[i.type].call({parser:this},i);if(s!==!1||!["escape","html","link","image","checkbox","strong","em","codespan","br","del","text"].includes(i.type)){r+=s||"";continue}}let o=i;switch(o.type){case"escape":{r+=a.text(o);break}case"html":{r+=a.html(o);break}case"link":{r+=a.link(o);break}case"image":{r+=a.image(o);break}case"checkbox":{r+=a.checkbox(o);break}case"strong":{r+=a.strong(o);break}case"em":{r+=a.em(o);break}case"codespan":{r+=a.codespan(o);break}case"br":{r+=a.br(o);break}case"del":{r+=a.del(o);break}case"text":{r+=a.text(o);break}default:{let s='Token with "'+o.type+'" type was not found.';if(this.options.silent)return console.error(s),"";throw new Error(s)}}}return r}},Dh=class{options;block;constructor(t){this.options=t||eu}static passThroughHooks=new Set(["preprocess","postprocess","processAllTokens","emStrongMask"]);static passThroughHooksRespectAsync=new Set(["preprocess","postprocess","processAllTokens"]);preprocess(t){return t}postprocess(t){return t}processAllTokens(t){return t}emStrongMask(t){return t}provideLexer(t=this.block){return t?Bn.lex:Bn.lexInline}provideParser(t=this.block){return t?_n.parse:_n.parseInline}},CC=class{defaults=gC();options=this.setOptions;parse=this.parseMarkdown(!0);parseInline=this.parseMarkdown(!1);Parser=_n;Renderer=l0;TextRenderer=wC;Lexer=Bn;Tokenizer=s0;Hooks=Dh;constructor(...t){this.use(...t)}walkTokens(t,e){let a=[];for(let r of t)switch(a=a.concat(e.call(this,r)),r.type){case"table":{let n=r;for(let i of n.header)a=a.concat(this.walkTokens(i.tokens,e));for(let i of n.rows)for(let o of i)a=a.concat(this.walkTokens(o.tokens,e));break}case"list":{let n=r;a=a.concat(this.walkTokens(n.items,e));break}default:{let n=r;this.defaults.extensions?.childTokens?.[n.type]?this.defaults.extensions.childTokens[n.type].forEach(i=>{let o=n[i].flat(1/0);a=a.concat(this.walkTokens(o,e))}):n.tokens&&(a=a.concat(this.walkTokens(n.tokens,e)))}}return a}use(...t){let e=this.defaults.extensions||{renderers:{},childTokens:{}};return t.forEach(a=>{let r={...a};if(r.async=this.defaults.async||r.async||!1,a.extensions&&(a.extensions.forEach(n=>{if(!n.name)throw new Error("extension name required");if("renderer"in n){let i=e.renderers[n.name];i?e.renderers[n.name]=function(...o){let s=n.renderer.apply(this,o);return s===!1&&(s=i.apply(this,o)),s}:e.renderers[n.name]=n.renderer}if("tokenizer"in n){if(!n.level||n.level!=="block"&&n.level!=="inline")throw new Error("extension level must be 'block' or 'inline'");let i=e[n.level];i?i.unshift(n.tokenizer):e[n.level]=[n.tokenizer],n.start&&(n.level==="block"?e.startBlock?e.startBlock.push(n.start):e.startBlock=[n.start]:n.level==="inline"&&(e.startInline?e.startInline.push(n.start):e.startInline=[n.start]))}"childTokens"in n&&n.childTokens&&(e.childTokens[n.name]=n.childTokens)}),r.extensions=e),a.renderer){let n=this.defaults.renderer||new l0(this.defaults);for(let i in a.renderer){if(!(i in n))throw new Error(`renderer '${i}' does not exist`);if(["options","parser"].includes(i))continue;let o=i,s=a.renderer[o],l=n[o];n[o]=(...u)=>{let c=s.apply(n,u);return c===!1&&(c=l.apply(n,u)),c||""}}r.renderer=n}if(a.tokenizer){let n=this.defaults.tokenizer||new s0(this.defaults);for(let i in a.tokenizer){if(!(i in n))throw new Error(`tokenizer '${i}' does not exist`);if(["options","rules","lexer"].includes(i))continue;let o=i,s=a.tokenizer[o],l=n[o];n[o]=(...u)=>{let c=s.apply(n,u);return c===!1&&(c=l.apply(n,u)),c}}r.tokenizer=n}if(a.hooks){let n=this.defaults.hooks||new Dh;for(let i in a.hooks){if(!(i in n))throw new Error(`hook '${i}' does not exist`);if(["options","block"].includes(i))continue;let o=i,s=a.hooks[o],l=n[o];Dh.passThroughHooks.has(i)?n[o]=u=>{if(this.defaults.async&&Dh.passThroughHooksRespectAsync.has(i))return(async()=>{let f=await s.call(n,u);return l.call(n,f)})();let c=s.call(n,u);return l.call(n,c)}:n[o]=(...u)=>{if(this.defaults.async)return(async()=>{let f=await s.apply(n,u);return f===!1&&(f=await l.apply(n,u)),f})();let c=s.apply(n,u);return c===!1&&(c=l.apply(n,u)),c}}r.hooks=n}if(a.walkTokens){let n=this.defaults.walkTokens,i=a.walkTokens;r.walkTokens=function(o){let s=[];return s.push(i.call(this,o)),n&&(s=s.concat(n.call(this,o))),s}}this.defaults={...this.defaults,...r}}),this}setOptions(t){return this.defaults={...this.defaults,...t},this}lexer(t,e){return Bn.lex(t,e??this.defaults)}parser(t,e){return _n.parse(t,e??this.defaults)}parseMarkdown(t){return(e,a)=>{let r={...a},n={...this.defaults,...r},i=this.onError(!!n.silent,!!n.async);if(this.defaults.async===!0&&r.async===!1)return i(new Error("marked(): The async option was set to true by an extension. Remove async: false from the parse options object to return a Promise."));if(typeof e>"u"||e===null)return i(new Error("marked(): input parameter is undefined or null"));if(typeof e!="string")return i(new Error("marked(): input parameter is of type "+Object.prototype.toString.call(e)+", string expected"));if(n.hooks&&(n.hooks.options=n,n.hooks.block=t),n.async)return(async()=>{let o=n.hooks?await n.hooks.preprocess(e):e,s=await(n.hooks?await n.hooks.provideLexer(t):t?Bn.lex:Bn.lexInline)(o,n),l=n.hooks?await n.hooks.processAllTokens(s):s;n.walkTokens&&await Promise.all(this.walkTokens(l,n.walkTokens));let u=await(n.hooks?await n.hooks.provideParser(t):t?_n.parse:_n.parseInline)(l,n);return n.hooks?await n.hooks.postprocess(u):u})().catch(i);try{n.hooks&&(e=n.hooks.preprocess(e));let o=(n.hooks?n.hooks.provideLexer(t):t?Bn.lex:Bn.lexInline)(e,n);n.hooks&&(o=n.hooks.processAllTokens(o)),n.walkTokens&&this.walkTokens(o,n.walkTokens);let s=(n.hooks?n.hooks.provideParser(t):t?_n.parse:_n.parseInline)(o,n);return n.hooks&&(s=n.hooks.postprocess(s)),s}catch(o){return i(o)}}}onError(t,e){return a=>{if(a.message+=`
139
- Please report this to https://github.com/markedjs/marked.`,t){let r="<p>An error occurred:</p><pre>"+Rr(a.message+"",!0)+"</pre>";return e?Promise.resolve(r):r}if(e)return Promise.reject(a);throw a}}},Jl=new CC;function it(t,e){return Jl.parse(t,e)}it.options=it.setOptions=function(t){return Jl.setOptions(t),it.defaults=Jl.defaults,tz(it.defaults),it};it.getDefaults=gC;it.defaults=eu;function J8(...t){return Jl.use(...t),it.defaults=Jl.defaults,tz(it.defaults),it}it.use=J8;it.walkTokens=function(t,e){return Jl.walkTokens(t,e)};it.parseInline=Jl.parseInline;it.Parser=_n;it.parser=_n.parse;it.Renderer=l0;it.TextRenderer=wC;it.Lexer=Bn;it.lexer=Bn.lex;it.Tokenizer=s0;it.Hooks=Dh;it.parse=it;var $se=it.options,Bse=it.setOptions,_se=it.walkTokens,zse=it.parseInline;var Nse=_n.parse,Xse=Bn.lex;var Hse=L(F(),1);var Nh=L(H(),1);function u0({className:t,orientation:e="horizontal",...a}){return(0,Nh.jsx)(Ll.Root,{"data-slot":"tabs","data-orientation":e,orientation:e,className:pe("group/tabs flex gap-2 data-[orientation=horizontal]:flex-col",t),...a})}var eW=li("group/tabs-list inline-flex w-fit items-center justify-center rounded-lg p-[3px] text-muted-foreground group-data-[orientation=horizontal]/tabs:h-9 group-data-[orientation=vertical]/tabs:h-fit group-data-[orientation=vertical]/tabs:flex-col data-[variant=line]:rounded-none",{variants:{variant:{default:"bg-muted",line:"gap-1 bg-transparent"}},defaultVariants:{variant:"default"}});function c0({className:t,variant:e="default",...a}){return(0,Nh.jsx)(Ll.List,{"data-slot":"tabs-list","data-variant":e,className:pe(eW({variant:e}),t),...a})}function zh({className:t,...e}){return(0,Nh.jsx)(Ll.Trigger,{"data-slot":"tabs-trigger",className:pe("relative inline-flex h-[calc(100%-1px)] flex-1 items-center justify-center gap-1.5 rounded-md border border-transparent px-2 py-1 text-sm font-medium whitespace-nowrap text-foreground/60 transition-all group-data-[orientation=vertical]/tabs:w-full group-data-[orientation=vertical]/tabs:justify-start hover:text-foreground focus-visible:border-ring focus-visible:ring-[3px] focus-visible:ring-ring/50 focus-visible:outline-1 focus-visible:outline-ring disabled:pointer-events-none disabled:opacity-50 group-data-[variant=default]/tabs-list:data-[state=active]:shadow-sm group-data-[variant=line]/tabs-list:data-[state=active]:shadow-none dark:text-muted-foreground dark:hover:text-foreground [&_svg]:pointer-events-none [&_svg]:shrink-0 [&_svg:not([class*='size-'])]:size-4","group-data-[variant=line]/tabs-list:bg-transparent group-data-[variant=line]/tabs-list:data-[state=active]:bg-transparent dark:group-data-[variant=line]/tabs-list:data-[state=active]:border-transparent dark:group-data-[variant=line]/tabs-list:data-[state=active]:bg-transparent","data-[state=active]:bg-background data-[state=active]:text-foreground dark:data-[state=active]:border-input dark:data-[state=active]:bg-input/30 dark:data-[state=active]:text-foreground","after:absolute after:bg-foreground after:opacity-0 after:transition-opacity group-data-[orientation=horizontal]/tabs:after:inset-x-0 group-data-[orientation=horizontal]/tabs:after:bottom-[-5px] group-data-[orientation=horizontal]/tabs:after:h-0.5 group-data-[orientation=vertical]/tabs:after:inset-y-0 group-data-[orientation=vertical]/tabs:after:-right-1 group-data-[orientation=vertical]/tabs:after:w-0.5 group-data-[variant=line]/tabs-list:data-[state=active]:after:opacity-100",t),...e})}function Es({className:t,...e}){return(0,Nh.jsx)(Ll.Content,{"data-slot":"tabs-content",className:pe("flex-1 outline-none",t),...e})}var lr=L(H(),1),tW=new CC({renderer:{html:({text:t})=>t.replace(/&/g,"&amp;").replace(/</g,"&lt;").replace(/>/g,"&gt;")},walkTokens:t=>{(t.type==="link"||t.type==="image")&&/^\s*(javascript|vbscript|data):/i.test(t.href)&&(t.href="#")}}),cz="h-auto flex-none cursor-pointer rounded-md px-[11px] py-[5px] text-[11.5px] font-semibold text-zinc-500 data-[state=active]:shadow-[0_1px_2px_rgba(0,0,0,0.08)]";function kC({body:t,onChange:e}){return(0,lr.jsxs)(u0,{defaultValue:e===void 0?"preview":"source",className:"gap-0 overflow-hidden rounded-xl border bg-background",children:[(0,lr.jsxs)("div",{className:"flex items-center gap-2.5 border-b border-[#f0f0f0] px-[13px] py-[9px]",children:[(0,lr.jsx)("span",{className:"text-[10.5px] font-bold tracking-[0.06em] text-zinc-400 uppercase",children:"Body"}),(0,lr.jsx)("span",{className:"font-mono text-[10.5px] text-zinc-400",children:"markdown"}),(0,lr.jsxs)(c0,{className:"ml-auto h-auto gap-0.5 rounded-lg bg-[#f0f0f2] p-[3px]",children:[(0,lr.jsx)(zh,{value:"source",className:cz,children:"Source"}),(0,lr.jsx)(zh,{value:"preview",className:cz,children:"Preview"})]})]}),(0,lr.jsx)(Es,{value:"source",className:"h-[300px] flex-none",children:(0,lr.jsx)(aW,{body:t,onChange:e})}),(0,lr.jsx)(Es,{value:"preview",children:(0,lr.jsx)("div",{className:"min-h-32 px-[18px] py-4 text-[12.5px] leading-[1.65] text-zinc-700 [&_code]:rounded [&_code]:bg-muted [&_code]:px-1 [&_code]:font-mono [&_code]:text-xs [&_h1]:mb-[7px] [&_h1]:text-[15px] [&_h1]:font-bold [&_h1]:text-foreground [&_h2]:mt-4 [&_h2]:mb-[7px] [&_h2]:text-[13px] [&_h2]:font-bold [&_h2]:text-foreground [&_strong]:font-semibold [&_strong]:text-foreground [&_li]:ml-5 [&_ol]:list-decimal [&_p]:mb-2 [&_ul]:list-disc",dangerouslySetInnerHTML:{__html:tW.parse(t,{async:!1})}})})]})}function aW({body:t,onChange:e}){let a=(0,fz.useCallback)(r=>{let n=new oe({parent:r,doc:t,extensions:[U5(),G$(Y$),lB(),Xl.of([..._B,...dB]),oe.lineWrapping,oe.editable.of(e!==void 0),oe.updateListener.of(i=>{i.docChanged&&e?.(i.state.doc.toString())})]});return()=>n.destroy()},[]);return(0,lr.jsx)("div",{className:"h-full",ref:a})}var ole=L(F(),1);var dz=L(H(),1);function tu({className:t,type:e,...a}){return(0,dz.jsx)("input",{type:e,"data-slot":"input",className:pe("h-[30px] w-full min-w-0 rounded-lg border border-input bg-background px-[11px] py-1 font-mono text-[11.5px] text-foreground transition-[color,box-shadow] outline-none selection:bg-primary selection:text-primary-foreground file:inline-flex file:h-7 file:border-0 file:bg-transparent file:text-sm file:font-medium file:text-foreground placeholder:text-muted-foreground disabled:pointer-events-none disabled:cursor-not-allowed disabled:opacity-50 dark:bg-input/30","focus-visible:border-[#d92f45]","aria-invalid:border-destructive aria-invalid:ring-destructive/20 dark:aria-invalid:ring-destructive/40",t),...a})}var ule=L(F(),1);var hz=L(H(),1);function Xh({className:t,...e}){return(0,hz.jsx)(Dg.Root,{"data-slot":"label",className:pe("flex items-center gap-2 text-sm leading-none font-medium select-none group-data-[disabled=true]:pointer-events-none group-data-[disabled=true]:opacity-50 peer-disabled:cursor-not-allowed peer-disabled:opacity-50",t),...e})}var hle=L(F(),1);var It=L(H(),1);function LC({...t}){return(0,It.jsx)(Da.Root,{"data-slot":"select",...t})}function TC({...t}){return(0,It.jsx)(Da.Value,{"data-slot":"select-value",...t})}function PC({className:t,size:e="default",children:a,...r}){return(0,It.jsxs)(Da.Trigger,{"data-slot":"select-trigger","data-size":e,className:pe("flex w-fit cursor-pointer items-center justify-between gap-2 rounded-lg border border-input bg-background px-[11px] py-1 font-mono text-[11.5px] whitespace-nowrap text-foreground transition-[color,box-shadow] outline-none focus-visible:border-[#d92f45] disabled:cursor-not-allowed disabled:opacity-50 aria-invalid:border-destructive aria-invalid:ring-destructive/20 data-[placeholder]:text-muted-foreground data-[size=default]:h-[30px] data-[size=sm]:h-7 *:data-[slot=select-value]:line-clamp-1 *:data-[slot=select-value]:flex *:data-[slot=select-value]:items-center *:data-[slot=select-value]:gap-2 dark:bg-input/30 dark:hover:bg-input/50 dark:aria-invalid:ring-destructive/40 [&_svg]:pointer-events-none [&_svg]:shrink-0 [&_svg:not([class*='size-'])]:size-4 [&_svg:not([class*='text-'])]:text-muted-foreground",t),...r,children:[a,(0,It.jsx)(Da.Icon,{asChild:!0,children:(0,It.jsx)(xc,{className:"size-4 opacity-50"})})]})}function RC({className:t,children:e,position:a="item-aligned",align:r="center",...n}){return(0,It.jsx)(Da.Portal,{children:(0,It.jsxs)(Da.Content,{"data-slot":"select-content",className:pe("relative z-50 max-h-(--radix-select-content-available-height) min-w-[8rem] origin-(--radix-select-content-transform-origin) overflow-x-hidden overflow-y-auto rounded-md border bg-popover text-popover-foreground shadow-md data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2 data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=closed]:zoom-out-95 data-[state=open]:animate-in data-[state=open]:fade-in-0 data-[state=open]:zoom-in-95",a==="popper"&&"data-[side=bottom]:translate-y-1 data-[side=left]:-translate-x-1 data-[side=right]:translate-x-1 data-[side=top]:-translate-y-1",t),position:a,align:r,...n,children:[(0,It.jsx)(rW,{}),(0,It.jsx)(Da.Viewport,{className:pe("p-1",a==="popper"&&"h-[var(--radix-select-trigger-height)] w-full min-w-[var(--radix-select-trigger-width)] scroll-my-1"),children:e}),(0,It.jsx)(nW,{})]})})}function IC({className:t,children:e,...a}){return(0,It.jsxs)(Da.Item,{"data-slot":"select-item",className:pe("relative flex w-full cursor-default items-center gap-2 rounded-sm py-1.5 pr-8 pl-2 text-sm outline-hidden select-none focus:bg-accent focus:text-accent-foreground data-[disabled]:pointer-events-none data-[disabled]:opacity-50 [&_svg]:pointer-events-none [&_svg]:shrink-0 [&_svg:not([class*='size-'])]:size-4 [&_svg:not([class*='text-'])]:text-muted-foreground *:[span]:last:flex *:[span]:last:items-center *:[span]:last:gap-2",t),...a,children:[(0,It.jsx)("span",{"data-slot":"select-item-indicator",className:"absolute right-2 flex size-3.5 items-center justify-center",children:(0,It.jsx)(Da.ItemIndicator,{children:(0,It.jsx)(wd,{className:"size-4"})})}),(0,It.jsx)(Da.ItemText,{children:e})]})}function rW({className:t,...e}){return(0,It.jsx)(Da.ScrollUpButton,{"data-slot":"select-scroll-up-button",className:pe("flex cursor-default items-center justify-center py-1",t),...e,children:(0,It.jsx)(Cd,{className:"size-4"})})}function nW({className:t,...e}){return(0,It.jsx)(Da.ScrollDownButton,{"data-slot":"select-scroll-down-button",className:pe("flex cursor-default items-center justify-center py-1",t),...e,children:(0,It.jsx)(xc,{className:"size-4"})})}var K=L(H(),1);function AC({id:t,newKind:e,onDone:a,onClose:r}){let{data:n}=CA(t);if(t===void 0)return(0,K.jsx)(pz,{openedPrimitive:null,entityTag:"",newKind:e??"",onDone:a,onClose:r});if(n===void 0)return null;let{answer:i,entityTag:o}=n;return i.type==="Fault"?(0,K.jsx)(gz,{faults:[i]}):i.data.layerName!=="repo"?(0,K.jsx)(iW,{openedPrimitive:i}):(0,K.jsx)(pz,{openedPrimitive:i,entityTag:o,newKind:"",onDone:a,onClose:r})}function pz({openedPrimitive:t,entityTag:e,newKind:a,onDone:r,onClose:n}){let i=t?.data,[o,s]=(0,df.useState)(i?.kind??a),[l,u]=(0,df.useState)(i===void 0?"":String(i.headers.id)),[c,f]=(0,df.useState)(()=>Object.fromEntries(Object.entries(i?.headers??{}).filter(([R])=>R!=="id").map(([R,D])=>[R,typeof D=="string"?D:[...D]]))),[d,h]=(0,df.useState)(t?.data.body??""),[p,m]=(0,df.useState)([]),{data:x}=yc(),{data:g}=kA(o),{data:O}=oi(),y=LA(),b=TA(),v=PA(),S=x===void 0?[]:Object.keys(x.data),w=g?.type==="PrimitiveRequirements"?g.data.headers:[],k=O?.type==="Primitives"?O.data.primitives.filter(({data:R})=>R.kind==="corpus").map(({data:R})=>R.id):[],T=Object.fromEntries(w.flatMap(({data:{field:R}})=>{let D=c[R],Y=typeof D=="string"?D.trim():(D??[]).map(B=>B.trim()).filter(B=>B!=="");return Y.length===0?[]:[[R,Y]]})),Q=R=>m(R.type==="Faults"?R.data.faults:[R]),$=async()=>{let R=t===null?await y.mutateAsync({kind:o,id:l,headers:T,body:d}):await b.mutateAsync({param:{id:t.data.id},header:{"if-match":e},json:{headers:T,body:d}});if(R.type!=="Primitive")return Q(R);let{file:D,headers:Y}=R.data;r(t===null?"Primitive created":"Primitive saved",`${D} \xB7 ${t===null&&typeof Y.executionPath=="string"?`${Y.executionPath} beside it is the file it runs, write the script there \xB7 `:""}nothing compiled until the next build`)},A=async()=>{if(t===null)return;let R=await v.mutateAsync(t.data.id);if(R!==null)return Q(R);r("Primitive deleted",`${t.data.file} \xB7 what still names it is reported by Doctor`)};return(0,K.jsxs)("div",{className:"space-y-3.5",children:[(0,K.jsxs)("div",{className:mz,children:[t===null?(0,K.jsxs)(K.Fragment,{children:[(0,K.jsx)(fo,{label:"kind",htmlFor:"primitive-kind",children:(0,K.jsxs)(LC,{value:o,onValueChange:s,children:[(0,K.jsx)(PC,{id:"primitive-kind",className:"w-full",children:(0,K.jsx)(TC,{})}),(0,K.jsx)(RC,{children:S.map(R=>(0,K.jsx)(IC,{value:R,children:R},R))})]})}),(0,K.jsx)(fo,{label:"id",htmlFor:"primitive-id",children:(0,K.jsx)(tu,{id:"primitive-id",value:l,placeholder:"no-any",spellCheck:!1,onChange:R=>u(R.currentTarget.value)})})]}):(0,K.jsxs)(K.Fragment,{children:[(0,K.jsx)(fo,{label:"kind",hint:"the id is the file \u2014 rename by creating a new primitive and deleting this one",children:(0,K.jsx)("span",{className:"font-mono text-[11.5px]",children:o})}),(0,K.jsx)(fo,{label:"id",children:(0,K.jsx)("span",{className:"font-mono text-[11.5px]",children:l})})]}),w.map(({data:{field:R,shape:D,required:Y,allowedValues:B}})=>(0,K.jsx)(fo,{label:R,htmlFor:`header-${R}`,hint:Y?"required":void 0,children:D==="list"?(0,K.jsx)(oW,{field:R,entries:Array.isArray(c[R])?c[R]:[],onChange:q=>f({...c,[R]:q})}):B!==void 0?(0,K.jsxs)(LC,{value:typeof c[R]=="string"?c[R]:"",onValueChange:q=>f({...c,[R]:q}),children:[(0,K.jsx)(PC,{id:`header-${R}`,className:"w-full",children:(0,K.jsx)(TC,{placeholder:"\u2014"})}),(0,K.jsx)(RC,{children:B.map(q=>(0,K.jsx)(IC,{value:q,children:q},q))})]}):(0,K.jsx)(tu,{id:`header-${R}`,spellCheck:!1,autoComplete:"off",value:typeof c[R]=="string"?c[R]:"",list:R==="rationale"?"corpus-ids":void 0,onChange:q=>f({...c,[R]:q.currentTarget.value})})},R))]}),(0,K.jsx)("datalist",{id:"corpus-ids",children:k.map(R=>(0,K.jsx)("option",{value:R},R))}),(0,K.jsx)(kC,{body:d,onChange:h}),p.length>0&&(0,K.jsx)(gz,{faults:p}),(0,K.jsxs)("div",{className:ci,children:[(0,K.jsx)(Ae,{onClick:()=>{$()},children:t===null?"Create primitive":"Save"}),(0,K.jsx)(Ae,{variant:"outline",onClick:n,children:"Cancel"}),t!==null&&(0,K.jsx)(Ae,{variant:"destructive",className:"ml-auto",onClick:()=>{A()},children:"Delete"})]})]})}function iW({openedPrimitive:t}){let{kind:e,description:a,file:r,layerName:n,headers:i}=t.data;return(0,K.jsxs)("div",{className:"space-y-3.5",children:[(0,K.jsxs)(jr,{className:"rounded-xl border-[#7c3aed33] bg-[#f6f2ff]",children:[(0,K.jsx)(Fr,{className:"text-[12.5px] font-bold",children:n==="vendor"?"Installed from a vendor, and read-only here.":"Built into cw, and read-only here."}),(0,K.jsx)(Hr,{className:"text-[11.5px] text-zinc-600",children:"To differ from it, author a primitive of your own under an id of its own."})]}),(0,K.jsxs)("div",{className:mz,children:[(0,K.jsx)(fo,{label:"kind",children:(0,K.jsx)("span",{className:"font-mono text-[11.5px]",children:e})}),(0,K.jsx)(fo,{label:"file",children:(0,K.jsx)("span",{className:"font-mono text-[11.5px]",children:r})}),(0,K.jsx)(fo,{label:"description",children:(0,K.jsx)("span",{className:"text-xs",children:a})}),Object.entries(i).filter(([o])=>o!=="id"&&o!=="description").map(([o,s])=>(0,K.jsx)(fo,{label:o,children:(0,K.jsx)("span",{className:"font-mono text-[11.5px]",children:typeof s=="string"?s:s.join(", ")})},o))]}),(0,K.jsx)(kC,{body:t.data.body})]})}var mz="overflow-hidden rounded-[11px] border border-[#f0f0f0] bg-background divide-y divide-zinc-100";function fo({label:t,htmlFor:e,hint:a,children:r}){return(0,K.jsxs)("div",{className:"flex items-center gap-3 px-[13px] py-2.5",children:[(0,K.jsx)(Xh,{htmlFor:e,className:"w-[118px] shrink-0 text-[10.5px] font-bold tracking-[0.06em] text-zinc-400 uppercase",children:t}),(0,K.jsx)("div",{className:"min-w-0 flex-1",children:r}),a!==void 0&&(0,K.jsx)("span",{className:"max-w-[45%] shrink text-right text-[11.5px] text-zinc-400",children:a})]})}function oW({field:t,entries:e,onChange:a}){let r=e.length===0?[""]:e;return(0,K.jsxs)("div",{className:"flex flex-col gap-1.5",children:[r.map((n,i)=>(0,K.jsxs)("div",{className:"flex items-center gap-1.5",children:[(0,K.jsx)(tu,{id:i===0?`header-${t}`:void 0,"aria-label":`${t} ${i+1}`,spellCheck:!1,value:n,onChange:o=>a(r.map((s,l)=>l===i?o.currentTarget.value:s))}),r.length>1&&(0,K.jsx)(Ae,{variant:"outline",size:"icon",className:"size-[26px] shrink-0 rounded-[7px] text-zinc-400 [&_svg:not([class*='size-'])]:size-[11px]","aria-label":`Remove this ${t} entry`,onClick:()=>a(r.filter((o,s)=>s!==i)),children:(0,K.jsx)(ul,{})})]},i)),(0,K.jsxs)(Ae,{variant:"outline",size:"sm",className:"h-auto self-start rounded-[7px] border-dashed border-zinc-300 px-2.5 py-[5px] text-[11px] font-normal text-zinc-500",onClick:()=>a([...r,""]),children:["Add ",t]})]})}function gz({faults:t}){return(0,K.jsxs)(jr,{variant:"destructive",className:"rounded-xl border-[#f6d9d9] bg-[#fef6f6]",children:[(0,K.jsx)(Fr,{className:"text-[12.5px] font-bold text-foreground",children:"Refused, and nothing was written"}),(0,K.jsx)(Hr,{children:t.map(({data:{message:e,fix:a}})=>(0,K.jsxs)("p",{className:"whitespace-pre-line",children:[e," ",(0,K.jsx)("span",{className:"text-muted-foreground",children:a})]},e))})]})}var f0=L(F(),1);var pt=L(H(),1);function Oz({onDone:t,onClose:e}){let[a,r]=(0,f0.useState)(""),[n,i]=(0,f0.useState)(""),[o,s]=(0,f0.useState)(null),l=yc(),u=EA(),c=async()=>{let f=n.trim(),d=await u.mutateAsync({source:a.trim(),...f===""?{}:{version:f}});if(d!==null)return s(d);t("Vendor source added",`${a.trim()}${f===""?"":` @ ${f}`} \xB7 run Build to compile what it adds`)};return(0,pt.jsxs)("div",{className:"space-y-3.5",children:[(0,pt.jsx)("p",{className:"text-[13px] leading-[1.65] text-zinc-700",children:"A vendor source is a repository governed by cw: only its charter, under .cw/charter/, is installed."}),(0,pt.jsxs)("div",{className:"divide-y divide-zinc-100 overflow-hidden rounded-[11px] border border-[#f0f0f0]",children:[(0,pt.jsxs)("div",{className:"flex items-center gap-3 px-[13px] py-2.5",children:[(0,pt.jsx)(Xh,{htmlFor:"vendor-source",className:"w-[118px] shrink-0 text-[10.5px] font-bold tracking-[0.06em] text-zinc-400 uppercase",children:"source"}),(0,pt.jsx)(tu,{id:"vendor-source",value:a,spellCheck:!1,onChange:f=>r(f.target.value)})]}),(0,pt.jsxs)("div",{className:"flex items-center gap-3 px-[13px] py-2.5",children:[(0,pt.jsx)(Xh,{htmlFor:"vendor-version",className:"w-[118px] shrink-0 text-[10.5px] font-bold tracking-[0.06em] text-zinc-400 uppercase",children:"version"}),(0,pt.jsx)(tu,{id:"vendor-version",value:n,spellCheck:!1,onChange:f=>i(f.target.value)}),(0,pt.jsx)("span",{className:"max-w-[45%] shrink text-right text-[11.5px] text-zinc-400",children:"a tag, branch or commit; left empty, the source's default"})]})]}),(0,pt.jsxs)("div",{className:"rounded-[11px] border bg-zinc-50 px-3.5 py-3","aria-label":"Reserved directories",children:[(0,pt.jsx)("div",{className:"mb-1 text-[11px] font-bold tracking-[0.07em] text-zinc-400 uppercase",children:"Directories under its .cw/charter/"}),Object.entries(l.data?.data??{}).map(([f,d])=>(0,pt.jsxs)("div",{className:"flex items-baseline gap-[9px] border-t border-zinc-100 py-[7px]",children:[(0,pt.jsxs)("span",{className:"min-w-[150px] font-mono text-[11.5px]",children:[f,"/"]}),(0,pt.jsx)("span",{className:"text-[11.5px] text-zinc-500",children:d})]},f))]}),o!==null&&(0,pt.jsxs)(jr,{variant:"destructive",className:"rounded-xl border-[#f6d9d9] bg-[#fef6f6]",children:[(0,pt.jsx)(Fr,{className:"text-[12.5px] font-bold text-foreground",children:"Refused, and nothing was installed"}),(0,pt.jsx)(Hr,{children:(0,pt.jsxs)("p",{className:"whitespace-pre-line",children:[o.data.message," ",(0,pt.jsx)("span",{className:"text-muted-foreground",children:o.data.fix})]})})]}),(0,pt.jsxs)("div",{className:ci,children:[(0,pt.jsx)(Ae,{disabled:u.isPending||a.trim()==="",onClick:()=>{c()},children:"Add source"}),(0,pt.jsx)(Ae,{variant:"outline",onClick:e,children:"Cancel"})]})]})}var QC=L(F(),1);var At=L(H(),1);function xz({name:t,onDone:e,onClose:a}){let n=Hm().data?.data.testSuites.find(({data:i})=>i.name===t);return n===void 0?null:(0,At.jsx)(sW,{name:t,initialText:n.data.text??"",onDone:e,onClose:a},t)}function sW({name:t,initialText:e,onDone:a,onClose:r}){let[n,i]=(0,QC.useState)(e),[o,s]=(0,QC.useState)(null),l=_A(),u=zA(),c=async()=>{let d=await l.mutateAsync({name:t,text:n});if(typeof d!="string")return s(d);a("Saved",`.cw/test/${t} rewritten \xB7 run the cases again`)},f=async()=>{let d=await u.mutateAsync(t);if(d!==null)return s(d);a("Test file deleted",`.cw/test/${t} removed`)};return(0,At.jsxs)("div",{className:"space-y-3",children:[(0,At.jsxs)("p",{className:"text-xs leading-[1.65] text-zinc-600 [&_code]:font-mono",children:["A case is one situation \u2014 a touched file (",(0,At.jsx)("code",{children:"do.touchFile"}),") or a raised event (",(0,At.jsx)("code",{children:"when"}),") \u2014 and expects one thing:"," ",(0,At.jsx)("code",{children:"activate"}),", ",(0,At.jsx)("code",{children:"run"})," or ",(0,At.jsx)("code",{children:"allow"}),"."]}),(0,At.jsx)("textarea",{"aria-label":"Test file text",className:"h-[340px] w-full resize-y rounded-[11px] border bg-zinc-50 px-3.5 py-3 font-mono text-[11.5px] leading-[1.65] outline-none",spellCheck:!1,value:n,onChange:d=>i(d.target.value)}),o!==null&&(0,At.jsxs)(jr,{variant:"destructive",className:"rounded-xl border-[#f6d9d9] bg-[#fef6f6]",children:[(0,At.jsx)(Fr,{className:"text-[12.5px] font-bold text-foreground",children:"Refused, and nothing was written"}),(0,At.jsx)(Hr,{children:(0,At.jsxs)("p",{className:"break-words whitespace-pre-line",children:[o.data.message," ",(0,At.jsx)("span",{className:"text-muted-foreground",children:o.data.fix})]})})]}),(0,At.jsx)("p",{className:"text-[11.5px] leading-[1.6] text-zinc-400",children:"Read only when tests run \u2014 never compiled, never read by an agent."}),(0,At.jsxs)("div",{className:ci,children:[(0,At.jsx)(Ae,{disabled:l.isPending,onClick:()=>{c()},children:"Save"}),(0,At.jsx)(Ae,{variant:"outline",onClick:r,children:"Cancel"}),(0,At.jsx)(Ae,{variant:"destructive",className:"ml-auto",disabled:u.isPending,onClick:()=>{f()},children:"Delete file"})]})]})}var Nle=L(F(),1);var ur=L(H(),1);function yz({...t}){return(0,ur.jsx)(yn.Root,{"data-slot":"dialog",...t})}function lW({...t}){return(0,ur.jsx)(yn.Portal,{"data-slot":"dialog-portal",...t})}function uW({className:t,...e}){return(0,ur.jsx)(yn.Overlay,{"data-slot":"dialog-overlay",className:pe("fixed inset-0 z-50 bg-[rgba(9,9,11,0.35)] data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:animate-in data-[state=open]:fade-in-0",t),...e})}function bz({className:t,children:e,showCloseButton:a=!0,...r}){return(0,ur.jsxs)(lW,{"data-slot":"dialog-portal",children:[(0,ur.jsx)(uW,{}),(0,ur.jsxs)(yn.Content,{"data-slot":"dialog-content",className:pe("fixed top-[50%] left-[50%] z-50 grid w-full max-w-[calc(100%-2rem)] translate-x-[-50%] translate-y-[-50%] gap-4 rounded-lg border bg-background p-6 shadow-lg duration-200 outline-none data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=closed]:zoom-out-95 data-[state=open]:animate-in data-[state=open]:fade-in-0 data-[state=open]:zoom-in-95 sm:max-w-lg",t),...r,children:[e,a&&(0,ur.jsxs)(yn.Close,{"data-slot":"dialog-close",className:"absolute top-4 right-[18px] cursor-pointer rounded-xs p-0.5 text-zinc-400 ring-offset-background transition-colors hover:text-foreground focus:outline-hidden focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 disabled:pointer-events-none [&_svg]:pointer-events-none [&_svg]:shrink-0 [&_svg:not([class*='size-'])]:size-4",children:[(0,ur.jsx)(ul,{}),(0,ur.jsx)("span",{className:"sr-only",children:"Close"})]})]})]})}function vz({className:t,...e}){return(0,ur.jsx)("div",{"data-slot":"dialog-header",className:pe("flex flex-col gap-2 text-center sm:text-left",t),...e})}function Sz({className:t,...e}){return(0,ur.jsx)(yn.Title,{"data-slot":"dialog-title",className:pe("text-lg leading-none font-semibold",t),...e})}function wz({className:t,...e}){return(0,ur.jsx)(yn.Description,{"data-slot":"dialog-description",className:pe("text-sm text-muted-foreground",t),...e})}var pa=L(H(),1),cW={explanation:{title:()=>"Explain",context:({id:t})=>t,holdsDraft:!1,render:({id:t},{open:e})=>(0,pa.jsx)(IE,{id:t,onExplain:a=>e("explanation",{id:a})},t)},primitive:{title:({id:t})=>t,context:()=>"",holdsDraft:!0,render:({id:t},{close:e})=>(0,pa.jsx)(AC,{id:t,onDone:d0(e),onClose:e},t)},newPrimitive:{title:()=>"New primitive",context:()=>"",holdsDraft:!0,render:({kind:t},{close:e})=>(0,pa.jsx)(AC,{newKind:t,onDone:d0(e),onClose:e},`new ${t}`)},buildPreview:{title:()=>"cw build",context:()=>"nothing written yet",holdsDraft:!1,render:(t,{open:e})=>(0,pa.jsx)(kE,{onBuilt:a=>e("buildOutcome",{buildAnswer:a})})},buildOutcome:{title:()=>"cw build",context:()=>"",holdsDraft:!1,render:({buildAnswer:t})=>(0,pa.jsx)(LE,{buildAnswer:t})},addVendor:{title:()=>"Add vendor source",context:()=>"",holdsDraft:!0,render:(t,{close:e})=>(0,pa.jsx)(Oz,{onDone:d0(e),onClose:e})},testSuite:{title:({name:t})=>`.cw/test/${t}`,context:()=>"",holdsDraft:!0,render:({name:t},{close:e})=>(0,pa.jsx)(xz,{name:t,onDone:d0(e),onClose:e},t)},doctor:{title:()=>"Doctor",context:()=>"cw 0.6.1",holdsDraft:!1,render:(t,{open:e})=>(0,pa.jsx)(RE,{onBuilt:a=>e("buildOutcome",{buildAnswer:a})})}};function d0(t){return(e,a)=>{t(),cl(e,{description:a})}}var Cz=(0,au.createContext)(null);function ho(){return(0,au.useContext)(Cz)}function kz({children:t}){let[e,a]=(0,au.useState)(null),[r,n]=(0,au.useState)(!1),i={open:(s,l)=>{a({name:s,params:l}),n(!0)},close:()=>n(!1)},o=e===null?null:cW[e.name];return(0,pa.jsxs)(Cz.Provider,{value:i,children:[t,(0,pa.jsx)(yz,{open:r,onOpenChange:n,children:e!==null&&o!==null&&(0,pa.jsxs)(bz,{className:"flex max-h-[88vh] w-[920px] max-w-[calc(100%-48px)] flex-col gap-0 overflow-hidden rounded-[15px] border-0 p-0 shadow-[0_34px_80px_-22px_rgba(0,0,0,0.4)] sm:max-w-[calc(100%-48px)]",onInteractOutside:s=>o.holdsDraft&&s.preventDefault(),onEscapeKeyDown:s=>o.holdsDraft&&s.preventDefault(),children:[(0,pa.jsxs)(vz,{className:"flex-row items-baseline gap-2.5 border-b border-[#f0f0f0] py-[15px] pr-12 pl-[18px]",children:[(0,pa.jsx)(Sz,{className:"text-[14.5px] font-bold tracking-[-0.01em]",children:o.title(e.params)}),(0,pa.jsx)(wz,{className:"font-mono text-[11px] text-zinc-400",children:o.context(e.params)})]}),(0,pa.jsx)("div",{className:"min-h-0 flex-1 overflow-y-auto px-5 py-[18px]",children:o.render(e.params,i)})]})})]})}var p0=L(F(),1);var tue=L(F(),1);var fW=L(H(),1),Lz=li("inline-flex items-center justify-center gap-2 rounded-md text-sm font-medium whitespace-nowrap transition-[color,box-shadow] outline-none hover:bg-muted hover:text-muted-foreground focus-visible:border-ring focus-visible:ring-[3px] focus-visible:ring-ring/50 disabled:pointer-events-none disabled:opacity-50 aria-invalid:border-destructive aria-invalid:ring-destructive/20 data-[state=on]:bg-accent data-[state=on]:text-accent-foreground dark:aria-invalid:ring-destructive/40 [&_svg]:pointer-events-none [&_svg]:shrink-0 [&_svg:not([class*='size-'])]:size-4",{variants:{variant:{default:"bg-transparent",outline:"border border-input bg-transparent shadow-xs hover:bg-accent hover:text-accent-foreground"},size:{default:"h-9 min-w-9 px-2",sm:"h-8 min-w-8 px-1.5",lg:"h-10 min-w-10 px-2.5"}},defaultVariants:{variant:"default",size:"default"}});var h0=L(H(),1),Tz=p0.createContext({size:"default",variant:"default",spacing:0});function Pz({className:t,variant:e,size:a,spacing:r=0,children:n,...i}){return(0,h0.jsx)(qd.Root,{"data-slot":"toggle-group","data-variant":e,"data-size":a,"data-spacing":r,style:{"--gap":r},className:pe("group/toggle-group flex w-fit items-center gap-[--spacing(var(--gap))] rounded-md data-[spacing=default]:data-[variant=outline]:shadow-xs",t),...i,children:(0,h0.jsx)(Tz.Provider,{value:{variant:e,size:a,spacing:r},children:n})})}function Rz({className:t,children:e,variant:a,size:r,...n}){let i=p0.useContext(Tz);return(0,h0.jsx)(qd.Item,{"data-slot":"toggle-group-item","data-variant":i.variant||a,"data-size":i.size||r,"data-spacing":i.spacing,className:pe(Lz({variant:i.variant||a,size:i.size||r}),"w-auto min-w-0 shrink-0 px-3 focus:z-10 focus-visible:z-10","data-[spacing=0]:rounded-none data-[spacing=0]:shadow-none data-[spacing=0]:first:rounded-l-md data-[spacing=0]:last:rounded-r-md data-[spacing=0]:data-[variant=outline]:border-l-0 data-[spacing=0]:data-[variant=outline]:first:border-l",t),...n,children:e})}var se=L(H(),1);function DC({layerNames:t,kind:e,onKindChange:a}){let{open:r}=ho(),n=yc(),i=oi();if(n.data===void 0||i.data===void 0)return null;let o=n.data.data,s=i.data;if(s.type==="FaultsByFile")return(0,se.jsx)(dW,{faultsByFile:s});if(s.type==="Fault")return(0,se.jsx)(hW,{fault:s});let l=s.data.primitives.filter(({data:d})=>t.includes(d.layerName)),u=new Map(Object.keys(o).map(d=>[d,l.filter(({data:h})=>h.kind===d).length])),c=e??[...u].find(([,d])=>d>0)?.[0]??Object.keys(o)[0],f=l.filter(({data:d})=>d.kind===c);return(0,se.jsxs)("div",{className:"min-w-0",children:[(0,se.jsxs)("div",{className:"mb-3 flex items-baseline gap-[9px]",children:[(0,se.jsx)("h2",{className:"text-[12.5px] font-bold",children:"Charter primitives"}),(0,se.jsxs)("span",{className:"text-[11.5px] text-zinc-400",children:[l.length," in this charter"]}),t.includes("repo")&&(0,se.jsxs)(Ae,{size:"sm",variant:"outline",className:"ml-auto",onClick:()=>r("newPrimitive",{kind:c}),children:["New ",c]})]}),(0,se.jsx)(Pz,{type:"single",spacing:1.5,"aria-label":"Kinds",className:"mb-3 flex-wrap",value:c,onValueChange:d=>d!==""&&a(d),children:[...u].map(([d,h])=>(0,se.jsxs)(Rz,{value:d,"aria-label":d,className:`group/chip h-auto cursor-pointer gap-1.5 rounded-[9px] border bg-background px-2.5 py-1.5 text-[11.5px] font-medium text-zinc-700 capitalize hover:bg-background hover:text-zinc-700 data-[state=on]:border-foreground data-[state=on]:bg-foreground data-[state=on]:font-semibold data-[state=on]:text-white ${h===0&&d!==c?"opacity-50":""}`,children:[d,(0,se.jsx)(mi,{className:"rounded-none bg-transparent p-0 font-mono text-[10px] font-normal text-zinc-400 group-data-[state=on]/chip:text-white/70",children:h})]},d))}),(0,se.jsxs)("p",{className:"mb-2.5 flex items-baseline gap-2 px-0.5",children:[(0,se.jsx)("span",{className:"shrink-0 text-[10.5px] font-bold tracking-[0.06em] text-zinc-400 uppercase",children:"Activates when"}),(0,se.jsx)("span",{className:"text-xs leading-normal text-zinc-700","aria-label":"Activates when",children:o[c]})]}),f.length===0?(0,se.jsxs)("p",{className:"rounded-[14px] border p-[22px] text-center text-[12.5px] text-zinc-400",children:["No ",c," in this charter yet."]}):(0,se.jsx)(pW,{kind:c,listed:f})]})}function dW({faultsByFile:t}){let e=Object.entries(t.data.files);return(0,se.jsxs)("div",{className:"space-y-3.5",children:[(0,se.jsxs)(jr,{variant:"destructive",className:"rounded-xl border-[#f6d9d9] bg-[#fef6f6]",children:[(0,se.jsx)(Fr,{className:"text-[12.5px] font-bold text-foreground",children:"The engine will not read this charter"}),(0,se.jsxs)(Hr,{children:[e.length," file",e.length===1?" is":"s are"," refused, so there is no listing to show. Fix",e.length===1?" it":" them"," and the charter comes back."]})]}),(0,se.jsx)(fs,{faultsByFile:t,label:"Refused files"})]})}function hW({fault:t}){return(0,se.jsxs)(jr,{variant:"destructive",className:"rounded-xl border-[#f6d9d9] bg-[#fef6f6]",children:[(0,se.jsx)(Fr,{className:"text-[12.5px] font-bold text-foreground",children:t.data.message}),(0,se.jsx)(Hr,{children:t.data.fix})]})}function MC(t){return t===void 0?void 0:typeof t=="string"?[t]:t}function pW({kind:t,listed:e}){let{open:a}=ho(),r=t==="guide",n=t!=="mixin";return(0,se.jsx)("div",{className:"overflow-hidden rounded-[14px] border bg-background",children:(0,se.jsxs)(Tl,{"aria-label":`${t} primitives`,className:"table-fixed",children:[(0,se.jsx)(wE,{children:(0,se.jsxs)(Rl,{className:"border-[#ececef] bg-zinc-50 hover:bg-zinc-50 [&>th]:h-auto [&>th]:px-[15px] [&>th]:py-[9px] [&>th]:text-[9.5px] [&>th]:font-bold [&>th]:tracking-[0.07em] [&>th]:text-zinc-400 [&>th]:uppercase",children:[(0,se.jsx)(Il,{className:"w-[170px]",children:"Id"}),(0,se.jsx)(Il,{children:"Description"}),r&&(0,se.jsxs)(se.Fragment,{children:[(0,se.jsx)(Il,{className:"w-[170px] text-right",children:"Matching globs"}),(0,se.jsx)(Il,{className:"w-[120px] text-right",children:"Rationale"})]}),n&&(0,se.jsx)(Il,{className:"w-[120px] text-right",children:"Mixins"}),(0,se.jsx)(Il,{className:"w-[50px]"})]})}),(0,se.jsx)(Pl,{children:e.map(({data:{id:i,description:o,file:s,headers:l}})=>{let u=MC(l.globs);return(0,se.jsxs)(Rl,{className:"group/row border-[#f7f7f8] align-top hover:bg-zinc-50 [&>td]:px-[15px] [&>td]:py-3",children:[(0,se.jsx)(kn,{className:"truncate",children:(0,se.jsx)(Ae,{variant:"link",className:"block h-auto max-w-full truncate rounded-none p-0 text-left font-mono text-[11.5px] font-bold text-foreground",title:`Open ${s}`,onClick:()=>a("primitive",{id:i}),children:String(l.id)})}),(0,se.jsxs)(kn,{className:"whitespace-normal",children:[(0,se.jsx)("div",{className:"text-[12.5px] font-semibold",children:o}),(0,se.jsx)("div",{className:"mt-[3px] truncate font-mono text-[10.5px] text-zinc-400",children:s})]}),r&&(0,se.jsxs)(se.Fragment,{children:[(0,se.jsx)(EC,{named:u,none:"all patterns",said:u===void 0,label:"Matching globs"}),(0,se.jsx)(EC,{named:MC(l.rationale),none:"none",said:!1,label:"Rationale"})]}),n&&(0,se.jsx)(EC,{named:MC(l.mixins),none:"none",said:!1,label:"Mixins"}),(0,se.jsx)(kn,{children:(0,se.jsx)(Ae,{variant:"ghost",size:"icon",className:"ml-auto size-6 rounded-[7px] border border-transparent text-zinc-300 group-hover/row:border-zinc-200 group-hover/row:bg-background group-hover/row:text-zinc-400 hover:!border-foreground hover:bg-background hover:!text-foreground [&_svg:not([class*='size-'])]:size-[13px]","aria-label":`Explain ${i}`,onClick:()=>a("explanation",{id:i}),children:(0,se.jsx)(pn,{})})})]},i)})})]})})}function EC({named:t,none:e,said:a,label:r}){return(0,se.jsx)(kn,{"aria-label":r,children:(0,se.jsx)("div",{className:"flex min-w-0 flex-wrap content-start justify-end gap-1",children:t===void 0||t.length===0?(0,se.jsx)("span",{className:`text-[10.5px] ${a?"text-destructive":"text-zinc-300"}`,children:e}):t.map(n=>(0,se.jsx)(mi,{title:n,className:"block max-w-full truncate rounded-[5px] bg-zinc-100 px-1.5 py-0.5 font-mono text-[10px] font-normal text-zinc-700",children:n},n))})})}var qC=L(F(),1);var Lue=L(F(),1);var Iz=1,mW=.9,gW=.8,OW=.17,$C=.1,BC=.999,xW=.9999,yW=.99,bW=/[\\\/_+.#"@\[\(\{&]/,vW=/[\\\/_+.#"@\[\(\{&]/g,SW=/[\s-]/,Qz=/[\s-]/g;function _C(t,e,a,r,n,i,o){if(i===e.length)return n===t.length?Iz:yW;var s=`${n},${i}`;if(o[s]!==void 0)return o[s];for(var l=r.charAt(i),u=a.indexOf(l,n),c=0,f,d,h,p;u>=0;)f=_C(t,e,a,r,u+1,i+1,o),f>c&&(u===n?f*=Iz:bW.test(t.charAt(u-1))?(f*=gW,h=t.slice(n,u-1).match(vW),h&&n>0&&(f*=Math.pow(BC,h.length))):SW.test(t.charAt(u-1))?(f*=mW,p=t.slice(n,u-1).match(Qz),p&&n>0&&(f*=Math.pow(BC,p.length))):(f*=OW,n>0&&(f*=Math.pow(BC,u-n))),t.charAt(u)!==e.charAt(i)&&(f*=xW)),(f<$C&&a.charAt(u-1)===r.charAt(i+1)||r.charAt(i+1)===r.charAt(i)&&a.charAt(u-1)!==r.charAt(i))&&(d=_C(t,e,a,r,u+1,i+2,o),d*$C>f&&(f=d*$C)),f>c&&(c=f),u=a.indexOf(l,u+1);return o[s]=c,c}function Az(t){return t.toLowerCase().replace(Qz," ")}function Mz(t,e,a){return t=a&&a.length>0?`${t+" "+a.join(" ")}`:t,_C(t,e,Az(t),Az(e),0,0,{})}var J=L(F(),1);var qh='[cmdk-group=""]',zC='[cmdk-group-items=""]',wW='[cmdk-group-heading=""]',Dz='[cmdk-item=""]',Ez=`${Dz}:not([aria-disabled="true"])`,NC="cmdk-item-select",hf="data-value",CW=(t,e,a)=>Mz(t,e,a),$z=J.createContext(void 0),Zh=()=>J.useContext($z),Bz=J.createContext(void 0),XC=()=>J.useContext(Bz),_z=J.createContext(void 0),zz=J.forwardRef((t,e)=>{let a=pf(()=>{var P,G;return{search:"",value:(G=(P=t.value)!=null?P:t.defaultValue)!=null?G:"",selectedItemId:void 0,filtered:{count:0,items:new Map,groups:new Set}}}),r=pf(()=>new Set),n=pf(()=>new Map),i=pf(()=>new Map),o=pf(()=>new Set),s=Nz(t),{label:l,children:u,value:c,onValueChange:f,filter:d,shouldFilter:h,loop:p,disablePointerSelection:m=!1,vimBindings:x=!0,...g}=t,O=Dt(),y=Dt(),b=Dt(),v=J.useRef(null),S=DW();ru(()=>{if(c!==void 0){let P=c.trim();a.current.value=P,w.emit()}},[c]),ru(()=>{S(6,R)},[]);let w=J.useMemo(()=>({subscribe:P=>(o.current.add(P),()=>o.current.delete(P)),snapshot:()=>a.current,setState:(P,G,N)=>{var M,j,de,ee;if(!Object.is(a.current[P],G)){if(a.current[P]=G,P==="search")A(),Q(),S(1,$);else if(P==="value"){if(document.activeElement.hasAttribute("cmdk-input")||document.activeElement.hasAttribute("cmdk-root")){let Z=document.getElementById(b);Z?Z.focus():(M=document.getElementById(O))==null||M.focus()}if(S(7,()=>{var Z;a.current.selectedItemId=(Z=D())==null?void 0:Z.id,w.emit()}),N||S(5,R),((j=s.current)==null?void 0:j.value)!==void 0){let Z=G??"";(ee=(de=s.current).onValueChange)==null||ee.call(de,Z);return}}w.emit()}},emit:()=>{o.current.forEach(P=>P())}}),[]),k=J.useMemo(()=>({value:(P,G,N)=>{var M;G!==((M=i.current.get(P))==null?void 0:M.value)&&(i.current.set(P,{value:G,keywords:N}),a.current.filtered.items.set(P,T(G,N)),S(2,()=>{Q(),w.emit()}))},item:(P,G)=>(r.current.add(P),G&&(n.current.has(G)?n.current.get(G).add(P):n.current.set(G,new Set([P]))),S(3,()=>{A(),Q(),a.current.value||$(),w.emit()}),()=>{i.current.delete(P),r.current.delete(P),a.current.filtered.items.delete(P);let N=D();S(4,()=>{A(),N?.getAttribute("id")===P&&$(),w.emit()})}),group:P=>(n.current.has(P)||n.current.set(P,new Set),()=>{i.current.delete(P),n.current.delete(P)}),filter:()=>s.current.shouldFilter,label:l||t["aria-label"],getDisablePointerSelection:()=>s.current.disablePointerSelection,listId:O,inputId:b,labelId:y,listInnerRef:v}),[]);function T(P,G){var N,M;let j=(M=(N=s.current)==null?void 0:N.filter)!=null?M:CW;return P?j(P,a.current.search,G):0}function Q(){if(!a.current.search||s.current.shouldFilter===!1)return;let P=a.current.filtered.items,G=[];a.current.filtered.groups.forEach(M=>{let j=n.current.get(M),de=0;j.forEach(ee=>{let Z=P.get(ee);de=Math.max(Z,de)}),G.push([M,de])});let N=v.current;Y().sort((M,j)=>{var de,ee;let Z=M.getAttribute("id"),Ze=j.getAttribute("id");return((de=P.get(Ze))!=null?de:0)-((ee=P.get(Z))!=null?ee:0)}).forEach(M=>{let j=M.closest(zC);j?j.appendChild(M.parentElement===j?M:M.closest(`${zC} > *`)):N.appendChild(M.parentElement===N?M:M.closest(`${zC} > *`))}),G.sort((M,j)=>j[1]-M[1]).forEach(M=>{var j;let de=(j=v.current)==null?void 0:j.querySelector(`${qh}[${hf}="${encodeURIComponent(M[0])}"]`);de?.parentElement.appendChild(de)})}function $(){let P=Y().find(N=>N.getAttribute("aria-disabled")!=="true"),G=P?.getAttribute(hf);w.setState("value",G||void 0)}function A(){var P,G,N,M;if(!a.current.search||s.current.shouldFilter===!1){a.current.filtered.count=r.current.size;return}a.current.filtered.groups=new Set;let j=0;for(let de of r.current){let ee=(G=(P=i.current.get(de))==null?void 0:P.value)!=null?G:"",Z=(M=(N=i.current.get(de))==null?void 0:N.keywords)!=null?M:[],Ze=T(ee,Z);a.current.filtered.items.set(de,Ze),Ze>0&&j++}for(let[de,ee]of n.current)for(let Z of ee)if(a.current.filtered.items.get(Z)>0){a.current.filtered.groups.add(de);break}a.current.filtered.count=j}function R(){var P,G,N;let M=D();M&&(((P=M.parentElement)==null?void 0:P.firstChild)===M&&((N=(G=M.closest(qh))==null?void 0:G.querySelector(wW))==null||N.scrollIntoView({block:"nearest"})),M.scrollIntoView({block:"nearest"}))}function D(){var P;return(P=v.current)==null?void 0:P.querySelector(`${Dz}[aria-selected="true"]`)}function Y(){var P;return Array.from(((P=v.current)==null?void 0:P.querySelectorAll(Ez))||[])}function B(P){let G=Y()[P];G&&w.setState("value",G.getAttribute(hf))}function q(P){var G;let N=D(),M=Y(),j=M.findIndex(ee=>ee===N),de=M[j+P];(G=s.current)!=null&&G.loop&&(de=j+P<0?M[M.length-1]:j+P===M.length?M[0]:M[j+P]),de&&w.setState("value",de.getAttribute(hf))}function re(P){let G=D(),N=G?.closest(qh),M;for(;N&&!M;)N=P>0?MW(N,qh):EW(N,qh),M=N?.querySelector(Ez);M?w.setState("value",M.getAttribute(hf)):q(P)}let ie=()=>B(Y().length-1),z=P=>{P.preventDefault(),P.metaKey?ie():P.altKey?re(1):q(1)},Pe=P=>{P.preventDefault(),P.metaKey?B(0):P.altKey?re(-1):q(-1)};return J.createElement(ue.div,{ref:e,tabIndex:-1,...g,"cmdk-root":"",onKeyDown:P=>{var G;(G=g.onKeyDown)==null||G.call(g,P);let N=P.nativeEvent.isComposing||P.keyCode===229;if(!(P.defaultPrevented||N))switch(P.key){case"n":case"j":{x&&P.ctrlKey&&z(P);break}case"ArrowDown":{z(P);break}case"p":case"k":{x&&P.ctrlKey&&Pe(P);break}case"ArrowUp":{Pe(P);break}case"Home":{P.preventDefault(),B(0);break}case"End":{P.preventDefault(),ie();break}case"Enter":{P.preventDefault();let M=D();if(M){let j=new Event(NC);M.dispatchEvent(j)}}}}},J.createElement("label",{"cmdk-label":"",htmlFor:k.inputId,id:k.labelId,style:BW},l),m0(t,P=>J.createElement(Bz.Provider,{value:w},J.createElement($z.Provider,{value:k},P))))}),kW=J.forwardRef((t,e)=>{var a,r;let n=Dt(),i=J.useRef(null),o=J.useContext(_z),s=Zh(),l=Nz(t),u=(r=(a=l.current)==null?void 0:a.forceMount)!=null?r:o?.forceMount;ru(()=>{if(!u)return s.item(n,o?.id)},[u]);let c=Xz(n,i,[t.value,t.children,i],t.keywords),f=XC(),d=Ds(S=>S.value&&S.value===c.current),h=Ds(S=>u||s.filter()===!1?!0:S.search?S.filtered.items.get(n)>0:!0);J.useEffect(()=>{let S=i.current;if(!(!S||t.disabled))return S.addEventListener(NC,p),()=>S.removeEventListener(NC,p)},[h,t.onSelect,t.disabled]);function p(){var S,w;m(),(w=(S=l.current).onSelect)==null||w.call(S,c.current)}function m(){f.setState("value",c.current,!0)}if(!h)return null;let{disabled:x,value:g,onSelect:O,forceMount:y,keywords:b,...v}=t;return J.createElement(ue.div,{ref:ts(i,e),...v,id:n,"cmdk-item":"",role:"option","aria-disabled":!!x,"aria-selected":!!d,"data-disabled":!!x,"data-selected":!!d,onPointerMove:x||s.getDisablePointerSelection()?void 0:m,onClick:x?void 0:p},t.children)}),LW=J.forwardRef((t,e)=>{let{heading:a,children:r,forceMount:n,...i}=t,o=Dt(),s=J.useRef(null),l=J.useRef(null),u=Dt(),c=Zh(),f=Ds(h=>n||c.filter()===!1?!0:h.search?h.filtered.groups.has(o):!0);ru(()=>c.group(o),[]),Xz(o,s,[t.value,t.heading,l]);let d=J.useMemo(()=>({id:o,forceMount:n}),[n]);return J.createElement(ue.div,{ref:ts(s,e),...i,"cmdk-group":"",role:"presentation",hidden:f?void 0:!0},a&&J.createElement("div",{ref:l,"cmdk-group-heading":"","aria-hidden":!0,id:u},a),m0(t,h=>J.createElement("div",{"cmdk-group-items":"",role:"group","aria-labelledby":a?u:void 0},J.createElement(_z.Provider,{value:d},h))))}),TW=J.forwardRef((t,e)=>{let{alwaysRender:a,...r}=t,n=J.useRef(null),i=Ds(o=>!o.search);return!a&&!i?null:J.createElement(ue.div,{ref:ts(n,e),...r,"cmdk-separator":"",role:"separator"})}),PW=J.forwardRef((t,e)=>{let{onValueChange:a,...r}=t,n=t.value!=null,i=XC(),o=Ds(u=>u.search),s=Ds(u=>u.selectedItemId),l=Zh();return J.useEffect(()=>{t.value!=null&&i.setState("search",t.value)},[t.value]),J.createElement(ue.input,{ref:e,...r,"cmdk-input":"",autoComplete:"off",autoCorrect:"off",spellCheck:!1,"aria-autocomplete":"list",role:"combobox","aria-expanded":!0,"aria-controls":l.listId,"aria-labelledby":l.labelId,"aria-activedescendant":s,id:l.inputId,type:"text",value:n?t.value:o,onChange:u=>{n||i.setState("search",u.target.value),a?.(u.target.value)}})}),RW=J.forwardRef((t,e)=>{let{children:a,label:r="Suggestions",...n}=t,i=J.useRef(null),o=J.useRef(null),s=Ds(u=>u.selectedItemId),l=Zh();return J.useEffect(()=>{if(o.current&&i.current){let u=o.current,c=i.current,f,d=new ResizeObserver(()=>{f=requestAnimationFrame(()=>{let h=u.offsetHeight;c.style.setProperty("--cmdk-list-height",h.toFixed(1)+"px")})});return d.observe(u),()=>{cancelAnimationFrame(f),d.unobserve(u)}}},[]),J.createElement(ue.div,{ref:ts(i,e),...n,"cmdk-list":"",role:"listbox",tabIndex:-1,"aria-activedescendant":s,"aria-label":r,id:l.listId},m0(t,u=>J.createElement("div",{ref:ts(o,l.listInnerRef),"cmdk-list-sizer":""},u)))}),IW=J.forwardRef((t,e)=>{let{open:a,onOpenChange:r,overlayClassName:n,contentClassName:i,container:o,...s}=t;return J.createElement(Av,{open:a,onOpenChange:r},J.createElement(Qv,{container:o},J.createElement(Mv,{"cmdk-overlay":"",className:n}),J.createElement(Ev,{"aria-label":t.label,"cmdk-dialog":"",className:i},J.createElement(zz,{ref:e,...s}))))}),AW=J.forwardRef((t,e)=>Ds(a=>a.filtered.count===0)?J.createElement(ue.div,{ref:e,...t,"cmdk-empty":"",role:"presentation"}):null),QW=J.forwardRef((t,e)=>{let{progress:a,children:r,label:n="Loading...",...i}=t;return J.createElement(ue.div,{ref:e,...i,"cmdk-loading":"",role:"progressbar","aria-valuenow":a,"aria-valuemin":0,"aria-valuemax":100,"aria-label":n},m0(t,o=>J.createElement("div",{"aria-hidden":!0},o)))}),nu=Object.assign(zz,{List:RW,Item:kW,Input:PW,Group:LW,Separator:TW,Dialog:IW,Empty:AW,Loading:QW});function MW(t,e){let a=t.nextElementSibling;for(;a;){if(a.matches(e))return a;a=a.nextElementSibling}}function EW(t,e){let a=t.previousElementSibling;for(;a;){if(a.matches(e))return a;a=a.previousElementSibling}}function Nz(t){let e=J.useRef(t);return ru(()=>{e.current=t}),e}var ru=typeof window>"u"?J.useEffect:J.useLayoutEffect;function pf(t){let e=J.useRef();return e.current===void 0&&(e.current=t()),e}function Ds(t){let e=XC(),a=()=>t(e.snapshot());return J.useSyncExternalStore(e.subscribe,a,a)}function Xz(t,e,a,r=[]){let n=J.useRef(),i=Zh();return ru(()=>{var o;let s=(()=>{var u;for(let c of a){if(typeof c=="string")return c.trim();if(typeof c=="object"&&"current"in c)return c.current?(u=c.current.textContent)==null?void 0:u.trim():n.current}})(),l=r.map(u=>u.trim());i.value(t,s,l),(o=e.current)==null||o.setAttribute(hf,s),n.current=s}),n}var DW=()=>{let[t,e]=J.useState(),a=pf(()=>new Map);return ru(()=>{a.current.forEach(r=>r()),a.current=new Map},[t]),(r,n)=>{a.current.set(r,n),e({})}};function $W(t){let e=t.type;return typeof e=="function"?e(t.props):"render"in e?e.render(t.props):t}function m0({asChild:t,children:e},a){return t&&J.isValidElement(e)?J.cloneElement($W(e),{ref:e.ref},a(e.props.children)):a(e)}var BW={position:"absolute",width:"1px",height:"1px",padding:"0",margin:"-1px",overflow:"hidden",clip:"rect(0, 0, 0, 0)",whiteSpace:"nowrap",borderWidth:"0"};var Si=L(H(),1);function qz({className:t,...e}){return(0,Si.jsx)(nu,{"data-slot":"command",className:pe("flex h-full w-full flex-col overflow-hidden rounded-md bg-popover text-popover-foreground",t),...e})}function Zz({className:t,...e}){return(0,Si.jsxs)("div",{"data-slot":"command-input-wrapper",className:"flex h-9 items-center gap-2 border-b px-3",children:[(0,Si.jsx)(Ld,{className:"size-4 shrink-0 opacity-50"}),(0,Si.jsx)(nu.Input,{"data-slot":"command-input",className:pe("flex h-10 w-full rounded-md bg-transparent py-3 text-sm outline-hidden placeholder:text-muted-foreground disabled:cursor-not-allowed disabled:opacity-50",t),...e})]})}function Vz({className:t,...e}){return(0,Si.jsx)(nu.List,{"data-slot":"command-list",className:pe("max-h-[300px] scroll-py-1 overflow-x-hidden overflow-y-auto",t),...e})}function Uz({...t}){return(0,Si.jsx)(nu.Empty,{"data-slot":"command-empty",className:"py-6 text-center text-sm",...t})}function jz({className:t,...e}){return(0,Si.jsx)(nu.Group,{"data-slot":"command-group",className:pe("overflow-hidden p-1 text-foreground [&_[cmdk-group-heading]]:px-2 [&_[cmdk-group-heading]]:py-1.5 [&_[cmdk-group-heading]]:text-xs [&_[cmdk-group-heading]]:font-medium [&_[cmdk-group-heading]]:text-muted-foreground",t),...e})}function Fz({className:t,...e}){return(0,Si.jsx)(nu.Item,{"data-slot":"command-item",className:pe("relative flex cursor-default items-center gap-2 rounded-sm px-2 py-1.5 text-sm outline-hidden select-none data-[disabled=true]:pointer-events-none data-[disabled=true]:opacity-50 data-[selected=true]:bg-accent data-[selected=true]:text-accent-foreground [&_svg]:pointer-events-none [&_svg]:shrink-0 [&_svg:not([class*='size-'])]:size-4 [&_svg:not([class*='text-'])]:text-muted-foreground",t),...e})}var mt=L(H(),1);function Gz({onPick:t}){let[e,a]=(0,qC.useState)(""),[r,n]=(0,qC.useState)(!1),{data:i}=oi(e);return(0,mt.jsxs)(qz,{shouldFilter:!1,className:"relative w-full overflow-visible rounded-[9px] border bg-zinc-50 text-zinc-400 focus-within:border-foreground focus-within:bg-background focus-within:text-zinc-500 [&_[data-slot=command-input-wrapper]]:h-[32px] [&_[data-slot=command-input-wrapper]]:border-0 [&_[data-slot=command-input]]:h-8 [&_[data-slot=command-input]]:text-[12.5px] [&_[data-slot=command-input]]:text-foreground [&_[data-slot=command-input]]:placeholder:text-zinc-400",onFocus:()=>n(!0),onBlur:()=>n(!1),children:[(0,mt.jsx)(Zz,{placeholder:"Search everything",spellCheck:!1,value:e,onValueChange:a,onKeyDown:o=>o.key==="Escape"&&a("")}),r&&e!==""&&(0,mt.jsxs)(Vz,{className:"absolute top-full right-0 left-0 z-50 mt-[7px] max-h-[min(460px,62vh)] rounded-xl border bg-popover p-[5px] shadow-[0_20px_44px_-16px_rgba(0,0,0,0.3)] [&_[cmdk-group-heading]]:px-[11px] [&_[cmdk-group-heading]]:pt-2 [&_[cmdk-group-heading]]:pb-1.5 [&_[cmdk-group-heading]]:text-[10px] [&_[cmdk-group-heading]]:font-bold [&_[cmdk-group-heading]]:tracking-[0.07em] [&_[cmdk-group-heading]]:text-zinc-400 [&_[cmdk-group-heading]]:uppercase [&_[data-slot=command-group]]:p-0",onMouseDown:o=>o.preventDefault(),children:[i?.type==="FaultsByFile"&&(0,mt.jsx)("p",{className:"px-3 py-3.5 text-xs text-zinc-400",children:"The engine will not read this charter, so there is nothing to search."}),i?.type==="Fault"&&(0,mt.jsxs)("p",{className:"px-3 py-3.5 text-xs text-zinc-400",children:[i.data.message," ",i.data.fix]}),i?.type==="Primitives"&&(0,mt.jsxs)(mt.Fragment,{children:[(0,mt.jsx)(Uz,{className:"px-3 py-3.5 text-xs text-zinc-400",children:"Nothing in the charter says that."}),i.data.primitives.length>0&&(0,mt.jsx)(jz,{heading:`${i.data.primitives.length} primitive${i.data.primitives.length===1?"":"s"}`,children:i.data.primitives.map(o=>{let{id:s,kind:l,description:u,layerName:c,headers:f}=o.data;return(0,mt.jsxs)(Fz,{value:s,className:"grid cursor-pointer grid-cols-[74px_minmax(0,1fr)_max-content] items-baseline gap-2.5 rounded-lg px-[11px] py-2 data-[selected=true]:bg-zinc-50 data-[selected=true]:outline data-[selected=true]:outline-zinc-200",onSelect:()=>{a(""),n(!1),t(o)},children:[(0,mt.jsx)("span",{className:"font-mono text-[9.5px] font-bold tracking-[0.03em] text-zinc-500 uppercase",children:l}),(0,mt.jsxs)("span",{className:"min-w-0",children:[(0,mt.jsx)("span",{className:"block truncate font-mono text-xs text-foreground",children:(0,mt.jsx)(Hz,{text:String(f.id),word:e})}),(0,mt.jsx)("span",{className:"mt-0.5 block truncate text-[11px] leading-[1.45] text-zinc-400",children:(0,mt.jsx)(Hz,{text:u,word:e})})]}),(0,mt.jsx)(mi,{className:`rounded-[5px] px-1.5 py-0.5 font-mono text-[9.5px] font-bold tracking-[0.03em] ${_W[c]}`,children:c})]},s)})})]})]})]})}var _W={repo:"bg-[#eff6ff] text-[#1d4ed8]",vendor:"bg-[#f6f2ff] text-[#7c3aed]",builtin:"bg-zinc-100 text-zinc-700"};function Hz({text:t,word:e}){let a=t.toLowerCase().indexOf(e.toLowerCase());return a===-1||e===""?(0,mt.jsx)(mt.Fragment,{children:t}):(0,mt.jsxs)(mt.Fragment,{children:[t.slice(0,a),(0,mt.jsx)("mark",{className:"rounded-[2px] bg-[#fff2b8] text-inherit",children:t.slice(a,a+e.length)}),t.slice(a+e.length)]})}var ma=L(H(),1);function Yz(){let t=AA(),e=QA();if(t.data===void 0)return null;if(t.data.type!=="MainContexts")return(0,ma.jsx)("p",{className:"text-xs text-zinc-500",children:"Nothing was counted: the charter does not hold. Open Doctor to see why."});let{contexts:a}=t.data.data;if(a.length===0)return(0,ma.jsx)("p",{className:"text-xs text-zinc-500",children:"No agent is chosen, so no agent loads anything of the charter."});let r=e.data?.data.mainContextCeiling;return(0,ma.jsx)("div",{className:"space-y-6",children:a.map(({data:{agent:n,isExact:i,sessionLoads:o,fileLoads:s,totalTokens:l}})=>(0,ma.jsxs)("section",{className:"space-y-3","aria-label":`${n} main context`,children:[(0,ma.jsxs)("h2",{className:"text-[13px] font-semibold",children:[n," opens a session with ",l.toLocaleString("en-US")," tokens of the charter, ",i?"counted exactly":"estimated",r!==void 0&&(0,ma.jsxs)("span",{className:l>r?"text-[#b45309]":"text-zinc-400",children:[" ","\xB7 ",l>r?"past":"within"," the ceiling of ",r.toLocaleString("en-US")]})]}),[["Loaded when a session opens",o],["Loaded when a file it names is touched, not in the total",s]].map(([u,c])=>c.length>0&&(0,ma.jsxs)("div",{className:"space-y-1.5",children:[(0,ma.jsx)("h3",{className:"text-[10.5px] font-bold tracking-[0.06em] text-zinc-400 uppercase",children:u}),(0,ma.jsx)("table",{className:"w-full overflow-hidden rounded-[11px] border border-[#f0f0f0] text-xs","aria-label":u,children:(0,ma.jsx)("tbody",{children:c.map(({data:{id:f,kind:d,tokens:h,globs:p}})=>(0,ma.jsxs)("tr",{className:"border-b border-zinc-100 last:border-b-0",children:[(0,ma.jsx)("td",{className:"w-[90px] px-[13px] py-2 text-right font-mono",children:h.toLocaleString("en-US")}),(0,ma.jsx)("td",{className:"w-[90px] px-2 py-2 text-zinc-500",children:d}),(0,ma.jsx)("td",{className:"px-2 py-2 font-mono",children:f}),(0,ma.jsx)("td",{className:"px-2 py-2 font-mono text-zinc-400",children:p?.join(", ")})]},f))})})]},u))]},n))})}var Wz=L(F(),1);var De=L(H(),1);function Kz(){let{open:t}=ho(),e=Hm(),a=$A(),r=oi(),n=BA(),[i,o]=(0,Wz.useState)(null);if(e.data===void 0)return null;let{testSuites:s}=e.data.data,l=new Set(r.data?.type==="Primitives"?r.data.data.primitives.map(({data:m})=>m.id):[]),u=a.data?.type==="TestRunReport"?a.data:void 0,c=m=>u?.data.testCaseReports.filter(({data:x})=>x.suiteName===m)??[],f=s.reduce((m,{data:x})=>m+x.cases.length,0),d=u?.data.testCaseReports.filter(({data:m})=>!m.passed).length??0,h=async()=>{let{data:m}=await a.refetch();if(m?.type!=="TestRunReport")return;let x=m.data.testCaseReports.find(({data:g})=>!g.passed);x!==void 0&&o(x.data.suiteName)},p=async()=>{let m=await n.mutateAsync();o(m),t("testSuite",{name:m}),cl("Test file created",{description:`.cw/test/${m} \xB7 edit the cases, then run them`})};return(0,De.jsxs)("div",{className:"space-y-2.5",children:[(0,De.jsxs)("div",{className:`mb-[18px] flex flex-wrap items-center gap-[11px] rounded-xl border px-[15px] py-[13px] ${u===void 0?"":d>0?"border-[#f6d9d9] bg-[#fef6f6]":"border-[#dcf0e2] bg-[#f5fbf7]"}`,"aria-label":"Test summary",children:[(0,De.jsx)("span",{className:"text-[12.5px] font-bold",children:u===void 0?`${f} case${f===1?"":"s"} in ${s.length} file${s.length===1?"":"s"}`:`${u.data.testCaseReports.length-d} of ${u.data.testCaseReports.length} cases pass`}),(0,De.jsx)("span",{className:"min-w-0 flex-1 text-[11.5px] leading-[1.6] text-zinc-500",children:"A case names the file a change touches or the event it raises, then says what must come up. It runs nothing and asks no agent."}),(0,De.jsx)(Ae,{variant:"outline",disabled:n.isPending,onClick:()=>{p()},children:"New test file"}),(0,De.jsx)(Ae,{disabled:a.isFetching,onClick:()=>{h()},children:"Run all tests"})]}),a.data?.type==="FaultsByFile"&&(0,De.jsx)(fs,{faultsByFile:a.data,label:"Nothing was resolved"}),s.length===0&&(0,De.jsx)("div",{className:"rounded-xl border border-dashed px-[15px] py-3.5 text-[11.5px] leading-[1.6] text-zinc-500",children:"No test file yet. Test files live in .cw/test/."}),s.map(({data:m})=>{let x=c(m.name),g=x.filter(({data:O})=>!O.passed).length;return(0,De.jsxs)("section",{className:"overflow-hidden rounded-[14px] border bg-background","aria-label":m.name,children:[(0,De.jsxs)("div",{className:"flex items-baseline gap-2.5 px-[15px] py-3",children:[(0,De.jsxs)("button",{className:"flex min-w-0 flex-1 cursor-pointer items-baseline gap-2.5 text-left","aria-expanded":i===m.name,onClick:()=>o(i===m.name?null:m.name),children:[(0,De.jsx)("span",{className:"font-mono text-[11.5px] font-bold",children:m.name}),(0,De.jsx)("span",{className:"min-w-0 flex-1 text-[11.5px] text-zinc-500",children:m.description}),(0,De.jsxs)("span",{className:`font-mono text-[10.5px] ${g>0?"text-destructive":"text-zinc-400"}`,children:[m.cases.length," case",m.cases.length===1?"":"s",g>0&&` \xB7 ${g} failing`]})]}),(0,De.jsx)(Ae,{variant:"ghost",className:"h-auto p-0 text-[11.5px] text-zinc-400 hover:bg-transparent hover:text-foreground",onClick:()=>t("testSuite",{name:m.name}),children:"Edit"})]}),m.fault!==void 0&&(0,De.jsxs)("p",{className:"border-t border-[#f7f7f8] px-[15px] py-2.5 text-[11.5px] text-destructive",children:[m.fault.data.message," ",(0,De.jsx)("span",{className:"text-zinc-400",children:m.fault.data.fix})]}),i===m.name&&m.cases.map(({data:O},y)=>(0,De.jsx)(zW,{testCase:O,testCaseReport:x[y],isHeld:O.id===void 0||l.has(O.id),onOpen:b=>t("primitive",{id:b})},y))]},m.name)})]})}function zW({testCase:t,testCaseReport:e,isHeld:a,onOpen:r}){let n=e?.data.unmet,{id:i,expectation:o}=t;return(0,De.jsxs)("div",{className:`grid grid-cols-[minmax(150px,1fr)_minmax(0,1.4fr)_auto] items-baseline gap-3 border-t border-[#f7f7f8] px-[15px] py-2.5 ${n?"bg-[#fef6f6]":""}`,children:[(0,De.jsx)("span",{className:"font-mono text-[10.5px]",children:t.situation}),n!==void 0?(0,De.jsxs)("span",{className:"font-mono text-[10.5px] text-destructive",children:[n.data.message," ",(0,De.jsx)("span",{className:"text-zinc-400",children:n.data.fix})]}):(0,De.jsx)("span",{className:"font-mono text-[10.5px] text-zinc-400",children:i===void 0||!o.endsWith(i)?o:(0,De.jsxs)(De.Fragment,{children:[o.slice(0,-i.length),a?(0,De.jsx)("button",{className:"cursor-pointer text-[#1d4ed8] underline underline-offset-2",onClick:()=>r(i),children:i}):(0,De.jsxs)(De.Fragment,{children:[(0,De.jsx)("span",{className:"underline decoration-dotted underline-offset-2",children:i})," ",(0,De.jsx)(mi,{className:"rounded-[5px] bg-zinc-100 px-1.5 py-0 font-sans text-[10px] font-normal text-zinc-500",children:"not in the charter"})]})]})}),(0,De.jsx)(mi,{className:`rounded-[5px] px-[7px] py-0 text-[11.5px] font-bold tracking-[0.04em] [font-variant-caps:all-small-caps] ${e===void 0?"bg-zinc-50 text-[#c4c4c8]":e.data.passed?"bg-[#f0fdf4] text-[#15803d]":"bg-[#fdeef0] text-[#b91c1c]"}`,children:e===void 0?"not run":e.data.passed?"pass":"fail"})]})}var Zt=L(H(),1);function Jz(){let{open:t}=ho(),e=MA(),a=oi(),r=DA();if(e.data===void 0)return null;let n=e.data,i=a.data?.type==="Primitives"?a.data.data.primitives.filter(({data:s})=>s.layerName==="vendor"):[],o=async s=>{let l=await r.mutateAsync(s.split("/").at(-1)??"");if(l!==null)return void cl.error(l.data.message,{description:l.data.fix});cl("Vendor source removed",{description:`${s} \xB7 run Build to compile the charter without it`})};return n.length===0?(0,Zt.jsxs)("div",{className:"flex items-center gap-[9px] rounded-xl border border-dashed px-[15px] py-3.5","aria-label":"Vendor sources",children:[(0,Zt.jsx)("span",{className:"text-xs font-semibold",children:"No vendor source installed"}),(0,Zt.jsx)(Ae,{size:"sm",className:"ml-auto",onClick:()=>t("addVendor",{}),children:"Add vendor source"})]}):(0,Zt.jsxs)("section",{className:"divide-y divide-[#f0f0f0] overflow-hidden rounded-[13px] border bg-background","aria-label":"Vendor sources",children:[(0,Zt.jsx)("h2",{className:"px-3.5 py-[11px] text-[10.5px] font-bold tracking-[0.06em] text-zinc-400 uppercase",children:"Vendor sources"}),n.map(s=>{let l=i.filter(({data:c})=>c.file.startsWith(`${s}/`)),u=[...new Set(l.map(({data:c})=>c.kind))].sort().map(c=>[c,l.filter(({data:f})=>f.kind===c).length]);return(0,Zt.jsxs)("div",{className:"flex flex-col gap-2.5 bg-[#f6f2ff] px-3.5 py-3","aria-label":s,children:[(0,Zt.jsxs)("div",{className:"min-w-0 space-y-0.5",children:[(0,Zt.jsx)("div",{className:"text-[12.5px] font-semibold",children:s.split("/").at(-1)}),(0,Zt.jsxs)("div",{className:"text-[11px] text-zinc-500",children:[(0,Zt.jsxs)("span",{className:"font-mono",children:[s,"/"]})," \xB7 read-only"]})]}),(0,Zt.jsx)("dl",{className:"grid grid-cols-[1fr_auto] gap-x-2 gap-y-1.5 text-[11.5px] text-zinc-500","aria-label":"Primitives by kind",children:u.map(([c,f])=>(0,Zt.jsxs)("div",{className:"contents",children:[(0,Zt.jsx)("dt",{children:c}),(0,Zt.jsx)("dd",{className:"font-mono text-[10.5px] text-zinc-400",children:f})]},c))}),(0,Zt.jsx)(Ae,{size:"sm",variant:"outline",className:"self-start",disabled:r.isPending,onClick:()=>{o(s)},children:"Remove"})]},s)}),(0,Zt.jsx)("div",{className:"px-3.5 py-[11px]",children:(0,Zt.jsx)(Ae,{size:"sm",variant:"outline",onClick:()=>t("addVendor",{}),children:"Add source"})})]})}var iu=L(H(),1),eN=({...t})=>(0,iu.jsx)(VA,{theme:"light",className:"toaster group",icons:{success:(0,iu.jsx)(Go,{className:"size-4"}),info:(0,iu.jsx)(kd,{className:"size-4"}),warning:(0,iu.jsx)(Ko,{className:"size-4"}),error:(0,iu.jsx)(Wo,{className:"size-4"}),loading:(0,iu.jsx)(Yo,{className:"size-4 animate-spin"})},style:{"--normal-bg":"var(--popover)","--normal-text":"var(--popover-foreground)","--normal-border":"var(--border)","--border-radius":"var(--radius)"},...t});var qe=L(H(),1),NW=[["repo","Repo Charter"],["vendor","Vendor"],["test","Test"],["context","Context"]],g0="rounded-2xl border bg-background px-[22px] py-5";function XW(){let[t,e]=(0,Vh.useState)("repo"),[a,r]=(0,Vh.useState)(null),{open:n}=ho();return(0,qe.jsxs)(qe.Fragment,{children:[(0,qe.jsxs)("header",{className:"sticky top-0 z-20 flex h-14 items-center gap-3 border-b bg-background px-[26px]",children:[(0,qe.jsxs)("span",{className:"flex items-center gap-[9px] text-[13.5px] font-bold tracking-[-0.01em]",children:[(0,qe.jsx)("img",{src:"./logo.png",alt:"",className:"size-[22px] object-contain"}),"Cherry Works"]}),(0,qe.jsx)("span",{className:"font-mono text-[11.5px] text-zinc-400"}),(0,qe.jsx)("div",{className:"ml-auto flex w-full max-w-[460px]",children:(0,qe.jsx)(Gz,{onPick:({data:{id:i,kind:o,layerName:s}})=>{e(s==="vendor"?"vendor":"repo"),r(o),n("primitive",{id:i})}})}),(0,qe.jsx)(Ae,{variant:"outline",onClick:()=>n("buildPreview",{}),children:"Build"}),(0,qe.jsx)(Ae,{variant:"outline",onClick:()=>n("doctor",{}),children:"Doctor"})]}),(0,qe.jsx)("main",{className:"mx-auto max-w-[1120px] px-[26px] pt-[22px] pb-[60px]",children:(0,qe.jsxs)(u0,{value:t,onValueChange:i=>{e(i),r(null)},children:[(0,qe.jsx)(c0,{className:"mb-4 h-auto w-full gap-1 rounded-[11px] bg-[#e9e9ec] p-1",children:NW.map(([i,o])=>(0,qe.jsx)(zh,{value:i,className:"h-auto rounded-lg py-[9px] text-[12.5px] font-semibold text-zinc-500 data-[state=active]:shadow-[0_1px_3px_rgba(0,0,0,0.09)]",children:o},i))}),(0,qe.jsx)(Es,{value:"repo",className:g0,children:(0,qe.jsx)(DC,{layerNames:["repo","builtin"],kind:a,onKindChange:r})}),(0,qe.jsxs)(Es,{value:"vendor",className:`${g0} grid items-start gap-4 md:has-[>section]:grid-cols-[210px_minmax(0,1fr)]`,children:[(0,qe.jsx)(Jz,{}),(0,qe.jsx)(DC,{layerNames:["vendor"],kind:a,onKindChange:r})]}),(0,qe.jsx)(Es,{value:"test",className:g0,children:(0,qe.jsx)(Kz,{})}),(0,qe.jsx)(Es,{value:"context",className:g0,children:(0,qe.jsx)(Yz,{})})]})}),(0,qe.jsx)(eN,{})]})}var qW=new Bb;(0,tN.createRoot)(document.getElementById("root")).render((0,qe.jsx)(Vh.StrictMode,{children:(0,qe.jsx)(Lb,{client:qW,children:(0,qe.jsx)(kz,{children:(0,qe.jsx)(XW,{})})})}));
139
+ Please report this to https://github.com/markedjs/marked.`,t){let r="<p>An error occurred:</p><pre>"+Rr(a.message+"",!0)+"</pre>";return e?Promise.resolve(r):r}if(e)return Promise.reject(a);throw a}}},Jl=new CC;function it(t,e){return Jl.parse(t,e)}it.options=it.setOptions=function(t){return Jl.setOptions(t),it.defaults=Jl.defaults,tz(it.defaults),it};it.getDefaults=gC;it.defaults=eu;function J8(...t){return Jl.use(...t),it.defaults=Jl.defaults,tz(it.defaults),it}it.use=J8;it.walkTokens=function(t,e){return Jl.walkTokens(t,e)};it.parseInline=Jl.parseInline;it.Parser=_n;it.parser=_n.parse;it.Renderer=l0;it.TextRenderer=wC;it.Lexer=Bn;it.lexer=Bn.lex;it.Tokenizer=s0;it.Hooks=Dh;it.parse=it;var $se=it.options,Bse=it.setOptions,_se=it.walkTokens,zse=it.parseInline;var Nse=_n.parse,Xse=Bn.lex;var Hse=L(F(),1);var Nh=L(H(),1);function u0({className:t,orientation:e="horizontal",...a}){return(0,Nh.jsx)(Ll.Root,{"data-slot":"tabs","data-orientation":e,orientation:e,className:pe("group/tabs flex gap-2 data-[orientation=horizontal]:flex-col",t),...a})}var eW=li("group/tabs-list inline-flex w-fit items-center justify-center rounded-lg p-[3px] text-muted-foreground group-data-[orientation=horizontal]/tabs:h-9 group-data-[orientation=vertical]/tabs:h-fit group-data-[orientation=vertical]/tabs:flex-col data-[variant=line]:rounded-none",{variants:{variant:{default:"bg-muted",line:"gap-1 bg-transparent"}},defaultVariants:{variant:"default"}});function c0({className:t,variant:e="default",...a}){return(0,Nh.jsx)(Ll.List,{"data-slot":"tabs-list","data-variant":e,className:pe(eW({variant:e}),t),...a})}function zh({className:t,...e}){return(0,Nh.jsx)(Ll.Trigger,{"data-slot":"tabs-trigger",className:pe("relative inline-flex h-[calc(100%-1px)] flex-1 items-center justify-center gap-1.5 rounded-md border border-transparent px-2 py-1 text-sm font-medium whitespace-nowrap text-foreground/60 transition-all group-data-[orientation=vertical]/tabs:w-full group-data-[orientation=vertical]/tabs:justify-start hover:text-foreground focus-visible:border-ring focus-visible:ring-[3px] focus-visible:ring-ring/50 focus-visible:outline-1 focus-visible:outline-ring disabled:pointer-events-none disabled:opacity-50 group-data-[variant=default]/tabs-list:data-[state=active]:shadow-sm group-data-[variant=line]/tabs-list:data-[state=active]:shadow-none dark:text-muted-foreground dark:hover:text-foreground [&_svg]:pointer-events-none [&_svg]:shrink-0 [&_svg:not([class*='size-'])]:size-4","group-data-[variant=line]/tabs-list:bg-transparent group-data-[variant=line]/tabs-list:data-[state=active]:bg-transparent dark:group-data-[variant=line]/tabs-list:data-[state=active]:border-transparent dark:group-data-[variant=line]/tabs-list:data-[state=active]:bg-transparent","data-[state=active]:bg-background data-[state=active]:text-foreground dark:data-[state=active]:border-input dark:data-[state=active]:bg-input/30 dark:data-[state=active]:text-foreground","after:absolute after:bg-foreground after:opacity-0 after:transition-opacity group-data-[orientation=horizontal]/tabs:after:inset-x-0 group-data-[orientation=horizontal]/tabs:after:bottom-[-5px] group-data-[orientation=horizontal]/tabs:after:h-0.5 group-data-[orientation=vertical]/tabs:after:inset-y-0 group-data-[orientation=vertical]/tabs:after:-right-1 group-data-[orientation=vertical]/tabs:after:w-0.5 group-data-[variant=line]/tabs-list:data-[state=active]:after:opacity-100",t),...e})}function Es({className:t,...e}){return(0,Nh.jsx)(Ll.Content,{"data-slot":"tabs-content",className:pe("flex-1 outline-none",t),...e})}var lr=L(H(),1),tW=new CC({renderer:{html:({text:t})=>t.replace(/&/g,"&amp;").replace(/</g,"&lt;").replace(/>/g,"&gt;")},walkTokens:t=>{(t.type==="link"||t.type==="image")&&/^\s*(javascript|vbscript|data):/i.test(t.href)&&(t.href="#")}}),cz="h-auto flex-none cursor-pointer rounded-md px-[11px] py-[5px] text-[11.5px] font-semibold text-zinc-500 data-[state=active]:shadow-[0_1px_2px_rgba(0,0,0,0.08)]";function kC({body:t,onChange:e}){return(0,lr.jsxs)(u0,{defaultValue:e===void 0?"preview":"source",className:"gap-0 overflow-hidden rounded-xl border bg-background",children:[(0,lr.jsxs)("div",{className:"flex items-center gap-2.5 border-b border-[#f0f0f0] px-[13px] py-[9px]",children:[(0,lr.jsx)("span",{className:"text-[10.5px] font-bold tracking-[0.06em] text-zinc-400 uppercase",children:"Body"}),(0,lr.jsx)("span",{className:"font-mono text-[10.5px] text-zinc-400",children:"markdown"}),(0,lr.jsxs)(c0,{className:"ml-auto h-auto gap-0.5 rounded-lg bg-[#f0f0f2] p-[3px]",children:[(0,lr.jsx)(zh,{value:"source",className:cz,children:"Source"}),(0,lr.jsx)(zh,{value:"preview",className:cz,children:"Preview"})]})]}),(0,lr.jsx)(Es,{value:"source",className:"h-[300px] flex-none",children:(0,lr.jsx)(aW,{body:t,onChange:e})}),(0,lr.jsx)(Es,{value:"preview",children:(0,lr.jsx)("div",{className:"min-h-32 px-[18px] py-4 text-[12.5px] leading-[1.65] text-zinc-700 [&_code]:rounded [&_code]:bg-muted [&_code]:px-1 [&_code]:font-mono [&_code]:text-xs [&_h1]:mb-[7px] [&_h1]:text-[15px] [&_h1]:font-bold [&_h1]:text-foreground [&_h2]:mt-4 [&_h2]:mb-[7px] [&_h2]:text-[13px] [&_h2]:font-bold [&_h2]:text-foreground [&_strong]:font-semibold [&_strong]:text-foreground [&_li]:ml-5 [&_ol]:list-decimal [&_p]:mb-2 [&_ul]:list-disc",dangerouslySetInnerHTML:{__html:tW.parse(t,{async:!1})}})})]})}function aW({body:t,onChange:e}){let a=(0,fz.useCallback)(r=>{let n=new oe({parent:r,doc:t,extensions:[U5(),G$(Y$),lB(),Xl.of([..._B,...dB]),oe.lineWrapping,oe.editable.of(e!==void 0),oe.updateListener.of(i=>{i.docChanged&&e?.(i.state.doc.toString())})]});return()=>n.destroy()},[]);return(0,lr.jsx)("div",{className:"h-full",ref:a})}var ole=L(F(),1);var dz=L(H(),1);function tu({className:t,type:e,...a}){return(0,dz.jsx)("input",{type:e,"data-slot":"input",className:pe("h-[30px] w-full min-w-0 rounded-lg border border-input bg-background px-[11px] py-1 font-mono text-[11.5px] text-foreground transition-[color,box-shadow] outline-none selection:bg-primary selection:text-primary-foreground file:inline-flex file:h-7 file:border-0 file:bg-transparent file:text-sm file:font-medium file:text-foreground placeholder:text-muted-foreground disabled:pointer-events-none disabled:cursor-not-allowed disabled:opacity-50 dark:bg-input/30","focus-visible:border-[#d92f45]","aria-invalid:border-destructive aria-invalid:ring-destructive/20 dark:aria-invalid:ring-destructive/40",t),...a})}var ule=L(F(),1);var hz=L(H(),1);function Xh({className:t,...e}){return(0,hz.jsx)(Dg.Root,{"data-slot":"label",className:pe("flex items-center gap-2 text-sm leading-none font-medium select-none group-data-[disabled=true]:pointer-events-none group-data-[disabled=true]:opacity-50 peer-disabled:cursor-not-allowed peer-disabled:opacity-50",t),...e})}var hle=L(F(),1);var It=L(H(),1);function LC({...t}){return(0,It.jsx)(Da.Root,{"data-slot":"select",...t})}function TC({...t}){return(0,It.jsx)(Da.Value,{"data-slot":"select-value",...t})}function PC({className:t,size:e="default",children:a,...r}){return(0,It.jsxs)(Da.Trigger,{"data-slot":"select-trigger","data-size":e,className:pe("flex w-fit cursor-pointer items-center justify-between gap-2 rounded-lg border border-input bg-background px-[11px] py-1 font-mono text-[11.5px] whitespace-nowrap text-foreground transition-[color,box-shadow] outline-none focus-visible:border-[#d92f45] disabled:cursor-not-allowed disabled:opacity-50 aria-invalid:border-destructive aria-invalid:ring-destructive/20 data-[placeholder]:text-muted-foreground data-[size=default]:h-[30px] data-[size=sm]:h-7 *:data-[slot=select-value]:line-clamp-1 *:data-[slot=select-value]:flex *:data-[slot=select-value]:items-center *:data-[slot=select-value]:gap-2 dark:bg-input/30 dark:hover:bg-input/50 dark:aria-invalid:ring-destructive/40 [&_svg]:pointer-events-none [&_svg]:shrink-0 [&_svg:not([class*='size-'])]:size-4 [&_svg:not([class*='text-'])]:text-muted-foreground",t),...r,children:[a,(0,It.jsx)(Da.Icon,{asChild:!0,children:(0,It.jsx)(xc,{className:"size-4 opacity-50"})})]})}function RC({className:t,children:e,position:a="item-aligned",align:r="center",...n}){return(0,It.jsx)(Da.Portal,{children:(0,It.jsxs)(Da.Content,{"data-slot":"select-content",className:pe("relative z-50 max-h-(--radix-select-content-available-height) min-w-[8rem] origin-(--radix-select-content-transform-origin) overflow-x-hidden overflow-y-auto rounded-md border bg-popover text-popover-foreground shadow-md data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2 data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=closed]:zoom-out-95 data-[state=open]:animate-in data-[state=open]:fade-in-0 data-[state=open]:zoom-in-95",a==="popper"&&"data-[side=bottom]:translate-y-1 data-[side=left]:-translate-x-1 data-[side=right]:translate-x-1 data-[side=top]:-translate-y-1",t),position:a,align:r,...n,children:[(0,It.jsx)(rW,{}),(0,It.jsx)(Da.Viewport,{className:pe("p-1",a==="popper"&&"h-[var(--radix-select-trigger-height)] w-full min-w-[var(--radix-select-trigger-width)] scroll-my-1"),children:e}),(0,It.jsx)(nW,{})]})})}function IC({className:t,children:e,...a}){return(0,It.jsxs)(Da.Item,{"data-slot":"select-item",className:pe("relative flex w-full cursor-default items-center gap-2 rounded-sm py-1.5 pr-8 pl-2 text-sm outline-hidden select-none focus:bg-accent focus:text-accent-foreground data-[disabled]:pointer-events-none data-[disabled]:opacity-50 [&_svg]:pointer-events-none [&_svg]:shrink-0 [&_svg:not([class*='size-'])]:size-4 [&_svg:not([class*='text-'])]:text-muted-foreground *:[span]:last:flex *:[span]:last:items-center *:[span]:last:gap-2",t),...a,children:[(0,It.jsx)("span",{"data-slot":"select-item-indicator",className:"absolute right-2 flex size-3.5 items-center justify-center",children:(0,It.jsx)(Da.ItemIndicator,{children:(0,It.jsx)(wd,{className:"size-4"})})}),(0,It.jsx)(Da.ItemText,{children:e})]})}function rW({className:t,...e}){return(0,It.jsx)(Da.ScrollUpButton,{"data-slot":"select-scroll-up-button",className:pe("flex cursor-default items-center justify-center py-1",t),...e,children:(0,It.jsx)(Cd,{className:"size-4"})})}function nW({className:t,...e}){return(0,It.jsx)(Da.ScrollDownButton,{"data-slot":"select-scroll-down-button",className:pe("flex cursor-default items-center justify-center py-1",t),...e,children:(0,It.jsx)(xc,{className:"size-4"})})}var K=L(H(),1);function AC({id:t,newKind:e,onDone:a,onClose:r}){let{data:n}=CA(t);if(t===void 0)return(0,K.jsx)(pz,{openedPrimitive:null,entityTag:"",newKind:e??"",onDone:a,onClose:r});if(n===void 0)return null;let{answer:i,entityTag:o}=n;return i.type==="Fault"?(0,K.jsx)(gz,{faults:[i]}):i.data.layerName!=="repo"?(0,K.jsx)(iW,{openedPrimitive:i}):(0,K.jsx)(pz,{openedPrimitive:i,entityTag:o,newKind:"",onDone:a,onClose:r})}function pz({openedPrimitive:t,entityTag:e,newKind:a,onDone:r,onClose:n}){let i=t?.data,[o,s]=(0,df.useState)(i?.kind??a),[l,u]=(0,df.useState)(i===void 0?"":String(i.headers.id)),[c,f]=(0,df.useState)(()=>Object.fromEntries(Object.entries(i?.headers??{}).filter(([R])=>R!=="id").map(([R,D])=>[R,typeof D=="string"?D:[...D]]))),[d,h]=(0,df.useState)(t?.data.body??""),[p,m]=(0,df.useState)([]),{data:x}=yc(),{data:g}=kA(o),{data:O}=oi(),y=LA(),b=TA(),v=PA(),S=x===void 0?[]:Object.keys(x.data),w=g?.type==="PrimitiveRequirements"?g.data.headers:[],k=O?.type==="Primitives"?O.data.primitives.filter(({data:R})=>R.kind==="corpus").map(({data:R})=>R.id):[],T=Object.fromEntries(w.flatMap(({data:{field:R}})=>{let D=c[R],Y=typeof D=="string"?D.trim():(D??[]).map(B=>B.trim()).filter(B=>B!=="");return Y.length===0?[]:[[R,Y]]})),Q=R=>m(R.type==="Faults"?R.data.faults:[R]),$=async()=>{let R=t===null?await y.mutateAsync({kind:o,id:l,headers:T,body:d}):await b.mutateAsync({param:{id:t.data.id},header:{"if-match":e},json:{headers:T,body:d}});if(R.type!=="Primitive")return Q(R);let{file:D,headers:Y}=R.data;r(t===null?"Primitive created":"Primitive saved",`${D} \xB7 ${t===null&&typeof Y.executionPath=="string"?`${Y.executionPath} beside it is the file it runs, write the script there \xB7 `:""}nothing compiled until the next build`)},A=async()=>{if(t===null)return;let R=await v.mutateAsync(t.data.id);if(R!==null)return Q(R);r("Primitive deleted",`${t.data.file} \xB7 what still names it is reported by Doctor`)};return(0,K.jsxs)("div",{className:"space-y-3.5",children:[(0,K.jsxs)("div",{className:mz,children:[t===null?(0,K.jsxs)(K.Fragment,{children:[(0,K.jsx)(fo,{label:"kind",htmlFor:"primitive-kind",children:(0,K.jsxs)(LC,{value:o,onValueChange:s,children:[(0,K.jsx)(PC,{id:"primitive-kind",className:"w-full",children:(0,K.jsx)(TC,{})}),(0,K.jsx)(RC,{children:S.map(R=>(0,K.jsx)(IC,{value:R,children:R},R))})]})}),(0,K.jsx)(fo,{label:"id",htmlFor:"primitive-id",children:(0,K.jsx)(tu,{id:"primitive-id",value:l,placeholder:"no-any",spellCheck:!1,onChange:R=>u(R.currentTarget.value)})})]}):(0,K.jsxs)(K.Fragment,{children:[(0,K.jsx)(fo,{label:"kind",hint:"the id is the file \u2014 rename by creating a new primitive and deleting this one",children:(0,K.jsx)("span",{className:"font-mono text-[11.5px]",children:o})}),(0,K.jsx)(fo,{label:"id",children:(0,K.jsx)("span",{className:"font-mono text-[11.5px]",children:l})})]}),w.map(({data:{field:R,shape:D,required:Y,allowedValues:B}})=>(0,K.jsx)(fo,{label:R,htmlFor:`header-${R}`,hint:Y?"required":void 0,children:D==="list"?(0,K.jsx)(oW,{field:R,entries:Array.isArray(c[R])?c[R]:[],onChange:q=>f({...c,[R]:q})}):B!==void 0?(0,K.jsxs)(LC,{value:typeof c[R]=="string"?c[R]:"",onValueChange:q=>f({...c,[R]:q}),children:[(0,K.jsx)(PC,{id:`header-${R}`,className:"w-full",children:(0,K.jsx)(TC,{placeholder:"\u2014"})}),(0,K.jsx)(RC,{children:B.map(q=>(0,K.jsx)(IC,{value:q,children:q},q))})]}):(0,K.jsx)(tu,{id:`header-${R}`,spellCheck:!1,autoComplete:"off",value:typeof c[R]=="string"?c[R]:"",list:R==="rationale"?"corpus-ids":void 0,onChange:q=>f({...c,[R]:q.currentTarget.value})})},R))]}),(0,K.jsx)("datalist",{id:"corpus-ids",children:k.map(R=>(0,K.jsx)("option",{value:R},R))}),(0,K.jsx)(kC,{body:d,onChange:h}),p.length>0&&(0,K.jsx)(gz,{faults:p}),(0,K.jsxs)("div",{className:ci,children:[(0,K.jsx)(Ae,{onClick:()=>{$()},children:t===null?"Create primitive":"Save"}),(0,K.jsx)(Ae,{variant:"outline",onClick:n,children:"Cancel"}),t!==null&&(0,K.jsx)(Ae,{variant:"destructive",className:"ml-auto",onClick:()=>{A()},children:"Delete"})]})]})}function iW({openedPrimitive:t}){let{kind:e,description:a,file:r,layerName:n,headers:i}=t.data;return(0,K.jsxs)("div",{className:"space-y-3.5",children:[(0,K.jsxs)(jr,{className:"rounded-xl border-[#7c3aed33] bg-[#f6f2ff]",children:[(0,K.jsx)(Fr,{className:"text-[12.5px] font-bold",children:n==="vendor"?"Installed from a vendor, and read-only here.":"Built into cw, and read-only here."}),(0,K.jsx)(Hr,{className:"text-[11.5px] text-zinc-600",children:"To differ from it, author a primitive of your own under an id of its own."})]}),(0,K.jsxs)("div",{className:mz,children:[(0,K.jsx)(fo,{label:"kind",children:(0,K.jsx)("span",{className:"font-mono text-[11.5px]",children:e})}),(0,K.jsx)(fo,{label:"file",children:(0,K.jsx)("span",{className:"font-mono text-[11.5px]",children:r})}),(0,K.jsx)(fo,{label:"description",children:(0,K.jsx)("span",{className:"text-xs",children:a})}),Object.entries(i).filter(([o])=>o!=="id"&&o!=="description").map(([o,s])=>(0,K.jsx)(fo,{label:o,children:(0,K.jsx)("span",{className:"font-mono text-[11.5px]",children:typeof s=="string"?s:s.join(", ")})},o))]}),(0,K.jsx)(kC,{body:t.data.body})]})}var mz="overflow-hidden rounded-[11px] border border-[#f0f0f0] bg-background divide-y divide-zinc-100";function fo({label:t,htmlFor:e,hint:a,children:r}){return(0,K.jsxs)("div",{className:"flex items-center gap-3 px-[13px] py-2.5",children:[(0,K.jsx)(Xh,{htmlFor:e,className:"w-[118px] shrink-0 text-[10.5px] font-bold tracking-[0.06em] text-zinc-400 uppercase",children:t}),(0,K.jsx)("div",{className:"min-w-0 flex-1",children:r}),a!==void 0&&(0,K.jsx)("span",{className:"max-w-[45%] shrink text-right text-[11.5px] text-zinc-400",children:a})]})}function oW({field:t,entries:e,onChange:a}){let r=e.length===0?[""]:e;return(0,K.jsxs)("div",{className:"flex flex-col gap-1.5",children:[r.map((n,i)=>(0,K.jsxs)("div",{className:"flex items-center gap-1.5",children:[(0,K.jsx)(tu,{id:i===0?`header-${t}`:void 0,"aria-label":`${t} ${i+1}`,spellCheck:!1,value:n,onChange:o=>a(r.map((s,l)=>l===i?o.currentTarget.value:s))}),r.length>1&&(0,K.jsx)(Ae,{variant:"outline",size:"icon",className:"size-[26px] shrink-0 rounded-[7px] text-zinc-400 [&_svg:not([class*='size-'])]:size-[11px]","aria-label":`Remove this ${t} entry`,onClick:()=>a(r.filter((o,s)=>s!==i)),children:(0,K.jsx)(ul,{})})]},i)),(0,K.jsxs)(Ae,{variant:"outline",size:"sm",className:"h-auto self-start rounded-[7px] border-dashed border-zinc-300 px-2.5 py-[5px] text-[11px] font-normal text-zinc-500",onClick:()=>a([...r,""]),children:["Add ",t]})]})}function gz({faults:t}){return(0,K.jsxs)(jr,{variant:"destructive",className:"rounded-xl border-[#f6d9d9] bg-[#fef6f6]",children:[(0,K.jsx)(Fr,{className:"text-[12.5px] font-bold text-foreground",children:"Refused, and nothing was written"}),(0,K.jsx)(Hr,{children:t.map(({data:{message:e,fix:a}})=>(0,K.jsxs)("p",{className:"whitespace-pre-line",children:[e," ",(0,K.jsx)("span",{className:"text-muted-foreground",children:a})]},e))})]})}var f0=L(F(),1);var pt=L(H(),1);function Oz({onDone:t,onClose:e}){let[a,r]=(0,f0.useState)(""),[n,i]=(0,f0.useState)(""),[o,s]=(0,f0.useState)(null),l=yc(),u=EA(),c=async()=>{let f=n.trim(),d=await u.mutateAsync({source:a.trim(),...f===""?{}:{version:f}});if(d!==null)return s(d);t("Vendor source added",`${a.trim()}${f===""?"":` @ ${f}`} \xB7 run Build to compile what it adds`)};return(0,pt.jsxs)("div",{className:"space-y-3.5",children:[(0,pt.jsx)("p",{className:"text-[13px] leading-[1.65] text-zinc-700",children:"A vendor source is a repository governed by cw: only its charter, under .cw/charter/, is installed."}),(0,pt.jsxs)("div",{className:"divide-y divide-zinc-100 overflow-hidden rounded-[11px] border border-[#f0f0f0]",children:[(0,pt.jsxs)("div",{className:"flex items-center gap-3 px-[13px] py-2.5",children:[(0,pt.jsx)(Xh,{htmlFor:"vendor-source",className:"w-[118px] shrink-0 text-[10.5px] font-bold tracking-[0.06em] text-zinc-400 uppercase",children:"source"}),(0,pt.jsx)(tu,{id:"vendor-source",value:a,spellCheck:!1,onChange:f=>r(f.target.value)})]}),(0,pt.jsxs)("div",{className:"flex items-center gap-3 px-[13px] py-2.5",children:[(0,pt.jsx)(Xh,{htmlFor:"vendor-version",className:"w-[118px] shrink-0 text-[10.5px] font-bold tracking-[0.06em] text-zinc-400 uppercase",children:"version"}),(0,pt.jsx)(tu,{id:"vendor-version",value:n,spellCheck:!1,onChange:f=>i(f.target.value)}),(0,pt.jsx)("span",{className:"max-w-[45%] shrink text-right text-[11.5px] text-zinc-400",children:"a tag, branch or commit; left empty, the source's default"})]})]}),(0,pt.jsxs)("div",{className:"rounded-[11px] border bg-zinc-50 px-3.5 py-3","aria-label":"Reserved directories",children:[(0,pt.jsx)("div",{className:"mb-1 text-[11px] font-bold tracking-[0.07em] text-zinc-400 uppercase",children:"Directories under its .cw/charter/"}),Object.entries(l.data?.data??{}).map(([f,d])=>(0,pt.jsxs)("div",{className:"flex items-baseline gap-[9px] border-t border-zinc-100 py-[7px]",children:[(0,pt.jsxs)("span",{className:"min-w-[150px] font-mono text-[11.5px]",children:[f,"/"]}),(0,pt.jsx)("span",{className:"text-[11.5px] text-zinc-500",children:d})]},f))]}),o!==null&&(0,pt.jsxs)(jr,{variant:"destructive",className:"rounded-xl border-[#f6d9d9] bg-[#fef6f6]",children:[(0,pt.jsx)(Fr,{className:"text-[12.5px] font-bold text-foreground",children:"Refused, and nothing was installed"}),(0,pt.jsx)(Hr,{children:(0,pt.jsxs)("p",{className:"whitespace-pre-line",children:[o.data.message," ",(0,pt.jsx)("span",{className:"text-muted-foreground",children:o.data.fix})]})})]}),(0,pt.jsxs)("div",{className:ci,children:[(0,pt.jsx)(Ae,{disabled:u.isPending||a.trim()==="",onClick:()=>{c()},children:"Add source"}),(0,pt.jsx)(Ae,{variant:"outline",onClick:e,children:"Cancel"})]})]})}var QC=L(F(),1);var At=L(H(),1);function xz({name:t,onDone:e,onClose:a}){let n=Hm().data?.data.testSuites.find(({data:i})=>i.name===t);return n===void 0?null:(0,At.jsx)(sW,{name:t,initialText:n.data.text??"",onDone:e,onClose:a},t)}function sW({name:t,initialText:e,onDone:a,onClose:r}){let[n,i]=(0,QC.useState)(e),[o,s]=(0,QC.useState)(null),l=_A(),u=zA(),c=async()=>{let d=await l.mutateAsync({name:t,text:n});if(typeof d!="string")return s(d);a("Saved",`.cw/test/${t} rewritten \xB7 run the cases again`)},f=async()=>{let d=await u.mutateAsync(t);if(d!==null)return s(d);a("Test file deleted",`.cw/test/${t} removed`)};return(0,At.jsxs)("div",{className:"space-y-3",children:[(0,At.jsxs)("p",{className:"text-xs leading-[1.65] text-zinc-600 [&_code]:font-mono",children:["A case is one situation \u2014 a touched file (",(0,At.jsx)("code",{children:"do.touchFile"}),") or a raised event (",(0,At.jsx)("code",{children:"when"}),") \u2014 and expects one thing:"," ",(0,At.jsx)("code",{children:"activate"}),", ",(0,At.jsx)("code",{children:"run"})," or ",(0,At.jsx)("code",{children:"allow"}),"."]}),(0,At.jsx)("textarea",{"aria-label":"Test file text",className:"h-[340px] w-full resize-y rounded-[11px] border bg-zinc-50 px-3.5 py-3 font-mono text-[11.5px] leading-[1.65] outline-none",spellCheck:!1,value:n,onChange:d=>i(d.target.value)}),o!==null&&(0,At.jsxs)(jr,{variant:"destructive",className:"rounded-xl border-[#f6d9d9] bg-[#fef6f6]",children:[(0,At.jsx)(Fr,{className:"text-[12.5px] font-bold text-foreground",children:"Refused, and nothing was written"}),(0,At.jsx)(Hr,{children:(0,At.jsxs)("p",{className:"break-words whitespace-pre-line",children:[o.data.message," ",(0,At.jsx)("span",{className:"text-muted-foreground",children:o.data.fix})]})})]}),(0,At.jsx)("p",{className:"text-[11.5px] leading-[1.6] text-zinc-400",children:"Read only when tests run \u2014 never compiled, never read by an agent."}),(0,At.jsxs)("div",{className:ci,children:[(0,At.jsx)(Ae,{disabled:l.isPending,onClick:()=>{c()},children:"Save"}),(0,At.jsx)(Ae,{variant:"outline",onClick:r,children:"Cancel"}),(0,At.jsx)(Ae,{variant:"destructive",className:"ml-auto",disabled:u.isPending,onClick:()=>{f()},children:"Delete file"})]})]})}var Nle=L(F(),1);var ur=L(H(),1);function yz({...t}){return(0,ur.jsx)(yn.Root,{"data-slot":"dialog",...t})}function lW({...t}){return(0,ur.jsx)(yn.Portal,{"data-slot":"dialog-portal",...t})}function uW({className:t,...e}){return(0,ur.jsx)(yn.Overlay,{"data-slot":"dialog-overlay",className:pe("fixed inset-0 z-50 bg-[rgba(9,9,11,0.35)] data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:animate-in data-[state=open]:fade-in-0",t),...e})}function bz({className:t,children:e,showCloseButton:a=!0,...r}){return(0,ur.jsxs)(lW,{"data-slot":"dialog-portal",children:[(0,ur.jsx)(uW,{}),(0,ur.jsxs)(yn.Content,{"data-slot":"dialog-content",className:pe("fixed top-[50%] left-[50%] z-50 grid w-full max-w-[calc(100%-2rem)] translate-x-[-50%] translate-y-[-50%] gap-4 rounded-lg border bg-background p-6 shadow-lg duration-200 outline-none data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=closed]:zoom-out-95 data-[state=open]:animate-in data-[state=open]:fade-in-0 data-[state=open]:zoom-in-95 sm:max-w-lg",t),...r,children:[e,a&&(0,ur.jsxs)(yn.Close,{"data-slot":"dialog-close",className:"absolute top-4 right-[18px] cursor-pointer rounded-xs p-0.5 text-zinc-400 ring-offset-background transition-colors hover:text-foreground focus:outline-hidden focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 disabled:pointer-events-none [&_svg]:pointer-events-none [&_svg]:shrink-0 [&_svg:not([class*='size-'])]:size-4",children:[(0,ur.jsx)(ul,{}),(0,ur.jsx)("span",{className:"sr-only",children:"Close"})]})]})]})}function vz({className:t,...e}){return(0,ur.jsx)("div",{"data-slot":"dialog-header",className:pe("flex flex-col gap-2 text-center sm:text-left",t),...e})}function Sz({className:t,...e}){return(0,ur.jsx)(yn.Title,{"data-slot":"dialog-title",className:pe("text-lg leading-none font-semibold",t),...e})}function wz({className:t,...e}){return(0,ur.jsx)(yn.Description,{"data-slot":"dialog-description",className:pe("text-sm text-muted-foreground",t),...e})}var pa=L(H(),1),cW={explanation:{title:()=>"Explain",context:({id:t})=>t,holdsDraft:!1,render:({id:t},{open:e})=>(0,pa.jsx)(IE,{id:t,onExplain:a=>e("explanation",{id:a})},t)},primitive:{title:({id:t})=>t,context:()=>"",holdsDraft:!0,render:({id:t},{close:e})=>(0,pa.jsx)(AC,{id:t,onDone:d0(e),onClose:e},t)},newPrimitive:{title:()=>"New primitive",context:()=>"",holdsDraft:!0,render:({kind:t},{close:e})=>(0,pa.jsx)(AC,{newKind:t,onDone:d0(e),onClose:e},`new ${t}`)},buildPreview:{title:()=>"cw build",context:()=>"nothing written yet",holdsDraft:!1,render:(t,{open:e})=>(0,pa.jsx)(kE,{onBuilt:a=>e("buildOutcome",{buildAnswer:a})})},buildOutcome:{title:()=>"cw build",context:()=>"",holdsDraft:!1,render:({buildAnswer:t})=>(0,pa.jsx)(LE,{buildAnswer:t})},addVendor:{title:()=>"Add vendor source",context:()=>"",holdsDraft:!0,render:(t,{close:e})=>(0,pa.jsx)(Oz,{onDone:d0(e),onClose:e})},testSuite:{title:({name:t})=>`.cw/test/${t}`,context:()=>"",holdsDraft:!0,render:({name:t},{close:e})=>(0,pa.jsx)(xz,{name:t,onDone:d0(e),onClose:e},t)},doctor:{title:()=>"Doctor",context:()=>"cw 0.6.2",holdsDraft:!1,render:(t,{open:e})=>(0,pa.jsx)(RE,{onBuilt:a=>e("buildOutcome",{buildAnswer:a})})}};function d0(t){return(e,a)=>{t(),cl(e,{description:a})}}var Cz=(0,au.createContext)(null);function ho(){return(0,au.useContext)(Cz)}function kz({children:t}){let[e,a]=(0,au.useState)(null),[r,n]=(0,au.useState)(!1),i={open:(s,l)=>{a({name:s,params:l}),n(!0)},close:()=>n(!1)},o=e===null?null:cW[e.name];return(0,pa.jsxs)(Cz.Provider,{value:i,children:[t,(0,pa.jsx)(yz,{open:r,onOpenChange:n,children:e!==null&&o!==null&&(0,pa.jsxs)(bz,{className:"flex max-h-[88vh] w-[920px] max-w-[calc(100%-48px)] flex-col gap-0 overflow-hidden rounded-[15px] border-0 p-0 shadow-[0_34px_80px_-22px_rgba(0,0,0,0.4)] sm:max-w-[calc(100%-48px)]",onInteractOutside:s=>o.holdsDraft&&s.preventDefault(),onEscapeKeyDown:s=>o.holdsDraft&&s.preventDefault(),children:[(0,pa.jsxs)(vz,{className:"flex-row items-baseline gap-2.5 border-b border-[#f0f0f0] py-[15px] pr-12 pl-[18px]",children:[(0,pa.jsx)(Sz,{className:"text-[14.5px] font-bold tracking-[-0.01em]",children:o.title(e.params)}),(0,pa.jsx)(wz,{className:"font-mono text-[11px] text-zinc-400",children:o.context(e.params)})]}),(0,pa.jsx)("div",{className:"min-h-0 flex-1 overflow-y-auto px-5 py-[18px]",children:o.render(e.params,i)})]})})]})}var p0=L(F(),1);var tue=L(F(),1);var fW=L(H(),1),Lz=li("inline-flex items-center justify-center gap-2 rounded-md text-sm font-medium whitespace-nowrap transition-[color,box-shadow] outline-none hover:bg-muted hover:text-muted-foreground focus-visible:border-ring focus-visible:ring-[3px] focus-visible:ring-ring/50 disabled:pointer-events-none disabled:opacity-50 aria-invalid:border-destructive aria-invalid:ring-destructive/20 data-[state=on]:bg-accent data-[state=on]:text-accent-foreground dark:aria-invalid:ring-destructive/40 [&_svg]:pointer-events-none [&_svg]:shrink-0 [&_svg:not([class*='size-'])]:size-4",{variants:{variant:{default:"bg-transparent",outline:"border border-input bg-transparent shadow-xs hover:bg-accent hover:text-accent-foreground"},size:{default:"h-9 min-w-9 px-2",sm:"h-8 min-w-8 px-1.5",lg:"h-10 min-w-10 px-2.5"}},defaultVariants:{variant:"default",size:"default"}});var h0=L(H(),1),Tz=p0.createContext({size:"default",variant:"default",spacing:0});function Pz({className:t,variant:e,size:a,spacing:r=0,children:n,...i}){return(0,h0.jsx)(qd.Root,{"data-slot":"toggle-group","data-variant":e,"data-size":a,"data-spacing":r,style:{"--gap":r},className:pe("group/toggle-group flex w-fit items-center gap-[--spacing(var(--gap))] rounded-md data-[spacing=default]:data-[variant=outline]:shadow-xs",t),...i,children:(0,h0.jsx)(Tz.Provider,{value:{variant:e,size:a,spacing:r},children:n})})}function Rz({className:t,children:e,variant:a,size:r,...n}){let i=p0.useContext(Tz);return(0,h0.jsx)(qd.Item,{"data-slot":"toggle-group-item","data-variant":i.variant||a,"data-size":i.size||r,"data-spacing":i.spacing,className:pe(Lz({variant:i.variant||a,size:i.size||r}),"w-auto min-w-0 shrink-0 px-3 focus:z-10 focus-visible:z-10","data-[spacing=0]:rounded-none data-[spacing=0]:shadow-none data-[spacing=0]:first:rounded-l-md data-[spacing=0]:last:rounded-r-md data-[spacing=0]:data-[variant=outline]:border-l-0 data-[spacing=0]:data-[variant=outline]:first:border-l",t),...n,children:e})}var se=L(H(),1);function DC({layerNames:t,kind:e,onKindChange:a}){let{open:r}=ho(),n=yc(),i=oi();if(n.data===void 0||i.data===void 0)return null;let o=n.data.data,s=i.data;if(s.type==="FaultsByFile")return(0,se.jsx)(dW,{faultsByFile:s});if(s.type==="Fault")return(0,se.jsx)(hW,{fault:s});let l=s.data.primitives.filter(({data:d})=>t.includes(d.layerName)),u=new Map(Object.keys(o).map(d=>[d,l.filter(({data:h})=>h.kind===d).length])),c=e??[...u].find(([,d])=>d>0)?.[0]??Object.keys(o)[0],f=l.filter(({data:d})=>d.kind===c);return(0,se.jsxs)("div",{className:"min-w-0",children:[(0,se.jsxs)("div",{className:"mb-3 flex items-baseline gap-[9px]",children:[(0,se.jsx)("h2",{className:"text-[12.5px] font-bold",children:"Charter primitives"}),(0,se.jsxs)("span",{className:"text-[11.5px] text-zinc-400",children:[l.length," in this charter"]}),t.includes("repo")&&(0,se.jsxs)(Ae,{size:"sm",variant:"outline",className:"ml-auto",onClick:()=>r("newPrimitive",{kind:c}),children:["New ",c]})]}),(0,se.jsx)(Pz,{type:"single",spacing:1.5,"aria-label":"Kinds",className:"mb-3 flex-wrap",value:c,onValueChange:d=>d!==""&&a(d),children:[...u].map(([d,h])=>(0,se.jsxs)(Rz,{value:d,"aria-label":d,className:`group/chip h-auto cursor-pointer gap-1.5 rounded-[9px] border bg-background px-2.5 py-1.5 text-[11.5px] font-medium text-zinc-700 capitalize hover:bg-background hover:text-zinc-700 data-[state=on]:border-foreground data-[state=on]:bg-foreground data-[state=on]:font-semibold data-[state=on]:text-white ${h===0&&d!==c?"opacity-50":""}`,children:[d,(0,se.jsx)(mi,{className:"rounded-none bg-transparent p-0 font-mono text-[10px] font-normal text-zinc-400 group-data-[state=on]/chip:text-white/70",children:h})]},d))}),(0,se.jsxs)("p",{className:"mb-2.5 flex items-baseline gap-2 px-0.5",children:[(0,se.jsx)("span",{className:"shrink-0 text-[10.5px] font-bold tracking-[0.06em] text-zinc-400 uppercase",children:"Activates when"}),(0,se.jsx)("span",{className:"text-xs leading-normal text-zinc-700","aria-label":"Activates when",children:o[c]})]}),f.length===0?(0,se.jsxs)("p",{className:"rounded-[14px] border p-[22px] text-center text-[12.5px] text-zinc-400",children:["No ",c," in this charter yet."]}):(0,se.jsx)(pW,{kind:c,listed:f})]})}function dW({faultsByFile:t}){let e=Object.entries(t.data.files);return(0,se.jsxs)("div",{className:"space-y-3.5",children:[(0,se.jsxs)(jr,{variant:"destructive",className:"rounded-xl border-[#f6d9d9] bg-[#fef6f6]",children:[(0,se.jsx)(Fr,{className:"text-[12.5px] font-bold text-foreground",children:"The engine will not read this charter"}),(0,se.jsxs)(Hr,{children:[e.length," file",e.length===1?" is":"s are"," refused, so there is no listing to show. Fix",e.length===1?" it":" them"," and the charter comes back."]})]}),(0,se.jsx)(fs,{faultsByFile:t,label:"Refused files"})]})}function hW({fault:t}){return(0,se.jsxs)(jr,{variant:"destructive",className:"rounded-xl border-[#f6d9d9] bg-[#fef6f6]",children:[(0,se.jsx)(Fr,{className:"text-[12.5px] font-bold text-foreground",children:t.data.message}),(0,se.jsx)(Hr,{children:t.data.fix})]})}function MC(t){return t===void 0?void 0:typeof t=="string"?[t]:t}function pW({kind:t,listed:e}){let{open:a}=ho(),r=t==="guide",n=t!=="mixin";return(0,se.jsx)("div",{className:"overflow-hidden rounded-[14px] border bg-background",children:(0,se.jsxs)(Tl,{"aria-label":`${t} primitives`,className:"table-fixed",children:[(0,se.jsx)(wE,{children:(0,se.jsxs)(Rl,{className:"border-[#ececef] bg-zinc-50 hover:bg-zinc-50 [&>th]:h-auto [&>th]:px-[15px] [&>th]:py-[9px] [&>th]:text-[9.5px] [&>th]:font-bold [&>th]:tracking-[0.07em] [&>th]:text-zinc-400 [&>th]:uppercase",children:[(0,se.jsx)(Il,{className:"w-[170px]",children:"Id"}),(0,se.jsx)(Il,{children:"Description"}),r&&(0,se.jsxs)(se.Fragment,{children:[(0,se.jsx)(Il,{className:"w-[170px] text-right",children:"Matching globs"}),(0,se.jsx)(Il,{className:"w-[120px] text-right",children:"Rationale"})]}),n&&(0,se.jsx)(Il,{className:"w-[120px] text-right",children:"Mixins"}),(0,se.jsx)(Il,{className:"w-[50px]"})]})}),(0,se.jsx)(Pl,{children:e.map(({data:{id:i,description:o,file:s,headers:l}})=>{let u=MC(l.globs);return(0,se.jsxs)(Rl,{className:"group/row border-[#f7f7f8] align-top hover:bg-zinc-50 [&>td]:px-[15px] [&>td]:py-3",children:[(0,se.jsx)(kn,{className:"truncate",children:(0,se.jsx)(Ae,{variant:"link",className:"block h-auto max-w-full truncate rounded-none p-0 text-left font-mono text-[11.5px] font-bold text-foreground",title:`Open ${s}`,onClick:()=>a("primitive",{id:i}),children:String(l.id)})}),(0,se.jsxs)(kn,{className:"whitespace-normal",children:[(0,se.jsx)("div",{className:"text-[12.5px] font-semibold",children:o}),(0,se.jsx)("div",{className:"mt-[3px] truncate font-mono text-[10.5px] text-zinc-400",children:s})]}),r&&(0,se.jsxs)(se.Fragment,{children:[(0,se.jsx)(EC,{named:u,none:"all patterns",said:u===void 0,label:"Matching globs"}),(0,se.jsx)(EC,{named:MC(l.rationale),none:"none",said:!1,label:"Rationale"})]}),n&&(0,se.jsx)(EC,{named:MC(l.mixins),none:"none",said:!1,label:"Mixins"}),(0,se.jsx)(kn,{children:(0,se.jsx)(Ae,{variant:"ghost",size:"icon",className:"ml-auto size-6 rounded-[7px] border border-transparent text-zinc-300 group-hover/row:border-zinc-200 group-hover/row:bg-background group-hover/row:text-zinc-400 hover:!border-foreground hover:bg-background hover:!text-foreground [&_svg:not([class*='size-'])]:size-[13px]","aria-label":`Explain ${i}`,onClick:()=>a("explanation",{id:i}),children:(0,se.jsx)(pn,{})})})]},i)})})]})})}function EC({named:t,none:e,said:a,label:r}){return(0,se.jsx)(kn,{"aria-label":r,children:(0,se.jsx)("div",{className:"flex min-w-0 flex-wrap content-start justify-end gap-1",children:t===void 0||t.length===0?(0,se.jsx)("span",{className:`text-[10.5px] ${a?"text-destructive":"text-zinc-300"}`,children:e}):t.map(n=>(0,se.jsx)(mi,{title:n,className:"block max-w-full truncate rounded-[5px] bg-zinc-100 px-1.5 py-0.5 font-mono text-[10px] font-normal text-zinc-700",children:n},n))})})}var qC=L(F(),1);var Lue=L(F(),1);var Iz=1,mW=.9,gW=.8,OW=.17,$C=.1,BC=.999,xW=.9999,yW=.99,bW=/[\\\/_+.#"@\[\(\{&]/,vW=/[\\\/_+.#"@\[\(\{&]/g,SW=/[\s-]/,Qz=/[\s-]/g;function _C(t,e,a,r,n,i,o){if(i===e.length)return n===t.length?Iz:yW;var s=`${n},${i}`;if(o[s]!==void 0)return o[s];for(var l=r.charAt(i),u=a.indexOf(l,n),c=0,f,d,h,p;u>=0;)f=_C(t,e,a,r,u+1,i+1,o),f>c&&(u===n?f*=Iz:bW.test(t.charAt(u-1))?(f*=gW,h=t.slice(n,u-1).match(vW),h&&n>0&&(f*=Math.pow(BC,h.length))):SW.test(t.charAt(u-1))?(f*=mW,p=t.slice(n,u-1).match(Qz),p&&n>0&&(f*=Math.pow(BC,p.length))):(f*=OW,n>0&&(f*=Math.pow(BC,u-n))),t.charAt(u)!==e.charAt(i)&&(f*=xW)),(f<$C&&a.charAt(u-1)===r.charAt(i+1)||r.charAt(i+1)===r.charAt(i)&&a.charAt(u-1)!==r.charAt(i))&&(d=_C(t,e,a,r,u+1,i+2,o),d*$C>f&&(f=d*$C)),f>c&&(c=f),u=a.indexOf(l,u+1);return o[s]=c,c}function Az(t){return t.toLowerCase().replace(Qz," ")}function Mz(t,e,a){return t=a&&a.length>0?`${t+" "+a.join(" ")}`:t,_C(t,e,Az(t),Az(e),0,0,{})}var J=L(F(),1);var qh='[cmdk-group=""]',zC='[cmdk-group-items=""]',wW='[cmdk-group-heading=""]',Dz='[cmdk-item=""]',Ez=`${Dz}:not([aria-disabled="true"])`,NC="cmdk-item-select",hf="data-value",CW=(t,e,a)=>Mz(t,e,a),$z=J.createContext(void 0),Zh=()=>J.useContext($z),Bz=J.createContext(void 0),XC=()=>J.useContext(Bz),_z=J.createContext(void 0),zz=J.forwardRef((t,e)=>{let a=pf(()=>{var P,G;return{search:"",value:(G=(P=t.value)!=null?P:t.defaultValue)!=null?G:"",selectedItemId:void 0,filtered:{count:0,items:new Map,groups:new Set}}}),r=pf(()=>new Set),n=pf(()=>new Map),i=pf(()=>new Map),o=pf(()=>new Set),s=Nz(t),{label:l,children:u,value:c,onValueChange:f,filter:d,shouldFilter:h,loop:p,disablePointerSelection:m=!1,vimBindings:x=!0,...g}=t,O=Dt(),y=Dt(),b=Dt(),v=J.useRef(null),S=DW();ru(()=>{if(c!==void 0){let P=c.trim();a.current.value=P,w.emit()}},[c]),ru(()=>{S(6,R)},[]);let w=J.useMemo(()=>({subscribe:P=>(o.current.add(P),()=>o.current.delete(P)),snapshot:()=>a.current,setState:(P,G,N)=>{var M,j,de,ee;if(!Object.is(a.current[P],G)){if(a.current[P]=G,P==="search")A(),Q(),S(1,$);else if(P==="value"){if(document.activeElement.hasAttribute("cmdk-input")||document.activeElement.hasAttribute("cmdk-root")){let Z=document.getElementById(b);Z?Z.focus():(M=document.getElementById(O))==null||M.focus()}if(S(7,()=>{var Z;a.current.selectedItemId=(Z=D())==null?void 0:Z.id,w.emit()}),N||S(5,R),((j=s.current)==null?void 0:j.value)!==void 0){let Z=G??"";(ee=(de=s.current).onValueChange)==null||ee.call(de,Z);return}}w.emit()}},emit:()=>{o.current.forEach(P=>P())}}),[]),k=J.useMemo(()=>({value:(P,G,N)=>{var M;G!==((M=i.current.get(P))==null?void 0:M.value)&&(i.current.set(P,{value:G,keywords:N}),a.current.filtered.items.set(P,T(G,N)),S(2,()=>{Q(),w.emit()}))},item:(P,G)=>(r.current.add(P),G&&(n.current.has(G)?n.current.get(G).add(P):n.current.set(G,new Set([P]))),S(3,()=>{A(),Q(),a.current.value||$(),w.emit()}),()=>{i.current.delete(P),r.current.delete(P),a.current.filtered.items.delete(P);let N=D();S(4,()=>{A(),N?.getAttribute("id")===P&&$(),w.emit()})}),group:P=>(n.current.has(P)||n.current.set(P,new Set),()=>{i.current.delete(P),n.current.delete(P)}),filter:()=>s.current.shouldFilter,label:l||t["aria-label"],getDisablePointerSelection:()=>s.current.disablePointerSelection,listId:O,inputId:b,labelId:y,listInnerRef:v}),[]);function T(P,G){var N,M;let j=(M=(N=s.current)==null?void 0:N.filter)!=null?M:CW;return P?j(P,a.current.search,G):0}function Q(){if(!a.current.search||s.current.shouldFilter===!1)return;let P=a.current.filtered.items,G=[];a.current.filtered.groups.forEach(M=>{let j=n.current.get(M),de=0;j.forEach(ee=>{let Z=P.get(ee);de=Math.max(Z,de)}),G.push([M,de])});let N=v.current;Y().sort((M,j)=>{var de,ee;let Z=M.getAttribute("id"),Ze=j.getAttribute("id");return((de=P.get(Ze))!=null?de:0)-((ee=P.get(Z))!=null?ee:0)}).forEach(M=>{let j=M.closest(zC);j?j.appendChild(M.parentElement===j?M:M.closest(`${zC} > *`)):N.appendChild(M.parentElement===N?M:M.closest(`${zC} > *`))}),G.sort((M,j)=>j[1]-M[1]).forEach(M=>{var j;let de=(j=v.current)==null?void 0:j.querySelector(`${qh}[${hf}="${encodeURIComponent(M[0])}"]`);de?.parentElement.appendChild(de)})}function $(){let P=Y().find(N=>N.getAttribute("aria-disabled")!=="true"),G=P?.getAttribute(hf);w.setState("value",G||void 0)}function A(){var P,G,N,M;if(!a.current.search||s.current.shouldFilter===!1){a.current.filtered.count=r.current.size;return}a.current.filtered.groups=new Set;let j=0;for(let de of r.current){let ee=(G=(P=i.current.get(de))==null?void 0:P.value)!=null?G:"",Z=(M=(N=i.current.get(de))==null?void 0:N.keywords)!=null?M:[],Ze=T(ee,Z);a.current.filtered.items.set(de,Ze),Ze>0&&j++}for(let[de,ee]of n.current)for(let Z of ee)if(a.current.filtered.items.get(Z)>0){a.current.filtered.groups.add(de);break}a.current.filtered.count=j}function R(){var P,G,N;let M=D();M&&(((P=M.parentElement)==null?void 0:P.firstChild)===M&&((N=(G=M.closest(qh))==null?void 0:G.querySelector(wW))==null||N.scrollIntoView({block:"nearest"})),M.scrollIntoView({block:"nearest"}))}function D(){var P;return(P=v.current)==null?void 0:P.querySelector(`${Dz}[aria-selected="true"]`)}function Y(){var P;return Array.from(((P=v.current)==null?void 0:P.querySelectorAll(Ez))||[])}function B(P){let G=Y()[P];G&&w.setState("value",G.getAttribute(hf))}function q(P){var G;let N=D(),M=Y(),j=M.findIndex(ee=>ee===N),de=M[j+P];(G=s.current)!=null&&G.loop&&(de=j+P<0?M[M.length-1]:j+P===M.length?M[0]:M[j+P]),de&&w.setState("value",de.getAttribute(hf))}function re(P){let G=D(),N=G?.closest(qh),M;for(;N&&!M;)N=P>0?MW(N,qh):EW(N,qh),M=N?.querySelector(Ez);M?w.setState("value",M.getAttribute(hf)):q(P)}let ie=()=>B(Y().length-1),z=P=>{P.preventDefault(),P.metaKey?ie():P.altKey?re(1):q(1)},Pe=P=>{P.preventDefault(),P.metaKey?B(0):P.altKey?re(-1):q(-1)};return J.createElement(ue.div,{ref:e,tabIndex:-1,...g,"cmdk-root":"",onKeyDown:P=>{var G;(G=g.onKeyDown)==null||G.call(g,P);let N=P.nativeEvent.isComposing||P.keyCode===229;if(!(P.defaultPrevented||N))switch(P.key){case"n":case"j":{x&&P.ctrlKey&&z(P);break}case"ArrowDown":{z(P);break}case"p":case"k":{x&&P.ctrlKey&&Pe(P);break}case"ArrowUp":{Pe(P);break}case"Home":{P.preventDefault(),B(0);break}case"End":{P.preventDefault(),ie();break}case"Enter":{P.preventDefault();let M=D();if(M){let j=new Event(NC);M.dispatchEvent(j)}}}}},J.createElement("label",{"cmdk-label":"",htmlFor:k.inputId,id:k.labelId,style:BW},l),m0(t,P=>J.createElement(Bz.Provider,{value:w},J.createElement($z.Provider,{value:k},P))))}),kW=J.forwardRef((t,e)=>{var a,r;let n=Dt(),i=J.useRef(null),o=J.useContext(_z),s=Zh(),l=Nz(t),u=(r=(a=l.current)==null?void 0:a.forceMount)!=null?r:o?.forceMount;ru(()=>{if(!u)return s.item(n,o?.id)},[u]);let c=Xz(n,i,[t.value,t.children,i],t.keywords),f=XC(),d=Ds(S=>S.value&&S.value===c.current),h=Ds(S=>u||s.filter()===!1?!0:S.search?S.filtered.items.get(n)>0:!0);J.useEffect(()=>{let S=i.current;if(!(!S||t.disabled))return S.addEventListener(NC,p),()=>S.removeEventListener(NC,p)},[h,t.onSelect,t.disabled]);function p(){var S,w;m(),(w=(S=l.current).onSelect)==null||w.call(S,c.current)}function m(){f.setState("value",c.current,!0)}if(!h)return null;let{disabled:x,value:g,onSelect:O,forceMount:y,keywords:b,...v}=t;return J.createElement(ue.div,{ref:ts(i,e),...v,id:n,"cmdk-item":"",role:"option","aria-disabled":!!x,"aria-selected":!!d,"data-disabled":!!x,"data-selected":!!d,onPointerMove:x||s.getDisablePointerSelection()?void 0:m,onClick:x?void 0:p},t.children)}),LW=J.forwardRef((t,e)=>{let{heading:a,children:r,forceMount:n,...i}=t,o=Dt(),s=J.useRef(null),l=J.useRef(null),u=Dt(),c=Zh(),f=Ds(h=>n||c.filter()===!1?!0:h.search?h.filtered.groups.has(o):!0);ru(()=>c.group(o),[]),Xz(o,s,[t.value,t.heading,l]);let d=J.useMemo(()=>({id:o,forceMount:n}),[n]);return J.createElement(ue.div,{ref:ts(s,e),...i,"cmdk-group":"",role:"presentation",hidden:f?void 0:!0},a&&J.createElement("div",{ref:l,"cmdk-group-heading":"","aria-hidden":!0,id:u},a),m0(t,h=>J.createElement("div",{"cmdk-group-items":"",role:"group","aria-labelledby":a?u:void 0},J.createElement(_z.Provider,{value:d},h))))}),TW=J.forwardRef((t,e)=>{let{alwaysRender:a,...r}=t,n=J.useRef(null),i=Ds(o=>!o.search);return!a&&!i?null:J.createElement(ue.div,{ref:ts(n,e),...r,"cmdk-separator":"",role:"separator"})}),PW=J.forwardRef((t,e)=>{let{onValueChange:a,...r}=t,n=t.value!=null,i=XC(),o=Ds(u=>u.search),s=Ds(u=>u.selectedItemId),l=Zh();return J.useEffect(()=>{t.value!=null&&i.setState("search",t.value)},[t.value]),J.createElement(ue.input,{ref:e,...r,"cmdk-input":"",autoComplete:"off",autoCorrect:"off",spellCheck:!1,"aria-autocomplete":"list",role:"combobox","aria-expanded":!0,"aria-controls":l.listId,"aria-labelledby":l.labelId,"aria-activedescendant":s,id:l.inputId,type:"text",value:n?t.value:o,onChange:u=>{n||i.setState("search",u.target.value),a?.(u.target.value)}})}),RW=J.forwardRef((t,e)=>{let{children:a,label:r="Suggestions",...n}=t,i=J.useRef(null),o=J.useRef(null),s=Ds(u=>u.selectedItemId),l=Zh();return J.useEffect(()=>{if(o.current&&i.current){let u=o.current,c=i.current,f,d=new ResizeObserver(()=>{f=requestAnimationFrame(()=>{let h=u.offsetHeight;c.style.setProperty("--cmdk-list-height",h.toFixed(1)+"px")})});return d.observe(u),()=>{cancelAnimationFrame(f),d.unobserve(u)}}},[]),J.createElement(ue.div,{ref:ts(i,e),...n,"cmdk-list":"",role:"listbox",tabIndex:-1,"aria-activedescendant":s,"aria-label":r,id:l.listId},m0(t,u=>J.createElement("div",{ref:ts(o,l.listInnerRef),"cmdk-list-sizer":""},u)))}),IW=J.forwardRef((t,e)=>{let{open:a,onOpenChange:r,overlayClassName:n,contentClassName:i,container:o,...s}=t;return J.createElement(Av,{open:a,onOpenChange:r},J.createElement(Qv,{container:o},J.createElement(Mv,{"cmdk-overlay":"",className:n}),J.createElement(Ev,{"aria-label":t.label,"cmdk-dialog":"",className:i},J.createElement(zz,{ref:e,...s}))))}),AW=J.forwardRef((t,e)=>Ds(a=>a.filtered.count===0)?J.createElement(ue.div,{ref:e,...t,"cmdk-empty":"",role:"presentation"}):null),QW=J.forwardRef((t,e)=>{let{progress:a,children:r,label:n="Loading...",...i}=t;return J.createElement(ue.div,{ref:e,...i,"cmdk-loading":"",role:"progressbar","aria-valuenow":a,"aria-valuemin":0,"aria-valuemax":100,"aria-label":n},m0(t,o=>J.createElement("div",{"aria-hidden":!0},o)))}),nu=Object.assign(zz,{List:RW,Item:kW,Input:PW,Group:LW,Separator:TW,Dialog:IW,Empty:AW,Loading:QW});function MW(t,e){let a=t.nextElementSibling;for(;a;){if(a.matches(e))return a;a=a.nextElementSibling}}function EW(t,e){let a=t.previousElementSibling;for(;a;){if(a.matches(e))return a;a=a.previousElementSibling}}function Nz(t){let e=J.useRef(t);return ru(()=>{e.current=t}),e}var ru=typeof window>"u"?J.useEffect:J.useLayoutEffect;function pf(t){let e=J.useRef();return e.current===void 0&&(e.current=t()),e}function Ds(t){let e=XC(),a=()=>t(e.snapshot());return J.useSyncExternalStore(e.subscribe,a,a)}function Xz(t,e,a,r=[]){let n=J.useRef(),i=Zh();return ru(()=>{var o;let s=(()=>{var u;for(let c of a){if(typeof c=="string")return c.trim();if(typeof c=="object"&&"current"in c)return c.current?(u=c.current.textContent)==null?void 0:u.trim():n.current}})(),l=r.map(u=>u.trim());i.value(t,s,l),(o=e.current)==null||o.setAttribute(hf,s),n.current=s}),n}var DW=()=>{let[t,e]=J.useState(),a=pf(()=>new Map);return ru(()=>{a.current.forEach(r=>r()),a.current=new Map},[t]),(r,n)=>{a.current.set(r,n),e({})}};function $W(t){let e=t.type;return typeof e=="function"?e(t.props):"render"in e?e.render(t.props):t}function m0({asChild:t,children:e},a){return t&&J.isValidElement(e)?J.cloneElement($W(e),{ref:e.ref},a(e.props.children)):a(e)}var BW={position:"absolute",width:"1px",height:"1px",padding:"0",margin:"-1px",overflow:"hidden",clip:"rect(0, 0, 0, 0)",whiteSpace:"nowrap",borderWidth:"0"};var Si=L(H(),1);function qz({className:t,...e}){return(0,Si.jsx)(nu,{"data-slot":"command",className:pe("flex h-full w-full flex-col overflow-hidden rounded-md bg-popover text-popover-foreground",t),...e})}function Zz({className:t,...e}){return(0,Si.jsxs)("div",{"data-slot":"command-input-wrapper",className:"flex h-9 items-center gap-2 border-b px-3",children:[(0,Si.jsx)(Ld,{className:"size-4 shrink-0 opacity-50"}),(0,Si.jsx)(nu.Input,{"data-slot":"command-input",className:pe("flex h-10 w-full rounded-md bg-transparent py-3 text-sm outline-hidden placeholder:text-muted-foreground disabled:cursor-not-allowed disabled:opacity-50",t),...e})]})}function Vz({className:t,...e}){return(0,Si.jsx)(nu.List,{"data-slot":"command-list",className:pe("max-h-[300px] scroll-py-1 overflow-x-hidden overflow-y-auto",t),...e})}function Uz({...t}){return(0,Si.jsx)(nu.Empty,{"data-slot":"command-empty",className:"py-6 text-center text-sm",...t})}function jz({className:t,...e}){return(0,Si.jsx)(nu.Group,{"data-slot":"command-group",className:pe("overflow-hidden p-1 text-foreground [&_[cmdk-group-heading]]:px-2 [&_[cmdk-group-heading]]:py-1.5 [&_[cmdk-group-heading]]:text-xs [&_[cmdk-group-heading]]:font-medium [&_[cmdk-group-heading]]:text-muted-foreground",t),...e})}function Fz({className:t,...e}){return(0,Si.jsx)(nu.Item,{"data-slot":"command-item",className:pe("relative flex cursor-default items-center gap-2 rounded-sm px-2 py-1.5 text-sm outline-hidden select-none data-[disabled=true]:pointer-events-none data-[disabled=true]:opacity-50 data-[selected=true]:bg-accent data-[selected=true]:text-accent-foreground [&_svg]:pointer-events-none [&_svg]:shrink-0 [&_svg:not([class*='size-'])]:size-4 [&_svg:not([class*='text-'])]:text-muted-foreground",t),...e})}var mt=L(H(),1);function Gz({onPick:t}){let[e,a]=(0,qC.useState)(""),[r,n]=(0,qC.useState)(!1),{data:i}=oi(e);return(0,mt.jsxs)(qz,{shouldFilter:!1,className:"relative w-full overflow-visible rounded-[9px] border bg-zinc-50 text-zinc-400 focus-within:border-foreground focus-within:bg-background focus-within:text-zinc-500 [&_[data-slot=command-input-wrapper]]:h-[32px] [&_[data-slot=command-input-wrapper]]:border-0 [&_[data-slot=command-input]]:h-8 [&_[data-slot=command-input]]:text-[12.5px] [&_[data-slot=command-input]]:text-foreground [&_[data-slot=command-input]]:placeholder:text-zinc-400",onFocus:()=>n(!0),onBlur:()=>n(!1),children:[(0,mt.jsx)(Zz,{placeholder:"Search everything",spellCheck:!1,value:e,onValueChange:a,onKeyDown:o=>o.key==="Escape"&&a("")}),r&&e!==""&&(0,mt.jsxs)(Vz,{className:"absolute top-full right-0 left-0 z-50 mt-[7px] max-h-[min(460px,62vh)] rounded-xl border bg-popover p-[5px] shadow-[0_20px_44px_-16px_rgba(0,0,0,0.3)] [&_[cmdk-group-heading]]:px-[11px] [&_[cmdk-group-heading]]:pt-2 [&_[cmdk-group-heading]]:pb-1.5 [&_[cmdk-group-heading]]:text-[10px] [&_[cmdk-group-heading]]:font-bold [&_[cmdk-group-heading]]:tracking-[0.07em] [&_[cmdk-group-heading]]:text-zinc-400 [&_[cmdk-group-heading]]:uppercase [&_[data-slot=command-group]]:p-0",onMouseDown:o=>o.preventDefault(),children:[i?.type==="FaultsByFile"&&(0,mt.jsx)("p",{className:"px-3 py-3.5 text-xs text-zinc-400",children:"The engine will not read this charter, so there is nothing to search."}),i?.type==="Fault"&&(0,mt.jsxs)("p",{className:"px-3 py-3.5 text-xs text-zinc-400",children:[i.data.message," ",i.data.fix]}),i?.type==="Primitives"&&(0,mt.jsxs)(mt.Fragment,{children:[(0,mt.jsx)(Uz,{className:"px-3 py-3.5 text-xs text-zinc-400",children:"Nothing in the charter says that."}),i.data.primitives.length>0&&(0,mt.jsx)(jz,{heading:`${i.data.primitives.length} primitive${i.data.primitives.length===1?"":"s"}`,children:i.data.primitives.map(o=>{let{id:s,kind:l,description:u,layerName:c,headers:f}=o.data;return(0,mt.jsxs)(Fz,{value:s,className:"grid cursor-pointer grid-cols-[74px_minmax(0,1fr)_max-content] items-baseline gap-2.5 rounded-lg px-[11px] py-2 data-[selected=true]:bg-zinc-50 data-[selected=true]:outline data-[selected=true]:outline-zinc-200",onSelect:()=>{a(""),n(!1),t(o)},children:[(0,mt.jsx)("span",{className:"font-mono text-[9.5px] font-bold tracking-[0.03em] text-zinc-500 uppercase",children:l}),(0,mt.jsxs)("span",{className:"min-w-0",children:[(0,mt.jsx)("span",{className:"block truncate font-mono text-xs text-foreground",children:(0,mt.jsx)(Hz,{text:String(f.id),word:e})}),(0,mt.jsx)("span",{className:"mt-0.5 block truncate text-[11px] leading-[1.45] text-zinc-400",children:(0,mt.jsx)(Hz,{text:u,word:e})})]}),(0,mt.jsx)(mi,{className:`rounded-[5px] px-1.5 py-0.5 font-mono text-[9.5px] font-bold tracking-[0.03em] ${_W[c]}`,children:c})]},s)})})]})]})]})}var _W={repo:"bg-[#eff6ff] text-[#1d4ed8]",vendor:"bg-[#f6f2ff] text-[#7c3aed]",builtin:"bg-zinc-100 text-zinc-700"};function Hz({text:t,word:e}){let a=t.toLowerCase().indexOf(e.toLowerCase());return a===-1||e===""?(0,mt.jsx)(mt.Fragment,{children:t}):(0,mt.jsxs)(mt.Fragment,{children:[t.slice(0,a),(0,mt.jsx)("mark",{className:"rounded-[2px] bg-[#fff2b8] text-inherit",children:t.slice(a,a+e.length)}),t.slice(a+e.length)]})}var ma=L(H(),1);function Yz(){let t=AA(),e=QA();if(t.data===void 0)return null;if(t.data.type!=="MainContexts")return(0,ma.jsx)("p",{className:"text-xs text-zinc-500",children:"Nothing was counted: the charter does not hold. Open Doctor to see why."});let{contexts:a}=t.data.data;if(a.length===0)return(0,ma.jsx)("p",{className:"text-xs text-zinc-500",children:"No agent is chosen, so no agent loads anything of the charter."});let r=e.data?.data.mainContextCeiling;return(0,ma.jsx)("div",{className:"space-y-6",children:a.map(({data:{agent:n,isExact:i,sessionLoads:o,fileLoads:s,totalTokens:l}})=>(0,ma.jsxs)("section",{className:"space-y-3","aria-label":`${n} main context`,children:[(0,ma.jsxs)("h2",{className:"text-[13px] font-semibold",children:[n," opens a session with ",l.toLocaleString("en-US")," tokens of the charter, ",i?"counted exactly":"estimated",r!==void 0&&(0,ma.jsxs)("span",{className:l>r?"text-[#b45309]":"text-zinc-400",children:[" ","\xB7 ",l>r?"past":"within"," the ceiling of ",r.toLocaleString("en-US")]})]}),[["Loaded when a session opens",o],["Loaded when a file it names is touched, not in the total",s]].map(([u,c])=>c.length>0&&(0,ma.jsxs)("div",{className:"space-y-1.5",children:[(0,ma.jsx)("h3",{className:"text-[10.5px] font-bold tracking-[0.06em] text-zinc-400 uppercase",children:u}),(0,ma.jsx)("table",{className:"w-full overflow-hidden rounded-[11px] border border-[#f0f0f0] text-xs","aria-label":u,children:(0,ma.jsx)("tbody",{children:c.map(({data:{id:f,kind:d,tokens:h,globs:p}})=>(0,ma.jsxs)("tr",{className:"border-b border-zinc-100 last:border-b-0",children:[(0,ma.jsx)("td",{className:"w-[90px] px-[13px] py-2 text-right font-mono",children:h.toLocaleString("en-US")}),(0,ma.jsx)("td",{className:"w-[90px] px-2 py-2 text-zinc-500",children:d}),(0,ma.jsx)("td",{className:"px-2 py-2 font-mono",children:f}),(0,ma.jsx)("td",{className:"px-2 py-2 font-mono text-zinc-400",children:p?.join(", ")})]},f))})})]},u))]},n))})}var Wz=L(F(),1);var De=L(H(),1);function Kz(){let{open:t}=ho(),e=Hm(),a=$A(),r=oi(),n=BA(),[i,o]=(0,Wz.useState)(null);if(e.data===void 0)return null;let{testSuites:s}=e.data.data,l=new Set(r.data?.type==="Primitives"?r.data.data.primitives.map(({data:m})=>m.id):[]),u=a.data?.type==="TestRunReport"?a.data:void 0,c=m=>u?.data.testCaseReports.filter(({data:x})=>x.suiteName===m)??[],f=s.reduce((m,{data:x})=>m+x.cases.length,0),d=u?.data.testCaseReports.filter(({data:m})=>!m.passed).length??0,h=async()=>{let{data:m}=await a.refetch();if(m?.type!=="TestRunReport")return;let x=m.data.testCaseReports.find(({data:g})=>!g.passed);x!==void 0&&o(x.data.suiteName)},p=async()=>{let m=await n.mutateAsync();o(m),t("testSuite",{name:m}),cl("Test file created",{description:`.cw/test/${m} \xB7 edit the cases, then run them`})};return(0,De.jsxs)("div",{className:"space-y-2.5",children:[(0,De.jsxs)("div",{className:`mb-[18px] flex flex-wrap items-center gap-[11px] rounded-xl border px-[15px] py-[13px] ${u===void 0?"":d>0?"border-[#f6d9d9] bg-[#fef6f6]":"border-[#dcf0e2] bg-[#f5fbf7]"}`,"aria-label":"Test summary",children:[(0,De.jsx)("span",{className:"text-[12.5px] font-bold",children:u===void 0?`${f} case${f===1?"":"s"} in ${s.length} file${s.length===1?"":"s"}`:`${u.data.testCaseReports.length-d} of ${u.data.testCaseReports.length} cases pass`}),(0,De.jsx)("span",{className:"min-w-0 flex-1 text-[11.5px] leading-[1.6] text-zinc-500",children:"A case names the file a change touches or the event it raises, then says what must come up. It runs nothing and asks no agent."}),(0,De.jsx)(Ae,{variant:"outline",disabled:n.isPending,onClick:()=>{p()},children:"New test file"}),(0,De.jsx)(Ae,{disabled:a.isFetching,onClick:()=>{h()},children:"Run all tests"})]}),a.data?.type==="FaultsByFile"&&(0,De.jsx)(fs,{faultsByFile:a.data,label:"Nothing was resolved"}),s.length===0&&(0,De.jsx)("div",{className:"rounded-xl border border-dashed px-[15px] py-3.5 text-[11.5px] leading-[1.6] text-zinc-500",children:"No test file yet. Test files live in .cw/test/."}),s.map(({data:m})=>{let x=c(m.name),g=x.filter(({data:O})=>!O.passed).length;return(0,De.jsxs)("section",{className:"overflow-hidden rounded-[14px] border bg-background","aria-label":m.name,children:[(0,De.jsxs)("div",{className:"flex items-baseline gap-2.5 px-[15px] py-3",children:[(0,De.jsxs)("button",{className:"flex min-w-0 flex-1 cursor-pointer items-baseline gap-2.5 text-left","aria-expanded":i===m.name,onClick:()=>o(i===m.name?null:m.name),children:[(0,De.jsx)("span",{className:"font-mono text-[11.5px] font-bold",children:m.name}),(0,De.jsx)("span",{className:"min-w-0 flex-1 text-[11.5px] text-zinc-500",children:m.description}),(0,De.jsxs)("span",{className:`font-mono text-[10.5px] ${g>0?"text-destructive":"text-zinc-400"}`,children:[m.cases.length," case",m.cases.length===1?"":"s",g>0&&` \xB7 ${g} failing`]})]}),(0,De.jsx)(Ae,{variant:"ghost",className:"h-auto p-0 text-[11.5px] text-zinc-400 hover:bg-transparent hover:text-foreground",onClick:()=>t("testSuite",{name:m.name}),children:"Edit"})]}),m.fault!==void 0&&(0,De.jsxs)("p",{className:"border-t border-[#f7f7f8] px-[15px] py-2.5 text-[11.5px] text-destructive",children:[m.fault.data.message," ",(0,De.jsx)("span",{className:"text-zinc-400",children:m.fault.data.fix})]}),i===m.name&&m.cases.map(({data:O},y)=>(0,De.jsx)(zW,{testCase:O,testCaseReport:x[y],isHeld:O.id===void 0||l.has(O.id),onOpen:b=>t("primitive",{id:b})},y))]},m.name)})]})}function zW({testCase:t,testCaseReport:e,isHeld:a,onOpen:r}){let n=e?.data.unmet,{id:i,expectation:o}=t;return(0,De.jsxs)("div",{className:`grid grid-cols-[minmax(150px,1fr)_minmax(0,1.4fr)_auto] items-baseline gap-3 border-t border-[#f7f7f8] px-[15px] py-2.5 ${n?"bg-[#fef6f6]":""}`,children:[(0,De.jsx)("span",{className:"font-mono text-[10.5px]",children:t.situation}),n!==void 0?(0,De.jsxs)("span",{className:"font-mono text-[10.5px] text-destructive",children:[n.data.message," ",(0,De.jsx)("span",{className:"text-zinc-400",children:n.data.fix})]}):(0,De.jsx)("span",{className:"font-mono text-[10.5px] text-zinc-400",children:i===void 0||!o.endsWith(i)?o:(0,De.jsxs)(De.Fragment,{children:[o.slice(0,-i.length),a?(0,De.jsx)("button",{className:"cursor-pointer text-[#1d4ed8] underline underline-offset-2",onClick:()=>r(i),children:i}):(0,De.jsxs)(De.Fragment,{children:[(0,De.jsx)("span",{className:"underline decoration-dotted underline-offset-2",children:i})," ",(0,De.jsx)(mi,{className:"rounded-[5px] bg-zinc-100 px-1.5 py-0 font-sans text-[10px] font-normal text-zinc-500",children:"not in the charter"})]})]})}),(0,De.jsx)(mi,{className:`rounded-[5px] px-[7px] py-0 text-[11.5px] font-bold tracking-[0.04em] [font-variant-caps:all-small-caps] ${e===void 0?"bg-zinc-50 text-[#c4c4c8]":e.data.passed?"bg-[#f0fdf4] text-[#15803d]":"bg-[#fdeef0] text-[#b91c1c]"}`,children:e===void 0?"not run":e.data.passed?"pass":"fail"})]})}var Zt=L(H(),1);function Jz(){let{open:t}=ho(),e=MA(),a=oi(),r=DA();if(e.data===void 0)return null;let n=e.data,i=a.data?.type==="Primitives"?a.data.data.primitives.filter(({data:s})=>s.layerName==="vendor"):[],o=async s=>{let l=await r.mutateAsync(s.split("/").at(-1)??"");if(l!==null)return void cl.error(l.data.message,{description:l.data.fix});cl("Vendor source removed",{description:`${s} \xB7 run Build to compile the charter without it`})};return n.length===0?(0,Zt.jsxs)("div",{className:"flex items-center gap-[9px] rounded-xl border border-dashed px-[15px] py-3.5","aria-label":"Vendor sources",children:[(0,Zt.jsx)("span",{className:"text-xs font-semibold",children:"No vendor source installed"}),(0,Zt.jsx)(Ae,{size:"sm",className:"ml-auto",onClick:()=>t("addVendor",{}),children:"Add vendor source"})]}):(0,Zt.jsxs)("section",{className:"divide-y divide-[#f0f0f0] overflow-hidden rounded-[13px] border bg-background","aria-label":"Vendor sources",children:[(0,Zt.jsx)("h2",{className:"px-3.5 py-[11px] text-[10.5px] font-bold tracking-[0.06em] text-zinc-400 uppercase",children:"Vendor sources"}),n.map(s=>{let l=i.filter(({data:c})=>c.file.startsWith(`${s}/`)),u=[...new Set(l.map(({data:c})=>c.kind))].sort().map(c=>[c,l.filter(({data:f})=>f.kind===c).length]);return(0,Zt.jsxs)("div",{className:"flex flex-col gap-2.5 bg-[#f6f2ff] px-3.5 py-3","aria-label":s,children:[(0,Zt.jsxs)("div",{className:"min-w-0 space-y-0.5",children:[(0,Zt.jsx)("div",{className:"text-[12.5px] font-semibold",children:s.split("/").at(-1)}),(0,Zt.jsxs)("div",{className:"text-[11px] text-zinc-500",children:[(0,Zt.jsxs)("span",{className:"font-mono",children:[s,"/"]})," \xB7 read-only"]})]}),(0,Zt.jsx)("dl",{className:"grid grid-cols-[1fr_auto] gap-x-2 gap-y-1.5 text-[11.5px] text-zinc-500","aria-label":"Primitives by kind",children:u.map(([c,f])=>(0,Zt.jsxs)("div",{className:"contents",children:[(0,Zt.jsx)("dt",{children:c}),(0,Zt.jsx)("dd",{className:"font-mono text-[10.5px] text-zinc-400",children:f})]},c))}),(0,Zt.jsx)(Ae,{size:"sm",variant:"outline",className:"self-start",disabled:r.isPending,onClick:()=>{o(s)},children:"Remove"})]},s)}),(0,Zt.jsx)("div",{className:"px-3.5 py-[11px]",children:(0,Zt.jsx)(Ae,{size:"sm",variant:"outline",onClick:()=>t("addVendor",{}),children:"Add source"})})]})}var iu=L(H(),1),eN=({...t})=>(0,iu.jsx)(VA,{theme:"light",className:"toaster group",icons:{success:(0,iu.jsx)(Go,{className:"size-4"}),info:(0,iu.jsx)(kd,{className:"size-4"}),warning:(0,iu.jsx)(Ko,{className:"size-4"}),error:(0,iu.jsx)(Wo,{className:"size-4"}),loading:(0,iu.jsx)(Yo,{className:"size-4 animate-spin"})},style:{"--normal-bg":"var(--popover)","--normal-text":"var(--popover-foreground)","--normal-border":"var(--border)","--border-radius":"var(--radius)"},...t});var qe=L(H(),1),NW=[["repo","Repo Charter"],["vendor","Vendor"],["test","Test"],["context","Context"]],g0="rounded-2xl border bg-background px-[22px] py-5";function XW(){let[t,e]=(0,Vh.useState)("repo"),[a,r]=(0,Vh.useState)(null),{open:n}=ho();return(0,qe.jsxs)(qe.Fragment,{children:[(0,qe.jsxs)("header",{className:"sticky top-0 z-20 flex h-14 items-center gap-3 border-b bg-background px-[26px]",children:[(0,qe.jsxs)("span",{className:"flex items-center gap-[9px] text-[13.5px] font-bold tracking-[-0.01em]",children:[(0,qe.jsx)("img",{src:"./logo.png",alt:"",className:"size-[22px] object-contain"}),"Cherry Works"]}),(0,qe.jsx)("span",{className:"font-mono text-[11.5px] text-zinc-400"}),(0,qe.jsx)("div",{className:"ml-auto flex w-full max-w-[460px]",children:(0,qe.jsx)(Gz,{onPick:({data:{id:i,kind:o,layerName:s}})=>{e(s==="vendor"?"vendor":"repo"),r(o),n("primitive",{id:i})}})}),(0,qe.jsx)(Ae,{variant:"outline",onClick:()=>n("buildPreview",{}),children:"Build"}),(0,qe.jsx)(Ae,{variant:"outline",onClick:()=>n("doctor",{}),children:"Doctor"})]}),(0,qe.jsx)("main",{className:"mx-auto max-w-[1120px] px-[26px] pt-[22px] pb-[60px]",children:(0,qe.jsxs)(u0,{value:t,onValueChange:i=>{e(i),r(null)},children:[(0,qe.jsx)(c0,{className:"mb-4 h-auto w-full gap-1 rounded-[11px] bg-[#e9e9ec] p-1",children:NW.map(([i,o])=>(0,qe.jsx)(zh,{value:i,className:"h-auto rounded-lg py-[9px] text-[12.5px] font-semibold text-zinc-500 data-[state=active]:shadow-[0_1px_3px_rgba(0,0,0,0.09)]",children:o},i))}),(0,qe.jsx)(Es,{value:"repo",className:g0,children:(0,qe.jsx)(DC,{layerNames:["repo","builtin"],kind:a,onKindChange:r})}),(0,qe.jsxs)(Es,{value:"vendor",className:`${g0} grid items-start gap-4 md:has-[>section]:grid-cols-[210px_minmax(0,1fr)]`,children:[(0,qe.jsx)(Jz,{}),(0,qe.jsx)(DC,{layerNames:["vendor"],kind:a,onKindChange:r})]}),(0,qe.jsx)(Es,{value:"test",className:g0,children:(0,qe.jsx)(Kz,{})}),(0,qe.jsx)(Es,{value:"context",className:g0,children:(0,qe.jsx)(Yz,{})})]})}),(0,qe.jsx)(eN,{})]})}var qW=new Bb;(0,tN.createRoot)(document.getElementById("root")).render((0,qe.jsx)(Vh.StrictMode,{children:(0,qe.jsx)(Lb,{client:qW,children:(0,qe.jsx)(kz,{children:(0,qe.jsx)(XW,{})})})}));
140
140
  /*! Bundled license information:
141
141
 
142
142
  react/cjs/react.production.js:
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "cherry-works",
3
- "version": "0.6.1",
3
+ "version": "0.6.2",
4
4
  "description": "The charter engine: resolves a charter and compiles it into what a coding agent reads.",
5
5
  "keywords": [
6
6
  "claude-code",