@rainmanhhh/pi-web 0.11.1 → 0.11.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (83) hide show
  1. package/dist/server.mjs +1 -1
  2. package/dist/static/assets/{CodeMirrorEditor-enK68VuA.js → CodeMirrorEditor-D3sEScCY.js} +1 -1
  3. package/dist/static/assets/architecture-YZFGNWBL-DAqKsYal.js +1 -0
  4. package/dist/static/assets/{architectureDiagram-Q4EWVU46-Bf-negXI.js → architectureDiagram-Q4EWVU46-B4YEh94Y.js} +1 -1
  5. package/dist/static/assets/{blockDiagram-DXYQGD6D-DZLStv5o.js → blockDiagram-DXYQGD6D-B8qeHh9A.js} +1 -1
  6. package/dist/static/assets/{c4Diagram-AHTNJAMY-CT2kyWZH.js → c4Diagram-AHTNJAMY-BjC5ngQ8.js} +1 -1
  7. package/dist/static/assets/channel-D05UYX5c.js +1 -0
  8. package/dist/static/assets/{chunk-4TB4RGXK-CQ3_2Vz3.js → chunk-4TB4RGXK-CyR9c2s8.js} +1 -1
  9. package/dist/static/assets/{chunk-5FUZZQ4R-DVDsXKCo.js → chunk-5FUZZQ4R-BXaU8Fe8.js} +1 -1
  10. package/dist/static/assets/{chunk-5PVQY5BW-DV5dqGst.js → chunk-5PVQY5BW-BgvsrI4W.js} +1 -1
  11. package/dist/static/assets/{chunk-EDXVE4YY-DRiVYUjr.js → chunk-EDXVE4YY-BE2vtEaV.js} +1 -1
  12. package/dist/static/assets/{chunk-ENJZ2VHE-Bf5DGfjB.js → chunk-ENJZ2VHE-EM0mdCTz.js} +1 -1
  13. package/dist/static/assets/{chunk-ICPOFSXX-B9DZTbkf.js → chunk-ICPOFSXX-4jzvXWCQ.js} +1 -1
  14. package/dist/static/assets/{chunk-K5T4RW27-De_MOD34.js → chunk-K5T4RW27-BZGfe2N3.js} +1 -1
  15. package/dist/static/assets/{chunk-OYMX7WX6-DGYkvqBZ.js → chunk-OYMX7WX6-BFxH5fKn.js} +1 -1
  16. package/dist/static/assets/{chunk-U2HBQHQK-KDX6hjoY.js → chunk-U2HBQHQK-B4XFChWM.js} +1 -1
  17. package/dist/static/assets/{chunk-X2U36JSP-BOUAGb99.js → chunk-X2U36JSP-BILcDhez.js} +1 -1
  18. package/dist/static/assets/{chunk-YZCP3GAM-PiIqqLxZ.js → chunk-YZCP3GAM-DEKOTV5c.js} +1 -1
  19. package/dist/static/assets/{chunk-ZZ45TVLE-cysaMLUG.js → chunk-ZZ45TVLE-DqGj-MH6.js} +1 -1
  20. package/dist/static/assets/classDiagram-6PBFFD2Q-CdLqFhh8.js +1 -0
  21. package/dist/static/assets/classDiagram-v2-HSJHXN6E-CdLqFhh8.js +1 -0
  22. package/dist/static/assets/clone-DXOJGiSl.js +1 -0
  23. package/dist/static/assets/{dagre-CHwoVw3H.js → dagre-COiaTyYd.js} +1 -1
  24. package/dist/static/assets/{dagre-KV5264BT-B7vQgFmO.js → dagre-KV5264BT-C4_Q4cS8.js} +1 -1
  25. package/dist/static/assets/{diagram-5BDNPKRD-240pKB_4.js → diagram-5BDNPKRD-B21bxv4z.js} +1 -1
  26. package/dist/static/assets/{diagram-G4DWMVQ6-BWKHm0Gz.js → diagram-G4DWMVQ6-BwdKIIqc.js} +1 -1
  27. package/dist/static/assets/{diagram-MMDJMWI5-B4hfONPM.js → diagram-MMDJMWI5-CX8rBSlF.js} +1 -1
  28. package/dist/static/assets/{diagram-TYMM5635-BWHrukgQ.js → diagram-TYMM5635-Doit3S2F.js} +1 -1
  29. package/dist/static/assets/{erDiagram-SMLLAGMA-CiicWkOt.js → erDiagram-SMLLAGMA-BTwL3zsD.js} +1 -1
  30. package/dist/static/assets/{flatten-C57dHuKJ.js → flatten-CAitJeC-.js} +1 -1
  31. package/dist/static/assets/{flowDiagram-DWJPFMVM-C1JZU05R.js → flowDiagram-DWJPFMVM-DNa2xkfA.js} +1 -1
  32. package/dist/static/assets/{ganttDiagram-T4ZO3ILL-CQT_vWKU.js → ganttDiagram-T4ZO3ILL-BmAaNfVF.js} +1 -1
  33. package/dist/static/assets/gitGraph-7Q5UKJZL-C5YzUhFm.js +1 -0
  34. package/dist/static/assets/{gitGraphDiagram-UUTBAWPF-BSPb-EbU.js → gitGraphDiagram-UUTBAWPF-DlZgNse9.js} +1 -1
  35. package/dist/static/assets/{graphlib-DF4uDOZk.js → graphlib-x5i5LesA.js} +1 -1
  36. package/dist/static/assets/{highlighted-body-OFNGDK62-C0jUCt_M.js → highlighted-body-OFNGDK62-Dxqk82uK.js} +1 -1
  37. package/dist/static/assets/{index-WaWNavWH.js → index-BVb1AG6p.js} +7 -7
  38. package/dist/static/assets/{index-3NV8dq-a.css → index-C07NoAh_.css} +1 -1
  39. package/dist/static/assets/info-OMHHGYJF-CYcMs4S-.js +1 -0
  40. package/dist/static/assets/{infoDiagram-42DDH7IO-CMNG3_eL.js → infoDiagram-42DDH7IO-BVohDmOX.js} +1 -1
  41. package/dist/static/assets/{ishikawaDiagram-UXIWVN3A-DbD7i6Ct.js → ishikawaDiagram-UXIWVN3A-BzSmscWX.js} +1 -1
  42. package/dist/static/assets/{journeyDiagram-VCZTEJTY-DOridHw2.js → journeyDiagram-VCZTEJTY-DANQeDkx.js} +1 -1
  43. package/dist/static/assets/{kanban-definition-6JOO6SKY-Zebheh_K.js → kanban-definition-6JOO6SKY-kxmvd_Zh.js} +1 -1
  44. package/dist/static/assets/{line-Dm8olauw.js → line-BMA0V_Vz.js} +1 -1
  45. package/dist/static/assets/mermaid-GHXKKRXX-vAoExaD2.js +1 -0
  46. package/dist/static/assets/{mermaid-parser.core-xEXDlRWe.js → mermaid-parser.core-CVGOr4EN.js} +2 -2
  47. package/dist/static/assets/{mermaid.core-7W9L1Y7M.js → mermaid.core-BUzSYTs3.js} +4 -4
  48. package/dist/static/assets/{mindmap-definition-QFDTVHPH-B-xGT-HL.js → mindmap-definition-QFDTVHPH-BsqEHHAZ.js} +1 -1
  49. package/dist/static/assets/packet-4T2RLAQJ-DxnUPhtz.js +1 -0
  50. package/dist/static/assets/pie-ZZUOXDRM-QAnFn_Sw.js +1 -0
  51. package/dist/static/assets/{pieDiagram-DEJITSTG-BEfNRC7x.js → pieDiagram-DEJITSTG-8jNyfJm_.js} +1 -1
  52. package/dist/static/assets/{quadrantDiagram-34T5L4WZ-JMiljc7b.js → quadrantDiagram-34T5L4WZ-DY9kIsSh.js} +1 -1
  53. package/dist/static/assets/radar-PYXPWWZC-yQkMbyxi.js +1 -0
  54. package/dist/static/assets/{reduce-o-e85cGy.js → reduce-Drz2Xbw7.js} +1 -1
  55. package/dist/static/assets/{requirementDiagram-MS252O5E-CDqTs_8O.js → requirementDiagram-MS252O5E-DfYW1xSz.js} +1 -1
  56. package/dist/static/assets/{sankeyDiagram-XADWPNL6-2ImEgJkc.js → sankeyDiagram-XADWPNL6-CU-b2MqD.js} +1 -1
  57. package/dist/static/assets/{sequenceDiagram-FGHM5R23-DrtsEVwQ.js → sequenceDiagram-FGHM5R23-COxemxUB.js} +1 -1
  58. package/dist/static/assets/{stateDiagram-FHFEXIEX-CNunwJsK.js → stateDiagram-FHFEXIEX-DZS1Bj9U.js} +1 -1
  59. package/dist/static/assets/stateDiagram-v2-QKLJ7IA2-Nc54mDSt.js +1 -0
  60. package/dist/static/assets/{timeline-definition-GMOUNBTQ-C2poQkr-.js → timeline-definition-GMOUNBTQ-vKIr-FT-.js} +1 -1
  61. package/dist/static/assets/treeView-SZITEDCU-CcBNjQsM.js +1 -0
  62. package/dist/static/assets/treemap-W4RFUUIX-ClvYvu0R.js +1 -0
  63. package/dist/static/assets/{vennDiagram-DHZGUBPP-C7m_URij.js → vennDiagram-DHZGUBPP-CTjYPPuX.js} +1 -1
  64. package/dist/static/assets/wardley-RL74JXVD-DgiLZOcg.js +1 -0
  65. package/dist/static/assets/{wardleyDiagram-NUSXRM2D-qX7ITjRO.js → wardleyDiagram-NUSXRM2D-DObzy-4f.js} +1 -1
  66. package/dist/static/assets/{xychartDiagram-5P7HB3ND-CihcUgxm.js → xychartDiagram-5P7HB3ND-DUPIMESi.js} +1 -1
  67. package/dist/static/index.html +2 -2
  68. package/package.json +1 -1
  69. package/dist/static/assets/architecture-YZFGNWBL-2xj13NxB.js +0 -1
  70. package/dist/static/assets/channel-DVWcvR-4.js +0 -1
  71. package/dist/static/assets/classDiagram-6PBFFD2Q-CowlYm-Z.js +0 -1
  72. package/dist/static/assets/classDiagram-v2-HSJHXN6E-CowlYm-Z.js +0 -1
  73. package/dist/static/assets/clone-oLICz3HX.js +0 -1
  74. package/dist/static/assets/gitGraph-7Q5UKJZL-DUbNkr6r.js +0 -1
  75. package/dist/static/assets/info-OMHHGYJF-B5EcoKr2.js +0 -1
  76. package/dist/static/assets/mermaid-GHXKKRXX-CCuppwni.js +0 -1
  77. package/dist/static/assets/packet-4T2RLAQJ-CpjNSj51.js +0 -1
  78. package/dist/static/assets/pie-ZZUOXDRM-Bts2OhIO.js +0 -1
  79. package/dist/static/assets/radar-PYXPWWZC-Dh13Ne6g.js +0 -1
  80. package/dist/static/assets/stateDiagram-v2-QKLJ7IA2-BKjTYSb3.js +0 -1
  81. package/dist/static/assets/treeView-SZITEDCU-DKcDfsfa.js +0 -1
  82. package/dist/static/assets/treemap-W4RFUUIX-Cy9QgWRe.js +0 -1
  83. package/dist/static/assets/wardley-RL74JXVD-NFEz2vtl.js +0 -1
