chapterhouse 0.3.3 → 0.3.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/api/server.js +2 -2
- package/dist/store/db.js +23 -1
- package/dist/store/db.test.js +43 -0
- package/package.json +1 -1
- package/web/dist/assets/{index-DSqc46G_.js → index-BWQf0ac8.js} +3 -3
- package/web/dist/assets/{index-DSqc46G_.js.map → index-BWQf0ac8.js.map} +1 -1
- package/web/dist/index.html +1 -1
package/dist/api/server.js
CHANGED
|
@@ -19,7 +19,7 @@ import { withWikiWrite } from "../wiki/lock.js";
|
|
|
19
19
|
import { listSkills, removeSkill } from "../copilot/skills.js";
|
|
20
20
|
import { restartDaemon } from "../daemon.js";
|
|
21
21
|
import { API_TOKEN_PATH, resolveWikiRelativePath } from "../paths.js";
|
|
22
|
-
import { getDb, getSessionMessages, getTaskEvents } from "../store/db.js";
|
|
22
|
+
import { getDb, getSessionMessages, getTaskEvents, normalizeSqliteTsToIso } from "../store/db.js";
|
|
23
23
|
import { getStatus, onStatusChange } from "../status.js";
|
|
24
24
|
import { formatSseData, formatSseEvent } from "./sse.js";
|
|
25
25
|
import { syncDecisionsFileToWiki } from "../squad/mirror.js";
|
|
@@ -614,7 +614,7 @@ app.get("/api/projects", (_req, res) => {
|
|
|
614
614
|
squadDir: r.squad_dir,
|
|
615
615
|
// Count from live filesystem — authoritative per Squad SDK rule: repo files win over cache.
|
|
616
616
|
agentCount: countAgentsOnDisk(r.project_root),
|
|
617
|
-
loadedAt: r.loaded_at,
|
|
617
|
+
loadedAt: normalizeSqliteTsToIso(r.loaded_at),
|
|
618
618
|
lastUsedAt: r.last_used_at != null ? new Date(r.last_used_at).toISOString() : undefined,
|
|
619
619
|
})));
|
|
620
620
|
});
|
package/dist/store/db.js
CHANGED
|
@@ -307,6 +307,28 @@ export function getRecentConversation(limit, sessionKey) {
|
|
|
307
307
|
}
|
|
308
308
|
const MAX_SESSION_MESSAGES_LIMIT = 500;
|
|
309
309
|
const DEFAULT_SESSION_MESSAGES_LIMIT = 100;
|
|
310
|
+
/**
|
|
311
|
+
* Normalize a SQLite CURRENT_TIMESTAMP string to a proper ISO-8601 UTC string.
|
|
312
|
+
*
|
|
313
|
+
* SQLite stores CURRENT_TIMESTAMP as "YYYY-MM-DD HH:MM:SS" — no timezone
|
|
314
|
+
* marker, space separator. Browsers that receive this bare string may parse it
|
|
315
|
+
* as *local* time instead of UTC, shifting every displayed timestamp by the
|
|
316
|
+
* user's UTC offset. This helper appends the `Z` suffix (and replaces the space
|
|
317
|
+
* separator with `T`) so that `new Date(ts)` always parses as UTC.
|
|
318
|
+
*
|
|
319
|
+
* - Already-ISO strings (containing `T`) are returned unchanged (idempotent).
|
|
320
|
+
* - Strings with a `T` but no `Z` are left as-is; they are already ISO format
|
|
321
|
+
* and the caller is responsible for any timezone semantics (we do not blindly
|
|
322
|
+
* append `Z` and risk double-shifting a value that might already be local).
|
|
323
|
+
* - Falsy / empty input is returned as an empty string rather than throwing.
|
|
324
|
+
*/
|
|
325
|
+
export function normalizeSqliteTsToIso(ts) {
|
|
326
|
+
if (!ts)
|
|
327
|
+
return "";
|
|
328
|
+
if (ts.includes("T"))
|
|
329
|
+
return ts;
|
|
330
|
+
return ts.replace(" ", "T") + "Z";
|
|
331
|
+
}
|
|
310
332
|
/**
|
|
311
333
|
* Return conversation_log rows for a specific session as structured JSON,
|
|
312
334
|
* suitable for seeding the frontend Zustand store on mount.
|
|
@@ -328,7 +350,7 @@ export function getSessionMessages(sessionKey, limit) {
|
|
|
328
350
|
return rows.map((r) => ({
|
|
329
351
|
role: r.role,
|
|
330
352
|
content: r.content,
|
|
331
|
-
ts: r.ts,
|
|
353
|
+
ts: normalizeSqliteTsToIso(r.ts),
|
|
332
354
|
}));
|
|
333
355
|
}
|
|
334
356
|
/**
|
package/dist/store/db.test.js
CHANGED
|
@@ -280,4 +280,47 @@ test("#86: agent_task_events table exists in schema after getDb()", async () =>
|
|
|
280
280
|
dbModule.closeDb();
|
|
281
281
|
}
|
|
282
282
|
});
|
|
283
|
+
// ---------------------------------------------------------------------------
|
|
284
|
+
// normalizeSqliteTsToIso — unit tests
|
|
285
|
+
// ---------------------------------------------------------------------------
|
|
286
|
+
test("normalizeSqliteTsToIso converts SQLite space-separated UTC string to ISO-8601", async () => {
|
|
287
|
+
const dbModule = await loadDbModule();
|
|
288
|
+
assert.equal(dbModule.normalizeSqliteTsToIso("2026-05-09 00:54:31"), "2026-05-09T00:54:31Z", "space-separated string should become T-separated with Z suffix");
|
|
289
|
+
});
|
|
290
|
+
test("normalizeSqliteTsToIso is idempotent for already-ISO strings ending with Z", async () => {
|
|
291
|
+
const dbModule = await loadDbModule();
|
|
292
|
+
assert.equal(dbModule.normalizeSqliteTsToIso("2026-05-09T00:54:31Z"), "2026-05-09T00:54:31Z", "already-ISO string should be returned unchanged");
|
|
293
|
+
});
|
|
294
|
+
test("normalizeSqliteTsToIso leaves T-but-no-Z strings untouched", async () => {
|
|
295
|
+
// Strings that already contain T are considered already in ISO format.
|
|
296
|
+
// We do NOT append Z because the timezone semantics are unknown — the caller
|
|
297
|
+
// is responsible. Appending Z blindly could double-shift a local-time value.
|
|
298
|
+
const dbModule = await loadDbModule();
|
|
299
|
+
assert.equal(dbModule.normalizeSqliteTsToIso("2026-05-09T00:54:31"), "2026-05-09T00:54:31", "T-but-no-Z string should be left as-is");
|
|
300
|
+
});
|
|
301
|
+
test("normalizeSqliteTsToIso handles empty and nullish input gracefully", async () => {
|
|
302
|
+
const dbModule = await loadDbModule();
|
|
303
|
+
assert.equal(dbModule.normalizeSqliteTsToIso(""), "", "empty string → empty string");
|
|
304
|
+
assert.equal(dbModule.normalizeSqliteTsToIso(null), "", "null → empty string");
|
|
305
|
+
assert.equal(dbModule.normalizeSqliteTsToIso(undefined), "", "undefined → empty string");
|
|
306
|
+
});
|
|
307
|
+
// ---------------------------------------------------------------------------
|
|
308
|
+
// getSessionMessages — integration: ts field is normalized to ISO UTC
|
|
309
|
+
// ---------------------------------------------------------------------------
|
|
310
|
+
test("getSessionMessages returns ts values normalized to ISO-8601 UTC (ends with Z)", async () => {
|
|
311
|
+
const dbModule = await loadDbModule();
|
|
312
|
+
try {
|
|
313
|
+
const db = dbModule.getDb();
|
|
314
|
+
// Insert a row with a bare SQLite-format timestamp (no T, no Z)
|
|
315
|
+
db.prepare(`INSERT INTO conversation_log (role, content, source, session_key, ts)
|
|
316
|
+
VALUES ('user', 'timezone test', 'web', 'tz-session', '2026-05-09 01:23:45')`).run();
|
|
317
|
+
const messages = dbModule.getSessionMessages("tz-session");
|
|
318
|
+
assert.equal(messages.length, 1, "should return the inserted row");
|
|
319
|
+
assert.equal(messages[0].ts, "2026-05-09T01:23:45Z", "ts must be normalized to ISO-8601 UTC");
|
|
320
|
+
assert.ok(messages[0].ts.endsWith("Z"), "ts must end with Z");
|
|
321
|
+
}
|
|
322
|
+
finally {
|
|
323
|
+
dbModule.closeDb();
|
|
324
|
+
}
|
|
325
|
+
});
|
|
283
326
|
//# sourceMappingURL=db.test.js.map
|
package/package.json
CHANGED
|
@@ -173,10 +173,10 @@ https://github.com/highlightjs/highlight.js/issues/2277`),k=T,L=D),N===void 0&&(
|
|
|
173
173
|
|
|
174
174
|
Try sending your message again.`,"default")}finally{f(!1)}}function W(T){T.key==="Enter"&&!T.shiftKey&&(T.preventDefault(),X()),T.key==="Escape"&&_&&(T.preventDefault(),Q())}return w.jsxs("div",{className:"chat",children:[w.jsx("p",{className:"sr-only","aria-live":"polite",children:_?"Chapterhouse is responding.":t.status==="dreaming"?t.message||"Chapterhouse is thinking.":""}),w.jsx("section",{className:"chat-scroll",ref:y,"aria-label":"Conversation",children:w.jsx("div",{className:"chat-log",role:"log","aria-live":"polite","aria-relevant":"additions text","aria-busy":_,children:w.jsx(lQ,{messages:e,lastCompletedAssistantId:$,latestAssistantRef:v,rehydrating:O,systemStatus:t,assistantLabel:"Chapterhouse",emptyState:w.jsx(yl,{title:"Talk to Chapterhouse.",description:'Try: "What sessions are running?" · "Start working on the auth bug in ~/dev/myapp"',action:w.jsxs("p",{className:"dim small",children:["Type ",w.jsx("code",{children:"/help"})," for slash commands."]})})})})}),w.jsxs("div",{className:"composer",children:[p?w.jsx(br,{inline:!0,message:p,onRetry:u.trim()&&l?()=>void X():void 0}):null,w.jsx("label",{className:"sr-only",htmlFor:"chat-composer",children:"Message Chapterhouse"}),w.jsx("textarea",{id:"chat-composer",ref:b,value:u,onChange:T=>h(T.target.value),onKeyDown:W,placeholder:"Message Chapterhouse…",rows:3,disabled:!l||d,"aria-describedby":`${S}${t.status==="dreaming"?` ${E}`:""}`}),w.jsx("div",{id:S,className:"composer-help dim small",children:"Enter sends · Shift+Enter adds a newline · Escape cancels an in-flight response."}),t.status==="dreaming"?w.jsxs("div",{id:E,className:"dreaming-indicator","aria-live":"polite",children:[w.jsx("span",{className:"dreaming-indicator-glyph","aria-hidden":"true",children:"✦"}),w.jsx("span",{children:t.message||"Chapterhouse is thinking…"})]}):null,w.jsx("div",{className:"composer-actions",children:_?w.jsx("button",{type:"button",onClick:()=>void Q(),className:"btn cancel",children:"Cancel"}):w.jsx("button",{type:"button",onClick:()=>void X(),disabled:!u.trim()||!l||d,className:"btn primary","aria-busy":d,children:d?"Sending…":"Send"})})]})]})}const Mie="Available slash commands:\n- `/clear` — clear the on-screen conversation (server history is preserved)\n- `/cancel` — cancel the in-flight response\n- `/copy` — copy the last assistant response to the clipboard\n- `/help` — show this list";function Qie(){const{systemStatus:t}=nR(),{projectRef:e}=NU(),n=es(),r=P.useMemo(()=>kG(e),[e]),i=P.useMemo(()=>vG(r),[r]),s=r.split("/").filter(Boolean).pop()??r,o=Ze(k=>k.messagesBySession[i]??uv),a=Ze(k=>k.addUserMessage),l=Ze(k=>k.markMessageSent),c=Ze(k=>k.clearMessages),u=Ze(k=>k.finishAssistant),h=Ze(k=>k.startAssistantMessage),d=Ze(k=>k.seedMessages),f=Ze(k=>k.connectionId),[p,g]=P.useState(""),[O,m]=P.useState(!1),[y,b]=P.useState(null),[v,x]=P.useState(!1),S=P.useRef(null),E=P.useRef(null),I=P.useRef(null),M=P.useRef(null),_=P.useId(),$=P.useId();P.useEffect(()=>{const k=Ze.getState().messagesBySession[i];if(k&&k.length>0)return;let q=!1;return x(!0),rt.getSessionMessages(i).then(({messages:J})=>{q||J.length>0&&d(J,i)}).catch(()=>{}).finally(()=>{q||x(!1)}),()=>{q=!0}},[i]);const Q=P.useMemo(()=>[...o].reverse().find(k=>k.role==="assistant"),[o]),F=P.useMemo(()=>[...o].reverse().find(k=>k.role==="assistant"&&!k.pending),[o]),X=(Q==null?void 0:Q.role)==="assistant"&&Q.pending,W=(F==null?void 0:F.id)??null;P.useEffect(()=>{const k=S.current;k&&(k.scrollTop=k.scrollHeight)},[o]),P.useEffect(()=>{var k;!W||M.current===W||(M.current=W,document.activeElement!==E.current&&((k=I.current)==null||k.focus({preventScroll:!0})))},[W]);async function T(){try{b(null),await rt.cancel()}catch(k){b(k instanceof Error?k.message:String(k))}}async function D(k){const q=k.trim().toLowerCase();if(!q.startsWith("/"))return!1;const[J]=q.split(/\s+/);switch(J){case"/clear":return b(null),c(i),!0;case"/cancel":return await T(),!0;case"/copy":{const A=[...o].reverse().find(Y=>Y.role==="assistant");if(!A)return b("There is no assistant response to copy yet."),!0;try{await navigator.clipboard.writeText(A.content),b(null)}catch(Y){b(Y instanceof Error?Y.message:"Couldn't copy the last response.")}return!0}case"/help":{const A=h(i);return u(A,Mie,i),b(null),!0}default:return!1}}async function N(){const k=p.trim();if(!k||O)return;if(b(null),await D(k)){g("");return}if(!f){b("Still connecting to Chapterhouse. Try again in a moment.");return}g("");const q=a(k,i);m(!0);try{await rt.sendMessage(k,f,r,i),l(q,i)}catch(J){const A=J instanceof Error?J.message:String(J);g(k),b(A);const Y=h(i);u(Y,`**Error:** ${A}
|
|
175
175
|
|
|
176
|
-
Try sending your message again.`,i)}finally{m(!1)}}function L(k){k.key==="Enter"&&!k.shiftKey&&(k.preventDefault(),N()),k.key==="Escape"&&X&&(k.preventDefault(),T())}return w.jsxs("div",{className:"chat",children:[w.jsx("p",{className:"sr-only","aria-live":"polite",children:X?"Squad Coordinator is responding.":t.status==="dreaming"?t.message||"Squad Coordinator is thinking.":""}),w.jsxs("div",{className:"project-chat-header",role:"banner","aria-label":`Squad Coordinator for ${s}`,children:[w.jsxs("div",{className:"project-chat-header-identity",children:[w.jsx("span",{className:"project-chat-icon","aria-hidden":"true",children:"🏗️"}),w.jsxs("span",{className:"project-chat-title",children:["Squad Coordinator — ",w.jsx("strong",{children:s})]}),w.jsx("span",{className:"project-chat-path dim",title:r,children:r})]}),w.jsx("button",{type:"button",className:"btn",onClick:()=>n("/chat"),"aria-label":"Back to Chapterhouse",children:"← Back to Chapterhouse"})]}),w.jsx("section",{className:"chat-scroll",ref:S,"aria-label":"Conversation",children:w.jsx("div",{className:"chat-log",role:"log","aria-live":"polite","aria-relevant":"additions text","aria-busy":X,children:w.jsx(lQ,{messages:o,lastCompletedAssistantId:W,latestAssistantRef:I,rehydrating:v,systemStatus:t,assistantLabel:"Squad Coordinator",emptyState:w.jsx(yl,{title:`Working in ${s}.`,description:`Try: "@ripley fix the auth bug" · "Who's on the squad team?"`,action:w.jsxs("p",{className:"dim small",children:["Type ",w.jsx("code",{children:"/help"})," for slash commands."]})})})})}),w.jsxs("div",{className:"composer",children:[y?w.jsx(br,{inline:!0,message:y,onRetry:p.trim()&&f?()=>void N():void 0}):null,w.jsx("label",{className:"sr-only",htmlFor:"project-chat-composer",children:"Message Squad Coordinator"}),w.jsx("textarea",{id:"project-chat-composer",ref:E,value:p,onChange:k=>g(k.target.value),onKeyDown:L,placeholder:`Message Squad (${s})…`,rows:3,disabled:!f||O,"aria-describedby":`${_}${t.status==="dreaming"?` ${$}`:""}`}),w.jsx("div",{id:_,className:"composer-help dim small",children:"Enter sends · Shift+Enter adds a newline · Escape cancels an in-flight response."}),t.status==="dreaming"?w.jsxs("div",{id:$,className:"dreaming-indicator","aria-live":"polite",children:[w.jsx("span",{className:"dreaming-indicator-glyph","aria-hidden":"true",children:"✦"}),w.jsx("span",{children:t.message||"Squad Coordinator is thinking…"})]}):null,w.jsx("div",{className:"composer-actions",children:X?w.jsx("button",{type:"button",onClick:()=>void T(),className:"btn cancel",children:"Cancel"}):w.jsx("button",{type:"button",onClick:()=>void N(),disabled:!p.trim()||!f||O,className:"btn primary","aria-busy":O,children:O?"Sending…":"Send"})})]})]})}function Lie(){const[t,e]=P.useState(null),[n,r]=P.useState(null),[i,s]=P.useState([]),[o,a]=P.useState(null),[l,c]=P.useState(!0),u=P.useRef(null),h=P.useRef(null);async function d({silent:O=!1}={}){O||c(!0);try{const m=await rt.listWorkers();if(e(m),a(null),n){const y=await rt.getWorker(n.taskId).catch(()=>null);y&&r(y)}}catch(m){a(m instanceof Error?m.message:String(m))}finally{O||c(!1)}}P.useEffect(()=>{d();const O=setInterval(()=>{d({silent:!0})},4e3);return()=>clearInterval(O)},[n==null?void 0:n.taskId]),P.useEffect(()=>{
|
|
176
|
+
Try sending your message again.`,i)}finally{m(!1)}}function L(k){k.key==="Enter"&&!k.shiftKey&&(k.preventDefault(),N()),k.key==="Escape"&&X&&(k.preventDefault(),T())}return w.jsxs("div",{className:"chat",children:[w.jsx("p",{className:"sr-only","aria-live":"polite",children:X?"Squad Coordinator is responding.":t.status==="dreaming"?t.message||"Squad Coordinator is thinking.":""}),w.jsxs("div",{className:"project-chat-header",role:"banner","aria-label":`Squad Coordinator for ${s}`,children:[w.jsxs("div",{className:"project-chat-header-identity",children:[w.jsx("span",{className:"project-chat-icon","aria-hidden":"true",children:"🏗️"}),w.jsxs("span",{className:"project-chat-title",children:["Squad Coordinator — ",w.jsx("strong",{children:s})]}),w.jsx("span",{className:"project-chat-path dim",title:r,children:r})]}),w.jsx("button",{type:"button",className:"btn",onClick:()=>n("/chat"),"aria-label":"Back to Chapterhouse",children:"← Back to Chapterhouse"})]}),w.jsx("section",{className:"chat-scroll",ref:S,"aria-label":"Conversation",children:w.jsx("div",{className:"chat-log",role:"log","aria-live":"polite","aria-relevant":"additions text","aria-busy":X,children:w.jsx(lQ,{messages:o,lastCompletedAssistantId:W,latestAssistantRef:I,rehydrating:v,systemStatus:t,assistantLabel:"Squad Coordinator",emptyState:w.jsx(yl,{title:`Working in ${s}.`,description:`Try: "@ripley fix the auth bug" · "Who's on the squad team?"`,action:w.jsxs("p",{className:"dim small",children:["Type ",w.jsx("code",{children:"/help"})," for slash commands."]})})})})}),w.jsxs("div",{className:"composer",children:[y?w.jsx(br,{inline:!0,message:y,onRetry:p.trim()&&f?()=>void N():void 0}):null,w.jsx("label",{className:"sr-only",htmlFor:"project-chat-composer",children:"Message Squad Coordinator"}),w.jsx("textarea",{id:"project-chat-composer",ref:E,value:p,onChange:k=>g(k.target.value),onKeyDown:L,placeholder:`Message Squad (${s})…`,rows:3,disabled:!f||O,"aria-describedby":`${_}${t.status==="dreaming"?` ${$}`:""}`}),w.jsx("div",{id:_,className:"composer-help dim small",children:"Enter sends · Shift+Enter adds a newline · Escape cancels an in-flight response."}),t.status==="dreaming"?w.jsxs("div",{id:$,className:"dreaming-indicator","aria-live":"polite",children:[w.jsx("span",{className:"dreaming-indicator-glyph","aria-hidden":"true",children:"✦"}),w.jsx("span",{children:t.message||"Squad Coordinator is thinking…"})]}):null,w.jsx("div",{className:"composer-actions",children:X?w.jsx("button",{type:"button",onClick:()=>void T(),className:"btn cancel",children:"Cancel"}):w.jsx("button",{type:"button",onClick:()=>void N(),disabled:!p.trim()||!f||O,className:"btn primary","aria-busy":O,children:O?"Sending…":"Send"})})]})]})}function Lie(){const[t,e]=P.useState(null),[n,r]=P.useState(null),[i,s]=P.useState([]),[o,a]=P.useState(null),[l,c]=P.useState(!0),u=P.useRef(null),h=P.useRef(null);async function d({silent:O=!1}={}){O||c(!0);try{const m=await rt.listWorkers();if(e(m),a(null),n){const y=await rt.getWorker(n.taskId).catch(()=>null);y&&r(y)}}catch(m){a(m instanceof Error?m.message:String(m))}finally{O||c(!1)}}P.useEffect(()=>{d();const O=setInterval(()=>{d({silent:!0})},4e3);return()=>clearInterval(O)},[n==null?void 0:n.taskId]),P.useEffect(()=>{const O=h.current;if(!O)return;O.scrollHeight-O.scrollTop-O.clientHeight<80&&(O.scrollTop=O.scrollHeight)},[i.length]);async function f(O){var y;(y=u.current)==null||y.abort();const m=new AbortController;u.current=m;try{const b=await rt.getWorkerEvents(O);s(b.events);const v=b.events.length>0?b.events[b.events.length-1].seq:0,x=await cv({Accept:"text/event-stream"}),S=await fetch(`/api/workers/${encodeURIComponent(O)}/events/stream`,{method:"GET",headers:x,cache:"no-store",signal:m.signal});if(!S.ok||!S.body)return;const E=S.body.getReader(),I=new TextDecoder;let M="",_=v;for(;;){const{value:$,done:Q}=await E.read();if(Q||m.signal.aborted)break;M+=I.decode($,{stream:!0});const F=M.split(`
|
|
177
177
|
|
|
178
178
|
`);M=F.pop()??"";for(const X of F){const W=X.split(`
|
|
179
|
-
`).find(T=>T.startsWith("data: "));if(W)try{const T=JSON.parse(W.slice(6));if(T.type==="task_event"&&typeof T.seq=="number"&&T.seq>_){_=T.seq;const D={id:typeof T.id=="number"?T.id:0,taskId:typeof T.taskId=="string"?T.taskId:O,seq:T.seq,ts:typeof T.ts=="number"?T.ts:Date.now(),kind:T.kind==="tool_complete"?"tool_complete":"tool_start",toolName:typeof T.toolName=="string"?T.toolName:null,summary:typeof T.summary=="string"?T.summary:null};s(N=>[...N,D])}}catch{}}}}catch(b){if(b instanceof Error&&b.name==="AbortError")return}}async function p(O){try{const m=await rt.getWorker(O.taskId);r(m),s([]),a(null),f(O.taskId)}catch(m){a(m instanceof Error?m.message:String(m))}}P.useEffect(()=>()=>{var O;(O=u.current)==null||O.abort()},[]);function g(O){return new Date(O).toLocaleTimeString([],{hour:"2-digit",minute:"2-digit",second:"2-digit"})}return w.jsxs("div",{className:"page workers",children:[w.jsxs("header",{className:"page-header",children:[w.jsx("h1",{children:"Workers"}),w.jsx("p",{className:"dim",children:"Active and recent agent tasks (last 24 h). Updates every 4s."})]}),o?w.jsx(br,{inline:!0,message:o,onRetry:()=>void d()}):null,w.jsxs("div",{className:"workers-layout",children:[w.jsxs("div",{className:"workers-list","aria-busy":l,children:[l&&t===null?w.jsx(Jn,{inline:!0,label:"Loading workers"}):null,t&&t.length===0?w.jsx(yl,{icon:"🤖",title:"No tasks yet",description:"No agent tasks in the last 24 hours."}):null,t==null?void 0:t.map(O=>w.jsxs("button",{type:"button",className:"worker-row"+((n==null?void 0:n.taskId)===O.taskId?" selected":""),onClick:()=>void p(O),"aria-pressed":(n==null?void 0:n.taskId)===O.taskId,children:[w.jsxs("div",{className:"worker-row-head",children:[w.jsx("strong",{children:O.name||`@${O.slug}`}),w.jsx("span",{className:`worker-status worker-status--${O.status}`,children:O.status})]}),w.jsx("div",{className:"worker-row-desc",children:O.description}),w.jsxs("div",{className:"dim small",children:["@",O.slug," · ",O.model]})]},O.taskId))]}),w.jsx("div",{className:"workers-detail","aria-live":"polite",children:n?w.jsxs(w.Fragment,{children:[w.jsxs("h2",{children:[n.name||n.agentSlug," ",w.jsxs("span",{className:"dim worker-detail-slug",children:["@",n.agentSlug]})]}),w.jsx("p",{className:"worker-detail-description",children:n.description}),w.jsxs("p",{className:"dim small worker-detail-meta",children:[w.jsx("span",{className:`worker-status worker-status--${n.status}`,children:n.status})," · ","started ",n.startedAt,n.completedAt?` · completed ${n.completedAt}`:""," · ",w.jsx("span",{className:"worker-detail-taskid",children:n.taskId})]}),w.jsx("h3",{children:"Activity"}),i.length===0&&n.status==="running"?w.jsx("p",{className:"dim small",children:"Waiting for tool-call activity…"}):i.length===0?w.jsx("p",{className:"dim small",children:"(no tool-call activity recorded)"}):w.jsxs("div",{className:"worker-events",children:[i.map(O=>w.jsxs("div",{className:`worker-event worker-event--${O.kind}`,children:[w.jsx("span",{className:"worker-event-ts",children:g(O.ts)}),O.kind==="tool_start"?w.jsxs("span",{className:"worker-event-body",children:[w.jsx("span",{className:"worker-event-icon",children:"⚙️"}),w.jsx("strong",{children:O.toolName??"tool"}),O.summary?w.jsxs("span",{className:"dim",children:[" — ",O.summary]}):null]}):w.jsxs("span",{className:"worker-event-body",children:[w.jsx("span",{className:"worker-event-icon",children:"✅"}),O.summary?w.jsx("span",{className:"dim",children:O.summary}):w.jsx("span",{className:"dim",children:"done"})]})]},O.id)),w.jsx("div",{ref:h})]}),w.jsx("h3",{children:"Result"}),w.jsx("pre",{className:"output",children:n.result??"(no output yet — task still running)"})]}):w.jsx(yl,{icon:"👈",title:"Pick a worker",description:"Select a task from the list to inspect its details."})})]})]})}function Die(){const[t,e]=P.useState(null),[n,r]=P.useState(null),[i,s]=P.useState(!0),[o,a]=P.useState(!1),[l,c]=P.useState(!1),[u,h]=P.useState(""),[d,f]=P.useState(!1),[p,g]=P.useState(null),O=P.useRef(null),m=es();async function y(){s(!0);try{const S=await df.list();e(S),r(null),a(!1)}catch(S){const E=S instanceof Error?S.message:String(S);E.includes("503")||E.toLowerCase().includes("squad integration is disabled")?(a(!0),e([])):r(E)}finally{s(!1)}}P.useEffect(()=>{y()},[]),P.useEffect(()=>{var S;l&&((S=O.current)==null||S.focus())},[l]);async function b(S){S.preventDefault();const E=u.trim();if(E){f(!0),g(null);try{await df.register(E),h(""),c(!1),await y()}catch(I){g(I instanceof Error?I.message:String(I))}finally{f(!1)}}}async function v(S){try{await df.remove(S),await y()}catch(E){r(E instanceof Error?E.message:String(E))}}function x(S){m(`/projects/chat/${b$(S)}`)}return w.jsxs("div",{className:"page projects",children:[w.jsxs("header",{className:"page-header",children:[w.jsx("h1",{children:"Projects"}),w.jsxs("p",{className:"dim",children:["Registered Squad projects. Each project needs a ",w.jsx("code",{children:".squad/"})," directory."]})]}),o?w.jsx("div",{className:"projects-disabled",role:"status",children:w.jsxs("p",{children:[w.jsx("strong",{children:"Squad integration is disabled."})," Set"," ",w.jsx("code",{children:"ENABLE_SQUAD=1"})," in your environment to enable project features."]})}):w.jsxs(w.Fragment,{children:[n?w.jsx(br,{inline:!0,message:n,onRetry:()=>void y()}):null,w.jsx("div",{className:"projects-toolbar",children:l?w.jsxs("form",{className:"projects-register-form",onSubmit:S=>void b(S),children:[w.jsx("input",{ref:O,type:"text",className:"projects-path-input",placeholder:"/absolute/path/to/project",value:u,onChange:S=>h(S.target.value),"aria-label":"Project path",disabled:d}),w.jsx("button",{type:"submit",className:"btn primary",disabled:d||!u.trim(),children:d?"Registering…":"Add"}),w.jsx("button",{type:"button",className:"btn",onClick:()=>{c(!1),g(null),h("")},disabled:d,children:"Cancel"}),p?w.jsx("span",{className:"projects-register-error dim",role:"alert",children:p}):null]}):w.jsx("button",{type:"button",className:"btn primary",onClick:()=>c(!0),"aria-expanded":l,children:"Register Project"})}),i&&t===null?w.jsx(Jn,{inline:!0,label:"Loading projects"}):w.jsxs("div",{className:"projects-list","aria-busy":i,children:[t&&t.length===0?w.jsx(yl,{icon:"🗂️",title:"No projects registered",description:"Add a project path above to get started."}):null,t==null?void 0:t.map(S=>w.jsxs("div",{className:"project-row",children:[w.jsxs("div",{className:"project-row-info",children:[w.jsx("strong",{className:"project-root",title:S.projectRoot,children:S.projectRoot}),w.jsxs("span",{className:"project-meta dim",children:[w.jsxs("span",{className:"project-badge",children:[S.agentCount," agent",S.agentCount!==1?"s":""]}),w.jsx("span",{children:S.squadDir}),w.jsxs("span",{children:["loaded ",S.loadedAt]})]})]}),w.jsxs("div",{className:"project-row-actions",children:[w.jsx("button",{type:"button",className:"btn primary",onClick:()=>x(S.projectRoot),"aria-label":`New session for ${S.projectRoot}`,children:"Chat in Project Context"}),w.jsx("button",{type:"button",className:"btn danger",onClick:()=>void v(S.projectRoot),"aria-label":`Remove ${S.projectRoot}`,children:"×"})]})]},S.projectRoot))]})]})]})}function Tp({title:t,description:e,actions:n,compact:r=!1}){return w.jsxs("div",{className:`wiki-empty-state${r?" compact":""}`,children:[w.jsx("h2",{children:t}),w.jsx("p",{children:e}),n?w.jsx("div",{className:"wiki-empty-state-actions",children:n}):null]})}const Sl="pages";function nm(t){return t.replace(new RegExp(`^${Sl}/?`),"").split("/").filter(Boolean)}function GE(t){return t.toLocaleLowerCase()}function qE(t,e){const n=Hl(t.page??t.path).toLocaleLowerCase();return n==="index"||e&&n===e.toLocaleLowerCase()?0:1}function Qv(t){return t==="team"?"Team":"Personal"}function cQ(t){return t==="team"?"👥":"👤"}function zie(t,e,n){if(n!=="all"&&t.section!==n)return!1;const r=e.trim().toLocaleLowerCase();if(!r)return!0;const i=[t.title,t.summary,t.section,t.path,Hl(t),Qv(t.scope),...nm(t.path),...t.tags].join(" ").toLocaleLowerCase();return r.split(/\s+/).every(s=>i.includes(s))}function Hl(t){const e=typeof t=="string"?t:t.path;return(e.split("/").pop()??e).replace(/\.md$/i,"")||"untitled"}function KE(t){const e=nm(t),n=[];let r=Sl;for(const i of e.slice(0,-1))r=`${r}/${i}`,n.push(r);return n}function Bie(t,e){const n=nm(t),r=e.find(o=>o.path===t),i=[{label:"Wiki",path:Sl,type:"folder"}];let s=Sl;for(const[o,a]of n.entries()){const l=o===n.length-1;s=`${s}/${a}`,i.push({label:l?Hl(r??t):a,path:l?t:s,type:l?"page":"folder"})}return i}function uQ(t,e){for(const n of t){if(n.path===e)return n;if(n.type==="folder"){const r=uQ(n.children,e);if(r)return r}}return null}function Yb(t){for(const e of t){if(e.type==="page")return e.path;const n=Yb(e.children);if(n)return n}return null}function jie(t,e){if(t===Sl)return Yb(e);const n=uQ(e,t);return n?n.type==="page"?n.path:Yb(n.children):null}function hQ(t,e){return[...t].sort((n,r)=>{if(n.type!==r.type)return n.type==="folder"?-1:1;if(n.type==="page"&&r.type==="page"){const i=qE(n,e)-qE(r,e);if(i!==0)return i}return GE(n.name).localeCompare(GE(r.name),void 0,{numeric:!0,sensitivity:"base"})}).map(n=>n.type==="folder"?{...n,children:hQ(n.children,n.name)}:n)}function Uie(t){const e=[];for(const n of t){const r=nm(n.path);if(r.length===0)continue;let i=e,s=Sl;for(const[o,a]of r.entries()){const l=o===r.length-1;if(s=`${s}/${a}`,l){i.push({id:n.path,name:Hl(n),type:"page",path:n.path,children:[],page:n});continue}let c=i.find(u=>u.type==="folder"&&u.path===s);c||(c={id:s,name:a,type:"folder",path:s,children:[]},i.push(c)),i=c.children}}return hQ(e)}function dQ(t,e,n){return t.flatMap(r=>{if(r.type==="page")return r.page&&zie(r.page,e,n)?[r]:[];const i=dQ(r.children,e,n);return i.length>0?[{...r,children:i}]:[]})}function Zie({items:t,onOpenItem:e}){return w.jsx("nav",{className:"wiki-breadcrumbs","aria-label":"Wiki breadcrumbs",children:w.jsx("ol",{children:t.map((n,r)=>{const i=r===t.length-1;return w.jsx("li",{children:i?w.jsx("span",{"aria-current":"page",children:n.label}):w.jsx("button",{type:"button",className:"wiki-breadcrumb-button",onClick:()=>e(n),children:n.label})},`${n.type}-${n.path}`)})})})}function Fie(t){if(!t)return"Unknown update time";const e=new Date(t);return Number.isNaN(e.getTime())?t:new Intl.DateTimeFormat(void 0,{dateStyle:"medium",timeStyle:"short"}).format(e)}function Xie({page:t,breadcrumbs:e,onOpenBreadcrumb:n,onEdit:r,onDelete:i}){const s=Qv(t.scope),o=cQ(t.scope);return w.jsxs("header",{className:"wiki-page-header",children:[w.jsx(Zie,{items:e,onOpenItem:n}),w.jsxs("div",{className:"wiki-page-header-main",children:[w.jsxs("div",{className:"wiki-page-title-block",children:[w.jsx("h2",{children:t.title||Hl(t)}),t.summary?w.jsx("p",{className:"wiki-page-summary",children:t.summary}):null]}),w.jsxs("div",{className:"wiki-page-actions",children:[w.jsx("button",{type:"button",className:"btn",onClick:r,children:"Edit"}),w.jsx("button",{type:"button",className:"btn danger",onClick:i,children:"Delete"})]})]}),w.jsxs("div",{className:"wiki-meta",children:[w.jsxs("span",{className:`wiki-badge wiki-scope-badge wiki-scope-badge-${t.scope}`,children:[o," ",s]}),t.section?w.jsx("span",{className:"wiki-badge",children:t.section}):null,t.tags.map(a=>w.jsxs("span",{className:"wiki-tag",children:["#",a]},a)),w.jsxs("span",{className:"wiki-meta-item",children:["Updated ",Fie(t.updated)]}),w.jsx("code",{className:"wiki-meta-path",children:t.path})]})]})}function Wie({pages:t}){return t.some(n=>n.scope==="team")?w.jsxs("span",{className:"wiki-badge wiki-scope-badge wiki-scope-badge-team wiki-scope-indicator","aria-label":"Wiki scope: Personal + Team",children:[w.jsx("span",{"aria-hidden":"true",children:"👥"})," Personal + Team"]}):w.jsxs("span",{className:"wiki-badge wiki-scope-badge wiki-scope-badge-personal wiki-scope-indicator","aria-label":"Wiki scope: Personal",children:[w.jsx("span",{"aria-hidden":"true",children:"👤"})," Personal"]})}const Vie=P.forwardRef(function({query:e,onQueryChange:n,sectionFilter:r,onSectionFilterChange:i,sections:s,resultCount:o,totalCount:a},l){const c=e.trim().length>0||r!=="all";return w.jsxs("div",{className:"wiki-search",children:[w.jsxs("label",{className:"wiki-search-field",htmlFor:"wiki-search-input",children:[w.jsx("span",{className:"sr-only",children:"Search wiki pages"}),w.jsx("input",{id:"wiki-search-input",ref:l,type:"search",value:e,onChange:u=>n(u.target.value),placeholder:"Search title, path, summary, tags…","aria-label":"Search wiki pages"})]}),w.jsxs("label",{className:"wiki-filter",htmlFor:"wiki-section-filter",children:[w.jsx("span",{children:"Section"}),w.jsxs("select",{id:"wiki-section-filter",value:r,onChange:u=>i(u.target.value),"aria-label":"Filter wiki pages by section",children:[w.jsx("option",{value:"all",children:"All sections"}),s.map(u=>w.jsx("option",{value:u,children:u},u))]})]}),w.jsx("div",{className:"wiki-search-meta","aria-live":"polite",children:c?`${o} of ${a} pages shown`:`${a} pages`})]})});function fQ(t){return t.type==="page"?1:t.children.reduce((e,n)=>e+fQ(n),0)}function pQ({node:t,depth:e,selectedPath:n,expandedPaths:r,onToggleFolder:i,onSelectPage:s,showPageMeta:o=!1}){var h;const a={paddingInlineStart:`${10+e*16}px`};if(t.type==="folder"){const d=r.has(t.path),f=fQ(t);return w.jsxs("li",{className:"wiki-node wiki-node-folder",children:[w.jsxs("button",{type:"button",className:`wiki-node-button wiki-node-folder-button${d?" expanded":""}`,style:a,onClick:()=>i(t.path),"aria-expanded":d,children:[w.jsx("span",{className:"wiki-node-icon","aria-hidden":"true",children:d?"▾":"▸"}),w.jsx("span",{className:"wiki-node-label",children:t.name}),w.jsx("span",{className:"wiki-node-count",children:f})]}),d?w.jsx("ul",{className:"wiki-tree-children",children:t.children.map(p=>w.jsx(pQ,{node:p,depth:e+1,selectedPath:n,expandedPaths:r,onToggleFolder:i,onSelectPage:s,showPageMeta:o},p.id))}):null]})}const l=((h=t.page)==null?void 0:h.scope)??"personal",c=cQ(l),u=Qv(l);return w.jsx("li",{className:"wiki-node wiki-node-page",children:w.jsxs("button",{type:"button",className:`wiki-node-button wiki-node-page-button${n===t.path?" selected":""}`,style:a,onClick:()=>s(t.path),"aria-pressed":n===t.path,children:[w.jsx("span",{className:`wiki-node-icon wiki-node-scope-icon wiki-node-scope-icon-${l}`,"aria-hidden":"true",children:c}),w.jsxs("span",{className:"wiki-node-content",children:[w.jsx("span",{className:"wiki-node-label",children:t.name}),o?w.jsx("span",{className:"wiki-node-meta",children:w.jsxs("span",{className:`wiki-scope-badge wiki-scope-badge-${l}`,children:[c," ",u]})}):null]})]})})}function Hie({nodes:t,selectedPath:e,expandedPaths:n,onToggleFolder:r,onSelectPage:i,showPageMeta:s=!1}){return w.jsx("ul",{className:"wiki-tree",children:t.map(o=>w.jsx(pQ,{node:o,depth:0,selectedPath:e,expandedPaths:n,onToggleFolder:r,onSelectPage:i,showPageMeta:s},o.id))})}function Yie({searchRef:t,query:e,onQueryChange:n,sectionFilter:r,onSectionFilterChange:i,sections:s,resultCount:o,totalCount:a,loading:l,tree:c,selectedPath:u,expandedPaths:h,onToggleFolder:d,onSelectPage:f,onCreatePage:p,onClearFilters:g}){const O=e.trim().length>0||r!=="all";return w.jsxs("nav",{className:"wiki-sidebar","aria-label":"Wiki navigation","aria-busy":l,children:[w.jsxs("div",{className:"wiki-sidebar-header",children:[w.jsxs("div",{className:"wiki-sidebar-header-row",children:[w.jsxs("div",{children:[w.jsx("h2",{children:"Browse pages"}),w.jsx("p",{className:"dim small",children:"Filesystem navigation with section filtering."})]}),w.jsx("button",{type:"button",className:"btn primary",onClick:p,children:"New page"})]}),w.jsx(Vie,{ref:t,query:e,onQueryChange:n,sectionFilter:r,onSectionFilterChange:i,sections:s,resultCount:o,totalCount:a}),w.jsx("div",{className:"wiki-shortcuts dim small",children:"/ search · n new page · e edit page"}),w.jsxs("div",{className:"wiki-scope-legend dim small","aria-label":"Wiki page scope legend",children:[w.jsxs("span",{children:[w.jsx("span",{"aria-hidden":"true",children:"👤"})," Personal"]}),w.jsxs("span",{children:[w.jsx("span",{"aria-hidden":"true",children:"👥"})," Team"]})]})]}),w.jsxs("div",{className:"wiki-sidebar-body",children:[l&&a===0?w.jsx(Jn,{inline:!0,label:"Loading wiki pages"}):null,!l&&a===0?w.jsx(Tp,{compact:!0,title:"No wiki pages yet",description:"Create the first page to start building your team handbook.",actions:w.jsx("button",{type:"button",className:"btn primary",onClick:p,children:"Create a page"})}):null,a>0&&c.length===0?w.jsx(Tp,{compact:!0,title:"No pages match",description:"Try a different search or clear the current section filter.",actions:O?w.jsx("button",{type:"button",className:"btn",onClick:g,children:"Clear filters"}):void 0}):null,c.length>0?w.jsx(Hie,{nodes:c,selectedPath:u,expandedPaths:h,onToggleFolder:d,onSelectPage:f,showPageMeta:O}):null]})]})}function vO(t,e){return Array.from(new Set([...t,...e]))}function gQ(t){return t.reduce((e,n)=>e+(n.type==="page"?1:gQ(n.children)),0)}function mQ(t){return t.flatMap(e=>e.type==="folder"?[e.path,...mQ(e.children)]:[])}function Gie(){const[t]=lR(),e=t.get("selected"),[n,r]=P.useState(null),[i,s]=P.useState(null),[o,a]=P.useState(!0),[l,c]=P.useState(!1),[u,h]=P.useState(null),[d,f]=P.useState(null),[p,g]=P.useState(""),[O,m]=P.useState("all"),[y,b]=P.useState([]),[v,x]=P.useState(0),S=es(),E=P.useRef(null);async function I(){a(!0);try{const Y=await rt.listPages();r(Y),h(null)}catch(Y){h(Y instanceof Error?Y.message:String(Y))}finally{a(!1)}}P.useEffect(()=>{I()},[]),P.useEffect(()=>{if(!e){s(null),f(null),c(!1);return}let Y=!1;return s(null),c(!0),rt.readPage(e).then(ge=>{Y||(s(ge.content),f(null))}).catch(ge=>{Y||f(ge instanceof Error?ge.message:String(ge))}).finally(()=>{Y||c(!1)}),()=>{Y=!0}},[e,v]),P.useEffect(()=>{e&&b(Y=>vO(Y,KE(e)))},[e]),P.useEffect(()=>{function Y(ue){return ue instanceof HTMLElement?!!ue.closest("input, textarea, select, [contenteditable='true']"):!1}function ge(ue){var mt,Lt;if(!(ue.defaultPrevented||ue.metaKey||ue.ctrlKey||ue.altKey)){if(ue.key==="/"&&!Y(ue.target)){ue.preventDefault(),(mt=E.current)==null||mt.focus(),(Lt=E.current)==null||Lt.select();return}Y(ue.target)||(ue.key.toLocaleLowerCase()==="n"&&(ue.preventDefault(),S("/wiki/edit?new=1")),ue.key.toLocaleLowerCase()==="e"&&e&&(ue.preventDefault(),S(`/wiki/edit?path=${encodeURIComponent(e)}`)))}}return window.addEventListener("keydown",ge),()=>window.removeEventListener("keydown",ge)},[S,e]);const M=P.useMemo(()=>n?Uie(n):[],[n]),_=P.useMemo(()=>dQ(M,p,O),[M,p,O]),$=P.useMemo(()=>gQ(_),[_]),Q=(n==null?void 0:n.length)??0,F=P.useMemo(()=>Array.from(new Set((n??[]).map(Y=>Y.section).filter(Boolean))).sort((Y,ge)=>Y.localeCompare(ge)),[n]),X=P.useMemo(()=>p.trim()||O!=="all"?mQ(_):[],[_,p,O]),W=P.useMemo(()=>new Set(vO(y,X)),[X,y]),T=P.useMemo(()=>e?(n==null?void 0:n.find(Y=>Y.path===e))??{path:e,title:Hl(e),summary:"",section:"",tags:[],updated:"",scope:"personal"}:null,[n,e]),D=P.useMemo(()=>e?Bie(e,n??[]):[],[n,e]);async function N(){if(!(!e||!confirm(`Delete ${e}?`)))try{await rt.deletePage(e),s(null),h(null),f(null),S("/wiki"),await I()}catch(Y){f(Y instanceof Error?Y.message:String(Y))}}function L(Y){S(`/wiki?selected=${encodeURIComponent(Y)}`)}function k(Y){b(ge=>ge.includes(Y)?ge.filter(ue=>ue!==Y):[...ge,Y])}function q(Y){if(g(""),Y.type==="page"){L(Y.path);return}if(Y.path==="pages"){S("/wiki");return}b(ue=>vO(ue,[...KE(Y.path),Y.path]));const ge=jie(Y.path,M);ge&&L(ge)}const J=u??d,A=u?()=>void I():()=>x(Y=>Y+1);return w.jsxs("div",{className:"page wiki",children:[w.jsxs("header",{className:"page-header",children:[w.jsxs("div",{className:"wiki-scope-header-row",children:[w.jsx("h1",{children:"Wiki"}),n!==null&&w.jsx(Wie,{pages:n})]}),w.jsx("p",{className:"dim",children:"A docs-style browser for Chapterhouse's shared engineering knowledge, stored at ~/.chapterhouse/wiki/."})]}),J?w.jsx(br,{inline:!0,message:J,onRetry:A}):null,w.jsxs("div",{className:"wiki-layout",children:[w.jsx(Yie,{searchRef:E,query:p,onQueryChange:g,sectionFilter:O,onSectionFilterChange:m,sections:F,resultCount:$,totalCount:Q,loading:o,tree:_,selectedPath:e,expandedPaths:W,onToggleFolder:k,onSelectPage:L,onCreatePage:()=>S("/wiki/edit?new=1"),onClearFilters:()=>{g(""),m("all")}}),w.jsx("section",{className:"wiki-main","aria-live":"polite",children:T?w.jsxs("article",{className:"wiki-document",children:[w.jsx(Xie,{page:T,breadcrumbs:D,onOpenBreadcrumb:q,onEdit:()=>S(`/wiki/edit?path=${encodeURIComponent(T.path)}`),onDelete:()=>void N()}),w.jsx("div",{className:"wiki-document-body",children:l?w.jsx(Jn,{inline:!0,label:"Loading page"}):i!==null?w.jsx("div",{className:"wiki-article",children:w.jsx(aQ,{content:i})}):w.jsx(Tp,{compact:!0,title:"Page unavailable",description:"The page metadata loaded, but the content could not be shown yet. Try reloading the page.",actions:w.jsx("button",{type:"button",className:"btn",onClick:A,children:"Retry"})})})]}):w.jsx(Tp,{title:Q===0?"Start the wiki":"Pick a page",description:Q===0?"Create the first page and the wiki will organize itself into folders from its path.":"Choose a page from the sidebar, or create a new one if the answer does not exist yet.",actions:w.jsx("button",{type:"button",className:"btn primary",onClick:()=>S("/wiki/edit?new=1"),children:"New page"})})})]})]})}function Gb(){return Gb=Object.assign?Object.assign.bind():function(t){for(var e=1;e<arguments.length;e++){var n=arguments[e];for(var r in n)({}).hasOwnProperty.call(n,r)&&(t[r]=n[r])}return t},Gb.apply(null,arguments)}function qie(t,e){if(t==null)return{};var n={};for(var r in t)if({}.hasOwnProperty.call(t,r)){if(e.indexOf(r)!==-1)continue;n[r]=t[r]}return n}let qb=[],OQ=[];(()=>{let t="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,3b,f,,w,1j,,,,4,8,4,,3,7,a,2,t,,1m,,,,2,4,8,,9,,a,2,q,,2,2,1l,,4,2,4,2,2,3,3,,u,2,3,,b,2,1l,,4,5,,2,4,,k,2,m,6,,,1m,,,2,,4,8,,7,3,a,2,u,,1n,,,,c,,9,,14,,3,,1l,3,5,3,,4,7,2,b,2,t,,1m,,2,,2,,3,,5,2,7,2,b,2,s,2,1l,2,,,2,4,8,,9,,a,2,t,,20,,4,,2,3,,,8,,29,,2,7,c,8,2q,,2,9,b,6,22,2,r,,,,,,1j,e,,5,,2,5,b,,10,9,,2u,4,,6,,2,2,2,p,2,4,3,g,4,d,,2,2,6,,f,,jj,3,qa,3,t,3,t,2,u,2,1s,2,,7,8,,2,b,9,,19,3,3b,2,y,,3a,3,4,2,9,,6,3,63,2,2,,1m,,,7,,,,,2,8,6,a,2,,1c,h,1r,4,1c,7,,,5,,14,9,c,2,w,4,2,2,,3,1k,,,2,3,,,3,1m,8,2,2,48,3,,d,,7,4,,6,,3,2,5i,1m,,5,ek,,5f,x,2da,3,3x,,2o,w,fe,6,2x,2,n9w,4,,a,w,2,28,2,7k,,3,,4,,p,2,5,,47,2,q,i,d,,12,8,p,b,1a,3,1c,,2,4,2,2,13,,1v,6,2,2,2,2,c,,8,,1b,,1f,,,3,2,2,5,2,,,16,2,8,,6m,,2,,4,,fn4,,kh,g,g,g,a6,2,gt,,6a,,45,5,1ae,3,,2,5,4,14,3,4,,4l,2,fx,4,ar,2,49,b,4w,,1i,f,1k,3,1d,4,2,2,1x,3,10,5,,8,1q,,c,2,1g,9,a,4,2,,2n,3,2,,,2,6,,4g,,3,8,l,2,1l,2,,,,,m,,e,7,3,5,5f,8,2,3,,,n,,29,,2,6,,,2,,,2,,2,6j,,2,4,6,2,,2,r,2,2d,8,2,,,2,2y,,,,2,6,,,2t,3,2,4,,5,77,9,,2,6t,,a,2,,,4,,40,4,2,2,4,,w,a,14,6,2,4,8,,9,6,2,3,1a,d,,2,ba,7,,6,,,2a,m,2,7,,2,,2,3e,6,3,,,2,,7,,,20,2,3,,,,9n,2,f0b,5,1n,7,t4,,1r,4,29,,f5k,2,43q,,,3,4,5,8,8,2,7,u,4,44,3,1iz,1j,4,1e,8,,e,,m,5,,f,11s,7,,h,2,7,,2,,5,79,7,c5,4,15s,7,31,7,240,5,gx7k,2o,3k,6o".split(",").map(e=>e?parseInt(e,36):1);for(let e=0,n=0;e<t.length;e++)(e%2?OQ:qb).push(n=n+t[e])})();function Kie(t){if(t<768)return!1;for(let e=0,n=qb.length;;){let r=e+n>>1;if(t<qb[r])n=r;else if(t>=OQ[r])e=r+1;else return!0;if(e==n)return!1}}function JE(t){return t>=127462&&t<=127487}const e_=8205;function Jie(t,e,n=!0,r=!0){return(n?yQ:ese)(t,e,r)}function yQ(t,e,n){if(e==t.length)return e;e&&bQ(t.charCodeAt(e))&&wQ(t.charCodeAt(e-1))&&e--;let r=xO(t,e);for(e+=t_(r);e<t.length;){let i=xO(t,e);if(r==e_||i==e_||n&&Kie(i))e+=t_(i),r=i;else if(JE(i)){let s=0,o=e-2;for(;o>=0&&JE(xO(t,o));)s++,o-=2;if(s%2==0)break;e+=2}else break}return e}function ese(t,e,n){for(;e>0;){let r=yQ(t,e-2,n);if(r<e)return r;e--}return 0}function xO(t,e){let n=t.charCodeAt(e);if(!wQ(n)||e+1==t.length)return n;let r=t.charCodeAt(e+1);return bQ(r)?(n-55296<<10)+(r-56320)+65536:n}function bQ(t){return t>=56320&&t<57344}function wQ(t){return t>=55296&&t<56320}function t_(t){return t<65536?1:2}class Ae{lineAt(e){if(e<0||e>this.length)throw new 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 new RangeError(`Invalid line number ${e} in ${this.lines}-line document`);return this.lineInner(e,!0,1,0)}replace(e,n,r){[e,n]=kl(this,e,n);let i=[];return this.decompose(0,e,i,2),r.length&&r.decompose(0,r.length,i,3),this.decompose(n,this.length,i,1),oi.from(i,this.length-(n-e)+r.length)}append(e){return this.replace(this.length,this.length,e)}slice(e,n=this.length){[e,n]=kl(this,e,n);let r=[];return this.decompose(e,n,r,0),oi.from(r,n-e)}eq(e){if(e==this)return!0;if(e.length!=this.length||e.lines!=this.lines)return!1;let n=this.scanIdentical(e,1),r=this.length-this.scanIdentical(e,-1),i=new tu(this),s=new tu(e);for(let o=n,a=n;;){if(i.next(o),s.next(o),o=0,i.lineBreak!=s.lineBreak||i.done!=s.done||i.value!=s.value)return!1;if(a+=i.value.length,i.done||a>=r)return!0}}iter(e=1){return new tu(this,e)}iterRange(e,n=this.length){return new SQ(this,e,n)}iterLines(e,n){let r;if(e==null)r=this.iter();else{n==null&&(n=this.lines+1);let i=this.line(e).from;r=this.iterRange(i,Math.max(i,n==this.lines+1?this.length:n<=1?0:this.line(n-1).to))}return new kQ(r)}toString(){return this.sliceString(0)}toJSON(){let e=[];return this.flatten(e),e}constructor(){}static of(e){if(e.length==0)throw new RangeError("A document must have at least one line");return e.length==1&&!e[0]?Ae.empty:e.length<=32?new yt(e):oi.from(yt.split(e,[]))}}class yt extends Ae{constructor(e,n=tse(e)){super(),this.text=e,this.length=n}get lines(){return this.text.length}get children(){return null}lineInner(e,n,r,i){for(let s=0;;s++){let o=this.text[s],a=i+o.length;if((n?r:a)>=e)return new nse(i,a,r,o);i=a+1,r++}}decompose(e,n,r,i){let s=e<=0&&n>=this.length?this:new yt(n_(this.text,e,n),Math.min(n,this.length)-Math.max(0,e));if(i&1){let o=r.pop(),a=gf(s.text,o.text.slice(),0,s.length);if(a.length<=32)r.push(new yt(a,o.length+s.length));else{let l=a.length>>1;r.push(new yt(a.slice(0,l)),new yt(a.slice(l)))}}else r.push(s)}replace(e,n,r){if(!(r instanceof yt))return super.replace(e,n,r);[e,n]=kl(this,e,n);let i=gf(this.text,gf(r.text,n_(this.text,0,e)),n),s=this.length+r.length-(n-e);return i.length<=32?new yt(i,s):oi.from(yt.split(i,[]),s)}sliceString(e,n=this.length,r=`
|
|
179
|
+
`).find(T=>T.startsWith("data: "));if(W)try{const T=JSON.parse(W.slice(6));if(T.type==="task_event"&&typeof T.seq=="number"&&T.seq>_){_=T.seq;const D={id:typeof T.id=="number"?T.id:0,taskId:typeof T.taskId=="string"?T.taskId:O,seq:T.seq,ts:typeof T.ts=="number"?T.ts:Date.now(),kind:T.kind==="tool_complete"?"tool_complete":"tool_start",toolName:typeof T.toolName=="string"?T.toolName:null,summary:typeof T.summary=="string"?T.summary:null};s(N=>[...N,D])}}catch{}}}}catch(b){if(b instanceof Error&&b.name==="AbortError")return}}async function p(O){try{const m=await rt.getWorker(O.taskId);r(m),s([]),a(null),f(O.taskId)}catch(m){a(m instanceof Error?m.message:String(m))}}P.useEffect(()=>()=>{var O;(O=u.current)==null||O.abort()},[]);function g(O){return new Date(O).toLocaleTimeString([],{hour:"2-digit",minute:"2-digit",second:"2-digit"})}return w.jsxs("div",{className:"page workers",children:[w.jsxs("header",{className:"page-header",children:[w.jsx("h1",{children:"Workers"}),w.jsx("p",{className:"dim",children:"Active and recent agent tasks (last 24 h). Updates every 4s."})]}),o?w.jsx(br,{inline:!0,message:o,onRetry:()=>void d()}):null,w.jsxs("div",{className:"workers-layout",children:[w.jsxs("div",{className:"workers-list","aria-busy":l,children:[l&&t===null?w.jsx(Jn,{inline:!0,label:"Loading workers"}):null,t&&t.length===0?w.jsx(yl,{icon:"🤖",title:"No tasks yet",description:"No agent tasks in the last 24 hours."}):null,t==null?void 0:t.map(O=>w.jsxs("button",{type:"button",className:"worker-row"+((n==null?void 0:n.taskId)===O.taskId?" selected":""),onClick:()=>void p(O),"aria-pressed":(n==null?void 0:n.taskId)===O.taskId,children:[w.jsxs("div",{className:"worker-row-head",children:[w.jsx("strong",{children:O.name||`@${O.slug}`}),w.jsx("span",{className:`worker-status worker-status--${O.status}`,children:O.status})]}),w.jsx("div",{className:"worker-row-desc",children:O.description}),w.jsxs("div",{className:"dim small",children:["@",O.slug," · ",O.model]})]},O.taskId))]}),w.jsx("div",{className:"workers-detail","aria-live":"polite",children:n?w.jsxs(w.Fragment,{children:[w.jsxs("h2",{children:[n.name||n.agentSlug," ",w.jsxs("span",{className:"dim worker-detail-slug",children:["@",n.agentSlug]})]}),w.jsx("p",{className:"worker-detail-description",children:n.description}),w.jsxs("p",{className:"dim small worker-detail-meta",children:[w.jsx("span",{className:`worker-status worker-status--${n.status}`,children:n.status})," · ","started ",n.startedAt,n.completedAt?` · completed ${n.completedAt}`:""," · ",w.jsx("span",{className:"worker-detail-taskid",children:n.taskId})]}),w.jsx("h3",{children:"Activity"}),i.length===0&&n.status==="running"?w.jsx("p",{className:"dim small",children:"Waiting for tool-call activity…"}):i.length===0?w.jsx("p",{className:"dim small",children:"(no tool-call activity recorded)"}):w.jsx("div",{className:"worker-events",ref:h,children:i.map(O=>w.jsxs("div",{className:`worker-event worker-event--${O.kind}`,children:[w.jsx("span",{className:"worker-event-ts",children:g(O.ts)}),O.kind==="tool_start"?w.jsxs("span",{className:"worker-event-body",children:[w.jsx("span",{className:"worker-event-icon",children:"⚙️"}),w.jsx("strong",{children:O.toolName??"tool"}),O.summary?w.jsxs("span",{className:"dim",children:[" — ",O.summary]}):null]}):w.jsxs("span",{className:"worker-event-body",children:[w.jsx("span",{className:"worker-event-icon",children:"✅"}),O.summary?w.jsx("span",{className:"dim",children:O.summary}):w.jsx("span",{className:"dim",children:"done"})]})]},O.id))}),w.jsx("h3",{children:"Result"}),w.jsx("pre",{className:"output",children:n.result??"(no output yet — task still running)"})]}):w.jsx(yl,{icon:"👈",title:"Pick a worker",description:"Select a task from the list to inspect its details."})})]})]})}function Die(){const[t,e]=P.useState(null),[n,r]=P.useState(null),[i,s]=P.useState(!0),[o,a]=P.useState(!1),[l,c]=P.useState(!1),[u,h]=P.useState(""),[d,f]=P.useState(!1),[p,g]=P.useState(null),O=P.useRef(null),m=es();async function y(){s(!0);try{const S=await df.list();e(S),r(null),a(!1)}catch(S){const E=S instanceof Error?S.message:String(S);E.includes("503")||E.toLowerCase().includes("squad integration is disabled")?(a(!0),e([])):r(E)}finally{s(!1)}}P.useEffect(()=>{y()},[]),P.useEffect(()=>{var S;l&&((S=O.current)==null||S.focus())},[l]);async function b(S){S.preventDefault();const E=u.trim();if(E){f(!0),g(null);try{await df.register(E),h(""),c(!1),await y()}catch(I){g(I instanceof Error?I.message:String(I))}finally{f(!1)}}}async function v(S){try{await df.remove(S),await y()}catch(E){r(E instanceof Error?E.message:String(E))}}function x(S){m(`/projects/chat/${b$(S)}`)}return w.jsxs("div",{className:"page projects",children:[w.jsxs("header",{className:"page-header",children:[w.jsx("h1",{children:"Projects"}),w.jsxs("p",{className:"dim",children:["Registered Squad projects. Each project needs a ",w.jsx("code",{children:".squad/"})," directory."]})]}),o?w.jsx("div",{className:"projects-disabled",role:"status",children:w.jsxs("p",{children:[w.jsx("strong",{children:"Squad integration is disabled."})," Set"," ",w.jsx("code",{children:"ENABLE_SQUAD=1"})," in your environment to enable project features."]})}):w.jsxs(w.Fragment,{children:[n?w.jsx(br,{inline:!0,message:n,onRetry:()=>void y()}):null,w.jsx("div",{className:"projects-toolbar",children:l?w.jsxs("form",{className:"projects-register-form",onSubmit:S=>void b(S),children:[w.jsx("input",{ref:O,type:"text",className:"projects-path-input",placeholder:"/absolute/path/to/project",value:u,onChange:S=>h(S.target.value),"aria-label":"Project path",disabled:d}),w.jsx("button",{type:"submit",className:"btn primary",disabled:d||!u.trim(),children:d?"Registering…":"Add"}),w.jsx("button",{type:"button",className:"btn",onClick:()=>{c(!1),g(null),h("")},disabled:d,children:"Cancel"}),p?w.jsx("span",{className:"projects-register-error dim",role:"alert",children:p}):null]}):w.jsx("button",{type:"button",className:"btn primary",onClick:()=>c(!0),"aria-expanded":l,children:"Register Project"})}),i&&t===null?w.jsx(Jn,{inline:!0,label:"Loading projects"}):w.jsxs("div",{className:"projects-list","aria-busy":i,children:[t&&t.length===0?w.jsx(yl,{icon:"🗂️",title:"No projects registered",description:"Add a project path above to get started."}):null,t==null?void 0:t.map(S=>w.jsxs("div",{className:"project-row",children:[w.jsxs("div",{className:"project-row-info",children:[w.jsx("strong",{className:"project-root",title:S.projectRoot,children:S.projectRoot}),w.jsxs("span",{className:"project-meta dim",children:[w.jsxs("span",{className:"project-badge",children:[S.agentCount," agent",S.agentCount!==1?"s":""]}),w.jsx("span",{children:S.squadDir}),w.jsxs("span",{children:["loaded ",S.loadedAt]})]})]}),w.jsxs("div",{className:"project-row-actions",children:[w.jsx("button",{type:"button",className:"btn primary",onClick:()=>x(S.projectRoot),"aria-label":`New session for ${S.projectRoot}`,children:"Chat in Project Context"}),w.jsx("button",{type:"button",className:"btn danger",onClick:()=>void v(S.projectRoot),"aria-label":`Remove ${S.projectRoot}`,children:"×"})]})]},S.projectRoot))]})]})]})}function Tp({title:t,description:e,actions:n,compact:r=!1}){return w.jsxs("div",{className:`wiki-empty-state${r?" compact":""}`,children:[w.jsx("h2",{children:t}),w.jsx("p",{children:e}),n?w.jsx("div",{className:"wiki-empty-state-actions",children:n}):null]})}const Sl="pages";function nm(t){return t.replace(new RegExp(`^${Sl}/?`),"").split("/").filter(Boolean)}function GE(t){return t.toLocaleLowerCase()}function qE(t,e){const n=Hl(t.page??t.path).toLocaleLowerCase();return n==="index"||e&&n===e.toLocaleLowerCase()?0:1}function Qv(t){return t==="team"?"Team":"Personal"}function cQ(t){return t==="team"?"👥":"👤"}function zie(t,e,n){if(n!=="all"&&t.section!==n)return!1;const r=e.trim().toLocaleLowerCase();if(!r)return!0;const i=[t.title,t.summary,t.section,t.path,Hl(t),Qv(t.scope),...nm(t.path),...t.tags].join(" ").toLocaleLowerCase();return r.split(/\s+/).every(s=>i.includes(s))}function Hl(t){const e=typeof t=="string"?t:t.path;return(e.split("/").pop()??e).replace(/\.md$/i,"")||"untitled"}function KE(t){const e=nm(t),n=[];let r=Sl;for(const i of e.slice(0,-1))r=`${r}/${i}`,n.push(r);return n}function Bie(t,e){const n=nm(t),r=e.find(o=>o.path===t),i=[{label:"Wiki",path:Sl,type:"folder"}];let s=Sl;for(const[o,a]of n.entries()){const l=o===n.length-1;s=`${s}/${a}`,i.push({label:l?Hl(r??t):a,path:l?t:s,type:l?"page":"folder"})}return i}function uQ(t,e){for(const n of t){if(n.path===e)return n;if(n.type==="folder"){const r=uQ(n.children,e);if(r)return r}}return null}function Yb(t){for(const e of t){if(e.type==="page")return e.path;const n=Yb(e.children);if(n)return n}return null}function jie(t,e){if(t===Sl)return Yb(e);const n=uQ(e,t);return n?n.type==="page"?n.path:Yb(n.children):null}function hQ(t,e){return[...t].sort((n,r)=>{if(n.type!==r.type)return n.type==="folder"?-1:1;if(n.type==="page"&&r.type==="page"){const i=qE(n,e)-qE(r,e);if(i!==0)return i}return GE(n.name).localeCompare(GE(r.name),void 0,{numeric:!0,sensitivity:"base"})}).map(n=>n.type==="folder"?{...n,children:hQ(n.children,n.name)}:n)}function Uie(t){const e=[];for(const n of t){const r=nm(n.path);if(r.length===0)continue;let i=e,s=Sl;for(const[o,a]of r.entries()){const l=o===r.length-1;if(s=`${s}/${a}`,l){i.push({id:n.path,name:Hl(n),type:"page",path:n.path,children:[],page:n});continue}let c=i.find(u=>u.type==="folder"&&u.path===s);c||(c={id:s,name:a,type:"folder",path:s,children:[]},i.push(c)),i=c.children}}return hQ(e)}function dQ(t,e,n){return t.flatMap(r=>{if(r.type==="page")return r.page&&zie(r.page,e,n)?[r]:[];const i=dQ(r.children,e,n);return i.length>0?[{...r,children:i}]:[]})}function Zie({items:t,onOpenItem:e}){return w.jsx("nav",{className:"wiki-breadcrumbs","aria-label":"Wiki breadcrumbs",children:w.jsx("ol",{children:t.map((n,r)=>{const i=r===t.length-1;return w.jsx("li",{children:i?w.jsx("span",{"aria-current":"page",children:n.label}):w.jsx("button",{type:"button",className:"wiki-breadcrumb-button",onClick:()=>e(n),children:n.label})},`${n.type}-${n.path}`)})})})}function Fie(t){if(!t)return"Unknown update time";const e=new Date(t);return Number.isNaN(e.getTime())?t:new Intl.DateTimeFormat(void 0,{dateStyle:"medium",timeStyle:"short"}).format(e)}function Xie({page:t,breadcrumbs:e,onOpenBreadcrumb:n,onEdit:r,onDelete:i}){const s=Qv(t.scope),o=cQ(t.scope);return w.jsxs("header",{className:"wiki-page-header",children:[w.jsx(Zie,{items:e,onOpenItem:n}),w.jsxs("div",{className:"wiki-page-header-main",children:[w.jsxs("div",{className:"wiki-page-title-block",children:[w.jsx("h2",{children:t.title||Hl(t)}),t.summary?w.jsx("p",{className:"wiki-page-summary",children:t.summary}):null]}),w.jsxs("div",{className:"wiki-page-actions",children:[w.jsx("button",{type:"button",className:"btn",onClick:r,children:"Edit"}),w.jsx("button",{type:"button",className:"btn danger",onClick:i,children:"Delete"})]})]}),w.jsxs("div",{className:"wiki-meta",children:[w.jsxs("span",{className:`wiki-badge wiki-scope-badge wiki-scope-badge-${t.scope}`,children:[o," ",s]}),t.section?w.jsx("span",{className:"wiki-badge",children:t.section}):null,t.tags.map(a=>w.jsxs("span",{className:"wiki-tag",children:["#",a]},a)),w.jsxs("span",{className:"wiki-meta-item",children:["Updated ",Fie(t.updated)]}),w.jsx("code",{className:"wiki-meta-path",children:t.path})]})]})}function Wie({pages:t}){return t.some(n=>n.scope==="team")?w.jsxs("span",{className:"wiki-badge wiki-scope-badge wiki-scope-badge-team wiki-scope-indicator","aria-label":"Wiki scope: Personal + Team",children:[w.jsx("span",{"aria-hidden":"true",children:"👥"})," Personal + Team"]}):w.jsxs("span",{className:"wiki-badge wiki-scope-badge wiki-scope-badge-personal wiki-scope-indicator","aria-label":"Wiki scope: Personal",children:[w.jsx("span",{"aria-hidden":"true",children:"👤"})," Personal"]})}const Vie=P.forwardRef(function({query:e,onQueryChange:n,sectionFilter:r,onSectionFilterChange:i,sections:s,resultCount:o,totalCount:a},l){const c=e.trim().length>0||r!=="all";return w.jsxs("div",{className:"wiki-search",children:[w.jsxs("label",{className:"wiki-search-field",htmlFor:"wiki-search-input",children:[w.jsx("span",{className:"sr-only",children:"Search wiki pages"}),w.jsx("input",{id:"wiki-search-input",ref:l,type:"search",value:e,onChange:u=>n(u.target.value),placeholder:"Search title, path, summary, tags…","aria-label":"Search wiki pages"})]}),w.jsxs("label",{className:"wiki-filter",htmlFor:"wiki-section-filter",children:[w.jsx("span",{children:"Section"}),w.jsxs("select",{id:"wiki-section-filter",value:r,onChange:u=>i(u.target.value),"aria-label":"Filter wiki pages by section",children:[w.jsx("option",{value:"all",children:"All sections"}),s.map(u=>w.jsx("option",{value:u,children:u},u))]})]}),w.jsx("div",{className:"wiki-search-meta","aria-live":"polite",children:c?`${o} of ${a} pages shown`:`${a} pages`})]})});function fQ(t){return t.type==="page"?1:t.children.reduce((e,n)=>e+fQ(n),0)}function pQ({node:t,depth:e,selectedPath:n,expandedPaths:r,onToggleFolder:i,onSelectPage:s,showPageMeta:o=!1}){var h;const a={paddingInlineStart:`${10+e*16}px`};if(t.type==="folder"){const d=r.has(t.path),f=fQ(t);return w.jsxs("li",{className:"wiki-node wiki-node-folder",children:[w.jsxs("button",{type:"button",className:`wiki-node-button wiki-node-folder-button${d?" expanded":""}`,style:a,onClick:()=>i(t.path),"aria-expanded":d,children:[w.jsx("span",{className:"wiki-node-icon","aria-hidden":"true",children:d?"▾":"▸"}),w.jsx("span",{className:"wiki-node-label",children:t.name}),w.jsx("span",{className:"wiki-node-count",children:f})]}),d?w.jsx("ul",{className:"wiki-tree-children",children:t.children.map(p=>w.jsx(pQ,{node:p,depth:e+1,selectedPath:n,expandedPaths:r,onToggleFolder:i,onSelectPage:s,showPageMeta:o},p.id))}):null]})}const l=((h=t.page)==null?void 0:h.scope)??"personal",c=cQ(l),u=Qv(l);return w.jsx("li",{className:"wiki-node wiki-node-page",children:w.jsxs("button",{type:"button",className:`wiki-node-button wiki-node-page-button${n===t.path?" selected":""}`,style:a,onClick:()=>s(t.path),"aria-pressed":n===t.path,children:[w.jsx("span",{className:`wiki-node-icon wiki-node-scope-icon wiki-node-scope-icon-${l}`,"aria-hidden":"true",children:c}),w.jsxs("span",{className:"wiki-node-content",children:[w.jsx("span",{className:"wiki-node-label",children:t.name}),o?w.jsx("span",{className:"wiki-node-meta",children:w.jsxs("span",{className:`wiki-scope-badge wiki-scope-badge-${l}`,children:[c," ",u]})}):null]})]})})}function Hie({nodes:t,selectedPath:e,expandedPaths:n,onToggleFolder:r,onSelectPage:i,showPageMeta:s=!1}){return w.jsx("ul",{className:"wiki-tree",children:t.map(o=>w.jsx(pQ,{node:o,depth:0,selectedPath:e,expandedPaths:n,onToggleFolder:r,onSelectPage:i,showPageMeta:s},o.id))})}function Yie({searchRef:t,query:e,onQueryChange:n,sectionFilter:r,onSectionFilterChange:i,sections:s,resultCount:o,totalCount:a,loading:l,tree:c,selectedPath:u,expandedPaths:h,onToggleFolder:d,onSelectPage:f,onCreatePage:p,onClearFilters:g}){const O=e.trim().length>0||r!=="all";return w.jsxs("nav",{className:"wiki-sidebar","aria-label":"Wiki navigation","aria-busy":l,children:[w.jsxs("div",{className:"wiki-sidebar-header",children:[w.jsxs("div",{className:"wiki-sidebar-header-row",children:[w.jsxs("div",{children:[w.jsx("h2",{children:"Browse pages"}),w.jsx("p",{className:"dim small",children:"Filesystem navigation with section filtering."})]}),w.jsx("button",{type:"button",className:"btn primary",onClick:p,children:"New page"})]}),w.jsx(Vie,{ref:t,query:e,onQueryChange:n,sectionFilter:r,onSectionFilterChange:i,sections:s,resultCount:o,totalCount:a}),w.jsx("div",{className:"wiki-shortcuts dim small",children:"/ search · n new page · e edit page"}),w.jsxs("div",{className:"wiki-scope-legend dim small","aria-label":"Wiki page scope legend",children:[w.jsxs("span",{children:[w.jsx("span",{"aria-hidden":"true",children:"👤"})," Personal"]}),w.jsxs("span",{children:[w.jsx("span",{"aria-hidden":"true",children:"👥"})," Team"]})]})]}),w.jsxs("div",{className:"wiki-sidebar-body",children:[l&&a===0?w.jsx(Jn,{inline:!0,label:"Loading wiki pages"}):null,!l&&a===0?w.jsx(Tp,{compact:!0,title:"No wiki pages yet",description:"Create the first page to start building your team handbook.",actions:w.jsx("button",{type:"button",className:"btn primary",onClick:p,children:"Create a page"})}):null,a>0&&c.length===0?w.jsx(Tp,{compact:!0,title:"No pages match",description:"Try a different search or clear the current section filter.",actions:O?w.jsx("button",{type:"button",className:"btn",onClick:g,children:"Clear filters"}):void 0}):null,c.length>0?w.jsx(Hie,{nodes:c,selectedPath:u,expandedPaths:h,onToggleFolder:d,onSelectPage:f,showPageMeta:O}):null]})]})}function vO(t,e){return Array.from(new Set([...t,...e]))}function gQ(t){return t.reduce((e,n)=>e+(n.type==="page"?1:gQ(n.children)),0)}function mQ(t){return t.flatMap(e=>e.type==="folder"?[e.path,...mQ(e.children)]:[])}function Gie(){const[t]=lR(),e=t.get("selected"),[n,r]=P.useState(null),[i,s]=P.useState(null),[o,a]=P.useState(!0),[l,c]=P.useState(!1),[u,h]=P.useState(null),[d,f]=P.useState(null),[p,g]=P.useState(""),[O,m]=P.useState("all"),[y,b]=P.useState([]),[v,x]=P.useState(0),S=es(),E=P.useRef(null);async function I(){a(!0);try{const Y=await rt.listPages();r(Y),h(null)}catch(Y){h(Y instanceof Error?Y.message:String(Y))}finally{a(!1)}}P.useEffect(()=>{I()},[]),P.useEffect(()=>{if(!e){s(null),f(null),c(!1);return}let Y=!1;return s(null),c(!0),rt.readPage(e).then(ge=>{Y||(s(ge.content),f(null))}).catch(ge=>{Y||f(ge instanceof Error?ge.message:String(ge))}).finally(()=>{Y||c(!1)}),()=>{Y=!0}},[e,v]),P.useEffect(()=>{e&&b(Y=>vO(Y,KE(e)))},[e]),P.useEffect(()=>{function Y(ue){return ue instanceof HTMLElement?!!ue.closest("input, textarea, select, [contenteditable='true']"):!1}function ge(ue){var mt,Lt;if(!(ue.defaultPrevented||ue.metaKey||ue.ctrlKey||ue.altKey)){if(ue.key==="/"&&!Y(ue.target)){ue.preventDefault(),(mt=E.current)==null||mt.focus(),(Lt=E.current)==null||Lt.select();return}Y(ue.target)||(ue.key.toLocaleLowerCase()==="n"&&(ue.preventDefault(),S("/wiki/edit?new=1")),ue.key.toLocaleLowerCase()==="e"&&e&&(ue.preventDefault(),S(`/wiki/edit?path=${encodeURIComponent(e)}`)))}}return window.addEventListener("keydown",ge),()=>window.removeEventListener("keydown",ge)},[S,e]);const M=P.useMemo(()=>n?Uie(n):[],[n]),_=P.useMemo(()=>dQ(M,p,O),[M,p,O]),$=P.useMemo(()=>gQ(_),[_]),Q=(n==null?void 0:n.length)??0,F=P.useMemo(()=>Array.from(new Set((n??[]).map(Y=>Y.section).filter(Boolean))).sort((Y,ge)=>Y.localeCompare(ge)),[n]),X=P.useMemo(()=>p.trim()||O!=="all"?mQ(_):[],[_,p,O]),W=P.useMemo(()=>new Set(vO(y,X)),[X,y]),T=P.useMemo(()=>e?(n==null?void 0:n.find(Y=>Y.path===e))??{path:e,title:Hl(e),summary:"",section:"",tags:[],updated:"",scope:"personal"}:null,[n,e]),D=P.useMemo(()=>e?Bie(e,n??[]):[],[n,e]);async function N(){if(!(!e||!confirm(`Delete ${e}?`)))try{await rt.deletePage(e),s(null),h(null),f(null),S("/wiki"),await I()}catch(Y){f(Y instanceof Error?Y.message:String(Y))}}function L(Y){S(`/wiki?selected=${encodeURIComponent(Y)}`)}function k(Y){b(ge=>ge.includes(Y)?ge.filter(ue=>ue!==Y):[...ge,Y])}function q(Y){if(g(""),Y.type==="page"){L(Y.path);return}if(Y.path==="pages"){S("/wiki");return}b(ue=>vO(ue,[...KE(Y.path),Y.path]));const ge=jie(Y.path,M);ge&&L(ge)}const J=u??d,A=u?()=>void I():()=>x(Y=>Y+1);return w.jsxs("div",{className:"page wiki",children:[w.jsxs("header",{className:"page-header",children:[w.jsxs("div",{className:"wiki-scope-header-row",children:[w.jsx("h1",{children:"Wiki"}),n!==null&&w.jsx(Wie,{pages:n})]}),w.jsx("p",{className:"dim",children:"A docs-style browser for Chapterhouse's shared engineering knowledge, stored at ~/.chapterhouse/wiki/."})]}),J?w.jsx(br,{inline:!0,message:J,onRetry:A}):null,w.jsxs("div",{className:"wiki-layout",children:[w.jsx(Yie,{searchRef:E,query:p,onQueryChange:g,sectionFilter:O,onSectionFilterChange:m,sections:F,resultCount:$,totalCount:Q,loading:o,tree:_,selectedPath:e,expandedPaths:W,onToggleFolder:k,onSelectPage:L,onCreatePage:()=>S("/wiki/edit?new=1"),onClearFilters:()=>{g(""),m("all")}}),w.jsx("section",{className:"wiki-main","aria-live":"polite",children:T?w.jsxs("article",{className:"wiki-document",children:[w.jsx(Xie,{page:T,breadcrumbs:D,onOpenBreadcrumb:q,onEdit:()=>S(`/wiki/edit?path=${encodeURIComponent(T.path)}`),onDelete:()=>void N()}),w.jsx("div",{className:"wiki-document-body",children:l?w.jsx(Jn,{inline:!0,label:"Loading page"}):i!==null?w.jsx("div",{className:"wiki-article",children:w.jsx(aQ,{content:i})}):w.jsx(Tp,{compact:!0,title:"Page unavailable",description:"The page metadata loaded, but the content could not be shown yet. Try reloading the page.",actions:w.jsx("button",{type:"button",className:"btn",onClick:A,children:"Retry"})})})]}):w.jsx(Tp,{title:Q===0?"Start the wiki":"Pick a page",description:Q===0?"Create the first page and the wiki will organize itself into folders from its path.":"Choose a page from the sidebar, or create a new one if the answer does not exist yet.",actions:w.jsx("button",{type:"button",className:"btn primary",onClick:()=>S("/wiki/edit?new=1"),children:"New page"})})})]})]})}function Gb(){return Gb=Object.assign?Object.assign.bind():function(t){for(var e=1;e<arguments.length;e++){var n=arguments[e];for(var r in n)({}).hasOwnProperty.call(n,r)&&(t[r]=n[r])}return t},Gb.apply(null,arguments)}function qie(t,e){if(t==null)return{};var n={};for(var r in t)if({}.hasOwnProperty.call(t,r)){if(e.indexOf(r)!==-1)continue;n[r]=t[r]}return n}let qb=[],OQ=[];(()=>{let t="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,3b,f,,w,1j,,,,4,8,4,,3,7,a,2,t,,1m,,,,2,4,8,,9,,a,2,q,,2,2,1l,,4,2,4,2,2,3,3,,u,2,3,,b,2,1l,,4,5,,2,4,,k,2,m,6,,,1m,,,2,,4,8,,7,3,a,2,u,,1n,,,,c,,9,,14,,3,,1l,3,5,3,,4,7,2,b,2,t,,1m,,2,,2,,3,,5,2,7,2,b,2,s,2,1l,2,,,2,4,8,,9,,a,2,t,,20,,4,,2,3,,,8,,29,,2,7,c,8,2q,,2,9,b,6,22,2,r,,,,,,1j,e,,5,,2,5,b,,10,9,,2u,4,,6,,2,2,2,p,2,4,3,g,4,d,,2,2,6,,f,,jj,3,qa,3,t,3,t,2,u,2,1s,2,,7,8,,2,b,9,,19,3,3b,2,y,,3a,3,4,2,9,,6,3,63,2,2,,1m,,,7,,,,,2,8,6,a,2,,1c,h,1r,4,1c,7,,,5,,14,9,c,2,w,4,2,2,,3,1k,,,2,3,,,3,1m,8,2,2,48,3,,d,,7,4,,6,,3,2,5i,1m,,5,ek,,5f,x,2da,3,3x,,2o,w,fe,6,2x,2,n9w,4,,a,w,2,28,2,7k,,3,,4,,p,2,5,,47,2,q,i,d,,12,8,p,b,1a,3,1c,,2,4,2,2,13,,1v,6,2,2,2,2,c,,8,,1b,,1f,,,3,2,2,5,2,,,16,2,8,,6m,,2,,4,,fn4,,kh,g,g,g,a6,2,gt,,6a,,45,5,1ae,3,,2,5,4,14,3,4,,4l,2,fx,4,ar,2,49,b,4w,,1i,f,1k,3,1d,4,2,2,1x,3,10,5,,8,1q,,c,2,1g,9,a,4,2,,2n,3,2,,,2,6,,4g,,3,8,l,2,1l,2,,,,,m,,e,7,3,5,5f,8,2,3,,,n,,29,,2,6,,,2,,,2,,2,6j,,2,4,6,2,,2,r,2,2d,8,2,,,2,2y,,,,2,6,,,2t,3,2,4,,5,77,9,,2,6t,,a,2,,,4,,40,4,2,2,4,,w,a,14,6,2,4,8,,9,6,2,3,1a,d,,2,ba,7,,6,,,2a,m,2,7,,2,,2,3e,6,3,,,2,,7,,,20,2,3,,,,9n,2,f0b,5,1n,7,t4,,1r,4,29,,f5k,2,43q,,,3,4,5,8,8,2,7,u,4,44,3,1iz,1j,4,1e,8,,e,,m,5,,f,11s,7,,h,2,7,,2,,5,79,7,c5,4,15s,7,31,7,240,5,gx7k,2o,3k,6o".split(",").map(e=>e?parseInt(e,36):1);for(let e=0,n=0;e<t.length;e++)(e%2?OQ:qb).push(n=n+t[e])})();function Kie(t){if(t<768)return!1;for(let e=0,n=qb.length;;){let r=e+n>>1;if(t<qb[r])n=r;else if(t>=OQ[r])e=r+1;else return!0;if(e==n)return!1}}function JE(t){return t>=127462&&t<=127487}const e_=8205;function Jie(t,e,n=!0,r=!0){return(n?yQ:ese)(t,e,r)}function yQ(t,e,n){if(e==t.length)return e;e&&bQ(t.charCodeAt(e))&&wQ(t.charCodeAt(e-1))&&e--;let r=xO(t,e);for(e+=t_(r);e<t.length;){let i=xO(t,e);if(r==e_||i==e_||n&&Kie(i))e+=t_(i),r=i;else if(JE(i)){let s=0,o=e-2;for(;o>=0&&JE(xO(t,o));)s++,o-=2;if(s%2==0)break;e+=2}else break}return e}function ese(t,e,n){for(;e>0;){let r=yQ(t,e-2,n);if(r<e)return r;e--}return 0}function xO(t,e){let n=t.charCodeAt(e);if(!wQ(n)||e+1==t.length)return n;let r=t.charCodeAt(e+1);return bQ(r)?(n-55296<<10)+(r-56320)+65536:n}function bQ(t){return t>=56320&&t<57344}function wQ(t){return t>=55296&&t<56320}function t_(t){return t<65536?1:2}class Ae{lineAt(e){if(e<0||e>this.length)throw new 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 new RangeError(`Invalid line number ${e} in ${this.lines}-line document`);return this.lineInner(e,!0,1,0)}replace(e,n,r){[e,n]=kl(this,e,n);let i=[];return this.decompose(0,e,i,2),r.length&&r.decompose(0,r.length,i,3),this.decompose(n,this.length,i,1),oi.from(i,this.length-(n-e)+r.length)}append(e){return this.replace(this.length,this.length,e)}slice(e,n=this.length){[e,n]=kl(this,e,n);let r=[];return this.decompose(e,n,r,0),oi.from(r,n-e)}eq(e){if(e==this)return!0;if(e.length!=this.length||e.lines!=this.lines)return!1;let n=this.scanIdentical(e,1),r=this.length-this.scanIdentical(e,-1),i=new tu(this),s=new tu(e);for(let o=n,a=n;;){if(i.next(o),s.next(o),o=0,i.lineBreak!=s.lineBreak||i.done!=s.done||i.value!=s.value)return!1;if(a+=i.value.length,i.done||a>=r)return!0}}iter(e=1){return new tu(this,e)}iterRange(e,n=this.length){return new SQ(this,e,n)}iterLines(e,n){let r;if(e==null)r=this.iter();else{n==null&&(n=this.lines+1);let i=this.line(e).from;r=this.iterRange(i,Math.max(i,n==this.lines+1?this.length:n<=1?0:this.line(n-1).to))}return new kQ(r)}toString(){return this.sliceString(0)}toJSON(){let e=[];return this.flatten(e),e}constructor(){}static of(e){if(e.length==0)throw new RangeError("A document must have at least one line");return e.length==1&&!e[0]?Ae.empty:e.length<=32?new yt(e):oi.from(yt.split(e,[]))}}class yt extends Ae{constructor(e,n=tse(e)){super(),this.text=e,this.length=n}get lines(){return this.text.length}get children(){return null}lineInner(e,n,r,i){for(let s=0;;s++){let o=this.text[s],a=i+o.length;if((n?r:a)>=e)return new nse(i,a,r,o);i=a+1,r++}}decompose(e,n,r,i){let s=e<=0&&n>=this.length?this:new yt(n_(this.text,e,n),Math.min(n,this.length)-Math.max(0,e));if(i&1){let o=r.pop(),a=gf(s.text,o.text.slice(),0,s.length);if(a.length<=32)r.push(new yt(a,o.length+s.length));else{let l=a.length>>1;r.push(new yt(a.slice(0,l)),new yt(a.slice(l)))}}else r.push(s)}replace(e,n,r){if(!(r instanceof yt))return super.replace(e,n,r);[e,n]=kl(this,e,n);let i=gf(this.text,gf(r.text,n_(this.text,0,e)),n),s=this.length+r.length-(n-e);return i.length<=32?new yt(i,s):oi.from(yt.split(i,[]),s)}sliceString(e,n=this.length,r=`
|
|
180
180
|
`){[e,n]=kl(this,e,n);let i="";for(let s=0,o=0;s<=n&&o<this.text.length;o++){let a=this.text[o],l=s+a.length;s>e&&o&&(i+=r),e<l&&n>s&&(i+=a.slice(Math.max(0,e-s),n-s)),s=l+1}return i}flatten(e){for(let n of this.text)e.push(n)}scanIdentical(){return 0}static split(e,n){let r=[],i=-1;for(let s of e)r.push(s),i+=s.length+1,r.length==32&&(n.push(new yt(r,i)),r=[],i=-1);return i>-1&&n.push(new yt(r,i)),n}}class oi extends Ae{constructor(e,n){super(),this.children=e,this.length=n,this.lines=0;for(let r of e)this.lines+=r.lines}lineInner(e,n,r,i){for(let s=0;;s++){let o=this.children[s],a=i+o.length,l=r+o.lines-1;if((n?l:a)>=e)return o.lineInner(e,n,r,i);i=a+1,r=l+1}}decompose(e,n,r,i){for(let s=0,o=0;o<=n&&s<this.children.length;s++){let a=this.children[s],l=o+a.length;if(e<=l&&n>=o){let c=i&((o<=e?1:0)|(l>=n?2:0));o>=e&&l<=n&&!c?r.push(a):a.decompose(e-o,n-o,r,c)}o=l+1}}replace(e,n,r){if([e,n]=kl(this,e,n),r.lines<this.lines)for(let i=0,s=0;i<this.children.length;i++){let o=this.children[i],a=s+o.length;if(e>=s&&n<=a){let l=o.replace(e-s,n-s,r),c=this.lines-o.lines+l.lines;if(l.lines<c>>4&&l.lines>c>>6){let u=this.children.slice();return u[i]=l,new oi(u,this.length-(n-e)+r.length)}return super.replace(s,a,l)}s=a+1}return super.replace(e,n,r)}sliceString(e,n=this.length,r=`
|
|
181
181
|
`){[e,n]=kl(this,e,n);let i="";for(let s=0,o=0;s<this.children.length&&o<=n;s++){let a=this.children[s],l=o+a.length;o>e&&s&&(i+=r),e<l&&n>o&&(i+=a.sliceString(e-o,n-o,r)),o=l+1}return i}flatten(e){for(let n of this.children)n.flatten(e)}scanIdentical(e,n){if(!(e instanceof oi))return 0;let r=0,[i,s,o,a]=n>0?[0,0,this.children.length,e.children.length]:[this.children.length-1,e.children.length-1,-1,-1];for(;;i+=n,s+=n){if(i==o||s==a)return r;let l=this.children[i],c=e.children[s];if(l!=c)return r+l.scanIdentical(c,n);r+=l.length+1}}static from(e,n=e.reduce((r,i)=>r+i.length+1,-1)){let r=0;for(let f of e)r+=f.lines;if(r<32){let f=[];for(let p of e)p.flatten(f);return new yt(f,n)}let i=Math.max(32,r>>5),s=i<<1,o=i>>1,a=[],l=0,c=-1,u=[];function h(f){let p;if(f.lines>s&&f instanceof oi)for(let g of f.children)h(g);else f.lines>o&&(l>o||!l)?(d(),a.push(f)):f instanceof yt&&l&&(p=u[u.length-1])instanceof yt&&f.lines+p.lines<=32?(l+=f.lines,c+=f.length+1,u[u.length-1]=new yt(p.text.concat(f.text),p.length+1+f.length)):(l+f.lines>i&&d(),l+=f.lines,c+=f.length+1,u.push(f))}function d(){l!=0&&(a.push(u.length==1?u[0]:oi.from(u,c)),c=-1,l=u.length=0)}for(let f of e)h(f);return d(),a.length==1?a[0]:new oi(a,n)}}Ae.empty=new yt([""],0);function tse(t){let e=-1;for(let n of t)e+=n.length+1;return e}function gf(t,e,n=0,r=1e9){for(let i=0,s=0,o=!0;s<t.length&&i<=r;s++){let a=t[s],l=i+a.length;l>=n&&(l>r&&(a=a.slice(0,r-i)),i<n&&(a=a.slice(n-i)),o?(e[e.length-1]+=a,o=!1):e.push(a)),i=l+1}return e}function n_(t,e,n){return gf(t,[""],e,n)}class tu{constructor(e,n=1){this.dir=n,this.done=!1,this.lineBreak=!1,this.value="",this.nodes=[e],this.offsets=[n>0?1:(e instanceof yt?e.text.length:e.children.length)<<1]}nextInner(e,n){for(this.done=this.lineBreak=!1;;){let r=this.nodes.length-1,i=this.nodes[r],s=this.offsets[r],o=s>>1,a=i instanceof yt?i.text.length:i.children.length;if(o==(n>0?a:0)){if(r==0)return this.done=!0,this.value="",this;n>0&&this.offsets[r-1]++,this.nodes.pop(),this.offsets.pop()}else if((s&1)==(n>0?0:1)){if(this.offsets[r]+=n,e==0)return this.lineBreak=!0,this.value=`
|
|
182
182
|
`,this;e--}else if(i instanceof yt){let l=i.text[o+(n<0?-1:0)];if(this.offsets[r]+=n,l.length>Math.max(0,e))return this.value=e==0?l:n>0?l.slice(e):l.slice(0,l.length-e),this;e-=l.length}else{let l=i.children[o+(n<0?-1:0)];e>l.length?(e-=l.length,this.offsets[r]+=n):(n<0&&this.offsets[r]--,this.nodes.push(l),this.offsets.push(n>0?1:(l instanceof yt?l.text.length:l.children.length)<<1))}}}next(e=0){return e<0&&(this.nextInner(-e,-this.dir),e=this.value.length),this.nextInner(e,this.dir)}}class SQ{constructor(e,n,r){this.value="",this.done=!1,this.cursor=new tu(e,n>r?-1:1),this.pos=n>r?e.length:0,this.from=Math.min(n,r),this.to=Math.max(n,r)}nextInner(e,n){if(n<0?this.pos<=this.from:this.pos>=this.to)return this.value="",this.done=!0,this;e+=Math.max(0,n<0?this.pos-this.to:this.from-this.pos);let r=n<0?this.pos-this.from:this.to-this.pos;e>r&&(e=r),r-=e;let{value:i}=this.cursor.next(e);return this.pos+=(i.length+e)*n,this.value=i.length<=r?i:n<0?i.slice(i.length-r):i.slice(0,r),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!=""}}class kQ{constructor(e){this.inner=e,this.afterBreak=!0,this.value="",this.done=!1}next(e=0){let{done:n,lineBreak:r,value:i}=this.inner.next(e);return n&&this.afterBreak?(this.value="",this.afterBreak=!1):n?(this.done=!0,this.value=""):r?this.afterBreak?this.value="":(this.afterBreak=!0,this.next()):(this.value=i,this.afterBreak=!1),this}get lineBreak(){return!1}}typeof Symbol<"u"&&(Ae.prototype[Symbol.iterator]=function(){return this.iter()},tu.prototype[Symbol.iterator]=SQ.prototype[Symbol.iterator]=kQ.prototype[Symbol.iterator]=function(){return this});let nse=class{constructor(e,n,r,i){this.from=e,this.to=n,this.number=r,this.text=i}get length(){return this.to-this.from}};function kl(t,e,n){return e=Math.max(0,Math.min(t.length,e)),[e,Math.max(e,Math.min(t.length,n))]}function Mt(t,e,n=!0,r=!0){return Jie(t,e,n,r)}function rse(t){return t>=56320&&t<57344}function ise(t){return t>=55296&&t<56320}function Cn(t,e){let n=t.charCodeAt(e);if(!ise(n)||e+1==t.length)return n;let r=t.charCodeAt(e+1);return rse(r)?(n-55296<<10)+(r-56320)+65536:n}function Lv(t){return t<=65535?String.fromCharCode(t):(t-=65536,String.fromCharCode((t>>10)+55296,(t&1023)+56320))}function ai(t){return t<65536?1:2}const Kb=/\r\n?|\n/;var Zt=function(t){return t[t.Simple=0]="Simple",t[t.TrackDel=1]="TrackDel",t[t.TrackBefore=2]="TrackBefore",t[t.TrackAfter=3]="TrackAfter",t}(Zt||(Zt={}));class Oi{constructor(e){this.sections=e}get length(){let e=0;for(let n=0;n<this.sections.length;n+=2)e+=this.sections[n];return e}get newLength(){let e=0;for(let n=0;n<this.sections.length;n+=2){let r=this.sections[n+1];e+=r<0?this.sections[n]:r}return e}get empty(){return this.sections.length==0||this.sections.length==2&&this.sections[1]<0}iterGaps(e){for(let n=0,r=0,i=0;n<this.sections.length;){let s=this.sections[n++],o=this.sections[n++];o<0?(e(r,i,s),i+=s):i+=o,r+=s}}iterChangedRanges(e,n=!1){Jb(this,e,n)}get invertedDesc(){let e=[];for(let n=0;n<this.sections.length;){let r=this.sections[n++],i=this.sections[n++];i<0?e.push(r,i):e.push(i,r)}return new Oi(e)}composeDesc(e){return this.empty?e:e.empty?this:vQ(this,e)}mapDesc(e,n=!1){return e.empty?this:ew(this,e,n)}mapPos(e,n=-1,r=Zt.Simple){let i=0,s=0;for(let o=0;o<this.sections.length;){let a=this.sections[o++],l=this.sections[o++],c=i+a;if(l<0){if(c>e)return s+(e-i);s+=a}else{if(r!=Zt.Simple&&c>=e&&(r==Zt.TrackDel&&i<e&&c>e||r==Zt.TrackBefore&&i<e||r==Zt.TrackAfter&&c>e))return null;if(c>e||c==e&&n<0&&!a)return e==i||n<0?s:s+l;s+=l}i=c}if(e>i)throw new RangeError(`Position ${e} is out of range for changeset of length ${i}`);return s}touchesRange(e,n=e){for(let r=0,i=0;r<this.sections.length&&i<=n;){let s=this.sections[r++],o=this.sections[r++],a=i+s;if(o>=0&&i<=n&&a>=e)return i<e&&a>n?"cover":!0;i=a}return!1}toString(){let e="";for(let n=0;n<this.sections.length;){let r=this.sections[n++],i=this.sections[n++];e+=(e?" ":"")+r+(i>=0?":"+i:"")}return e}toJSON(){return this.sections}static fromJSON(e){if(!Array.isArray(e)||e.length%2||e.some(n=>typeof n!="number"))throw new RangeError("Invalid JSON representation of ChangeDesc");return new Oi(e)}static create(e){return new Oi(e)}}class At extends Oi{constructor(e,n){super(e),this.inserted=n}apply(e){if(this.length!=e.length)throw new RangeError("Applying change set to a document with the wrong length");return Jb(this,(n,r,i,s,o)=>e=e.replace(i,i+(r-n),o),!1),e}mapDesc(e,n=!1){return ew(this,e,n,!0)}invert(e){let n=this.sections.slice(),r=[];for(let i=0,s=0;i<n.length;i+=2){let o=n[i],a=n[i+1];if(a>=0){n[i]=a,n[i+1]=o;let l=i>>1;for(;r.length<l;)r.push(Ae.empty);r.push(o?e.slice(s,s+o):Ae.empty)}s+=o}return new At(n,r)}compose(e){return this.empty?e:e.empty?this:vQ(this,e,!0)}map(e,n=!1){return e.empty?this:ew(this,e,n,!0)}iterChanges(e,n=!1){Jb(this,e,n)}get desc(){return Oi.create(this.sections)}filter(e){let n=[],r=[],i=[],s=new Fu(this);e:for(let o=0,a=0;;){let l=o==e.length?1e9:e[o++];for(;a<l||a==l&&s.len==0;){if(s.done)break e;let u=Math.min(s.len,l-a);qt(i,u,-1);let h=s.ins==-1?-1:s.off==0?s.ins:0;qt(n,u,h),h>0&&_s(r,n,s.text),s.forward(u),a+=u}let c=e[o++];for(;a<c;){if(s.done)break e;let u=Math.min(s.len,c-a);qt(n,u,-1),qt(i,u,s.ins==-1?-1:s.off==0?s.ins:0),s.forward(u),a+=u}}return{changes:new At(n,r),filtered:Oi.create(i)}}toJSON(){let e=[];for(let n=0;n<this.sections.length;n+=2){let r=this.sections[n],i=this.sections[n+1];i<0?e.push(r):i==0?e.push([r]):e.push([r].concat(this.inserted[n>>1].toJSON()))}return e}static of(e,n,r){let i=[],s=[],o=0,a=null;function l(u=!1){if(!u&&!i.length)return;o<n&&qt(i,n-o,-1);let h=new At(i,s);a=a?a.compose(h.map(a)):h,i=[],s=[],o=0}function c(u){if(Array.isArray(u))for(let h of u)c(h);else if(u instanceof At){if(u.length!=n)throw new RangeError(`Mismatched change set length (got ${u.length}, expected ${n})`);l(),a=a?a.compose(u.map(a)):u}else{let{from:h,to:d=h,insert:f}=u;if(h>d||h<0||d>n)throw new RangeError(`Invalid change range ${h} to ${d} (in doc of length ${n})`);let p=f?typeof f=="string"?Ae.of(f.split(r||Kb)):f:Ae.empty,g=p.length;if(h==d&&g==0)return;h<o&&l(),h>o&&qt(i,h-o,-1),qt(i,d-h,g),_s(s,i,p),o=d}}return c(e),l(!a),a}static empty(e){return new At(e?[e,-1]:[],[])}static fromJSON(e){if(!Array.isArray(e))throw new RangeError("Invalid JSON representation of ChangeSet");let n=[],r=[];for(let i=0;i<e.length;i++){let s=e[i];if(typeof s=="number")n.push(s,-1);else{if(!Array.isArray(s)||typeof s[0]!="number"||s.some((o,a)=>a&&typeof o!="string"))throw new RangeError("Invalid JSON representation of ChangeSet");if(s.length==1)n.push(s[0],0);else{for(;r.length<i;)r.push(Ae.empty);r[i]=Ae.of(s.slice(1)),n.push(s[0],r[i].length)}}}return new At(n,r)}static createSet(e,n){return new At(e,n)}}function qt(t,e,n,r=!1){if(e==0&&n<=0)return;let i=t.length-2;i>=0&&n<=0&&n==t[i+1]?t[i]+=e:i>=0&&e==0&&t[i]==0?t[i+1]+=n:r?(t[i]+=e,t[i+1]+=n):t.push(e,n)}function _s(t,e,n){if(n.length==0)return;let r=e.length-2>>1;if(r<t.length)t[t.length-1]=t[t.length-1].append(n);else{for(;t.length<r;)t.push(Ae.empty);t.push(n)}}function Jb(t,e,n){let r=t.inserted;for(let i=0,s=0,o=0;o<t.sections.length;){let a=t.sections[o++],l=t.sections[o++];if(l<0)i+=a,s+=a;else{let c=i,u=s,h=Ae.empty;for(;c+=a,u+=l,l&&r&&(h=h.append(r[o-2>>1])),!(n||o==t.sections.length||t.sections[o+1]<0);)a=t.sections[o++],l=t.sections[o++];e(i,c,s,u,h),i=c,s=u}}}function ew(t,e,n,r=!1){let i=[],s=r?[]:null,o=new Fu(t),a=new Fu(e);for(let l=-1;;){if(o.done&&a.len||a.done&&o.len)throw new Error("Mismatched change set lengths");if(o.ins==-1&&a.ins==-1){let c=Math.min(o.len,a.len);qt(i,c,-1),o.forward(c),a.forward(c)}else if(a.ins>=0&&(o.ins<0||l==o.i||o.off==0&&(a.len<o.len||a.len==o.len&&!n))){let c=a.len;for(qt(i,a.ins,-1);c;){let u=Math.min(o.len,c);o.ins>=0&&l<o.i&&o.len<=u&&(qt(i,0,o.ins),s&&_s(s,i,o.text),l=o.i),o.forward(u),c-=u}a.next()}else if(o.ins>=0){let c=0,u=o.len;for(;u;)if(a.ins==-1){let h=Math.min(u,a.len);c+=h,u-=h,a.forward(h)}else if(a.ins==0&&a.len<u)u-=a.len,a.next();else break;qt(i,c,l<o.i?o.ins:0),s&&l<o.i&&_s(s,i,o.text),l=o.i,o.forward(o.len-u)}else{if(o.done&&a.done)return s?At.createSet(i,s):Oi.create(i);throw new Error("Mismatched change set lengths")}}}function vQ(t,e,n=!1){let r=[],i=n?[]:null,s=new Fu(t),o=new Fu(e);for(let a=!1;;){if(s.done&&o.done)return i?At.createSet(r,i):Oi.create(r);if(s.ins==0)qt(r,s.len,0,a),s.next();else if(o.len==0&&!o.done)qt(r,0,o.ins,a),i&&_s(i,r,o.text),o.next();else{if(s.done||o.done)throw new Error("Mismatched change set lengths");{let l=Math.min(s.len2,o.len),c=r.length;if(s.ins==-1){let u=o.ins==-1?-1:o.off?0:o.ins;qt(r,l,u,a),i&&u&&_s(i,r,o.text)}else o.ins==-1?(qt(r,s.off?0:s.len,l,a),i&&_s(i,r,s.textBit(l))):(qt(r,s.off?0:s.len,o.off?0:o.ins,a),i&&!o.off&&_s(i,r,o.text));a=(s.ins>l||o.ins>=0&&o.len>l)&&(a||r.length>c),s.forward2(l),o.forward(l)}}}}class Fu{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,n=this.i-2>>1;return n>=e.length?Ae.empty:e[n]}textBit(e){let{inserted:n}=this.set,r=this.i-2>>1;return r>=n.length&&!e?Ae.empty:n[r].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)}}class So{constructor(e,n,r){this.from=e,this.to=n,this.flags=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 bidiLevel(){let e=this.flags&7;return e==7?null:e}get goalColumn(){let e=this.flags>>6;return e==16777215?void 0:e}map(e,n=-1){let r,i;return this.empty?r=i=e.mapPos(this.from,n):(r=e.mapPos(this.from,1),i=e.mapPos(this.to,-1)),r==this.from&&i==this.to?this:new So(r,i,this.flags)}extend(e,n=e,r=0){if(e<=this.anchor&&n>=this.anchor)return B.range(e,n,void 0,void 0,r);let i=Math.abs(e-this.anchor)>Math.abs(n-this.anchor)?e:n;return B.range(this.anchor,i,void 0,void 0,r)}eq(e,n=!1){return this.anchor==e.anchor&&this.head==e.head&&this.goalColumn==e.goalColumn&&(!n||!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 new RangeError("Invalid JSON representation for SelectionRange");return B.range(e.anchor,e.head)}static create(e,n,r){return new So(e,n,r)}}class B{constructor(e,n){this.ranges=e,this.mainIndex=n}map(e,n=-1){return e.empty?this:B.create(this.ranges.map(r=>r.map(e,n)),this.mainIndex)}eq(e,n=!1){if(this.ranges.length!=e.ranges.length||this.mainIndex!=e.mainIndex)return!1;for(let r=0;r<this.ranges.length;r++)if(!this.ranges[r].eq(e.ranges[r],n))return!1;return!0}get main(){return this.ranges[this.mainIndex]}asSingle(){return this.ranges.length==1?this:new B([this.main],0)}addRange(e,n=!0){return B.create([e].concat(this.ranges),n?0:this.mainIndex+1)}replaceRange(e,n=this.mainIndex){let r=this.ranges.slice();return r[n]=e,B.create(r,this.mainIndex)}toJSON(){return{ranges:this.ranges.map(e=>e.toJSON()),main:this.mainIndex}}static fromJSON(e){if(!e||!Array.isArray(e.ranges)||typeof e.main!="number"||e.main>=e.ranges.length)throw new RangeError("Invalid JSON representation for EditorSelection");return new B(e.ranges.map(n=>So.fromJSON(n)),e.main)}static single(e,n=e){return new B([B.range(e,n)],0)}static create(e,n=0){if(e.length==0)throw new RangeError("A selection needs at least one range");for(let r=0,i=0;i<e.length;i++){let s=e[i];if(s.empty?s.from<=r:s.from<r)return B.normalized(e.slice(),n);r=s.to}return new B(e,n)}static cursor(e,n=0,r,i){return So.create(e,e,(n==0?0:n<0?8:16)|(r==null?7:Math.min(6,r))|(i??16777215)<<6)}static range(e,n,r,i,s){let o=(r??16777215)<<6|(i==null?7:Math.min(6,i));return!s&&e!=n&&(s=n<e?1:-1),n<e?So.create(n,e,48|o):So.create(e,n,(s?s<0?8:16:0)|o)}static normalized(e,n=0){let r=e[n];e.sort((i,s)=>i.from-s.from),n=e.indexOf(r);for(let i=1;i<e.length;i++){let s=e[i],o=e[i-1];if(s.empty?s.from<=o.to:s.from<o.to){let a=o.from,l=Math.max(s.to,o.to);i<=n&&n--,e.splice(--i,2,s.anchor>s.head?B.range(l,a):B.range(a,l))}}return new B(e,n)}}function xQ(t,e){for(let n of t.ranges)if(n.to>e)throw new RangeError("Selection points outside of document")}let Dv=0;class ie{constructor(e,n,r,i,s){this.combine=e,this.compareInput=n,this.compare=r,this.isStatic=i,this.id=Dv++,this.default=e([]),this.extensions=typeof s=="function"?s(this):s}get reader(){return this}static define(e={}){return new ie(e.combine||(n=>n),e.compareInput||((n,r)=>n===r),e.compare||(e.combine?(n,r)=>n===r:zv),!!e.static,e.enables)}of(e){return new mf([],this,0,e)}compute(e,n){if(this.isStatic)throw new Error("Can't compute a static facet");return new mf(e,this,1,n)}computeN(e,n){if(this.isStatic)throw new Error("Can't compute a static facet");return new mf(e,this,2,n)}from(e,n){return n||(n=r=>r),this.compute([e],r=>n(r.field(e)))}}function zv(t,e){return t==e||t.length==e.length&&t.every((n,r)=>n===e[r])}class mf{constructor(e,n,r,i){this.dependencies=e,this.facet=n,this.type=r,this.value=i,this.id=Dv++}dynamicSlot(e){var n;let r=this.value,i=this.facet.compareInput,s=this.id,o=e[s]>>1,a=this.type==2,l=!1,c=!1,u=[];for(let h of this.dependencies)h=="doc"?l=!0:h=="selection"?c=!0:((n=e[h.id])!==null&&n!==void 0?n:1)&1||u.push(e[h.id]);return{create(h){return h.values[o]=r(h),1},update(h,d){if(l&&d.docChanged||c&&(d.docChanged||d.selection)||tw(h,u)){let f=r(h);if(a?!r_(f,h.values[o],i):!i(f,h.values[o]))return h.values[o]=f,1}return 0},reconfigure:(h,d)=>{let f,p=d.config.address[s];if(p!=null){let g=Pp(d,p);if(this.dependencies.every(O=>O instanceof ie?d.facet(O)===h.facet(O):O instanceof Vt?d.field(O,!1)==h.field(O,!1):!0)||(a?r_(f=r(h),g,i):i(f=r(h),g)))return h.values[o]=g,0}else f=r(h);return h.values[o]=f,1}}}}function r_(t,e,n){if(t.length!=e.length)return!1;for(let r=0;r<t.length;r++)if(!n(t[r],e[r]))return!1;return!0}function tw(t,e){let n=!1;for(let r of e)nu(t,r)&1&&(n=!0);return n}function sse(t,e,n){let r=n.map(l=>t[l.id]),i=n.map(l=>l.type),s=r.filter(l=>!(l&1)),o=t[e.id]>>1;function a(l){let c=[];for(let u=0;u<r.length;u++){let h=Pp(l,r[u]);if(i[u]==2)for(let d of h)c.push(d);else c.push(h)}return e.combine(c)}return{create(l){for(let c of r)nu(l,c);return l.values[o]=a(l),1},update(l,c){if(!tw(l,s))return 0;let u=a(l);return e.compare(u,l.values[o])?0:(l.values[o]=u,1)},reconfigure(l,c){let u=tw(l,r),h=c.config.facets[e.id],d=c.facet(e);if(h&&!u&&zv(n,h))return l.values[o]=d,0;let f=a(l);return e.compare(f,d)?(l.values[o]=d,0):(l.values[o]=f,1)}}}const vd=ie.define({static:!0});class Vt{constructor(e,n,r,i,s){this.id=e,this.createF=n,this.updateF=r,this.compareF=i,this.spec=s,this.provides=void 0}static define(e){let n=new Vt(Dv++,e.create,e.update,e.compare||((r,i)=>r===i),e);return e.provide&&(n.provides=e.provide(n)),n}create(e){let n=e.facet(vd).find(r=>r.field==this);return((n==null?void 0:n.create)||this.createF)(e)}slot(e){let n=e[this.id]>>1;return{create:r=>(r.values[n]=this.create(r),1),update:(r,i)=>{let s=r.values[n],o=this.updateF(s,i);return this.compareF(s,o)?0:(r.values[n]=o,1)},reconfigure:(r,i)=>{let s=r.facet(vd),o=i.facet(vd),a;return(a=s.find(l=>l.field==this))&&a!=o.find(l=>l.field==this)?(r.values[n]=a.create(r),1):i.config.address[this.id]!=null?(r.values[n]=i.field(this),0):(r.values[n]=this.create(r),1)}}}init(e){return[this,vd.of({field:this,create:e})]}get extension(){return this}}const go={lowest:4,low:3,default:2,high:1,highest:0};function kc(t){return e=>new CQ(e,t)}const ns={highest:kc(go.highest),high:kc(go.high),default:kc(go.default),low:kc(go.low),lowest:kc(go.lowest)};class CQ{constructor(e,n){this.inner=e,this.prec=n}}class rm{of(e){return new nw(this,e)}reconfigure(e){return rm.reconfigure.of({compartment:this,extension:e})}get(e){return e.config.compartments.get(this)}}class nw{constructor(e,n){this.compartment=e,this.inner=n}}class Ap{constructor(e,n,r,i,s,o){for(this.base=e,this.compartments=n,this.dynamicSlots=r,this.address=i,this.staticValues=s,this.facets=o,this.statusTemplate=[];this.statusTemplate.length<r.length;)this.statusTemplate.push(0)}staticFacet(e){let n=this.address[e.id];return n==null?e.default:this.staticValues[n>>1]}static resolve(e,n,r){let i=[],s=Object.create(null),o=new Map;for(let d of ose(e,n,o))d instanceof Vt?i.push(d):(s[d.facet.id]||(s[d.facet.id]=[])).push(d);let a=Object.create(null),l=[],c=[];for(let d of i)a[d.id]=c.length<<1,c.push(f=>d.slot(f));let u=r==null?void 0:r.config.facets;for(let d in s){let f=s[d],p=f[0].facet,g=u&&u[d]||[];if(f.every(O=>O.type==0))if(a[p.id]=l.length<<1|1,zv(g,f))l.push(r.facet(p));else{let O=p.combine(f.map(m=>m.value));l.push(r&&p.compare(O,r.facet(p))?r.facet(p):O)}else{for(let O of f)O.type==0?(a[O.id]=l.length<<1|1,l.push(O.value)):(a[O.id]=c.length<<1,c.push(m=>O.dynamicSlot(m)));a[p.id]=c.length<<1,c.push(O=>sse(O,p,f))}}let h=c.map(d=>d(a));return new Ap(e,o,h,a,l,s)}}function ose(t,e,n){let r=[[],[],[],[],[]],i=new Map;function s(o,a){let l=i.get(o);if(l!=null){if(l<=a)return;let c=r[l].indexOf(o);c>-1&&r[l].splice(c,1),o instanceof nw&&n.delete(o.compartment)}if(i.set(o,a),Array.isArray(o))for(let c of o)s(c,a);else if(o instanceof nw){if(n.has(o.compartment))throw new RangeError("Duplicate use of compartment in extensions");let c=e.get(o.compartment)||o.inner;n.set(o.compartment,c),s(c,a)}else if(o instanceof CQ)s(o.inner,o.prec);else if(o instanceof Vt)r[a].push(o),o.provides&&s(o.provides,a);else if(o instanceof mf)r[a].push(o),o.facet.extensions&&s(o.facet.extensions,go.default);else{let c=o.extension;if(!c)throw new Error(`Unrecognized extension value in extension set (${o}). This sometimes happens because multiple instances of @codemirror/state are loaded, breaking instanceof checks.`);s(c,a)}}return s(t,go.default),r.reduce((o,a)=>o.concat(a))}function nu(t,e){if(e&1)return 2;let n=e>>1,r=t.status[n];if(r==4)throw new Error("Cyclic dependency between fields and/or facets");if(r&2)return r;t.status[n]=4;let i=t.computeSlot(t,t.config.dynamicSlots[n]);return t.status[n]=2|i}function Pp(t,e){return e&1?t.config.staticValues[e>>1]:t.values[e>>1]}const EQ=ie.define(),rw=ie.define({combine:t=>t.some(e=>e),static:!0}),_Q=ie.define({combine:t=>t.length?t[0]:void 0,static:!0}),TQ=ie.define(),AQ=ie.define(),PQ=ie.define(),IQ=ie.define({combine:t=>t.length?t[0]:!1});class vi{constructor(e,n){this.type=e,this.value=n}static define(){return new ase}}class ase{of(e){return new vi(this,e)}}class lse{constructor(e){this.map=e}of(e){return new ye(this,e)}}class ye{constructor(e,n){this.type=e,this.value=n}map(e){let n=this.type.map(this.value,e);return n===void 0?void 0:n==this.value?this:new ye(this.type,n)}is(e){return this.type==e}static define(e={}){return new lse(e.map||(n=>n))}static mapEffects(e,n){if(!e.length)return e;let r=[];for(let i of e){let s=i.map(n);s&&r.push(s)}return r}}ye.reconfigure=ye.define();ye.appendConfig=ye.define();class Et{constructor(e,n,r,i,s,o){this.startState=e,this.changes=n,this.selection=r,this.effects=i,this.annotations=s,this.scrollIntoView=o,this._doc=null,this._state=null,r&&xQ(r,n.newLength),s.some(a=>a.type==Et.time)||(this.annotations=s.concat(Et.time.of(Date.now())))}static create(e,n,r,i,s,o){return new Et(e,n,r,i,s,o)}get newDoc(){return this._doc||(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 n of this.annotations)if(n.type==e)return n.value}get docChanged(){return!this.changes.empty}get reconfigured(){return this.startState.config!=this.state.config}isUserEvent(e){let n=this.annotation(Et.userEvent);return!!(n&&(n==e||n.length>e.length&&n.slice(0,e.length)==e&&n[e.length]=="."))}}Et.time=vi.define();Et.userEvent=vi.define();Et.addToHistory=vi.define();Et.remote=vi.define();function cse(t,e){let n=[];for(let r=0,i=0;;){let s,o;if(r<t.length&&(i==e.length||e[i]>=t[r]))s=t[r++],o=t[r++];else if(i<e.length)s=e[i++],o=e[i++];else return n;!n.length||n[n.length-1]<s?n.push(s,o):n[n.length-1]<o&&(n[n.length-1]=o)}}function RQ(t,e,n){var r;let i,s,o;return n?(i=e.changes,s=At.empty(e.changes.length),o=t.changes.compose(e.changes)):(i=e.changes.map(t.changes),s=t.changes.mapDesc(e.changes,!0),o=t.changes.compose(i)),{changes:o,selection:e.selection?e.selection.map(s):(r=t.selection)===null||r===void 0?void 0:r.map(i),effects:ye.mapEffects(t.effects,i).concat(ye.mapEffects(e.effects,s)),annotations:t.annotations.length?t.annotations.concat(e.annotations):e.annotations,scrollIntoView:t.scrollIntoView||e.scrollIntoView}}function iw(t,e,n){let r=e.selection,i=Ka(e.annotations);return e.userEvent&&(i=i.concat(Et.userEvent.of(e.userEvent))),{changes:e.changes instanceof At?e.changes:At.of(e.changes||[],n,t.facet(_Q)),selection:r&&(r instanceof B?r:B.single(r.anchor,r.head)),effects:Ka(e.effects),annotations:i,scrollIntoView:!!e.scrollIntoView}}function NQ(t,e,n){let r=iw(t,e.length?e[0]:{},t.doc.length);e.length&&e[0].filter===!1&&(n=!1);for(let s=1;s<e.length;s++){e[s].filter===!1&&(n=!1);let o=!!e[s].sequential;r=RQ(r,iw(t,e[s],o?r.changes.newLength:t.doc.length),o)}let i=Et.create(t,r.changes,r.selection,r.effects,r.annotations,r.scrollIntoView);return hse(n?use(i):i)}function use(t){let e=t.startState,n=!0;for(let i of e.facet(TQ)){let s=i(t);if(s===!1){n=!1;break}Array.isArray(s)&&(n=n===!0?s:cse(n,s))}if(n!==!0){let i,s;if(n===!1)s=t.changes.invertedDesc,i=At.empty(e.doc.length);else{let o=t.changes.filter(n);i=o.changes,s=o.filtered.mapDesc(o.changes).invertedDesc}t=Et.create(e,i,t.selection&&t.selection.map(s),ye.mapEffects(t.effects,s),t.annotations,t.scrollIntoView)}let r=e.facet(AQ);for(let i=r.length-1;i>=0;i--){let s=r[i](t);s instanceof Et?t=s:Array.isArray(s)&&s.length==1&&s[0]instanceof Et?t=s[0]:t=NQ(e,Ka(s),!1)}return t}function hse(t){let e=t.startState,n=e.facet(PQ),r=t;for(let i=n.length-1;i>=0;i--){let s=n[i](t);s&&Object.keys(s).length&&(r=RQ(r,iw(e,s,t.changes.newLength),!0))}return r==t?t:Et.create(e,t.changes,t.selection,r.effects,r.annotations,r.scrollIntoView)}const dse=[];function Ka(t){return t==null?dse:Array.isArray(t)?t:[t]}var it=function(t){return t[t.Word=0]="Word",t[t.Space=1]="Space",t[t.Other=2]="Other",t}(it||(it={}));const fse=/[\u00df\u0587\u0590-\u05f4\u0600-\u06ff\u3040-\u309f\u30a0-\u30ff\u3400-\u4db5\u4e00-\u9fcc\uac00-\ud7af]/;let sw;try{sw=new RegExp("[\\p{Alphabetic}\\p{Number}_]","u")}catch{}function pse(t){if(sw)return sw.test(t);for(let e=0;e<t.length;e++){let n=t[e];if(/\w/.test(n)||n>""&&(n.toUpperCase()!=n.toLowerCase()||fse.test(n)))return!0}return!1}function gse(t){return e=>{if(!/\S/.test(e))return it.Space;if(pse(e))return it.Word;for(let n=0;n<t.length;n++)if(e.indexOf(t[n])>-1)return it.Word;return it.Other}}class Ee{constructor(e,n,r,i,s,o){this.config=e,this.doc=n,this.selection=r,this.values=i,this.status=e.statusTemplate.slice(),this.computeSlot=s,o&&(o._state=this);for(let a=0;a<this.config.dynamicSlots.length;a++)nu(this,a<<1);this.computeSlot=null}field(e,n=!0){let r=this.config.address[e.id];if(r==null){if(n)throw new RangeError("Field is not present in this state");return}return nu(this,r),Pp(this,r)}update(...e){return NQ(this,e,!0)}applyTransaction(e){let n=this.config,{base:r,compartments:i}=n;for(let a of e.effects)a.is(rm.reconfigure)?(n&&(i=new Map,n.compartments.forEach((l,c)=>i.set(c,l)),n=null),i.set(a.value.compartment,a.value.extension)):a.is(ye.reconfigure)?(n=null,r=a.value):a.is(ye.appendConfig)&&(n=null,r=Ka(r).concat(a.value));let s;n?s=e.startState.values.slice():(n=Ap.resolve(r,i,this),s=new Ee(n,this.doc,this.selection,n.dynamicSlots.map(()=>null),(l,c)=>c.reconfigure(l,this),null).values);let o=e.startState.facet(rw)?e.newSelection:e.newSelection.asSingle();new Ee(n,e.newDoc,o,s,(a,l)=>l.update(a,e),e)}replaceSelection(e){return typeof e=="string"&&(e=this.toText(e)),this.changeByRange(n=>({changes:{from:n.from,to:n.to,insert:e},range:B.cursor(n.from+e.length)}))}changeByRange(e){let n=this.selection,r=e(n.ranges[0]),i=this.changes(r.changes),s=[r.range],o=Ka(r.effects);for(let a=1;a<n.ranges.length;a++){let l=e(n.ranges[a]),c=this.changes(l.changes),u=c.map(i);for(let d=0;d<a;d++)s[d]=s[d].map(u);let h=i.mapDesc(c,!0);s.push(l.range.map(h)),i=i.compose(u),o=ye.mapEffects(o,u).concat(ye.mapEffects(Ka(l.effects),h))}return{changes:i,selection:B.create(s,n.mainIndex),effects:o}}changes(e=[]){return e instanceof At?e:At.of(e,this.doc.length,this.facet(Ee.lineSeparator))}toText(e){return Ae.of(e.split(this.facet(Ee.lineSeparator)||Kb))}sliceDoc(e=0,n=this.doc.length){return this.doc.sliceString(e,n,this.lineBreak)}facet(e){let n=this.config.address[e.id];return n==null?e.default:(nu(this,n),Pp(this,n))}toJSON(e){let n={doc:this.sliceDoc(),selection:this.selection.toJSON()};if(e)for(let r in e){let i=e[r];i instanceof Vt&&this.config.address[i.id]!=null&&(n[r]=i.spec.toJSON(this.field(e[r]),this))}return n}static fromJSON(e,n={},r){if(!e||typeof e.doc!="string")throw new RangeError("Invalid JSON representation for EditorState");let i=[];if(r){for(let s in r)if(Object.prototype.hasOwnProperty.call(e,s)){let o=r[s],a=e[s];i.push(o.init(l=>o.spec.fromJSON(a,l)))}}return Ee.create({doc:e.doc,selection:B.fromJSON(e.selection),extensions:n.extensions?i.concat([n.extensions]):i})}static create(e={}){let n=Ap.resolve(e.extensions||[],new Map),r=e.doc instanceof Ae?e.doc:Ae.of((e.doc||"").split(n.staticFacet(Ee.lineSeparator)||Kb)),i=e.selection?e.selection instanceof B?e.selection:B.single(e.selection.anchor,e.selection.head):B.single(0);return xQ(i,r.length),n.staticFacet(rw)||(i=i.asSingle()),new Ee(n,r,i,n.dynamicSlots.map(()=>null),(s,o)=>o.create(s),null)}get tabSize(){return this.facet(Ee.tabSize)}get lineBreak(){return this.facet(Ee.lineSeparator)||`
|
|
@@ -205,4 +205,4 @@ Try sending your message again.`,i)}finally{m(!1)}}function L(k){k.key==="Enter"
|
|
|
205
205
|
\${}
|
|
206
206
|
}
|
|
207
207
|
}`,{label:"class",detail:"definition",type:"keyword"}),kn('import {${names}} from "${module}"\n${}',{label:"import",detail:"named",type:"keyword"}),kn('import ${name} from "${module}"\n${}',{label:"import",detail:"default",type:"keyword"})],dge=iz.concat([kn("interface ${name} {\n ${}\n}",{label:"interface",detail:"definition",type:"keyword"}),kn("type ${name} = ${type}",{label:"type",detail:"definition",type:"keyword"}),kn("enum ${name} {\n ${}\n}",{label:"enum",detail:"definition",type:"keyword"})]),AA=new WL,sz=new Set(["Script","Block","FunctionExpression","FunctionDeclaration","ArrowFunction","MethodDeclaration","ForStatement"]);function Tc(t){return(e,n)=>{let r=e.node.getChild("VariableDefinition");return r&&n(r,t),!0}}const fge=["FunctionDeclaration"],pge={FunctionDeclaration:Tc("function"),ClassDeclaration:Tc("class"),ClassExpression:()=>!0,EnumDeclaration:Tc("constant"),TypeAliasDeclaration:Tc("type"),NamespaceDeclaration:Tc("namespace"),VariableDefinition(t,e){t.matchContext(fge)||e(t,"variable")},TypeDefinition(t,e){e(t,"type")},__proto__:null};function oz(t,e){let n=AA.get(e);if(n)return n;let r=[],i=!0;function s(o,a){let l=t.sliceString(o.from,o.to);r.push({label:l,type:a})}return e.cursor(Qe.IncludeAnonymous).iterate(o=>{if(i)i=!1;else if(o.name){let a=pge[o.name];if(a&&a(o,s)||sz.has(o.name))return!1}else if(o.to-o.from>8192){for(let a of oz(t,o.node))r.push(a);return!1}}),AA.set(e,r),r}const PA=/^[\w$\xa1-\uffff][\w$\d\xa1-\uffff]*$/,az=["TemplateString","String","RegExp","LineComment","BlockComment","VariableDefinition","TypeDefinition","Label","PropertyDefinition","PropertyName","PrivatePropertyDefinition","PrivatePropertyName","JSXText","JSXAttributeValue","JSXOpenTag","JSXCloseTag","JSXSelfClosingTag",".","?."];function gge(t){let e=He(t.state).resolveInner(t.pos,-1);if(az.indexOf(e.name)>-1)return null;let n=e.name=="VariableName"||e.to-e.from<20&&PA.test(t.state.sliceDoc(e.from,e.to));if(!n&&!t.explicit)return null;let r=[];for(let i=e;i;i=i.parent)sz.has(i.name)&&(r=r.concat(oz(t.state.doc,i)));return{options:r,from:n?e.from:t.pos,validFor:PA}}const yi=_l.define({name:"javascript",parser:hge.configure({props:[Rh.add({IfStatement:kf({except:/^\s*({|else\b)/}),TryStatement:kf({except:/^\s*({|catch\b|finally\b)/}),LabeledStatement:Ble,SwitchBody:t=>{let e=t.textAfter,n=/^\s*\}/.test(e),r=/^\s*(case|default)\b/.test(e);return t.baseIndent+(n?0:r?1:2)*t.unit},Block:zle({closing:"}"}),ArrowFunction:t=>t.baseIndent+t.unit,"TemplateString BlockComment":()=>null,"Statement Property":kf({except:/^\s*{/}),JSXElement(t){let e=/^\s*<\//.test(t.textAfter);return t.lineIndent(t.node.from)+(e?0:t.unit)},JSXEscape(t){let e=/\s*\}/.test(t.textAfter);return t.lineIndent(t.node.from)+(e?0:t.unit)},"JSXOpenTag JSXSelfClosingTag"(t){return t.column(t.node.from)+t.unit}}),Kl.add({"Block ClassBody SwitchBody EnumBody ObjectExpression ArrayExpression ObjectType":eD,BlockComment(t){return{from:t.from+2,to:t.to-2}},JSXElement(t){let e=t.firstChild;if(!e||e.name=="JSXSelfClosingTag")return null;let n=t.lastChild;return{from:e.to,to:n.type.isError?t.to:n.from}},"JSXSelfClosingTag JSXOpenTag"(t){var e;let n=(e=t.firstChild)===null||e===void 0?void 0:e.nextSibling,r=t.lastChild;return!n||n.type.isError?null:{from:n.to,to:r.type.isError?t.to:r.from}}})]}),languageData:{closeBrackets:{brackets:["(","[","{","'",'"',"`"]},commentTokens:{line:"//",block:{open:"/*",close:"*/"}},indentOnInput:/^\s*(?:case |default:|\{|\}|<\/)$/,wordChars:"$"}}),lz={test:t=>/^JSX/.test(t.name),facet:o0({commentTokens:{block:{open:"{/*",close:"*/}"}}})},cz=yi.configure({dialect:"ts"},"typescript"),uz=yi.configure({dialect:"jsx",props:[a0.add(t=>t.isTop?[lz]:void 0)]}),hz=yi.configure({dialect:"jsx ts",props:[a0.add(t=>t.isTop?[lz]:void 0)]},"typescript");let dz=t=>({label:t,type:"keyword"});const fz="break case const continue default delete export extends false finally in instanceof let new return static super switch this throw true typeof var yield".split(" ").map(dz),mge=fz.concat(["declare","implements","private","protected","public"].map(dz));function Oge(t={}){let e=t.jsx?t.typescript?hz:uz:t.typescript?cz:yi,n=t.typescript?dge.concat(mge):iz.concat(fz);return new th(e,[yi.data.of({autocomplete:ohe(az,n2(n))}),yi.data.of({autocomplete:gge}),t.jsx?wge:[]])}function yge(t){for(;;){if(t.name=="JSXOpenTag"||t.name=="JSXSelfClosingTag"||t.name=="JSXFragmentTag")return t;if(t.name=="JSXEscape"||!t.parent)return null;t=t.parent}}function IA(t,e,n=t.length){for(let r=e==null?void 0:e.firstChild;r;r=r.nextSibling)if(r.name=="JSXIdentifier"||r.name=="JSXBuiltin"||r.name=="JSXNamespacedName"||r.name=="JSXMemberExpression")return t.sliceString(r.from,Math.min(r.to,n));return""}const bge=typeof navigator=="object"&&/Android\b/.test(navigator.userAgent),wge=te.inputHandler.of((t,e,n,r,i)=>{if((bge?t.composing:t.compositionStarted)||t.state.readOnly||e!=n||r!=">"&&r!="/"||!yi.isActiveAt(t.state,e,-1))return!1;let s=i(),{state:o}=s,a=o.changeByRange(l=>{var c;let{head:u}=l,h=He(o).resolveInner(u-1,-1),d;if(h.name=="JSXStartTag"&&(h=h.parent),!(o.doc.sliceString(u-1,u)!=r||h.name=="JSXAttributeValue"&&h.to>u)){if(r==">"&&h.name=="JSXFragmentTag")return{range:l,changes:{from:u,insert:"</>"}};if(r=="/"&&h.name=="JSXStartCloseTag"){let f=h.parent,p=f.parent;if(p&&f.from==u-2&&((d=IA(o.doc,p.firstChild,u))||((c=p.firstChild)===null||c===void 0?void 0:c.name)=="JSXFragmentTag")){let g=`${d}>`;return{range:B.cursor(u+g.length,-1),changes:{from:u,insert:g}}}}else if(r==">"){let f=yge(h);if(f&&f.name=="JSXOpenTag"&&!/^\/?>|^<\//.test(o.doc.sliceString(u,u+2))&&(d=IA(o.doc,f,u)))return{range:l,changes:{from:u,insert:`</${d}>`}}}}return{range:l}});return a.changes.empty?!1:(t.dispatch([s,o.update(a,{userEvent:"input.complete",scrollIntoView:!0})]),!0)}),Ac=["_blank","_self","_top","_parent"],cy=["ascii","utf-8","utf-16","latin1","latin1"],uy=["get","post","put","delete"],hy=["application/x-www-form-urlencoded","multipart/form-data","text/plain"],jn=["true","false"],le={},Sge={a:{attrs:{href:null,ping:null,type:null,media:null,target:Ac,hreflang:null}},abbr:le,address:le,area:{attrs:{alt:null,coords:null,href:null,target:null,ping:null,media:null,hreflang:null,type:null,shape:["default","rect","circle","poly"]}},article:le,aside:le,audio:{attrs:{src:null,mediagroup:null,crossorigin:["anonymous","use-credentials"],preload:["none","metadata","auto"],autoplay:["autoplay"],loop:["loop"],controls:["controls"]}},b:le,base:{attrs:{href:null,target:Ac}},bdi:le,bdo:le,blockquote:{attrs:{cite:null}},body:le,br:le,button:{attrs:{form:null,formaction:null,name:null,value:null,autofocus:["autofocus"],disabled:["autofocus"],formenctype:hy,formmethod:uy,formnovalidate:["novalidate"],formtarget:Ac,type:["submit","reset","button"]}},canvas:{attrs:{width:null,height:null}},caption:le,center:le,cite:le,code:le,col:{attrs:{span:null}},colgroup:{attrs:{span:null}},command:{attrs:{type:["command","checkbox","radio"],label:null,icon:null,radiogroup:null,command:null,title:null,disabled:["disabled"],checked:["checked"]}},data:{attrs:{value:null}},datagrid:{attrs:{disabled:["disabled"],multiple:["multiple"]}},datalist:{attrs:{data:null}},dd:le,del:{attrs:{cite:null,datetime:null}},details:{attrs:{open:["open"]}},dfn:le,div:le,dl:le,dt:le,em:le,embed:{attrs:{src:null,type:null,width:null,height:null}},eventsource:{attrs:{src:null}},fieldset:{attrs:{disabled:["disabled"],form:null,name:null}},figcaption:le,figure:le,footer:le,form:{attrs:{action:null,name:null,"accept-charset":cy,autocomplete:["on","off"],enctype:hy,method:uy,novalidate:["novalidate"],target:Ac}},h1:le,h2:le,h3:le,h4:le,h5:le,h6:le,head:{children:["title","base","link","style","meta","script","noscript","command"]},header:le,hgroup:le,hr:le,html:{attrs:{manifest:null}},i:le,iframe:{attrs:{src:null,srcdoc:null,name:null,width:null,height:null,sandbox:["allow-top-navigation","allow-same-origin","allow-forms","allow-scripts"],seamless:["seamless"]}},img:{attrs:{alt:null,src:null,ismap:null,usemap:null,width:null,height:null,crossorigin:["anonymous","use-credentials"]}},input:{attrs:{alt:null,dirname:null,form:null,formaction:null,height:null,list:null,max:null,maxlength:null,min:null,name:null,pattern:null,placeholder:null,size:null,src:null,step:null,value:null,width:null,accept:["audio/*","video/*","image/*"],autocomplete:["on","off"],autofocus:["autofocus"],checked:["checked"],disabled:["disabled"],formenctype:hy,formmethod:uy,formnovalidate:["novalidate"],formtarget:Ac,multiple:["multiple"],readonly:["readonly"],required:["required"],type:["hidden","text","search","tel","url","email","password","datetime","date","month","week","time","datetime-local","number","range","color","checkbox","radio","file","submit","image","reset","button"]}},ins:{attrs:{cite:null,datetime:null}},kbd:le,keygen:{attrs:{challenge:null,form:null,name:null,autofocus:["autofocus"],disabled:["disabled"],keytype:["RSA"]}},label:{attrs:{for:null,form:null}},legend:le,li:{attrs:{value:null}},link:{attrs:{href:null,type:null,hreflang:null,media:null,sizes:["all","16x16","16x16 32x32","16x16 32x32 64x64"]}},map:{attrs:{name:null}},mark:le,menu:{attrs:{label:null,type:["list","context","toolbar"]}},meta:{attrs:{content:null,charset:cy,name:["viewport","application-name","author","description","generator","keywords"],"http-equiv":["content-language","content-type","default-style","refresh"]}},meter:{attrs:{value:null,min:null,low:null,high:null,max:null,optimum:null}},nav:le,noscript:le,object:{attrs:{data:null,type:null,name:null,usemap:null,form:null,width:null,height:null,typemustmatch:["typemustmatch"]}},ol:{attrs:{reversed:["reversed"],start:null,type:["1","a","A","i","I"]},children:["li","script","template","ul","ol"]},optgroup:{attrs:{disabled:["disabled"],label:null}},option:{attrs:{disabled:["disabled"],label:null,selected:["selected"],value:null}},output:{attrs:{for:null,form:null,name:null}},p:le,param:{attrs:{name:null,value:null}},pre:le,progress:{attrs:{value:null,max:null}},q:{attrs:{cite:null}},rp:le,rt:le,ruby:le,samp:le,script:{attrs:{type:["text/javascript"],src:null,async:["async"],defer:["defer"],charset:cy}},section:le,select:{attrs:{form:null,name:null,size:null,autofocus:["autofocus"],disabled:["disabled"],multiple:["multiple"]}},slot:{attrs:{name:null}},small:le,source:{attrs:{src:null,type:null,media:null}},span:le,strong:le,style:{attrs:{type:["text/css"],media:null,scoped:null}},sub:le,summary:le,sup:le,table:le,tbody:le,td:{attrs:{colspan:null,rowspan:null,headers:null}},template:le,textarea:{attrs:{dirname:null,form:null,maxlength:null,name:null,placeholder:null,rows:null,cols:null,autofocus:["autofocus"],disabled:["disabled"],readonly:["readonly"],required:["required"],wrap:["soft","hard"]}},tfoot:le,th:{attrs:{colspan:null,rowspan:null,headers:null,scope:["row","col","rowgroup","colgroup"]}},thead:le,time:{attrs:{datetime:null}},title:le,tr:le,track:{attrs:{src:null,label:null,default:null,kind:["subtitles","captions","descriptions","chapters","metadata"],srclang:null}},ul:{children:["li","script","template","ul","ol"]},var:le,video:{attrs:{src:null,poster:null,width:null,height:null,crossorigin:["anonymous","use-credentials"],preload:["auto","metadata","none"],autoplay:["autoplay"],mediagroup:["movie"],muted:["muted"],controls:["controls"]}},wbr:le},pz={accesskey:null,class:null,contenteditable:jn,contextmenu:null,dir:["ltr","rtl","auto"],draggable:["true","false","auto"],dropzone:["copy","move","link","string:","file:"],hidden:["hidden"],id:null,inert:["inert"],itemid:null,itemprop:null,itemref:null,itemscope:["itemscope"],itemtype:null,lang:["ar","bn","de","en-GB","en-US","es","fr","hi","id","ja","pa","pt","ru","tr","zh"],spellcheck:jn,autocorrect:jn,autocapitalize:jn,style:null,tabindex:null,title:null,translate:["yes","no"],rel:["stylesheet","alternate","author","bookmark","help","license","next","nofollow","noreferrer","prefetch","prev","search","tag"],role:"alert application article banner button cell checkbox complementary contentinfo dialog document feed figure form grid gridcell heading img list listbox listitem main navigation region row rowgroup search switch tab table tabpanel textbox timer".split(" "),"aria-activedescendant":null,"aria-atomic":jn,"aria-autocomplete":["inline","list","both","none"],"aria-busy":jn,"aria-checked":["true","false","mixed","undefined"],"aria-controls":null,"aria-describedby":null,"aria-disabled":jn,"aria-dropeffect":null,"aria-expanded":["true","false","undefined"],"aria-flowto":null,"aria-grabbed":["true","false","undefined"],"aria-haspopup":jn,"aria-hidden":jn,"aria-invalid":["true","false","grammar","spelling"],"aria-label":null,"aria-labelledby":null,"aria-level":null,"aria-live":["off","polite","assertive"],"aria-multiline":jn,"aria-multiselectable":jn,"aria-owns":null,"aria-posinset":null,"aria-pressed":["true","false","mixed","undefined"],"aria-readonly":jn,"aria-relevant":null,"aria-required":jn,"aria-selected":["true","false","undefined"],"aria-setsize":null,"aria-sort":["ascending","descending","none","other"],"aria-valuemax":null,"aria-valuemin":null,"aria-valuenow":null,"aria-valuetext":null},gz="beforeunload copy cut dragstart dragover dragleave dragenter dragend drag paste focus blur change click load mousedown mouseenter mouseleave mouseup keydown keyup resize scroll unload".split(" ").map(t=>"on"+t);for(let t of gz)pz[t]=null;class dh{constructor(e,n){this.tags={...Sge,...e},this.globalAttrs={...pz,...n},this.allTags=Object.keys(this.tags),this.globalAttrNames=Object.keys(this.globalAttrs)}}dh.default=new dh;function Rl(t,e,n=t.length){if(!e)return"";let r=e.firstChild,i=r&&r.getChild("TagName");return i?t.sliceString(i.from,Math.min(i.to,n)):""}function Nl(t,e=!1){for(;t;t=t.parent)if(t.name=="Element")if(e)e=!1;else return t;return null}function mz(t,e,n){let r=n.tags[Rl(t,Nl(e))];return(r==null?void 0:r.children)||n.allTags}function M0(t,e){let n=[];for(let r=Nl(e);r&&!r.type.isTop;r=Nl(r.parent)){let i=Rl(t,r);if(i&&r.lastChild.name=="CloseTag")break;i&&n.indexOf(i)<0&&(e.name=="EndTag"||e.from>=r.firstChild.to)&&n.push(i)}return n}const Oz=/^[:\-\.\w\u00b7-\uffff]*$/;function RA(t,e,n,r,i){let s=/\s*>/.test(t.sliceDoc(i,i+5))?"":">",o=Nl(n,n.name=="StartTag"||n.name=="TagName");return{from:r,to:i,options:mz(t.doc,o,e).map(a=>({label:a,type:"type"})).concat(M0(t.doc,n).map((a,l)=>({label:"/"+a,apply:"/"+a+s,type:"type",boost:99-l}))),validFor:/^\/?[:\-\.\w\u00b7-\uffff]*$/}}function NA(t,e,n,r){let i=/\s*>/.test(t.sliceDoc(r,r+5))?"":">";return{from:n,to:r,options:M0(t.doc,e).map((s,o)=>({label:s,apply:s+i,type:"type",boost:99-o})),validFor:Oz}}function kge(t,e,n,r){let i=[],s=0;for(let o of mz(t.doc,n,e))i.push({label:"<"+o,type:"type"});for(let o of M0(t.doc,n))i.push({label:"</"+o+">",type:"type",boost:99-s++});return{from:r,to:r,options:i,validFor:/^<\/?[:\-\.\w\u00b7-\uffff]*$/}}function vge(t,e,n,r,i){let s=Nl(n),o=s?e.tags[Rl(t.doc,s)]:null,a=o&&o.attrs?Object.keys(o.attrs):[],l=o&&o.globalAttrs===!1?a:a.length?a.concat(e.globalAttrNames):e.globalAttrNames;return{from:r,to:i,options:l.map(c=>({label:c,type:"property"})),validFor:Oz}}function xge(t,e,n,r,i){var s;let o=(s=n.parent)===null||s===void 0?void 0:s.getChild("AttributeName"),a=[],l;if(o){let c=t.sliceDoc(o.from,o.to),u=e.globalAttrs[c];if(!u){let h=Nl(n),d=h?e.tags[Rl(t.doc,h)]:null;u=(d==null?void 0:d.attrs)&&d.attrs[c]}if(u){let h=t.sliceDoc(r,i).toLowerCase(),d='"',f='"';/^['"]/.test(h)?(l=h[0]=='"'?/^[^"]*$/:/^[^']*$/,d="",f=t.sliceDoc(i,i+1)==h[0]?"":h[0],h=h.slice(1),r++):l=/^[^\s<>='"]*$/;for(let p of u)a.push({label:p,apply:d+p+f,type:"constant"})}}return{from:r,to:i,options:a,validFor:l}}function yz(t,e){let{state:n,pos:r}=e,i=He(n).resolveInner(r,-1),s=i.resolve(r);for(let o=r,a;s==i&&(a=i.childBefore(o));){let l=a.lastChild;if(!l||!l.type.isError||l.from<l.to)break;s=i=a,o=l.from}return i.name=="TagName"?i.parent&&/CloseTag$/.test(i.parent.name)?NA(n,i,i.from,r):RA(n,t,i,i.from,r):i.name=="StartTag"||i.name=="IncompleteTag"?RA(n,t,i,r,r):i.name=="StartCloseTag"||i.name=="IncompleteCloseTag"?NA(n,i,r,r):i.name=="OpenTag"||i.name=="SelfClosingTag"||i.name=="AttributeName"?vge(n,t,i,i.name=="AttributeName"?i.from:r,r):i.name=="Is"||i.name=="AttributeValue"||i.name=="UnquotedAttributeValue"?xge(n,t,i,i.name=="Is"?r:i.from,r):e.explicit&&(s.name=="Element"||s.name=="Text"||s.name=="Document")?kge(n,t,i,r):null}function Cge(t){return yz(dh.default,t)}function Ege(t){let{extraTags:e,extraGlobalAttributes:n}=t,r=n||e?new dh(e,n):dh.default;return i=>yz(r,i)}const _ge=yi.parser.configure({top:"SingleExpression"}),bz=[{tag:"script",attrs:t=>t.type=="text/typescript"||t.lang=="ts",parser:cz.parser},{tag:"script",attrs:t=>t.type=="text/babel"||t.type=="text/jsx",parser:uz.parser},{tag:"script",attrs:t=>t.type=="text/typescript-jsx",parser:hz.parser},{tag:"script",attrs(t){return/^(importmap|speculationrules|application\/(.+\+)?json)$/i.test(t.type)},parser:_ge},{tag:"script",attrs(t){return!t.type||/^(?:text|application)\/(?:x-)?(?:java|ecma)script$|^module$|^$/i.test(t.type)},parser:yi.parser},{tag:"style",attrs(t){return(!t.lang||t.lang=="css")&&(!t.type||/^(text\/)?(x-)?(stylesheet|css)$/i.test(t.type))},parser:og.parser}],wz=[{name:"style",parser:og.parser.configure({top:"Styles"})}].concat(gz.map(t=>({name:t,parser:yi.parser}))),Sz=_l.define({name:"html",parser:Kfe.configure({props:[Rh.add({Element(t){let e=/^(\s*)(<\/)?/.exec(t.textAfter);return t.node.to<=t.pos+e[0].length?t.continue():t.lineIndent(t.node.from)+(e[2]?0:t.unit)},"OpenTag CloseTag SelfClosingTag"(t){return t.column(t.node.from)+t.unit},Document(t){if(t.pos+/\s*/.exec(t.textAfter)[0].length<t.node.to)return t.continue();let e=null,n;for(let r=t.node;;){let i=r.lastChild;if(!i||i.name!="Element"||i.to!=r.to)break;e=r=i}return e&&!((n=e.lastChild)&&(n.name=="CloseTag"||n.name=="SelfClosingTag"))?t.lineIndent(e.from)+t.unit:null}}),Kl.add({Element(t){let e=t.firstChild,n=t.lastChild;return!e||e.name!="OpenTag"?null:{from:e.to,to:n.name=="CloseTag"?n.from:t.to}}}),fD.add({"OpenTag CloseTag":t=>t.getChild("TagName")})]}),languageData:{commentTokens:{block:{open:"<!--",close:"-->"}},indentOnInput:/^\s*<\/\w+\W$/,wordChars:"-_"}}),Ef=Sz.configure({wrap:q2(bz,wz)});function Tge(t={}){let e="",n;t.matchClosingTags===!1&&(e="noMatch"),t.selfClosingTags===!0&&(e=(e?e+" ":"")+"selfClosing"),(t.nestedLanguages&&t.nestedLanguages.length||t.nestedAttributes&&t.nestedAttributes.length)&&(n=q2((t.nestedLanguages||[]).concat(bz),(t.nestedAttributes||[]).concat(wz)));let r=n?Sz.configure({wrap:n,dialect:e}):e?Ef.configure({dialect:e}):Ef;return new th(r,[Ef.data.of({autocomplete:Ege(t)}),t.autoCloseTags!==!1?Age:[],Oge().support,$pe().support])}const $A=new Set("area base br col command embed frame hr img input keygen link meta param source track wbr menuitem".split(" ")),Age=te.inputHandler.of((t,e,n,r,i)=>{if(t.composing||t.state.readOnly||e!=n||r!=">"&&r!="/"||!Ef.isActiveAt(t.state,e,-1))return!1;let s=i(),{state:o}=s,a=o.changeByRange(l=>{var c,u,h;let d=o.doc.sliceString(l.from-1,l.to)==r,{head:f}=l,p=He(o).resolveInner(f,-1),g;if(d&&r==">"&&p.name=="EndTag"){let O=p.parent;if(((u=(c=O.parent)===null||c===void 0?void 0:c.lastChild)===null||u===void 0?void 0:u.name)!="CloseTag"&&(g=Rl(o.doc,O.parent,f))&&!$A.has(g)){let m=f+(o.doc.sliceString(f,f+1)===">"?1:0),y=`</${g}>`;return{range:l,changes:{from:f,to:m,insert:y}}}}else if(d&&r=="/"&&p.name=="IncompleteCloseTag"){let O=p.parent;if(p.from==f-2&&((h=O.lastChild)===null||h===void 0?void 0:h.name)!="CloseTag"&&(g=Rl(o.doc,O,f))&&!$A.has(g)){let m=f+(o.doc.sliceString(f,f+1)===">"?1:0),y=`${g}>`;return{range:B.cursor(f+y.length,-1),changes:{from:f,to:m,insert:y}}}}return{range:l}});return a.changes.empty?!1:(t.dispatch([s,o.update(a,{userEvent:"input.complete",scrollIntoView:!0})]),!0)}),kz=o0({commentTokens:{block:{open:"<!--",close:"-->"}}}),vz=new be,xz=Wde.configure({props:[Kl.add(t=>!t.is("Block")||t.is("Document")||Kw(t)!=null||Pge(t)?void 0:(e,n)=>({from:n.doc.lineAt(e.from).to,to:e.to})),vz.add(Kw),Rh.add({Document:()=>null}),vo.add({Document:kz})]});function Kw(t){let e=/^(?:ATX|Setext)Heading(\d)$/.exec(t.name);return e?+e[1]:void 0}function Pge(t){return t.name=="OrderedList"||t.name=="BulletList"}function Ige(t,e){let n=t;for(;;){let r=n.nextSibling,i;if(!r||(i=Kw(r.type))!=null&&i<=e)break;n=r}return n.to}const Rge=JL.of((t,e,n)=>{for(let r=He(t).resolveInner(n,-1);r&&!(r.from<e);r=r.parent){let i=r.type.prop(vz);if(i==null)continue;let s=Ige(r,i);if(s>n)return{from:n,to:s}}return null});function Q0(t){return new dr(kz,t,[],"markdown")}const Nge=Q0(xz),$ge=xz.configure([rfe,sfe,ife,ofe,{props:[Kl.add({Table:(t,e)=>({from:e.doc.lineAt(t.from).to,to:t.to})})]}]),ag=Q0($ge);function Mge(t,e){return n=>{if(n&&t){let r=null;if(n=/\S*/.exec(n)[0],typeof t=="function"?r=t(n):r=Up.matchLanguageName(t,n,!0),r instanceof Up)return r.support?r.support.language.parser:eh.getSkippingParser(r.load());if(r)return r.parser}return e?e.parser:null}}class dy{constructor(e,n,r,i,s,o,a){this.node=e,this.from=n,this.to=r,this.spaceBefore=i,this.spaceAfter=s,this.type=o,this.item=a}blank(e,n=!0){let r=this.spaceBefore+(this.node.name=="Blockquote"?">":"");if(e!=null){for(;r.length<e;)r+=" ";return r}else{for(let i=this.to-this.from-r.length-this.spaceAfter.length;i>0;i--)r+=" ";return r+(n?this.spaceAfter:"")}}marker(e,n){let r=this.node.name=="OrderedList"?String(+Ez(this.item,e)[2]+n):"";return this.spaceBefore+r+this.type+this.spaceAfter}}function Cz(t,e){let n=[],r=[];for(let i=t;i;i=i.parent){if(i.name=="FencedCode")return r;(i.name=="ListItem"||i.name=="Blockquote")&&n.push(i)}for(let i=n.length-1;i>=0;i--){let s=n[i],o,a=e.lineAt(s.from),l=s.from-a.from;if(s.name=="Blockquote"&&(o=/^ *>( ?)/.exec(a.text.slice(l))))r.push(new dy(s,l,l+o[0].length,"",o[1],">",null));else if(s.name=="ListItem"&&s.parent.name=="OrderedList"&&(o=/^( *)\d+([.)])( *)/.exec(a.text.slice(l)))){let c=o[3],u=o[0].length;c.length>=4&&(c=c.slice(0,c.length-4),u-=4),r.push(new dy(s.parent,l,l+u,o[1],c,o[2],s))}else if(s.name=="ListItem"&&s.parent.name=="BulletList"&&(o=/^( *)([-+*])( {1,4}\[[ xX]\])?( +)/.exec(a.text.slice(l)))){let c=o[4],u=o[0].length;c.length>4&&(c=c.slice(0,c.length-4),u-=4);let h=o[2];o[3]&&(h+=o[3].replace(/[xX]/," ")),r.push(new dy(s.parent,l,l+u,o[1],c,h,s))}}return r}function Ez(t,e){return/^(\s*)(\d+)(?=[.)])/.exec(e.sliceString(t.from,t.from+10))}function fy(t,e,n,r=0){for(let i=-1,s=t;;){if(s.name=="ListItem"){let a=Ez(s,e),l=+a[2];if(i>=0){if(l!=i+1)return;n.push({from:s.from+a[1].length,to:s.from+a[0].length,insert:String(i+2+r)})}i=l}let o=s.nextSibling;if(!o)break;s=o}}function L0(t,e){let n=/^[ \t]*/.exec(t)[0].length;if(!n||e.facet(ql)!=" ")return t;let r=Ur(t,4,n),i="";for(let s=r;s>0;)s>=4?(i+=" ",s-=4):(i+=" ",s--);return i+t.slice(n)}const Qge=(t={})=>({state:e,dispatch:n})=>{let r=He(e),{doc:i}=e,s=null,o=e.changeByRange(a=>{if(!a.empty||!ag.isActiveAt(e,a.from,-1)&&!ag.isActiveAt(e,a.from,1))return s={range:a};let l=a.from,c=i.lineAt(l),u=Cz(r.resolveInner(l,-1),i);for(;u.length&&u[u.length-1].from>l-c.from;)u.pop();if(!u.length)return s={range:a};let h=u[u.length-1];if(h.to-h.spaceAfter.length>l-c.from)return s={range:a};let d=l>=h.to-h.spaceAfter.length&&!/\S/.test(c.text.slice(h.to));if(h.item&&d){let m=h.node.firstChild,y=h.node.getChild("ListItem","ListItem");if(m.to>=l||y&&y.to<l||c.from>0&&!/[^\s>]/.test(i.lineAt(c.from-1).text)||t.nonTightLists===!1){let b=u.length>1?u[u.length-2]:null,v,x="";b&&b.item?(v=c.from+b.from,x=b.marker(i,1)):v=c.from+(b?b.to:0);let S=[{from:v,to:l,insert:x}];return h.node.name=="OrderedList"&&fy(h.item,i,S,-2),b&&b.node.name=="OrderedList"&&fy(b.item,i,S),{range:B.cursor(v+x.length),changes:S}}else{let b=QA(u,e,c);return{range:B.cursor(l+b.length+1),changes:{from:c.from,insert:b+e.lineBreak}}}}if(h.node.name=="Blockquote"&&d&&c.from){let m=i.lineAt(c.from-1),y=/>\s*$/.exec(m.text);if(y&&y.index==h.from){let b=e.changes([{from:m.from+y.index,to:m.to},{from:c.from+h.from,to:c.to}]);return{range:a.map(b),changes:b}}}let f=[];h.node.name=="OrderedList"&&fy(h.item,i,f);let p=h.item&&h.item.from<c.from,g="";if(!p||/^[\s\d.)\-+*>]*/.exec(c.text)[0].length>=h.to)for(let m=0,y=u.length-1;m<=y;m++)g+=m==y&&!p?u[m].marker(i,1):u[m].blank(m<y?Ur(c.text,4,u[m+1].from)-g.length:null);let O=l;for(;O>c.from&&/\s/.test(c.text.charAt(O-c.from-1));)O--;return g=L0(g,e),Dge(h.node,e.doc)&&(g=QA(u,e,c)+e.lineBreak+g),f.push({from:O,to:l,insert:e.lineBreak+g}),{range:B.cursor(O+g.length+1),changes:f}});return s?!1:(n(e.update(o,{scrollIntoView:!0,userEvent:"input"})),!0)},Lge=Qge();function MA(t){return t.name=="QuoteMark"||t.name=="ListMark"}function Dge(t,e){if(t.name!="OrderedList"&&t.name!="BulletList")return!1;let n=t.firstChild,r=t.getChild("ListItem","ListItem");if(!r)return!1;let i=e.lineAt(n.to),s=e.lineAt(r.from),o=/^[\s>]*$/.test(i.text);return i.number+(o?0:1)<s.number}function QA(t,e,n){let r="";for(let i=0,s=t.length-2;i<=s;i++)r+=t[i].blank(i<s?Ur(n.text,4,t[i+1].from)-r.length:null,i<s);return L0(r,e)}function zge(t,e){let n=t.resolveInner(e,-1),r=e;MA(n)&&(r=n.from,n=n.parent);for(let i;i=n.childBefore(r);)if(MA(i))r=i.from;else if(i.name=="OrderedList"||i.name=="BulletList")n=i.lastChild,r=n.to;else break;return n}const Bge=({state:t,dispatch:e})=>{let n=He(t),r=null,i=t.changeByRange(s=>{let o=s.from,{doc:a}=t;if(s.empty&&ag.isActiveAt(t,s.from)){let l=a.lineAt(o),c=Cz(zge(n,o),a);if(c.length){let u=c[c.length-1],h=u.to-u.spaceAfter.length+(u.spaceAfter?1:0);if(o-l.from>h&&!/\S/.test(l.text.slice(h,o-l.from)))return{range:B.cursor(l.from+h),changes:{from:l.from+h,to:o}};if(o-l.from==h&&(!u.item||l.from<=u.item.from||!/\S/.test(l.text.slice(0,u.to)))){let d=l.from+u.from;if(u.item&&u.node.from<u.item.from&&/\S/.test(l.text.slice(u.from,u.to))){let f=u.blank(Ur(l.text,4,u.to)-Ur(l.text,4,u.from));return d==l.from&&(f=L0(f,t)),{range:B.cursor(d+f.length),changes:{from:d,to:l.from+u.to,insert:f}}}if(d<o)return{range:B.cursor(d),changes:{from:d,to:o}}}}}return r={range:s}});return r?!1:(e(t.update(i,{scrollIntoView:!0,userEvent:"delete"})),!0)},jge=[{key:"Enter",run:Lge},{key:"Backspace",run:Bge}],_z=Tge({matchClosingTags:!1});function Uge(t={}){let{codeLanguages:e,defaultCodeLanguage:n,addKeymap:r=!0,base:{parser:i}=Nge,completeHTMLTags:s=!0,pasteURLAsLink:o=!0,htmlTagLanguage:a=_z}=t;if(!(i instanceof Om))throw new RangeError("Base parser provided to `markdown` should be a Markdown parser");let l=t.extensions?[t.extensions]:[],c=[a.support,Rge],u;o&&c.push(Wge),n instanceof th?(c.push(n.support),u=n.language):n&&(u=n);let h=e||u?Mge(e,u):void 0;l.push(Hde({codeParser:h,htmlParser:a.language.parser})),r&&c.push(ns.high(Yl.of(jge)));let d=Q0(i.configure(l));return s&&c.push(d.data.of({autocomplete:Zge})),new th(d,c)}function Zge(t){let{state:e,pos:n}=t,r=/<[:\-\.\w\u00b7-\uffff]*$/.exec(e.sliceDoc(n-25,n));if(!r)return null;let i=He(e).resolveInner(n,-1);for(;i&&!i.type.isTop;){if(i.name=="CodeBlock"||i.name=="FencedCode"||i.name=="ProcessingInstructionBlock"||i.name=="CommentBlock"||i.name=="Link"||i.name=="Image")return null;i=i.parent}return{from:n-r[0].length,to:n,options:Fge(),validFor:/^<[:\-\.\w\u00b7-\uffff]*$/}}let py=null;function Fge(){if(py)return py;let t=Cge(new O0(Ee.create({extensions:_z}),0,!0));return py=t?t.options:[]}const Xge=/code|horizontalrule|html|link|comment|processing|escape|entity|image|mark|url/i,Wge=te.domEventHandlers({paste:(t,e)=>{var n;let{main:r}=e.state.selection;if(r.empty)return!1;let i=(n=t.clipboardData)===null||n===void 0?void 0:n.getData("text/plain");if(!i||!/^(https?:\/\/|mailto:|xmpp:|www\.)/.test(i)||(/^www\./.test(i)&&(i="https://"+i),!ag.isActiveAt(e.state,r.from,1)))return!1;let s=He(e.state),o=!1;return s.iterate({from:r.from,to:r.to,enter:a=>{(a.from>r.from||Xge.test(a.name))&&(o=!0)},leave:a=>{a.to<r.to&&(o=!0)}}),o?!1:(e.dispatch({changes:[{from:r.from,insert:"["},{from:r.to,insert:`](${i})`}],userEvent:"input.paste",scrollIntoView:!0}),!0)}});function Vge(){const[t]=lR(),e=t.get("path"),n=t.get("new")==="1",[r,i]=P.useState(e||"pages/"),[s,o]=P.useState(""),[a,l]=P.useState(n),[c,u]=P.useState(!1),[h,d]=P.useState(null),f=es();P.useEffect(()=>{if(!e||n){l(!0);return}l(!1),rt.readPage(e).then(g=>{o(g.content),l(!0),d(null)}).catch(g=>d(g instanceof Error?g.message:String(g)))},[e,n]);async function p(){if(!r.startsWith("pages/")||!r.endsWith(".md")){d("Path must start with pages/ and end in .md");return}u(!0),d(null);try{await rt.writePage(r,s),f(`/wiki?selected=${encodeURIComponent(r)}`)}catch(g){d(g instanceof Error?g.message:String(g))}finally{u(!1)}}return a?w.jsxs("div",{className:"page wiki-edit",children:[w.jsx("header",{className:"page-header",children:w.jsx("h1",{children:n?"New page":"Edit page"})}),h?w.jsx(br,{inline:!0,message:h,onRetry:()=>void p()}):null,w.jsx("div",{className:"row",children:w.jsxs("label",{htmlFor:"wiki-path",children:["Path",w.jsx("input",{id:"wiki-path",type:"text",value:r,onChange:g=>i(g.target.value),disabled:!n,"aria-invalid":!!(h&&(!r.startsWith("pages/")||!r.endsWith(".md")))})]})}),w.jsx("div",{className:"wiki-editor","aria-label":"Markdown editor",children:w.jsx(O2,{value:s,height:"60vh",extensions:[Uge()],onChange:g=>o(g),theme:"dark"})}),w.jsxs("div",{className:"composer-actions",children:[w.jsx("button",{type:"button",className:"btn primary",onClick:()=>void p(),disabled:c,children:c?"Saving…":"Save"}),w.jsx("button",{type:"button",className:"btn",onClick:()=>f(e?`/wiki?selected=${encodeURIComponent(e)}`:"/wiki"),children:"Cancel"})]})]}):w.jsx(Jn,{centered:!0,label:"Loading editor",detail:"Fetching the wiki page content."})}function Hge(){const[t,e]=P.useState(null),[n,r]=P.useState(null),[i,s]=P.useState(!0);async function o(){s(!0);try{const l=await rt.listSkills();e(l),r(null)}catch(l){r(l instanceof Error?l.message:String(l))}finally{s(!1)}}P.useEffect(()=>{o()},[]);async function a(l){if(confirm(`Uninstall ${l}?`))try{const c=await rt.removeSkill(l);if(!c.ok){r(c.message);return}await o()}catch(c){r(c instanceof Error?c.message:String(c))}}return w.jsxs("div",{className:"page skills",children:[w.jsxs("header",{className:"page-header",children:[w.jsx("h1",{children:"Skills"}),w.jsx("p",{className:"dim",children:"Bundled skills ship with Chapterhouse. Local skills live in ~/.chapterhouse/skills/ and can be uninstalled here."})]}),n?w.jsx(br,{inline:!0,message:n,onRetry:()=>void o()}):null,i&&t===null?w.jsx(Jn,{inline:!0,label:"Loading skills"}):null,w.jsx("div",{className:"skill-grid",children:t==null?void 0:t.map(l=>w.jsxs("div",{className:"skill-card",children:[w.jsxs("div",{className:"skill-head",children:[w.jsx("strong",{children:l.name}),w.jsx("span",{className:`tag tag-${l.source}`,children:l.source})]}),w.jsx("div",{className:"dim small",children:l.slug}),w.jsx("p",{children:l.description}),l.source==="local"?w.jsx("button",{type:"button",className:"btn danger",onClick:()=>void a(l.slug),children:"Uninstall"}):null]},l.directory))})]})}function Yge(){const[t,e]=P.useState(null),[n,r]=P.useState(null),[i,s]=P.useState(!0);async function o(){s(!0);try{e(await rt.listHistory()),r(null)}catch(a){r(a instanceof Error?a.message:String(a))}finally{s(!1)}}return P.useEffect(()=>{o()},[]),w.jsxs("div",{className:"page history",children:[w.jsxs("header",{className:"page-header",children:[w.jsx("h1",{children:"Conversation history"}),w.jsxs("p",{className:"dim",children:["Daily summaries Chapterhouse writes to ",w.jsx("code",{children:"pages/conversations/"}),". Newest first."]})]}),n?w.jsx(br,{inline:!0,message:n,onRetry:()=>void o()}):null,i&&t===null?w.jsx(Jn,{inline:!0,label:"Loading conversation history"}):null,t&&t.length===0?w.jsx(yl,{icon:"📄",title:"No history yet",description:"Conversation summaries will appear here once Chapterhouse writes them to pages/conversations/."}):null,w.jsx("ul",{className:"history-list",children:t==null?void 0:t.map(a=>{const l=a.path.split("/").pop()||a.path,c=new Date(a.mtime).toLocaleString();return w.jsxs("li",{children:[w.jsx(aR,{to:`/wiki?selected=${encodeURIComponent(a.path)}`,className:"link",children:l}),w.jsxs("span",{className:"dim small",children:[" · ",c]})]},a.path)})})]})}function Gge(){const[t,e]=P.useState(null),[n,r]=P.useState(null),[i,s]=P.useState(null),[o,a]=P.useState(null),[l,c]=P.useState(!0),[u,h]=P.useState(!1),d=Ze(m=>m.setCurrentModel);async function f(){a(null),c(!0);try{const[m,y]=await Promise.all([rt.listModels(),rt.getAuto()]);e(m.models),r(m.current),d(m.current),s(y)}catch(m){a(m instanceof Error?m.message:String(m))}finally{c(!1)}}P.useEffect(()=>{f()},[]);async function p(m){if(!(!m||m===n)){h(!0),a(null);try{await rt.setModel(m),r(m),d(m)}catch(y){a(y instanceof Error?y.message:String(y))}finally{h(!1)}}}async function g(){if(i){h(!0),a(null);try{await rt.setAuto({enabled:!i.enabled}),await f()}catch(m){a(m instanceof Error?m.message:String(m))}finally{h(!1)}}}async function O(){if(confirm("Restart the daemon? In-flight workers will be stopped.")){a(null),h(!0);try{await rt.restart()}catch(m){a(m instanceof Error?m.message:String(m))}finally{h(!1)}}}return w.jsxs("div",{className:"page settings",children:[w.jsx("header",{className:"page-header",children:w.jsx("h1",{children:"Settings"})}),o?w.jsx(br,{inline:!0,message:o,onRetry:()=>void f()}):null,w.jsxs("section",{"aria-busy":l||u,children:[w.jsx("h2",{children:"Model"}),l&&t===null?w.jsx(Jn,{inline:!0,label:"Loading available models"}):w.jsxs("div",{className:"row settings-row",children:[w.jsxs("label",{className:"settings-field",htmlFor:"model-select",children:[w.jsx("span",{className:"settings-field-label",children:"Available models"}),w.jsx("select",{id:"model-select",value:n??"",onChange:m=>void p(m.target.value),disabled:u,children:t==null?void 0:t.map(m=>w.jsx("option",{value:m,children:m},m))})]}),w.jsxs("span",{className:"dim small",children:["Current: ",n??"(unknown)"]})]})]}),w.jsxs("section",{"aria-busy":l||u,children:[w.jsx("h2",{children:"Auto-routing"}),l&&i===null?w.jsx(Jn,{inline:!0,label:"Loading routing preferences"}):i?w.jsxs(w.Fragment,{children:[w.jsxs("p",{children:["Auto-routing is currently ",w.jsx("strong",{children:i.enabled?"enabled":"disabled"}),". When on, Chapterhouse picks the model tier per message."]}),w.jsx("button",{type:"button",className:"btn",onClick:()=>void g(),disabled:u,children:i.enabled?"Disable":"Enable"})]}):null]}),w.jsxs("section",{children:[w.jsx("h2",{children:"Daemon"}),w.jsx("button",{type:"button",className:"btn danger",onClick:()=>void O(),disabled:u,children:"Restart daemon"})]})]})}gy.createRoot(document.getElementById("root")).render(w.jsx(Oa.StrictMode,{children:w.jsx(FG,{children:w.jsx(oZ,{children:w.jsx(qU,{children:w.jsxs(rr,{path:"/",element:w.jsx(ZG,{}),children:[w.jsx(rr,{index:!0,element:w.jsx(HU,{to:"/chat",replace:!0})}),w.jsx(rr,{path:"chat",element:w.jsx($ie,{})}),w.jsx(rr,{path:"projects",element:w.jsx(Die,{})}),w.jsx(rr,{path:"projects/chat/:projectRef",element:w.jsx(Qie,{})}),w.jsx(rr,{path:"workers",element:w.jsx(Lie,{})}),w.jsx(rr,{path:"wiki",element:w.jsx(Gie,{})}),w.jsx(rr,{path:"wiki/edit",element:w.jsx(Vge,{})}),w.jsx(rr,{path:"skills",element:w.jsx(Hge,{})}),w.jsx(rr,{path:"history",element:w.jsx(Yge,{})}),w.jsx(rr,{path:"settings",element:w.jsx(Gge,{})})]})})})})}));
|
|
208
|
-
//# sourceMappingURL=index-
|
|
208
|
+
//# sourceMappingURL=index-BWQf0ac8.js.map
|