cherry-works 0.3.0 → 0.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -230,10 +230,21 @@ longer hold.
230
230
  cw vendor add git@github.com:your-org/charter-baseline.git --ref v1.2.0
231
231
  ```
232
232
 
233
- A vendor source is a git repository with primitives laid out in folders by kind.
234
- It is installed under `.cw/vendor/<name>/`, pinned to the ref you chose and
235
- committed. Vendored primitives are read-only. To differ from one, write your own
236
- primitive under a new identity.
233
+ A vendor source is a git repository set up with `cw init`: author its charter
234
+ there, test it, and push. Only its `.cw/charter/` folder is installed, under
235
+ `.cw/vendor/<name>/`, pinned to the ref you chose and committed. A repository
236
+ without that folder is refused, and so is one that has vendors of its own:
237
+ vendoring is one level deep. Vendored primitives are read-only. To differ from
238
+ one, write your own primitive under a new identity.
239
+
240
+ Run `cw vendor add` again with a new `--ref` to update a source, and
241
+ `cw vendor remove <name>` to take it away. Run `cw build` after either.
242
+
243
+ ### Recommended charter vendors
244
+
245
+ | Charter | What it gives your agent | Install |
246
+ | --- | --- | --- |
247
+ | [hexagonal-architecture-charter](https://github.com/tamnguyenvt/hexagonal-architecture-charter) | Sets up a hexagonal (ports and adapters) architecture in a folder you choose, then keeps the agent following it. | `cw vendor add git@github.com:tamnguyenvt/hexagonal-architecture-charter.git --ref v0.1.0` |
237
248
 
238
249
  ## Places outside the repository
239
250
 
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.3.0",
6
+ version: "0.4.0",
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
@@ -6,7 +6,7 @@ import { pathToFileURL as pathToFileURL2 } from "url";
6
6
  // package.json
7
7
  var package_default = {
8
8
  name: "cherry-works",
9
- version: "0.3.0",
9
+ version: "0.4.0",
10
10
  description: "The charter engine: resolves a charter and compiles it into what a coding agent reads.",
11
11
  keywords: [
12
12
  "claude-code",
@@ -3354,8 +3354,7 @@ async function ensureVCSReady(repo, vcs2, because) {
3354
3354
  async function addVendor(repo, vcs2, source, version) {
3355
3355
  await ensureVCSReady(repo, vcs2, "installing a vendor commits what it installs");
3356
3356
  const folder = `${VENDOR_DIRECTORY}/${vendorSourceOf(source).name}`;
3357
- await vcs2.subtreeAdd(source, repo, folder, version);
3358
- return folder;
3357
+ return vcs2.subtreeAdd(source, CHARTER_DIRECTORY, repo, folder, version, VENDOR_DIRECTORY);
3359
3358
  }
3360
3359
  async function removeVendor(repo, vcs2, name) {
3361
3360
  await ensureVCSReady(repo, vcs2, "removing a vendor commits that it is gone");
@@ -4900,12 +4899,6 @@ import { promisify } from "util";
4900
4899
  import { fileURLToPath as fileURLToPath2 } from "url";
4901
4900
  var run = promisify(execFile);
4902
4901
  var Git = class {
4903
- /** How it looks at a folder. Reading files is somebody else's port, and this
4904
- * asks it rather than reaching for the filesystem itself. */
4905
- constructor(fileReader2) {
4906
- this.fileReader = fileReader2;
4907
- }
4908
- fileReader;
4909
4902
  async isInstalled(folder) {
4910
4903
  try {
4911
4904
  await run("git", ["rev-parse", "--git-dir"], { cwd: fileURLToPath2(folder) });
@@ -4947,35 +4940,65 @@ var Git = class {
4947
4940
  }
4948
4941
  }
4949
4942
  /**
4950
- * `git subtree`, handed the source exactly as it was written: `add` where the
4951
- * folder is not there yet and `pull` where it is, so installing a source and
4952
- * bringing it up to date are one call (FR-023, FR-030).
4943
+ * `git fetch`, handed the source exactly as it was written, then
4944
+ * `git read-tree` of the one folder asked for into the folder given, and a
4945
+ * commit: a folder already there is removed in the same commit, so
4946
+ * installing a source and bringing it up to date are one call (FR-023,
4947
+ * FR-030, FR-042).
4953
4948
  *
4954
4949
  * Which transport it is, whether the credentials are there, whether the
4955
4950
  * version exists: git answers all three, and what it says is what the user
4956
- * reads (FR-031).
4957
- *
4958
- * `--squash` because what is installed is content to read and not a history
4959
- * to walk: one commit lands, holding the source's files under the folder
4960
- * given (FR-028). `HEAD` where no version is named, which is what the source
4951
+ * reads (FR-031). `HEAD` where no version is named, which is what the source
4961
4952
  * calls its own default.
4953
+ *
4954
+ * `git subtree` takes a source whole and cannot take one folder of it, so
4955
+ * the tree is read straight off what was fetched. Whether that folder is
4956
+ * there, and whether the refused one is, is asked of git before anything is
4957
+ * touched. One commit lands, holding the folder's files and no history to
4958
+ * walk (FR-028); none lands where the copy is what was already there.
4962
4959
  */
4963
- async subtreeAdd(source, repo, intoSubFolder, version) {
4960
+ async subtreeAdd(source, sourceSubFolder, repo, intoSubFolder, version, refusedIfSourceHolds) {
4964
4961
  const cwd = fileURLToPath2(repo);
4965
- const targetFolder = new URL(`${intoSubFolder}/`, repo);
4966
- const targetFolderExist = (await this.fileReader.readFilesRecursively(targetFolder)).length > 0;
4962
+ const ref = version ?? "HEAD";
4967
4963
  try {
4968
- await run(
4969
- "git",
4970
- ["subtree", targetFolderExist ? "pull" : "add", `--prefix=${intoSubFolder}`, "--squash", "--", source, version ?? "HEAD"],
4971
- { cwd }
4972
- );
4964
+ await run("git", ["fetch", "--quiet", "--no-tags", "--", source, ref], { cwd });
4973
4965
  } catch (raised) {
4974
4966
  throw new DrivenFault(
4975
4967
  `${raised}`,
4976
4968
  version === void 0 ? "Check the address, and that you can reach it from here." : `Check the address, and that "${version}" is a tag or branch it has.`
4977
4969
  );
4978
4970
  }
4971
+ const { stdout: fetchedCommit } = await run("git", ["rev-parse", "FETCH_HEAD"], { cwd });
4972
+ const isTreeAt = (folder) => run("git", ["cat-file", "-t", `${fetchedCommit.trim()}:${folder}`], { cwd }).then(
4973
+ ({ stdout }) => stdout.trim() === "tree",
4974
+ () => false
4975
+ );
4976
+ const atVersion = version === void 0 ? "" : ` at ${version}`;
4977
+ if (!await isTreeAt(sourceSubFolder))
4978
+ throw new DrivenFault(
4979
+ `${source} has no folder "${sourceSubFolder}"${atVersion}.`,
4980
+ `Check that the source holds "${sourceSubFolder}" at the version asked for.`
4981
+ );
4982
+ if (refusedIfSourceHolds !== void 0 && await isTreeAt(refusedIfSourceHolds))
4983
+ throw new DrivenFault(
4984
+ `${source} holds "${refusedIfSourceHolds}"${atVersion}, which this copy refuses.`,
4985
+ `Remove "${refusedIfSourceHolds}" from the source, or copy a version without it.`
4986
+ );
4987
+ const sourceTree = `${fetchedCommit.trim()}:${sourceSubFolder}`;
4988
+ try {
4989
+ await run("git", ["rm", "-r", "--quiet", "--ignore-unmatch", "--", intoSubFolder], { cwd });
4990
+ await run("git", ["read-tree", `--prefix=${intoSubFolder}/`, "-u", sourceTree], { cwd });
4991
+ const unchanged = await run("git", ["diff", "--cached", "--quiet"], { cwd }).then(
4992
+ () => true,
4993
+ () => false
4994
+ );
4995
+ if (!unchanged)
4996
+ await run("git", ["commit", "-qm", `Install ${source}${atVersion} into ${intoSubFolder}`], { cwd });
4997
+ return intoSubFolder;
4998
+ } catch (raised) {
4999
+ await run("git", ["restore", "--source=HEAD", "--staged", "--worktree", "--", intoSubFolder], { cwd }).catch(() => void 0);
5000
+ throw new DrivenFault(`${raised}`, `Check that "${intoSubFolder}" holds nothing of your own in hand, and run this again.`);
5001
+ }
4979
5002
  }
4980
5003
  /** `git rm -r` and a commit of its own: the folder is gone from the working
4981
5004
  * tree and from the history from here on, the way adding it put it into
@@ -5258,7 +5281,7 @@ function faultOf(raised, failed, fix) {
5258
5281
  var fileReader = new FileReaders();
5259
5282
  var yamlParser = new YamlParser();
5260
5283
  var fileWriter = new FileOutput();
5261
- var vcs = new Git(fileReader);
5284
+ var vcs = new Git();
5262
5285
  var secrets = new OsSecrets();
5263
5286
  var authorizing = new OAuth();
5264
5287
  var mcpServers = new McpClients();
@@ -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>${Tr(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?Tr(a,!0):this.parser.parseInline(r),o=F5(t);if(o===null)return i;t=Tr(o,n);let s='<a href="'+t+'"';return e&&(s+=' title="'+Tr(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=F5(t);if(n===null)return Tr(a);t=n;let i=`<img src="${Tr(t)}" alt="${Tr(a)}"`;return e&&(i+=` title="${Tr(e)}"`),i+=">",i}text(t){return"tokens"in t&&t.tokens?this.parser.parseInline(t.tokens):"escaped"in t&&t.escaped?t.text:Tr(t.text)}},vC=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}},Bn=class hC{options;renderer;textRenderer;constructor(e){this.options=e||Kl,this.options.renderer=this.options.renderer||new s0,this.renderer=this.options.renderer,this.renderer.options=this.options,this.renderer.parser=this,this.textRenderer=new vC}static parse(e,a){return new hC(a).parse(e)}static parseInline(e,a){return new hC(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}},Eh=class{options;block;constructor(t){this.options=t||Kl}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?$n.lex:$n.lexInline}provideParser(t=this.block){return t?Bn.parse:Bn.parseInline}},SC=class{defaults=pC();options=this.setOptions;parse=this.parseMarkdown(!0);parseInline=this.parseMarkdown(!1);Parser=Bn;Renderer=s0;TextRenderer=vC;Lexer=$n;Tokenizer=o0;Hooks=Eh;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 s0(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 o0(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 Eh;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];Eh.passThroughHooks.has(i)?n[o]=u=>{if(this.defaults.async&&Eh.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 $n.lex(t,e??this.defaults)}parser(t,e){return Bn.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?$n.lex:$n.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?Bn.parse:Bn.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?$n.lex:$n.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?Bn.parse:Bn.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>"+Tr(a.message+"",!0)+"</pre>";return e?Promise.resolve(r):r}if(e)return Promise.reject(a);throw a}}},Wl=new SC;function it(t,e){return Wl.parse(t,e)}it.options=it.setOptions=function(t){return Wl.setOptions(t),it.defaults=Wl.defaults,K5(it.defaults),it};it.getDefaults=pC;it.defaults=Kl;function G8(...t){return Wl.use(...t),it.defaults=Wl.defaults,K5(it.defaults),it}it.use=G8;it.walkTokens=function(t,e){return Wl.walkTokens(t,e)};it.parseInline=Wl.parseInline;it.Parser=Bn;it.parser=Bn.parse;it.Renderer=s0;it.TextRenderer=vC;it.Lexer=$n;it.lexer=$n.lex;it.Tokenizer=o0;it.Hooks=Eh;it.parse=it;var Qse=it.options,Mse=it.setOptions,Ese=it.walkTokens,Dse=it.parseInline;var $se=Bn.parse,Bse=$n.lex;var Vse=L(F(),1);var zh=L(G(),1);function l0({className:t,orientation:e="horizontal",...a}){return(0,zh.jsx)(Cl.Root,{"data-slot":"tabs","data-orientation":e,orientation:e,className:pe("group/tabs flex gap-2 data-[orientation=horizontal]:flex-col",t),...a})}var Y8=si("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 u0({className:t,variant:e="default",...a}){return(0,zh.jsx)(Cl.List,{"data-slot":"tabs-list","data-variant":e,className:pe(Y8({variant:e}),t),...a})}function _h({className:t,...e}){return(0,zh.jsx)(Cl.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 Jl({className:t,...e}){return(0,zh.jsx)(Cl.Content,{"data-slot":"tabs-content",className:pe("flex-1 outline-none",t),...e})}var or=L(G(),1),W8=new SC({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="#")}}),sz="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 wC({body:t,onChange:e}){return(0,or.jsxs)(l0,{defaultValue:e===void 0?"preview":"source",className:"gap-0 overflow-hidden rounded-xl border bg-background",children:[(0,or.jsxs)("div",{className:"flex items-center gap-2.5 border-b border-[#f0f0f0] px-[13px] py-[9px]",children:[(0,or.jsx)("span",{className:"text-[10.5px] font-bold tracking-[0.06em] text-zinc-400 uppercase",children:"Body"}),(0,or.jsx)("span",{className:"font-mono text-[10.5px] text-zinc-400",children:"markdown"}),(0,or.jsxs)(u0,{className:"ml-auto h-auto gap-0.5 rounded-lg bg-[#f0f0f2] p-[3px]",children:[(0,or.jsx)(_h,{value:"source",className:sz,children:"Source"}),(0,or.jsx)(_h,{value:"preview",className:sz,children:"Preview"})]})]}),(0,or.jsx)(Jl,{value:"source",className:"h-[300px] flex-none",children:(0,or.jsx)(K8,{body:t,onChange:e})}),(0,or.jsx)(Jl,{value:"preview",children:(0,or.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:W8.parse(t,{async:!1})}})})]})}function K8({body:t,onChange:e}){let a=(0,lz.useCallback)(r=>{let n=new oe({parent:r,doc:t,extensions:[q5(),j$(F$),iB(),zl.of([...DB,...uB]),oe.lineWrapping,oe.editable.of(e!==void 0),oe.updateListener.of(i=>{i.docChanged&&e?.(i.state.doc.toString())})]});return()=>n.destroy()},[]);return(0,or.jsx)("div",{className:"h-full",ref:a})}var ale=L(F(),1);var uz=L(G(),1);function eu({className:t,type:e,...a}){return(0,uz.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 ile=L(F(),1);var cz=L(G(),1);function Nh({className:t,...e}){return(0,cz.jsx)(Eg.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 ule=L(F(),1);var Rt=L(G(),1);function CC({...t}){return(0,Rt.jsx)(Ea.Root,{"data-slot":"select",...t})}function kC({...t}){return(0,Rt.jsx)(Ea.Value,{"data-slot":"select-value",...t})}function LC({className:t,size:e="default",children:a,...r}){return(0,Rt.jsxs)(Ea.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,Rt.jsx)(Ea.Icon,{asChild:!0,children:(0,Rt.jsx)(Oc,{className:"size-4 opacity-50"})})]})}function TC({className:t,children:e,position:a="item-aligned",align:r="center",...n}){return(0,Rt.jsx)(Ea.Portal,{children:(0,Rt.jsxs)(Ea.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,Rt.jsx)(J8,{}),(0,Rt.jsx)(Ea.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,Rt.jsx)(eW,{})]})})}function PC({className:t,children:e,...a}){return(0,Rt.jsxs)(Ea.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,Rt.jsx)("span",{"data-slot":"select-item-indicator",className:"absolute right-2 flex size-3.5 items-center justify-center",children:(0,Rt.jsx)(Ea.ItemIndicator,{children:(0,Rt.jsx)(Sd,{className:"size-4"})})}),(0,Rt.jsx)(Ea.ItemText,{children:e})]})}function J8({className:t,...e}){return(0,Rt.jsx)(Ea.ScrollUpButton,{"data-slot":"select-scroll-up-button",className:pe("flex cursor-default items-center justify-center py-1",t),...e,children:(0,Rt.jsx)(wd,{className:"size-4"})})}function eW({className:t,...e}){return(0,Rt.jsx)(Ea.ScrollDownButton,{"data-slot":"select-scroll-down-button",className:pe("flex cursor-default items-center justify-center py-1",t),...e,children:(0,Rt.jsx)(Oc,{className:"size-4"})})}var K=L(G(),1);function RC({identity:t,newKind:e,onDone:a,onClose:r}){let{data:n}=wA(t);if(t===void 0)return(0,K.jsx)(fz,{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)(hz,{faults:[i]}):i.data.layerName!=="repo"?(0,K.jsx)(tW,{openedPrimitive:i}):(0,K.jsx)(fz,{openedPrimitive:i,entityTag:o,newKind:"",onDone:a,onClose:r})}function fz({openedPrimitive:t,entityTag:e,newKind:a,onDone:r,onClose:n}){let i=t?.data,[o,s]=(0,ff.useState)(i?.kind??a),[l,u]=(0,ff.useState)(i===void 0?"":String(i.headers.id)),[c,f]=(0,ff.useState)(()=>Object.fromEntries(Object.entries(i?.headers??{}).filter(([R])=>R!=="id").map(([R,D])=>[R,typeof D=="string"?D:[...D]]))),[d,h]=(0,ff.useState)(t?.data.body??""),[p,m]=(0,ff.useState)([]),{data:x}=xc(),{data:g}=CA(o),{data:O}=ii(),y=kA(),b=LA(),v=TA(),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.identity):[],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:{identity:t.data.identity},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.identity);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:dz,children:[t===null?(0,K.jsxs)(K.Fragment,{children:[(0,K.jsx)(co,{label:"kind",htmlFor:"primitive-kind",children:(0,K.jsxs)(CC,{value:o,onValueChange:s,children:[(0,K.jsx)(LC,{id:"primitive-kind",className:"w-full",children:(0,K.jsx)(kC,{})}),(0,K.jsx)(TC,{children:S.map(R=>(0,K.jsx)(PC,{value:R,children:R},R))})]})}),(0,K.jsx)(co,{label:"id",htmlFor:"primitive-id",children:(0,K.jsx)(eu,{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)(co,{label:"kind",hint:"the identity 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)(co,{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)(co,{label:R,htmlFor:`header-${R}`,hint:Y?"required":void 0,children:D==="list"?(0,K.jsx)(aW,{field:R,entries:Array.isArray(c[R])?c[R]:[],onChange:q=>f({...c,[R]:q})}):B!==void 0?(0,K.jsxs)(CC,{value:typeof c[R]=="string"?c[R]:"",onValueChange:q=>f({...c,[R]:q}),children:[(0,K.jsx)(LC,{id:`header-${R}`,className:"w-full",children:(0,K.jsx)(kC,{placeholder:"\u2014"})}),(0,K.jsx)(TC,{children:B.map(q=>(0,K.jsx)(PC,{value:q,children:q},q))})]}):(0,K.jsx)(eu,{id:`header-${R}`,spellCheck:!1,autoComplete:"off",value:typeof c[R]=="string"?c[R]:"",list:R==="rationale"?"corpus-identities":void 0,onChange:q=>f({...c,[R]:q.currentTarget.value})})},R))]}),(0,K.jsx)("datalist",{id:"corpus-identities",children:k.map(R=>(0,K.jsx)("option",{value:R},R))}),(0,K.jsx)(wC,{body:d,onChange:h}),p.length>0&&(0,K.jsx)(hz,{faults:p}),(0,K.jsxs)("div",{className:ui,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 tW({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)(Ur,{className:"rounded-xl border-[#7c3aed33] bg-[#f6f2ff]",children:[(0,K.jsx)(jr,{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)(Fr,{className:"text-[11.5px] text-zinc-600",children:"To differ from it, author a primitive of your own under an identity of its own."})]}),(0,K.jsxs)("div",{className:dz,children:[(0,K.jsx)(co,{label:"kind",children:(0,K.jsx)("span",{className:"font-mono text-[11.5px]",children:e})}),(0,K.jsx)(co,{label:"file",children:(0,K.jsx)("span",{className:"font-mono text-[11.5px]",children:r})}),(0,K.jsx)(co,{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)(co,{label:o,children:(0,K.jsx)("span",{className:"font-mono text-[11.5px]",children:typeof s=="string"?s:s.join(", ")})},o))]}),(0,K.jsx)(wC,{body:t.data.body})]})}var dz="overflow-hidden rounded-[11px] border border-[#f0f0f0] bg-background divide-y divide-zinc-100";function co({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)(Nh,{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 aW({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)(eu,{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)(sl,{})})]},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 hz({faults:t}){return(0,K.jsxs)(Ur,{variant:"destructive",className:"rounded-xl border-[#f6d9d9] bg-[#fef6f6]",children:[(0,K.jsx)(jr,{className:"text-[12.5px] font-bold text-foreground",children:"Refused, and nothing was written"}),(0,K.jsx)(Fr,{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 c0=L(F(),1);var pt=L(G(),1);function pz({onDone:t,onClose:e}){let[a,r]=(0,c0.useState)(""),[n,i]=(0,c0.useState)(""),[o,s]=(0,c0.useState)(null),l=xc(),u=AA(),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 of primitives laid out by kind."}),(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)(Nh,{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)(eu,{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)(Nh,{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)(eu,{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:"Reserved directories at its root"}),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)(Ur,{variant:"destructive",className:"rounded-xl border-[#f6d9d9] bg-[#fef6f6]",children:[(0,pt.jsx)(jr,{className:"text-[12.5px] font-bold text-foreground",children:"Refused, and nothing was installed"}),(0,pt.jsx)(Fr,{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:ui,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 IC=L(F(),1);var It=L(G(),1);function mz({name:t,onDone:e,onClose:a}){let n=Fm().data?.data.testSuites.find(({data:i})=>i.name===t);return n===void 0?null:(0,It.jsx)(rW,{name:t,initialText:n.data.text??"",onDone:e,onClose:a},t)}function rW({name:t,initialText:e,onDone:a,onClose:r}){let[n,i]=(0,IC.useState)(e),[o,s]=(0,IC.useState)(null),l=DA(),u=$A(),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,It.jsxs)("div",{className:"space-y-3",children:[(0,It.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,It.jsx)("code",{children:"do.touchFile"}),") or a raised event (",(0,It.jsx)("code",{children:"when"}),") \u2014 and expects one thing:"," ",(0,It.jsx)("code",{children:"activate"}),", ",(0,It.jsx)("code",{children:"run"})," or ",(0,It.jsx)("code",{children:"allow"}),"."]}),(0,It.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,It.jsxs)(Ur,{variant:"destructive",className:"rounded-xl border-[#f6d9d9] bg-[#fef6f6]",children:[(0,It.jsx)(jr,{className:"text-[12.5px] font-bold text-foreground",children:"Refused, and nothing was written"}),(0,It.jsx)(Fr,{children:(0,It.jsxs)("p",{className:"break-words whitespace-pre-line",children:[o.data.message," ",(0,It.jsx)("span",{className:"text-muted-foreground",children:o.data.fix})]})})]}),(0,It.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,It.jsxs)("div",{className:ui,children:[(0,It.jsx)(Ae,{disabled:l.isPending,onClick:()=>{c()},children:"Save"}),(0,It.jsx)(Ae,{variant:"outline",onClick:r,children:"Cancel"}),(0,It.jsx)(Ae,{variant:"destructive",className:"ml-auto",disabled:u.isPending,onClick:()=>{f()},children:"Delete file"})]})]})}var $le=L(F(),1);var sr=L(G(),1);function gz({...t}){return(0,sr.jsx)(xn.Root,{"data-slot":"dialog",...t})}function nW({...t}){return(0,sr.jsx)(xn.Portal,{"data-slot":"dialog-portal",...t})}function iW({className:t,...e}){return(0,sr.jsx)(xn.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 Oz({className:t,children:e,showCloseButton:a=!0,...r}){return(0,sr.jsxs)(nW,{"data-slot":"dialog-portal",children:[(0,sr.jsx)(iW,{}),(0,sr.jsxs)(xn.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,sr.jsxs)(xn.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,sr.jsx)(sl,{}),(0,sr.jsx)("span",{className:"sr-only",children:"Close"})]})]})]})}function xz({className:t,...e}){return(0,sr.jsx)("div",{"data-slot":"dialog-header",className:pe("flex flex-col gap-2 text-center sm:text-left",t),...e})}function yz({className:t,...e}){return(0,sr.jsx)(xn.Title,{"data-slot":"dialog-title",className:pe("text-lg leading-none font-semibold",t),...e})}function bz({className:t,...e}){return(0,sr.jsx)(xn.Description,{"data-slot":"dialog-description",className:pe("text-sm text-muted-foreground",t),...e})}var pa=L(G(),1),oW={explanation:{title:()=>"Explain",context:({identity:t})=>t,holdsDraft:!1,render:({identity:t},{open:e})=>(0,pa.jsx)(TE,{identity:t,onExplain:a=>e("explanation",{identity:a})},t)},primitive:{title:({identity:t})=>t,context:()=>"",holdsDraft:!0,render:({identity:t},{close:e})=>(0,pa.jsx)(RC,{identity:t,onDone:f0(e),onClose:e},t)},newPrimitive:{title:()=>"New primitive",context:()=>"",holdsDraft:!0,render:({kind:t},{close:e})=>(0,pa.jsx)(RC,{newKind:t,onDone:f0(e),onClose:e},`new ${t}`)},buildPreview:{title:()=>"cw build",context:()=>"nothing written yet",holdsDraft:!1,render:(t,{open:e})=>(0,pa.jsx)(SE,{onBuilt:a=>e("buildOutcome",{buildAnswer:a})})},buildOutcome:{title:()=>"cw build",context:()=>"",holdsDraft:!1,render:({buildAnswer:t})=>(0,pa.jsx)(wE,{buildAnswer:t})},addVendor:{title:()=>"Add vendor source",context:()=>"",holdsDraft:!0,render:(t,{close:e})=>(0,pa.jsx)(pz,{onDone:f0(e),onClose:e})},testSuite:{title:({name:t})=>`.cw/test/${t}`,context:()=>"",holdsDraft:!0,render:({name:t},{close:e})=>(0,pa.jsx)(mz,{name:t,onDone:f0(e),onClose:e},t)},doctor:{title:()=>"Doctor",context:()=>"cw 0.3.0",holdsDraft:!1,render:(t,{open:e})=>(0,pa.jsx)(LE,{onBuilt:a=>e("buildOutcome",{buildAnswer:a})})}};function f0(t){return(e,a)=>{t(),ll(e,{description:a})}}var vz=(0,tu.createContext)(null);function fo(){return(0,tu.useContext)(vz)}function Sz({children:t}){let[e,a]=(0,tu.useState)(null),[r,n]=(0,tu.useState)(!1),i={open:(s,l)=>{a({name:s,params:l}),n(!0)},close:()=>n(!1)},o=e===null?null:oW[e.name];return(0,pa.jsxs)(vz.Provider,{value:i,children:[t,(0,pa.jsx)(gz,{open:r,onOpenChange:n,children:e!==null&&o!==null&&(0,pa.jsxs)(Oz,{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)(xz,{className:"flex-row items-baseline gap-2.5 border-b border-[#f0f0f0] py-[15px] pr-12 pl-[18px]",children:[(0,pa.jsx)(yz,{className:"text-[14.5px] font-bold tracking-[-0.01em]",children:o.title(e.params)}),(0,pa.jsx)(bz,{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 h0=L(F(),1);var Wle=L(F(),1);var sW=L(G(),1),wz=si("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 d0=L(G(),1),Cz=h0.createContext({size:"default",variant:"default",spacing:0});function kz({className:t,variant:e,size:a,spacing:r=0,children:n,...i}){return(0,d0.jsx)(Xd.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,d0.jsx)(Cz.Provider,{value:{variant:e,size:a,spacing:r},children:n})})}function Lz({className:t,children:e,variant:a,size:r,...n}){let i=h0.useContext(Cz);return(0,d0.jsx)(Xd.Item,{"data-slot":"toggle-group-item","data-variant":i.variant||a,"data-size":i.size||r,"data-spacing":i.spacing,className:pe(wz({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(G(),1);function MC({layerNames:t,kind:e,onKindChange:a}){let{open:r}=fo(),n=xc(),i=ii();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)(lW,{faultsByFile:s});if(s.type==="Fault")return(0,se.jsx)(uW,{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)(kz,{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)(Lz,{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)(pi,{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)(cW,{kind:c,listed:f})]})}function lW({faultsByFile:t}){let e=Object.entries(t.data.files);return(0,se.jsxs)("div",{className:"space-y-3.5",children:[(0,se.jsxs)(Ur,{variant:"destructive",className:"rounded-xl border-[#f6d9d9] bg-[#fef6f6]",children:[(0,se.jsx)(jr,{className:"text-[12.5px] font-bold text-foreground",children:"The engine will not read this charter"}),(0,se.jsxs)(Fr,{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)(cs,{faultsByFile:t,label:"Refused files"})]})}function uW({fault:t}){return(0,se.jsxs)(Ur,{variant:"destructive",className:"rounded-xl border-[#f6d9d9] bg-[#fef6f6]",children:[(0,se.jsx)(jr,{className:"text-[12.5px] font-bold text-foreground",children:t.data.message}),(0,se.jsx)(Fr,{children:t.data.fix})]})}function AC(t){return t===void 0?void 0:typeof t=="string"?[t]:t}function cW({kind:t,listed:e}){let{open:a}=fo(),r=t==="guide",n=t!=="mixin";return(0,se.jsx)("div",{className:"overflow-hidden rounded-[14px] border bg-background",children:(0,se.jsxs)(kl,{"aria-label":`${t} primitives`,className:"table-fixed",children:[(0,se.jsx)(bE,{children:(0,se.jsxs)(Tl,{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)(Pl,{className:"w-[170px]",children:"Id"}),(0,se.jsx)(Pl,{children:"Description"}),r&&(0,se.jsxs)(se.Fragment,{children:[(0,se.jsx)(Pl,{className:"w-[170px] text-right",children:"Matching globs"}),(0,se.jsx)(Pl,{className:"w-[120px] text-right",children:"Rationale"})]}),n&&(0,se.jsx)(Pl,{className:"w-[120px] text-right",children:"Mixins"}),(0,se.jsx)(Pl,{className:"w-[50px]"})]})}),(0,se.jsx)(Ll,{children:e.map(({data:{identity:i,description:o,file:s,headers:l}})=>{let u=AC(l.globs);return(0,se.jsxs)(Tl,{className:"group/row border-[#f7f7f8] align-top hover:bg-zinc-50 [&>td]:px-[15px] [&>td]:py-3",children:[(0,se.jsx)(Cn,{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",{identity:i}),children:String(l.id)})}),(0,se.jsxs)(Cn,{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)(QC,{named:u,none:"all patterns",said:u===void 0,label:"Matching globs"}),(0,se.jsx)(QC,{named:AC(l.rationale),none:"none",said:!1,label:"Rationale"})]}),n&&(0,se.jsx)(QC,{named:AC(l.mixins),none:"none",said:!1,label:"Mixins"}),(0,se.jsx)(Cn,{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",{identity:i}),children:(0,se.jsx)(hn,{})})})]},i)})})]})})}function QC({named:t,none:e,said:a,label:r}){return(0,se.jsx)(Cn,{"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)(pi,{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 NC=L(F(),1);var Sue=L(F(),1);var Tz=1,fW=.9,dW=.8,hW=.17,EC=.1,DC=.999,pW=.9999,mW=.99,gW=/[\\\/_+.#"@\[\(\{&]/,OW=/[\\\/_+.#"@\[\(\{&]/g,xW=/[\s-]/,Rz=/[\s-]/g;function $C(t,e,a,r,n,i,o){if(i===e.length)return n===t.length?Tz:mW;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*=Tz:gW.test(t.charAt(u-1))?(f*=dW,h=t.slice(n,u-1).match(OW),h&&n>0&&(f*=Math.pow(DC,h.length))):xW.test(t.charAt(u-1))?(f*=fW,p=t.slice(n,u-1).match(Rz),p&&n>0&&(f*=Math.pow(DC,p.length))):(f*=hW,n>0&&(f*=Math.pow(DC,u-n))),t.charAt(u)!==e.charAt(i)&&(f*=pW)),(f<EC&&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*EC>f&&(f=d*EC)),f>c&&(c=f),u=a.indexOf(l,u+1);return o[s]=c,c}function Pz(t){return t.toLowerCase().replace(Rz," ")}function Iz(t,e,a){return t=a&&a.length>0?`${t+" "+a.join(" ")}`:t,$C(t,e,Pz(t),Pz(e),0,0,{})}var J=L(F(),1);var Xh='[cmdk-group=""]',BC='[cmdk-group-items=""]',yW='[cmdk-group-heading=""]',Qz='[cmdk-item=""]',Az=`${Qz}:not([aria-disabled="true"])`,_C="cmdk-item-select",df="data-value",bW=(t,e,a)=>Iz(t,e,a),Mz=J.createContext(void 0),qh=()=>J.useContext(Mz),Ez=J.createContext(void 0),zC=()=>J.useContext(Ez),Dz=J.createContext(void 0),$z=J.forwardRef((t,e)=>{let a=hf(()=>{var P,H;return{search:"",value:(H=(P=t.value)!=null?P:t.defaultValue)!=null?H:"",selectedItemId:void 0,filtered:{count:0,items:new Map,groups:new Set}}}),r=hf(()=>new Set),n=hf(()=>new Map),i=hf(()=>new Map),o=hf(()=>new Set),s=Bz(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=AW();au(()=>{if(c!==void 0){let P=c.trim();a.current.value=P,w.emit()}},[c]),au(()=>{S(6,R)},[]);let w=J.useMemo(()=>({subscribe:P=>(o.current.add(P),()=>o.current.delete(P)),snapshot:()=>a.current,setState:(P,H,N)=>{var M,j,de,ee;if(!Object.is(a.current[P],H)){if(a.current[P]=H,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=H??"";(ee=(de=s.current).onValueChange)==null||ee.call(de,Z);return}}w.emit()}},emit:()=>{o.current.forEach(P=>P())}}),[]),k=J.useMemo(()=>({value:(P,H,N)=>{var M;H!==((M=i.current.get(P))==null?void 0:M.value)&&(i.current.set(P,{value:H,keywords:N}),a.current.filtered.items.set(P,T(H,N)),S(2,()=>{Q(),w.emit()}))},item:(P,H)=>(r.current.add(P),H&&(n.current.has(H)?n.current.get(H).add(P):n.current.set(H,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,H){var N,M;let j=(M=(N=s.current)==null?void 0:N.filter)!=null?M:bW;return P?j(P,a.current.search,H):0}function Q(){if(!a.current.search||s.current.shouldFilter===!1)return;let P=a.current.filtered.items,H=[];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)}),H.push([M,de])});let N=v.current;Y().sort((M,j)=>{var de,ee;let Z=M.getAttribute("id"),qe=j.getAttribute("id");return((de=P.get(qe))!=null?de:0)-((ee=P.get(Z))!=null?ee:0)}).forEach(M=>{let j=M.closest(BC);j?j.appendChild(M.parentElement===j?M:M.closest(`${BC} > *`)):N.appendChild(M.parentElement===N?M:M.closest(`${BC} > *`))}),H.sort((M,j)=>j[1]-M[1]).forEach(M=>{var j;let de=(j=v.current)==null?void 0:j.querySelector(`${Xh}[${df}="${encodeURIComponent(M[0])}"]`);de?.parentElement.appendChild(de)})}function $(){let P=Y().find(N=>N.getAttribute("aria-disabled")!=="true"),H=P?.getAttribute(df);w.setState("value",H||void 0)}function A(){var P,H,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=(H=(P=i.current.get(de))==null?void 0:P.value)!=null?H:"",Z=(M=(N=i.current.get(de))==null?void 0:N.keywords)!=null?M:[],qe=T(ee,Z);a.current.filtered.items.set(de,qe),qe>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,H,N;let M=D();M&&(((P=M.parentElement)==null?void 0:P.firstChild)===M&&((N=(H=M.closest(Xh))==null?void 0:H.querySelector(yW))==null||N.scrollIntoView({block:"nearest"})),M.scrollIntoView({block:"nearest"}))}function D(){var P;return(P=v.current)==null?void 0:P.querySelector(`${Qz}[aria-selected="true"]`)}function Y(){var P;return Array.from(((P=v.current)==null?void 0:P.querySelectorAll(Az))||[])}function B(P){let H=Y()[P];H&&w.setState("value",H.getAttribute(df))}function q(P){var H;let N=D(),M=Y(),j=M.findIndex(ee=>ee===N),de=M[j+P];(H=s.current)!=null&&H.loop&&(de=j+P<0?M[M.length-1]:j+P===M.length?M[0]:M[j+P]),de&&w.setState("value",de.getAttribute(df))}function re(P){let H=D(),N=H?.closest(Xh),M;for(;N&&!M;)N=P>0?RW(N,Xh):IW(N,Xh),M=N?.querySelector(Az);M?w.setState("value",M.getAttribute(df)):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 H;(H=g.onKeyDown)==null||H.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(_C);M.dispatchEvent(j)}}}}},J.createElement("label",{"cmdk-label":"",htmlFor:k.inputId,id:k.labelId,style:MW},l),p0(t,P=>J.createElement(Ez.Provider,{value:w},J.createElement(Mz.Provider,{value:k},P))))}),vW=J.forwardRef((t,e)=>{var a,r;let n=Dt(),i=J.useRef(null),o=J.useContext(Dz),s=qh(),l=Bz(t),u=(r=(a=l.current)==null?void 0:a.forceMount)!=null?r:o?.forceMount;au(()=>{if(!u)return s.item(n,o?.id)},[u]);let c=_z(n,i,[t.value,t.children,i],t.keywords),f=zC(),d=Ms(S=>S.value&&S.value===c.current),h=Ms(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(_C,p),()=>S.removeEventListener(_C,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:es(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)}),SW=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=qh(),f=Ms(h=>n||c.filter()===!1?!0:h.search?h.filtered.groups.has(o):!0);au(()=>c.group(o),[]),_z(o,s,[t.value,t.heading,l]);let d=J.useMemo(()=>({id:o,forceMount:n}),[n]);return J.createElement(ue.div,{ref:es(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),p0(t,h=>J.createElement("div",{"cmdk-group-items":"",role:"group","aria-labelledby":a?u:void 0},J.createElement(Dz.Provider,{value:d},h))))}),wW=J.forwardRef((t,e)=>{let{alwaysRender:a,...r}=t,n=J.useRef(null),i=Ms(o=>!o.search);return!a&&!i?null:J.createElement(ue.div,{ref:es(n,e),...r,"cmdk-separator":"",role:"separator"})}),CW=J.forwardRef((t,e)=>{let{onValueChange:a,...r}=t,n=t.value!=null,i=zC(),o=Ms(u=>u.search),s=Ms(u=>u.selectedItemId),l=qh();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)}})}),kW=J.forwardRef((t,e)=>{let{children:a,label:r="Suggestions",...n}=t,i=J.useRef(null),o=J.useRef(null),s=Ms(u=>u.selectedItemId),l=qh();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:es(i,e),...n,"cmdk-list":"",role:"listbox",tabIndex:-1,"aria-activedescendant":s,"aria-label":r,id:l.listId},p0(t,u=>J.createElement("div",{ref:es(o,l.listInnerRef),"cmdk-list-sizer":""},u)))}),LW=J.forwardRef((t,e)=>{let{open:a,onOpenChange:r,overlayClassName:n,contentClassName:i,container:o,...s}=t;return J.createElement(Rv,{open:a,onOpenChange:r},J.createElement(Iv,{container:o},J.createElement(Av,{"cmdk-overlay":"",className:n}),J.createElement(Qv,{"aria-label":t.label,"cmdk-dialog":"",className:i},J.createElement($z,{ref:e,...s}))))}),TW=J.forwardRef((t,e)=>Ms(a=>a.filtered.count===0)?J.createElement(ue.div,{ref:e,...t,"cmdk-empty":"",role:"presentation"}):null),PW=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},p0(t,o=>J.createElement("div",{"aria-hidden":!0},o)))}),ru=Object.assign($z,{List:kW,Item:vW,Input:CW,Group:SW,Separator:wW,Dialog:LW,Empty:TW,Loading:PW});function RW(t,e){let a=t.nextElementSibling;for(;a;){if(a.matches(e))return a;a=a.nextElementSibling}}function IW(t,e){let a=t.previousElementSibling;for(;a;){if(a.matches(e))return a;a=a.previousElementSibling}}function Bz(t){let e=J.useRef(t);return au(()=>{e.current=t}),e}var au=typeof window>"u"?J.useEffect:J.useLayoutEffect;function hf(t){let e=J.useRef();return e.current===void 0&&(e.current=t()),e}function Ms(t){let e=zC(),a=()=>t(e.snapshot());return J.useSyncExternalStore(e.subscribe,a,a)}function _z(t,e,a,r=[]){let n=J.useRef(),i=qh();return au(()=>{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(df,s),n.current=s}),n}var AW=()=>{let[t,e]=J.useState(),a=hf(()=>new Map);return au(()=>{a.current.forEach(r=>r()),a.current=new Map},[t]),(r,n)=>{a.current.set(r,n),e({})}};function QW(t){let e=t.type;return typeof e=="function"?e(t.props):"render"in e?e.render(t.props):t}function p0({asChild:t,children:e},a){return t&&J.isValidElement(e)?J.cloneElement(QW(e),{ref:e.ref},a(e.props.children)):a(e)}var MW={position:"absolute",width:"1px",height:"1px",padding:"0",margin:"-1px",overflow:"hidden",clip:"rect(0, 0, 0, 0)",whiteSpace:"nowrap",borderWidth:"0"};var vi=L(G(),1);function zz({className:t,...e}){return(0,vi.jsx)(ru,{"data-slot":"command",className:pe("flex h-full w-full flex-col overflow-hidden rounded-md bg-popover text-popover-foreground",t),...e})}function Nz({className:t,...e}){return(0,vi.jsxs)("div",{"data-slot":"command-input-wrapper",className:"flex h-9 items-center gap-2 border-b px-3",children:[(0,vi.jsx)(kd,{className:"size-4 shrink-0 opacity-50"}),(0,vi.jsx)(ru.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 Xz({className:t,...e}){return(0,vi.jsx)(ru.List,{"data-slot":"command-list",className:pe("max-h-[300px] scroll-py-1 overflow-x-hidden overflow-y-auto",t),...e})}function qz({...t}){return(0,vi.jsx)(ru.Empty,{"data-slot":"command-empty",className:"py-6 text-center text-sm",...t})}function Zz({className:t,...e}){return(0,vi.jsx)(ru.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 Vz({className:t,...e}){return(0,vi.jsx)(ru.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(G(),1);function jz({onPick:t}){let[e,a]=(0,NC.useState)(""),[r,n]=(0,NC.useState)(!1),{data:i}=ii(e);return(0,mt.jsxs)(zz,{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)(Nz,{placeholder:"Search everything",spellCheck:!1,value:e,onValueChange:a,onKeyDown:o=>o.key==="Escape"&&a("")}),r&&e!==""&&(0,mt.jsxs)(Xz,{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)(qz,{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)(Zz,{heading:`${i.data.primitives.length} primitive${i.data.primitives.length===1?"":"s"}`,children:i.data.primitives.map(o=>{let{identity:s,kind:l,description:u,layerName:c,headers:f}=o.data;return(0,mt.jsxs)(Vz,{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)(Uz,{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)(Uz,{text:u,word:e})})]}),(0,mt.jsx)(pi,{className:`rounded-[5px] px-1.5 py-0.5 font-mono text-[9.5px] font-bold tracking-[0.03em] ${EW[c]}`,children:c})]},s)})})]})]})]})}var EW={repo:"bg-[#eff6ff] text-[#1d4ed8]",vendor:"bg-[#f6f2ff] text-[#7c3aed]",builtin:"bg-zinc-100 text-zinc-700"};function Uz({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 Fz=L(F(),1);var De=L(G(),1);function Hz(){let{open:t}=fo(),e=Fm(),a=MA(),r=ii(),n=EA(),[i,o]=(0,Fz.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.identity):[]),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}),ll("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)(cs,{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)(DW,{testCase:O,testCaseReport:x[y],isHeld:O.identity===void 0||l.has(O.identity),onOpen:b=>t("primitive",{identity:b})},y))]},m.name)})]})}function DW({testCase:t,testCaseReport:e,isHeld:a,onOpen:r}){let n=e?.data.unmet,{identity: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)(pi,{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)(pi,{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(G(),1);function Gz(){let{open:t}=fo(),e=IA(),a=ii(),r=QA();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 ll.error(l.data.message,{description:l.data.fix});ll("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))].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 nu=L(G(),1),Yz=({...t})=>(0,nu.jsx)(XA,{theme:"light",className:"toaster group",icons:{success:(0,nu.jsx)(Ho,{className:"size-4"}),info:(0,nu.jsx)(Cd,{className:"size-4"}),warning:(0,nu.jsx)(Wo,{className:"size-4"}),error:(0,nu.jsx)(Yo,{className:"size-4"}),loading:(0,nu.jsx)(Go,{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 Ge=L(G(),1),$W=[["repo","Repo Charter"],["vendor","Vendor"],["test","Test"]],XC="rounded-2xl border bg-background px-[22px] py-5";function BW(){let[t,e]=(0,Zh.useState)("repo"),[a,r]=(0,Zh.useState)(null),{open:n}=fo();return(0,Ge.jsxs)(Ge.Fragment,{children:[(0,Ge.jsxs)("header",{className:"sticky top-0 z-20 flex h-14 items-center gap-3 border-b bg-background px-[26px]",children:[(0,Ge.jsxs)("span",{className:"flex items-center gap-[9px] text-[13.5px] font-bold tracking-[-0.01em]",children:[(0,Ge.jsx)("img",{src:"./logo.png",alt:"",className:"size-[22px] object-contain"}),"Cherry Works"]}),(0,Ge.jsx)("span",{className:"font-mono text-[11.5px] text-zinc-400"}),(0,Ge.jsx)("div",{className:"ml-auto flex w-full max-w-[460px]",children:(0,Ge.jsx)(jz,{onPick:({data:{identity:i,kind:o,layerName:s}})=>{e(s==="vendor"?"vendor":"repo"),r(o),n("primitive",{identity:i})}})}),(0,Ge.jsx)(Ae,{variant:"outline",onClick:()=>n("buildPreview",{}),children:"Build"}),(0,Ge.jsx)(Ae,{variant:"outline",onClick:()=>n("doctor",{}),children:"Doctor"})]}),(0,Ge.jsx)("main",{className:"mx-auto max-w-[1120px] px-[26px] pt-[22px] pb-[60px]",children:(0,Ge.jsxs)(l0,{value:t,onValueChange:i=>{e(i),r(null)},children:[(0,Ge.jsx)(u0,{className:"mb-4 h-auto w-full gap-1 rounded-[11px] bg-[#e9e9ec] p-1",children:$W.map(([i,o])=>(0,Ge.jsx)(_h,{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,Ge.jsx)(Jl,{value:"repo",className:XC,children:(0,Ge.jsx)(MC,{layerNames:["repo","builtin"],kind:a,onKindChange:r})}),(0,Ge.jsxs)(Jl,{value:"vendor",className:`${XC} grid items-start gap-4 md:has-[>section]:grid-cols-[210px_minmax(0,1fr)]`,children:[(0,Ge.jsx)(Gz,{}),(0,Ge.jsx)(MC,{layerNames:["vendor"],kind:a,onKindChange:r})]}),(0,Ge.jsx)(Jl,{value:"test",className:XC,children:(0,Ge.jsx)(Hz,{})})]})}),(0,Ge.jsx)(Yz,{})]})}var _W=new Db;(0,Wz.createRoot)(document.getElementById("root")).render((0,Ge.jsx)(Zh.StrictMode,{children:(0,Ge.jsx)(Cb,{client:_W,children:(0,Ge.jsx)(Sz,{children:(0,Ge.jsx)(BW,{})})})}));
139
+ Please report this to https://github.com/markedjs/marked.`,t){let r="<p>An error occurred:</p><pre>"+Tr(a.message+"",!0)+"</pre>";return e?Promise.resolve(r):r}if(e)return Promise.reject(a);throw a}}},Wl=new SC;function it(t,e){return Wl.parse(t,e)}it.options=it.setOptions=function(t){return Wl.setOptions(t),it.defaults=Wl.defaults,K5(it.defaults),it};it.getDefaults=pC;it.defaults=Kl;function G8(...t){return Wl.use(...t),it.defaults=Wl.defaults,K5(it.defaults),it}it.use=G8;it.walkTokens=function(t,e){return Wl.walkTokens(t,e)};it.parseInline=Wl.parseInline;it.Parser=Bn;it.parser=Bn.parse;it.Renderer=s0;it.TextRenderer=vC;it.Lexer=$n;it.lexer=$n.lex;it.Tokenizer=o0;it.Hooks=Eh;it.parse=it;var Qse=it.options,Mse=it.setOptions,Ese=it.walkTokens,Dse=it.parseInline;var $se=Bn.parse,Bse=$n.lex;var Vse=L(F(),1);var zh=L(G(),1);function l0({className:t,orientation:e="horizontal",...a}){return(0,zh.jsx)(Cl.Root,{"data-slot":"tabs","data-orientation":e,orientation:e,className:pe("group/tabs flex gap-2 data-[orientation=horizontal]:flex-col",t),...a})}var Y8=si("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 u0({className:t,variant:e="default",...a}){return(0,zh.jsx)(Cl.List,{"data-slot":"tabs-list","data-variant":e,className:pe(Y8({variant:e}),t),...a})}function _h({className:t,...e}){return(0,zh.jsx)(Cl.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 Jl({className:t,...e}){return(0,zh.jsx)(Cl.Content,{"data-slot":"tabs-content",className:pe("flex-1 outline-none",t),...e})}var or=L(G(),1),W8=new SC({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="#")}}),sz="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 wC({body:t,onChange:e}){return(0,or.jsxs)(l0,{defaultValue:e===void 0?"preview":"source",className:"gap-0 overflow-hidden rounded-xl border bg-background",children:[(0,or.jsxs)("div",{className:"flex items-center gap-2.5 border-b border-[#f0f0f0] px-[13px] py-[9px]",children:[(0,or.jsx)("span",{className:"text-[10.5px] font-bold tracking-[0.06em] text-zinc-400 uppercase",children:"Body"}),(0,or.jsx)("span",{className:"font-mono text-[10.5px] text-zinc-400",children:"markdown"}),(0,or.jsxs)(u0,{className:"ml-auto h-auto gap-0.5 rounded-lg bg-[#f0f0f2] p-[3px]",children:[(0,or.jsx)(_h,{value:"source",className:sz,children:"Source"}),(0,or.jsx)(_h,{value:"preview",className:sz,children:"Preview"})]})]}),(0,or.jsx)(Jl,{value:"source",className:"h-[300px] flex-none",children:(0,or.jsx)(K8,{body:t,onChange:e})}),(0,or.jsx)(Jl,{value:"preview",children:(0,or.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:W8.parse(t,{async:!1})}})})]})}function K8({body:t,onChange:e}){let a=(0,lz.useCallback)(r=>{let n=new oe({parent:r,doc:t,extensions:[q5(),j$(F$),iB(),zl.of([...DB,...uB]),oe.lineWrapping,oe.editable.of(e!==void 0),oe.updateListener.of(i=>{i.docChanged&&e?.(i.state.doc.toString())})]});return()=>n.destroy()},[]);return(0,or.jsx)("div",{className:"h-full",ref:a})}var ale=L(F(),1);var uz=L(G(),1);function eu({className:t,type:e,...a}){return(0,uz.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 ile=L(F(),1);var cz=L(G(),1);function Nh({className:t,...e}){return(0,cz.jsx)(Eg.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 ule=L(F(),1);var Rt=L(G(),1);function CC({...t}){return(0,Rt.jsx)(Ea.Root,{"data-slot":"select",...t})}function kC({...t}){return(0,Rt.jsx)(Ea.Value,{"data-slot":"select-value",...t})}function LC({className:t,size:e="default",children:a,...r}){return(0,Rt.jsxs)(Ea.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,Rt.jsx)(Ea.Icon,{asChild:!0,children:(0,Rt.jsx)(Oc,{className:"size-4 opacity-50"})})]})}function TC({className:t,children:e,position:a="item-aligned",align:r="center",...n}){return(0,Rt.jsx)(Ea.Portal,{children:(0,Rt.jsxs)(Ea.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,Rt.jsx)(J8,{}),(0,Rt.jsx)(Ea.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,Rt.jsx)(eW,{})]})})}function PC({className:t,children:e,...a}){return(0,Rt.jsxs)(Ea.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,Rt.jsx)("span",{"data-slot":"select-item-indicator",className:"absolute right-2 flex size-3.5 items-center justify-center",children:(0,Rt.jsx)(Ea.ItemIndicator,{children:(0,Rt.jsx)(Sd,{className:"size-4"})})}),(0,Rt.jsx)(Ea.ItemText,{children:e})]})}function J8({className:t,...e}){return(0,Rt.jsx)(Ea.ScrollUpButton,{"data-slot":"select-scroll-up-button",className:pe("flex cursor-default items-center justify-center py-1",t),...e,children:(0,Rt.jsx)(wd,{className:"size-4"})})}function eW({className:t,...e}){return(0,Rt.jsx)(Ea.ScrollDownButton,{"data-slot":"select-scroll-down-button",className:pe("flex cursor-default items-center justify-center py-1",t),...e,children:(0,Rt.jsx)(Oc,{className:"size-4"})})}var K=L(G(),1);function RC({identity:t,newKind:e,onDone:a,onClose:r}){let{data:n}=wA(t);if(t===void 0)return(0,K.jsx)(fz,{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)(hz,{faults:[i]}):i.data.layerName!=="repo"?(0,K.jsx)(tW,{openedPrimitive:i}):(0,K.jsx)(fz,{openedPrimitive:i,entityTag:o,newKind:"",onDone:a,onClose:r})}function fz({openedPrimitive:t,entityTag:e,newKind:a,onDone:r,onClose:n}){let i=t?.data,[o,s]=(0,ff.useState)(i?.kind??a),[l,u]=(0,ff.useState)(i===void 0?"":String(i.headers.id)),[c,f]=(0,ff.useState)(()=>Object.fromEntries(Object.entries(i?.headers??{}).filter(([R])=>R!=="id").map(([R,D])=>[R,typeof D=="string"?D:[...D]]))),[d,h]=(0,ff.useState)(t?.data.body??""),[p,m]=(0,ff.useState)([]),{data:x}=xc(),{data:g}=CA(o),{data:O}=ii(),y=kA(),b=LA(),v=TA(),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.identity):[],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:{identity:t.data.identity},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.identity);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:dz,children:[t===null?(0,K.jsxs)(K.Fragment,{children:[(0,K.jsx)(co,{label:"kind",htmlFor:"primitive-kind",children:(0,K.jsxs)(CC,{value:o,onValueChange:s,children:[(0,K.jsx)(LC,{id:"primitive-kind",className:"w-full",children:(0,K.jsx)(kC,{})}),(0,K.jsx)(TC,{children:S.map(R=>(0,K.jsx)(PC,{value:R,children:R},R))})]})}),(0,K.jsx)(co,{label:"id",htmlFor:"primitive-id",children:(0,K.jsx)(eu,{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)(co,{label:"kind",hint:"the identity 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)(co,{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)(co,{label:R,htmlFor:`header-${R}`,hint:Y?"required":void 0,children:D==="list"?(0,K.jsx)(aW,{field:R,entries:Array.isArray(c[R])?c[R]:[],onChange:q=>f({...c,[R]:q})}):B!==void 0?(0,K.jsxs)(CC,{value:typeof c[R]=="string"?c[R]:"",onValueChange:q=>f({...c,[R]:q}),children:[(0,K.jsx)(LC,{id:`header-${R}`,className:"w-full",children:(0,K.jsx)(kC,{placeholder:"\u2014"})}),(0,K.jsx)(TC,{children:B.map(q=>(0,K.jsx)(PC,{value:q,children:q},q))})]}):(0,K.jsx)(eu,{id:`header-${R}`,spellCheck:!1,autoComplete:"off",value:typeof c[R]=="string"?c[R]:"",list:R==="rationale"?"corpus-identities":void 0,onChange:q=>f({...c,[R]:q.currentTarget.value})})},R))]}),(0,K.jsx)("datalist",{id:"corpus-identities",children:k.map(R=>(0,K.jsx)("option",{value:R},R))}),(0,K.jsx)(wC,{body:d,onChange:h}),p.length>0&&(0,K.jsx)(hz,{faults:p}),(0,K.jsxs)("div",{className:ui,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 tW({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)(Ur,{className:"rounded-xl border-[#7c3aed33] bg-[#f6f2ff]",children:[(0,K.jsx)(jr,{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)(Fr,{className:"text-[11.5px] text-zinc-600",children:"To differ from it, author a primitive of your own under an identity of its own."})]}),(0,K.jsxs)("div",{className:dz,children:[(0,K.jsx)(co,{label:"kind",children:(0,K.jsx)("span",{className:"font-mono text-[11.5px]",children:e})}),(0,K.jsx)(co,{label:"file",children:(0,K.jsx)("span",{className:"font-mono text-[11.5px]",children:r})}),(0,K.jsx)(co,{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)(co,{label:o,children:(0,K.jsx)("span",{className:"font-mono text-[11.5px]",children:typeof s=="string"?s:s.join(", ")})},o))]}),(0,K.jsx)(wC,{body:t.data.body})]})}var dz="overflow-hidden rounded-[11px] border border-[#f0f0f0] bg-background divide-y divide-zinc-100";function co({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)(Nh,{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 aW({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)(eu,{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)(sl,{})})]},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 hz({faults:t}){return(0,K.jsxs)(Ur,{variant:"destructive",className:"rounded-xl border-[#f6d9d9] bg-[#fef6f6]",children:[(0,K.jsx)(jr,{className:"text-[12.5px] font-bold text-foreground",children:"Refused, and nothing was written"}),(0,K.jsx)(Fr,{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 c0=L(F(),1);var pt=L(G(),1);function pz({onDone:t,onClose:e}){let[a,r]=(0,c0.useState)(""),[n,i]=(0,c0.useState)(""),[o,s]=(0,c0.useState)(null),l=xc(),u=AA(),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)(Nh,{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)(eu,{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)(Nh,{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)(eu,{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)(Ur,{variant:"destructive",className:"rounded-xl border-[#f6d9d9] bg-[#fef6f6]",children:[(0,pt.jsx)(jr,{className:"text-[12.5px] font-bold text-foreground",children:"Refused, and nothing was installed"}),(0,pt.jsx)(Fr,{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:ui,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 IC=L(F(),1);var It=L(G(),1);function mz({name:t,onDone:e,onClose:a}){let n=Fm().data?.data.testSuites.find(({data:i})=>i.name===t);return n===void 0?null:(0,It.jsx)(rW,{name:t,initialText:n.data.text??"",onDone:e,onClose:a},t)}function rW({name:t,initialText:e,onDone:a,onClose:r}){let[n,i]=(0,IC.useState)(e),[o,s]=(0,IC.useState)(null),l=DA(),u=$A(),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,It.jsxs)("div",{className:"space-y-3",children:[(0,It.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,It.jsx)("code",{children:"do.touchFile"}),") or a raised event (",(0,It.jsx)("code",{children:"when"}),") \u2014 and expects one thing:"," ",(0,It.jsx)("code",{children:"activate"}),", ",(0,It.jsx)("code",{children:"run"})," or ",(0,It.jsx)("code",{children:"allow"}),"."]}),(0,It.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,It.jsxs)(Ur,{variant:"destructive",className:"rounded-xl border-[#f6d9d9] bg-[#fef6f6]",children:[(0,It.jsx)(jr,{className:"text-[12.5px] font-bold text-foreground",children:"Refused, and nothing was written"}),(0,It.jsx)(Fr,{children:(0,It.jsxs)("p",{className:"break-words whitespace-pre-line",children:[o.data.message," ",(0,It.jsx)("span",{className:"text-muted-foreground",children:o.data.fix})]})})]}),(0,It.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,It.jsxs)("div",{className:ui,children:[(0,It.jsx)(Ae,{disabled:l.isPending,onClick:()=>{c()},children:"Save"}),(0,It.jsx)(Ae,{variant:"outline",onClick:r,children:"Cancel"}),(0,It.jsx)(Ae,{variant:"destructive",className:"ml-auto",disabled:u.isPending,onClick:()=>{f()},children:"Delete file"})]})]})}var $le=L(F(),1);var sr=L(G(),1);function gz({...t}){return(0,sr.jsx)(xn.Root,{"data-slot":"dialog",...t})}function nW({...t}){return(0,sr.jsx)(xn.Portal,{"data-slot":"dialog-portal",...t})}function iW({className:t,...e}){return(0,sr.jsx)(xn.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 Oz({className:t,children:e,showCloseButton:a=!0,...r}){return(0,sr.jsxs)(nW,{"data-slot":"dialog-portal",children:[(0,sr.jsx)(iW,{}),(0,sr.jsxs)(xn.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,sr.jsxs)(xn.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,sr.jsx)(sl,{}),(0,sr.jsx)("span",{className:"sr-only",children:"Close"})]})]})]})}function xz({className:t,...e}){return(0,sr.jsx)("div",{"data-slot":"dialog-header",className:pe("flex flex-col gap-2 text-center sm:text-left",t),...e})}function yz({className:t,...e}){return(0,sr.jsx)(xn.Title,{"data-slot":"dialog-title",className:pe("text-lg leading-none font-semibold",t),...e})}function bz({className:t,...e}){return(0,sr.jsx)(xn.Description,{"data-slot":"dialog-description",className:pe("text-sm text-muted-foreground",t),...e})}var pa=L(G(),1),oW={explanation:{title:()=>"Explain",context:({identity:t})=>t,holdsDraft:!1,render:({identity:t},{open:e})=>(0,pa.jsx)(TE,{identity:t,onExplain:a=>e("explanation",{identity:a})},t)},primitive:{title:({identity:t})=>t,context:()=>"",holdsDraft:!0,render:({identity:t},{close:e})=>(0,pa.jsx)(RC,{identity:t,onDone:f0(e),onClose:e},t)},newPrimitive:{title:()=>"New primitive",context:()=>"",holdsDraft:!0,render:({kind:t},{close:e})=>(0,pa.jsx)(RC,{newKind:t,onDone:f0(e),onClose:e},`new ${t}`)},buildPreview:{title:()=>"cw build",context:()=>"nothing written yet",holdsDraft:!1,render:(t,{open:e})=>(0,pa.jsx)(SE,{onBuilt:a=>e("buildOutcome",{buildAnswer:a})})},buildOutcome:{title:()=>"cw build",context:()=>"",holdsDraft:!1,render:({buildAnswer:t})=>(0,pa.jsx)(wE,{buildAnswer:t})},addVendor:{title:()=>"Add vendor source",context:()=>"",holdsDraft:!0,render:(t,{close:e})=>(0,pa.jsx)(pz,{onDone:f0(e),onClose:e})},testSuite:{title:({name:t})=>`.cw/test/${t}`,context:()=>"",holdsDraft:!0,render:({name:t},{close:e})=>(0,pa.jsx)(mz,{name:t,onDone:f0(e),onClose:e},t)},doctor:{title:()=>"Doctor",context:()=>"cw 0.4.0",holdsDraft:!1,render:(t,{open:e})=>(0,pa.jsx)(LE,{onBuilt:a=>e("buildOutcome",{buildAnswer:a})})}};function f0(t){return(e,a)=>{t(),ll(e,{description:a})}}var vz=(0,tu.createContext)(null);function fo(){return(0,tu.useContext)(vz)}function Sz({children:t}){let[e,a]=(0,tu.useState)(null),[r,n]=(0,tu.useState)(!1),i={open:(s,l)=>{a({name:s,params:l}),n(!0)},close:()=>n(!1)},o=e===null?null:oW[e.name];return(0,pa.jsxs)(vz.Provider,{value:i,children:[t,(0,pa.jsx)(gz,{open:r,onOpenChange:n,children:e!==null&&o!==null&&(0,pa.jsxs)(Oz,{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)(xz,{className:"flex-row items-baseline gap-2.5 border-b border-[#f0f0f0] py-[15px] pr-12 pl-[18px]",children:[(0,pa.jsx)(yz,{className:"text-[14.5px] font-bold tracking-[-0.01em]",children:o.title(e.params)}),(0,pa.jsx)(bz,{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 h0=L(F(),1);var Wle=L(F(),1);var sW=L(G(),1),wz=si("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 d0=L(G(),1),Cz=h0.createContext({size:"default",variant:"default",spacing:0});function kz({className:t,variant:e,size:a,spacing:r=0,children:n,...i}){return(0,d0.jsx)(Xd.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,d0.jsx)(Cz.Provider,{value:{variant:e,size:a,spacing:r},children:n})})}function Lz({className:t,children:e,variant:a,size:r,...n}){let i=h0.useContext(Cz);return(0,d0.jsx)(Xd.Item,{"data-slot":"toggle-group-item","data-variant":i.variant||a,"data-size":i.size||r,"data-spacing":i.spacing,className:pe(wz({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(G(),1);function MC({layerNames:t,kind:e,onKindChange:a}){let{open:r}=fo(),n=xc(),i=ii();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)(lW,{faultsByFile:s});if(s.type==="Fault")return(0,se.jsx)(uW,{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)(kz,{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)(Lz,{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)(pi,{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)(cW,{kind:c,listed:f})]})}function lW({faultsByFile:t}){let e=Object.entries(t.data.files);return(0,se.jsxs)("div",{className:"space-y-3.5",children:[(0,se.jsxs)(Ur,{variant:"destructive",className:"rounded-xl border-[#f6d9d9] bg-[#fef6f6]",children:[(0,se.jsx)(jr,{className:"text-[12.5px] font-bold text-foreground",children:"The engine will not read this charter"}),(0,se.jsxs)(Fr,{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)(cs,{faultsByFile:t,label:"Refused files"})]})}function uW({fault:t}){return(0,se.jsxs)(Ur,{variant:"destructive",className:"rounded-xl border-[#f6d9d9] bg-[#fef6f6]",children:[(0,se.jsx)(jr,{className:"text-[12.5px] font-bold text-foreground",children:t.data.message}),(0,se.jsx)(Fr,{children:t.data.fix})]})}function AC(t){return t===void 0?void 0:typeof t=="string"?[t]:t}function cW({kind:t,listed:e}){let{open:a}=fo(),r=t==="guide",n=t!=="mixin";return(0,se.jsx)("div",{className:"overflow-hidden rounded-[14px] border bg-background",children:(0,se.jsxs)(kl,{"aria-label":`${t} primitives`,className:"table-fixed",children:[(0,se.jsx)(bE,{children:(0,se.jsxs)(Tl,{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)(Pl,{className:"w-[170px]",children:"Id"}),(0,se.jsx)(Pl,{children:"Description"}),r&&(0,se.jsxs)(se.Fragment,{children:[(0,se.jsx)(Pl,{className:"w-[170px] text-right",children:"Matching globs"}),(0,se.jsx)(Pl,{className:"w-[120px] text-right",children:"Rationale"})]}),n&&(0,se.jsx)(Pl,{className:"w-[120px] text-right",children:"Mixins"}),(0,se.jsx)(Pl,{className:"w-[50px]"})]})}),(0,se.jsx)(Ll,{children:e.map(({data:{identity:i,description:o,file:s,headers:l}})=>{let u=AC(l.globs);return(0,se.jsxs)(Tl,{className:"group/row border-[#f7f7f8] align-top hover:bg-zinc-50 [&>td]:px-[15px] [&>td]:py-3",children:[(0,se.jsx)(Cn,{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",{identity:i}),children:String(l.id)})}),(0,se.jsxs)(Cn,{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)(QC,{named:u,none:"all patterns",said:u===void 0,label:"Matching globs"}),(0,se.jsx)(QC,{named:AC(l.rationale),none:"none",said:!1,label:"Rationale"})]}),n&&(0,se.jsx)(QC,{named:AC(l.mixins),none:"none",said:!1,label:"Mixins"}),(0,se.jsx)(Cn,{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",{identity:i}),children:(0,se.jsx)(hn,{})})})]},i)})})]})})}function QC({named:t,none:e,said:a,label:r}){return(0,se.jsx)(Cn,{"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)(pi,{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 NC=L(F(),1);var Sue=L(F(),1);var Tz=1,fW=.9,dW=.8,hW=.17,EC=.1,DC=.999,pW=.9999,mW=.99,gW=/[\\\/_+.#"@\[\(\{&]/,OW=/[\\\/_+.#"@\[\(\{&]/g,xW=/[\s-]/,Rz=/[\s-]/g;function $C(t,e,a,r,n,i,o){if(i===e.length)return n===t.length?Tz:mW;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*=Tz:gW.test(t.charAt(u-1))?(f*=dW,h=t.slice(n,u-1).match(OW),h&&n>0&&(f*=Math.pow(DC,h.length))):xW.test(t.charAt(u-1))?(f*=fW,p=t.slice(n,u-1).match(Rz),p&&n>0&&(f*=Math.pow(DC,p.length))):(f*=hW,n>0&&(f*=Math.pow(DC,u-n))),t.charAt(u)!==e.charAt(i)&&(f*=pW)),(f<EC&&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*EC>f&&(f=d*EC)),f>c&&(c=f),u=a.indexOf(l,u+1);return o[s]=c,c}function Pz(t){return t.toLowerCase().replace(Rz," ")}function Iz(t,e,a){return t=a&&a.length>0?`${t+" "+a.join(" ")}`:t,$C(t,e,Pz(t),Pz(e),0,0,{})}var J=L(F(),1);var Xh='[cmdk-group=""]',BC='[cmdk-group-items=""]',yW='[cmdk-group-heading=""]',Qz='[cmdk-item=""]',Az=`${Qz}:not([aria-disabled="true"])`,_C="cmdk-item-select",df="data-value",bW=(t,e,a)=>Iz(t,e,a),Mz=J.createContext(void 0),qh=()=>J.useContext(Mz),Ez=J.createContext(void 0),zC=()=>J.useContext(Ez),Dz=J.createContext(void 0),$z=J.forwardRef((t,e)=>{let a=hf(()=>{var P,H;return{search:"",value:(H=(P=t.value)!=null?P:t.defaultValue)!=null?H:"",selectedItemId:void 0,filtered:{count:0,items:new Map,groups:new Set}}}),r=hf(()=>new Set),n=hf(()=>new Map),i=hf(()=>new Map),o=hf(()=>new Set),s=Bz(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=AW();au(()=>{if(c!==void 0){let P=c.trim();a.current.value=P,w.emit()}},[c]),au(()=>{S(6,R)},[]);let w=J.useMemo(()=>({subscribe:P=>(o.current.add(P),()=>o.current.delete(P)),snapshot:()=>a.current,setState:(P,H,N)=>{var M,j,de,ee;if(!Object.is(a.current[P],H)){if(a.current[P]=H,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=H??"";(ee=(de=s.current).onValueChange)==null||ee.call(de,Z);return}}w.emit()}},emit:()=>{o.current.forEach(P=>P())}}),[]),k=J.useMemo(()=>({value:(P,H,N)=>{var M;H!==((M=i.current.get(P))==null?void 0:M.value)&&(i.current.set(P,{value:H,keywords:N}),a.current.filtered.items.set(P,T(H,N)),S(2,()=>{Q(),w.emit()}))},item:(P,H)=>(r.current.add(P),H&&(n.current.has(H)?n.current.get(H).add(P):n.current.set(H,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,H){var N,M;let j=(M=(N=s.current)==null?void 0:N.filter)!=null?M:bW;return P?j(P,a.current.search,H):0}function Q(){if(!a.current.search||s.current.shouldFilter===!1)return;let P=a.current.filtered.items,H=[];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)}),H.push([M,de])});let N=v.current;Y().sort((M,j)=>{var de,ee;let Z=M.getAttribute("id"),qe=j.getAttribute("id");return((de=P.get(qe))!=null?de:0)-((ee=P.get(Z))!=null?ee:0)}).forEach(M=>{let j=M.closest(BC);j?j.appendChild(M.parentElement===j?M:M.closest(`${BC} > *`)):N.appendChild(M.parentElement===N?M:M.closest(`${BC} > *`))}),H.sort((M,j)=>j[1]-M[1]).forEach(M=>{var j;let de=(j=v.current)==null?void 0:j.querySelector(`${Xh}[${df}="${encodeURIComponent(M[0])}"]`);de?.parentElement.appendChild(de)})}function $(){let P=Y().find(N=>N.getAttribute("aria-disabled")!=="true"),H=P?.getAttribute(df);w.setState("value",H||void 0)}function A(){var P,H,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=(H=(P=i.current.get(de))==null?void 0:P.value)!=null?H:"",Z=(M=(N=i.current.get(de))==null?void 0:N.keywords)!=null?M:[],qe=T(ee,Z);a.current.filtered.items.set(de,qe),qe>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,H,N;let M=D();M&&(((P=M.parentElement)==null?void 0:P.firstChild)===M&&((N=(H=M.closest(Xh))==null?void 0:H.querySelector(yW))==null||N.scrollIntoView({block:"nearest"})),M.scrollIntoView({block:"nearest"}))}function D(){var P;return(P=v.current)==null?void 0:P.querySelector(`${Qz}[aria-selected="true"]`)}function Y(){var P;return Array.from(((P=v.current)==null?void 0:P.querySelectorAll(Az))||[])}function B(P){let H=Y()[P];H&&w.setState("value",H.getAttribute(df))}function q(P){var H;let N=D(),M=Y(),j=M.findIndex(ee=>ee===N),de=M[j+P];(H=s.current)!=null&&H.loop&&(de=j+P<0?M[M.length-1]:j+P===M.length?M[0]:M[j+P]),de&&w.setState("value",de.getAttribute(df))}function re(P){let H=D(),N=H?.closest(Xh),M;for(;N&&!M;)N=P>0?RW(N,Xh):IW(N,Xh),M=N?.querySelector(Az);M?w.setState("value",M.getAttribute(df)):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 H;(H=g.onKeyDown)==null||H.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(_C);M.dispatchEvent(j)}}}}},J.createElement("label",{"cmdk-label":"",htmlFor:k.inputId,id:k.labelId,style:MW},l),p0(t,P=>J.createElement(Ez.Provider,{value:w},J.createElement(Mz.Provider,{value:k},P))))}),vW=J.forwardRef((t,e)=>{var a,r;let n=Dt(),i=J.useRef(null),o=J.useContext(Dz),s=qh(),l=Bz(t),u=(r=(a=l.current)==null?void 0:a.forceMount)!=null?r:o?.forceMount;au(()=>{if(!u)return s.item(n,o?.id)},[u]);let c=_z(n,i,[t.value,t.children,i],t.keywords),f=zC(),d=Ms(S=>S.value&&S.value===c.current),h=Ms(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(_C,p),()=>S.removeEventListener(_C,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:es(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)}),SW=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=qh(),f=Ms(h=>n||c.filter()===!1?!0:h.search?h.filtered.groups.has(o):!0);au(()=>c.group(o),[]),_z(o,s,[t.value,t.heading,l]);let d=J.useMemo(()=>({id:o,forceMount:n}),[n]);return J.createElement(ue.div,{ref:es(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),p0(t,h=>J.createElement("div",{"cmdk-group-items":"",role:"group","aria-labelledby":a?u:void 0},J.createElement(Dz.Provider,{value:d},h))))}),wW=J.forwardRef((t,e)=>{let{alwaysRender:a,...r}=t,n=J.useRef(null),i=Ms(o=>!o.search);return!a&&!i?null:J.createElement(ue.div,{ref:es(n,e),...r,"cmdk-separator":"",role:"separator"})}),CW=J.forwardRef((t,e)=>{let{onValueChange:a,...r}=t,n=t.value!=null,i=zC(),o=Ms(u=>u.search),s=Ms(u=>u.selectedItemId),l=qh();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)}})}),kW=J.forwardRef((t,e)=>{let{children:a,label:r="Suggestions",...n}=t,i=J.useRef(null),o=J.useRef(null),s=Ms(u=>u.selectedItemId),l=qh();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:es(i,e),...n,"cmdk-list":"",role:"listbox",tabIndex:-1,"aria-activedescendant":s,"aria-label":r,id:l.listId},p0(t,u=>J.createElement("div",{ref:es(o,l.listInnerRef),"cmdk-list-sizer":""},u)))}),LW=J.forwardRef((t,e)=>{let{open:a,onOpenChange:r,overlayClassName:n,contentClassName:i,container:o,...s}=t;return J.createElement(Rv,{open:a,onOpenChange:r},J.createElement(Iv,{container:o},J.createElement(Av,{"cmdk-overlay":"",className:n}),J.createElement(Qv,{"aria-label":t.label,"cmdk-dialog":"",className:i},J.createElement($z,{ref:e,...s}))))}),TW=J.forwardRef((t,e)=>Ms(a=>a.filtered.count===0)?J.createElement(ue.div,{ref:e,...t,"cmdk-empty":"",role:"presentation"}):null),PW=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},p0(t,o=>J.createElement("div",{"aria-hidden":!0},o)))}),ru=Object.assign($z,{List:kW,Item:vW,Input:CW,Group:SW,Separator:wW,Dialog:LW,Empty:TW,Loading:PW});function RW(t,e){let a=t.nextElementSibling;for(;a;){if(a.matches(e))return a;a=a.nextElementSibling}}function IW(t,e){let a=t.previousElementSibling;for(;a;){if(a.matches(e))return a;a=a.previousElementSibling}}function Bz(t){let e=J.useRef(t);return au(()=>{e.current=t}),e}var au=typeof window>"u"?J.useEffect:J.useLayoutEffect;function hf(t){let e=J.useRef();return e.current===void 0&&(e.current=t()),e}function Ms(t){let e=zC(),a=()=>t(e.snapshot());return J.useSyncExternalStore(e.subscribe,a,a)}function _z(t,e,a,r=[]){let n=J.useRef(),i=qh();return au(()=>{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(df,s),n.current=s}),n}var AW=()=>{let[t,e]=J.useState(),a=hf(()=>new Map);return au(()=>{a.current.forEach(r=>r()),a.current=new Map},[t]),(r,n)=>{a.current.set(r,n),e({})}};function QW(t){let e=t.type;return typeof e=="function"?e(t.props):"render"in e?e.render(t.props):t}function p0({asChild:t,children:e},a){return t&&J.isValidElement(e)?J.cloneElement(QW(e),{ref:e.ref},a(e.props.children)):a(e)}var MW={position:"absolute",width:"1px",height:"1px",padding:"0",margin:"-1px",overflow:"hidden",clip:"rect(0, 0, 0, 0)",whiteSpace:"nowrap",borderWidth:"0"};var vi=L(G(),1);function zz({className:t,...e}){return(0,vi.jsx)(ru,{"data-slot":"command",className:pe("flex h-full w-full flex-col overflow-hidden rounded-md bg-popover text-popover-foreground",t),...e})}function Nz({className:t,...e}){return(0,vi.jsxs)("div",{"data-slot":"command-input-wrapper",className:"flex h-9 items-center gap-2 border-b px-3",children:[(0,vi.jsx)(kd,{className:"size-4 shrink-0 opacity-50"}),(0,vi.jsx)(ru.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 Xz({className:t,...e}){return(0,vi.jsx)(ru.List,{"data-slot":"command-list",className:pe("max-h-[300px] scroll-py-1 overflow-x-hidden overflow-y-auto",t),...e})}function qz({...t}){return(0,vi.jsx)(ru.Empty,{"data-slot":"command-empty",className:"py-6 text-center text-sm",...t})}function Zz({className:t,...e}){return(0,vi.jsx)(ru.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 Vz({className:t,...e}){return(0,vi.jsx)(ru.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(G(),1);function jz({onPick:t}){let[e,a]=(0,NC.useState)(""),[r,n]=(0,NC.useState)(!1),{data:i}=ii(e);return(0,mt.jsxs)(zz,{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)(Nz,{placeholder:"Search everything",spellCheck:!1,value:e,onValueChange:a,onKeyDown:o=>o.key==="Escape"&&a("")}),r&&e!==""&&(0,mt.jsxs)(Xz,{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)(qz,{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)(Zz,{heading:`${i.data.primitives.length} primitive${i.data.primitives.length===1?"":"s"}`,children:i.data.primitives.map(o=>{let{identity:s,kind:l,description:u,layerName:c,headers:f}=o.data;return(0,mt.jsxs)(Vz,{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)(Uz,{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)(Uz,{text:u,word:e})})]}),(0,mt.jsx)(pi,{className:`rounded-[5px] px-1.5 py-0.5 font-mono text-[9.5px] font-bold tracking-[0.03em] ${EW[c]}`,children:c})]},s)})})]})]})]})}var EW={repo:"bg-[#eff6ff] text-[#1d4ed8]",vendor:"bg-[#f6f2ff] text-[#7c3aed]",builtin:"bg-zinc-100 text-zinc-700"};function Uz({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 Fz=L(F(),1);var De=L(G(),1);function Hz(){let{open:t}=fo(),e=Fm(),a=MA(),r=ii(),n=EA(),[i,o]=(0,Fz.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.identity):[]),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}),ll("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)(cs,{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)(DW,{testCase:O,testCaseReport:x[y],isHeld:O.identity===void 0||l.has(O.identity),onOpen:b=>t("primitive",{identity:b})},y))]},m.name)})]})}function DW({testCase:t,testCaseReport:e,isHeld:a,onOpen:r}){let n=e?.data.unmet,{identity: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)(pi,{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)(pi,{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(G(),1);function Gz(){let{open:t}=fo(),e=IA(),a=ii(),r=QA();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 ll.error(l.data.message,{description:l.data.fix});ll("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))].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 nu=L(G(),1),Yz=({...t})=>(0,nu.jsx)(XA,{theme:"light",className:"toaster group",icons:{success:(0,nu.jsx)(Ho,{className:"size-4"}),info:(0,nu.jsx)(Cd,{className:"size-4"}),warning:(0,nu.jsx)(Wo,{className:"size-4"}),error:(0,nu.jsx)(Yo,{className:"size-4"}),loading:(0,nu.jsx)(Go,{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 Ge=L(G(),1),$W=[["repo","Repo Charter"],["vendor","Vendor"],["test","Test"]],XC="rounded-2xl border bg-background px-[22px] py-5";function BW(){let[t,e]=(0,Zh.useState)("repo"),[a,r]=(0,Zh.useState)(null),{open:n}=fo();return(0,Ge.jsxs)(Ge.Fragment,{children:[(0,Ge.jsxs)("header",{className:"sticky top-0 z-20 flex h-14 items-center gap-3 border-b bg-background px-[26px]",children:[(0,Ge.jsxs)("span",{className:"flex items-center gap-[9px] text-[13.5px] font-bold tracking-[-0.01em]",children:[(0,Ge.jsx)("img",{src:"./logo.png",alt:"",className:"size-[22px] object-contain"}),"Cherry Works"]}),(0,Ge.jsx)("span",{className:"font-mono text-[11.5px] text-zinc-400"}),(0,Ge.jsx)("div",{className:"ml-auto flex w-full max-w-[460px]",children:(0,Ge.jsx)(jz,{onPick:({data:{identity:i,kind:o,layerName:s}})=>{e(s==="vendor"?"vendor":"repo"),r(o),n("primitive",{identity:i})}})}),(0,Ge.jsx)(Ae,{variant:"outline",onClick:()=>n("buildPreview",{}),children:"Build"}),(0,Ge.jsx)(Ae,{variant:"outline",onClick:()=>n("doctor",{}),children:"Doctor"})]}),(0,Ge.jsx)("main",{className:"mx-auto max-w-[1120px] px-[26px] pt-[22px] pb-[60px]",children:(0,Ge.jsxs)(l0,{value:t,onValueChange:i=>{e(i),r(null)},children:[(0,Ge.jsx)(u0,{className:"mb-4 h-auto w-full gap-1 rounded-[11px] bg-[#e9e9ec] p-1",children:$W.map(([i,o])=>(0,Ge.jsx)(_h,{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,Ge.jsx)(Jl,{value:"repo",className:XC,children:(0,Ge.jsx)(MC,{layerNames:["repo","builtin"],kind:a,onKindChange:r})}),(0,Ge.jsxs)(Jl,{value:"vendor",className:`${XC} grid items-start gap-4 md:has-[>section]:grid-cols-[210px_minmax(0,1fr)]`,children:[(0,Ge.jsx)(Gz,{}),(0,Ge.jsx)(MC,{layerNames:["vendor"],kind:a,onKindChange:r})]}),(0,Ge.jsx)(Jl,{value:"test",className:XC,children:(0,Ge.jsx)(Hz,{})})]})}),(0,Ge.jsx)(Yz,{})]})}var _W=new Db;(0,Wz.createRoot)(document.getElementById("root")).render((0,Ge.jsx)(Zh.StrictMode,{children:(0,Ge.jsx)(Cb,{client:_W,children:(0,Ge.jsx)(Sz,{children:(0,Ge.jsx)(BW,{})})})}));
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.3.0",
3
+ "version": "0.4.0",
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",