package/dist/server.mjs CHANGED
@@ -249,7 +249,7 @@ Expecting one of '${n.join("', '")}'`);if(this._lifeCycleHooks[e])this._lifeCycl
249
249
  `),this.outputHelp({error:!0});let n=t||{},r=n.exitCode||1,i=n.code||"commander.error";this._exit(r,i,e)}_parseOptionsEnv(){this.options.forEach((e)=>{if(e.envVar&&e.envVar in le.env){let t=e.attributeName();if(this.getOptionValue(t)===void 0||["default","config","env"].includes(this.getOptionValueSource(t)))if(e.required||e.optional)this.emit(`optionEnv:${e.name()}`,le.env[e.envVar]);else this.emit(`optionEnv:${e.name()}`)}})}_parseOptionsImplied(){let e=new id(this.options),t=(n)=>this.getOptionValue(n)!==void 0&&!["default","implied"].includes(this.getOptionValueSource(n));this.options.filter((n)=>n.implied!==void 0&&t(n.attributeName())&&e.valueFromOption(this.getOptionValue(n.attributeName()),n)).forEach((n)=>{Object.keys(n.implied).filter((r)=>!t(r)).forEach((r)=>{this.setOptionValueWithSource(r,n.implied[r],"implied")})})}missingArgument(e){let t=`error: missing required argument '${e}'`;this.error(t,{code:"commander.missingArgument"})}optionMissingArgument(e){let t=`error: option '${e.flags}' argument missing`;this.error(t,{code:"commander.optionMissingArgument"})}missingMandatoryOptionValue(e){let t=`error: required option '${e.flags}' not specified`;this.error(t,{code:"commander.missingMandatoryOptionValue"})}_conflictingOption(e,t){let n=(o)=>{let a=o.attributeName(),s=this.getOptionValue(a),u=this.options.find((d)=>d.negate&&a===d.attributeName()),c=this.options.find((d)=>!d.negate&&a===d.attributeName());if(u&&(u.presetArg===void 0&&s===!1||u.presetArg!==void 0&&s===u.presetArg))return u;return c||o},r=(o)=>{let a=n(o),s=a.attributeName();if(this.getOptionValueSource(s)==="env")return`environment variable '${a.envVar}'`;return`option '${a.flags}'`},i=`error: ${r(e)} cannot be used with ${r(t)}`;this.error(i,{code:"commander.conflictingOption"})}unknownOption(e){if(this._allowUnknownOption)return;let t="";if(e.startsWith("--")&&this._showSuggestionAfterError){let r=[],i=this;do{let o=i.createHelp().visibleOptions(i).filter((a)=>a.long).map((a)=>a.long);r=r.concat(o),i=i.parent}while(i&&!i._enablePositionalOptions);t=od(e,r)}let n=`error: unknown option '${e}'${t}`;this.error(n,{code:"commander.unknownOption"})}_excessArguments(e){if(this._allowExcessArguments)return;let t=this.registeredArguments.length,n=t===1?"":"s",r=e.length,i=this.parent?` for '${this.name()}'`:"",o=e.join(", "),a=`error: too many arguments${i}. Expected ${t} argument${n} but got ${r}: ${o}.`;this.error(a,{code:"commander.excessArguments"})}unknownCommand(){let e=this.args[0],t="";if(this._showSuggestionAfterError){let r=[];this.createHelp().visibleCommands(this).forEach((i)=>{if(r.push(i.name()),i.alias())r.push(i.alias())}),t=od(e,r)}let n=`error: unknown command '${e}'${t}`;this.error(n,{code:"commander.unknownCommand"})}version(e,t,n){if(e===void 0)return this._version;this._version=e,t=t||"-V, --version",n=n||"output the version number";let r=this.createOption(t,n);return this._versionOptionName=r.attributeName(),this._registerOption(r),this.on("option:"+r.name(),()=>{this._outputConfiguration.writeOut(`${e}
250
250
  `),this._exit(0,"commander.version",e)}),this}description(e,t){if(e===void 0&&t===void 0)return this._description;if(this._description=e,t)this._argsDescription=t;return this}summary(e){if(e===void 0)return this._summary;return this._summary=e,this}alias(e){if(e===void 0)return this._aliases[0];let t=this;if(this.commands.length!==0&&this.commands[this.commands.length-1]._executableHandler)t=this.commands[this.commands.length-1];if(e===t._name)throw Error("Command alias can't be the same as its name");let n=this.parent?._findCommand(e);if(n){let r=[n.name()].concat(n.aliases()).join("|");throw Error(`cannot add alias '${e}' to command '${this.name()}' as already have command '${r}'`)}return t._aliases.push(e),this}aliases(e){if(e===void 0)return this._aliases;return e.forEach((t)=>this.alias(t)),this}usage(e){if(e===void 0){if(this._usage)return this._usage;let t=this.registeredArguments.map((n)=>Bs(n));return[].concat(this.options.length||this._helpOption!==null?"[options]":[],this.commands.length?"[command]":[],this.registeredArguments.length?t:[]).join(" ")}return this._usage=e,this}name(e){if(e===void 0)return this._name;return this._name=e,this}helpGroup(e){if(e===void 0)return this._helpGroupHeading??"";return this._helpGroupHeading=e,this}commandsGroup(e){if(e===void 0)return this._defaultCommandGroup??"";return this._defaultCommandGroup=e,this}optionsGroup(e){if(e===void 0)return this._defaultOptionGroup??"";return this._defaultOptionGroup=e,this}_initOptionGroup(e){if(this._defaultOptionGroup&&!e.helpGroupHeading)e.helpGroup(this._defaultOptionGroup)}_initCommandGroup(e){if(this._defaultCommandGroup&&!e.helpGroup())e.helpGroup(this._defaultCommandGroup)}nameFromFilename(e){return this._name=En.basename(e,En.extname(e)),this}executableDir(e){if(e===void 0)return this._executableDir;return this._executableDir=e,this}helpInformation(e){let t=this.createHelp(),n=this._getOutputContext(e);t.prepareContext({error:n.error,helpWidth:n.helpWidth,outputHasColors:n.hasColors});let r=t.formatHelp(this,t);if(n.hasColors)return r;return this._outputConfiguration.stripColor(r)}_getOutputContext(e){e=e||{};let t=!!e.error,n,r,i;if(t)n=(a)=>this._outputConfiguration.writeErr(a),r=this._outputConfiguration.getErrHasColors(),i=this._outputConfiguration.getErrHelpWidth();else n=(a)=>this._outputConfiguration.writeOut(a),r=this._outputConfiguration.getOutHasColors(),i=this._outputConfiguration.getOutHelpWidth();return{error:t,write:(a)=>{if(!r)a=this._outputConfiguration.stripColor(a);return n(a)},hasColors:r,helpWidth:i}}outputHelp(e){let t;if(typeof e==="function")t=e,e=void 0;let n=this._getOutputContext(e),r={error:n.error,write:n.write,command:this};this._getCommandAndAncestors().reverse().forEach((o)=>o.emit("beforeAllHelp",r)),this.emit("beforeHelp",r);let i=this.helpInformation({error:n.error});if(t){if(i=t(i),typeof i!=="string"&&!Buffer.isBuffer(i))throw Error("outputHelp callback must return a string or a Buffer")}if(n.write(i),this._getHelpOption()?.long)this.emit(this._getHelpOption().long);this.emit("afterHelp",r),this._getCommandAndAncestors().forEach((o)=>o.emit("afterAllHelp",r))}helpOption(e,t){if(typeof e==="boolean"){if(e){if(this._helpOption===null)this._helpOption=void 0;if(this._defaultOptionGroup)this._initOptionGroup(this._getHelpOption())}else this._helpOption=null;return this}if(this._helpOption=this.createOption(e??"-h, --help",t??"display help for command"),e||t)this._initOptionGroup(this._helpOption);return this}_getHelpOption(){if(this._helpOption===void 0)this.helpOption(void 0,void 0);return this._helpOption}addHelpOption(e){return this._helpOption=e,this._initOptionGroup(e),this}help(e){this.outputHelp(e);let t=Number(le.exitCode??0);if(t===0&&e&&typeof e!=="function"&&e.error)t=1;this._exit(t,"commander.help","(outputHelp)")}addHelpText(e,t){let n=["beforeAll","before","after","afterAll"];if(!n.includes(e))throw Error(`Unexpected value for position to addHelpText.
251
251
  Expecting one of '${n.join("', '")}'`);let r=`${e}Help`;return this.on(r,(i)=>{let o;if(typeof t==="function")o=t({error:i.error,command:i.command});else o=t;if(o)i.write(`${o}
252
- `)}),this}_outputHelpIfRequested(e){let t=this._getHelpOption();if(t&&e.find((r)=>t.is(r)))this.outputHelp(),this._exit(0,"commander.helpDisplayed","(outputHelp)")}}function tb(e){return e.map((t)=>{if(!t.startsWith("--inspect"))return t;let n,r="127.0.0.1",i="9229",o;if((o=t.match(/^(--inspect(-brk)?)$/))!==null)n=o[1];else if((o=t.match(/^(--inspect(-brk|-port)?)=([^:]+)$/))!==null)if(n=o[1],/^\d+$/.test(o[3]))i=o[3];else r=o[3];else if((o=t.match(/^(--inspect(-brk|-port)?)=([^:]+):(\d+)$/))!==null)n=o[1],r=o[3],i=o[4];if(n&&i!=="0")return`${n}=${r}:${parseInt(i)+1}`;return t})}function nb(){if(le.env.NO_COLOR||le.env.FORCE_COLOR==="0"||le.env.FORCE_COLOR==="false")return!1;if(le.env.FORCE_COLOR||le.env.CLICOLOR_FORCE!==void 0)return!0;return}var Fee=new gi;var rb={name:"@rainmanhhh/pi-web",version:"0.11.1",description:"Web UI for the pi coding agent (fork of @agegr/pi-web)",homepage:"https://gitee.com/dsxbygzzl/pi-web#readme",repository:{type:"git",url:"git+https://gitee.com/dsxbygzzl/pi-web.git"},bugs:{url:"https://gitee.com/dsxbygzzl/pi-web/issues"},author:"rainmanhhh",license:"MIT",publishConfig:{access:"public",registry:"https://registry.npmjs.org"},engines:{node:">=22.19.0"},files:["dist","public","extensions","package.json"],bin:{"pi-web":"dist/server.mjs"},scripts:{dev:"vite","dev:lan":"vite --host 0.0.0.0",mb:"bun run --env-file=.env.manual api",mf:"bun run --env-file=.env.manual dev -- --port 3001",api:"bun run server/main.ts","api:node":"bun run build:server && node dist/server.mjs","build:server":'bun build server/main.ts --target node --outfile dist/server.mjs --minify --external "@earendil-works/*" --define "process.env.PI_WEB_PACKAGED=1"',"e2e:stop":"bun run scripts/e2e-stop.mjs",build:"vite build && bun run scripts/prune-fonts.mjs","build:analyze":"vite build --config scripts/analyze-bundle.config.ts && bun run scripts/prune-fonts.mjs",lint:"oxlint --fix",jscpd:"jscpd --config .jscpd.json",check:"tsc --noEmit",format:"biome check --write .",prepublishOnly:"bun run check && bun run build && bun run build:server","test:e2e":"playwright test","test:unit":"vitest run",prepare:"husky || true"},dependencies:{"@codemirror/commands":"^6.11.0","@codemirror/lang-css":"^6.3.1","@codemirror/lang-html":"^6.4.12","@codemirror/lang-javascript":"^6.2.5","@codemirror/lang-json":"^6.0.2","@codemirror/lang-markdown":"^6.5.2","@codemirror/lang-yaml":"^6.1.3","@codemirror/language":"^6.12.4","@codemirror/state":"^6.7.1","@codemirror/theme-one-dark":"^6.1.3","@codemirror/view":"^6.43.9","@earendil-works/pi-agent-core":"0.84.2","@earendil-works/pi-ai":"0.84.2","@earendil-works/pi-coding-agent":"0.84.2","@earendil-works/pi-tui":"0.84.2","@hono/node-server":"^2.1.0","class-variance-authority":"^0.7.1",clsx:"^2.1.1",codemirror:"^6.0.2",hono:"^4.13.1","lucide-react":"^1.31.0",pointrix:"^1.1.0","proper-lockfile":"4.1.2","radix-ui":"^1.6.7",react:"^19.2.4","react-dom":"^19.2.4",shadcn:"^4.17.0",streamdown:"2.5.0","tailwind-merge":"^3.6.0","tw-animate-css":"^1.4.0",undici:"8.9.0"},devDependencies:{"@lobehub/icons":"^5.6.0","@playwright/test":"^1.62.1","@tailwindcss/postcss":"^4.2.2","@testing-library/dom":"^10.4.1","@testing-library/react":"^16.3.2","@types/node":"^25","@types/proper-lockfile":"4.1.4","@types/react":"^19","@types/react-dom":"^19","@types/react-resizable":"^4.0.0","@types/react-syntax-highlighter":"^15.5.13","@vitejs/plugin-react":"^6.0.5",biome:"^0.3.3",commander:"^15.0.0",husky:"^9.1.7",jiti:"^2.7.0",jscpd:"^5.0.14",jsdom:"^30.0.1",katex:"^0.16.47","lint-staged":"^17.3.0",mammoth:"^1.12.0",mermaid:"^11.14.0",oxlint:"^1.78.0",postcss:"^8","react-markdown":"^10.1.0","react-syntax-highlighter":"^16.1.1","rehype-katex":"^7.0.1","rehype-raw":"^7.0.0","rehype-sanitize":"^6.0.0","remark-gfm":"^4.0.1","remark-math":"^6.0.0",tailwindcss:"^4.2.2",typescript:"^7.0.2",vite:"^8.2.1","vite-plugin-svgr":"^5.2.0",vitest:"^4.1.10"},type:"module"};import{getAgentDir as x3}from"@earendil-works/pi-coding-agent";var ib={port:31415};var sd=(e,t,n)=>(r,i)=>{let o=-1;return a(0);async function a(s){if(s<=o)throw Error("next() called multiple times");o=s;let u,c=!1,d;if(e[s])d=e[s][0][0],r.req.routeIndex=s;else d=s===e.length&&i||void 0;if(d)try{u=await d(r,()=>a(s+1))}catch(f){if(f instanceof Error&&t)r.error=f,u=await t(f,r),c=!0;else throw f}else if(r.finalized===!1&&n)u=await n(r);if(u&&(r.finalized===!1||c))r.res=u;return r}};var ob=Symbol();var ab=(e,t)=>new Response(e,{headers:{"Content-Type":t.replace(/^[^;]+/,(r)=>r.toLowerCase())}}).formData();var Ws=(e)=>("headers"in e),cb=async(e,t=Object.create(null))=>{let{all:n=!1,dot:r=!1}=t,a=(Ws(e)?e.headers:e.raw.headers).get("Content-Type")?.split(";")[0].trim().toLowerCase();if(a==="multipart/form-data"||a==="application/x-www-form-urlencoded")return UF(e,{all:n,dot:r});return{}};async function UF(e,t){if(!Ws(e)&&e.bodyCache.formData)return sb(await e.bodyCache.formData,t);let n=Ws(e)?e.headers:e.raw.headers,r=await e.arrayBuffer(),i=ab(r,n.get("Content-Type")||"");if(!Ws(e))e.bodyCache.formData=i;let o=await i;if(o)return sb(o,t);return{}}function sb(e,t){let n=Object.create(null);if(e.forEach((r,i)=>{if(!(t.all||i.endsWith("[]")))n[i]=r;else AF(n,i,r)}),t.dot)Object.entries(n).forEach(([r,i])=>{if(r.includes("."))CF(n,r,i),delete n[r]});return n}var AF=(e,t,n)=>{if(e[t]!==void 0)if(Array.isArray(e[t]))e[t].push(n);else e[t]=[e[t],n];else if(!t.endsWith("[]"))e[t]=n;else e[t]=[n]},CF=(e,t,n)=>{if(/(?:^|\.)__proto__\./.test(t))return;let r=e,i=t.split(".");i.forEach((o,a)=>{if(a===i.length-1)r[o]=n;else{if(!r[o]||typeof r[o]!=="object"||Array.isArray(r[o])||r[o]instanceof File)r[o]=Object.create(null);r=r[o]}})};var ud=(e)=>{let t=e.split("/");if(t[0]==="")t.shift();return t},ub=(e)=>{let{groups:t,path:n}=kF(e),r=ud(n);return FF(r,t)},kF=(e)=>{let t=[];return e=e.replace(/\{[^}]+\}/g,(n,r)=>{let i=`@${r}`;return t.push([i,n]),i}),{groups:t,path:e}},FF=(e,t)=>{for(let n=t.length-1;n>=0;n--){let[r]=t[n];for(let i=e.length-1;i>=0;i--)if(e[i].includes(r)){e[i]=e[i].replace(r,t[n][1]);break}}return e},Ls={},lb=(e,t)=>{if(e==="*")return"*";let n=e.match(/^\:([^\{\}]+)(?:\{(.+)\})?$/);if(n){let r=`${e}#${t}`;if(!Ls[r])if(n[2])Ls[r]=t&&t[0]!==":"&&t[0]!=="*"?[r,n[1],new RegExp(`^${n[2]}(?=/${t})`)]:[e,n[1],new RegExp(`^${n[2]}$`)];else Ls[r]=[e,n[1],!0];return Ls[r]}return null},db=(e,t)=>{try{return t(e)}catch{return e.replace(/(?:%[0-9A-Fa-f]{2})+/g,(n)=>{try{return t(n)}catch{return n}})}},RF=(e)=>db(e,decodeURI),ld=(e)=>{let t=e.url,n=t.indexOf("/",t.indexOf(":")+4),r=n;for(;r<t.length;r++){let i=t.charCodeAt(r);if(i===37){let o=t.indexOf("?",r),a=t.indexOf("#",r),s=o===-1?a===-1?void 0:a:a===-1?o:Math.min(o,a),u=t.slice(n,s);return RF(u.includes("%25")?u.replace(/%25/g,"%2525"):u)}else if(i===63||i===35)break}return t.slice(n,r)};var fb=(e)=>{let t=ld(e);return t.length>1&&t.at(-1)==="/"?t.slice(0,-1):t},Gn=(e,t,...n)=>{if(n.length)t=Gn(t,...n);return`${e?.[0]==="/"?"":"/"}${e}${t==="/"?"":`${e?.at(-1)==="/"?"":"/"}${t?.[0]==="/"?t.slice(1):t}`}`},js=(e)=>{if(e.charCodeAt(e.length-1)!==63||!e.includes(":"))return null;let t=e.split("/"),n=[],r="";return t.forEach((i)=>{if(i!==""&&!/\:/.test(i))r+="/"+i;else if(/\:/.test(i))if(/\?/.test(i)){if(n.length===0&&r==="")n.push("/");else n.push(r);let o=i.replace("?","");r+="/"+o,n.push(r)}else r+="/"+i}),n.filter((i,o,a)=>a.indexOf(i)===o)},qs=(e)=>e.indexOf("%")!==-1?db(e,OF):e,cd=(e)=>{if(e.indexOf("+")!==-1)e=e.replace(/\+/g," ");return qs(e)},hb=(e,t,n)=>{let r;if(!n&&t&&t.indexOf("%")===-1&&t.indexOf("+")===-1){let a=e.indexOf("?",8);if(a===-1)return;if(!e.startsWith(t,a+1))a=e.indexOf(`&${t}`,a+1);while(a!==-1){let s=e.charCodeAt(a+t.length+1);if(s===61){let u=a+t.length+2,c=e.indexOf("&",u);return cd(e.slice(u,c===-1?void 0:c))}else if(s==38||isNaN(s))return"";a=e.indexOf(`&${t}`,a+1)}if(r=/[%+]/.test(e),!r)return}let i=Object.create(null);r??=/[%+]/.test(e);let o=e.indexOf("?",8);while(o!==-1){let a=e.indexOf("&",o+1),s=e.indexOf("=",o);if(s>a&&a!==-1)s=-1;let u=e.slice(o+1,s===-1?a===-1?void 0:a:s);if(r)u=cd(u);if(o=a,u==="")continue;let c;if(s===-1)c="";else if(c=e.slice(s+1,a===-1?void 0:a),r)c=cd(c);if(n){if(!(i[u]&&Array.isArray(i[u])))i[u]=[];i[u].push(c)}else i[u]??=c}return t?i[t]:i},pb=hb,gb=(e,t)=>hb(e,t,!0),OF=decodeURIComponent;var mb=class{raw;#e;#t;routeIndex=0;path;bodyCache={};constructor(e,t="/",n=[[]]){this.raw=e,this.path=t,this.#t=n}param(e){return e?this.#n(e):this.#o()}#n(e){let t=this.#t[0][this.routeIndex][1][e],n=this.#r(t);return n&&qs(n)}#o(){let e={},t=Object.keys(this.#t[0][this.routeIndex][1]);for(let n of t){let r=this.#r(this.#t[0][this.routeIndex][1][n]);if(r!==void 0)e[n]=qs(r)}return e}#r(e){return this.#t[1]?this.#t[1][e]:e}query(e){return pb(this.url,e)}queries(e){return gb(this.url,e)}header(e){if(e)return this.raw.headers.get(e)??void 0;let t=Object.create(null);return this.raw.headers.forEach((n,r)=>{t[r]=n}),t}async parseBody(e){return cb(this,e)}#i=(e)=>{let{bodyCache:t,raw:n}=this,r=t[e];if(r)return r;for(let i in t)return t[i].then((o)=>{if(i==="json")o=JSON.stringify(o);return new Response(o)[e]()});return t[e]=n[e]()};json(){return this.#i("text").then((e)=>JSON.parse(e))}text(){return this.#i("text")}arrayBuffer(){return this.#i("arrayBuffer")}bytes(){return this.#i("arrayBuffer").then((e)=>new Uint8Array(e))}blob(){return this.#i("blob")}formData(){return this.#i("formData")}addValidatedData(e,t){(this.#e??={})[e]=t}valid(e){return this.#e?.[e]}get url(){return this.raw.url}get method(){return this.raw.method}get[ob](){return this.#t}get matchedRoutes(){return this.#t[0].map(([[,e]])=>e)}get routePath(){return this.#t[0].map(([[,e]])=>e)[this.routeIndex].path}};var yb={Stringify:1,BeforeStream:2,Stream:3},IF=(e,t)=>{let n=new String(e);return n.isEscaped=!0,n.callbacks=t,n};var dd=async(e,t,n,r,i)=>{if(typeof e==="object"&&!(e instanceof String)){if(!(e instanceof Promise))e=e.toString();if(e instanceof Promise)e=await e}let o=e.callbacks;if(!o?.length)return Promise.resolve(e);if(i)i[0]+=e;else i=[e];let a=Promise.all(o.map((s)=>s({phase:t,buffer:i,context:r}))).then((s)=>Promise.all(s.filter(Boolean).map((u)=>dd(u,t,!1,r,i))).then(()=>i[0]));if(n)return IF(await a,o);else return a};var PF="text/plain; charset=UTF-8",fd=(e,t)=>({"Content-Type":e,...t}),Mo=(e,t)=>new Response(e,t),hd=class{#e;#t;env={};#n;finalized=!1;error;#o;#r;#i;#l;#c;#u;#s;#d;#f;constructor(e,t){if(this.#e=e,t)this.#r=t.executionCtx,this.env=t.env,this.#u=t.notFoundHandler,this.#f=t.path,this.#d=t.matchResult}get req(){return this.#t??=new mb(this.#e,this.#f,this.#d),this.#t}get event(){if(this.#r&&"respondWith"in this.#r)return this.#r;else throw Error("This context has no FetchEvent")}get executionCtx(){if(this.#r)return this.#r;else throw Error("This context has no ExecutionContext")}get res(){return this.#i||=Mo(null,{headers:this.#s??=new Headers})}set res(e){if(this.#i&&e){e=Mo(e.body,e);for(let[t,n]of this.#i.headers.entries()){if(t==="content-type")continue;if(t==="set-cookie"){let r=this.#i.headers.getSetCookie();e.headers.delete("set-cookie");for(let i of r)e.headers.append("set-cookie",i)}else e.headers.set(t,n)}}this.#i=e,this.finalized=!0}render=(...e)=>(this.#c??=(t)=>this.html(t),this.#c(...e));setLayout=(e)=>this.#l=e;getLayout=()=>this.#l;setRenderer=(e)=>{this.#c=e};header=(e,t,n)=>{if(this.finalized)this.#i=Mo(this.#i.body,this.#i);let r=this.#i?this.#i.headers:this.#s??=new Headers;if(t===void 0)r.delete(e);else if(n?.append)r.append(e,t);else r.set(e,t)};status=(e)=>{this.#o=e};set=(e,t)=>{this.#n??=new Map,this.#n.set(e,t)};get=(e)=>this.#n?this.#n.get(e):void 0;get var(){if(!this.#n)return{};return Object.fromEntries(this.#n)}#a(e,t,n){let r=this.#i?new Headers(this.#i.headers):this.#s;if(typeof t==="object"&&t.headers){r??=new Headers;for(let[o,a]of new Headers(t.headers))if(o==="set-cookie")r.append(o,a);else r.set(o,a)}if(n){if(!r){let o=0;for(let a in n)if(++o>1||typeof n[a]!=="string"){r=new Headers;break}}if(r)for(let o in n){let a=n[o];if(typeof a==="string")r.set(o,a);else{r.delete(o);for(let s of a)r.append(o,s)}}}let i=typeof t==="number"?t:t?.status??this.#o;return Mo(e,{status:i,headers:r??n})}newResponse=(...e)=>this.#a(...e);body=(e,t,n)=>this.#a(e,t,n);text=(e,t,n)=>!this.#s&&!this.#o&&!t&&!n&&!this.finalized?new Response(e):this.#a(e,t,fd(PF,n));json=(e,t,n)=>this.#a(JSON.stringify(e),t,fd("application/json",n));html=(e,t,n)=>{let r=(i)=>this.#a(i,t,fd("text/html; charset=UTF-8",n));return typeof e==="object"?dd(e,yb.Stringify,!1,{}).then(r):r(e)};redirect=(e,t)=>{let n=String(e);return this.header("Location",!/[^\x00-\xFF]/.test(n)?n:encodeURI(n)),this.newResponse(null,t??302)};notFound=()=>(this.#u??=()=>Mo(),this.#u(this))};var Be="ALL",bb="all",vb=["get","post","put","delete","options","patch","query"],Hs="Can not add a route since the matcher is already built.",$s=class extends Error{};var xb="__COMPOSED_HANDLER";var BF=(e)=>e.text("404 Not Found",404),Db=(e,t)=>{if("getResponse"in e){let n=e.getResponse();return t.newResponse(n.body,n)}return console.error(e),t.text("Internal Server Error",500)},wb=class e{get;post;put;delete;options;patch;query;all;on;use;router;getPath;_basePath="/";#e="/";routes=[];constructor(t={}){[...vb,bb].forEach((o)=>{this[o]=(a,...s)=>{if(typeof a==="string")this.#e=a;else this.#o(o,this.#e,a);return s.forEach((u)=>{this.#o(o,this.#e,u)}),this}}),this.on=(o,a,...s)=>{for(let u of[a].flat()){this.#e=u;for(let c of[o].flat())s.map((d)=>{this.#o(c.toUpperCase(),this.#e,d)})}return this},this.use=(o,...a)=>{if(typeof o==="string")this.#e=o;else this.#e="*",a.unshift(o);return a.forEach((s)=>{this.#o(Be,this.#e,s)}),this};let{strict:r,...i}=t;Object.assign(this,i),this.getPath=r??!0?t.getPath??ld:fb}#t(){let t=new e({router:this.router,getPath:this.getPath});return t.errorHandler=this.errorHandler,t.#n=this.#n,t.routes=this.routes,t}#n=BF;errorHandler=Db;route(t,n){let r=this.basePath(t);return n.routes.map((i)=>{let o;if(n.errorHandler===Db)o=i.handler;else o=async(a,s)=>(await sd([],n.errorHandler)(a,()=>i.handler(a,s))).res,o[xb]=i.handler;r.#o(i.method,i.path,o,i.basePath)}),this}basePath(t){let n=this.#t();return n._basePath=Gn(this._basePath,t),n}onError=(t)=>(this.errorHandler=t,this);notFound=(t)=>(this.#n=t,this);mount(t,n,r){let i,o;if(r)if(typeof r==="function")o=r;else if(o=r.optionHandler,r.replaceRequest===!1)i=(u)=>u;else i=r.replaceRequest;let a=o?(u)=>{let c=o(u);return Array.isArray(c)?c:[c]}:(u)=>{let c=void 0;try{c=u.executionCtx}catch{}return[u.env,c]};i||=(()=>{let u=Gn(this._basePath,t),c=u==="/"?0:u.length;return(d)=>{let f=new URL(d.url);return f.pathname=this.getPath(d).slice(c)||"/",new Request(f,d)}})();let s=async(u,c)=>{let d=await n(i(u.req.raw),...a(u));if(d)return d;await c()};return this.#o(Be,Gn(t,"*"),s),this}#o(t,n,r,i){t=t.toUpperCase(),n=Gn(this._basePath,n);let o={basePath:i!==void 0?Gn(this._basePath,i):this._basePath,path:n,method:t,handler:r};this.router.add(t,n,[r,o]),this.routes.push(o)}#r(t,n){if(t instanceof Error)return this.errorHandler(t,n);throw t}#i(t,n,r,i){if(i==="HEAD")return(async()=>new Response(null,await this.#i(t,n,r,"GET")))();let o=this.getPath(t,{env:r}),a=this.router.match(i,o),s=new hd(t,{path:o,matchResult:a,env:r,executionCtx:n,notFoundHandler:this.#n});if(a[0].length===1){let c;try{c=a[0][0][0][0](s,async()=>{s.res=await this.#n(s)})}catch(d){return this.#r(d,s)}return c instanceof Promise?c.then((d)=>d||(s.finalized?s.res:this.#n(s))).catch((d)=>this.#r(d,s)):c??this.#n(s)}let u=sd(a[0],this.errorHandler,this.#n);return(async()=>{try{let c=await u(s);if(!c.finalized)throw Error("Context is not finalized. Did you forget to return a Response object or `await next()`?");return c.res}catch(c){return this.#r(c,s)}})()}fetch=(t,...n)=>this.#i(t,n[1],n[0],t.method);request=(t,n,r,i)=>{if(t instanceof Request)return this.fetch(n?new Request(t,n):t,r,i);return t=t.toString(),this.fetch(new Request(/^https?:\/\//.test(t)?t:`http://localhost${Gn("/",t)}`,n),r,i)};fire=()=>{addEventListener("fetch",(t)=>{t.respondWith(this.#i(t.request,t,void 0,t.request.method))})}};var zs=[];function pd(e,t){let n=this.buildAllMatchers(),r=(i,o)=>{let a=n[i]||n[Be],s=a[2][o];if(s)return s;let u=o.match(a[0]);if(!u)return[[],zs];let c=u.indexOf("",1);return[a[1][c],u]};return this.match=r,r(e,t)}var Vs="[^/]+",mi=".*",Er="(?:|/.*)",Xn=Symbol(),_b=new Set(".\\+*[^]$()");function MF(e,t){if(e.length===1)return t.length===1?e<t?-1:1:-1;if(t.length===1)return 1;if(e===mi||e===Er)return t===Er?-1:1;else if(t===mi||t===Er)return-1;if(e===Vs)return 1;else if(t===Vs)return-1;return e.length===t.length?e<t?-1:1:t.length-e.length}var Tb=class e{#e;#t;#n=Object.create(null);insert(t,n,r,i,o){let a=this;for(let s=0,u=t.length;s<u;s++){let c=t[s],d=c.length===1?c==="*"?s===u-1?["","",mi]:["","",Vs]:null:c==="/*"?["","",Er]:c.match(/^\:([^\{\}]+)(?:\{(.+)\})?$/),f;if(d){let h=d[1],p=d[2]||Vs;if(h&&d[2]){if(p===".*")throw Xn;if(p=p.replace(/^\((?!\?:)(?=[^)]+\)$)/,"(?:"),/\((?!\?:)/.test(p))throw Xn;if(p.length===1&&_b.has(p))throw Xn}if(f=a.#n[p],!f){if(p!==mi&&p!==Er){for(let m in a.#n)if((p.length>1||m.length>1)&&m!==mi&&m!==Er)throw Xn}f=a.#n[p]=new e}if(h!=="")f.#t??=i.varIndex++,r.push([h,f.#t])}else if(f=a.#n[c],!f){for(let h in a.#n)if(h.length>1&&h!==mi&&h!==Er)throw Xn;f=a.#n[c]=new e}a=f}if(a.#e!==void 0)throw Xn;a.#e=o?-1:n}buildRegExpStr(){let n=Object.keys(this.#n).sort(MF).map((r)=>{let i=this.#n[r],o=i.buildRegExpStr();return o===""?"":(typeof i.#t==="number"?`(${r})@${i.#t}`:_b.has(r)?`\\${r}`:r)+o}).filter(Boolean);if(typeof this.#e==="number"&&this.#e!==-1)n.unshift(`#${this.#e}`);if(n.length===0)return"";if(n.length===1)return n[0];return"(?:"+n.join("|")+")"}};var gd=class{#e={varIndex:0};#t=new Tb;#n=0;paths=Object.create(null);insert(e,t){if(t){this.#t.insert(e.split(""),0,[],this.#e,!0);return}let n=[],r=[],i=e;for(let a=0;;){let s=!1;if(i=i.replace(/\{[^}]+\}/g,(u)=>{let c=`@\\${a}`;return r[a]=[c,u],a++,s=!0,c}),!s)break}let o=i.match(/(?::[^\/]+)|(?:\/\*$)|./g)||[];for(let a=r.length-1;a>=0;a--){let[s]=r[a];for(let u=o.length-1;u>=0;u--)if(o[u].indexOf(s)!==-1){o[u]=o[u].replace(s,r[a][1]);break}}this.#t.insert(o,this.#n,n,this.#e,!1),this.paths[e]=[this.#n++,n]}buildRegExp(){let e=this.#t.buildRegExpStr();if(e==="")return[/^$/,[],[]];let t=0,n=[],r=[];return e=e.replace(/#(\d+)|@(\d+)|\.\*\$/g,(i,o,a)=>{if(o!==void 0)return n[++t]=Number(o),"$()";if(a!==void 0)return r[Number(a)]=++t,"";return""}),[new RegExp(`^${e}`),n,r]}};var Eb=Object.create(null);function Sb(e){return Eb[e]??=new RegExp(e==="*"?"":`^${e.replace(/\/\*$|([.\\+*[^\]$()])/g,(t,n)=>n?`\\${n}`:"(?:|/.*)")}$`)}function NF(){Eb=Object.create(null)}function Gs(e,t){if(!e)return;for(let n of Object.keys(e).sort((r,i)=>i.length-r.length))if(Sb(n).test(t))return[...e[n]];return}var Xs=class{name="RegExpRouter";#e;#t;#n;constructor(){this.#e={[Be]:Object.create(null)},this.#t={[Be]:Object.create(null)},this.#n={[Be]:new gd}}#o(e,t){try{this.#n[e].insert(t,!/\*|\/:/.test(t))}catch(n){throw n===Xn?new $s(t):n}}add(e,t,n){let r=this.#e,i=this.#t;if(!r||!i)throw Error(Hs);if(!r[e])this.#n[e]=new gd,[r,i].forEach((s)=>{s[e]=Object.create(null),Object.keys(s[Be]).forEach((u)=>{s[e][u]=[...s[Be][u]],this.#o(e,u)})});if(t==="/*")t="*";let o=(t.match(/\/:/g)||[]).length;if(/\*$/.test(t)){let s=Sb(t);Object.keys(r).forEach((u)=>{if((e===Be||e===u)&&!r[u][t])this.#o(u,t),r[u][t]=Gs(r[u],t)||Gs(r[Be],t)||[]}),Object.keys(r).forEach((u)=>{if(e===Be||e===u)Object.keys(r[u]).forEach((c)=>{s.test(c)&&r[u][c].push([n,o])})}),Object.keys(i).forEach((u)=>{if(e===Be||e===u)Object.keys(i[u]).forEach((c)=>s.test(c)&&i[u][c].push([n,o]))});return}let a=js(t)||[t];for(let s=0,u=a.length;s<u;s++){let c=a[s];Object.keys(i).forEach((d)=>{if(e===Be||e===d){if(!i[d][c])this.#o(d,c),i[d][c]=[...Gs(r[d],c)||Gs(r[Be],c)||[]];i[d][c].push([n,o-u+s+1])}})}}match=pd;buildAllMatchers(){let e=Object.create(null);return Object.keys(this.#t).concat(Object.keys(this.#e)).forEach((t)=>{e[t]||=this.#r(t)}),this.#e=this.#t=this.#n=void 0,NF(),e}#r(e){let t=this.#e[e],n=this.#t[e],r=this.#n[e],i=Object.create(null),o=[];[t,n].forEach((d)=>{for(let f in d){let h=d[f],p=r.paths[f];if(!p){i[f]=[h.map(([b])=>[b,Object.create(null)]),zs];continue}let m=p[1];o[p[0]]=h.map(([b,v])=>{let y=Object.create(null);v-=1;for(;v>=0;v--){let[D,g]=m[v];y[D]=g}return[b,y]})}});let[a,s,u]=r.buildRegExp();for(let d=0,f=o.length;d<f;d++)for(let h=0,p=o[d].length;h<p;h++){let m=o[d][h]?.[1];if(!m)continue;let b=Object.keys(m);for(let v=0,y=b.length;v<y;v++)m[b[v]]=u[m[b[v]]]}let c=[];for(let d in s)c[d]=o[s[d]];return[a,c,i]}};var md=class{name="SmartRouter";#e=[];#t=[];constructor(e){this.#e=e.routers}add(e,t,n){if(!this.#t)throw Error(Hs);this.#t.push([e,t,n])}match(e,t){if(!this.#t)throw Error("Fatal error");let n=this.#e,r=this.#t,i=n.length,o=0,a;for(;o<i;o++){let s=n[o];try{for(let u=0,c=r.length;u<c;u++)s.add(...r[u]);a=s.match(e,t)}catch(u){if(u instanceof $s)continue;throw u}this.match=s.match.bind(s),this.#e=[s],this.#t=void 0;break}if(o===i)throw Error("Fatal error");return this.name=`SmartRouter + ${this.activeRouter.name}`,a}get activeRouter(){if(this.#t||this.#e.length!==1)throw Error("No active router has been determined yet.");return this.#e[0]}};var No=Object.create(null),WF=(e)=>{for(let t in e)return!0;return!1},Ub=class e{#e;#t;#n;#o=0;#r=No;constructor(t,n,r){if(this.#t=r||Object.create(null),this.#e=[],t&&n){let i=Object.create(null);i[t]={handler:n,possibleKeys:[],score:0},this.#e=[i]}this.#n=[]}insert(t,n,r){this.#o=++this.#o;let i=this,o=ub(n),a=[];for(let s=0,u=o.length;s<u;s++){let c=o[s],d=o[s+1],f=lb(c,d),h=Array.isArray(f)?f[0]:c;if(h in i.#t){if(i=i.#t[h],f)a.push(f[1]);continue}if(i.#t[h]=new e,f)i.#n.push(f),a.push(f[1]);i=i.#t[h]}return i.#e.push({[t]:{handler:r,possibleKeys:a.filter((s,u,c)=>c.indexOf(s)===u),score:this.#o}}),i}#i(t,n,r,i,o){for(let a=0,s=n.#e.length;a<s;a++){let u=n.#e[a],c=u[r]||u[Be],d={};if(c!==void 0){if(c.params=Object.create(null),t.push(c),i!==No||o&&o!==No)for(let f=0,h=c.possibleKeys.length;f<h;f++){let p=c.possibleKeys[f],m=d[c.score];c.params[p]=o?.[p]&&!m?o[p]:i[p]??o?.[p],d[c.score]=!0}}}}search(t,n){let r=[];this.#r=No;let o=[this],a=ud(n),s=[],u=a.length,c=null;for(let d=0;d<u;d++){let f=a[d],h=d===u-1,p=[];for(let b=0,v=o.length;b<v;b++){let y=o[b],D=y.#t[f];if(D)if(D.#r=y.#r,h){if(D.#t["*"])this.#i(r,D.#t["*"],t,y.#r);this.#i(r,D,t,y.#r)}else p.push(D);for(let g=0,x=y.#n.length;g<x;g++){let E=y.#n[g],U=y.#r===No?{}:{...y.#r};if(E==="*"){let I=y.#t["*"];if(I)this.#i(r,I,t,y.#r),I.#r=U,p.push(I);continue}let[_,A,S]=E;if(!f&&!(S instanceof RegExp))continue;let M=y.#t[_];if(S instanceof RegExp){if(c===null){c=Array(u);let W=n[0]==="/"?1:0;for(let j=0;j<u;j++)c[j]=W,W+=a[j].length+1}let I=n.substring(c[d]),k=S.exec(I);if(k){if(U[A]=k[0],this.#i(r,M,t,y.#r,U),k[0].length===I.length&&M.#t["*"])this.#i(r,M.#t["*"],t,y.#r,U);if(WF(M.#t)){M.#r=U;let W=k[0].match(/\//g)?.length??0;(s[W]||=[]).push(M)}continue}}if(S===!0||S.test(f))if(U[A]=f,h){if(this.#i(r,M,t,U,y.#r),M.#t["*"])this.#i(r,M.#t["*"],t,U,y.#r)}else M.#r=U,p.push(M)}}let m=s.shift();o=m?p.concat(m):p}if(r.length>1)r.sort((d,f)=>d.score-f.score);return[r.map(({handler:d,params:f})=>[d,f])]}};var yd=class{name="TrieRouter";#e;constructor(){this.#e=new Ub}add(e,t,n){let r=js(t);if(r){for(let i=0,o=r.length;i<o;i++)this.#e.insert(e,r[i],n);return}this.#e.insert(e,t,n)}match(e,t){return this.#e.search(e,t)}};var bd=class extends wb{constructor(e={}){super(e);this.router=e.router??new md({routers:[new Xs,new yd]})}};import{getAgentDir as MQ}from"@earendil-works/pi-coding-agent";import{isIP as Ab}from"node:net";function Cb(e){return(e.startsWith("[")&&e.endsWith("]")?e.slice(1,-1):e).toLowerCase().replace(/\.$/,"")}function kb(e){if(!e||/[\s/@\\]/.test(e))return null;try{let t=new URL(`http://${e}`);if(t.username||t.password||t.pathname!=="/"||t.search||t.hash)return null;return Cb(t.hostname)}catch{return null}}function LF(e){let t=e?.trim();if(!t)return null;return Ab(t)?Cb(t):kb(t)}function jF(e){return e==="localhost"||e.endsWith(".localhost")}function Fb(){return[process.env.PI_WEB_HOSTNAME,...process.env.PI_WEB_ALLOWED_HOSTS?.split(",")??[]].filter((e)=>Boolean(e?.trim()))}function Rb(e){try{return new URL(e).origin}catch{return null}}function qF(e){let t=new URL(e.url),n=e.headers.get("host");return n?Rb(`${t.protocol}//${n}`):null}function HF(e){if(e.method!=="GET"||e.headers.get("sec-fetch-mode")!=="navigate"||e.headers.get("sec-fetch-dest")!=="document"||e.headers.get("sec-fetch-user")!=="?1")return!1;try{return/^\/api\/sessions\/[^/]+\/export$/.test(new URL(e.url).pathname)}catch{return!1}}function vd(e,t=Fb()){let n=e.headers.get("host"),r=n?kb(n):null;if(!r)return!1;if(jF(r)||Ab(r))return!0;return t.some((i)=>LF(i)===r)}function $F(e){let t=e.headers.get("origin");if(e.headers.get("sec-fetch-site")==="cross-site")return!1;if(!t)return!0;let r=qF(e);return r!==null&&Rb(t)===r}function zF(e){return e.headers.has("origin")||e.headers.has("sec-fetch-site")}function Ft(e,t=Fb()){if(!vd(e,t))return!1;if(HF(e))return!0;return!zF(e)||$F(e)}function Kn(e){let t=e.headers.get("content-type")?.split(";",1)[0]?.trim().toLowerCase();return t==="application/json"||Boolean(t?.startsWith("application/")&&t.endsWith("+json"))}import{createHash as VF,timingSafeEqual as GF}from"node:crypto";var XF="pi";function Ob(e){return VF("sha256").update(e,"utf8").digest()}function Ib(e,t){return GF(Ob(e),Ob(t))}function xd(e=process.env.PI_WEB_PASSWORD){return typeof e==="string"&&e.length>0}function Pb(e,t=process.env.PI_WEB_PASSWORD){if(!xd(t)||!e)return!1;let n=/^Basic\s+(\S+)$/i.exec(e);if(!n)return!1;let r;try{let c=Buffer.from(n[1],"base64");if(c.toString("base64")!==n[1])return!1;r=new TextDecoder("utf-8",{fatal:!0}).decode(c)}catch{return!1}let i=r.indexOf(":");if(i===-1)return!1;let o=r.slice(0,i),a=r.slice(i+1),s=Ib(o,XF),u=Ib(a,t);return s&&u}class Dd extends Request{nextUrl;constructor(e){let t=e.method!=="GET"&&e.method!=="HEAD";super(e.url,{method:e.method,headers:e.headers,body:t?e.body:void 0,duplex:t?"half":void 0,signal:e.signal});this.nextUrl=new URL(e.url)}}class w extends Response{static json(e,t){let n=new Headers(t?.headers);return n.set("content-type","application/json; charset=utf-8"),new w(JSON.stringify(e),{status:t?.status??200,statusText:t?.statusText,headers:n})}}var wd=!1,Bb=performance.now();function Mb(e){if(wd=e,Bb=performance.now(),wd)Nb("boot","debug log enabled")}function Sr(e){return(t,n)=>Nb(e,t,n)}function Nb(e,t,n){if(!wd)return;let r=performance.now()-Bb,i=new Date,o=(s,u=2)=>String(s).padStart(u,"0"),a=`${o(i.getHours())}:${o(i.getMinutes())}:${o(i.getSeconds())}.${o(i.getMilliseconds(),3)}`;console.debug(`[debug][${e}][${a}][+${r.toFixed(1)}ms] ${t}${n?` — ${n}`:""}`)}var KF=Sr("mount"),ZF=["GET","POST","PUT","PATCH","DELETE"];function te(e,t,n){let r=t.split("/").filter(Boolean),i=[],o=new Map;for(let s of r){let u=s.match(/^\[\.\.\.(.+)\]$/),c=s.match(/^\[(.+)\]$/);if(u)i.push(`:${u[1]}{.+}`),o.set(u[1],{hono:u[1],catchAll:!0});else if(c)i.push(`:${c[1]}`),o.set(c[1],{hono:c[1],catchAll:!1});else i.push(s)}let a=`/${i.join("/")}`;for(let s of ZF){let u=n[s];if(typeof u!=="function")continue;let c=u;e.on(s,a,async(d)=>{let f=performance.now(),h={};for(let[m,{hono:b,catchAll:v}]of o)if(v){let y=d.req.param(b)??"";h[m]=y===""?[]:y.split("/")}else h[m]=d.req.param(b)??"";let p=await c(new Dd(d.req.raw),{params:Promise.resolve(h)});return KF(`${s} ${d.req.path}`,`${p.status} ${Math.round(performance.now()-f)}ms`),p})}}var Rd={};ne(Rd,{GET:()=>B8});import{tmpdir as I8}from"node:os";import{Readable as P8}from"node:stream";import{constants as _d}from"node:fs";import{lstat as YF,open as JF}from"node:fs/promises";import{basename as QF,dirname as e8,resolve as Wb}from"node:path";var Ks=5242880;function Lb(e,t){let n=Wb(e);if(e8(n)!==Wb(t))return null;if(!/^pi-bash-[A-Za-z0-9_-]+\.log$/.test(QF(n)))return null;return n}async function Td(e){if(!(await YF(e)).isFile())throw Error("Bash output path is not a regular file");let n=typeof _d.O_NOFOLLOW==="number"?_d.O_NOFOLLOW:0,r=await JF(e,_d.O_RDONLY|n);try{let i=await r.stat();if(!i.isFile())throw Error("Bash output path is not a regular file");return{handle:r,fileInfo:i}}catch(i){throw await r.close(),i}}async function jb(e,t=Ks){let{handle:n,fileInfo:r}=await Td(e);try{if(r.size>t)return{tooLarge:!0,size:r.size};let i=Buffer.alloc(r.size),o=0;while(o<i.length){let a=await n.read(i,o,i.length-o,o);if(a.bytesRead===0)break;o+=a.bytesRead}return{tooLarge:!1,content:i.subarray(0,o).toString("utf8"),size:o}}finally{await n.close()}}import{open as Zb,readFile as p8,readdir as g8}from"node:fs/promises";import{existsSync as m8,readdirSync as y8}from"node:fs";import{join as Qs,normalize as kd}from"node:path";import{getAgentDir as b8,buildContextEntries as v8,buildSessionContext as x8,SessionManager as Yb}from"@earendil-works/pi-coding-agent";function t8(e){return typeof e==="object"&&e!==null&&!Array.isArray(e)}function n8(e){if(!t8(e)||e.type!=="toolCall")return null;return{type:"toolCall",toolCallId:typeof e.toolCallId==="string"?e.toolCallId:typeof e.id==="string"?e.id:"",toolName:typeof e.toolName==="string"?e.toolName:typeof e.name==="string"?e.name:"",input:typeof e.input==="object"&&e.input!==null&&!Array.isArray(e.input)?e.input:typeof e.arguments==="object"&&e.arguments!==null&&!Array.isArray(e.arguments)?e.arguments:{}}}function Ed(e){if(e.role!=="assistant")return e;let t=e.content;if(!Array.isArray(t))return e;let n=t.map((r)=>n8(r)??r);return{...e,content:n}}import qb from"node:path";function Rt(e,t=process.platform){let n=t==="win32"?qb.win32.normalize(e):qb.posix.normalize(e);return t==="win32"?n.toLowerCase():n}import{execFile as r8}from"node:child_process";import{existsSync as Ys,mkdirSync as i8,realpathSync as o8}from"node:fs";import{basename as a8,dirname as Ud,join as $b,resolve as s8}from"node:path";import{promisify as c8}from"node:util";function We(e){let t=e.replace(/\\/g,"/");return/^[a-zA-Z]:$/.test(t)?`${t}/`:t}function Sd(){if(!globalThis.__piAdditionalAllowedRoots)globalThis.__piAdditionalAllowedRoots=new Set;return globalThis.__piAdditionalAllowedRoots}function ft(e){if(!e)return;let t=We(e);Sd().add(t),globalThis.__piAllowedRootsCache?.roots.add(t)}var u8=c8(r8),Hb=60000;function l8(){if(!globalThis.__piProjectCache)globalThis.__piProjectCache=new Map;return globalThis.__piProjectCache}function zb(){globalThis.__piProjectCache?.clear()}async function Ur(e,t){let{stdout:n}=await u8("git",["-C",e,...t],{timeout:1e4,maxBuffer:1048576,env:{...process.env,LC_ALL:"C"}});return n.trim()}function Zs(e){let t=e.replace(/\\/g,"/");if(process.platform==="win32")t=t.replace(/^\/([a-zA-Z])\/(?=.)/,(n,r)=>`${r.toUpperCase()}:/`),t=t.toLowerCase();return t}function d8(e){let t=Ud(e);if(!t.endsWith("-worktrees"))return null;let n=t.slice(0,-10);if(!n||!Ys($b(n,".git")))return null;return{projectRoot:n,branch:a8(e),isWorktree:!0,isTopLevel:!0}}async function Js(e){let t=l8(),n=t.get(e);if(n&&n.expiresAt>Date.now())return n.info;let r;try{if(!Ys(e))return r=d8(e)??{projectRoot:e,branch:null,isWorktree:!1,isTopLevel:!1},t.set(e,{info:r,expiresAt:Date.now()+Hb}),r;let i=await Ur(e,["rev-parse","--path-format=absolute","--git-common-dir","--git-dir","--show-toplevel","--abbrev-ref","HEAD"]),[o,a,s,u]=i.split(`
252
+ `)}),this}_outputHelpIfRequested(e){let t=this._getHelpOption();if(t&&e.find((r)=>t.is(r)))this.outputHelp(),this._exit(0,"commander.helpDisplayed","(outputHelp)")}}function tb(e){return e.map((t)=>{if(!t.startsWith("--inspect"))return t;let n,r="127.0.0.1",i="9229",o;if((o=t.match(/^(--inspect(-brk)?)$/))!==null)n=o[1];else if((o=t.match(/^(--inspect(-brk|-port)?)=([^:]+)$/))!==null)if(n=o[1],/^\d+$/.test(o[3]))i=o[3];else r=o[3];else if((o=t.match(/^(--inspect(-brk|-port)?)=([^:]+):(\d+)$/))!==null)n=o[1],r=o[3],i=o[4];if(n&&i!=="0")return`${n}=${r}:${parseInt(i)+1}`;return t})}function nb(){if(le.env.NO_COLOR||le.env.FORCE_COLOR==="0"||le.env.FORCE_COLOR==="false")return!1;if(le.env.FORCE_COLOR||le.env.CLICOLOR_FORCE!==void 0)return!0;return}var Fee=new gi;var rb={name:"@rainmanhhh/pi-web",version:"0.11.2",description:"Web UI for the pi coding agent (fork of @agegr/pi-web)",homepage:"https://gitee.com/dsxbygzzl/pi-web#readme",repository:{type:"git",url:"git+https://gitee.com/dsxbygzzl/pi-web.git"},bugs:{url:"https://gitee.com/dsxbygzzl/pi-web/issues"},author:"rainmanhhh",license:"MIT",publishConfig:{access:"public",registry:"https://registry.npmjs.org"},engines:{node:">=22.19.0"},files:["dist","public","extensions","package.json"],bin:{"pi-web":"dist/server.mjs"},scripts:{dev:"vite","dev:lan":"vite --host 0.0.0.0",mb:"bun run --env-file=.env.manual api",mf:"bun run --env-file=.env.manual dev -- --port 3001",api:"bun run server/main.ts","api:node":"bun run build:server && node dist/server.mjs","build:server":'bun build server/main.ts --target node --outfile dist/server.mjs --minify --external "@earendil-works/*" --define "process.env.PI_WEB_PACKAGED=1"',"e2e:stop":"bun run scripts/e2e-stop.mjs",build:"vite build && bun run scripts/prune-fonts.mjs","build:analyze":"vite build --config scripts/analyze-bundle.config.ts && bun run scripts/prune-fonts.mjs",lint:"oxlint --fix",jscpd:"jscpd --config .jscpd.json",check:"tsc --noEmit",format:"biome check --write .",prepublishOnly:"bun run check && bun run build && bun run build:server","test:e2e":"playwright test","test:unit":"vitest run",prepare:"husky || true"},dependencies:{"@codemirror/commands":"^6.11.0","@codemirror/lang-css":"^6.3.1","@codemirror/lang-html":"^6.4.12","@codemirror/lang-javascript":"^6.2.5","@codemirror/lang-json":"^6.0.2","@codemirror/lang-markdown":"^6.5.2","@codemirror/lang-yaml":"^6.1.3","@codemirror/language":"^6.12.4","@codemirror/state":"^6.7.1","@codemirror/theme-one-dark":"^6.1.3","@codemirror/view":"^6.43.9","@earendil-works/pi-agent-core":"0.84.2","@earendil-works/pi-ai":"0.84.2","@earendil-works/pi-coding-agent":"0.84.2","@earendil-works/pi-tui":"0.84.2","@hono/node-server":"^2.1.0","class-variance-authority":"^0.7.1",clsx:"^2.1.1",codemirror:"^6.0.2",hono:"^4.13.1","lucide-react":"^1.31.0",pointrix:"^1.1.0","proper-lockfile":"4.1.2","radix-ui":"^1.6.7",react:"^19.2.4","react-dom":"^19.2.4",shadcn:"^4.17.0",streamdown:"2.5.0","tailwind-merge":"^3.6.0","tw-animate-css":"^1.4.0",undici:"8.9.0"},devDependencies:{"@lobehub/icons":"^5.6.0","@playwright/test":"^1.62.1","@tailwindcss/postcss":"^4.2.2","@testing-library/dom":"^10.4.1","@testing-library/react":"^16.3.2","@types/node":"^25","@types/proper-lockfile":"4.1.4","@types/react":"^19","@types/react-dom":"^19","@types/react-resizable":"^4.0.0","@types/react-syntax-highlighter":"^15.5.13","@vitejs/plugin-react":"^6.0.5",biome:"^0.3.3",commander:"^15.0.0",husky:"^9.1.7",jiti:"^2.7.0",jscpd:"^5.0.14",jsdom:"^30.0.1",katex:"^0.16.47","lint-staged":"^17.3.0",mammoth:"^1.12.0",mermaid:"^11.14.0",oxlint:"^1.78.0",postcss:"^8","react-markdown":"^10.1.0","react-syntax-highlighter":"^16.1.1","rehype-katex":"^7.0.1","rehype-raw":"^7.0.0","rehype-sanitize":"^6.0.0","remark-gfm":"^4.0.1","remark-math":"^6.0.0",tailwindcss:"^4.2.2",typescript:"^7.0.2",vite:"^8.2.1","vite-plugin-svgr":"^5.2.0",vitest:"^4.1.10"},type:"module"};import{getAgentDir as x3}from"@earendil-works/pi-coding-agent";var ib={port:31415};var sd=(e,t,n)=>(r,i)=>{let o=-1;return a(0);async function a(s){if(s<=o)throw Error("next() called multiple times");o=s;let u,c=!1,d;if(e[s])d=e[s][0][0],r.req.routeIndex=s;else d=s===e.length&&i||void 0;if(d)try{u=await d(r,()=>a(s+1))}catch(f){if(f instanceof Error&&t)r.error=f,u=await t(f,r),c=!0;else throw f}else if(r.finalized===!1&&n)u=await n(r);if(u&&(r.finalized===!1||c))r.res=u;return r}};var ob=Symbol();var ab=(e,t)=>new Response(e,{headers:{"Content-Type":t.replace(/^[^;]+/,(r)=>r.toLowerCase())}}).formData();var Ws=(e)=>("headers"in e),cb=async(e,t=Object.create(null))=>{let{all:n=!1,dot:r=!1}=t,a=(Ws(e)?e.headers:e.raw.headers).get("Content-Type")?.split(";")[0].trim().toLowerCase();if(a==="multipart/form-data"||a==="application/x-www-form-urlencoded")return UF(e,{all:n,dot:r});return{}};async function UF(e,t){if(!Ws(e)&&e.bodyCache.formData)return sb(await e.bodyCache.formData,t);let n=Ws(e)?e.headers:e.raw.headers,r=await e.arrayBuffer(),i=ab(r,n.get("Content-Type")||"");if(!Ws(e))e.bodyCache.formData=i;let o=await i;if(o)return sb(o,t);return{}}function sb(e,t){let n=Object.create(null);if(e.forEach((r,i)=>{if(!(t.all||i.endsWith("[]")))n[i]=r;else AF(n,i,r)}),t.dot)Object.entries(n).forEach(([r,i])=>{if(r.includes("."))CF(n,r,i),delete n[r]});return n}var AF=(e,t,n)=>{if(e[t]!==void 0)if(Array.isArray(e[t]))e[t].push(n);else e[t]=[e[t],n];else if(!t.endsWith("[]"))e[t]=n;else e[t]=[n]},CF=(e,t,n)=>{if(/(?:^|\.)__proto__\./.test(t))return;let r=e,i=t.split(".");i.forEach((o,a)=>{if(a===i.length-1)r[o]=n;else{if(!r[o]||typeof r[o]!=="object"||Array.isArray(r[o])||r[o]instanceof File)r[o]=Object.create(null);r=r[o]}})};var ud=(e)=>{let t=e.split("/");if(t[0]==="")t.shift();return t},ub=(e)=>{let{groups:t,path:n}=kF(e),r=ud(n);return FF(r,t)},kF=(e)=>{let t=[];return e=e.replace(/\{[^}]+\}/g,(n,r)=>{let i=`@${r}`;return t.push([i,n]),i}),{groups:t,path:e}},FF=(e,t)=>{for(let n=t.length-1;n>=0;n--){let[r]=t[n];for(let i=e.length-1;i>=0;i--)if(e[i].includes(r)){e[i]=e[i].replace(r,t[n][1]);break}}return e},Ls={},lb=(e,t)=>{if(e==="*")return"*";let n=e.match(/^\:([^\{\}]+)(?:\{(.+)\})?$/);if(n){let r=`${e}#${t}`;if(!Ls[r])if(n[2])Ls[r]=t&&t[0]!==":"&&t[0]!=="*"?[r,n[1],new RegExp(`^${n[2]}(?=/${t})`)]:[e,n[1],new RegExp(`^${n[2]}$`)];else Ls[r]=[e,n[1],!0];return Ls[r]}return null},db=(e,t)=>{try{return t(e)}catch{return e.replace(/(?:%[0-9A-Fa-f]{2})+/g,(n)=>{try{return t(n)}catch{return n}})}},RF=(e)=>db(e,decodeURI),ld=(e)=>{let t=e.url,n=t.indexOf("/",t.indexOf(":")+4),r=n;for(;r<t.length;r++){let i=t.charCodeAt(r);if(i===37){let o=t.indexOf("?",r),a=t.indexOf("#",r),s=o===-1?a===-1?void 0:a:a===-1?o:Math.min(o,a),u=t.slice(n,s);return RF(u.includes("%25")?u.replace(/%25/g,"%2525"):u)}else if(i===63||i===35)break}return t.slice(n,r)};var fb=(e)=>{let t=ld(e);return t.length>1&&t.at(-1)==="/"?t.slice(0,-1):t},Gn=(e,t,...n)=>{if(n.length)t=Gn(t,...n);return`${e?.[0]==="/"?"":"/"}${e}${t==="/"?"":`${e?.at(-1)==="/"?"":"/"}${t?.[0]==="/"?t.slice(1):t}`}`},js=(e)=>{if(e.charCodeAt(e.length-1)!==63||!e.includes(":"))return null;let t=e.split("/"),n=[],r="";return t.forEach((i)=>{if(i!==""&&!/\:/.test(i))r+="/"+i;else if(/\:/.test(i))if(/\?/.test(i)){if(n.length===0&&r==="")n.push("/");else n.push(r);let o=i.replace("?","");r+="/"+o,n.push(r)}else r+="/"+i}),n.filter((i,o,a)=>a.indexOf(i)===o)},qs=(e)=>e.indexOf("%")!==-1?db(e,OF):e,cd=(e)=>{if(e.indexOf("+")!==-1)e=e.replace(/\+/g," ");return qs(e)},hb=(e,t,n)=>{let r;if(!n&&t&&t.indexOf("%")===-1&&t.indexOf("+")===-1){let a=e.indexOf("?",8);if(a===-1)return;if(!e.startsWith(t,a+1))a=e.indexOf(`&${t}`,a+1);while(a!==-1){let s=e.charCodeAt(a+t.length+1);if(s===61){let u=a+t.length+2,c=e.indexOf("&",u);return cd(e.slice(u,c===-1?void 0:c))}else if(s==38||isNaN(s))return"";a=e.indexOf(`&${t}`,a+1)}if(r=/[%+]/.test(e),!r)return}let i=Object.create(null);r??=/[%+]/.test(e);let o=e.indexOf("?",8);while(o!==-1){let a=e.indexOf("&",o+1),s=e.indexOf("=",o);if(s>a&&a!==-1)s=-1;let u=e.slice(o+1,s===-1?a===-1?void 0:a:s);if(r)u=cd(u);if(o=a,u==="")continue;let c;if(s===-1)c="";else if(c=e.slice(s+1,a===-1?void 0:a),r)c=cd(c);if(n){if(!(i[u]&&Array.isArray(i[u])))i[u]=[];i[u].push(c)}else i[u]??=c}return t?i[t]:i},pb=hb,gb=(e,t)=>hb(e,t,!0),OF=decodeURIComponent;var mb=class{raw;#e;#t;routeIndex=0;path;bodyCache={};constructor(e,t="/",n=[[]]){this.raw=e,this.path=t,this.#t=n}param(e){return e?this.#n(e):this.#o()}#n(e){let t=this.#t[0][this.routeIndex][1][e],n=this.#r(t);return n&&qs(n)}#o(){let e={},t=Object.keys(this.#t[0][this.routeIndex][1]);for(let n of t){let r=this.#r(this.#t[0][this.routeIndex][1][n]);if(r!==void 0)e[n]=qs(r)}return e}#r(e){return this.#t[1]?this.#t[1][e]:e}query(e){return pb(this.url,e)}queries(e){return gb(this.url,e)}header(e){if(e)return this.raw.headers.get(e)??void 0;let t=Object.create(null);return this.raw.headers.forEach((n,r)=>{t[r]=n}),t}async parseBody(e){return cb(this,e)}#i=(e)=>{let{bodyCache:t,raw:n}=this,r=t[e];if(r)return r;for(let i in t)return t[i].then((o)=>{if(i==="json")o=JSON.stringify(o);return new Response(o)[e]()});return t[e]=n[e]()};json(){return this.#i("text").then((e)=>JSON.parse(e))}text(){return this.#i("text")}arrayBuffer(){return this.#i("arrayBuffer")}bytes(){return this.#i("arrayBuffer").then((e)=>new Uint8Array(e))}blob(){return this.#i("blob")}formData(){return this.#i("formData")}addValidatedData(e,t){(this.#e??={})[e]=t}valid(e){return this.#e?.[e]}get url(){return this.raw.url}get method(){return this.raw.method}get[ob](){return this.#t}get matchedRoutes(){return this.#t[0].map(([[,e]])=>e)}get routePath(){return this.#t[0].map(([[,e]])=>e)[this.routeIndex].path}};var yb={Stringify:1,BeforeStream:2,Stream:3},IF=(e,t)=>{let n=new String(e);return n.isEscaped=!0,n.callbacks=t,n};var dd=async(e,t,n,r,i)=>{if(typeof e==="object"&&!(e instanceof String)){if(!(e instanceof Promise))e=e.toString();if(e instanceof Promise)e=await e}let o=e.callbacks;if(!o?.length)return Promise.resolve(e);if(i)i[0]+=e;else i=[e];let a=Promise.all(o.map((s)=>s({phase:t,buffer:i,context:r}))).then((s)=>Promise.all(s.filter(Boolean).map((u)=>dd(u,t,!1,r,i))).then(()=>i[0]));if(n)return IF(await a,o);else return a};var PF="text/plain; charset=UTF-8",fd=(e,t)=>({"Content-Type":e,...t}),Mo=(e,t)=>new Response(e,t),hd=class{#e;#t;env={};#n;finalized=!1;error;#o;#r;#i;#l;#c;#u;#s;#d;#f;constructor(e,t){if(this.#e=e,t)this.#r=t.executionCtx,this.env=t.env,this.#u=t.notFoundHandler,this.#f=t.path,this.#d=t.matchResult}get req(){return this.#t??=new mb(this.#e,this.#f,this.#d),this.#t}get event(){if(this.#r&&"respondWith"in this.#r)return this.#r;else throw Error("This context has no FetchEvent")}get executionCtx(){if(this.#r)return this.#r;else throw Error("This context has no ExecutionContext")}get res(){return this.#i||=Mo(null,{headers:this.#s??=new Headers})}set res(e){if(this.#i&&e){e=Mo(e.body,e);for(let[t,n]of this.#i.headers.entries()){if(t==="content-type")continue;if(t==="set-cookie"){let r=this.#i.headers.getSetCookie();e.headers.delete("set-cookie");for(let i of r)e.headers.append("set-cookie",i)}else e.headers.set(t,n)}}this.#i=e,this.finalized=!0}render=(...e)=>(this.#c??=(t)=>this.html(t),this.#c(...e));setLayout=(e)=>this.#l=e;getLayout=()=>this.#l;setRenderer=(e)=>{this.#c=e};header=(e,t,n)=>{if(this.finalized)this.#i=Mo(this.#i.body,this.#i);let r=this.#i?this.#i.headers:this.#s??=new Headers;if(t===void 0)r.delete(e);else if(n?.append)r.append(e,t);else r.set(e,t)};status=(e)=>{this.#o=e};set=(e,t)=>{this.#n??=new Map,this.#n.set(e,t)};get=(e)=>this.#n?this.#n.get(e):void 0;get var(){if(!this.#n)return{};return Object.fromEntries(this.#n)}#a(e,t,n){let r=this.#i?new Headers(this.#i.headers):this.#s;if(typeof t==="object"&&t.headers){r??=new Headers;for(let[o,a]of new Headers(t.headers))if(o==="set-cookie")r.append(o,a);else r.set(o,a)}if(n){if(!r){let o=0;for(let a in n)if(++o>1||typeof n[a]!=="string"){r=new Headers;break}}if(r)for(let o in n){let a=n[o];if(typeof a==="string")r.set(o,a);else{r.delete(o);for(let s of a)r.append(o,s)}}}let i=typeof t==="number"?t:t?.status??this.#o;return Mo(e,{status:i,headers:r??n})}newResponse=(...e)=>this.#a(...e);body=(e,t,n)=>this.#a(e,t,n);text=(e,t,n)=>!this.#s&&!this.#o&&!t&&!n&&!this.finalized?new Response(e):this.#a(e,t,fd(PF,n));json=(e,t,n)=>this.#a(JSON.stringify(e),t,fd("application/json",n));html=(e,t,n)=>{let r=(i)=>this.#a(i,t,fd("text/html; charset=UTF-8",n));return typeof e==="object"?dd(e,yb.Stringify,!1,{}).then(r):r(e)};redirect=(e,t)=>{let n=String(e);return this.header("Location",!/[^\x00-\xFF]/.test(n)?n:encodeURI(n)),this.newResponse(null,t??302)};notFound=()=>(this.#u??=()=>Mo(),this.#u(this))};var Be="ALL",bb="all",vb=["get","post","put","delete","options","patch","query"],Hs="Can not add a route since the matcher is already built.",$s=class extends Error{};var xb="__COMPOSED_HANDLER";var BF=(e)=>e.text("404 Not Found",404),Db=(e,t)=>{if("getResponse"in e){let n=e.getResponse();return t.newResponse(n.body,n)}return console.error(e),t.text("Internal Server Error",500)},wb=class e{get;post;put;delete;options;patch;query;all;on;use;router;getPath;_basePath="/";#e="/";routes=[];constructor(t={}){[...vb,bb].forEach((o)=>{this[o]=(a,...s)=>{if(typeof a==="string")this.#e=a;else this.#o(o,this.#e,a);return s.forEach((u)=>{this.#o(o,this.#e,u)}),this}}),this.on=(o,a,...s)=>{for(let u of[a].flat()){this.#e=u;for(let c of[o].flat())s.map((d)=>{this.#o(c.toUpperCase(),this.#e,d)})}return this},this.use=(o,...a)=>{if(typeof o==="string")this.#e=o;else this.#e="*",a.unshift(o);return a.forEach((s)=>{this.#o(Be,this.#e,s)}),this};let{strict:r,...i}=t;Object.assign(this,i),this.getPath=r??!0?t.getPath??ld:fb}#t(){let t=new e({router:this.router,getPath:this.getPath});return t.errorHandler=this.errorHandler,t.#n=this.#n,t.routes=this.routes,t}#n=BF;errorHandler=Db;route(t,n){let r=this.basePath(t);return n.routes.map((i)=>{let o;if(n.errorHandler===Db)o=i.handler;else o=async(a,s)=>(await sd([],n.errorHandler)(a,()=>i.handler(a,s))).res,o[xb]=i.handler;r.#o(i.method,i.path,o,i.basePath)}),this}basePath(t){let n=this.#t();return n._basePath=Gn(this._basePath,t),n}onError=(t)=>(this.errorHandler=t,this);notFound=(t)=>(this.#n=t,this);mount(t,n,r){let i,o;if(r)if(typeof r==="function")o=r;else if(o=r.optionHandler,r.replaceRequest===!1)i=(u)=>u;else i=r.replaceRequest;let a=o?(u)=>{let c=o(u);return Array.isArray(c)?c:[c]}:(u)=>{let c=void 0;try{c=u.executionCtx}catch{}return[u.env,c]};i||=(()=>{let u=Gn(this._basePath,t),c=u==="/"?0:u.length;return(d)=>{let f=new URL(d.url);return f.pathname=this.getPath(d).slice(c)||"/",new Request(f,d)}})();let s=async(u,c)=>{let d=await n(i(u.req.raw),...a(u));if(d)return d;await c()};return this.#o(Be,Gn(t,"*"),s),this}#o(t,n,r,i){t=t.toUpperCase(),n=Gn(this._basePath,n);let o={basePath:i!==void 0?Gn(this._basePath,i):this._basePath,path:n,method:t,handler:r};this.router.add(t,n,[r,o]),this.routes.push(o)}#r(t,n){if(t instanceof Error)return this.errorHandler(t,n);throw t}#i(t,n,r,i){if(i==="HEAD")return(async()=>new Response(null,await this.#i(t,n,r,"GET")))();let o=this.getPath(t,{env:r}),a=this.router.match(i,o),s=new hd(t,{path:o,matchResult:a,env:r,executionCtx:n,notFoundHandler:this.#n});if(a[0].length===1){let c;try{c=a[0][0][0][0](s,async()=>{s.res=await this.#n(s)})}catch(d){return this.#r(d,s)}return c instanceof Promise?c.then((d)=>d||(s.finalized?s.res:this.#n(s))).catch((d)=>this.#r(d,s)):c??this.#n(s)}let u=sd(a[0],this.errorHandler,this.#n);return(async()=>{try{let c=await u(s);if(!c.finalized)throw Error("Context is not finalized. Did you forget to return a Response object or `await next()`?");return c.res}catch(c){return this.#r(c,s)}})()}fetch=(t,...n)=>this.#i(t,n[1],n[0],t.method);request=(t,n,r,i)=>{if(t instanceof Request)return this.fetch(n?new Request(t,n):t,r,i);return t=t.toString(),this.fetch(new Request(/^https?:\/\//.test(t)?t:`http://localhost${Gn("/",t)}`,n),r,i)};fire=()=>{addEventListener("fetch",(t)=>{t.respondWith(this.#i(t.request,t,void 0,t.request.method))})}};var zs=[];function pd(e,t){let n=this.buildAllMatchers(),r=(i,o)=>{let a=n[i]||n[Be],s=a[2][o];if(s)return s;let u=o.match(a[0]);if(!u)return[[],zs];let c=u.indexOf("",1);return[a[1][c],u]};return this.match=r,r(e,t)}var Vs="[^/]+",mi=".*",Er="(?:|/.*)",Xn=Symbol(),_b=new Set(".\\+*[^]$()");function MF(e,t){if(e.length===1)return t.length===1?e<t?-1:1:-1;if(t.length===1)return 1;if(e===mi||e===Er)return t===Er?-1:1;else if(t===mi||t===Er)return-1;if(e===Vs)return 1;else if(t===Vs)return-1;return e.length===t.length?e<t?-1:1:t.length-e.length}var Tb=class e{#e;#t;#n=Object.create(null);insert(t,n,r,i,o){let a=this;for(let s=0,u=t.length;s<u;s++){let c=t[s],d=c.length===1?c==="*"?s===u-1?["","",mi]:["","",Vs]:null:c==="/*"?["","",Er]:c.match(/^\:([^\{\}]+)(?:\{(.+)\})?$/),f;if(d){let h=d[1],p=d[2]||Vs;if(h&&d[2]){if(p===".*")throw Xn;if(p=p.replace(/^\((?!\?:)(?=[^)]+\)$)/,"(?:"),/\((?!\?:)/.test(p))throw Xn;if(p.length===1&&_b.has(p))throw Xn}if(f=a.#n[p],!f){if(p!==mi&&p!==Er){for(let m in a.#n)if((p.length>1||m.length>1)&&m!==mi&&m!==Er)throw Xn}f=a.#n[p]=new e}if(h!=="")f.#t??=i.varIndex++,r.push([h,f.#t])}else if(f=a.#n[c],!f){for(let h in a.#n)if(h.length>1&&h!==mi&&h!==Er)throw Xn;f=a.#n[c]=new e}a=f}if(a.#e!==void 0)throw Xn;a.#e=o?-1:n}buildRegExpStr(){let n=Object.keys(this.#n).sort(MF).map((r)=>{let i=this.#n[r],o=i.buildRegExpStr();return o===""?"":(typeof i.#t==="number"?`(${r})@${i.#t}`:_b.has(r)?`\\${r}`:r)+o}).filter(Boolean);if(typeof this.#e==="number"&&this.#e!==-1)n.unshift(`#${this.#e}`);if(n.length===0)return"";if(n.length===1)return n[0];return"(?:"+n.join("|")+")"}};var gd=class{#e={varIndex:0};#t=new Tb;#n=0;paths=Object.create(null);insert(e,t){if(t){this.#t.insert(e.split(""),0,[],this.#e,!0);return}let n=[],r=[],i=e;for(let a=0;;){let s=!1;if(i=i.replace(/\{[^}]+\}/g,(u)=>{let c=`@\\${a}`;return r[a]=[c,u],a++,s=!0,c}),!s)break}let o=i.match(/(?::[^\/]+)|(?:\/\*$)|./g)||[];for(let a=r.length-1;a>=0;a--){let[s]=r[a];for(let u=o.length-1;u>=0;u--)if(o[u].indexOf(s)!==-1){o[u]=o[u].replace(s,r[a][1]);break}}this.#t.insert(o,this.#n,n,this.#e,!1),this.paths[e]=[this.#n++,n]}buildRegExp(){let e=this.#t.buildRegExpStr();if(e==="")return[/^$/,[],[]];let t=0,n=[],r=[];return e=e.replace(/#(\d+)|@(\d+)|\.\*\$/g,(i,o,a)=>{if(o!==void 0)return n[++t]=Number(o),"$()";if(a!==void 0)return r[Number(a)]=++t,"";return""}),[new RegExp(`^${e}`),n,r]}};var Eb=Object.create(null);function Sb(e){return Eb[e]??=new RegExp(e==="*"?"":`^${e.replace(/\/\*$|([.\\+*[^\]$()])/g,(t,n)=>n?`\\${n}`:"(?:|/.*)")}$`)}function NF(){Eb=Object.create(null)}function Gs(e,t){if(!e)return;for(let n of Object.keys(e).sort((r,i)=>i.length-r.length))if(Sb(n).test(t))return[...e[n]];return}var Xs=class{name="RegExpRouter";#e;#t;#n;constructor(){this.#e={[Be]:Object.create(null)},this.#t={[Be]:Object.create(null)},this.#n={[Be]:new gd}}#o(e,t){try{this.#n[e].insert(t,!/\*|\/:/.test(t))}catch(n){throw n===Xn?new $s(t):n}}add(e,t,n){let r=this.#e,i=this.#t;if(!r||!i)throw Error(Hs);if(!r[e])this.#n[e]=new gd,[r,i].forEach((s)=>{s[e]=Object.create(null),Object.keys(s[Be]).forEach((u)=>{s[e][u]=[...s[Be][u]],this.#o(e,u)})});if(t==="/*")t="*";let o=(t.match(/\/:/g)||[]).length;if(/\*$/.test(t)){let s=Sb(t);Object.keys(r).forEach((u)=>{if((e===Be||e===u)&&!r[u][t])this.#o(u,t),r[u][t]=Gs(r[u],t)||Gs(r[Be],t)||[]}),Object.keys(r).forEach((u)=>{if(e===Be||e===u)Object.keys(r[u]).forEach((c)=>{s.test(c)&&r[u][c].push([n,o])})}),Object.keys(i).forEach((u)=>{if(e===Be||e===u)Object.keys(i[u]).forEach((c)=>s.test(c)&&i[u][c].push([n,o]))});return}let a=js(t)||[t];for(let s=0,u=a.length;s<u;s++){let c=a[s];Object.keys(i).forEach((d)=>{if(e===Be||e===d){if(!i[d][c])this.#o(d,c),i[d][c]=[...Gs(r[d],c)||Gs(r[Be],c)||[]];i[d][c].push([n,o-u+s+1])}})}}match=pd;buildAllMatchers(){let e=Object.create(null);return Object.keys(this.#t).concat(Object.keys(this.#e)).forEach((t)=>{e[t]||=this.#r(t)}),this.#e=this.#t=this.#n=void 0,NF(),e}#r(e){let t=this.#e[e],n=this.#t[e],r=this.#n[e],i=Object.create(null),o=[];[t,n].forEach((d)=>{for(let f in d){let h=d[f],p=r.paths[f];if(!p){i[f]=[h.map(([b])=>[b,Object.create(null)]),zs];continue}let m=p[1];o[p[0]]=h.map(([b,v])=>{let y=Object.create(null);v-=1;for(;v>=0;v--){let[D,g]=m[v];y[D]=g}return[b,y]})}});let[a,s,u]=r.buildRegExp();for(let d=0,f=o.length;d<f;d++)for(let h=0,p=o[d].length;h<p;h++){let m=o[d][h]?.[1];if(!m)continue;let b=Object.keys(m);for(let v=0,y=b.length;v<y;v++)m[b[v]]=u[m[b[v]]]}let c=[];for(let d in s)c[d]=o[s[d]];return[a,c,i]}};var md=class{name="SmartRouter";#e=[];#t=[];constructor(e){this.#e=e.routers}add(e,t,n){if(!this.#t)throw Error(Hs);this.#t.push([e,t,n])}match(e,t){if(!this.#t)throw Error("Fatal error");let n=this.#e,r=this.#t,i=n.length,o=0,a;for(;o<i;o++){let s=n[o];try{for(let u=0,c=r.length;u<c;u++)s.add(...r[u]);a=s.match(e,t)}catch(u){if(u instanceof $s)continue;throw u}this.match=s.match.bind(s),this.#e=[s],this.#t=void 0;break}if(o===i)throw Error("Fatal error");return this.name=`SmartRouter + ${this.activeRouter.name}`,a}get activeRouter(){if(this.#t||this.#e.length!==1)throw Error("No active router has been determined yet.");return this.#e[0]}};var No=Object.create(null),WF=(e)=>{for(let t in e)return!0;return!1},Ub=class e{#e;#t;#n;#o=0;#r=No;constructor(t,n,r){if(this.#t=r||Object.create(null),this.#e=[],t&&n){let i=Object.create(null);i[t]={handler:n,possibleKeys:[],score:0},this.#e=[i]}this.#n=[]}insert(t,n,r){this.#o=++this.#o;let i=this,o=ub(n),a=[];for(let s=0,u=o.length;s<u;s++){let c=o[s],d=o[s+1],f=lb(c,d),h=Array.isArray(f)?f[0]:c;if(h in i.#t){if(i=i.#t[h],f)a.push(f[1]);continue}if(i.#t[h]=new e,f)i.#n.push(f),a.push(f[1]);i=i.#t[h]}return i.#e.push({[t]:{handler:r,possibleKeys:a.filter((s,u,c)=>c.indexOf(s)===u),score:this.#o}}),i}#i(t,n,r,i,o){for(let a=0,s=n.#e.length;a<s;a++){let u=n.#e[a],c=u[r]||u[Be],d={};if(c!==void 0){if(c.params=Object.create(null),t.push(c),i!==No||o&&o!==No)for(let f=0,h=c.possibleKeys.length;f<h;f++){let p=c.possibleKeys[f],m=d[c.score];c.params[p]=o?.[p]&&!m?o[p]:i[p]??o?.[p],d[c.score]=!0}}}}search(t,n){let r=[];this.#r=No;let o=[this],a=ud(n),s=[],u=a.length,c=null;for(let d=0;d<u;d++){let f=a[d],h=d===u-1,p=[];for(let b=0,v=o.length;b<v;b++){let y=o[b],D=y.#t[f];if(D)if(D.#r=y.#r,h){if(D.#t["*"])this.#i(r,D.#t["*"],t,y.#r);this.#i(r,D,t,y.#r)}else p.push(D);for(let g=0,x=y.#n.length;g<x;g++){let E=y.#n[g],U=y.#r===No?{}:{...y.#r};if(E==="*"){let I=y.#t["*"];if(I)this.#i(r,I,t,y.#r),I.#r=U,p.push(I);continue}let[_,A,S]=E;if(!f&&!(S instanceof RegExp))continue;let M=y.#t[_];if(S instanceof RegExp){if(c===null){c=Array(u);let W=n[0]==="/"?1:0;for(let j=0;j<u;j++)c[j]=W,W+=a[j].length+1}let I=n.substring(c[d]),k=S.exec(I);if(k){if(U[A]=k[0],this.#i(r,M,t,y.#r,U),k[0].length===I.length&&M.#t["*"])this.#i(r,M.#t["*"],t,y.#r,U);if(WF(M.#t)){M.#r=U;let W=k[0].match(/\//g)?.length??0;(s[W]||=[]).push(M)}continue}}if(S===!0||S.test(f))if(U[A]=f,h){if(this.#i(r,M,t,U,y.#r),M.#t["*"])this.#i(r,M.#t["*"],t,U,y.#r)}else M.#r=U,p.push(M)}}let m=s.shift();o=m?p.concat(m):p}if(r.length>1)r.sort((d,f)=>d.score-f.score);return[r.map(({handler:d,params:f})=>[d,f])]}};var yd=class{name="TrieRouter";#e;constructor(){this.#e=new Ub}add(e,t,n){let r=js(t);if(r){for(let i=0,o=r.length;i<o;i++)this.#e.insert(e,r[i],n);return}this.#e.insert(e,t,n)}match(e,t){return this.#e.search(e,t)}};var bd=class extends wb{constructor(e={}){super(e);this.router=e.router??new md({routers:[new Xs,new yd]})}};import{getAgentDir as MQ}from"@earendil-works/pi-coding-agent";import{isIP as Ab}from"node:net";function Cb(e){return(e.startsWith("[")&&e.endsWith("]")?e.slice(1,-1):e).toLowerCase().replace(/\.$/,"")}function kb(e){if(!e||/[\s/@\\]/.test(e))return null;try{let t=new URL(`http://${e}`);if(t.username||t.password||t.pathname!=="/"||t.search||t.hash)return null;return Cb(t.hostname)}catch{return null}}function LF(e){let t=e?.trim();if(!t)return null;return Ab(t)?Cb(t):kb(t)}function jF(e){return e==="localhost"||e.endsWith(".localhost")}function Fb(){return[process.env.PI_WEB_HOSTNAME,...process.env.PI_WEB_ALLOWED_HOSTS?.split(",")??[]].filter((e)=>Boolean(e?.trim()))}function Rb(e){try{return new URL(e).origin}catch{return null}}function qF(e){let t=new URL(e.url),n=e.headers.get("host");return n?Rb(`${t.protocol}//${n}`):null}function HF(e){if(e.method!=="GET"||e.headers.get("sec-fetch-mode")!=="navigate"||e.headers.get("sec-fetch-dest")!=="document"||e.headers.get("sec-fetch-user")!=="?1")return!1;try{return/^\/api\/sessions\/[^/]+\/export$/.test(new URL(e.url).pathname)}catch{return!1}}function vd(e,t=Fb()){let n=e.headers.get("host"),r=n?kb(n):null;if(!r)return!1;if(jF(r)||Ab(r))return!0;return t.some((i)=>LF(i)===r)}function $F(e){let t=e.headers.get("origin");if(e.headers.get("sec-fetch-site")==="cross-site")return!1;if(!t)return!0;let r=qF(e);return r!==null&&Rb(t)===r}function zF(e){return e.headers.has("origin")||e.headers.has("sec-fetch-site")}function Ft(e,t=Fb()){if(!vd(e,t))return!1;if(HF(e))return!0;return!zF(e)||$F(e)}function Kn(e){let t=e.headers.get("content-type")?.split(";",1)[0]?.trim().toLowerCase();return t==="application/json"||Boolean(t?.startsWith("application/")&&t.endsWith("+json"))}import{createHash as VF,timingSafeEqual as GF}from"node:crypto";var XF="pi";function Ob(e){return VF("sha256").update(e,"utf8").digest()}function Ib(e,t){return GF(Ob(e),Ob(t))}function xd(e=process.env.PI_WEB_PASSWORD){return typeof e==="string"&&e.length>0}function Pb(e,t=process.env.PI_WEB_PASSWORD){if(!xd(t)||!e)return!1;let n=/^Basic\s+(\S+)$/i.exec(e);if(!n)return!1;let r;try{let c=Buffer.from(n[1],"base64");if(c.toString("base64")!==n[1])return!1;r=new TextDecoder("utf-8",{fatal:!0}).decode(c)}catch{return!1}let i=r.indexOf(":");if(i===-1)return!1;let o=r.slice(0,i),a=r.slice(i+1),s=Ib(o,XF),u=Ib(a,t);return s&&u}class Dd extends Request{nextUrl;constructor(e){let t=e.method!=="GET"&&e.method!=="HEAD";super(e.url,{method:e.method,headers:e.headers,body:t?e.body:void 0,duplex:t?"half":void 0,signal:e.signal});this.nextUrl=new URL(e.url)}}class w extends Response{static json(e,t){let n=new Headers(t?.headers);return n.set("content-type","application/json; charset=utf-8"),new w(JSON.stringify(e),{status:t?.status??200,statusText:t?.statusText,headers:n})}}var wd=!1,Bb=performance.now();function Mb(e){if(wd=e,Bb=performance.now(),wd)Nb("boot","debug log enabled")}function Sr(e){return(t,n)=>Nb(e,t,n)}function Nb(e,t,n){if(!wd)return;let r=performance.now()-Bb,i=new Date,o=(s,u=2)=>String(s).padStart(u,"0"),a=`${o(i.getHours())}:${o(i.getMinutes())}:${o(i.getSeconds())}.${o(i.getMilliseconds(),3)}`;console.debug(`[debug][${e}][${a}][+${r.toFixed(1)}ms] ${t}${n?` — ${n}`:""}`)}var KF=Sr("mount"),ZF=["GET","POST","PUT","PATCH","DELETE"];function te(e,t,n){let r=t.split("/").filter(Boolean),i=[],o=new Map;for(let s of r){let u=s.match(/^\[\.\.\.(.+)\]$/),c=s.match(/^\[(.+)\]$/);if(u)i.push(`:${u[1]}{.+}`),o.set(u[1],{hono:u[1],catchAll:!0});else if(c)i.push(`:${c[1]}`),o.set(c[1],{hono:c[1],catchAll:!1});else i.push(s)}let a=`/${i.join("/")}`;for(let s of ZF){let u=n[s];if(typeof u!=="function")continue;let c=u;e.on(s,a,async(d)=>{let f=performance.now(),h={};for(let[m,{hono:b,catchAll:v}]of o)if(v){let y=d.req.param(b)??"";h[m]=y===""?[]:y.split("/")}else h[m]=d.req.param(b)??"";let p=await c(new Dd(d.req.raw),{params:Promise.resolve(h)});return KF(`${s} ${d.req.path}`,`${p.status} ${Math.round(performance.now()-f)}ms`),p})}}var Rd={};ne(Rd,{GET:()=>B8});import{tmpdir as I8}from"node:os";import{Readable as P8}from"node:stream";import{constants as _d}from"node:fs";import{lstat as YF,open as JF}from"node:fs/promises";import{basename as QF,dirname as e8,resolve as Wb}from"node:path";var Ks=5242880;function Lb(e,t){let n=Wb(e);if(e8(n)!==Wb(t))return null;if(!/^pi-bash-[A-Za-z0-9_-]+\.log$/.test(QF(n)))return null;return n}async function Td(e){if(!(await YF(e)).isFile())throw Error("Bash output path is not a regular file");let n=typeof _d.O_NOFOLLOW==="number"?_d.O_NOFOLLOW:0,r=await JF(e,_d.O_RDONLY|n);try{let i=await r.stat();if(!i.isFile())throw Error("Bash output path is not a regular file");return{handle:r,fileInfo:i}}catch(i){throw await r.close(),i}}async function jb(e,t=Ks){let{handle:n,fileInfo:r}=await Td(e);try{if(r.size>t)return{tooLarge:!0,size:r.size};let i=Buffer.alloc(r.size),o=0;while(o<i.length){let a=await n.read(i,o,i.length-o,o);if(a.bytesRead===0)break;o+=a.bytesRead}return{tooLarge:!1,content:i.subarray(0,o).toString("utf8"),size:o}}finally{await n.close()}}import{open as Zb,readFile as p8,readdir as g8}from"node:fs/promises";import{existsSync as m8,readdirSync as y8}from"node:fs";import{join as Qs,normalize as kd}from"node:path";import{getAgentDir as b8,buildContextEntries as v8,buildSessionContext as x8,SessionManager as Yb}from"@earendil-works/pi-coding-agent";function t8(e){return typeof e==="object"&&e!==null&&!Array.isArray(e)}function n8(e){if(!t8(e)||e.type!=="toolCall")return null;return{type:"toolCall",toolCallId:typeof e.toolCallId==="string"?e.toolCallId:typeof e.id==="string"?e.id:"",toolName:typeof e.toolName==="string"?e.toolName:typeof e.name==="string"?e.name:"",input:typeof e.input==="object"&&e.input!==null&&!Array.isArray(e.input)?e.input:typeof e.arguments==="object"&&e.arguments!==null&&!Array.isArray(e.arguments)?e.arguments:{}}}function Ed(e){if(e.role!=="assistant")return e;let t=e.content;if(!Array.isArray(t))return e;let n=t.map((r)=>n8(r)??r);return{...e,content:n}}import qb from"node:path";function Rt(e,t=process.platform){let n=t==="win32"?qb.win32.normalize(e):qb.posix.normalize(e);return t==="win32"?n.toLowerCase():n}import{execFile as r8}from"node:child_process";import{existsSync as Ys,mkdirSync as i8,realpathSync as o8}from"node:fs";import{basename as a8,dirname as Ud,join as $b,resolve as s8}from"node:path";import{promisify as c8}from"node:util";function We(e){let t=e.replace(/\\/g,"/");return/^[a-zA-Z]:$/.test(t)?`${t}/`:t}function Sd(){if(!globalThis.__piAdditionalAllowedRoots)globalThis.__piAdditionalAllowedRoots=new Set;return globalThis.__piAdditionalAllowedRoots}function ft(e){if(!e)return;let t=We(e);Sd().add(t),globalThis.__piAllowedRootsCache?.roots.add(t)}var u8=c8(r8),Hb=60000;function l8(){if(!globalThis.__piProjectCache)globalThis.__piProjectCache=new Map;return globalThis.__piProjectCache}function zb(){globalThis.__piProjectCache?.clear()}async function Ur(e,t){let{stdout:n}=await u8("git",["-C",e,...t],{timeout:1e4,maxBuffer:1048576,env:{...process.env,LC_ALL:"C"}});return n.trim()}function Zs(e){let t=e.replace(/\\/g,"/");if(process.platform==="win32")t=t.replace(/^\/([a-zA-Z])\/(?=.)/,(n,r)=>`${r.toUpperCase()}:/`),t=t.toLowerCase();return t}function d8(e){let t=Ud(e);if(!t.endsWith("-worktrees"))return null;let n=t.slice(0,-10);if(!n||!Ys($b(n,".git")))return null;return{projectRoot:n,branch:a8(e),isWorktree:!0,isTopLevel:!0}}async function Js(e){let t=l8(),n=t.get(e);if(n&&n.expiresAt>Date.now())return n.info;let r;try{if(!Ys(e))return r=d8(e)??{projectRoot:e,branch:null,isWorktree:!1,isTopLevel:!1},t.set(e,{info:r,expiresAt:Date.now()+Hb}),r;let i=await Ur(e,["rev-parse","--path-format=absolute","--git-common-dir","--git-dir","--show-toplevel","--abbrev-ref","HEAD"]),[o,a,s,u]=i.split(`
253
253
  `).map((h)=>h.trim()),c=e;try{c=o8(e)}catch{}let d=Zs(s)===Zs(c),f=a!==o&&d;r={projectRoot:f?Ud(o):e,branch:u&&u!=="HEAD"?u:null,isWorktree:f,isTopLevel:d}}catch{r={projectRoot:e,branch:null,isWorktree:!1,isTopLevel:!1}}return t.set(e,{info:r,expiresAt:Date.now()+Hb}),r}async function f8(e){let t=await Ur(e,["rev-parse","--path-format=absolute","--git-common-dir"]);return Ud(t)}async function Ad(e){let t=await Ur(e,["worktree","list","--porcelain"]),n=[],r=null,i=()=>{if(r?.path){if(!r.prunable&&Ys(r.path))n.push({path:r.path,branch:r.branch??null,isMain:n.length===0})}r=null};for(let o of t.split(`
254
254
  `))if(o.startsWith("worktree "))i(),r={path:o.slice(9).trim()};else if(o.startsWith("branch ")&&r)r.branch=o.slice(7).trim().replace(/^refs\/heads\//,"");else if(o.startsWith("prunable")&&r)r.prunable=!0;else if(o.trim()==="")i();return i(),n}function h8(e){return e.replace(/[/\\:*?"<>|\s]+/g,"-").replace(/^-+|-+$/g,"")}async function Vb(e,t){let n=t.trim();if(!n)throw Error("Branch name is required");let r=h8(n);if(!r)throw Error(`Invalid branch name: ${t}`);let i=await f8(e),o=`${s8(i)}-worktrees`,a=$b(o,r);if(Ys(a))throw Error(`Directory already exists: ${a}`);i8(o,{recursive:!0});let s=!1;try{await Ur(i,["rev-parse","--verify","--quiet",`refs/heads/${n}`]),s=!0}catch{s=!1}try{if(s)await Ur(i,["worktree","add","--",a,n]);else await Ur(i,["worktree","add","-b",n,"--",a])}catch(u){throw Error(Xb(u),{cause:u})}return ft(a),zb(),{path:a,branch:n}}async function Gb(e,t,n=!1){let i=(await Ad(e)).find((o)=>Zs(o.path)===Zs(t));if(!i)throw Error(`Not a worktree of this repository: ${t}`);if(i.isMain)throw Error("Cannot remove the main worktree");try{await Ur(e,["worktree","remove",...n?["--force"]:[],t])}catch(o){throw Error(Xb(o),{cause:o})}zb()}function Xb(e){let t=e.stderr;if(typeof t==="string"&&t.trim())return t.trim();return e instanceof Error?e.message:String(e)}async function D8(e,t){let n=new Map;for(let o of e)n.set(Rt(o.path),o.id);let r=[...new Set(e.map((o)=>o.cwd).filter(Boolean))],i=new Map;return await Promise.all(r.map(async(o)=>{i.set(o,await Js(o))})),e.map((o)=>{Zn(o.id,o.path,t);let a=o.cwd?i.get(o.cwd):void 0;return{path:o.path,id:o.id,cwd:o.cwd,name:o.name,created:o.created instanceof Date?o.created.toISOString():String(o.created),modified:o.modified instanceof Date?o.modified.toISOString():String(o.modified),messageCount:o.messageCount,firstMessage:o.firstMessage||"(no messages)",parentSessionId:o.parentSessionPath?n.get(Rt(o.parentSessionPath)):void 0,projectRoot:a?.projectRoot??o.cwd,...a?.isWorktree&&a.branch?{worktreeBranch:a.branch}:{}}})}async function w8(){let e=await Jb(Qs(b8(),"sessions"));for(let t of e)Zn(t.id,t.path);return e}async function _8(e){let t=[],n=async(r)=>{let i;try{i=await g8(r,{withFileTypes:!0})}catch{return}for(let o of i){let a=Qs(r,o.name);if(o.isDirectory())await n(a);else if(o.name.endsWith(".jsonl"))t.push(a)}};try{await n(e)}catch{}return t}function T8(e){if(!Array.isArray(e.content))return"";return e.content.filter((t)=>!!t&&typeof t==="object"&&t.type==="text"&&typeof t.text==="string").map((t)=>t.text).join(" ")}async function E8(e){let t=await p8(e,"utf8"),n=[];for(let c of t.split(`
255
255
  `)){let d=c.trim();if(!d)continue;try{let f=JSON.parse(d);if(f&&typeof f==="object")n.push(f)}catch{}}if(n.length===0)throw Error("file contains no session entries");let r=n[0];if(r?.type!=="session"||typeof r.id!=="string")throw Error("missing session header (first line must be a session entry)");let i=new Date(r.timestamp);if(Number.isNaN(i.getTime()))throw Error(`invalid session header timestamp: ${JSON.stringify(r.timestamp)}`);let o=0,a="",s,u;for(let c of n){let d=c;if(d.type==="session_info"){let m=d.name;if(typeof m==="string"&&m.trim())s=m.trim();continue}if(d.type!=="message")continue;o++;let f=d.message;if(!f||f.role!=="user"&&f.role!=="assistant")continue;let h=typeof f.timestamp==="number"?f.timestamp:new Date(d.timestamp).getTime();if(typeof h==="number"&&!Number.isNaN(h))u=Math.max(u??0,h);if(f.role==="user"&&!a){let m=T8(f);if(m)a=m}}return{path:e,id:r.id,cwd:typeof r.cwd==="string"?r.cwd:"",name:s,parentSessionPath:typeof r.parentSession==="string"?r.parentSession:void 0,created:i,modified:typeof u==="number"&&u>0?new Date(u):i,messageCount:o,firstMessage:a||"(no messages)",allMessagesText:""}}function S8(e,t){if(e.error)return t.error?0:1;if(t.error)return-1;return e.modified<t.modified?1:e.modified>t.modified?-1:0}async function U8(e){try{let t=await Zb(e,"r");try{let n=Buffer.alloc(8192),{bytesRead:r}=await t.read(n,0,n.length,null),i=n.subarray(0,r).toString("utf8").split(`
@@ -1,4 +1,4 @@
1
- import{o as e}from"./rolldown-runtime-C_s2cVnS.js";import{o as t,s as n}from"./index-WaWNavWH.js";var r=e(n(),1),i=[],a=[];(()=>{let e=`lc,34,7n,7,7b,19,,,,2,,2,,,20,b,1c,l,g,,2t,7,2,6,2,2,,4,z,,u,r,2j,b,1m,9,9,,o,4,,9,,3,,5,17,3,1n,9,16,o,,x,1i,3,,i,,7,a,2,t,3,1k,,,7,2,2,2,3,9,,a,2,q,,2,3,1k,,,5,4,2,2,3,3,,u,2,3,,b,3,1k,,,8,,3,,3,k,2,m,6,,3,1k,,,7,2,2,2,3,7,3,a,2,u,,1n,5,3,3,,4,9,,14,5,1j,,,7,,3,,4,7,2,b,2,t,3,1k,,,7,,3,,4,7,2,b,2,f,,c,4,1j,2,,7,,3,,4,9,,a,2,t,3,1y,,4,6,,,,8,i,2,1p,,,8,c,8,2q,,,a,b,7,21,2,r,,,,,,4,2,1d,k,,2,5,b,,10,9,,2u,b,,6,n,4,4,3,g,4,d,,,3,6,,f,,jj,3,qa,4,s,3,t,2,u,2,1s,w,9,,19,3,,,39,2,y,,3a,c,4,c,63,5,1l,a,,,,,2,o,2,,1c,1a,2,c,k,5,1b,h,12,9,c,3,u,d,1k,e,1c,k,48,3,,l,4,,6,,2,3,5i,1s,ek,,5f,x,2da,3,3x,,2o,w,fe,6,2x,2,n9w,4,,a,w,2,28,2,7k,,3,,4,,n,5,4,,2b,2,1e,i,q,i,d,,12,8,p,d,18,4,1b,e,10,,1v,e,c,,8,2,1a,,1f,,,3,2,2,5,2,,,15,5,5,2,6k,8,,2,fn4,,kh,g,g,g,a6,2,gt,,6a,,45,5,1ae,3,,2,5,4,14,3,4,,4l,2,fx,4,1t,5,8t,2,25,6,1y,b,1d,4,3e,3,1h,f,15,,2,2,a,4,19,b,7,,1p,3,10,e,g,2,18,,c,3,1c,e,8,4,,2,2k,c,6,,2,,4d,c,l,4,1j,2,,7,2,2,2,3,9,,a,2,2,7,3,5,1v,9,,,2,,,4,,5,,,e,2,2a,i,n,,29,k,6j,7,2,9,r,2,2a,h,2y,d,2t,3,2,a,74,f,6t,6,,2,2,4,,,,2,3x,7,2,7,3,,s,a,14,7,,4,8,,9,b,1a,g,5i,8,5j,8,,8,2a,m,,e,3e,6,3,,,2,,7,,,1u,5,,2,,5,9n,4,9,2,,,1c,7,3,5,n,,44l,,6,f,8ug,i,1xc,5,1n,7,t4,,,1j,7,4,29,,b,2,f57,2,3mp,1a,2,n,f2,5,3,6,8,8,2,7,u,4,44,3,1iz,1j,4,1e,8,,e,,m,5,,f,11s,7,,h,2,7,,2,,5,2s,,4g,7,af,,1p,4,e4,4,72,2,6r,,2,,7,2,5,,d6,7,31,7,240,5`.split(`,`).map(e=>e?parseInt(e,36):1);for(let t=0,n=0;t<e.length;t++)(t%2?a:i).push(n+=e[t])})();function o(e){if(e<768)return!1;for(let t=0,n=i.length;;){let r=t+n>>1;if(e<i[r])n=r;else if(e>=a[r])t=r+1;else return!0;if(t==n)return!1}}function s(e){return e>=127462&&e<=127487}var c=8205;function l(e,t,n=!0,r=!0){return(n?u:d)(e,t,r)}function u(e,t,n){if(t==e.length)return t;t&&p(e.charCodeAt(t))&&m(e.charCodeAt(t-1))&&t--;let r=f(e,t);for(t+=h(r);t<e.length;){let i=f(e,t);if(r==c||i==c||n&&o(i))t+=h(i),r=i;else if(s(i)){let n=0,r=t-2;for(;r>=0&&s(f(e,r));)n++,r-=2;if(n%2==0)break;t+=2}else break}return t}function d(e,t,n){for(;t>1;){let r=u(e,t-2,n);if(r<t)return r;t--}return 0}function f(e,t){let n=e.charCodeAt(t);if(!m(n)||t+1==e.length)return n;let r=e.charCodeAt(t+1);return p(r)?(n-55296<<10)+(r-56320)+65536:n}function p(e){return e>=56320&&e<57344}function m(e){return e>=55296&&e<56320}function h(e){return e<65536?1:2}var g=class e{lineAt(e){if(e<0||e>this.length)throw RangeError(`Invalid position ${e} in document of length ${this.length}`);return this.lineInner(e,!1,1,0)}line(e){if(e<1||e>this.lines)throw RangeError(`Invalid line number ${e} in ${this.lines}-line document`);return this.lineInner(e,!0,1,0)}replace(e,t,n){[e,t]=ae(this,e,t);let r=[];return this.decompose(0,e,r,2),n.length&&n.decompose(0,n.length,r,3),this.decompose(t,this.length,r,1),v.from(r,this.length-(t-e)+n.length)}append(e){return this.replace(this.length,this.length,e)}slice(e,t=this.length){[e,t]=ae(this,e,t);let n=[];return this.decompose(e,t,n,0),v.from(n,t-e)}eq(e){if(e==this)return!0;if(e.length!=this.length||e.lines!=this.lines)return!1;let t=this.scanIdentical(e,1),n=this.length-this.scanIdentical(e,-1),r=new b(this),i=new b(e);for(let e=t,a=t;;){if(r.next(e),i.next(e),e=0,r.lineBreak!=i.lineBreak||r.done!=i.done||r.value!=i.value)return!1;if(a+=r.value.length,r.done||a>=n)return!0}}iter(e=1){return new b(this,e)}iterRange(e,t=this.length){return new ne(this,e,t)}iterLines(e,t){let n;if(e==null)n=this.iter();else{t??=this.lines+1;let r=this.line(e).from;n=this.iterRange(r,Math.max(r,t==this.lines+1?this.length:t<=1?0:this.line(t-1).to))}return new re(n)}toString(){return this.sliceString(0)}toJSON(){let e=[];return this.flatten(e),e}constructor(){}static of(t){if(t.length==0)throw RangeError(`A document must have at least one line`);return t.length==1&&!t[0]?e.empty:t.length<=32?new _(t):v.from(_.split(t,[]))}},_=class e extends g{constructor(e,t=y(e)){super(),this.text=e,this.length=t}get lines(){return this.text.length}get children(){return null}lineInner(e,t,n,r){for(let i=0;;i++){let a=this.text[i],o=r+a.length;if((t?n:o)>=e)return new ie(r,o,n,a);r=o+1,n++}}decompose(t,n,r,i){let a=t<=0&&n>=this.length?this:new e(te(this.text,t,n),Math.min(n,this.length)-Math.max(0,t));if(i&1){let t=r.pop(),n=ee(a.text,t.text.slice(),0,a.length);if(n.length<=32)r.push(new e(n,t.length+a.length));else{let t=n.length>>1;r.push(new e(n.slice(0,t)),new e(n.slice(t)))}}else r.push(a)}replace(t,n,r){if(!(r instanceof e))return super.replace(t,n,r);[t,n]=ae(this,t,n);let i=ee(this.text,ee(r.text,te(this.text,0,t)),n),a=this.length+r.length-(n-t);return i.length<=32?new e(i,a):v.from(e.split(i,[]),a)}sliceString(e,t=this.length,n=`
1
+ import{o as e}from"./rolldown-runtime-C_s2cVnS.js";import{o as t,s as n}from"./index-BVb1AG6p.js";var r=e(n(),1),i=[],a=[];(()=>{let e=`lc,34,7n,7,7b,19,,,,2,,2,,,20,b,1c,l,g,,2t,7,2,6,2,2,,4,z,,u,r,2j,b,1m,9,9,,o,4,,9,,3,,5,17,3,1n,9,16,o,,x,1i,3,,i,,7,a,2,t,3,1k,,,7,2,2,2,3,9,,a,2,q,,2,3,1k,,,5,4,2,2,3,3,,u,2,3,,b,3,1k,,,8,,3,,3,k,2,m,6,,3,1k,,,7,2,2,2,3,7,3,a,2,u,,1n,5,3,3,,4,9,,14,5,1j,,,7,,3,,4,7,2,b,2,t,3,1k,,,7,,3,,4,7,2,b,2,f,,c,4,1j,2,,7,,3,,4,9,,a,2,t,3,1y,,4,6,,,,8,i,2,1p,,,8,c,8,2q,,,a,b,7,21,2,r,,,,,,4,2,1d,k,,2,5,b,,10,9,,2u,b,,6,n,4,4,3,g,4,d,,,3,6,,f,,jj,3,qa,4,s,3,t,2,u,2,1s,w,9,,19,3,,,39,2,y,,3a,c,4,c,63,5,1l,a,,,,,2,o,2,,1c,1a,2,c,k,5,1b,h,12,9,c,3,u,d,1k,e,1c,k,48,3,,l,4,,6,,2,3,5i,1s,ek,,5f,x,2da,3,3x,,2o,w,fe,6,2x,2,n9w,4,,a,w,2,28,2,7k,,3,,4,,n,5,4,,2b,2,1e,i,q,i,d,,12,8,p,d,18,4,1b,e,10,,1v,e,c,,8,2,1a,,1f,,,3,2,2,5,2,,,15,5,5,2,6k,8,,2,fn4,,kh,g,g,g,a6,2,gt,,6a,,45,5,1ae,3,,2,5,4,14,3,4,,4l,2,fx,4,1t,5,8t,2,25,6,1y,b,1d,4,3e,3,1h,f,15,,2,2,a,4,19,b,7,,1p,3,10,e,g,2,18,,c,3,1c,e,8,4,,2,2k,c,6,,2,,4d,c,l,4,1j,2,,7,2,2,2,3,9,,a,2,2,7,3,5,1v,9,,,2,,,4,,5,,,e,2,2a,i,n,,29,k,6j,7,2,9,r,2,2a,h,2y,d,2t,3,2,a,74,f,6t,6,,2,2,4,,,,2,3x,7,2,7,3,,s,a,14,7,,4,8,,9,b,1a,g,5i,8,5j,8,,8,2a,m,,e,3e,6,3,,,2,,7,,,1u,5,,2,,5,9n,4,9,2,,,1c,7,3,5,n,,44l,,6,f,8ug,i,1xc,5,1n,7,t4,,,1j,7,4,29,,b,2,f57,2,3mp,1a,2,n,f2,5,3,6,8,8,2,7,u,4,44,3,1iz,1j,4,1e,8,,e,,m,5,,f,11s,7,,h,2,7,,2,,5,2s,,4g,7,af,,1p,4,e4,4,72,2,6r,,2,,7,2,5,,d6,7,31,7,240,5`.split(`,`).map(e=>e?parseInt(e,36):1);for(let t=0,n=0;t<e.length;t++)(t%2?a:i).push(n+=e[t])})();function o(e){if(e<768)return!1;for(let t=0,n=i.length;;){let r=t+n>>1;if(e<i[r])n=r;else if(e>=a[r])t=r+1;else return!0;if(t==n)return!1}}function s(e){return e>=127462&&e<=127487}var c=8205;function l(e,t,n=!0,r=!0){return(n?u:d)(e,t,r)}function u(e,t,n){if(t==e.length)return t;t&&p(e.charCodeAt(t))&&m(e.charCodeAt(t-1))&&t--;let r=f(e,t);for(t+=h(r);t<e.length;){let i=f(e,t);if(r==c||i==c||n&&o(i))t+=h(i),r=i;else if(s(i)){let n=0,r=t-2;for(;r>=0&&s(f(e,r));)n++,r-=2;if(n%2==0)break;t+=2}else break}return t}function d(e,t,n){for(;t>1;){let r=u(e,t-2,n);if(r<t)return r;t--}return 0}function f(e,t){let n=e.charCodeAt(t);if(!m(n)||t+1==e.length)return n;let r=e.charCodeAt(t+1);return p(r)?(n-55296<<10)+(r-56320)+65536:n}function p(e){return e>=56320&&e<57344}function m(e){return e>=55296&&e<56320}function h(e){return e<65536?1:2}var g=class e{lineAt(e){if(e<0||e>this.length)throw RangeError(`Invalid position ${e} in document of length ${this.length}`);return this.lineInner(e,!1,1,0)}line(e){if(e<1||e>this.lines)throw RangeError(`Invalid line number ${e} in ${this.lines}-line document`);return this.lineInner(e,!0,1,0)}replace(e,t,n){[e,t]=ae(this,e,t);let r=[];return this.decompose(0,e,r,2),n.length&&n.decompose(0,n.length,r,3),this.decompose(t,this.length,r,1),v.from(r,this.length-(t-e)+n.length)}append(e){return this.replace(this.length,this.length,e)}slice(e,t=this.length){[e,t]=ae(this,e,t);let n=[];return this.decompose(e,t,n,0),v.from(n,t-e)}eq(e){if(e==this)return!0;if(e.length!=this.length||e.lines!=this.lines)return!1;let t=this.scanIdentical(e,1),n=this.length-this.scanIdentical(e,-1),r=new b(this),i=new b(e);for(let e=t,a=t;;){if(r.next(e),i.next(e),e=0,r.lineBreak!=i.lineBreak||r.done!=i.done||r.value!=i.value)return!1;if(a+=r.value.length,r.done||a>=n)return!0}}iter(e=1){return new b(this,e)}iterRange(e,t=this.length){return new ne(this,e,t)}iterLines(e,t){let n;if(e==null)n=this.iter();else{t??=this.lines+1;let r=this.line(e).from;n=this.iterRange(r,Math.max(r,t==this.lines+1?this.length:t<=1?0:this.line(t-1).to))}return new re(n)}toString(){return this.sliceString(0)}toJSON(){let e=[];return this.flatten(e),e}constructor(){}static of(t){if(t.length==0)throw RangeError(`A document must have at least one line`);return t.length==1&&!t[0]?e.empty:t.length<=32?new _(t):v.from(_.split(t,[]))}},_=class e extends g{constructor(e,t=y(e)){super(),this.text=e,this.length=t}get lines(){return this.text.length}get children(){return null}lineInner(e,t,n,r){for(let i=0;;i++){let a=this.text[i],o=r+a.length;if((t?n:o)>=e)return new ie(r,o,n,a);r=o+1,n++}}decompose(t,n,r,i){let a=t<=0&&n>=this.length?this:new e(te(this.text,t,n),Math.min(n,this.length)-Math.max(0,t));if(i&1){let t=r.pop(),n=ee(a.text,t.text.slice(),0,a.length);if(n.length<=32)r.push(new e(n,t.length+a.length));else{let t=n.length>>1;r.push(new e(n.slice(0,t)),new e(n.slice(t)))}}else r.push(a)}replace(t,n,r){if(!(r instanceof e))return super.replace(t,n,r);[t,n]=ae(this,t,n);let i=ee(this.text,ee(r.text,te(this.text,0,t)),n),a=this.length+r.length-(n-t);return i.length<=32?new e(i,a):v.from(e.split(i,[]),a)}sliceString(e,t=this.length,n=`
2
2
  `){[e,t]=ae(this,e,t);let r=``;for(let i=0,a=0;i<=t&&a<this.text.length;a++){let o=this.text[a],s=i+o.length;i>e&&a&&(r+=n),e<s&&t>i&&(r+=o.slice(Math.max(0,e-i),t-i)),i=s+1}return r}flatten(e){for(let t of this.text)e.push(t)}scanIdentical(){return 0}static split(t,n){let r=[],i=-1;for(let a of t)r.push(a),i+=a.length+1,r.length==32&&(n.push(new e(r,i)),r=[],i=-1);return i>-1&&n.push(new e(r,i)),n}},v=class e extends g{constructor(e,t){super(),this.children=e,this.length=t,this.lines=0;for(let t of e)this.lines+=t.lines}lineInner(e,t,n,r){for(let i=0;;i++){let a=this.children[i],o=r+a.length,s=n+a.lines-1;if((t?s:o)>=e)return a.lineInner(e,t,n,r);r=o+1,n=s+1}}decompose(e,t,n,r){for(let i=0,a=0;a<=t&&i<this.children.length;i++){let o=this.children[i],s=a+o.length;if(e<=s&&t>=a){let i=r&(a<=e|(s>=t?2:0));a>=e&&s<=t&&!i?n.push(o):o.decompose(e-a,t-a,n,i)}a=s+1}}replace(t,n,r){if([t,n]=ae(this,t,n),r.lines<this.lines)for(let i=0,a=0;i<this.children.length;i++){let o=this.children[i],s=a+o.length;if(t>=a&&n<=s){let c=o.replace(t-a,n-a,r),l=this.lines-o.lines+c.lines;if(c.lines<l>>4&&c.lines>l>>6){let a=this.children.slice();return a[i]=c,new e(a,this.length-(n-t)+r.length)}return super.replace(a,s,c)}a=s+1}return super.replace(t,n,r)}sliceString(e,t=this.length,n=`
3
3
  `){[e,t]=ae(this,e,t);let r=``;for(let i=0,a=0;i<this.children.length&&a<=t;i++){let o=this.children[i],s=a+o.length;a>e&&i&&(r+=n),e<s&&t>a&&(r+=o.sliceString(e-a,t-a,n)),a=s+1}return r}flatten(e){for(let t of this.children)t.flatten(e)}scanIdentical(t,n){if(!(t instanceof e))return 0;let r=0,[i,a,o,s]=n>0?[0,0,this.children.length,t.children.length]:[this.children.length-1,t.children.length-1,-1,-1];for(;;i+=n,a+=n){if(i==o||a==s)return r;let e=this.children[i],c=t.children[a];if(e!=c)return r+e.scanIdentical(c,n);r+=e.length+1}}static from(t,n=t.reduce((e,t)=>e+t.length+1,-1)){let r=0;for(let e of t)r+=e.lines;if(r<32){let e=[];for(let n of t)n.flatten(e);return new _(e,n)}let i=Math.max(32,r>>5),a=i<<1,o=i>>1,s=[],c=0,l=-1,u=[];function d(t){let n;if(t.lines>a&&t instanceof e)for(let e of t.children)d(e);else t.lines>o&&(c>o||!c)?(f(),s.push(t)):t instanceof _&&c&&(n=u[u.length-1])instanceof _&&t.lines+n.lines<=32?(c+=t.lines,l+=t.length+1,u[u.length-1]=new _(n.text.concat(t.text),n.length+1+t.length)):(c+t.lines>i&&f(),c+=t.lines,l+=t.length+1,u.push(t))}function f(){c!=0&&(s.push(u.length==1?u[0]:e.from(u,l)),l=-1,c=u.length=0)}for(let e of t)d(e);return f(),s.length==1?s[0]:new e(s,n)}};g.empty=new _([``],0);function y(e){let t=-1;for(let n of e)t+=n.length+1;return t}function ee(e,t,n=0,r=1e9){for(let i=0,a=0,o=!0;a<e.length&&i<=r;a++){let s=e[a],c=i+s.length;c>=n&&(c>r&&(s=s.slice(0,r-i)),i<n&&(s=s.slice(n-i)),o?(t[t.length-1]+=s,o=!1):t.push(s)),i=c+1}return t}function te(e,t,n){return ee(e,[``],t,n)}var b=class{constructor(e,t=1){this.dir=t,this.done=!1,this.lineBreak=!1,this.value=``,this.nodes=[e],this.offsets=[t>0?1:(e instanceof _?e.text.length:e.children.length)<<1]}nextInner(e,t){for(this.done=this.lineBreak=!1;;){let n=this.nodes.length-1,r=this.nodes[n],i=this.offsets[n],a=i>>1,o=r instanceof _?r.text.length:r.children.length;if(a==(t>0?o:0)){if(n==0)return this.done=!0,this.value=``,this;t>0&&this.offsets[n-1]++,this.nodes.pop(),this.offsets.pop()}else if((i&1)==(t>0?0:1)){if(this.offsets[n]+=t,e==0)return this.lineBreak=!0,this.value=`
4
4
  `,this;e--}else if(r instanceof _){let i=r.text[a+(t<0?-1:0)];if(this.offsets[n]+=t,i.length>Math.max(0,e))return this.value=e==0?i:t>0?i.slice(e):i.slice(0,i.length-e),this;e-=i.length}else{let i=r.children[a+(t<0?-1:0)];e>i.length?(e-=i.length,this.offsets[n]+=t):(t<0&&this.offsets[n]--,this.nodes.push(i),this.offsets.push(t>0?1:(i instanceof _?i.text.length:i.children.length)<<1))}}}next(e=0){return e<0&&(this.nextInner(-e,-this.dir),e=this.value.length),this.nextInner(e,this.dir)}},ne=class{constructor(e,t,n){this.value=``,this.done=!1,this.cursor=new b(e,t>n?-1:1),this.pos=t>n?e.length:0,this.from=Math.min(t,n),this.to=Math.max(t,n)}nextInner(e,t){if(t<0?this.pos<=this.from:this.pos>=this.to)return this.value=``,this.done=!0,this;e+=Math.max(0,t<0?this.pos-this.to:this.from-this.pos);let n=t<0?this.pos-this.from:this.to-this.pos;e>n&&(e=n),n-=e;let{value:r}=this.cursor.next(e);return this.pos+=(r.length+e)*t,this.value=r.length<=n?r:t<0?r.slice(r.length-n):r.slice(0,n),this.done=!this.value,this}next(e=0){return e<0?e=Math.max(e,this.from-this.pos):e>0&&(e=Math.min(e,this.to-this.pos)),this.nextInner(e,this.cursor.dir)}get lineBreak(){return this.cursor.lineBreak&&this.value!=``}},re=class{constructor(e){this.inner=e,this.afterBreak=!0,this.value=``,this.done=!1}next(e=0){let{done:t,lineBreak:n,value:r}=this.inner.next(e);return t&&this.afterBreak?(this.value=``,this.afterBreak=!1):t?(this.done=!0,this.value=``):n?this.afterBreak?this.value=``:(this.afterBreak=!0,this.next()):(this.value=r,this.afterBreak=!1),this}get lineBreak(){return!1}};typeof Symbol<`u`&&(g.prototype[Symbol.iterator]=function(){return this.iter()},b.prototype[Symbol.iterator]=ne.prototype[Symbol.iterator]=re.prototype[Symbol.iterator]=function(){return this});var ie=class{constructor(e,t,n,r){this.from=e,this.to=t,this.number=n,this.text=r}get length(){return this.to-this.from}};function ae(e,t,n){return t=Math.max(0,Math.min(e.length,t)),[t,Math.max(t,Math.min(e.length,n))]}function x(e,t,n=!0,r=!0){return l(e,t,n,r)}function oe(e){return e>=56320&&e<57344}function se(e){return e>=55296&&e<56320}function S(e,t){let n=e.charCodeAt(t);if(!se(n)||t+1==e.length)return n;let r=e.charCodeAt(t+1);return oe(r)?(n-55296<<10)+(r-56320)+65536:n}function ce(e){return e<=65535?String.fromCharCode(e):(e-=65536,String.fromCharCode((e>>10)+55296,(e&1023)+56320))}function le(e){return e<65536?1:2}var ue=/\r\n?|\n/,C=(function(e){return e[e.Simple=0]=`Simple`,e[e.TrackDel=1]=`TrackDel`,e[e.TrackBefore=2]=`TrackBefore`,e[e.TrackAfter=3]=`TrackAfter`,e})(C||={}),de=class e{constructor(e){this.sections=e}get length(){let e=0;for(let t=0;t<this.sections.length;t+=2)e+=this.sections[t];return e}get newLength(){let e=0;for(let t=0;t<this.sections.length;t+=2){let n=this.sections[t+1];e+=n<0?this.sections[t]:n}return e}get empty(){return this.sections.length==0||this.sections.length==2&&this.sections[1]<0}iterGaps(e){for(let t=0,n=0,r=0;t<this.sections.length;){let i=this.sections[t++],a=this.sections[t++];a<0?(e(n,r,i),r+=i):r+=a,n+=i}}iterChangedRanges(e,t=!1){me(this,e,t)}get invertedDesc(){let t=[];for(let e=0;e<this.sections.length;){let n=this.sections[e++],r=this.sections[e++];r<0?t.push(n,r):t.push(r,n)}return new e(t)}composeDesc(e){return this.empty?e:e.empty?this:ge(this,e)}mapDesc(e,t=!1){return e.empty?this:he(this,e,t)}mapPos(e,t=-1,n=C.Simple){let r=0,i=0;for(let a=0;a<this.sections.length;){let o=this.sections[a++],s=this.sections[a++],c=r+o;if(s<0){if(c>e)return i+(e-r);i+=o}else{if(n!=C.Simple&&c>=e&&(n==C.TrackDel&&r<e&&c>e||n==C.TrackBefore&&r<e||n==C.TrackAfter&&c>e))return null;if(c>e||c==e&&t<0&&!o)return e==r||t<0?i:i+s;i+=s}r=c}if(e>r)throw RangeError(`Position ${e} is out of range for changeset of length ${r}`);return i}touchesRange(e,t=e){for(let n=0,r=0;n<this.sections.length&&r<=t;){let i=this.sections[n++],a=this.sections[n++],o=r+i;if(a>=0&&r<=t&&o>=e)return r<e&&o>t?`cover`:!0;r=o}return!1}toString(){let e=``;for(let t=0;t<this.sections.length;){let n=this.sections[t++],r=this.sections[t++];e+=(e?` `:``)+n+(r>=0?`:`+r:``)}return e}toJSON(){return this.sections}static fromJSON(t){if(!Array.isArray(t)||t.length%2||t.some(e=>typeof e!=`number`))throw RangeError(`Invalid JSON representation of ChangeDesc`);return new e(t)}static create(t){return new e(t)}},fe=class e extends de{constructor(e,t){super(e),this.inserted=t}apply(e){if(this.length!=e.length)throw RangeError(`Applying change set to a document with the wrong length`);return me(this,(t,n,r,i,a)=>e=e.replace(r,r+(n-t),a),!1),e}mapDesc(e,t=!1){return he(this,e,t,!0)}invert(t){let n=this.sections.slice(),r=[];for(let e=0,i=0;e<n.length;e+=2){let a=n[e],o=n[e+1];if(o>=0){n[e]=o,n[e+1]=a;let s=e>>1;for(;r.length<s;)r.push(g.empty);r.push(a?t.slice(i,i+a):g.empty)}i+=a}return new e(n,r)}compose(e){return this.empty?e:e.empty?this:ge(this,e,!0)}map(e,t=!1){return e.empty?this:he(this,e,t,!0)}iterChanges(e,t=!1){me(this,e,t)}get desc(){return de.create(this.sections)}filter(t){let n=[],r=[],i=[],a=new _e(this);done:for(let e=0,o=0;;){let s=e==t.length?1e9:t[e++];for(;o<s||o==s&&a.len==0;){if(a.done)break done;let e=Math.min(a.len,s-o);w(i,e,-1);let t=a.ins==-1?-1:a.off==0?a.ins:0;w(n,e,t),t>0&&pe(r,n,a.text),a.forward(e),o+=e}let c=t[e++];for(;o<c;){if(a.done)break done;let e=Math.min(a.len,c-o);w(n,e,-1),w(i,e,a.ins==-1?-1:a.off==0?a.ins:0),a.forward(e),o+=e}}return{changes:new e(n,r),filtered:de.create(i)}}toJSON(){let e=[];for(let t=0;t<this.sections.length;t+=2){let n=this.sections[t],r=this.sections[t+1];r<0?e.push(n):r==0?e.push([n]):e.push([n].concat(this.inserted[t>>1].toJSON()))}return e}static of(t,n,r){let i=[],a=[],o=0,s=null;function c(t=!1){if(!t&&!i.length)return;o<n&&w(i,n-o,-1);let r=new e(i,a);s=s?s.compose(r.map(s)):r,i=[],a=[],o=0}function l(t){if(Array.isArray(t))for(let e of t)l(e);else if(t instanceof e){if(t.length!=n)throw RangeError(`Mismatched change set length (got ${t.length}, expected ${n})`);c(),s=s?s.compose(t.map(s)):t}else{let{from:e,to:s=e,insert:l}=t;if(e>s||e<0||s>n)throw RangeError(`Invalid change range ${e} to ${s} (in doc of length ${n})`);let u=l?typeof l==`string`?g.of(l.split(r||ue)):l:g.empty,d=u.length;if(e==s&&d==0)return;e<o&&c(),e>o&&w(i,e-o,-1),w(i,s-e,d),pe(a,i,u),o=s}}return l(t),c(!s),s}static empty(t){return new e(t?[t,-1]:[],[])}static fromJSON(t){if(!Array.isArray(t))throw RangeError(`Invalid JSON representation of ChangeSet`);let n=[],r=[];for(let e=0;e<t.length;e++){let i=t[e];if(typeof i==`number`)n.push(i,-1);else if(!Array.isArray(i)||typeof i[0]!=`number`||i.some((e,t)=>t&&typeof e!=`string`))throw RangeError(`Invalid JSON representation of ChangeSet`);else if(i.length==1)n.push(i[0],0);else{for(;r.length<e;)r.push(g.empty);r[e]=g.of(i.slice(1)),n.push(i[0],r[e].length)}}return new e(n,r)}static createSet(t,n){return new e(t,n)}};function w(e,t,n,r=!1){if(t==0&&n<=0)return;let i=e.length-2;i>=0&&n<=0&&n==e[i+1]?e[i]+=t:i>=0&&t==0&&e[i]==0?e[i+1]+=n:r?(e[i]+=t,e[i+1]+=n):e.push(t,n)}function pe(e,t,n){if(n.length==0)return;let r=t.length-2>>1;if(r<e.length)e[e.length-1]=e[e.length-1].append(n);else{for(;e.length<r;)e.push(g.empty);e.push(n)}}function me(e,t,n){let r=e.inserted;for(let i=0,a=0,o=0;o<e.sections.length;){let s=e.sections[o++],c=e.sections[o++];if(c<0)i+=s,a+=s;else{let l=i,u=a,d=g.empty;for(;l+=s,u+=c,c&&r&&(d=d.append(r[o-2>>1])),!(n||o==e.sections.length||e.sections[o+1]<0);)s=e.sections[o++],c=e.sections[o++];t(i,l,a,u,d),i=l,a=u}}}function he(e,t,n,r=!1){let i=[],a=r?[]:null,o=new _e(e),s=new _e(t);for(let e=-1;;)if(o.done&&s.len||s.done&&o.len)throw Error(`Mismatched change set lengths`);else if(o.ins==-1&&s.ins==-1){let e=Math.min(o.len,s.len);w(i,e,-1),o.forward(e),s.forward(e)}else if(s.ins>=0&&(o.ins<0||e==o.i||o.off==0&&(s.len<o.len||s.len==o.len&&!n))){let t=s.len;for(w(i,s.ins,-1);t;){let n=Math.min(o.len,t);o.ins>=0&&e<o.i&&o.len<=n&&(w(i,0,o.ins),a&&pe(a,i,o.text),e=o.i),o.forward(n),t-=n}s.next()}else if(o.ins>=0){let t=0,n=o.len;for(;n;)if(s.ins==-1){let e=Math.min(n,s.len);t+=e,n-=e,s.forward(e)}else if(s.ins==0&&s.len<n)n-=s.len,s.next();else break;w(i,t,e<o.i?o.ins:0),a&&e<o.i&&pe(a,i,o.text),e=o.i,o.forward(o.len-n)}else if(o.done&&s.done)return a?fe.createSet(i,a):de.create(i);else throw Error(`Mismatched change set lengths`)}function ge(e,t,n=!1){let r=[],i=n?[]:null,a=new _e(e),o=new _e(t);for(let e=!1;;)if(a.done&&o.done)return i?fe.createSet(r,i):de.create(r);else if(a.ins==0)w(r,a.len,0,e),a.next();else if(o.len==0&&!o.done)w(r,0,o.ins,e),i&&pe(i,r,o.text),o.next();else if(a.done||o.done)throw Error(`Mismatched change set lengths`);else{let t=Math.min(a.len2,o.len),n=r.length;if(a.ins==-1){let n=o.ins==-1?-1:o.off?0:o.ins;w(r,t,n,e),i&&n&&pe(i,r,o.text)}else o.ins==-1?(w(r,a.off?0:a.len,t,e),i&&pe(i,r,a.textBit(t))):(w(r,a.off?0:a.len,o.off?0:o.ins,e),i&&!o.off&&pe(i,r,o.text));e=(a.ins>t||o.ins>=0&&o.len>t)&&(e||r.length>n),a.forward2(t),o.forward(t)}}var _e=class{constructor(e){this.set=e,this.i=0,this.next()}next(){let{sections:e}=this.set;this.i<e.length?(this.len=e[this.i++],this.ins=e[this.i++]):(this.len=0,this.ins=-2),this.off=0}get done(){return this.ins==-2}get len2(){return this.ins<0?this.len:this.ins}get text(){let{inserted:e}=this.set,t=this.i-2>>1;return t>=e.length?g.empty:e[t]}textBit(e){let{inserted:t}=this.set,n=this.i-2>>1;return n>=t.length&&!e?g.empty:t[n].slice(this.off,e==null?void 0:this.off+e)}forward(e){e==this.len?this.next():(this.len-=e,this.off+=e)}forward2(e){this.ins==-1?this.forward(e):e==this.ins?this.next():(this.ins-=e,this.off+=e)}},ve=class e{constructor(e,t,n,r){this.from=e,this.to=t,this.flags=n,this.goalColumn=r}get anchor(){return this.flags&32?this.to:this.from}get head(){return this.flags&32?this.from:this.to}get empty(){return this.from==this.to}get assoc(){return this.flags&8?-1:this.flags&16?1:0}get undirectional(){return(this.flags&64)>0}get bidiLevel(){let e=this.flags&7;return e==7?null:e}map(t,n=-1){let r,i;return this.empty?r=i=t.mapPos(this.from,n):(r=t.mapPos(this.from,1),i=t.mapPos(this.to,-1)),r==this.from&&i==this.to?this:new e(r,i,this.flags,this.goalColumn)}extend(e,t=e,n=0){if(e<=this.anchor&&t>=this.anchor)return T.range(e,t,void 0,void 0,n);let r=Math.abs(e-this.anchor)>Math.abs(t-this.anchor)?e:t;return T.range(this.anchor,r,void 0,void 0,n)}eq(e,t=!1){return this.anchor==e.anchor&&this.head==e.head&&this.goalColumn==e.goalColumn&&(!t||!this.empty||this.assoc==e.assoc)}toJSON(){return{anchor:this.anchor,head:this.head}}static fromJSON(e){if(!e||typeof e.anchor!=`number`||typeof e.head!=`number`)throw RangeError(`Invalid JSON representation for SelectionRange`);return T.range(e.anchor,e.head)}static create(t,n,r,i){return new e(t,n,r,i)}},T=class e{constructor(e,t){this.ranges=e,this.mainIndex=t}map(t,n=-1){return t.empty?this:e.create(this.ranges.map(e=>e.map(t,n)),this.mainIndex)}eq(e,t=!1){if(this.ranges.length!=e.ranges.length||this.mainIndex!=e.mainIndex)return!1;for(let n=0;n<this.ranges.length;n++)if(!this.ranges[n].eq(e.ranges[n],t))return!1;return!0}get main(){return this.ranges[this.mainIndex]}asSingle(){return this.ranges.length==1?this:new e([this.main],0)}addRange(t,n=!0){return e.create([t].concat(this.ranges),n?0:this.mainIndex+1)}replaceRange(t,n=this.mainIndex){let r=this.ranges.slice();return r[n]=t,e.create(r,this.mainIndex)}toJSON(){return{ranges:this.ranges.map(e=>e.toJSON()),main:this.mainIndex}}static fromJSON(t){if(!t||!Array.isArray(t.ranges)||typeof t.main!=`number`||t.main>=t.ranges.length)throw RangeError(`Invalid JSON representation for EditorSelection`);return new e(t.ranges.map(e=>ve.fromJSON(e)),t.main)}static single(t,n=t){return new e([e.range(t,n)],0)}static create(t,n=0){if(t.length==0)throw RangeError(`A selection needs at least one range`);for(let r=0,i=0;i<t.length;i++){let a=t[i];if(a.empty?a.from<=r:a.from<r)return e.normalized(t.slice(),n);r=a.to}return new e(t,n)}static cursor(e,t=0,n,r){return ve.create(e,e,(t==0?0:t<0?8:16)|(n==null?7:Math.min(6,n)),r)}static range(e,t,n,r,i){let a=r==null?7:Math.min(6,r);return!i&&e!=t&&(i=t<e?1:-1),i&&(a|=i<0?8:16),t<e?ve.create(t,e,a|32,n):ve.create(e,t,a,n)}static undirectionalRange(e,t){return ve.create(e,t,64,void 0)}static normalized(t,n=0){let r=t[n];t.sort((e,t)=>e.from-t.from),n=t.indexOf(r);for(let r=1;r<t.length;r++){let i=t[r],a=t[r-1];if(i.empty?i.from<=a.to:i.from<a.to){let o=a.from,s=Math.max(i.to,a.to);r<=n&&n--,t.splice(--r,2,i.anchor>i.head?e.range(s,o):e.range(o,s))}}return new e(t,n)}};function ye(e,t){for(let n of e.ranges)if(n.to>t)throw RangeError(`Selection points outside of document`)}var be=0,E=class e{constructor(e,t,n,r,i){this.combine=e,this.compareInput=t,this.compare=n,this.isStatic=r,this.id=be++,this.default=e([]),this.extensions=typeof i==`function`?i(this):i}get reader(){return this}static define(t={}){return new e(t.combine||(e=>e),t.compareInput||((e,t)=>e===t),t.compare||(t.combine?(e,t)=>e===t:xe),!!t.static,t.enables)}of(e){return new Se([],this,0,e)}compute(e,t){if(this.isStatic)throw Error(`Can't compute a static facet`);return new Se(e,this,1,t)}computeN(e,t){if(this.isStatic)throw Error(`Can't compute a static facet`);return new Se(e,this,2,t)}from(e,t){return t||=e=>e,this.compute([e],n=>t(n.field(e)))}};function xe(e,t){return e==t||e.length==t.length&&e.every((e,n)=>e===t[n])}var Se=class{constructor(e,t,n,r){this.dependencies=e,this.facet=t,this.type=n,this.value=r,this.id=be++}dynamicSlot(e){let t=this.value,n=this.facet.compareInput,r=this.id,i=e[r]>>1,a=this.type==2,o=!1,s=!1,c=[];for(let t of this.dependencies)t==`doc`?o=!0:t==`selection`?s=!0:(e[t.id]??1)&1||c.push(e[t.id]);return{create(e){return e.values[i]=t(e),1},update(e,r){if(o&&r.docChanged||s&&(r.docChanged||r.selection)||we(e,c)){let r=t(e);if(a?!Ce(r,e.values[i],n):!n(r,e.values[i]))return e.values[i]=r,1}return 0},reconfigure:(e,o)=>{let s,c=o.config.address[r];if(c!=null){let r=Le(o,c);if(this.dependencies.every(t=>t instanceof E?o.facet(t)===e.facet(t):t instanceof De?o.field(t,!1)==e.field(t,!1):!0)||(a?Ce(s=t(e),r,n):n(s=t(e),r)))return e.values[i]=r,0}else s=t(e);return e.values[i]=s,1}}}get extension(){return this}};function Ce(e,t,n){if(e.length!=t.length)return!1;for(let r=0;r<e.length;r++)if(!n(e[r],t[r]))return!1;return!0}function we(e,t){let n=!1;for(let r of t)Ie(e,r)&1&&(n=!0);return n}function Te(e,t,n){let r=n.map(t=>e[t.id]),i=n.map(e=>e.type),a=r.filter(e=>!(e&1)),o=e[t.id]>>1;function s(e){let n=[];for(let t=0;t<r.length;t++){let a=Le(e,r[t]);if(i[t]==2)for(let e of a)n.push(e);else n.push(a)}return t.combine(n)}return{create(e){for(let t of r)Ie(e,t);return e.values[o]=s(e),1},update(e,n){if(!we(e,a))return 0;let r=s(e);return t.compare(r,e.values[o])?0:(e.values[o]=r,1)},reconfigure(e,i){let a=we(e,r),c=i.config.facets[t.id],l=i.facet(t);if(c&&!a&&xe(n,c))return e.values[o]=l,0;let u=s(e);return t.compare(u,l)?(e.values[o]=l,0):(e.values[o]=u,1)}}}var Ee=E.define({static:!0}),De=class e{constructor(e,t,n,r,i){this.id=e,this.createF=t,this.updateF=n,this.compareF=r,this.spec=i,this.provides=void 0}static define(t){let n=new e(be++,t.create,t.update,t.compare||((e,t)=>e===t),t);return t.provide&&(n.provides=t.provide(n)),n}create(e){return(e.facet(Ee).find(e=>e.field==this)?.create||this.createF)(e)}slot(e){let t=e[this.id]>>1;return{create:e=>(e.values[t]=this.create(e),1),update:(e,n)=>{let r=e.values[t],i=this.updateF(r,n);return this.compareF(r,i)?0:(e.values[t]=i,1)},reconfigure:(e,n)=>{let r=e.facet(Ee),i=n.facet(Ee),a;return(a=r.find(e=>e.field==this))&&a!=i.find(e=>e.field==this)?(e.values[t]=a.create(e),1):n.config.address[this.id]==null?(e.values[t]=this.create(e),1):(e.values[t]=n.field(this),0)}}}init(e){return[this,Ee.of({field:this,create:e})]}get extension(){return this}},Oe={lowest:4,low:3,default:2,high:1,highest:0};function ke(e){return t=>new je(t,e)}var Ae={highest:ke(Oe.highest),high:ke(Oe.high),default:ke(Oe.default),low:ke(Oe.low),lowest:ke(Oe.lowest)},je=class{constructor(e,t){this.inner=e,this.prec=t}get extension(){return this}},Me=class e{of(e){return new Ne(this,e)}reconfigure(t){return e.reconfigure.of({compartment:this,extension:t})}get(e){return e.config.compartments.get(this)}},Ne=class{constructor(e,t){this.compartment=e,this.inner=t}get extension(){return this}},Pe=class e{constructor(e,t,n,r,i,a){for(this.base=e,this.compartments=t,this.dynamicSlots=n,this.address=r,this.staticValues=i,this.facets=a,this.statusTemplate=[];this.statusTemplate.length<n.length;)this.statusTemplate.push(0)}staticFacet(e){let t=this.address[e.id];return t==null?e.default:this.staticValues[t>>1]}static resolve(t,n,r){let i=[],a=Object.create(null),o=new Map;for(let e of Fe(t,n,o))e instanceof De?i.push(e):(a[e.facet.id]||(a[e.facet.id]=[])).push(e);let s=Object.create(null),c=[],l=[];for(let e of i)s[e.id]=l.length<<1,l.push(t=>e.slot(t));let u=r?.config.facets;for(let e in a){let t=a[e],n=t[0].facet,i=u&&u[e]||[];if(t.every(e=>e.type==0)){if(s[n.id]=c.length<<1|1,xe(i,t))c.push(r.facet(n));else{let e=n.combine(t.map(e=>e.value));c.push(r&&n.compare(e,r.facet(n))?r.facet(n):e)}}else{for(let e of t)e.type==0?(s[e.id]=c.length<<1|1,c.push(e.value)):(s[e.id]=l.length<<1,l.push(t=>e.dynamicSlot(t)));s[n.id]=l.length<<1,l.push(e=>Te(e,n,t))}}let d=l.map(e=>e(s));return new e(t,o,d,s,c,a)}};function Fe(e,t,n){let r=[[],[],[],[],[]],i=new Map;function a(e,o){let s=i.get(e);if(s!=null){if(s<=o)return;let t=r[s].indexOf(e);t>-1&&r[s].splice(t,1),e instanceof Ne&&n.delete(e.compartment)}if(i.set(e,o),Array.isArray(e))for(let t of e)a(t,o);else if(e instanceof Ne){if(n.has(e.compartment))throw RangeError(`Duplicate use of compartment in extensions`);let r=t.get(e.compartment)||e.inner;n.set(e.compartment,r),a(r,o)}else if(e instanceof je)a(e.inner,e.prec);else if(e instanceof De)r[o].push(e),e.provides&&a(e.provides,o);else if(e instanceof Se)r[o].push(e),e.facet.extensions&&a(e.facet.extensions,Oe.default);else{let t=e.extension;if(!t)throw Error(`Unrecognized extension value in extension set (${e}).`);if(t==e)throw Error(`Unrecognized extension value in extension set (${e}). This sometimes happens because multiple instances of @codemirror/state are loaded, breaking instanceof checks.`);a(t,o)}}return a(e,Oe.default),r.reduce((e,t)=>e.concat(t))}function Ie(e,t){if(t&1)return 2;let n=t>>1,r=e.status[n];if(r==4)throw Error(`Cyclic dependency between fields and/or facets`);if(r&2)return r;e.status[n]=4;let i=e.computeSlot(e,e.config.dynamicSlots[n]);return e.status[n]=2|i}function Le(e,t){return t&1?e.config.staticValues[t>>1]:e.values[t>>1]}var Re=E.define(),ze=E.define({combine:e=>e.some(e=>e),static:!0}),Be=E.define({combine:e=>e.length?e[0]:void 0,static:!0}),Ve=E.define(),He=E.define(),Ue=E.define(),We=E.define({combine:e=>e.length?e[0]:!1}),Ge=class{constructor(e,t){this.type=e,this.value=t}static define(){return new Ke}},Ke=class{of(e){return new Ge(this,e)}},qe=class{constructor(e){this.map=e}of(e){return new D(this,e)}},D=class e{constructor(e,t){this.type=e,this.value=t}map(t){let n=this.type.map(this.value,t);return n===void 0?void 0:n==this.value?this:new e(this.type,n)}is(e){return this.type==e}static define(e={}){return new qe(e.map||(e=>e))}static mapEffects(e,t){if(!e.length)return e;let n=[];for(let r of e){let e=r.map(t);e&&n.push(e)}return n}};D.reconfigure=D.define(),D.appendConfig=D.define();var Je=class e{constructor(t,n,r,i,a,o){this.startState=t,this.changes=n,this.selection=r,this.effects=i,this.annotations=a,this.scrollIntoView=o,this._doc=null,this._state=null,r&&ye(r,n.newLength),a.some(t=>t.type==e.time)||(this.annotations=a.concat(e.time.of(Date.now())))}static create(t,n,r,i,a,o){return new e(t,n,r,i,a,o)}get newDoc(){return this._doc||=this.changes.apply(this.startState.doc)}get newSelection(){return this.selection||this.startState.selection.map(this.changes)}get state(){return this._state||this.startState.applyTransaction(this),this._state}annotation(e){for(let t of this.annotations)if(t.type==e)return t.value}get docChanged(){return!this.changes.empty}get reconfigured(){return this.startState.config!=this.state.config}isUserEvent(t){let n=this.annotation(e.userEvent);return!!(n&&(n==t||n.length>t.length&&n.slice(0,t.length)==t&&n[t.length]==`.`))}};Je.time=Ge.define(),Je.userEvent=Ge.define(),Je.addToHistory=Ge.define(),Je.remote=Ge.define();function Ye(e,t){let n=[];for(let r=0,i=0;;){let a,o;if(r<e.length&&(i==t.length||t[i]>=e[r]))a=e[r++],o=e[r++];else if(i<t.length)a=t[i++],o=t[i++];else return n;!n.length||n[n.length-1]<a?n.push(a,o):n[n.length-1]<o&&(n[n.length-1]=o)}}function Xe(e,t,n){let r,i,a;return n?(r=t.changes,i=fe.empty(t.changes.length),a=e.changes.compose(t.changes)):(r=t.changes.map(e.changes),i=e.changes.mapDesc(t.changes,!0),a=e.changes.compose(r)),{changes:a,selection:t.selection?t.selection.map(i):e.selection?.map(r),effects:D.mapEffects(e.effects,r).concat(D.mapEffects(t.effects,i)),annotations:e.annotations.length?e.annotations.concat(t.annotations):t.annotations,scrollIntoView:e.scrollIntoView||t.scrollIntoView}}function Ze(e,t,n){let r=t.selection,i=nt(t.annotations);return t.userEvent&&(i=i.concat(Je.userEvent.of(t.userEvent))),{changes:t.changes instanceof fe?t.changes:fe.of(t.changes||[],n,e.facet(Be)),selection:r&&(r instanceof T?r:T.single(r.anchor,r.head)),effects:nt(t.effects),annotations:i,scrollIntoView:!!t.scrollIntoView}}function Qe(e,t,n){let r=Ze(e,t.length?t[0]:{},e.doc.length);t.length&&t[0].filter===!1&&(n=!1);for(let i=1;i<t.length;i++){t[i].filter===!1&&(n=!1);let a=!!t[i].sequential;r=Xe(r,Ze(e,t[i],a?r.changes.newLength:e.doc.length),a)}let i=Je.create(e,r.changes,r.selection,r.effects,r.annotations,r.scrollIntoView);return et(n?$e(i):i)}function $e(e){let t=e.startState,n=!0;for(let r of t.facet(Ve)){let t=r(e);if(t===!1){n=!1;break}Array.isArray(t)&&(n=n===!0?t:Ye(n,t))}if(n!==!0){let r,i;if(n===!1)i=e.changes.invertedDesc,r=fe.empty(t.doc.length);else{let t=e.changes.filter(n);r=t.changes,i=t.filtered.mapDesc(t.changes).invertedDesc}e=Je.create(t,r,e.selection&&e.selection.map(i),D.mapEffects(e.effects,i),e.annotations,e.scrollIntoView)}let r=t.facet(He);for(let n=r.length-1;n>=0;n--){let i=r[n](e);e=i instanceof Je?i:Array.isArray(i)&&i.length==1&&i[0]instanceof Je?i[0]:Qe(t,nt(i),!1)}return e}function et(e){let t=e.startState,n=t.facet(Ue),r=e;for(let i=n.length-1;i>=0;i--){let a=n[i](e);a&&Object.keys(a).length&&(r=Xe(r,Ze(t,a,e.changes.newLength),!0))}return r==e?e:Je.create(t,e.changes,e.selection,r.effects,r.annotations,r.scrollIntoView)}var tt=[];function nt(e){return e==null?tt:Array.isArray(e)?e:[e]}var O=(function(e){return e[e.Word=0]=`Word`,e[e.Space=1]=`Space`,e[e.Other=2]=`Other`,e})(O||={}),rt=/[\u00df\u0587\u0590-\u05f4\u0600-\u06ff\u3040-\u309f\u30a0-\u30ff\u3400-\u4db5\u4e00-\u9fcc\uac00-\ud7af]/,it;try{it=RegExp(`[\\p{Alphabetic}\\p{Number}_]`,`u`)}catch{}function at(e){if(it)return it.test(e);for(let t=0;t<e.length;t++){let n=e[t];if(/\w/.test(n)||n>`€`&&(n.toUpperCase()!=n.toLowerCase()||rt.test(n)))return!0}return!1}function ot(e){return t=>{if(!/\S/.test(t))return O.Space;if(at(t))return O.Word;for(let n=0;n<e.length;n++)if(t.indexOf(e[n])>-1)return O.Word;return O.Other}}var k=class e{constructor(e,t,n,r,i,a){this.config=e,this.doc=t,this.selection=n,this.values=r,this.status=e.statusTemplate.slice(),this.computeSlot=i,a&&(a._state=this);for(let e=0;e<this.config.dynamicSlots.length;e++)Ie(this,e<<1);this.computeSlot=null}field(e,t=!0){let n=this.config.address[e.id];if(n==null){if(t)throw RangeError(`Field is not present in this state`);return}return Ie(this,n),Le(this,n)}update(...e){return Qe(this,e,!0)}applyTransaction(t){let n=this.config,{base:r,compartments:i}=n;for(let e of t.effects)e.is(Me.reconfigure)?(n&&=(i=new Map,n.compartments.forEach((e,t)=>i.set(t,e)),null),i.set(e.value.compartment,e.value.extension)):e.is(D.reconfigure)?(n=null,r=e.value):e.is(D.appendConfig)&&(n=null,r=nt(r).concat(e.value));let a;n?a=t.startState.values.slice():(n=Pe.resolve(r,i,this),a=new e(n,this.doc,this.selection,n.dynamicSlots.map(()=>null),(e,t)=>t.reconfigure(e,this),null).values);let o=t.startState.facet(ze)?t.newSelection:t.newSelection.asSingle();new e(n,t.newDoc,o,a,(e,n)=>n.update(e,t),t)}replaceSelection(e){return typeof e==`string`&&(e=this.toText(e)),this.changeByRange(t=>({changes:{from:t.from,to:t.to,insert:e},range:T.cursor(t.from+e.length)}))}changeByRange(e){let t=this.selection,n=e(t.ranges[0]),r=this.changes(n.changes),i=[n.range],a=nt(n.effects);for(let n=1;n<t.ranges.length;n++){let o=e(t.ranges[n]),s=this.changes(o.changes),c=s.map(r);for(let e=0;e<n;e++)i[e]=i[e].map(c);let l=r.mapDesc(s,!0);i.push(o.range.map(l)),r=r.compose(c),a=D.mapEffects(a,c).concat(D.mapEffects(nt(o.effects),l))}return{changes:r,selection:T.create(i,t.mainIndex),effects:a}}changes(t=[]){return t instanceof fe?t:fe.of(t,this.doc.length,this.facet(e.lineSeparator))}toText(t){return g.of(t.split(this.facet(e.lineSeparator)||ue))}sliceDoc(e=0,t=this.doc.length){return this.doc.sliceString(e,t,this.lineBreak)}facet(e){let t=this.config.address[e.id];return t==null?e.default:(Ie(this,t),Le(this,t))}toJSON(e){let t={doc:this.sliceDoc(),selection:this.selection.toJSON()};if(e)for(let n in e){let r=e[n];r instanceof De&&this.config.address[r.id]!=null&&(t[n]=r.spec.toJSON(this.field(e[n]),this))}return t}static fromJSON(t,n={},r){if(!t||typeof t.doc!=`string`)throw RangeError(`Invalid JSON representation for EditorState`);let i=[];if(r){for(let e in r)if(Object.prototype.hasOwnProperty.call(t,e)){let n=r[e],a=t[e];i.push(n.init(e=>n.spec.fromJSON(a,e)))}}return e.create({doc:t.doc,selection:T.fromJSON(t.selection),extensions:n.extensions?i.concat([n.extensions]):i})}static create(t={}){let n=Pe.resolve(t.extensions||[],new Map),r=t.doc instanceof g?t.doc:g.of((t.doc||``).split(n.staticFacet(e.lineSeparator)||ue)),i=t.selection?t.selection instanceof T?t.selection:T.single(t.selection.anchor,t.selection.head):T.single(0);return ye(i,r.length),n.staticFacet(ze)||(i=i.asSingle()),new e(n,r,i,n.dynamicSlots.map(()=>null),(e,t)=>t.create(e),null)}get tabSize(){return this.facet(e.tabSize)}get lineBreak(){return this.facet(e.lineSeparator)||`
@@ -0,0 +1 @@
1
+ import"./chunk-K5T4RW27-BZGfe2N3.js";import{y as e}from"./mermaid-parser.core-CVGOr4EN.js";export{e as createArchitectureServices};